-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlaunch_sta_ap.sh
executable file
·121 lines (89 loc) · 2.71 KB
/
launch_sta_ap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
HOSTPAD_DIR=/home/liamhu/svn/3rd-party/hostapd/hostapd2.0
WPA_SUPPLICANT_DIR=/home/liamhu/wpa_supplicant-2.4/wpa_supplicant
## unload ap
service isc-dhcp-server stop
killall dhcpd
killall hostapd
killall wpa_supplicant
# load driver
./load.sh
# find wlan1
ssv_wlan_1=`script/find_ssv_wlan`
sleep 1
ssv_phy=`script/find_ssv_phy`
if [ -z "$ssv_phy" ]; then
echo SSV PHY device not found.;
exit 1;
fi
ssv_wlan_1=`script/find_ssv_wlan`
if [ -z "$ssv_wlan_1" ]; then
echo SSV primary WLAN device not found.;
exit 1;
fi
echo "Primary SSV WLAN interface is $ssv_wlan_1"
# add wlan2
ssv_wlan_2=`echo $ssv_wlan_1 | sed -e s/wlan//g`
ssv_wlan_2=`expr $ssv_wlan_2 + 1`
ssv_wlan_2="wlan$ssv_wlan_2"
echo Second WLAN interface is $ssv_wlan_2
echo "Add second interface $ssv_wlan_2 to SSV PHY device $ssv_phy"
iw $ssv_phy interface add $ssv_wlan_2 type station
sleep 1
ssv_wlans="`script/find_ssv_wlan`"
for ssv_wlan in $ssv_wlans; do
if [ $ssv_wlan != $ssv_wlan_1 ]; then
echo Second SSV WLAN device is actually $ssv_wlan
break;
fi
done
ifconfig $ssv_wlan_1 192.168.1.33 up
sleep 2
$WPA_SUPPLICANT_DIR/wpa_supplicant -Dnl80211 -i $ssv_wlan_1 -c ./wpa_supplicant.conf -dd -B -f /var/log/wpa_supplicant.log
echo -e "${YELLOW}Config wireless AP...${NC}"
cp script/template/load_dhcp.sh load_dhcp.sh
awk 'NF' script/template/hostapd.conf | grep -v '#' > hostapd.conf
awk 'NF' ap.cfg | grep -v '#' >> hostapd.conf
sed -i "s/wlan@@/$ssv_wlan/" load_dhcp.sh
sed -i "s/wlan@@/$ssv_wlan/" hostapd.conf
chmod 777 load_dhcp.sh
dhcp_config_file="/etc/default/isc-dhcp-server"
dhcp_config=$(grep "$ssv_wlan" $dhcp_config_file)
if [ "$dhcp_config" == "" ]; then
echo -en "${YELLOW}Config $dhcp_config_file.....${NC}"
rm -rf tmp
sed '/INTERFACE/d' /etc/default/isc-dhcp-server >>tmp
echo "INTERFACES=\"$ssv_wlan\"" >>tmp
rm -rf $dhcp_config_file
mv tmp /etc/default/isc-dhcp-server
echo -e "${YELLOW}OK${NC}"
fi
dir=$(pwd)
echo -e "${YELLOW}Wireless Done. ${NC}"
trap handle_stop INT
function version_great() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
nmcli_version=$(nmcli -v | cut -d ' ' -f 4)
chk_nmcli_version=0.9.8.999
function handle_stop() {
# popd
if version_great $nmcli_version $chk_nmcli_version; then
nmcli radio wifi on
else
nmcli nm wifi on
fi
echo -e "${YELLOW}Shutting down AP.${NC}"
./ap_shutdown.sh
}
if version_great $nmcli_version $chk_nmcli_version; then
nmcli radio wifi off
else
nmcli nm wifi off
fi
sudo rfkill unblock wlan
./load_dhcp.sh &
PID=$!
wait $PID
echo -e "${YELLOW}Load AP...${NC}"
echo -e "${GREEN}Launch hostapd.${NC}"
#run hostapd2.0
$HOSTPAD_DIR/hostapd/hostapd -t hostapd.conf