anchao opened a new pull request, #20686: URL: https://github.com/apache/nuttx/pull/20686
## Summary
This PR adds a native NuttX Bluetooth host stack under `net/bt`, together
with
the public Bluetooth header namespace, `net_buf` memory support, build
integration, and a broad `sim:bt` coverage configuration.
The stack is ported from Zephyr Bluetooth host components and adapted to run
inside NuttX without requiring an external RTOS runtime. It keeps the
controller
interface separated through the HCI transport and driver abstraction layers,
while exposing Bluetooth APIs through the NuttX public include tree.
This provides the foundation for BLE, BR/EDR Classic, Bluetooth Mesh, LE
Audio,
GATT services, and profile-level shell/demo coverage in NuttX.
## What is included
### Core Bluetooth Host
This PR adds the core host-side Bluetooth protocol machinery, including:
- Bluetooth address handling
- Identity management
- HCI command and event processing
- HCI driver registration and transport abstraction
- Buffer ownership and monitor support
- Settings storage and key management
- SMP pairing support
- ATT request processing
- GATT database handling
- L2CAP channels
- ISO channels
- Advertising and scanning
- Connection management
- Direction finding and channel sounding helpers
- Common data and utility helpers
These pieces provide both the internal host stack logic and the public APIs
needed by applications, services, profiles, and shell commands.
### Classic BR/EDR Support
The PR adds Classic Bluetooth support, including:
- Inquiry and BR/EDR connection management
- BR/EDR L2CAP
- RFCOMM
- SDP
- SCO plumbing
- Secure Simple Pairing
- A2DP
- AVRCP and AVRCP Cover Art
- GOEP and OBEX
- BIP
- PBAP
- MAP
- HFP Audio Gateway
- HFP Hands-Free
- HID Device
- HID Host
- SPP shell support
Classic shell commands expose profile-level test and operation flows so
these
features can be compiled and exercised from the NuttX shell environment.
### Bluetooth Mesh Support
This PR adds Bluetooth Mesh host support, including:
- Provisioning and bearer handling
- Network, transport, and access layers
- Subnet and key management
- Replay protection
- Beacons
- Friend and Low Power Node behavior
- GATT Proxy and Proxy Client/Server
- Heartbeat
- Configuration Client/Server
- Health Client/Server
- Model message helpers
- Settings persistence
- Mesh shell utilities
- BLOB Transfer
- Firmware Update and Firmware Distribution
- Remote Provisioning
- Large Composition Data
- Directed Forwarding
- Bridge Configuration
- On-Demand Private Proxy
- Opcode Aggregation
- Private Beacon
- SAR Configuration
- Solicitation PDU RPL
- Mesh statistics
- Related client and server models
### LE Audio Support
The PR adds LE Audio infrastructure and profiles, including:
- BAP Unicast Client/Server
- BAP Broadcast Source/Sink
- Scan Delegator
- Broadcast Assistant
- PACS and ASCS
- CAP Acceptor, Initiator, and Commander
- AICS
- VCP and VOCS
- MICP
- CSIP
- TBS
- MCS and MCC
- Media Proxy
- HAS
- TMAS and TMAP
- GMAP
- PBP
- CCID and CCP
- Codec helpers
- LC3 preset definitions
- Endpoint and stream management
- LE Audio shell coverage
These components provide the public headers and implementation structure
needed
for both unicast and broadcast audio roles, as well as coordinated and
content-control audio use cases.
### GATT Services
This PR adds GATT service support and service implementations, including:
- GAP
- BAS
- DIS
- TPS
- HRS
- CTS
- ETS
- IAS
- ANS
- NUS
- OTS
- Service configuration and callbacks
- Object Transfer support
- Nordic UART Service instances
- Immediate Alert Client/Server helpers
- Battery Service variants
- Shell integration where applicable
The `sim:bt` configuration enables common services such as BAS, DIS, TPS,
and
NUS so that GATT server behavior can be exercised from the simulator build.
### Common Support and Compatibility Layer
This PR adds the compatibility and support infrastructure required by the
host
stack, including:
- NuttX-backed kernel object wrappers
- Work queues and timeout helpers
- Atomics
- Static iterable section compatibility
- Logging compatibility
- Settings compatibility
- Device stubs
- Crypto helpers
- EAD support
- SBC codec support
- Host utility code
- `net_buf` and `net_buf_simple` memory support
- Path-derived public header guards
The compatibility surface is kept local to the Bluetooth subsystem, while
public
Bluetooth APIs are exposed through the NuttX include namespace.
### Build and Configuration
This PR adds build-system integration for the Bluetooth stack:
- Make build integration
- CMake build integration
- Kconfig coverage for the core host
- Kconfig coverage for Classic
- Kconfig coverage for Mesh
- Kconfig coverage for services
- Kconfig coverage for LE Audio
- Kconfig coverage for crypto, common library, and `net_buf` support
- `sim:bt` defconfig for broad compile coverage
- Private include paths for internal compatibility headers
The build integration keeps Bluetooth implementation details contained
within
the Bluetooth subsystem and avoids leaking internal compatibility headers
into
unrelated NuttX targets.
## Runtime/demo coverage
The `sim:bt` configuration includes demo-oriented behavior for exercising
the
stack in the simulator, including:
- Automatic Bluetooth enable during system initialization
- Automatic LE advertising startup
- LE advertising restart after LE disconnect and connection object recycling
- Runtime logging from the NUS demo application layer
- Demo GATT services for simple read/write and notification testing
- Standard BAS, DIS, and TPS service enablement
- A2DP sink registration for SBC/AAC endpoints
- AVRCP CT/TG callback logging
- A2DP media receive callback logging with payload dump support
The runtime logs are intentionally kept in the NUS demo application layer
rather
than being added to the protocol stack internals.
## Current limitation
The current Bluetooth host stack supports only flat builds and therefore
CONFIG_BT depends on BUILD_FLAT.
Protected builds and kernel builds are not supported in this initial
version.
Support for protected and kernel build modes is planned for 27Q2. As part of
that work, the related Bluetooth profiles will be added to the libc build
where
needed so they can work correctly across NuttX protected/kernel build
boundaries.
## Impact
N/A
## Testing
The current test and validation coverage is limited to the simulator
platform.
A simulator-based Bluetooth test framework has been completed and is used to
exercise both Classic Bluetooth and BLE paths. The `sim:bt` configuration
provides broad build coverage for the host stack, services, profiles, and
demo
integration.
Validated coverage includes:
- Simulator build coverage for the Bluetooth host stack
- Classic Bluetooth test coverage through the simulator framework
- BLE test coverage through the simulator framework
- BR/EDR profile registration and callback-path validation
- LE advertising startup and restart behavior
- LE connection and disconnection callback-path validation
- GATT database discovery path validation
- Standard GATT service enablement, including BAS, DIS, and TPS
- NUS demo service registration and runtime callback-path validation
- A2DP sink endpoint registration for SBC/AAC
- A2DP media receive callback logging and payload dump path
- AVRCP CT/TG callback registration and callback logging paths
Build validation was performed with the simulator Bluetooth configuration:
Makefile:
```
./tools/configure.sh sim/bt
make -j
```
CMake:
```
cmake -B build -DBOARD_CONFIG=sim:bt -GNinja
cmake --build build
```
A2DP connection:
```
archer@archer:~/code/nuttx/n8/nuttx$ sudo ./nuttx
[sudo] password for archer:
[ 0.360] [ 5] <inf> bt_dev_show_info: HCI transport: nuttx_bt_hci
[ 0.360] [ 5] <inf> bt_dev_show_info: Identity: P:00:1A:7D:8D:C8:4B
[ 0.360] [ 5] <inf> bt_dev_show_info: HCI: version 4.0 (0x06) revision
0x22bb, manufacturer 0x000a
[ 0.360] [ 5] <inf> bt_dev_show_info: LMP: version 4.0 (0x06) subver
0x22bb
[ 0.370] [ 5] <inf> bt_nus_update_device_name: Bluetooth device name:
NuttX-BT-C84B
[ 0.370] [ 5] <inf> bt_nus_auth_register: Bluetooth auth callbacks
registered
[ 0.410] [ 5] <inf> bt_nus_start_le_adv: LE advertising active after
Bluetooth enable
[ 0.410] [ 5] <inf> bt_nus_a2dp_sink_register: A2DP SBC sink endpoint
registered
[ 0.410] [ 5] <inf> bt_nus_a2dp_sink_register: A2DP AAC sink endpoint
registered
[ 0.410] [ 5] <inf> bt_nus_avrcp_ct_register: AVRCP CT callbacks
registered
[ 0.410] [ 5] <wrn> bt_avctp_server_register: L2CAP server has been
registered
[ 0.410] [ 5] <wrn> bt_avctp_server_register: L2CAP server has been
registered
[ 0.410] [ 5] <inf> bt_nus_avrcp_tg_register: AVRCP TG callbacks
registered
NuttShell (NSH) NuttX-10.4.0
nsh> [ 22.310] [ 8] <inf> bt_nus_br_conn_req: BR/EDR conn req: addr
98:0D:AF:0E:77:65 cod 0x7a020c
[ 22.330] [ 8] <inf> bt_nus_connected: BR/EDR connected: 98:0D:AF:0E:77:65
[ 22.470] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (205 == 205)
[ 24.170] [ 8] <inf> bt_nus_disconnected: BR/EDR disconnected:
98:0D:AF:0E:77:65 reason 0x13
[ 24.170] [ 2] <inf> bt_nus_le_recycled: LE connection object recycled
[ 24.170] [ 2] <inf> bt_nus_start_le_adv: LE advertising active after
connection recycled
[ 27.410] [ 8] <inf> bt_nus_br_conn_req: BR/EDR conn req: addr
98:0D:AF:0E:77:65 cod 0x7a020c
[ 27.430] [ 8] <inf> bt_nus_connected: BR/EDR connected: 98:0D:AF:0E:77:65
[ 27.620] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (205 == 205)
[ 28.570] [ 8] <inf> bt_nus_pairing_confirm: Pairing confirmed:
98:0D:AF:0E:77:65
[ 29.190] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (1020 == 1020)
[ 29.220] [ 2] <inf> bt_nus_a2dp_connected: A2DP sink connected callback:
a2dp 0x401341e8 err 0
[ 29.220] [ 2] <inf> bt_nus_a2dp_connected: A2DP sink connected
[ 29.230] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (1020 == 1020)
[ 29.260] [ 2] <inf> bt_nus_avrcp_ct_connected: AVRCP CT connected
callback: conn 98:0D:AF:0E:77:65 ct 0x40122970
[ 29.260] [ 2] <inf> bt_nus_avrcp_tg_connected: AVRCP TG connected
callback: conn 98:0D:AF:0E:77:65 tg 0x40122eb8
[ 29.270] [ 8] <wrn> l2cap_br_check_chan_config: Unsupported extended
window size
[ 29.270] [ 8] <wrn> l2cap_br_check_chan_config: Unsupported FCS option,
force to enable FCS
[ 29.270] [ 8] <inf> bt_nus_avrcp_tg_get_caps: AVRCP TG get_caps callback:
tg 0x40122eb8 tid 2 cap_id 0x03
[ 29.400] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (339 == 339)
[ 29.460] [ 2] <inf> bt_nus_avrcp_ct_browsing_connected: AVRCP CT
browsing_connected callback: conn 98:0D:AF:0E:77:65 ct 0x40122970
[ 29.460] [ 2] <inf> bt_nus_avrcp_tg_browsing_connected: AVRCP TG
browsing_connected callback: conn 98:0D:AF:0E:77:65 tg 0x40122eb8
[ 29.590] [ 8] <inf> bt_nus_a2dp_config_req: A2DP sink config_req
callback: a2dp 0x401341e8 ep 0x40105be0 stream 0x40125d40
[ 29.590] [ 8] <inf> bt_nus_a2dp_log_codec_cfg: A2DP config_req codec:
delay_report 1 codec_ie 0x767cbfe87c2f
[ 29.590] [ 8] <inf> bt_nus_dump_buf: A2DP config_req codec: len 6 dump 6
[ 29.590] [ 8] <inf> bt_nus_dump_buf: A2DP config_req codec[0]: 80 01 04
83 e8 00 00 00 00 00 00 00 00 00 00 00
[ 29.590] [ 8] <inf> bt_nus_a2dp_stream_configured: A2DP sink stream
configured callback: stream 0x40125d40
[ 29.590] [ 8] <inf> bt_nus_dump_buf: A2DP stream codec config: len 6 dump
6
[ 29.590] [ 8] <inf> bt_nus_dump_buf: A2DP stream codec config[0]: 80 01
04 83 e8 00 00 00 00 00 00 00 00 00 00 00
[ 29.690] [ 8] <inf> bt_nus_a2dp_accept_req: A2DP sink establish_req
callback: stream 0x40125d40
[ 29.960] [ 8] <wrn> l2cap_br_conf_rsp_opt_mtu: Proposed MTU is the same
as given value (1020 == 1020)
[ 30.000] [ 2] <inf> bt_nus_a2dp_stream_established: A2DP sink stream
established callback: stream 0x40125d40
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
