@@ -144,9 +144,7 @@ static esp_err_t wifi_join(const char *ssid, const char *password)
144144 return ESP_ERR_INVALID_ARG ;
145145 }
146146
147- esp_openthread_task_switching_lock_release ();
148147 esp_err_t err = example_wifi_sta_do_connect (wifi_config , true);
149- esp_openthread_task_switching_lock_acquire (portMAX_DELAY );
150148 return err ;
151149}
152150
@@ -179,9 +177,7 @@ void esp_ot_wifi_border_router_init_flag_set(bool initialized)
179177esp_err_t esp_ot_wifi_connect (const char * ssid , const char * password )
180178{
181179 if (!s_wifi_initialized ) {
182- esp_openthread_task_switching_lock_release ();
183180 example_wifi_start ();
184- esp_openthread_task_switching_lock_acquire (portMAX_DELAY );
185181#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_OPENTHREAD_RADIO_NATIVE
186182 ESP_ERROR_CHECK (esp_coex_wifi_i154_enable ());
187183#endif
@@ -224,9 +220,7 @@ esp_err_t esp_ot_wifi_disconnect(void)
224220 ESP_ERROR_CHECK (esp_event_handler_unregister (WIFI_EVENT , WIFI_EVENT_STA_CONNECTED , & handler_on_wifi_connect ));
225221 s_wifi_handler_registered = false;
226222 s_wifi_state = OT_WIFI_DISCONNECTED ;
227- esp_openthread_task_switching_lock_release ();
228223 esp_err_t err = example_wifi_sta_do_disconnect ();
229- esp_openthread_task_switching_lock_acquire (portMAX_DELAY );
230224 return err ;
231225}
232226
@@ -298,7 +292,10 @@ otError esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs
298292 otCliOutputFormat ("None ssid\n" );
299293 return OT_ERROR_INVALID_ARGS ;
300294 }
301- if (esp_ot_wifi_connect (ssid , psk ) == ESP_OK ) {
295+ esp_openthread_task_switching_lock_release ();
296+ esp_err_t error = esp_ot_wifi_connect (ssid , psk );
297+ esp_openthread_task_switching_lock_acquire (portMAX_DELAY );
298+ if (error == ESP_OK ) {
302299 if (!s_border_router_initialized ) {
303300 esp_openthread_set_backbone_netif (get_example_netif ());
304301 if (esp_openthread_border_router_init () != ESP_OK ) {
@@ -315,7 +312,10 @@ otError esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs
315312 otCliOutputFormat ("%s\n" , wifi_state_string [s_wifi_state ]);
316313 } else if (strcmp (aArgs [0 ], "disconnect" ) == 0 ) {
317314 if (s_wifi_state ) {
318- if (esp_ot_wifi_disconnect () == ESP_OK ) {
315+ esp_openthread_task_switching_lock_release ();
316+ esp_err_t error = esp_ot_wifi_disconnect ();
317+ esp_openthread_task_switching_lock_acquire (portMAX_DELAY );
318+ if (error == ESP_OK ) {
319319 otCliOutputFormat ("disconnect wifi\n" );
320320 } else {
321321 ESP_LOGE (OT_EXT_CLI_TAG , "Fail to disconnect wifi" );
0 commit comments