feat(esp_wifi): Refactor and improve FTM code

Enable FTM Responder mode for ESP32C6. Update wifi libs with below -

1. Break FTM State Machine code into separate functions
2. Use dynamic allocation for FTM session to save memory
3. Add API to get FTM report instead of event based mechanism
4. Add FTM Request retry and comeback support
This commit is contained in:
Nachiket Kukade
2024-03-26 11:45:25 +05:30
parent fcb76f0671
commit 413bcd8fcd
9 changed files with 116 additions and 38 deletions

View File

@@ -1294,6 +1294,26 @@ esp_err_t esp_wifi_ftm_end_session(void);
*/
esp_err_t esp_wifi_ftm_resp_set_offset(int16_t offset_cm);
/**
* @brief Get FTM measurements report copied into a user provided buffer.
*
* @attention 1. To get the FTM report, user first needs to allocate a buffer of size
* (sizeof(wifi_ftm_report_entry_t) * num_entries) where the API will fill up to num_entries
* valid FTM measurements in the buffer. Total number of entries can be found in the event
* WIFI_EVENT_FTM_REPORT as ftm_report_num_entries
* @attention 2. The internal FTM report is freed upon use of this API which means the API can only be used
* once afer every FTM session initiated
* @attention 3. Passing the buffer as NULL merely frees the FTM report
*
* @param report Pointer to the buffer for receiving the FTM report
* @param num_entries Number of FTM report entries to be filled in the report
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_ftm_get_report(wifi_ftm_report_entry_t *report, uint8_t num_entries);
/**
* @brief Enable or disable 11b rate of specified interface
*

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -661,7 +661,9 @@ typedef struct {
uint8_t resp_mac[6]; /**< MAC address of the FTM Responder */
uint8_t channel; /**< Primary channel of the FTM Responder */
uint8_t frm_count; /**< No. of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0(No pref), 16, 24, 32, 64) */
uint16_t burst_period; /**< Requested time period between consecutive FTM bursts in 100's of milliseconds (0 - No pref) */
uint16_t burst_period; /**< Requested period between FTM bursts in 100's of milliseconds (allowed values 0(No pref) - 100) */
bool use_get_report_api; /**< True - Using esp_wifi_ftm_get_report to get FTM report, False - Using ftm_report_data from
WIFI_EVENT_FTM_REPORT to get FTM report */
} wifi_ftm_initiator_cfg_t;
/**
@@ -1015,6 +1017,8 @@ typedef enum {
FTM_STATUS_CONF_REJECTED, /**< Peer rejected FTM configuration in FTM Request */
FTM_STATUS_NO_RESPONSE, /**< Peer did not respond to FTM Requests */
FTM_STATUS_FAIL, /**< Unknown error during FTM exchange */
FTM_STATUS_NO_VALID_MSMT, /**< FTM session did not result in any valid measurements */
FTM_STATUS_USER_TERM, /**< User triggered termination */
} wifi_ftm_status_t;
/** Argument structure for */
@@ -1035,7 +1039,8 @@ typedef struct {
uint32_t rtt_raw; /**< Raw average Round-Trip-Time with peer in Nano-Seconds */
uint32_t rtt_est; /**< Estimated Round-Trip-Time with peer in Nano-Seconds */
uint32_t dist_est; /**< Estimated one-way distance in Centi-Meters */
wifi_ftm_report_entry_t *ftm_report_data; /**< Pointer to FTM Report with multiple entries, should be freed after use */
wifi_ftm_report_entry_t *ftm_report_data; /**< Pointer to FTM Report, should be freed after use. Note: Highly recommended
to use API esp_wifi_ftm_get_report to get the report instead of using this */
uint8_t ftm_report_num_entries; /**< Number of entries in the FTM Report data */
} wifi_event_ftm_report_t;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -25,6 +25,9 @@
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#include "apps_private/wifi_apps_private.h"
#endif
#ifdef CONFIG_ESP_WIFI_FTM_ENABLE
#include "esp_chip_info.h"
#endif
static bool s_wifi_inited = false;
@@ -318,6 +321,13 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
#endif
esp_wifi_set_log_level();
esp_wifi_power_domain_on();
#ifdef CONFIG_ESP_WIFI_FTM_ENABLE
esp_chip_info_t info = {0};
esp_chip_info(&info);
if (info.model == CHIP_ESP32C6 && info.revision <= 1) {
((wifi_init_config_t *)config)->feature_caps &= ~(CONFIG_FEATURE_FTM_INITIATOR_BIT);
}
#endif
result = esp_wifi_init_internal(config);
if (result == ESP_OK) {
#if CONFIG_MAC_BB_PD
@@ -395,9 +405,10 @@ void wifi_apb80m_release(void)
#endif //CONFIG_PM_ENABLE
#ifndef CONFIG_ESP_WIFI_FTM_ENABLE
void ieee80211_ftm_attach(void)
esp_err_t ieee80211_ftm_attach(void)
{
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
return ESP_OK;
}
#endif

View File

@@ -1325,7 +1325,7 @@ config SOC_WIFI_HW_TSF
config SOC_WIFI_FTM_SUPPORT
bool
default n
default y
config SOC_WIFI_GCMP_SUPPORT
bool

View File

@@ -544,7 +544,7 @@
/*------------------------------------ WI-FI CAPS ------------------------------------*/
#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */
#define SOC_WIFI_FTM_SUPPORT (0) /*!< Support FTM */
#define SOC_WIFI_FTM_SUPPORT (1) /*!< Support FTM */
#define SOC_WIFI_GCMP_SUPPORT (1) /*!< Support GCMP(GCMP128 and GCMP256) */
#define SOC_WIFI_WAPI_SUPPORT (1) /*!< Support WAPI */
#define SOC_WIFI_CSI_SUPPORT (1) /*!< Support CSI */