anchao opened a new pull request #1651: URL: https://github.com/apache/incubator-nuttx/pull/1651
## Summary The current implementation of Xiaomi’s Bluetooth stack is different with the current architecture. HCI transport layer communication will be based on /dev/ttyS* devices instead of sockets, The stack module prefers like bluedroid instead of bluez, host/l2cap will run on userspace, The reasons for this are as follows: ``` 1. Low coupling and more flexible: The stack implementation is completely decoupled from the operating system, which will completely decouple the nuttx from the stack with different implementation characteristics, Developers will have more ways to choose the stack which they need (btstack/zephyr/nimble/bluedroid ?) 2. Easier to porting: Implement and maintain the OSI layer is enough to porting the open source stack. 3. Sustainability/low maintenance cost: Keep in sync with the main line of the 3-party stack, regularly updated with the common code. (For the stack common code is not modified at all or some minor possible modification,) 4. Code contribution: Since the common code is exactly the same as the main line, the stack issues will be solved in the corresponding community. This is also the contribution of nuttx developers to other open source projects. ``` At present, Xiaomi has completed the porting of the zephyr stack(including ble, mesh, shell,etc), and preparing to apply it to the internal module products, `https://github.com/anchao/zblue` 1. Shell: ``` https://github.com/anchao/zblue/tree/master/port/subsys/bluetooth/shell https://github.com/anchao/zblue/tree/master/subsys/bluetooth/shell ``` 2. Stack: `https://github.com/anchao/zblue/tree/master/subsys/bluetooth` 3. OSI porting: `https://github.com/anchao/zblue/tree/master/port` 4. HCI and Chip: ``` Realtek AmebaZ rtl8720c: https://github.com/anchao/zblue/tree/master/port/chip/amebaz XRadio tech: https://github.com/anchao/zblue/tree/master/port/chip/xr829 libusb H2 for NuttX simulation(refer to sim/zblue): https://github.com/anchao/zblue/tree/master/port/drivers/bluetooth/hci/libusb.c ``` and also we have nuttx sim demo for the zephyr stack, If anyone is interested, you can try the following steps to run the stack on sim: 1. USB Dongle: (Recommend CSR8510 (BT+BLE+MESH 5.0)) ``` $ lsusb ... Bus 001 Device 073: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) ... ``` 2. Setup Environment: ``` sudo apt-get install libusb-1.0-0-dev:i386 sudo apt-get install libusb-1.0-0-dev ``` 3. Download the source code: ``` git clone g...@github.com:apache/incubator-nuttx.git git clone g...@github.com:apache/incubator-nuttx-apps.git git clone g...@github.com:anchao/external.git git clone g...@github.com:anchao/tinycrypt.git external/tinycrypt git clone g...@github.com:anchao/zblue.git external/zblue mv incubator-nuttx-apps apps ln -s ../external apps/external ``` Apply the patch list of this PR to incubator-nuttx: Directory structure: ``` $ tree ├── apps │ ├── external -> ../external ├── external │ ├── tinycrypt │ ── zblue ── incubator-nuttx ``` 5. Compile sim/zblue ``` cd incubator-nuttx ./tools/configure.sh sim/zblue make ``` 6. Startup the stack: ``` archer@c:~/code/nuttx/incubator-nuttx$ sudo ./nuttx NuttShell (NSH) NuttX-9.1.0 nsh> nsh> bt init [ 2.285300] 0a12:0001 (bus 1, device 105) - class e0 subclass 1 protocol 1 [ 2.285300] -> using 0x81 for HCI Events [ 2.285300] -> using 0x02 for ACL Data Out [ 2.285300] -> using 0x82 for ACL Data In [ 2.285300] -> using 0x03 for SCO Data Out [ 2.285300] -> using 0x83 for SCO Data In [ 2.640300] Controller doesn't seem to support Zephyr vendor HCI [ 2.640300] No ID address. App must call settings_load() [ 2.640300] Bluetooth initialized [ 2.643300] Identity: 00:1A:7D:DA:71:13 (public) [ 2.643300] HCI: version 4.0 (0x06) revision 0x22bb, manufacturer 0x000a [ 2.643300] LMP: version 4.0 (0x06) subver 0x22bb nsh> nsh> ps PID GROUP PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK USED FILLED COMMAND 0 0 0 FIFO Kthread N-- Ready 00000000 002048 001296 63.2% Idle Task 1 1 224 FIFO Kthread --- Waiting Signal 00000000 008208 001980 24.1% hpwork 2 1 100 FIFO Task --- Running 00000000 030736 002432 7.9% init 4 4 102 FIFO Kthread --- Waiting Semaphore 00000000 008176 000692 8.4% BT TX 0xf7945040 5 4 103 FIFO Kthread --- Waiting Semaphore 00000000 008176 000820 10.0% BT RX 0xf7945040 6 4 105 FIFO Kthread --- Waiting Semaphore 00000000 008176 000692 8.4% BT ECC 0xf7945040 7 4 103 FIFO Kthread --- Waiting Signal 00000000 008176 001020 12.4% BT Driver 0xf7945040 nsh> ``` 7. BLE Peripheral: ``` archer@c:~/code/nuttx/incubator-nuttx$ sudo ./nuttx NuttShell (NSH) NuttX-9.1.0 nsh> peripheral [ 1.938300] 0a12:0001 (bus 1, device 105) - class e0 subclass 1 protocol 1 [ 1.938300] -> using 0x81 for HCI Events [ 1.938300] -> using 0x02 for ACL Data Out [ 1.938300] -> using 0x82 for ACL Data In [ 1.938300] -> using 0x03 for SCO Data Out [ 1.938300] -> using 0x83 for SCO Data In [ 2.286500] Controller doesn't seem to support Zephyr vendor HCI [ 2.286500] No ID address. App must call settings_load() Bluetooth initialized [ 2.288500] Identity: 00:1A:7D:DA:71:13 (public) [ 2.288500] HCI: version 4.0 (0x06) revision 0x22bb, manufacturer 0x000a [ 2.288500] LMP: version 4.0 (0x06) subver 0x22bb Advertising successfully started ``` 8. BLE Central: ``` archer@c:~/code/nuttx/incubator-nuttx$ sudo ./nuttx NuttShell (NSH) NuttX-9.1.0 nsh> central [ 4.013700] 0a12:0001 (bus 1, device 105) - class e0 subclass 1 protocol 1 [ 4.013700] -> using 0x81 for HCI Events [ 4.013700] -> using 0x02 for ACL Data Out [ 4.013700] -> using 0x82 for ACL Data In [ 4.013700] -> using 0x03 for SCO Data Out [ 4.013700] -> using 0x83 for SCO Data In [ 4.365500] Controller doesn't seem to support Zephyr vendor HCI [ 4.365500] No ID address. App must call settings_load() [ 4.367500] Identity: 00:1A:7D:DA:71:13 (public) [ 4.367500] HCI: version 4.0 (0x06) revision 0x22bb, manufacturer 0x000a [ 4.367500] LMP: version 4.0 (0x06) subver 0x22bb Bluetooth initialized Scanning successfully started nsh> Device found: 78:20:CC:53:FB:E4 (random) (RSSI -79) Device found: 78:11:DC:92:42:42 (public) (RSSI -65) Connected: 78:11:DC:92:42:42 (public) Disconnected: 78:11:DC:92:42:42 (public) (reason 0x08) Scanning successfully started Device found: 73:4F:31:AC:17:CB (random) (RSSI -69) Connected: 73:4F:31:AC:17:CB (random) Disconnected: 73:4F:31:AC:17:CB (random) (reason 0x16) Scanning successfully started Device found: 58:77:EF:3D:A0:6D (random) (RSSI -62) Connected: 58:77:EF:3D:A0:6D (random) Disconnected: 58:77:EF:3D:A0:6D (random) (reason 0x16) Scanning successfully started Device found: 6A:E7:51:C7:66:F3 (random) (RSSI -62) Connected: 6A:E7:51:C7:66:F3 (random) Disconnected: 6A:E7:51:C7:66:F3 (random) (reason 0x3e) Scanning successfully started Device found: 55:D6:73:66:9F:3C (random) (RSSI -66) Connected: 55:D6:73:66:9F:3C (random) Disconnected: 55:D6:73:66:9F:3C (random) (reason 0x3e) Scanning successfully started Device found: 7A:4A:23:31:82:93 (random) (RSSI -72) Device found: 47:F9:5A:17:6A:CE (random) (RSSI -59) Connected: 47:F9:5A:17:6A:CE (random) ``` 9. BLE Mesh node: ``` archer@c:~/code/nuttx/incubator-nuttx$ sudo ./nuttx NuttShell (NSH) NuttX-9.1.0 nsh> btmesh Initializing... [ 5.340600] 0a12:0001 (bus 1, device 107) - class e0 subclass 1 protocol 1 [ 5.340600] -> using 0x81 for HCI Events [ 5.340600] -> using 0x02 for ACL Data Out [ 5.340600] -> using 0x82 for ACL Data In [ 5.340600] -> using 0x03 for SCO Data Out [ 5.340600] -> using 0x83 for SCO Data In nsh> [ 5.700400] Controller doesn't seem to support Zephyr vendor HCI [ 5.700400] No ID address. App must call settings_load() Bluetooth initialized [ 5.732400] Identity: 00:1A:7D:DA:71:13 (public) [ 5.732400] HCI: version 4.0 (0x06) revision 0x22bb, manufacturer 0x000a [ 5.732400] LMP: version 4.0 (0x06) subver 0x22bb [ 5.732400] Device UUID: 00000000-0000-0000-0000-00000000dddd Mesh initialized OOB Number: 1993 [ 28.035000] Primary Element: 0x0002 [ 37.035000] No matching TX context for ack ``` 10. Shell: ``` nsh> bt [ 1.766000] Bluetooth shell commands : [ 1.766000] [00]: bt init : [none] [ 1.766000] [01]: bt hci-cmd : <ogf> <ocf> [data] [ 1.766000] [02]: bt id-create : [addr] [ 1.766000] [03]: bt id-reset : <id> [addr] [ 1.766000] [04]: bt id-delete : <id> [ 1.766000] [05]: bt id-show : [none] [ 1.766000] [06]: bt id-select : <id> [ 1.766000] [07]: bt name : [name] [ 1.766000] [08]: bt scan : <value: on, passive, off> [filter: dups, nodups] [wl] [coded] [no-1m] [ 1.766000] [09]: bt advertise : <type: off, on, scan, nconn> [mode: discov, non_discov] [whitelist: wl, wl-scan, wl-conn] [identity] [no-name] [one-time] [ 1.766000] [10]: bt directed-adv : <address: XX:XX:XX:XX:XX:XX> <type: (public|random)> [mode: low] [identity] [dir-rpa] [ 1.766000] [11]: bt adv-create : <type: conn-scan conn-nscan, nconn-scan nconn-nscan> [ext-adv] [no-2m] [coded] [whitelist: wl, wl-scan, wl-conn] [identity] [name] [directed <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>] [mode: low] [ 1.766000] [12]: bt adv-param : <type: conn-scan conn-nscan, nconn-scan nconn-nscan> [ext-adv] [no-2m] [coded] [whitelist: wl, wl-scan, wl-conn] [identity] [name] [directed <address: XX:XX:XX:XX:XX:XX> <type: (public|random)>] [mode: low] [ 1.766000] [13]: bt adv-data : <data> [scan-response <data>] <type: discov, name, hex> .... nsh> gatt [ 3.717700] Bluetooth GATT shell commands : [ 3.717700] [00]: gatt discover : [UUID] [start handle] [end handle] [ 3.717700] [01]: gatt discover-characteristic : [UUID] [start handle] [end handle] [ 3.717700] [02]: gatt discover-descriptor : [UUID] [start handle] [end handle] [ 3.717700] [03]: gatt discover-include : [UUID] [start handle] [end handle] [ 3.717700] [04]: gatt discover-primary : [UUID] [start handle] [end handle] [ 3.717700] [05]: gatt discover-secondary : [UUID] [start handle] [end handle] .... nsh> l2cap [ 18.302000] Bluetooth L2CAP shell commands : [ 18.302000] [00]: l2cap connect : <psm> [ 18.302000] [01]: l2cap disconnect : [none] [ 18.302000] [02]: l2cap metrics : <value on, off> .... nsh> mesh [ 24.813900] Bluetooth Mesh shell commands : [ 24.813900] [00]: mesh init : (null) [ 24.813900] [01]: mesh reset : (null) [ 24.813900] [02]: mesh ident : (null) [ 24.813900] [03]: mesh dst : [destination address] [ 24.813900] [04]: mesh netidx : [NetIdx] [ 24.813900] [05]: mesh appidx : [AppIdx] [ 24.813900] [06]: mesh net-send : <hex string> [ 24.813900] [07]: mesh rpl-clear : (null) [ 24.813900] [08]: mesh pb-gatt : <val: off, on> [ 24.813900] [09]: mesh pb-adv : <val: off, on> [ 24.813900] [10]: mesh uuid : <UUID: 1-16 hex values> [ 24.813900] [11]: mesh input-num : <number> [ 24.813900] [12]: mesh input-str : <string> [ 24.813900] [13]: mesh static-oob : [val: 1-16 hex values] [ 24.813900] [14]: mesh provision : <NetKeyIndex> <addr> [IVIndex] .... ``` ## Impact ## Testing ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org