Merge pull request #13084 from haukepetersen/opt_nimble_netifl2capabort

pkg/nimble_netif: catch L2CAP connection failures
This commit is contained in:
Hauke Petersen 2020-01-13 14:40:32 +01:00 committed by GitHub
commit 001a216e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -333,6 +333,12 @@ static int _on_l2cap_client_evt(struct ble_l2cap_event *event, void *arg)
switch (event->type) {
case BLE_L2CAP_EVENT_COC_CONNECTED:
if (event->connect.status != 0) {
/* in the unlikely event the L2CAP connection establishment
* fails, we close the GAP connection */
ble_gap_terminate(conn->gaphandle, BLE_ERR_REM_USER_CONN_TERM);
break;
}
conn->coc = event->connect.chan;
conn->state |= NIMBLE_NETIF_L2CAP_CLIENT;
conn->state &= ~NIMBLE_NETIF_CONNECTING;
@ -370,6 +376,13 @@ static int _on_l2cap_server_evt(struct ble_l2cap_event *event, void *arg)
handle = nimble_netif_conn_get_by_gaphandle(event->connect.conn_handle);
conn = nimble_netif_conn_get(handle);
assert(conn);
if (event->connect.status != 0) {
/* in the unlikely event the L2CAP connection establishment
* fails, we close the GAP connection */
ble_gap_terminate(conn->gaphandle, BLE_ERR_REM_USER_CONN_TERM);
break;
}
conn->coc = event->connect.chan;
conn->state |= NIMBLE_NETIF_L2CAP_SERVER;
conn->state &= ~(NIMBLE_NETIF_ADV | NIMBLE_NETIF_CONNECTING);