nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req With this patch, if legacy device response with REJECT CMD on LE Create Base Connection request, application will be corretly notified.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/44df175e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/44df175e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/44df175e Branch: refs/heads/master Commit: 44df175e480d0935346edf5b5b8be3bfa03f3304 Parents: e488b9d Author: Åukasz Rymanowski <[email protected]> Authored: Sun Feb 12 21:49:47 2017 +0100 Committer: Åukasz Rymanowski <[email protected]> Committed: Fri Mar 3 12:40:42 2017 +0100 ---------------------------------------------------------------------- net/nimble/host/src/ble_l2cap_coc.c | 5 ++++ net/nimble/host/src/ble_l2cap_sig.c | 39 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44df175e/net/nimble/host/src/ble_l2cap_coc.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c index ec01fec..f7ecef4 100644 --- a/net/nimble/host/src/ble_l2cap_coc.c +++ b/net/nimble/host/src/ble_l2cap_coc.c @@ -281,6 +281,11 @@ ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan) { struct ble_l2cap_event event = { }; + /* FIXME */ + if (!chan->cb) { + return; + } + event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED; event.disconnect.conn_handle = chan->conn_handle; event.disconnect.chan = chan; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44df175e/net/nimble/host/src/ble_l2cap_sig.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c index b77fa3b..a33ddef 100644 --- a/net/nimble/host/src/ble_l2cap_sig.c +++ b/net/nimble/host/src/ble_l2cap_sig.c @@ -92,6 +92,7 @@ typedef int ble_l2cap_sig_rx_fn(uint16_t conn_handle, static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_noop; static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_req_rx; static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_rsp_rx; +static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_reject; #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_req_rx; @@ -108,7 +109,7 @@ static ble_l2cap_sig_rx_fn ble_l2cap_sig_le_credits_rx; #endif static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = { - [BLE_L2CAP_SIG_OP_REJECT] = ble_l2cap_sig_rx_noop, + [BLE_L2CAP_SIG_OP_REJECT] = ble_l2cap_sig_rx_reject, [BLE_L2CAP_SIG_OP_CONNECT_RSP] = ble_l2cap_sig_rx_noop, [BLE_L2CAP_SIG_OP_CONFIG_RSP] = ble_l2cap_sig_rx_noop, [BLE_L2CAP_SIG_OP_DISCONN_REQ] = ble_l2cap_sig_disc_req_rx, @@ -613,6 +614,15 @@ ble_l2cap_sig_coc_connect_cb(struct ble_l2cap_sig_proc *proc, int status) } ble_l2cap_event_coc_connected(chan, status); + + if (status) { + /* Normally in channel free we send disconnected event to application. + * However in case on error during creation connection we send connected + * event with error status. To avoid additional disconnected event lets + * clear callbacks since we don't needed it anymore.*/ + chan->cb = NULL; + ble_l2cap_chan_free(chan); + } } static int @@ -1037,6 +1047,33 @@ ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits) return ble_l2cap_sig_tx(chan->conn_handle, txom); } #endif + +static int +ble_l2cap_sig_rx_reject(uint16_t conn_handle, + struct ble_l2cap_sig_hdr *hdr, + struct os_mbuf **om) +{ + struct ble_l2cap_sig_proc *proc; + proc = ble_l2cap_sig_proc_extract(conn_handle, + BLE_L2CAP_SIG_PROC_OP_CONNECT, + hdr->identifier); + if (!proc) { + return 0; + } + + switch (proc->id) { +#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 + case BLE_L2CAP_SIG_PROC_OP_CONNECT: + ble_l2cap_sig_coc_connect_cb(proc, BLE_HS_EREJECT); + break; +#endif + default: + break; + } + + ble_l2cap_sig_proc_free(proc); + return 0; +} /***************************************************************************** * $misc * *****************************************************************************/
