blob: 78442d8aefe573ca863722cf4835604f013aede8 (
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
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
|
#!/bin/sh
set -e
[ "${IFACE%%[0-9]*}" = "wlan" ] || exit 0
[ "$IF_WIRELESS_SSID" ] || exit 1
[ "$IF_WIRELESS_CHANNEL" ] || exit 1
[ "$IF_WIRELESS_HWMODE" ] || IF_WIRELESS_HWMODE=g
[ "$IF_WIRELESS_EXTENSION" ] || IF_WIRELESS_EXTENSION=0
wpa=0
wpa1=0
wpa2=0
case "$IF_WIRELESS_SECURITY" in
none)
sec=1
;;
wep)
sec=2
;;
wpa)
sec=1
wpa1=1
;;
wpa2)
sec=1
wpa2=1
;;
wpa+wpa2)
sec=1
wpa=1
;;
*)
sec=1
;;
esac
case "$IF_WIRELESS_MODE" in
ap)
logger -t hostap "Creating hostapd configuration"
cat /etc/hostapd.conf > /tmp/hostapd.conf
chmod 600 /tmp/hostapd.conf
echo "interface=${IFACE}" >> /tmp/hostapd.conf
echo "ssid=$IF_WIRELESS_SSID" >> /tmp/hostapd.conf
echo "channel=$IF_WIRELESS_CHANNEL" >> /tmp/hostapd.conf
echo "hw_mode=$IF_WIRELESS_HWMODE" >> /tmp/hostapd.conf
echo "auth_algs=$sec" >> /tmp/hostapd.conf
[ $wpa -eq 0 ] && [ $wpa1 -eq 0 ] && [ $wpa2 -eq 0 ] && {
logger -t hostap "using no security mechanism"
echo "wpa=0" >> /tmp/hostapd.conf
}
[ $wpa1 -eq 1 ] && {
logger -t hostap "using WPA for security"
echo "wpa=1" >> /tmp/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf
echo "wpa_pairwise=TKIP" >> /tmp/hostapd.conf
echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf
}
[ $wpa2 -eq 1 ] && {
logger -t hostap "using WPA2 for security"
echo "wpa=2" >> /tmp/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf
echo "rsn_pairwise=CCMP" >> /tmp/hostapd.conf
echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf
}
[ $wpa -eq 1 ] && {
logger -t hostap "using WPA and WPA2 for security"
echo "wpa=3" >> /tmp/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> /tmp/hostapd.conf
echo "wpa_pairwise=TKIP" >> /tmp/hostapd.conf
echo "rsn_pairwise=CCMP" >> /tmp/hostapd.conf
echo "wpa_passphrase=$IF_WIRELESS_PASSPHRASE" >> /tmp/hostapd.conf
}
;;
sta)
ip link set up dev ${IFACE}
[ $IF_WIRELESS_EXTENSION -eq 1 ] && {
[ -x /usr/sbin/iwconfig ] || {
logger -t wireless "No wireless-tools found"
exit 1
}
driver=wext
iwconfig ${IFACE} essid $IF_WIRELESS_SSID
} || {
[ -x /usr/sbin/iw ] || {
logger -t wireless "No iw utility found"
exit 1
}
driver=nl80211
iw dev ${IFACE} set channel $IF_WIRELESS_CHANNEL
iw dev ${IFACE} connect $IF_WIRELESS_SSID
}
[ $wpa2 -eq 1 ] && {
[ -x /usr/sbin/wpa_supplicant ] || {
logger -t wireless "No wpa_supplicant found"
exit 1
}
touch /tmp/wpa_supplicant.conf
chmod 600 /tmp/wpa_supplicant.conf
echo "network={" > /tmp/wpa_supplicant.conf
echo " ssid=\"$IF_WIRELESS_SSID\"" >> /tmp/wpa_supplicant.conf
echo " psk=\"$IF_WIRELESS_PASSPHRASE\"" >> /tmp/wpa_supplicant.conf
echo " priority=5" >> /tmp/wpa_supplicant.conf
echo "}" >> /tmp/wpa_supplicant.conf
wpa_supplicant -B -D${driver} -i${IFACE} -c/tmp/wpa_supplicant.conf
}
;;
*)
echo "Unknown operation mode $IF_WIRELESS_MODE given!"
exit 1
;;
esac
exit 0
|