diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index a78f2da55e4..2443d24263e 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -439,7 +439,7 @@ static int h4_open(void) return 0; } -static struct bt_hci_driver drv = { +static const struct bt_hci_driver drv = { .name = "H:4", .bus = BT_HCI_DRIVER_BUS_UART, .open = h4_open, diff --git a/drivers/bluetooth/hci/h5.c b/drivers/bluetooth/hci/h5.c index 9d73f8b21a7..9e39a2b53eb 100644 --- a/drivers/bluetooth/hci/h5.c +++ b/drivers/bluetooth/hci/h5.c @@ -747,7 +747,7 @@ static int h5_open(void) return 0; } -static struct bt_hci_driver drv = { +static const struct bt_hci_driver drv = { .name = "H:5", .bus = BT_HCI_DRIVER_BUS_UART, .open = h5_open, diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 7031b6b77fa..a311ce68aa4 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -338,7 +338,7 @@ static int bt_spi_open(void) return 0; } -static struct bt_hci_driver drv = { +static const struct bt_hci_driver drv = { .name = "BT SPI", .bus = BT_HCI_DRIVER_BUS_SPI, .open = bt_spi_open, diff --git a/include/drivers/bluetooth/hci_driver.h b/include/drivers/bluetooth/hci_driver.h index 45733d51497..16533dc2d50 100644 --- a/include/drivers/bluetooth/hci_driver.h +++ b/include/drivers/bluetooth/hci_driver.h @@ -151,7 +151,7 @@ struct bt_hci_driver { * * @return 0 on success or negative error number on failure. */ -int bt_hci_driver_register(struct bt_hci_driver *drv); +int bt_hci_driver_register(const struct bt_hci_driver *drv); #ifdef __cplusplus } diff --git a/subsys/bluetooth/controller/hci/hci_driver.c b/subsys/bluetooth/controller/hci/hci_driver.c index dc411ee72dc..65751f98422 100644 --- a/subsys/bluetooth/controller/hci/hci_driver.c +++ b/subsys/bluetooth/controller/hci/hci_driver.c @@ -413,7 +413,7 @@ static int hci_driver_open(void) return 0; } -static struct bt_hci_driver drv = { +static const struct bt_hci_driver drv = { .name = "Controller", .bus = BT_HCI_DRIVER_BUS_VIRTUAL, .open = hci_driver_open, diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 164f2dcdab3..a897bc00454 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3604,6 +3604,10 @@ int bt_send(struct net_buf *buf) bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len); + if (IS_ENABLED(CONFIG_BLUETOOTH_TINYCRYPT_ECC)) { + return bt_hci_ecc_send(buf); + } + return bt_dev.drv->send(buf); } @@ -3678,7 +3682,7 @@ int bt_recv_prio(struct net_buf *buf) return 0; } -int bt_hci_driver_register(struct bt_hci_driver *drv) +int bt_hci_driver_register(const struct bt_hci_driver *drv) { if (bt_dev.drv) { return -EALREADY; @@ -3838,7 +3842,9 @@ int bt_enable(bt_ready_cb_t cb) K_PRIO_COOP(7), 0, K_NO_WAIT); #endif - bt_hci_ecc_init(); + if (IS_ENABLED(CONFIG_BLUETOOTH_TINYCRYPT_ECC)) { + bt_hci_ecc_init(); + } err = bt_dev.drv->open(); if (err) { diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index 1c329de9a0a..a63c8fce57c 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -129,7 +129,7 @@ struct bt_dev { struct k_fifo cmd_tx_queue; /* Registered HCI driver */ - struct bt_hci_driver *drv; + const struct bt_hci_driver *drv; #if defined(CONFIG_BLUETOOTH_PRIVACY) /* Local Identity Resolving Key */ diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index e0debf5732b..5473c1b59e8 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -53,7 +53,6 @@ static const uint8_t debug_public_key[64] = { #endif static K_FIFO_DEFINE(ecc_queue); -static int (*drv_send)(struct net_buf *buf); static uint32_t private_key[8]; static void send_cmd_status(uint16_t opcode, uint8_t status) @@ -247,7 +246,7 @@ static void clear_ecc_events(struct net_buf *buf) cmd->events[1] &= ~0x01; /* LE Generate DHKey Compl Event */ } -static int ecc_send(struct net_buf *buf) +int bt_hci_ecc_send(struct net_buf *buf) { if (bt_buf_get_type(buf) == BT_BUF_CMD) { @@ -266,7 +265,7 @@ static int ecc_send(struct net_buf *buf) } } - return drv_send(buf); + return bt_dev.drv->send(buf); } void bt_hci_ecc_init(void) @@ -274,8 +273,4 @@ void bt_hci_ecc_init(void) k_thread_spawn(ecc_thread_stack, sizeof(ecc_thread_stack), ecc_thread, NULL, NULL, NULL, K_PRIO_PREEMPT(10), 0, K_NO_WAIT); - - /* set wrapper for driver send function */ - drv_send = bt_dev.drv->send; - bt_dev.drv->send = ecc_send; } diff --git a/subsys/bluetooth/host/hci_ecc.h b/subsys/bluetooth/host/hci_ecc.h index fd7bcf6777b..dcf4cf9decc 100644 --- a/subsys/bluetooth/host/hci_ecc.h +++ b/subsys/bluetooth/host/hci_ecc.h @@ -6,8 +6,5 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_BLUETOOTH_TINYCRYPT_ECC) void bt_hci_ecc_init(void); -#else -#define bt_hci_ecc_init() -#endif /* CONFIG_BLUETOOTH_TINYCRYPT_ECC */ +int bt_hci_ecc_send(struct net_buf *buf); diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index 45fcb67b336..96fea6cb10c 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -25,7 +25,7 @@ NET_BUF_POOL_DEFINE(hci_rx_pool, CONFIG_BLUETOOTH_RX_BUF_COUNT, struct bt_dev_raw bt_dev; -int bt_hci_driver_register(struct bt_hci_driver *drv) +int bt_hci_driver_register(const struct bt_hci_driver *drv) { if (bt_dev.drv) { return -EALREADY; @@ -114,7 +114,7 @@ int bt_send(struct net_buf *buf) int bt_enable_raw(struct k_fifo *rx_queue) { - struct bt_hci_driver *drv = bt_dev.drv; + const struct bt_hci_driver *drv = bt_dev.drv; int err; BT_DBG(""); @@ -126,7 +126,9 @@ int bt_enable_raw(struct k_fifo *rx_queue) return -ENODEV; } - bt_hci_ecc_init(); + if (IS_ENABLED(CONFIG_BLUETOOTH_TINYCRYPT_ECC)) { + bt_hci_ecc_init(); + } err = drv->open(); if (err) { diff --git a/subsys/bluetooth/host/hci_raw_internal.h b/subsys/bluetooth/host/hci_raw_internal.h index 5355d0db3b7..9539cc10350 100644 --- a/subsys/bluetooth/host/hci_raw_internal.h +++ b/subsys/bluetooth/host/hci_raw_internal.h @@ -12,7 +12,7 @@ extern "C" { struct bt_dev_raw { /* Registered HCI driver */ - struct bt_hci_driver *drv; + const struct bt_hci_driver *drv; }; extern struct bt_dev_raw bt_dev; diff --git a/tests/bluetooth/test_bluetooth/src/bluetooth.c b/tests/bluetooth/test_bluetooth/src/bluetooth.c index 98eb49e29bb..753a863def9 100644 --- a/tests/bluetooth/test_bluetooth/src/bluetooth.c +++ b/tests/bluetooth/test_bluetooth/src/bluetooth.c @@ -29,7 +29,7 @@ static int driver_send(struct net_buf *buf) return 0; } -static struct bt_hci_driver drv = { +static const struct bt_hci_driver drv = { .name = "test", .bus = BT_HCI_DRIVER_BUS_VIRTUAL, .open = driver_open,