blob: bbd6258f1deb0a504441666d9b09a9c3dbd820f5 (
plain)
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
|
#!/bin/sh -x
wifi=wlan0
iface=@wifi-iface[0]
radio=$(uci get wireless.${iface}.device)
connect_wifi(){
# channel ssid encryption key
uci set wireless.${iface}.mode=sta
ifconfig $wifi up
uci set wireless.${radio}.channel=$1
uci set "wireless.${iface}.ssid=$2"
if [ $3 == "none" ] ; then
uci set wireless.${iface}.encryption=none
uci -q delete wireless.${iface}.key
else
uci set "wireless.${iface}.key=$4"
uci set wireless.${iface}.encryption=$3
fi
uci commit wireless
wifi up
}
iwlist_scan(){
count=0
iwlist scan ${1:-} 2>/dev/null | ( while read line;
do
case "$line" in
*"Cell "*)
#echo
: $((count+=1))
echo MAC_${count}="${line#*Address: }"
;;
*Channel:*)
echo CHANNEL_${count}="${line#*:}"
;;
*Quality=*)
echo QUALITY_${count}="`printf '%s' ${line#*Quality=} | cut -d/ -f 1`"
;;
*"Encryption key:"*)
echo ENCRYPTION_${count}="${line#*key:}"
;;
*ESSID:*)
echo ESSID_${count}="${line#*ESSID:}"
;;
*"IE: IEEE 802.11i/WPA2"*)
echo WPA2_${count}=1
;;
*"IE: WPA Version 1"*)
echo WPA_${count}=1
;;
*);;
esac
done; echo WIFI_COUNT=$count)
}
iwlist_scan > /tmp/${wifi}.scan
connect_wifi "$@"
|