2 append DRIVERS
"mac80211"
4 mac80211_hostapd_setup_base
() {
8 cfgfile
="/var/run/hostapd-$phy.conf"
9 config_get device
"$vif" device
10 config_get country
"$device" country
11 config_get hwmode
"$device" hwmode
12 config_get channel
"$device" channel
13 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode
"$device"
14 [ "$channel" = auto
] && channel
=
16 config_get hwmode_11n
"$device" hwmode_11n
17 [ -n "$hwmode_11n" ] && {
19 append base_cfg
"ieee80211n=1" "$N"
20 config_get htmode
"$device" htmode
21 config_get ht_capab_list
"$device" ht_capab
23 HT20|HT40
+|HT40-
) ht_capab
="[$htmode]";;
26 for cap
in $ht_capab_list; do
27 ht_capab
="$ht_capab[$cap]"
29 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
32 cat > "$cfgfile" <<EOF
33 ctrl_interface=/var/run/hostapd-$phy
38 wmm_ac_bk_txop_limit=0
43 wmm_ac_be_txop_limit=0
48 wmm_ac_vi_txop_limit=94
53 wmm_ac_vo_txop_limit=47
56 tx_queue_data3_cwmin=15
57 tx_queue_data3_cwmax=1023
58 tx_queue_data3_burst=0
60 tx_queue_data2_cwmin=15
61 tx_queue_data2_cwmax=63
62 tx_queue_data2_burst=0
64 tx_queue_data1_cwmin=7
65 tx_queue_data1_cwmax=15
66 tx_queue_data1_burst=3.0
68 tx_queue_data0_cwmin=3
69 tx_queue_data0_cwmax=7
70 tx_queue_data0_burst=1.5
71 ${hwmode:+hw_mode=$hwmode}
72 ${channel:+channel=$channel}
73 ${country:+country_code=$country}
79 mac80211_hostapd_setup_bss
() {
84 cfgfile
="/var/run/hostapd-$phy.conf"
85 config_get ifname
"$vif" ifname
87 if [ -f "$cfgfile" ]; then
88 append hostapd_cfg
"bss=$ifname" "$N"
90 mac80211_hostapd_setup_base
"$phy" "$ifname"
91 append hostapd_cfg
"interface=$ifname" "$N"
95 net_cfg
="$(find_net_config "$vif")"
96 [ -z "$net_cfg" ] || bridge
="$(bridge_interface "$net_cfg")"
97 config_set
"$vif" bridge
"$bridge"
99 hostapd_set_bss_options hostapd_cfg
"$vif"
101 config_get_bool wds
"$vif" wds
0
102 [ "$wds" -gt 0 ] && append hostapd_cfg
"wds_sta=1" "$N"
104 config_get macaddr
"$vif" macaddr
105 config_get_bool hidden
"$vif" hidden
0
106 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
110 ignore_broadcast_ssid=$hidden
114 mac80211_start_vif
() {
119 net_cfg
="$(find_net_config "$vif")"
120 [ -z "$net_cfg" ] || start_net
"$ifname" "$net_cfg"
122 set_wifi_up
"$vif" "$ifname"
125 find_mac80211_phy
() {
128 local macaddr
="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
129 config_get phy
"$device" phy
130 [ -z "$phy" -a -n "$macaddr" ] && {
131 for phy
in $
(ls /sys
/class
/ieee80211
2>/dev
/null
); do
132 [ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] ||
continue
133 config_set
"$device" phy
"$phy"
136 config_get phy
"$device" phy
138 [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] ||
{
139 echo "PHY for wifi device $1 not found"
142 [ -z "$macaddr" ] && {
143 config_set
"$device" macaddr
"$(cat /sys/class/ieee80211/${phy}/macaddress)"
150 local adhoc sta ap monitor mesh
152 config_get vifs
"$device" vifs
154 config_get mode
"$vif" mode
156 adhoc|sta|ap|monitor|mesh
)
159 *) echo "$device($vif): Invalid mode, ignored."; continue;;
163 config_set
"$device" vifs
"${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
170 find_mac80211_phy
"$device" ||
return 0
171 config_get phy
"$device" phy
173 set_wifi_down
"$device"
174 # kill all running hostapd and wpa_supplicant processes that
175 # are running on atheros/mac80211 vifs
176 for pid
in `pidof hostapd`; do
177 grep -E "$phy" /proc
/$pid/cmdline
>/dev
/null
&& \
182 for wdev
in $
(ls /sys
/class
/ieee80211
/${phy}/device
/net
2>/dev
/null
); do
183 [ -f "/var/run/$wdev.pid" ] && kill $
(cat /var
/run
/$wdev.pid
) >&/dev
/null
2>&1
184 for pid
in `pidof wpa_supplicant`; do
185 grep "$wdev" /proc
/$pid/cmdline
>/dev
/null
&& \
188 ifconfig
"$wdev" down
2>/dev
/null
198 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
202 config_get channel "$device" channel
203 config_get vifs "$device" vifs
204 config_get txpower "$device" txpower
205 config_get country "$device" country
206 config_get distance "$device" distance
207 find_mac80211_phy "$device" || return 0
208 config_get phy "$device" phy
214 [ -n "$country" ] && iw reg set "$country"
215 [ "$channel" = "auto
" -o "$channel" = "0" ] || {
219 [ -n "$distance" ] && iw phy "$phy" set distance "$distance"
222 # convert channel to frequency
223 local freq="$
(get_freq
"$phy" "${fixed:+$channel}")"
225 wifi_fixup_hwmode "$device" "g
"
227 while [ -d "/sys
/class
/net
/wlan
$i" ]; do
231 config_get ifname "$vif" ifname
232 [ -n "$ifname" ] || {
235 config_set "$vif" ifname "$ifname"
237 config_get enc "$vif" encryption
238 config_get mode "$vif" mode
239 config_get ssid "$vif" ssid
241 # It is far easier to delete and create the desired interface
244 iw phy "$phy" interface add "$ifname" type adhoc
247 # Hostapd will handle recreating the interface and
248 # it's accompanying monitor
249 apidx="$
(($apidx + 1))"
251 [ "$apidx" -gt 1 ] || iw phy "$phy" interface add "$ifname" type managed
254 config_get mesh_id "$vif" mesh_id
255 iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
258 iw phy "$phy" interface add "$ifname" type monitor
262 config_get_bool wds "$vif" wds 0
263 [ "$wds" -gt 0 ] && wdsflag="4addr on
"
264 iw phy "$phy" interface add "$ifname" type managed $wdsflag
265 config_get_bool powersave "$vif" powersave 0
266 [ "$powersave" -gt 0 ] && powersave="on
" || powersave="off
"
267 iwconfig "$ifname" power "$powersave"
271 # All interfaces must have unique mac addresses
272 # which can either be explicitly set in the device
273 # section, or automatically generated
274 config_get macaddr "$device" macaddr
275 local mac_1="${macaddr%%:*}"
276 local mac_2="${macaddr#*:}"
278 config_get vif_mac "$vif" macaddr
279 [ -n "$vif_mac" ] || {
280 if [ "$macidx" -gt 0 ]; then
281 offset="$
(( 2 + $macidx * 4 ))"
285 vif_mac="$
( printf %02x $
((0x
$mac_1 + $offset)) ):$mac_2"
286 macidx="$
(($macidx + 1))"
288 [ "$mode" = "ap
" ] || ifconfig "$ifname" hw ether "$vif_mac"
289 config_set "$vif" macaddr "$vif_mac"
296 # ALL ap functionality will be passed to hostapd
298 # !! mesh / adhoc / station !!
299 # none -> NO encryption
301 # wep + keymgmt = '' -> we use iw to connect to the
304 # wep + keymgmt = 'NONE' -> wpa_supplicant will be
305 # configured to handle the wep connection
306 if [ ! "$mode" = "ap
" ]; then
307 # We attempt to set the channel for all interfaces, although
308 # mac80211 may not support it or the driver might not yet
309 # for ap mode this is handled by hostapd
310 [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
316 config_get keymgmt "$vif" keymgmt
319 config_get keymgmt "$vif" keymgmt
320 if [ -z "$keymgmt" ]; then
321 config_get key "$vif" key
325 for idx in 1 2 3 4; do
328 config_get ckey "$vif" "key
${idx}"
329 if [ -n "$ckey" ]; then
330 [ $idx -eq $key ] && zidx="d
:${zidx}"
331 append keystring "${zidx}:$
(prepare_key_wep
"$ckey")"
336 keystring="d
:0:$
(prepare_key_wep
"$key")"
342 config_get key "$vif" key
347 # txpower is not yet implemented in iw
348 config_get vif_txpower "$vif" txpower
349 # use vif_txpower (from wifi-iface) to override txpower (from
350 # wifi-device) if the latter doesn't exist
351 txpower="${txpower:-$vif_txpower}"
352 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
354 config_get frag "$vif" frag
355 if [ -n "$frag" ]; then
356 iw phy "$phy" set frag "${frag%%.*}"
359 config_get rts "$vif" rts
360 if [ -n "$rts" ]; then
361 iw phy "$phy" set rts "${rts%%.*}"
364 ifconfig "$ifname" up
366 [ "$mode" = "ap
" ] || mac80211_start_vif "$vif" "$ifname"
370 config_get bssid "$vif" bssid
371 iw dev "$ifname" ibss join "$ssid" $freq ${fixed:+fixed-freq} $bssid
374 config_get bssid "$vif" bssid
377 if [ -z "$keymgmt" ]; then
378 [ -n "$keystring" ] &&
379 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid key $keystring
381 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
382 wpa_supplicant_setup_vif "$vif" wext || {
383 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
384 # make sure this wifi interface won't accidentally stay open without encryption
385 ifconfig "$ifname" down
392 config_get key "$vif" key
393 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
394 wpa_supplicant_setup_vif "$vif" wext || {
395 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
396 # make sure this wifi interface won't accidentally stay open without encryption
397 ifconfig "$ifname" down
403 if [ -z "$keymgmt" ]; then
404 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid
406 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
407 wpa_supplicant_setup_vif "$vif" wext || {
408 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
409 # make sure this wifi interface won't accidentally stay open without encryption
410 ifconfig "$ifname" down
423 rm -f /var/run/hostapd-$phy.conf
425 config_get mode "$vif" mode
426 [ "$mode" = "ap
" ] || continue
427 mac80211_hostapd_setup_bss "$phy" "$vif"
431 [ -n "$start_hostapd" ] || return 0
433 hostapd -P /var/run/wifi-$phy.pid -B /var/run/hostapd-$phy.conf || {
434 echo "Failed to start hostapd
for $phy"
440 config_get mode "$vif" mode
441 config_get ifname "$vif" ifname
442 [ "$mode" = "ap
" ] || continue
443 mac80211_start_vif "$vif" "$ifname"
449 config_get phy "$1" phy
451 find_mac80211_phy "$1" >/dev/null || return 0
452 config_get phy "$1" phy
454 [ "$phy" = "$dev" ] && found=1
461 config_get type "radio
$devidx" type
462 [ -n "$type" ] || break
463 devidx=$(($devidx + 1))
465 for dev in $(ls /sys/class/ieee80211); do
467 config_foreach check_device wifi-device
468 [ "$found" -gt 0 ] && continue
474 for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
475 ht_cap="$
(($ht_cap |
$cap))"
478 [ "$ht_cap" -gt 0 ] && {
480 append ht_capab " option htmode HT20
" "$N"
482 list=" list ht_capab
"
483 [ "$
(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC
" "$N"
484 [ "$
(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20
" "$N"
485 [ "$
(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40
" "$N"
486 [ "$
(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40
" "$N"
488 iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a
"; channel="36"; }
491 config wifi-device radio$devidx
493 option channel ${channel}
494 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
495 option hwmode 11${mode_11n}${mode_band}
497 # REMOVE THIS LINE TO ENABLE WIFI:
501 option device radio$devidx
505 option encryption none
508 devidx=$(($devidx + 1))