initial
[wilink8-wlan/wl18xx-target-scripts.git] / mr / ap_add.sh
1 #!/system/bin/sh
3 INSMOD=/system/bin/insmod
4 IFCONFIG=/system/bin/ifconfig
5 HOSTAPD=/system/bin/hostapd
6 IW=/system/bin/iw
7 HOSTAPD_CONF=/data/misc/wifi/hostapd.conf
9 if [ "$1"=="" -a "$2"=="" ]; then
10 echo "please give MAC and desired MAC address - exiting ..." ; exit 1; fi
12 WLAN1_MAC=$1
13 STA_CHANNEL=$2
14 WLAN_IF=wlan1
15 WLAN_IP=192.168.43.1
16 WLAN_NETMASK=255.255.255.0
18 SERVICE_SUPPLICANT=wpa_supplicant
19 SERVICE_HOSTAPD=hostapd_bin
21 SUPP_STAT=`getprop init.svc.$SERVICE_SUPPLICANT`
22 echo "wpa_supplicant state: $SUPP_STAT"
24 HOSTAPD_STAT=`getprop init.svc.$SERVICE_HOSTAPD`
25 echo "hostapd state: $HOSTAPD_STAT"
26 if [ "$HOSTAPD_STAT" == "running" ] ; then echo "hostapd is in running state, exiting..." ; exit 0 ; fi
29 sleep 1
30 iw wlan0 set power_save off
32 echo "creating new interface"
33 $IW `ls /sys/class/ieee80211/` interface add wlan1 type managed
34 ifconfig wlan1 hw ether $WLAN1_MAC
36 if [ ! -f $HOSTAPD_CONF ] ; then \
37         cp /etc/wifi/hostapd.conf $HOSTAPD_CONF ; \
38         chmod 777 $HOSTAPD_CONF ; \
39 fi
41 echo "loading hostapd"
42 echo "setting the correct channel"
43 sed s/channel=[0-9]*/channel=$STA_CHANNEL/ $HOSTAPD_CONF > /data/misc/wifi/tmp.conf
44 mv -f /data/misc/wifi/tmp.conf $HOSTAPD_CONF
46 sleep 1
47 setprop ctl.start $SERVICE_HOSTAPD
48 sleep 2
50 echo "enable interface"
51 $IFCONFIG $WLAN_IF up $WLAN_IP netmask $WLAN_NETMASK
52 sleep 1
53 $IFCONFIG $WLAN_IF
54 sleep 2
56 echo "starting dhcp deamon"
57 udhcpd -f dhcpd.conf &