[package] opkg: fallback to dest->root_dir if specified overlay_root does not exist...
[openwrt.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 crypto=
71 ;;
72 esac
73 config_get ifname "$vif" ifname
74 config_get bridge "$vif" bridge
75 config_get ssid "$vif" ssid
76 config_get device "$vif" device
77 config_get channel "$device" channel
78 config_get hwmode "$device" hwmode
79 config_get wpa_group_rekey "$vif" wpa_group_rekey
80 config_get ieee80211d "$vif" ieee80211d
81 config_get_bool hidden "$vif" hidden 0
82 config_get_bool wds "$vif" wds 0
83 [ "$wds" -gt 0 -a "$driver" = "nl80211" ] && wds="wds_sta=1" || wds=""
84 case "$hwmode" in
85 bg) hwmode=g;;
86 esac
87 config_get country "$device" country
88 [ "$channel" = auto ] && channel=
89 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
90 [ -n "$hwmode" ] && {
91 config_get hwmode_11n "$device" hwmode_11n
92 [ -n "$hwmode_11n" ] && {
93 hwmode="$hwmode_11n"
94 config_get ht_capab "$device" ht_capab
95 [ -n "$ht_capab" -a -n "${ht_capab%%\[*}" ] && {
96 ht_capab=`echo "[$ht_capab]" | sed -e 's, ,][,g'`
97 }
98 }
99 }
100 cat > /var/run/hostapd-$ifname.conf <<EOF
101 ctrl_interface=/var/run/hostapd-$ifname
102 driver=$driver
103 interface=$ifname
104 ${hwmode:+hw_mode=$hwmode}
105 ${channel:+channel=$channel}
106 ${bridge:+bridge=$bridge}
107 ssid=$ssid
108 wpa=$wpa
109 ${crypto:+wpa_pairwise=$crypto}
110 ${country:+country_code=$country}
111 ${hwmode_11n:+ieee80211n=1}
112 ${ht_capab:+ht_capab=$ht_capab}
113 ${wpa_group_rekey:+wpa_group_rekey=$wpa_group_rekey}
114 ${ieee80211d:+ieee80211d=$ieee80211d}
115 $wds
116 $hostapd_cfg
117 EOF
118 case "$driver" in
119 madwifi)
120 ;;
121 *)
122 cat >> /var/run/hostapd-$ifname.conf <<EOF
123 ignore_broadcast_ssid=$hidden
124 wmm_enabled=1
125 wmm_ac_bk_cwmin=4
126 wmm_ac_bk_cwmax=10
127 wmm_ac_bk_aifs=7
128 wmm_ac_bk_txop_limit=0
129 wmm_ac_bk_acm=0
130 wmm_ac_be_aifs=3
131 wmm_ac_be_cwmin=4
132 wmm_ac_be_cwmax=10
133 wmm_ac_be_txop_limit=0
134 wmm_ac_be_acm=0
135 wmm_ac_vi_aifs=2
136 wmm_ac_vi_cwmin=3
137 wmm_ac_vi_cwmax=4
138 wmm_ac_vi_txop_limit=94
139 wmm_ac_vi_acm=0
140 wmm_ac_vo_aifs=2
141 wmm_ac_vo_cwmin=2
142 wmm_ac_vo_cwmax=3
143 wmm_ac_vo_txop_limit=47
144 wmm_ac_vo_acm=0
145 tx_queue_data3_aifs=7
146 tx_queue_data3_cwmin=15
147 tx_queue_data3_cwmax=1023
148 tx_queue_data3_burst=0
149 tx_queue_data2_aifs=3
150 tx_queue_data2_cwmin=15
151 tx_queue_data2_cwmax=63
152 tx_queue_data2_burst=0
153 tx_queue_data1_aifs=1
154 tx_queue_data1_cwmin=7
155 tx_queue_data1_cwmax=15
156 tx_queue_data1_burst=3.0
157 tx_queue_data0_aifs=1
158 tx_queue_data0_cwmin=3
159 tx_queue_data0_cwmax=7
160 tx_queue_data0_burst=1.5
161 EOF
162 ;;
163 esac
164 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf
165 }
166
This page took 0.049321 seconds and 5 git commands to generate.