From dcb0840260b2856af0691980d0743d6e50e7abe8 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 10 Jan 2020 15:50:53 +0100 Subject: [PATCH] pkg/nimble_netif: catch L2CAP connection failures --- pkg/nimble/netif/nimble_netif.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index d41274d189..0a4b4a627e 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -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; @@ -371,6 +377,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);