diff --git a/include/nuttx/wireless/bt_driver.h b/include/nuttx/wireless/bt_driver.h index 38c5a068424..5c4c3290344 100644 --- a/include/nuttx/wireless/bt_driver.h +++ b/include/nuttx/wireless/bt_driver.h @@ -60,11 +60,12 @@ struct bt_driver_s /* Open the HCI transport */ - CODE int (*open)(void); + CODE int (*open)(FAR const struct bt_driver_s *dev); /* Send data to HCI */ - CODE int (*send)(FAR struct bt_buf_s *buf); + CODE int (*send)(FAR const struct bt_driver_s *dev, + FAR struct bt_buf_s *buf); }; /**************************************************************************** @@ -73,11 +74,11 @@ struct bt_driver_s /* Register a new HCI driver to the Bluetooth stack */ -int bt_driver_register(FAR struct bt_driver_s *drv); +int bt_driver_register(FAR const struct bt_driver_s *dev); /* Unregister a previously registered HCI driver */ -void bt_driver_unregister(FAR struct bt_driver_s *drv); +void bt_driver_unregister(FAR const struct bt_driver_s *dev); /* Receive data from the controller/HCI driver */ diff --git a/wireless/bluetooth/Kconfig b/wireless/bluetooth/Kconfig index 4190b48458a..84b84fe8d74 100644 --- a/wireless/bluetooth/Kconfig +++ b/wireless/bluetooth/Kconfig @@ -1,5 +1,6 @@ ############################################################################# -# Kconfig - Bluetooth LE stack configuration options +# wireless/bluetooth/Kconfig +# Bluetooth LE stack configuration options # # Copyright (C) 2018 Gregory Nutt. All rights reserved. # Author: Gregory Nutt diff --git a/wireless/bluetooth/bt_conn.c b/wireless/bluetooth/bt_conn.c index 1d01159fa6f..02ddc8d5a76 100644 --- a/wireless/bluetooth/bt_conn.c +++ b/wireless/bluetooth/bt_conn.c @@ -358,7 +358,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[]) } wlinfo("passing buf %p len %u to driver\n", buf, buf->len); - g_btdev.dev->send(buf); + g_btdev.dev->send(g_btdev.dev, buf); bt_buf_put(buf); } diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c index d3cf4309eb6..7ee1f7e1457 100644 --- a/wireless/bluetooth/bt_hcicore.c +++ b/wireless/bluetooth/bt_hcicore.c @@ -169,7 +169,7 @@ int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf) if (opcode == BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS) { - g_btdev.dev->send(buf); + g_btdev.dev->send(g_btdev.dev, buf); bt_buf_put(buf); return 0; } @@ -975,7 +975,7 @@ static void hci_event(FAR struct bt_buf_s *buf) static int hci_tx_kthread(int argc, FAR char *argv[]) { - FAR struct bt_driver_s *dev = g_btdev.dev; + FAR const struct bt_driver_s *dev = g_btdev.dev; int ret; wlinfo("started\n"); @@ -1006,7 +1006,7 @@ static int hci_tx_kthread(int argc, FAR char *argv[]) wlinfo("Sending command %x (buf %p) to driver\n", buf->u.hci.opcode, buf); - dev->send(buf); + dev->send(dev, buf); /* Clear out any existing sent command */ @@ -1397,44 +1397,36 @@ void bt_recv(FAR struct bt_buf_s *buf) } } -int bt_driver_register(FAR struct bt_driver_s *dev) +int bt_driver_register(FAR const struct bt_driver_s *dev) { - if (g_btdev.dev) + DEBUGASSERT(dev != NULL && dev->open != NULL && dev->send != NULL); + + if (g_btdev.dev != NULL) { return -EALREADY; } - if (!dev->open || !dev->send) - { - return -EINVAL; - } - g_btdev.dev = dev; return 0; } -void bt_driver_unregister(FAR struct bt_driver_s *dev) +void bt_driver_unregister(FAR const struct bt_driver_s *dev) { g_btdev.dev = NULL; } int bt_init(void) { - FAR struct bt_driver_s *dev = g_btdev.dev; + FAR const struct bt_driver_s *dev = g_btdev.dev; int err; - if (!dev) - { - wlerr("ERROR: No HCI driver registered\n"); - return -ENODEV; - } - + DEBUGASSERT(dev != NULL); bt_buf_init(); cmd_queue_init(); rx_queue_init(); - err = dev->open(); + err = dev->open(dev); if (err) { wlerr("ERROR: HCI driver open failed (%d)\n", err); diff --git a/wireless/bluetooth/bt_hcicore.h b/wireless/bluetooth/bt_hcicore.h index db0b0677902..168cf0b663f 100644 --- a/wireless/bluetooth/bt_hcicore.h +++ b/wireless/bluetooth/bt_hcicore.h @@ -136,7 +136,7 @@ struct bt_dev_s /* Registered HCI driver */ - FAR struct bt_driver_s *dev; + FAR const struct bt_driver_s *dev; }; /****************************************************************************