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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BT_BUF_H
|
|
|
|
#define __BT_BUF_H
|
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @brief Data buffers
|
|
|
|
* @defgroup bt_buf Data buffers
|
|
|
|
* @ingroup bluetooth
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-04-09 16:29:50 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#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,
|
2016-04-09 16:29:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Minimum amount of user data size for buffers passed to the stack. */
|
|
|
|
#define BT_BUF_USER_DATA_MIN 4
|
|
|
|
|
2016-12-21 23:49:39 +08:00
|
|
|
/** Data size neeed for HCI RX buffers */
|
|
|
|
#define BT_BUF_RX_SIZE (CONFIG_BLUETOOTH_HCI_RECV_RESERVE + \
|
|
|
|
CONFIG_BLUETOOTH_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
|
|
|
|
*
|
|
|
|
* This will not set the buffer type so bt_buf_set_type() needs to be called
|
|
|
|
* before bt_recv().
|
|
|
|
*
|
|
|
|
* @param timeout Timeout in milliseconds, or one of the special values
|
|
|
|
* K_NO_WAIT and K_FOREVER.
|
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
|
|
|
struct net_buf *bt_buf_get_rx(int32_t timeout);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
*(uint8_t *)net_buf_user_data(buf) = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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)
|
|
|
|
{
|
|
|
|
return *(uint8_t *)net_buf_user_data(buf);
|
|
|
|
}
|
|
|
|
|
2016-05-17 00:54:24 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-04-09 16:29:50 +08:00
|
|
|
#endif /* __BT_BUF_H */
|