Skip to content

Commit 153a7f6

Browse files
nimble/host: Rework L2CAP RX
1 parent 5ab995f commit 153a7f6

File tree

9 files changed

+153
-253
lines changed

9 files changed

+153
-253
lines changed

nimble/host/src/ble_att.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ ble_att_rx_extended(uint16_t conn_handle, uint16_t cid, struct os_mbuf **om)
563563
}
564564

565565
static int
566-
ble_att_rx(struct ble_l2cap_chan *chan)
566+
ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
567567
{
568568
uint16_t conn_handle;
569569

@@ -572,7 +572,7 @@ ble_att_rx(struct ble_l2cap_chan *chan)
572572
return BLE_HS_ENOTCONN;
573573
}
574574

575-
return ble_att_rx_extended(conn_handle, chan->scid, &chan->rx_buf);
575+
return ble_att_rx_extended(conn_handle, chan->scid, om);
576576
}
577577

578578
uint16_t

nimble/host/src/ble_hs_conn.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ ble_hs_conn_alloc(uint16_t conn_handle)
207207
void
208208
ble_hs_conn_delete_chan(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
209209
{
210-
if (conn->bhc_rx_chan == chan) {
211-
conn->bhc_rx_chan = NULL;
212-
}
213-
214210
SLIST_REMOVE(&conn->bhc_channels, chan, ble_l2cap_chan, next);
215211
ble_l2cap_chan_free(conn, chan);
216212
}
@@ -244,6 +240,9 @@ ble_hs_conn_free(struct ble_hs_conn *conn)
244240
return;
245241
}
246242

243+
os_mbuf_free_chain(conn->rx_frags);
244+
conn->rx_frags = NULL;
245+
247246
ble_att_svr_prep_clear(&conn->bhc_att_svr.basc_prep_list);
248247

249248
while ((chan = SLIST_FIRST(&conn->bhc_channels)) != NULL) {
@@ -504,8 +503,8 @@ ble_hs_conn_timer(void)
504503
* passes after a partial packet is received, the connection is
505504
* terminated.
506505
*/
507-
if (conn->bhc_rx_chan != NULL) {
508-
time_diff = conn->bhc_rx_timeout - now;
506+
if (conn->rx_len) {
507+
time_diff = conn->rx_frag_tmo - now;
509508

510509
if (time_diff <= 0) {
511510
/* ACL reassembly has timed out.*/

nimble/host/src/ble_hs_conn_priv.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,18 @@ struct ble_hs_conn {
6868
ble_hs_conn_flags_t bhc_flags;
6969

7070
struct ble_l2cap_chan_list bhc_channels;
71-
struct ble_l2cap_chan *bhc_rx_chan; /* Channel rxing current packet. */
72-
ble_npl_time_t bhc_rx_timeout;
71+
72+
/* ACL RX fragments */
73+
struct os_mbuf *rx_frags;
74+
/* Expected data length for ACL RX */
75+
uint16_t rx_len;
76+
/* L2CAP Source CID for ACL RX */
77+
uint16_t rx_cid;
78+
#if MYNEWT_VAL(BLE_L2CAP_RX_FRAG_TIMEOUT) != 0
79+
/* Timeout for next fragment for ACL RX */
80+
ble_npl_time_t rx_frag_tmo;
81+
#endif
82+
7383
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
7484
uint32_t l2cap_coc_cid_mask[BLE_HS_CONN_L2CAP_COC_CID_MASK_LEN];
7585
#endif

nimble/host/src/ble_hs_hci_evt.c

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,14 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
10981098
{
10991099
#if NIMBLE_BLE_CONNECT
11001100
struct hci_data_hdr hci_hdr;
1101-
struct ble_hs_conn *conn;
1102-
ble_l2cap_rx_fn *rx_cb;
11031101
uint16_t conn_handle;
1104-
int reject_cid;
1102+
uint8_t pb;
11051103
int rc;
11061104

11071105
rc = ble_hs_hci_util_data_hdr_strip(om, &hci_hdr);
11081106
if (rc != 0) {
1109-
goto err;
1107+
os_mbuf_free_chain(om);
1108+
return rc;
11101109
}
11111110

11121111
#if (BLETEST_THROUGHPUT_TEST == 0)
@@ -1122,50 +1121,14 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
11221121
#endif
11231122

11241123
if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
1125-
rc = BLE_HS_EBADDATA;
1126-
goto err;
1124+
os_mbuf_free_chain(om);
1125+
return BLE_HS_EBADDATA;
11271126
}
11281127

11291128
conn_handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
1129+
pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
1130+
rc = ble_l2cap_rx(conn_handle, pb, om);
11301131

1131-
ble_hs_lock();
1132-
1133-
conn = ble_hs_conn_find(conn_handle);
1134-
if (conn == NULL) {
1135-
/* Peer not connected; quietly discard packet. */
1136-
rc = BLE_HS_ENOTCONN;
1137-
reject_cid = -1;
1138-
} else {
1139-
/* Forward ACL data to L2CAP. */
1140-
rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &reject_cid);
1141-
om = NULL;
1142-
}
1143-
1144-
ble_hs_unlock();
1145-
1146-
switch (rc) {
1147-
case 0:
1148-
/* Final fragment received. */
1149-
BLE_HS_DBG_ASSERT(rx_cb != NULL);
1150-
rc = rx_cb(conn->bhc_rx_chan);
1151-
ble_l2cap_remove_rx(conn, conn->bhc_rx_chan);
1152-
break;
1153-
1154-
case BLE_HS_EAGAIN:
1155-
/* More fragments on the way. */
1156-
break;
1157-
1158-
default:
1159-
if (reject_cid != -1) {
1160-
ble_l2cap_sig_reject_invalid_cid_tx(conn_handle, 0, 0, reject_cid);
1161-
}
1162-
goto err;
1163-
}
1164-
1165-
return 0;
1166-
1167-
err:
1168-
os_mbuf_free_chain(om);
11691132
return rc;
11701133
#else
11711134
return BLE_HS_ENOTSUP;

0 commit comments

Comments
 (0)