2 .
/lib
/netifd
/netifd-wireless.sh
3 .
/lib
/netifd
/hostapd.sh
4 .
/lib
/netifd
/mac80211.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"
25 drv_mac80211_init_device_config
() {
26 hostapd_common_add_device_config
28 config_add_string path phy
'macaddr:macaddr'
29 config_add_string hwmode
30 config_add_string tx_burst
31 config_add_string distance
32 config_add_int beacon_int chanbw frag rts
33 config_add_int rxantenna txantenna antenna_gain txpower
34 config_add_boolean noscan ht_coex acs_exclude_dfs
35 config_add_array ht_capab
36 config_add_array channels
50 config_add_int vht_max_a_mpdu_len_exp vht_max_mpdu vht_link_adapt vht160 rx_stbc tx_stbc
60 drv_mac80211_init_iface_config
() {
61 hostapd_common_add_bss_config
63 config_add_string
'macaddr:macaddr' ifname
65 config_add_boolean wds powersave
enable
66 config_add_string wds_bridge
67 config_add_int maxassoc
68 config_add_int max_listen_int
69 config_add_int dtim_period
70 config_add_int start_disabled
73 config_add_string mesh_id
74 config_add_int
$MP_CONFIG_INT
75 config_add_boolean
$MP_CONFIG_BOOL
76 config_add_string
$MP_CONFIG_STRING
79 mac80211_add_capabilities
() {
80 local __var
="$1"; shift
81 local __mask
="$1"; shift
89 [ "$(($4))" -gt 0 ] ||
continue
90 [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] ||
continue
95 export -n -- "$__var=$__out"
98 mac80211_hostapd_setup_base
() {
103 [ "$auto_channel" -gt 0 ] && channel
=acs_survey
104 [ "$auto_channel" -gt 0 ] && json_get_values channel_list channels
106 [ "$auto_channel" -gt 0 ] && json_get_vars acs_exclude_dfs
107 [ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
108 append base_cfg
"acs_exclude_dfs=1" "$N"
110 json_get_vars noscan ht_coex
111 json_get_values ht_capab_list ht_capab tx_burst
115 [ "$noscan" -gt 0 ] && hostapd_noscan
=1
116 [ "$tx_burst" = 0 ] && tx_burst
=
122 HT40
*|VHT40|VHT80|VHT160
)
125 case "$(( ($channel / 4) % 2 ))" in
126 1) ht_capab
="[HT40+]";;
127 0) ht_capab
="[HT40-]";;
132 HT40
+) ht_capab
="[HT40+]";;
133 HT40-
) ht_capab
="[HT40-]";;
135 if [ "$channel" -lt 7 ]; then
144 [ "$auto_channel" -gt 0 ] && ht_capab
="[HT40+]"
149 [ -n "$ieee80211n" ] && {
150 append base_cfg
"ieee80211n=1" "$N"
152 set_default ht_coex
0
153 append base_cfg
"ht_coex=$ht_coex" "$N"
166 for cap
in $
(iw phy
"$phy" info |
grep 'Capabilities:' | cut
-d: -f2); do
167 ht_cap_mask
="$(($ht_cap_mask | $cap))"
170 cap_rx_stbc
=$
((($ht_cap_mask >> 8) & 3))
171 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
172 ht_cap_mask
="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
174 mac80211_add_capabilities ht_capab_flags
$ht_cap_mask \
176 GF
:0x10::$greenfield \
177 SHORT-GI-20
:0x20::$short_gi_20 \
178 SHORT-GI-40
:0x40::$short_gi_40 \
179 TX-STBC
:0x80::$tx_stbc \
180 RX-STBC1
:0x300:0x100:1 \
181 RX-STBC12
:0x300:0x200:1 \
182 RX-STBC123
:0x300:0x300:1 \
183 MAX-AMSDU-7935
:0x800::$max_amsdu \
184 DSSS_CCK-40
:0x1000::$dsss_cck_40
186 ht_capab
="$ht_capab$ht_capab_flags"
187 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
196 case "$(( ($channel / 4) % 2 ))" in
197 1) idx
=$
(($channel + 2));;
198 0) idx
=$
(($channel - 2));;
201 append base_cfg
"vht_oper_chwidth=0" "$N"
202 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
205 case "$(( ($channel / 4) % 4 ))" in
206 1) idx
=$
(($channel + 6));;
207 2) idx
=$
(($channel + 2));;
208 3) idx
=$
(($channel - 2));;
209 0) idx
=$
(($channel - 6));;
212 append base_cfg
"vht_oper_chwidth=1" "$N"
213 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
217 36|
40|
44|
48|
52|
56|
60|
64) idx
=50;;
218 100|
104|
108|
112|
116|
120|
124|
128) idx
=114;;
221 append base_cfg
"vht_oper_chwidth=2" "$N"
222 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
226 if [ "$enable_ac" != "0" ]; then
238 rx_antenna_pattern
:1 \
239 tx_antenna_pattern
:1 \
240 vht_max_a_mpdu_len_exp
:7 \
246 set_default tx_burst
2.0
247 append base_cfg
"ieee80211ac=1" "$N"
249 for cap
in $
(iw phy
"$phy" info |
awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
250 vht_cap
="$(($vht_cap | $cap))"
253 cap_rx_stbc
=$
((($vht_cap >> 8) & 7))
254 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
255 vht_cap
="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
257 mac80211_add_capabilities vht_capab
$vht_cap \
258 RXLDPC
:0x10::$rxldpc \
259 SHORT-GI-80
:0x20::$short_gi_80 \
260 SHORT-GI-160
:0x40::$short_gi_160 \
261 TX-STBC-2BY1
:0x80::$tx_stbc_2by1 \
262 SU-BEAMFORMER
:0x800::$su_beamformer \
263 SU-BEAMFORMEE
:0x1000::$su_beamformee \
264 MU-BEAMFORMER
:0x80000::$mu_beamformer \
265 MU-BEAMFORMEE
:0x100000::$mu_beamformee \
266 VHT-TXOP-PS
:0x200000::$vht_txop_ps \
267 HTC-VHT
:0x400000::$htc_vht \
268 RX-ANTENNA-PATTERN
:0x10000000::$rx_antenna_pattern \
269 TX-ANTENNA-PATTERN
:0x20000000::$tx_antenna_pattern \
270 RX-STBC-1
:0x700:0x100:1 \
271 RX-STBC-12
:0x700:0x200:1 \
272 RX-STBC-123
:0x700:0x300:1 \
273 RX-STBC-1234
:0x700:0x400:1 \
275 # supported Channel widths
277 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
279 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
281 [ "$vht160_hw" = 1 ] && vht_capab
="$vht_capab[VHT160]"
282 [ "$vht160_hw" = 2 ] && vht_capab
="$vht_capab[VHT160-80PLUS80]"
284 # maximum MPDU length
286 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
288 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
289 vht_max_mpdu_hw
=11454
290 [ "$vht_max_mpdu_hw" != 3895 ] && \
291 vht_capab
="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
293 # maximum A-MPDU length exponent
294 vht_max_a_mpdu_len_exp_hw
=0
295 [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
296 vht_max_a_mpdu_len_exp_hw
=1
297 [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
298 vht_max_a_mpdu_len_exp_hw
=2
299 [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
300 vht_max_a_mpdu_len_exp_hw
=3
301 [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
302 vht_max_a_mpdu_len_exp_hw
=4
303 [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
304 vht_max_a_mpdu_len_exp_hw
=5
305 [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
306 vht_max_a_mpdu_len_exp_hw
=6
307 [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
308 vht_max_a_mpdu_len_exp_hw
=7
309 vht_capab
="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
311 # whether or not the STA supports link adaptation using VHT variant
313 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
315 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
317 [ "$vht_link_adapt_hw" != 0 ] && \
318 vht_capab
="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
320 [ -n "$vht_capab" ] && append base_cfg
"vht_capab=$vht_capab" "$N"
323 hostapd_prepare_device_config
"$hostapd_conf_file" nl80211
324 cat >> "$hostapd_conf_file" <<EOF
325 ${channel:+channel=$channel}
326 ${channel_list:+chanlist=$channel_list}
327 ${hostapd_noscan:+noscan=1}
328 ${tx_burst:+tx_queue_data2_burst=$tx_burst}
333 radio_md5sum
=$
(md5sum $hostapd_conf_file | cut
-d" " -f1)
334 echo "radio_config_id=${radio_md5sum}" >> $hostapd_conf_file
337 mac80211_hostapd_setup_bss
() {
344 append hostapd_cfg
"$type=$ifname" "$N"
346 hostapd_set_bss_options hostapd_cfg
"$vif" ||
return 1
347 json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
350 set_default start_disabled
0
352 [ "$wds" -gt 0 ] && {
353 append hostapd_cfg
"wds_sta=1" "$N"
354 [ -n "$wds_bridge" ] && append hostapd_cfg
"wds_bridge=$wds_bridge" "$N"
356 [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg
"start_disabled=1" "$N"
358 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
361 ${dtim_period:+dtim_period=$dtim_period}
362 ${max_listen_int:+max_listen_interval=$max_listen_int}
366 mac80211_get_addr
() {
368 local idx
="$(($2 + 1))"
370 head -n $
(($macidx + 1)) /sys
/class
/ieee80211
/${phy}/addresses |
tail -n1
373 mac80211_generate_mac
() {
375 local id
="${macidx:-0}"
377 local ref
="$(cat /sys/class/ieee80211/${phy}/macaddress)"
378 local mask
="$(cat /sys/class/ieee80211/${phy}/address_mask)"
380 [ "$mask" = "00:00:00:00:00:00" ] && {
381 mask
="ff:ff:ff:ff:ff:ff";
383 [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt 1 ] && {
384 addr
="$(mac80211_get_addr "$phy" "$id")"
392 local oIFS
="$IFS"; IFS
=":"; set -- $mask; IFS
="$oIFS"
397 local oIFS
="$IFS"; IFS
=":"; set -- $ref; IFS
="$oIFS"
400 [ "$((0x$mask1))" -gt 0 ] && {
403 b1
=$
(($b1 ^
((($id - !($b1 & 2)) << 2) | 0x2)))
404 printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
408 [ "$((0x$mask6))" -lt 255 ] && {
409 printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
413 off2=$(( (0x$6 + $id) / 0x100 ))
414 printf "%s:%s:%s:%s:%02x:%02x" \
416 $(( (0x$5 + $off2) % 0x100 )) \
417 $(( (0x$6 + $id) % 0x100 ))
421 [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
423 phy="$(mac80211_path_to_phy "$path")"
424 [ -n "$phy" ] && return 0
426 [ -n "$macaddr" ] && {
427 for phy in $(ls /sys/class/ieee80211 2>/dev
/null
); do
428 grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
434 mac80211_check_ap
() {
438 mac80211_iw_interface_add
() {
446 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag >/dev
/null
2>&1
450 # Device might have just been deleted, give the kernel some time to finish cleaning it up
453 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag >/dev
/null
2>&1
458 # Keep matching pre-existing interface
459 [ -d "/sys/class/ieee80211/${phy}/device/net/${ifname}" ] && \
460 case "$(iw dev $ifname info | grep "^
\ttype
" | cut -d' ' -f2- 2>/dev/null)" in
462 [ "$type" = "__ap" ] && rc
=0
465 [ "$type" = "adhoc" ] && rc
=0
468 [ "$type" = "managed" ] && rc
=0
471 [ "$type" = "mp" ] && rc
=0
474 [ "$type" = "monitor" ] && rc
=0
480 iw dev
"$ifname" del
>/dev
/null
2>&1
484 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag >/dev
/null
2>&1
490 # Device might not support virtual interfaces, so the interface never got deleted in the first place.
491 # Check if the interface already exists, and avoid failing in this case.
492 [ -d "/sys/class/ieee80211/${phy}/device/net/${ifname}" ] && rc
=0
496 # Device doesn't support virtual interfaces and may have existing interface other than ifname.
497 oldifname
="$(basename "/sys
/class
/ieee80211
/${phy}/device
/net
"/* 2>/dev/null)"
498 [ "$oldifname" ] && ip link
set "$oldifname" name
"$ifname" 1>/dev
/null
2>&1
502 [ "$rc" != 0 ] && wireless_setup_failed INTERFACE_CREATION_FAILED
506 mac80211_prepare_vif
() {
509 json_get_vars ifname mode ssid wds powersave macaddr
enable wpa_psk_file vlan_file
511 [ -n "$ifname" ] || ifname
="wlan${phy#phy}${if_idx:+-$if_idx}"
512 if_idx
=$
((${if_idx:-0} + 1))
515 set_default powersave
0
519 [ -n "$macaddr" ] ||
{
520 macaddr
="$(mac80211_generate_mac $phy)"
521 macidx
="$(($macidx + 1))"
525 json_add_string ifname
"$ifname"
528 [ "$mode" == "ap" ] && {
529 [ -z "$wpa_psk_file" ] && hostapd_set_psk
"$ifname"
530 [ -z "$vlan_file" ] && hostapd_set_vlan
"$ifname"
535 # It is far easier to delete and create the desired interface
538 mac80211_iw_interface_add
"$phy" "$ifname" adhoc ||
return
541 # Hostapd will handle recreating the interface and
542 # subsequent virtual APs belonging to the same PHY
543 if [ -n "$hostapd_ctrl" ]; then
549 mac80211_hostapd_setup_bss
"$phy" "$ifname" "$macaddr" "$type" ||
return
551 NEWAPLIST
="${NEWAPLIST}$ifname "
552 [ -n "$hostapd_ctrl" ] ||
{
553 ap_ifname
="${ifname}"
554 hostapd_ctrl
="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
558 mac80211_iw_interface_add
"$phy" "$ifname" mp ||
return
561 mac80211_iw_interface_add
"$phy" "$ifname" monitor ||
return
565 [ "$enable" = 0 ] || staidx
="$(($staidx + 1))"
566 [ "$wds" -gt 0 ] && wdsflag
="4addr on"
567 mac80211_iw_interface_add
"$phy" "$ifname" managed
"$wdsflag" ||
return
568 if [ "$wds" -gt 0 ]; then
569 iw
"$ifname" set 4addr on
571 iw
"$ifname" set 4addr off
573 [ "$powersave" -gt 0 ] && powersave
="on" || powersave
="off"
574 iw
"$ifname" set power_save
"$powersave"
580 [ "$auto_channel" -gt 0 ] || iw dev
"$ifname" set channel
"$channel" $iw_htmode
584 if [ "$mode" != "ap" ]; then
585 # ALL ap functionality will be passed to hostapd
586 # All interfaces must have unique mac addresses
587 # which can either be explicitly set in the device
588 # section, or automatically generated
589 ip link
set dev
"$ifname" address
"$macaddr"
595 mac80211_setup_supplicant
() {
598 local spobj
="$(ubus -S list | grep wpa_supplicant.${ifname})"
600 [ "$enable" = 0 ] && {
601 ubus call wpa_supplicant.
${phy} config_del
"{\"iface\":\"$ifname\"}"
602 ip link
set dev
"$ifname" down
607 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
{
611 if [ "$mode" = "sta" ]; then
612 wpa_supplicant_add_network
"$ifname"
614 wpa_supplicant_add_network
"$ifname" "$freq" "$htmode" "$noscan"
617 NEWSPLIST
="${NEWSPLIST}$ifname "
619 if [ "${NEWAPLIST%% *}" != "${OLDAPLIST%% *}" ]; then
620 [ "$spobj" ] && ubus call wpa_supplicant config_remove
"{\"iface\":\"$ifname\"}"
623 [ -z "$spobj" ] && add_sp
=1
625 NEW_MD5_SP
=$
(test -e "${_config}" && md5sum ${_config})
626 OLD_MD5_SP
=$
(uci
-q -P /var
/state get wireless._
${phy}.md5_
${ifname})
627 if [ "$add_sp" = "1" ]; then
628 wpa_supplicant_run
"$ifname" "$hostapd_ctrl"
630 [ "${NEW_MD5_SP}" == "${OLD_MD5_SP}" ] || ubus call
$spobj reload
632 uci
-q -P /var
/state
set wireless._
${phy}.md5_${ifname}="${NEW_MD5_SP}"
636 mac80211_setup_supplicant_noctl() {
638 local spobj="$
(ubus
-S list |
grep wpa_supplicant.
${ifname})"
639 wpa_supplicant_prepare_interface "$ifname" nl80211 || {
644 wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
646 NEWSPLIST="${NEWSPLIST}$ifname "
647 [ "$enable" = 0 ] && {
648 ubus call wpa_supplicant config_remove "{\"iface
\":\"$ifname\"}"
649 ip link set dev "$ifname" down
652 if [ -z "$spobj" ]; then
653 wpa_supplicant_run "$ifname"
655 ubus call $spobj reload
659 mac80211_prepare_iw_htmode() {
661 VHT20|HT20) iw_htmode=HT20;;
665 case "$
(( ($channel / 4) % 2 ))" in
666 1) iw_htmode="HT40
+" ;;
667 0) iw_htmode="HT40-
";;
672 HT40+) iw_htmode="HT40
+";;
673 HT40-) iw_htmode="HT40-
";;
675 if [ "$channel" -lt 7 ]; then
684 [ "$auto_channel" -gt 0 ] && iw_htmode="HT40
+"
696 mac80211_setup_adhoc() {
698 json_get_vars bssid ssid key mcast_rate
700 NEWUMLIST="${NEWUMLIST}$ifname "
702 [ "$enable" = 0 ] && {
703 ip link set dev "$ifname" down
708 [ "$auth_type" = "wep
" ] && {
713 for idx in 1 2 3 4; do
714 json_get_var ikey "key
$idx"
717 ikey="$
(($idx - 1)):$
(prepare_key_wep
"$ikey")"
718 [ $idx -eq $key ] && ikey="d
:$ikey"
719 append keyspec "$ikey"
724 append keyspec "d
:0:$
(prepare_key_wep
"$key")"
730 for br in $basic_rate_list; do
731 wpa_supplicant_add_rate brstr "$br"
735 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
737 iw dev "$ifname" ibss join "$ssid" $freq $iw_htmode fixed-freq $bssid \
738 beacon-interval $beacon_int \
739 ${brstr:+basic-rates $brstr} \
740 ${mcval:+mcast-rate $mcval} \
741 ${keyspec:+keys $keyspec}
744 mac80211_setup_mesh() {
746 json_get_vars ssid mesh_id mcast_rate
748 NEWUMLIST="${NEWUMLIST}$ifname "
750 [ "$enable" = 0 ] && {
751 ip link set dev "$ifname" down
756 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
757 [ -n "$mesh_id" ] && ssid="$mesh_id"
759 iw dev "$ifname" mesh join "$ssid" freq $freq $iw_htmode \
760 ${mcval:+mcast-rate $mcval} \
761 beacon-interval $beacon_int
764 mac80211_setup_vif() {
775 json_get_var vif_txpower
776 json_get_var vif_enable enable 1
778 [ "$vif_enable" = 1 ] || action=down
779 if [ "$mode" != "ap
" ] || [ "$ifname" = "$ap_ifname" ]; then
780 ip link set dev "$ifname" "$action" || {
781 wireless_setup_vif_failed IFUP_ERROR
785 [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
790 wireless_vif_parse_encryption
791 [ -z "$htmode" ] && htmode="NOHT
";
792 freq="$
(get_freq
"$phy" "$channel")"
793 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ] || chan_is_dfs "$phy" "$channel"; then
794 mac80211_setup_supplicant $vif_enable || failed=1
796 mac80211_setup_mesh $vif_enable
798 for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
799 json_get_var mp_val "$var"
800 [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"
804 wireless_vif_parse_encryption
805 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
806 freq="$
(get_freq
"$phy" "$channel")"
807 mac80211_setup_supplicant_noctl $vif_enable || failed=1
809 mac80211_setup_adhoc $vif_enable
813 mac80211_setup_supplicant $vif_enable || failed=1
818 [ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
824 iw "$phy" info | grep -E -m1 "(\
* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
830 iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep -q "MHz.*radar detection"
834 mac80211_vap_cleanup() {
838 for wdev in $vaps; do
839 [ "$service" != "none" ] && ubus call ${service} config_remove "{\"iface\":\"$wdev\"}"
840 ip link set dev "$wdev" down 2>/dev/null
845 mac80211_interface_cleanup() {
847 local primary_ap=$(uci -q -P /var/state get wireless._${phy}.aplist)
848 primary_ap=${primary_ap%% *}
850 mac80211_vap_cleanup hostapd "${primary_ap}"
851 mac80211_vap_cleanup wpa_supplicant "$(uci -q -P /var/state get wireless._${phy}.splist)"
852 mac80211_vap_cleanup none "$(uci -q -P /var/state get wireless._${phy}.umlist)"
855 mac80211_set_noscan() {
859 drv_mac80211_cleanup() {
860 hostapd_common_cleanup
863 drv_mac80211_setup() {
867 country chanbw distance \
868 txpower antenna_gain \
869 rxantenna txantenna \
870 frag rts beacon_int:100 htmode
871 json_get_values basic_rate_list basic_rate
875 echo "Could not find PHY for device '$1'"
880 [ -z "$(uci -q -P /var/state show wireless._${phy})" ] && {
881 uci -q -P /var/state set wireless._${phy}=phy
882 wireless_set_data phy="$phy"
885 OLDAPLIST=$(uci -q -P /var/state get wireless._${phy}.aplist)
886 OLDSPLIST=$(uci -q -P /var/state get wireless._${phy}.splist)
887 OLDUMLIST=$(uci -q -P /var/state get wireless._${phy}.umlist)
893 for wdev in $(list_phy_interfaces "$phy"); do
895 for cwdev in $OLDAPLIST $OLDSPLIST $OLDUMLIST; do
896 if [ "$wdev" = "$cwdev" ]; then
901 if [ "$found" = "0" ]; then
902 ip link set dev "$wdev" down
907 # convert channel to frequency
908 [ "$auto_channel" -gt 0 ] || freq="$(get_freq "$phy" "$channel")"
910 [ -n "$country" ] && {
911 iw reg get | grep -q "^country $country:" || {
912 iw reg set "$country"
917 hostapd_conf_file="/var/run/hostapd-$phy.conf"
923 [ -n "$chanbw" ] && {
924 for file in /sys/kernel/debug/ieee80211/$phy/ath9k*/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
925 [ -f "$file" ] && echo "$chanbw" > "$file"
929 set_default rxantenna 0xffffffff
930 set_default txantenna 0xffffffff
931 set_default distance 0
932 set_default antenna_gain 0
934 [ "$txantenna" = "all" ] && txantenna=0xffffffff
935 [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
937 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
938 iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1
939 iw phy "$phy" set distance "$distance" >/dev/null 2>&1
941 if [ -n "$txpower" ]; then
942 iw phy "$phy" set txpower fixed "${txpower%%.*}00"
944 iw phy "$phy" set txpower auto
947 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
948 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
954 for_each_interface "ap" mac80211_check_ap
956 rm -f "$hostapd_conf_file"
958 for_each_interface "sta adhoc mesh" mac80211_set_noscan
959 [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
961 mac80211_prepare_iw_htmode
962 for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
964 for_each_interface "ap" mac80211_prepare_vif
965 NEW_MD5=$(test -e "${hostapd_conf_file}" && md5sum ${hostapd_conf_file})
966 OLD_MD5=$(uci -q -P /var/state get wireless._${phy}.md5)
967 if [ "${NEWAPLIST}" != "${OLDAPLIST}" ]; then
968 mac80211_vap_cleanup hostapd "${OLDAPLIST}"
970 [ -n "${NEWAPLIST}" ] && mac80211_iw_interface_add "$phy" "${NEWAPLIST%% *}" __ap
972 local primary_ap=${NEWAPLIST%% *}
973 [ -n "$hostapd_ctrl" ] && {
975 if [ -n "$(ubus list | grep hostapd.$primary_ap)" ]; then
976 [ "${NEW_MD5}" = "${OLD_MD5}" ] || {
977 ubus call hostapd.$primary_ap reload
979 if [ "$no_reload" != "0" ]; then
980 mac80211_vap_cleanup hostapd "${OLDAPLIST}"
981 mac80211_vap_cleanup wpa_supplicant "$(uci -q -P /var/state get wireless._${phy}.splist)"
982 mac80211_vap_cleanup none "$(uci -q -P /var/state get wireless._${phy}.umlist)"
984 mac80211_iw_interface_add "$phy" "${NEWAPLIST%% *}" __ap
985 for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
989 if [ "$no_reload" != "0" ]; then
991 ubus wait_for hostapd
992 ubus call hostapd config_add "{\"iface\":\"$primary_ap\", \"config\":\"${hostapd_conf_file}\"}"
993 local hostapd_pid=$(ubus call service list '{"name": "hostapd"}' | jsonfilter -l 1 -e "@['hostapd
'].instances['hostapd
'].pid")
994 wireless_add_process "$hostapd_pid" "/usr/sbin/hostapd" 1
998 wireless_setup_failed HOSTAPD_START_FAILED
1002 uci -q -P /var/state set wireless._${phy}.aplist="${NEWAPLIST}"
1003 uci -q -P /var/state set wireless._${phy}.md5="${NEW_MD5}"
1005 [ "${add_ap}" = 1 ] && sleep 1
1006 for_each_interface "ap" mac80211_setup_vif
1011 for_each_interface "sta adhoc mesh monitor" mac80211_setup_vif
1013 uci -q -P /var/state set wireless._${phy}.splist="${NEWSPLIST}"
1014 uci -q -P /var/state set wireless._${phy}.umlist="${NEWUMLIST}"
1018 for oldvap in $OLDSPLIST; do
1020 for newvap in $NEWSPLIST; do
1021 [ "$oldvap" = "$newvap" ] && foundvap=1
1023 [ "$foundvap" = "0" ] && dropvap="$dropvap $oldvap"
1025 [ -n "$dropvap" ] && mac80211_vap_cleanup wpa_supplicant "$dropvap"
1029 _list_phy_interfaces() {
1031 if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
1032 ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
1034 ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's
,net
:,,g
'
1038 list_phy_interfaces() {
1041 for dev in $(_list_phy_interfaces "$phy"); do
1042 readlink "/sys/class/net/${dev}/phy80211" | grep -q "/${phy}\$" || continue
1047 drv_mac80211_teardown() {
1048 wireless_process_kill_all
1054 mac80211_interface_cleanup "$phy"
1055 uci -q -P /var/state revert wireless._${phy}