2 .
/lib
/netifd
/netifd-wireless.sh
3 .
/lib
/netifd
/hostapd.sh
5 init_wireless_driver
"$@"
7 MP_CONFIG_INT
="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh_max_peer_links
8 mesh_max_retries mesh_ttl mesh_element_ttl mesh_hwmp_max_preq_retries
9 mesh_path_refresh_time mesh_min_discovery_timeout mesh_hwmp_active_path_timeout
10 mesh_hwmp_preq_min_interval mesh_hwmp_net_diameter_traversal_time mesh_hwmp_rootmode
11 mesh_hwmp_rann_interval mesh_gate_announcements mesh_sync_offset_max_neighor
12 mesh_rssi_threshold mesh_hwmp_active_path_to_root_timeout mesh_hwmp_root_interval
13 mesh_hwmp_confirmation_interval mesh_awake_window mesh_plink_timeout"
14 MP_CONFIG_BOOL
="mesh_auto_open_plinks mesh_fwding"
15 MP_CONFIG_STRING
="mesh_power_mode"
17 drv_mac80211_init_device_config
() {
18 hostapd_common_add_device_config
20 config_add_string path phy
'macaddr:macaddr'
21 config_add_string hwmode
22 config_add_int beacon_int chanbw frag rts
23 config_add_int rxantenna txantenna antenna_gain txpower distance
24 config_add_boolean noscan
25 config_add_array ht_capab
39 config_add_int vht_max_mpdu vht_max_rx_stbc vht_link_adapt vht160
42 drv_mac80211_init_iface_config
() {
43 hostapd_common_add_bss_config
45 config_add_string
'macaddr:macaddr' ifname
47 config_add_boolean wds powersave
48 config_add_int maxassoc
49 config_add_int max_listen_int
50 config_add_int dtim_interval
53 config_add_string mesh_id
54 config_add_int
$MP_CONFIG_INT
55 config_add_boolean
$MP_CONFIG_BOOL
56 config_add_string
$MP_CONFIG_STRING
59 mac80211_add_capabilities
() {
60 local __var
="$1"; shift
61 local __mask
="$1"; shift
69 [ "$(($4))" -gt 0 ] ||
continue
70 [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] ||
continue
75 export -n -- "$__var=$__out"
78 mac80211_hostapd_setup_base
() {
83 [ "$auto_channel" -gt 0 ] && channel
=acs_survey
85 [ "$enable_ht" -gt 0 ] && {
86 json_get_vars noscan htmode
87 json_get_values ht_capab_list ht_capab
93 HT40
*|VHT40|VHT80|VHT160
)
94 case "$(( ($channel / 4) % 2 ))" in
95 1) ht_capab
="[HT40+]";;
96 0) ht_capab
="[HT40-]";;
102 [ -n "$ieee80211n" ] && {
103 append base_cfg
"ieee80211n=1" "$N"
115 for cap
in $
(iw phy
"$phy" info |
grep 'Capabilities:' | cut
-d: -f2); do
116 ht_cap_mask
="$(($ht_cap_mask | $cap))"
119 cap_rx_stbc
=$
((($ht_cap_mask >> 8) & 3))
120 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
121 ht_cap_mask
="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
123 mac80211_add_capabilities ht_capab_flags
$ht_cap_mask \
125 GF
:0x10::$greenfield \
126 SHORT-GI-20
:0x20::$short_gi_20 \
127 SHORT-GI-40
:0x40::$short_gi_40 \
128 TX-STBC
:0x80::$max_tx_stbc \
129 RX-STBC1
:0x300:0x100:1 \
130 RX-STBC12
:0x300:0x200:1 \
131 RX-STBC123
:0x300:0x300:1 \
132 DSSS_CCK-40
:0x1000::$dsss_cck_40
134 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab$ht_capab_flags" "$N"
142 case "$(( ($channel / 4) % 2 ))" in
143 1) idx
=$
(($channel + 2));;
144 0) idx
=$
(($channel - 2));;
147 append base_cfg
"vht_oper_chwidth=0" "$N"
148 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
151 case "$(( ($channel / 4) % 2 ))" in
152 1) idx
=$
(($channel + 6));;
153 2) idx
=$
(($channel + 2));;
154 3) idx
=$
(($channel - 2));;
155 0) idx
=$
(($channel - 6));;
158 append base_cfg
"vht_oper_chwidth=1" "$N"
159 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
163 36|
40|
44|
48|
52|
56|
60|
64) idx
=50;;
164 100|
104|
108|
112|
116|
120|
124|
128) idx
=114;;
167 append base_cfg
"vht_oper_chwidth=2" "$N"
168 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
172 if [ "$enable_ac" != "0" ]; then
184 rx_antenna_pattern
:1 \
185 tx_antenna_pattern
:1 \
191 append base_cfg
"ieee80211ac=1" "$N"
193 for cap
in $
(iw phy
"$phy" info |
awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
194 vht_cap
="$(($vht_cap | $cap))"
197 cap_rx_stbc
=$
((($vht_cap >> 8) & 7))
198 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
199 ht_cap_mask
="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
201 mac80211_add_capabilities vht_capab
$vht_cap \
202 RXLDPC
:0x10::$rxldpc \
203 SHORT-GI-80
:0x20::$short_gi_80 \
204 SHORT-GI-160
:0x40::$short_gi_160 \
205 TX-STBC-2BY1
:0x80::$tx_stbc \
206 SU-BEAMFORMER
:0x800::$su_beamformer \
207 SU-BEAMFORMEE
:0x1000::$su_beamformee \
208 MU-BEAMFORMER
:0x80000::$mu_beamformer \
209 MU-BEAMFORMEE
:0x100000::$mu_beamformee \
210 VHT-TXOP-PS
:0x200000::$vht_txop_ps \
211 HTC-VHT
:0x400000::$htc_vht \
212 RX-ANTENNA-PATTERN
:0x10000000::$rx_antenna_pattern \
213 TX-ANTENNA-PATTERN
:0x20000000::$tx_antenna_pattern \
214 RX-STBC1
:0x700:0x100:1 \
215 RX-STBC12
:0x700:0x200:1 \
216 RX-STBC123
:0x700:0x300:1 \
217 RX-STBC1234
:0x700:0x400:1 \
219 # supported Channel widths
221 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
223 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
225 [ "$vht160_hw" = 1 ] && vht_capab
="$vht_capab[VHT160]"
226 [ "$vht160_hw" = 2 ] && vht_capab
="$vht_capab[VHT160-80PLUS80]"
228 # maximum MPDU length
230 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
232 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
233 vht_max_mpdu_hw
=11454
234 [ "$vht_max_mpdu_hw" != 3895 ] && \
235 vht_capab
="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
237 # whether or not the STA supports link adaptation using VHT variant
239 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
241 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
243 [ "$vht_link_adapt_hw" != 0 ] && \
244 vht_capab
="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
246 [ -n "$vht_capab" ] && append base_cfg
"vht_capab=$vht_capab" "$N"
250 hostapd_prepare_device_config
"$hostapd_conf_file" nl80211
251 cat >> "$hostapd_conf_file" <<EOF
252 ${channel:+channel=$channel}
253 ${noscan:+noscan=$noscan}
260 mac80211_hostapd_setup_bss
() {
267 append hostapd_cfg
"$type=$ifname" "$N"
269 hostapd_set_bss_options hostapd_cfg
"$vif" ||
return 1
270 json_get_vars wds dtim_period max_listen_int
274 [ "$wds" -gt 0 ] && append hostapd_cfg
"wds_sta=1" "$N"
275 [ "$staidx" -gt 0 ] && append hostapd_cfg
"start_disabled=1" "$N"
277 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
280 ${dtim_period:+dtim_period=$dtim_period}
281 ${max_listen_int:+max_listen_interval=$max_listen_int}
285 mac80211_generate_mac
() {
287 local id
="${macidx:-0}"
289 local ref
="$(cat /sys/class/ieee80211/${phy}/macaddress)"
290 local mask
="$(cat /sys/class/ieee80211/${phy}/address_mask)"
292 [ "$mask" = "00:00:00:00:00:00" ] && mask
="ff:ff:ff:ff:ff:ff";
293 local oIFS
="$IFS"; IFS
=":"; set -- $mask; IFS
="$oIFS"
298 local oIFS
="$IFS"; IFS
=":"; set -- $ref; IFS
="$oIFS"
301 [ "$((0x$mask1))" -gt 0 ] && {
304 b1
=$
(($b1 ^
((($id - 1) << 2) | 0x2)))
305 printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
309 [ "$((0x$mask6))" -lt 255 ] && {
310 printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
314 off2=$(( (0x$6 + $id) / 0x100 ))
315 printf "%s:%s:%s:%s:%02x:%02x" \
317 $(( (0x$5 + $off2) % 0x100 )) \
318 $(( (0x$6 + $id) % 0x100 ))
322 [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
323 [ -n "$path" -a -d "/sys/devices/$path/ieee80211" ] && {
324 phy="$(ls /sys/devices/$path/ieee80211 | grep -m 1 phy)"
325 [ -n "$phy" ] && return 0
327 [ -n "$macaddr" ] && {
328 for phy in $(ls /sys/class/ieee80211 2>/dev
/null
); do
329 grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
335 mac80211_check_ap
() {
339 mac80211_prepare_vif
() {
342 json_get_vars ifname mode ssid wds powersave macaddr
344 [ -n "$ifname" ] || ifname
="wlan${phy#phy}${if_idx:+-$if_idx}"
345 if_idx
=$
((${if_idx:-0} + 1))
348 set_default powersave
0
352 [ -n "$macaddr" ] ||
{
353 macaddr
="$(mac80211_generate_mac $phy)"
354 macidx
="$(($macidx + 1))"
358 json_add_string ifname
"$ifname"
362 # It is far easier to delete and create the desired interface
365 iw phy
"$phy" interface add
"$ifname" type adhoc
368 # Hostapd will handle recreating the interface and
369 # subsequent virtual APs belonging to the same PHY
370 if [ -n "$hostapd_ctrl" ]; then
376 mac80211_hostapd_setup_bss
"$phy" "$ifname" "$macaddr" "$type" ||
return
378 [ -n "$hostapd_ctrl" ] ||
{
379 iw phy
"$phy" interface add
"$ifname" type managed
380 hostapd_ctrl
="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
384 json_get_vars key mesh_id
385 if [ -n "$key" ]; then
386 iw phy
"$phy" interface add
"$ifname" type mp
388 iw phy
"$phy" interface add
"$ifname" type mp mesh_id
"$mesh_id"
392 iw phy
"$phy" interface add
"$ifname" type monitor
396 staidx
="$(($staidx + 1))"
397 [ "$wds" -gt 0 ] && wdsflag
="4addr on"
398 iw phy
"$phy" interface add
"$ifname" type managed
$wdsflag
399 [ "$powersave" -gt 0 ] && powersave
="on" || powersave
="off"
400 iw
"$ifname" set power_save
"$powersave"
406 [ "$auto_channel" -gt 0 ] || iw dev
"$ifname" set channel
"$channel" $htmode
410 if [ "$mode" != "ap" ]; then
411 # ALL ap functionality will be passed to hostapd
412 # All interfaces must have unique mac addresses
413 # which can either be explicitly set in the device
414 # section, or automatically generated
415 ifconfig
"$ifname" hw ether
"$macaddr"
421 mac80211_setup_supplicant
() {
422 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
return 1
423 wpa_supplicant_add_network
"$ifname"
424 wpa_supplicant_run
"$ifname" ${hostapd_ctrl:+-H $hostapd_ctrl}
427 mac80211_setup_adhoc
() {
428 json_get_vars bssid ssid key mcast_rate
431 [ "$auth_type" == "wep" ] && {
436 for idx
in 1 2 3 4; do
437 json_get_var ikey
"key$idx"
440 ikey
="$(($idx - 1)):$(prepare_key_wep "$ikey")"
441 [ $idx -eq $key ] && ikey
="d:$ikey"
442 append keyspec
"$ikey"
447 append keyspec
"d:0:$(prepare_key_wep "$key")"
453 for br
in $basic_rate_list; do
454 hostapd_add_rate brstr
"$br"
458 [ -n "$mcast_rate" ] && hostapd_add_rate mcval
"$mcast_rate"
460 iw dev
"$ifname" ibss
join "$ssid" $freq $htmode fixed-freq
$bssid \
461 ${beacon_int:+beacon-interval $beacon_int} \
462 ${brstr:+basic-rates $brstr} \
463 ${mcval:+mcast-rate $mcval} \
464 ${keyspec:+keys $keyspec}
467 mac80211_setup_vif
() {
477 json_get_var vif_txpower txpower
479 ifconfig
"$ifname" up ||
{
480 wireless_setup_vif_failed IFUP_ERROR
485 set_default vif_txpower
"$txpower"
486 [ -z "$vif_txpower" ] || iw dev
"$ifname" set txpower fixed
"${vif_txpower%%.*}00"
490 for var
in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
491 json_get_var mp_val
"$var"
492 [ -n "$mp_val" ] && iw dev
"$ifname" set mesh_param
"$var" "$mp_val"
497 if [ -n "$key" ]; then
498 if [ -e "/lib/wifi/authsae.sh" ]; then
499 .
/lib
/wifi
/authsae.sh
500 authsae_start_interface || failed
=1
502 wireless_setup_vif_failed AUTHSAE_NOT_INSTALLED
509 wireless_vif_parse_encryption
510 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
511 mac80211_setup_supplicant || failed
=1
517 mac80211_setup_supplicant || failed
=1
522 [ -n "$failed" ] || wireless_add_vif
"$name" "$ifname"
528 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
531 mac80211_interface_cleanup() {
534 for wdev in $(list_phy_interfaces "$phy"); do
535 ifconfig "$wdev" down 2>/dev/null
540 drv_mac80211_cleanup() {
541 hostapd_common_cleanup
544 drv_mac80211_setup() {
548 country chanbw distance \
549 txpower antenna_gain \
550 rxantenna txantenna \
552 json_get_values basic_rate_list basic_rate
556 echo "Could not
find PHY
for device
'$1'"
561 wireless_set_data phy="$phy"
562 mac80211_interface_cleanup "$phy"
564 # convert channel to frequency
565 [ "$auto_channel" -gt 0 ] || freq="$
(get_freq
"$phy" "$channel")"
567 [ -n "$country" ] && {
568 iw reg get | grep -q "^country
$country:" || {
569 iw reg set "$country"
574 hostapd_conf_file="/var
/run
/hostapd-
$phy.conf
"
580 [ -n "$chanbw" ] && {
581 for file in /sys/kernel/debug/ieee80211/$phy/ath9k/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
582 [ -f "$file" ] && echo "$chanbw" > "$file"
586 set_default rxantenna all
587 set_default txantenna all
588 set_default distance 0
589 set_default antenna_gain 0
591 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
592 iw phy "$phy" set antenna_gain $antenna_gain
593 iw phy "$phy" set distance "$distance"
595 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
596 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
600 for_each_interface "ap
" mac80211_check_ap
602 rm -f "$hostapd_conf_file"
603 [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
605 for_each_interface "sta adhoc mesh monitor
" mac80211_prepare_vif
606 for_each_interface "ap
" mac80211_prepare_vif
608 [ -n "$hostapd_ctrl" ] && {
609 /usr/sbin/hostapd -P /var/run/wifi-$phy.pid -B "$hostapd_conf_file"
611 wireless_add_process "$
(cat /var
/run
/wifi-
$phy.pid
)" "/usr
/sbin
/hostapd
" 1
613 wireless_setup_failed HOSTAPD_START_FAILED
618 for_each_interface "ap sta adhoc mesh monitor
" mac80211_setup_vif
623 list_phy_interfaces() {
625 if [ -d "/sys
/class
/ieee80211
/${phy}/device
/net
" ]; then
626 ls "/sys
/class
/ieee80211
/${phy}/device
/net
" 2>/dev/null;
628 ls "/sys
/class
/ieee80211
/${phy}/device
" 2>/dev/null | grep net: | sed -e 's,net:,,g'
632 drv_mac80211_teardown() {
633 wireless_process_kill_all
639 mac80211_interface_cleanup "$phy"