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:
liqinhui 2023-06-26 19:18:32 +08:00 committed by Xiang Xiao
parent 061be5f18e
commit d27ca03b6c
14 changed files with 2317 additions and 4 deletions

View File

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

View File

@ -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)

View File

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

View File

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

View File

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

115
tools/simwifi/README Normal file
View File

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

View File

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

View File

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

View File

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

576
tools/simwifi/sim_wifi.sh Executable file
View File

@ -0,0 +1,576 @@
#!/bin/bash
#****************************************************************************
# tools/simwifi/sim_wifi.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#****************************************************************************
#
NUTTX_BR_IF="nuttx0"
RUN_DIR="/var/run/simwifi"
CUR_DIR=""
DBG_LEVEL=1
WPA_PID_FILE="$RUN_DIR/wpa_supplicant.pid"
WPA_CONF_FILE="$RUN_DIR/wpa_supplicant.conf"
HOSTAPD_PID_FILE="$RUN_DIR/hostapd.pid"
HOSTAPD_CONF_FILE="$RUN_DIR/hostapd.conf"
DNSMASQ_PID="$RUN_DIR/dnsmasq.pid"
DNSMASQ_CONF="$RUN_DIR/dnsmasq.conf"
UDHCPC_PID="$RUN_DIR/udhcpc.pid"
UDHCPC_SCRIPT="$RUN_DIR/udhcpc.script"
LOG_FILE="$RUN_DIR/simwifi.log"
STATE_FILE="$RUN_DIR/simwifi.state"
DEFCONF_FILE="$RUN_DIR/simwifi.conf"
DHCP_CLIENT=$(which udhcpc)
DNSMASQ=$(which dnsmasq)
WPA_SUPPLICANT=$(which wpa_supplicant)
HOSTAPD=$(which hostapd)
# print the debug message
sw_dbg()
{
[ $1 -ge $DBG_LEVEL ] && {
echo "$2"
}
}
# get var from the file
# $1:key $2:file
get_var()
{
cat $2 | grep $1 | awk -F':' '{print $2}'
}
check_state()
{
old_state=$(get_var state $STATE_FILE)
sw_dbg 1 "new state:$1, old_state:$old_state"
if [ "$1" = "$old_state" ]; then
sw_dbg 1 "cur_state is $1"
exit 0
fi
}
# set simwifi state
set_state()
{
state=$1
wlan_if=$2
br_if=$3
wan_if=$4
sw_dbg 1 "[set_state] new state:$1"
if [ "$state" != "SW_INIT" -a "$state" != "SW_HWSIM" -a \
"$state" != "SW_NET" -a "$state" != "SW_STA" -a \
"$state" != "SW_AP" -a "$state" != "SW_STAAP" ]; then
echo "no state: $1"
exit -1
fi
sw_dbg 1 "state:$state wlan_if:$wlan_if, br_if:$br_if wan_if:$wan_if"
echo "state:$state" > $STATE_FILE
[ -n "$wlan_if" ] && echo "wlan:$wlan_if" >> $STATE_FILE
[ -n "$br_if" ] && echo "br:$br_if" >> $STATE_FILE
[ -n "$wan_if" ] && echo "wan:$wan_if" >> $STATE_FILE
}
# recover the simwifi state to SW_INIT
recovery_to_init()
{
cur_state=$(get_var state $STATE_FILE)
wlan_if=$(get_var wlan $STATE_FILE)
br_if=$(get_var br $STATE_FILE)
sw_dbg 1 "[recovery_to_init] cur_s:$cur_state"
case $cur_state in
SW_INIT) ;;
SW_HWSIM) stop_hwsim;;
SW_STAAP) stop_staap;;
SW_NET) stop_net $wlan_if;;
SW_STA) stop_sta;;
SW_AP) stop_ap $wlan_if;;
*) set_state SW_INIT;;
esac
}
# Get the absolute pathname of sim_wifi.sh
get_script_path()
{
SOURCE=$1
while [ -h "$SOURCE" ]; do
SOURCE=$(readlink $SOURCE)
done
CUR_DIR=$(cd $(dirname $SOURCE) && pwd)
}
# Copy the configure file to the $RUN_DIR
init_env()
{
sw_dbg 1 "init env"
[ -f "$STATE_FILE" ] && {
check_hwsim_mode
recovery_to_init
}
mkdir -p $RUN_DIR
touch $STATE_FILE
if [ "$1" = "hwsim" ]; then
cp -fr $CUR_DIR/hostapd_hwsim.conf $HOSTAPD_CONF_FILE
cp -fr $CUR_DIR/wpa_supplicant_hwsim.conf $WPA_CONF_FILE
else
cp -fr $CUR_DIR/hostapd.conf $HOSTAPD_CONF_FILE
cp -fr $CUR_DIR/wpa_supplicant.conf $WPA_CONF_FILE
fi
cp -fr $CUR_DIR/dnsmasq.conf $DNSMASQ_CONF
cp -fr $CUR_DIR/udhcpc.script $UDHCPC_SCRIPT
}
# Rename the interface name
rename_ifdev()
{
old_name=$1
new_name=$2
ifconfig $old_name down && ip link set $old_name name $new_name
ifconfig $new_name up
}
kill_service()
{
service_name=$(basename $1 .pid)
sw_dbg 1 "kill $service_name"
if [ -f "$1" ]; then
pid=$(cat $1)
kill -9 $pid
rm $1
else
sw_dbg 1 "$1 isn't existed."
killall $service_name
fi
}
stop_wpa()
{
kill_service $WPA_PID_FILE
}
stop_hostapd()
{
kill_service $HOSTAPD_PID_FILE
}
start_hostapd()
{
sw_dbg 1 "start ap on $1"
#Waiting 1s. If not, the hostapd starting maybe fail on switching mode.
sleep 1
$HOSTAPD -B -i$1 -P $HOSTAPD_PID_FILE $HOSTAPD_CONF_FILE -t &>>$LOG_FILE
}
start_wpa()
{
sw_dbg 1 "start sta on $1"
#Waiting 1s. If not, the wap_supplicant starting maybe fail on switching mode.
sleep 1
$WPA_SUPPLICANT -B -c $WPA_CONF_FILE -i$1 -P $WPA_PID_FILE &>>$LOG_FILE
}
start_udhcpc()
{
sw_dbg 1 "start dhcp client on $1"
[ -n "$2" ] && script_opt=" -s $UDHCPC_SCRIPT"
$DHCP_CLIENT -i $1 -p $UDHCPC_PID $script_opt &>>$LOG_FILE &
}
stop_udhcpc()
{
kill_service $UDHCPC_PID
}
start_bridge()
{
sw_dbg 1 "start bridge to $1"
$CUR_DIR/../simhostroute.sh $1 on &>>$LOG_FILE
}
stop_bridge()
{
sw_dbg 1 "stop bridge to $1"
sw_dbg 1 "Warning: The $NUTTX_BR_IF will be deleted!"
$CUR_DIR/../simhostroute.sh $1 off &>>$LOG_FILE
}
start_dhcp_server()
{
sw_dbg 1 "start dhcp server on $1"
dbg_option=$($DNSMASQ --help|grep log-debug | awk '{print $1}')
$DNSMASQ -i$1 -C $DNSMASQ_CONF $dbg_option -x $DNSMASQ_PID &>>$LOG_FILE
}
stop_dhcp_server()
{
kill_service $DNSMASQ_PID
}
check_hwsim_mode()
{
cur_state=$(get_var state $STATE_FILE)
sw_dbg 1 "[check_hwsim_mode]state: $cur_state"
if [ "$cur_state" = "SW_HWSIM" ]; then
sw_dbg 1 "cur_state is hwsim mode. \
Don't set the sta/ap mode."
exit 0
fi
}
start_hwsim()
{
sta_if=${1:-wlan0}
ap_if=${2:-wlan1}
sw_dbg 1 "start hwsim on $sta_if $ap_if"
init_env hwsim
start_hostapd $ap_if
start_wpa $sta_if
start_dhcp_server $NUTTX_BR_IF
set_state SW_HWSIM
}
stop_hwsim()
{
stop_wpa
stop_hostapd
stop_dhcp_server
set_state SW_INIT
}
start_net()
{
init_env
start_wpa $1
start_udhcpc $1
start_bridge $1
start_dhcp_server $NUTTX_BR_IF
set_state SW_NET $1 $NUTTX_BR_IF $1
}
# Warning:The function will delete nuttx0
stop_net()
{
stop_wpa
stop_udhcpc
stop_bridge $1
stop_dhcp_server
set_state SW_INIT
}
start_sta()
{
[ -z "$(ifconfig | grep "$NUTTX_BR_IF")" ] && {
sw_dbg 1 "Please ensure that the $NUTTX_BR_IF is existed."
exit -2
}
check_state SW_STA
check_state SW_STAAP
init_env
start_wpa $1
start_udhcpc $1 s
start_dhcp_server $NUTTX_BR_IF
set_state SW_STA $1 $NUTTX_BR_IF;
exit 0
}
del_gw_wlan()
{
wlan_if=$1
router=$(ip route show | grep default | grep $wlan_if)
[ -n "$router" ] && {
ip route del $router
sw_dbg 1 "del the default router on $wlan_if"
}
}
stop_sta()
{
stop_wpa
stop_udhcpc
stop_dhcp_server
#check and delete default on wlan0
wlan_if=$(get_var wlan $STATE_FILE)
del_gw_wlan $wlan_if
set_state SW_INIT
}
start_ap()
{
[ -z "$1" ] && {
echo "Missing parameter wlan interface."
exit -1
}
[ -z "$2" ] && {
[ -z "$(ifconfig | grep "$NUTTX_BR_IF")" ] && {
echo "Missing parameter wan interface."
echo "Please ensure that the $NUTTX_BR_IF is existed."
exit -2
}
wan_if=""
} || {
wan_if=$2
}
check_state SW_AP
check_state SW_STAAP
init_env
start_hostapd $1
# nuttx0 doesn't exist and wan_if is configured.
[ -z "$(ifconfig | grep "$NUTTX_BR_IF")" -a -n "$wan_if" ] && {
start_bridge $wan_if
}
ip link set dev $1 master $NUTTX_BR_IF
start_dhcp_server $NUTTX_BR_IF
set_state SW_AP $1 $wan_if;
exit 0
}
stop_ap()
{
stop_hostapd
[ -z "$2" ] || stop_bridge $2
sw_dbg 1 "stop_ap $1"
ip link set dev $1 nomaster
stop_dhcp_server
set_state SW_INIT
}
check_ifname()
{
[ -z "$(ifconfig | grep "$1")" ] && {
echo "The $1 does not exist."
exit -1
}
}
start_staap()
{
sta_if=${1:-wlan0}
ap_if=${2:-wlan1}
sw_dbg 1 "start staap $sta_if $ap_if"
for i in $sta_if $ap_if $NUTTX_BR_IF; do
check_ifname $i
done
check_state SW_STAAP
init_env
start_hostapd $ap_if
sleep 1
start_wpa $sta_if
ip link set dev $ap_if master $NUTTX_BR_IF
start_udhcpc $sta_if
start_dhcp_server $NUTTX_BR_IF
set_state SW_STAAP "$sta_if,$ap_if" $NUTTX_BR_IF
}
stop_staap()
{
stop_wpa
stop_hostapd
stop_udhcpc
stop_dhcp_server
ip link set dev wlan1 nomaster
set_state SW_INIT
}
show_process()
{
ps -ef | grep "$1 " | grep -v grep
}
show_status()
{
#1.env conf
[ -d "$RUN_DIR" ] && {
echo "$RUN_DIR"
ls $RUN_DIR
}
#2. key services
echo -e "\nservices list"
for i in wpa_supplicant hostapd dnsmasq udhcpc; do
show_process $i
done
#3. bridge nuttx0 info
[ -n "$(ifconfig | grep $NUTTX_BR_IF)" ] && {
echo -e "\nbridge $NUTTX_BR_IF"
ip link show master $NUTTX_BR_IF
}
#4.show DEFCONF_FILE
echo -e "\ndefault config"
cat $DEFCONF_FILE
#5. show state
echo ""
cat $STATE_FILE
#6. show router
echo ""
ip route show
}
# $1 is the default wan interface for start_sta
# $2 is the simwifi mode, (rnc/hwsim)
init()
{
[ -z "$1" ] && {
echo "Missing the default wan interface."
exit -1
}
[ -z "$2" ] && {
echo "Missing the simwifi mode."
exit -2
}
init_env
echo "defwan:$1" > $DEFCONF_FILE
[ -n "$1" -a -n "$(ifconfig | grep $1)" ] && start_bridge $1
echo "mode:$2" >> $DEFCONF_FILE
[ "$2" = "hwsim" ] && modprobe mac80211_hwsim
set_state SW_INIT
}
clean()
{
recovery_to_init
cur_mode=$(get_var mode $DEFCONF_FILE)
[ "$cur_mode" = "hwsim" ] && modprobe -r mac80211_hwsim
rm -fr $RUN_DIR
}
usage()
{
echo "$(basename $SOURCE) (rename <old> <new> |"
echo -e "\t init <wan> <mode> |clean |"
echo -e "\t start_wpa <wlan0> |stop_wpa |"
echo -e "\t start_hostapd <wlan0> |stop_hostapd |"
echo -e "\t start_udhcpc <wlan0> |stop_udhcpc |"
echo -e "\t start_dhcp <wlan0> |stop_dhcp |"
echo -e "\t start_hwsim |stop_hwsim |up_hwsim |"
echo -e "\t start_staap |stop_staap |"
echo -e "\t start_net <wlan0> |stop_net <wlan0> |"
echo -e "\t start_sta <wlan0> |stop_sta |"
echo -e "\t start_ap <wlan0> [eth0] |stop_ap <wlan0> [eth0] |"
echo -e "\t start_bridge <eth0> |stop_bridge <eth0> |"
echo -e "\t show | help)"
}
# locate the directory of the sim_wifi.sh.
get_script_path $0
case $1 in
init) init $2 $3;;
clean) clean;;
start_bridge) start_bridge $2;;
stop_bridge) stop_bridge $2;;
start_hwsim) start_hwsim $2 $3;;
stop_hwsim) stop_hwsim;;
up_hwsim) ifconfig hwsim0 up;;
start_wpa) start_wpa $2;;
stop_wpa) stop_wpa;;
start_hostapd) start_hostapd $2;;
stop_hostapd) stop_hostapd;;
rename) rename_ifdev $2 $3;;
start_udhcpc) start_udhcpc $2;;
stop_udhcpc) stop_udhcpc;;
start_dhcp) start_dhcp_server $2;;
stop_dhcp) stop_dhcp_server;;
start_net) start_net $2;;
stop_net) stop_net $2;;
start_sta) start_sta $2;;
stop_sta) stop_sta;;
start_ap) start_ap $2 $3;;
stop_ap) stop_ap $2 $3;;
start_staap) start_staap;;
stop_staap) stop_staap;;
show) show_status;;
help|*) usage;;
esac

View File

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

View File

@ -0,0 +1,2 @@
ctrl_interface=/var/run/simwifi/wpa_supplicant
update_config=1

View File

@ -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
}