mr scripts v1
[wilink8-wlan/wl18xx-target-scripts.git] / mr / sta_add.sh
1 #!/system/bin/sh
3 if [ "$1" == "" ] ; then 
4         echo "Please insert parameters <IP> <NEW_APUT_CHANNEL> [MAC]" 
5         echo "MAC is optional, if don't want to change APUT CH then enter second parameter: 0" 
6         echo "ie: sta_add.sh 10.2.47.6 11 08:00:28:13:33:38" 
7         exit 0 
8 fi
10 IW=/system/bin/iw
11 INSMOD=/system/bin/insmod
12 IFCONFIG=/system/xbin/busybox/ifconfig
13 WPA_SUPPLICANT=/system/bin/wpa_supplicant
15 SUPPLICANT_CONF=/data/misc/wifi/wpa_supplicant.conf
16 HOSTAPD_CONF=/data/misc/wifi/hostapd.conf
18 AP_START=/data/misc/wifi/ap_start.sh
19 AP_STOP=/data/misc/wifi/ap_stop.sh
21 WLAN_IF_SUT=wlan0
22 WLAN_IF_APUT=wlan1
23 WLAN_IP=$1
24 WLAN_NETMASK=255.255.255.0
25 MAC=$3
26 CHANNEL=$2
27 PHY=`ls /sys/class/ieee80211/`
28 CURRENT_AP_CHANNEL=`grep channel= $HOSTAPD_CONF | sed "s:channel=::"`
30 SERVICE_SUPPLICANT=wpa_supplicant
31 SERVICE_HOSTAPD=hostapd_bin
33 echo "adding interface"
34 $IW $PHY interface add $WLAN_IF_SUT type managed
35 sleep 1
37 if [ "$MAC" != "" ] ; then
38         echo "setting new mac" 
39         $IFCONFIG $WLAN_IF_SUT hw ether $MAC 
40 fi
42 echo "enable interface"
43 $IFCONFIG $WLAN_IF_SUT up $WLAN_IP netmask $WLAN_NETMASK
44 sleep 1
46 if [ ! -f $SUPPLICANT_CONF ] ; then 
47         cp /etc/wifi/wpa_supplicant.conf $SUPPLICANT_CONF 
48 fi
49 chmod 777 $SUPPLICANT_CONF 
51 echo "loading supplicant"
52 setprop ctl.start "$SERVICE_SUPPLICANT:-i$WLAN_IF_SUT -c$SUPPLICANT_CONF"
53 sleep 1
55 if [ "$CHANNEL" != "$CURRENT_AP_CHANNEL" ] && [ "$CHANNEL" != "0" ] ; then
56         #-------------------------- CHannel Change --------------------
57         sed -i 's/^channel=[0-9,a-z,A-Z,_,$, ,]*/channel='$CHANNEL'/' $HOSTAPD_CONF 
59         #---------------------------- STOP_APUT -----------------------
60         echo "kill udhcpd" 
61         killall udhcpd 
63         echo "unload hostapd" 
64         setprop ctl.stop $SERVICE_HOSTAPD 
65         sleep 1 
67         echo "disable interface" 
68         $IFCONFIG $WLAN_IF_APUT down 
69         #---------------------------- STOP_APUT -----------------------
71         sleep 3
72         #---------------------------- START_APUT -----------------------
73         echo "loading hostapd" 
74         setprop ctl.start $SERVICE_HOSTAPD 
75         sleep 2 
77         echo "enable interface" 
78         $IFCONFIG $WLAN_IF_APUT up  
80         echo "starting dhcp deamon" 
81         udhcpd -f dhcpd.conf & 
82         #---------------------------- START_APUT -----------------------
83 fi