LingaoM opened a new pull request, #20879:
URL: https://github.com/apache/nuttx/pull/20879

   ## Summary
   
   Fix two runtime issues discovered while testing NuttX Bluetooth Hosts 
against BSWorld's Python Controller. Both firmware configurations built 
successfully, but failed during runtime initialization.
   
   1. **Deliver sim oneshot ticks in interrupt context.**
   
      The sleep-driven timer path directly calls its handler from IDLE. Timer 
expiry therefore runs in task context, where the ownership check introduced by 
e65ca9912808 rejects application timers and suppresses their notifications.
   
      Register the timer IRQ handler in both modes and dispatch sleep-driven 
ticks through `sim_doirq()`. This preserves the ownership check and restores 
correct interrupt context. The issue caused NimBLE's HCI receive polling 
callout to stop firing.
   
   2. **Check Controller to Host flow control capabilities.**
   
      The Bluetooth Host unconditionally sends optional flow-control commands, 
causing initialization to fail on Controllers that do not support them. It also 
reports completed ACL packets when flow control is inactive.
   
      Read Local Supported Commands before configuring flow control. Warn and 
continue when support is unavailable, and skip these commands when disabled by 
configuration. Wait for Host Buffer Size completion before enabling flow 
control, and report completed packets only after successful activation.
   
   ## Impact
   
   - Restores POSIX timer notifications in sleep-driven sim, including ordinary 
sim and BabbleSim-enabled configurations.
   - Allows the native Bluetooth Host to initialize with Controllers lacking 
optional Controller to Host flow control.
   - Preserves flow-control setup and completed-packet reporting for supported 
Controllers.
   - No changes to public APIs, configuration options or build requirements.
   - The timer change is confined to `arch/sim`; the Bluetooth change affects 
the native Host stack.
   
   ## Testing
   
   Environment:
   
   - Host: Ubuntu 22.04, x86_64.
   - Compiler: GCC 14.3.0.
   - Targets: `sim:bthcisock` and `sim:nimble`.
   - Bluetooth tests used BabbleSim time and Python Controllers through Unix 
sockets.
   
   ### Timer regression
   
   With BabbleSim disabled, ran a standalone POSIX `SIGEV_THREAD` timer with a 
10 ms period and inspected its callback count after 150 ms.
   
   Before:
   
   ```text
   TIMER_PROBE fired=0
   ```
   
   After:
   
   ```text
   TIMER_PROBE fired=14
   ```
   
   The existing BSWorld NimBLE integration test failed before the timer fix 
with repeated initialization resets:
   
   ```text
   Resetting state; reason=19
   ```
   
   After the fix, discovery, connection, GATT discovery and subscription passed 
with the timer ownership check retained.
   
   ### Bluetooth integration and flow control
   
   Built the native Host with Controller to Host flow control both enabled and 
disabled.
   
   Passed:
   
   - BTSak advertising and scanning.
   - NimBLE discovery, connection, GATT discovery and subscription.
   - Eight protocol-injection cases covering supported/unsupported 
capabilities, configuration disabling, truncated responses and rejected setup 
commands.
   
   The injection tests also verified command ordering and completed-packet 
reporting through the actual ACL receive buffer release path.
   
   ```text
   test_btsak_discovers_advertiser PASSED
   test_nimble_connects_and_subscribes PASSED
   ```
   
   ```text
   ============================== 8 passed in 1.53s 
===============================
   ```
   
   `git diff --check` and `tools/checkpatch.sh` passed for both commits.


-- 
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]

Reply via email to