Skip to content

Add BlueZ D-Bus backend for Linux desktop Bluetooth support#79

Merged
stoprocent merged 2 commits into
mainfrom
claude/add-dbus-ble-backend-uL6Se
May 7, 2026
Merged

Add BlueZ D-Bus backend for Linux desktop Bluetooth support#79
stoprocent merged 2 commits into
mainfrom
claude/add-dbus-ble-backend-uL6Se

Conversation

@stoprocent
Copy link
Copy Markdown
Owner

Summary

This PR adds a new D-Bus backend for noble that enables Bluetooth support on Linux desktop systems using BlueZ's D-Bus interface. This complements the existing HCI socket binding and provides a more stable, user-friendly alternative for desktop Linux environments.

Key Changes

  • New D-Bus Bindings Module (lib/dbus/bindings.js): Complete implementation of the noble bindings interface using the dbus-next library to communicate with BlueZ via D-Bus. Includes:

    • Adapter discovery and state management (powered on/off)
    • Device discovery with advertisement parsing (local name, TX power, manufacturer data, service data, UUIDs)
    • Connection/disconnection lifecycle management
    • GATT service, characteristic, and descriptor discovery
    • Read/write operations on characteristics and descriptors
    • Notification/indication support with property change listeners
    • RSSI updates and scan parameter management
  • UUID Utilities (lib/dbus/uuid.js): Helper functions for UUID normalization and expansion between Bluetooth short forms (16-bit, 32-bit) and full 128-bit UUIDs, plus MAC address and D-Bus device path conversions.

  • Comprehensive Test Suite (test/lib/dbus/bindings.test.js, test/lib/dbus/uuid.test.js): Full test coverage including:

    • Adapter initialization and state transitions
    • Device discovery with advertisement parsing
    • GATT hierarchy traversal (services → characteristics → descriptors)
    • Read/write/notify operations
    • Error handling for unsupported operations
  • Integration: Updated lib/resolve-bindings.js to register the new 'dbus' binding type and added dbus-next as an optional dependency in package.json.

  • Documentation: Updated README.md to document the new D-Bus binding option.

Notable Implementation Details

  • The implementation mirrors BlueZ's D-Bus object hierarchy, maintaining a local cache of managed objects that gets updated via InterfacesAdded/InterfacesRemoved signals.
  • Advertisement data is reconstructed from BlueZ device properties (Name, Alias, TxPower, UUIDs, ManufacturerData, ServiceData).
  • Characteristic flags are mapped to noble's property names (e.g., 'write-without-response' → 'writeWithoutResponse').
  • Notifications are implemented by listening to PropertiesChanged signals on characteristic Value properties.
  • The binding gracefully handles unsupported operations (e.g., readHandle, broadcast) by emitting warnings.
  • Proper cleanup of D-Bus listeners and proxies on stop/disconnect to prevent resource leaks.

https://claude.ai/code/session_01MXwXDUiGpmLM3iTUb2GV99

claude added 2 commits May 6, 2026 18:57
Adds a new optional binding that talks to bluetoothd via the org.bluez
D-Bus API instead of the kernel HCI socket. Useful on desktop Linux
where the system Bluetooth stack owns the adapter and the HCI backend
needs root or fights with bluetoothd / desktop applets.

Backend covers basic GATT central use: scan (with UUID filter),
connect/disconnect, service / characteristic / descriptor discovery,
read, write (with and without response), notify/indicate. Raw HCI
handle I/O, custom scan parameters, and broadcast property changes
are not supported and surface as warnings/errors.

The HCI backend remains the default on Linux. Opt in with either
withBindings('dbus') or NOBLE_BINDINGS=dbus. dbus-next is added as
an optional dependency so non-Linux installs don't pull it.
Pulling dbus-next as an optionalDependency made it (and its transitive
optional native dep usocket) install on macOS CI runners. With ~1100
extra lockfile lines and a vendored native install script, npm ci on
macos-latest started exiting non-zero, taking the test job and the
fail-fast'd Windows jobs with it.

The dbus backend is Linux-only by definition, and the binding already
prints a clear "Install it with: npm install dbus-next" message when
the module is missing. Make users install dbus-next themselves; revert
the lockfile churn so non-Linux CI is unaffected. README updated.
@stoprocent stoprocent merged commit 76540f4 into main May 7, 2026
29 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🎉 This PR is included in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants