2016-04-09 16:29:50 +08:00
|
|
|
/** @file
|
|
|
|
* @brief Bluetooth data buffer API
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-09 16:29:50 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
|
|
|
|
#define ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
|
2016-04-09 16:29:50 +08:00
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @brief Data buffers
|
|
|
|
* @defgroup bt_buf Data buffers
|
|
|
|
* @ingroup bluetooth
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-04-09 16:29:50 +08:00
|
|
|
#include <net/buf.h>
|
2016-04-09 18:53:17 +08:00
|
|
|
#include <bluetooth/hci.h>
|
2016-04-09 16:29:50 +08:00
|
|
|
|
|
|
|
/** Possible types of buffers passed around the Bluetooth stack */
|
|
|
|
enum bt_buf_type {
|
2016-07-18 17:26:01 +08:00
|
|
|
/** HCI command */
|
|
|
|
BT_BUF_CMD,
|
|
|
|
/** HCI event */
|
|
|
|
BT_BUF_EVT,
|
|
|
|
/** Outgoing ACL data */
|
|
|
|
BT_BUF_ACL_OUT,
|
|
|
|
/** Incoming ACL data */
|
|
|
|
BT_BUF_ACL_IN,
|
2020-05-12 06:13:59 +08:00
|
|
|
/** Outgoing ISO data */
|
|
|
|
BT_BUF_ISO_OUT,
|
|
|
|
/** Incoming ISO data */
|
|
|
|
BT_BUF_ISO_IN,
|
2020-04-08 05:32:43 +08:00
|
|
|
/** H:4 data */
|
|
|
|
BT_BUF_H4,
|
2016-04-09 16:29:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Minimum amount of user data size for buffers passed to the stack. */
|
2019-11-27 02:59:03 +08:00
|
|
|
#define BT_BUF_USER_DATA_MIN __DEPRECATED_MACRO 4
|
2016-04-09 16:29:50 +08:00
|
|
|
|
2019-11-12 23:02:13 +08:00
|
|
|
#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
|
|
|
|
|
2020-01-10 16:23:09 +08:00
|
|
|
#define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
|
|
|
|
|
2016-12-21 23:49:39 +08:00
|
|
|
/** Data size neeed for HCI RX buffers */
|
2020-01-10 16:23:09 +08:00
|
|
|
#define BT_BUF_RX_SIZE (BT_BUF_SIZE(CONFIG_BT_RX_BUF_LEN))
|
2016-04-09 18:53:17 +08:00
|
|
|
|
2016-12-25 17:20:32 +08:00
|
|
|
/** Allocate a buffer for incoming data
|
|
|
|
*
|
2017-05-04 16:25:28 +08:00
|
|
|
* This will set the buffer type so bt_buf_set_type() does not need to
|
|
|
|
* be explicitly called before bt_recv_prio().
|
2016-12-25 17:20:32 +08:00
|
|
|
*
|
2017-05-04 16:25:28 +08:00
|
|
|
* @param type Type of buffer. Only BT_BUF_EVT and BT_BUF_ACL_IN are
|
|
|
|
* allowed.
|
2020-04-06 19:33:41 +08:00
|
|
|
* @param timeout Non-negative waiting period to obtain a buffer or one of the
|
|
|
|
* special values K_NO_WAIT and K_FOREVER.
|
2016-12-25 17:20:32 +08:00
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
2020-04-06 19:33:41 +08:00
|
|
|
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
|
2016-12-25 17:20:32 +08:00
|
|
|
|
2020-04-08 05:32:43 +08:00
|
|
|
/** Allocate a buffer for outgoing data
|
|
|
|
*
|
|
|
|
* This will set the buffer type so bt_buf_set_type() does not need to
|
|
|
|
* be explicitly called before bt_send().
|
|
|
|
*
|
|
|
|
* @param type Type of buffer. Only BT_BUF_CMD, BT_BUF_ACL_OUT or
|
|
|
|
* BT_BUF_H4, when operating on H:4 mode, are allowed.
|
2020-04-06 19:33:41 +08:00
|
|
|
* @param timeout Non-negative waiting period to obtain a buffer or one of the
|
|
|
|
* special values K_NO_WAIT and K_FOREVER.
|
2020-04-08 05:32:43 +08:00
|
|
|
* @param data Initial data to append to buffer.
|
|
|
|
* @param size Initial data size.
|
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
2020-04-06 19:33:41 +08:00
|
|
|
struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout,
|
2020-04-08 05:32:43 +08:00
|
|
|
const void *data, size_t size);
|
|
|
|
|
2017-02-01 23:37:14 +08:00
|
|
|
/** Allocate a buffer for an HCI Command Complete/Status Event
|
|
|
|
*
|
|
|
|
* This will set the buffer type so bt_buf_set_type() does not need to
|
|
|
|
* be explicitly called before bt_recv_prio().
|
|
|
|
*
|
2020-04-06 19:33:41 +08:00
|
|
|
* @param timeout Non-negative waiting period to obtain a buffer or one of the
|
|
|
|
* special values K_NO_WAIT and K_FOREVER.
|
2017-02-01 23:37:14 +08:00
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
2020-04-06 19:33:41 +08:00
|
|
|
struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout);
|
2017-02-01 23:37:14 +08:00
|
|
|
|
2019-06-17 20:54:45 +08:00
|
|
|
/** Allocate a buffer for an HCI Event
|
|
|
|
*
|
|
|
|
* This will set the buffer type so bt_buf_set_type() does not need to
|
|
|
|
* be explicitly called before bt_recv_prio() or bt_recv().
|
|
|
|
*
|
2019-06-28 17:09:36 +08:00
|
|
|
* @param evt HCI event code
|
|
|
|
* @param discardable Whether the driver considers the event discardable.
|
2020-04-06 19:33:41 +08:00
|
|
|
* @param timeout Non-negative waiting period to obtain a buffer or one of
|
|
|
|
* the special values K_NO_WAIT and K_FOREVER.
|
2019-06-17 20:54:45 +08:00
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
2020-05-28 00:26:57 +08:00
|
|
|
struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout);
|
2019-06-17 20:54:45 +08:00
|
|
|
|
2016-04-09 16:29:50 +08:00
|
|
|
/** Set the buffer type
|
|
|
|
*
|
|
|
|
* @param buf Bluetooth buffer
|
|
|
|
* @param type The BT_* type to set the buffer to
|
|
|
|
*/
|
|
|
|
static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
|
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
*(uint8_t *)net_buf_user_data(buf) = type;
|
2016-04-09 16:29:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the buffer type
|
|
|
|
*
|
|
|
|
* @param buf Bluetooth buffer
|
|
|
|
*
|
|
|
|
* @return The BT_* type to of the buffer
|
|
|
|
*/
|
|
|
|
static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
|
|
|
|
{
|
2018-01-29 22:07:45 +08:00
|
|
|
/* De-referencing the pointer from net_buf_user_data(buf) as a
|
|
|
|
* pointer to an enum causes issues on qemu_x86 because the true
|
|
|
|
* size is 8-bit, but the enum is 32-bit on qemu_x86. So we put in
|
|
|
|
* a temporary cast to 8-bit to ensure only 8 bits are read from
|
|
|
|
* the pointer.
|
|
|
|
*/
|
2020-05-28 00:26:57 +08:00
|
|
|
return (enum bt_buf_type)(*(uint8_t *)net_buf_user_data(buf));
|
2016-04-09 16:29:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_ */
|