Skip to content

Commit 766a414

Browse files
committed
nimble/host: Fix controller to host flow control
Thiscode was not updated to use packed structs.
1 parent 4ceecdb commit 766a414

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

nimble/host/src/ble_hs_flow.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ static int
4444
ble_hs_flow_tx_num_comp_pkts(void)
4545
{
4646
uint8_t buf[
47-
BLE_HCI_HOST_NUM_COMP_PKTS_HDR_LEN +
48-
BLE_HCI_HOST_NUM_COMP_PKTS_ENT_LEN
47+
sizeof(struct ble_hci_cb_host_num_comp_pkts_cp) +
48+
sizeof(struct ble_hci_cb_host_num_comp_pkts_entry)
4949
];
50-
struct hci_host_num_comp_pkts_entry entry;
50+
struct ble_hci_cb_host_num_comp_pkts_cp *cmd = (void *) buf;
5151
struct ble_hs_conn *conn;
5252
int rc;
5353

@@ -62,16 +62,12 @@ ble_hs_flow_tx_num_comp_pkts(void)
6262

6363
if (conn->bhc_completed_pkts > 0) {
6464
/* Only specify one connection per command. */
65-
buf[0] = 1;
65+
/* TODO could combine this in single HCI command */
66+
cmd->handles = 1;
6667

6768
/* Append entry for this connection. */
68-
entry.conn_handle = conn->bhc_handle;
69-
entry.num_pkts = conn->bhc_completed_pkts;
70-
rc = ble_hs_hci_cmd_build_host_num_comp_pkts_entry(
71-
&entry,
72-
buf + BLE_HCI_HOST_NUM_COMP_PKTS_HDR_LEN,
73-
sizeof buf - BLE_HCI_HOST_NUM_COMP_PKTS_HDR_LEN);
74-
BLE_HS_DBG_ASSERT(rc == 0);
69+
cmd->h[0].handle = htole16(conn->bhc_handle);
70+
cmd->h[0].count = htole16(conn->bhc_completed_pkts);
7571

7672
conn->bhc_completed_pkts = 0;
7773

@@ -224,7 +220,11 @@ int
224220
ble_hs_flow_startup(void)
225221
{
226222
#if MYNEWT_VAL(BLE_HS_FLOW_CTRL)
227-
struct hci_host_buf_size buf_size_cmd;
223+
struct ble_hci_cb_ctlr_to_host_fc_cp enable_cmd;
224+
struct ble_hci_cb_host_buf_size_cp buf_size_cmd = {
225+
.acl_data_len = htole16(MYNEWT_VAL(BLE_ACL_BUF_SIZE)),
226+
.acl_num = htole16(MYNEWT_VAL(BLE_ACL_BUF_COUNT)),
227+
};
228228
int rc;
229229

230230
ble_npl_event_init(&ble_hs_flow_ev, ble_hs_flow_event_cb, NULL);
@@ -233,18 +233,23 @@ ble_hs_flow_startup(void)
233233
ble_hci_trans_set_acl_free_cb(NULL, NULL);
234234
ble_npl_callout_stop(&ble_hs_flow_timer);
235235

236-
rc = ble_hs_hci_cmd_tx_set_ctlr_to_host_fc(BLE_HCI_CTLR_TO_HOST_FC_ACL);
236+
enable_cmd.enable = BLE_HCI_CTLR_TO_HOST_FC_ACL;
237+
238+
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_CTLR_BASEBAND,
239+
BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC),
240+
&enable_cmd, sizeof(enable_cmd), NULL, 0);
237241
if (rc != 0) {
238242
return rc;
239243
}
240244

241-
buf_size_cmd = (struct hci_host_buf_size) {
242-
.acl_pkt_len = MYNEWT_VAL(BLE_ACL_BUF_SIZE),
243-
.num_acl_pkts = MYNEWT_VAL(BLE_ACL_BUF_COUNT),
244-
};
245-
rc = ble_hs_hci_cmd_tx_host_buf_size(&buf_size_cmd);
245+
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_CTLR_BASEBAND,
246+
BLE_HCI_OCF_CB_HOST_BUF_SIZE),
247+
&buf_size_cmd, sizeof(buf_size_cmd), NULL, 0);
246248
if (rc != 0) {
247-
ble_hs_hci_cmd_tx_set_ctlr_to_host_fc(BLE_HCI_CTLR_TO_HOST_FC_OFF);
249+
enable_cmd.enable = BLE_HCI_CTLR_TO_HOST_FC_OFF;
250+
ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_CTLR_BASEBAND,
251+
BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC),
252+
&enable_cmd, sizeof(enable_cmd), NULL, 0);
248253
return rc;
249254
}
250255

nimble/include/nimble/hci_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ struct ble_hci_cb_host_buf_size_cp {
114114
} __attribute__((packed));
115115

116116
#define BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS (0x0035)
117-
struct ble_hci_handle_count {
117+
struct ble_hci_cb_host_num_comp_pkts_entry {
118118
uint16_t handle;
119119
uint16_t count;
120-
} __packed;
120+
} __attribute__((packed));
121121
struct ble_hci_cb_host_num_comp_pkts_cp {
122122
uint8_t handles;
123-
struct ble_hci_handle_count h[0];
123+
struct ble_hci_cb_host_num_comp_pkts_entry h[0];
124124
} __attribute__((packed));
125125

126126
#define BLE_HCI_OCF_CB_SET_EVENT_MASK2 (0x0063)

0 commit comments

Comments
 (0)