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_int beacon_int chanbw frag rts
32 config_add_int rxantenna txantenna antenna_gain txpower distance
33 config_add_boolean noscan ht_coex acs_exclude_dfs
34 config_add_array ht_capab
35 config_add_array channels
49 config_add_int vht_max_a_mpdu_len_exp vht_max_mpdu vht_link_adapt vht160 rx_stbc tx_stbc
59 drv_mac80211_init_iface_config
() {
60 hostapd_common_add_bss_config
62 config_add_string
'macaddr:macaddr' ifname
64 config_add_boolean wds powersave
enable
65 config_add_string wds_bridge
66 config_add_int maxassoc
67 config_add_int max_listen_int
68 config_add_int dtim_period
69 config_add_int start_disabled
72 config_add_string mesh_id
73 config_add_int
$MP_CONFIG_INT
74 config_add_boolean
$MP_CONFIG_BOOL
75 config_add_string
$MP_CONFIG_STRING
78 mac80211_add_capabilities
() {
79 local __var
="$1"; shift
80 local __mask
="$1"; shift
88 [ "$(($4))" -gt 0 ] ||
continue
89 [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] ||
continue
94 export -n -- "$__var=$__out"
97 mac80211_hostapd_setup_base
() {
102 [ "$auto_channel" -gt 0 ] && channel
=acs_survey
103 [ "$auto_channel" -gt 0 ] && json_get_values channel_list channels
105 [ "$auto_channel" -gt 0 ] && json_get_vars acs_exclude_dfs
106 [ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
107 append base_cfg
"acs_exclude_dfs=1" "$N"
109 json_get_vars noscan ht_coex
110 json_get_values ht_capab_list ht_capab tx_burst
114 [ "$noscan" -gt 0 ] && hostapd_noscan
=1
115 [ "$tx_burst" = 0 ] && tx_burst
=
121 HT40
*|VHT40|VHT80|VHT160
)
124 case "$(( ($channel / 4) % 2 ))" in
125 1) ht_capab
="[HT40+]";;
126 0) ht_capab
="[HT40-]";;
131 HT40
+) ht_capab
="[HT40+]";;
132 HT40-
) ht_capab
="[HT40-]";;
134 if [ "$channel" -lt 7 ]; then
143 [ "$auto_channel" -gt 0 ] && ht_capab
="[HT40+]"
148 [ -n "$ieee80211n" ] && {
149 append base_cfg
"ieee80211n=1" "$N"
151 set_default ht_coex
0
152 append base_cfg
"ht_coex=$ht_coex" "$N"
165 for cap
in $
(iw phy
"$phy" info |
grep 'Capabilities:' | cut
-d: -f2); do
166 ht_cap_mask
="$(($ht_cap_mask | $cap))"
169 cap_rx_stbc
=$
((($ht_cap_mask >> 8) & 3))
170 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
171 ht_cap_mask
="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
173 mac80211_add_capabilities ht_capab_flags
$ht_cap_mask \
175 GF
:0x10::$greenfield \
176 SHORT-GI-20
:0x20::$short_gi_20 \
177 SHORT-GI-40
:0x40::$short_gi_40 \
178 TX-STBC
:0x80::$tx_stbc \
179 RX-STBC1
:0x300:0x100:1 \
180 RX-STBC12
:0x300:0x200:1 \
181 RX-STBC123
:0x300:0x300:1 \
182 MAX-AMSDU-7935
:0x800::$max_amsdu \
183 DSSS_CCK-40
:0x1000::$dsss_cck_40
185 ht_capab
="$ht_capab$ht_capab_flags"
186 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
195 case "$(( ($channel / 4) % 2 ))" in
196 1) idx
=$
(($channel + 2));;
197 0) idx
=$
(($channel - 2));;
200 append base_cfg
"vht_oper_chwidth=0" "$N"
201 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
204 case "$(( ($channel / 4) % 4 ))" in
205 1) idx
=$
(($channel + 6));;
206 2) idx
=$
(($channel + 2));;
207 3) idx
=$
(($channel - 2));;
208 0) idx
=$
(($channel - 6));;
211 append base_cfg
"vht_oper_chwidth=1" "$N"
212 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
216 36|
40|
44|
48|
52|
56|
60|
64) idx
=50;;
217 100|
104|
108|
112|
116|
120|
124|
128) idx
=114;;
220 append base_cfg
"vht_oper_chwidth=2" "$N"
221 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
225 if [ "$enable_ac" != "0" ]; then
237 rx_antenna_pattern
:1 \
238 tx_antenna_pattern
:1 \
239 vht_max_a_mpdu_len_exp
:7 \
245 set_default tx_burst
2.0
246 append base_cfg
"ieee80211ac=1" "$N"
248 for cap
in $
(iw phy
"$phy" info |
awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
249 vht_cap
="$(($vht_cap | $cap))"
252 cap_rx_stbc
=$
((($vht_cap >> 8) & 7))
253 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc
="$rx_stbc"
254 vht_cap
="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
256 mac80211_add_capabilities vht_capab
$vht_cap \
257 RXLDPC
:0x10::$rxldpc \
258 SHORT-GI-80
:0x20::$short_gi_80 \
259 SHORT-GI-160
:0x40::$short_gi_160 \
260 TX-STBC-2BY1
:0x80::$tx_stbc_2by1 \
261 SU-BEAMFORMER
:0x800::$su_beamformer \
262 SU-BEAMFORMEE
:0x1000::$su_beamformee \
263 MU-BEAMFORMER
:0x80000::$mu_beamformer \
264 MU-BEAMFORMEE
:0x100000::$mu_beamformee \
265 VHT-TXOP-PS
:0x200000::$vht_txop_ps \
266 HTC-VHT
:0x400000::$htc_vht \
267 RX-ANTENNA-PATTERN
:0x10000000::$rx_antenna_pattern \
268 TX-ANTENNA-PATTERN
:0x20000000::$tx_antenna_pattern \
269 RX-STBC-1
:0x700:0x100:1 \
270 RX-STBC-12
:0x700:0x200:1 \
271 RX-STBC-123
:0x700:0x300:1 \
272 RX-STBC-1234
:0x700:0x400:1 \
274 # supported Channel widths
276 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
278 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
280 [ "$vht160_hw" = 1 ] && vht_capab
="$vht_capab[VHT160]"
281 [ "$vht160_hw" = 2 ] && vht_capab
="$vht_capab[VHT160-80PLUS80]"
283 # maximum MPDU length
285 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
287 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
288 vht_max_mpdu_hw
=11454
289 [ "$vht_max_mpdu_hw" != 3895 ] && \
290 vht_capab
="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
292 # maximum A-MPDU length exponent
293 vht_max_a_mpdu_len_exp_hw
=0
294 [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
295 vht_max_a_mpdu_len_exp_hw
=1
296 [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
297 vht_max_a_mpdu_len_exp_hw
=2
298 [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
299 vht_max_a_mpdu_len_exp_hw
=3
300 [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
301 vht_max_a_mpdu_len_exp_hw
=4
302 [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
303 vht_max_a_mpdu_len_exp_hw
=5
304 [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
305 vht_max_a_mpdu_len_exp_hw
=6
306 [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
307 vht_max_a_mpdu_len_exp_hw
=7
308 vht_capab
="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
310 # whether or not the STA supports link adaptation using VHT variant
312 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
314 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
316 [ "$vht_link_adapt_hw" != 0 ] && \
317 vht_capab
="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
319 [ -n "$vht_capab" ] && append base_cfg
"vht_capab=$vht_capab" "$N"
322 hostapd_prepare_device_config
"$hostapd_conf_file" nl80211
323 cat >> "$hostapd_conf_file" <<EOF
324 ${channel:+channel=$channel}
325 ${channel_list:+chanlist=$channel_list}
326 ${hostapd_noscan:+noscan=1}
327 ${tx_burst:+tx_queue_data2_burst=$tx_burst}
332 radio_md5sum
=$
(md5sum $hostapd_conf_file | cut
-d" " -f1)
333 echo "radio_config_id=${radio_md5sum}" >> $hostapd_conf_file
336 mac80211_hostapd_setup_bss
() {
343 append hostapd_cfg
"$type=$ifname" "$N"
345 hostapd_set_bss_options hostapd_cfg
"$vif" ||
return 1
346 json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
349 set_default start_disabled
0
351 [ "$wds" -gt 0 ] && {
352 append hostapd_cfg
"wds_sta=1" "$N"
353 [ -n "$wds_bridge" ] && append hostapd_cfg
"wds_bridge=$wds_bridge" "$N"
355 [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg
"start_disabled=1" "$N"
357 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
360 ${dtim_period:+dtim_period=$dtim_period}
361 ${max_listen_int:+max_listen_interval=$max_listen_int}
365 mac80211_get_addr
() {
367 local idx
="$(($2 + 1))"
369 head -n $
(($macidx + 1)) /sys
/class
/ieee80211
/${phy}/addresses |
tail -n1
372 mac80211_generate_mac
() {
374 local id
="${macidx:-0}"
376 local ref
="$(cat /sys/class/ieee80211/${phy}/macaddress)"
377 local mask
="$(cat /sys/class/ieee80211/${phy}/address_mask)"
379 [ "$mask" = "00:00:00:00:00:00" ] && {
380 mask
="ff:ff:ff:ff:ff:ff";
382 [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt 1 ] && {
383 addr
="$(mac80211_get_addr "$phy" "$id")"
391 local oIFS
="$IFS"; IFS
=":"; set -- $mask; IFS
="$oIFS"
396 local oIFS
="$IFS"; IFS
=":"; set -- $ref; IFS
="$oIFS"
399 [ "$((0x$mask1))" -gt 0 ] && {
402 b1
=$
(($b1 ^
((($id - !($b1 & 2)) << 2) | 0x2)))
403 printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
407 [ "$((0x$mask6))" -lt 255 ] && {
408 printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
412 off2=$(( (0x$6 + $id) / 0x100 ))
413 printf "%s:%s:%s:%s:%02x:%02x" \
415 $(( (0x$5 + $off2) % 0x100 )) \
416 $(( (0x$6 + $id) % 0x100 ))
420 [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
422 phy="$(mac80211_path_to_phy "$path")"
423 [ -n "$phy" ] && return 0
425 [ -n "$macaddr" ] && {
426 for phy in $(ls /sys/class/ieee80211 2>/dev
/null
); do
427 grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
433 mac80211_check_ap
() {
437 mac80211_iw_interface_add
() {
444 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag
448 # Device might have just been deleted, give the kernel some time to finish cleaning it up
451 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag
456 # Keep matching pre-existing interface
457 [ -d "/sys/class/ieee80211/${phy}/device/net/${ifname}" ] && \
458 case "$(iw dev wlan0 info | grep "^
\ttype
" | cut -d' ' -f2- 2>/dev/null)" in
460 [ "$type" = "__ap" ] && rc
=0
463 [ "$type" = "adhoc" ] && rc
=0
466 [ "$type" = "managed" ] && rc
=0
469 [ "$type" = "mp" ] && rc
=0
472 [ "$type" = "monitor" ] && rc
=0
481 iw phy
"$phy" interface add
"$ifname" type "$type" $wdsflag
486 # Device might not support virtual interfaces, so the interface never got deleted in the first place.
487 # Check if the interface already exists, and avoid failing in this case.
488 ip link show dev
"$ifname" >/dev
/null
2>/dev
/null
&& rc
=0
491 [ "$rc" != 0 ] && wireless_setup_failed INTERFACE_CREATION_FAILED
495 mac80211_prepare_vif
() {
498 json_get_vars ifname mode ssid wds powersave macaddr
enable
500 [ -n "$ifname" ] || ifname
="wlan${phy#phy}${if_idx:+-$if_idx}"
501 if_idx
=$
((${if_idx:-0} + 1))
504 set_default powersave
0
508 [ -n "$macaddr" ] ||
{
509 macaddr
="$(mac80211_generate_mac $phy)"
510 macidx
="$(($macidx + 1))"
514 json_add_string ifname
"$ifname"
518 # It is far easier to delete and create the desired interface
521 mac80211_iw_interface_add
"$phy" "$ifname" adhoc ||
return
524 # Hostapd will handle recreating the interface and
525 # subsequent virtual APs belonging to the same PHY
526 if [ -n "$hostapd_ctrl" ]; then
532 mac80211_hostapd_setup_bss
"$phy" "$ifname" "$macaddr" "$type" ||
return
534 NEWAPLIST
="${NEWAPLIST}$ifname "
535 [ -n "$hostapd_ctrl" ] ||
{
536 ap_ifname
="${ifname}"
537 hostapd_ctrl
="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
541 mac80211_iw_interface_add
"$phy" "$ifname" mp ||
return
544 mac80211_iw_interface_add
"$phy" "$ifname" monitor ||
return
548 [ "$enable" = 0 ] || staidx
="$(($staidx + 1))"
549 [ "$wds" -gt 0 ] && wdsflag
="4addr on"
550 mac80211_iw_interface_add
"$phy" "$ifname" managed
"$wdsflag" ||
return
551 if [ "$wds" -gt 0 ]; then
552 iw
"$ifname" set 4addr on
554 iw
"$ifname" set 4addr off
556 [ "$powersave" -gt 0 ] && powersave
="on" || powersave
="off"
557 iw
"$ifname" set power_save
"$powersave"
563 [ "$auto_channel" -gt 0 ] || iw dev
"$ifname" set channel
"$channel" $iw_htmode
567 if [ "$mode" != "ap" ]; then
568 # ALL ap functionality will be passed to hostapd
569 # All interfaces must have unique mac addresses
570 # which can either be explicitly set in the device
571 # section, or automatically generated
572 ip link
set dev
"$ifname" address
"$macaddr"
578 mac80211_setup_supplicant
() {
581 local spobj
="$(ubus -S list | grep wpa_supplicant.${ifname})"
583 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
return 1
584 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
{
588 if [ "$mode" = "sta" ]; then
589 wpa_supplicant_add_network
"$ifname"
591 wpa_supplicant_add_network
"$ifname" "$freq" "$htmode" "$noscan"
594 NEWSPLIST
="${NEWSPLIST}$ifname "
596 if [ "${NEWAPLIST%% *}" != "${OLDAPLIST%% *}" ]; then
597 [ "$spobj" ] && ubus call wpa_supplicant.
${phy} config_del
"{\"iface\":\"$ifname\"}"
600 [ "$enable" = 0 ] && {
601 ubus call wpa_supplicant.
${phy} config_del
"{\"iface\":\"$ifname\"}"
602 ip link
set dev
"$ifname" down
605 [ -z "$spobj" ] && add_sp
=1
607 if [ "$add_sp" = "1" ]; then
608 wpa_supplicant_run
"$ifname" "$hostapd_ctrl"
610 ubus call
$spobj reload
614 mac80211_setup_supplicant_noctl
() {
616 local spobj
="$(ubus -S list | grep wpa_supplicant.${ifname})"
617 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
{
622 wpa_supplicant_add_network
"$ifname" "$freq" "$htmode" "$noscan"
624 NEWSPLIST
="${NEWSPLIST}$ifname "
625 [ "$enable" = 0 ] && {
626 ubus call wpa_supplicant.
${phy} config_del
"{\"iface\":\"$ifname\"}"
627 ip link
set dev
"$ifname" down
630 if [ -z "$spobj" ]; then
631 wpa_supplicant_run
"$ifname"
633 ubus call
$spobj reload
637 mac80211_prepare_iw_htmode
() {
639 VHT20|HT20
) iw_htmode
=HT20
;;
643 case "$(( ($channel / 4) % 2 ))" in
644 1) iw_htmode
="HT40+" ;;
645 0) iw_htmode
="HT40-";;
650 HT40
+) iw_htmode
="HT40+";;
651 HT40-
) iw_htmode
="HT40-";;
653 if [ "$channel" -lt 7 ]; then
662 [ "$auto_channel" -gt 0 ] && iw_htmode
="HT40+"
674 mac80211_setup_adhoc
() {
676 json_get_vars bssid ssid key mcast_rate
678 NEWUMLIST
="${NEWUMLIST}$ifname "
680 [ "$enable" = 0 ] && {
681 ip link
set dev
"$ifname" down
686 [ "$auth_type" = "wep" ] && {
691 for idx
in 1 2 3 4; do
692 json_get_var ikey
"key$idx"
695 ikey
="$(($idx - 1)):$(prepare_key_wep "$ikey")"
696 [ $idx -eq $key ] && ikey
="d:$ikey"
697 append keyspec
"$ikey"
702 append keyspec
"d:0:$(prepare_key_wep "$key")"
708 for br
in $basic_rate_list; do
709 wpa_supplicant_add_rate brstr
"$br"
713 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval
"$mcast_rate"
715 iw dev
"$ifname" ibss
join "$ssid" $freq $iw_htmode fixed-freq
$bssid \
716 beacon-interval
$beacon_int \
717 ${brstr:+basic-rates $brstr} \
718 ${mcval:+mcast-rate $mcval} \
719 ${keyspec:+keys $keyspec}
722 mac80211_setup_mesh
() {
724 json_get_vars ssid mesh_id mcast_rate
726 NEWUMLIST
="${NEWUMLIST}$ifname "
728 [ "$enable" = 0 ] && {
729 ip link
set dev
"$ifname" down
734 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval
"$mcast_rate"
735 [ -n "$mesh_id" ] && ssid
="$mesh_id"
737 iw dev
"$ifname" mesh
join "$ssid" freq
$freq $iw_htmode \
738 ${mcval:+mcast-rate $mcval} \
739 beacon-interval
$beacon_int
742 mac80211_setup_vif
() {
753 json_get_var vif_txpower
754 json_get_var vif_enable
enable 1
756 [ "$vif_enable" = 1 ] || action
=down
757 if [ "$mode" != "ap" ] ||
[ "$ifname" = "$ap_ifname" ]; then
758 logger ip link
set dev
"$ifname" $action
759 ip link
set dev
"$ifname" "$action" ||
{
760 wireless_setup_vif_failed IFUP_ERROR
764 [ -z "$vif_txpower" ] || iw dev
"$ifname" set txpower fixed
"${vif_txpower%%.*}00"
769 wireless_vif_parse_encryption
770 freq
="$(get_freq "$phy" "$channel")"
771 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ] || chan_is_dfs
"$phy" "$channel"; then
772 mac80211_setup_supplicant
$vif_enable || failed
=1
774 mac80211_setup_mesh
$vif_enable
776 for var
in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
777 json_get_var mp_val
"$var"
778 [ -n "$mp_val" ] && iw dev
"$ifname" set mesh_param
"$var" "$mp_val"
782 wireless_vif_parse_encryption
783 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
784 freq
="$(get_freq "$phy" "$channel")"
785 mac80211_setup_supplicant_noctl
$vif_enable || failed
=1
787 mac80211_setup_adhoc
$vif_enable
791 mac80211_setup_supplicant
$vif_enable || failed
=1
796 [ -n "$failed" ] || wireless_add_vif
"$name" "$ifname"
802 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
808 iw "$phy" info | grep -E -m1 "(\
* ${chan:-....} MHz
${chan:+|\\[$chan\\]})" | grep -q "MHz.
*radar detection
"
812 mac80211_vap_cleanup() {
816 for wdev in $vaps; do
817 [ "$service" != "none
" ] && ubus call ${service}.${phy} config_remove "{\"iface\":\"$wdev\"}"
818 ip link
set dev
"$wdev" down
2>/dev
/null
823 mac80211_interface_cleanup
() {
825 local primary_ap
=$
(uci
-q -P /var
/state get wireless._
${phy}.aplist
)
826 primary_ap
=${primary_ap%% *}
828 mac80211_vap_cleanup hostapd
"${primary_ap}"
829 mac80211_vap_cleanup wpa_supplicant
"$(uci -q -P /var/state get wireless._${phy}.splist)"
830 mac80211_vap_cleanup none
"$(uci -q -P /var/state get wireless._${phy}.umlist)"
833 mac80211_set_noscan
() {
837 drv_mac80211_cleanup
() {
838 hostapd_common_cleanup
841 drv_mac80211_setup
() {
845 country chanbw distance \
846 txpower antenna_gain \
847 rxantenna txantenna \
848 frag rts beacon_int
:100 htmode
849 json_get_values basic_rate_list basic_rate
853 echo "Could not find PHY for device '$1'"
858 [ -z "$(uci -q -P /var/state show wireless._${phy})" ] && {
859 uci
-q -P /var
/state
set wireless._
${phy}=phy
860 wireless_set_data phy
="$phy"
863 OLDAPLIST
=$
(uci
-q -P /var
/state get wireless._
${phy}.aplist
)
864 OLDSPLIST
=$
(uci
-q -P /var
/state get wireless._
${phy}.splist
)
865 OLDUMLIST
=$
(uci
-q -P /var
/state get wireless._
${phy}.umlist
)
871 for wdev
in $
(list_phy_interfaces
"$phy"); do
873 for cwdev
in $OLDAPLIST $OLDSPLIST $OLDUMLIST; do
874 if [ "$wdev" = "$cwdev" ]; then
879 if [ "$found" = "0" ]; then
880 ip link
set dev
"$wdev" down
885 # convert channel to frequency
886 [ "$auto_channel" -gt 0 ] || freq
="$(get_freq "$phy" "$channel")"
888 [ -n "$country" ] && {
889 iw reg get |
grep -q "^country $country:" ||
{
890 iw reg
set "$country"
895 hostapd_conf_file
="/var/run/hostapd-$phy.conf"
901 [ -n "$chanbw" ] && {
902 for file in /sys
/kernel
/debug
/ieee80211
/$phy/ath9k
*/chanbw
/sys
/kernel
/debug
/ieee80211
/$phy/ath5k
/bwmode
; do
903 [ -f "$file" ] && echo "$chanbw" > "$file"
907 set_default rxantenna
0xffffffff
908 set_default txantenna
0xffffffff
909 set_default distance
0
910 set_default antenna_gain
0
912 [ "$txantenna" = "all" ] && txantenna
=0xffffffff
913 [ "$rxantenna" = "all" ] && rxantenna
=0xffffffff
915 iw phy
"$phy" set antenna
$txantenna $rxantenna >/dev
/null
2>&1
916 iw phy
"$phy" set antenna_gain
$antenna_gain
917 iw phy
"$phy" set distance
"$distance"
919 if [ -n "$txpower" ]; then
920 iw phy
"$phy" set txpower fixed
"${txpower%%.*}00"
922 iw phy
"$phy" set txpower auto
925 [ -n "$frag" ] && iw phy
"$phy" set frag
"${frag%%.*}"
926 [ -n "$rts" ] && iw phy
"$phy" set rts
"${rts%%.*}"
932 for_each_interface
"ap" mac80211_check_ap
934 rm -f "$hostapd_conf_file"
936 for_each_interface
"sta adhoc mesh" mac80211_set_noscan
937 [ -n "$has_ap" ] && mac80211_hostapd_setup_base
"$phy"
939 mac80211_prepare_iw_htmode
940 for_each_interface
"sta adhoc mesh monitor" mac80211_prepare_vif
942 for_each_interface
"ap" mac80211_prepare_vif
943 NEW_MD5
=$
(test -e "${hostapd_conf_file}" && md5sum ${hostapd_conf_file})
944 OLD_MD5
=$
(uci
-q -P /var
/state get wireless._
${phy}.md5
)
945 if [ "${NEWAPLIST}" != "${OLDAPLIST}" ]; then
946 mac80211_vap_cleanup hostapd
"${OLDAPLIST}"
947 [ -n "${NEWAPLIST}" ] && mac80211_iw_interface_add
"$phy" "${NEWAPLIST%% *}" __ap ||
return
950 local primary_ap
=${NEWAPLIST%% *}
951 [ -n "$hostapd_ctrl" ] && {
953 if [ -n "$(ubus list | grep hostapd.$primary_ap)" ]; then
954 [ "${NEW_MD5}" = "${OLD_MD5}" ] ||
{
955 ubus call hostapd.
$primary_ap reload
957 mac80211_vap_cleanup hostapd
"${OLDAPLIST}"
958 [ -n "${NEWAPLIST}" ] && mac80211_iw_interface_add
"$phy" "${NEWAPLIST%% *}" __ap ||
return
961 if [ "$no_reload" != "0" ]; then
963 ubus wait_for hostapd.
$phy
964 ubus call hostapd.
${phy} config_add "{\"iface\":\"$primary_ap\", \"config\":\"${hostapd_conf_file}\"}"
965 local hostapd_pid=$(ubus call service list '{"name
": "hostapd
"}' | jsonfilter -l 1 -e "@
['hostapd'].instances
['hostapd-${phy}'].pid
")
966 wireless_add_process "$hostapd_pid" "/usr
/sbin
/hostapd
" 1
970 wireless_setup_failed HOSTAPD_START_FAILED
974 uci -q -P /var/state set wireless._${phy}.aplist="${NEWAPLIST}"
975 uci -q -P /var/state set wireless._${phy}.md5="${NEW_MD5}"
977 [ "${add_ap}" = 1 ] && sleep 1
978 for_each_interface "ap
" mac80211_setup_vif
983 for_each_interface "sta adhoc mesh monitor
" mac80211_setup_vif
985 uci -q -P /var/state set wireless._${phy}.splist="${NEWSPLIST}"
986 uci -q -P /var/state set wireless._${phy}.umlist="${NEWUMLIST}"
990 for oldvap in $OLDSPLIST; do
992 for newvap in $NEWSPLIST; do
993 [ "$oldvap" = "$newvap" ] && foundvap=1
995 [ "$foundvap" = "0" ] && dropvap="$dropvap $oldvap"
997 [ -n "$dropvap" ] && mac80211_vap_cleanup wpa_supplicant "$dropvap"
1001 _list_phy_interfaces() {
1003 if [ -d "/sys
/class
/ieee80211
/${phy}/device
/net
" ]; then
1004 ls "/sys
/class
/ieee80211
/${phy}/device
/net
" 2>/dev/null;
1006 ls "/sys
/class
/ieee80211
/${phy}/device
" 2>/dev/null | grep net: | sed -e 's,net:,,g'
1010 list_phy_interfaces() {
1013 for dev in $(_list_phy_interfaces "$phy"); do
1014 readlink "/sys
/class
/net
/${dev}/phy80211
" | grep -q "/${phy}\$
" || continue
1019 drv_mac80211_teardown() {
1020 wireless_process_kill_all
1026 mac80211_interface_cleanup "$phy"
1027 uci -q -P /var/state revert wireless._${phy}