nimble/l2cap: Improve L2CAP LE CoC connection handling With this patch we make sure remote does not use already used CID
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/687403eb Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/687403eb Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/687403eb Branch: refs/heads/1_0_0_dev Commit: 687403eb222dc00e72e82345c62228fc9ab42048 Parents: 01835da Author: Åukasz Rymanowski <[email protected]> Authored: Wed Mar 1 11:42:43 2017 +0100 Committer: Marko Kiiskila <[email protected]> Committed: Mon Mar 6 15:53:37 2017 -0800 ---------------------------------------------------------------------- net/nimble/host/src/ble_l2cap_sig.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/687403eb/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 439acfe..1840b0a 100644 --- a/net/nimble/host/src/ble_l2cap_sig.c +++ b/net/nimble/host/src/ble_l2cap_sig.c @@ -658,14 +658,19 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr, ble_hs_lock(); conn = ble_hs_conn_find_assert(conn_handle); - /* Verify CID */ + /* Verify CID. Note, scid in the request is dcid for out local channel */ scid = le16toh(req->scid); if (scid < BLE_L2CAP_COC_CID_START || scid > BLE_L2CAP_COC_CID_END) { - /*FIXME: Check if SCID is not already used */ rsp->result = htole16(BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID); goto failed; } + chan = ble_hs_conn_chan_find_by_dcid(conn, scid); + if (chan) { + rsp->result = htole16(BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED); + goto failed; + } + rc = ble_l2cap_coc_create_srv_chan(conn_handle, le16toh(req->psm), &chan); if (rc != 0) { uint16_t coc_err = ble_l2cap_sig_ble_hs_err2coc_err(rc);
