Skip to content

Commit e5b66a7

Browse files
jori-nordiccvinayak
authored andcommitted
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 <[email protected]> (cherry picked from commit 32212bf) Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent b2a5527 commit e5b66a7

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,39 @@ static void handle_vs_event(uint8_t event, struct net_buf *buf,
196196
/* Other possible errors are handled by handle_event_common function */
197197
}
198198

199-
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
200-
void bt_hci_host_num_completed_packets(struct net_buf *buf)
199+
void bt_send_one_host_num_completed_packets(uint16_t handle)
201200
{
201+
if (!IS_ENABLED(CONFIG_BT_HCI_ACL_FLOW_CONTROL)) {
202+
ARG_UNUSED(handle);
203+
return;
204+
}
202205

203206
struct bt_hci_cp_host_num_completed_packets *cp;
204-
uint16_t handle = acl(buf)->handle;
205207
struct bt_hci_handle_count *hc;
208+
struct net_buf *buf;
209+
int err;
210+
211+
LOG_DBG("Reporting completed packet for handle %u", handle);
212+
213+
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS,
214+
sizeof(*cp) + sizeof(*hc));
215+
BT_ASSERT_MSG(buf, "Unable to alloc for Host NCP");
216+
217+
cp = net_buf_add(buf, sizeof(*cp));
218+
cp->num_handles = sys_cpu_to_le16(1);
219+
220+
hc = net_buf_add(buf, sizeof(*hc));
221+
hc->handle = sys_cpu_to_le16(handle);
222+
hc->count = sys_cpu_to_le16(1);
223+
224+
err = bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
225+
BT_ASSERT_MSG(err == 0, "Unable to send Host NCP (err %d)", err);
226+
}
227+
228+
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
229+
void bt_hci_host_num_completed_packets(struct net_buf *buf)
230+
{
231+
uint16_t handle = acl(buf)->handle;
206232
struct bt_conn *conn;
207233
uint8_t index = acl(buf)->index;
208234

@@ -228,23 +254,7 @@ void bt_hci_host_num_completed_packets(struct net_buf *buf)
228254

229255
bt_conn_unref(conn);
230256

231-
LOG_DBG("Reporting completed packet for handle %u", handle);
232-
233-
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS,
234-
sizeof(*cp) + sizeof(*hc));
235-
if (!buf) {
236-
LOG_ERR("Unable to allocate new HCI command");
237-
return;
238-
}
239-
240-
cp = net_buf_add(buf, sizeof(*cp));
241-
cp->num_handles = sys_cpu_to_le16(1);
242-
243-
hc = net_buf_add(buf, sizeof(*hc));
244-
hc->handle = sys_cpu_to_le16(handle);
245-
hc->count = sys_cpu_to_le16(1);
246-
247-
bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
257+
bt_send_one_host_num_completed_packets(handle);
248258
}
249259
#endif /* defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) */
250260

0 commit comments

Comments
 (0)