merge r13084 to 8.09
[openwrt/svn-archive/archive.git] / package / hostapd / files / hostapd.sh
1 hostapd_setup_vif() {
2 local vif="$1"
3 local driver="$2"
4 local hostapd_cfg=
5
6 # Examples:
7 # psk-mixed/tkip => WPA1+2 PSK, TKIP
8 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
9 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
10 # ...
11
12 # TODO: move this parsing function somewhere generic, so that
13 # later it can be reused by drivers that don't use hostapd
14
15 # crypto defaults: WPA2 vs WPA1
16 case "$enc" in
17 wpa2*|WPA2*|*PSK2*|*psk2*)
18 wpa=2
19 crypto="CCMP"
20 ;;
21 *mixed*)
22 wpa=3
23 crypto="CCMP TKIP"
24 ;;
25 *)
26 wpa=1
27 crypto="TKIP"
28 ;;
29 esac
30
31 # explicit override for crypto setting
32 case "$enc" in
33 *tkip+aes|*TKIP+AES|*tkip+ccmp|*TKIP+CCMP) crypto="CCMP TKIP";;
34 *tkip|*TKIP) crypto="TKIP";;
35 *aes|*AES|*ccmp|*CCMP) crypto="CCMP";;
36 esac
37
38 # use crypto/auth settings for building the hostapd config
39 case "$enc" in
40 *psk*|*PSK*)
41 config_get psk "$vif" key
42 if [ ${#psk} -eq 64 ]; then
43 append hostapd_cfg "wpa_psk=$psk" "$N"
44 else
45 append hostapd_cfg "wpa_passphrase=$psk" "$N"
46 fi
47 ;;
48 *wpa*|*WPA*)
49 # required fields? formats?
50 # hostapd is particular, maybe a default configuration for failures
51 config_get server "$vif" server
52 append hostapd_cfg "auth_server_addr=$server" "$N"
53 config_get port "$vif" port
54 port=${port:-1812}
55 append hostapd_cfg "auth_server_port=$port" "$N"
56 config_get secret "$vif" key
57 append hostapd_cfg "auth_server_shared_secret=$secret" "$N"
58 config_get nasid "$vif" nasid
59 append hostapd_cfg "nas_identifier=$nasid" "$N"
60 append hostapd_cfg "eapol_key_index_workaround=1" "$N"
61 append hostapd_cfg "radius_acct_interim_interval=300" "$N"
62 append hostapd_cfg "ieee8021x=1" "$N"
63 append hostapd_cfg "auth_algs=1" "$N"
64 append hostapd_cfg "wpa_key_mgmt=WPA-EAP" "$N"
65 append hostapd_cfg "wpa_group_rekey=300" "$N"
66 append hostapd_cfg "wpa_gmk_rekey=640" "$N"
67 ;;
68 *)
69 wpa=0
70 ;;
71 esac
72 config_get ifname "$vif" ifname
73 config_get bridge "$vif" bridge
74 config_get ssid "$vif" ssid
75 config_get device "$vif" device
76 config_get channel "$device" channel
77 config_get agmode "$device" agmode
78 case "$agmode" in
79 11a) agmode=a;;
80 11b) agmode=b;;
81 11g) agmode=g;;
82 *)
83 agmode=
84 [ "$channel" -gt 14 ] && agmode=a
85 ;;
86 esac
87 cat > /var/run/hostapd-$ifname.conf <<EOF
88 driver=$driver
89 interface=$ifname
90 hw_mode=${agmode:-g}
91 channel=$channel
92 ${bridge:+bridge=$bridge}
93 ssid=$ssid
94 debug=0
95 wpa=$wpa
96 wpa_pairwise=$crypto
97 $hostapd_cfg
98 EOF
99 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf
100 }
101