From 82f409107cf8f464b92c34cd0563b524397412a8 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Fri, 3 Nov 2023 16:17:24 +0800 Subject: [PATCH] feat(wifi): add new api to get one scan ap record --- components/esp_wifi/include/esp_wifi.h | 31 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 892fff6958..dd20644e54 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -403,9 +403,9 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid); /** * @brief Scan all available APs. * - * @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the - * will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause - * the memory to be freed once the scan is done + * @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory. And then + * can be freed in esp_wifi_scan_get_ap_records(), esp_wifi_scan_get_ap_record() or esp_wifi_clear_ap_list(), + * so call any one to free the memory once the scan is done. * @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds. * Values above 1500ms may cause station to disconnect from AP and are not recommended. * @@ -452,7 +452,9 @@ esp_err_t esp_wifi_scan_stop(void); esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number); /** - * @brief Get AP list found in last scan + * @brief Get AP list found in last scan. + * + * @attention This API will free all memory occupied by scanned AP list. * * @param[inout] number As input param, it stores max AP number ap_records can hold. * As output param, it receives the actual AP number this API returns. @@ -467,11 +469,30 @@ esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number); */ esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records); +/** + * @brief Get one AP record from the scanned AP list. + * + * @attention Different from esp_wifi_scan_get_ap_records(), this API only gets one AP record + * from the scanned AP list each time. This API will free the memory of one AP record, + * if the user doesn't get all records in the scannned AP list, then needs to call esp_wifi_clear_ap_list() + * to free the remaining memory. + * + * @param[out] ap_record pointer to one AP record + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start + * - ESP_ERR_INVALID_ARG: invalid argument + * - ESP_FAIL: scan APs is NULL, means all AP records fetched or no AP found + */ +esp_err_t esp_wifi_scan_get_ap_record(wifi_ap_record_t *ap_record); /** * @brief Clear AP list found in last scan * - * @attention When the obtained ap list fails,bss info must be cleared,otherwise it may cause memory leakage. + * @attention This API will free all memory occupied by scanned AP list. + * When the obtained AP list fails, AP records must be cleared,otherwise it may cause memory leakage. * * @return * - ESP_OK: succeed