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 config_get_bool noscan "$device" noscan
14 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
15 [ "$channel" = auto ] && channel=
17 config_get hwmode_11n "$device" hwmode_11n
18 [ -n "$hwmode_11n" ] && {
20 append base_cfg "ieee80211n=1" "$N"
21 config_get htmode "$device" htmode
22 config_get ht_capab_list "$device" ht_capab
24 HT20|HT40+|HT40-) ht_capab="[$htmode]";;
27 for cap in $ht_capab_list; do
28 ht_capab="$ht_capab[$cap]"
30 [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
33 cat > "$cfgfile" <<EOF
34 ctrl_interface=/var/run/hostapd-$phy
39 wmm_ac_bk_txop_limit=0
44 wmm_ac_be_txop_limit=0
49 wmm_ac_vi_txop_limit=94
54 wmm_ac_vo_txop_limit=47
57 tx_queue_data3_cwmin=15
58 tx_queue_data3_cwmax=1023
59 tx_queue_data3_burst=0
61 tx_queue_data2_cwmin=15
62 tx_queue_data2_cwmax=63
63 tx_queue_data2_burst=0
65 tx_queue_data1_cwmin=7
66 tx_queue_data1_cwmax=15
67 tx_queue_data1_burst=3.0
69 tx_queue_data0_cwmin=3
70 tx_queue_data0_cwmax=7
71 tx_queue_data0_burst=1.5
72 ${hwmode:+hw_mode=$hwmode}
73 ${channel:+channel=$channel}
74 ${country:+country_code=$country}
75 ${noscan:+noscan=$noscan}
81 mac80211_hostapd_setup_bss() {
86 cfgfile="/var/run/hostapd-$phy.conf"
87 config_get ifname "$vif" ifname
89 if [ -f "$cfgfile" ]; then
90 append hostapd_cfg "bss=$ifname" "$N"
92 mac80211_hostapd_setup_base "$phy" "$ifname"
93 append hostapd_cfg "interface=$ifname" "$N"
97 net_cfg="$(find_net_config "$vif")"
98 [ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
99 config_set "$vif" bridge "$bridge"
101 hostapd_set_bss_options hostapd_cfg "$vif"
103 config_get_bool wds "$vif" wds 0
104 [ "$wds" -gt 0 ] && append hostapd_cfg "wds_sta=1" "$N"
106 config_get macaddr "$vif" macaddr
107 config_get_bool hidden "$vif" hidden 0
108 cat >> /var/run/hostapd-$phy.conf <<EOF
112 ignore_broadcast_ssid=$hidden
116 mac80211_start_vif() {
121 net_cfg="$(find_net_config "$vif")"
122 [ -z "$net_cfg" ] || start_net "$ifname" "$net_cfg"
124 set_wifi_up "$vif" "$ifname"
127 find_mac80211_phy() {
130 local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
131 config_get phy "$device" phy
132 [ -z "$phy" -a -n "$macaddr" ] && {
133 for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
134 [ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] || continue
135 config_set "$device" phy "$phy"
138 config_get phy "$device" phy
140 [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
141 echo "PHY for wifi device $1 not found"
144 [ -z "$macaddr" ] && {
145 config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
152 local adhoc sta ap monitor mesh
154 config_get vifs "$device" vifs
156 config_get mode "$vif" mode
158 adhoc|sta|ap|monitor|mesh)
161 *) echo "$device($vif): Invalid mode, ignored."; continue;;
165 config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
168 list_phy_interfaces() {
170 if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
171 ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
173 ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g'
180 find_mac80211_phy "$device" || return 0
181 config_get phy "$device" phy
183 set_wifi_down "$device"
184 # kill all running hostapd and wpa_supplicant processes that
185 # are running on atheros/mac80211 vifs
186 for pid in `pidof hostapd`; do
187 grep -E "$phy" /proc/$pid/cmdline >/dev/null && \
192 for wdev in $(list_phy_interfaces "$phy"); do
193 [ -f "/var/run/$wdev.pid" ] && kill $(cat /var/run/$wdev.pid) >&/dev/null 2>&1
194 for pid in `pidof wpa_supplicant`; do
195 grep "$wdev" /proc/$pid/cmdline >/dev/null && \
198 ifconfig "$wdev" down 2>/dev/null
208 iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
212 config_get channel "$device" channel
213 config_get vifs "$device" vifs
214 config_get txpower "$device" txpower
215 config_get country "$device" country
216 config_get distance "$device" distance
217 config_get frag "$device" frag
218 config_get rts "$device" rts
219 find_mac80211_phy "$device" || return 0
220 config_get phy "$device" phy
226 [ -n "$country" ] && iw reg set "$country"
227 [ "$channel" = "auto" -o "$channel" = "0" ] || {
231 [ -n "$distance" ] && iw phy "$phy" set distance "$distance"
232 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
233 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
236 # convert channel to frequency
237 local freq="$(get_freq "$phy" "${fixed:+$channel}")"
239 wifi_fixup_hwmode "$device" "g"
241 while [ -d "/sys/class/net/wlan$i" ]; do
245 config_get ifname "$vif" ifname
246 [ -n "$ifname" ] || {
249 config_set "$vif" ifname "$ifname"
251 config_get mode "$vif" mode
252 config_get ssid "$vif" ssid
254 # It is far easier to delete and create the desired interface
257 iw phy "$phy" interface add "$ifname" type adhoc
260 # Hostapd will handle recreating the interface and
261 # it's accompanying monitor
262 apidx="$(($apidx + 1))"
264 [ "$apidx" -gt 1 ] || iw phy "$phy" interface add "$ifname" type managed
267 config_get mesh_id "$vif" mesh_id
268 iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
271 iw phy "$phy" interface add "$ifname" type monitor
275 config_get_bool wds "$vif" wds 0
276 [ "$wds" -gt 0 ] && wdsflag="4addr on"
277 iw phy "$phy" interface add "$ifname" type managed $wdsflag
278 config_get_bool powersave "$vif" powersave 0
279 [ "$powersave" -gt 0 ] && powersave="on" || powersave="off"
280 iwconfig "$ifname" power "$powersave"
284 # All interfaces must have unique mac addresses
285 # which can either be explicitly set in the device
286 # section, or automatically generated
287 config_get macaddr "$device" macaddr
288 local mac_1="${macaddr%%:*}"
289 local mac_2="${macaddr#*:}"
291 config_get vif_mac "$vif" macaddr
292 [ -n "$vif_mac" ] || {
293 if [ "$macidx" -gt 0 ]; then
294 offset="$(( 2 + $macidx * 4 ))"
298 vif_mac="$( printf %02x $((0x$mac_1 + $offset)) ):$mac_2"
299 macidx="$(($macidx + 1))"
301 [ "$mode" = "ap" ] || ifconfig "$ifname" hw ether "$vif_mac"
302 config_set "$vif" macaddr "$vif_mac"
306 # ALL ap functionality will be passed to hostapd
310 # ALL station functionality will be passed to wpa_supplicant
312 if [ ! "$mode" = "ap" ]; then
313 # We attempt to set the channel for all interfaces, although
314 # mac80211 may not support it or the driver might not yet
315 # for ap mode this is handled by hostapd
316 [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
319 # txpower is not yet implemented in iw
320 config_get vif_txpower "$vif" txpower
321 # use vif_txpower (from wifi-iface) to override txpower (from
322 # wifi-device) if the latter doesn't exist
323 txpower="${txpower:-$vif_txpower}"
324 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
328 rm -f /var/run/hostapd-$phy.conf
330 config_get mode "$vif" mode
331 [ "$mode" = "ap" ] || continue
332 mac80211_hostapd_setup_bss "$phy" "$vif"
336 [ -n "$start_hostapd" ] && {
337 hostapd -P /var/run/wifi-$phy.pid -B /var/run/hostapd-$phy.conf || {
338 echo "Failed to start hostapd for $phy"
344 config_get mode "$vif" mode
345 config_get ifname "$vif" ifname
346 [ "$mode" = "ap" ] || continue
347 mac80211_start_vif "$vif" "$ifname"
352 config_get mode "$vif" mode
353 config_get ifname "$vif" ifname
354 [ ! "$mode" = "ap" ] || continue
355 ifconfig "$ifname" up
357 if [ ! "$mode" = "ap" ]; then
358 ifconfig "$ifname" up
361 config_get bssid "$vif" bssid
362 config_get ssid "$vif" ssid
363 iw dev "$ifname" ibss join "$ssid" $freq ${fixed:+fixed-freq} $bssid
366 if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
367 wpa_supplicant_setup_vif "$vif" nl80211 || {
368 echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
369 # make sure this wifi interface won't accidentally stay open without encryption
370 ifconfig "$ifname" down
376 mac80211_start_vif "$vif" "$ifname"
384 config_get phy "$1" phy
386 find_mac80211_phy "$1" >/dev/null || return 0
387 config_get phy "$1" phy
389 [ "$phy" = "$dev" ] && found=1
396 config_get type "radio$devidx" type
397 [ -n "$type" ] || break
398 devidx=$(($devidx + 1))
400 for dev in $(ls /sys/class/ieee80211); do
402 config_foreach check_device wifi-device
403 [ "$found" -gt 0 ] && continue
409 for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
410 ht_cap="$(($ht_cap | $cap))"
413 [ "$ht_cap" -gt 0 ] && {
415 append ht_capab " option htmode HT20" "$N"
417 list=" list ht_capab"
418 [ "$(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC" "$N"
419 [ "$(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20" "$N"
420 [ "$(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40" "$N"
421 [ "$(($ht_cap & 128))" -eq 128 ] && append ht_capab "$list TX-STBC" "$N"
422 [ "$(($ht_cap & 768))" -eq 256 ] && append ht_capab "$list RX-STBC1" "$N"
423 [ "$(($ht_cap & 768))" -eq 512 ] && append ht_capab "$list RX-STBC12" "$N"
424 [ "$(($ht_cap & 768))" -eq 768 ] && append ht_capab "$list RX-STBC123" "$N"
425 [ "$(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40" "$N"
427 iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
430 config wifi-device radio$devidx
432 option channel ${channel}
433 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
434 option hwmode 11${mode_11n}${mode_band}
436 # REMOVE THIS LINE TO ENABLE WIFI:
440 option device radio$devidx
444 option encryption none
447 devidx=$(($devidx + 1))