Add FTM support and examples (#5272)

Rework of #5266 by @pedrominatel
This commit is contained in:
Me No Dev
2021-06-16 21:24:48 +03:00
committed by GitHub
parent b1bcec08f8
commit cf43d174b7
8 changed files with 366 additions and 6 deletions

View File

@ -395,6 +395,14 @@ static void _arduino_event_cb(void* arg, esp_event_base_t event_base, int32_t ev
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP) {
arduino_event.event_id = ARDUINO_EVENT_WPS_ER_PBC_OVERLAP;
/*
* FTM
* */
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_FTM_REPORT) {
wifi_event_ftm_report_t * event = (wifi_event_ftm_report_t*)event_data;
arduino_event.event_id = ARDUINO_EVENT_WIFI_FTM_REPORT;
memcpy(&arduino_event.event_info.wifi_ftm_report, event_data, sizeof(wifi_event_ftm_report_t));
/*
* SMART CONFIG
@ -778,7 +786,8 @@ const char * arduino_event_names[] = {
"WIFI_READY",
"SCAN_DONE",
"STA_START", "STA_STOP", "STA_CONNECTED", "STA_DISCONNECTED", "STA_AUTHMODE_CHANGE", "STA_GOT_IP", "STA_GOT_IP6", "STA_LOST_IP",
"AP_START", "AP_STOP", "AP_STACONNECTED", "AP_STADISCONNECTED", "AP_STAIPASSIGNED", "AP_PROBEREQRECVED", "AP_GOT_IP6",
"AP_START", "AP_STOP", "AP_STACONNECTED", "AP_STADISCONNECTED", "AP_STAIPASSIGNED", "AP_PROBEREQRECVED", "AP_GOT_IP6",
"FTM_REPORT",
"ETH_START", "ETH_STOP", "ETH_CONNECTED", "ETH_DISCONNECTED", "ETH_GOT_IP", "ETH_GOT_IP6",
"WPS_ER_SUCCESS", "WPS_ER_FAILED", "WPS_ER_TIMEOUT", "WPS_ER_PIN", "WPS_ER_PBC_OVERLAP",
"SC_SCAN_DONE", "SC_FOUND_CHANNEL", "SC_GOT_SSID_PSWD", "SC_SEND_ACK_DONE",
@ -1125,6 +1134,32 @@ wifi_power_t WiFiGenericClass::getTxPower(){
return (wifi_power_t)power;
}
/**
* Initiate FTM Session.
* @param frm_count Number of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0(No pref), 16, 24, 32, 64)
* @param burst_period Requested time period between consecutive FTM bursts in 100's of milliseconds (allowed values - 0(No pref), 2 - 255)
* @param channel Primary channel of the FTM Responder
* @param mac MAC address of the FTM Responder
* @return true on success
*/
bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uint8_t channel, const uint8_t * mac) {
wifi_ftm_initiator_cfg_t ftmi_cfg = {
.resp_mac = {0,0,0,0,0,0},
.channel = channel,
.frm_count = frm_count,
.burst_period = burst_period,
};
if(mac != NULL){
memcpy(ftmi_cfg.resp_mac, mac, 6);
}
// Request FTM session with the Responder
if (ESP_OK != esp_wifi_ftm_initiate_session(&ftmi_cfg)) {
log_e("Failed to initiate FTM session");
return false;
}
return true;
}
// -----------------------------------------------------------------------------------------------------------------------
// ------------------------------------------------ Generic Network function ---------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------