Bluetooth: Make bt_hci_driver instances link-time constants

Declaring these as const lets the linker generate more optimal code.
Some extra care is needed with hci_ecc.c since it was overwriting the
send callback. Now the choice of send() call is done directly in the
bt_send() function

Change-Id: Iac74f5ee9bee097bbb34c11bd13d1d886700f5cc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-03-14 15:00:15 +02:00
commit 5517893543
12 changed files with 24 additions and 24 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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) {

View file

@ -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 */

View file

@ -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;
}

View file

@ -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);

View file

@ -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) {

View file

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

View file

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