Stephen-F opened a new pull request, #18847:
URL: https://github.com/apache/nuttx/pull/18847

     Summary                                                                    
   
                                                                                
   
     bluetooth_sendto() uses netdev_findbyindex(conn->bc_ldev + 1) to locate the
     Bluetooth network device for a BTPROTO_HCI socket. netdev_findbyindex 
searches
      by global interface index, but bc_ldev is a 0-based count among Bluetooth
     devices only. The two are only coincidentally equal when a BT device 
happens
     to be registered at global index 1 (immediately after loopback). On any 
system
      where a non-BT netdev (e.g. Ethernet, loopback) is registered before the 
BT
     device, bc_ldev + 1 will not match the BT device's global index and the 
lookup
      will silently return NULL or the wrong device.
   
     This was noted in the original code with a /* TODO: should actually look 
among
      BT devices */ comment that was never resolved.
   
     The fix replaces netdev_findbyindex with a netdev_foreach walk using a 
small
     private callback (bluetooth_dev_byidx_callback) that counts only
     NET_LL_BLUETOOTH devices and returns the bc_ldev-th one, making the lookup
     independent of global registration order.
   
     Impact
   
     Users of BTPROTO_HCI sockets on systems with more than one netdev (e.g.
     loopback + BT, or Ethernet + BT) were silently getting a failed or 
incorrect
     device lookup. This fix corrects that without any API or ABI changes. No
     Kconfig changes, no build system impact, no documentation changes required.
   
     Testing
   
     Tested on a custom ARM Cortex-M7 board (STM32H7-based) with an STM32WB BLE
     co-processor connected over HCI UART. The board registers a loopback netdev
     before the BT netdev, which caused netdev_findbyindex(conn->bc_ldev + 1) to
     return NULL consistently. With this fix, netdev_foreach correctly locates 
the
     BT device by position among NET_LL_BLUETOOTH devices, and HCI socket send
     succeeds.
   
     Host: Linux x86_64, GCC ARM toolchain.


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