[package] hostapd: allow mixed TKIP/CCMP for 11n
[openwrt.git] / package / hostapd / files / hostapd.sh
1 hostapd_set_bss_options() {
2 local var="$1"
3 local vif="$2"
4 local enc wpa_group_rekey wps_possible
5
6 config_get enc "$vif" encryption
7 config_get wpa_group_rekey "$vif" wpa_group_rekey
8 config_get_bool ap_isolate "$vif" isolate 0
9
10 config_get device "$vif" device
11 config_get hwmode "$device" hwmode
12 config_get phy "$device" phy
13
14 append "$var" "ctrl_interface=/var/run/hostapd-$phy" "$N"
15
16 if [ "$ap_isolate" -gt 0 ]; then
17 append "$var" "ap_isolate=$ap_isolate" "$N"
18 fi
19
20 # Examples:
21 # psk-mixed/tkip => WPA1+2 PSK, TKIP
22 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
23 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
24 # ...
25
26 # TODO: move this parsing function somewhere generic, so that
27 # later it can be reused by drivers that don't use hostapd
28
29 # crypto defaults: WPA2 vs WPA1
30 case "$enc" in
31 wpa2*|*psk2*)
32 wpa=2
33 crypto="CCMP"
34 ;;
35 *mixed*)
36 wpa=3
37 crypto="CCMP TKIP"
38 ;;
39 *)
40 wpa=1
41 crypto="TKIP"
42 ;;
43 esac
44
45 # explicit override for crypto setting
46 case "$enc" in
47 *tkip+aes|*tkip+ccmp|*aes+tkip|*ccmp+tkip) crypto="CCMP TKIP";;
48 *aes|*ccmp) crypto="CCMP";;
49 *tkip) crypto="TKIP";;
50 esac
51
52 # enforce CCMP for 11ng and 11na
53 case "$hwmode:$crypto" in
54 *ng:TKIP|*na:TKIP) crypto="CCMP TKIP";;
55 esac
56
57 # use crypto/auth settings for building the hostapd config
58 case "$enc" in
59 *psk*)
60 config_get psk "$vif" key
61 if [ ${#psk} -eq 64 ]; then
62 append "$var" "wpa_psk=$psk" "$N"
63 else
64 append "$var" "wpa_passphrase=$psk" "$N"
65 fi
66 wps_possible=1
67 ;;
68 *wpa*)
69 # required fields? formats?
70 # hostapd is particular, maybe a default configuration for failures
71 config_get server "$vif" server
72 append "$var" "auth_server_addr=$server" "$N"
73 config_get port "$vif" port
74 port=${port:-1812}
75 append "$var" "auth_server_port=$port" "$N"
76 config_get secret "$vif" key
77 append "$var" "auth_server_shared_secret=$secret" "$N"
78 config_get nasid "$vif" nasid
79 append "$var" "nas_identifier=$nasid" "$N"
80 append "$var" "eapol_key_index_workaround=1" "$N"
81 append "$var" "radius_acct_interim_interval=300" "$N"
82 append "$var" "ieee8021x=1" "$N"
83 append "$var" "wpa_key_mgmt=WPA-EAP" "$N"
84 append "$var" "wpa_group_rekey=300" "$N"
85 append "$var" "wpa_gmk_rekey=640" "$N"
86 ;;
87 *wep*)
88 config_get key "$vif" key
89 key="${key:-1}"
90 case "$key" in
91 [1234])
92 for idx in 1 2 3 4; do
93 local zidx
94 zidx=$(($idx - 1))
95 config_get ckey "$vif" "key${idx}"
96 [ -n "$ckey" ] && \
97 append "$var" "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N"
98 done
99 append "$var" "wep_default_key=$((key - 1))" "$N"
100 ;;
101 *)
102 append "$var" "wep_key0=$(prepare_key_wep "$key")" "$N"
103 append "$var" "wep_default_key=0" "$N"
104 ;;
105 esac
106 case "$enc" in
107 *shared*)
108 auth_algs=2
109 ;;
110 *mixed*)
111 auth_algs=3
112 ;;
113 esac
114 wpa=0
115 crypto=
116 ;;
117 *)
118 wpa=0
119 crypto=
120 ;;
121 esac
122 append "$var" "auth_algs=${auth_algs:-1}" "$N"
123 append "$var" "wpa=$wpa" "$N"
124 [ -n "$crypto" ] && append "$var" "wpa_pairwise=$crypto" "$N"
125 [ -n "$wpa_group_rekey" ] && append "$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
126
127 config_get ssid "$vif" ssid
128 config_get bridge "$vif" bridge
129 config_get ieee80211d "$vif" ieee80211d
130 config_get iapp_interface "$vif" iapp_interface
131
132 config_get_bool wps_pbc "$vif" wps_pushbutton 0
133 [ -n "$wps_possible" -a "$wps_pbc" -gt 0 ] && {
134 append "$var" "eap_server=1" "$N"
135 append "$var" "wps_state=2" "$N"
136 append "$var" "ap_setup_locked=1" "$N"
137 append "$var" "config_methods=push_button" "$N"
138 }
139
140 append "$var" "ssid=$ssid" "$N"
141 [ -n "$bridge" ] && append "$var" "bridge=$bridge" "$N"
142 [ -n "$ieee80211d" ] && append "$var" "ieee80211d=$ieee80211d" "$N"
143 [ -n "$iapp_interface" ] && append "$var" iapp_interface=$(uci_get_state network "$iapp_interface" ifname "$iapp_interface") "$N"
144
145 if [ "$wpa" -ge "2" ]
146 then
147 # RSN -> allow preauthentication
148 config_get rsn_preauth "$vif" rsn_preauth
149 if [ -n "$bridge" -a "$rsn_preauth" = 1 ]
150 then
151 append "$var" "rsn_preauth=1" "$N"
152 append "$var" "rsn_preauth_interfaces=$bridge" "$N"
153 fi
154
155 # RSN -> allow management frame protection
156 config_get ieee80211w "$vif" ieee80211w
157 case "$ieee80211w" in
158 [012])
159 append "$var" "ieee80211w=$ieee80211w" "$N"
160 [ "$ieee80211w" -gt "0" ] && {
161 config_get ieee80211w_max_timeout "$vif" ieee80211w_max_timeout
162 config_get ieee80211w_retry_timeout "$vif" ieee80211w_retry_timeout
163 [ -n "$ieee80211w_max_timeout" ] && \
164 append "$var" "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
165 [ -n "$ieee80211w_retry_timeout" ] && \
166 append "$var" "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
167 }
168 ;;
169 esac
170 fi
171 }
172
173 hostapd_setup_vif() {
174 local vif="$1"
175 local driver="$2"
176 hostapd_cfg=
177
178 hostapd_set_bss_options hostapd_cfg "$vif"
179 config_get ifname "$vif" ifname
180 config_get device "$vif" device
181 config_get channel "$device" channel
182 config_get hwmode "$device" hwmode
183 case "$hwmode" in
184 *bg|*gdt|*gst|*fh) hwmode=g;;
185 *adt|*ast) hwmode=a;;
186 esac
187 [ "$channel" = auto ] && channel=
188 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
189 cat > /var/run/hostapd-$ifname.conf <<EOF
190 driver=$driver
191 interface=$ifname
192 ${hwmode:+hw_mode=${hwmode#11}}
193 ${channel:+channel=$channel}
194 $hostapd_cfg
195 EOF
196 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf
197 }
198
This page took 0.049744 seconds and 5 git commands to generate.