nuttx/net/bluetooth
Stephen Fox 990ac856b2 net/bluetooth: fix BTPROTO_HCI socket device lookup
bluetooth_sendto() uses netdev_findbyindex(conn->bc_ldev + 1) to find
the Bluetooth network device for an HCI socket.  netdev_findbyindex
searches by global interface index, but bc_ldev is a 0-based count of
Bluetooth devices only — it bears no fixed relationship to the global
interface index.  If any netdev other than a Bluetooth device is
registered before it (e.g. loopback or Ethernet), the Bluetooth device
will not be at global index bc_ldev + 1 and the lookup will return NULL
or the wrong device.

Fix this by replacing netdev_findbyindex with a netdev_foreach walk
using a small callback (bluetooth_dev_byidx_callback) that counts only
NET_LL_BLUETOOTH devices and returns the bc_ldev-th one, regardless of
what else is registered or in what order.

Signed-off-by: Stephen Fox <stephenfox@geotab.com>
2026-05-06 14:45:46 +08:00
..
bluetooth.h
bluetooth_callback.c
bluetooth_conn.c
bluetooth_container.c
bluetooth_finddev.c
bluetooth_initialize.c
bluetooth_input.c
bluetooth_poll.c
bluetooth_recvmsg.c
bluetooth_sendmsg.c net/bluetooth: fix BTPROTO_HCI socket device lookup 2026-05-06 14:45:46 +08:00
bluetooth_sockif.c
CMakeLists.txt
Kconfig
Make.defs