2 .
/lib
/netifd
/netifd-wireless.sh
3 .
/lib
/netifd
/hostapd.sh
4 .
/lib
/functions
/system.sh
6 init_wireless_driver
"$@"
8 MP_CONFIG_INT
="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh_max_peer_links
9 mesh_max_retries mesh_ttl mesh_element_ttl mesh_hwmp_max_preq_retries
10 mesh_path_refresh_time mesh_min_discovery_timeout mesh_hwmp_active_path_timeout
11 mesh_hwmp_preq_min_interval mesh_hwmp_net_diameter_traversal_time mesh_hwmp_rootmode
12 mesh_hwmp_rann_interval mesh_gate_announcements mesh_sync_offset_max_neighor
13 mesh_rssi_threshold mesh_hwmp_active_path_to_root_timeout mesh_hwmp_root_interval
14 mesh_hwmp_confirmation_interval mesh_awake_window mesh_plink_timeout"
15 MP_CONFIG_BOOL
="mesh_auto_open_plinks mesh_fwding"
16 MP_CONFIG_STRING
="mesh_power_mode"
19 ucode
/usr
/share
/hostap
/wdev.uc
"$@"
22 drv_mac80211_init_device_config
() {
23 hostapd_common_add_device_config
25 config_add_string path phy
'macaddr:macaddr'
26 config_add_string tx_burst
27 config_add_string distance
28 config_add_int beacon_int chanbw frag rts
29 config_add_int rxantenna txantenna txpower min_tx_power
30 config_add_boolean noscan ht_coex acs_exclude_dfs background_radar
31 config_add_array ht_capab
32 config_add_array channels
33 config_add_array scan_list
52 he_bss_color_enabled \
57 vht_max_a_mpdu_len_exp \
64 he_spr_non_srg_obss_pd_max_offset
74 drv_mac80211_init_iface_config
() {
75 hostapd_common_add_bss_config
77 config_add_string
'macaddr:macaddr' ifname
79 config_add_boolean wds powersave
enable
80 config_add_string wds_bridge
81 config_add_int maxassoc
82 config_add_int max_listen_int
83 config_add_int dtim_period
84 config_add_int start_disabled
87 config_add_string mesh_id
88 config_add_int
$MP_CONFIG_INT
89 config_add_boolean
$MP_CONFIG_BOOL
90 config_add_string
$MP_CONFIG_STRING
93 mac80211_add_capabilities
() {
94 local __var
="$1"; shift
95 local __mask
="$1"; shift
100 for capab
in "$@"; do
103 [ "$(($4))" -gt 0 ] ||
continue
104 [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] ||
continue
109 export -n -- "$__var=$__out"
112 mac80211_add_he_capabilities
() {
117 for capab
in "$@"; do
119 [ "$(($4))" -gt 0 ] ||
continue
120 [ "$(((0x$2) & $3))" -gt 0 ] ||
{
124 append base_cfg
"$1=1" "$N"
129 mac80211_hostapd_setup_base
() {
134 [ "$auto_channel" -gt 0 ] && channel
=acs_survey
136 [ "$auto_channel" -gt 0 ] && json_get_vars acs_exclude_dfs
137 [ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
138 append base_cfg
"acs_exclude_dfs=1" "$N"
140 json_get_vars noscan ht_coex min_tx_power
:0 tx_burst
141 json_get_values ht_capab_list ht_capab
142 json_get_values channel_list channels
144 [ "$auto_channel" = 0 ] && [ -z "$channel_list" ] && \
145 channel_list
="$channel"
147 [ "$min_tx_power" -gt 0 ] && append base_cfg
"min_tx_power=$min_tx_power"
151 [ "$noscan" -gt 0 ] && hostapd_noscan
=1
152 [ "$tx_burst" = 0 ] && tx_burst
=
155 [ "$band" = "6g" ] && chan_ofs
=1
161 HT40
*|VHT40|VHT80|VHT160|HE40|HE80|HE160
)
164 case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
165 1) ht_capab
="[HT40+]";;
166 0) ht_capab
="[HT40-]";;
171 HT40
+) ht_capab
="[HT40+]";;
172 HT40-
) ht_capab
="[HT40-]";;
174 if [ "$channel" -lt 7 ]; then
183 [ "$auto_channel" -gt 0 ] && ht_capab
="[HT40+]"
188 [ -n "$ieee80211n" ] && {
189 append base_cfg
"ieee80211n=1" "$N"
191 set_default ht_coex
0
192 append base_cfg
"ht_coex=$ht_coex" "$N"
205 for cap
in $
(iw phy
"$phy" info |
grep 'Capabilities:' | cut
-d: -f2); do
206 ht_cap_mask
="$(($ht_cap_mask | $cap))"
209 cap_rx_stbc
=$
((($ht_cap_mask >> 8) & 3))
210 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
211 ht_cap_mask
="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
213 mac80211_add_capabilities ht_capab_flags
$ht_cap_mask \
215 GF
:0x10::$greenfield \
216 SHORT-GI-20
:0x20::$short_gi_20 \
217 SHORT-GI-40
:0x40::$short_gi_40 \
218 TX-STBC
:0x80::$tx_stbc \
219 RX-STBC1
:0x300:0x100:1 \
220 RX-STBC12
:0x300:0x200:1 \
221 RX-STBC123
:0x300:0x300:1 \
222 MAX-AMSDU-7935
:0x800::$max_amsdu \
223 DSSS_CCK-40
:0x1000::$dsss_cck_40
225 ht_capab
="$ht_capab$ht_capab_flags"
226 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
236 VHT20|HE20
) enable_ac
=1;;
238 case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
239 1) idx
=$
(($channel + 2));;
240 0) idx
=$
(($channel - 2));;
246 case "$(( (($channel / 4) + $chan_ofs) % 4 ))" in
247 1) idx
=$
(($channel + 6));;
248 2) idx
=$
(($channel + 2));;
249 3) idx
=$
(($channel - 2));;
250 0) idx
=$
(($channel - 6));;
257 if [ "$band" = "6g" ]; then
259 1|
5|
9|
13|
17|
21|
25|
29) idx
=15;;
260 33|
37|
41|
45|
49|
53|
57|
61) idx
=47;;
261 65|
69|
73|
77|
81|
85|
89|
93) idx
=79;;
262 97|
101|
105|
109|
113|
117|
121|
125) idx
=111;;
263 129|
133|
137|
141|
145|
149|
153|
157) idx
=143;;
264 161|
165|
169|
173|
177|
181|
185|
189) idx
=175;;
265 193|
197|
201|
205|
209|
213|
217|
221) idx
=207;;
269 36|
40|
44|
48|
52|
56|
60|
64) idx
=50;;
270 100|
104|
108|
112|
116|
120|
124|
128) idx
=114;;
278 [ "$band" = "5g" ] && {
279 json_get_vars background_radar
:0
281 [ "$background_radar" -eq 1 ] && append base_cfg
"enable_background_radar=1" "$N"
283 [ "$band" = "6g" ] && {
287 HE
*) op_class
=$
((132 + $vht_oper_chwidth))
289 [ -n "$op_class" ] && append base_cfg
"op_class=$op_class" "$N"
291 [ "$hwmode" = "a" ] || enable_ac
=0
293 if [ "$enable_ac" != "0" ]; then
305 beamformee_antennas
:4 \
306 beamformer_antennas
:4 \
307 rx_antenna_pattern
:1 \
308 tx_antenna_pattern
:1 \
309 vht_max_a_mpdu_len_exp
:7 \
315 set_default tx_burst
2.0
316 append base_cfg
"ieee80211ac=1" "$N"
318 for cap
in $
(iw phy
"$phy" info |
awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
319 vht_cap
="$(($vht_cap | $cap))"
322 append base_cfg
"vht_oper_chwidth=$vht_oper_chwidth" "$N"
323 append base_cfg
"vht_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
325 cap_rx_stbc
=$
((($vht_cap >> 8) & 7))
326 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
327 vht_cap
="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
329 mac80211_add_capabilities vht_capab
$vht_cap \
330 RXLDPC
:0x10::$rxldpc \
331 SHORT-GI-80
:0x20::$short_gi_80 \
332 SHORT-GI-160
:0x40::$short_gi_160 \
333 TX-STBC-2BY1
:0x80::$tx_stbc_2by1 \
334 SU-BEAMFORMER
:0x800::$su_beamformer \
335 SU-BEAMFORMEE
:0x1000::$su_beamformee \
336 MU-BEAMFORMER
:0x80000::$mu_beamformer \
337 MU-BEAMFORMEE
:0x100000::$mu_beamformee \
338 VHT-TXOP-PS
:0x200000::$vht_txop_ps \
339 HTC-VHT
:0x400000::$htc_vht \
340 RX-ANTENNA-PATTERN
:0x10000000::$rx_antenna_pattern \
341 TX-ANTENNA-PATTERN
:0x20000000::$tx_antenna_pattern \
342 RX-STBC-1
:0x700:0x100:1 \
343 RX-STBC-12
:0x700:0x200:1 \
344 RX-STBC-123
:0x700:0x300:1 \
345 RX-STBC-1234
:0x700:0x400:1 \
347 [ "$(($vht_cap & 0x800))" -gt 0 -a "$su_beamformer" -gt 0 ] && {
348 cap_ant
="$(( ( ($vht_cap >> 16) & 3 ) + 1 ))"
349 [ "$cap_ant" -gt "$beamformer_antennas" ] && cap_ant
="$beamformer_antennas"
350 [ "$cap_ant" -gt 1 ] && vht_capab
="$vht_capab[SOUNDING-DIMENSION-$cap_ant]"
353 [ "$(($vht_cap & 0x1000))" -gt 0 -a "$su_beamformee" -gt 0 ] && {
354 cap_ant
="$(( ( ($vht_cap >> 13) & 3 ) + 1 ))"
355 [ "$cap_ant" -gt "$beamformee_antennas" ] && cap_ant
="$beamformee_antennas"
356 [ "$cap_ant" -gt 1 ] && vht_capab
="$vht_capab[BF-ANTENNA-$cap_ant]"
359 # supported Channel widths
361 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
363 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
365 [ "$vht160_hw" = 1 ] && vht_capab
="$vht_capab[VHT160]"
366 [ "$vht160_hw" = 2 ] && vht_capab
="$vht_capab[VHT160-80PLUS80]"
368 # maximum MPDU length
370 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
372 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
373 vht_max_mpdu_hw
=11454
374 [ "$vht_max_mpdu_hw" != 3895 ] && \
375 vht_capab
="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
377 # maximum A-MPDU length exponent
378 vht_max_a_mpdu_len_exp_hw
=0
379 [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
380 vht_max_a_mpdu_len_exp_hw
=1
381 [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
382 vht_max_a_mpdu_len_exp_hw
=2
383 [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
384 vht_max_a_mpdu_len_exp_hw
=3
385 [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
386 vht_max_a_mpdu_len_exp_hw
=4
387 [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
388 vht_max_a_mpdu_len_exp_hw
=5
389 [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
390 vht_max_a_mpdu_len_exp_hw
=6
391 [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
392 vht_max_a_mpdu_len_exp_hw
=7
393 vht_capab
="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
395 # whether or not the STA supports link adaptation using VHT variant
397 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
399 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
401 [ "$vht_link_adapt_hw" != 0 ] && \
402 vht_capab
="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
404 [ -n "$vht_capab" ] && append base_cfg
"vht_capab=$vht_capab" "$N"
413 if [ "$enable_ax" != "0" ]; then
419 he_spr_sr_control
:3 \
420 he_spr_psr_enabled
:0 \
421 he_spr_non_srg_obss_pd_max_offset
:0 \
423 he_bss_color_enabled
:1
425 he_phy_cap
=$
(iw phy
"$phy" info |
sed -n '/HE Iftypes: AP/,$p' |
awk -F "[()]" '/HE PHY Capabilities/ { print $2 }' |
head -1)
426 he_phy_cap
=${he_phy_cap:2}
427 he_mac_cap
=$
(iw phy
"$phy" info |
sed -n '/HE Iftypes: AP/,$p' |
awk -F "[()]" '/HE MAC Capabilities/ { print $2 }' |
head -1)
428 he_mac_cap
=${he_mac_cap:2}
430 append base_cfg
"ieee80211ax=1" "$N"
431 [ "$hwmode" = "a" ] && {
432 append base_cfg
"he_oper_chwidth=$vht_oper_chwidth" "$N"
433 append base_cfg
"he_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
436 mac80211_add_he_capabilities \
437 he_su_beamformer
:${he_phy_cap:6:2}:0x80:$he_su_beamformer \
438 he_su_beamformee
:${he_phy_cap:8:2}:0x1:$he_su_beamformee \
439 he_mu_beamformer
:${he_phy_cap:8:2}:0x2:$he_mu_beamformer \
440 he_spr_psr_enabled
:${he_phy_cap:14:2}:0x1:$he_spr_psr_enabled \
441 he_twt_required
:${he_mac_cap:0:2}:0x6:$he_twt_required
443 if [ "$he_bss_color_enabled" -gt 0 ]; then
444 append base_cfg
"he_bss_color=$he_bss_color" "$N"
445 [ "$he_spr_non_srg_obss_pd_max_offset" -gt 0 ] && { \
446 append base_cfg
"he_spr_non_srg_obss_pd_max_offset=$he_spr_non_srg_obss_pd_max_offset" "$N"
447 he_spr_sr_control
=$
((he_spr_sr_control |
(1 << 2)))
449 [ "$he_spr_psr_enabled" -gt 0 ] || he_spr_sr_control=$((he_spr_sr_control | (1 << 0)))
450 append base_cfg "he_spr_sr_control=$he_spr_sr_control" "$N"
452 append base_cfg "he_bss_color_disabled=1" "$N"
456 append base_cfg "he_default_pe_duration=4" "$N"
457 append base_cfg "he_rts_threshold=1023" "$N"
458 append base_cfg "he_mu_edca_qos_info_param_count=0" "$N"
459 append base_cfg "he_mu_edca_qos_info_q_ack=0" "$N"
460 append base_cfg "he_mu_edca_qos_info_queue_request=0" "$N"
461 append base_cfg "he_mu_edca_qos_info_txop_request=0" "$N"
462 append base_cfg "he_mu_edca_ac_be_aifsn=8" "$N"
463 append base_cfg "he_mu_edca_ac_be_aci=0" "$N"
464 append base_cfg "he_mu_edca_ac_be_ecwmin=9" "$N"
465 append base_cfg "he_mu_edca_ac_be_ecwmax=10" "$N"
466 append base_cfg "he_mu_edca_ac_be_timer=255" "$N"
467 append base_cfg "he_mu_edca_ac_bk_aifsn=15" "$N"
468 append base_cfg "he_mu_edca_ac_bk_aci=1" "$N"
469 append base_cfg "he_mu_edca_ac_bk_ecwmin=9" "$N"
470 append base_cfg "he_mu_edca_ac_bk_ecwmax=10" "$N"
471 append base_cfg "he_mu_edca_ac_bk_timer=255" "$N"
472 append base_cfg "he_mu_edca_ac_vi_ecwmin=5" "$N"
473 append base_cfg "he_mu_edca_ac_vi_ecwmax=7" "$N"
474 append base_cfg "he_mu_edca_ac_vi_aifsn=5" "$N"
475 append base_cfg "he_mu_edca_ac_vi_aci=2" "$N"
476 append base_cfg "he_mu_edca_ac_vi_timer
=255" "$N"
477 append base_cfg "he_mu_edca_ac_vo_aifsn
=5" "$N"
478 append base_cfg "he_mu_edca_ac_vo_aci
=3" "$N"
479 append base_cfg "he_mu_edca_ac_vo_ecwmin
=5" "$N"
480 append base_cfg "he_mu_edca_ac_vo_ecwmax
=7" "$N"
481 append base_cfg "he_mu_edca_ac_vo_timer
=255" "$N"
484 hostapd_prepare_device_config "$hostapd_conf_file" nl80211
485 cat >> "$hostapd_conf_file" <<EOF
486 ${channel:+channel=$channel}
487 ${channel_list:+chanlist=$channel_list}
488 ${hostapd_noscan:+noscan=1}
489 ${tx_burst:+tx_queue_data2_burst=$tx_burst}
496 mac80211_hostapd_setup_bss() {
503 append hostapd_cfg "$type=$ifname" "$N"
505 hostapd_set_bss_options hostapd_cfg "$phy" "$vif" || return 1
506 json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
509 set_default start_disabled 0
511 [ "$wds" -gt 0 ] && {
512 append hostapd_cfg "wds_sta
=1" "$N"
513 [ -n "$wds_bridge" ] && append hostapd_cfg "wds_bridge
=$wds_bridge" "$N"
515 [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg "start_disabled
=1" "$N"
517 cat >> /var/run/hostapd-$phy.conf <<EOF
520 ${dtim_period:+dtim_period=$dtim_period}
521 ${max_listen_int:+max_listen_interval=$max_listen_int}
525 mac80211_get_addr() {
527 local idx="$
(($2 + 1))"
529 head -n $idx /sys/class/ieee80211/${phy}/addresses | tail -n1
532 mac80211_generate_mac() {
534 local id="${macidx:-0}"
536 local ref="$
(cat /sys
/class
/ieee80211
/${phy}/macaddress
)"
537 local mask="$
(cat /sys
/class
/ieee80211
/${phy}/address_mask
)"
539 [ "$mask" = "00:00:00:00:00:00" ] && {
540 mask="ff
:ff
:ff
:ff
:ff
:ff
";
542 [ "$
(wc -l < /sys
/class
/ieee80211
/${phy}/addresses
)" -gt $id ] && {
543 addr="$
(mac80211_get_addr
"$phy" "$id")"
551 local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
556 local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
559 [ "$
((0x
$mask1))" -gt 0 ] && {
562 b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
563 printf "%02x
:%s
:%s
:%s
:%s
:%s
" $b1 $2 $3 $4 $5 $6
567 [ "$
((0x
$mask6))" -lt 255 ] && {
568 printf "%s
:%s
:%s
:%s
:%s
:%02x
" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
572 off2=$(( (0x$6 + $id) / 0x100 ))
573 printf "%s
:%s
:%s
:%s
:%02x
:%02x
" \
575 $(( (0x$5 + $off2) % 0x100 )) \
576 $(( (0x$6 + $id) % 0x100 ))
579 get_board_phy_name() (
581 local fallback_phy=""
592 [ "${ref_path%+*}" = "$path" ] && fallback_phy=$key
593 [ "$ref_path" = "$path" ] || return 0
599 json_load_file /etc/board.json
600 json_for_each_item __check_phy wlan "$path"
601 [ -n "$fallback_phy" ] && echo "${fallback_phy}.
${path##*+}"
604 rename_board_phy_by_path() {
607 local new_phy="$
(get_board_phy_name
"$path")"
608 [ -z "$new_phy" -o "$new_phy" = "$phy" ] && return
610 iw "$phy" set name "$new_phy" && phy="$new_phy"
613 rename_board_phy_by_name() (
615 local suffix="${phy##*.}"
616 [ "$suffix" = "$phy" ] && suffix=
618 json_load_file /etc/board.json
620 json_select "${phy%.*}" || return 0
623 prev_phy="$
(iwinfo nl80211 phyname
"path=$path${suffix:++$suffix}")"
624 [ -n "$prev_phy" ] || return 0
626 [ "$prev_phy" = "$phy" ] && return 0
628 iw "$prev_phy" set name "$phy"
633 rename_board_phy_by_name "$phy"
634 [ -d /sys/class/ieee80211/$phy ] && return 0
637 phy="$
(iwinfo nl80211 phyname
"path=$path")"
639 rename_board_phy_by_path "$path"
643 [ -n "$macaddr" ] && {
644 for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
645 grep -i -q "$macaddr" "/sys
/class
/ieee80211
/${phy}/macaddress
" && {
646 path="$
(iwinfo nl80211 path
"$phy")"
647 rename_board_phy_by_path "$path"
655 mac80211_check_ap() {
659 mac80211_set_ifname() {
662 eval "ifname
=\"$phy-$prefix\
${idx_$prefix:-0}\"; idx_
$prefix=\$
((\
${idx_$prefix:-0 } + 1))"
665 mac80211_prepare_vif() {
668 json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
670 [ -n "$ifname" ] || {
674 ap|sta|mesh) prefix=$mode;;
676 monitor) prefix=mon;;
679 mac80211_set_ifname "$phy" "$prefix"
682 append active_ifnames "$ifname"
684 set_default powersave 0
685 json_add_string _ifname "$ifname"
687 if [ -z "$macaddr" ]; then
688 macaddr="$
(mac80211_generate_mac
$phy)"
689 macidx="$
(($macidx + 1))"
690 elif [ "$macaddr" = 'random' ]; then
691 macaddr="$
(macaddr_random
)"
693 json_add_string _macaddr "$macaddr"
697 [ "$mode" == "ap
" ] && {
698 [ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
699 [ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
704 # It is far easier to delete and create the desired interface
707 # Hostapd will handle recreating the interface and
708 # subsequent virtual APs belonging to the same PHY
709 if [ -n "$hostapd_ctrl" ]; then
715 mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
717 [ -n "$hostapd_ctrl" ] || {
718 ap_ifname="${ifname}"
719 hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
727 mac80211_prepare_iw_htmode() {
729 VHT20|HT20|HE20) iw_htmode=HT20;;
730 HT40*|VHT40|VHT160|HE40)
734 HT40+) iw_htmode="HT40
+";;
735 HT40-) iw_htmode="HT40-
";;
737 if [ "$channel" -lt 7 ]; then
746 case "$
(( ($channel / 4) % 2 ))" in
747 1) iw_htmode="HT40
+" ;;
748 0) iw_htmode="HT40-
";;
752 [ "$auto_channel" -gt 0 ] && iw_htmode="HT40
+"
764 mac80211_add_mesh_params() {
765 for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
766 eval "mp_val
=\"\$
$var\""
767 [ -n "$mp_val" ] && json_add_string "$var" "$mp_val"
771 mac80211_setup_adhoc() {
773 json_get_vars bssid ssid key mcast_rate
775 NEWUMLIST="${NEWUMLIST}$ifname "
777 [ "$enable" = 0 ] && {
778 ip link set dev "$ifname" down
783 [ "$auth_type" = "wep
" ] && {
788 for idx in 1 2 3 4; do
789 json_get_var ikey "key
$idx"
792 ikey="$
(($idx - 1)):$
(prepare_key_wep
"$ikey")"
793 [ $idx -eq $key ] && ikey="d
:$ikey"
794 append keyspec "$ikey"
799 append keyspec "d
:0:$
(prepare_key_wep
"$key")"
805 for br in $basic_rate_list; do
806 wpa_supplicant_add_rate brstr "$br"
810 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
813 json_set_namespace wdev_uc prev
815 json_add_object "$ifname"
816 json_add_string mode adhoc
817 json_add_string macaddr "$macaddr"
818 json_add_string ssid "$ssid"
819 json_add_string freq "$freq"
820 json_add_string htmode "$iw_htmode"
821 [ -n "$bssid" ] && json_add_string bssid "$bssid"
822 json_add_int beacon-interval "$beacon_int"
823 [ -n "$brstr" ] && json_add_string basic-rates "$brstr"
824 [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
825 [ -n "$keyspec" ] && json_add_string keys "$keyspec"
828 json_set_namespace "$prev"
831 mac80211_setup_mesh() {
832 json_get_vars ssid mesh_id mcast_rate
835 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
836 [ -n "$mesh_id" ] && ssid="$mesh_id"
839 json_set_namespace wdev_uc prev
841 json_add_object "$ifname"
842 json_add_string mode mesh
843 json_add_string macaddr "$macaddr"
844 json_add_string ssid "$ssid"
845 json_add_string freq "$freq"
846 json_add_string htmode "$iw_htmode"
847 [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
848 json_add_int beacon-interval "$beacon_int"
849 mac80211_add_mesh_params
853 json_set_namespace "$prev"
856 mac80211_setup_monitor() {
858 json_set_namespace wdev_uc prev
860 json_add_object "$ifname"
861 json_add_string mode monitor
862 [ -n "$freq" ] && json_add_string freq "$freq"
863 json_add_string htmode "$iw_htmode"
866 json_set_namespace "$prev"
869 mac80211_set_vif_txpower() {
873 json_get_var ifname _ifname
874 json_get_vars vif_txpower
877 [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
880 wpa_supplicant_init_config() {
881 json_set_namespace wpa_supp prev
884 json_add_array config
886 json_set_namespace "$prev"
889 wpa_supplicant_add_interface() {
894 _wpa_supplicant_common "$ifname"
896 json_set_namespace wpa_supp prev
899 json_add_string ctrl "$_rpath"
900 json_add_string iface "$ifname"
901 json_add_string mode "$mode"
902 json_add_string config "$_config"
903 json_add_string macaddr "$macaddr"
904 [ -n "$network_bridge" ] && json_add_string bridge "$network_bridge"
905 [ -n "$wds" ] && json_add_boolean 4addr "$wds"
906 json_add_boolean powersave "$powersave"
907 [ "$mode" = "mesh
" ] && mac80211_add_mesh_params
910 json_set_namespace "$prev"
915 wpa_supplicant_set_config() {
919 json_set_namespace wpa_supp prev
921 json_add_string phy "$phy"
922 json_add_boolean defer 1
923 local data="$
(json_dump
)"
926 json_set_namespace "$prev"
928 ubus -S -t 0 wait_for wpa_supplicant || {
929 [ -n "$wpa_supp_init" ] || return 0
931 ubus wait_for wpa_supplicant
934 local supplicant_res="$
(ubus call wpa_supplicant config_set
"$data")"
936 [ "$ret" != 0 -o -z "$supplicant_res" ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
938 wireless_add_process "$
(jsonfilter
-s "$supplicant_res" -l 1 -e @.pid
)" "/usr
/sbin
/wpa_supplicant
" 1 1
942 hostapd_set_config() {
943 [ -n "$hostapd_ctrl" ] || {
944 ubus call hostapd config_set '{ "phy
": "'"$phy"'", "config
": "", "prev_config
": "'"${hostapd_conf_file}.prev"'" }' > /dev/null
948 ubus wait_for hostapd
949 local hostapd_res="$
(ubus call hostapd config_set
"{ \"phy\": \"$phy\", \"config\":\"${hostapd_conf_file}\", \"prev_config\": \"${hostapd_conf_file}.prev\"}")"
951 [ "$ret" != 0 -o -z "$hostapd_res" ] && {
952 wireless_setup_failed HOSTAPD_START_FAILED
955 wireless_add_process "$
(jsonfilter
-s "$hostapd_res" -l 1 -e @.pid
)" "/usr
/sbin
/hostapd
" 1 1
959 wpa_supplicant_start() {
962 [ -n "$wpa_supp_init" ] || return 0
964 ubus call wpa_supplicant config_set '{ "phy
": "'"$phy"'" }' > /dev/null
967 mac80211_setup_supplicant() {
971 wpa_supplicant_prepare_interface "$ifname" nl80211 || return 1
973 if [ "$mode" = "sta
" ]; then
974 wpa_supplicant_add_network "$ifname"
976 wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
979 wpa_supplicant_add_interface "$ifname" "$mode"
984 mac80211_setup_vif() {
989 json_get_var ifname _ifname
990 json_get_var macaddr _macaddr
991 json_get_vars mode wds powersave
993 set_default powersave 0
998 json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING
999 wireless_vif_parse_encryption
1000 [ -z "$htmode" ] && htmode="NOHT
";
1001 if wpa_supplicant -vmesh; then
1002 mac80211_setup_supplicant || failed=1
1008 wireless_vif_parse_encryption
1009 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
1010 mac80211_setup_supplicant || failed=1
1012 mac80211_setup_adhoc
1016 mac80211_setup_supplicant || failed=1
1019 mac80211_setup_monitor
1024 [ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
1039 iw "$phy" info | awk -v band="$band" -v channel="[$channel]" '
1042 band_match = band == $2
1045 band_match && $3 == "MHz
" && $4 == channel {
1055 iw "$phy" info | grep -E -m1 "(\
* ${chan:-....} MHz
${chan:+|\\[$chan\\]})" | grep -q "MHz.
*radar detection
"
1059 mac80211_set_noscan() {
1063 drv_mac80211_cleanup() {
1064 hostapd_common_cleanup
1067 mac80211_reset_config() {
1070 hostapd_conf_file="/var
/run
/hostapd-
$phy.conf
"
1071 ubus call hostapd config_set '{ "phy
": "'"$phy"'", "config
": "", "prev_config
": "'"$hostapd_conf_file"'" }' > /dev/null
1072 ubus call wpa_supplicant config_set '{ "phy
": "'"$phy"'", "config
": [] }' > /dev/null
1073 wdev_tool "$phy" '{}'
1076 drv_mac80211_setup() {
1080 country chanbw distance \
1082 rxantenna txantenna \
1083 frag rts beacon_int:100 htmode
1084 json_get_values basic_rate_list basic_rate
1085 json_get_values scan_list scan_list
1088 json_select data && {
1089 json_get_var prev_rxantenna rxantenna
1090 json_get_var prev_txantenna txantenna
1095 echo "Could not
find PHY
for device
'$1'"
1096 wireless_set_retry 0
1104 # convert channel to frequency
1105 [ "$auto_channel" -gt 0 ] || freq="$
(get_freq
"$phy" "$channel" "$band")"
1107 [ -n "$country" ] && {
1108 iw reg get | grep -q "^country
$country:" || {
1109 iw reg set "$country"
1114 hostapd_conf_file="/var
/run
/hostapd-
$phy.conf
"
1119 [ -n "$chanbw" ] && {
1120 for file in /sys/kernel/debug/ieee80211/$phy/ath9k*/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
1121 [ -f "$file" ] && echo "$chanbw" > "$file"
1125 set_default rxantenna 0xffffffff
1126 set_default txantenna 0xffffffff
1127 set_default distance 0
1129 [ "$txantenna" = "all
" ] && txantenna=0xffffffff
1130 [ "$rxantenna" = "all
" ] && rxantenna=0xffffffff
1132 [ "$rxantenna" = "$prev_rxantenna" -a "$txantenna" = "$prev_txantenna" ] || mac80211_reset_config "$phy"
1133 wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna"
1135 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
1136 iw phy "$phy" set distance "$distance" >/dev/null 2>&1
1138 if [ -n "$txpower" ]; then
1139 iw phy "$phy" set txpower fixed "${txpower%%.*}00"
1141 iw phy "$phy" set txpower auto
1144 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
1145 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
1152 for_each_interface "ap
" mac80211_check_ap
1154 [ -f "$hostapd_conf_file" ] && mv "$hostapd_conf_file" "$hostapd_conf_file.prev
"
1156 for_each_interface "sta adhoc mesh
" mac80211_set_noscan
1157 [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
1160 json_set_namespace wdev_uc prev
1162 json_set_namespace "$prev"
1164 wpa_supplicant_init_config
1166 mac80211_prepare_iw_htmode
1168 for_each_interface "ap sta adhoc mesh monitor
" mac80211_prepare_vif
1169 for_each_interface "ap sta adhoc mesh monitor
" mac80211_setup_vif
1171 [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy"
1172 [ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy"
1174 [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy"
1176 json_set_namespace wdev_uc prev
1177 wdev_tool "$phy" "$
(json_dump
)" $active_ifnames
1178 json_set_namespace "$prev"
1180 for_each_interface "ap sta adhoc mesh monitor
" mac80211_set_vif_txpower
1184 _list_phy_interfaces() {
1186 if [ -d "/sys
/class
/ieee80211
/${phy}/device
/net
" ]; then
1187 ls "/sys
/class
/ieee80211
/${phy}/device
/net
" 2>/dev/null;
1189 ls "/sys
/class
/ieee80211
/${phy}/device
" 2>/dev/null | grep net: | sed -e 's,net:,,g'
1193 list_phy_interfaces() {
1196 for dev in $(_list_phy_interfaces "$phy"); do
1197 readlink "/sys
/class
/net
/${dev}/phy80211
" | grep -q "/${phy}\$
" || continue
1202 drv_mac80211_teardown() {
1207 echo "Bug
: PHY is undefined
for device
'$1'"
1211 mac80211_reset_config "$phy"
1213 for wdev in $(list_phy_interfaces "$phy"); do
1214 ip link set dev "$wdev" down