From 28573a6f991fea5b7082bdd15f56958f55c5a582 Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Mon, 15 Dec 2025 23:24:15 +0530 Subject: [PATCH] network_provisioning: Fix prov-ctrl reset handler to return success when already in provisioning mode If firmware has already called network_prov_mgr_reset_wifi_sm_state_on_failure() or network_prov_mgr_reset_thread_sm_state_on_failure(), the device state is already reset to provisioning mode. The prov-ctrl handler now returns success in this case instead of an invalid state error, allowing phone apps to successfully reset even if firmware has already performed the reset operation. --- network_provisioning/CHANGELOG.md | 9 +++++++++ network_provisioning/idf_component.yml | 2 +- network_provisioning/src/manager.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/network_provisioning/CHANGELOG.md b/network_provisioning/CHANGELOG.md index c94b60e6bb..cd7ad16d74 100644 --- a/network_provisioning/CHANGELOG.md +++ b/network_provisioning/CHANGELOG.md @@ -1,3 +1,12 @@ +# 1.2.1 (15-Dec-2025) + +- Fix prov-ctrl reset handler to return success when device is already in provisioning mode + - If firmware has already called `network_prov_mgr_reset_wifi_sm_state_on_failure()` or + `network_prov_mgr_reset_thread_sm_state_on_failure()`, the device state is already reset + to provisioning mode. The prov-ctrl handler now returns success in this case instead of + an invalid state error, allowing phone apps to successfully reset even if firmware has + already performed the reset operation. + # 07-October-2025 - Use managed cJSON component for IDF v6.0 and above diff --git a/network_provisioning/idf_component.yml b/network_provisioning/idf_component.yml index d079c9f18f..4930e1385c 100644 --- a/network_provisioning/idf_component.yml +++ b/network_provisioning/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.2.0" +version: "1.2.1" description: Network provisioning component for Wi-Fi or Thread devices url: https://github.com/espressif/idf-extra-components/tree/master/network_provisioning dependencies: diff --git a/network_provisioning/src/manager.c b/network_provisioning/src/manager.c index 933b941d8d..20a304df8c 100644 --- a/network_provisioning/src/manager.c +++ b/network_provisioning/src/manager.c @@ -2350,6 +2350,13 @@ esp_err_t network_prov_mgr_reset_wifi_sm_state_on_failure(void) ACQUIRE_LOCK(prov_ctx_lock); esp_err_t err = ESP_OK; + /* If already in STARTED state, reset has already been performed (e.g., by firmware). + * Return success as the device is effectively already reset and in provisioning mode. */ + if (prov_ctx->prov_state == NETWORK_PROV_STATE_STARTED) { + ESP_LOGD(TAG, "Reset already performed, device already in provisioning mode"); + goto exit; + } + if (prov_ctx->prov_state != NETWORK_PROV_STATE_FAIL) { ESP_LOGE(TAG, "Trying reset when not in failure state. Current state: %d", prov_ctx->prov_state); err = ESP_ERR_INVALID_STATE; @@ -2448,6 +2455,13 @@ esp_err_t network_prov_mgr_reset_thread_sm_state_on_failure(void) otInstance *instance = esp_openthread_get_instance(); esp_openthread_lock_acquire(portMAX_DELAY); + /* If already in STARTED state, reset has already been performed (e.g., by firmware). + * Return success as the device is effectively already reset and in provisioning mode. */ + if (prov_ctx->prov_state == NETWORK_PROV_STATE_STARTED) { + ESP_LOGD(TAG, "Reset already performed, device already in provisioning mode"); + goto exit; + } + if (prov_ctx->prov_state != NETWORK_PROV_STATE_FAIL) { ESP_LOGE(TAG, "Trying reset when not in failure state. Current state: %d", prov_ctx->prov_state); err = ESP_ERR_INVALID_STATE;