diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index 42724d2245..1da02cf877 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -1795,6 +1795,24 @@ esp_err_t esp_ble_gap_set_sch_len(uint8_t role, uint32_t len) return esp_ble_gap_vendor_command_send(&vs_cmd); } #endif // CONFIG_SOC_BLE_MULTI_CONN_OPTIMIZATION + +esp_err_t esp_ble_gap_set_scan_chan_map(uint8_t state, uint8_t chan_map[5]) +{ + esp_ble_vendor_cmd_params_t vs_cmd; + uint8_t cmd_param[6]; + + if (chan_map == NULL) { + return ESP_ERR_INVALID_ARG; + } + + cmd_param[0] = state; + memcpy(&cmd_param[1], chan_map, 5); + vs_cmd.opcode = 0xFD19; + vs_cmd.param_len = 6; + vs_cmd.p_param_buf = cmd_param; + + return esp_ble_gap_vendor_command_send(&vs_cmd); +} #endif // (BLE_VENDOR_HCI_EN == TRUE) #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index 630b8a3a1d..eb2073dbbc 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -248,6 +248,7 @@ typedef enum { ESP_GAP_BLE_READ_CHANNEL_MAP_COMPLETE_EVT, /*!< When BLE channel map result is received, the event comes */ ESP_GAP_BLE_SET_COMMON_FACTOR_CMPL_EVT, /*!< When set the common factor complete, the event comes */ ESP_GAP_BLE_SET_SCH_LEN_CMPL_EVT, /*!< When set the scheduling length complete, the event comes */ + ESP_GAP_BLE_SET_SCAN_CHAN_MAP_CMPL_EVT, /*!< When set the channel map for scanning complete, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1762,6 +1763,12 @@ typedef union { struct ble_set_sch_len_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate scheduling length set operation success status */ } set_sch_len_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_SCH_LEN_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_SET_SCAN_CHAN_MAP_CMPL_EVT + */ + struct ble_set_scan_chan_map_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate channel map for scanning set operation success status */ + } set_scan_chan_map_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_SCAN_CHAN_MAP_CMPL_EVT */ #endif // #if (BLE_VENDOR_HCI_EN == TRUE) #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) /** @@ -3144,6 +3151,28 @@ esp_err_t esp_ble_gap_set_common_factor(uint32_t common_factor); */ esp_err_t esp_ble_gap_set_sch_len(uint8_t role, uint32_t len); +/** + * @brief This function is used to Set the channel map for LE scanning or initiating state. + * + * @note - This function must be called before starting scanning or initiating. + * - At least one channel should be marked as used. + * + * @param[in] state: The LE state for which the channel map is applied. + * - 0 : Scanning state + * - 1 : Initiating state + * @param[in] chan_map: A 5-byte array representing the channel usage bit mask. + * Each bit corresponds to one channel from channel 0 to channel 39. + * The least significant bit of chan_map[0] corresponds to channel 0. + * The most significant bit of chan_map[4] corresponds to channel 39. + * - Bit = 1 : channel is used + * - Bit = 0 : channel is not used + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_set_scan_chan_map(uint8_t state, uint8_t chan_map[5]); + /** * @brief This function is used to read the current and maximum transmit power levels of the local Controller. * diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index e84ebe6c86..a82cd1105b 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1452,6 +1452,10 @@ static void btc_ble_vendor_hci_cmd_complete_callback(tBTA_VSC_CMPL *p_param) msg.act = ESP_GAP_BLE_SET_SCH_LEN_CMPL_EVT; param.set_sch_len_cmpl.status = p_param->p_param_buf[0]; break; + case 0xFD19: + msg.act = ESP_GAP_BLE_SET_SCAN_CHAN_MAP_CMPL_EVT; + param.set_scan_chan_map_cmpl.status = btc_hci_to_esp_status(p_param->p_param_buf[0]); + break; default: param.vendor_cmd_cmpl.opcode = p_param->opcode; param.vendor_cmd_cmpl.param_len = p_param->param_len;