Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
bluetooth.h
Go to the documentation of this file.
1
8
14
15#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_
16#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_
17
28
29#include <stdbool.h>
30#include <stdint.h>
31#include <zephyr/net_buf.h>
35#include <zephyr/device.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
48
49enum {
50 /* The host should never send HCI_Reset */
52 /* The controller does not auto-initiate a DLE procedure when the
53 * initial connection data length parameters are not equal to the
54 * default data length parameters. Therefore the host should initiate
55 * the DLE procedure after connection establishment.
56 *
57 * That requirement is stated in Core Spec v5.4 Vol 6 Part B. 4.5.10
58 * Data PDU length management:
59 *
60 * > For a new connection:
61 * > - ... If either value is not 27, then the Controller should
62 * > initiate the Data Length Update procedure at the earliest
63 * > practical opportunity.
64 */
66};
67
83
84#define BT_DT_HCI_QUIRK_OR(node_id, prop, idx) \
85 UTIL_CAT(BT_HCI_QUIRK_, DT_STRING_UPPER_TOKEN_BY_IDX(node_id, prop, idx))
86#define BT_DT_HCI_QUIRKS_GET(node_id) COND_CODE_1(DT_NODE_HAS_PROP(node_id, bt_hci_quirks), \
87 (DT_FOREACH_PROP_ELEM_SEP(node_id, \
88 bt_hci_quirks, \
89 BT_DT_HCI_QUIRK_OR, \
90 (|))), \
91 (0))
92#define BT_DT_HCI_QUIRKS_INST_GET(inst) BT_DT_HCI_QUIRKS_GET(DT_DRV_INST(inst))
93
94#define BT_DT_HCI_NAME_GET(node_id) DT_PROP_OR(node_id, bt_hci_name, "HCI")
95#define BT_DT_HCI_NAME_INST_GET(inst) BT_DT_HCI_NAME_GET(DT_DRV_INST(inst))
96
97/* Fallback default when there's no property, same as "virtual" */
98#define BT_PRIV_HCI_BUS_DEFAULT (0)
99#define BT_DT_HCI_BUS_GET(node_id) DT_ENUM_IDX_OR(node_id, bt_hci_bus, BT_PRIV_HCI_BUS_DEFAULT)
100
101#define BT_DT_HCI_BUS_INST_GET(inst) BT_DT_HCI_BUS_GET(DT_DRV_INST(inst))
102
107
113typedef int (*bt_hci_recv_t)(const struct device *dev, struct net_buf *buf);
114
119typedef int (*bt_hci_api_open_t)(const struct device *dev, bt_hci_recv_t recv);
120
125typedef int (*bt_hci_api_close_t)(const struct device *dev);
126
131typedef int (*bt_hci_api_send_t)(const struct device *dev, struct net_buf *buf);
132
137typedef int (*bt_hci_api_setup_t)(const struct device *dev,
138 const struct bt_hci_setup_params *param);
139
143__subsystem struct bt_hci_driver_api {
156#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)
162#endif /* CONFIG_BT_HCI_SETUP */
163};
164
167
182static inline int bt_hci_open(const struct device *dev, bt_hci_recv_t recv)
183{
184 return DEVICE_API_GET(bt_hci, dev)->open(dev, recv);
185}
186
197static inline int bt_hci_close(const struct device *dev)
198{
199 const struct bt_hci_driver_api *api = DEVICE_API_GET(bt_hci, dev);
200
201 if (api->close == NULL) {
202 return -ENOSYS;
203 }
204
205 return api->close(dev);
206}
207
227static inline int bt_hci_send(const struct device *dev, struct net_buf *buf)
228{
229 return DEVICE_API_GET(bt_hci, dev)->send(dev, buf);
230}
231
232#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)
245static inline int bt_hci_setup(const struct device *dev, struct bt_hci_setup_params *params)
246{
247 const struct bt_hci_driver_api *api = DEVICE_API_GET(bt_hci, dev);
248
249 if (api->setup == NULL) {
250 return -ENOSYS;
251 }
252
253 return api->setup(dev, params);
254}
255#endif
256
260
261/* The following functions are not strictly part of the HCI driver API, in that
262 * they do not take as input a struct device which implements the HCI driver API.
263 */
264
276int bt_hci_transport_setup(const struct device *dev);
277
289int bt_hci_transport_teardown(const struct device *dev);
290
303
317
331
332#ifdef __cplusplus
333}
334#endif
335
336#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_ */
Bluetooth device address definitions and utilities.
Bluetooth data buffer API.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
struct net_buf * bt_hci_evt_create(uint8_t evt, uint8_t len)
Allocate an HCI event buffer.
struct net_buf * bt_hci_cmd_complete_create(uint16_t op, uint8_t plen)
Allocate an HCI Command Complete event buffer.
struct net_buf * bt_hci_cmd_status_create(uint16_t op, uint8_t status)
Allocate an HCI Command Status event buffer.
int bt_hci_transport_setup(const struct device *dev)
Setup the HCI transport, which usually means to reset the Bluetooth IC.
int bt_hci_transport_teardown(const struct device *dev)
Teardown the HCI transport.
int(* bt_hci_api_send_t)(const struct device *dev, struct net_buf *buf)
Callback API to send an HCI buffer to the controller.
Definition bluetooth.h:131
int(* bt_hci_recv_t)(const struct device *dev, struct net_buf *buf)
Deliver HCI data from the controller to the host.
Definition bluetooth.h:113
int(* bt_hci_api_close_t)(const struct device *dev)
Callback API to close the HCI transport.
Definition bluetooth.h:125
int(* bt_hci_api_setup_t)(const struct device *dev, const struct bt_hci_setup_params *param)
Callback API for HCI vendor-specific setup.
Definition bluetooth.h:137
int(* bt_hci_api_open_t)(const struct device *dev, bt_hci_recv_t recv)
Callback API to open the HCI transport.
Definition bluetooth.h:119
static int bt_hci_setup(const struct device *dev, struct bt_hci_setup_params *params)
HCI vendor-specific setup.
Definition bluetooth.h:245
static int bt_hci_send(const struct device *dev, struct net_buf *buf)
Send HCI buffer to controller.
Definition bluetooth.h:227
bt_hci_bus
Possible values for the 'bus' member of the bt_hci_driver struct.
Definition bluetooth.h:69
static int bt_hci_open(const struct device *dev, bt_hci_recv_t recv)
Open the HCI transport.
Definition bluetooth.h:182
static int bt_hci_close(const struct device *dev)
Close the HCI transport.
Definition bluetooth.h:197
@ BT_HCI_QUIRK_NO_AUTO_DLE
Definition bluetooth.h:65
@ BT_HCI_QUIRK_NO_RESET
Definition bluetooth.h:51
@ BT_HCI_BUS_VIRTUAL
Definition bluetooth.h:70
@ BT_HCI_BUS_USB
Definition bluetooth.h:71
@ BT_HCI_BUS_PCCARD
Definition bluetooth.h:72
@ BT_HCI_BUS_VIRTIO
Definition bluetooth.h:80
@ BT_HCI_BUS_SPI
Definition bluetooth.h:77
@ BT_HCI_BUS_UART
Definition bluetooth.h:73
@ BT_HCI_BUS_IPC
Definition bluetooth.h:81
@ BT_HCI_BUS_PCI
Definition bluetooth.h:75
@ BT_HCI_BUS_RS232
Definition bluetooth.h:74
@ BT_HCI_BUS_SDIO
Definition bluetooth.h:76
@ BT_HCI_BUS_I2C
Definition bluetooth.h:78
@ BT_HCI_BUS_SMD
Definition bluetooth.h:79
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
Buffer management.
ssize_t recv(int sock, void *buf, size_t max_len, int flags)
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Bluetooth Device Address.
Definition addr.h:40
<span class="mlabel">Driver Operations</span> Bluetooth HCI driver operations
Definition bluetooth.h:143
bt_hci_api_close_t close
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition bluetooth.h:151
bt_hci_api_send_t send
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition bluetooth.h:155
bt_hci_api_open_t open
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition bluetooth.h:147
bt_hci_api_setup_t setup
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition bluetooth.h:161
Definition bluetooth.h:41
bt_addr_t public_addr
The public identity address to give to the controller.
Definition bluetooth.h:46
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Network buffer representation.
Definition net_buf.h:1015
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1044