Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
bluetooth.h
Go to the documentation of this file.
1
8#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_
9#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_
10
22#include <stdbool.h>
23#include <stdint.h>
24#include <zephyr/net_buf.h>
28#include <zephyr/device.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
41
42enum {
43 /* The host should never send HCI_Reset */
45 /* The controller does not auto-initiate a DLE procedure when the
46 * initial connection data length parameters are not equal to the
47 * default data length parameters. Therefore the host should initiate
48 * the DLE procedure after connection establishment.
49 *
50 * That requirement is stated in Core Spec v5.4 Vol 6 Part B. 4.5.10
51 * Data PDU length management:
52 *
53 * > For a new connection:
54 * > - ... If either value is not 27, then the Controller should
55 * > initiate the Data Length Update procedure at the earliest
56 * > practical opportunity.
57 */
59};
60
74
75#define BT_DT_HCI_QUIRK_OR(node_id, prop, idx) \
76 UTIL_CAT(BT_HCI_QUIRK_, DT_STRING_UPPER_TOKEN_BY_IDX(node_id, prop, idx))
77#define BT_DT_HCI_QUIRKS_GET(node_id) COND_CODE_1(DT_NODE_HAS_PROP(node_id, bt_hci_quirks), \
78 (DT_FOREACH_PROP_ELEM_SEP(node_id, \
79 bt_hci_quirks, \
80 BT_DT_HCI_QUIRK_OR, \
81 (|))), \
82 (0))
83#define BT_DT_HCI_QUIRKS_INST_GET(inst) BT_DT_HCI_QUIRKS_GET(DT_DRV_INST(inst))
84
85#define BT_DT_HCI_NAME_GET(node_id) DT_PROP_OR(node_id, bt_hci_name, "HCI")
86#define BT_DT_HCI_NAME_INST_GET(inst) BT_DT_HCI_NAME_GET(DT_DRV_INST(inst))
87
88#define BT_DT_HCI_BUS_GET(node_id) \
89 UTIL_CAT(BT_HCI_BUS_, DT_STRING_UPPER_TOKEN_OR(node_id, bt_hci_bus, VIRTUAL))
90#define BT_DT_HCI_BUS_INST_GET(inst) BT_DT_HCI_BUS_GET(DT_DRV_INST(inst))
91
92typedef int (*bt_hci_recv_t)(const struct device *dev, struct net_buf *buf);
93
94__subsystem struct bt_hci_driver_api {
95 int (*open)(const struct device *dev, bt_hci_recv_t recv);
96 int (*close)(const struct device *dev);
97 int (*send)(const struct device *dev, struct net_buf *buf);
98#if defined(CONFIG_BT_HCI_SETUP)
99 int (*setup)(const struct device *dev,
100 const struct bt_hci_setup_params *param);
101#endif /* defined(CONFIG_BT_HCI_SETUP) */
102};
103
119static inline int bt_hci_open(const struct device *dev, bt_hci_recv_t recv)
120{
121 const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api;
122
123 return api->open(dev, recv);
124}
125
136static inline int bt_hci_close(const struct device *dev)
137{
138 const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api;
139
140 if (api->close == NULL) {
141 return -ENOSYS;
142 }
143
144 return api->close(dev);
145}
146
160static inline int bt_hci_send(const struct device *dev, struct net_buf *buf)
161{
162 const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api;
163
164 return api->send(dev, buf);
165}
166
167#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)
180static inline int bt_hci_setup(const struct device *dev, struct bt_hci_setup_params *params)
181{
182 const struct bt_hci_driver_api *api = (const struct bt_hci_driver_api *)dev->api;
183
184 if (api->setup == NULL) {
185 return -ENOSYS;
186 }
187
188 return api->setup(dev, params);
189}
190#endif
191
196/* The following functions are not strictly part of the HCI driver API, in that
197 * they do not take as input a struct device which implements the HCI driver API.
198 */
199
211int bt_hci_transport_setup(const struct device *dev);
212
224int bt_hci_transport_teardown(const struct device *dev);
225
238
252
266
267#ifdef __cplusplus
268}
269#endif
270
271#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_H_ */
Bluetooth device address definitions and utilities.
Bluetooth data buffer API.
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.
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition socket.h:929
static int bt_hci_setup(const struct device *dev, struct bt_hci_setup_params *params)
HCI vendor-specific setup.
Definition bluetooth.h:180
static int bt_hci_send(const struct device *dev, struct net_buf *buf)
Send HCI buffer to controller.
Definition bluetooth.h:160
int(* bt_hci_recv_t)(const struct device *dev, struct net_buf *buf)
Definition bluetooth.h:92
bt_hci_bus
Possible values for the 'bus' member of the bt_hci_driver struct.
Definition bluetooth.h:62
static int bt_hci_open(const struct device *dev, bt_hci_recv_t recv)
Open the HCI transport.
Definition bluetooth.h:119
static int bt_hci_close(const struct device *dev)
Close the HCI transport.
Definition bluetooth.h:136
@ BT_HCI_BUS_VIRTUAL
Definition bluetooth.h:63
@ BT_HCI_BUS_USB
Definition bluetooth.h:64
@ BT_HCI_BUS_IPM
Definition bluetooth.h:72
@ BT_HCI_BUS_PCCARD
Definition bluetooth.h:65
@ BT_HCI_BUS_SPI
Definition bluetooth.h:70
@ BT_HCI_BUS_UART
Definition bluetooth.h:66
@ BT_HCI_BUS_PCI
Definition bluetooth.h:68
@ BT_HCI_BUS_RS232
Definition bluetooth.h:67
@ BT_HCI_BUS_SDIO
Definition bluetooth.h:69
@ BT_HCI_BUS_I2C
Definition bluetooth.h:71
@ BT_HCI_QUIRK_NO_AUTO_DLE
Definition bluetooth.h:58
@ BT_HCI_QUIRK_NO_RESET
Definition bluetooth.h:44
#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
Buffer management.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Bluetooth Device Address.
Definition addr.h:40
Definition bluetooth.h:94
int(* open)(const struct device *dev, bt_hci_recv_t recv)
Definition bluetooth.h:95
int(* close)(const struct device *dev)
Definition bluetooth.h:96
int(* send)(const struct device *dev, struct net_buf *buf)
Definition bluetooth.h:97
Definition bluetooth.h:34
bt_addr_t public_addr
The public identity address to give to the controller.
Definition bluetooth.h:39
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
Network buffer representation.
Definition net_buf.h:1006
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1035