@stoprocent/noble 1.9.2-16 → 1.10.0

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.
@@ -34,7 +34,7 @@ class HciSerialParser extends Transform {
34
34
  this.prePacketSize = 5;
35
35
  }
36
36
 
37
- if (this.packetData.length < this.packetSize + this.prePacketSize || this.packetSize == 0) {
37
+ if (this.packetData.length < this.packetSize + this.prePacketSize || this.packetSize === 0) {
38
38
  skipPacket = true; continue;
39
39
  }
40
40
 
@@ -189,6 +189,9 @@ Hci.prototype.waitForReset = function (buffer) {
189
189
  Hci.prototype.setupDevice = function () {
190
190
  clearTimeout(this._deviceUpTimer);
191
191
 
192
+ if (this._isExtended) {
193
+ this.setCodedPhySupport();
194
+ }
192
195
  this.setSocketFilter();
193
196
  this.setEventMask();
194
197
  this.setLeEventMask();
@@ -201,6 +204,26 @@ Hci.prototype.setupDevice = function () {
201
204
 
202
205
  Hci.prototype.setCodedPhySupport = function () {
203
206
  const cmd = Buffer.alloc(7);
207
+
208
+ // header
209
+ cmd.writeUInt8(HCI_COMMAND_PKT, 0);
210
+ cmd.writeUInt16LE(OCF_SET_PHY | (OGF_LE_CTL << 10), 1);
211
+
212
+ // length
213
+ cmd.writeUInt8(0x03, 3);
214
+
215
+ // data
216
+ cmd.writeUInt8(0x00, 4); // all phy prefs
217
+ cmd.writeUInt8(0x05, 5); // tx phy: 0x01 - LE 1M, 0x03 - LE 1M + LE 2M, 0x05 - LE 1M + LE CODED, 0x07 - LE 1M + LE 2M + LE CODED
218
+ cmd.writeUInt8(0x05, 6); // rx phy: 0x01 - LE 1M, 0x03 - LE 1M + LE 2M, 0x05 - LE 1M + LE CODED, 0x07 - LE 1M + LE 2M + LE CODED
219
+
220
+ debug(`set all phys supporting - writing: ${cmd.toString('hex')}`);
221
+ this._socketQueue.push({ buffer: cmd });
222
+ };
223
+
224
+ Hci.prototype.setRandomMAC = function () {
225
+ const cmd = Buffer.alloc(10);
226
+
204
227
  // header
205
228
  cmd.writeUInt8(HCI_COMMAND_PKT, 0);
206
229
  cmd.writeUInt16LE(OCF_SET_RANDOM_MAC | (OGF_LE_CTL << 10), 1);
@@ -1,43 +1,7 @@
1
- const os = require('os');
2
-
3
- function getWindowsBindings () {
4
- const ver = os
5
- .release()
6
- .split('.')
7
- .map((str) => parseInt(str, 10));
8
- if (
9
- !(
10
- ver[0] > 10 ||
11
- (ver[0] === 10 && ver[1] > 0) ||
12
- (ver[0] === 10 && ver[1] === 0 && ver[2] >= 15063)
13
- )
14
- ) {
15
- return require('./hci-socket/bindings');
16
- } else {
17
- return require('./win/bindings');
18
- }
19
- }
20
1
 
21
2
  module.exports = function (options) {
22
- const platform = os.platform();
23
-
24
- if (process.env.NOBLE_WEBSOCKET) {
25
- return new (require('./websocket/bindings'))(options);
26
- } else if (process.env.NOBLE_HCI_UART_PORT) {
3
+ if (process.env.NOBLE_HCI_UART_PORT) {
27
4
  return new (require('./hci-uart/bindings'))(options);
28
- } else if (process.env.NOBLE_DISTRIBUTED) {
29
- return new (require('./distributed/bindings'))(options);
30
- } else if (
31
- platform === 'linux' ||
32
- platform === 'freebsd' ||
33
- (process.env.BLUETOOTH_HCI_SOCKET_USB_VID &&
34
- process.env.BLUETOOTH_HCI_SOCKET_USB_PID)
35
- ) {
36
- return new (require('./hci-socket/bindings'))(options);
37
- } else if (platform === 'darwin') {
38
- return new (require('./mac/bindings'))(options);
39
- } else if (platform === 'win32') {
40
- return new (getWindowsBindings())(options);
41
5
  } else {
42
6
  throw new Error('Unsupported platform');
43
7
  }
@@ -0,0 +1,161 @@
1
+ From 95f8cb1e22f514092f7e2ffc8e887a26d37cb7cd Mon Sep 17 00:00:00 2001
2
+ From: Marek Serafin <marek@snowheads.pl>
3
+ Date: Thu, 29 Sep 2022 16:07:07 +0200
4
+ Subject: [PATCH] hci uart on usb cdc
5
+
6
+ Cleanup UART Example
7
+
8
+ config updates
9
+ ---
10
+ samples/bluetooth/hci_uart/Kconfig | 7 +++
11
+ .../boards/nrf52840dk_nrf52840.overlay | 18 +++++--
12
+ samples/bluetooth/hci_uart/prj.conf | 54 ++++++++++++++-----
13
+ samples/bluetooth/hci_uart/src/main.c | 8 ++-
14
+ 4 files changed, 68 insertions(+), 19 deletions(-)
15
+ create mode 100644 samples/bluetooth/hci_uart/Kconfig
16
+
17
+ diff --git a/samples/bluetooth/hci_uart/Kconfig b/samples/bluetooth/hci_uart/Kconfig
18
+ new file mode 100644
19
+ index 0000000000..0db92f0403
20
+ --- /dev/null
21
+ +++ b/samples/bluetooth/hci_uart/Kconfig
22
+ @@ -0,0 +1,7 @@
23
+ +# Copyright (c) 2019 Nordic Semiconductor ASA
24
+ +# SPDX-License-Identifier: Apache-2.0
25
+ +
26
+ +config USB_DEVICE_PID
27
+ + default USB_PID_CDC_ACM_COMPOSITE_SAMPLE
28
+ +
29
+ +source "Kconfig.zephyr"
30
+ diff --git a/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay b/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
31
+ index b3c844493c..580854bc90 100644
32
+ --- a/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
33
+ +++ b/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
34
+ @@ -1,8 +1,16 @@
35
+ /* SPDX-License-Identifier: Apache-2.0 */
36
+
37
+ -&uart0 {
38
+ - compatible = "nordic,nrf-uart";
39
+ - current-speed = <1000000>;
40
+ - status = "okay";
41
+ - hw-flow-control;
42
+ +/ {
43
+ + chosen {
44
+ + zephyr,bt-c2h-uart = &cdc_acm_uart0;
45
+ + };
46
+ };
47
+ +
48
+ +&zephyr_udc0 {
49
+ + cdc_acm_uart0: cdc_acm_uart0 {
50
+ + compatible = "zephyr,cdc-acm-uart";
51
+ + label = "CDC_ACM_0";
52
+ + current-speed = <1000000>;
53
+ + hw-flow-control;
54
+ + };
55
+ +};
56
+
57
+ diff --git a/samples/bluetooth/hci_uart/prj.conf b/samples/bluetooth/hci_uart/prj.conf
58
+ index bdc73dd68e..41fd4be447 100644
59
+ --- a/samples/bluetooth/hci_uart/prj.conf
60
+ +++ b/samples/bluetooth/hci_uart/prj.conf
61
+ @@ -1,23 +1,51 @@
62
+ -CONFIG_CONSOLE=n
63
+ +CONFIG_CONSOLE=y
64
+ CONFIG_STDOUT_CONSOLE=n
65
+ CONFIG_UART_CONSOLE=n
66
+ CONFIG_GPIO=y
67
+ CONFIG_SERIAL=y
68
+ -CONFIG_UART_INTERRUPT_DRIVEN=y
69
+ CONFIG_BT=y
70
+ CONFIG_BT_HCI_RAW=y
71
+ CONFIG_BT_HCI_RAW_H4=y
72
+ CONFIG_BT_HCI_RAW_H4_ENABLE=y
73
+ -CONFIG_BT_BUF_ACL_RX_SIZE=255
74
+ -CONFIG_BT_BUF_CMD_TX_SIZE=255
75
+ -CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255
76
+ +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=251
77
+ CONFIG_BT_CTLR_ASSERT_HANDLER=y
78
+ -CONFIG_BT_MAX_CONN=16
79
+ -CONFIG_BT_TINYCRYPT_ECC=n
80
+ +CONFIG_BT_MAX_CONN=5
81
+ +CONFIG_BT_CTLR_DTM_HCI=y
82
+ +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
83
+ +CONFIG_USE_SEGGER_RTT=y
84
+ +CONFIG_RTT_CONSOLE=y
85
+ +CONFIG_LOG=y
86
+ +CONFIG_BT_BUF_CMD_TX_COUNT=40
87
+ +CONFIG_BT_BUF_ACL_RX_COUNT=40
88
+ +CONFIG_BT_BUF_ACL_TX_COUNT=80
89
+ +CONFIG_BT_BUF_EVT_RX_COUNT=80
90
+ +CONFIG_BT_BUF_ACL_RX_SIZE=1024
91
+ +CONFIG_BT_BUF_ACL_TX_SIZE=1024
92
+ +CONFIG_BT_BUF_CMD_TX_SIZE=251
93
+ +CONFIG_BT_BUF_EVT_RX_SIZE=251
94
+ +CONFIG_BT_HCI_TX_STACK_SIZE=1024
95
+ +CONFIG_BT_CTLR=y
96
+ +CONFIG_BT_LL_SW_SPLIT=y
97
+ +CONFIG_BT_CTLR_CRYPTO=y
98
+ +CONFIG_BT_CTLR_LE_ENC=y
99
+ +CONFIG_BT_CTLR_PRIVACY=y
100
+ +CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y
101
+ CONFIG_BT_CTLR_DTM_HCI=y
102
+ -
103
+ -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
104
+ -
105
+ -# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
106
+ -# Host number of completed commands does not follow normal flow control.
107
+ -CONFIG_BT_BUF_CMD_TX_COUNT=10
108
+ +CONFIG_BT_CTLR_ADVANCED_FEATURES=y
109
+ +CONFIG_BT_CTLR_PARAM_CHECK=y
110
+ +CONFIG_BT_CTLR_PROFILE_ISR=y
111
+ +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=251
112
+ +CONFIG_LOG_BACKEND_RTT_MODE_DROP=n
113
+ +CONFIG_BT_CTLR_RX_BUFFERS=18
114
+ +CONFIG_BT_CTLR_ASSERT_HANDLER=y
115
+ +CONFIG_BT_WAIT_NOP=y
116
+ +CONFIG_UART_INTERRUPT_DRIVEN=y
117
+ +CONFIG_UART_LINE_CTRL=y
118
+ +CONFIG_USB_DEVICE_STACK=y
119
+ +CONFIG_USB_DEVICE_PRODUCT="ASSA ABLOY UART HCI Dongle"
120
+ +CONFIG_USB_COMPOSITE_DEVICE=y
121
+ +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=10240
122
+ +CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
123
+ +CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
124
+ +CONFIG_USB_DEVICE_VID=0x2554
125
+ +CONFIG_USB_DEVICE_PID=0xD00D
126
+ diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c
127
+ index a93ab0cf52..b694991529 100644
128
+ --- a/samples/bluetooth/hci_uart/src/main.c
129
+ +++ b/samples/bluetooth/hci_uart/src/main.c
130
+ @@ -19,6 +19,7 @@
131
+ #include <zephyr/device.h>
132
+ #include <zephyr/init.h>
133
+ #include <zephyr/drivers/uart.h>
134
+ +#include <zephyr/usb/usb_device.h>
135
+
136
+ #include <zephyr/net/buf.h>
137
+ #include <zephyr/bluetooth/bluetooth.h>
138
+ @@ -185,7 +186,6 @@ static void rx_isr(void)
139
+ {
140
+ uint8_t discard[H4_DISCARD_LEN];
141
+ size_t to_read = MIN(remaining, sizeof(discard));
142
+ -
143
+ read = h4_read(hci_uart_dev, discard, to_read);
144
+ remaining -= read;
145
+ if (remaining == 0) {
146
+ @@ -351,6 +351,12 @@ void main(void)
147
+ static K_FIFO_DEFINE(rx_queue);
148
+ int err;
149
+
150
+ + err = usb_enable(NULL);
151
+ + if (err != 0) {
152
+ + LOG_ERR("Failed to enable USB");
153
+ + return;
154
+ + }
155
+ +
156
+ LOG_DBG("Start");
157
+ __ASSERT(hci_uart_dev, "UART device is NULL");
158
+
159
+ --
160
+ 2.37.0 (Apple Git-136)
161
+