This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3843f7b4fe6906914a4b1546f8c35c481908ed76
Author: liqinhui <[email protected]>
AuthorDate: Wed Apr 2 16:41:01 2025 +0800

    wifi: Support the wifi operations based on the bss file.
    
    Add support for BSS file-based WiFi simulation.
    
    Signed-off-by: liqinhui <[email protected]>
---
 arch/sim/Kconfig                 | 24 +++++++++++++++++++++++-
 arch/sim/src/Makefile            |  2 +-
 arch/sim/src/sim/CMakeLists.txt  |  2 +-
 arch/sim/src/sim/sim_netdriver.c | 18 +++++++++++++++++-
 drivers/net/wifi_sim.c           | 22 ++++++++++++++++++++++
 include/nuttx/net/wifi_sim.h     |  1 +
 6 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig
index 944a12c6c7e..c545404454a 100644
--- a/arch/sim/Kconfig
+++ b/arch/sim/Kconfig
@@ -284,16 +284,38 @@ config SIM_NETDEV_NUMBER
                Note that only one network device will be brought up by netinit 
automatically,
                others will be kept in DOWN state by default.
 
+if SIM_NETDEV && DRIVERS_IEEE80211 && NETDEV_WIRELESS_HANDLER
+
 config SIM_WIFIDEV_NUMBER
        int "Number of Simulated WiFi Device"
        default 0
        range 0 SIM_NETDEV_NUMBER
-       depends on SIM_NETDEV && DRIVERS_IEEE80211 && NETDEV_WIRELESS_HANDLER
        ---help---
                The number of simulated wifi network devices.
 
                Note that only one network device will be brought up by netinit 
automatically,
                others will be kept in DOWN state by default.
+
+choice
+       prompt "Select SimWiFi Platform"
+       depends on SIM_WIFIDEV_NUMBER != 0
+       default SIM_WIFIDEV_HOST
+
+config SIM_WIFIDEV_HOST
+       bool "Use the host Wi-Fi interfaces"
+       ---help---
+               Use the host Wi-Fi interfaces, which are either simulated by
+               hwsim or the real wireless network cards.
+
+config SIM_WIFIDEV_PSEUDO
+       bool "Use the Simulated Wi-Fi devices"
+       depends on DRIVERS_WIFI_SIM
+       ---help---
+               Use the the Simulated Wi-Fi devices, which are supported by the 
bss file.
+endchoice
+
+endif
+
 endif
 
 config SIM_NETDEV_VPNKIT_PATH
diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
index a84649acbd6..9c4b42e8e76 100644
--- a/arch/sim/src/Makefile
+++ b/arch/sim/src/Makefile
@@ -209,7 +209,7 @@ ifeq ($(CONFIG_FS_FAT),y)
   STDLIBS += -lz
 endif
 
-ifneq ($(CONFIG_SIM_WIFIDEV_NUMBER),0)
+ifeq ($(CONFIG_SIM_WIFIDEV_HOST),y)
   CFLAGS += -DTOPDIR=\"$(TOPDIR)\"
   CSRCS += sim_wifihost.c
 endif
diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt
index 875040d5ef0..a0b26bb3017 100644
--- a/arch/sim/src/sim/CMakeLists.txt
+++ b/arch/sim/src/sim/CMakeLists.txt
@@ -213,7 +213,7 @@ if(CONFIG_SIM_X11FB)
   endif()
 endif()
 
-if(NOT ${CONFIG_SIM_WIFIDEV_NUMBER} EQUAL 0)
+if(CONFIG_SIM_WIFIDEV_HOST)
   add_compile_options(-DTOPDIR=$(TOPDIR))
   list(APPEND SRCS sim_wifihost.c)
 endif()
diff --git a/arch/sim/src/sim/sim_netdriver.c b/arch/sim/src/sim/sim_netdriver.c
index 9a893b53b64..6ad654b3014 100644
--- a/arch/sim/src/sim/sim_netdriver.c
+++ b/arch/sim/src/sim/sim_netdriver.c
@@ -70,6 +70,7 @@
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev_lowerhalf.h>
 #include <nuttx/net/pkt.h>
+#include <nuttx/net/wifi_sim.h>
 
 #include "sim_internal.h"
 #include "sim_wifihost.h"
@@ -99,8 +100,10 @@
 
 struct sim_netdev_s
 {
-#if CONFIG_SIM_WIFIDEV_NUMBER != 0
+#if defined(CONFIG_SIM_WIFIDEV_HOST)
   struct sim_wifihost_lowerhalf_s dev;
+#elif defined(CONFIG_SIM_WIFIDEV_PSEUDO)
+  struct wifi_sim_lowerhalf_s dev;
 #else
   struct netdev_lowerhalf_s dev;
 #endif
@@ -214,7 +217,11 @@ static int netdriver_ifup(struct netdev_lowerhalf_s *dev)
 #if CONFIG_SIM_WIFIDEV_NUMBER != 0
   if (DEVIDX(dev) < CONFIG_SIM_WIFIDEV_NUMBER)
     {
+#  if defined(CONFIG_SIM_WIFIDEV_HOST)
       if (sim_wifihost_connected((struct sim_wifihost_lowerhalf_s *)dev))
+#  elif defined(CONFIG_SIM_WIFIDEV_PSEUDO)
+      if (wifi_sim_connected((struct wifi_sim_lowerhalf_s *)dev))
+#  endif
         {
           netdev_lower_carrier_on(dev);
         }
@@ -303,8 +310,17 @@ int sim_netdriver_init(void)
 #if CONFIG_SIM_WIFIDEV_NUMBER != 0
       if (devidx < CONFIG_SIM_WIFIDEV_NUMBER)
         {
+          int ret =
+#  if defined(CONFIG_SIM_WIFIDEV_HOST)
           sim_wifihost_init((struct sim_wifihost_lowerhalf_s *)dev,
                             devidx);
+#  elif defined(CONFIG_SIM_WIFIDEV_PSEUDO)
+          wifi_sim_init((struct wifi_sim_lowerhalf_s *)dev);
+#  endif
+          if (ret < 0)
+            {
+              return ret;
+            }
         }
 #endif
 
diff --git a/drivers/net/wifi_sim.c b/drivers/net/wifi_sim.c
index 12ae4de51e1..70ef054593b 100644
--- a/drivers/net/wifi_sim.c
+++ b/drivers/net/wifi_sim.c
@@ -1977,6 +1977,8 @@ int wifi_sim_init(FAR struct wifi_sim_lowerhalf_s *netdev)
   priv->lower          = &netdev->lower;
   netdev->wifi         = priv;
 
+  priv->mode           = IW_MODE_AUTO;
+
   return OK;
 }
 
@@ -1996,3 +1998,23 @@ void wifi_sim_remove(FAR struct wifi_sim_lowerhalf_s 
*netdev)
   kmm_free(netdev->wifi);
 }
 
+/****************************************************************************
+ * Name: wifi_sim_connected
+ ****************************************************************************/
+
+bool wifi_sim_connected(FAR struct wifi_sim_lowerhalf_s *dev)
+{
+  FAR struct wifi_sim_s *wifidev = (FAR struct wifi_sim_s *)dev->wifi;
+
+  if (wifidev->mode == IW_MODE_MASTER)
+    {
+      return true;
+    }
+  else if (wifidev->mode == IW_MODE_INFRA)
+    {
+      return wifidev->state == WLAN_STA_STATE_CONNECTED;
+    }
+
+  return false;
+}
+
diff --git a/include/nuttx/net/wifi_sim.h b/include/nuttx/net/wifi_sim.h
index 1b3d473a6e6..8fb707bbe28 100644
--- a/include/nuttx/net/wifi_sim.h
+++ b/include/nuttx/net/wifi_sim.h
@@ -64,6 +64,7 @@ struct wifi_sim_lowerhalf_s
 
 int  wifi_sim_init(FAR struct wifi_sim_lowerhalf_s *netdev);
 void wifi_sim_remove(FAR struct wifi_sim_lowerhalf_s *netdev);
+bool wifi_sim_connected(FAR struct wifi_sim_lowerhalf_s *dev);
 
 #undef EXTERN
 #ifdef __cplusplus

Reply via email to