2 append DRIVERS
"mac80211"
4 mac80211_hostapd_setup_base
() {
8 cfgfile
="/var/run/hostapd-$phy.conf"
9 macfile
="/var/run/hostapd-$phy.maclist"
10 [ -e "$macfile" ] && rm -f "$macfile"
12 config_get device
"$vif" device
13 config_get country
"$device" country
14 config_get hwmode
"$device" hwmode
15 config_get channel
"$device" channel
16 config_get beacon_int
"$device" beacon_int
17 config_get basic_rate_list
"$device" basic_rate
18 config_get_bool noscan
"$device" noscan
20 hostapd_set_log_options base_cfg
"$device"
22 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode
"$device"
24 [ "$channel" = auto
] && {
25 channel
=$
(iw phy
"$phy" info | \
26 sed -ne '/MHz/ { /disabled\|passive\|radar/d; s/.*\[//; s/\].*//; p; q }')
27 config_set
"$device" channel
"$channel"
31 config_get hwmode_11n
"$device" hwmode_11n
32 [ -n "$hwmode_11n" ] && {
34 append base_cfg
"ieee80211n=1" "$N"
35 config_get htmode
"$device" htmode
36 config_get ht_capab_list
"$device" ht_capab
38 HT20|HT40
+|HT40-
) ht_capab
="[$htmode]";;
41 for cap
in $ht_capab_list; do
42 ht_capab
="$ht_capab[$cap]"
44 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
49 [ -n "$country" ] && country_ie
=1
50 config_get_bool country_ie
"$device" country_ie
"$country_ie"
51 [ "$country_ie" -gt 0 ] && append base_cfg
"ieee80211d=1" "$N"
53 config_get macfilter
"$vif" macfilter
56 append base_cfg
"macaddr_acl=1" "$N"
57 append base_cfg
"accept_mac_file=$macfile" "$N"
60 append base_cfg
"macaddr_acl=0" "$N"
61 append base_cfg
"deny_mac_file=$macfile" "$N"
64 config_get maclist
"$vif" maclist
65 [ -n "$maclist" ] && {
66 for mac
in $maclist; do
67 echo "$mac" >> $macfile
72 [ -n "$basic_rate_list" ] && {
73 for br
in $basic_rate_list; do
74 brval
="$(($br / 100))"
75 [ -n "$brstr" ] && brstr
="$brstr "
80 cat >> "$cfgfile" <<EOF
81 ctrl_interface=/var/run/hostapd-$phy
86 wmm_ac_bk_txop_limit=0
91 wmm_ac_be_txop_limit=0
96 wmm_ac_vi_txop_limit=94
101 wmm_ac_vo_txop_limit=47
103 tx_queue_data3_aifs=7
104 tx_queue_data3_cwmin=15
105 tx_queue_data3_cwmax=1023
106 tx_queue_data3_burst=0
107 tx_queue_data2_aifs=3
108 tx_queue_data2_cwmin=15
109 tx_queue_data2_cwmax=63
110 tx_queue_data2_burst=0
111 tx_queue_data1_aifs=1
112 tx_queue_data1_cwmin=7
113 tx_queue_data1_cwmax=15
114 tx_queue_data1_burst=3.0
115 tx_queue_data0_aifs=1
116 tx_queue_data0_cwmin=3
117 tx_queue_data0_cwmax=7
118 tx_queue_data0_burst=1.5
119 ${hwmode:+hw_mode=$hwmode}
120 ${channel:+channel=$channel}
121 ${beacon_int:+beacon_int=$beacon_int}
122 ${country:+country_code=$country}
123 ${noscan:+noscan=$noscan}
124 ${brstr:+basic_rates=$brstr}
130 mac80211_hostapd_setup_bss
() {
135 cfgfile
="/var/run/hostapd-$phy.conf"
136 config_get ifname
"$vif" ifname
138 if [ -f "$cfgfile" ]; then
139 append hostapd_cfg
"bss=$ifname" "$N"
141 mac80211_hostapd_setup_base
"$phy" "$ifname"
142 append hostapd_cfg
"interface=$ifname" "$N"
146 net_cfg
="$(find_net_config "$vif")"
147 [ -z "$net_cfg" ] || bridge
="$(bridge_interface "$net_cfg")"
148 config_set
"$vif" bridge
"$bridge"
150 hostapd_set_bss_options hostapd_cfg
"$vif"
152 config_get_bool wds
"$vif" wds
0
153 [ "$wds" -gt 0 ] && append hostapd_cfg
"wds_sta=1" "$N"
155 local macaddr hidden maxassoc wmm
156 config_get macaddr
"$vif" macaddr
157 config_get maxassoc
"$vif" maxassoc
158 config_get dtim_period
"$vif" dtim_period
159 config_get max_listen_int
"$vif" max_listen_int
160 config_get_bool hidden
"$vif" hidden
0
161 config_get_bool wmm
"$vif" wmm
1
162 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
166 ignore_broadcast_ssid=$hidden
167 ${dtim_period:+dtim_period=$dtim_period}
168 ${max_listen_int:+max_listen_interval=$max_listen_int}
169 ${maxassoc:+max_num_sta=$maxassoc}
173 mac80211_start_vif
() {
178 net_cfg
="$(find_net_config "$vif")"
179 [ -z "$net_cfg" ] || start_net
"$ifname" "$net_cfg"
181 set_wifi_up
"$vif" "$ifname"
184 find_mac80211_phy
() {
187 local macaddr
="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
188 config_get phy
"$device" phy
189 [ -z "$phy" -a -n "$macaddr" ] && {
190 for phy
in $
(ls /sys
/class
/ieee80211
2>/dev
/null
); do
191 [ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] ||
continue
192 config_set
"$device" phy
"$phy"
195 config_get phy
"$device" phy
197 [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] ||
{
198 echo "PHY for wifi device $1 not found"
201 [ -z "$macaddr" ] && {
202 config_set
"$device" macaddr
"$(cat /sys/class/ieee80211/${phy}/macaddress)"
209 local adhoc sta ap monitor mesh disabled
211 config_get vifs
"$device" vifs
213 config_get_bool disabled
"$vif" disabled
0
214 [ $disabled = 0 ] ||
continue
216 config_get mode
"$vif" mode
218 adhoc|sta|ap|monitor|mesh
)
221 *) echo "$device($vif): Invalid mode, ignored."; continue;;
225 config_set
"$device" vifs
"${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
228 list_phy_interfaces
() {
230 if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
231 ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev
/null
;
233 ls "/sys/class/ieee80211/${phy}/device" 2>/dev
/null |
grep net
: |
sed -e 's,net:,,g'
240 find_mac80211_phy
"$device" ||
return 0
241 config_get phy
"$device" phy
243 set_wifi_down
"$device"
244 # kill all running hostapd and wpa_supplicant processes that
245 # are running on atheros/mac80211 vifs
246 for pid
in `pidof hostapd`; do
247 grep -E "$phy" /proc
/$pid/cmdline
>/dev
/null
&& \
252 for wdev
in $
(list_phy_interfaces
"$phy"); do
253 [ -f "/var/run/$wdev.pid" ] && kill $
(cat /var
/run
/$wdev.pid
) >&/dev
/null
2>&1
254 for pid
in `pidof wpa_supplicant`; do
255 grep "$wdev" /proc
/$pid/cmdline
>/dev
/null
&& \
258 ifconfig
"$wdev" down
2>/dev
/null
268 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
272 config_get channel "$device" channel
273 config_get vifs "$device" vifs
274 config_get txpower "$device" txpower
275 config_get country "$device" country
276 config_get distance "$device" distance
277 config_get txantenna "$device" txantenna all
278 config_get rxantenna "$device" rxantenna all
279 config_get frag "$device" frag
280 config_get rts "$device" rts
281 find_mac80211_phy "$device" || return 0
282 config_get phy "$device" phy
287 local hostapd_ctrl=""
289 config_get ath9k_chanbw "$device" ath9k_chanbw
290 [ -n "$ath9k_chanbw" -a -d /sys/kernel/debug/ieee80211/$phy/ath9k ] && echo "$ath9k_chanbw" > /sys/kernel/debug/ieee80211/$phy/ath9k/chanbw
292 [ -n "$country" ] && iw reg set "$country"
293 [ "$channel" = "auto
" -o "$channel" = "0" ] || {
297 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
299 [ -n "$distance" ] && iw phy "$phy" set distance "$distance"
300 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
301 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
304 # convert channel to frequency
305 local freq="$
(get_freq
"$phy" "${fixed:+$channel}")"
307 wifi_fixup_hwmode "$device" "g
"
309 while [ -d "/sys
/class
/net
/wlan
$i" ]; do
313 config_get ifname "$vif" ifname
314 [ -n "$ifname" ] || {
317 config_set "$vif" ifname "$ifname"
319 config_get mode "$vif" mode
320 config_get ssid "$vif" ssid
322 # It is far easier to delete and create the desired interface
325 iw phy "$phy" interface add "$ifname" type adhoc
328 # Hostapd will handle recreating the interface and
329 # it's accompanying monitor
330 apidx="$
(($apidx + 1))"
332 [ "$apidx" -gt 1 ] || iw phy "$phy" interface add "$ifname" type managed
335 config_get mesh_id "$vif" mesh_id
336 iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
339 iw phy "$phy" interface add "$ifname" type monitor
343 config_get_bool wds "$vif" wds 0
344 [ "$wds" -gt 0 ] && wdsflag="4addr on
"
345 iw phy "$phy" interface add "$ifname" type managed $wdsflag
346 config_get_bool powersave "$vif" powersave 0
347 [ "$powersave" -gt 0 ] && powersave="on
" || powersave="off
"
348 iwconfig "$ifname" power "$powersave"
352 # All interfaces must have unique mac addresses
353 # which can either be explicitly set in the device
354 # section, or automatically generated
355 config_get macaddr "$device" macaddr
356 local mac_1="${macaddr%%:*}"
357 local mac_2="${macaddr#*:}"
359 config_get vif_mac "$vif" macaddr
360 [ -n "$vif_mac" ] || {
361 if [ "$macidx" -gt 0 ]; then
362 offset="$
(( 2 + $macidx * 4 ))"
366 vif_mac="$
( printf %02x $
((0x
$mac_1 + $offset)) ):$mac_2"
367 macidx="$
(($macidx + 1))"
369 [ "$mode" = "ap
" ] || ifconfig "$ifname" hw ether "$vif_mac"
370 config_set "$vif" macaddr "$vif_mac"
374 # ALL ap functionality will be passed to hostapd
378 # ALL station functionality will be passed to wpa_supplicant
380 if [ ! "$mode" = "ap
" ]; then
381 # We attempt to set the channel for all interfaces, although
382 # mac80211 may not support it or the driver might not yet
383 # for ap mode this is handled by hostapd
384 [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
387 config_get vif_txpower "$vif" txpower
388 # use vif_txpower (from wifi-iface) to override txpower (from
389 # wifi-device) if the latter doesn't exist
390 txpower="${txpower:-$vif_txpower}"
391 [ -z "$txpower" ] || iw dev "$ifname" set txpower fixed "${txpower%%.*}00"
395 rm -f /var/run/hostapd-$phy.conf
397 config_get mode "$vif" mode
398 [ "$mode" = "ap
" ] || continue
399 mac80211_hostapd_setup_bss "$phy" "$vif"
403 [ -n "$start_hostapd" ] && {
404 hostapd -P /var/run/wifi-$phy.pid -B /var/run/hostapd-$phy.conf || {
405 echo "Failed to start hostapd
for $phy"
411 config_get mode "$vif" mode
412 config_get ifname "$vif" ifname
413 [ "$mode" = "ap
" ] || continue
414 hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd-$phy/$ifname}"
415 mac80211_start_vif "$vif" "$ifname"
420 config_get mode "$vif" mode
421 config_get ifname "$vif" ifname
422 [ ! "$mode" = "ap
" ] || continue
423 ifconfig "$ifname" up
425 if [ ! "$mode" = "ap
" ]; then
426 ifconfig "$ifname" up
429 config_get bssid "$vif" bssid
430 config_get ssid "$vif" ssid
431 config_get beacon_int "$device" beacon_int
432 config_get basic_rate_list "$device" basic_rate
433 config_get encryption "$vif" encryption
434 config_get key "$vif" key 1
435 config_get mcast_rate "$vif" mcast_rate
438 [ "$encryption" == "wep
" ] && {
442 for idx in 1 2 3 4; do
444 config_get ikey "$vif" "key
$idx"
447 ikey="$
(($idx - 1)):$
(prepare_key_wep
"$ikey")"
448 [ $idx -eq $key ] && ikey="d
:$ikey"
449 append keyspec "$ikey"
453 *) append keyspec "d
:0:$
(prepare_key_wep
"$key")" ;;
457 local br brval brsub brstr
458 [ -n "$basic_rate_list" ] && {
459 for br in $basic_rate_list; do
460 brval="$
(($br / 1000))"
461 brsub="$
((($br / 100) % 10))"
462 [ "$brsub" -gt 0 ] && brval="$brval.
$brsub"
463 [ -n "$brstr" ] && brstr="$brstr,"
469 [ -n "$mcast_rate" ] && {
470 mcval="$
(($mcast_rate / 1000))"
471 mcsub="$
(( ($mcast_rate / 100) % 10 ))"
472 [ "$mcsub" -gt 0 ] && mcval="$mcval.
$mcsub"
475 config_get htmode "$device" htmode
481 iw dev "$ifname" ibss join "$ssid" $freq $htmode \
482 ${fixed:+fixed-freq} $bssid \
483 ${beacon_int:+beacon-interval $beacon_int} \
484 ${brstr:+basic-rates $brstr} \
485 ${mcval:+mcast-rate $mcval} \
486 ${keyspec:+keys $keyspec}
489 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
490 wpa_supplicant_setup_vif "$vif" nl80211 "${hostapd_ctrl:+-H $hostapd_ctrl}" || {
491 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
492 # make sure this wifi interface won't accidentally stay open without encryption
493 ifconfig "$ifname" down
499 mac80211_start_vif "$vif" "$ifname"
506 check_mac80211_device() {
507 config_get phy "$1" phy
509 find_mac80211_phy "$1" >/dev/null || return 0
510 config_get phy "$1" phy
512 [ "$phy" = "$dev" ] && found=1
519 config_get type "radio
$devidx" type
520 [ -n "$type" ] || break
521 devidx=$(($devidx + 1))
523 for dev in $(ls /sys/class/ieee80211); do
525 config_foreach check_mac80211_device wifi-device
526 [ "$found" -gt 0 ] && continue
532 for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
533 ht_cap="$
(($ht_cap |
$cap))"
536 [ "$ht_cap" -gt 0 ] && {
538 append ht_capab " option htmode HT20
" "$N"
540 list=" list ht_capab
"
541 [ "$
(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC
" "$N"
542 [ "$
(($ht_cap & 16))" -eq 16 ] && append ht_capab "$list GF
" "$N"
543 [ "$
(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20
" "$N"
544 [ "$
(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40
" "$N"
545 [ "$
(($ht_cap & 128))" -eq 128 ] && append ht_capab "$list TX-STBC
" "$N"
546 [ "$
(($ht_cap & 768))" -eq 256 ] && append ht_capab "$list RX-STBC1
" "$N"
547 [ "$
(($ht_cap & 768))" -eq 512 ] && append ht_capab "$list RX-STBC12
" "$N"
548 [ "$
(($ht_cap & 768))" -eq 768 ] && append ht_capab "$list RX-STBC123
" "$N"
549 [ "$
(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40
" "$N"
551 iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a
"; channel="36"; }
554 config wifi-device radio$devidx
556 option channel ${channel}
557 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
558 option hwmode 11${mode_11n}${mode_band}
560 # REMOVE THIS LINE TO ENABLE WIFI:
564 option device radio$devidx
568 option encryption none
571 devidx=$(($devidx + 1))