Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
bluetooth-hci-socket
Advanced tools
Bluetooth HCI socket binding for Node.js
NOTE: Currently only supports Linux and Windows.
Note: the node-usb dependency might fail install, this is ok, because it is an optional optional dependency. Installing libudev-dev
via your Linux distribution's package manager will resolve the problem.
This library needs raw USB access to a Bluetooth 4.0 USB adapter, as it needs to bypass the Windows Bluetooth stack.
A WinUSB driver is required, use Zadig tool to replace the driver for your adapter.
WARNING: This will make the adapter unavaible in Windows Bluetooth settings!
Name | USB VID | USB PID |
---|---|---|
BCM920702 Bluetooth 4.0 | 0x0a5c | 0x21e8 |
BCM20702A0 Bluetooth 4.0 | 0x19ff | 0x0239 |
CSR8510 A10 | 0x0a12 | 0x0001 |
Asus BT-400 | 0x0b05 | 0x17cb |
npm install bluetooth-hci-socket
var BluetoothHciSocket = require('bluetooth-hci-socket');
var bluetoothHciSocket = new BluetoothHciSocket();
var filter = new Buffer(14);
// ...
bluetoothHciSocket.setFilter(filter);
bluetoothHciSocket.bindRaw([deviceId]); // optional deviceId (integer)
bluetoothHciSocket.bindUser([deviceId]); // optional deviceId (integer)
Requires the device to be in the powered down state (sudo hciconfig hciX down
).
bluetoothHciSocket.bindControl();
Query the device state.
var isDevUp = bluetoothHciSocket.isDevUp(); // returns: true or false
Note: must be called after bindRaw
.
Start or stop event handling:
bluetoothHciSocket.start();
// ...
bluetoothHciSocket.stop();
Note: must be called after bindRaw
or bindControl
.
var data = new Buffer(/* ... */);
// ...
bluetoothHciSocket.write(data);
Note: must be called after bindRaw
or bindControl
.
bluetoothHciSocket.on('data', function(data) {
// data is a Buffer
// ...
});
bluetoothHciSocket.on('error', function(error) {
// error is a Error
// ...
});
See examples folder for code examples.
Unload btusb
kernel module:
sudo rmmod btusb
Set BLUETOOTH_HCI_SOCKET_FORCE_USB
environment variable:
sudo BLUETOOTH_HCI_SOCKET_FORCE_USB=1 node <file>.js
sudo kextunload -b com.apple.iokit.CSRBluetoothHostControllerUSBTransport
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
Set BLUETOOTH_HCI_SOCKET_USB_VID
and BLUETOOTH_HCI_SOCKET_USB_PID
environment variables.
Example for USB device id: 050d:065a:
set BLUETOOTH_HCI_SOCKET_USB_VID=0x050d
set BLUETOOTH_HCI_SOCKET_USB_PID=0x065a
node <file>.js
FAQs
Bluetooth HCI socket binding for Node.js
The npm package bluetooth-hci-socket receives a total of 786 weekly downloads. As such, bluetooth-hci-socket popularity was classified as not popular.
We found that bluetooth-hci-socket demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.