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
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 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_int
$MP_CONFIG_INT
54 config_add_boolean
$MP_CONFIG_BOOL
55 config_add_string
$MP_CONFIG_STRING
58 mac80211_hostapd_setup_base
() {
63 [ "$auto_channel" -gt 0 ] && channel
=acs_survey
65 [ "$enable_ht" -gt 0 ] && {
66 json_get_vars noscan htmode
67 json_get_values ht_capab_list ht_capab
69 append base_cfg
"ieee80211n=1" "$N"
73 HT20|HT40-|HT40
+) ht_capab
="[$htmode]";;
76 36|
44|
52|
60|
100|
108|
116|
124|
132|
140|
149|
157) ht_capab
="[HT40+]";;
77 40|
48|
56|
64|
104|
112|
120|
128|
136|
144|
153|
161) ht_capab
="[HT40-]";;
81 for cap
in $ht_capab_list; do
82 ht_capab
="$ht_capab[$cap]"
85 [ -n "$ht_capab" ] && append base_cfg
"ht_capab=$ht_capab" "$N"
107 append base_cfg
"vht_oper_chwidth=0" "$N"
108 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
112 36|
40|
44|
48) idx
=42;;
113 52|
56|
60|
64) idx
=58;;
114 100|
104|
108|
112) idx
=106;;
115 116|
120|
124|
128) idx
=122;;
116 132|
136|
140|
144) idx
=138;;
117 149|
153|
157|
161) idx
=155;;
120 append base_cfg
"vht_oper_chwidth=1" "$N"
121 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
125 36|
40|
44|
48|
52|
56|
60|
64) idx
=50;;
126 100|
104|
108|
112|
116|
120|
124|
128) idx
=114;;
129 append base_cfg
"vht_oper_chwidth=2" "$N"
130 append base_cfg
"vht_oper_centr_freq_seg0_idx=$idx" "$N"
134 if [ "$enable_ac" != "0" ]; then
146 rx_antenna_pattern
:1 \
147 tx_antenna_pattern
:1 \
153 append base_cfg
"ieee80211ac=1" "$N"
156 for cap
in $
(iw phy
"$phy" info |
awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
157 vht_cap
="$(($vht_cap | $cap))"
161 [ "$((($vht_cap & 16) * $rxldpc))" -eq 16 ] && \
162 vht_capab
="$vht_capab[RXLDPC]"
163 [ "$((($vht_cap & 32) * $short_gi_80))" -eq 32 ] && \
164 vht_capab
="$vht_capab[SHORT-GI-80]"
165 [ "$((($vht_cap & 64) * $short_gi_160))" -eq 64 ] && \
166 vht_capab
="$vht_capab[SHORT-GI-160]"
167 [ "$((($vht_cap & 128) * $tx_stbc_2by1))" -eq 128 ] && \
168 vht_capab
="$vht_capab[TX-STBC-2BY1]"
169 [ "$((($vht_cap & 2048) * $su_beamformer))" -eq 2048 ] && \
170 vht_capab
="$vht_capab[SU-BEAMFORMER]"
171 [ "$((($vht_cap & 4096) * $su_beamformee))" -eq 4096 ] && \
172 vht_capab
="$vht_capab[SU-BEAMFORMEE]"
173 [ "$((($vht_cap & 524288) * $mu_beamformer))" -eq 524288 ] && \
174 vht_capab
="$vht_capab[MU-BEAMFORMER]"
175 [ "$((($vht_cap & 1048576) * $mu_beamformee))" -eq 1048576 ] && \
176 vht_capab
="$vht_capab[MU-BEAMFORMEE]"
177 [ "$((($vht_cap & 2097152) * $vht_txop_ps))" -eq 2097152 ] && \
178 vht_capab
="$vht_capab[VHT-TXOP-PS]"
179 [ "$((($vht_cap & 4194304) * $htc_vht))" -eq 4194304 ] && \
180 vht_capab
="$vht_capab[HTC-VHT]"
181 [ "$((($vht_cap & 268435456) * $rx_antenna_pattern))" -eq 268435456 ] && \
182 vht_capab
="$vht_capab[RX-ANTENNA-PATTERN]"
183 [ "$((($vht_cap & 536870912) * $tx_antenna_pattern))" -eq 536870912 ] && \
184 vht_capab
="$vht_capab[TX-ANTENNA-PATTERN]"
186 # supported Channel widths
188 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
190 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
192 [ "$vht160_hw" = 1 ] && vht_capab
="$vht_capab[VHT160]"
193 [ "$vht160_hw" = 2 ] && vht_capab
="$vht_capab[VHT160-80PLUS80]"
195 # maximum MPDU length
197 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
199 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
200 vht_max_mpdu_hw
=11454
201 [ "$vht_max_mpdu_hw" != 3895 ] && \
202 vht_capab
="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
204 # support for the reception of PPDUs using STBC
206 [ "$(($vht_cap & 1792))" -ge 256 -a 1 -le "$vht_max_rx_stbc" ] && \
208 [ "$(($vht_cap & 1792))" -ge 512 -a 2 -le "$vht_max_rx_stbc" ] && \
210 [ "$(($vht_cap & 1792))" -ge 768 -a 3 -le "$vht_max_rx_stbc" ] && \
212 [ "$(($vht_cap & 1792))" -ge 1024 -a 4 -le "$vht_max_rx_stbc" ] && \
214 [ "$vht_max_rx_stbc_hw" = 1 ] && vht_capab
="$vht_capab[RX-STBC-1]"
215 [ "$vht_max_rx_stbc_hw" = 2 ] && vht_capab
="$vht_capab[RX-STBC-12]"
216 [ "$vht_max_rx_stbc_hw" = 3 ] && vht_capab
="$vht_capab[RX-STBC-123]"
217 [ "$vht_max_rx_stbc_hw" = 4 ] && vht_capab
="$vht_capab[RX-STBC-1234]"
219 # whether or not the STA supports link adaptation using VHT variant
221 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
223 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
225 [ "$vht_link_adapt_hw" != 0 ] && \
226 vht_capab
="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
228 [ -n "$vht_capab" ] && append base_cfg
"vht_capab=$vht_capab" "$N"
232 hostapd_prepare_device_config
"$hostapd_conf_file" nl80211
233 cat >> "$hostapd_conf_file" <<EOF
234 ${channel:+channel=$channel}
235 ${noscan:+noscan=$noscan}
242 mac80211_hostapd_setup_bss
() {
249 append hostapd_cfg
"$type=$ifname" "$N"
251 hostapd_set_bss_options hostapd_cfg
"$vif" ||
return 1
252 json_get_vars wds dtim_period max_listen_int
256 [ "$wds" -gt 0 ] && append hostapd_cfg
"wds_sta=1" "$N"
257 [ "$staidx" -gt 0 ] && append hostapd_cfg
"start_disabled=1" "$N"
259 cat >> /var
/run
/hostapd-
$phy.conf
<<EOF
262 ${dtim_period:+dtim_period=$dtim_period}
263 ${max_listen_int:+max_listen_interval=$max_listen_int}
267 mac80211_generate_mac
() {
269 local id
="${macidx:-0}"
271 local ref
="$(cat /sys/class/ieee80211/${phy}/macaddress)"
272 local mask
="$(cat /sys/class/ieee80211/${phy}/address_mask)"
274 [ "$mask" = "00:00:00:00:00:00" ] && mask
="ff:ff:ff:ff:ff:ff";
275 local oIFS
="$IFS"; IFS
=":"; set -- $mask; IFS
="$oIFS"
280 local oIFS
="$IFS"; IFS
=":"; set -- $ref; IFS
="$oIFS"
283 [ "$((0x$mask1))" -gt 0 ] && {
286 b1
=$
(($b1 ^
((($id - 1) << 2) | 0x2)))
287 printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
291 [ "$((0x$mask6))" -lt 255 ] && {
292 printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
296 off2=$(( (0x$6 + $id) / 0x100 ))
297 printf "%s:%s:%s:%s:%02x:%02x" \
299 $(( (0x$5 + $off2) % 0x100 )) \
300 $(( (0x$6 + $id) % 0x100 ))
304 [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
305 [ -n "$path" -a -d "/sys/devices/$path/ieee80211" ] && {
306 phy="$(ls /sys/devices/$path/ieee80211 | grep -m 1 phy)"
307 [ -n "$phy" ] && return 0
309 [ -n "$macaddr" ] && {
310 for phy in $(ls /sys/class/ieee80211 2>/dev
/null
); do
311 grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
317 mac80211_check_ap
() {
321 mac80211_prepare_vif
() {
324 json_get_vars ifname mode ssid wds powersave macaddr
326 [ -n "$ifname" ] || ifname
="wlan${phy#phy}${if_idx:+-$if_idx}"
327 if_idx
=$
((${if_idx:-0} + 1))
330 set_default powersave
0
334 [ -n "$macaddr" ] ||
{
335 macaddr
="$(mac80211_generate_mac $phy)"
336 macidx
="$(($macidx + 1))"
340 json_add_string ifname
"$ifname"
344 # It is far easier to delete and create the desired interface
347 iw phy
"$phy" interface add
"$ifname" type adhoc
350 # Hostapd will handle recreating the interface and
351 # subsequent virtual APs belonging to the same PHY
352 if [ -n "$hostapd_ctrl" ]; then
358 mac80211_hostapd_setup_bss
"$phy" "$ifname" "$macaddr" "$type" ||
return
360 [ -n "$hostapd_ctrl" ] ||
{
361 iw phy
"$phy" interface add
"$ifname" type managed
362 hostapd_ctrl
="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
366 json_get_vars key mesh_id
367 if [ -n "$key" ]; then
368 iw phy
"$phy" interface add
"$ifname" type mp
370 iw phy
"$phy" interface add
"$ifname" type mp mesh_id
"$mesh_id"
374 iw phy
"$phy" interface add
"$ifname" type monitor
378 staidx
="$(($staidx + 1))"
379 [ "$wds" -gt 0 ] && wdsflag
="4addr on"
380 iw phy
"$phy" interface add
"$ifname" type managed
$wdsflag
381 [ "$powersave" -gt 0 ] && powersave
="on" || powersave
="off"
382 iw
"$ifname" set power_save
"$powersave"
388 [ "$auto_channel" -gt 0 ] || iw dev
"$ifname" set channel
"$channel" $htmode
392 if [ "$mode" != "ap" ]; then
393 # ALL ap functionality will be passed to hostapd
394 # All interfaces must have unique mac addresses
395 # which can either be explicitly set in the device
396 # section, or automatically generated
397 ifconfig
"$ifname" hw ether
"$macaddr"
403 mac80211_setup_supplicant
() {
404 wpa_supplicant_prepare_interface
"$ifname" nl80211 ||
return 1
405 wpa_supplicant_add_network
"$ifname"
406 wpa_supplicant_run
"$ifname" ${hostapd_ctrl:+-H $hostapd_ctrl}
409 mac80211_setup_adhoc
() {
410 json_get_vars bssid ssid key mcast_rate
413 [ "$auth_type" == "wep" ] && {
418 for idx
in 1 2 3 4; do
419 json_get_var ikey
"key$idx"
422 ikey
="$(($idx - 1)):$(prepare_key_wep "$ikey")"
423 [ $idx -eq $key ] && ikey
="d:$ikey"
424 append keyspec
"$ikey"
429 append keyspec
"d:0:$(prepare_key_wep "$key")"
435 for br
in $basic_rate_list; do
436 hostapd_add_rate brstr
"$br"
440 [ -n "$mcast_rate" ] && hostapd_add_rate mcval
"$mcast_rate"
442 iw dev
"$ifname" ibss
join "$ssid" $freq $htmode fixed-freq
$bssid \
443 ${beacon_int:+beacon-interval $beacon_int} \
444 ${brstr:+basic-rates $brstr} \
445 ${mcval:+mcast-rate $mcval} \
446 ${keyspec:+keys $keyspec}
449 mac80211_setup_vif
() {
458 json_get_var vif_txpower txpower
460 ifconfig
"$ifname" up ||
{
461 wireless_setup_vif_failed IFUP_ERROR
466 set_default vif_txpower
"$txpower"
467 [ -z "$vif_txpower" ] || iw dev
"$ifname" set txpower fixed
"${vif_txpower%%.*}00"
471 for var
in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
472 json_get_var mp_val
"$var"
473 [ -n "$mp_val" ] && iw dev
"$ifname" set mesh_param
"$var" "$mp_val"
478 wireless_vif_parse_encryption
479 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
480 mac80211_setup_supplicant || failed
=1
486 mac80211_setup_supplicant || failed
=1
491 [ -n "$failed" ] || wireless_add_vif
"$name" "$ifname"
497 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
500 mac80211_interface_cleanup() {
503 for wdev in $(list_phy_interfaces "$phy"); do
504 ifconfig "$wdev" down 2>/dev/null
509 drv_mac80211_cleanup() {
510 hostapd_common_cleanup
513 drv_mac80211_setup() {
517 country chanbw distance \
518 txpower antenna_gain \
519 rxantenna txantenna \
521 json_get_values basic_rate_list basic_rate
525 echo "Could not
find PHY
for device
'$1'"
530 wireless_set_data phy="$phy"
531 mac80211_interface_cleanup "$phy"
533 # convert channel to frequency
534 [ "$auto_channel" -gt 0 ] || freq="$
(get_freq
"$phy" "$channel")"
536 [ -n "$country" ] && {
537 iw reg get | grep -q "^country
$country:" || {
538 iw reg set "$country"
543 hostapd_conf_file="/var
/run
/hostapd-
$phy.conf
"
549 [ -n "$chanbw" ] && {
550 for file in /sys/kernel/debug/ieee80211/$phy/ath9k/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
551 [ -f "$file" ] && echo "$chanbw" > "$file"
555 set_default rxantenna all
556 set_default txantenna all
557 set_default distance 0
558 set_default antenna_gain 0
560 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
561 iw phy "$phy" set antenna_gain $antenna_gain
562 iw phy "$phy" set distance "$distance"
564 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
565 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
569 for_each_interface "ap
" mac80211_check_ap
571 rm -f "$hostapd_conf_file"
572 [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
574 for_each_interface "sta adhoc mesh monitor
" mac80211_prepare_vif
575 for_each_interface "ap
" mac80211_prepare_vif
577 [ -n "$hostapd_ctrl" ] && {
578 /usr/sbin/hostapd -P /var/run/wifi-$phy.pid -B "$hostapd_conf_file"
580 wireless_add_process "$
(cat /var
/run
/wifi-
$phy.pid
)" "/usr
/sbin
/hostapd
" 1
582 wireless_setup_failed HOSTAPD_START_FAILED
587 for_each_interface "ap sta adhoc mesh monitor
" mac80211_setup_vif
592 list_phy_interfaces() {
594 if [ -d "/sys
/class
/ieee80211
/${phy}/device
/net
" ]; then
595 ls "/sys
/class
/ieee80211
/${phy}/device
/net
" 2>/dev/null;
597 ls "/sys
/class
/ieee80211
/${phy}/device
" 2>/dev/null | grep net: | sed -e 's,net:,,g'
601 drv_mac80211_teardown() {
602 wireless_process_kill_all
608 mac80211_interface_cleanup "$phy"