pkarashchenko commented on code in PR #8818:
URL: https://github.com/apache/nuttx/pull/8818#discussion_r1137782277


##########
arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c:
##########
@@ -4701,10 +4783,37 @@ int esp_wifi_sta_stop(void)
 
   g_sta_started = false;
 
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+  if (g_softap_started)
+    {
+      ret = esp_wifi_set_mode(WIFI_MODE_AP);
+      if (ret)
+        {
+          wlerr("Failed to set Wi-Fi AP mode ret=%d\n", ret);
+          ret = wifi_errno_trans(ret);
+          goto errout_set_mode;
+        }
+
+      ret = esp_wifi_start();
+      if (ret)
+        {
+          wlerr("Failed to start Wi-Fi AP ret=%d\n", ret);
+          ret = wifi_errno_trans(ret);
+          goto errout_set_mode;
+        }
+    }
+#endif /* ESP32S3_WLAN_HAS_SOFTAP */
+
   wlinfo("OK to stop Wi-Fi station\n");
 
   esp_wifi_lock(false);
   return OK;
+
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+errout_set_mode:
+  esp_wifi_lock(false);
+  return ret;
+#endif /* ESP32S3_WLAN_HAS_SOFTAP */

Review Comment:
   ```suggestion
     wlinfo("OK to stop Wi-Fi station\n");
   
   errout:
     esp_wifi_lock(false);
     return ret;
   ```
   and use `errout` label 



##########
arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c:
##########
@@ -4642,7 +4713,18 @@ int esp_wifi_sta_start(void)
       wlinfo("Failed to stop Wi-Fi ret=%d\n", ret);
     }
 
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+  if (g_softap_started)
+    {
+      mode = WIFI_MODE_APSTA;
+    }
+  else
+    {
+      mode = WIFI_MODE_STA;
+    }
+#else
   mode = WIFI_MODE_STA;
+#endif /* ESP32S3_WLAN_HAS_SOFTAP */

Review Comment:
   ```suggestion
   #ifdef ESP32S3_WLAN_HAS_SOFTAP
     if (g_softap_started)
       {
         mode = WIFI_MODE_APSTA;
       }
     else
   #endif /* ESP32S3_WLAN_HAS_SOFTAP */
       {
         mode = WIFI_MODE_STA;
       }
   ```



##########
arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c:
##########
@@ -5645,6 +5923,802 @@ int esp_wifi_sta_rssi(struct iwreq *iwr, bool set)
 }
 #endif /* ESP32S3_WLAN_HAS_STA */
 
+/****************************************************************************
+ * SoftAP functions
+ ****************************************************************************/
+
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+
+/****************************************************************************
+ * Name: esp_wifi_softap_start
+ *
+ * Description:
+ *   Start Wi-Fi SoftAP.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   OK on success (positive non-zero values are cmd-specific)
+ *   Negated errno returned on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_softap_start(void)
+{
+  int ret;
+  wifi_mode_t mode;
+
+  esp_wifi_lock(true);
+
+  ret = esp_wifi_stop();
+  if (ret)
+    {
+      wlinfo("Failed to stop Wi-Fi ret=%d\n", ret);
+    }
+
+#ifdef ESP32S3_WLAN_HAS_STA
+  if (g_sta_started)
+    {
+      mode = WIFI_MODE_APSTA;
+    }
+  else
+    {
+      mode = WIFI_MODE_AP;
+    }
+#else
+  mode = WIFI_MODE_AP;
+#endif /* ESP32S3_WLAN_HAS_STA */

Review Comment:
   ```suggestion
   #ifdef ESP32S3_WLAN_HAS_STA
     if (g_sta_started)
       {
         mode = WIFI_MODE_APSTA;
       }
     else
   #endif /* ESP32S3_WLAN_HAS_STA */
       {
         mode = WIFI_MODE_AP;
       }
   ```



##########
arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c:
##########
@@ -5645,6 +5923,802 @@ int esp_wifi_sta_rssi(struct iwreq *iwr, bool set)
 }
 #endif /* ESP32S3_WLAN_HAS_STA */
 
+/****************************************************************************
+ * SoftAP functions
+ ****************************************************************************/
+
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+
+/****************************************************************************
+ * Name: esp_wifi_softap_start
+ *
+ * Description:
+ *   Start Wi-Fi SoftAP.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   OK on success (positive non-zero values are cmd-specific)
+ *   Negated errno returned on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_softap_start(void)
+{
+  int ret;
+  wifi_mode_t mode;
+
+  esp_wifi_lock(true);
+
+  ret = esp_wifi_stop();
+  if (ret)
+    {
+      wlinfo("Failed to stop Wi-Fi ret=%d\n", ret);
+    }
+
+#ifdef ESP32S3_WLAN_HAS_STA
+  if (g_sta_started)
+    {
+      mode = WIFI_MODE_APSTA;
+    }
+  else
+    {
+      mode = WIFI_MODE_AP;
+    }
+#else
+  mode = WIFI_MODE_AP;
+#endif /* ESP32S3_WLAN_HAS_STA */
+
+  ret = esp_wifi_set_mode(mode);
+  if (ret)
+    {
+      wlerr("Failed to set Wi-Fi mode=%d ret=%d\n", mode, ret);
+      ret = wifi_errno_trans(ret);
+      goto errout_set_mode;
+    }
+
+  ret = esp_wifi_start();
+  if (ret)
+    {
+      wlerr("Failed to start Wi-Fi with mode=%d ret=%d\n", mode, ret);
+      ret = wifi_errno_trans(ret);
+      goto errout_set_mode;
+    }
+
+  g_softap_started = true;
+
+  wlinfo("OK to start Wi-Fi SoftAP\n");
+
+  esp_wifi_lock(false);
+  return OK;
+
+errout_set_mode:
+  esp_wifi_lock(false);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp_wifi_softap_stop
+ *
+ * Description:
+ *   Stop Wi-Fi SoftAP.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   OK on success (positive non-zero values are cmd-specific)
+ *   Negated errno returned on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_softap_stop(void)
+{
+  int ret;
+
+  esp_wifi_lock(true);
+
+  ret = esp_wifi_stop();
+  if (ret)
+    {
+      wlinfo("Failed to stop Wi-Fi ret=%d\n", ret);
+    }
+
+  g_softap_started = false;
+
+#ifdef ESP32S3_WLAN_HAS_STA
+  if (g_sta_started)
+    {
+      ret = esp_wifi_set_mode(WIFI_MODE_STA);
+      if (ret)
+        {
+          wlerr("Failed to set Wi-Fi AP mode ret=%d\n", ret);
+          ret = wifi_errno_trans(ret);
+          goto errout_set_mode;
+        }
+
+      ret = esp_wifi_start();
+      if (ret)
+        {
+          wlerr("Failed to start Wi-Fi AP ret=%d\n", ret);
+          ret = wifi_errno_trans(ret);
+          goto errout_set_mode;
+        }
+    }
+#endif /* ESP32S3_WLAN_HAS_STA */
+
+  wlinfo("OK to stop Wi-Fi SoftAP\n");
+
+  esp_wifi_lock(false);
+  return OK;
+
+#ifdef ESP32S3_WLAN_HAS_STA
+errout_set_mode:
+  esp_wifi_lock(false);
+  return ret;
+#endif /* ESP32S3_WLAN_HAS_STA */

Review Comment:
   ditto



##########
arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c:
##########
@@ -5645,6 +5923,802 @@ int esp_wifi_sta_rssi(struct iwreq *iwr, bool set)
 }
 #endif /* ESP32S3_WLAN_HAS_STA */
 
+/****************************************************************************
+ * SoftAP functions
+ ****************************************************************************/
+
+#ifdef ESP32S3_WLAN_HAS_SOFTAP
+
+/****************************************************************************
+ * Name: esp_wifi_softap_start
+ *
+ * Description:
+ *   Start Wi-Fi SoftAP.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   OK on success (positive non-zero values are cmd-specific)
+ *   Negated errno returned on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_softap_start(void)
+{
+  int ret;
+  wifi_mode_t mode;
+
+  esp_wifi_lock(true);
+
+  ret = esp_wifi_stop();
+  if (ret)
+    {
+      wlinfo("Failed to stop Wi-Fi ret=%d\n", ret);
+    }
+
+#ifdef ESP32S3_WLAN_HAS_STA
+  if (g_sta_started)
+    {
+      mode = WIFI_MODE_APSTA;
+    }
+  else
+    {
+      mode = WIFI_MODE_AP;
+    }
+#else
+  mode = WIFI_MODE_AP;
+#endif /* ESP32S3_WLAN_HAS_STA */
+
+  ret = esp_wifi_set_mode(mode);
+  if (ret)
+    {
+      wlerr("Failed to set Wi-Fi mode=%d ret=%d\n", mode, ret);
+      ret = wifi_errno_trans(ret);
+      goto errout_set_mode;
+    }
+
+  ret = esp_wifi_start();
+  if (ret)
+    {
+      wlerr("Failed to start Wi-Fi with mode=%d ret=%d\n", mode, ret);
+      ret = wifi_errno_trans(ret);
+      goto errout_set_mode;
+    }
+
+  g_softap_started = true;
+
+  wlinfo("OK to start Wi-Fi SoftAP\n");
+
+  esp_wifi_lock(false);
+  return OK;
+
+errout_set_mode:
+  esp_wifi_lock(false);
+  return ret;

Review Comment:
   ditto



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to