From d59bb2debcbe47cf10e1b199b30684e175bfefaa Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Thu, 31 Jul 2025 11:38:53 +0530 Subject: [PATCH] fix(nimble) Add VSC for Set Scan Channel Bitmap for esp32c2 --- nimble/host/include/host/ble_esp_gap.h | 17 +++++++++++++++++ nimble/host/src/ble_gap.c | 12 ++++++++++++ nimble/include/nimble/hci_common.h | 3 +++ 3 files changed, 32 insertions(+) diff --git a/nimble/host/include/host/ble_esp_gap.h b/nimble/host/include/host/ble_esp_gap.h index c94d81eb5..e174058ea 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -262,6 +262,23 @@ int ble_gap_clear_legacy_adv(void); */ int ble_gap_set_chan_select(uint8_t select); +/** + * This API is used to Set scan channel bitmap for scan/init. + * + * Currently supported only for ESP32C2 chipset. + * + * @param state 0:Scanning + * 1:Initiating + * + * @param bitmap[5] Represents 5 byte channel bitmap. Bit 37,38 and 39 set to + * represent primary channels, enabled by default. + * + * Bit 39 refers to MSb of MSB of 5-byte bitmap + * + * @return status, 0 on success; nonzero on failure. + */ +int ble_gap_set_scan_chan(uint8_t state, uint8_t *bitmap); + #endif /** diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index f182dbaaf..f76aad252 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -9403,6 +9403,18 @@ int ble_gap_set_chan_select(uint8_t select) return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_CHAN_SELECT, &select, 1, NULL, 0); } + +int ble_gap_set_scan_chan(uint8_t state, uint8_t *bitmap) +{ + uint8_t vs_cmd[6]; + memset(vs_cmd, 0x0, sizeof(vs_cmd)); + + vs_cmd[0] = state; + memcpy(&vs_cmd[1], bitmap, 5); + + return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_SCAN_CHAN, + &vs_cmd, sizeof(vs_cmd), NULL, 0); +} #endif int diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 62ac9e8e7..1a5469108 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1384,6 +1384,9 @@ struct ble_hci_vs_duplicate_exception_list_cp { #define BLE_HCI_OCF_VS_SET_CHAN_SELECT (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0112)) #define BLE_HCI_OCF_VS_SET_EVT_MASK (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0116)) + +#define BLE_HCI_OCF_VS_SET_SCAN_CHAN (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0119)) + struct ble_hci_vs_set_event_mask_cp { uint32_t event_mask; } __attribute__((packed));