Bluetooth: Add bt_buf_get_rx() helper API

The separate ACL & event pools will soon be removed, and it's already
now convenient to have a generic API when the exact type of the
incoming packet is not yet known.

Change-Id: I84cb65d17ea69ebeaeb21532fbf76689e4fb59a0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-12-25 11:20:32 +02:00
commit 0174200cd0
3 changed files with 28 additions and 0 deletions

View file

@ -52,6 +52,17 @@ enum bt_buf_type {
sizeof(struct bt_hci_acl_hdr) + \
CONFIG_BLUETOOTH_RX_BUF_LEN)
/** 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);
/** Allocate a buffer for an HCI event
*
* This will set the BT_BUF_EVT buffer type so bt_buf_set_type()

View file

@ -4018,6 +4018,18 @@ struct net_buf *bt_buf_get_acl(int32_t timeout)
#endif /* CONFIG_BLUETOOTH_CONN */
}
struct net_buf *bt_buf_get_rx(int32_t timeout)
{
struct net_buf *buf;
buf = net_buf_alloc(&hci_rx_pool, timeout);
if (buf) {
net_buf_reserve(buf, CONFIG_BLUETOOTH_HCI_RECV_RESERVE);
}
return buf;
}
#if defined(CONFIG_BLUETOOTH_BREDR)
static int br_start_inquiry(const struct bt_br_discovery_param *param)
{

View file

@ -59,6 +59,11 @@ void bt_hci_driver_unregister(struct bt_hci_driver *drv)
bt_dev.drv = NULL;
}
struct net_buf *bt_buf_get_rx(int timeout)
{
return net_buf_alloc(&hci_rx_pool, timeout);
}
struct net_buf *bt_buf_get_evt(uint8_t opcode, int timeout)
{
struct net_buf *buf;