mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
wifi: Support the wifi operations based on the bss file.
Add support for BSS file-based WiFi simulation. Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
+23
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user