@stoprocent/noble 1.9.2-16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +11 -0
- package/.eslintrc.js +25 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/fediverse-action.yml +16 -0
- package/.github/workflows/nodepackage.yml +77 -0
- package/.github/workflows/npm-publish.yml +26 -0
- package/.github/workflows/prebuild.yml +65 -0
- package/.nycrc.json +4 -0
- package/CHANGELOG.md +119 -0
- package/LICENSE +20 -0
- package/MAINTAINERS.md +1 -0
- package/README.md +833 -0
- package/assets/noble-logo.png +0 -0
- package/assets/noble-logo.svg +13 -0
- package/binding.gyp +19 -0
- package/codecov.yml +5 -0
- package/examples/advertisement-discovery.js +65 -0
- package/examples/cache-gatt-discovery.js +198 -0
- package/examples/cache-gatt-reconnect.js +164 -0
- package/examples/echo.js +104 -0
- package/examples/enter-exit.js +78 -0
- package/examples/peripheral-explorer-async.js +133 -0
- package/examples/peripheral-explorer.js +225 -0
- package/examples/pizza/README.md +15 -0
- package/examples/pizza/central.js +194 -0
- package/examples/pizza/pizza.js +60 -0
- package/index.d.ts +203 -0
- package/index.js +6 -0
- package/lib/characteristic.js +161 -0
- package/lib/characteristics.json +449 -0
- package/lib/descriptor.js +72 -0
- package/lib/descriptors.json +47 -0
- package/lib/distributed/bindings.js +326 -0
- package/lib/hci-socket/acl-stream.js +60 -0
- package/lib/hci-socket/bindings.js +788 -0
- package/lib/hci-socket/crypto.js +74 -0
- package/lib/hci-socket/gap.js +432 -0
- package/lib/hci-socket/gatt.js +809 -0
- package/lib/hci-socket/hci-status.json +71 -0
- package/lib/hci-socket/hci.js +1264 -0
- package/lib/hci-socket/signaling.js +76 -0
- package/lib/hci-socket/smp.js +140 -0
- package/lib/hci-uart/bindings.js +569 -0
- package/lib/hci-uart/hci-serial-parser.js +70 -0
- package/lib/hci-uart/hci.js +1336 -0
- package/lib/mac/binding.gyp +26 -0
- package/lib/mac/bindings.js +11 -0
- package/lib/mac/src/ble_manager.h +41 -0
- package/lib/mac/src/ble_manager.mm +435 -0
- package/lib/mac/src/callbacks.cc +222 -0
- package/lib/mac/src/callbacks.h +84 -0
- package/lib/mac/src/napi_objc.h +12 -0
- package/lib/mac/src/napi_objc.mm +50 -0
- package/lib/mac/src/noble_mac.h +34 -0
- package/lib/mac/src/noble_mac.mm +264 -0
- package/lib/mac/src/objc_cpp.h +26 -0
- package/lib/mac/src/objc_cpp.mm +126 -0
- package/lib/mac/src/peripheral.h +23 -0
- package/lib/manufacture.js +48 -0
- package/lib/noble.js +593 -0
- package/lib/peripheral.js +219 -0
- package/lib/resolve-bindings-web.js +9 -0
- package/lib/resolve-bindings.js +44 -0
- package/lib/service.js +72 -0
- package/lib/services.json +92 -0
- package/lib/webbluetooth/bindings.js +368 -0
- package/lib/websocket/bindings.js +321 -0
- package/lib/win/binding.gyp +23 -0
- package/lib/win/bindings.js +11 -0
- package/lib/win/src/ble_manager.cc +802 -0
- package/lib/win/src/ble_manager.h +77 -0
- package/lib/win/src/callbacks.cc +274 -0
- package/lib/win/src/callbacks.h +33 -0
- package/lib/win/src/napi_winrt.cc +76 -0
- package/lib/win/src/napi_winrt.h +12 -0
- package/lib/win/src/noble_winrt.cc +308 -0
- package/lib/win/src/noble_winrt.h +34 -0
- package/lib/win/src/notify_map.cc +62 -0
- package/lib/win/src/notify_map.h +50 -0
- package/lib/win/src/peripheral.h +23 -0
- package/lib/win/src/peripheral_winrt.cc +296 -0
- package/lib/win/src/peripheral_winrt.h +82 -0
- package/lib/win/src/radio_watcher.cc +125 -0
- package/lib/win/src/radio_watcher.h +61 -0
- package/lib/win/src/winrt_cpp.cc +82 -0
- package/lib/win/src/winrt_cpp.h +11 -0
- package/lib/win/src/winrt_guid.cc +12 -0
- package/lib/win/src/winrt_guid.h +13 -0
- package/misc/nrf52840dk.hex +6921 -0
- package/misc/prj.conf +43 -0
- package/package.json +96 -0
- package/test/lib/characteristic.test.js +791 -0
- package/test/lib/descriptor.test.js +249 -0
- package/test/lib/distributed/bindings.test.js +918 -0
- package/test/lib/hci-socket/acl-stream.test.js +188 -0
- package/test/lib/hci-socket/bindings.test.js +1756 -0
- package/test/lib/hci-socket/crypto.test.js +55 -0
- package/test/lib/hci-socket/gap.test.js +1089 -0
- package/test/lib/hci-socket/gatt.test.js +2392 -0
- package/test/lib/hci-socket/hci.test.js +1891 -0
- package/test/lib/hci-socket/signaling.test.js +94 -0
- package/test/lib/hci-socket/smp.test.js +268 -0
- package/test/lib/manufacture.test.js +77 -0
- package/test/lib/peripheral.test.js +623 -0
- package/test/lib/resolve-bindings.test.js +102 -0
- package/test/lib/service.test.js +195 -0
- package/test/lib/webbluetooth/bindings.test.js +190 -0
- package/test/lib/websocket/bindings.test.js +456 -0
- package/test/noble.test.js +1565 -0
- package/test.js +131 -0
- package/with-bindings.js +5 -0
- package/ws-slave.js +404 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const should = require('should');
|
|
2
|
+
const sinon = require('sinon');
|
|
3
|
+
const proxyquire = require('proxyquire').noCallThru();
|
|
4
|
+
|
|
5
|
+
const fakeOs = {};
|
|
6
|
+
const { assert } = sinon;
|
|
7
|
+
const Signaling = proxyquire('../../../lib/hci-socket/signaling', { os: fakeOs });
|
|
8
|
+
|
|
9
|
+
describe('hci-socket signaling', () => {
|
|
10
|
+
let signaling;
|
|
11
|
+
|
|
12
|
+
const handle = 'handle';
|
|
13
|
+
const aclStream = {
|
|
14
|
+
on: sinon.spy(),
|
|
15
|
+
removeListener: sinon.spy(),
|
|
16
|
+
write: sinon.spy()
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
signaling = new Signaling(handle, aclStream);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
sinon.reset();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('construct', () => {
|
|
28
|
+
assert.callCount(aclStream.on, 2);
|
|
29
|
+
assert.calledWithMatch(aclStream.on, 'data', sinon.match.func);
|
|
30
|
+
assert.calledWithMatch(aclStream.on, 'end', sinon.match.func);
|
|
31
|
+
|
|
32
|
+
should(signaling._handle).equal(handle);
|
|
33
|
+
should(signaling._aclStream).equal(aclStream);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('onAclStreamData', () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
signaling.processConnectionParameterUpdateRequest = sinon.spy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
sinon.reset();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should do nothing as not SIGNALING_CID', () => {
|
|
46
|
+
signaling.onAclStreamData(0, 'data');
|
|
47
|
+
assert.notCalled(signaling.processConnectionParameterUpdateRequest);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should do nothing as not CONNECTION_PARAMETER_UPDATE_REQUEST', () => {
|
|
51
|
+
const data = Buffer.from([0, 1, 2, 3, 4]);
|
|
52
|
+
signaling.onAclStreamData(5, data);
|
|
53
|
+
assert.notCalled(signaling.processConnectionParameterUpdateRequest);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should do nothing processConnectionParameterUpdateRequest', () => {
|
|
57
|
+
const data = Buffer.from([18, 1, 2, 3, 4, 5]);
|
|
58
|
+
signaling.onAclStreamData(5, data);
|
|
59
|
+
assert.calledOnceWithExactly(signaling.processConnectionParameterUpdateRequest, 1, Buffer.from([4, 5]));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('onAclStreamEnd', () => {
|
|
64
|
+
signaling.onAclStreamEnd();
|
|
65
|
+
|
|
66
|
+
assert.callCount(aclStream.removeListener, 2);
|
|
67
|
+
assert.calledWithMatch(aclStream.removeListener, 'data', sinon.match.func);
|
|
68
|
+
assert.calledWithMatch(aclStream.removeListener, 'end', sinon.match.func);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('processConnectionParameterUpdateRequest', () => {
|
|
72
|
+
it('should not write on linux', () => {
|
|
73
|
+
fakeOs.platform = sinon.fake.returns('linux');
|
|
74
|
+
const callback = sinon.spy();
|
|
75
|
+
|
|
76
|
+
signaling.on('connectionParameterUpdateRequest', callback);
|
|
77
|
+
signaling.processConnectionParameterUpdateRequest(1, Buffer.from([1, 0, 2, 0, 3, 0, 4, 0]));
|
|
78
|
+
|
|
79
|
+
assert.notCalled(callback);
|
|
80
|
+
assert.notCalled(aclStream.write);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should write on !linux', () => {
|
|
84
|
+
fakeOs.platform = sinon.fake.returns('!linux');
|
|
85
|
+
const callback = sinon.spy();
|
|
86
|
+
|
|
87
|
+
signaling.on('connectionParameterUpdateRequest', callback);
|
|
88
|
+
signaling.processConnectionParameterUpdateRequest(1, Buffer.from([1, 0, 2, 0, 3, 0, 4, 0]));
|
|
89
|
+
|
|
90
|
+
assert.calledOnceWithExactly(callback, handle, 1.25, 2.5, 3, 40);
|
|
91
|
+
assert.calledOnceWithExactly(aclStream.write, 5, Buffer.from([0x13, 0x01, 0x02, 0x00, 0x00, 0x00]));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
const should = require('should');
|
|
2
|
+
const sinon = require('sinon');
|
|
3
|
+
const proxyquire = require('proxyquire').noCallThru();
|
|
4
|
+
|
|
5
|
+
const crypto = {};
|
|
6
|
+
const { assert } = sinon;
|
|
7
|
+
const Smp = proxyquire('../../../lib/hci-socket/smp', { './crypto': crypto });
|
|
8
|
+
|
|
9
|
+
describe('hci-socket smp', () => {
|
|
10
|
+
let smp;
|
|
11
|
+
|
|
12
|
+
const aclStream = {};
|
|
13
|
+
const localAddressType = 'public';
|
|
14
|
+
const localAddress = 'aa:bb:cc:dd:ee:ff';
|
|
15
|
+
const remoteAddressType = 'random';
|
|
16
|
+
const remoteAddress = '00:11:22:33:44:55';
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
aclStream.on = sinon.spy();
|
|
20
|
+
aclStream.removeListener = sinon.spy();
|
|
21
|
+
aclStream.write = sinon.spy();
|
|
22
|
+
|
|
23
|
+
smp = new Smp(aclStream, localAddressType, localAddress, remoteAddressType, remoteAddress);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
sinon.reset();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('construct 1', () => {
|
|
31
|
+
assert.callCount(aclStream.on, 2);
|
|
32
|
+
assert.calledWithMatch(aclStream.on, 'data', sinon.match.func);
|
|
33
|
+
assert.calledWithMatch(aclStream.on, 'end', sinon.match.func);
|
|
34
|
+
|
|
35
|
+
should(smp._iat).deepEqual(Buffer.from([0x00]));
|
|
36
|
+
should(smp._ia).deepEqual(Buffer.from([0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa]));
|
|
37
|
+
should(smp._rat).deepEqual(Buffer.from([0x01]));
|
|
38
|
+
should(smp._ra).deepEqual(Buffer.from([0x55, 0x44, 0x33, 0x22, 0x11, 0x00]));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('construct 2', () => {
|
|
42
|
+
sinon.reset(aclStream);
|
|
43
|
+
const smp = new Smp(aclStream, remoteAddressType, remoteAddress, localAddressType, localAddress);
|
|
44
|
+
|
|
45
|
+
assert.callCount(aclStream.on, 2);
|
|
46
|
+
assert.calledWithMatch(aclStream.on, 'data', sinon.match.func);
|
|
47
|
+
assert.calledWithMatch(aclStream.on, 'end', sinon.match.func);
|
|
48
|
+
|
|
49
|
+
should(smp._iat).deepEqual(Buffer.from([0x01]));
|
|
50
|
+
should(smp._ia).deepEqual(Buffer.from([0x55, 0x44, 0x33, 0x22, 0x11, 0x00]));
|
|
51
|
+
should(smp._rat).deepEqual(Buffer.from([0x00]));
|
|
52
|
+
should(smp._ra).deepEqual(Buffer.from([0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa]));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should write sendPairingRequest', () => {
|
|
56
|
+
smp.write = sinon.spy();
|
|
57
|
+
|
|
58
|
+
smp.sendPairingRequest();
|
|
59
|
+
|
|
60
|
+
assert.calledOnceWithExactly(smp.write, Buffer.from([0x01, 0x03, 0x00, 0x01, 0x10, 0x00, 0x01]));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('onAclStreamData', () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
smp.handlePairingResponse = sinon.spy();
|
|
66
|
+
smp.handlePairingConfirm = sinon.spy();
|
|
67
|
+
smp.handlePairingRandom = sinon.spy();
|
|
68
|
+
smp.handlePairingFailed = sinon.spy();
|
|
69
|
+
smp.handleEncryptInfo = sinon.spy();
|
|
70
|
+
smp.handleMasterIdent = sinon.spy();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should do nothing with !SMP_CID', () => {
|
|
74
|
+
smp.onAclStreamData(0);
|
|
75
|
+
|
|
76
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
77
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
78
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
79
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
80
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
81
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handlePairingResponse', () => {
|
|
85
|
+
const data = Buffer.from([0x02, 0x33, 0x44]);
|
|
86
|
+
smp.onAclStreamData(6, data);
|
|
87
|
+
|
|
88
|
+
assert.calledOnceWithExactly(smp.handlePairingResponse, data);
|
|
89
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
90
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
91
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
92
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
93
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should handlePairingConfirm', () => {
|
|
97
|
+
const data = Buffer.from([0x03, 0x33, 0x44]);
|
|
98
|
+
smp.onAclStreamData(6, data);
|
|
99
|
+
|
|
100
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
101
|
+
assert.calledOnceWithExactly(smp.handlePairingConfirm, data);
|
|
102
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
103
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
104
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
105
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handlePairingRandom', () => {
|
|
109
|
+
const data = Buffer.from([0x04, 0x33, 0x44]);
|
|
110
|
+
smp.onAclStreamData(6, data);
|
|
111
|
+
|
|
112
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
113
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
114
|
+
assert.calledOnceWithExactly(smp.handlePairingRandom, data);
|
|
115
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
116
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
117
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handlePairingFailed', () => {
|
|
121
|
+
const data = Buffer.from([0x05, 0x33, 0x44]);
|
|
122
|
+
smp.onAclStreamData(6, data);
|
|
123
|
+
|
|
124
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
125
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
126
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
127
|
+
assert.calledOnceWithExactly(smp.handlePairingFailed, data);
|
|
128
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
129
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should handleEncryptInfo', () => {
|
|
133
|
+
const data = Buffer.from([0x06, 0x33, 0x44]);
|
|
134
|
+
smp.onAclStreamData(6, data);
|
|
135
|
+
|
|
136
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
137
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
138
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
139
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
140
|
+
assert.calledOnceWithExactly(smp.handleEncryptInfo, data);
|
|
141
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should handleMasterIdent', () => {
|
|
145
|
+
const data = Buffer.from([0x07, 0x33, 0x44]);
|
|
146
|
+
smp.onAclStreamData(6, data);
|
|
147
|
+
|
|
148
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
149
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
150
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
151
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
152
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
153
|
+
assert.calledOnceWithExactly(smp.handleMasterIdent, data);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should do nothing on bad code', () => {
|
|
157
|
+
const data = Buffer.from([0x08, 0x33, 0x44]);
|
|
158
|
+
smp.onAclStreamData(6, data);
|
|
159
|
+
|
|
160
|
+
assert.notCalled(smp.handlePairingResponse);
|
|
161
|
+
assert.notCalled(smp.handlePairingConfirm);
|
|
162
|
+
assert.notCalled(smp.handlePairingRandom);
|
|
163
|
+
assert.notCalled(smp.handlePairingFailed);
|
|
164
|
+
assert.notCalled(smp.handleEncryptInfo);
|
|
165
|
+
assert.notCalled(smp.handleMasterIdent);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('onAclStreamEnd', () => {
|
|
170
|
+
const callback = sinon.spy();
|
|
171
|
+
smp.on('end', callback);
|
|
172
|
+
smp.onAclStreamEnd();
|
|
173
|
+
|
|
174
|
+
assert.callCount(aclStream.removeListener, 2);
|
|
175
|
+
assert.calledWithMatch(aclStream.removeListener, 'data', sinon.match.func);
|
|
176
|
+
assert.calledWithMatch(aclStream.removeListener, 'end', sinon.match.func);
|
|
177
|
+
assert.calledOnceWithExactly(callback);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('handlePairingResponse', () => {
|
|
181
|
+
smp.write = sinon.spy();
|
|
182
|
+
crypto.r = sinon.spy();
|
|
183
|
+
crypto.c1 = sinon.fake.returns(Buffer.from([0x99]));
|
|
184
|
+
|
|
185
|
+
smp.handlePairingResponse('data');
|
|
186
|
+
|
|
187
|
+
should(smp._pres).equal('data');
|
|
188
|
+
|
|
189
|
+
assert.calledOnceWithExactly(crypto.r);
|
|
190
|
+
assert.calledOnce(crypto.c1);
|
|
191
|
+
assert.calledOnceWithExactly(smp.write, Buffer.from([0x03, 0x99]));
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('handlePairingConfirm', () => {
|
|
195
|
+
smp.write = sinon.spy();
|
|
196
|
+
smp._r = Buffer.from([0x99]);
|
|
197
|
+
|
|
198
|
+
smp.handlePairingConfirm('data');
|
|
199
|
+
|
|
200
|
+
should(smp._pcnf).equal('data');
|
|
201
|
+
|
|
202
|
+
assert.calledOnceWithExactly(smp.write, Buffer.from([0x04, 0x99]));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('handlePairingRandom', () => {
|
|
206
|
+
it('should emit stk', () => {
|
|
207
|
+
crypto.c1 = sinon.fake.returns(Buffer.from([0x99]));
|
|
208
|
+
crypto.s1 = sinon.fake.returns('stk_answer');
|
|
209
|
+
|
|
210
|
+
const data = Buffer.from([0, 1]);
|
|
211
|
+
const callback = sinon.spy();
|
|
212
|
+
const failCallback = sinon.spy();
|
|
213
|
+
|
|
214
|
+
smp._pcnf = Buffer.from([3, 153]);
|
|
215
|
+
smp.on('stk', callback);
|
|
216
|
+
smp.on('fail', failCallback);
|
|
217
|
+
smp.handlePairingRandom(data);
|
|
218
|
+
|
|
219
|
+
assert.calledOnceWithExactly(callback, 'stk_answer');
|
|
220
|
+
assert.notCalled(failCallback);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should write and emit fail stk', () => {
|
|
224
|
+
crypto.c1 = sinon.fake.returns(Buffer.from([0x99]));
|
|
225
|
+
crypto.s1 = sinon.fake.returns('stk_answer');
|
|
226
|
+
|
|
227
|
+
const data = Buffer.from([0, 1]);
|
|
228
|
+
const callback = sinon.spy();
|
|
229
|
+
const failCallback = sinon.spy();
|
|
230
|
+
|
|
231
|
+
smp.write = sinon.spy();
|
|
232
|
+
smp._pcnf = Buffer.from([0]);
|
|
233
|
+
smp.on('stk', callback);
|
|
234
|
+
smp.on('fail', failCallback);
|
|
235
|
+
smp.handlePairingRandom(data);
|
|
236
|
+
|
|
237
|
+
assert.calledOnceWithExactly(smp.write, Buffer.from([4, 3]));
|
|
238
|
+
assert.notCalled(callback);
|
|
239
|
+
assert.calledOnceWithExactly(failCallback);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should emit fail on handlePairingFailed', () => {
|
|
244
|
+
const callback = sinon.spy();
|
|
245
|
+
smp.on('fail', callback);
|
|
246
|
+
smp.handlePairingFailed();
|
|
247
|
+
assert.calledOnceWithExactly(callback);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('should emit ltk on handleEncryptInfo', () => {
|
|
251
|
+
const callback = sinon.spy();
|
|
252
|
+
smp.on('ltk', callback);
|
|
253
|
+
smp.handleEncryptInfo(Buffer.from([0x02, 0x03, 0x04]));
|
|
254
|
+
assert.calledOnceWithExactly(callback, Buffer.from([0x03, 0x04]));
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('should emit ltk on handleMasterIdent', () => {
|
|
258
|
+
const callback = sinon.spy();
|
|
259
|
+
smp.on('masterIdent', callback);
|
|
260
|
+
smp.handleMasterIdent(Buffer.from([0x02, 0x03, 0x04, 0x05, 0x06]));
|
|
261
|
+
assert.calledOnceWithExactly(callback, Buffer.from([0x03, 0x04]), Buffer.from([0x05, 0x06]));
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('should write on aclStream', () => {
|
|
265
|
+
smp.write('data');
|
|
266
|
+
assert.calledOnceWithExactly(aclStream.write, 6, 'data');
|
|
267
|
+
});
|
|
268
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const should = require('should');
|
|
2
|
+
const proxyquire = require('proxyquire').noCallThru();
|
|
3
|
+
|
|
4
|
+
const decValues = {
|
|
5
|
+
135: 'DEC name'
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const hexValues = {
|
|
9
|
+
135: 'HEX name'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const Manufacture = proxyquire('../../lib/manufacture', {
|
|
13
|
+
'./manufactures-dec.json': decValues,
|
|
14
|
+
'./manufactures-hex.json': hexValues
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('manufacture', () => {
|
|
18
|
+
it('should have only data, no name', () => {
|
|
19
|
+
const noble = 'fake_noble';
|
|
20
|
+
const data = 'not_a_json';
|
|
21
|
+
const manufacture = new Manufacture(noble, data);
|
|
22
|
+
|
|
23
|
+
should(manufacture._noble).eql(noble);
|
|
24
|
+
should(manufacture.data).eql(data);
|
|
25
|
+
should(manufacture.name).eql(null);
|
|
26
|
+
|
|
27
|
+
should(manufacture.toString()).eql('{"name":null,"data":"not_a_json"}');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should have data and name', () => {
|
|
31
|
+
const noble = 'fake_noble';
|
|
32
|
+
const data = Buffer.from([0x87, 0x00, 0x0d, 0x9c], 'hex');
|
|
33
|
+
const manufacture = new Manufacture(noble, data);
|
|
34
|
+
|
|
35
|
+
should(manufacture._noble).eql(noble);
|
|
36
|
+
should(manufacture.data).eql(data);
|
|
37
|
+
should(manufacture.name).eql('DEC name');
|
|
38
|
+
|
|
39
|
+
should(manufacture.toString()).eql(
|
|
40
|
+
'{"name":"DEC name","data":{"type":"Buffer","data":[135,0,13,156]}}'
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should have no array data', () => {
|
|
45
|
+
const noble = 'fake_noble';
|
|
46
|
+
const data = '{type: "not an array"}';
|
|
47
|
+
const manufacture = new Manufacture(noble, data);
|
|
48
|
+
|
|
49
|
+
should(manufacture._noble).eql(noble);
|
|
50
|
+
should(manufacture.data).eql(data);
|
|
51
|
+
should(manufacture.name).eql(null);
|
|
52
|
+
|
|
53
|
+
should(manufacture.toString()).eql(
|
|
54
|
+
'{"name":null,"data":"{type: \\"not an array\\"}"}'
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('get existing name from HEX', () => {
|
|
59
|
+
const name = Manufacture.nameFromHex(135);
|
|
60
|
+
should(name).eql('HEX name');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('get unknown name from HEX', () => {
|
|
64
|
+
const name = Manufacture.nameFromHex(1);
|
|
65
|
+
should(name).eql(undefined);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('get existing name from DEC', () => {
|
|
69
|
+
const name = Manufacture.nameFromDec(135);
|
|
70
|
+
should(name).eql('DEC name');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('get unknown name from DEC', () => {
|
|
74
|
+
const name = Manufacture.nameFromDec(1);
|
|
75
|
+
should(name).eql(undefined);
|
|
76
|
+
});
|
|
77
|
+
});
|