From 91ebcfeb7d7dcb9e581bf0553888ba1d07f75b19 Mon Sep 17 00:00:00 2001 From: johnny Date: Mon, 18 Jun 2018 01:19:20 -0400 Subject: [PATCH 01/23] Fix build on node 10.x This fix comes from https://github.com/noble/node-bluetooth-hci-socket/issues/84#issuecomment-391951781 , so I can't personally vouch for it. Change-Id: Ifde2a3b996ab89a4b12b0eb155c081aca2b11dc3 Origin: https://github.com/jrobeson/node-bluetooth-hci-socket Forwarded: https://github.com/noble/node-bluetooth-hci-socket/pull/91 --- package.json | 2 +- src/BluetoothHciSocket.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 43ee21f..017aae3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ ], "dependencies": { "debug": "^2.2.0", - "nan": "^2.0.5", + "nan": "^2.10.0", "node-pre-gyp": "0.6.x" }, "optionalDependencies": { diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 469cda2..0cc7427 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -273,7 +273,7 @@ void BluetoothHciSocket::emitErrnoError() { Nan::New(strerror(errno)).ToLocalChecked() }; - Local error = errorConstructor->NewInstance(1, constructorArgs); + Local error = Nan::NewInstance(errorConstructor, 1, constructorArgs).ToLocalChecked(); Local argv[2] = { Nan::New("error").ToLocalChecked(), From ef70ab50a2b3d5491b2de50a37c7476e884fd169 Mon Sep 17 00:00:00 2001 From: johnny Date: Sat, 23 Jun 2018 02:59:55 -0400 Subject: [PATCH 02/23] Add binding_path path fix Change-Id: Ide752983f00395cf8cb59ab727a58ff0692112dd Origin: https://github.com/jrobeson/node-bluetooth-hci-socket Forwarded: https://github.com/noble/node-bluetooth-hci-socket/pull/91 --- lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/native.js b/lib/native.js index 68c4e79..051c847 100644 --- a/lib/native.js +++ b/lib/native.js @@ -2,7 +2,7 @@ var events = require('events'); var binary = require('node-pre-gyp'); var path = require('path'); -var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json'))); +var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json'))); var binding = require(binding_path); var BluetoothHciSocket = binding.BluetoothHciSocket; From 3a8425a367755aff75220a7330e6e2807102d58a Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Thu, 8 Nov 2018 09:28:23 +0100 Subject: [PATCH 03/23] usb: Add missing semicolon to comply es6 Change-Id: I94fdcbea6957d9f2c7eb5e28d8364363be6a3520 Forwarded: https://github.com/noble/node-bluetooth-hci-socket/pull/102 Signed-off-by: Philippe Coval --- lib/usb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/usb.js b/lib/usb.js index 1027b36..24cc86f 100644 --- a/lib/usb.js +++ b/lib/usb.js @@ -114,7 +114,7 @@ BluetoothHciSocket.prototype.getDeviceList = function() { "busNumber": dev.busNumber, "deviceAddress": dev.deviceAddress, })); -} +}; BluetoothHciSocket.prototype.bindControl = function() { this._mode = 'control'; From 9054b925b59ecbf48142642880a18597e058760b Mon Sep 17 00:00:00 2001 From: Owen Brotherwood Date: Sat, 4 Feb 2017 16:51:00 +0100 Subject: [PATCH 04/23] Windows Zadig update - current Zadig advice "Delete the driver software for this device" - Zadig tries to create a system restoral point but this usually fails on my Windows 10 (but thanks Zadig for trying) Change-Id: I004df41220c7e12b7cf8b1f1f1a65aab701ffe32 Origin: https://github.com/noble/node-bluetooth-hci-socket/commit/1620b37d47b5168decffbf23c82d6c038a2d0e5a.patch Forwarded: https://github.com/noble/node-bluetooth-hci-socket/pull/54/ --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 43f792a..179bcd8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ This library needs raw USB access to a Bluetooth 4.0 USB adapter, as it needs to A [WinUSB](https://msdn.microsoft.com/en-ca/library/windows/hardware/ff540196(v=vs.85).aspx) driver is required, use [Zadig tool](http://zadig.akeo.ie) to replace the driver for your adapter. __WARNING:__ This will make the adapter unavailable in Windows Bluetooth settings! To roll back to the original driver go to: ```Device Manager -> Open Device -> Update Driver``` +Note: +- that one should select "Delete the driver software for this device" as per Zadig instructions if the generation of the system restoral point by Zadig fails if one wishes to use restore system restoral point as an option. #### Compatible Bluetooth 4.0 USB Adapter's From 9d7c4873a2cf6a8e3acac4ba42fe97aef291efc7 Mon Sep 17 00:00:00 2001 From: johnny Date: Mon, 18 Jun 2018 01:23:07 -0400 Subject: [PATCH 05/23] Add Node 8.x and 10.x to the build matrices --- .travis.yml | 2 ++ appveyor.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4707af0..c706668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ env: - NODE_VERSION="4" - NODE_VERSION="5" - NODE_VERSION="6" + - NODE_VERSION="8" + - NODE_VERSION="10" before_install: - sudo apt-get install build-essential libudev-dev -y diff --git a/appveyor.yml b/appveyor.yml index 955348e..e8a4040 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ environment: - node_version: '4' - node_version: '5' - node_version: '6' + - node_version: '8' + - node_version: '10' install: - ps: Install-Product node $env:node_version $env:platform From e0d41624aeaa3955cab04338c771969d445c656b Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Fri, 14 Dec 2018 10:18:17 +0100 Subject: [PATCH 06/23] travis: Also build master branches Origin: https://github.com/abandonware/node-bluetooth-hci-socket Change-Id: I0b1c9c2a6950fa562c0e59ebdc780960bf219a6a Signed-off-by: Philippe Coval --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c706668..a7c1ce9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ branches: only: + - master - node-pre-gyp - /^[0-9]/ From 0c001d1bfeb4c01fb1a125e87fde9c684a4a2c5f Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Tue, 18 Dec 2018 12:48:14 +0100 Subject: [PATCH 07/23] remove nodejs 4 because also EOL and node-gyp dep no longer support it --- appveyor.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e8a4040..5f2e9ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,6 @@ environment: GYP_MSVS_VERSION: 2013 matrix: - - node_version: '4' - node_version: '5' - node_version: '6' - node_version: '8' @@ -16,10 +15,6 @@ environment: install: - ps: Install-Product node $env:node_version $env:platform - ps: npm install -g node-gyp node-pre-gyp-github - # This fixes an issue with Node 4.x on x86. If it builds without this line - # needing to be set, we can remove it. - - ps: npm config -g set node-gyp "$(npm config -g get prefix)\node_modules\node-gyp\bin\node-gyp.js" - - ps: if ($env:appveyor_repo_tag -match "true" -and $env:appveyor_repo_tag_name -match '^v?[0-9]') { $publish_binary=1; } build_script: From 699cbc52236bdf697dff5559f06d56e39b697e5d Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Tue, 18 Dec 2018 15:49:42 +0100 Subject: [PATCH 08/23] npm: Reformat package.json Before updating revision Change-Id: I4e19251e6ec5ea7d69b2390fe152fe337862ccb3 Forwarded: https://github.com/noble/node-bluetooth-hci-socket/pull/105 Origin: https://github.com/abandonware/node-bluetooth-hci-socket/ Bug: https://github.com/noble/node-bluetooth-hci-socket/issues/85 Signed-off-by: Philippe Coval --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 017aae3..07c825f 100644 --- a/package.json +++ b/package.json @@ -37,15 +37,15 @@ "jshint": "^2.8.0" }, "scripts": { - "preinstall": "npm install node-pre-gyp", - "install": "node-pre-gyp install --fallback-to-build", - "test": "jshint lib/*.js" + "preinstall": "npm install node-pre-gyp", + "install": "node-pre-gyp install --fallback-to-build", + "test": "jshint lib/*.js" }, "binary": { - "module_name": "binding", - "module_path": "./lib/binding/", - "host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/", - "package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz", - "remote_path": "{version}" + "module_name": "binding", + "module_path": "./lib/binding/", + "host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/", + "package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz", + "remote_path": "{version}" } } From addadd03c8861612338729ed8431e41316c7a29b Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Wed, 19 Dec 2018 16:57:57 +0100 Subject: [PATCH 09/23] npm: Prevent sporadic build issues Might be caused by parallel jobs? ``` > @abandonware/bluetooth-hci-socket@0.5.3-0 install /local/home/philippe/var/cache/url/git/ssh/github.com/tizenteam/node-bluetooth-hci-socket/src/node-bluetooth-hci-socket > node-pre-gyp install --fallback-to-build (...) Release/obj.target/binding/src/BluetoothHciSocket.o: file not recognized: File truncated collect2: error: ld returned 1 exit status (...) ``` Or ``` rm: cannot remove './Release/.deps/Release/obj.target/binding/src/BluetoothHciSocket.o.d.raw': No such file or directory (...) make: *** [Release/obj.target/binding/src/BluetoothHciSocket.o] Error 1 ``` Origin: https://github.com/abandonware/node-bluetooth-hci-socket/pull/4 Relate-to: https://github.com/noble/node-bluetooth-hci-socket/pull/91 Change-Id: I34726c8adffc7c39f585f42da1f7d776c5761a17 Signed-off-by: Philippe Coval --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07c825f..5d3a5c0 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dependencies": { "debug": "^2.2.0", "nan": "^2.10.0", - "node-pre-gyp": "0.6.x" + "node-pre-gyp": "^0.12.0" }, "optionalDependencies": { "usb": "^1.1.0" From 63eab350b49e5fce88436873e4c2cc1111158dc8 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Wed, 19 Dec 2018 22:41:28 +0100 Subject: [PATCH 10/23] npm update debug Change-Id: I5fbe3eb7463edc95bb44558d5874ff2123e7e46c Signed-off-by: Philippe Coval --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d3a5c0..fd4a233 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "win32" ], "dependencies": { - "debug": "^2.2.0", + "debug": "^4.1.0", "nan": "^2.10.0", "node-pre-gyp": "^0.12.0" }, From c3d2e39eb8dc643f26ee2dd2dfb543569f9a1dc5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 28 Aug 2019 12:46:33 +0300 Subject: [PATCH 11/23] Update usb dependency to version supporting Node 12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd4a233..a0ffd96 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "node-pre-gyp": "^0.12.0" }, "optionalDependencies": { - "usb": "^1.1.0" + "usb": "^1.6.0" }, "devDependencies": { "jshint": "^2.8.0" From 0c44954cc227de6438e37e4f12b4b52677d0304f Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 28 Aug 2019 12:50:33 +0300 Subject: [PATCH 12/23] Remove deprecated preinstall for node-pre-gyp --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a0ffd96..07ece32 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "jshint": "^2.8.0" }, "scripts": { - "preinstall": "npm install node-pre-gyp", "install": "node-pre-gyp install --fallback-to-build", "test": "jshint lib/*.js" }, From b44242e9bd0668b79ff31c954ee3eb0c94af560e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 28 Aug 2019 13:30:51 +0300 Subject: [PATCH 13/23] Fix things up for Node 12, nan 2.14.x --- package.json | 4 ++-- src/BluetoothHciSocket.cpp | 29 ++++++++++------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 07ece32..8b75c62 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ ], "dependencies": { "debug": "^4.1.0", - "nan": "^2.10.0", - "node-pre-gyp": "^0.12.0" + "nan": "^2.14.0", + "node-pre-gyp": "^0.13.0" }, "optionalDependencies": { "usb": "^1.6.0" diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 0cc7427..6c8df85 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -126,7 +126,7 @@ NAN_MODULE_INIT(BluetoothHciSocket::Init) { Nan::SetPrototypeMethod(tmpl, "stop", Stop); Nan::SetPrototypeMethod(tmpl, "write", Write); - target->Set(Nan::New("BluetoothHciSocket").ToLocalChecked(), tmpl->GetFunction()); + Nan::Set(target, Nan::New("BluetoothHciSocket").ToLocalChecked(), Nan::GetFunction(tmpl).ToLocalChecked()); } BluetoothHciSocket::BluetoothHciSocket() : @@ -264,16 +264,7 @@ void BluetoothHciSocket::write_(char* data, int length) { } void BluetoothHciSocket::emitErrnoError() { - Nan::HandleScope scope; - - Local globalObj = Nan::GetCurrentContext()->Global(); - Local errorConstructor = Local::Cast(globalObj->Get(Nan::New("Error").ToLocalChecked())); - - Local constructorArgs[1] = { - Nan::New(strerror(errno)).ToLocalChecked() - }; - - Local error = Nan::NewInstance(errorConstructor, 1, constructorArgs).ToLocalChecked(); + v8::Local error = Nan::ErrnoException(errno, NULL, strerror(errno)); Local argv[2] = { Nan::New("error").ToLocalChecked(), @@ -393,7 +384,7 @@ NAN_METHOD(BluetoothHciSocket::BindRaw) { if (info.Length() > 0) { Local arg0 = info[0]; if (arg0->IsInt32() || arg0->IsUint32()) { - devId = arg0->IntegerValue(); + devId = Nan::To(arg0).FromJust(); pDevId = &devId; } @@ -415,7 +406,7 @@ NAN_METHOD(BluetoothHciSocket::BindUser) { if (info.Length() > 0) { Local arg0 = info[0]; if (arg0->IsInt32() || arg0->IsUint32()) { - devId = arg0->IntegerValue(); + devId = Nan::To(arg0).FromJust(); pDevId = &devId; } @@ -468,12 +459,12 @@ NAN_METHOD(BluetoothHciSocket::GetDeviceList) { bool devUp = dr->dev_opt & (1 << HCI_UP); if (dr != NULL) { v8::Local obj = Nan::New(); - obj->Set(Nan::New("devId").ToLocalChecked(), Nan::New(devId)); - obj->Set(Nan::New("devUp").ToLocalChecked(), Nan::New(devUp)); - obj->Set(Nan::New("idVendor").ToLocalChecked(), Nan::Null()); - obj->Set(Nan::New("idProduct").ToLocalChecked(), Nan::Null()); - obj->Set(Nan::New("busNumber").ToLocalChecked(), Nan::Null()); - obj->Set(Nan::New("deviceAddress").ToLocalChecked(), Nan::Null()); + Nan::Set(obj, Nan::New("devId").ToLocalChecked(), Nan::New(devId)); + Nan::Set(obj, Nan::New("devUp").ToLocalChecked(), Nan::New(devUp)); + Nan::Set(obj, Nan::New("idVendor").ToLocalChecked(), Nan::Null()); + Nan::Set(obj, Nan::New("idProduct").ToLocalChecked(), Nan::Null()); + Nan::Set(obj, Nan::New("busNumber").ToLocalChecked(), Nan::Null()); + Nan::Set(obj, Nan::New("deviceAddress").ToLocalChecked(), Nan::Null()); Nan::Set(deviceList, di++, obj); } } From 5d3e40a34db5aeacbc69733d16c6afe0bdcbcfd7 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 28 Aug 2019 13:31:12 +0300 Subject: [PATCH 14/23] Fix jshint complaints about arrows; attempt importing code as part of test --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b75c62..c05a588 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "scripts": { "install": "node-pre-gyp install --fallback-to-build", - "test": "jshint lib/*.js" + "test": "jshint lib/*.js && node ." }, "binary": { "module_name": "binding", @@ -46,5 +46,8 @@ "host": "https://github.com/sandeepmistry/node-bluetooth-hci-socket/releases/download/", "package_name": "{module_name}-{version}-{node_abi}-{platform}-{arch}.tar.gz", "remote_path": "{version}" + }, + "jshintConfig": { + "esversion": 6 } } From 4f8a0a9fae8e02cfd2fc11e51f1df8c40c3149f5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 28 Aug 2019 13:32:54 +0300 Subject: [PATCH 15/23] Test on Node 12 too --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index a7c1ce9..486d98a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - NODE_VERSION="6" - NODE_VERSION="8" - NODE_VERSION="10" + - NODE_VERSION="12" before_install: - sudo apt-get install build-essential libudev-dev -y diff --git a/appveyor.yml b/appveyor.yml index 5f2e9ce..4529889 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,6 +11,7 @@ environment: - node_version: '6' - node_version: '8' - node_version: '10' + - node_version: '12' install: - ps: Install-Product node $env:node_version $env:platform From 0514a794e5f2a043a8bbdc278e470f3b2d5a6884 Mon Sep 17 00:00:00 2001 From: Quy Nguyen Date: Tue, 19 Nov 2019 18:17:28 +0700 Subject: [PATCH 16/23] Add one more support device --- README.md | 1 + lib/usb.js | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 179bcd8..ba9d95a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Note: | BCM920702 Bluetooth 4.0 | 0x0a5c | 0x21e8 | | BCM20702A0 Bluetooth 4.0 | 0x19ff | 0x0239 | | BCM20702A0 Bluetooth 4.0 | 0x0489 | 0xe07a | +| BCM20702A0 Bluetooth 4.0 | 0x413c | 0x8143 | | CSR8510 A10 | 0x0a12 | 0x0001 | | Asus BT-400 | 0x0b05 | 0x17cb | | Intel Wireless Bluetooth 6235 | 0x8087 | 0x07da | diff --git a/lib/usb.js b/lib/usb.js index 24cc86f..c7d2193 100644 --- a/lib/usb.js +++ b/lib/usb.js @@ -15,6 +15,7 @@ var VENDOR_DEVICE_LIST = [ {vid: 0x0CF3, pid: 0xE300 }, // Qualcomm Atheros QCA61x4 {vid: 0x0a5c, pid: 0x21e8 }, // Broadcom BCM20702A0 {vid: 0x19ff, pid: 0x0239 }, // Broadcom BCM20702A0 + {vid: 0x413c, pid: 0x8143 }, // Broadcom BCM20702A0 {vid: 0x0a12, pid: 0x0001 }, // CSR {vid: 0x0b05, pid: 0x17cb }, // ASUS BT400 {vid: 0x8087, pid: 0x07da }, // Intel 6235 From b61988f3d6aee53df629214f53fc9c70f437de75 Mon Sep 17 00:00:00 2001 From: Michael Stegeman Date: Thu, 16 Jan 2020 23:29:42 -0900 Subject: [PATCH 17/23] Switch from Travis CI to GitHub actions. --- .github/workflows/nodepackage.yml | 35 ++++++++++++++++++++++++++++ .travis.yml | 38 ------------------------------- 2 files changed, 35 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/nodepackage.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/nodepackage.yml b/.github/workflows/nodepackage.yml new file mode 100644 index 0000000..949842a --- /dev/null +++ b/.github/workflows/nodepackage.yml @@ -0,0 +1,35 @@ +name: Node.js package + +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node_version: [ + 6, + 8, + 10, + 12, + ] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node_version }} + - name: Install dependencies + run: | + sudo apt -qq update + sudo apt install -y libudev-dev + - name: Test build + run: | + export PATH=./node_modules/.bin:${PATH} + npm install --build-from-source --node-gyp=$(which pangyp) + ./node_modules/.bin/node-pre-gyp package diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 486d98a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -branches: - only: - - master - - node-pre-gyp - - /^[0-9]/ - -language: cpp - -dist: trusty - -env: - matrix: - - NODE_VERSION="4" - - NODE_VERSION="5" - - NODE_VERSION="6" - - NODE_VERSION="8" - - NODE_VERSION="10" - - NODE_VERSION="12" - -before_install: - - sudo apt-get install build-essential libudev-dev -y - - export NVM_DIR=~/.nvm - - . $HOME/.nvm/nvm.sh - - nvm install $NODE_VERSION - - node --version - - npm --version - -install: -- export PATH=./node_modules/.bin/:$PATH -- npm install -g node-pre-gyp-github - -script: -- npm install --build-from-source --node-gyp=$(which pangyp) -- "./node_modules/.bin/node-pre-gyp package" -- echo $TRAVIS_TAG -- > - ([[ "$TRAVIS_TAG" =~ ^[0-9] ]] && - node-pre-gyp-github publish) || true From 70332b892e47bfcca6d4453e32636525435fb772 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:06:40 +0200 Subject: [PATCH 18/23] Add syscall description to emitErrnoError --- src/BluetoothHciSocket.cpp | 8 ++++---- src/BluetoothHciSocket.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 6c8df85..0e0c867 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -227,7 +227,7 @@ bool BluetoothHciSocket::isDevUp() { void BluetoothHciSocket::setFilter(char* data, int length) { if (setsockopt(this->_socket, SOL_HCI, HCI_FILTER, data, length) < 0) { - this->emitErrnoError(); + this->emitErrnoError("setsockopt"); } } @@ -259,12 +259,12 @@ void BluetoothHciSocket::stop() { void BluetoothHciSocket::write_(char* data, int length) { if (write(this->_socket, data, length) < 0) { - this->emitErrnoError(); + this->emitErrnoError("write"); } } -void BluetoothHciSocket::emitErrnoError() { - v8::Local error = Nan::ErrnoException(errno, NULL, strerror(errno)); +void BluetoothHciSocket::emitErrnoError(const char *syscall) { + v8::Local error = Nan::ErrnoException(errno, syscall, strerror(errno)); Local argv[2] = { Nan::New("error").ToLocalChecked(), diff --git a/src/BluetoothHciSocket.h b/src/BluetoothHciSocket.h index 97e4244..3c47389 100644 --- a/src/BluetoothHciSocket.h +++ b/src/BluetoothHciSocket.h @@ -39,7 +39,7 @@ class BluetoothHciSocket : public node::ObjectWrap { void poll(); - void emitErrnoError(); + void emitErrnoError(const char *syscall); int devIdFor(int* devId, bool isUp); void kernelDisconnectWorkArounds(int length, char* data); From 0eef541d8b66e5772e679b57fa49b20084bc0df6 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:24:01 +0200 Subject: [PATCH 19/23] Guard against possibly failing syscalls Refs https://github.com/noble/node-bluetooth-hci-socket/issues/115 --- src/BluetoothHciSocket.cpp | 59 +++++++++++++++++++++++++++++++------- src/BluetoothHciSocket.h | 2 +- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 0e0c867..02a7c5b 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -130,11 +130,26 @@ NAN_MODULE_INIT(BluetoothHciSocket::Init) { } BluetoothHciSocket::BluetoothHciSocket() : - node::ObjectWrap() { - - this->_socket = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI); + node::ObjectWrap(), + _mode(0), + _socket(-1), + _devId(0), + _pollHandle(), + _address(), + _addressType(0) + { + + int fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI); + if (fd == -1) { + Nan::ThrowError(Nan::ErrnoException(errno, "socket")); + return; + } + this->_socket = fd; - uv_poll_init(uv_default_loop(), &this->_pollHandle, this->_socket); + if (uv_poll_init(uv_default_loop(), &this->_pollHandle, this->_socket) < 0) { + Nan::ThrowError("uv_poll_init failed"); + return; + } this->_pollHandle.data = this; } @@ -146,7 +161,9 @@ BluetoothHciSocket::~BluetoothHciSocket() { } void BluetoothHciSocket::start() { - uv_poll_start(&this->_pollHandle, UV_READABLE, BluetoothHciSocket::PollCallback); + if (uv_poll_start(&this->_pollHandle, UV_READABLE, BluetoothHciSocket::PollCallback) < 0) { + Nan::ThrowError("uv_poll_start failed"); + } } int BluetoothHciSocket::bindRaw(int* devId) { @@ -161,7 +178,10 @@ int BluetoothHciSocket::bindRaw(int* devId) { this->_devId = a.hci_dev; this->_mode = HCI_CHANNEL_RAW; - bind(this->_socket, (struct sockaddr *) &a, sizeof(a)); + if (bind(this->_socket, (struct sockaddr *) &a, sizeof(a)) < 0) { + Nan::ThrowError(Nan::ErrnoException(errno, "bind")); + return -1; + } // get the local address and address type memset(&di, 0x00, sizeof(di)); @@ -193,7 +213,10 @@ int BluetoothHciSocket::bindUser(int* devId) { this->_devId = a.hci_dev; this->_mode = HCI_CHANNEL_USER; - bind(this->_socket, (struct sockaddr *) &a, sizeof(a)); + if (bind(this->_socket, (struct sockaddr *) &a, sizeof(a)) < 0) { + Nan::ThrowError(Nan::ErrnoException(errno, "bind")); + return -1; + } return this->_devId; } @@ -208,7 +231,10 @@ void BluetoothHciSocket::bindControl() { this->_mode = HCI_CHANNEL_CONTROL; - bind(this->_socket, (struct sockaddr *) &a, sizeof(a)); + if (bind(this->_socket, (struct sockaddr *) &a, sizeof(a)) < 0) { + Nan::ThrowError(Nan::ErrnoException(errno, "bind")); + return; + } } bool BluetoothHciSocket::isDevUp() { @@ -241,6 +267,7 @@ void BluetoothHciSocket::poll() { if (length > 0) { if (this->_mode == HCI_CHANNEL_RAW) { + // TODO: This does not check for the retval of this function – should it? this->kernelDisconnectWorkArounds(length, data); } @@ -308,7 +335,7 @@ int BluetoothHciSocket::devIdFor(int* pDevId, bool isUp) { return devId; } -void BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { +int BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { // HCI Event - LE Meta Event - LE Connection Complete => manually create L2CAP socket to force kernel to book keep // HCI Event - Disconn Complete =======================> close socket from above @@ -327,13 +354,19 @@ void BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { #endif l2socket = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); + if(l2socket == -1) { + return -1; + } memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; l2a.l2_cid = l2cid; memcpy(&l2a.l2_bdaddr, _address, sizeof(l2a.l2_bdaddr)); l2a.l2_bdaddr_type = _addressType; - bind(l2socket, (struct sockaddr*)&l2a, sizeof(l2a)); + if (bind(l2socket, (struct sockaddr*)&l2a, sizeof(l2a)) < 0) { + close(l2socket); + return -2; + } memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; @@ -341,7 +374,10 @@ void BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { l2a.l2_cid = l2cid; l2a.l2_bdaddr_type = data[8] + 1; // BDADDR_LE_PUBLIC (0x01), BDADDR_LE_RANDOM (0x02) - connect(l2socket, (struct sockaddr *)&l2a, sizeof(l2a)); + if (connect(l2socket, (struct sockaddr *)&l2a, sizeof(l2a)) < -1) { + close(l2socket); + return -3; + } this->_l2sockets[handle] = l2socket; } else if (length == 7 && data[0] == 0x04 && data[1] == 0x05 && data[2] == 0x04 && data[3] == 0x00) { @@ -352,6 +388,7 @@ void BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { this->_l2sockets.erase(handle); } } + return 0; } NAN_METHOD(BluetoothHciSocket::New) { diff --git a/src/BluetoothHciSocket.h b/src/BluetoothHciSocket.h index 3c47389..fb89242 100644 --- a/src/BluetoothHciSocket.h +++ b/src/BluetoothHciSocket.h @@ -41,7 +41,7 @@ class BluetoothHciSocket : public node::ObjectWrap { void emitErrnoError(const char *syscall); int devIdFor(int* devId, bool isUp); - void kernelDisconnectWorkArounds(int length, char* data); + int kernelDisconnectWorkArounds(int length, char* data); static void PollCloseCallback(uv_poll_t* handle); static void PollCallback(uv_poll_t* handle, int status, int events); From ace38fc4876ef3c66ad38e803c80125670c6571d Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:24:49 +0200 Subject: [PATCH 20/23] Heed clang-tidy --- src/BluetoothHciSocket.cpp | 25 +++++++++++++------------ src/BluetoothHciSocket.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 02a7c5b..e5b50a6 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -167,8 +167,8 @@ void BluetoothHciSocket::start() { } int BluetoothHciSocket::bindRaw(int* devId) { - struct sockaddr_hci a; - struct hci_dev_info di; + struct sockaddr_hci a = {}; + struct hci_dev_info di = {}; memset(&a, 0, sizeof(a)); a.hci_family = AF_BLUETOOTH; @@ -203,7 +203,7 @@ int BluetoothHciSocket::bindRaw(int* devId) { } int BluetoothHciSocket::bindUser(int* devId) { - struct sockaddr_hci a; + struct sockaddr_hci a = {}; memset(&a, 0, sizeof(a)); a.hci_family = AF_BLUETOOTH; @@ -222,7 +222,7 @@ int BluetoothHciSocket::bindUser(int* devId) { } void BluetoothHciSocket::bindControl() { - struct sockaddr_hci a; + struct sockaddr_hci a = {}; memset(&a, 0, sizeof(a)); a.hci_family = AF_BLUETOOTH; @@ -238,7 +238,7 @@ void BluetoothHciSocket::bindControl() { } bool BluetoothHciSocket::isDevUp() { - struct hci_dev_info di; + struct hci_dev_info di = {}; bool isUp = false; memset(&di, 0x00, sizeof(di)); @@ -301,10 +301,10 @@ void BluetoothHciSocket::emitErrnoError(const char *syscall) { Nan::MakeCallback(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); } -int BluetoothHciSocket::devIdFor(int* pDevId, bool isUp) { +int BluetoothHciSocket::devIdFor(const int* pDevId, bool isUp) { int devId = 0; // default - if (pDevId == NULL) { + if (pDevId == nullptr) { struct hci_dev_list_req *dl; struct hci_dev_req *dr; @@ -316,7 +316,7 @@ int BluetoothHciSocket::devIdFor(int* pDevId, bool isUp) { if (ioctl(this->_socket, HCIGETDEVLIST, dl) > -1) { for (int i = 0; i < dl->dev_num; i++, dr++) { bool devUp = dr->dev_opt & (1 << HCI_UP); - bool match = isUp ? devUp : !devUp; + bool match = (isUp == devUp); if (match) { // choose the first device that is match @@ -341,7 +341,7 @@ int BluetoothHciSocket::kernelDisconnectWorkArounds(int length, char* data) { if (length == 22 && data[0] == 0x04 && data[1] == 0x3e && data[2] == 0x13 && data[3] == 0x01 && data[4] == 0x00) { int l2socket; - struct sockaddr_l2 l2a; + struct sockaddr_l2 l2a = {}; unsigned short l2cid; unsigned short handle = *((unsigned short*)(&data[5])); @@ -416,7 +416,7 @@ NAN_METHOD(BluetoothHciSocket::BindRaw) { BluetoothHciSocket* p = node::ObjectWrap::Unwrap(info.This()); int devId = 0; - int* pDevId = NULL; + int* pDevId = nullptr; if (info.Length() > 0) { Local arg0 = info[0]; @@ -438,7 +438,7 @@ NAN_METHOD(BluetoothHciSocket::BindUser) { BluetoothHciSocket* p = node::ObjectWrap::Unwrap(info.This()); int devId = 0; - int* pDevId = NULL; + int* pDevId = nullptr; if (info.Length() > 0) { Local arg0 = info[0]; @@ -494,7 +494,8 @@ NAN_METHOD(BluetoothHciSocket::GetDeviceList) { for (int i = 0; i < dl->dev_num; i++, dr++) { uint16_t devId = dr->dev_id; bool devUp = dr->dev_opt & (1 << HCI_UP); - if (dr != NULL) { + // TODO: smells like there's a bug here (but dr isn't read so...) + if (dr != nullptr) { v8::Local obj = Nan::New(); Nan::Set(obj, Nan::New("devId").ToLocalChecked(), Nan::New(devId)); Nan::Set(obj, Nan::New("devUp").ToLocalChecked(), Nan::New(devUp)); diff --git a/src/BluetoothHciSocket.h b/src/BluetoothHciSocket.h index fb89242..34e6b81 100644 --- a/src/BluetoothHciSocket.h +++ b/src/BluetoothHciSocket.h @@ -40,7 +40,7 @@ class BluetoothHciSocket : public node::ObjectWrap { void poll(); void emitErrnoError(const char *syscall); - int devIdFor(int* devId, bool isUp); + int devIdFor(const int* devId, bool isUp); int kernelDisconnectWorkArounds(int length, char* data); static void PollCloseCallback(uv_poll_t* handle); From b0d4ac4e736bfb3f4273bd5e7d3037181429a603 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:33:06 +0200 Subject: [PATCH 21/23] Naively replace MakeCallback with its inner implementation --- src/BluetoothHciSocket.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index e5b50a6..0cd3878 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -276,7 +276,13 @@ void BluetoothHciSocket::poll() { Nan::CopyBuffer(data, length).ToLocalChecked() }; - Nan::MakeCallback(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); + Nan::AsyncResource res("BluetoothHciSocket::poll"); + res.runInAsyncScope( + Nan::New(this->This), + Nan::New("emit").ToLocalChecked(), + 2, + argv + ).FromMaybe(v8::Local()); } } @@ -297,8 +303,13 @@ void BluetoothHciSocket::emitErrnoError(const char *syscall) { Nan::New("error").ToLocalChecked(), error }; - - Nan::MakeCallback(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); + Nan::AsyncResource res("BluetoothHciSocket::emitErrnoError"); + res.runInAsyncScope( + Nan::New(this->This), + Nan::New("emit").ToLocalChecked(), + 2, + argv + ).FromMaybe(v8::Local()); } int BluetoothHciSocket::devIdFor(const int* pDevId, bool isUp) { From 6bb57dacc417eb4096cf80c45fe2c37b220f7269 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:43:32 +0200 Subject: [PATCH 22/23] Defer "unsupported platform" to instantiation time --- index.js | 2 +- lib/unsupported.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 lib/unsupported.js diff --git a/index.js b/index.js index 58db67e..8b8ccf0 100644 --- a/index.js +++ b/index.js @@ -7,5 +7,5 @@ if (process.env.BLUETOOTH_HCI_SOCKET_FORCE_USB || platform === 'win32' || platfo } else if (platform === 'linux' || platform === 'android') { module.exports = require('./lib/native'); } else { - throw new Error('Unsupported platform'); + module.exports = require('./lib/unsupported'); } diff --git a/lib/unsupported.js b/lib/unsupported.js new file mode 100644 index 0000000..11dc682 --- /dev/null +++ b/lib/unsupported.js @@ -0,0 +1,5 @@ +function UnsupportedPlatformBluetoothHciSocket() { + throw new Error('Unsupported platform'); +} + +module.exports = UnsupportedPlatformBluetoothHciSocket; \ No newline at end of file From cb5afc4d3798734ed4457b3c786acc9a1110bb58 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Jan 2020 17:36:18 +0200 Subject: [PATCH 23/23] Run test in Github actions --- .github/workflows/nodepackage.yml | 4 +++- package.json | 2 +- test.js | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test.js diff --git a/.github/workflows/nodepackage.yml b/.github/workflows/nodepackage.yml index 949842a..1176a5e 100644 --- a/.github/workflows/nodepackage.yml +++ b/.github/workflows/nodepackage.yml @@ -28,8 +28,10 @@ jobs: run: | sudo apt -qq update sudo apt install -y libudev-dev - - name: Test build + - name: Build run: | export PATH=./node_modules/.bin:${PATH} npm install --build-from-source --node-gyp=$(which pangyp) ./node_modules/.bin/node-pre-gyp package + - name: Test + run: npm test \ No newline at end of file diff --git a/package.json b/package.json index c05a588..dbad5eb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "scripts": { "install": "node-pre-gyp install --fallback-to-build", - "test": "jshint lib/*.js && node ." + "test": "jshint lib/*.js && node test.js" }, "binary": { "module_name": "binding", diff --git a/test.js b/test.js new file mode 100644 index 0000000..e599d55 --- /dev/null +++ b/test.js @@ -0,0 +1,8 @@ +const BluetoothHCISocket = require('.'); + +// This test basically just makes sure we don't segfault at initialization time. +try { + console.log(new BluetoothHCISocket()); +} catch(err) { + console.error(err); +} \ No newline at end of file