Bluetooth: Host: Remove deprecated HCI driver API

Remove the deprecated HCI driver API which was provided by the hci_driver.h
header file. The deprecation happened in Zephyr 3.7, so the API can now be
removed for Zephyr 4.1.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
This commit is contained in:
Johan Hedberg 2024-11-19 21:20:10 +02:00 committed by Alberto Escolar
commit 30d1d0e526
12 changed files with 43 additions and 429 deletions

View file

@ -8,4 +8,4 @@ HCI Drivers
API Reference API Reference
************* *************
.. doxygengroup:: bt_hci_driver .. doxygengroup:: bt_hci_api

View file

@ -1,242 +0,0 @@
/** @file
* @brief Bluetooth HCI driver API.
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_
#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_
/**
* @brief HCI drivers
*
* @deprecated This is the old HCI driver API. Drivers should use @ref bt_hci_api instead.
*
* @defgroup bt_hci_driver HCI drivers
* @ingroup bluetooth
* @{
*/
#include <stdbool.h>
#include <zephyr/net_buf.h>
#include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
/* The host should never send HCI_Reset */
BT_QUIRK_NO_RESET = BIT(0),
/* The controller does not auto-initiate a DLE procedure when the
* initial connection data length parameters are not equal to the
* default data length parameters. Therefore the host should initiate
* the DLE procedure after connection establishment. */
BT_QUIRK_NO_AUTO_DLE = BIT(1),
};
/**
* @brief Receive data from the controller/HCI driver.
*
* This is the main function through which the HCI driver provides the
* host with data from the controller. The buffer needs to have its type
* set with the help of bt_buf_set_type() before calling this API.
*
* @param buf Network buffer containing data from the controller.
*
* @return 0 on success or negative error number on failure.
*
* @deprecated Use the new HCI driver interface instead: @ref bt_hci_api
*/
__deprecated int bt_recv(struct net_buf *buf);
/** Possible values for the 'bus' member of the bt_hci_driver struct */
enum bt_hci_driver_bus {
BT_HCI_DRIVER_BUS_VIRTUAL = 0,
BT_HCI_DRIVER_BUS_USB = 1,
BT_HCI_DRIVER_BUS_PCCARD = 2,
BT_HCI_DRIVER_BUS_UART = 3,
BT_HCI_DRIVER_BUS_RS232 = 4,
BT_HCI_DRIVER_BUS_PCI = 5,
BT_HCI_DRIVER_BUS_SDIO = 6,
BT_HCI_DRIVER_BUS_SPI = 7,
BT_HCI_DRIVER_BUS_I2C = 8,
BT_HCI_DRIVER_BUS_IPM = 9,
};
#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)
struct bt_hci_setup_params {
/** The public identity address to give to the controller. This field is used when the
* driver selects @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR} to indicate that it supports
* setting the controller's public address.
*/
bt_addr_t public_addr;
};
#endif
/**
* @brief Abstraction which represents the HCI transport to the controller.
*
* This struct is used to represent the HCI transport to the Bluetooth
* controller.
*/
struct bt_hci_driver {
/** Name of the driver */
const char *name;
/** Bus of the transport (BT_HCI_DRIVER_BUS_*) */
enum bt_hci_driver_bus bus;
/** Specific controller quirks. These are set by the HCI driver
* and acted upon by the host. They can either be statically
* set at buildtime, or set at runtime before the HCI driver's
* open() callback returns.
*/
uint32_t quirks;
/**
* @brief Open the HCI transport.
*
* Opens the HCI transport for operation. This function must not
* return until the transport is ready for operation, meaning it
* is safe to start calling the send() handler.
*
* @return 0 on success or negative error number on failure.
*/
int (*open)(void);
/**
* @brief Close the HCI transport.
*
* Closes the HCI transport. This function must not return until the
* transport is closed.
*
* @return 0 on success or negative error number on failure.
*/
int (*close)(void);
/**
* @brief Send HCI buffer to controller.
*
* Send an HCI command or ACL data to the controller. The exact
* type of the data can be checked with the help of bt_buf_get_type().
*
* @note This function must only be called from a cooperative thread.
*
* @param buf Buffer containing data to be sent to the controller.
*
* @return 0 on success or negative error number on failure.
*/
int (*send)(struct net_buf *buf);
#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)
/**
* @brief HCI vendor-specific setup
*
* Executes vendor-specific commands sequence to initialize
* BT Controller before BT Host executes Reset sequence.
*
* @note @kconfig{CONFIG_BT_HCI_SETUP} must be selected for this
* field to be available.
*
* @return 0 on success or negative error number on failure.
*/
int (*setup)(const struct bt_hci_setup_params *params);
#endif /* defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)*/
};
/**
* @brief Register a new HCI driver to the Bluetooth stack.
*
* This needs to be called before any application code runs. The bt_enable()
* API will fail if there is no driver registered.
*
* @param drv A bt_hci_driver struct representing the driver.
*
* @return 0 on success or negative error number on failure.
*
* @deprecated Use the new HCI driver interface instead: @ref bt_hci_api
*/
__deprecated int bt_hci_driver_register(const struct bt_hci_driver *drv);
/**
* @brief Setup the HCI transport, which usually means to reset the
* Bluetooth IC.
*
* @note A weak version of this function is included in the H4 driver, so
* defining it is optional per board.
*
* @param dev The device structure for the bus connecting to the IC
*
* @return 0 on success, negative error value on failure
*/
int bt_hci_transport_setup(const struct device *dev);
/**
* @brief Teardown the HCI transport.
*
* @note A weak version of this function is included in the IPC driver, so
* defining it is optional. NRF5340 includes support to put network core
* in reset state.
*
* @param dev The device structure for the bus connecting to the IC
*
* @return 0 on success, negative error value on failure
*/
int bt_hci_transport_teardown(const struct device *dev);
/** Allocate an HCI event buffer.
*
* This function allocates a new buffer for an HCI event. It is given the
* event code and the total length of the parameters. Upon successful return
* the buffer is ready to have the parameters encoded into it.
*
* @param evt Event OpCode.
* @param len Length of event parameters.
*
* @return Newly allocated buffer.
*/
struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len);
/** Allocate an HCI Command Complete event buffer.
*
* This function allocates a new buffer for HCI Command Complete event.
* It is given the OpCode (encoded e.g. using the BT_OP macro) and the total
* length of the parameters. Upon successful return the buffer is ready to have
* the parameters encoded into it.
*
* @param op Command OpCode.
* @param plen Length of command parameters.
*
* @return Newly allocated buffer.
*/
struct net_buf *bt_hci_cmd_complete_create(uint16_t op, uint8_t plen);
/** Allocate an HCI Command Status event buffer.
*
* This function allocates a new buffer for HCI Command Status event.
* It is given the OpCode (encoded e.g. using the BT_OP macro) and the status
* code. Upon successful return the buffer is ready to have the parameters
* encoded into it.
*
* @param op Command OpCode.
* @param status Status code.
*
* @return Newly allocated buffer.
*/
struct net_buf *bt_hci_cmd_status_create(uint16_t op, uint8_t status);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ */

View file

@ -15,7 +15,7 @@
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/sys/atomic.h> #include <zephyr/sys/atomic.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include <zephyr/bluetooth/hci_types.h> #include <zephyr/bluetooth/hci_types.h>
#include <zephyr/bluetooth/hci_vs.h> #include <zephyr/bluetooth/hci_vs.h>

View file

@ -24,7 +24,7 @@
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/direction.h> #include <zephyr/bluetooth/direction.h>
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/bluetooth/att.h> #include <zephyr/bluetooth/att.h>
#include "common/assert.h" #include "common/assert.h"

View file

@ -6,7 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include "common/assert.h" #include "common/assert.h"
struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len) struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)

View file

@ -30,11 +30,7 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/hci_vs.h> #include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/bluetooth/testing.h> #include <zephyr/bluetooth/testing.h>
#if DT_HAS_CHOSEN(zephyr_bt_hci)
#include <zephyr/drivers/bluetooth.h> #include <zephyr/drivers/bluetooth.h>
#else
#include <zephyr/drivers/bluetooth/hci_driver.h>
#endif
#include "common/bt_str.h" #include "common/bt_str.h"
#include "common/assert.h" #include "common/assert.h"
@ -70,9 +66,20 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_core); LOG_MODULE_REGISTER(bt_hci_core);
#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) #if DT_HAS_CHOSEN(zephyr_bt_hci)
#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) #define BT_HCI_NODE DT_CHOSEN(zephyr_bt_hci)
#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) #define BT_HCI_DEV DEVICE_DT_GET(BT_HCI_NODE)
#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_NODE)
#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_NODE)
#define BT_HCI_QUIRKS BT_DT_HCI_QUIRKS_GET(BT_HCI_NODE)
#else
/* The zephyr,bt-hci chosen property is mandatory, except for unit tests */
BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI");
#define BT_HCI_DEV NULL
#define BT_HCI_BUS 0
#define BT_HCI_NAME ""
#define BT_HCI_QUIRKS 0
#endif
void bt_tx_irq_raise(void); void bt_tx_irq_raise(void);
@ -96,9 +103,7 @@ struct bt_dev bt_dev = {
#if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC) #if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC)
.appearance = CONFIG_BT_DEVICE_APPEARANCE, .appearance = CONFIG_BT_DEVICE_APPEARANCE,
#endif #endif
#if DT_HAS_CHOSEN(zephyr_bt_hci) .hci = BT_HCI_DEV,
.hci = DEVICE_DT_GET(BT_HCI_DEV),
#endif
}; };
static bt_ready_cb_t ready_cb; static bt_ready_cb_t ready_cb;
@ -126,27 +131,15 @@ static struct cmd_data cmd_data[CONFIG_BT_BUF_CMD_TX_COUNT];
#define cmd(buf) (&cmd_data[net_buf_id(buf)]) #define cmd(buf) (&cmd_data[net_buf_id(buf)])
#define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) #define acl(buf) ((struct acl_data *)net_buf_user_data(buf))
#if DT_HAS_CHOSEN(zephyr_bt_hci)
static bool drv_quirk_no_reset(void) static bool drv_quirk_no_reset(void)
{ {
return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_RESET) != 0); return ((BT_HCI_QUIRKS & BT_HCI_QUIRK_NO_RESET) != 0);
} }
bool bt_drv_quirk_no_auto_dle(void) bool bt_drv_quirk_no_auto_dle(void)
{ {
return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_AUTO_DLE) != 0); return ((BT_HCI_QUIRKS & BT_HCI_QUIRK_NO_AUTO_DLE) != 0);
} }
#else
static bool drv_quirk_no_reset(void)
{
return ((bt_dev.drv->quirks & BT_QUIRK_NO_RESET) != 0);
}
bool bt_drv_quirk_no_auto_dle(void)
{
return ((bt_dev.drv->quirks & BT_QUIRK_NO_AUTO_DLE) != 0);
}
#endif
void bt_hci_cmd_state_set_init(struct net_buf *buf, void bt_hci_cmd_state_set_init(struct net_buf *buf,
struct bt_hci_cmd_state_set *state, struct bt_hci_cmd_state_set *state,
@ -4008,19 +4001,10 @@ static int hci_init(void)
} }
#endif /* defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR) */ #endif /* defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR) */
#if DT_HAS_CHOSEN(zephyr_bt_hci)
err = bt_hci_setup(bt_dev.hci, &setup_params); err = bt_hci_setup(bt_dev.hci, &setup_params);
if (err && err != -ENOSYS) { if (err && err != -ENOSYS) {
return err; return err;
} }
#else
if (bt_dev.drv->setup) {
err = bt_dev.drv->setup(&setup_params);
if (err) {
return err;
}
}
#endif
#endif /* defined(CONFIG_BT_HCI_SETUP) */ #endif /* defined(CONFIG_BT_HCI_SETUP) */
err = common_init(); err = common_init();
@ -4075,11 +4059,7 @@ int bt_send(struct net_buf *buf)
return bt_hci_ecc_send(buf); return bt_hci_ecc_send(buf);
} }
#if DT_HAS_CHOSEN(zephyr_bt_hci)
return bt_hci_send(bt_dev.hci, buf); return bt_hci_send(bt_dev.hci, buf);
#else
return bt_dev.drv->send(buf);
#endif
} }
static const struct event_handler prio_events[] = { static const struct event_handler prio_events[] = {
@ -4181,14 +4161,9 @@ static int bt_recv_unsafe(struct net_buf *buf)
} }
} }
#if DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_recv(const struct device *dev, struct net_buf *buf) int bt_hci_recv(const struct device *dev, struct net_buf *buf)
{ {
ARG_UNUSED(dev); ARG_UNUSED(dev);
#else
int bt_recv(struct net_buf *buf)
{
#endif
int err; int err;
k_sched_lock(); k_sched_lock();
@ -4198,29 +4173,6 @@ int bt_recv(struct net_buf *buf)
return err; return err;
} }
/* Old-style HCI driver registration */
#if !DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_driver_register(const struct bt_hci_driver *drv)
{
if (bt_dev.drv) {
return -EALREADY;
}
if (!drv->open || !drv->send) {
return -EINVAL;
}
bt_dev.drv = drv;
LOG_DBG("Registered %s", drv->name ? drv->name : "");
bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, drv->bus,
BT_ADDR_ANY, drv->name ? drv->name : "bt0");
return 0;
}
#endif /* !DT_HAS_CHOSEN(zephyr_bt_hci) */
void bt_finalize_init(void) void bt_finalize_init(void)
{ {
atomic_set_bit(bt_dev.flags, BT_DEV_READY); atomic_set_bit(bt_dev.flags, BT_DEV_READY);
@ -4349,19 +4301,17 @@ int bt_enable(bt_ready_cb_t cb)
{ {
int err; int err;
#if DT_HAS_CHOSEN(zephyr_bt_hci) if (IS_ENABLED(CONFIG_ZTEST) && bt_dev.hci == NULL) {
LOG_ERR("No DT chosen property for HCI");
return -ENODEV;
}
if (!device_is_ready(bt_dev.hci)) { if (!device_is_ready(bt_dev.hci)) {
LOG_ERR("HCI driver is not ready"); LOG_ERR("HCI driver is not ready");
return -ENODEV; return -ENODEV;
} }
bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME);
#else /* !DT_HAS_CHONSEN(zephyr_bt_hci) */
if (!bt_dev.drv) {
LOG_ERR("No HCI driver registered");
return -ENODEV;
}
#endif
atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE);
@ -4403,11 +4353,7 @@ int bt_enable(bt_ready_cb_t cb)
k_thread_name_set(&bt_workq.thread, "BT RX WQ"); k_thread_name_set(&bt_workq.thread, "BT RX WQ");
#endif #endif
#if DT_HAS_CHOSEN(zephyr_bt_hci)
err = bt_hci_open(bt_dev.hci, bt_hci_recv); err = bt_hci_open(bt_dev.hci, bt_hci_recv);
#else
err = bt_dev.drv->open();
#endif
if (err) { if (err) {
LOG_ERR("HCI driver open failed (%d)", err); LOG_ERR("HCI driver open failed (%d)", err);
return err; return err;
@ -4427,17 +4373,6 @@ int bt_disable(void)
{ {
int err; int err;
#if !DT_HAS_CHOSEN(zephyr_bt_hci)
if (!bt_dev.drv) {
LOG_ERR("No HCI driver registered");
return -ENODEV;
}
if (!bt_dev.drv->close) {
return -ENOTSUP;
}
#endif
if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_DISABLE)) { if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_DISABLE)) {
return -EALREADY; return -EALREADY;
} }
@ -4465,16 +4400,13 @@ int bt_disable(void)
disconnected_handles_reset(); disconnected_handles_reset();
#endif /* CONFIG_BT_CONN */ #endif /* CONFIG_BT_CONN */
#if DT_HAS_CHOSEN(zephyr_bt_hci)
err = bt_hci_close(bt_dev.hci); err = bt_hci_close(bt_dev.hci);
if (err == -ENOSYS) { if (err == -ENOSYS) {
atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE);
atomic_set_bit(bt_dev.flags, BT_DEV_READY); atomic_set_bit(bt_dev.flags, BT_DEV_READY);
return -ENOTSUP; return -ENOTSUP;
} }
#else
err = bt_dev.drv->close();
#endif
if (err) { if (err) {
LOG_ERR("HCI driver close failed (%d)", err); LOG_ERR("HCI driver close failed (%d)", err);

View file

@ -403,12 +403,7 @@ struct bt_dev {
/* Queue for outgoing HCI commands */ /* Queue for outgoing HCI commands */
struct k_fifo cmd_tx_queue; struct k_fifo cmd_tx_queue;
#if DT_HAS_CHOSEN(zephyr_bt_hci)
const struct device *hci; const struct device *hci;
#else
/* Registered HCI driver */
const struct bt_hci_driver *drv;
#endif
#if defined(CONFIG_BT_PRIVACY) #if defined(CONFIG_BT_PRIVACY)
/* Local Identity Resolving Key */ /* Local Identity Resolving Key */
@ -443,9 +438,7 @@ extern sys_slist_t bt_auth_info_cbs;
enum bt_security_err bt_security_err_get(uint8_t hci_err); enum bt_security_err bt_security_err_get(uint8_t hci_err);
#endif /* CONFIG_BT_SMP || CONFIG_BT_CLASSIC */ #endif /* CONFIG_BT_SMP || CONFIG_BT_CLASSIC */
#if DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_recv(const struct device *dev, struct net_buf *buf); int bt_hci_recv(const struct device *dev, struct net_buf *buf);
#endif
/* Data type to store state related with command to be updated /* Data type to store state related with command to be updated
* when command completes successfully. * when command completes successfully.

View file

@ -27,11 +27,7 @@
#include <zephyr/bluetooth/buf.h> #include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#if DT_HAS_CHOSEN(zephyr_bt_hci)
#include <zephyr/drivers/bluetooth.h> #include <zephyr/drivers/bluetooth.h>
#else
#include <zephyr/drivers/bluetooth/hci_driver.h>
#endif
#include "common/bt_str.h" #include "common/bt_str.h"
@ -102,11 +98,7 @@ static void send_cmd_status(uint16_t opcode, uint8_t status)
evt->opcode = sys_cpu_to_le16(opcode); evt->opcode = sys_cpu_to_le16(opcode);
evt->status = status; evt->status = status;
#if DT_HAS_CHOSEN(zephyr_bt_hci)
bt_hci_recv(bt_dev.hci, buf); bt_hci_recv(bt_dev.hci, buf);
#else
bt_recv(buf);
#endif
} }
#if defined(CONFIG_BT_USE_PSA_API) #if defined(CONFIG_BT_USE_PSA_API)
@ -217,11 +209,7 @@ static void emulate_le_p256_public_key_cmd(void)
atomic_clear_bit(flags, PENDING_PUB_KEY); atomic_clear_bit(flags, PENDING_PUB_KEY);
#if DT_HAS_CHOSEN(zephyr_bt_hci)
bt_hci_recv(bt_dev.hci, buf); bt_hci_recv(bt_dev.hci, buf);
#else
bt_recv(buf);
#endif
} }
static void emulate_le_generate_dhkey(void) static void emulate_le_generate_dhkey(void)
@ -303,11 +291,7 @@ exit:
atomic_clear_bit(flags, PENDING_DHKEY); atomic_clear_bit(flags, PENDING_DHKEY);
#if DT_HAS_CHOSEN(zephyr_bt_hci)
bt_hci_recv(bt_dev.hci, buf); bt_hci_recv(bt_dev.hci, buf);
#else
bt_recv(buf);
#endif
} }
static void ecc_process(struct k_work *work) static void ecc_process(struct k_work *work)
@ -432,11 +416,7 @@ int bt_hci_ecc_send(struct net_buf *buf)
} }
} }
#if DT_HAS_CHOSEN(zephyr_bt_hci)
return bt_hci_send(bt_dev.hci, buf); return bt_hci_send(bt_dev.hci, buf);
#else
return bt_dev.drv->send(buf);
#endif
} }
void bt_hci_ecc_supported_commands(uint8_t *supported_commands) void bt_hci_ecc_supported_commands(uint8_t *supported_commands)

View file

@ -11,11 +11,7 @@
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/devicetree.h> #include <zephyr/devicetree.h>
#if DT_HAS_CHOSEN(zephyr_bt_hci)
#include <zephyr/drivers/bluetooth.h> #include <zephyr/drivers/bluetooth.h>
#else
#include <zephyr/drivers/bluetooth/hci_driver.h>
#endif
#include <zephyr/bluetooth/buf.h> #include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/hci_raw.h> #include <zephyr/bluetooth/hci_raw.h>
#include <zephyr/bluetooth/l2cap.h> #include <zephyr/bluetooth/l2cap.h>
@ -53,40 +49,25 @@ NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
sizeof(struct bt_buf_data), NULL); sizeof(struct bt_buf_data), NULL);
#endif /* CONFIG_BT_ISO */ #endif /* CONFIG_BT_ISO */
#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) #if DT_HAS_CHOSEN(zephyr_bt_hci)
#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) #define BT_HCI_NODE DT_CHOSEN(zephyr_bt_hci)
#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) #define BT_HCI_DEV DEVICE_DT_GET(BT_HCI_NODE)
#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_NODE)
#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_NODE)
#else
/* The zephyr,bt-hci chosen property is mandatory, except for unit tests */
BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI");
#define BT_HCI_DEV NULL
#define BT_HCI_BUS 0
#define BT_HCI_NAME ""
#endif
struct bt_dev_raw bt_dev = { struct bt_dev_raw bt_dev = {
#if DT_HAS_CHOSEN(zephyr_bt_hci) .hci = BT_HCI_DEV,
.hci = DEVICE_DT_GET(BT_HCI_DEV),
#endif
}; };
struct bt_hci_raw_cmd_ext *cmd_ext; struct bt_hci_raw_cmd_ext *cmd_ext;
static size_t cmd_ext_size; static size_t cmd_ext_size;
#if !DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_driver_register(const struct bt_hci_driver *drv)
{
if (bt_dev.drv) {
return -EALREADY;
}
if (!drv->open || !drv->send) {
return -EINVAL;
}
bt_dev.drv = drv;
LOG_DBG("Registered %s", drv->name ? drv->name : "");
bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, drv->bus,
BT_ADDR_ANY, drv->name ? drv->name : "bt0");
return 0;
}
#endif
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)
{ {
struct net_buf *buf; struct net_buf *buf;
@ -191,14 +172,10 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeou
return bt_buf_get_rx(BT_BUF_EVT, timeout); return bt_buf_get_rx(BT_BUF_EVT, timeout);
} }
#if DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_recv(const struct device *dev, struct net_buf *buf) int bt_hci_recv(const struct device *dev, struct net_buf *buf)
{ {
ARG_UNUSED(dev); ARG_UNUSED(dev);
#else
int bt_recv(struct net_buf *buf)
{
#endif
LOG_DBG("buf %p len %u", buf, buf->len); LOG_DBG("buf %p len %u", buf, buf->len);
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len); bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);
@ -243,11 +220,7 @@ static void bt_cmd_complete_ext(uint16_t op, uint8_t status)
cc = net_buf_add(buf, sizeof(*cc)); cc = net_buf_add(buf, sizeof(*cc));
cc->status = status; cc->status = status;
#if DT_HAS_CHOSEN(zephyr_bt_hci)
bt_hci_recv(bt_dev.hci, buf); bt_hci_recv(bt_dev.hci, buf);
#else
bt_recv(buf);
#endif
} }
static uint8_t bt_send_ext(struct net_buf *buf) static uint8_t bt_send_ext(struct net_buf *buf)
@ -327,11 +300,7 @@ int bt_send(struct net_buf *buf)
return bt_hci_ecc_send(buf); return bt_hci_ecc_send(buf);
} }
#if DT_HAS_CHOSEN(zephyr_bt_hci)
return bt_hci_send(bt_dev.hci, buf); return bt_hci_send(bt_dev.hci, buf);
#else
return bt_dev.drv->send(buf);
#endif
} }
int bt_hci_raw_set_mode(uint8_t mode) int bt_hci_raw_set_mode(uint8_t mode)
@ -375,7 +344,6 @@ int bt_enable_raw(struct k_fifo *rx_queue)
raw_rx = rx_queue; raw_rx = rx_queue;
#if DT_HAS_CHOSEN(zephyr_bt_hci)
if (!device_is_ready(bt_dev.hci)) { if (!device_is_ready(bt_dev.hci)) {
LOG_ERR("HCI driver is not ready"); LOG_ERR("HCI driver is not ready");
return -ENODEV; return -ENODEV;
@ -384,16 +352,6 @@ int bt_enable_raw(struct k_fifo *rx_queue)
bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME);
err = bt_hci_open(bt_dev.hci, bt_hci_recv); err = bt_hci_open(bt_dev.hci, bt_hci_recv);
#else
const struct bt_hci_driver *drv = bt_dev.drv;
if (!drv) {
LOG_ERR("No HCI driver registered");
return -ENODEV;
}
err = drv->open();
#endif
if (err) { if (err) {
LOG_ERR("HCI driver open failed (%d)", err); LOG_ERR("HCI driver open failed (%d)", err);
return err; return err;

View file

@ -14,17 +14,10 @@ extern "C" {
#endif #endif
struct bt_dev_raw { struct bt_dev_raw {
#if DT_HAS_CHOSEN(zephyr_bt_hci)
const struct device *hci; const struct device *hci;
#else
/* Registered HCI driver */
const struct bt_hci_driver *drv;
#endif
}; };
#if DT_HAS_CHOSEN(zephyr_bt_hci)
int bt_hci_recv(const struct device *dev, struct net_buf *buf); int bt_hci_recv(const struct device *dev, struct net_buf *buf);
#endif
extern struct bt_dev_raw bt_dev; extern struct bt_dev_raw bt_dev;

View file

@ -18,7 +18,7 @@
#include <zephyr/bluetooth/hci_raw.h> #include <zephyr/bluetooth/hci_raw.h>
#include <zephyr/bluetooth/l2cap.h> #include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/hci_vs.h> #include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include <zephyr/sys/atomic.h> #include <zephyr/sys/atomic.h>
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>

View file

@ -32,7 +32,7 @@
#include <zephyr/bluetooth/hci_raw.h> #include <zephyr/bluetooth/hci_raw.h>
#include <zephyr/bluetooth/l2cap.h> #include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/hci_vs.h> #include <zephyr/bluetooth/hci_vs.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include <zephyr/sys/atomic.h> #include <zephyr/sys/atomic.h>
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>