From 7be10cd22ac795b717e8801a8f3c80cea5f27bbb Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 29 Apr 2026 17:42:43 +0530 Subject: [PATCH] fix(nimble): Add support for shorter connection interval --- nimble/host/src/ble_gap.c | 7 ++++--- nimble/host/src/ble_hs_hci_evt.c | 4 ++-- nimble/host/src/ble_l2cap.c | 9 --------- nimble/include/nimble/hci_common.h | 13 +++++++++++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 0176aa6b5..af46121f0 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -6963,12 +6963,12 @@ ble_gap_check_conn_params(uint8_t phy, const struct ble_gap_conn_params *params) } } /* Check connection interval min */ - if ((params->itvl_min < BLE_HCI_CONN_ITVL_MIN) || + if ((params->itvl_min < BLE_HOST_CONN_PARAM_ITVL_MIN) || (params->itvl_min > BLE_HCI_CONN_ITVL_MAX)) { return BLE_ERR_INV_HCI_CMD_PARMS; } /* Check connection interval max */ - if ((params->itvl_max < BLE_HCI_CONN_ITVL_MIN) || + if ((params->itvl_max < BLE_HOST_CONN_PARAM_ITVL_MIN) || (params->itvl_max > BLE_HCI_CONN_ITVL_MAX) || (params->itvl_max < params->itvl_min)) { return BLE_ERR_INV_HCI_CMD_PARMS; @@ -8338,7 +8338,8 @@ ble_gap_validate_conn_params(const struct ble_gap_upd_params *params) return false; } - if (params->itvl_min < 0x0006 || params->itvl_max > 0x0C80) { + if (params->itvl_min < BLE_HOST_CONN_PARAM_ITVL_MIN || + params->itvl_max > BLE_HCI_CONN_ITVL_MAX) { return false; } diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c index 82ac2322a..efb4f4bd6 100644 --- a/nimble/host/src/ble_hs_hci_evt.c +++ b/nimble/host/src/ble_hs_hci_evt.c @@ -1495,7 +1495,7 @@ ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data, } if (ev->status == 0) { - BLE_HS_DBG_ASSERT(le16toh(ev->conn_itvl) >= BLE_HCI_CONN_ITVL_MIN); + BLE_HS_DBG_ASSERT(le16toh(ev->conn_itvl) >= BLE_HOST_CONN_PARAM_ITVL_MIN); BLE_HS_DBG_ASSERT(le16toh(ev->conn_itvl) <= BLE_HCI_CONN_ITVL_MAX); BLE_HS_DBG_ASSERT(le16toh(ev->conn_latency) >= BLE_HCI_CONN_LATENCY_MIN); @@ -1533,7 +1533,7 @@ ble_hs_hci_evt_le_conn_parm_req(uint8_t subevent, const void *data, unsigned int return BLE_HS_ECONTROLLER; } - BLE_HS_DBG_ASSERT(le16toh(ev->min_interval) >= BLE_HCI_CONN_ITVL_MIN); + BLE_HS_DBG_ASSERT(le16toh(ev->min_interval) >= BLE_HOST_CONN_PARAM_ITVL_MIN); BLE_HS_DBG_ASSERT(le16toh(ev->max_interval) <= BLE_HCI_CONN_ITVL_MAX); BLE_HS_DBG_ASSERT(le16toh(ev->max_interval) >= le16toh(ev->min_interval)); diff --git a/nimble/host/src/ble_l2cap.c b/nimble/host/src/ble_l2cap.c index f2ec61223..b5bd26721 100644 --- a/nimble/host/src/ble_l2cap.c +++ b/nimble/host/src/ble_l2cap.c @@ -304,15 +304,6 @@ ble_l2cap_remove_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan) #else conn->bhc_rx_chan = NULL; #endif - if (chan->rx_buf == NULL) { - BLE_HS_LOG(INFO, "L2CAP remove_rx: rx_buf already NULL; " - "conn_handle=0x%04x scid=0x%04x\n", - conn->bhc_handle, chan->scid); - } else { - BLE_HS_LOG(INFO, "L2CAP remove_rx: freeing partial rx_buf; " - "conn_handle=0x%04x scid=0x%04x rx_len=%d\n", - conn->bhc_handle, chan->scid, chan->rx_len); - } os_mbuf_free_chain(chan->rx_buf); chan->rx_buf = NULL; chan->rx_len = 0; diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 2991796d3..29dc30ff1 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1689,7 +1689,20 @@ struct ble_hci_vs_set_event_mask_cp { #define BLE_HCI_CONN_FILT_NO_WL (0) #define BLE_HCI_CONN_FILT_USE_WL (1) #define BLE_HCI_CONN_FILT_MAX (1) +/* Bluetooth Core Spec minimum connection interval (7.5 ms in 1.25 ms units). */ #define BLE_HCI_CONN_ITVL_MIN (0x0006) +/* Host-side validation floor for connection interval (1.25 ms units). When + * CONFIG_BT_BLE_HOST_ALLOW_SUB_SPEC_MIN_CONN_INT is enabled, the host accepts + * sub-spec intervals and defers the real lower bound to the controller; 0x0001 + * is used instead of 0 so uint16_t range checks stay well-defined under + * -Wtype-limits. For spec-visible values (e.g. PPCP) use BLE_HCI_CONN_ITVL_MIN. + */ +#if defined(CONFIG_BT_BLE_HOST_ALLOW_SUB_SPEC_MIN_CONN_INT) && \ + (CONFIG_BT_BLE_HOST_ALLOW_SUB_SPEC_MIN_CONN_INT) +#define BLE_HOST_CONN_PARAM_ITVL_MIN (0x0001) +#else +#define BLE_HOST_CONN_PARAM_ITVL_MIN BLE_HCI_CONN_ITVL_MIN +#endif #define BLE_HCI_CONN_ITVL_MAX (0x0c80) #define BLE_HCI_CONN_LATENCY_MIN (0x0000) #define BLE_HCI_CONN_LATENCY_MAX (0x01f3)