Skip to content

Commit

Permalink
Merge branch 'bugfix/ftm_apsta_bw_issue' into 'master'
Browse files Browse the repository at this point in the history
Fix FTM issues in AP-STA mode

Closes WIFIBUG-634

See merge request espressif/esp-idf!32276
  • Loading branch information
jack0c committed Sep 6, 2024
2 parents dba8722 + 4854bf8 commit 3864200
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
2 changes: 1 addition & 1 deletion components/esp_wifi/lib
Submodule lib updated 61 files
+ esp32/libcore.a
+ esp32/libespnow.a
+ esp32/libmesh.a
+ esp32/libnet80211.a
+ esp32/libpp.a
+ esp32/libsmartconfig.a
+ esp32/libwapi.a
+ esp32_host/libcore.a
+ esp32_host/libespnow.a
+ esp32_host/libmesh.a
+ esp32_host/libnet80211.a
+ esp32_host/libpp.a
+ esp32_host/libsmartconfig.a
+ esp32_host/libwapi.a
+ esp32c2/libcore.a
+ esp32c2/libespnow.a
+ esp32c2/libnet80211.a
+ esp32c2/libpp.a
+ esp32c2/libsmartconfig.a
+ esp32c3/libcore.a
+ esp32c3/libespnow.a
+ esp32c3/libmesh.a
+ esp32c3/libnet80211.a
+ esp32c3/libpp.a
+ esp32c3/libsmartconfig.a
+ esp32c3/libwapi.a
+ esp32c5/libcore.a
+ esp32c5/libespnow.a
+ esp32c5/libmesh.a
+ esp32c5/libnet80211.a
+ esp32c5/libpp.a
+ esp32c5/libsmartconfig.a
+ esp32c5/libwapi.a
+ esp32c6/libcore.a
+ esp32c6/libespnow.a
+ esp32c6/libmesh.a
+ esp32c6/libnet80211.a
+ esp32c6/libpp.a
+ esp32c6/libsmartconfig.a
+ esp32c6/libwapi.a
+ esp32c61/libcore.a
+ esp32c61/libespnow.a
+ esp32c61/libmesh.a
+ esp32c61/libnet80211.a
+ esp32c61/libpp.a
+ esp32c61/libsmartconfig.a
+ esp32c61/libwapi.a
+ esp32s2/libcore.a
+ esp32s2/libespnow.a
+ esp32s2/libmesh.a
+ esp32s2/libnet80211.a
+ esp32s2/libpp.a
+ esp32s2/libsmartconfig.a
+ esp32s2/libwapi.a
+ esp32s3/libcore.a
+ esp32s3/libespnow.a
+ esp32s3/libmesh.a
+ esp32s3/libnet80211.a
+ esp32s3/libpp.a
+ esp32s3/libsmartconfig.a
+ esp32s3/libwapi.a
72 changes: 56 additions & 16 deletions examples/wifi/ftm/main/ftm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,61 @@ void initialise_wifi(void)
initialized = true;
}

esp_err_t wifi_add_mode(wifi_mode_t mode)
{
wifi_mode_t cur_mode, new_mode = mode;

if (esp_wifi_get_mode(&cur_mode)) {
ESP_LOGE(TAG_STA, "Failed to get mode!");
return ESP_FAIL;
}

if (mode == WIFI_MODE_STA) {
if (cur_mode == WIFI_MODE_STA || cur_mode == WIFI_MODE_APSTA) {
int bits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT, 0, 1, 0);
if (bits & CONNECTED_BIT) {
s_reconnect = false;
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
ESP_ERROR_CHECK( esp_wifi_disconnect() );
xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portMAX_DELAY);
}
return ESP_OK;
} else if (cur_mode == WIFI_MODE_AP) {
new_mode = WIFI_MODE_APSTA;
} else {
new_mode = WIFI_MODE_STA;
}
} else if (mode == WIFI_MODE_AP) {
if (cur_mode == WIFI_MODE_AP || cur_mode == WIFI_MODE_APSTA) {
/* Do nothing */
return ESP_OK;
} else if (cur_mode == WIFI_MODE_STA) {
new_mode = WIFI_MODE_APSTA;
} else {
new_mode = WIFI_MODE_AP;
}
}

ESP_ERROR_CHECK( esp_wifi_set_mode(new_mode) );
return ESP_OK;
}

static bool wifi_cmd_sta_join(const char *ssid, const char *pass)
{
int bits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT, 0, 1, 0);

wifi_config_t wifi_config = { 0 };
if (ESP_OK != wifi_add_mode(WIFI_MODE_STA)) {
return false;
}

wifi_config_t wifi_config = { 0 };
strlcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
if (pass) {
strlcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
}

if (bits & CONNECTED_BIT) {
s_reconnect = false;
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
ESP_ERROR_CHECK( esp_wifi_disconnect() );
xEventGroupWaitBits(s_wifi_event_group, DISCONNECTED_BIT, 0, 1, portMAX_DELAY);
}

s_reconnect = true;
s_retry_num = 0;
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_connect() );
s_reconnect = true;
s_retry_num = 0;

xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT, 0, 1, 5000 / portTICK_PERIOD_MS);

Expand Down Expand Up @@ -312,9 +344,15 @@ static bool wifi_perform_scan(const char *ssid, bool internal)
{
wifi_scan_config_t scan_config = { 0 };
scan_config.ssid = (uint8_t *) ssid;
wifi_mode_t mode;
uint8_t i;

ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_get_mode(&mode) );
if ((mode != WIFI_MODE_STA) && (mode != WIFI_MODE_APSTA)) {
if (ESP_OK != wifi_add_mode(WIFI_MODE_STA)) {
return false;
}
}
if (ESP_OK != esp_wifi_scan_start(&scan_config, true)) {
ESP_LOGI(TAG_STA, "Failed to perform scan");
return false;
Expand Down Expand Up @@ -389,11 +427,13 @@ static bool wifi_cmd_ap_set(const char* ssid, const char* pass, uint8_t channel,
return false;
}

if (ESP_OK != wifi_add_mode(WIFI_MODE_AP)) {
return false;
}
if (strlen(pass) == 0) {
g_ap_config.ap.authmode = WIFI_AUTH_OPEN;
}
g_ap_config.ap.channel = channel;
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &g_ap_config));
if (bw == 40) {
esp_wifi_set_bandwidth(ESP_IF_WIFI_AP, WIFI_BW_HT40);
Expand Down Expand Up @@ -668,7 +708,7 @@ void register_wifi(void)
ftm_args.initiator = arg_lit0("I", "ftm_initiator", "FTM Initiator mode");
ftm_args.ssid = arg_str0("s", "ssid", "SSID", "SSID of AP");
ftm_args.frm_count = arg_int0("c", "frm_count", "<0/8/16/24/32/64>", "FTM frames to be exchanged (0: No preference)");
ftm_args.burst_period = arg_int0("p", "burst_period", "<0-100 (x 100 mSec)>", "Periodicity of FTM bursts in 100's of miliseconds (0: No preference)");
ftm_args.burst_period = arg_int0("p", "burst_period", "<0-100 (x 100 mSec)>", "Periodicity of FTM bursts in 100's of milliseconds (0: No preference)");
/* FTM Responder commands */
ftm_args.responder = arg_lit0("R", "ftm_responder", "FTM Responder mode");
ftm_args.enable = arg_lit0("e", "enable", "Restart SoftAP with FTM enabled");
Expand Down

0 comments on commit 3864200

Please sign in to comment.