Bluetooth: host: extract sending of host num complete
The functionality is moved in preparation of the next commit which will re-use this function from somewhere else. Also add (default-on) asserts that we are able to allocate and send the command. If that is not the case, we will leak buffers from the PoV of the controller, leading to a stall in data transfer. Depending on the error, we could probably recover using a disconnection. For now, do the safe thing and stop the whole stack. Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
This commit is contained in:
parent
4284f99870
commit
32212bfb63
1 changed files with 30 additions and 20 deletions
|
@ -228,13 +228,39 @@ static void handle_vs_event(uint8_t event, struct net_buf *buf,
|
||||||
/* Other possible errors are handled by handle_event_common function */
|
/* Other possible errors are handled by handle_event_common function */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_send_one_host_num_completed_packets(uint16_t handle)
|
||||||
|
{
|
||||||
|
if (!IS_ENABLED(CONFIG_BT_HCI_ACL_FLOW_CONTROL)) {
|
||||||
|
ARG_UNUSED(handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bt_hci_cp_host_num_completed_packets *cp;
|
||||||
|
struct bt_hci_handle_count *hc;
|
||||||
|
struct net_buf *buf;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
LOG_DBG("Reporting completed packet for handle %u", handle);
|
||||||
|
|
||||||
|
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS,
|
||||||
|
sizeof(*cp) + sizeof(*hc));
|
||||||
|
BT_ASSERT_MSG(buf, "Unable to alloc for Host NCP");
|
||||||
|
|
||||||
|
cp = net_buf_add(buf, sizeof(*cp));
|
||||||
|
cp->num_handles = sys_cpu_to_le16(1);
|
||||||
|
|
||||||
|
hc = net_buf_add(buf, sizeof(*hc));
|
||||||
|
hc->handle = sys_cpu_to_le16(handle);
|
||||||
|
hc->count = sys_cpu_to_le16(1);
|
||||||
|
|
||||||
|
err = bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
|
||||||
|
BT_ASSERT_MSG(err == 0, "Unable to send Host NCP (err %d)", err);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
|
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
|
||||||
void bt_hci_host_num_completed_packets(struct net_buf *buf)
|
void bt_hci_host_num_completed_packets(struct net_buf *buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct bt_hci_cp_host_num_completed_packets *cp;
|
|
||||||
uint16_t handle = acl(buf)->handle;
|
uint16_t handle = acl(buf)->handle;
|
||||||
struct bt_hci_handle_count *hc;
|
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
uint8_t index = acl(buf)->index;
|
uint8_t index = acl(buf)->index;
|
||||||
|
|
||||||
|
@ -260,23 +286,7 @@ void bt_hci_host_num_completed_packets(struct net_buf *buf)
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
|
||||||
LOG_DBG("Reporting completed packet for handle %u", handle);
|
bt_send_one_host_num_completed_packets(handle);
|
||||||
|
|
||||||
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS,
|
|
||||||
sizeof(*cp) + sizeof(*hc));
|
|
||||||
if (!buf) {
|
|
||||||
LOG_ERR("Unable to allocate new HCI command");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cp = net_buf_add(buf, sizeof(*cp));
|
|
||||||
cp->num_handles = sys_cpu_to_le16(1);
|
|
||||||
|
|
||||||
hc = net_buf_add(buf, sizeof(*hc));
|
|
||||||
hc->handle = sys_cpu_to_le16(handle);
|
|
||||||
hc->count = sys_cpu_to_le16(1);
|
|
||||||
|
|
||||||
bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
|
|
||||||
}
|
}
|
||||||
#endif /* defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) */
|
#endif /* defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue