initial
[wilink8-wlan/wl18xx-target-scripts.git] / mr / ap_start.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 WLAN_IF=wlan1
10 WLAN_IP=192.168.43.1
11 WLAN_NETMASK=255.255.255.0
13 SERVICE_SUPPLICANT=wpa_supplicant
14 SERVICE_HOSTAPD=hostapd_bin
17 HOSTAPD_STAT=`getprop init.svc.$SERVICE_HOSTAPD`
18 echo "hostapd state: $HOSTAPD_STAT"
19 #if [ "$HOSTAPD_STAT" == "running" ] ; then echo "hostapd is in running state, exiting..." ; exit 0 ; fi
21 SUPP_STAT=`getprop init.svc.$SERVICE_SUPPLICANT`
22 echo "wpa_supplicant state: $SUPP_STAT"
24 if [ "$SUPP_STAT" == "running" ] ;
25 then
26         WLAN_FREQ=`iw dev wlan0 link 2>/dev/null | grep freq | sed 's/.*freq: //'`
27 #### iw phy | grep `iw dev wlan0 link 2>/dev/null | grep freq | sed 's/.*freq: //'` | awk '{print $2 " " $4}' | awk '{print $2}'
28 #### iw phy | grep `iw dev wlan0 link 2>/dev/null | grep freq | sed 's/.*freq: //'` | awk '{print $2 " " $4}' | awk '{print $2}' | sed "s:\[::" | sed "s:\]::"
32 else
33         WLAN_FREQ=2462
34 fi
36 if [ "$WLAN_FREQ" == "" ] ;
37 then
38         WLAN_CHANNEL=`grep channel= /data/misc/wifi/hostapd.conf | sed "s:channel=::"`
39 else
40         WLAN_CHANNEL=$(( ($WLAN_FREQ - 2412)/5 +1 ))
41 fi
43 echo WLAN_CHANNEL = $WLAN_CHANNEL
45 exit 0
47 :load_driver
49 echo "loading driver"
50 $INSMOD /system/lib/modules/wl12xx_sdio.ko
51 sleep 1
53 echo "setting regulatory domain"
54 $IW reg set `grep country_code= /data/misc/wifi/hostapd.conf | sed "s:country_code=::"`
55 $IW reg get
57 echo "creating new interface"
58 $IW wlan0 del
59 $IW `ls /sys/class/ieee80211/` interface add wlan1 type managed
61 if [ ! -f $HOSTAPD_CONF ] ; then \
62         cp /etc/wifi/hostapd.conf $HOSTAPD_CONF ; \
63         chmod 777 $HOSTAPD_CONF ; \
64 fi
66 echo "loading hostapd"
67 setprop ctl.start $SERVICE_HOSTAPD
68 sleep 2
70 echo "enable interface"
71 $IFCONFIG $WLAN_IF up $WLAN_IP netmask $WLAN_NETMASK
72 sleep 1
73 $IFCONFIG $WLAN_IF
74 sleep 2
76 echo "starting dhcp deamon"
77 udhcpd -f dhcpd.conf &