Avoid Wi-Fi restarts for disabled profiles Fix #3
This commit is contained in:
+49
-4
@@ -196,6 +196,48 @@ static void copy_working_config(wifi_app_config_t *config)
|
||||
unlock_shared();
|
||||
}
|
||||
|
||||
static bool profiles_equal(const wifi_config_sta_profile_t *left,
|
||||
const wifi_config_sta_profile_t *right)
|
||||
{
|
||||
return left->enabled == right->enabled &&
|
||||
left->priority == right->priority &&
|
||||
left->security == right->security &&
|
||||
left->ssid_len == right->ssid_len &&
|
||||
left->psk_len == right->psk_len &&
|
||||
memcmp(left->ssid, right->ssid, left->ssid_len) == 0 &&
|
||||
memcmp(left->psk, right->psk, left->psk_len) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disabled profiles are staged configuration, not current radio policy. Their
|
||||
* credentials and priority may be prepared without interrupting a live link.
|
||||
*/
|
||||
static bool config_requires_radio_restart(const wifi_app_config_t *current,
|
||||
const wifi_app_config_t *candidate)
|
||||
{
|
||||
if (current->ap_policy != candidate->ap_policy ||
|
||||
current->ap_ssid_len != candidate->ap_ssid_len ||
|
||||
current->ap_psk_len != candidate->ap_psk_len ||
|
||||
current->ap_channel != candidate->ap_channel ||
|
||||
memcmp(current->ap_ssid, candidate->ap_ssid, current->ap_ssid_len) != 0 ||
|
||||
memcmp(current->ap_psk, candidate->ap_psk, current->ap_psk_len) != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t slot = 0U; slot < WIFI_CONFIG_STA_PROFILE_COUNT; ++slot) {
|
||||
const wifi_config_sta_profile_t *old_profile = ¤t->profiles[slot];
|
||||
const wifi_config_sta_profile_t *new_profile = &candidate->profiles[slot];
|
||||
bool old_enabled = old_profile->enabled != 0U;
|
||||
bool new_enabled = new_profile->enabled != 0U;
|
||||
|
||||
if (old_enabled != new_enabled ||
|
||||
(old_enabled && !profiles_equal(old_profile, new_profile))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool connected_event_matches_active_profile(const manager_message_t *message)
|
||||
{
|
||||
bool matches = false;
|
||||
@@ -1357,11 +1399,14 @@ esp_err_t wifi_manager_apply_working_config(const wifi_app_config_t *config)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
manager_message_t message = {.type = MESSAGE_COMMAND_APPLY};
|
||||
lock_shared();
|
||||
if (!enqueue_message(&message)) {
|
||||
unlock_shared();
|
||||
return ESP_ERR_TIMEOUT;
|
||||
bool restart_radio = config_requires_radio_restart(&s_shared.config, config);
|
||||
if (restart_radio) {
|
||||
manager_message_t message = {.type = MESSAGE_COMMAND_APPLY};
|
||||
if (!enqueue_message(&message)) {
|
||||
unlock_shared();
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
s_shared.config = *config;
|
||||
++s_shared.snapshot.config_generation;
|
||||
|
||||
+3
-2
@@ -83,8 +83,9 @@ esp_err_t wifi_manager_init(const wifi_app_config_t *config);
|
||||
esp_err_t wifi_manager_get_working_config(wifi_app_config_t *config);
|
||||
|
||||
/*
|
||||
* Replaces the RAM working configuration. Application is asynchronous; when
|
||||
* Wi-Fi is running, the manager task restarts it using the newest generation.
|
||||
* Replaces the RAM working configuration. Disabled-profile-only edits do not
|
||||
* interrupt a running radio; changes to effective station/AP policy are
|
||||
* applied asynchronously by restarting with the newest generation.
|
||||
*/
|
||||
esp_err_t wifi_manager_apply_working_config(const wifi_app_config_t *config);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user