Bluetooth: Introduce buffer type parameter to bt_buf_get_rx
This is preparation for re-introducing host flow control. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
ccd4d4f401
commit
70e09b11ea
8 changed files with 28 additions and 31 deletions
|
@ -167,7 +167,11 @@ static struct net_buf *get_rx(int timeout)
|
|||
return bt_buf_get_cmd_complete(timeout);
|
||||
}
|
||||
|
||||
return bt_buf_get_rx(timeout);
|
||||
if (rx.type == H4_ACL) {
|
||||
return bt_buf_get_rx(BT_BUF_ACL_IN, timeout);
|
||||
} else {
|
||||
return bt_buf_get_rx(BT_BUF_EVT, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
static void rx_thread(void *p1, void *p2, void *p3)
|
||||
|
|
|
@ -412,12 +412,11 @@ static inline struct net_buf *get_evt_buf(u8_t evt)
|
|||
buf = bt_buf_get_cmd_complete(K_NO_WAIT);
|
||||
break;
|
||||
default:
|
||||
buf = bt_buf_get_rx(K_NO_WAIT);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT);
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
bt_buf_set_type(h5.rx_buf, BT_BUF_EVT);
|
||||
net_buf_add_u8(h5.rx_buf, evt);
|
||||
}
|
||||
|
||||
|
@ -489,14 +488,14 @@ static void bt_uart_isr(struct device *unused)
|
|||
h5.rx_state = PAYLOAD;
|
||||
break;
|
||||
case HCI_ACLDATA_PKT:
|
||||
h5.rx_buf = bt_buf_get_rx(K_NO_WAIT);
|
||||
h5.rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN,
|
||||
K_NO_WAIT);
|
||||
if (!h5.rx_buf) {
|
||||
BT_WARN("No available data buffers");
|
||||
h5_reset_rx();
|
||||
continue;
|
||||
}
|
||||
|
||||
bt_buf_set_type(h5.rx_buf, BT_BUF_ACL_IN);
|
||||
h5.rx_state = PAYLOAD;
|
||||
break;
|
||||
case HCI_3WIRE_LINK_PKT:
|
||||
|
|
|
@ -181,17 +181,15 @@ static void bt_spi_rx_thread(void)
|
|||
buf = bt_buf_get_cmd_complete(K_FOREVER);
|
||||
break;
|
||||
default:
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
break;
|
||||
}
|
||||
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
net_buf_add_mem(buf, &rxmsg[1],
|
||||
rxmsg[EVT_HEADER_SIZE] + 2);
|
||||
break;
|
||||
case HCI_ACL:
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
bt_buf_set_type(buf, BT_BUF_ACL_IN);
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
|
||||
memcpy(&acl_hdr, &rxmsg[1], sizeof(acl_hdr));
|
||||
net_buf_add_mem(buf, &acl_hdr, sizeof(acl_hdr));
|
||||
net_buf_add_mem(buf, &rxmsg[5],
|
||||
|
|
|
@ -43,14 +43,16 @@ enum bt_buf_type {
|
|||
|
||||
/** 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().
|
||||
* This will set the buffer type so bt_buf_set_type() does not need to
|
||||
* be explicitly called before bt_recv_prio().
|
||||
*
|
||||
* @param type Type of buffer. Only BT_BUF_EVT and BT_BUF_ACL_IN are
|
||||
* allowed.
|
||||
* @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(s32_t timeout);
|
||||
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout);
|
||||
|
||||
/** Allocate a buffer for an HCI Command Complete/Status Event
|
||||
*
|
||||
|
|
|
@ -72,8 +72,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
|
|||
#if defined(CONFIG_BLUETOOTH_CONN)
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
hci_num_cmplt_encode(buf, handle, num_cmplt);
|
||||
BT_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt);
|
||||
bt_recv_prio(buf);
|
||||
|
@ -117,20 +116,18 @@ static inline struct net_buf *encode_node(struct radio_pdu_node_rx *node_rx,
|
|||
case HCI_CLASS_EVT_REQUIRED:
|
||||
case HCI_CLASS_EVT_CONNECTION:
|
||||
if (class == HCI_CLASS_EVT_DISCARDABLE) {
|
||||
buf = bt_buf_get_rx(K_NO_WAIT);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT);
|
||||
} else {
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
}
|
||||
if (buf) {
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
hci_evt_encode(node_rx, buf);
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_BLUETOOTH_CONN)
|
||||
case HCI_CLASS_ACL_DATA:
|
||||
/* generate ACL data */
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
bt_buf_set_type(buf, BT_BUF_ACL_IN);
|
||||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
|
||||
hci_acl_encode(node_rx, buf);
|
||||
break;
|
||||
#endif
|
||||
|
|
|
@ -4101,13 +4101,17 @@ int bt_le_scan_stop(void)
|
|||
return bt_le_scan_update(false);
|
||||
}
|
||||
|
||||
struct net_buf *bt_buf_get_rx(s32_t timeout)
|
||||
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
|
||||
__ASSERT(type == BT_BUF_EVT || type == BT_BUF_ACL_IN,
|
||||
"Invalid buffer type requested");
|
||||
|
||||
buf = net_buf_alloc(&hci_rx_pool, timeout);
|
||||
if (buf) {
|
||||
net_buf_reserve(buf, CONFIG_BLUETOOTH_HCI_RESERVE);
|
||||
bt_buf_set_type(buf, type);
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
@ -4133,12 +4137,7 @@ struct net_buf *bt_buf_get_cmd_complete(s32_t timeout)
|
|||
return buf;
|
||||
}
|
||||
|
||||
buf = bt_buf_get_rx(timeout);
|
||||
if (buf) {
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
}
|
||||
|
||||
return buf;
|
||||
return bt_buf_get_rx(BT_BUF_EVT, timeout);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLUETOOTH_BREDR)
|
||||
|
|
|
@ -137,8 +137,7 @@ static void emulate_le_p256_public_key_cmd(void)
|
|||
|
||||
status = generate_keys();
|
||||
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
|
||||
hdr = net_buf_add(buf, sizeof(*hdr));
|
||||
hdr->evt = BT_HCI_EVT_LE_META_EVENT;
|
||||
|
@ -176,8 +175,7 @@ static void emulate_le_generate_dhkey(void)
|
|||
ret = ecdh_shared_secret(ecc.dhkey, &ecc.pk, ecc.private_key);
|
||||
}
|
||||
|
||||
buf = bt_buf_get_rx(K_FOREVER);
|
||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||
buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER);
|
||||
|
||||
hdr = net_buf_add(buf, sizeof(*hdr));
|
||||
hdr->evt = BT_HCI_EVT_LE_META_EVENT;
|
||||
|
|
|
@ -45,7 +45,7 @@ int bt_hci_driver_register(const struct bt_hci_driver *drv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct net_buf *bt_buf_get_rx(s32_t timeout)
|
||||
struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
|
||||
{
|
||||
return net_buf_alloc(&hci_rx_pool, timeout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue