2016-04-09 11:29:50 +03:00
|
|
|
/** @file
|
|
|
|
* @brief Bluetooth data buffer API
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-09 11:29:50 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BT_BUF_H
|
|
|
|
#define __BT_BUF_H
|
|
|
|
|
2016-05-16 19:54:24 +03: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 10:32:08 -05:00
|
|
|
#include <zephyr/types.h>
|
2016-04-09 11:29:50 +03:00
|
|
|
#include <net/buf.h>
|
2016-04-09 13:53:17 +03:00
|
|
|
#include <bluetooth/hci.h>
|
2016-04-09 11:29:50 +03:00
|
|
|
|
|
|
|
/** Possible types of buffers passed around the Bluetooth stack */
|
|
|
|
enum bt_buf_type {
|
2016-07-18 11:26:01 +02: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 11:29:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Minimum amount of user data size for buffers passed to the stack. */
|
|
|
|
#define BT_BUF_USER_DATA_MIN 4
|
|
|
|
|
2016-12-21 17:49:39 +02:00
|
|
|
/** Data size neeed for HCI RX buffers */
|
2017-02-01 12:59:11 +02:00
|
|
|
#define BT_BUF_RX_SIZE (CONFIG_BLUETOOTH_HCI_RESERVE + \
|
2016-12-21 17:49:39 +02:00
|
|
|
CONFIG_BLUETOOTH_RX_BUF_LEN)
|
2016-04-09 13:53:17 +03:00
|
|
|
|
2016-12-25 11:20:32 +02: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.
|
|
|
|
*/
|
2017-04-20 12:00:29 -05:00
|
|
|
struct net_buf *bt_buf_get_rx(s32_t timeout);
|
2016-12-25 11:20:32 +02:00
|
|
|
|
2017-02-01 17:37:14 +02: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().
|
|
|
|
*
|
|
|
|
* @param timeout Timeout in milliseconds, or one of the special values
|
|
|
|
* K_NO_WAIT and K_FOREVER.
|
|
|
|
* @return A new buffer.
|
|
|
|
*/
|
2017-04-20 12:00:29 -05:00
|
|
|
struct net_buf *bt_buf_get_cmd_complete(s32_t timeout);
|
2017-02-01 17:37:14 +02:00
|
|
|
|
2016-04-09 11:29:50 +03: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)
|
|
|
|
{
|
2017-04-20 12:00:29 -05:00
|
|
|
*(u8_t *)net_buf_user_data(buf) = type;
|
2016-04-09 11:29:50 +03: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)
|
|
|
|
{
|
2017-04-20 12:00:29 -05:00
|
|
|
return *(u8_t *)net_buf_user_data(buf);
|
2016-04-09 11:29:50 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 19:54:24 +03:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-04-09 11:29:50 +03:00
|
|
|
#endif /* __BT_BUF_H */
|