This is an automated email from the ASF dual-hosted git repository. janc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit ef1838a4db513d53db681aa4c8aef5e87762eeb3 Author: Szymon Janc <szymon.j...@codecoup.pl> AuthorDate: Wed Feb 26 11:52:00 2025 +0100 nimble/host: Don't used magic CID numbers in L2CAP code Use defines for specifying allowed COC CID range. --- nimble/host/include/host/ble_l2cap.h | 6 ++++++ nimble/host/src/ble_l2cap.c | 4 +++- nimble/host/src/ble_l2cap_coc_priv.h | 3 --- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/nimble/host/include/host/ble_l2cap.h b/nimble/host/include/host/ble_l2cap.h index f836e97c6..d6532cf3e 100644 --- a/nimble/host/include/host/ble_l2cap.h +++ b/nimble/host/include/host/ble_l2cap.h @@ -66,6 +66,12 @@ struct ble_hs_conn; /** Security Manager (SM) CID. */ #define BLE_L2CAP_CID_SM 6 +/** Start range for connection oriented channel CID. */ +#define BLE_L2CAP_COC_CID_START 0x0040 + +/** End range for connection oriented channel CID. */ +#define BLE_L2CAP_COC_CID_END 0x007F + /** @} */ /** diff --git a/nimble/host/src/ble_l2cap.c b/nimble/host/src/ble_l2cap.c index 50fe18c65..2b979e918 100644 --- a/nimble/host/src/ble_l2cap.c +++ b/nimble/host/src/ble_l2cap.c @@ -385,7 +385,9 @@ ble_l2cap_rx(struct ble_hs_conn *conn, } /* For CIDs from dynamic range we check if SDU size isn't larger than MPS */ - if (chan->dcid >= 0x0040 && chan->dcid <= 0x007F && l2cap_hdr.len > chan->my_coc_mps) { + if (chan->dcid >= BLE_L2CAP_COC_CID_START && + chan->dcid <= BLE_L2CAP_COC_CID_END && + l2cap_hdr.len > chan->my_coc_mps) { /* Data exceeds MPS */ BLE_HS_LOG(ERROR, "error: sdu_len > chan->my_coc_mps (%d>%d)\n", l2cap_hdr.len, chan->my_coc_mps); diff --git a/nimble/host/src/ble_l2cap_coc_priv.h b/nimble/host/src/ble_l2cap_coc_priv.h index 37a95b31e..8a87303fb 100644 --- a/nimble/host/src/ble_l2cap_coc_priv.h +++ b/nimble/host/src/ble_l2cap_coc_priv.h @@ -30,9 +30,6 @@ extern "C" { #endif -#define BLE_L2CAP_COC_CID_START 0x0040 -#define BLE_L2CAP_COC_CID_END 0x007F - struct ble_l2cap_chan; #define BLE_L2CAP_COC_FLAG_STALLED 0x01