Repository: incubator-mynewt-core Updated Branches: refs/heads/develop e128963da -> 02ab1a63b
BLE Host - Add "black hole" L2CAP CID. This L2CAP channel is only useful for testing. Sometimes we don't want "invalid CID" responses to be sent. 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/02ab1a63 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/02ab1a63 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/02ab1a63 Branch: refs/heads/develop Commit: 02ab1a63be4c5403c855e090e8613172c743c68d Parents: e128963 Author: Christopher Collins <[email protected]> Authored: Sun Jun 5 13:31:35 2016 +0800 Committer: Christopher Collins <[email protected]> Committed: Sun Jun 5 13:31:35 2016 +0800 ---------------------------------------------------------------------- net/nimble/host/src/ble_l2cap.c | 19 +++++++++++++------ net/nimble/host/src/ble_l2cap_priv.h | 11 ++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/02ab1a63/net/nimble/host/src/ble_l2cap.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c index 6dcc34a..62244a7 100644 --- a/net/nimble/host/src/ble_l2cap.c +++ b/net/nimble/host/src/ble_l2cap.c @@ -209,14 +209,21 @@ ble_l2cap_rx(struct ble_hs_conn *conn, chan = ble_hs_conn_chan_find(conn, l2cap_hdr.blh_cid); if (chan == NULL) { - BLE_HS_LOG(DEBUG, "rx on unknown L2CAP channel: %d\n", - l2cap_hdr.blh_cid); rc = BLE_HS_ENOENT; - chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_SIG); - if (chan != NULL) { - ble_l2cap_sig_reject_invalid_cid_tx(conn, chan, 0, 0, - l2cap_hdr.blh_cid); + /* Unsupported channel. If the target CID is the black hole + * channel, quietly drop the packet. Otherwise, send an invalid + * CID response. + */ + if (l2cap_hdr.blh_cid != BLE_L2CAP_CID_BLACK_HOLE) { + BLE_HS_LOG(DEBUG, "rx on unknown L2CAP channel: %d\n", + l2cap_hdr.blh_cid); + + chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_SIG); + if (chan != NULL) { + ble_l2cap_sig_reject_invalid_cid_tx(conn, chan, 0, 0, + l2cap_hdr.blh_cid); + } } goto err; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/02ab1a63/net/nimble/host/src/ble_l2cap_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h index 1a0e458..9cbf879 100644 --- a/net/nimble/host/src/ble_l2cap_priv.h +++ b/net/nimble/host/src/ble_l2cap_priv.h @@ -44,9 +44,14 @@ extern STATS_SECT_DECL(ble_l2cap_stats) ble_l2cap_stats; extern struct os_mempool ble_l2cap_chan_pool; -#define BLE_L2CAP_CID_ATT 4 -#define BLE_L2CAP_CID_SIG 5 -#define BLE_L2CAP_CID_SM 6 +#define BLE_L2CAP_CID_ATT 4 +#define BLE_L2CAP_CID_SIG 5 +#define BLE_L2CAP_CID_SM 6 + +/* This is nimble specific; packets sent to the black hole CID do not elicit + * an "invalid CID" response. + */ +#define BLE_L2CAP_CID_BLACK_HOLE 0xffff #define BLE_L2CAP_HDR_SZ 4
