mirror of
https://github.com/apache/nuttx.git
synced 2026-08-18 01:49:24 +08:00
wifi/simdriver: Support the sim wifi.
Add the Sim WiFi function, which can provide the wifi operating on nuttx sim emulator, and support two modes that simulate wifi, HWSIM and RNC(real network card). - In the HWSIM mode, we simulates two wlan interfaces. The wlan0 is STA and the wlan1 is AP. The wlan0 can connect to the wlan1 in the nuttx simulator. - In the RNC mode, we can use the same wlan interface name on the nuttx simulator to control the connection behavior of the real wireless card. Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
+11
-1
@@ -223,13 +223,23 @@ config SIM_NETDEV_NUMBER
|
||||
int "Number of Simulated Network Device"
|
||||
default 1
|
||||
range 1 8
|
||||
depends on SIM_NETDEV_TAP
|
||||
depends on SIM_NETDEV
|
||||
---help---
|
||||
The number of simulated network devices.
|
||||
|
||||
Note that only one network device will be brought up by netinit automatically,
|
||||
others will be kept in DOWN state by default.
|
||||
|
||||
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.
|
||||
endif
|
||||
|
||||
config SIM_NETDEV_VPNKIT_PATH
|
||||
|
||||
@@ -179,6 +179,10 @@ ifeq ($(CONFIG_FS_FAT),y)
|
||||
STDLIBS += -lz
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_SIM_WIFIDEV_NUMBER),0)
|
||||
CFLAGS += -DTOPDIR=\"$(TOPDIR)\"
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SIM_NETDEV_TAP),y)
|
||||
CSRCS += sim_netdriver.c
|
||||
ifneq ($(CONFIG_WINDOWS_CYGWIN),y)
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
# define CONFIG_SIM_NETDEV_NUMBER 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SIM_WIFIDEV_NUMBER
|
||||
# define CONFIG_SIM_WIFIDEV_NUMBER 0
|
||||
#endif
|
||||
|
||||
/* Determine which (if any) console driver to use */
|
||||
|
||||
#ifndef CONFIG_DEV_CONSOLE
|
||||
|
||||
@@ -86,6 +86,9 @@
|
||||
#define DEVIDX(p) ((struct sim_netdev_s *)(p) - g_sim_dev)
|
||||
#define DEVBUF(p) (((struct sim_netdev_s *)(p))->buf)
|
||||
|
||||
#if CONFIG_SIM_WIFIDEV_NUMBER != 0
|
||||
# include "sim_wifidriver.c"
|
||||
#else
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -95,6 +98,7 @@ struct sim_netdev_s
|
||||
struct netdev_lowerhalf_s dev;
|
||||
uint8_t buf[SIM_NETDEV_BUFSIZE]; /* Used when packet buffer is fragmented */
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
@@ -188,7 +192,21 @@ static int netdriver_ifup(struct netdev_lowerhalf_s *dev)
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
sim_netdev_ifup(DEVIDX(dev), &dev->netdev.d_ipv6addr);
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
netdev_lower_carrier_on(dev);
|
||||
|
||||
#if CONFIG_SIM_WIFIDEV_NUMBER != 0
|
||||
if (DEVIDX(dev) < CONFIG_SIM_WIFIDEV_NUMBER)
|
||||
{
|
||||
if (wifidriver_connected(dev))
|
||||
{
|
||||
netdev_lower_carrier_on(dev);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
netdev_lower_carrier_on(dev);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -236,11 +254,19 @@ int sim_netdriver_init(void)
|
||||
dev->quota[NETPKT_RX] = 1;
|
||||
dev->ops = &g_ops;
|
||||
|
||||
#if CONFIG_SIM_WIFIDEV_NUMBER != 0
|
||||
if (devidx < CONFIG_SIM_WIFIDEV_NUMBER)
|
||||
{
|
||||
wifidriver_init(dev, devidx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Register the device with the OS so that socket IOCTLs can be
|
||||
* performed
|
||||
*/
|
||||
|
||||
netdev_lower_register(dev, NET_LL_ETHERNET);
|
||||
netdev_lower_register(dev, devidx < CONFIG_SIM_WIFIDEV_NUMBER ?
|
||||
NET_LL_IEEE80211 : NET_LL_ETHERNET);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -48,7 +48,7 @@ config NETDEV_WORK_THREAD_PRIORITY
|
||||
config NETDEV_WIRELESS_HANDLER
|
||||
bool "Support wireless handler in upper-half driver"
|
||||
default y
|
||||
depends on NETDEV_IOCTL
|
||||
depends on NETDEV_WIRELESS_IOCTL
|
||||
---help---
|
||||
Enable the wireless handler support in upper-half driver.
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
|
||||
# Function
|
||||
|
||||
The simwifi can provides host Settings for sim wifi on nuttx sim emulator.
|
||||
The script sim_wifi.sh supports two modes that simulate wifi, HWSIM and RNC
|
||||
(real network card).
|
||||
|
||||
- In the HWSIM mode, we simulates two wlan interfaces. The wlan0 is STA and
|
||||
the wlan1 is AP. The wlan0 can connect to the wlan1 in the nuttx simulator.
|
||||
- In the RNC mode, we can use the same wlan interface name on the nuttx simulator
|
||||
to control the connection behavior of the real wireless card.
|
||||
|
||||
# Config
|
||||
|
||||
Before using the Sim WiFi function, we need to perform the following
|
||||
configurations:
|
||||
|
||||
- nuttx
|
||||
SIM_NETDEV_NUMBER=3
|
||||
SIM_WIFIDEV_NUMBER=2
|
||||
SIM_NETDEV_TAP=y
|
||||
DRIVERS_IEEE80211=y
|
||||
NETDEV_WIRELESS_HANDLER=y
|
||||
|
||||
- apps
|
||||
WIRELESS_WAPI_CMDTOOL=y
|
||||
SYSTEM_DHCPC_RENEW=y
|
||||
NETUTILS_DHCPD=y
|
||||
|
||||
# Using
|
||||
|
||||
We can use the './tools/simwifi/sim_wifi.sh help' command to view the commands
|
||||
provided by the sim_wifi.sh script and the results are as follows.
|
||||
|
||||
sim_wifi.sh (rename <old> <new> |
|
||||
init <wan> <mode> |clean |
|
||||
start_wpa <wlan0> |stop_wpa |
|
||||
start_hostapd <wlan0> |stop_hostapd |
|
||||
start_udhcpc <wlan0> |stop_udhcpc |
|
||||
start_dhcp <wlan0> |stop_dhcp |
|
||||
start_hwsim |stop_hwsim |up_hwsim |
|
||||
start_net <wlan0> |stop_net <wlan0> |
|
||||
start_sta <wlan0> |stop_sta |
|
||||
start_ap <wlan0> [eth0] |stop_ap <wlan0> [eth0] |
|
||||
start_bridge <eth0> |stop_bridge <eth0> |
|
||||
show | help)
|
||||
|
||||
- Init the simwifi, the command format is as follows:
|
||||
sudo ./tools/simwifi/sim_wifi.sh init <wan> <mode>
|
||||
|
||||
The <wan> is the name of the interface for accessing the Internet.
|
||||
The <mode> is the simwifi mode, HWSIM and RNC.
|
||||
|
||||
Setting HWSIM:
|
||||
sudo ./tools/simwifi/sim_wifi.sh init eno1 HWSIM
|
||||
|
||||
Setting RNC:
|
||||
sudo ./tools/simwifi/sim_wifi.sh init eno1 RNC
|
||||
|
||||
- In HWSIM mode:
|
||||
Start the hwsim services, the command is as follows.
|
||||
sudo ./tools/simwifi/sim_wifi.sh start_hwsim
|
||||
|
||||
Stop the hwsim services, the command is as follows
|
||||
sudo ./tools/simwifi/sim_wifi.sh stop_hwsim
|
||||
|
||||
|
||||
- In RNC mode:
|
||||
Maybe the real wireless card name format is not wlanx, in this case
|
||||
we need to change it to wlanx format. The command is as follows
|
||||
sudo simwifi rename <old_name> wlanx
|
||||
|
||||
* Set the real wireless network card to STA mode.
|
||||
sudo ./tools/simwifi/sim_wifi.sh start_sta wlan0
|
||||
|
||||
* Set the real wireless network card to AP mode.
|
||||
sudo ./tools/simwifi/sim_wifi.sh start_ap wlan0
|
||||
|
||||
Finally we can clean up all the files, configurations and services of the simwifi.
|
||||
sudo ./tools/simwifi/sim_wifi.sh clean
|
||||
|
||||
# Location problems
|
||||
We can use the following command to locate the problem and display the
|
||||
status.
|
||||
cmd: sudo ./tools/simwifi/sim_wifi.sh show
|
||||
log:
|
||||
|
||||
/var/run/simwifi
|
||||
dnsmasq.conf hostapd simwifi.log udhcpc.script wpa_supplicant.pid
|
||||
dnsmasq.leases hostapd.conf simwifi.state wpa_supplicant
|
||||
dnsmasq.pid simwifi.conf udhcpc.pid wpa_supplicant.conf
|
||||
|
||||
services list
|
||||
root 1880671 2046 0 10月10 ? 00:00:00 /usr/sbin/wpa_supplicant -B -c /var/run/simwifi/wpa_supplicant.conf -iwlan0 -P /var/run/simwifi/wpa_supplicant.pid
|
||||
nobody 1880680 2046 0 10月10 ? 00:00:00 /usr/sbin/dnsmasq -inuttx0 -C /var/run/simwifi/dnsmasq.conf --log-debug -x /var/run/simwifi/dnsmasq.pid
|
||||
root 1880672 2046 0 10月10 ? 00:00:00 /usr/sbin/udhcpc -i wlan0 -p /var/run/simwifi/udhcpc.pid -s /var/run/simwifi/udhcpc.script
|
||||
|
||||
bridge nuttx0
|
||||
222: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master nuttx0 state UNKNOWN mode DEFAULT group default qlen 1000
|
||||
link/ether 2e:b0:bc:79:41:02 brd ff:ff:ff:ff:ff:ff
|
||||
223: tap1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master nuttx0 state DOWN mode DEFAULT group default qlen 1000
|
||||
link/ether a6:33:96:26:a4:1d brd ff:ff:ff:ff:ff:ff
|
||||
|
||||
default config
|
||||
defwan:eno1
|
||||
mode:rnc
|
||||
|
||||
state:SW_STA
|
||||
wlan:wlan0
|
||||
br:nuttx0
|
||||
|
||||
default via 10.221.127.254 dev eno1 proto dhcp metric 100
|
||||
10.0.1.0/24 dev nuttx0 proto kernel scope link src 10.0.1.1
|
||||
10.221.96.0/19 dev eno1 proto kernel scope link src 10.221.108.5 metric 100
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
dhcp-leasefile=/var/run/simwifi/dnsmasq.leases
|
||||
port=0
|
||||
|
||||
dhcp-range=10.0.1.100,10.0.1.250,255.255.255.0,12h
|
||||
dhcp-option=option:router,10.0.1.1
|
||||
dhcp-option=option:dns-server,8.8.8.8,8.8.4.4
|
||||
dhcp-option=option:netmask,255.255.255.0
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
ctrl_interface=/var/run/simwifi/hostapd
|
||||
driver=nl80211
|
||||
ssid=NuttX_WiFi
|
||||
hw_mode=g
|
||||
channel=8
|
||||
wmm_enabled=0
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
wpa=2
|
||||
wpa_passphrase=12345678
|
||||
wpa_key_mgmt=WPA-PSK
|
||||
wpa_pairwise=TKIP
|
||||
rsn_pairwise=CCMP
|
||||
@@ -0,0 +1,14 @@
|
||||
ctrl_interface=/var/run/simwifi/hostapd
|
||||
driver=nl80211
|
||||
ssid=Hwsim_WiFi
|
||||
hw_mode=g
|
||||
channel=8
|
||||
wmm_enabled=0
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
wpa=2
|
||||
wpa_passphrase=12345678
|
||||
wpa_key_mgmt=WPA-PSK
|
||||
wpa_pairwise=TKIP
|
||||
rsn_pairwise=CCMP
|
||||
Executable
+576
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# Busybox udhcpc dispatcher script.
|
||||
# Copyright (C) 2009 by Axel Beckert.
|
||||
# Copyright (C) 2014 by Michael Tokarev.
|
||||
#
|
||||
# Based on the busybox example scripts and the old udhcp source
|
||||
# Modified base on default.scripts.
|
||||
|
||||
log() {
|
||||
logger -t "udhcpc[$PPID]" -p daemon.$1 "$interface: $2"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
bound|renew)
|
||||
|
||||
# Configure new IP address.
|
||||
# Do it unconditionally even if the address hasn't changed,
|
||||
# to also set subnet, broadcast, mtu, ...
|
||||
busybox ifconfig $interface ${mtu:+mtu $mtu} \
|
||||
$ip netmask $subnet ${broadcast:+broadcast $broadcast}
|
||||
|
||||
log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease"
|
||||
;;
|
||||
|
||||
deconfig)
|
||||
busybox ip link set $interface up
|
||||
busybox ip -4 addr flush dev $interface
|
||||
busybox ip -4 route flush dev $interface
|
||||
log notice "deconfigured"
|
||||
;;
|
||||
|
||||
leasefail | nak)
|
||||
log err "configuration failed: $1: $message"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "$0: Unknown udhcpc command: $1" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,2 @@
|
||||
ctrl_interface=/var/run/simwifi/wpa_supplicant
|
||||
update_config=1
|
||||
@@ -0,0 +1,10 @@
|
||||
ctrl_interface=/var/run/simwifi/wpa_supplicant
|
||||
update_config=1
|
||||
|
||||
network={
|
||||
ssid="Hwsim_WiFi"
|
||||
psk="12345678"
|
||||
key_mgmt=WPA-PSK
|
||||
group=CCMP
|
||||
disabled=1
|
||||
}
|
||||
Reference in New Issue
Block a user