mac80211: apply wds fix

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-11-15 09:27:35 +01:00
parent d3c0df1a4f
commit 2416019d87
2 changed files with 142 additions and 150 deletions

View File

@@ -567,58 +567,10 @@ mac80211_check_ap() {
has_ap=1 has_ap=1
} }
mac80211_prepare_vif() { mac80211_set_ifname() {
json_select config local phy="$1"
json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
[ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}" [ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}"
if_idx=$((${if_idx:-0} + 1)) if_idx=$((${if_idx:-0} + 1))
append active_ifnames "$ifname"
set_default wds 0
set_default powersave 0
json_add_string _ifname "$ifname"
default_macaddr=
[ -n "$macaddr" ] || {
macaddr="$(mac80211_generate_mac $phy)"
macidx="$(($macidx + 1))"
default_macaddr=1
}
json_add_string _macaddr "$macaddr"
json_add_string _default_macaddr "$default_macaddr"
json_select ..
[ "$mode" == "ap" ] && {
[ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
[ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
}
json_select config
# It is far easier to delete and create the desired interface
case "$mode" in
ap)
# Hostapd will handle recreating the interface and
# subsequent virtual APs belonging to the same PHY
if [ -n "$hostapd_ctrl" ]; then
type=bss
else
type=interface
fi
mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
[ -n "$hostapd_ctrl" ] || {
ap_ifname="${ifname}"
hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
}
;;
esac
json_select ..
} }
mac80211_prepare_iw_htmode() { mac80211_prepare_iw_htmode() {
@@ -763,19 +715,6 @@ mac80211_setup_monitor() {
json_set_namespace "$prev" json_set_namespace "$prev"
} }
mac80211_set_vif_txpower() {
local name="$1"
json_select config
json_get_var ifname _ifname
json_get_vars vif_txpower wds
json_select ..
set_default wds 0
[ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
[ "$wds" -gt 0 ] && echo 1 > /sys/kernel/debug/ieee80211/$phy/netdev\:$ifname/disable_offload
}
wpa_supplicant_init_config() { wpa_supplicant_init_config() {
json_set_namespace wpa_supp prev json_set_namespace wpa_supp prev
@@ -880,19 +819,39 @@ mac80211_setup_supplicant() {
return 0 return 0
} }
mac80211_setup_vif() { mac80211_prepare_vif() {
local name="$1"
local failed
json_select config json_select config
json_get_var ifname _ifname
json_get_var macaddr _macaddr
json_get_var default_macaddr _default_macaddr
json_get_vars mode wds powersave
set_default powersave 0 json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
[ -n "$ifname" ] || {
local prefix;
case "$mode" in
ap|sta|mesh) prefix=$mode;;
adhoc) prefix=ibss;;
monitor) prefix=mon;;
esac
mac80211_set_ifname "$phy" "$prefix"
}
append active_ifnames "$ifname"
default_macaddr=
if [ -z "$macaddr" ]; then
macaddr="$(mac80211_generate_mac $phy)"
macidx="$(($macidx + 1))"
default_macaddr=1
elif [ "$macaddr" = 'random' ]; then
macaddr="$(macaddr_random)"
fi
local failed=
set_default wds 0 set_default wds 0
set_default powersave 0
# It is far easier to delete and create the desired interface
case "$mode" in case "$mode" in
mesh) mesh)
json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING
@@ -918,10 +877,48 @@ mac80211_setup_vif() {
monitor) monitor)
mac80211_setup_monitor mac80211_setup_monitor
;; ;;
ap)
# Hostapd will handle recreating the interface and
# subsequent virtual APs belonging to the same PHY
if [ -n "$hostapd_ctrl" ]; then
type=bss
else
type=interface
fi
mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
[ -n "$hostapd_ctrl" ] || {
ap_ifname="${ifname}"
hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
}
;;
esac esac
[ -n "$failed" ] || {
json_add_string _ifname "$ifname"
json_add_string _macaddr "$macaddr"
json_add_string _default_macaddr "$default_macaddr"
}
json_select .. json_select ..
[ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
[ "$mode" == "ap" ] && {
[ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
[ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
}
}
mac80211_setup_vif() {
local name="$1"
json_select config
json_get_var ifname _ifname
json_get_vars vif_txpower
json_select ..
[ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
[ -n "$ifname" ] && wireless_add_vif "$name" "$ifname"
} }
get_freq() { get_freq() {
@@ -1073,7 +1070,6 @@ drv_mac80211_setup() {
mac80211_prepare_iw_htmode mac80211_prepare_iw_htmode
active_ifnames= active_ifnames=
for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif
for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
[ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy" [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy"
[ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy" [ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy"
@@ -1084,7 +1080,7 @@ drv_mac80211_setup() {
wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames
json_set_namespace "$prev" json_set_namespace "$prev"
for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
wireless_set_up wireless_set_up
} }

View File

@@ -567,58 +567,10 @@ mac80211_check_ap() {
has_ap=1 has_ap=1
} }
mac80211_prepare_vif() { mac80211_set_ifname() {
json_select config local phy="$1"
json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
[ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}" [ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}"
if_idx=$((${if_idx:-0} + 1)) if_idx=$((${if_idx:-0} + 1))
append active_ifnames "$ifname"
set_default wds 0
set_default powersave 0
json_add_string _ifname "$ifname"
default_macaddr=
[ -n "$macaddr" ] || {
macaddr="$(mac80211_generate_mac $phy)"
macidx="$(($macidx + 1))"
default_macaddr=1
}
json_add_string _macaddr "$macaddr"
json_add_string _default_macaddr "$default_macaddr"
json_select ..
[ "$mode" == "ap" ] && {
[ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
[ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
}
json_select config
# It is far easier to delete and create the desired interface
case "$mode" in
ap)
# Hostapd will handle recreating the interface and
# subsequent virtual APs belonging to the same PHY
if [ -n "$hostapd_ctrl" ]; then
type=bss
else
type=interface
fi
mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
[ -n "$hostapd_ctrl" ] || {
ap_ifname="${ifname}"
hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
}
;;
esac
json_select ..
} }
mac80211_prepare_iw_htmode() { mac80211_prepare_iw_htmode() {
@@ -763,19 +715,6 @@ mac80211_setup_monitor() {
json_set_namespace "$prev" json_set_namespace "$prev"
} }
mac80211_set_vif_txpower() {
local name="$1"
json_select config
json_get_var ifname _ifname
json_get_vars vif_txpower wds
json_select ..
set_default wds 0
[ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
[ "$wds" -gt 0 ] && echo 1 > /sys/kernel/debug/ieee80211/$phy/netdev\:$ifname/disable_offload
}
wpa_supplicant_init_config() { wpa_supplicant_init_config() {
json_set_namespace wpa_supp prev json_set_namespace wpa_supp prev
@@ -880,19 +819,39 @@ mac80211_setup_supplicant() {
return 0 return 0
} }
mac80211_setup_vif() { mac80211_prepare_vif() {
local name="$1"
local failed
json_select config json_select config
json_get_var ifname _ifname
json_get_var macaddr _macaddr
json_get_var default_macaddr _default_macaddr
json_get_vars mode wds powersave
set_default powersave 0 json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
[ -n "$ifname" ] || {
local prefix;
case "$mode" in
ap|sta|mesh) prefix=$mode;;
adhoc) prefix=ibss;;
monitor) prefix=mon;;
esac
mac80211_set_ifname "$phy" "$prefix"
}
append active_ifnames "$ifname"
default_macaddr=
if [ -z "$macaddr" ]; then
macaddr="$(mac80211_generate_mac $phy)"
macidx="$(($macidx + 1))"
default_macaddr=1
elif [ "$macaddr" = 'random' ]; then
macaddr="$(macaddr_random)"
fi
local failed=
set_default wds 0 set_default wds 0
set_default powersave 0
# It is far easier to delete and create the desired interface
case "$mode" in case "$mode" in
mesh) mesh)
json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING
@@ -918,10 +877,48 @@ mac80211_setup_vif() {
monitor) monitor)
mac80211_setup_monitor mac80211_setup_monitor
;; ;;
ap)
# Hostapd will handle recreating the interface and
# subsequent virtual APs belonging to the same PHY
if [ -n "$hostapd_ctrl" ]; then
type=bss
else
type=interface
fi
mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
[ -n "$hostapd_ctrl" ] || {
ap_ifname="${ifname}"
hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
}
;;
esac esac
[ -n "$failed" ] || {
json_add_string _ifname "$ifname"
json_add_string _macaddr "$macaddr"
json_add_string _default_macaddr "$default_macaddr"
}
json_select .. json_select ..
[ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
[ "$mode" == "ap" ] && {
[ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
[ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
}
}
mac80211_setup_vif() {
local name="$1"
json_select config
json_get_var ifname _ifname
json_get_vars vif_txpower
json_select ..
[ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
[ -n "$ifname" ] && wireless_add_vif "$name" "$ifname"
} }
get_freq() { get_freq() {
@@ -1073,7 +1070,6 @@ drv_mac80211_setup() {
mac80211_prepare_iw_htmode mac80211_prepare_iw_htmode
active_ifnames= active_ifnames=
for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif
for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
[ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy" [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy"
[ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy" [ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy"
@@ -1084,7 +1080,7 @@ drv_mac80211_setup() {
wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames
json_set_namespace "$prev" json_set_namespace "$prev"
for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
wireless_set_up wireless_set_up
} }