saramonteiro commented on a change in pull request #2939: URL: https://github.com/apache/incubator-nuttx/pull/2939#discussion_r593173928
########## File path: arch/xtensa/src/esp32/esp32_wifi_adapter.c ########## @@ -4682,82 +4775,812 @@ int esp_wifi_set_ssid(const uint8_t *pdata, uint8_t len) * ****************************************************************************/ -int esp_wifi_connect_internal(void) +int esp_wifi_sta_start(void) { int ret; - wifi_config_t wifi_cfg; - struct timespec timeout; + wifi_mode_t mode; - if (g_connected) - { - wlinfo("INFO: WiFi has connected AP\n"); - return 0; - } + esp_wifi_lock(true); - ret = esp_wifi_set_mode(WIFI_MODE_STA); + ret = esp_wifi_stop(); if (ret) { - wlerr("ERROR: Failed to set station mode error=%d\n", ret); - esp_wifi_deinit(); - return -1; + wlinfo("INFO: Failed to stop WiFi ret=%d\n", ret); } - memset(&wifi_cfg, 0, sizeof(wifi_config_t)); - memcpy((char *)wifi_cfg.sta.ssid, g_ssid, g_ssid_len); - memcpy((char *)wifi_cfg.sta.password, g_password, g_password_len); - +#ifdef ESP32_WLAN_HAS_SOFTAP + if (g_softap_started) + { + mode = WIFI_MODE_APSTA; + } +#else + mode = WIFI_MODE_STA; +#endif + + ret = esp_wifi_set_mode(mode); + if (ret) + { + wlerr("ERROR: Failed to set WiFi mode=%d ret=%d\n", mode, ret); + ret = wifi_errno_trans(ret); + goto errout_set_mode; + } + + ret = esp_wifi_start(); + if (ret) + { + wlerr("ERROR: Failed to start WiFi with mode=%d ret=%d\n", mode, ret); + ret = wifi_errno_trans(ret); + goto errout_set_mode; + } + + g_sta_started = true; + + wlinfo("INFO: OK to start WiFi station\n"); + + esp_wifi_lock(false); + return OK; + +errout_set_mode: + esp_wifi_lock(false); + return ret; +} + +/**************************************************************************** + * Name: esp_wifi_sta_stop + * + * Description: + * Stop WiFi station. + * + * Input Parameters: + * None + * + * Returned Value: + * 0 if success or -1 if fail + * + ****************************************************************************/ + +int esp_wifi_sta_stop(void) +{ + int ret; + + esp_wifi_lock(true); + + ret = esp_wifi_stop(); + if (ret) + { + wlinfo("INFO: Failed to stop WiFi ret=%d\n", ret); + } + + g_sta_started = false; + +#ifdef ESP32_WLAN_HAS_SOFTAP + if (g_softap_started) + { + ret = esp_wifi_set_mode(WIFI_MODE_AP); + if (ret) + { + wlerr("ERROR: Failed to set WiFi AP mode ret=%d\n", ret); + ret = wifi_errno_trans(ret); + goto errout_set_mode; + } + + ret = esp_wifi_start(); + if (ret) + { + wlerr("ERROR: Failed to start WiFi AP ret=%d\n", ret); + ret = wifi_errno_trans(ret); + goto errout_set_mode; + } + } +#endif + + wlinfo("INFO: OK to stop WiFi station\n"); + + esp_wifi_lock(false); + return OK; + +#ifdef ESP32_WLAN_HAS_SOFTAP +errout_set_mode: + esp_wifi_lock(true); + return ret; +#endif +} + +/**************************************************************************** + * Name: esp_wifi_sta_send_data + * + * Description: + * Use WiFi station interface to send 802.3 frame + * + * Input Parameters: + * pbuf - Packet buffer pointer + * len - Packet length + * + * Returned Value: + * 0 if success or others if fail + * + ****************************************************************************/ + +int esp_wifi_sta_send_data(void *pbuf, uint32_t len) +{ + int ret; + + ret = esp_wifi_internal_tx(WIFI_IF_STA, pbuf, len); + + return wifi_errno_trans(ret); +} + +/**************************************************************************** + * Name: esp_wifi_sta_register_recv_cb + * + * Description: + * Regitser WiFi station receive packet callback function Review comment: ```suggestion * Register WiFi station receive packet callback function ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org