123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #ifndef ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
- #define ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
- #include <zephyr/types.h>
- #include <net/buf.h>
- #include <bluetooth/hci.h>
- #include <sys/util.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- enum bt_buf_type {
-
- BT_BUF_CMD,
-
- BT_BUF_EVT,
-
- BT_BUF_ACL_OUT,
-
- BT_BUF_ACL_IN,
-
- BT_BUF_ISO_OUT,
-
- BT_BUF_ISO_IN,
-
- BT_BUF_H4,
-
- BT_BUF_SCO_OUT,
-
- BT_BUF_SCO_IN,
- };
- struct bt_buf_data {
- uint8_t type;
- };
- #if defined(CONFIG_BT_HCI_RAW)
- #define BT_BUF_RESERVE MAX(CONFIG_BT_HCI_RESERVE, CONFIG_BT_HCI_RAW_RESERVE)
- #else
- #define BT_BUF_RESERVE CONFIG_BT_HCI_RESERVE
- #endif
- #define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
- #define BT_BUF_ACL_SIZE(size) BT_BUF_SIZE(BT_HCI_ACL_HDR_SIZE + (size))
- #define BT_BUF_EVT_SIZE(size) BT_BUF_SIZE(BT_HCI_EVT_HDR_SIZE + (size))
- #define BT_BUF_CMD_SIZE(size) BT_BUF_SIZE(BT_HCI_CMD_HDR_SIZE + (size))
- #define BT_BUF_ACL_RX_SIZE BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE)
- #define BT_BUF_EVT_RX_SIZE BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_RX_SIZE)
- #define BT_BUF_RX_SIZE (MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE))
- #define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
- struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
- struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout,
- const void *data, size_t size);
- struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout);
- struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout);
- static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
- {
- ((struct bt_buf_data *)net_buf_user_data(buf))->type = type;
- }
- static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
- {
- return (enum bt_buf_type)((struct bt_buf_data *)net_buf_user_data(buf))
- ->type;
- }
- struct net_buf *bt_buf_get_rx_len(enum bt_buf_type type, k_timeout_t timeout, int len);
- struct net_buf *bt_buf_get_evt_len(uint8_t evt, bool discardable,
- k_timeout_t timeout, int len);
- #ifdef __cplusplus
- }
- #endif
- #endif
|