diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 847e6044a4f..7ed86ecb922 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -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 */ } +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) 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; - struct bt_hci_handle_count *hc; struct bt_conn *conn; 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); - 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)); - 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); + bt_send_one_host_num_completed_packets(handle); } #endif /* defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) */