From be1cb862f1e0f8069b6f3224d1c0a034a0fdc9aa Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 5 Sep 2023 14:05:55 +0800 Subject: [PATCH 01/32] ipq807x: CIG WF-186w - Adjust the LAN ID to match printed labels Fixes: WIFI-12915 Signed-off-by: Ken --- feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network index 942e88bce..b3e9120b1 100755 --- a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network +++ b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network @@ -64,7 +64,7 @@ qcom_setup_interfaces() ucidef_set_interface_wan "eth0" ;; cig,wf186w) - ucidef_add_switch "switch0" "4:wan" "1:lan" "2:lan" "3:lan" "0:lan" "6@eth0" + ucidef_add_switch "switch0" "4:wan" "0:lan" "1:lan" "2:lan" "3:lan" "6@eth0" ;; yuncore,fap650) ucidef_set_interface_lan "eth3 eth2 eth1 eth0" From b6b298ad685f8f76a48494b8241340d4172ed037 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 6 Sep 2023 16:06:50 +0200 Subject: [PATCH 02/32] hostapd: fix association of clients on Open/VLAN SSIDs Fixes: WIFI-12929 Signed-off-by: John Crispin --- feeds/ipq807x_v5.4/hostapd/files/hostapd.sh | 2 +- feeds/ipq95xx/hostapd/files/hostapd.sh | 2 +- feeds/wifi-ax/hostapd/files/hostapd.sh | 1 + patches/wifi/0005-hostapd-add-TIP-hostapd.sh-version.patch | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh b/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh index 90d921041..145848189 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh +++ b/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh @@ -772,9 +772,9 @@ hostapd_set_bss_options() { # Here we make the assumption that if we're in open mode # with WPS enabled, we got to be in unconfigured state. wps_not_configured=1 + vlan_possible=1 [ "$macfilter" = radius ] && { append_radius_server - vlan_possible=1 } ;; psk|sae|psk-sae) diff --git a/feeds/ipq95xx/hostapd/files/hostapd.sh b/feeds/ipq95xx/hostapd/files/hostapd.sh index d22e12454..02eed1010 100644 --- a/feeds/ipq95xx/hostapd/files/hostapd.sh +++ b/feeds/ipq95xx/hostapd/files/hostapd.sh @@ -771,10 +771,10 @@ hostapd_set_bss_options() { wps_possible=1 # Here we make the assumption that if we're in open mode # with WPS enabled, we got to be in unconfigured state. + vlan_possible=1 wps_not_configured=1 [ "$macfilter" = radius ] && { append_radius_server - vlan_possible=1 } ;; psk|sae|psk-sae) diff --git a/feeds/wifi-ax/hostapd/files/hostapd.sh b/feeds/wifi-ax/hostapd/files/hostapd.sh index 90d921041..9855925e0 100644 --- a/feeds/wifi-ax/hostapd/files/hostapd.sh +++ b/feeds/wifi-ax/hostapd/files/hostapd.sh @@ -772,6 +772,7 @@ hostapd_set_bss_options() { # Here we make the assumption that if we're in open mode # with WPS enabled, we got to be in unconfigured state. wps_not_configured=1 + vlan_possible=1 [ "$macfilter" = radius ] && { append_radius_server vlan_possible=1 diff --git a/patches/wifi/0005-hostapd-add-TIP-hostapd.sh-version.patch b/patches/wifi/0005-hostapd-add-TIP-hostapd.sh-version.patch index 463476621..8b91d8576 100644 --- a/patches/wifi/0005-hostapd-add-TIP-hostapd.sh-version.patch +++ b/patches/wifi/0005-hostapd-add-TIP-hostapd.sh-version.patch @@ -381,9 +381,9 @@ index 65ae662c4d..90d9210410 100644 # Here we make the assumption that if we're in open mode # with WPS enabled, we got to be in unconfigured state. wps_not_configured=1 ++ vlan_possible=1 + [ "$macfilter" = radius ] && { + append_radius_server -+ vlan_possible=1 + } ;; psk|sae|psk-sae) From 989d39d1f2acd495bb105cbaaf87405e7b84658a Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 6 Sep 2023 16:14:05 +0200 Subject: [PATCH 03/32] ucentral-schema: update to latest HEAD a4c8a13 increase reassociation_deadline to 3s when using multi-psk Fixes: WIFI-12598 Signed-off-by: John Crispin --- feeds/ucentral/ucentral-schema/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-schema/Makefile b/feeds/ucentral/ucentral-schema/Makefile index c5f7e54c4..91066b25e 100644 --- a/feeds/ucentral/ucentral-schema/Makefile +++ b/feeds/ucentral/ucentral-schema/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git -PKG_MIRROR_HASH:=6da4c8a82c5393d54bfe1a91479730cc126e7de1cf1565a0274d600759e668e0 +PKG_MIRROR_HASH:=a04f51a70b29a2ac127d50d94ae7f5a6695ab47a8d87ab42c2baac926679f176 PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-05-29 -PKG_SOURCE_VERSION:=708b1de986b63c35e4f5e79a3183ffb4a36f40a1 +PKG_SOURCE_VERSION:=a4c8a1368a36906f10f53db39eba7e59ea500483 PKG_MAINTAINER:=John Crispin PKG_LICENSE:=BSD-3-Clause From 03ec2de777c9949ef8fefbab780593bd704de8f3 Mon Sep 17 00:00:00 2001 From: Arif Alam Date: Thu, 7 Sep 2023 10:05:50 -0400 Subject: [PATCH 04/32] ucentral-event: dhcp relay option 82 parameters Add the ability to configure circuit-id and remote-id sub-options. Signed-off-by: Arif Alam --- .../ucentral-event/files/ucentral-event | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-event/files/ucentral-event b/feeds/ucentral/ucentral-event/files/ucentral-event index 595f37aa2..1c22baa4e 100755 --- a/feeds/ucentral/ucentral-event/files/ucentral-event +++ b/feeds/ucentral/ucentral-event/files/ucentral-event @@ -231,14 +231,27 @@ function dhcp_subscriber_remove_cb(remove) { printf('dhcp remove: %.J\n', remove); } +function match_dhcp_relay_option82(format, hapd) { + switch(format) { + case 'ap-mac': + uci.load('ucentral'); + let ucentral = uci.get_all('ucentral', 'config'); + return ucentral.serial; + case 'ssid': + return hapd.config.ssid; + case 'vlan-id': + return hapd.config.vlan_id; + } +} + function dhcp_relay_subscriber_notify_cb(notify) { let ifname = split(notify.data.info.device, '-v'); let hapd = hostapd[ifname[0]]; let vlan = ifname[1]; if (hapd) { vlan ??= hapd.config.vlan_id; - let circuit_id = `${vlan}`; - let remote_id = hapd.bssid; + let circuit_id = match_dhcp_relay_option82(relay['vlan' + vlan]?.circuit_id, hapd); + let remote_id = match_dhcp_relay_option82(relay['vlan' + vlan]?.remote_id, hapd); return { address: relay['vlan' + vlan]?.server, options: [ From 082134bc437fa227f81661f466eac87c20c46150 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 11 Sep 2023 07:31:55 +0200 Subject: [PATCH 05/32] ucentral-schema: update to latest HEAD fd6a079 dhcp-relay: dhcp relay option 82 parameters Signed-off-by: John Crispin --- feeds/ucentral/ucentral-schema/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-schema/Makefile b/feeds/ucentral/ucentral-schema/Makefile index 91066b25e..00c81e58b 100644 --- a/feeds/ucentral/ucentral-schema/Makefile +++ b/feeds/ucentral/ucentral-schema/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git -PKG_MIRROR_HASH:=a04f51a70b29a2ac127d50d94ae7f5a6695ab47a8d87ab42c2baac926679f176 +PKG_MIRROR_HASH:=c0173d6d4a71bc5760fbf882805e55e4be3eadf69059723f16fde388965ad6af PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-05-29 -PKG_SOURCE_VERSION:=a4c8a1368a36906f10f53db39eba7e59ea500483 +PKG_SOURCE_VERSION:=fd6a079907df46adb20071d430133d710fa9815a PKG_MAINTAINER:=John Crispin PKG_LICENSE:=BSD-3-Clause From 6a797e8a6434588f06fd4d0a9e89ab871b226dd3 Mon Sep 17 00:00:00 2001 From: Paul White Date: Sat, 2 Sep 2023 22:44:54 -0700 Subject: [PATCH 06/32] ucentral-schema: cig.wf186w: wan_port set to eth0 Reset the ucentral UCI config 'event.config.wan_port' to eth0 for the WF186W board Signed-off-by: Paul White --- .../files/etc/uci-defaults/99-ucentral-event | 10 ++++++++++ 1 file changed, 10 insertions(+) mode change 100644 => 100755 feeds/ucentral/ucentral-schema/files/etc/uci-defaults/99-ucentral-event diff --git a/feeds/ucentral/ucentral-schema/files/etc/uci-defaults/99-ucentral-event b/feeds/ucentral/ucentral-schema/files/etc/uci-defaults/99-ucentral-event old mode 100644 new mode 100755 index 0004442ec..ec69974d4 --- a/feeds/ucentral/ucentral-schema/files/etc/uci-defaults/99-ucentral-event +++ b/feeds/ucentral/ucentral-schema/files/etc/uci-defaults/99-ucentral-event @@ -1,5 +1,15 @@ #!/bin/sh +. /lib/functions.sh + +case "$(board_name)" in + "cig,wf186w") + uci del event.config.wan_port + uci add_list event.config.wan_port=eth0 + exit 0 + ;; +esac + wan=$(cat /etc/board.json | jsonfilter -e '@.network.wan.device') [ -z "$wan" ] && eval $(jsonfilter -i /etc/board.json -e 'wan=@.network.wan.ports.*') for w in $wan; do From 513eec1c5f79357f3a6ec2532ba2b4a107b4be85 Mon Sep 17 00:00:00 2001 From: Paul White Date: Sat, 2 Sep 2023 22:41:46 -0700 Subject: [PATCH 07/32] ipq807x: cig.wf186w: Add MPSK Dynamic VLAN support When a MPSK VLAN netdev is created on the cig.wf186w board, this script will configure switch0 via swconfig for the corresponding VLAN Signed-off-by: Paul White --- .../base-files/etc/hotplug.d/net/50-dvlan | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/net/50-dvlan diff --git a/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/net/50-dvlan b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/net/50-dvlan new file mode 100644 index 000000000..aa137fac8 --- /dev/null +++ b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/net/50-dvlan @@ -0,0 +1,40 @@ +#!/bin/sh + +. /lib/functions.sh + +debug() { + logger -t HOTPLUG-DVLAN "$*" +} + +if [ "${INTERFACE:0:4}" != "wlan" ]; then + exit 0 +fi + +case "$(board_name)" in + "cig,wf186w") + wan_iface="eth0" + switch_dev="switch0" + switch_wan_port=4 + switch_cpu_port=6 + ;; + + *) + exit 0 +esac + +VSTR="$(echo $INTERFACE | egrep -o 'v([0-9]+)$')" +[ -z "$VSTR" ] && exit 0 +VID="${VSTR:1}" +[ $VID -lt 1 -o $VID -gt 4096 ] && exit 0 + +if [ "$ACTION" = "add" ]; then + debug "[$INTERFACE] Dynamic VLAN $VID added, configuring switch" + swconfig dev ${switch_dev} vlan $VID set ports "${switch_wan_port}t ${switch_cpu_port}t" +elif [ "$ACTION" = "remove" ]; then + let cnt="$(bridge vlan show vid $VID | egrep "^wlan" | wc -l)" + debug "[$INTERFACE] Dynamic VLAN interface removed, references left = $cnt" + if [ $cnt -eq 0 ]; then + debug "[$INTERFACE] No more references, removing $VID from switch" + swconfig dev ${switch_dev} vlan $VID set ports "" + fi +fi From 6d16e50bbe518c54801ac340daef00bf6c8e7782 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 12 Sep 2023 16:16:04 +0200 Subject: [PATCH 08/32] ipq807x: do not include kmod-qca-nss-drv-bridge-mgr This was causing issues with bridge-vlans that have mixed tagged and untagged ports. Signed-off-by: John Crispin --- feeds/ipq807x/ipq807x/Makefile | 2 +- feeds/ipq807x_v5.4/ipq50xx/Makefile | 2 +- feeds/ipq807x_v5.4/ipq60xx/Makefile | 2 +- feeds/ipq807x_v5.4/ipq807x/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/feeds/ipq807x/ipq807x/Makefile b/feeds/ipq807x/ipq807x/Makefile index d2cee7116..8ca9b2b39 100644 --- a/feeds/ipq807x/ipq807x/Makefile +++ b/feeds/ipq807x/ipq807x/Makefile @@ -18,7 +18,7 @@ DEFAULT_PACKAGES += kmod-qca-nss-dp kmod-qca-ssdk swconfig \ kmod-usb-phy-ipq807x kmod-usb-dwc3-of-simple \ kmod-ath11k-ahb kmod-qrtr_mproc wpad \ kmod-gpio-button-hotplug kmod-bootconfig \ - qca-thermald-10.4 qca-ssdk-shell kmod-qca-nss-drv-bridge-mgr \ + qca-thermald-10.4 qca-ssdk-shell \ uboot-envtools $(eval $(call BuildTarget)) diff --git a/feeds/ipq807x_v5.4/ipq50xx/Makefile b/feeds/ipq807x_v5.4/ipq50xx/Makefile index e6a2581a7..4d1b6f3c8 100644 --- a/feeds/ipq807x_v5.4/ipq50xx/Makefile +++ b/feeds/ipq807x_v5.4/ipq50xx/Makefile @@ -20,7 +20,7 @@ DEFAULT_PACKAGES += kmod-qca-nss-dp kmod-qca-ssdk swconfig \ kmod-usb-phy-ipq5018 kmod-usb-dwc3-qcom-internal \ kmod-ath11k-ahb ath11k-firmware-ipq5018 \ kmod-gpio-button-hotplug iwinfo \ - qca-ssdk-shell kmod-qca-nss-drv-bridge-mgr \ + qca-ssdk-shell \ uboot-envtools $(eval $(call BuildTarget)) diff --git a/feeds/ipq807x_v5.4/ipq60xx/Makefile b/feeds/ipq807x_v5.4/ipq60xx/Makefile index f612c6e07..1061765d8 100644 --- a/feeds/ipq807x_v5.4/ipq60xx/Makefile +++ b/feeds/ipq807x_v5.4/ipq60xx/Makefile @@ -20,7 +20,7 @@ DEFAULT_PACKAGES += kmod-qca-nss-dp kmod-qca-ssdk swconfig \ kmod-usb-phy-ipq807x kmod-usb-dwc3-qcom-internal \ kmod-ath11k-ahb ath11k-firmware-ipq60xx \ kmod-gpio-button-hotplug iwinfo \ - qca-ssdk-shell kmod-qca-nss-drv-bridge-mgr \ + qca-ssdk-shell \ uboot-envtools $(eval $(call BuildTarget)) diff --git a/feeds/ipq807x_v5.4/ipq807x/Makefile b/feeds/ipq807x_v5.4/ipq807x/Makefile index e91744cc4..7b8f8df0d 100644 --- a/feeds/ipq807x_v5.4/ipq807x/Makefile +++ b/feeds/ipq807x_v5.4/ipq807x/Makefile @@ -20,7 +20,7 @@ DEFAULT_PACKAGES += kmod-qca-nss-dp kmod-qca-ssdk swconfig \ kmod-usb-phy-ipq807x kmod-usb-dwc3-qcom-internal \ kmod-ath11k-ahb ath11k-firmware-ipq807x \ kmod-gpio-button-hotplug iwinfo \ - qca-ssdk-shell kmod-qca-nss-drv-bridge-mgr \ + qca-ssdk-shell \ uboot-envtools $(eval $(call BuildTarget)) From b3a0ebe53468e169fd6a95cf5fcf2901cd4e4424 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 12 Sep 2023 16:16:43 +0200 Subject: [PATCH 09/32] ipq807x: disable SWITCHDEV support It is not used by the firmware. Signed-off-by: John Crispin --- feeds/ipq807x/ipq807x/ipq60xx/config-default | 2 +- feeds/ipq807x/ipq807x/ipq807x/config-default | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ipq807x/ipq807x/ipq60xx/config-default b/feeds/ipq807x/ipq807x/ipq60xx/config-default index 3d7c59698..a0ecdbdb8 100644 --- a/feeds/ipq807x/ipq807x/ipq60xx/config-default +++ b/feeds/ipq807x/ipq807x/ipq60xx/config-default @@ -82,7 +82,7 @@ CONFIG_MIGRATION=y CONFIG_MPILIB=y CONFIG_MSM_SECURE_BUFFER=y CONFIG_NEED_SG_DMA_LENGTH=y -CONFIG_NET_SWITCHDEV=y +# CONFIG_NET_SWITCHDEV is not set CONFIG_NUM_ALT_PARTITION=16 CONFIG_OF_IOMMU=y CONFIG_OID_REGISTRY=y diff --git a/feeds/ipq807x/ipq807x/ipq807x/config-default b/feeds/ipq807x/ipq807x/ipq807x/config-default index f1e8aadc9..5d5d8ba52 100644 --- a/feeds/ipq807x/ipq807x/ipq807x/config-default +++ b/feeds/ipq807x/ipq807x/ipq807x/config-default @@ -4,7 +4,7 @@ CONFIG_ARCH_IPQ807x=y CONFIG_IPQ_ADSS_807x=y CONFIG_IPQ_APSS_807x=y CONFIG_IPQ_GCC_807x=y -CONFIG_NET_SWITCHDEV=y +# CONFIG_NET_SWITCHDEV is not set CONFIG_NUM_ALT_PARTITION=16 CONFIG_PINCTRL_IPQ807x=y # CONFIG_IPC_LOGGING is not set From 550bb6fb7e5c833edf228ca8f14f5348ebda3009 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 12 Sep 2023 16:18:01 +0200 Subject: [PATCH 10/32] hostapd: update the snooping patch Fixes: WIFI-12929 Signed-off-by: John Crispin --- .../hostapd/patches/740-snoop_iface.patch | 83 +++++++++++++++++-- .../hostapd/patches/740-snoop_iface.patch | 83 +++++++++++++++++-- 2 files changed, 154 insertions(+), 12 deletions(-) diff --git a/feeds/ipq807x_v5.4/hostapd/patches/740-snoop_iface.patch b/feeds/ipq807x_v5.4/hostapd/patches/740-snoop_iface.patch index 94816ee0e..667c73ffd 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/740-snoop_iface.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/740-snoop_iface.patch @@ -10,7 +10,7 @@ --- a/src/ap/x_snoop.c +++ b/src/ap/x_snoop.c -@@ -31,14 +31,16 @@ int x_snoop_init(struct hostapd_data *ha +@@ -31,28 +31,31 @@ int x_snoop_init(struct hostapd_data *ha return -1; } @@ -29,13 +29,20 @@ wpa_printf(MSG_DEBUG, "x_snoop: Failed to enable proxyarp on the bridge port"); return -1; -@@ -52,7 +54,8 @@ int x_snoop_init(struct hostapd_data *ha + } + + if (hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, +- 1)) { ++ conf->snoop_iface[0] ? conf->snoop_iface : NULL, 1)) { + wpa_printf(MSG_DEBUG, + "x_snoop: Failed to enable accepting gratuitous ARP on the bridge"); + return -1; } #ifdef CONFIG_IPV6 - if (hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, 1)) { + if (!conf->snoop_iface[0] && -+ hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, 1)) { ++ hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, NULL, 1)) { wpa_printf(MSG_DEBUG, "x_snoop: Failed to enable multicast snooping on the bridge"); return -1; @@ -44,15 +51,27 @@ struct hostapd_bss_config *conf = hapd->conf; struct l2_packet_data *l2; + const char *ifname = conf->bridge; - -- l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1); ++ + if (conf->snoop_iface[0]) + ifname = conf->snoop_iface; -+ + +- l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1); + l2 = l2_packet_init(ifname, NULL, ETH_P_ALL, handler, hapd, 1); if (l2 == NULL) { wpa_printf(MSG_DEBUG, "x_snoop: Failed to initialize L2 packet processing %s", +@@ -125,7 +132,10 @@ void x_snoop_mcast_to_ucast_convert_send + + void x_snoop_deinit(struct hostapd_data *hapd) + { +- hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, 0); ++ struct hostapd_bss_config *conf = hapd->conf; ++ ++ hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, ++ conf->snoop_iface[0] ? conf->snoop_iface : NULL, 0); + hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 0); + hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, 0); + } --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -2343,6 +2343,8 @@ static int hostapd_config_fill(struct ho @@ -64,3 +83,55 @@ } else if (os_strcmp(buf, "vlan_bridge") == 0) { os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge)); } else if (os_strcmp(buf, "wds_bridge") == 0) { +--- a/src/ap/ap_drv_ops.h ++++ b/src/ap/ap_drv_ops.h +@@ -340,12 +340,12 @@ static inline int hostapd_drv_br_port_se + + static inline int hostapd_drv_br_set_net_param(struct hostapd_data *hapd, + enum drv_br_net_param param, +- unsigned int val) ++ const char *ifname, unsigned int val) + { + if (hapd->driver == NULL || hapd->drv_priv == NULL || + hapd->driver->br_set_net_param == NULL) + return -1; +- return hapd->driver->br_set_net_param(hapd->drv_priv, param, val); ++ return hapd->driver->br_set_net_param(hapd->drv_priv, param, ifname, val); + } + + static inline int hostapd_drv_vendor_cmd(struct hostapd_data *hapd, +--- a/src/drivers/driver.h ++++ b/src/drivers/driver.h +@@ -3756,7 +3756,7 @@ struct wpa_driver_ops { + * Returns: 0 on success, negative (<0) on failure + */ + int (*br_set_net_param)(void *priv, enum drv_br_net_param param, +- unsigned int val); ++ const char *ifname, unsigned int val); + + /** + * get_wowlan - Get wake-on-wireless status +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -10825,7 +10825,7 @@ static const char * drv_br_net_param_str + + + static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, +- unsigned int val) ++ const char *ifname, unsigned int val) + { + struct i802_bss *bss = priv; + char path[128]; +@@ -10851,8 +10851,11 @@ static int wpa_driver_br_set_net_param(v + return -EINVAL; + } + ++ if (!ifname) ++ ifname = bss->brname; ++ + os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", +- ip_version, bss->brname, param_txt); ++ ip_version, ifname, param_txt); + + set_val: + if (linux_write_system_file(path, val)) diff --git a/feeds/wifi-ax/hostapd/patches/740-snoop_iface.patch b/feeds/wifi-ax/hostapd/patches/740-snoop_iface.patch index 94816ee0e..667c73ffd 100644 --- a/feeds/wifi-ax/hostapd/patches/740-snoop_iface.patch +++ b/feeds/wifi-ax/hostapd/patches/740-snoop_iface.patch @@ -10,7 +10,7 @@ --- a/src/ap/x_snoop.c +++ b/src/ap/x_snoop.c -@@ -31,14 +31,16 @@ int x_snoop_init(struct hostapd_data *ha +@@ -31,28 +31,31 @@ int x_snoop_init(struct hostapd_data *ha return -1; } @@ -29,13 +29,20 @@ wpa_printf(MSG_DEBUG, "x_snoop: Failed to enable proxyarp on the bridge port"); return -1; -@@ -52,7 +54,8 @@ int x_snoop_init(struct hostapd_data *ha + } + + if (hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, +- 1)) { ++ conf->snoop_iface[0] ? conf->snoop_iface : NULL, 1)) { + wpa_printf(MSG_DEBUG, + "x_snoop: Failed to enable accepting gratuitous ARP on the bridge"); + return -1; } #ifdef CONFIG_IPV6 - if (hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, 1)) { + if (!conf->snoop_iface[0] && -+ hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, 1)) { ++ hostapd_drv_br_set_net_param(hapd, DRV_BR_MULTICAST_SNOOPING, NULL, 1)) { wpa_printf(MSG_DEBUG, "x_snoop: Failed to enable multicast snooping on the bridge"); return -1; @@ -44,15 +51,27 @@ struct hostapd_bss_config *conf = hapd->conf; struct l2_packet_data *l2; + const char *ifname = conf->bridge; - -- l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1); ++ + if (conf->snoop_iface[0]) + ifname = conf->snoop_iface; -+ + +- l2 = l2_packet_init(conf->bridge, NULL, ETH_P_ALL, handler, hapd, 1); + l2 = l2_packet_init(ifname, NULL, ETH_P_ALL, handler, hapd, 1); if (l2 == NULL) { wpa_printf(MSG_DEBUG, "x_snoop: Failed to initialize L2 packet processing %s", +@@ -125,7 +132,10 @@ void x_snoop_mcast_to_ucast_convert_send + + void x_snoop_deinit(struct hostapd_data *hapd) + { +- hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, 0); ++ struct hostapd_bss_config *conf = hapd->conf; ++ ++ hostapd_drv_br_set_net_param(hapd, DRV_BR_NET_PARAM_GARP_ACCEPT, ++ conf->snoop_iface[0] ? conf->snoop_iface : NULL, 0); + hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_PROXYARP, 0); + hostapd_drv_br_port_set_attr(hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, 0); + } --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -2343,6 +2343,8 @@ static int hostapd_config_fill(struct ho @@ -64,3 +83,55 @@ } else if (os_strcmp(buf, "vlan_bridge") == 0) { os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge)); } else if (os_strcmp(buf, "wds_bridge") == 0) { +--- a/src/ap/ap_drv_ops.h ++++ b/src/ap/ap_drv_ops.h +@@ -340,12 +340,12 @@ static inline int hostapd_drv_br_port_se + + static inline int hostapd_drv_br_set_net_param(struct hostapd_data *hapd, + enum drv_br_net_param param, +- unsigned int val) ++ const char *ifname, unsigned int val) + { + if (hapd->driver == NULL || hapd->drv_priv == NULL || + hapd->driver->br_set_net_param == NULL) + return -1; +- return hapd->driver->br_set_net_param(hapd->drv_priv, param, val); ++ return hapd->driver->br_set_net_param(hapd->drv_priv, param, ifname, val); + } + + static inline int hostapd_drv_vendor_cmd(struct hostapd_data *hapd, +--- a/src/drivers/driver.h ++++ b/src/drivers/driver.h +@@ -3756,7 +3756,7 @@ struct wpa_driver_ops { + * Returns: 0 on success, negative (<0) on failure + */ + int (*br_set_net_param)(void *priv, enum drv_br_net_param param, +- unsigned int val); ++ const char *ifname, unsigned int val); + + /** + * get_wowlan - Get wake-on-wireless status +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -10825,7 +10825,7 @@ static const char * drv_br_net_param_str + + + static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, +- unsigned int val) ++ const char *ifname, unsigned int val) + { + struct i802_bss *bss = priv; + char path[128]; +@@ -10851,8 +10851,11 @@ static int wpa_driver_br_set_net_param(v + return -EINVAL; + } + ++ if (!ifname) ++ ifname = bss->brname; ++ + os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", +- ip_version, bss->brname, param_txt); ++ ip_version, ifname, param_txt); + + set_val: + if (linux_write_system_file(path, val)) From 90e78c606884abf11f77f4bab2da1b9ef819d9cc Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 12 Sep 2023 16:55:51 +0200 Subject: [PATCH 11/32] ucentral-schema: update to latest HEAD 58d7d72 fix beacon rates Fixes: WIFI-12935 Signed-off-by: John Crispin --- feeds/ucentral/ucentral-schema/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-schema/Makefile b/feeds/ucentral/ucentral-schema/Makefile index 00c81e58b..c9c8a5698 100644 --- a/feeds/ucentral/ucentral-schema/Makefile +++ b/feeds/ucentral/ucentral-schema/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git -PKG_MIRROR_HASH:=c0173d6d4a71bc5760fbf882805e55e4be3eadf69059723f16fde388965ad6af +PKG_MIRROR_HASH:=f0d822da4c291b5ba90c10b58106604b2a8e8a4cb9ce95a9034f1d7c0b6ac63e PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-05-29 -PKG_SOURCE_VERSION:=fd6a079907df46adb20071d430133d710fa9815a +PKG_SOURCE_VERSION:=58d7d72995ac11e8001503e5209dff6a7067c382 PKG_MAINTAINER:=John Crispin PKG_LICENSE:=BSD-3-Clause From f17e635d34046086233a57689c4fd203ebb549b2 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 13 Sep 2023 16:35:50 +0200 Subject: [PATCH 12/32] ucentral-schema: update to latest HEAD f113e61 fix uci for network devices that have a dot in the name Signed-off-by: John Crispin --- feeds/ucentral/ucentral-schema/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-schema/Makefile b/feeds/ucentral/ucentral-schema/Makefile index c9c8a5698..8d34c2509 100644 --- a/feeds/ucentral/ucentral-schema/Makefile +++ b/feeds/ucentral/ucentral-schema/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git -PKG_MIRROR_HASH:=f0d822da4c291b5ba90c10b58106604b2a8e8a4cb9ce95a9034f1d7c0b6ac63e +PKG_MIRROR_HASH:=9d1acf9dde96d42283892a8cbcb8ae5afd040ea0d351a381b9e13bf60ed8398c PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-05-29 -PKG_SOURCE_VERSION:=58d7d72995ac11e8001503e5209dff6a7067c382 +PKG_SOURCE_VERSION:=f113e6192784f968668aec8aa19fe356b304aa14 PKG_MAINTAINER:=John Crispin PKG_LICENSE:=BSD-3-Clause From e7ca6e8455d8514d155a0144beb9a1fd97a47028 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 13 Sep 2023 16:36:35 +0200 Subject: [PATCH 13/32] hostapd: fix ft-anonce behavior for broken clients Signed-off-by: John Crispin --- .../hostapd/patches/999-ft-anonce.patch | 48 +++++++++++++++++++ .../hostapd/patches/999-ft-anonce.patch | 48 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 feeds/ipq807x_v5.4/hostapd/patches/999-ft-anonce.patch create mode 100644 feeds/wifi-ax/hostapd/patches/999-ft-anonce.patch diff --git a/feeds/ipq807x_v5.4/hostapd/patches/999-ft-anonce.patch b/feeds/ipq807x_v5.4/hostapd/patches/999-ft-anonce.patch new file mode 100644 index 000000000..40956fa65 --- /dev/null +++ b/feeds/ipq807x_v5.4/hostapd/patches/999-ft-anonce.patch @@ -0,0 +1,48 @@ +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_ft.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_ft.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_ft.c +@@ -3067,6 +3067,7 @@ static int wpa_ft_process_auth_req(struc + size_t identity_len = 0, radius_cui_len = 0; + int use_sha384; + size_t pmk_r1_len, kdk_len; ++ struct os_reltime now; + + *resp_ies = NULL; + *resp_ies_len = 0; +@@ -3185,10 +3186,19 @@ pmk_r1_derived: + os_memcpy(sm->pmk_r1, pmk_r1, pmk_r1_len); + sm->pmk_r1_len = pmk_r1_len; + +- if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { +- wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " +- "ANonce"); +- return WLAN_STATUS_UNSPECIFIED_FAILURE; ++ if (os_get_reltime(&now) < 0 || ++ os_reltime_expired(&now, &sm->ANonce_time, 1)) { ++ if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { ++ wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " ++ "ANonce"); ++ return WLAN_STATUS_UNSPECIFIED_FAILURE; ++ } ++ sm->ANonce_time.sec = now.sec; ++ sm->ANonce_time.usec = now.usec; ++ wpa_printf(MSG_INFO, "FT: ANonce was randomized"); ++ } else { ++ wpa_printf(MSG_INFO, "FT: ANonce has not expired"); ++ + } + + wpa_hexdump(MSG_DEBUG, "FT: Received SNonce", +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_i.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_i.h ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_i.h +@@ -54,6 +54,7 @@ struct wpa_state_machine { + bool MICVerified; + bool GUpdateStationKeys; + u8 ANonce[WPA_NONCE_LEN]; ++ struct os_reltime ANonce_time; + u8 SNonce[WPA_NONCE_LEN]; + u8 alt_SNonce[WPA_NONCE_LEN]; + u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN]; diff --git a/feeds/wifi-ax/hostapd/patches/999-ft-anonce.patch b/feeds/wifi-ax/hostapd/patches/999-ft-anonce.patch new file mode 100644 index 000000000..40956fa65 --- /dev/null +++ b/feeds/wifi-ax/hostapd/patches/999-ft-anonce.patch @@ -0,0 +1,48 @@ +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_ft.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_ft.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_ft.c +@@ -3067,6 +3067,7 @@ static int wpa_ft_process_auth_req(struc + size_t identity_len = 0, radius_cui_len = 0; + int use_sha384; + size_t pmk_r1_len, kdk_len; ++ struct os_reltime now; + + *resp_ies = NULL; + *resp_ies_len = 0; +@@ -3185,10 +3186,19 @@ pmk_r1_derived: + os_memcpy(sm->pmk_r1, pmk_r1, pmk_r1_len); + sm->pmk_r1_len = pmk_r1_len; + +- if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { +- wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " +- "ANonce"); +- return WLAN_STATUS_UNSPECIFIED_FAILURE; ++ if (os_get_reltime(&now) < 0 || ++ os_reltime_expired(&now, &sm->ANonce_time, 1)) { ++ if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) { ++ wpa_printf(MSG_DEBUG, "FT: Failed to get random data for " ++ "ANonce"); ++ return WLAN_STATUS_UNSPECIFIED_FAILURE; ++ } ++ sm->ANonce_time.sec = now.sec; ++ sm->ANonce_time.usec = now.usec; ++ wpa_printf(MSG_INFO, "FT: ANonce was randomized"); ++ } else { ++ wpa_printf(MSG_INFO, "FT: ANonce has not expired"); ++ + } + + wpa_hexdump(MSG_DEBUG, "FT: Received SNonce", +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_i.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_i.h ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_i.h +@@ -54,6 +54,7 @@ struct wpa_state_machine { + bool MICVerified; + bool GUpdateStationKeys; + u8 ANonce[WPA_NONCE_LEN]; ++ struct os_reltime ANonce_time; + u8 SNonce[WPA_NONCE_LEN]; + u8 alt_SNonce[WPA_NONCE_LEN]; + u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN]; From 0a13684bb6fd117908b8d375a930f003bed94b4d Mon Sep 17 00:00:00 2001 From: John Crispin Date: Fri, 15 Sep 2023 16:55:37 +0200 Subject: [PATCH 14/32] ipq807x: fix certificates mounting in dual-boot scenario on yuncore,fap655 Signed-off-by: John Crispin --- feeds/tip/certificates/files/etc/init.d/certificates | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feeds/tip/certificates/files/etc/init.d/certificates b/feeds/tip/certificates/files/etc/init.d/certificates index 5c0a8690c..0de5c408a 100755 --- a/feeds/tip/certificates/files/etc/init.d/certificates +++ b/feeds/tip/certificates/files/etc/init.d/certificates @@ -75,7 +75,8 @@ boot() { PART_NAME=rootfs_1 fi ;; - yuncore,ax840) + yuncore,ax840|\ + yuncore,fap655) PART_NAME=rootfs_1 ;; *) From 38e6aee074169c74aff772642f16bac8e1892202 Mon Sep 17 00:00:00 2001 From: Ken Date: Thu, 14 Sep 2023 13:31:22 +0800 Subject: [PATCH 15/32] ipq807x: BSP patch for WF-186H Fixes: WIFI-12922 Signed-off-by: Ken --- .../ipq807x/base-files/etc/board.d/02_network | 12 + .../etc/hotplug.d/firmware/10-ath11k-caldata | 18 + .../base-files/lib/upgrade/platform.sh | 2 + .../arm/boot/dts/qcom-ipq5018-cig-wf186h.dts | 23 + .../boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts | 965 ++++++++++++++++++ feeds/ipq807x/ipq807x/image/ipq50xx.mk | 9 + .../files/etc/board.d/04-regdm | 1 + feeds/wifi-ax/ath11k-wifi/Makefile | 2 + .../ath11k-wifi/board-cig-wf186h.bin.IPQ5018 | Bin 0 -> 131072 bytes .../ath11k-wifi/board-cig-wf186h.bin.QCN6122 | Bin 0 -> 131072 bytes profiles/cig_wf186h.yml | 26 + 11 files changed, 1058 insertions(+) create mode 100644 feeds/ipq807x/ipq807x/files/arch/arm/boot/dts/qcom-ipq5018-cig-wf186h.dts create mode 100644 feeds/ipq807x/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts create mode 100755 feeds/wifi-ax/ath11k-wifi/board-cig-wf186h.bin.IPQ5018 create mode 100755 feeds/wifi-ax/ath11k-wifi/board-cig-wf186h.bin.QCN6122 create mode 100644 profiles/cig_wf186h.yml diff --git a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network index b3e9120b1..7c341f149 100755 --- a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network +++ b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network @@ -66,6 +66,9 @@ qcom_setup_interfaces() cig,wf186w) ucidef_add_switch "switch0" "4:wan" "0:lan" "1:lan" "2:lan" "3:lan" "6@eth0" ;; + cig,wf186h) + ucidef_add_switch "switch0" "4:wan" "1:lan" "2:lan" "6@eth0" + ;; yuncore,fap650) ucidef_set_interface_lan "eth3 eth2 eth1 eth0" ucidef_set_interface_wan "eth4" @@ -180,6 +183,15 @@ qcom_setup_macs() # ip link set eth1 address $wan_mac # ucidef_set_label_macaddr $wan_mac ;; + cig,wf186h) + mtd=$(find_mtd_chardev "0:APPSBLENV") + [ -z "$mtd" ] && return; + mac=$(grep BaseMacAddress= $mtd | cut -dx -f2) + [ -z "$mac" ] && return; + wan_mac=$(macaddr_canonicalize $mac) + ucidef_set_network_device_mac eth0 $wan_mac + ip link set eth0 address $wan_mac + ;; cybertan,eww631-a1|\ cybertan,eww631-b1) mac=$(grep -i -m 1 BaseMacAddress= /dev/`cat /proc/mtd | grep APPSBLENV | cut -d: -f1` | cut -d= -f2) diff --git a/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata index 7cd81a6fa..8dc88c875 100755 --- a/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata +++ b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata @@ -85,6 +85,19 @@ ath11k_generate_macs_wf186w() { echo -ne \\x${mac3//:/\\x} >> /lib/firmware/ath11k-macs } +ath11k_generate_macs_wf186h() { + touch /lib/firmware/ath11k-macs + local dev=$(find_mtd_chardev "0:APPSBLENV") + mac=$(grep BaseMacAddress= $dev | cut -dx -f2) + eth=$(macaddr_canonicalize $mac) + mac1=$(macaddr_add $eth 2) + mac2=$(macaddr_add $eth 3) + mac3=$(macaddr_add $eth 4) + echo -ne \\x${mac1//:/\\x} >> /lib/firmware/ath11k-macs + echo -ne \\x${mac2//:/\\x} >> /lib/firmware/ath11k-macs + echo -ne \\x${mac3//:/\\x} >> /lib/firmware/ath11k-macs +} + caldata_die() { echo "caldata: " "$*" @@ -159,6 +172,7 @@ case "$FIRMWARE" in ath11k/IPQ5018/hw1.0/caldata.bin) case "$board" in cig,wf186w|\ + cig,wf186h|\ cybertan,eww622-a1|\ cybertan,eww631-a1|\ cybertan,eww631-b1|\ @@ -180,6 +194,7 @@ ath11k/IPQ5018/hw1.0/caldata.bin) ath11k/qcn6122/hw1.0/caldata_1.bin) case "$board" in cig,wf186w|\ + cig,wf186h|\ wallys,dr5018|\ hfcl,ion4xi_w|\ hfcl,ion4x_w|\ @@ -269,6 +284,9 @@ ath11k-macs) cig,wf186w) ath11k_generate_macs_wf186w ;; + cig,wf186h) + ath11k_generate_macs_wf186h + ;; esac ;; *) diff --git a/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh b/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh index 93fed0f77..cdd6593e1 100755 --- a/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh +++ b/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh @@ -111,6 +111,7 @@ platform_check_image() { board=$(board_name) case $board in cig,wf186w|\ + cig,wf186h|\ cig,wf188|\ cig,wf660a|\ cig,wf188n|\ @@ -267,6 +268,7 @@ platform_do_upgrade() { platform_do_upgrade_dualboot_datachk "$1" ;; cig,wf186w|\ + cig,wf186h|\ yuncore,ax840|\ yuncore,fap655) [ -f /proc/boot_info/rootfs/upgradepartition ] && { diff --git a/feeds/ipq807x/ipq807x/files/arch/arm/boot/dts/qcom-ipq5018-cig-wf186h.dts b/feeds/ipq807x/ipq807x/files/arch/arm/boot/dts/qcom-ipq5018-cig-wf186h.dts new file mode 100644 index 000000000..61b159fd1 --- /dev/null +++ b/feeds/ipq807x/ipq807x/files/arch/arm/boot/dts/qcom-ipq5018-cig-wf186h.dts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "../../../arm64/boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts" + +/ { + pmuv8: pmu { + compatible = "arm,cortex-a7-pmu"; + }; +}; diff --git a/feeds/ipq807x/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts b/feeds/ipq807x/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts new file mode 100644 index 000000000..5fb9e3469 --- /dev/null +++ b/feeds/ipq807x/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq5018-cig-wf186h.dts @@ -0,0 +1,965 @@ +/dts-v1/; +/* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "qcom-ipq5018.dtsi" + +/ { + #address-cells = <0x2>; + #size-cells = <0x2>; + model = "CIG wf186h"; + compatible = "cig,wf186h","qcom,ipq5018-mp03.3", "qcom,ipq5018"; + interrupt-parent = <&intc>; + + aliases { + sdhc1 = &sdhc_1; /* SDC1 eMMC slot */ + serial0 = &blsp1_uart1; + serial1 = &blsp1_uart2; + ethernet0 = "/soc/dp1"; + ethernet1 = "/soc/dp2"; + }; + + chosen { + bootargs = "console=ttyMSM0,115200,n8 rw init=/init"; + #ifdef __IPQ_MEM_PROFILE_256_MB__ + bootargs-append = " swiotlb=1"; + #else + bootargs-append = " swiotlb=1 coherent_pool=2M"; + #endif + stdout-path = "serial0"; + }; + + reserved-memory { + #ifdef __IPQ_MEM_PROFILE_256_MB__ + /* 256 MB Profile + * +=========+==============+========================+ + * | | | | + * | Region | Start Offset | Size | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | NSS | 0x40000000 | 8MB | + * | | | | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | | | | + * | | | | + * | Linux | 0x40800000 | Depends on total memory | + * | | | | + * | | | | + * | | | | + * + | | | + * +--------+--------------+-------------------------+ + * | | | | + * | uboot | 0x4A600000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | SBL | 0x4AA00000 | 1MB | + * +--------+--------------+-------------------------+ + * | smem | 0x4AB00000 | 1MB | + * +--------+--------------+-------------------------+ + * | | | | + * | TZ | 0x4AC00000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | | | | + * | Q6 | 0x4B000000 | 16MB | + * | code/ | | | + * | data | | | + * +--------+--------------+-------------------------+ + * | | | | + * |IPQ5018 | 0x4C000000 | 13MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4CD00000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4CE00000 | 1MB | + * +--------+--------------+-------------------------+ + * |QCN6122 | 0x4CF00000 | 15MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4DE00000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4DF00000 | 1MB | + * +--------+--------------+-------------------------+ + * | | | | + * |QCN9000 | 0x4E000000 | 17MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | MHI1 | 0x4F100000 | 16MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | + * | Rest of the memory for Linux | + * | | + * +=================================================+ + */ + + q6_mem_regions: q6_mem_regions@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 0x3000000>; + }; + + q6_code_data: q6_code_data@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 01000000>; + }; + + q6_ipq5018_data: q6_ipq5018_data@4c000000 { + no-map; + reg = <0x0 0x4c000000 0x0 0xD00000>; + }; + + m3_dump: m3_dump@4CD00000 { + no-map; + reg = <0x0 0x4CD00000 0x0 0x100000>; + }; + + q6_etr_region:q6_etr_dump@4CE00000 { + no-map; + reg = <0x0 0x4CE00000 0x0 0x100000>; + }; + + q6_qcn6122_data1: q6_qcn6122_data1@4CF00000 { + no-map; + reg = <0x0 0x4CF00000 0x0 0xF00000>; + }; + + m3_dump_qcn6122_1: m3_dump_qcn6122_1@4DE00000 { + no-map; + reg = <0x0 0x4DE00000 0x0 0x100000>; + }; + + q6_qcn6122_etr_1: q6_qcn6122_etr_1@4DF00000 { + no-map; + reg = <0x0 0x4DF00000 0x0 0x100000>; + }; + + q6_qcn9000_region: qcn9000_pcie0@4E000000 { + no-map; + reg = <0x0 0x4E000000 0x0 0x01100000>; + }; + + mhi_region1: dma_pool1@4F100000 { + compatible = "shared-dma-pool"; + no-map; + reg = <0x0 0x4F100000 0x0 0x01000000>; + }; + #elif __IPQ_MEM_PROFILE_512_MB__ + /* 512 MB Profile + * +=========+==============+========================+ + * | | | | + * | Region | Start Offset | Size | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | NSS | 0x40000000 | 16MB | + * | | | | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | | | | + * | | | | + * | Linux | 0x41000000 | Depends on total memory | + * | | | | + * | | | | + * | | | | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | uboot | 0x4A600000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | SBL | 0x4AA00000 | 1MB | + * +--------+--------------+-------------------------+ + * | smem | 0x4AB00000 | 1MB | + * +--------+--------------+-------------------------+ + * | | | | + * | TZ | 0x4AC00000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | Q6 | 0x4B000000 | 16MB | + * | code/ | | | + * | data | | | + * +--------+--------------+-------------------------+ + * | | | | + * |IPQ5018 | 0x4C000000 | 14MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4CE00000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4CF00000 | 1MB | + * +--------+--------------+-------------------------+ + * | caldb | 0x4D000000 | 2MB | + * +--------+--------------+-------------------------+ + * |QCN6122 | 0x4D200000 | 16MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4E200000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4E300000 | 1MB | + * +--------+--------------+-------------------------+ + * | caldb | 0x4E400000 | 5MB | + * +--------+--------------+-------------------------+ + * | | | | + * |QCN9000 | 0x4E900000 | 30MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | MHI1 | 0x50700000 | 16MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | + * | Rest of the memory for Linux | + * | | + * +=================================================+ + */ + + q6_mem_regions: q6_mem_regions@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 0x3900000>; + }; + + q6_code_data: q6_code_data@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 01000000>; + }; + + q6_ipq5018_data: q6_ipq5018_data@4C000000 { + no-map; + reg = <0x0 0x4C000000 0x0 0xE00000>; + }; + + m3_dump: m3_dump@4CE00000 { + no-map; + reg = <0x0 0x4CE00000 0x0 0x100000>; + }; + + q6_etr_region: q6_etr_dump@4CF00000 { + no-map; + reg = <0x0 0x4CF00000 0x0 0x100000>; + }; + + q6_caldb_region: q6_caldb_region@4D000000 { + no-map; + reg = <0x0 0x4D000000 0x0 0x200000>; + }; + + q6_qcn6122_data1: q6_qcn6122_data1@4D200000 { + no-map; + reg = <0x0 0x4D200000 0x0 0x1000000>; + }; + + m3_dump_qcn6122_1: m3_dump_qcn6122_1@4E200000 { + no-map; + reg = <0x0 0x4E200000 0x0 0x100000>; + }; + + q6_qcn6122_etr_1: q6_qcn6122_etr_1@4E300000 { + no-map; + reg = <0x0 0x4E300000 0x0 0x100000>; + }; + + q6_qcn6122_caldb_1: q6_qcn6122_caldb_1@4E400000 { + no-map; + reg = <0x0 0x4E400000 0x0 0x500000>; + }; + + q6_qcn9000_region: qcn9000_pcie0@4E900000 { + no-map; + reg = <0x0 0x4E900000 0x0 0x01E00000>; + }; + + mhi_region1: dma_pool1@50700000 { + compatible = "shared-dma-pool"; + no-map; + reg = <0x0 0x50700000 0x0 0x01000000>; + }; + #else + /* 1G Profile + * +=========+==============+========================+ + * | | | | + * | Region | Start Offset | Size | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | NSS | 0x40000000 | 16MB | + * | | | | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | | | | + * | | | | + * | Linux | 0x41000000 | Depends on total memory | + * | | | | + * | | | | + * | | | | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | uboot | 0x4A600000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | SBL | 0x4AA00000 | 1MB | + * +--------+--------------+-------------------------+ + * | smem | 0x4AB00000 | 1MB | + * +--------+--------------+-------------------------+ + * | | | | + * | TZ | 0x4AC00000 | 4MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | | | | + * | Q6 | 0x4B000000 | 16MB | + * | code/ | | | + * | data | | | + * +--------+--------------+-------------------------+ + * | | | | + * |IPQ5018 | 0x4C000000 | 14MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4CE00000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4CF00000 | 1MB | + * +--------+--------------+-------------------------+ + * | caldb | 0x4D000000 | 2MB | + * +--------+--------------+-------------------------+ + * |QCN6122 | 0x4D200000 | 16MB | + * | data | | | + * +--------+--------------+-------------------------+ + * | M3 Dump| 0x4E200000 | 1MB | + * +--------+--------------+-------------------------+ + * | QDSS | 0x4E300000 | 1MB | + * +--------+--------------+-------------------------+ + * | caldb | 0x4E400000 | 5MB | + * +--------+--------------+-------------------------+ + * | | | | + * |QCN9000 | 0x4E900000 | 45MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | | | + * | MHI1 | 0x51600000 | 24MB | + * | | | | + * +--------+--------------+-------------------------+ + * | | + * | Rest of the memory for Linux | + * | | + * +=================================================+ + */ + + q6_mem_regions: q6_mem_regions@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 0x3900000>; + }; + + q6_code_data: q6_code_data@4B000000 { + no-map; + reg = <0x0 0x4B000000 0x0 01000000>; + }; + + q6_ipq5018_data: q6_ipq5018_data@4C000000 { + no-map; + reg = <0x0 0x4C000000 0x0 0xE00000>; + }; + + m3_dump: m3_dump@4CE00000 { + no-map; + reg = <0x0 0x4CE00000 0x0 0x100000>; + }; + + q6_etr_region: q6_etr_dump@4CF00000 { + no-map; + reg = <0x0 0x4CF00000 0x0 0x100000>; + }; + + q6_caldb_region: q6_caldb_region@4D000000 { + no-map; + reg = <0x0 0x4D000000 0x0 0x200000>; + }; + + q6_qcn6122_data1: q6_qcn6122_data1@4D200000 { + no-map; + reg = <0x0 0x4D200000 0x0 0x1000000>; + }; + + m3_dump_qcn6122_1: m3_dump_qcn6122_1@4E200000 { + no-map; + reg = <0x0 0x4E200000 0x0 0x100000>; + }; + + q6_qcn6122_etr_1: q6_qcn6122_etr_1@4E300000 { + no-map; + reg = <0x0 0x4E300000 0x0 0x100000>; + }; + + q6_qcn6122_caldb_1: q6_qcn6122_caldb_1@4E400000 { + no-map; + reg = <0x0 0x4E400000 0x0 0x500000>; + }; + + q6_qcn9000_region: qcn9000_pcie0@4E900000 { + no-map; + reg = <0x0 0x4E900000 0x0 0x02D00000>; + }; + + mhi_region1: dma_pool1@51600000 { + compatible = "shared-dma-pool"; + no-map; + reg = <0x0 0x51600000 0x0 0x01800000>; + }; + #endif + }; + + soc { + serial@78af000 { + status = "ok"; + }; + + blsp1_uart2: serial@78b0000 { + pinctrl-0 = <&blsp1_uart_pins>; + pinctrl-names = "default"; + status = "ok"; + }; + + qpic_bam: dma@7984000{ + status = "ok"; + }; + + nand: qpic-nand@79b0000 { + pinctrl-0 = <&qspi_nand_pins>; + pinctrl-names = "default"; + status = "ok"; + }; + + spi_0: spi@78b5000 { /* BLSP1 QUP0 */ + pinctrl-0 = <&blsp0_spi_pins>; + pinctrl-names = "default"; + cs-select = <0>; + status = "ok"; + + m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + reg = <0>; + compatible = "n25q128a11"; + linux,modalias = "m25p80", "n25q128a11"; + spi-max-frequency = <50000000>; + use-default-sizes; + }; + }; + + mdio0: mdio@88000 { + status = "ok"; + ethernet-phy@0 { + reg = <7>; + }; + }; + + mdio1: mdio@90000 { + status = "ok"; + pinctrl-0 = <&mdio1_pins>; + pinctrl-names = "default"; + phy-reset-gpio = <&tlmm 35 0>; + cig_clk_div = <0xff>; + ethernet-phy@0 { + reg = <0x1d>; + }; + }; + + realtek@29{ + compatible = "realtek,rtl8367s"; + mii-bus = <&mdio1>; + realtek,extif0 = <0 0 10 1 1 1 1 1 2>; + switch = <&tlmm 35 0>; + phy-addr = <29>; + status = "ok"; + }; + ess-instance { + num_devices = <0x1>; + ess-switch@0x39c00000 { + compatible = "qcom,ess-switch-ipq50xx"; + device_id = <0>; + switch_mac_mode = <0xf>; /* mac mode for uniphy instance*/ + cmnblk_clk = "internal_96MHz"; /* cmnblk clk*/ + qcom,port_phyinfo { + port@0 { + port_id = <1>; + phy_address = <7>; + }; + port@1 { + port_id = <2>; + forced-speed = <1000>; + forced-duplex = <1>; + }; + }; + led_source@0 { + source = <0>; + mode = "normal"; + speed = "all"; + blink_en = "enable"; + active = "high"; + }; + }; + }; + + wifi0: wifi@c000000 { + status = "ok"; + }; + + dp1 { + device_type = "network"; + compatible = "qcom,nss-dp"; + clocks = <&gcc GCC_SNOC_GMAC1_AXI_CLK>; + clock-names = "nss-snoc-gmac-axi-clk"; + qcom,id = <2>; + reg = <0x39D00000 0x10000>; + interrupts = ; + qcom,mactype = <2>; + local-mac-address = [000000000000]; + phy-mode = "sgmii"; + }; + + dp2 { + device_type = "network"; + compatible = "qcom,nss-dp"; + clocks = <&gcc GCC_SNOC_GMAC0_AXI_CLK>; + clock-names = "nss-snoc-gmac-axi-clk"; + qcom,id = <1>; + reg = <0x39C00000 0x10000>; + interrupts = ; + qcom,mactype = <2>; + qcom,link-poll = <1>; + qcom,phy-mdio-addr = <7>; + mdio-bus = <&mdio0>; + local-mac-address = [000000000000]; + phy-mode = "sgmii"; + }; + + + qcom,test@0 { + status = "ok"; + }; + + lpass: lpass@0xA000000{ + status = "disabled"; + }; + + pcm: pcm@0xA3C0000{ + pinctrl-0 = <&audio_pins>; + pinctrl-names = "default"; + status = "disabled"; + }; + + gpio_keys { + compatible = "gpio-keys"; + pinctrl-0 = <&button_pins>; + pinctrl-names = "default"; + + button@1 { + label = "rst"; + linux,code = ; + gpios = <&tlmm 27 GPIO_ACTIVE_LOW>; + linux,input-type = <1>; + debounce-interval = <60>; + }; + }; + pcm_lb: pcm_lb@0 { + status = "disabled"; + }; + }; + + thermal-zones { + status = "ok"; + }; +}; + +&tlmm { + pinctrl-0 = <&phy_led_pins>; + pinctrl-names = "default"; + + blsp1_uart_pins: blsp1_uart_pins { + blsp1_uart_rx_tx { + pins = "gpio31", "gpio33"; + function = "blsp1_uart1"; + bias-disable; + }; + }; + + blsp0_spi_pins: blsp0_spi_pins { + mux { + pins = "gpio10", "gpio11", "gpio12", "gpio13"; + function = "blsp0_spi"; + drive-strength = <2>; + bias-disable; + }; + }; + + qspi_nand_pins: qspi_nand_pins { + qspi_clock { + pins = "gpio9"; + function = "qspi_clk"; + drive-strength = <8>; + bias-disable; + }; + qspi_cs { + pins = "gpio8"; + function = "qspi_cs"; + drive-strength = <8>; + bias-disable; + }; + qspi_data_0 { + pins = "gpio7"; + function = "qspi0"; + drive-strength = <8>; + bias-disable; + }; + qspi_data_1 { + pins = "gpio6"; + function = "qspi1"; + drive-strength = <8>; + bias-disable; + }; + qspi_data_2 { + pins = "gpio5"; + function = "qspi2"; + drive-strength = <8>; + bias-disable; + }; + qspi_data_3 { + pins = "gpio4"; + function = "qspi3"; + drive-strength = <8>; + bias-disable; + }; + }; + + mdio1_pins: mdio_pinmux { + mux_0 { + pins = "gpio36"; + function = "mdc"; + drive-strength = <8>; + bias-pull-up; + }; + + mux_1 { + pins = "gpio37"; + function = "mdio"; + drive-strength = <8>; + bias-pull-up; + }; + }; + + phy_led_pins: phy_led_pins { + gephy_led_pin { + pins = "gpio46"; + function = "led0"; + drive-strength = <8>; + bias-pull-down; + }; + }; + + i2c_pins: i2c_pins { + i2c_scl { + pins = "gpio25"; + function = "blsp2_i2c1"; + drive-strength = <8>; + bias-disable; + }; + + i2c_sda { + pins = "gpio26"; + function = "blsp2_i2c1"; + drive-strength = <8>; + bias-disable; + }; + }; + + button_pins: button_pins { + wps_button { + pins = "gpio38"; + function = "gpio"; + drive-strength = <8>; + bias-pull-up; + }; + rst_button { + pins = "gpio27"; + function = "gpio"; + drive-strength = <8>; + bias-pull-up; + }; + + }; + audio_pins: audio_pinmux { + mux_1 { + pins = "gpio24"; + function = "audio_rxbclk"; + drive-strength = <8>; + bias-pull-down; + }; + + mux_2 { + pins = "gpio25"; + function = "audio_rxfsync"; + drive-strength = <8>; + bias-pull-down; + }; + + mux_5 { + pins = "gpio28"; + function = "audio_txbclk"; + drive-strength = <8>; + bias-pull-down; + }; + + }; + + pwm_pins: pwm_pinmux { + mux_1 { + pins = "gpio0"; + function = "pwm10"; + drive-strength = <8>; + }; + mux_2 { + pins = "gpio1"; + function = "pwm20"; + drive-strength = <8>; + }; + mux_3 { + pins = "gpio45"; + function = "pwm3"; + drive-strength = <8>; + }; + }; + +}; + +&soc { + + pwm: pwm@0x1941010 { + pinctrl-0 = <&pwm_pins>; + pinctrl-names = "default"; + used-pwm-indices = <1>, <1>, <1>, <1>; + dft-pwm-status = <1>, <0>, <0>, <0>; + status = "ok"; + }; +}; + +&usb3 { + status = "disabled"; + device-power-gpio = <&tlmm 24 1>; +}; + +&eud { + status = "ok"; +}; + +&pcie_x1 { + status = "ok"; + perst-gpio = <&tlmm 18 1>; +}; + +&pcie_x2 { + status = "disabled"; + perst-gpio = <&tlmm 15 1>; +}; + +&dwc_0 { + /delete-property/ #phy-cells; + /delete-property/ phys; + /delete-property/ phy-names; +}; + +&hs_m31phy_0 { + status = "ok"; +}; + +&pcie_x1phy { + status = "disabled"; +}; + +&pcie_x2phy { + status = "disabled"; +}; + +&pcie_x1_rp { + status = "disabled"; + + mhi_0: qcom,mhi@0 { + reg = <0 0 0 0 0 >; + }; +}; + +&pcie_x2_rp { + status = "disabled"; + + mhi_1: qcom,mhi@1 { + reg = <0 0 0 0 0 >; + qrtr_instance_id = <0x21>; + #address-cells = <0x2>; + #size-cells = <0x2>; + memory-region = <&mhi_region1>; +#if !defined(__CNSS2__) + base-addr = <0x4E900000>; + m3-dump-addr = <0x4FD00000>; + etr-addr = <0x4FE00000>; + qcom,caldb-addr = <0x4FF00000>; + qcom,tgt-mem-mode = <0x1>; + mhi,max-channels = <30>; + mhi,timeout = <10000>; + qcom,board_id = <0xa4>; +#endif + }; +}; + +&wifi3 { + status = "ok"; +}; + +&qfprom { + status = "ok"; +}; + +&tsens { + status = "ok"; +}; + +&qcom_q6v5_wcss { + qcom,multipd_arch; + memory-region = <&q6_mem_regions>; + qcom,share_bootargs; + qcom,bootargs_smem = <507>; + boot-args = <0x2 0x4 0x2 0x12 0x0 0x0>; + + /* IPQ5018 */ + q6v5_wcss_userpd1 { + m3_firmware = "IPQ5018/m3_fw.mdt"; + interrupts-extended = <&wcss_smp2p_in 8 0>, + <&wcss_smp2p_in 9 0>, + <&wcss_smp2p_in 12 0>, + <&wcss_smp2p_in 11 0>; + interrupt-names ="fatal", + "ready", + "spawn_ack", + "stop-ack"; + qcom,smem-states = <&wcss_smp2p_out 8>, + <&wcss_smp2p_out 9>, + <&wcss_smp2p_out 10>; + qcom,smem-state-names = "shutdown", + "stop", + "spawn"; + qca,asid = <1>; + qca,auto-restart; + qca,int_radio; + #ifdef __IPQ_MEM_PROFILE_256_MB__ + memory-region = <&q6_ipq5018_data>, <&m3_dump>, + <&q6_etr_region>; + #else + memory-region = <&q6_ipq5018_data>, <&m3_dump>, + <&q6_etr_region>, <&q6_caldb_region>; + #endif + }; + + /* QCN6122 5G */ + q6v5_wcss_userpd2 { + m3_firmware = "qcn6122/m3_fw.mdt"; + interrupts-extended = <&wcss_smp2p_in 16 0>, + <&wcss_smp2p_in 17 0>, + <&wcss_smp2p_in 20 0>, + <&wcss_smp2p_in 19 0>; + interrupt-names ="fatal", + "ready", + "spawn_ack", + "stop-ack"; + qcom,smem-states = <&wcss_smp2p_out 16>, + <&wcss_smp2p_out 17>, + <&wcss_smp2p_out 18>; + qcom,smem-state-names = "shutdown", + "stop", + "spawn"; + qca,asid = <2>; + qca,auto-restart; + #ifdef __IPQ_MEM_PROFILE_256_MB__ + memory-region = <&q6_qcn6122_data1>, <&m3_dump_qcn6122_1>, + <&q6_qcn6122_etr_1>; + #else + memory-region = <&q6_qcn6122_data1>, <&m3_dump_qcn6122_1>, + <&q6_qcn6122_etr_1>, <&q6_qcn6122_caldb_1>; + #endif + }; +}; + +&i2c_0 { + pinctrl-0 = <&i2c_pins>; + pinctrl-names = "default"; + status = "disabled"; +}; + +&qgic_msi_0 { + status = "ok"; +}; + +&wifi0 { + /* IPQ5018 */ + qcom,multipd_arch; +#ifdef __IPQ_MEM_PROFILE_256_MB__ + qcom,tgt-mem-mode = <2>; +#else + qcom,tgt-mem-mode = <1>; +#endif + qcom,board_id = <0x24>; + qcom,bdf-addr = <0x0 0x4C000000 0x4C000000 0x0 0x0>; +#ifdef __CNSS2__ + qcom,caldb-addr = <0x0 0x4D000000 0 0 0>; +#else + qcom,caldb-addr = <0x4D000000>; + m3-dump-addr = <0x4CE00000>; +#endif + qcom,caldb-size = <0x200000>; + qcom,userpd-subsys-name = "q6v5_wcss_userpd1"; + status = "ok"; +}; + +&wifi1 { + /* QCN6122 5G */ + qcom,multipd_arch; +#ifdef __IPQ_MEM_PROFILE_256_MB__ + qcom,tgt-mem-mode = <2>; +#else + qcom,tgt-mem-mode = <1>; +#endif + qcom,board_id = <0x60>; + qcom,bdf-addr = <0x0 0x4D200000 0x4CF00000 0x0 0x0>; +#ifdef __CNSS2__ + qcom,caldb-addr = <0x0 0x4E400000 0 0 0>; +#else + qcom,caldb-addr = <0x4E400000>; + m3-dump-addr = <0x4E200000>; +#endif + qcom,caldb-size = <0x500000>; + qcom,userpd-subsys-name = "q6v5_wcss_userpd2"; + status = "ok"; +}; diff --git a/feeds/ipq807x/ipq807x/image/ipq50xx.mk b/feeds/ipq807x/ipq807x/image/ipq50xx.mk index db3eff672..fd9d721fb 100644 --- a/feeds/ipq807x/ipq807x/image/ipq50xx.mk +++ b/feeds/ipq807x/ipq807x/image/ipq50xx.mk @@ -28,6 +28,15 @@ define Device/cig_wf186w endef TARGET_DEVICES += cig_wf186w +define Device/cig_wf186h + DEVICE_TITLE := Cigtech WF-186h + DEVICE_DTS := qcom-ipq5018-cig-wf186h + SUPPORTED_DEVICES := cig,wf186h + DEVICE_PACKAGES := ath11k-wifi-cig-wf186h ath11k-firmware-ipq50xx-map-spruce + DEVICE_DTS_CONFIG := config@mp03.3 +endef +TARGET_DEVICES += cig_wf186h + define Device/cybertan_eww622_a1 DEVICE_TITLE := CyberTan EWW622-A1 DEVICE_DTS := qcom-ipq5018-eww622-a1 diff --git a/feeds/ucentral/ucentral-schema/files/etc/board.d/04-regdm b/feeds/ucentral/ucentral-schema/files/etc/board.d/04-regdm index 25beba72a..04f697ab4 100755 --- a/feeds/ucentral/ucentral-schema/files/etc/board.d/04-regdm +++ b/feeds/ucentral/ucentral-schema/files/etc/board.d/04-regdm @@ -8,6 +8,7 @@ board=$(board_name) case "$board" in cig,wf186w|\ +cig,wf186h|\ cig,wf194c4|\ cig,wf194c|\ cig,wf610d|\ diff --git a/feeds/wifi-ax/ath11k-wifi/Makefile b/feeds/wifi-ax/ath11k-wifi/Makefile index 532df868e..f1fcdfe2f 100644 --- a/feeds/wifi-ax/ath11k-wifi/Makefile +++ b/feeds/wifi-ax/ath11k-wifi/Makefile @@ -26,6 +26,7 @@ endef ALLWIFIBOARDS:= \ cig-wf188 \ cig-wf186w \ + cig-wf186h \ cig-wf660a \ cig-wf194c \ cig-wf194c4 \ @@ -348,6 +349,7 @@ endef $(eval $(call generate-ath11k-wifi-package,cig-wf188,Cigtech WF188)) $(eval $(call generate-ath11k-wifi-package,cig-wf186w,Cigtech WF186w)) +$(eval $(call generate-ath11k-wifi-package,cig-wf186h,Cigtech WF186h)) $(eval $(call generate-ath11k-wifi-package,cig-wf660a,Cigtech WF660a)) $(eval $(call generate-ath11k-wifi-package,cig-wf194c,Cigtech WF194c)) $(eval $(call generate-ath11k-wifi-package,cig-wf194c4,Cigtech WF194c4)) diff --git a/feeds/wifi-ax/ath11k-wifi/board-cig-wf186h.bin.IPQ5018 b/feeds/wifi-ax/ath11k-wifi/board-cig-wf186h.bin.IPQ5018 new file mode 100755 index 0000000000000000000000000000000000000000..9241704f308082b6a850bb9d5ce904edce7fefed GIT binary patch literal 131072 zcmeHQ33OcLb-wS-n~}yIYi6{J7R$2s#WqAX-fhsnS&M~MTNqmfr#QhRYykrX6a&Ff zzLDG|x(>64LgwS*7X;w(c($oo@9@FMT{qBA5%{k;uDK*G20tt3~ruZ|XiJ*7$#jAO@NDVtj88GP!(z2&*BZ;@tN4~g!Do;G? z6GYFv^UOO_rJqT>k6wvaHAbl0gZ?{t-Bua;HlVi}LOD__zv!A14Plwi54{z1;Lm<3BC$mBwGAsFSJ`fS=d{DZB7wBclRcn)Q-4tJm(ULAbQ;)$Pve*+I*9hk?4 zli=aqbSMUw$?Cv;;r6A&LvWgXvG|Cm3~omg>>*hl*dDw*unx=v=RYxp@z{dzC2Y#u zpVAI9o@`Q&*rcOF>?4j%IywZB$UkYpr!nHDn@(e8lT@WT*u*Fg%EQDVGWxf>AFaEu za)0jLM9kOu zPsi;TU*2(TOK7FOlVM;lc3_WV_Z5GR(i~Zd;u@=GmKYenBR?KZRc+-0LX>>p7^=7mIQVU+RTQx~ zNMDIE(ox1+Q{v!z}?abbq z2z&U^Z3oxwE8UYdkO&(++``^nxrFSx#NcV=%Q-GhI%>z0l0FB{5kON1T%HhcDf~ac|j6^O?>)UY)_t&OAl8%!`|#n*?yC9F(j7S-p6|QA|F$((6hfQ`n(vmn=F2lL996XeOheGUiWWR;IPI?SFBzdk}#yX%cO3@dE=!?Zz z&tm9{^bGKj#JN(=_-I4%D0p!8ow1Gf-Zzxwxl;NQd)HFzp9^u0Sd6`EY$bF^hYm@c zD_IBL^T`j!ZWm*z@@G97}+_!ud=P~5ZgH6hLECL;pJXf*~JT}X~LosY> z$xi41o63Yur6plgvWNc~@?!5>fOAAH`XUp38HqxNB+r%0Fh5kFj8e2CZV%PAJ%o}t zR|*f{u^3~sU<5p%4Ka-E2*!3OiLov719V_}D8slY0uMYkWsbo)BAGd+3OvfW6gIt- zZIW$z19ZTdFzIo@I(!299 zv?H6xCeD?iB+iv`Hb#Cqm%<+Mu-}WV2M;(`hLW&p85cNL%D8|{7NI}ICNVBDajr~D z;#}#@aV5wva~yb-IW7}AB(dIzJ@DAX93%6CYY#lvCTkBb!ycFijEki%4>(s&iwBfZ z$$fz`#2zqL$NM4)dysJjdyu&ved(R+ljVW*Q3mEY0~7bN^PCO}Qe}#8VEQb7ASE@p zU}0!cS~wC-&&bS*W#{DPEzVz3uyibCis#L-V`D@q6rmg{q)Mu$^;Ao()J@xHnD)@s zw2wyUAl*-&qEUK^o~0x7P5NhgkzT^*75JV-%m~ufBLDHv=P} zYZymYQ7ReOW#N7;lom<%YF$`VTvA$AUQt=K41WeVWgF~TGf{uC+OzK7&k?k31TC(H zPH%#b@lT=+RaKSJjIz>FNa@k4cpIb%3En*|SiWMev|)U!6-}3c($W%0S#eQONpVqe z(FBM+z!dRiWu*}0Ei5TQ{s|C!kXeo=dS|*#P9}YUHxagOXX-IZL#3sa{KR4f1%-u$ z<577&6vJN``~ChirJ>e4D-0|kOV$~;@aicZH=X{p8CW^PM|o5RybR3HoNyDOk20VP zCnGf?yp;t=&zCB!&CIwdGD#Js;Tk5XOF`w{LKOS z%k!SSx=hpb$q>UgE}h7x&!#vt0G(kQCTs)FJezczOqadEYm%_TyQZ|m@)gTr8{YTq z*~Zyl@``0VDvy7k{hH5)h8W2B(ljiUb7(C4FqVB7%RY={xH&PF`5W0jiqSlAtlu!n z2rt1*?z-9N_t_}({N>AQylyt?IMroN?2oyIPcgiN00AL4yS_nBBD;rKUUb8?+A14qZqKq#E}T^`z(g7&4LeJMv% z;UaLuCe~^=gohA5H`~g#Y^I{Usc3I1dJOvnGkElNGZ;!Sb)R4l^*Qp^wMo||+f>yO z)DqMZbQI_)&{3eHKu3X&0v!cs&nWQWJ^}8}J~I?f{9PczaEAbA!R_7-Y z@7#U+aG&7AeL~{z3DH*EC%{>7sc;dvVIS@j;1C`{_}p!`5BCW^+$Z>OpWwrNf)Doz zKHMkx^giLNG~&eEIB}g&%nT?$E(2;0Y7aUd+|f`|qvJuxgN_Fs4=w{bAI!)3z%q}H zSvbq$m*YMQ|HjSo9c5?2S#bL-oMqtx);VyN<^HvBp0#kEweTB$3;#aONoX?&s|Z zWsGk9Kp9X5l4oF&=|qF)7z6fR%kKBYZ$0crXq@t*Ho>Fd+!+sZYe_R# z*Z$P6oTv?)DjS&h6U=EMAo-JpraT)M2;=Yh;Y>IS?pPS#4*-`I#{Fp+e-9DH{VALY zXTj|YrSwFz!pkxGxRkzBH`&rKf2|JT=wW>)`RLp@!J}DnDuoY6&_DbQI_) z&{3eHKu3X&0v!dXe-uP;p8#jVS#ZZ9xKDsfi{L&Xg8PIB?i1ilI16rH1osJWfyf-a zPl(_?A%gpa2<{UixKD`SJ^{{zv*1$UB5=bI+$X>xJcRJMd!G=&eL@8H2@%{UL~x%F z!F@sm_X!cbPp}8uS@xc|3Mfu6z+IIIS?pPG(S-7+)&a+XRXQMdJ!kKUu+`cHzvv7gv96irQah{FhJR8M% zHj49X6z5qu6V8H5g^R!qM{%BoLwE?`bN4(O#d$W0^K2C7*(lDlQJiO^IL}7)Jj=s* z)*tWuseWZZ8Bhk40cAiLPzGj$fmz?sXa&l^X=Gp#!S=P12bnJjjWuR zm!c&o1ImChpbRJj%78MU3@8K2fHH7u8K@rP&#pi7=hZR(OsD+M6MtSD<4-T~XZsj` zrc;KdRR)v+Wk4BF29yD1Kp9X5&J6~_WTl=PEzwpe1ImChpbRJj%D{9Ph|u2YW|>j? zC=E&e@0(j^;rk-fX}|t;!;JbzGb;nifHI&ACe&8fJ~$}>lz6n@ei0>ejAJ6 zeEKbL3ya`Fx(c|5Meqew58TNjI7{*mQr)19OX)+1?`M(tO3|;6>iTTFlrBX45R1gG z;QH!&Sp-+pcHmYP!K%D@9;O^ zIfqEAeZ01okj2=#tqFZm24mnaQ?nV7K#59 zy-w*39Rv~m9;HE~?_!bo&v5@VY-17pH1pB0l|}Fox)!*dMex^AU$mizAc98>uD^{% z@C#gjYY&Uy409Km4TA&`{B6XW4ciGK_`8CKsKM!vml!v;6GY-)p$P1^lSS~WtY70+ z7QwGEZfal=yvny0xP?XVkC~s|0T#i(=JK1G2qO4bz|_>oBKY?l-`q|R!M_o_m71OU z{zq^dH9PJ7U%@@p?6mjKj9Z!sBKb`NxVxDkf-S~<%>)q~0;ZNG7QvYu-`GSD!G+9k zODl`uQc2%NEl&L_1ou#jQ-8JK4r+16|7rvLv^26v{`FjbOE*CTZ#FO=wDc21?4#DW zh5{{p1QA^08|2ZQ05q_^@#h z<8z2b@B>B#a1)E*PaAKO)!su8;rDT_uYHh3;=jPSV}M2QlidFu^(=y)miS)kaQOH# zu-VZ@5Q#q`xQ{v<{l6;d`>Dg>^LZ|>b1RFauRwdKvzj`~ZvKSGm5DcQ}1@}{@qu(<;ezx}! zMDo9GT!r$su?TMA@|!zZ1piU;H&Ul#-@g;wK%LHfa8%mcMV*elye08X)amrc+rVaL zFF~ZdW5!zGI)Vt^!|P3FCyQXqguQmvu?P;CzX0xL5gft#XLfZEL~uIex-NnU&X@QG z>T>j3W@3Kr8e)<7wI=xOYGD!FXkvVJb`wPG<$Uux#J90X{6@*&PhAdw7nvA;UCk^K zUoZ7-r7owx37EEavPk?E6XUtNokegP^V>bhB6zF$OW-;d!2>4jr@Mtk@HWBQsoSxS z9l-wXCW1)(uz3;Ex3UP{!}WJ}un6AE`gQjaMDPvV-tHcPNPBNKtB5YHW0CmVIDJnO zK?EP*@_M$i2)@I_`rgyeBKRY$U(XZVJ@$?l^}vYf%S^oyI2H&l5s}^ zi{OVie`hm`;7@b@?oNUTew^b68dwBh%j0XXmqpg+&v1NiCyT^C$@=y7u?T+JTuBRh z>j)zF?@Y`;y-}^y_-JR5_%}Iy?-qgxJ}S70dfoBGxS^FG68|`_ z*L{O5g6n-NfrnTG|B2hv*UBQ8n7_Uj7U3_%`=`D>7KzW~^}er*MR1O!@1Z_N-+W2m zKz&Ys6f*8_VUhHuKG2_m@3i~)BN zMDUOg`_caGERuf*>(@WTV%Nw0J)N8gT~LWUUjoDww?(yUb)7>^c-Oq+0eow z>A!^Y1vNCX2*wht&kPvw5t$KucV?6fvk>2)SwyB;Os0P$`DhdQ%o_6f({aknAU~B* zz|5oo#VCbxDTtY10cPWc#&0M@Z_*-ILd0B4QL~!TG3#Yurp+`87 zWfzs0Td9;TrZRJg%FRKlFk#x})l_9(MOFS^(K7!}X<6VJTJC>?R$w(e&-^)^?>|8A zu^y&s-$AOj?xB^|ztbw~Cv<`JGg@s8)7k}p0e2bP<+LXFUbx+~CiO3AZR-2ruAsHS zJ#g=b+Y1+@6!T?Th?OY~yZJQpca-M;FADqrKx8-DSb2f_(lffOGws9)GF$pOZ9pxb3&o+kS7FY$rXZW%qFK zi@{9TtL=X-?teP?Jp8r9>1}_#qye1rIX~mJ47dCa$B)^Qp3L}pJbYE=flS`lN8wyQ z*X8;-zw76=xPJae8?HY+;m3H2hnsFWE^nM3@!m9i`gF@NJ!P7jCWlU~}z{z~YOC_goxCX*6= za4YGr&AKc$iu7Ej?YH~d_S^cn{zMwPd^a!i>H4|7j^AV*+;FeoE~iWCwZm=yVoBc> zbM?PA%MSOZ&vVkS&UU?BF|>>9ysu_4|8{!z+x>EFmhEQ_ZNIDkKS_F9hjb4Q<>Ke^ z(_@##+%j#yU8d{jGTk&>&K0rmBE8+GuHPHZ{J7z4^S0mS+zn^_+0SXcdAY7DVn5;X z%{1}96>s|$G4{LZ-x3|{ytdy>&uy`FkZ`eqD`NlXNzZeTxaj}EWJLfH$P@K|OQsbm=s_&z2lJip-d^BsLTe}IAoD|-8I_$8FL0O>0oGM(jq5yB7bF5BHkcJIRsTBwLx3$ zNC%_Fb~nIozdxhK35ZC0v*HER`nkWX^m12U;m^ui-eG5`2HzGfTykEEgOT4y)>^h} ze(dtC^z}BRT1(>7YaI-GVg3uf*iXK^3pUy+aJ-+a+|`>LEcKy(TkQhk{5b`1dwmpK z?6$|Qe?fkiQ(vv{!Lx(?)cU0Ud>)tlyc^9X8^#powA55=z`>8j6kC3NQvj1=AdrH$AL$V*=>rs6L=*}w!aIcw z%(p&c0p6+Dw-crDi-HRi8`*MkyR23Wpn9_P{Z8Hj z(-UsEe$&9}?v#%n{6E)k@*?ln%ckJ^ji^V5(rkoZW$OTcTptO)RrKMF-mST|4r~hU z{(v`nx8}Ya*FWx;yl#8rx|v2nd@C>w7B%Tq3`8*P!fxUZusKR*h8tkV%Tysj)so(` z?-HDt_qzor_Gvc8q~knx{`fWv>loLch#wJ*$;){nqR*oEJ^}I2FM?UdekNkOy!bYQ z?D7(}W8;Nxb|*d*$EXkb$h0S6wSp7+PQ-S3S@HZf*6A)zh`!Y1+fAzzy!NcVq=KShDGO6nDTHpvKaR=`B<<0xUbxdTo)qO5=_mQ z@K57oRGh}jv?^sl8Bhk!5Cd8Cr!!RZ*->rGY5&NIp##l>ucy8Bhk40cAiLPzIC%Wk4BF29yD1Kp9X5lmTTx8Bhk40cAiL zPzIC%Wk4BF29yD1Kp9X5lmTTx8Bhk40cAiLPzIC%Wk4BF29yD1Kp9X5lmTTx88~SM z7Sp#+oOh1=!^V6XvD=Z7vhR0>@#e8($JmMXwbf+Ex3L{{9vT@j5?^yMY5PZ~G7gfPiG0(|rNy*EMcKc}j? ztBve#S#2ZRr|R79``>%dx##|OsaxHpmO++9d~E;SKbKe(xGu7My}WLa*NyVJNnXd~ z^^c`AUN&FLv7aGS=5WkA?lg!@1mbY$WAmZ2PL`aAQDB^5oNJtItTN6s&P41?<1C{U zugj6%VuX!y_iV*`S)9)hrP6d5G{`Wr5@ZHUiQ5HvIj795{t?m69~1q^(NMefYH)B{_k^1$fwUEWEU++_@efS!ITC0E_+sSNS?Vj?B>9)-sI5 zRjR_yE}qs~%Xo=6I7hIwr7iaU`(&KZ%f_@sXyS>(K#-bc=o{E$8;dEQbU3H%+$`Fn zETv>g3uJ=+t4( z#Xlh`|7)U>Nur{giSjoQ<(*3us=%iTznx0i&gz$m7C%q4@L{6jn}{M8LBARLVd(#_ z)cSw=r_hHF3->!d*xOwn&V!A`u<^UpHmb1asQ5N)e1#|q{Q_mFrNrN1^|#)cQ$2z{UrB z_}{5*RN>xb5qK;^UqsQDVdh~ad?zF&__U_)v+ySoADW=_JMz`XbCc zu7VE>;lr=f^kJ6cp%VIw{t7;z4Mph7@CESUZ1{kwZ@!tH52S}OpbRJjhhSjx!SUPL zwl#jd6l;rjOx`~Jxwb1CFDxDOQivwMH2(Rv&o*9OignaGChtJG36vZ1Qc&)J@mpc< z@=~mq-Z6RS_;s+ixpb|U;+8wu-d*F{+pa>nn6I4YpTFL_#&@)RqVbZ_VPCnw7~j=) zZR6IYc6?#{hPF?l+(@FF#%9NWw+D+`c{?7{$VtvXs~xk)?Opa$_7CiBMRykME81W5 z!=l%U-YY7Pc1Aa12YL9T=DXPM?8ANs`|s#Si3+j)gt7NrP)(E@JiIRF)_f0pSL`{< zc0hj|d(VF8FNZ$v0djp`XdTKD?;ERL#C-&8l-`0p*Cn_Q7;t>Z!}lAx*@x0hq*tR2 z>_aK`&g?^>tG{6J419o%^1ZNuy>AhCh+usUuRuGhU?b@}(?q@g82hk@eSm(F53HXq z59|ZmKwk(Co)6Wq5%SkIeZ2Zb*M}S7!zB(6k#o=n<{^!~^<7 z_~7!8_Zzcx5G0S4|VLr9*pao-0|S=&op?bhkhmNGY@|PA9`IMs=-5=^P(R8S-BTBxE+_k z#v0hbxDMB(XG470=lXCl))<}_%tKZBeZe*sV@xLbz~dV8BAs?Lcx|`=pO;*EkPqqd z03U=0*pU9jdN1=k&AG)sRDp+b^kvC7d|-X7abfO@pnn!mALn@y@6R1>fAW~(zNk%) z%LcTeY7cyXe(6WygV&e1Zsu9j*XvI`*oP9f!R^4cSK5&Vm&`-;UaXZj!UymWg?{1b z(C5BPbDf-gVq$OXzLuT##}eL6esf}9?EaQplhVF5@ks1TEuXh9_my+fZnHmrP}+ki zw>2s4E3pS#b|sa2YJ$^lODgB2?Xs`%>3(BkckG^)n{A9W@0fJbZu~&n7h7&hN}H}7 ze>w5h*k8aGzkdz~x7e3?HQ-+BTk!8o@Xy~ir`*l<7GJr)ly)Th{P@J4*uC)CU+(FN zuf-l}x!s=d={|vS_qE)TRPLFHM`K@Zxx@Z%zH*OG(??D_{w#^B>H5;+)ZdOn^O9`u zn-dSm9>6&8_xZOcz8>4%a+iIT&%Y;SY$S6vT{+JeANQ^HHTI^bB~PNgV2ZDL%_@dJfmguizSk z>+GVB;9A>)J&TRK!s}Bh`8x&Qi8MS*REuk5)lOU|FT`~g*QUsPT$|GTZs-&|@G3TN zjjP=5*eE#%HuB*^8sA4W;k$tP@8Dhl`ir5z@FH9zu}_E;!-q7#k2nQ38t}bJE%r=R zH^T?!0pBNZI~Jtz-O!Sk;RAT60S}e8zz6UU#Wg;H6)rE$?`4*-59o_p^hG85Vj(^! zjG`|hh4A6M)P2!}zNkYRswcq%_6lYATri6JknlYC@b9Vhd9Nb<2`+0Nfe$yp2exq< ze2Bn@cT?M7AL^e64`{<;=$CDRKJG)px$xnw)cWGXPl+0t2ejiz`l69}fPOW6sNg*l zc(hN44~6g{4IbHtrR>AEVTZ@{^_Ul%F&?l7kA%R(Z&J6T31hkrm|Bp=m}A&R*j#@xd>E6 z;DP6+tTB18k;WR+gubkYehtR7j7c8TXTgV=%nSD6ui*o1RAFwGUjQFkzysU(r!;tA zAD}-QA7o5oZq}hMsxYq0(T-xCn>@FEk%kXwgRGO#UySikwh=two-mAi^Sm_1w2a9g zyYm8LvI_kvV-oYiF2b06Bef6S8dn2-S>wQ?tZ_DcNaK1V;{jYYKJTs%-gw}(Hr?@n zc_BPtUc`Ced%~IU02__m7qB7Y0c%XWFVYwfGOsWmWUWVE`q%n&c_2NMfs>qpgZH&3 zIUSTkjoHkBX$3>Mc?ymDEftX*Kmy zj5g9{+Co>-HME^}(w%f4P10BC3EEG8LqDLG4m$TEcRO^NDMTN9AZK#Ct+7-psjaK^ z%iCipZ(x^2WMy#^!XIovZC!msV^hjD{3k9)Au6RtT19JUgf5^<=~Hwa-9~rA_kH;5 zoTunndXfGI{g_^%f1=lt&MCBtTd)~zZ>AE5kfhhiiC7CRTR7}UBwUccVE%kufp8q? zj<V=5uWz*N5w7DnU*V@$epu8QeHowKzc$O` zWaUxYJv{@b&GMMus-`Lf%78L(Xa?rdQ}{I6J2pE9x$lR3+qiLbw71vG_9KoD479dR zm$!NI+$ovtOA_+PI0@eeQXRdWovT;J3(aBFo8;%*MMuCV#$~(*4i%ZhJ(Jwxx!W_z zo+W#o7Seti80bxA@#v$pdWL6BVuoaHoj0?xb8~X=O`05LR%l*sF20|XBarP!R(4L_ zym|QkRE}e<=T@t4%78MU3@8K2fHH7=F_1?u?P8D30Dc(N%rguVzuyEg0*D9X_fikp zAR`N9vQRh+<+BmbPEkIDG9i=?p?nVFIfpO5HRmC350vD?)|{`-DE+(>^dR&Xp}+Vi zw+Q`3Df)}hUxfZ5^cSJOC`Eq}`iszCg#IG*7ioXZY9yKHF9Z|8LI@!O%m=0%`VYZG zu*_8bm^2$w0~7s@U?NxuAroT&0T}gS93YqomYHfiq^>Hdgo*KkU?NxuAroT>0T}gS zJRz6}mYHH)B^gZv=(;hhVXDe$Fc838M!;0fvk*c7OkxC{x<&wV8No!b0vVpm0nB9t z6Tw0V1u&NpfKe~zGJ=U<1u{IB1DMMQCW3_!3ScfH0Ha>aWdsw!3S@XLe>&&xq-*`B z584wPjML~kEs_BS(pZM)bdd~DkWmx)SWgg41PdXQkM#rr*f8?3o*fjNCcax9#~+U0y!jQ6>4U`=yAi=G?)wBpw#uaV!E+=gG4yefMC;eK0Z zmi)EiS1h;TZvbAv?+_gAW9g~O_;03`H8*>cBApbktiCG)nPH%6(UPX7Bva|6Bq=CR z24>9ww(q|0-4MqI_eXmTJ{j%fJH~+X9V0l-R*sL>7)b0}_!qISI*Pj%qE`F@;Wqr< z_A%PG;CBsbmo1CWc*v3J>8&BL?WHe^se%8YCycV9}MNpnI%5K8gnEgP} zTScp)ci_L}B~oV|8?zsUr8{P2gKNdj>5`>Oo%xzhJaaQ!Ehz)a!12n!sY?_0P3gps z*LJGk%78MEIR@nCA+Vp%!hRk>_n9-_`lY3jh5dXM_VZcT&m$<$X|Xo*LObjii=Iib z3+FPaEH^eZV3K|CHFGmhEgi26ER|2FKlpmQwnzQW90RG=70o|B7|7g+P)o{yGBDQ} zI6hV-_0nTtu8$}6PZ>C#8Sv(rz8_r%j^{CQGWvdWM}t~d29$wJFmN)iP1CW=kdzirYSxjOF9qLmJ#AJx%EVT3$IK$ z=bCqLFk`B6t02~X|#bY*TaWO_5nO_JBo&2<4oA7g^l2$ z>-KUQzE4yI9?EZaeHd_f2v~?I zxi8Y?fydMyw1a)P7(DR2@Wyo-Hh5md$Mm?5$MW=fs0Npd_7RoBha&h8!I%tlU({f3 zrZF$7zK8MnFgVx&ee|X1V_xO)+|K3R)+1d8CZC;nEVj4h&+ShnG$x;(_*(3tmfP(K zU)r}(Zcocy_Eo;LZ%uq9_NA8F?2r4>o|$+w_GRc^;Y)jR;^Ei>EuXh9_oY1r-3OuT zyC6+^<^1-(DZ01XAM@#cb7EiY{+3(qExxoTByDF>+Sex@ihZHw2Ky3Uxo=GDj@{F8 zvwf*A?Q0Vc#_npl-o{w;j>*R-_QdXOxh2WoW6=F#%T0b=ue`o11ImChpbRJj%78MU z3@8K2fHI&AC^Z0jV5 z7QwCb8{k0}!K+1ol-gbYI>n#0)V|iq@0R>FYHxG!0KH4u?ZX5SJ~vDGA!;9T^2eoo z54F4etq*Yfx>=;YPjY^LFN@%77k=1IiDvNd6w~pN@?zf*)l*I@YoX-cMHp_p=E84(coD7$%6| z?FQH1$0GQ7uD^GfMR1{c5t$tu2qO4<$TvGS5k&Cc2_B;kw?AHD+}TeM$^RLJF@6VG z1i!-mb*^O*{0qii9V~)d0(j7%tA|DKzc4=|>sbWfvIbhMeu)ces@1X z1ivMCEp@x~{ionQ>UP`ve+3Uyx7*(L8TWJ(MD$GqIMz)N!4~7uZh{ET1E!uX7Qr^> zcXkm(a3%BG)5{{bR?7ELk6Zsz!Nb(!*5536fO_2dzuW*nJ)JC~zmo0u#0Vm|)xdht zvyLD#K2{r7QC80=K?I){;PO2Lk@CI9I@sI9B6xu9_l~j%9x^bVdIwnq$Jn3sZ7hOE z(VpzyA%Y0rXuN^){Vakn;PSoeSOjlofBQxVB6uABQQr`Y;4MZQa3@P+4CDVw*6%x? zMe;u>`d!rL^4Z4i=^G@7a-qx=Ai;BBHmN_}p7ZZuxUkHrkKNd9WpU(-bp!FL*1 z|JJN!5q!I`6Z3P7MeyB518^6M;0KKN$m$;^i17Om*Vn&+Me@JScwjw?;77Rs2ijQ# zKPvenG~n{_G_X0)M-a*1FL;y&T>qby^6O~8VB7<6p%7Fb%rn^)wkVWu2qTfk_?)d(#;0_ve*MqmEy+btUj+b{O zzl#Rl{&)}A92_Bt*gIgX0B$3Q;4OT;860F0Y?&CZLv1XA^UQw*jCg$HzH;d%AOMPo;$n9?ernQ4ClE22pe2(?A2<~HkV;fimuQmS-xQ#{ddK2R( z*25xrqu@;xbH~R8z`>_8yhBwwD&V+ z6Mk%|jYaZ5$K{8+2qJg~+Z$fXBKQUq*Z1LdEP`)l|AsfP2;Rlz+Xq+#-_G_%dI=)< z3%FiU{}7Addl(ONun4}F^#{9I1V6y~u|a|eeu(qecd!V)n&;Ps5f-^V@8SHBK^Dn> zg#8;CWfAz(u&@X^mA`EPRhku?Mn{I=jO z8u8{AzLthunW-8(0MIG=7QeRg8tP z^>{wx)6Q@)JxSO_cJ#1F`KNGyK^>hef^mt}V-^eqh|DkW*vUps-B`|BNbzImtX}g#i~+fuAzlyKb4!qvdg(*U}9*SS5lLC1vLeKO-q8W(UPpI z=#=0av=mpvKQezs%Yr-TRO^0f4(z06>sC6=`Z={&uhQw(FKM~8nO5Zf3Btt)m(UqG zA4M3aGeVcriqOXpE~6DWTM#Zs*ou%t+2&7Z9VPsWtcs+~<9U%7XaaQv5Bzi61V``DzZ||Kagu^5V8HUMuk@ zrHqsA#GUd^++U{HEze~++@JGUj*ao^#Gj1EAI*6V@zuoTop`&H0Ze%;EBsucXMezr zWA&s*3V#((Z?SjSyss}n@ZwyT7iWDh&TaAH{6`yJJd%iGKE=~b&yL3%mq)(84Bvfv zc1)j5)A8r0_N2>6i_LL7FOIMS@fd}K6EDv7dU5v0i?h#89M8)8;)(Q-&n96eCdw!3 za(s4eO1n7T2p@cQq+OhDQz#w>w^IJwSQiL?Dk^x~*z(}_Day*S(S%CMcwqJM|-PM>;le>(HyrSq6~ z;tuCtI{VLYF6-Cjx-N^p%J$6#5`Q<|_RFFi_sYL3J~+Bg+$+y*aeR<;83UI^pYfIF zxWkW|9xuasj_w`kBd?9w#glHmuljuWMKrIN|6GE7h!)qyJS%h%x-o;jWQ_a9-REW?-JU^AZ5jF^GzsdubK#H6hFUu`fpa9#Bdr@ZAsa&UGW z#}M2$aLB`(5%K%ur61{g*f6sK6yQHKlf%JQ61FJ2r0V=czTe+4 znOWe&QzzCB(t?tfvz#Qx7G?SMu_FO?HJtqHk~7;~`)IvI1!c8fzTm6`Hcaeh*q`;D zzrbvNgNIQc@;!a8eit{JCVDfs{1m4;YBqyh123a;aK1?)9+D2m=(Na+*2MJ%N0zz% zvVIojR4g4C#mz6lUM|Y#Ek3Q=)rUQcawAQ+mE?o%1DDtJ`LPvgSd)zF23-tqOq%bO zPUtswCGrh&okLPHN*lD+$#gMl?DrC!_6G~ka}&bS-lDjH)j{qrD^l|2qQ4y4tVM)d8sPQ@C}*M99;g1?a{P&w9IJ&7ULBlcbwKJb=XuG;bQq;AGvbus ze1lGP3Uhgkb{;?VZpswwn-p&I3NQ}fFWkHY&)-uvIwcOq82`@rJ=Yn(%s<)>{+;p7 z<%6j2jMh#u;OW;n5W9BnkNlD)@gDR%`S9O)oiNRSEN+-nSkpowY{0>f#S~jXex)od zj#*jRcnzXFa;1D0<;}-m$mPw)Yc?5JZvzJZty~EEcKqcXzfjJ+g#B>Dph(2gEuj1` zQGR|HuMsk^y$Towc%4VQ6)Y^|jae@4gz(pR{G!JU7^rivuSP`>*Hq_PYm`iR*HH_9eqljHoK6%aR#l6hX7j0GHbbt_C?y5Yr516Oy~K6>!~d2y33@?O0>6uh`m z;Pauj80l9yJ|G_VN7Anqe|V#JZK>k}4+U?3z#F}5OMepgKOPrduf1{KOrs*c6_^2w zS~L{{VJy2CH}M15oFuc*OK|dKsgR^*Dev2N2~Mp0F~Ny_nuD?ExQC-3-)7-D#`P!i zw+qJN Date: Sat, 16 Sep 2023 17:19:08 +0200 Subject: [PATCH 16/32] certificates: fix mounting on cig,wf186w|cig,wf186h Signed-off-by: John Crispin --- feeds/tip/certificates/files/etc/init.d/certificates | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feeds/tip/certificates/files/etc/init.d/certificates b/feeds/tip/certificates/files/etc/init.d/certificates index 0de5c408a..2b1aa9807 100755 --- a/feeds/tip/certificates/files/etc/init.d/certificates +++ b/feeds/tip/certificates/files/etc/init.d/certificates @@ -75,6 +75,8 @@ boot() { PART_NAME=rootfs_1 fi ;; + cig,wf186w|\ + cig,wf186h|\ yuncore,ax840|\ yuncore,fap655) PART_NAME=rootfs_1 From 8e9f79964ae3b0864a1950c4e354e407336a1f1f Mon Sep 17 00:00:00 2001 From: Ken Date: Wed, 13 Sep 2023 13:35:58 +0800 Subject: [PATCH 17/32] ipq807x: Apply CE TX power to wf-186w Apply CE TX power for WF186w and WF186H include FCC as well. Fixes: WIFI-12920 Signed-off-by: Ken --- .../ath11k-wifi/board-cig-wf186w.bin.IPQ5018 | Bin 131072 -> 131072 bytes .../ath11k-wifi/board-cig-wf186w.bin.QCN6122 | Bin 131072 -> 131072 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/feeds/wifi-ax/ath11k-wifi/board-cig-wf186w.bin.IPQ5018 b/feeds/wifi-ax/ath11k-wifi/board-cig-wf186w.bin.IPQ5018 index d30fb8eebe31520b70533e0ba617db32f633ee60..9241704f308082b6a850bb9d5ce904edce7fefed 100755 GIT binary patch delta 246 zcmZo@;Am*z;9+E7VPOD)hNVp#d47d5wobN>QU;QVQHqm&!gBaE)z$6o?cwC)g;BAS zRl+Atwu@3>Zs42=R3|_APk4@iriPjtP#v5EDva5DB_fNFu@Gb;b1OuxfSQgrP#uDt zyfEpXn2wgFroBBn36%P=c|lATqj)Q4Kj#!quse~6GN8fYJjy^TVHjxX3VuCpZF?jP Q6kFQ7Ab$ITc*cYU0Kk4iq5uE@ delta 243 zcmZo@;Am*z;9+E7VPOD)2A3%td47d5mvPRV>=>oUw1RW8B9p>opRgQ0X=!^PP*MVs zqN0-*M#W8537>?n@=rK6m7A|bWHCLPYx+5vdUA5!oWLM0AH}q1a!jfi|2rA`5_4$RMon)6v&cRZ&sV z(}P<;iOA-F3N|)t4HY8;1Gsr02GJs$4R=VgZC=xIgNbvUsG3-{*kZBIP}du*a@iQ=7~`pOp_PHAK1jp!MJ%rk_^-41yNTRK_ZiQKfnZBAOajK zfC3x9?9B&+UjUVY)I03x;R2}#3SEE;sc=Gt7Qlr<*dX=@Fg4pe+HUiR@rWz{5T&|# delta 573 zcmZo@;Am*z;9+E7VPOD)hKXM`@?6Vft`RMqJik13vsZo>lZK3zjEp@BP%=fSmdCT&h(JvYWMI(K*Hcx|(?ilvk;vwS zb*yYwm~K=yP*z5=1IPrq5mf}FYqQ}FDYngPT5d3Lwu$zP8Kt%*kutQq0V=MEikeId8r*&4NW8 zCr zAW4R4^Ma@=j3ALoydPi!E)W5Z6+nRvVD{z%!Y_bILFyfL^l*XH1BEWYg;Y49LJQzR UA#4zP1els_9&NXI#CSv&06gxk6951J From 48cda63dc538982b5d51160780ec4ce7bb14af42 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 14 Sep 2023 08:06:02 +0200 Subject: [PATCH 18/32] hostapd: backport latest reload patches Signed-off-by: John Crispin --- ...ive-renaming-when-an-interface-is-up.patch | 67 ++ feeds/wifi-ax/hostapd/files/common.uc | 156 ++++- feeds/wifi-ax/hostapd/files/hostapd.sh | 3 +- feeds/wifi-ax/hostapd/files/hostapd.uc | 602 ++++++++++++++---- feeds/wifi-ax/hostapd/files/wdev.uc | 121 +++- feeds/wifi-ax/hostapd/files/wpa_supplicant.uc | 85 ++- .../hostapd/patches/601-ucode_support.patch | 214 ++++++- feeds/wifi-ax/hostapd/src/src/ap/ucode.c | 226 +++++-- feeds/wifi-ax/hostapd/src/src/utils/ucode.c | 15 +- .../hostapd/src/wpa_supplicant/ucode.c | 17 +- .../files/lib/netifd/wireless/mac80211.sh | 74 +-- 11 files changed, 1293 insertions(+), 287 deletions(-) create mode 100644 feeds/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch diff --git a/feeds/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch new file mode 100644 index 000000000..1a97d2759 --- /dev/null +++ b/feeds/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -0,0 +1,67 @@ +From: Andy Ren +Date: Mon, 7 Nov 2022 09:42:42 -0800 +Subject: [PATCH] net/core: Allow live renaming when an interface is up + +Allow a network interface to be renamed when the interface +is up. + +As described in the netconsole documentation [1], when netconsole is +used as a built-in, it will bring up the specified interface as soon as +possible. As a result, user space will not be able to rename the +interface since the kernel disallows renaming of interfaces that are +administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set +by the kernel. + +The original solution [2] to this problem was to add a new parameter to +the netconsole configuration parameters that allows renaming of +the interface used by netconsole while it is administratively up. +However, during the discussion that followed, it became apparent that we +have no reason to keep the current restriction and instead we should +allow user space to rename interfaces regardless of their administrative +state: + +1. The restriction was put in place over 20 years ago when renaming was +only possible via IOCTL and before rtnetlink started notifying user +space about such changes like it does today. + +2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version +5.2 and no regressions were reported. + +3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about +the administrative state of interface. + +Therefore, allow user space to rename running interfaces by removing the +restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in +possible triage by emitting a message to the kernel log that an +interface was renamed while UP. + +[1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst +[2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/ + +Signed-off-by: Andy Ren +Reviewed-by: Ido Schimmel +Reviewed-by: David Ahern +Signed-off-by: David S. Miller +--- + +--- a/net/core/dev.c ++++ b/net/core/dev.c +@@ -1152,8 +1152,6 @@ int dev_change_name(struct net_device *d + BUG_ON(!dev_net(dev)); + + net = dev_net(dev); +- if (dev->flags & IFF_UP) +- return -EBUSY; + + write_seqcount_begin(&devnet_rename_seq); + +@@ -1171,7 +1169,8 @@ int dev_change_name(struct net_device *d + } + + if (oldname[0] && !strchr(oldname, '%')) +- netdev_info(dev, "renamed from %s\n", oldname); ++ netdev_info(dev, "renamed from %s%s\n", oldname, ++ dev->flags & IFF_UP ? " (while UP)" : ""); + + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; diff --git a/feeds/wifi-ax/hostapd/files/common.uc b/feeds/wifi-ax/hostapd/files/common.uc index 9ece3b1af..ccffe3eb4 100644 --- a/feeds/wifi-ax/hostapd/files/common.uc +++ b/feeds/wifi-ax/hostapd/files/common.uc @@ -1,6 +1,6 @@ import * as nl80211 from "nl80211"; import * as rtnl from "rtnl"; -import { readfile } from "fs"; +import { readfile, glob, basename, readlink } from "fs"; const iftypes = { ap: nl80211.const.NL80211_IFTYPE_AP, @@ -94,6 +94,156 @@ function wdev_create(phy, name, data) return null; } +function phy_sysfs_file(phy, name) +{ + return trim(readfile(`/sys/class/ieee80211/${phy}/${name}`)); +} + +function macaddr_split(str) +{ + return map(split(str, ":"), (val) => hex(val)); +} + +function macaddr_join(addr) +{ + return join(":", map(addr, (val) => sprintf("%02x", val))); +} + +function wdev_macaddr(wdev) +{ + return trim(readfile(`/sys/class/net/${wdev}/address`)); +} + +const phy_proto = { + macaddr_init: function(used, options) { + this.macaddr_options = options ?? {}; + this.macaddr_list = {}; + + if (type(used) == "object") + for (let addr in used) + this.macaddr_list[addr] = used[addr]; + else + for (let addr in used) + this.macaddr_list[addr] = -1; + + this.for_each_wdev((wdev) => { + let macaddr = wdev_macaddr(wdev); + this.macaddr_list[macaddr] ??= -1; + }); + + return this.macaddr_list; + }, + + macaddr_generate: function(data) { + let phy = this.name; + let idx = int(data.id ?? 0); + let mbssid = int(data.mbssid ?? 0) > 0; + let num_global = int(data.num_global ?? 1); + let use_global = !mbssid && idx < num_global; + + let base_addr = phy_sysfs_file(phy, "macaddress"); + if (!base_addr) + return null; + + if (!idx && !mbssid) + return base_addr; + + let base_mask = phy_sysfs_file(phy, "address_mask"); + if (!base_mask) + return null; + + if (base_mask == "00:00:00:00:00:00" && idx >= num_global) { + let addrs = split(phy_sysfs_file(phy, "addresses"), "\n"); + + if (idx < length(addrs)) + return addrs[idx]; + + base_mask = "ff:ff:ff:ff:ff:ff"; + } + + let addr = macaddr_split(base_addr); + let mask = macaddr_split(base_mask); + let type; + + if (mbssid) + type = "b5"; + else if (use_global) + type = "add"; + else if (mask[0] > 0) + type = "b1"; + else if (mask[5] < 0xff) + type = "b5"; + else + type = "add"; + + switch (type) { + case "b1": + if (!(addr[0] & 2)) + idx--; + addr[0] |= 2; + addr[0] ^= idx << 2; + break; + case "b5": + if (mbssid) + addr[0] |= 2; + addr[5] ^= idx; + break; + default: + for (let i = 5; i > 0; i--) { + addr[i] += idx; + if (addr[i] < 256) + break; + addr[i] %= 256; + } + break; + } + + return macaddr_join(addr); + }, + + macaddr_next: function(val) { + let data = this.macaddr_options ?? {}; + let list = this.macaddr_list; + + for (let i = 0; i < 32; i++) { + data.id = i; + + let mac = this.macaddr_generate(data); + if (!mac) + return null; + + if (list[mac] != null) + continue; + + list[mac] = val != null ? val : -1; + return mac; + } + }, + + for_each_wdev: function(cb) { + let wdevs = glob(`/sys/class/ieee80211/${this.name}/device/net/*`); + wdevs = map(wdevs, (arg) => basename(arg)); + for (let wdev in wdevs) { + if (basename(readlink(`/sys/class/net/${wdev}/phy80211`)) != this.name) + continue; + + cb(wdev); + } + } +}; + +function phy_open(phy) +{ + let phyidx = readfile(`/sys/class/ieee80211/${phy}/index`); + if (!phyidx) + return null; + + return proto({ + name: phy, + idx: int(phyidx) + }, phy_proto); +} + const vlist_proto = { update: function(values, arg) { let data = this.data; @@ -150,7 +300,7 @@ function is_equal(val1, val2) { if (!is_equal(val1[key], val2[key])) return false; for (let key in val2) - if (!val1[key]) + if (val1[key] == null) return false; return true; } else { @@ -165,4 +315,4 @@ function vlist_new(cb) { }, vlist_proto); } -export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac }; +export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac, phy_open }; diff --git a/feeds/wifi-ax/hostapd/files/hostapd.sh b/feeds/wifi-ax/hostapd/files/hostapd.sh index 9855925e0..62c937ee5 100644 --- a/feeds/wifi-ax/hostapd/files/hostapd.sh +++ b/feeds/wifi-ax/hostapd/files/hostapd.sh @@ -725,8 +725,7 @@ hostapd_set_bss_options() { [ -n "$wpa_strict_rekey" ] && append bss_conf "wpa_strict_rekey=$wpa_strict_rekey" "$N" } - set_default nasid "${macaddr//\:}" - append bss_conf "nas_identifier=$nasid" "$N" + [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N" [ -n "$acct_server" ] && { append bss_conf "acct_server_addr=$acct_server" "$N" diff --git a/feeds/wifi-ax/hostapd/files/hostapd.uc b/feeds/wifi-ax/hostapd/files/hostapd.uc index f9f0c31ba..9b356dcc3 100644 --- a/feeds/wifi-ax/hostapd/files/hostapd.uc +++ b/feeds/wifi-ax/hostapd/files/hostapd.uc @@ -1,6 +1,6 @@ let libubus = require("ubus"); import { open, readfile } from "fs"; -import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac, phy_open } from "common"; let ubus = libubus.connect(); @@ -31,7 +31,7 @@ function iface_remove(cfg) wdev_remove(bss.ifname); } -function iface_gen_config(phy, config) +function iface_gen_config(phy, config, start_disabled) { let str = `data: ${join("\n", config.radio.data)} @@ -41,18 +41,92 @@ channel=${config.radio.channel} for (let i = 0; i < length(config.bss); i++) { let bss = config.bss[i]; let type = i > 0 ? "bss" : "interface"; + let nasid = bss.nasid ?? replace(bss.bssid, ":", ""); str += ` ${type}=${bss.ifname} +bssid=${bss.bssid} ${join("\n", bss.data)} +nas_identifier=${nasid} +`; + if (start_disabled) + str += ` +start_disabled=1 `; } return str; } -function iface_restart(phy, config, old_config) +function iface_freq_info(iface, config, params) { + let freq = params.frequency; + if (!freq) + return null; + + let sec_offset = params.sec_chan_offset; + if (sec_offset != -1 && sec_offset != 1) + sec_offset = 0; + + let width = 0; + for (let line in config.radio.data) { + if (!sec_offset && match(line, /^ht_capab=.*HT40/)) { + sec_offset = null; // auto-detect + continue; + } + + let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth)=(\d+)/); + if (!val) + continue; + + val = int(val[2]); + if (val > width) + width = val; + } + + if (freq < 4000) + width = 0; + + return hostapd.freq_info(freq, sec_offset, width); +} + +function iface_add(phy, config, phy_status) +{ + let config_inline = iface_gen_config(phy, config, !!phy_status); + + let bss = config.bss[0]; + let ret = hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`); + if (ret < 0) + return false; + + if (!phy_status) + return true; + + let iface = hostapd.interfaces[bss.ifname]; + if (!iface) + return false; + + let freq_info = iface_freq_info(iface, config, phy_status); + + return iface.start(freq_info) >= 0; +} + +function iface_config_macaddr_list(config) +{ + let macaddr_list = {}; + for (let i = 0; i < length(config.bss); i++) { + let bss = config.bss[i]; + if (!bss.default_macaddr) + macaddr_list[bss.bssid] = i; + } + + return macaddr_list; +} + +function iface_restart(phydev, config, old_config) +{ + let phy = phydev.name; + iface_remove(old_config); iface_remove(config); @@ -61,15 +135,29 @@ function iface_restart(phy, config, old_config) return; } + phydev.macaddr_init(iface_config_macaddr_list(config)); + for (let i = 0; i < length(config.bss); i++) { + let bss = config.bss[i]; + if (bss.default_macaddr) + bss.bssid = phydev.macaddr_next(); + } + let bss = config.bss[0]; let err = wdev_create(phy, bss.ifname, { mode: "ap" }); if (err) hostapd.printf(`Failed to create ${bss.ifname} on phy ${phy}: ${err}`); - let config_inline = iface_gen_config(phy, config); let ubus = hostapd.data.ubus; + let phy_status = ubus.call("wpa_supplicant", "phy_status", { phy: phy }); + if (phy_status && phy_status.state == "COMPLETED") { + if (iface_add(phy, config, phy_status)) + return; + + hostapd.printf(`Failed to bring up phy ${phy} ifname=${bss.ifname} with supplicant provided frequency`); + } + ubus.call("wpa_supplicant", "phy_set_state", { phy: phy, stop: true }); - if (hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`) < 0) + if (!iface_add(phy, config)) hostapd.printf(`hostapd.add_iface failed for phy ${phy} ifname=${bss.ifname}`); ubus.call("wpa_supplicant", "phy_set_state", { phy: phy, stop: false }); } @@ -111,8 +199,64 @@ function bss_reload_psk(bss, config, old_config) hostapd.printf(`Reload WPA PSK file for bss ${config.ifname}: ${ret}`); } -function iface_reload_config(phy, config, old_config) +function remove_file_fields(config) { + return filter(config, (line) => !hostapd.data.file_fields[split(line, "=")[0]]); +} + +function bss_remove_file_fields(config) +{ + let new_cfg = {}; + + for (let key in config) + new_cfg[key] = config[key]; + new_cfg.data = remove_file_fields(new_cfg.data); + new_cfg.hash = {}; + for (let key in config.hash) + new_cfg.hash[key] = config.hash[key]; + delete new_cfg.hash.wpa_psk_file; + + return new_cfg; +} + +function bss_config_hash(config) +{ + return hostapd.sha1(remove_file_fields(config) + ""); +} + +function bss_find_existing(config, prev_config, prev_hash) +{ + let hash = bss_config_hash(config.data); + + for (let i = 0; i < length(prev_config.bss); i++) { + if (!prev_hash[i] || hash != prev_hash[i]) + continue; + + prev_hash[i] = null; + return i; + } + + return -1; +} + +function get_config_bss(config, idx) +{ + if (!config.bss[idx]) { + hostapd.printf(`Invalid bss index ${idx}`); + return null; + } + + let ifname = config.bss[idx].ifname; + if (!ifname) + hostapd.printf(`Could not find bss ${config.bss[idx].ifname}`); + + return hostapd.bss[ifname]; +} + +function iface_reload_config(phydev, config, old_config) +{ + let phy = phydev.name; + if (!old_config || !is_equal(old_config.radio, config.radio)) return false; @@ -122,82 +266,231 @@ function iface_reload_config(phy, config, old_config) if (!old_config.bss || !old_config.bss[0]) return false; - if (config.bss[0].ifname != old_config.bss[0].ifname) - return false; - - let iface_name = config.bss[0].ifname; + let iface_name = old_config.bss[0].ifname; let iface = hostapd.interfaces[iface_name]; - if (!iface) + if (!iface) { + hostapd.printf(`Could not find previous interface ${iface_name}`); return false; + } let first_bss = hostapd.bss[iface_name]; - if (!first_bss) + if (!first_bss) { + hostapd.printf(`Could not find bss of previous interface ${iface_name}`); return false; + } + + let macaddr_list = iface_config_macaddr_list(config); + let bss_list = []; + let bss_list_cfg = []; + let prev_bss_hash = []; + + for (let bss in old_config.bss) { + let hash = bss_config_hash(bss.data); + push(prev_bss_hash, bss_config_hash(bss.data)); + } + + // Step 1: find (possibly renamed) interfaces with the same config + // and store them in the new order (with gaps) + for (let i = 0; i < length(config.bss); i++) { + let prev; + + // For fullmac devices, the first interface needs to be preserved, + // since it's treated as the master + if (!i && phy_is_fullmac(phy)) { + prev = 0; + prev_bss_hash[0] = null; + } else { + prev = bss_find_existing(config.bss[i], old_config, prev_bss_hash); + } + if (prev < 0) + continue; + + let cur_config = config.bss[i]; + let prev_config = old_config.bss[prev]; + + let prev_bss = get_config_bss(old_config, prev); + if (!prev_bss) + return false; + + // try to preserve MAC address of this BSS by reassigning another + // BSS if necessary + if (cur_config.default_macaddr && + !macaddr_list[prev_config.bssid]) { + macaddr_list[prev_config.bssid] = i; + cur_config.bssid = prev_config.bssid; + } + + bss_list[i] = prev_bss; + bss_list_cfg[i] = old_config.bss[prev]; + } + + if (config.mbssid && !bss_list_cfg[0]) { + hostapd.printf("First BSS changed with MBSSID enabled"); + return false; + } + + // Step 2: if none were found, rename and preserve the first one + if (length(bss_list) == 0) { + // can't change the bssid of the first bss + if (config.bss[0].bssid != old_config.bss[0].bssid) { + if (!config.bss[0].default_macaddr) { + hostapd.printf(`BSSID of first interface changed: ${lc(old_config.bss[0].bssid)} -> ${lc(config.bss[0].bssid)}`); + return false; + } + + config.bss[0].bssid = old_config.bss[0].bssid; + } + + let prev_bss = get_config_bss(old_config, 0); + if (!prev_bss) + return false; + + macaddr_list[config.bss[0].bssid] = 0; + bss_list[0] = prev_bss; + bss_list_cfg[0] = old_config.bss[0]; + prev_bss_hash[0] = null; + } + + // Step 3: delete all unused old interfaces + for (let i = 0; i < length(prev_bss_hash); i++) { + if (!prev_bss_hash[i]) + continue; + + let prev_bss = get_config_bss(old_config, i); + if (!prev_bss) + return false; + + let ifname = old_config.bss[i].ifname; + hostapd.printf(`Remove bss '${ifname}' on phy '${phy}'`); + prev_bss.delete(); + wdev_remove(ifname); + } + + // Step 4: rename preserved interfaces, use temporary name on duplicates + let rename_list = []; + for (let i = 0; i < length(bss_list); i++) { + if (!bss_list[i]) + continue; + + let old_ifname = bss_list_cfg[i].ifname; + let new_ifname = config.bss[i].ifname; + if (old_ifname == new_ifname) + continue; + + if (hostapd.bss[new_ifname]) { + new_ifname = "tmp_" + substr(hostapd.sha1(new_ifname), 0, 8); + push(rename_list, i); + } + + hostapd.printf(`Rename bss ${old_ifname} to ${new_ifname}`); + if (!bss_list[i].rename(new_ifname)) { + hostapd.printf(`Failed to rename bss ${old_ifname} to ${new_ifname}`); + return false; + } + + bss_list_cfg[i].ifname = new_ifname; + } + + // Step 5: rename interfaces with temporary names + for (let i in rename_list) { + let new_ifname = config.bss[i].ifname; + if (!bss_list[i].rename(new_ifname)) { + hostapd.printf(`Failed to rename bss to ${new_ifname}`); + return false; + } + bss_list_cfg[i].ifname = new_ifname; + } + + // Step 6: assign BSSID for newly created interfaces + let macaddr_data = { + num_global: config.num_global_macaddr ?? 1, + mbssid: config.mbssid ?? 0, + }; + macaddr_list = phydev.macaddr_init(macaddr_list, macaddr_data); + for (let i = 0; i < length(config.bss); i++) { + if (bss_list[i]) + continue; + let bsscfg = config.bss[i]; + + let mac_idx = macaddr_list[bsscfg.bssid]; + if (mac_idx < 0) + macaddr_list[bsscfg.bssid] = i; + if (mac_idx == i) + continue; + + // statically assigned bssid of the new interface is in conflict + // with the bssid of a reused interface. reassign the reused interface + if (!bsscfg.default_macaddr) { + // can't update bssid of the first BSS, need to restart + if (!mac_idx < 0) + return false; + + bsscfg = config.bss[mac_idx]; + } + + let addr = phydev.macaddr_next(i); + if (!addr) { + hostapd.printf(`Failed to generate mac address for phy ${phy}`); + return false; + } + bsscfg.bssid = addr; + } let config_inline = iface_gen_config(phy, config); - bss_reload_psk(first_bss, config.bss[0], old_config.bss[0]); - if (!is_equal(config.bss[0], old_config.bss[0])) { - if (phy_is_fullmac(phy)) - return false; + // Step 7: fill in the gaps with new interfaces + for (let i = 0; i < length(config.bss); i++) { + let ifname = config.bss[i].ifname; + let bss = bss_list[i]; - if (config.bss[0].bssid != old_config.bss[0].bssid) + if (bss) + continue; + + hostapd.printf(`Add bss ${ifname} on phy ${phy}`); + bss_list[i] = iface.add_bss(config_inline, i); + if (!bss_list[i]) { + hostapd.printf(`Failed to add new bss ${ifname} on phy ${phy}`); return false; + } + } + + // Step 8: update interface bss order + if (!iface.set_bss_order(bss_list)) { + hostapd.printf(`Failed to update BSS order on phy '${phy}'`); + return false; + } + + // Step 9: update config + for (let i = 0; i < length(config.bss); i++) { + if (!bss_list_cfg[i]) + continue; + + let ifname = config.bss[i].ifname; + let bss = bss_list[i]; + + if (is_equal(config.bss[i], bss_list_cfg[i])) + continue; + + if (is_equal(bss_remove_file_fields(config.bss[i]), + bss_remove_file_fields(bss_list_cfg[i]))) { + hostapd.printf(`Update config data files for bss ${ifname}`); + if (bss.set_config(config_inline, i, true) < 0) { + hostapd.printf(`Failed to update config data files for bss ${ifname}`); + return false; + } + bss.ctrl("RELOAD_WPA_PSK"); + continue; + } + + bss_reload_psk(bss, config.bss[i], bss_list_cfg[i]); + if (is_equal(config.bss[i], bss_list_cfg[i])) + continue; hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); - if (first_bss.set_config(config_inline, 0) < 0) { - hostapd.printf(`Failed to set config`); - return false; - } - } - - let new_cfg = array_to_obj(config.bss, "ifname", 1); - let old_cfg = array_to_obj(old_config.bss, "ifname", 1); - - for (let name in old_cfg) { - let bss = hostapd.bss[name]; - if (!bss) { - hostapd.printf(`bss '${name}' not found`); - return false; - } - - if (!new_cfg[name]) { - hostapd.printf(`Remove bss '${name}' on phy '${phy}'`); - bss.delete(); - wdev_remove(name); - continue; - } - - let new_cfg_data = new_cfg[name]; - delete new_cfg[name]; - - if (is_equal(old_cfg[name], new_cfg_data)) - continue; - - hostapd.printf(`Reload config for bss '${name}' on phy '${phy}'`); - let idx = find_array_idx(config.bss, "ifname", name); - if (idx < 0) { - hostapd.printf(`bss index not found`); - return false; - } - - if (bss.set_config(config_inline, idx) < 0) { - hostapd.printf(`Failed to set config`); - return false; - } - } - - for (let name in new_cfg) { - hostapd.printf(`Add bss '${name}' on phy '${phy}'`); - - let idx = find_array_idx(config.bss, "ifname", name); - if (idx < 0) { - hostapd.printf(`bss index not found`); - return false; - } - - if (iface.add_bss(config_inline, idx) < 0) { - hostapd.printf(`Failed to add bss`); + hostapd.printf(`old: ${bss_remove_file_fields(bss_list_cfg[i])}`); + hostapd.printf(`new: ${bss_remove_file_fields(config.bss[i])}`); + if (bss.set_config(config_inline, i) < 0) { + hostapd.printf(`Failed to set config for bss ${ifname}`); return false; } } @@ -205,6 +498,14 @@ function iface_reload_config(phy, config, old_config) return true; } +function iface_update_supplicant_macaddr(phy, config) +{ + let macaddr_list = []; + for (let i = 0; i < length(config.bss); i++) + push(macaddr_list, config.bss[i].bssid); + ubus.call("wpa_supplicant", "phy_set_macaddr_list", { phy: phy, macaddr: macaddr_list }); +} + function iface_set_config(phy, config) { let old_config = hostapd.data.config[phy]; @@ -214,14 +515,28 @@ function iface_set_config(phy, config) if (!config) return iface_remove(old_config); - let ret = iface_reload_config(phy, config, old_config); - if (ret) { - hostapd.printf(`Reloaded settings for phy ${phy}`); - return 0; + let phydev = phy_open(phy); + if (!phydev) { + hostapd.printf(`Failed to open phy ${phy}`); + return false; + } + + try { + let ret = iface_reload_config(phydev, config, old_config); + if (ret) { + iface_update_supplicant_macaddr(phy, config); + hostapd.printf(`Reloaded settings for phy ${phy}`); + return 0; + } + } catch (e) { + hostapd.printf(`Error reloading config: ${e}\n${e.stacktrace[0].context}`); } hostapd.printf(`Restart interface for phy ${phy}`); - return iface_restart(phy, config, old_config); + let ret = iface_restart(phydev, config, old_config); + iface_update_supplicant_macaddr(phy, config); + + return ret; } function config_add_bss(config, name) @@ -268,16 +583,28 @@ function iface_load_config(filename) continue; } + if (val[0] == "#num_global_macaddr" || + val[0] == "mbssid") + config[val[0]] = int(val[1]); + push(config.radio.data, line); } while ((line = trim(f.read("line"))) != null) { + if (line == "#default_macaddr") + bss.default_macaddr = true; + let val = split(line, "=", 2); if (!val[0]) continue; - if (val[0] == "bssid") - bss.bssid = val[1]; + if (val[0] == "bssid") { + bss.bssid = lc(val[1]); + continue; + } + + if (val[0] == "nas_identifier") + bss.nasid = val[1]; if (val[0] == "bss") { bss = config_add_bss(config, val[1]); @@ -294,28 +621,33 @@ function iface_load_config(filename) return config; } - +function ex_wrap(func) { + return (req) => { + try { + let ret = func(req); + return ret; + } catch(e) { + hostapd.printf(`Exception in ubus function: ${e}\n${e.stacktrace[0].context}`); + } + return libubus.STATUS_UNKNOWN_ERROR; + }; +} let main_obj = { reload: { args: { phy: "", }, - call: function(req) { - try { - let phy_list = req.args.phy ? [ req.args.phy ] : keys(hostapd.data.config); - for (let phy_name in phy_list) { - let phy = hostapd.data.config[phy_name]; - let config = iface_load_config(phy.orig_file); - iface_set_config(phy_name, config); - } - } catch(e) { - hostapd.printf(`Error reloading config: ${e}\n${e.stacktrace[0].context}`); - return libubus.STATUS_INVALID_ARGUMENT; + call: ex_wrap(function(req) { + let phy_list = req.args.phy ? [ req.args.phy ] : keys(hostapd.data.config); + for (let phy_name in phy_list) { + let phy = hostapd.data.config[phy_name]; + let config = iface_load_config(phy.orig_file); + iface_set_config(phy_name, config); } return 0; - } + }) }, apsta_state: { args: { @@ -326,7 +658,7 @@ let main_obj = { csa: true, csa_count: 0, }, - call: function(req) { + call: ex_wrap(function(req) { if (req.args.up == null || !req.args.phy) return libubus.STATUS_INVALID_ARGUMENT; @@ -344,34 +676,10 @@ let main_obj = { return 0; } - let freq = req.args.frequency; - if (!freq) + if (!req.args.frequency) return libubus.STATUS_INVALID_ARGUMENT; - let sec_offset = req.args.sec_chan_offset; - if (sec_offset != -1 && sec_offset != 1) - sec_offset = 0; - - let width = 0; - for (let line in config.radio.data) { - if (!sec_offset && match(line, /^ht_capab=.*HT40/)) { - sec_offset = null; // auto-detect - continue; - } - - let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth)=(\d+)/); - if (!val) - continue; - - val = int(val[2]); - if (val > width) - width = val; - } - - if (freq < 4000) - width = 0; - - let freq_info = hostapd.freq_info(freq, sec_offset, width); + let freq_info = iface_freq_info(iface, config, req.args); if (!freq_info) return libubus.STATUS_UNKNOWN_ERROR; @@ -387,7 +695,28 @@ let main_obj = { return libubus.STATUS_UNKNOWN_ERROR; return 0; - } + }) + }, + config_get_macaddr_list: { + args: { + phy: "" + }, + call: ex_wrap(function(req) { + let phy = req.args.phy; + if (!phy) + return libubus.STATUS_INVALID_ARGUMENT; + + let ret = { + macaddr: [], + }; + + let config = hostapd.data.config[phy]; + if (!config) + return ret; + + ret.macaddr = map(config.bss, (bss) => bss.bssid); + return ret; + }) }, config_set: { args: { @@ -395,7 +724,7 @@ let main_obj = { config: "", prev_config: "", }, - call: function(req) { + call: ex_wrap(function(req) { let phy = req.args.phy; let file = req.args.config; let prev_file = req.args.prev_config; @@ -403,34 +732,29 @@ let main_obj = { if (!phy) return libubus.STATUS_INVALID_ARGUMENT; - try { - if (prev_file && !hostapd.data.config[phy]) { - let config = iface_load_config(prev_file); - if (config) - config.radio.data = []; - hostapd.data.config[phy] = config; - } - - let config = iface_load_config(file); - - hostapd.printf(`Set new config for phy ${phy}: ${file}`); - iface_set_config(phy, config); - } catch(e) { - hostapd.printf(`Error loading config: ${e}\n${e.stacktrace[0].context}`); - return libubus.STATUS_INVALID_ARGUMENT; + if (prev_file && !hostapd.data.config[phy]) { + let config = iface_load_config(prev_file); + if (config) + config.radio.data = []; + hostapd.data.config[phy] = config; } + let config = iface_load_config(file); + + hostapd.printf(`Set new config for phy ${phy}: ${file}`); + iface_set_config(phy, config); + return { pid: hostapd.getpid() }; - } + }) }, config_add: { args: { iface: "", config: "", }, - call: function(req) { + call: ex_wrap(function(req) { if (!req.args.iface || !req.args.config) return libubus.STATUS_INVALID_ARGUMENT; @@ -440,19 +764,19 @@ let main_obj = { return { pid: hostapd.getpid() }; - } + }) }, config_remove: { args: { iface: "" }, - call: function(req) { + call: ex_wrap(function(req) { if (!req.args.iface) return libubus.STATUS_INVALID_ARGUMENT; hostapd.remove_iface(req.args.iface); return 0; - } + }) }, }; diff --git a/feeds/wifi-ax/hostapd/files/wdev.uc b/feeds/wifi-ax/hostapd/files/wdev.uc index 5b321423e..8a031b40b 100644 --- a/feeds/wifi-ax/hostapd/files/wdev.uc +++ b/feeds/wifi-ax/hostapd/files/wdev.uc @@ -1,11 +1,14 @@ #!/usr/bin/env ucode 'use strict'; -import { vlist_new, is_equal, wdev_create, wdev_remove } from "/usr/share/hostap/common.uc"; +import { vlist_new, is_equal, wdev_create, wdev_remove, phy_open } from "/usr/share/hostap/common.uc"; import { readfile, writefile, basename, readlink, glob } from "fs"; +let libubus = require("ubus"); let keep_devices = {}; let phy = shift(ARGV); -let new_config = shift(ARGV); +let command = shift(ARGV); +let phydev; + const mesh_params = [ "mesh_retry_timeout", "mesh_confirm_timeout", "mesh_holding_timeout", "mesh_max_peer_links", "mesh_max_retries", "mesh_ttl", "mesh_element_ttl", "mesh_hwmp_max_preq_retries", @@ -33,6 +36,11 @@ function iface_start(wdev) system([ "ip", "link", "set", "dev", ifname, "down" ]); wdev_remove(ifname); } + let wdev_config = {}; + for (let key in wdev) + wdev_config[key] = wdev[key]; + if (!wdev_config.macaddr && wdev.mode != "monitor") + wdev_config.macaddr = phydev.macaddr_next(); wdev_create(phy, ifname, wdev); system([ "ip", "link", "set", "dev", ifname, "up" ]); if (wdev.freq) @@ -47,7 +55,7 @@ function iface_start(wdev) system(cmd); } else if (wdev.mode == "mesh") { let cmd = [ "iw", "dev", ifname, "mesh", "join", wdev.ssid, "freq", wdev.freq, wdev.htmode ]; - for (let key in [ "beacon-interval", "mcast-rate" ]) + for (let key in [ "mcast-rate", "beacon-interval" ]) if (wdev[key]) push(cmd, key, wdev[key]); system(cmd); @@ -114,43 +122,86 @@ function add_existing(phy, config) } } +function usage() +{ + warn(`Usage: ${basename(sourcepath())} [] -let statefile = `/var/run/wdev-${phy}.json`; - -for (let dev in ARGV) - keep_devices[dev] = true; - -if (!phy || !new_config) { - warn(`Usage: ${basename(sourcepath())} [ [ - get phy MAC address for vif index +`); exit(1); } -if (!readfile(`/sys/class/ieee80211/${phy}/index`)) { +const commands = { + set_config: function(args) { + let statefile = `/var/run/wdev-${phy}.json`; + + let new_config = shift(args); + for (let dev in ARGV) + keep_devices[dev] = true; + + if (!new_config) + usage(); + + new_config = json(new_config); + if (!new_config) { + warn("Invalid configuration\n"); + exit(1); + } + + let old_config = readfile(statefile); + if (old_config) + old_config = json(old_config); + + let config = vlist_new(iface_cb); + if (type(old_config) == "object") + config.data = old_config; + + add_existing(phy, config.data); + add_ifname(config.data); + drop_inactive(config.data); + + let ubus = libubus.connect(); + let data = ubus.call("hostapd", "config_get_macaddr_list", { phy: phy }); + let macaddr_list = []; + if (type(data) == "object" && data.macaddr) + macaddr_list = data.macaddr; + ubus.disconnect(); + phydev.macaddr_init(macaddr_list); + + add_ifname(new_config); + config.update(new_config); + + drop_inactive(config.data); + delete_ifname(config.data); + writefile(statefile, sprintf("%J", config.data)); + }, + get_macaddr: function(args) { + let data = {}; + + for (let arg in args) { + arg = split(arg, "=", 2); + data[arg[0]] = arg[1]; + } + + let macaddr = phydev.macaddr_generate(data); + if (!macaddr) { + warn(`Could not get MAC address for phy ${phy}\n`); + exit(1); + } + + print(macaddr + "\n"); + }, +}; + +if (!phy || !command | !commands[command]) + usage(); + +phydev = phy_open(phy); +if (!phydev) { warn(`PHY ${phy} does not exist\n`); exit(1); } -new_config = json(new_config); -if (!new_config) { - warn("Invalid configuration\n"); - exit(1); -} - -let old_config = readfile(statefile); -if (old_config) - old_config = json(old_config); - -let config = vlist_new(iface_cb); -if (type(old_config) == "object") - config.data = old_config; - -add_existing(phy, config.data); -add_ifname(config.data); -drop_inactive(config.data); - -add_ifname(new_config); -config.update(new_config); - -drop_inactive(config.data); -delete_ifname(config.data); -writefile(statefile, sprintf("%J", config.data)); +commands[command](ARGV); diff --git a/feeds/wifi-ax/hostapd/files/wpa_supplicant.uc b/feeds/wifi-ax/hostapd/files/wpa_supplicant.uc index e3a3afcff..cb5f41b1a 100644 --- a/feeds/wifi-ax/hostapd/files/wpa_supplicant.uc +++ b/feeds/wifi-ax/hostapd/files/wpa_supplicant.uc @@ -1,11 +1,12 @@ let libubus = require("ubus"); import { open, readfile } from "fs"; -import { wdev_create, wdev_remove, is_equal, vlist_new } from "common"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_open } from "common"; let ubus = libubus.connect(); wpas.data.config = {}; wpas.data.iface_phy = {}; +wpas.data.macaddr_list = {}; function iface_stop(iface) { @@ -20,16 +21,23 @@ function iface_stop(iface) iface.running = false; } -function iface_start(phy, iface) +function iface_start(phydev, iface, macaddr_list) { + let phy = phydev.name; + if (iface.running) return; let ifname = iface.config.iface; + let wdev_config = {}; + for (let field in iface.config) + wdev_config[field] = iface.config[field]; + if (!wdev_config.macaddr) + wdev_config.macaddr = phydev.macaddr_next(); wpas.data.iface_phy[ifname] = phy; wdev_remove(ifname); - let ret = wdev_create(phy, ifname, iface.config); + let ret = wdev_create(phy, ifname, wdev_config); if (ret) wpas.printf(`Failed to create device ${ifname}: ${ret}`); wpas.add_iface(iface.config); @@ -43,6 +51,11 @@ function iface_cb(new_if, old_if) return; } + if (new_if && old_if) + wpas.printf(`Update configuration for interface ${old_if.config.iface}`); + else if (old_if) + wpas.printf(`Remove interface ${old_if.config.iface}`); + if (old_if) iface_stop(old_if); } @@ -73,9 +86,22 @@ function set_config(phy_name, config_list) function start_pending(phy_name) { let phy = wpas.data.config[phy_name]; + let ubus = wpas.data.ubus; + + if (!phy || !phy.data) + return; + + let phydev = phy_open(phy_name); + if (!phydev) { + wpas.printf(`Could not open phy ${phy_name}`); + return; + } + + let macaddr_list = wpas.data.macaddr_list[phy_name]; + phydev.macaddr_init(macaddr_list); for (let ifname in phy.data) - iface_start(phy_name, phy.data[ifname]); + iface_start(phydev, phy.data[ifname]); } let main_obj = { @@ -106,6 +132,55 @@ let main_obj = { return 0; } }, + phy_set_macaddr_list: { + args: { + phy: "", + macaddr: [], + }, + call: function(req) { + let phy = req.args.phy; + if (!phy) + return libubus.STATUS_INVALID_ARGUMENT; + + wpas.data.macaddr_list[phy] = req.args.macaddr; + return 0; + } + }, + phy_status: { + args: { + phy: "" + }, + call: function(req) { + if (!req.args.phy) + return libubus.STATUS_INVALID_ARGUMENT; + + let phy = wpas.data.config[req.args.phy]; + if (!phy) + return libubus.STATUS_NOT_FOUND; + + for (let ifname in phy.data) { + try { + let iface = wpas.interfaces[ifname]; + if (!iface) + continue; + + let status = iface.status(); + if (!status) + continue; + + if (status.state == "INTERFACE_DISABLED") + continue; + + status.ifname = ifname; + return status; + } catch (e) { + continue; + } + } + + return libubus.STATUS_NOT_FOUND; + } + }, config_set: { args: { phy: "", @@ -116,6 +191,7 @@ let main_obj = { if (!req.args.phy) return libubus.STATUS_INVALID_ARGUMENT; + wpas.printf(`Set new config for phy ${req.args.phy}`); try { if (req.args.config) set_config(req.args.phy, req.args.config); @@ -188,6 +264,7 @@ function iface_hostapd_notify(phy, ifname, iface, state) switch (state) { case "DISCONNECTED": case "AUTHENTICATING": + case "SCANNING": msg.up = false; break; case "INTERFACE_DISABLED": diff --git a/feeds/wifi-ax/hostapd/patches/601-ucode_support.patch b/feeds/wifi-ax/hostapd/patches/601-ucode_support.patch index d542f3b2b..52a762417 100644 --- a/feeds/wifi-ax/hostapd/patches/601-ucode_support.patch +++ b/feeds/wifi-ax/hostapd/patches/601-ucode_support.patch @@ -287,7 +287,33 @@ --- a/src/drivers/driver.h +++ b/src/drivers/driver.h -@@ -5827,6 +5827,7 @@ union wpa_event_data { +@@ -3357,6 +3357,25 @@ struct wpa_driver_ops { + const char *ifname); + + /** ++ * if_rename - Rename a virtual interface ++ * @priv: Private driver interface data ++ * @type: Interface type ++ * @ifname: Interface name of the virtual interface to be renamed ++ * (NULL when renaming the AP BSS interface) ++ * @new_name: New interface name of the virtual interface ++ * Returns: 0 on success, -1 on failure ++ */ ++ int (*if_rename)(void *priv, enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name); ++ ++ /** ++ * set_first_bss - Make a virtual interface the first (primary) bss ++ * @priv: Private driver interface data ++ * Returns: 0 on success, -1 on failure ++ */ ++ int (*set_first_bss)(void *priv); ++ ++ /** + * set_sta_vlan - Bind a station into a specific interface (AP only) + * @priv: Private driver interface data + * @ifname: Interface (main or virtual BSS or VLAN) +@@ -5827,6 +5846,7 @@ union wpa_event_data { /** * struct ch_switch @@ -295,7 +321,7 @@ * @freq: Frequency of new channel in MHz * @ht_enabled: Whether this is an HT channel * @ch_offset: Secondary channel offset -@@ -5835,6 +5836,7 @@ union wpa_event_data { +@@ -5835,6 +5855,7 @@ union wpa_event_data { * @cf2: Center frequency 2 */ struct ch_switch { @@ -348,3 +374,187 @@ switch (event) { case EVENT_AUTH: #ifdef CONFIG_FST +--- a/src/ap/ap_drv_ops.h ++++ b/src/ap/ap_drv_ops.h +@@ -367,6 +367,23 @@ static inline int hostapd_drv_stop_ap(st + return hapd->driver->stop_ap(hapd->drv_priv); + } + ++static inline int hostapd_drv_if_rename(struct hostapd_data *hapd, ++ enum wpa_driver_if_type type, ++ const char *ifname, ++ const char *new_name) ++{ ++ if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv) ++ return -1; ++ return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name); ++} ++ ++static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd) ++{ ++ if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv) ++ return 0; ++ return hapd->driver->set_first_bss(hapd->drv_priv); ++} ++ + static inline int hostapd_drv_channel_info(struct hostapd_data *hapd, + struct wpa_channel_info *ci) + { +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -1222,7 +1222,7 @@ static void wpa_driver_nl80211_event_rtm + } + wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", + namebuf, ifname); +- if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { ++ if (drv->first_bss->ifindex != ifi->ifi_index) { + wpa_printf(MSG_DEBUG, + "nl80211: Not the main interface (%s) - do not indicate interface down", + drv->first_bss->ifname); +@@ -1258,7 +1258,7 @@ static void wpa_driver_nl80211_event_rtm + } + wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", + namebuf, ifname); +- if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { ++ if (drv->first_bss->ifindex != ifi->ifi_index) { + wpa_printf(MSG_DEBUG, + "nl80211: Not the main interface (%s) - do not indicate interface up", + drv->first_bss->ifname); +@@ -7609,6 +7609,7 @@ static void *i802_init(struct hostapd_da + char master_ifname[IFNAMSIZ]; + int ifindex, br_ifindex = 0; + int br_added = 0; ++ int err; + + bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, + params->global_priv, 1, +@@ -7668,21 +7669,17 @@ static void *i802_init(struct hostapd_da + (params->num_bridge == 0 || !params->bridge[0])) + add_ifidx(drv, br_ifindex, drv->ifindex); + +- if (bss->added_if_into_bridge || bss->already_in_bridge) { +- int err; +- +- drv->rtnl_sk = nl_socket_alloc(); +- if (drv->rtnl_sk == NULL) { +- wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); +- goto failed; +- } ++ drv->rtnl_sk = nl_socket_alloc(); ++ if (drv->rtnl_sk == NULL) { ++ wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); ++ goto failed; ++ } + +- err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); +- if (err) { +- wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", +- nl_geterror(err)); +- goto failed; +- } ++ err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); ++ if (err) { ++ wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", ++ nl_geterror(err)); ++ goto failed; + } + + if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { +@@ -8041,6 +8038,50 @@ static int wpa_driver_nl80211_if_remove( + return 0; + } + ++static int wpa_driver_nl80211_if_rename(struct i802_bss *bss, ++ enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name) ++{ ++ struct wpa_driver_nl80211_data *drv = bss->drv; ++ struct ifinfomsg ifi = { ++ .ifi_family = AF_UNSPEC, ++ .ifi_index = bss->ifindex, ++ }; ++ struct nl_msg *msg; ++ int res = -ENOMEM; ++ ++ if (ifname) ++ ifi.ifi_index = if_nametoindex(ifname); ++ ++ msg = nlmsg_alloc_simple(RTM_SETLINK, 0); ++ if (!msg) ++ return res; ++ ++ if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0) ++ goto out; ++ ++ if (nla_put_string(msg, IFLA_IFNAME, new_name)) ++ goto out; ++ ++ res = nl_send_auto_complete(drv->rtnl_sk, msg); ++ if (res < 0) ++ goto out; ++ ++ res = nl_wait_for_ack(drv->rtnl_sk); ++ if (res) { ++ wpa_printf(MSG_INFO, ++ "nl80211: Renaming device %s to %s failed: %s", ++ ifname ? ifname : bss->ifname, new_name, nl_geterror(res)); ++ goto out; ++ } ++ ++ if (type == WPA_IF_AP_BSS && !ifname) ++ os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname)); ++ ++out: ++ nlmsg_free(msg); ++ return res; ++} + + static int cookie_handler(struct nl_msg *msg, void *arg) + { +@@ -9385,6 +9426,37 @@ static int driver_nl80211_if_remove(void + } + + ++static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name) ++{ ++ struct i802_bss *bss = priv; ++ return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name); ++} ++ ++ ++static int driver_nl80211_set_first_bss(void *priv) ++{ ++ struct i802_bss *bss = priv, *tbss; ++ struct wpa_driver_nl80211_data *drv = bss->drv; ++ ++ if (drv->first_bss == bss) ++ return 0; ++ ++ for (tbss = drv->first_bss; tbss; tbss = tbss->next) { ++ if (tbss->next != bss) ++ continue; ++ ++ tbss->next = bss->next; ++ bss->next = drv->first_bss; ++ drv->first_bss = bss; ++ drv->ctx = bss->ctx; ++ return 0; ++ } ++ ++ return -1; ++} ++ ++ + static int driver_nl80211_send_mlme(void *priv, const u8 *data, + size_t data_len, int noack, + unsigned int freq, +@@ -11967,6 +12039,8 @@ const struct wpa_driver_ops wpa_driver_n + .set_acl = wpa_driver_nl80211_set_acl, + .if_add = wpa_driver_nl80211_if_add, + .if_remove = driver_nl80211_if_remove, ++ .if_rename = driver_nl80211_if_rename, ++ .set_first_bss = driver_nl80211_set_first_bss, + .send_mlme = driver_nl80211_send_mlme, + .get_hw_feature_data = nl80211_get_hw_feature_data, + .sta_add = wpa_driver_nl80211_sta_add, diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ucode.c b/feeds/wifi-ax/hostapd/src/src/ap/ucode.c index 02413c70b..6ce8a3395 100644 --- a/feeds/wifi-ax/hostapd/src/src/ap/ucode.c +++ b/feeds/wifi-ax/hostapd/src/src/ap/ucode.c @@ -7,6 +7,8 @@ #include "beacon.h" #include "hw_features.h" #include "ap_drv_ops.h" +#include "dfs.h" +#include "acs.h" #include static uc_resource_type_t *global_type, *bss_type, *iface_type; @@ -118,6 +120,7 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) struct hostapd_config *conf; uc_value_t *file = uc_fn_arg(0); uc_value_t *index = uc_fn_arg(1); + uc_value_t *files_only = uc_fn_arg(2); unsigned int i, idx = 0; int ret = -1; @@ -129,9 +132,27 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) iface = hapd->iface; conf = interfaces->config_read_cb(ucv_string_get(file)); - if (!conf || idx > conf->num_bss || !conf->bss[idx]) + if (!conf) goto out; + if (idx > conf->num_bss || !conf->bss[idx]) + goto free; + + if (ucv_boolean_get(files_only)) { + struct hostapd_bss_config *bss = conf->bss[idx]; + struct hostapd_bss_config *old_bss = hapd->conf; + +#define swap_field(name) \ + do { \ + void *ptr = old_bss->name; \ + old_bss->name = bss->name; \ + bss->name = ptr; \ + } while (0) + + swap_field(ssid.wpa_psk_file); + goto done; + } + hostapd_bss_deinit_no_free(hapd); hostapd_drv_stop_ap(hapd); hostapd_free_hapd_data(hapd); @@ -142,12 +163,14 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) iface->conf->bss[i] = conf->bss[idx]; hapd->conf = conf->bss[idx]; conf->bss[idx] = old_bss; - hostapd_config_free(conf); - hostapd_setup_bss(hapd, hapd == iface->bss[0], !iface->conf->multiple_bssid); + hostapd_setup_bss(hapd, hapd == iface->bss[0], true); + hostapd_ucode_update_interfaces(); +done: ret = 0; - +free: + hostapd_config_free(conf); out: return ucv_int64_new(ret); } @@ -178,10 +201,15 @@ uc_hostapd_bss_delete(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface; int i, idx; - if (!hapd || hapd == hapd->iface->bss[0]) + if (!hapd) return NULL; iface = hapd->iface; + if (iface->num_bss == 1) { + wpa_printf(MSG_ERROR, "trying to delete last bss of an iface: %s\n", hapd->conf->iface); + return NULL; + } + for (idx = 0; idx < iface->num_bss; idx++) if (iface->bss[idx] == hapd) break; @@ -191,8 +219,13 @@ uc_hostapd_bss_delete(uc_vm_t *vm, size_t nargs) for (i = idx + 1; i < iface->num_bss; i++) iface->bss[i - 1] = iface->bss[i]; + iface->num_bss--; + iface->bss[0]->interface_added = 0; + hostapd_drv_set_first_bss(iface->bss[0]); + hapd->interface_added = 1; + hostapd_drv_stop_ap(hapd); hostapd_bss_deinit(hapd); hostapd_remove_iface_bss_conf(iface->conf, hapd->conf); @@ -266,6 +299,58 @@ out: return ret; } +static uc_value_t * +uc_hostapd_iface_set_bss_order(uc_vm_t *vm, size_t nargs) +{ + struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); + uc_value_t *bss_list = uc_fn_arg(0); + struct hostapd_data **new_bss; + struct hostapd_bss_config **new_conf; + + if (!iface) + return NULL; + + if (ucv_type(bss_list) != UC_ARRAY || + ucv_array_length(bss_list) != iface->num_bss) + return NULL; + + new_bss = calloc(iface->num_bss, sizeof(*new_bss)); + new_conf = calloc(iface->num_bss, sizeof(*new_conf)); + for (size_t i = 0; i < iface->num_bss; i++) { + struct hostapd_data *bss; + + bss = ucv_resource_data(ucv_array_get(bss_list, i), "hostapd.bss"); + if (bss->iface != iface) + goto free; + + for (size_t k = 0; k < i; k++) + if (new_bss[k] == bss) + goto free; + + new_bss[i] = bss; + new_conf[i] = bss->conf; + } + + new_bss[0]->interface_added = 0; + for (size_t i = 1; i < iface->num_bss; i++) + new_bss[i]->interface_added = 1; + + free(iface->bss); + iface->bss = new_bss; + + free(iface->conf->bss); + iface->conf->bss = new_conf; + iface->conf->num_bss = iface->num_bss; + hostapd_drv_set_first_bss(iface->bss[0]); + + return ucv_boolean_new(true); + +free: + free(new_bss); + free(new_conf); + return NULL; +} + static uc_value_t * uc_hostapd_bss_ctrl(uc_vm_t *vm, size_t nargs) { @@ -297,12 +382,21 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); int i; +#ifdef CONFIG_ACS + if (iface->state == HAPD_IFACE_ACS) { + acs_cleanup(iface); + iface->scan_cb = NULL; + hostapd_disable_iface(iface); + } +#endif + for (i = 0; i < iface->num_bss; i++) { struct hostapd_data *hapd = iface->bss[i]; hostapd_drv_stop_ap(hapd); - hapd->started = 0; + hapd->beacon_set_done = 0; } + return NULL; } static uc_value_t * @@ -317,6 +411,7 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) if (!iface) return NULL; + iface->freq = 0; if (!info) goto out; @@ -332,46 +427,52 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) conf->channel = intval; if ((intval = ucv_int64_get(ucv_object_get(info, "sec_channel", NULL))) && !errno) conf->secondary_channel = intval; -#ifdef CONFIG_IEEE80211AC - if ((intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL))) && !errno) { - conf->vht_oper_centr_freq_seg0_idx = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_centr_freq_seg0_idx = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_centr_freq_seg0_idx = intval; -#endif - } - if ((intval = ucv_int64_get(ucv_object_get(info, "center_seg1_idx", NULL))) && !errno) { - conf->vht_oper_centr_freq_seg1_idx = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_centr_freq_seg1_idx = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_centr_freq_seg1_idx = intval; -#endif - } + + intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL)); + if (!errno) + hostapd_set_oper_centr_freq_seg0_idx(conf, intval); + + intval = ucv_int64_get(ucv_object_get(info, "center_seg1_idx", NULL)); + if (!errno) + hostapd_set_oper_centr_freq_seg1_idx(conf, intval); + intval = ucv_int64_get(ucv_object_get(info, "oper_chwidth", NULL)); - if (!errno) { - conf->vht_oper_chwidth = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_chwidth = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_chwidth = intval; -#endif - } -#endif + if (!errno) + hostapd_set_oper_chwidth(conf, intval); + + intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL)); + if (!errno) + iface->freq = intval; + conf->acs = 0; out: - if (conf->channel) + switch (iface->state) { + case HAPD_IFACE_DISABLED: + break; + case HAPD_IFACE_ENABLED: + if (!hostapd_is_dfs_required(iface) || + hostapd_is_dfs_chan_available(iface)) + break; + wpa_printf(MSG_INFO, "DFS CAC required on new channel, restart interface"); + /* fallthrough */ + default: + hostapd_disable_iface(iface); + break; + } + + if (conf->channel && !iface->freq) iface->freq = hostapd_hw_get_freq(iface->bss[0], conf->channel); + if (iface->state != HAPD_IFACE_ENABLED) { + hostapd_enable_iface(iface); + return ucv_boolean_new(true); + } + for (i = 0; i < iface->num_bss; i++) { struct hostapd_data *hapd = iface->bss[i]; int ret; - hapd->started = 1; + hapd->conf->start_disabled = 0; hostapd_set_freq(hapd, conf->hw_mode, iface->freq, conf->channel, conf->enable_edmg, @@ -436,6 +537,55 @@ uc_hostapd_iface_switch_channel(uc_vm_t *vm, size_t nargs) return ucv_boolean_new(!ret); } +static uc_value_t * +uc_hostapd_bss_rename(uc_vm_t *vm, size_t nargs) +{ + struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); + uc_value_t *ifname_arg = uc_fn_arg(0); + char prev_ifname[IFNAMSIZ + 1]; + struct sta_info *sta; + const char *ifname; + int ret; + + if (!hapd || ucv_type(ifname_arg) != UC_STRING) + return NULL; + + os_strlcpy(prev_ifname, hapd->conf->iface, sizeof(prev_ifname)); + ifname = ucv_string_get(ifname_arg); + + hostapd_ubus_free_bss(hapd); + if (interfaces->ctrl_iface_deinit) + interfaces->ctrl_iface_deinit(hapd); + + ret = hostapd_drv_if_rename(hapd, WPA_IF_AP_BSS, NULL, ifname); + if (ret) + goto out; + + for (sta = hapd->sta_list; sta; sta = sta->next) { + char cur_name[IFNAMSIZ + 1], new_name[IFNAMSIZ + 1]; + + if (!(sta->flags & WLAN_STA_WDS) || sta->pending_wds_enable) + continue; + + snprintf(cur_name, sizeof(cur_name), "%s.sta%d", prev_ifname, sta->aid); + snprintf(new_name, sizeof(new_name), "%s.sta%d", ifname, sta->aid); + hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, cur_name, new_name); + } + + if (!strncmp(hapd->conf->ssid.vlan, hapd->conf->iface, sizeof(hapd->conf->ssid.vlan))) + os_strlcpy(hapd->conf->ssid.vlan, ifname, sizeof(hapd->conf->ssid.vlan)); + os_strlcpy(hapd->conf->iface, ifname, sizeof(hapd->conf->iface)); + hostapd_ubus_add_bss(hapd); + + hostapd_ucode_update_interfaces(); +out: + if (interfaces->ctrl_iface_init) + interfaces->ctrl_iface_init(hapd); + + return ret ? NULL : ucv_boolean_new(true); +} + + int hostapd_ucode_init(struct hapd_interfaces *ifaces) { static const uc_function_list_t global_fns[] = { @@ -449,9 +599,11 @@ int hostapd_ucode_init(struct hapd_interfaces *ifaces) static const uc_function_list_t bss_fns[] = { { "ctrl", uc_hostapd_bss_ctrl }, { "set_config", uc_hostapd_bss_set_config }, + { "rename", uc_hostapd_bss_rename }, { "delete", uc_hostapd_bss_delete }, }; static const uc_function_list_t iface_fns[] = { + { "set_bss_order", uc_hostapd_iface_set_bss_order }, { "add_bss", uc_hostapd_iface_add_bss }, { "stop", uc_hostapd_iface_stop }, { "start", uc_hostapd_iface_start }, diff --git a/feeds/wifi-ax/hostapd/src/src/utils/ucode.c b/feeds/wifi-ax/hostapd/src/src/utils/ucode.c index b106d856f..998cf5574 100644 --- a/feeds/wifi-ax/hostapd/src/src/utils/ucode.c +++ b/feeds/wifi-ax/hostapd/src/src/utils/ucode.c @@ -129,7 +129,10 @@ uc_value_t *uc_wpa_freq_info(uc_vm_t *vm, size_t nargs) tmp_channel &= ~((8 << width) - 1); center_idx = tmp_channel + center_ofs + (4 << width) - 1; - ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(center_idx)); + if (freq_val < 3000) + ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(0)); + else + ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(center_idx)); center_idx = (center_idx - channel) * 5 + freq_val; ucv_object_add(ret, "center_freq1", ucv_int64_new(center_idx)); @@ -295,9 +298,15 @@ uc_value_t *wpa_ucode_registry_get(uc_value_t *reg, int idx) uc_value_t *wpa_ucode_registry_remove(uc_value_t *reg, int idx) { uc_value_t *val = wpa_ucode_registry_get(reg, idx); + void **dataptr; - if (val) - ucv_array_set(reg, idx - 1, NULL); + if (!val) + return NULL; + + ucv_array_set(reg, idx - 1, NULL); + dataptr = ucv_resource_dataptr(val, NULL); + if (dataptr) + *dataptr = NULL; return val; } diff --git a/feeds/wifi-ax/hostapd/src/wpa_supplicant/ucode.c b/feeds/wifi-ax/hostapd/src/wpa_supplicant/ucode.c index d0a78d162..55d22584f 100644 --- a/feeds/wifi-ax/hostapd/src/wpa_supplicant/ucode.c +++ b/feeds/wifi-ax/hostapd/src/wpa_supplicant/ucode.c @@ -2,6 +2,7 @@ #include "utils/common.h" #include "utils/ucode.h" #include "drivers/driver.h" +#include "ap/hostapd.h" #include "wpa_supplicant_i.h" #include "wps_supplicant.h" #include "bss.h" @@ -211,12 +212,13 @@ uc_wpas_iface_status(uc_vm_t *vm, size_t nargs) ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION); if (ie && ie[1] >= 2) { const struct ieee80211_ht_operation *ht_oper; + int sec; ht_oper = (const void *) (ie + 2); - if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) + sec = ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; + if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) sec_chan = 1; - else if (ht_oper->ht_param & - HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) sec_chan = -1; } @@ -224,6 +226,15 @@ uc_wpas_iface_status(uc_vm_t *vm, size_t nargs) ucv_object_add(ret, "frequency", ucv_int64_new(bss->freq)); } +#ifdef CONFIG_MESH + if (wpa_s->ifmsh) { + struct hostapd_iface *ifmsh = wpa_s->ifmsh; + + ucv_object_add(ret, "sec_chan_offset", ucv_int64_new(ifmsh->conf->secondary_channel)); + ucv_object_add(ret, "frequency", ucv_int64_new(ifmsh->freq)); + } +#endif + return ret; } diff --git a/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh b/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh index dcf41441e..70c2348ad 100644 --- a/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -488,6 +488,7 @@ ${channel:+channel=$channel} ${channel_list:+chanlist=$channel_list} ${hostapd_noscan:+noscan=1} ${tx_burst:+tx_queue_data2_burst=$tx_burst} +#num_global_macaddr=$num_global_macaddr $base_cfg EOF @@ -528,6 +529,7 @@ mac80211_hostapd_setup_bss() { cat >> /var/run/hostapd-$phy.conf < /dev/null ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'", "config": [] }' > /dev/null - wdev_tool "$phy" '{}' + wdev_tool "$phy" set_config '{}' } drv_mac80211_setup() { @@ -1116,7 +1072,7 @@ drv_mac80211_setup() { mac80211_prepare_iw_htmode active_ifnames= - for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif ${multiple_bssid} + 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" @@ -1125,7 +1081,7 @@ drv_mac80211_setup() { [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy" json_set_namespace wdev_uc prev - wdev_tool "$phy" "$(json_dump)" $active_ifnames + wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames json_set_namespace "$prev" for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower From 95032994fe22cd215c7d0c6d94d126149d4e7fbd Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 14 Sep 2023 11:22:36 +0200 Subject: [PATCH 19/32] hostapd: move ubus.c changes from patches to src Signed-off-by: Felix Fietkau --- .../hostapd/patches/901-cfg-section.patch | 12 - .../hostapd/patches/920-sta_driver_data.patch | 40 +- .../hostapd/patches/999-ssi_signal.patch | 22 - feeds/wifi-ax/hostapd/src/src/ap/ubus.c | 39 + feeds/wifi-ax/hostapd/src/src/ap/ubus.c.orig | 1845 +++++++++++++++++ 5 files changed, 1885 insertions(+), 73 deletions(-) create mode 100644 feeds/wifi-ax/hostapd/src/src/ap/ubus.c.orig diff --git a/feeds/wifi-ax/hostapd/patches/901-cfg-section.patch b/feeds/wifi-ax/hostapd/patches/901-cfg-section.patch index b640f17db..9122a4236 100644 --- a/feeds/wifi-ax/hostapd/patches/901-cfg-section.patch +++ b/feeds/wifi-ax/hostapd/patches/901-cfg-section.patch @@ -19,18 +19,6 @@ enum hostapd_logger_level logger_syslog_level, logger_stdout_level; ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -424,6 +424,9 @@ hostapd_bss_get_status(struct ubus_conte - hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); - blobmsg_close_table(&b, dfs_table); - -+ if (hapd->conf->uci_section) -+ blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); -+ - ubus_send_reply(ctx, req, b.head); - - return 0; --- a/src/ap/ap_config.c +++ b/src/ap/ap_config.c @@ -785,6 +785,7 @@ void hostapd_config_free_bss(struct host diff --git a/feeds/wifi-ax/hostapd/patches/920-sta_driver_data.patch b/feeds/wifi-ax/hostapd/patches/920-sta_driver_data.patch index 6bf5e5661..4d11051d1 100644 --- a/feeds/wifi-ax/hostapd/patches/920-sta_driver_data.patch +++ b/feeds/wifi-ax/hostapd/patches/920-sta_driver_data.patch @@ -50,42 +50,4 @@ return NL_SKIP; } ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -306,6 +306,36 @@ hostapd_bss_get_clients(struct ubus_cont - blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); - blobmsg_close_table(&b, r); - blobmsg_add_u32(&b, "signal", sta_driver_data.signal); -+ -+ r = blobmsg_open_table(&b, "mcs"); -+ if (sta_driver_data.rx_hemcs) { -+ blobmsg_add_u32(&b, "he", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_hemcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_hemcs); -+ } else if (sta_driver_data.rx_vhtmcs) { -+ blobmsg_add_u32(&b, "vht", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vhtmcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vhtmcs); -+ } else { -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); -+ } -+ blobmsg_close_table(&b, r); -+ -+ r = blobmsg_open_table(&b, "nss"); -+ if (sta_driver_data.rx_he_nss) { -+ blobmsg_add_u32(&b, "he", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_he_nss); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_he_nss); -+ } else if (sta_driver_data.rx_vht_nss) { -+ blobmsg_add_u32(&b, "vht", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vht_nss); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vht_nss); -+ } else { -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); -+ } -+ blobmsg_close_table(&b, r); - } - - hostapd_parse_capab_blobmsg(sta); + diff --git a/feeds/wifi-ax/hostapd/patches/999-ssi_signal.patch b/feeds/wifi-ax/hostapd/patches/999-ssi_signal.patch index bdd0a0ede..cc7873284 100644 --- a/feeds/wifi-ax/hostapd/patches/999-ssi_signal.patch +++ b/feeds/wifi-ax/hostapd/patches/999-ssi_signal.patch @@ -61,28 +61,6 @@ }; ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -336,6 +336,9 @@ hostapd_bss_get_clients(struct ubus_cont - blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); - } - blobmsg_close_table(&b, r); -+ -+ if (sta->signal_mgmt) -+ blobmsg_add_u32(&b, "signal_mgmt", sta->signal_mgmt); - } - - hostapd_parse_capab_blobmsg(sta); -@@ -457,6 +460,9 @@ hostapd_bss_get_status(struct ubus_conte - if (hapd->conf->uci_section) - blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); - -+ if (hapd->signal_mgmt) -+ blobmsg_add_u32(&b, "signal_mgmt", hapd->signal_mgmt); -+ - ubus_send_reply(ctx, req, b.head); - - return 0; --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -451,6 +451,7 @@ struct hostapd_data { diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ubus.c b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c index befa3bc84..154876a84 100644 --- a/feeds/wifi-ax/hostapd/src/src/ap/ubus.c +++ b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c @@ -306,6 +306,39 @@ hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); blobmsg_close_table(&b, r); blobmsg_add_u32(&b, "signal", sta_driver_data.signal); + + r = blobmsg_open_table(&b, "mcs"); + if (sta_driver_data.rx_hemcs) { + blobmsg_add_u32(&b, "he", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_hemcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_hemcs); + } else if (sta_driver_data.rx_vhtmcs) { + blobmsg_add_u32(&b, "vht", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vhtmcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vhtmcs); + } else { + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); + } + blobmsg_close_table(&b, r); + + r = blobmsg_open_table(&b, "nss"); + if (sta_driver_data.rx_he_nss) { + blobmsg_add_u32(&b, "he", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_he_nss); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_he_nss); + } else if (sta_driver_data.rx_vht_nss) { + blobmsg_add_u32(&b, "vht", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vht_nss); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vht_nss); + } else { + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); + } + blobmsg_close_table(&b, r); + + if (sta->signal_mgmt) + blobmsg_add_u32(&b, "signal_mgmt", sta->signal_mgmt); } hostapd_parse_capab_blobmsg(sta); @@ -424,6 +457,12 @@ hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); blobmsg_close_table(&b, dfs_table); + if (hapd->conf->uci_section) + blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); + + if (hapd->signal_mgmt) + blobmsg_add_u32(&b, "signal_mgmt", hapd->signal_mgmt); + ubus_send_reply(ctx, req, b.head); return 0; diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ubus.c.orig b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c.orig new file mode 100644 index 000000000..befa3bc84 --- /dev/null +++ b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c.orig @@ -0,0 +1,1845 @@ +/* + * hostapd / ubus support + * Copyright (c) 2013, Felix Fietkau + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#include "utils/includes.h" +#include "utils/common.h" +#include "utils/eloop.h" +#include "utils/wpabuf.h" +#include "common/ieee802_11_defs.h" +#include "common/hw_features_common.h" +#include "hostapd.h" +#include "neighbor_db.h" +#include "wps_hostapd.h" +#include "sta_info.h" +#include "ubus.h" +#include "ap_drv_ops.h" +#include "beacon.h" +#include "rrm.h" +#include "wnm_ap.h" +#include "taxonomy.h" +#include "airtime_policy.h" +#include "hw_features.h" + +static struct ubus_context *ctx; +static struct blob_buf b; +static int ctx_ref; + +static inline struct hostapd_data *get_hapd_from_object(struct ubus_object *obj) +{ + return container_of(obj, struct hostapd_data, ubus.obj); +} + +struct ubus_banned_client { + struct avl_node avl; + u8 addr[ETH_ALEN]; +}; + +static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx) +{ + if (ubus_reconnect(ctx, NULL)) { + eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL); + return; + } + + ubus_add_uloop(ctx); +} + +static void hostapd_ubus_connection_lost(struct ubus_context *ctx) +{ + uloop_fd_delete(&ctx->sock); + eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL); +} + +static bool hostapd_ubus_init(void) +{ + if (ctx) + return true; + + eloop_add_uloop(); + ctx = ubus_connect(NULL); + if (!ctx) + return false; + + ctx->connection_lost = hostapd_ubus_connection_lost; + ubus_add_uloop(ctx); + + return true; +} + +static void hostapd_ubus_ref_inc(void) +{ + ctx_ref++; +} + +static void hostapd_ubus_ref_dec(void) +{ + ctx_ref--; + if (!ctx) + return; + + if (ctx_ref) + return; + + uloop_fd_delete(&ctx->sock); + ubus_free(ctx); + ctx = NULL; +} + +void hostapd_ubus_add_iface(struct hostapd_iface *iface) +{ + if (!hostapd_ubus_init()) + return; +} + +void hostapd_ubus_free_iface(struct hostapd_iface *iface) +{ + if (!ctx) + return; +} + +static void hostapd_notify_ubus(struct ubus_object *obj, char *bssname, char *event) +{ + char *event_type; + + if (!ctx || !obj) + return; + + if (asprintf(&event_type, "bss.%s", event) < 0) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "name", bssname); + ubus_notify(ctx, obj, event_type, b.head, -1); + free(event_type); +} + +static void +hostapd_bss_del_ban(void *eloop_data, void *user_ctx) +{ + struct ubus_banned_client *ban = eloop_data; + struct hostapd_data *hapd = user_ctx; + + avl_delete(&hapd->ubus.banned, &ban->avl); + free(ban); +} + +static void +hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time) +{ + struct ubus_banned_client *ban; + + if (time < 0) + time = 0; + + ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl); + if (!ban) { + if (!time) + return; + + ban = os_zalloc(sizeof(*ban)); + memcpy(ban->addr, addr, sizeof(ban->addr)); + ban->avl.key = ban->addr; + avl_insert(&hapd->ubus.banned, &ban->avl); + } else { + eloop_cancel_timeout(hostapd_bss_del_ban, ban, hapd); + if (!time) { + hostapd_bss_del_ban(ban, hapd); + return; + } + } + + eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd); +} + +static int +hostapd_bss_reload(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + return hostapd_reload_config(hapd->iface); +} + + +static void +hostapd_parse_vht_map_blobmsg(uint16_t map) +{ + char label[4]; + int16_t val; + int i; + + for (i = 0; i < 8; i++) { + snprintf(label, 4, "%dss", i + 1); + + val = (map & (BIT(1) | BIT(0))) + 7; + blobmsg_add_u16(&b, label, val == 10 ? -1 : val); + map = map >> 2; + } +} + +static void +hostapd_parse_vht_capab_blobmsg(struct ieee80211_vht_capabilities *vhtc) +{ + void *supported_mcs; + void *map; + int i; + + static const struct { + const char *name; + uint32_t flag; + } vht_capas[] = { + { "su_beamformee", VHT_CAP_SU_BEAMFORMEE_CAPABLE }, + { "mu_beamformee", VHT_CAP_MU_BEAMFORMEE_CAPABLE }, + }; + + for (i = 0; i < ARRAY_SIZE(vht_capas); i++) + blobmsg_add_u8(&b, vht_capas[i].name, + !!(vhtc->vht_capabilities_info & vht_capas[i].flag)); + + supported_mcs = blobmsg_open_table(&b, "mcs_map"); + + /* RX map */ + map = blobmsg_open_table(&b, "rx"); + hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc->vht_supported_mcs_set.rx_map)); + blobmsg_close_table(&b, map); + + /* TX map */ + map = blobmsg_open_table(&b, "tx"); + hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc->vht_supported_mcs_set.tx_map)); + blobmsg_close_table(&b, map); + + blobmsg_close_table(&b, supported_mcs); +} + +static void +hostapd_parse_capab_blobmsg(struct sta_info *sta) +{ + void *r, *v; + + v = blobmsg_open_table(&b, "capabilities"); + + if (sta->vht_capabilities) { + r = blobmsg_open_table(&b, "vht"); + hostapd_parse_vht_capab_blobmsg(sta->vht_capabilities); + blobmsg_close_table(&b, r); + } + + /* ToDo: Add HT / HE capability parsing */ + + blobmsg_close_table(&b, v); +} + +static int +hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct hostap_sta_driver_data sta_driver_data; + struct sta_info *sta; + void *list, *c; + char mac_buf[20]; + static const struct { + const char *name; + uint32_t flag; + } sta_flags[] = { + { "auth", WLAN_STA_AUTH }, + { "assoc", WLAN_STA_ASSOC }, + { "authorized", WLAN_STA_AUTHORIZED }, + { "preauth", WLAN_STA_PREAUTH }, + { "wds", WLAN_STA_WDS }, + { "wmm", WLAN_STA_WMM }, + { "ht", WLAN_STA_HT }, + { "vht", WLAN_STA_VHT }, + { "he", WLAN_STA_HE }, + { "wps", WLAN_STA_WPS }, + { "mfp", WLAN_STA_MFP }, + }; + + blob_buf_init(&b, 0); + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + list = blobmsg_open_table(&b, "clients"); + for (sta = hapd->sta_list; sta; sta = sta->next) { + void *r; + int i; + + sprintf(mac_buf, MACSTR, MAC2STR(sta->addr)); + c = blobmsg_open_table(&b, mac_buf); + for (i = 0; i < ARRAY_SIZE(sta_flags); i++) + blobmsg_add_u8(&b, sta_flags[i].name, + !!(sta->flags & sta_flags[i].flag)); + + r = blobmsg_open_array(&b, "rrm"); + for (i = 0; i < ARRAY_SIZE(sta->rrm_enabled_capa); i++) + blobmsg_add_u32(&b, "", sta->rrm_enabled_capa[i]); + blobmsg_close_array(&b, r); + blobmsg_add_u32(&b, "aid", sta->aid); +#ifdef CONFIG_TAXONOMY + r = blobmsg_alloc_string_buffer(&b, "signature", 1024); + if (retrieve_sta_taxonomy(hapd, sta, r, 1024) > 0) + blobmsg_add_string_buffer(&b); +#endif + + /* Driver information */ + if (hostapd_drv_read_sta_data(hapd, &sta_driver_data, sta->addr) >= 0) { + r = blobmsg_open_table(&b, "bytes"); + blobmsg_add_u64(&b, "rx", sta_driver_data.rx_bytes); + blobmsg_add_u64(&b, "tx", sta_driver_data.tx_bytes); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "airtime"); + blobmsg_add_u64(&b, "rx", sta_driver_data.rx_airtime); + blobmsg_add_u64(&b, "tx", sta_driver_data.tx_airtime); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "packets"); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_packets); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_packets); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "rate"); + /* Rate in kbits */ + blobmsg_add_u32(&b, "rx", sta_driver_data.current_rx_rate * 100); + blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); + blobmsg_close_table(&b, r); + blobmsg_add_u32(&b, "signal", sta_driver_data.signal); + } + + hostapd_parse_capab_blobmsg(sta); + + blobmsg_close_table(&b, c); + } + blobmsg_close_array(&b, list); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_bss_get_features(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + blob_buf_init(&b, 0); + blobmsg_add_u8(&b, "ht_supported", ht_supported(hapd->iface->hw_features)); + blobmsg_add_u8(&b, "vht_supported", vht_supported(hapd->iface->hw_features)); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +/* Imported from iw/util.c + * https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/util.c?id=4b25ae3537af48dbf9d0abf94132e5ba01b32c18#n200 + */ +int ieee80211_frequency_to_channel(int freq) +{ + /* see 802.11-2007 17.3.8.3.2 and Annex J */ + if (freq == 2484) + return 14; + /* see 802.11ax D6.1 27.3.23.2 and Annex E */ + else if (freq == 5935) + return 2; + else if (freq < 2484) + return (freq - 2407) / 5; + else if (freq >= 4910 && freq <= 4980) + return (freq - 4000) / 5; + else if (freq < 5950) + return (freq - 5000) / 5; + else if (freq <= 45000) /* DMG band lower limit */ + /* see 802.11ax D6.1 27.3.23.2 */ + return (freq - 5950) / 5; + else if (freq >= 58320 && freq <= 70200) + return (freq - 56160) / 2160; + else + return 0; +} + +static int +hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + void *airtime_table, *dfs_table, *rrm_table, *wnm_table; + struct os_reltime now; + char ssid[SSID_MAX_LEN + 1]; + char phy_name[17]; + size_t ssid_len = SSID_MAX_LEN; + u8 channel = 0, op_class = 0; + + if (hapd->conf->ssid.ssid_len < SSID_MAX_LEN) + ssid_len = hapd->conf->ssid.ssid_len; + + ieee80211_freq_to_channel_ext(hapd->iface->freq, + hapd->iconf->secondary_channel, + hostapd_get_oper_chwidth(hapd->iconf), + &op_class, &channel); + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "status", hostapd_state_text(hapd->iface->state)); + blobmsg_printf(&b, "bssid", MACSTR, MAC2STR(hapd->conf->bssid)); + + memset(ssid, 0, SSID_MAX_LEN + 1); + memcpy(ssid, hapd->conf->ssid.ssid, ssid_len); + blobmsg_add_string(&b, "ssid", ssid); + + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + blobmsg_add_u32(&b, "channel", channel); + blobmsg_add_u32(&b, "op_class", op_class); + blobmsg_add_u32(&b, "beacon_interval", hapd->iconf->beacon_int); + + snprintf(phy_name, 17, "%s", hapd->iface->phy); + blobmsg_add_string(&b, "phy", phy_name); + + /* RRM */ + rrm_table = blobmsg_open_table(&b, "rrm"); + blobmsg_add_u64(&b, "neighbor_report_tx", hapd->openwrt_stats.rrm.neighbor_report_tx); + blobmsg_close_table(&b, rrm_table); + + /* WNM */ + wnm_table = blobmsg_open_table(&b, "wnm"); + blobmsg_add_u64(&b, "bss_transition_query_rx", hapd->openwrt_stats.wnm.bss_transition_query_rx); + blobmsg_add_u64(&b, "bss_transition_request_tx", hapd->openwrt_stats.wnm.bss_transition_request_tx); + blobmsg_add_u64(&b, "bss_transition_response_rx", hapd->openwrt_stats.wnm.bss_transition_response_rx); + blobmsg_close_table(&b, wnm_table); + + /* Airtime */ + airtime_table = blobmsg_open_table(&b, "airtime"); + blobmsg_add_u64(&b, "time", hapd->iface->last_channel_time); + blobmsg_add_u64(&b, "time_busy", hapd->iface->last_channel_time_busy); + blobmsg_add_u16(&b, "utilization", hapd->iface->channel_utilization); + blobmsg_close_table(&b, airtime_table); + + /* DFS */ + dfs_table = blobmsg_open_table(&b, "dfs"); + blobmsg_add_u32(&b, "cac_seconds", hapd->iface->dfs_cac_ms / 1000); + blobmsg_add_u8(&b, "cac_active", !!(hapd->iface->cac_started)); + os_reltime_age(&hapd->iface->dfs_cac_start, &now); + blobmsg_add_u32(&b, "cac_seconds_left", + hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); + blobmsg_close_table(&b, dfs_table); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +enum { + NOTIFY_RESPONSE, + __NOTIFY_MAX +}; + +static const struct blobmsg_policy notify_policy[__NOTIFY_MAX] = { + [NOTIFY_RESPONSE] = { "notify_response", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_notify_response(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__NOTIFY_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct wpabuf *elems; + const char *pos; + size_t len; + + blobmsg_parse(notify_policy, __NOTIFY_MAX, tb, + blob_data(msg), blob_len(msg)); + + if (!tb[NOTIFY_RESPONSE]) + return UBUS_STATUS_INVALID_ARGUMENT; + + hapd->ubus.notify_response = blobmsg_get_u32(tb[NOTIFY_RESPONSE]); + + return UBUS_STATUS_OK; +} + +enum { + DEL_CLIENT_ADDR, + DEL_CLIENT_REASON, + DEL_CLIENT_DEAUTH, + DEL_CLIENT_BAN_TIME, + __DEL_CLIENT_MAX +}; + +static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = { + [DEL_CLIENT_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 }, + [DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 }, + [DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__DEL_CLIENT_MAX]; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct sta_info *sta; + bool deauth = false; + int reason; + u8 addr[ETH_ALEN]; + + blobmsg_parse(del_policy, __DEL_CLIENT_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[DEL_CLIENT_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[DEL_CLIENT_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[DEL_CLIENT_REASON]) + reason = blobmsg_get_u32(tb[DEL_CLIENT_REASON]); + + if (tb[DEL_CLIENT_DEAUTH]) + deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]); + + sta = ap_get_sta(hapd, addr); + if (sta) { + if (deauth) { + hostapd_drv_sta_deauth(hapd, addr, reason); + ap_sta_deauthenticate(hapd, sta, reason); + } else { + hostapd_drv_sta_disassoc(hapd, addr, reason); + ap_sta_disassociate(hapd, sta, reason); + } + } + + if (tb[DEL_CLIENT_BAN_TIME]) + hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME])); + + return 0; +} + +static void +blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const u8 *addr) +{ + char *s; + + s = blobmsg_alloc_string_buffer(buf, name, 20); + sprintf(s, MACSTR, MAC2STR(addr)); + blobmsg_add_string_buffer(buf); +} + +static int +hostapd_bss_list_bans(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct ubus_banned_client *ban; + void *c; + + blob_buf_init(&b, 0); + c = blobmsg_open_array(&b, "clients"); + avl_for_each_element(&hapd->ubus.banned, ban, avl) + blobmsg_add_macaddr(&b, NULL, ban->addr); + blobmsg_close_array(&b, c); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +#ifdef CONFIG_WPS +static int +hostapd_bss_wps_start(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = hostapd_wps_button_pushed(hapd, NULL); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} + + +static const char * pbc_status_enum_str(enum pbc_status status) +{ + switch (status) { + case WPS_PBC_STATUS_DISABLE: + return "Disabled"; + case WPS_PBC_STATUS_ACTIVE: + return "Active"; + case WPS_PBC_STATUS_TIMEOUT: + return "Timed-out"; + case WPS_PBC_STATUS_OVERLAP: + return "Overlap"; + default: + return "Unknown"; + } +} + +static int +hostapd_bss_wps_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + blob_buf_init(&b, 0); + + blobmsg_add_string(&b, "pbc_status", pbc_status_enum_str(hapd->wps_stats.pbc_status)); + blobmsg_add_string(&b, "last_wps_result", + (hapd->wps_stats.status == WPS_STATUS_SUCCESS ? + "Success": + (hapd->wps_stats.status == WPS_STATUS_FAILURE ? + "Failed" : "None"))); + + /* If status == Failure - Add possible Reasons */ + if(hapd->wps_stats.status == WPS_STATUS_FAILURE && + hapd->wps_stats.failure_reason > 0) + blobmsg_add_string(&b, "reason", wps_ei_str(hapd->wps_stats.failure_reason)); + + if (hapd->wps_stats.status) + blobmsg_printf(&b, "peer_address", MACSTR, MAC2STR(hapd->wps_stats.peer_addr)); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_bss_wps_cancel(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = hostapd_wps_cancel(hapd); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} +#endif /* CONFIG_WPS */ + +static int +hostapd_bss_update_beacon(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = ieee802_11_set_beacon(hapd); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} + +enum { + CONFIG_IFACE, + CONFIG_FILE, + __CONFIG_MAX +}; + +enum { + CSA_FREQ, + CSA_BCN_COUNT, + CSA_CENTER_FREQ1, + CSA_CENTER_FREQ2, + CSA_BANDWIDTH, + CSA_SEC_CHANNEL_OFFSET, + CSA_HT, + CSA_VHT, + CSA_HE, + CSA_BLOCK_TX, + CSA_FORCE, + __CSA_MAX +}; + +static const struct blobmsg_policy csa_policy[__CSA_MAX] = { + [CSA_FREQ] = { "freq", BLOBMSG_TYPE_INT32 }, + [CSA_BCN_COUNT] = { "bcn_count", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ1] = { "center_freq1", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ2] = { "center_freq2", BLOBMSG_TYPE_INT32 }, + [CSA_BANDWIDTH] = { "bandwidth", BLOBMSG_TYPE_INT32 }, + [CSA_SEC_CHANNEL_OFFSET] = { "sec_channel_offset", BLOBMSG_TYPE_INT32 }, + [CSA_HT] = { "ht", BLOBMSG_TYPE_BOOL }, + [CSA_VHT] = { "vht", BLOBMSG_TYPE_BOOL }, + [CSA_HE] = { "he", BLOBMSG_TYPE_BOOL }, + [CSA_BLOCK_TX] = { "block_tx", BLOBMSG_TYPE_BOOL }, + [CSA_FORCE] = { "force", BLOBMSG_TYPE_BOOL }, +}; + + +static void switch_chan_fallback_cb(void *eloop_data, void *user_ctx) +{ + struct hostapd_iface *iface = eloop_data; + struct hostapd_freq_params *freq_params = user_ctx; + + hostapd_switch_channel_fallback(iface, freq_params); +} + +#ifdef NEED_AP_MLME +static int +hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__CSA_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_config *iconf = hapd->iface->conf; + struct hostapd_freq_params *freq_params; + struct hostapd_hw_modes *mode = hapd->iface->current_mode; + struct csa_settings css = { + .freq_params = { + .ht_enabled = iconf->ieee80211n, + .vht_enabled = iconf->ieee80211ac, + .he_enabled = iconf->ieee80211ax, + .sec_channel_offset = iconf->secondary_channel, + } + }; + u8 chwidth = hostapd_get_oper_chwidth(iconf); + u8 seg0 = 0, seg1 = 0; + int ret = UBUS_STATUS_OK; + int i; + + blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[CSA_FREQ]) + return UBUS_STATUS_INVALID_ARGUMENT; + + switch (iconf->vht_oper_chwidth) { + case CHANWIDTH_USE_HT: + if (iconf->secondary_channel) + css.freq_params.bandwidth = 40; + else + css.freq_params.bandwidth = 20; + break; + case CHANWIDTH_160MHZ: + css.freq_params.bandwidth = 160; + break; + default: + css.freq_params.bandwidth = 80; + break; + } + + css.freq_params.freq = blobmsg_get_u32(tb[CSA_FREQ]); + +#define SET_CSA_SETTING(name, field, type) \ + do { \ + if (tb[name]) \ + css.field = blobmsg_get_ ## type(tb[name]); \ + } while(0) + + SET_CSA_SETTING(CSA_BCN_COUNT, cs_count, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ1, freq_params.center_freq1, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ2, freq_params.center_freq2, u32); + SET_CSA_SETTING(CSA_BANDWIDTH, freq_params.bandwidth, u32); + SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET, freq_params.sec_channel_offset, u32); + SET_CSA_SETTING(CSA_HT, freq_params.ht_enabled, bool); + SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool); + SET_CSA_SETTING(CSA_HE, freq_params.he_enabled, bool); + SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool); + + css.freq_params.channel = hostapd_hw_get_channel(hapd, css.freq_params.freq); + if (!css.freq_params.channel) + return UBUS_STATUS_NOT_SUPPORTED; + + switch (css.freq_params.bandwidth) { + case 160: + chwidth = CHANWIDTH_160MHZ; + break; + case 80: + chwidth = css.freq_params.center_freq2 ? CHANWIDTH_80P80MHZ : CHANWIDTH_80MHZ; + break; + default: + chwidth = CHANWIDTH_USE_HT; + break; + } + + hostapd_set_freq_params(&css.freq_params, iconf->hw_mode, + css.freq_params.freq, + css.freq_params.channel, iconf->enable_edmg, + iconf->edmg_channel, + css.freq_params.ht_enabled, + css.freq_params.vht_enabled, + css.freq_params.he_enabled, + css.freq_params.sec_channel_offset, + chwidth, seg0, seg1, + iconf->vht_capab, + mode ? &mode->he_capab[IEEE80211_MODE_AP] : + NULL); + + for (i = 0; i < hapd->iface->num_bss; i++) { + struct hostapd_data *bss = hapd->iface->bss[i]; + + if (hostapd_switch_channel(bss, &css) != 0) + ret = UBUS_STATUS_NOT_SUPPORTED; + } + + if (!ret || !tb[CSA_FORCE] || !blobmsg_get_bool(tb[CSA_FORCE])) + return ret; + + freq_params = malloc(sizeof(*freq_params)); + memcpy(freq_params, &css.freq_params, sizeof(*freq_params)); + eloop_register_timeout(0, 1, switch_chan_fallback_cb, + hapd->iface, freq_params); + + return 0; +#undef SET_CSA_SETTING +} +#endif + +enum { + VENDOR_ELEMENTS, + __VENDOR_ELEMENTS_MAX +}; + +static const struct blobmsg_policy ve_policy[__VENDOR_ELEMENTS_MAX] = { + /* vendor elements are provided as hex-string */ + [VENDOR_ELEMENTS] = { "vendor_elements", BLOBMSG_TYPE_STRING }, +}; + +static int +hostapd_vendor_elements(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__VENDOR_ELEMENTS_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_bss_config *bss = hapd->conf; + struct wpabuf *elems; + const char *pos; + size_t len; + + blobmsg_parse(ve_policy, __VENDOR_ELEMENTS_MAX, tb, + blob_data(msg), blob_len(msg)); + + if (!tb[VENDOR_ELEMENTS]) + return UBUS_STATUS_INVALID_ARGUMENT; + + pos = blobmsg_data(tb[VENDOR_ELEMENTS]); + len = os_strlen(pos); + if (len & 0x01) + return UBUS_STATUS_INVALID_ARGUMENT; + + len /= 2; + if (len == 0) { + wpabuf_free(bss->vendor_elements); + bss->vendor_elements = NULL; + return 0; + } + + elems = wpabuf_alloc(len); + if (elems == NULL) + return 1; + + if (hexstr2bin(pos, wpabuf_put(elems, len), len)) { + wpabuf_free(elems); + return UBUS_STATUS_INVALID_ARGUMENT; + } + + wpabuf_free(bss->vendor_elements); + bss->vendor_elements = elems; + + /* update beacons if vendor elements were set successfully */ + if (ieee802_11_update_beacons(hapd->iface) != 0) + return UBUS_STATUS_NOT_SUPPORTED; + return UBUS_STATUS_OK; +} + +static void +hostapd_rrm_print_nr(struct hostapd_neighbor_entry *nr) +{ + const u8 *data; + char *str; + int len; + + blobmsg_printf(&b, "", MACSTR, MAC2STR(nr->bssid)); + + str = blobmsg_alloc_string_buffer(&b, "", nr->ssid.ssid_len + 1); + memcpy(str, nr->ssid.ssid, nr->ssid.ssid_len); + str[nr->ssid.ssid_len] = 0; + blobmsg_add_string_buffer(&b); + + len = wpabuf_len(nr->nr); + str = blobmsg_alloc_string_buffer(&b, "", 2 * len + 1); + wpa_snprintf_hex(str, 2 * len + 1, wpabuf_head_u8(nr->nr), len); + blobmsg_add_string_buffer(&b); +} + +enum { + BSS_MGMT_EN_NEIGHBOR, + BSS_MGMT_EN_BEACON, +#ifdef CONFIG_WNM_AP + BSS_MGMT_EN_BSS_TRANSITION, +#endif + __BSS_MGMT_EN_MAX +}; + +static bool +__hostapd_bss_mgmt_enable_f(struct hostapd_data *hapd, int flag) +{ + struct hostapd_bss_config *bss = hapd->conf; + uint32_t flags; + + switch (flag) { + case BSS_MGMT_EN_NEIGHBOR: + if (bss->radio_measurements[0] & + WLAN_RRM_CAPS_NEIGHBOR_REPORT) + return false; + + bss->radio_measurements[0] |= + WLAN_RRM_CAPS_NEIGHBOR_REPORT; + hostapd_neighbor_set_own_report(hapd); + return true; + case BSS_MGMT_EN_BEACON: + flags = WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE | + WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE | + WLAN_RRM_CAPS_BEACON_REPORT_TABLE; + + if (bss->radio_measurements[0] & flags == flags) + return false; + + bss->radio_measurements[0] |= (u8) flags; + return true; +#ifdef CONFIG_WNM_AP + case BSS_MGMT_EN_BSS_TRANSITION: + if (bss->bss_transition) + return false; + + bss->bss_transition = 1; + return true; +#endif + } +} + +static void +__hostapd_bss_mgmt_enable(struct hostapd_data *hapd, uint32_t flags) +{ + bool update = false; + int i; + + for (i = 0; i < __BSS_MGMT_EN_MAX; i++) { + if (!(flags & (1 << i))) + continue; + + update |= __hostapd_bss_mgmt_enable_f(hapd, i); + } + + if (update) + ieee802_11_update_beacons(hapd->iface); +} + + +static const struct blobmsg_policy bss_mgmt_enable_policy[__BSS_MGMT_EN_MAX] = { + [BSS_MGMT_EN_NEIGHBOR] = { "neighbor_report", BLOBMSG_TYPE_BOOL }, + [BSS_MGMT_EN_BEACON] = { "beacon_report", BLOBMSG_TYPE_BOOL }, +#ifdef CONFIG_WNM_AP + [BSS_MGMT_EN_BSS_TRANSITION] = { "bss_transition", BLOBMSG_TYPE_BOOL }, +#endif +}; + +static int +hostapd_bss_mgmt_enable(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) + +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct blob_attr *tb[__BSS_MGMT_EN_MAX]; + struct blob_attr *cur; + uint32_t flags = 0; + int i; + bool neigh = false, beacon = false; + + blobmsg_parse(bss_mgmt_enable_policy, __BSS_MGMT_EN_MAX, tb, blob_data(msg), blob_len(msg)); + + for (i = 0; i < ARRAY_SIZE(tb); i++) { + if (!tb[i] || !blobmsg_get_bool(tb[i])) + continue; + + flags |= (1 << i); + } + + __hostapd_bss_mgmt_enable(hapd, flags); +} + + +static void +hostapd_rrm_nr_enable(struct hostapd_data *hapd) +{ + __hostapd_bss_mgmt_enable(hapd, 1 << BSS_MGMT_EN_NEIGHBOR); +} + +static int +hostapd_rrm_nr_get_own(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_neighbor_entry *nr; + void *c; + + hostapd_rrm_nr_enable(hapd); + + nr = hostapd_neighbor_get(hapd, hapd->own_addr, NULL); + if (!nr) + return UBUS_STATUS_NOT_FOUND; + + blob_buf_init(&b, 0); + + c = blobmsg_open_array(&b, "value"); + hostapd_rrm_print_nr(nr); + blobmsg_close_array(&b, c); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_rrm_nr_list(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_neighbor_entry *nr; + void *c; + + hostapd_rrm_nr_enable(hapd); + blob_buf_init(&b, 0); + + c = blobmsg_open_array(&b, "list"); + dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) { + void *cur; + + if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN)) + continue; + + cur = blobmsg_open_array(&b, NULL); + hostapd_rrm_print_nr(nr); + blobmsg_close_array(&b, cur); + } + blobmsg_close_array(&b, c); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +enum { + NR_SET_LIST, + __NR_SET_LIST_MAX +}; + +static const struct blobmsg_policy nr_set_policy[__NR_SET_LIST_MAX] = { + [NR_SET_LIST] = { "list", BLOBMSG_TYPE_ARRAY }, +}; + + +static void +hostapd_rrm_nr_clear(struct hostapd_data *hapd) +{ + struct hostapd_neighbor_entry *nr; + +restart: + dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) { + if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN)) + continue; + + hostapd_neighbor_remove(hapd, nr->bssid, &nr->ssid); + goto restart; + } +} + +static int +hostapd_rrm_nr_set(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + static const struct blobmsg_policy nr_e_policy[] = { + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + }; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct blob_attr *tb_l[__NR_SET_LIST_MAX]; + struct blob_attr *tb[ARRAY_SIZE(nr_e_policy)]; + struct blob_attr *cur; + int rem; + + hostapd_rrm_nr_enable(hapd); + + blobmsg_parse(nr_set_policy, __NR_SET_LIST_MAX, tb_l, blob_data(msg), blob_len(msg)); + if (!tb_l[NR_SET_LIST]) + return UBUS_STATUS_INVALID_ARGUMENT; + + hostapd_rrm_nr_clear(hapd); + blobmsg_for_each_attr(cur, tb_l[NR_SET_LIST], rem) { + struct wpa_ssid_value ssid; + struct wpabuf *data; + u8 bssid[ETH_ALEN]; + char *s, *nr_s; + + blobmsg_parse_array(nr_e_policy, ARRAY_SIZE(nr_e_policy), tb, blobmsg_data(cur), blobmsg_data_len(cur)); + if (!tb[0] || !tb[1] || !tb[2]) + goto invalid; + + /* Neighbor Report binary */ + nr_s = blobmsg_get_string(tb[2]); + data = wpabuf_parse_bin(nr_s); + if (!data) + goto invalid; + + /* BSSID */ + s = blobmsg_get_string(tb[0]); + if (strlen(s) == 0) { + /* Copy BSSID from neighbor report */ + if (hwaddr_compact_aton(nr_s, bssid)) + goto invalid; + } else if (hwaddr_aton(s, bssid)) { + goto invalid; + } + + /* SSID */ + s = blobmsg_get_string(tb[1]); + if (strlen(s) == 0) { + /* Copy SSID from hostapd BSS conf */ + memcpy(&ssid, &hapd->conf->ssid, sizeof(ssid)); + } else { + ssid.ssid_len = strlen(s); + if (ssid.ssid_len > sizeof(ssid.ssid)) + goto invalid; + + memcpy(&ssid, s, ssid.ssid_len); + } + + hostapd_neighbor_set(hapd, bssid, &ssid, data, NULL, NULL, 0, 0); + wpabuf_free(data); + continue; + +invalid: + return UBUS_STATUS_INVALID_ARGUMENT; + } + + return 0; +} + +enum { + BEACON_REQ_ADDR, + BEACON_REQ_MODE, + BEACON_REQ_OP_CLASS, + BEACON_REQ_CHANNEL, + BEACON_REQ_DURATION, + BEACON_REQ_BSSID, + BEACON_REQ_SSID, + __BEACON_REQ_MAX, +}; + +static const struct blobmsg_policy beacon_req_policy[__BEACON_REQ_MAX] = { + [BEACON_REQ_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [BEACON_REQ_OP_CLASS] { "op_class", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_CHANNEL] { "channel", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_DURATION] { "duration", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_MODE] { "mode", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_BSSID] { "bssid", BLOBMSG_TYPE_STRING }, + [BEACON_REQ_SSID] { "ssid", BLOBMSG_TYPE_STRING }, +}; + +static int +hostapd_rrm_beacon_req(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__BEACON_REQ_MAX]; + struct blob_attr *cur; + struct wpabuf *req; + u8 bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + u8 addr[ETH_ALEN]; + int mode, rem, ret; + int buf_len = 13; + + blobmsg_parse(beacon_req_policy, __BEACON_REQ_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[BEACON_REQ_ADDR] || !tb[BEACON_REQ_MODE] || !tb[BEACON_REQ_DURATION] || + !tb[BEACON_REQ_OP_CLASS] || !tb[BEACON_REQ_CHANNEL]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BEACON_REQ_SSID]) + buf_len += blobmsg_data_len(tb[BEACON_REQ_SSID]) + 2 - 1; + + mode = blobmsg_get_u32(tb[BEACON_REQ_MODE]); + if (hwaddr_aton(blobmsg_data(tb[BEACON_REQ_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BEACON_REQ_BSSID] && + hwaddr_aton(blobmsg_data(tb[BEACON_REQ_BSSID]), bssid)) + return UBUS_STATUS_INVALID_ARGUMENT; + + req = wpabuf_alloc(buf_len); + if (!req) + return UBUS_STATUS_UNKNOWN_ERROR; + + /* 1: regulatory class */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_OP_CLASS])); + + /* 2: channel number */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_CHANNEL])); + + /* 3-4: randomization interval */ + wpabuf_put_le16(req, 0); + + /* 5-6: duration */ + wpabuf_put_le16(req, blobmsg_get_u32(tb[BEACON_REQ_DURATION])); + + /* 7: mode */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_MODE])); + + /* 8-13: BSSID */ + wpabuf_put_data(req, bssid, ETH_ALEN); + + if ((cur = tb[BEACON_REQ_SSID]) != NULL) { + wpabuf_put_u8(req, WLAN_EID_SSID); + wpabuf_put_u8(req, blobmsg_data_len(cur) - 1); + wpabuf_put_data(req, blobmsg_data(cur), blobmsg_data_len(cur) - 1); + } + + ret = hostapd_send_beacon_req(hapd, addr, 0, req); + if (ret < 0) + return -ret; + + return 0; +} + + +#ifdef CONFIG_WNM_AP + +static int +hostapd_bss_tr_send(struct hostapd_data *hapd, u8 *addr, bool disassoc_imminent, bool abridged, + u16 disassoc_timer, u8 validity_period, u8 dialog_token, + struct blob_attr *neighbors) +{ + struct blob_attr *cur; + struct sta_info *sta; + int nr_len = 0; + int rem; + u8 *nr = NULL; + u8 req_mode = 0; + + sta = ap_get_sta(hapd, addr); + if (!sta) + return UBUS_STATUS_NOT_FOUND; + + if (neighbors) { + u8 *nr_cur; + + if (blobmsg_check_array(neighbors, + BLOBMSG_TYPE_STRING) < 0) + return UBUS_STATUS_INVALID_ARGUMENT; + + blobmsg_for_each_attr(cur, neighbors, rem) { + int len = strlen(blobmsg_get_string(cur)); + + if (len % 2) + return UBUS_STATUS_INVALID_ARGUMENT; + + nr_len += (len / 2) + 2; + } + + if (nr_len) { + nr = os_zalloc(nr_len); + if (!nr) + return UBUS_STATUS_UNKNOWN_ERROR; + } + + nr_cur = nr; + blobmsg_for_each_attr(cur, neighbors, rem) { + int len = strlen(blobmsg_get_string(cur)) / 2; + + *nr_cur++ = WLAN_EID_NEIGHBOR_REPORT; + *nr_cur++ = (u8) len; + if (hexstr2bin(blobmsg_data(cur), nr_cur, len)) { + free(nr); + return UBUS_STATUS_INVALID_ARGUMENT; + } + + nr_cur += len; + } + } + + if (nr) + req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED; + + if (abridged) + req_mode |= WNM_BSS_TM_REQ_ABRIDGED; + + if (disassoc_imminent) + req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT; + + if (wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer, validity_period, NULL, + dialog_token, NULL, nr, nr_len, NULL, 0)) + return UBUS_STATUS_UNKNOWN_ERROR; + + return 0; +} + +enum { + BSS_TR_ADDR, + BSS_TR_DA_IMMINENT, + BSS_TR_DA_TIMER, + BSS_TR_VALID_PERIOD, + BSS_TR_NEIGHBORS, + BSS_TR_ABRIDGED, + BSS_TR_DIALOG_TOKEN, + __BSS_TR_DISASSOC_MAX +}; + +static const struct blobmsg_policy bss_tr_policy[__BSS_TR_DISASSOC_MAX] = { + [BSS_TR_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [BSS_TR_DA_IMMINENT] = { "disassociation_imminent", BLOBMSG_TYPE_BOOL }, + [BSS_TR_DA_TIMER] = { "disassociation_timer", BLOBMSG_TYPE_INT32 }, + [BSS_TR_VALID_PERIOD] = { "validity_period", BLOBMSG_TYPE_INT32 }, + [BSS_TR_NEIGHBORS] = { "neighbors", BLOBMSG_TYPE_ARRAY }, + [BSS_TR_ABRIDGED] = { "abridged", BLOBMSG_TYPE_BOOL }, + [BSS_TR_DIALOG_TOKEN] = { "dialog_token", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_transition_request(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__BSS_TR_DISASSOC_MAX]; + struct sta_info *sta; + u32 da_timer = 0; + u32 valid_period = 0; + u8 addr[ETH_ALEN]; + u32 dialog_token = 1; + bool abridged; + bool da_imminent; + + blobmsg_parse(bss_tr_policy, __BSS_TR_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[BSS_TR_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[BSS_TR_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BSS_TR_DA_TIMER]) + da_timer = blobmsg_get_u32(tb[BSS_TR_DA_TIMER]); + + if (tb[BSS_TR_VALID_PERIOD]) + valid_period = blobmsg_get_u32(tb[BSS_TR_VALID_PERIOD]); + + if (tb[BSS_TR_DIALOG_TOKEN]) + dialog_token = blobmsg_get_u32(tb[BSS_TR_DIALOG_TOKEN]); + + da_imminent = !!(tb[BSS_TR_DA_IMMINENT] && blobmsg_get_bool(tb[BSS_TR_DA_IMMINENT])); + abridged = !!(tb[BSS_TR_ABRIDGED] && blobmsg_get_bool(tb[BSS_TR_ABRIDGED])); + + return hostapd_bss_tr_send(hapd, addr, da_imminent, abridged, da_timer, valid_period, + dialog_token, tb[BSS_TR_NEIGHBORS]); +} + +enum { + WNM_DISASSOC_ADDR, + WNM_DISASSOC_DURATION, + WNM_DISASSOC_NEIGHBORS, + WNM_DISASSOC_ABRIDGED, + __WNM_DISASSOC_MAX, +}; + +static const struct blobmsg_policy wnm_disassoc_policy[__WNM_DISASSOC_MAX] = { + [WNM_DISASSOC_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [WNM_DISASSOC_DURATION] { "duration", BLOBMSG_TYPE_INT32 }, + [WNM_DISASSOC_NEIGHBORS] { "neighbors", BLOBMSG_TYPE_ARRAY }, + [WNM_DISASSOC_ABRIDGED] { "abridged", BLOBMSG_TYPE_BOOL }, +}; + +static int +hostapd_wnm_disassoc_imminent(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__WNM_DISASSOC_MAX]; + struct sta_info *sta; + int duration = 10; + u8 addr[ETH_ALEN]; + bool abridged; + + blobmsg_parse(wnm_disassoc_policy, __WNM_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[WNM_DISASSOC_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[WNM_DISASSOC_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[WNM_DISASSOC_DURATION]) + duration = blobmsg_get_u32(tb[WNM_DISASSOC_DURATION]); + + abridged = !!(tb[WNM_DISASSOC_ABRIDGED] && blobmsg_get_bool(tb[WNM_DISASSOC_ABRIDGED])); + + return hostapd_bss_tr_send(hapd, addr, true, abridged, duration, duration, + 1, tb[WNM_DISASSOC_NEIGHBORS]); +} +#endif + +#ifdef CONFIG_AIRTIME_POLICY +enum { + UPDATE_AIRTIME_STA, + UPDATE_AIRTIME_WEIGHT, + __UPDATE_AIRTIME_MAX, +}; + + +static const struct blobmsg_policy airtime_policy[__UPDATE_AIRTIME_MAX] = { + [UPDATE_AIRTIME_STA] = { "sta", BLOBMSG_TYPE_STRING }, + [UPDATE_AIRTIME_WEIGHT] = { "weight", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_update_airtime(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__UPDATE_AIRTIME_MAX]; + struct sta_info *sta = NULL; + u8 addr[ETH_ALEN]; + int weight; + + blobmsg_parse(airtime_policy, __UPDATE_AIRTIME_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[UPDATE_AIRTIME_WEIGHT]) + return UBUS_STATUS_INVALID_ARGUMENT; + + weight = blobmsg_get_u32(tb[UPDATE_AIRTIME_WEIGHT]); + + if (!tb[UPDATE_AIRTIME_STA]) { + if (!weight) + return UBUS_STATUS_INVALID_ARGUMENT; + + hapd->conf->airtime_weight = weight; + return 0; + } + + if (hwaddr_aton(blobmsg_data(tb[UPDATE_AIRTIME_STA]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + sta = ap_get_sta(hapd, addr); + if (!sta) + return UBUS_STATUS_NOT_FOUND; + + sta->dyn_airtime_weight = weight; + airtime_policy_new_sta(hapd, sta); + + return 0; +} +#endif + + +static const struct ubus_method bss_methods[] = { + UBUS_METHOD_NOARG("reload", hostapd_bss_reload), + UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients), + UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status), + UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy), +#ifdef CONFIG_AIRTIME_POLICY + UBUS_METHOD("update_airtime", hostapd_bss_update_airtime, airtime_policy), +#endif + UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans), +#ifdef CONFIG_WPS + UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start), + UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status), + UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel), +#endif + UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon), + UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features), +#ifdef NEED_AP_MLME + UBUS_METHOD("switch_chan", hostapd_switch_chan, csa_policy), +#endif + UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements, ve_policy), + UBUS_METHOD("notify_response", hostapd_notify_response, notify_policy), + UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable, bss_mgmt_enable_policy), + UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own), + UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list), + UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set, nr_set_policy), + UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req, beacon_req_policy), +#ifdef CONFIG_WNM_AP + UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent, wnm_disassoc_policy), + UBUS_METHOD("bss_transition_request", hostapd_bss_transition_request, bss_tr_policy), +#endif +}; + +static struct ubus_object_type bss_object_type = + UBUS_OBJECT_TYPE("hostapd_bss", bss_methods); + +static int avl_compare_macaddr(const void *k1, const void *k2, void *ptr) +{ + return memcmp(k1, k2, ETH_ALEN); +} + +void hostapd_ubus_add_bss(struct hostapd_data *hapd) +{ + struct ubus_object *obj = &hapd->ubus.obj; + char *name; + int ret; + +#ifdef CONFIG_MESH + if (hapd->conf->mesh & MESH_ENABLED) + return; +#endif + + if (!hostapd_ubus_init()) + return; + + if (asprintf(&name, "hostapd.%s", hapd->conf->iface) < 0) + return; + + avl_init(&hapd->ubus.banned, avl_compare_macaddr, false, NULL); + obj->name = name; + obj->type = &bss_object_type; + obj->methods = bss_object_type.methods; + obj->n_methods = bss_object_type.n_methods; + ret = ubus_add_object(ctx, obj); + hostapd_ubus_ref_inc(); +} + +void hostapd_ubus_free_bss(struct hostapd_data *hapd) +{ + struct ubus_object *obj = &hapd->ubus.obj; + char *name = (char *) obj->name; + +#ifdef CONFIG_MESH + if (hapd->conf->mesh & MESH_ENABLED) + return; +#endif + + if (!ctx) + return; + + if (obj->id) { + ubus_remove_object(ctx, obj); + hostapd_ubus_ref_dec(); + } + + free(name); +} + +static void +hostapd_ubus_vlan_action(struct hostapd_data *hapd, struct hostapd_vlan *vlan, + const char *action) +{ + struct vlan_description *desc = &vlan->vlan_desc; + void *c; + int i; + + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "ifname", vlan->ifname); + blobmsg_add_string(&b, "bridge", vlan->bridge); + blobmsg_add_u32(&b, "vlan_id", vlan->vlan_id); + + if (desc->notempty) { + blobmsg_add_u32(&b, "untagged", desc->untagged); + c = blobmsg_open_array(&b, "tagged"); + for (i = 0; i < ARRAY_SIZE(desc->tagged) && desc->tagged[i]; i++) + blobmsg_add_u32(&b, "", desc->tagged[i]); + blobmsg_close_array(&b, c); + } + + ubus_notify(ctx, &hapd->ubus.obj, action, b.head, -1); +} + +void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) +{ + hostapd_ubus_vlan_action(hapd, vlan, "vlan_add"); +} + +void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) +{ + hostapd_ubus_vlan_action(hapd, vlan, "vlan_remove"); +} + +struct ubus_event_req { + struct ubus_notify_request nreq; + int resp; +}; + +static void +ubus_event_cb(struct ubus_notify_request *req, int idx, int ret) +{ + struct ubus_event_req *ureq = container_of(req, struct ubus_event_req, nreq); + + ureq->resp = ret; +} + +int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req) +{ + struct ubus_banned_client *ban; + const char *types[HOSTAPD_UBUS_TYPE_MAX] = { + [HOSTAPD_UBUS_PROBE_REQ] = "probe", + [HOSTAPD_UBUS_AUTH_REQ] = "auth", + [HOSTAPD_UBUS_ASSOC_REQ] = "assoc", + }; + const char *type = "mgmt"; + struct ubus_event_req ureq = {}; + const u8 *addr; + + if (req->mgmt_frame) + addr = req->mgmt_frame->sa; + else + addr = req->addr; + + ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl); + if (ban) + return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; + + if (!hapd->ubus.obj.has_subscribers) + return WLAN_STATUS_SUCCESS; + + if (req->type < ARRAY_SIZE(types)) + type = types[req->type]; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + if (req->mgmt_frame) + blobmsg_add_macaddr(&b, "target", req->mgmt_frame->da); + if (req->ssi_signal) + blobmsg_add_u32(&b, "signal", req->ssi_signal); + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + + if (req->elems) { + if(req->elems->ht_capabilities) + { + struct ieee80211_ht_capabilities *ht_capabilities; + void *ht_cap, *ht_cap_mcs_set, *mcs_set; + + + ht_capabilities = (struct ieee80211_ht_capabilities*) req->elems->ht_capabilities; + ht_cap = blobmsg_open_table(&b, "ht_capabilities"); + blobmsg_add_u16(&b, "ht_capabilities_info", ht_capabilities->ht_capabilities_info); + ht_cap_mcs_set = blobmsg_open_table(&b, "supported_mcs_set"); + blobmsg_add_u16(&b, "a_mpdu_params", ht_capabilities->a_mpdu_params); + blobmsg_add_u16(&b, "ht_extended_capabilities", ht_capabilities->ht_extended_capabilities); + blobmsg_add_u32(&b, "tx_bf_capability_info", ht_capabilities->tx_bf_capability_info); + blobmsg_add_u16(&b, "asel_capabilities", ht_capabilities->asel_capabilities); + mcs_set = blobmsg_open_array(&b, "supported_mcs_set"); + for (int i = 0; i < 16; i++) { + blobmsg_add_u16(&b, NULL, (u16) ht_capabilities->supported_mcs_set[i]); + } + blobmsg_close_array(&b, mcs_set); + blobmsg_close_table(&b, ht_cap_mcs_set); + blobmsg_close_table(&b, ht_cap); + } + if(req->elems->vht_capabilities) + { + struct ieee80211_vht_capabilities *vht_capabilities; + void *vht_cap, *vht_cap_mcs_set; + + vht_capabilities = (struct ieee80211_vht_capabilities*) req->elems->vht_capabilities; + vht_cap = blobmsg_open_table(&b, "vht_capabilities"); + blobmsg_add_u32(&b, "vht_capabilities_info", vht_capabilities->vht_capabilities_info); + vht_cap_mcs_set = blobmsg_open_table(&b, "vht_supported_mcs_set"); + blobmsg_add_u16(&b, "rx_map", vht_capabilities->vht_supported_mcs_set.rx_map); + blobmsg_add_u16(&b, "rx_highest", vht_capabilities->vht_supported_mcs_set.rx_highest); + blobmsg_add_u16(&b, "tx_map", vht_capabilities->vht_supported_mcs_set.tx_map); + blobmsg_add_u16(&b, "tx_highest", vht_capabilities->vht_supported_mcs_set.tx_highest); + blobmsg_close_table(&b, vht_cap_mcs_set); + blobmsg_close_table(&b, vht_cap); + } + } + + if (!hapd->ubus.notify_response) { + ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); + return WLAN_STATUS_SUCCESS; + } + + if (ubus_notify_async(ctx, &hapd->ubus.obj, type, b.head, &ureq.nreq)) + return WLAN_STATUS_SUCCESS; + + ureq.nreq.status_cb = ubus_event_cb; + ubus_complete_request(ctx, &ureq.nreq.req, 100); + + if (ureq.resp) + return ureq.resp; + + return WLAN_STATUS_SUCCESS; +} + +void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *addr) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + + ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); +} + + +void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", sta->addr); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + if (sta->bandwidth[0] || sta->bandwidth[1]) { + void *r = blobmsg_open_array(&b, "rate-limit"); + + blobmsg_add_u32(&b, "", sta->bandwidth[0]); + blobmsg_add_u32(&b, "", sta->bandwidth[1]); + blobmsg_close_array(&b, r); + } + + ubus_notify(ctx, &hapd->ubus.obj, "sta-authorized", b.head, -1); +} + +void hostapd_ubus_notify_beacon_report( + struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, + struct rrm_measurement_beacon_report *rep, size_t len) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr || !rep) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u16(&b, "op-class", rep->op_class); + blobmsg_add_u16(&b, "channel", rep->channel); + blobmsg_add_u64(&b, "start-time", rep->start_time); + blobmsg_add_u16(&b, "duration", rep->duration); + blobmsg_add_u16(&b, "report-info", rep->report_info); + blobmsg_add_u16(&b, "rcpi", rep->rcpi); + blobmsg_add_u16(&b, "rsni", rep->rsni); + blobmsg_add_macaddr(&b, "bssid", rep->bssid); + blobmsg_add_u16(&b, "antenna-id", rep->antenna_id); + blobmsg_add_u16(&b, "parent-tsf", rep->parent_tsf); + + ubus_notify(ctx, &hapd->ubus.obj, "beacon-report", b.head, -1); +} + +void hostapd_ubus_notify_radar_detected(struct hostapd_iface *iface, int frequency, + int chan_width, int cf1, int cf2) +{ + struct hostapd_data *hapd; + int i; + + blob_buf_init(&b, 0); + blobmsg_add_u16(&b, "frequency", frequency); + blobmsg_add_u16(&b, "width", chan_width); + blobmsg_add_u16(&b, "center1", cf1); + blobmsg_add_u16(&b, "center2", cf2); + + for (i = 0; i < iface->num_bss; i++) { + hapd = iface->bss[i]; + ubus_notify(ctx, &hapd->ubus.obj, "radar-detected", b.head, -1); + } +} + +#ifdef CONFIG_WNM_AP +static void hostapd_ubus_notify_bss_transition_add_candidate_list( + const u8 *candidate_list, u16 candidate_list_len) +{ + char *cl_str; + int i; + + if (candidate_list_len == 0) + return; + + cl_str = blobmsg_alloc_string_buffer(&b, "candidate-list", candidate_list_len * 2 + 1); + for (i = 0; i < candidate_list_len; i++) + snprintf(&cl_str[i*2], 3, "%02X", candidate_list[i]); + blobmsg_add_string_buffer(&b); + +} +#endif + +void hostapd_ubus_notify_bss_transition_response( + struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 status_code, + u8 bss_termination_delay, const u8 *target_bssid, + const u8 *candidate_list, u16 candidate_list_len) +{ +#ifdef CONFIG_WNM_AP + u16 i; + + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u8(&b, "dialog-token", dialog_token); + blobmsg_add_u8(&b, "status-code", status_code); + blobmsg_add_u8(&b, "bss-termination-delay", bss_termination_delay); + if (target_bssid) + blobmsg_add_macaddr(&b, "target-bssid", target_bssid); + + hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list, candidate_list_len); + + ubus_notify(ctx, &hapd->ubus.obj, "bss-transition-response", b.head, -1); +#endif +} + +int hostapd_ubus_notify_bss_transition_query( + struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, + const u8 *candidate_list, u16 candidate_list_len) +{ +#ifdef CONFIG_WNM_AP + struct ubus_event_req ureq = {}; + char *cl_str; + u16 i; + + if (!hapd->ubus.obj.has_subscribers) + return 0; + + if (!addr) + return 0; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u8(&b, "dialog-token", dialog_token); + blobmsg_add_u8(&b, "reason", reason); + hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list, candidate_list_len); + + if (!hapd->ubus.notify_response) { + ubus_notify(ctx, &hapd->ubus.obj, "bss-transition-query", b.head, -1); + return 0; + } + + if (ubus_notify_async(ctx, &hapd->ubus.obj, "bss-transition-query", b.head, &ureq.nreq)) + return 0; + + ureq.nreq.status_cb = ubus_event_cb; + ubus_complete_request(ctx, &ureq.nreq.req, 100); + + return ureq.resp; +#endif +} From 970b22856fb56a91184e1996c412a0b872acff82 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 14 Sep 2023 13:39:45 +0200 Subject: [PATCH 20/32] mac80211: fix reconfiguration on DFS channels in non-ETSI regdomains Signed-off-by: Felix Fietkau --- ...race-period-for-DFS-available-after-.patch | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 feeds/wifi-ax/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch diff --git a/feeds/wifi-ax/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch b/feeds/wifi-ax/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch new file mode 100644 index 000000000..aab3e6381 --- /dev/null +++ b/feeds/wifi-ax/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch @@ -0,0 +1,148 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 13:17:16 +0200 +Subject: [PATCH] cfg80211: allow grace period for DFS available after beacon + shutdown + +Fixes reconfiguring an AP on a DFS channel in non-ETSI regdomain + +Fixes: b35a51c7dd25 ("cfg80211: Make pre-CAC results valid only for ETSI domain") +Signed-off-by: Felix Fietkau +--- + +--- a/include/net/cfg80211.h ++++ b/include/net/cfg80211.h +@@ -162,6 +162,8 @@ enum ieee80211_channel_flags { + * @dfs_state: current state of this channel. Only relevant if radar is required + * on this channel. + * @dfs_state_entered: timestamp (jiffies) when the dfs state was entered. ++ * @dfs_state_last_available: timestamp (jiffies) of the last time when the ++ * channel was available. + * @dfs_cac_ms: DFS CAC time in milliseconds, this is valid for DFS channels. + */ + struct ieee80211_channel { +@@ -178,6 +180,7 @@ struct ieee80211_channel { + int orig_mag, orig_mpwr; + enum nl80211_dfs_state dfs_state; + unsigned long dfs_state_entered; ++ unsigned long dfs_state_last_available; + unsigned int dfs_cac_ms; + }; + +--- a/net/wireless/ap.c ++++ b/net/wireless/ap.c +@@ -25,6 +25,8 @@ int __cfg80211_stop_ap(struct cfg80211_r + if (!wdev->beacon_interval) + return -ENOENT; + ++ cfg80211_update_last_available(wdev->wiphy, &wdev->chandef); ++ + err = rdev_stop_ap(rdev, dev); + if (!err) { + wdev->conn_owner_nlportid = 0; +@@ -35,9 +37,6 @@ int __cfg80211_stop_ap(struct cfg80211_r + if (notify) + nl80211_send_ap_stopped(wdev); + +- /* Should we apply the grace period during beaconing interface +- * shutdown also? +- */ + cfg80211_sched_dfs_chan_update(rdev); + } + +--- a/net/wireless/chan.c ++++ b/net/wireless/chan.c +@@ -411,6 +411,8 @@ static void cfg80211_set_chans_dfs_state + + c->dfs_state = dfs_state; + c->dfs_state_entered = jiffies; ++ if (dfs_state == NL80211_DFS_AVAILABLE) ++ c->dfs_state_last_available = jiffies; + } + } + +@@ -769,6 +771,49 @@ static bool cfg80211_get_chans_dfs_avail + return true; + } + ++static void ++__cfg80211_update_last_available(struct wiphy *wiphy, ++ u32 center_freq, ++ u32 bandwidth) ++{ ++ struct ieee80211_channel *c; ++ u32 freq, start_freq, end_freq; ++ ++ start_freq = cfg80211_get_start_freq(center_freq, bandwidth); ++ end_freq = cfg80211_get_end_freq(center_freq, bandwidth); ++ ++ /* ++ * Check entire range of channels for the bandwidth. ++ * If any channel in between is disabled or has not ++ * had gone through CAC return false ++ */ ++ for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { ++ c = ieee80211_get_channel_khz(wiphy, freq); ++ if (!c) ++ return; ++ ++ c->dfs_state_last_available = jiffies; ++ } ++} ++ ++void cfg80211_update_last_available(struct wiphy *wiphy, ++ const struct cfg80211_chan_def *chandef) ++{ ++ int width; ++ ++ width = cfg80211_chandef_get_width(chandef); ++ if (width < 0) ++ return; ++ ++ __cfg80211_update_last_available(wiphy, MHZ_TO_KHZ(chandef->center_freq1), ++ width); ++ if (chandef->width != NL80211_CHAN_WIDTH_80P80) ++ return; ++ ++ __cfg80211_update_last_available(wiphy, MHZ_TO_KHZ(chandef->center_freq2), ++ width); ++} ++ + static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy, + const struct cfg80211_chan_def *chandef) + { +--- a/net/wireless/core.h ++++ b/net/wireless/core.h +@@ -483,6 +483,8 @@ void cfg80211_set_dfs_state(struct wiphy + enum nl80211_dfs_state dfs_state); + + void cfg80211_dfs_channels_update_work(struct work_struct *work); ++void cfg80211_update_last_available(struct wiphy *wiphy, ++ const struct cfg80211_chan_def *chandef); + + unsigned int + cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, +--- a/net/wireless/mlme.c ++++ b/net/wireless/mlme.c +@@ -858,6 +858,8 @@ void cfg80211_dfs_channels_update_work(s + if (c->dfs_state == NL80211_DFS_UNAVAILABLE) { + time_dfs_update = IEEE80211_DFS_MIN_NOP_TIME_MS; + radar_event = NL80211_RADAR_NOP_FINISHED; ++ timeout = c->dfs_state_entered + ++ msecs_to_jiffies(time_dfs_update); + } else { + if (regulatory_pre_cac_allowed(wiphy) || + cfg80211_any_wiphy_oper_chan(wiphy, c)) +@@ -865,11 +867,10 @@ void cfg80211_dfs_channels_update_work(s + + time_dfs_update = REG_PRE_CAC_EXPIRY_GRACE_MS; + radar_event = NL80211_RADAR_PRE_CAC_EXPIRED; ++ timeout = c->dfs_state_last_available + ++ msecs_to_jiffies(time_dfs_update); + } + +- timeout = c->dfs_state_entered + +- msecs_to_jiffies(time_dfs_update); +- + if (time_after_eq(jiffies, timeout)) { + c->dfs_state = NL80211_DFS_USABLE; + c->dfs_state_entered = jiffies; From 9a6e41adb843a2a107af769059c634846659d6ae Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 14 Sep 2023 13:40:27 +0200 Subject: [PATCH 21/32] hostapd: fix ucode reload issues Signed-off-by: Felix Fietkau --- ...d-frequency-info-in-start-AP-command.patch | 43 +++++++++++++++++++ ...ix-setting-QoS-map-on-secondary-BSSs.patch | 20 +++++++++ ...pdate-drv-ifindex-on-removing-the-fi.patch | 18 ++++++++ 3 files changed, 81 insertions(+) create mode 100644 feeds/wifi-ax/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch create mode 100644 feeds/wifi-ax/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch create mode 100644 feeds/wifi-ax/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch diff --git a/feeds/wifi-ax/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch b/feeds/wifi-ax/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch new file mode 100644 index 000000000..ebe0ef12a --- /dev/null +++ b/feeds/wifi-ax/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch @@ -0,0 +1,43 @@ +From: Harshitha Prem +Date: Wed, 22 Feb 2023 09:29:01 +0530 +Subject: [PATCH] nl80211: Add frequency info in start AP command + +When ACS is configured in multiple BSS case, sometimes a virtual AP +interface does not come up as the channel context information between +different BSSs of the same band does not match. + +Same behavior is observed in case of multiple band/hardware under a +single wiphy, when we bring up multiple virtual interface in various +bands simultaneously and the kernel maps a random channel as it has more +than one channel context, e.g., say a 2.4 GHz channel to a 5 GHz virtual +AP interface when the start AP command is sent. This is because the +frequency information is not present in the command. + +Add the frequency information into the start AP netlink command so that +the kernel maps the appropriate channel context by parsing it instead of +using a previous set channel information. + +Signed-off-by: Harshitha Prem +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -167,6 +167,8 @@ static int nl80211_send_frame_cmd(struct + const u16 *csa_offs, size_t csa_offs_len); + static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, + int report); ++static int nl80211_put_freq_params(struct nl_msg *msg, ++ const struct hostapd_freq_params *freq); + + #define IFIDX_ANY -1 + +@@ -4717,6 +4719,9 @@ static int wpa_driver_nl80211_set_ap(voi + nla_nest_end(msg, spr); + } + ++ if (params->freq && nl80211_put_freq_params(msg, params->freq) < 0) ++ goto fail; ++ + if (params->freq && params->freq->he_enabled) { + struct nlattr *bss_color; + diff --git a/feeds/wifi-ax/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch b/feeds/wifi-ax/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch new file mode 100644 index 000000000..f30159840 --- /dev/null +++ b/feeds/wifi-ax/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch @@ -0,0 +1,20 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 10:53:50 +0200 +Subject: [PATCH] driver_nl80211: fix setting QoS map on secondary BSSs + +The setting is per-BSS, not per PHY + +Signed-off-by: Felix Fietkau +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -10045,7 +10045,7 @@ static int nl80211_set_qos_map(void *pri + wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", + qos_map_set, qos_map_set_len); + +- if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || ++ if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_QOS_MAP)) || + nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { + nlmsg_free(msg); + return -ENOBUFS; diff --git a/feeds/wifi-ax/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch b/feeds/wifi-ax/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch new file mode 100644 index 000000000..a1a5b2821 --- /dev/null +++ b/feeds/wifi-ax/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch @@ -0,0 +1,18 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 11:28:03 +0200 +Subject: [PATCH] driver_nl80211: update drv->ifindex on removing the first + BSS + +Signed-off-by: Felix Fietkau +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -8003,6 +8003,7 @@ static int wpa_driver_nl80211_if_remove( + if (drv->first_bss->next) { + drv->first_bss = drv->first_bss->next; + drv->ctx = drv->first_bss->ctx; ++ drv->ifindex = drv->first_bss->ifindex; + os_free(bss); + } else { + wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); From 018f20119daaafac18e9029c4ff721dde4d11759 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 15 Sep 2023 15:01:44 +0200 Subject: [PATCH 22/32] netifd: add wireless vlan/sta fix Signed-off-by: Felix Fietkau --- .../patches/400-wireless_vlan_fix.patch | 587 ++++++++++++++++++ 1 file changed, 587 insertions(+) create mode 100644 package/network/config/netifd/patches/400-wireless_vlan_fix.patch diff --git a/package/network/config/netifd/patches/400-wireless_vlan_fix.patch b/package/network/config/netifd/patches/400-wireless_vlan_fix.patch new file mode 100644 index 000000000..449121dd3 --- /dev/null +++ b/package/network/config/netifd/patches/400-wireless_vlan_fix.patch @@ -0,0 +1,587 @@ +--- a/config.c ++++ b/config.c +@@ -557,8 +557,8 @@ config_parse_wireless_device(struct uci_ + wireless_device_create(drv, s->e.name, b.head); + } + +-static struct wireless_interface* +-config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s) ++static void ++config_parse_wireless_vlan(struct wireless_interface *vif, struct uci_section *s) + { + char *name; + +@@ -566,12 +566,12 @@ config_parse_wireless_interface(struct w + sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); + + blob_buf_init(&b, 0); +- uci_to_blob(&b, s, wdev->drv->interface.config); +- return wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name); ++ uci_to_blob(&b, s, vif->wdev->drv->vlan.config); ++ wireless_vlan_create(vif, b.head, s->anonymous ? name : s->e.name); + } + + static void +-config_parse_wireless_vlan(struct wireless_device *wdev, char *vif, struct uci_section *s) ++config_parse_wireless_station(struct wireless_interface *vif, struct uci_section *s) + { + char *name; + +@@ -579,21 +579,62 @@ config_parse_wireless_vlan(struct wirele + sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); + + blob_buf_init(&b, 0); +- uci_to_blob(&b, s, wdev->drv->vlan.config); +- wireless_vlan_create(wdev, vif, b.head, s->anonymous ? name : s->e.name); ++ uci_to_blob(&b, s, vif->wdev->drv->station.config); ++ wireless_station_create(vif, b.head, s->anonymous ? name : s->e.name); + } + + static void +-config_parse_wireless_station(struct wireless_device *wdev, char *vif, struct uci_section *s) ++config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s) + { ++ struct wireless_interface *vif; ++ struct uci_element *f; + char *name; + + name = alloca(strlen(s->type) + 16); + sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); + + blob_buf_init(&b, 0); +- uci_to_blob(&b, s, wdev->drv->station.config); +- wireless_station_create(wdev, vif, b.head, s->anonymous ? name : s->e.name); ++ uci_to_blob(&b, s, wdev->drv->interface.config); ++ vif = wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name); ++ if (!vif) ++ return; ++ ++ vif->vlan_idx = vif->sta_idx = 0; ++ vlist_update(&vif->vlans); ++ vlist_update(&vif->stations); ++ ++ if (s->anonymous) ++ goto out; ++ ++ uci_foreach_element(&uci_wireless->sections, f) { ++ struct uci_section *cur = uci_to_section(f); ++ const char *vif_name; ++ ++ if (strcmp(cur->type, "wifi-vlan") != 0) ++ continue; ++ ++ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface"); ++ if (vif_name && strcmp(s->e.name, vif_name)) ++ continue; ++ config_parse_wireless_vlan(vif, cur); ++ } ++ ++ uci_foreach_element(&uci_wireless->sections, f) { ++ struct uci_section *cur = uci_to_section(f); ++ const char *vif_name; ++ ++ if (strcmp(cur->type, "wifi-station") != 0) ++ continue; ++ ++ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface"); ++ if (vif_name && strcmp(s->e.name, vif_name)) ++ continue; ++ config_parse_wireless_station(vif, cur); ++ } ++ ++out: ++ vlist_flush(&vif->vlans); ++ vlist_flush(&vif->stations); + } + + static void +@@ -623,16 +664,10 @@ config_init_wireless(void) + vlist_for_each_element(&wireless_devices, wdev, node) { + wdev->vif_idx = 0; + vlist_update(&wdev->interfaces); +- wdev->vlan_idx = 0; +- vlist_update(&wdev->vlans); +- wdev->sta_idx = 0; +- vlist_update(&wdev->stations); + } + + uci_foreach_element(&uci_wireless->sections, e) { + struct uci_section *s = uci_to_section(e); +- struct wireless_interface *vif; +- struct uci_element *f; + + if (strcmp(s->type, "wifi-iface") != 0) + continue; +@@ -647,42 +682,11 @@ config_init_wireless(void) + continue; + } + +- vif = config_parse_wireless_interface(wdev, s); +- +- if (!vif || s->anonymous) +- continue; +- uci_foreach_element(&uci_wireless->sections, f) { +- struct uci_section *s = uci_to_section(f); +- const char *vif_name; +- +- if (strcmp(s->type, "wifi-vlan") != 0) +- continue; +- +- vif_name = uci_lookup_option_string(uci_ctx, s, "iface"); +- if (vif_name && strcmp(e->name, vif_name)) +- continue; +- config_parse_wireless_vlan(wdev, vif->name, s); +- } +- +- uci_foreach_element(&uci_wireless->sections, f) { +- struct uci_section *s = uci_to_section(f); +- const char *vif_name; +- +- if (strcmp(s->type, "wifi-station") != 0) +- continue; +- +- vif_name = uci_lookup_option_string(uci_ctx, s, "iface"); +- if (vif_name && strcmp(e->name, vif_name)) +- continue; +- config_parse_wireless_station(wdev, vif->name, s); +- } ++ config_parse_wireless_interface(wdev, s); + } + +- vlist_for_each_element(&wireless_devices, wdev, node) { ++ vlist_for_each_element(&wireless_devices, wdev, node) + vlist_flush(&wdev->interfaces); +- vlist_flush(&wdev->vlans); +- vlist_flush(&wdev->stations); +- } + } + + +--- a/scripts/netifd-wireless.sh ++++ b/scripts/netifd-wireless.sh +@@ -108,14 +108,16 @@ _wdev_wrapper() { + } + + _wdev_notify_init() { +- local command="$1" +- local name="$2" +- local value="$3" ++ local command="$1"; shift; + + json_init + json_add_int "command" "$command" + json_add_string "device" "$__netifd_device" +- [ -n "$name" -a -n "$value" ] && json_add_string "$name" "$value" ++ while [ -n "$1" ]; do ++ local name="$1"; shift ++ local value="$1"; shift ++ json_add_string "$name" "$value" ++ done + json_add_object "data" + } + +@@ -151,7 +153,7 @@ _wireless_add_vlan() { + local name="$1"; shift + local ifname="$1"; shift + +- _wdev_notify_init $CMD_SET_DATA "vlan" "$name" ++ _wdev_notify_init $CMD_SET_DATA interface "$__cur_interface" "vlan" "$name" + json_add_string "ifname" "$ifname" + _wdev_add_variables "$@" + _wdev_notify +@@ -333,6 +335,7 @@ for_each_interface() { + continue + } + fi ++ __cur_interface="$_w_iface" + "$@" "$_w_iface" + json_select .. + done +--- a/wireless.c ++++ b/wireless.c +@@ -205,9 +205,7 @@ prepare_config(struct wireless_device *w + blobmsg_add_blob(&b, vif->data); + + j = blobmsg_open_table(&b, "vlans"); +- vlist_for_each_element(&wdev->vlans, vlan, node) { +- if (strcmp(vlan->vif, vif->name)) +- continue; ++ vlist_for_each_element(&vif->vlans, vlan, node) { + k = blobmsg_open_table(&b, vlan->name); + vif_config_add_bridge(&b, vlan->network, up); + put_container(&b, vlan->config, "config"); +@@ -218,9 +216,7 @@ prepare_config(struct wireless_device *w + blobmsg_close_table(&b, j); + + j = blobmsg_open_table(&b, "stas"); +- vlist_for_each_element(&wdev->stations, sta, node) { +- if (strcmp(sta->vif, vif->name)) +- continue; ++ vlist_for_each_element(&vif->stations, sta, node) { + k = blobmsg_open_table(&b, sta->name); + put_container(&b, sta->config, "config"); + if (sta->data) +@@ -311,15 +307,15 @@ wireless_device_free_state(struct wirele + free(vif->data); + vif->data = NULL; + vif->ifname = NULL; +- } +- vlist_for_each_element(&wdev->vlans, vlan, node) { +- free(vlan->data); +- vlan->data = NULL; +- vlan->ifname = NULL; +- } +- vlist_for_each_element(&wdev->stations, sta, node) { +- free(sta->data); +- sta->data = NULL; ++ vlist_for_each_element(&vif->vlans, vlan, node) { ++ free(vlan->data); ++ vlan->data = NULL; ++ vlan->ifname = NULL; ++ } ++ vlist_for_each_element(&vif->stations, sta, node) { ++ free(sta->data); ++ sta->data = NULL; ++ } + } + } + +@@ -510,8 +506,6 @@ wireless_device_free(struct wireless_dev + { + wireless_handler_stop(wdev); + vlist_flush_all(&wdev->interfaces); +- vlist_flush_all(&wdev->vlans); +- vlist_flush_all(&wdev->stations); + avl_delete(&wireless_devices.avl, &wdev->node.avl); + free(wdev->config); + free(wdev->prev_config); +@@ -547,11 +541,12 @@ wireless_device_mark_down(struct wireles + + netifd_log_message(L_NOTICE, "Wireless device '%s' is now down\n", wdev->name); + +- vlist_for_each_element(&wdev->vlans, vlan, node) +- wireless_vlan_handle_link(vlan, false); + +- vlist_for_each_element(&wdev->interfaces, vif, node) ++ vlist_for_each_element(&wdev->interfaces, vif, node) { + wireless_interface_handle_link(vif, NULL, false); ++ vlist_for_each_element(&vif->vlans, vlan, node) ++ wireless_vlan_handle_link(vlan, false); ++ } + + wireless_process_kill_all(wdev, SIGTERM, true); + +@@ -623,10 +618,11 @@ wireless_device_mark_up(struct wireless_ + netifd_log_message(L_NOTICE, "Wireless device '%s' is now up\n", wdev->name); + wdev->retry = WIRELESS_SETUP_RETRY; + wdev->state = IFS_UP; +- vlist_for_each_element(&wdev->interfaces, vif, node) ++ vlist_for_each_element(&wdev->interfaces, vif, node) { + wireless_interface_handle_link(vif, NULL, true); +- vlist_for_each_element(&wdev->vlans, vlan, node) +- wireless_vlan_handle_link(vlan, true); ++ vlist_for_each_element(&vif->vlans, vlan, node) ++ wireless_vlan_handle_link(vlan, true); ++ } + } + + static void +@@ -848,6 +844,16 @@ wireless_interface_init_config(struct wi + vif->multicast_to_unicast = cur ? blobmsg_get_bool(cur) : -1; + } + ++static void ++vif_free(struct wireless_interface *vif) ++{ ++ vlist_flush_all(&vif->vlans); ++ vlist_flush_all(&vif->stations); ++ free((void *) vif->section); ++ free(vif->config); ++ free(vif); ++} ++ + /* vlist update call for wireless interface list */ + static void + vif_update(struct vlist_tree *tree, struct vlist_node *node_new, +@@ -884,9 +890,7 @@ vif_update(struct vlist_tree *tree, stru + } else if (vif_old) { + D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name); + wireless_interface_handle_link(vif_old, NULL, false); +- free((void *) vif_old->section); +- free(vif_old->config); +- free(vif_old); ++ vif_free(vif_old); + } + + wdev->config_update = true; +@@ -921,14 +925,10 @@ static void + vlan_update(struct vlist_tree *tree, struct vlist_node *node_new, + struct vlist_node *node_old) + { +- struct wireless_vlan *vlan_old = container_of(node_old, struct wireless_vlan, node); +- struct wireless_vlan *vlan_new = container_of(node_new, struct wireless_vlan, node); +- struct wireless_device *wdev; +- +- if (vlan_old) +- wdev = vlan_old->wdev; +- else +- wdev = vlan_new->wdev; ++ struct wireless_vlan *vlan_old = container_of_safe(node_old, struct wireless_vlan, node); ++ struct wireless_vlan *vlan_new = container_of_safe(node_new, struct wireless_vlan, node); ++ struct wireless_interface *vif = container_of(tree, struct wireless_interface, vlans); ++ struct wireless_device *wdev = vif->wdev; + + if (vlan_old && vlan_new) { + free((void *) vlan_old->section); +@@ -951,7 +951,7 @@ vlan_update(struct vlist_tree *tree, str + vlan_new->config = blob_memdup(vlan_new->config); + wireless_vlan_init_config(vlan_new); + } else if (vlan_old) { +- D(WIRELESS, "Delete wireless interface %s on device %s\n", vlan_old->name, wdev->name); ++ D(WIRELESS, "Delete wireless vlan %s on device %s\n", vlan_old->name, wdev->name); + wireless_vlan_handle_link(vlan_old, false); + free((void *) vlan_old->section); + free(vlan_old->config); +@@ -966,14 +966,10 @@ static void + station_update(struct vlist_tree *tree, struct vlist_node *node_new, + struct vlist_node *node_old) + { +- struct wireless_station *sta_old = container_of(node_old, struct wireless_station, node); +- struct wireless_station *sta_new = container_of(node_new, struct wireless_station, node); +- struct wireless_device *wdev; +- +- if (sta_old) +- wdev = sta_old->wdev; +- else +- wdev = sta_new->wdev; ++ struct wireless_station *sta_old = container_of_safe(node_old, struct wireless_station, node); ++ struct wireless_station *sta_new = container_of_safe(node_new, struct wireless_station, node); ++ struct wireless_interface *vif = container_of(tree, struct wireless_interface, stations); ++ struct wireless_device *wdev = vif->wdev; + + if (sta_old && sta_new) { + free((void *) sta_old->section); +@@ -1088,10 +1084,6 @@ wireless_device_create(struct wireless_d + INIT_LIST_HEAD(&wdev->script_proc); + vlist_init(&wdev->interfaces, avl_strcmp, vif_update); + wdev->interfaces.keep_old = true; +- vlist_init(&wdev->vlans, avl_strcmp, vlan_update); +- wdev->vlans.keep_old = true; +- vlist_init(&wdev->stations, avl_strcmp, station_update); +- wdev->stations.keep_old = true; + + wdev->timeout.cb = wireless_device_setup_timeout; + wdev->script_task.cb = wireless_device_script_task_cb; +@@ -1108,12 +1100,12 @@ wireless_device_create(struct wireless_d + + /* creates a wireless station object. Called by config */ + void +-wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section) ++wireless_station_create(struct wireless_interface *vif, struct blob_attr *data, const char *section) + { + struct wireless_station *sta; + struct blob_attr *tb[__STA_ATTR_MAX]; + struct blob_attr *cur; +- char *name_buf, *vif_buf; ++ char *name_buf; + char name[8]; + + blobmsg_parse(sta_policy, __STA_ATTR_MAX, tb, blob_data(data), blob_len(data)); +@@ -1122,18 +1114,15 @@ wireless_station_create(struct wireless_ + if (cur && blobmsg_get_bool(cur)) + return; + +- sprintf(name, "%d", wdev->sta_idx++); ++ sprintf(name, "%d", vif->sta_idx++); + + sta = calloc_a(sizeof(*sta), +- &name_buf, strlen(name) + 1, +- &vif_buf, strlen(vif) + 1); ++ &name_buf, strlen(name) + 1); + sta->name = strcpy(name_buf, name); +- sta->vif = strcpy(vif_buf, vif); +- sta->wdev = wdev; + sta->config = data; + sta->section = section; + +- vlist_add(&wdev->stations, &sta->node, sta->name); ++ vlist_add(&vif->stations, &sta->node, sta->name); + } + + /* ubus callback network.wireless.status, runs for every interface, encode the station */ +@@ -1151,12 +1140,12 @@ wireless_station_status(struct wireless_ + + /* create a vlan object. Called by config */ + void +-wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section) ++wireless_vlan_create(struct wireless_interface *vif, struct blob_attr *data, const char *section) + { + struct wireless_vlan *vlan; + struct blob_attr *tb[__VLAN_ATTR_MAX]; + struct blob_attr *cur; +- char *name_buf, *vif_buf; ++ char *name_buf; + char name[8]; + + blobmsg_parse(vlan_policy, __VLAN_ATTR_MAX, tb, blob_data(data), blob_len(data)); +@@ -1165,19 +1154,14 @@ wireless_vlan_create(struct wireless_dev + if (cur && blobmsg_get_bool(cur)) + return; + +- sprintf(name, "%d", wdev->vlan_idx++); ++ sprintf(name, "%d", vif->vlan_idx++); + +- vlan = calloc_a(sizeof(*vlan), +- &name_buf, strlen(name) + 1, +- &vif_buf, strlen(vif) + 1); ++ vlan = calloc_a(sizeof(*vlan), &name_buf, strlen(name) + 1); + vlan->name = strcpy(name_buf, name); +- vlan->vif = strcpy(vif_buf, vif); +- vlan->wdev = wdev; + vlan->config = data; + vlan->section = section; +- vlan->isolate = false; + +- vlist_add(&wdev->vlans, &vlan->node, vlan->name); ++ vlist_add(&vif->vlans, &vlan->node, vlan->name); + } + + /* ubus callback network.wireless.status, runs for every interface, encode the vlan informations */ +@@ -1220,6 +1204,12 @@ struct wireless_interface* wireless_inte + vif->section = section; + vif->isolate = false; + ++ vlist_init(&vif->vlans, avl_strcmp, vlan_update); ++ vif->vlans.keep_old = true; ++ ++ vlist_init(&vif->stations, avl_strcmp, station_update); ++ vif->stations.keep_old = true; ++ + vlist_add(&wdev->interfaces, &vif->node, vif->name); + + return vlist_find(&wdev->interfaces, name, vif, node); +@@ -1240,14 +1230,12 @@ wireless_interface_status(struct wireles + blobmsg_add_string(b, "ifname", iface->ifname); + put_container(b, iface->config, "config"); + j = blobmsg_open_array(b, "vlans"); +- vlist_for_each_element(&iface->wdev->vlans, vlan, node) +- if (!strcmp(iface->name, vlan->vif)) +- wireless_vlan_status(vlan, b); ++ vlist_for_each_element(&iface->vlans, vlan, node) ++ wireless_vlan_status(vlan, b); + blobmsg_close_array(b, j); + j = blobmsg_open_array(b, "stations"); +- vlist_for_each_element(&iface->wdev->stations, sta, node) +- if (!strcmp(iface->name, sta->vif)) +- wireless_station_status(sta, b); ++ vlist_for_each_element(&iface->stations, sta, node) ++ wireless_station_status(sta, b); + blobmsg_close_array(b, j); + blobmsg_close_table(b, i); + } +@@ -1496,7 +1484,9 @@ wireless_device_notify(struct wireless_d + } + + if ((cur = tb[NOTIFY_ATTR_VLAN]) != NULL) { +- vlan = vlist_find(&wdev->vlans, blobmsg_data(cur), vlan, node); ++ if (!vif) ++ return UBUS_STATUS_NOT_FOUND; ++ vlan = vlist_find(&vif->vlans, blobmsg_data(cur), vlan, node); + if (!vlan) + return UBUS_STATUS_NOT_FOUND; + } +@@ -1516,19 +1506,19 @@ wireless_device_notify(struct wireless_d + wireless_device_mark_up(wdev); + break; + case NOTIFY_CMD_SET_DATA: +- if (vif) +- pdata = &vif->data; +- else if (vlan) ++ if (vlan) + pdata = &vlan->data; ++ else if (vif) ++ pdata = &vif->data; + else + pdata = &wdev->data; + + free(*pdata); + *pdata = blob_memdup(cur); +- if (vif) +- wireless_interface_set_data(vif); +- else if (vlan) ++ if (vlan) + wireless_vlan_set_data(vlan); ++ else if (vif) ++ wireless_interface_set_data(vif); + break; + case NOTIFY_CMD_PROCESS_ADD: + return wireless_device_add_process(wdev, cur); +--- a/wireless.h ++++ b/wireless.h +@@ -44,8 +44,6 @@ struct wireless_device { + + struct wireless_driver *drv; + struct vlist_tree interfaces; +- struct vlist_tree vlans; +- struct vlist_tree stations; + char *name; + + struct netifd_process script_task; +@@ -73,8 +71,6 @@ struct wireless_device { + int retry; + + int vif_idx; +- int vlan_idx; +- int sta_idx; + }; + + struct wireless_interface { +@@ -82,6 +78,8 @@ struct wireless_interface { + const char *section; + char *name; + ++ struct vlist_tree vlans; ++ struct vlist_tree stations; + struct wireless_device *wdev; + + struct blob_attr *config; +@@ -94,6 +92,8 @@ struct wireless_interface { + bool isolate; + bool ap_mode; + int multicast_to_unicast; ++ int vlan_idx; ++ int sta_idx; + }; + + struct wireless_vlan { +@@ -101,9 +101,6 @@ struct wireless_vlan { + const char *section; + char *name; + +- struct wireless_device *wdev; +- char *vif; +- + struct blob_attr *config; + struct blob_attr *data; + +@@ -119,9 +116,6 @@ struct wireless_station { + const char *section; + char *name; + +- struct wireless_device *wdev; +- char *vif; +- + struct blob_attr *config; + struct blob_attr *data; + }; +@@ -143,8 +137,8 @@ void wireless_device_reconf(struct wirel + void wireless_device_status(struct wireless_device *wdev, struct blob_buf *b); + void wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b); + struct wireless_interface* wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section); +-void wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section); +-void wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section); ++void wireless_vlan_create(struct wireless_interface *vif, struct blob_attr *data, const char *section); ++void wireless_station_create(struct wireless_interface *vif, struct blob_attr *data, const char *section); + int wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data, + struct ubus_request_data *req); + From 1d9b69ee6f03adafaea3182a12e66d7f98f215fb Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 15 Sep 2023 15:02:46 +0200 Subject: [PATCH 23/32] hostapd: add vlan reload support and ap+sta fix Signed-off-by: Felix Fietkau --- feeds/wifi-ax/hostapd/files/hostapd.uc | 11 +- feeds/wifi-ax/hostapd/src/src/ap/ucode.c | 137 ++++++++++++++++++++--- 2 files changed, 129 insertions(+), 19 deletions(-) diff --git a/feeds/wifi-ax/hostapd/files/hostapd.uc b/feeds/wifi-ax/hostapd/files/hostapd.uc index 9b356dcc3..ebf732bea 100644 --- a/feeds/wifi-ax/hostapd/files/hostapd.uc +++ b/feeds/wifi-ax/hostapd/files/hostapd.uc @@ -215,6 +215,7 @@ function bss_remove_file_fields(config) for (let key in config.hash) new_cfg.hash[key] = config.hash[key]; delete new_cfg.hash.wpa_psk_file; + delete new_cfg.hash.vlan_file; return new_cfg; } @@ -475,11 +476,12 @@ function iface_reload_config(phydev, config, old_config) bss_remove_file_fields(bss_list_cfg[i]))) { hostapd.printf(`Update config data files for bss ${ifname}`); if (bss.set_config(config_inline, i, true) < 0) { - hostapd.printf(`Failed to update config data files for bss ${ifname}`); + hostapd.printf(`Could not update config data files for bss ${ifname}`); return false; + } else { + bss.ctrl("RELOAD_WPA_PSK"); + continue; } - bss.ctrl("RELOAD_WPA_PSK"); - continue; } bss_reload_psk(bss, config.bss[i], bss_list_cfg[i]); @@ -487,8 +489,6 @@ function iface_reload_config(phydev, config, old_config) continue; hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); - hostapd.printf(`old: ${bss_remove_file_fields(bss_list_cfg[i])}`); - hostapd.printf(`new: ${bss_remove_file_fields(config.bss[i])}`); if (bss.set_config(config_inline, i) < 0) { hostapd.printf(`Failed to set config for bss ${ifname}`); return false; @@ -688,7 +688,6 @@ let main_obj = { freq_info.csa_count = req.args.csa_count ?? 10; ret = iface.switch_channel(freq_info); } else { - iface.stop(); ret = iface.start(freq_info); } if (!ret) diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ucode.c b/feeds/wifi-ax/hostapd/src/src/ap/ucode.c index 6ce8a3395..9ffdbd96a 100644 --- a/feeds/wifi-ax/hostapd/src/src/ap/ucode.c +++ b/feeds/wifi-ax/hostapd/src/src/ap/ucode.c @@ -111,6 +111,94 @@ uc_hostapd_remove_iface(uc_vm_t *vm, size_t nargs) return NULL; } +static struct hostapd_vlan * +bss_conf_find_vlan(struct hostapd_bss_config *bss, int id) +{ + struct hostapd_vlan *vlan; + + for (vlan = bss->vlan; vlan; vlan = vlan->next) + if (vlan->vlan_id == id) + return vlan; + + return NULL; +} + +static int +bss_conf_rename_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan, + const char *ifname) +{ + if (!strcmp(ifname, vlan->ifname)) + return 0; + + hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, vlan->ifname, ifname); + os_strlcpy(vlan->ifname, ifname, sizeof(vlan->ifname)); + + return 0; +} + +static int +bss_reload_vlans(struct hostapd_data *hapd, struct hostapd_bss_config *bss) +{ + struct hostapd_bss_config *old_bss = hapd->conf; + struct hostapd_vlan *vlan, *vlan_new, *wildcard; + char ifname[IFNAMSIZ + 1], vlan_ifname[IFNAMSIZ + 1], *pos; + int ret; + + vlan = bss_conf_find_vlan(old_bss, VLAN_ID_WILDCARD); + wildcard = bss_conf_find_vlan(bss, VLAN_ID_WILDCARD); + if (!!vlan != !!wildcard) + return -1; + + if (vlan && wildcard && strcmp(vlan->ifname, wildcard->ifname) != 0) + strcpy(vlan->ifname, wildcard->ifname); + else + wildcard = NULL; + + for (vlan = bss->vlan; vlan; vlan = vlan->next) { + if (vlan->vlan_id == VLAN_ID_WILDCARD || + vlan->dynamic_vlan > 0) + continue; + + if (!bss_conf_find_vlan(old_bss, vlan->vlan_id)) + return -1; + } + + for (vlan = old_bss->vlan; vlan; vlan = vlan->next) { + if (vlan->vlan_id == VLAN_ID_WILDCARD) + continue; + + if (vlan->dynamic_vlan == 0) { + vlan_new = bss_conf_find_vlan(bss, vlan->vlan_id); + if (!vlan_new) + return -1; + + if (bss_conf_rename_vlan(hapd, vlan, vlan_new->ifname)) + return -1; + + continue; + } + + if (!wildcard) + continue; + + os_strlcpy(ifname, wildcard->ifname, sizeof(ifname)); + pos = os_strchr(ifname, '#'); + if (!pos) + return -1; + + *pos++ = '\0'; + ret = os_snprintf(vlan_ifname, sizeof(vlan_ifname), "%s%d%s", + ifname, vlan->vlan_id, pos); + if (os_snprintf_error(sizeof(vlan_ifname), ret)) + return -1; + + if (bss_conf_rename_vlan(hapd, vlan, vlan_ifname)) + return -1; + } + + return 0; +} + static uc_value_t * uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) { @@ -150,6 +238,7 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) } while (0) swap_field(ssid.wpa_psk_file); + ret = bss_reload_vlans(hapd, bss); goto done; } @@ -382,13 +471,23 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); int i; + switch (iface->state) { + case HAPD_IFACE_ENABLED: + case HAPD_IFACE_DISABLED: + break; #ifdef CONFIG_ACS - if (iface->state == HAPD_IFACE_ACS) { + case HAPD_IFACE_ACS: acs_cleanup(iface); iface->scan_cb = NULL; - hostapd_disable_iface(iface); - } + /* fallthrough */ #endif + default: + hostapd_disable_iface(iface); + break; + } + + if (iface->state != HAPD_IFACE_ENABLED) + hostapd_disable_iface(iface); for (i = 0; i < iface->num_bss; i++) { struct hostapd_data *hapd = iface->bss[i]; @@ -396,6 +495,7 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs) hostapd_drv_stop_ap(hapd); hapd->beacon_set_done = 0; } + return NULL; } @@ -405,28 +505,37 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); uc_value_t *info = uc_fn_arg(0); struct hostapd_config *conf; + bool changed = false; uint64_t intval; int i; if (!iface) return NULL; - iface->freq = 0; - if (!info) + if (!info) { + iface->freq = 0; goto out; + } if (ucv_type(info) != UC_OBJECT) return NULL; +#define UPDATE_VAL(field, name) \ + if ((intval = ucv_int64_get(ucv_object_get(info, name, NULL))) && \ + !errno && intval != conf->field) do { \ + conf->field = intval; \ + changed = true; \ + } while(0) + conf = iface->conf; - if ((intval = ucv_int64_get(ucv_object_get(info, "op_class", NULL))) && !errno) - conf->op_class = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "hw_mode", NULL))) && !errno) - conf->hw_mode = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "channel", NULL))) && !errno) - conf->channel = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "sec_channel", NULL))) && !errno) - conf->secondary_channel = intval; + UPDATE_VAL(op_class, "op_class"); + UPDATE_VAL(hw_mode, "hw_mode"); + UPDATE_VAL(channel, "channel"); + UPDATE_VAL(secondary_channel, "sec_channel"); + if (!changed && + (iface->bss[0]->beacon_set_done || + iface->state == HAPD_IFACE_DFS)) + return ucv_boolean_new(true); intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL)); if (!errno) @@ -443,6 +552,8 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL)); if (!errno) iface->freq = intval; + else + iface->freq = 0; conf->acs = 0; out: From 7e4e221ccb3ffec21ff6b5318257689db9c9770d Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sat, 16 Sep 2023 07:40:14 +0200 Subject: [PATCH 24/32] netifd: add dynamic interface patch Signed-off-by: John Crispin --- .../backports/0060-netif-dynamic-iface.patch | 285 ++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 patches/backports/0060-netif-dynamic-iface.patch diff --git a/patches/backports/0060-netif-dynamic-iface.patch b/patches/backports/0060-netif-dynamic-iface.patch new file mode 100644 index 000000000..f5a81247e --- /dev/null +++ b/patches/backports/0060-netif-dynamic-iface.patch @@ -0,0 +1,285 @@ +From 4e4128e44fcb6c0f444e4aa481eb8941f47a801a Mon Sep 17 00:00:00 2001 +From: Felix Fietkau +Date: Fri, 15 Sep 2023 20:47:10 +0200 +Subject: [PATCH] netifd: add support for enabling/disabling wifi interfaces + via ifup/ifdown + +Signed-off-by: Felix Fietkau +--- + package/network/config/netifd/files/sbin/ifup | 33 --- + .../patches/410-wireless_network_state.patch | 194 ++++++++++++++++++ + 2 files changed, 194 insertions(+), 33 deletions(-) + create mode 100644 package/network/config/netifd/patches/410-wireless_network_state.patch + +diff --git a/package/network/config/netifd/files/sbin/ifup b/package/network/config/netifd/files/sbin/ifup +index 15be535bbfc9..fbf2fd80c7ea 100755 +--- a/package/network/config/netifd/files/sbin/ifup ++++ b/package/network/config/netifd/files/sbin/ifup +@@ -1,7 +1,6 @@ + #!/bin/sh + + ifup_all= +-setup_wifi= + + if_call() { + local interface="$1" +@@ -14,7 +13,6 @@ case "$0" in + *ifdown) modes=down;; + *ifup) + modes="down up" +- setup_wifi=1 + ;; + *) echo "Invalid command: $0";; + esac +@@ -25,10 +23,6 @@ while :; do + ifup_all=1 + shift + ;; +- -w) +- setup_wifi= +- shift +- ;; + *) + break + ;; +@@ -40,7 +34,6 @@ if [ -n "$ifup_all" ]; then + for interface in $(ubus -S list 'network.interface.*'); do + if_call "${interface##network.interface.}" + done +- [ -n "$setup_wifi" ] && /sbin/wifi up + exit + else + ubus -S list "network.interface.$1" > /dev/null || { +@@ -49,29 +42,3 @@ else + } + if_call "$1" + fi +- +-if [ -n "$setup_wifi" ] && grep -sq config /etc/config/wireless; then +- . /lib/functions.sh +- +- find_related_radios() { +- local wdev wnet +- config_get wdev "$1" device +- config_get wnet "$1" network +- +- if [ -n "$wdev" ]; then +- for wnet in $wnet; do +- if [ "$wnet" = "$network" ]; then +- append radio_devs "$wdev" "$N" +- fi +- done +- fi +- } +- +- network="$1" +- config_load wireless +- config_foreach find_related_radios wifi-iface +- +- for dev in $(echo "$radio_devs" | sort -u); do +- /sbin/wifi up "$dev" +- done +-fi +diff --git a/package/network/config/netifd/patches/410-wireless_network_state.patch b/package/network/config/netifd/patches/410-wireless_network_state.patch +new file mode 100644 +index 000000000000..4e9b905190b6 +--- /dev/null ++++ b/package/network/config/netifd/patches/410-wireless_network_state.patch +@@ -0,0 +1,194 @@ ++--- a/config.c +++++ b/config.c ++@@ -784,7 +784,7 @@ config_init_all(void) ++ vlist_flush(&interfaces); ++ interface_refresh_assignments(false); ++ interface_start_pending(); ++- wireless_start_pending(); +++ wireless_start_pending(0); ++ ++ return ret; ++ } ++--- a/interface.c +++++ b/interface.c ++@@ -25,6 +25,7 @@ ++ #include "ubus.h" ++ #include "config.h" ++ #include "system.h" +++#include "wireless.h" ++ ++ struct vlist_tree interfaces; ++ static LIST_HEAD(iface_all_users); ++@@ -1125,6 +1126,7 @@ interface_set_up(struct interface *iface ++ const char *error = NULL; ++ ++ iface->autostart = true; +++ wireless_check_network_enabled(); ++ ++ if (iface->state != IFS_DOWN) ++ return; ++@@ -1157,6 +1159,7 @@ interface_set_down(struct interface *ifa ++ __interface_set_down(iface, false); ++ } else { ++ iface->autostart = false; +++ wireless_check_network_enabled(); ++ __interface_set_down(iface, false); ++ } ++ } ++--- a/wireless.c +++++ b/wireless.c ++@@ -198,6 +198,9 @@ prepare_config(struct wireless_device *w ++ ++ l = blobmsg_open_table(&b, "interfaces"); ++ vlist_for_each_element(&wdev->interfaces, vif, node) { +++ if (vif->disabled) +++ continue; +++ ++ i = blobmsg_open_table(&b, vif->name); ++ vif_config_add_bridge(&b, vif->network, up); ++ put_container(&b, vif->config, "config"); ++@@ -438,6 +441,8 @@ wireless_device_run_handler(struct wirel ++ wdev->prev_config = NULL; ++ } else { ++ prepare_config(wdev, &b, up); +++ free(wdev->prev_config); +++ wdev->prev_config = up ? blob_memdup(b.head) : NULL; ++ config = blobmsg_format_json(b.head, true); ++ } ++ ++@@ -495,8 +500,6 @@ __wireless_device_set_up(struct wireless ++ if ((!force && wdev->state != IFS_DOWN) || config_init) ++ return; ++ ++- free(wdev->prev_config); ++- wdev->prev_config = NULL; ++ wdev->state = IFS_SETUP; ++ wireless_device_run_handler(wdev, true); ++ } ++@@ -690,16 +693,6 @@ wdev_set_config_state(struct wireless_de ++ } ++ ++ static void ++-wdev_prepare_prev_config(struct wireless_device *wdev) ++-{ ++- if (wdev->prev_config) ++- return; ++- ++- prepare_config(wdev, &b, false); ++- wdev->prev_config = blob_memdup(b.head); ++-} ++- ++-static void ++ wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new) ++ { ++ struct blob_attr *new_config = wd_new->config; ++@@ -709,7 +702,6 @@ wdev_change_config(struct wireless_devic ++ wdev->serialize = wd_new->serialize; ++ free(wd_new); ++ ++- wdev_prepare_prev_config(wdev); ++ if (blob_attr_equal(wdev->config, new_config) && wdev->disabled == disabled) ++ return; ++ ++@@ -1533,19 +1525,78 @@ wireless_device_notify(struct wireless_d ++ return 0; ++ } ++ ++-/* called on startup and by netifd reload() */ ++-void ++-wireless_start_pending(void) +++static void +++wdev_check_network_enabled(struct wireless_device *wdev) +++{ +++ struct wireless_interface *vif; +++ struct interface *iface; +++ struct blob_attr *cur; +++ int rem; +++ +++ vlist_for_each_element(&wdev->interfaces, vif, node) { +++ int enabled = -1; +++ +++ blobmsg_for_each_attr(cur, vif->network, rem) { +++ iface = vlist_find(&interfaces, blobmsg_get_string(cur), iface, node); +++ if (!iface) +++ continue; +++ +++ if (iface->autostart) { +++ enabled = 1; +++ break; +++ } +++ if (enabled != 1) +++ enabled = 0; +++ } +++ +++ if (vif->disabled == !enabled) +++ continue; +++ +++ vif->disabled = !enabled; +++ wdev->config_update = true; +++ } +++} +++ +++static void +++__wireless_start_pending(struct uloop_timeout *t) ++ { ++ struct wireless_device *wdev; ++ ++ vlist_for_each_element(&wireless_devices, wdev, node) { +++ wdev_check_network_enabled(wdev); ++ if (wdev->config_update) ++ wdev_set_config_state(wdev, IFC_RELOAD); ++ __wireless_device_set_up(wdev, 0); ++ } ++ } ++ +++void wireless_start_pending(int timeout) +++{ +++ static struct uloop_timeout timer = { +++ .cb = __wireless_start_pending +++ }; +++ +++ if (timeout) { +++ uloop_timeout_set(&timer, timeout); +++ return; +++ } +++ +++ uloop_timeout_cancel(&timer); +++ timer.cb(&timer); +++} +++ +++void wireless_check_network_enabled(void) +++{ +++ struct wireless_device *wdev; +++ +++ vlist_for_each_element(&wireless_devices, wdev, node) { +++ wdev_check_network_enabled(wdev); +++ +++ if (wdev->config_update) +++ wireless_start_pending(1000); +++ } +++} +++ ++ void wireless_device_hotplug_event(const char *name, bool add) ++ { ++ struct wireless_interface *vif; ++--- a/wireless.h +++++ b/wireless.h ++@@ -94,6 +94,7 @@ struct wireless_interface { ++ int multicast_to_unicast; ++ int vlan_idx; ++ int sta_idx; +++ bool disabled; ++ }; ++ ++ struct wireless_vlan { ++@@ -142,7 +143,8 @@ void wireless_station_create(struct wire ++ int wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data, ++ struct ubus_request_data *req); ++ ++-void wireless_start_pending(void); +++void wireless_check_network_enabled(void); +++void wireless_start_pending(int timeout); ++ void wireless_init(void); ++ void wireless_device_hotplug_event(const char *name, bool add); ++ +-- +2.39.2 + From befac1e06547e8c7c9ba1d2fa2081fd9f9dc7ca8 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sat, 16 Sep 2023 16:55:57 +0200 Subject: [PATCH 25/32] netifd: backport vlan rewrite Signed-off-by: John Crispin --- patches/backports/0061-netifd-vlan-fix.patch | 607 +++++++++++++++++++ 1 file changed, 607 insertions(+) create mode 100644 patches/backports/0061-netifd-vlan-fix.patch diff --git a/patches/backports/0061-netifd-vlan-fix.patch b/patches/backports/0061-netifd-vlan-fix.patch new file mode 100644 index 000000000..16b9e68bf --- /dev/null +++ b/patches/backports/0061-netifd-vlan-fix.patch @@ -0,0 +1,607 @@ +From f7feafa6a88a70f96ac4bf556ff5b0665eb9735a Mon Sep 17 00:00:00 2001 +From: Felix Fietkau +Date: Fri, 15 Sep 2023 15:01:44 +0200 +Subject: [PATCH] netifd: add wireless vlan/sta fix + +Signed-off-by: Felix Fietkau +--- + .../patches/400-wireless_vlan_fix.patch | 587 ++++++++++++++++++ + 1 file changed, 587 insertions(+) + create mode 100644 package/network/config/netifd/patches/400-wireless_vlan_fix.patch + +diff --git a/package/network/config/netifd/patches/400-wireless_vlan_fix.patch b/package/network/config/netifd/patches/400-wireless_vlan_fix.patch +new file mode 100644 +index 000000000000..449121dd3d9e +--- /dev/null ++++ b/package/network/config/netifd/patches/400-wireless_vlan_fix.patch +@@ -0,0 +1,587 @@ ++--- a/config.c +++++ b/config.c ++@@ -557,8 +557,8 @@ config_parse_wireless_device(struct uci_ ++ wireless_device_create(drv, s->e.name, b.head); ++ } ++ ++-static struct wireless_interface* ++-config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s) +++static void +++config_parse_wireless_vlan(struct wireless_interface *vif, struct uci_section *s) ++ { ++ char *name; ++ ++@@ -566,12 +566,12 @@ config_parse_wireless_interface(struct w ++ sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); ++ ++ blob_buf_init(&b, 0); ++- uci_to_blob(&b, s, wdev->drv->interface.config); ++- return wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name); +++ uci_to_blob(&b, s, vif->wdev->drv->vlan.config); +++ wireless_vlan_create(vif, b.head, s->anonymous ? name : s->e.name); ++ } ++ ++ static void ++-config_parse_wireless_vlan(struct wireless_device *wdev, char *vif, struct uci_section *s) +++config_parse_wireless_station(struct wireless_interface *vif, struct uci_section *s) ++ { ++ char *name; ++ ++@@ -579,21 +579,62 @@ config_parse_wireless_vlan(struct wirele ++ sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); ++ ++ blob_buf_init(&b, 0); ++- uci_to_blob(&b, s, wdev->drv->vlan.config); ++- wireless_vlan_create(wdev, vif, b.head, s->anonymous ? name : s->e.name); +++ uci_to_blob(&b, s, vif->wdev->drv->station.config); +++ wireless_station_create(vif, b.head, s->anonymous ? name : s->e.name); ++ } ++ ++ static void ++-config_parse_wireless_station(struct wireless_device *wdev, char *vif, struct uci_section *s) +++config_parse_wireless_interface(struct wireless_device *wdev, struct uci_section *s) ++ { +++ struct wireless_interface *vif; +++ struct uci_element *f; ++ char *name; ++ ++ name = alloca(strlen(s->type) + 16); ++ sprintf(name, "@%s[%d]", s->type, config_section_idx(s)); ++ ++ blob_buf_init(&b, 0); ++- uci_to_blob(&b, s, wdev->drv->station.config); ++- wireless_station_create(wdev, vif, b.head, s->anonymous ? name : s->e.name); +++ uci_to_blob(&b, s, wdev->drv->interface.config); +++ vif = wireless_interface_create(wdev, b.head, s->anonymous ? name : s->e.name); +++ if (!vif) +++ return; +++ +++ vif->vlan_idx = vif->sta_idx = 0; +++ vlist_update(&vif->vlans); +++ vlist_update(&vif->stations); +++ +++ if (s->anonymous) +++ goto out; +++ +++ uci_foreach_element(&uci_wireless->sections, f) { +++ struct uci_section *cur = uci_to_section(f); +++ const char *vif_name; +++ +++ if (strcmp(cur->type, "wifi-vlan") != 0) +++ continue; +++ +++ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface"); +++ if (vif_name && strcmp(s->e.name, vif_name)) +++ continue; +++ config_parse_wireless_vlan(vif, cur); +++ } +++ +++ uci_foreach_element(&uci_wireless->sections, f) { +++ struct uci_section *cur = uci_to_section(f); +++ const char *vif_name; +++ +++ if (strcmp(cur->type, "wifi-station") != 0) +++ continue; +++ +++ vif_name = uci_lookup_option_string(uci_ctx, cur, "iface"); +++ if (vif_name && strcmp(s->e.name, vif_name)) +++ continue; +++ config_parse_wireless_station(vif, cur); +++ } +++ +++out: +++ vlist_flush(&vif->vlans); +++ vlist_flush(&vif->stations); ++ } ++ ++ static void ++@@ -623,16 +664,10 @@ config_init_wireless(void) ++ vlist_for_each_element(&wireless_devices, wdev, node) { ++ wdev->vif_idx = 0; ++ vlist_update(&wdev->interfaces); ++- wdev->vlan_idx = 0; ++- vlist_update(&wdev->vlans); ++- wdev->sta_idx = 0; ++- vlist_update(&wdev->stations); ++ } ++ ++ uci_foreach_element(&uci_wireless->sections, e) { ++ struct uci_section *s = uci_to_section(e); ++- struct wireless_interface *vif; ++- struct uci_element *f; ++ ++ if (strcmp(s->type, "wifi-iface") != 0) ++ continue; ++@@ -647,42 +682,11 @@ config_init_wireless(void) ++ continue; ++ } ++ ++- vif = config_parse_wireless_interface(wdev, s); ++- ++- if (!vif || s->anonymous) ++- continue; ++- uci_foreach_element(&uci_wireless->sections, f) { ++- struct uci_section *s = uci_to_section(f); ++- const char *vif_name; ++- ++- if (strcmp(s->type, "wifi-vlan") != 0) ++- continue; ++- ++- vif_name = uci_lookup_option_string(uci_ctx, s, "iface"); ++- if (vif_name && strcmp(e->name, vif_name)) ++- continue; ++- config_parse_wireless_vlan(wdev, vif->name, s); ++- } ++- ++- uci_foreach_element(&uci_wireless->sections, f) { ++- struct uci_section *s = uci_to_section(f); ++- const char *vif_name; ++- ++- if (strcmp(s->type, "wifi-station") != 0) ++- continue; ++- ++- vif_name = uci_lookup_option_string(uci_ctx, s, "iface"); ++- if (vif_name && strcmp(e->name, vif_name)) ++- continue; ++- config_parse_wireless_station(wdev, vif->name, s); ++- } +++ config_parse_wireless_interface(wdev, s); ++ } ++ ++- vlist_for_each_element(&wireless_devices, wdev, node) { +++ vlist_for_each_element(&wireless_devices, wdev, node) ++ vlist_flush(&wdev->interfaces); ++- vlist_flush(&wdev->vlans); ++- vlist_flush(&wdev->stations); ++- } ++ } ++ ++ ++--- a/scripts/netifd-wireless.sh +++++ b/scripts/netifd-wireless.sh ++@@ -108,14 +108,16 @@ _wdev_wrapper() { ++ } ++ ++ _wdev_notify_init() { ++- local command="$1" ++- local name="$2" ++- local value="$3" +++ local command="$1"; shift; ++ ++ json_init ++ json_add_int "command" "$command" ++ json_add_string "device" "$__netifd_device" ++- [ -n "$name" -a -n "$value" ] && json_add_string "$name" "$value" +++ while [ -n "$1" ]; do +++ local name="$1"; shift +++ local value="$1"; shift +++ json_add_string "$name" "$value" +++ done ++ json_add_object "data" ++ } ++ ++@@ -151,7 +153,7 @@ _wireless_add_vlan() { ++ local name="$1"; shift ++ local ifname="$1"; shift ++ ++- _wdev_notify_init $CMD_SET_DATA "vlan" "$name" +++ _wdev_notify_init $CMD_SET_DATA interface "$__cur_interface" "vlan" "$name" ++ json_add_string "ifname" "$ifname" ++ _wdev_add_variables "$@" ++ _wdev_notify ++@@ -333,6 +335,7 @@ for_each_interface() { ++ continue ++ } ++ fi +++ __cur_interface="$_w_iface" ++ "$@" "$_w_iface" ++ json_select .. ++ done ++--- a/wireless.c +++++ b/wireless.c ++@@ -205,9 +205,7 @@ prepare_config(struct wireless_device *w ++ blobmsg_add_blob(&b, vif->data); ++ ++ j = blobmsg_open_table(&b, "vlans"); ++- vlist_for_each_element(&wdev->vlans, vlan, node) { ++- if (strcmp(vlan->vif, vif->name)) ++- continue; +++ vlist_for_each_element(&vif->vlans, vlan, node) { ++ k = blobmsg_open_table(&b, vlan->name); ++ vif_config_add_bridge(&b, vlan->network, up); ++ put_container(&b, vlan->config, "config"); ++@@ -218,9 +216,7 @@ prepare_config(struct wireless_device *w ++ blobmsg_close_table(&b, j); ++ ++ j = blobmsg_open_table(&b, "stas"); ++- vlist_for_each_element(&wdev->stations, sta, node) { ++- if (strcmp(sta->vif, vif->name)) ++- continue; +++ vlist_for_each_element(&vif->stations, sta, node) { ++ k = blobmsg_open_table(&b, sta->name); ++ put_container(&b, sta->config, "config"); ++ if (sta->data) ++@@ -311,15 +307,15 @@ wireless_device_free_state(struct wirele ++ free(vif->data); ++ vif->data = NULL; ++ vif->ifname = NULL; ++- } ++- vlist_for_each_element(&wdev->vlans, vlan, node) { ++- free(vlan->data); ++- vlan->data = NULL; ++- vlan->ifname = NULL; ++- } ++- vlist_for_each_element(&wdev->stations, sta, node) { ++- free(sta->data); ++- sta->data = NULL; +++ vlist_for_each_element(&vif->vlans, vlan, node) { +++ free(vlan->data); +++ vlan->data = NULL; +++ vlan->ifname = NULL; +++ } +++ vlist_for_each_element(&vif->stations, sta, node) { +++ free(sta->data); +++ sta->data = NULL; +++ } ++ } ++ } ++ ++@@ -510,8 +506,6 @@ wireless_device_free(struct wireless_dev ++ { ++ wireless_handler_stop(wdev); ++ vlist_flush_all(&wdev->interfaces); ++- vlist_flush_all(&wdev->vlans); ++- vlist_flush_all(&wdev->stations); ++ avl_delete(&wireless_devices.avl, &wdev->node.avl); ++ free(wdev->config); ++ free(wdev->prev_config); ++@@ -547,11 +541,12 @@ wireless_device_mark_down(struct wireles ++ ++ netifd_log_message(L_NOTICE, "Wireless device '%s' is now down\n", wdev->name); ++ ++- vlist_for_each_element(&wdev->vlans, vlan, node) ++- wireless_vlan_handle_link(vlan, false); ++ ++- vlist_for_each_element(&wdev->interfaces, vif, node) +++ vlist_for_each_element(&wdev->interfaces, vif, node) { ++ wireless_interface_handle_link(vif, NULL, false); +++ vlist_for_each_element(&vif->vlans, vlan, node) +++ wireless_vlan_handle_link(vlan, false); +++ } ++ ++ wireless_process_kill_all(wdev, SIGTERM, true); ++ ++@@ -623,10 +618,11 @@ wireless_device_mark_up(struct wireless_ ++ netifd_log_message(L_NOTICE, "Wireless device '%s' is now up\n", wdev->name); ++ wdev->retry = WIRELESS_SETUP_RETRY; ++ wdev->state = IFS_UP; ++- vlist_for_each_element(&wdev->interfaces, vif, node) +++ vlist_for_each_element(&wdev->interfaces, vif, node) { ++ wireless_interface_handle_link(vif, NULL, true); ++- vlist_for_each_element(&wdev->vlans, vlan, node) ++- wireless_vlan_handle_link(vlan, true); +++ vlist_for_each_element(&vif->vlans, vlan, node) +++ wireless_vlan_handle_link(vlan, true); +++ } ++ } ++ ++ static void ++@@ -848,6 +844,16 @@ wireless_interface_init_config(struct wi ++ vif->multicast_to_unicast = cur ? blobmsg_get_bool(cur) : -1; ++ } ++ +++static void +++vif_free(struct wireless_interface *vif) +++{ +++ vlist_flush_all(&vif->vlans); +++ vlist_flush_all(&vif->stations); +++ free((void *) vif->section); +++ free(vif->config); +++ free(vif); +++} +++ ++ /* vlist update call for wireless interface list */ ++ static void ++ vif_update(struct vlist_tree *tree, struct vlist_node *node_new, ++@@ -884,9 +890,7 @@ vif_update(struct vlist_tree *tree, stru ++ } else if (vif_old) { ++ D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name); ++ wireless_interface_handle_link(vif_old, NULL, false); ++- free((void *) vif_old->section); ++- free(vif_old->config); ++- free(vif_old); +++ vif_free(vif_old); ++ } ++ ++ wdev->config_update = true; ++@@ -921,14 +925,10 @@ static void ++ vlan_update(struct vlist_tree *tree, struct vlist_node *node_new, ++ struct vlist_node *node_old) ++ { ++- struct wireless_vlan *vlan_old = container_of(node_old, struct wireless_vlan, node); ++- struct wireless_vlan *vlan_new = container_of(node_new, struct wireless_vlan, node); ++- struct wireless_device *wdev; ++- ++- if (vlan_old) ++- wdev = vlan_old->wdev; ++- else ++- wdev = vlan_new->wdev; +++ struct wireless_vlan *vlan_old = container_of_safe(node_old, struct wireless_vlan, node); +++ struct wireless_vlan *vlan_new = container_of_safe(node_new, struct wireless_vlan, node); +++ struct wireless_interface *vif = container_of(tree, struct wireless_interface, vlans); +++ struct wireless_device *wdev = vif->wdev; ++ ++ if (vlan_old && vlan_new) { ++ free((void *) vlan_old->section); ++@@ -951,7 +951,7 @@ vlan_update(struct vlist_tree *tree, str ++ vlan_new->config = blob_memdup(vlan_new->config); ++ wireless_vlan_init_config(vlan_new); ++ } else if (vlan_old) { ++- D(WIRELESS, "Delete wireless interface %s on device %s\n", vlan_old->name, wdev->name); +++ D(WIRELESS, "Delete wireless vlan %s on device %s\n", vlan_old->name, wdev->name); ++ wireless_vlan_handle_link(vlan_old, false); ++ free((void *) vlan_old->section); ++ free(vlan_old->config); ++@@ -966,14 +966,10 @@ static void ++ station_update(struct vlist_tree *tree, struct vlist_node *node_new, ++ struct vlist_node *node_old) ++ { ++- struct wireless_station *sta_old = container_of(node_old, struct wireless_station, node); ++- struct wireless_station *sta_new = container_of(node_new, struct wireless_station, node); ++- struct wireless_device *wdev; ++- ++- if (sta_old) ++- wdev = sta_old->wdev; ++- else ++- wdev = sta_new->wdev; +++ struct wireless_station *sta_old = container_of_safe(node_old, struct wireless_station, node); +++ struct wireless_station *sta_new = container_of_safe(node_new, struct wireless_station, node); +++ struct wireless_interface *vif = container_of(tree, struct wireless_interface, stations); +++ struct wireless_device *wdev = vif->wdev; ++ ++ if (sta_old && sta_new) { ++ free((void *) sta_old->section); ++@@ -1088,10 +1084,6 @@ wireless_device_create(struct wireless_d ++ INIT_LIST_HEAD(&wdev->script_proc); ++ vlist_init(&wdev->interfaces, avl_strcmp, vif_update); ++ wdev->interfaces.keep_old = true; ++- vlist_init(&wdev->vlans, avl_strcmp, vlan_update); ++- wdev->vlans.keep_old = true; ++- vlist_init(&wdev->stations, avl_strcmp, station_update); ++- wdev->stations.keep_old = true; ++ ++ wdev->timeout.cb = wireless_device_setup_timeout; ++ wdev->script_task.cb = wireless_device_script_task_cb; ++@@ -1108,12 +1100,12 @@ wireless_device_create(struct wireless_d ++ ++ /* creates a wireless station object. Called by config */ ++ void ++-wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section) +++wireless_station_create(struct wireless_interface *vif, struct blob_attr *data, const char *section) ++ { ++ struct wireless_station *sta; ++ struct blob_attr *tb[__STA_ATTR_MAX]; ++ struct blob_attr *cur; ++- char *name_buf, *vif_buf; +++ char *name_buf; ++ char name[8]; ++ ++ blobmsg_parse(sta_policy, __STA_ATTR_MAX, tb, blob_data(data), blob_len(data)); ++@@ -1122,18 +1114,15 @@ wireless_station_create(struct wireless_ ++ if (cur && blobmsg_get_bool(cur)) ++ return; ++ ++- sprintf(name, "%d", wdev->sta_idx++); +++ sprintf(name, "%d", vif->sta_idx++); ++ ++ sta = calloc_a(sizeof(*sta), ++- &name_buf, strlen(name) + 1, ++- &vif_buf, strlen(vif) + 1); +++ &name_buf, strlen(name) + 1); ++ sta->name = strcpy(name_buf, name); ++- sta->vif = strcpy(vif_buf, vif); ++- sta->wdev = wdev; ++ sta->config = data; ++ sta->section = section; ++ ++- vlist_add(&wdev->stations, &sta->node, sta->name); +++ vlist_add(&vif->stations, &sta->node, sta->name); ++ } ++ ++ /* ubus callback network.wireless.status, runs for every interface, encode the station */ ++@@ -1151,12 +1140,12 @@ wireless_station_status(struct wireless_ ++ ++ /* create a vlan object. Called by config */ ++ void ++-wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section) +++wireless_vlan_create(struct wireless_interface *vif, struct blob_attr *data, const char *section) ++ { ++ struct wireless_vlan *vlan; ++ struct blob_attr *tb[__VLAN_ATTR_MAX]; ++ struct blob_attr *cur; ++- char *name_buf, *vif_buf; +++ char *name_buf; ++ char name[8]; ++ ++ blobmsg_parse(vlan_policy, __VLAN_ATTR_MAX, tb, blob_data(data), blob_len(data)); ++@@ -1165,19 +1154,14 @@ wireless_vlan_create(struct wireless_dev ++ if (cur && blobmsg_get_bool(cur)) ++ return; ++ ++- sprintf(name, "%d", wdev->vlan_idx++); +++ sprintf(name, "%d", vif->vlan_idx++); ++ ++- vlan = calloc_a(sizeof(*vlan), ++- &name_buf, strlen(name) + 1, ++- &vif_buf, strlen(vif) + 1); +++ vlan = calloc_a(sizeof(*vlan), &name_buf, strlen(name) + 1); ++ vlan->name = strcpy(name_buf, name); ++- vlan->vif = strcpy(vif_buf, vif); ++- vlan->wdev = wdev; ++ vlan->config = data; ++ vlan->section = section; ++- vlan->isolate = false; ++ ++- vlist_add(&wdev->vlans, &vlan->node, vlan->name); +++ vlist_add(&vif->vlans, &vlan->node, vlan->name); ++ } ++ ++ /* ubus callback network.wireless.status, runs for every interface, encode the vlan informations */ ++@@ -1220,6 +1204,12 @@ struct wireless_interface* wireless_inte ++ vif->section = section; ++ vif->isolate = false; ++ +++ vlist_init(&vif->vlans, avl_strcmp, vlan_update); +++ vif->vlans.keep_old = true; +++ +++ vlist_init(&vif->stations, avl_strcmp, station_update); +++ vif->stations.keep_old = true; +++ ++ vlist_add(&wdev->interfaces, &vif->node, vif->name); ++ ++ return vlist_find(&wdev->interfaces, name, vif, node); ++@@ -1240,14 +1230,12 @@ wireless_interface_status(struct wireles ++ blobmsg_add_string(b, "ifname", iface->ifname); ++ put_container(b, iface->config, "config"); ++ j = blobmsg_open_array(b, "vlans"); ++- vlist_for_each_element(&iface->wdev->vlans, vlan, node) ++- if (!strcmp(iface->name, vlan->vif)) ++- wireless_vlan_status(vlan, b); +++ vlist_for_each_element(&iface->vlans, vlan, node) +++ wireless_vlan_status(vlan, b); ++ blobmsg_close_array(b, j); ++ j = blobmsg_open_array(b, "stations"); ++- vlist_for_each_element(&iface->wdev->stations, sta, node) ++- if (!strcmp(iface->name, sta->vif)) ++- wireless_station_status(sta, b); +++ vlist_for_each_element(&iface->stations, sta, node) +++ wireless_station_status(sta, b); ++ blobmsg_close_array(b, j); ++ blobmsg_close_table(b, i); ++ } ++@@ -1496,7 +1484,9 @@ wireless_device_notify(struct wireless_d ++ } ++ ++ if ((cur = tb[NOTIFY_ATTR_VLAN]) != NULL) { ++- vlan = vlist_find(&wdev->vlans, blobmsg_data(cur), vlan, node); +++ if (!vif) +++ return UBUS_STATUS_NOT_FOUND; +++ vlan = vlist_find(&vif->vlans, blobmsg_data(cur), vlan, node); ++ if (!vlan) ++ return UBUS_STATUS_NOT_FOUND; ++ } ++@@ -1516,19 +1506,19 @@ wireless_device_notify(struct wireless_d ++ wireless_device_mark_up(wdev); ++ break; ++ case NOTIFY_CMD_SET_DATA: ++- if (vif) ++- pdata = &vif->data; ++- else if (vlan) +++ if (vlan) ++ pdata = &vlan->data; +++ else if (vif) +++ pdata = &vif->data; ++ else ++ pdata = &wdev->data; ++ ++ free(*pdata); ++ *pdata = blob_memdup(cur); ++- if (vif) ++- wireless_interface_set_data(vif); ++- else if (vlan) +++ if (vlan) ++ wireless_vlan_set_data(vlan); +++ else if (vif) +++ wireless_interface_set_data(vif); ++ break; ++ case NOTIFY_CMD_PROCESS_ADD: ++ return wireless_device_add_process(wdev, cur); ++--- a/wireless.h +++++ b/wireless.h ++@@ -44,8 +44,6 @@ struct wireless_device { ++ ++ struct wireless_driver *drv; ++ struct vlist_tree interfaces; ++- struct vlist_tree vlans; ++- struct vlist_tree stations; ++ char *name; ++ ++ struct netifd_process script_task; ++@@ -73,8 +71,6 @@ struct wireless_device { ++ int retry; ++ ++ int vif_idx; ++- int vlan_idx; ++- int sta_idx; ++ }; ++ ++ struct wireless_interface { ++@@ -82,6 +78,8 @@ struct wireless_interface { ++ const char *section; ++ char *name; ++ +++ struct vlist_tree vlans; +++ struct vlist_tree stations; ++ struct wireless_device *wdev; ++ ++ struct blob_attr *config; ++@@ -94,6 +92,8 @@ struct wireless_interface { ++ bool isolate; ++ bool ap_mode; ++ int multicast_to_unicast; +++ int vlan_idx; +++ int sta_idx; ++ }; ++ ++ struct wireless_vlan { ++@@ -101,9 +101,6 @@ struct wireless_vlan { ++ const char *section; ++ char *name; ++ ++- struct wireless_device *wdev; ++- char *vif; ++- ++ struct blob_attr *config; ++ struct blob_attr *data; ++ ++@@ -119,9 +116,6 @@ struct wireless_station { ++ const char *section; ++ char *name; ++ ++- struct wireless_device *wdev; ++- char *vif; ++- ++ struct blob_attr *config; ++ struct blob_attr *data; ++ }; ++@@ -143,8 +137,8 @@ void wireless_device_reconf(struct wirel ++ void wireless_device_status(struct wireless_device *wdev, struct blob_buf *b); ++ void wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b); ++ struct wireless_interface* wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section); ++-void wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section); ++-void wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section); +++void wireless_vlan_create(struct wireless_interface *vif, struct blob_attr *data, const char *section); +++void wireless_station_create(struct wireless_interface *vif, struct blob_attr *data, const char *section); ++ int wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data, ++ struct ubus_request_data *req); ++ +-- +2.39.2 + From acd4b79dd4d14f7ae63294b527412512a2835809 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sun, 17 Sep 2023 06:49:46 +0200 Subject: [PATCH 26/32] ipq807x: backport latest wifi hot-reload to v5.4 kernel Signed-off-by: John Crispin --- feeds/ipq807x_v5.4/hostapd/files/common.uc | 156 +- feeds/ipq807x_v5.4/hostapd/files/hostapd.sh | 3 +- feeds/ipq807x_v5.4/hostapd/files/hostapd.uc | 603 ++++-- feeds/ipq807x_v5.4/hostapd/files/wdev.uc | 121 +- .../hostapd/files/wpa_supplicant.uc | 85 +- ...d-frequency-info-in-start-AP-command.patch | 43 + ...ix-setting-QoS-map-on-secondary-BSSs.patch | 20 + ...pdate-drv-ifindex-on-removing-the-fi.patch | 18 + .../hostapd/patches/601-ucode_support.patch | 214 +- .../hostapd/patches/901-cfg-section.patch | 12 - .../hostapd/patches/920-sta_driver_data.patch | 40 +- .../hostapd/patches/999-ssi_signal.patch | 22 - feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c | 39 + .../hostapd/src/src/ap/ubus.c.orig | 1845 +++++++++++++++++ feeds/ipq807x_v5.4/hostapd/src/src/ap/ucode.c | 355 +++- .../hostapd/src/src/utils/ucode.c | 15 +- .../hostapd/src/wpa_supplicant/ucode.c | 17 +- ...ive-renaming-when-an-interface-is-up.patch | 60 + ...ive-renaming-when-an-interface-is-up.patch | 67 + ...ive-renaming-when-an-interface-is-up.patch | 67 + .../files/lib/netifd/wireless/mac80211.sh | 74 +- ...race-period-for-DFS-available-after-.patch | 148 ++ 22 files changed, 3654 insertions(+), 370 deletions(-) create mode 100644 feeds/ipq807x_v5.4/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch create mode 100644 feeds/ipq807x_v5.4/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch create mode 100644 feeds/ipq807x_v5.4/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch create mode 100644 feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c.orig create mode 100644 feeds/ipq807x_v5.4/ipq60xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch create mode 100644 feeds/ipq807x_v5.4/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch create mode 100644 feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch create mode 100644 feeds/ipq807x_v5.4/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch diff --git a/feeds/ipq807x_v5.4/hostapd/files/common.uc b/feeds/ipq807x_v5.4/hostapd/files/common.uc index 9ece3b1af..ccffe3eb4 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/common.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/common.uc @@ -1,6 +1,6 @@ import * as nl80211 from "nl80211"; import * as rtnl from "rtnl"; -import { readfile } from "fs"; +import { readfile, glob, basename, readlink } from "fs"; const iftypes = { ap: nl80211.const.NL80211_IFTYPE_AP, @@ -94,6 +94,156 @@ function wdev_create(phy, name, data) return null; } +function phy_sysfs_file(phy, name) +{ + return trim(readfile(`/sys/class/ieee80211/${phy}/${name}`)); +} + +function macaddr_split(str) +{ + return map(split(str, ":"), (val) => hex(val)); +} + +function macaddr_join(addr) +{ + return join(":", map(addr, (val) => sprintf("%02x", val))); +} + +function wdev_macaddr(wdev) +{ + return trim(readfile(`/sys/class/net/${wdev}/address`)); +} + +const phy_proto = { + macaddr_init: function(used, options) { + this.macaddr_options = options ?? {}; + this.macaddr_list = {}; + + if (type(used) == "object") + for (let addr in used) + this.macaddr_list[addr] = used[addr]; + else + for (let addr in used) + this.macaddr_list[addr] = -1; + + this.for_each_wdev((wdev) => { + let macaddr = wdev_macaddr(wdev); + this.macaddr_list[macaddr] ??= -1; + }); + + return this.macaddr_list; + }, + + macaddr_generate: function(data) { + let phy = this.name; + let idx = int(data.id ?? 0); + let mbssid = int(data.mbssid ?? 0) > 0; + let num_global = int(data.num_global ?? 1); + let use_global = !mbssid && idx < num_global; + + let base_addr = phy_sysfs_file(phy, "macaddress"); + if (!base_addr) + return null; + + if (!idx && !mbssid) + return base_addr; + + let base_mask = phy_sysfs_file(phy, "address_mask"); + if (!base_mask) + return null; + + if (base_mask == "00:00:00:00:00:00" && idx >= num_global) { + let addrs = split(phy_sysfs_file(phy, "addresses"), "\n"); + + if (idx < length(addrs)) + return addrs[idx]; + + base_mask = "ff:ff:ff:ff:ff:ff"; + } + + let addr = macaddr_split(base_addr); + let mask = macaddr_split(base_mask); + let type; + + if (mbssid) + type = "b5"; + else if (use_global) + type = "add"; + else if (mask[0] > 0) + type = "b1"; + else if (mask[5] < 0xff) + type = "b5"; + else + type = "add"; + + switch (type) { + case "b1": + if (!(addr[0] & 2)) + idx--; + addr[0] |= 2; + addr[0] ^= idx << 2; + break; + case "b5": + if (mbssid) + addr[0] |= 2; + addr[5] ^= idx; + break; + default: + for (let i = 5; i > 0; i--) { + addr[i] += idx; + if (addr[i] < 256) + break; + addr[i] %= 256; + } + break; + } + + return macaddr_join(addr); + }, + + macaddr_next: function(val) { + let data = this.macaddr_options ?? {}; + let list = this.macaddr_list; + + for (let i = 0; i < 32; i++) { + data.id = i; + + let mac = this.macaddr_generate(data); + if (!mac) + return null; + + if (list[mac] != null) + continue; + + list[mac] = val != null ? val : -1; + return mac; + } + }, + + for_each_wdev: function(cb) { + let wdevs = glob(`/sys/class/ieee80211/${this.name}/device/net/*`); + wdevs = map(wdevs, (arg) => basename(arg)); + for (let wdev in wdevs) { + if (basename(readlink(`/sys/class/net/${wdev}/phy80211`)) != this.name) + continue; + + cb(wdev); + } + } +}; + +function phy_open(phy) +{ + let phyidx = readfile(`/sys/class/ieee80211/${phy}/index`); + if (!phyidx) + return null; + + return proto({ + name: phy, + idx: int(phyidx) + }, phy_proto); +} + const vlist_proto = { update: function(values, arg) { let data = this.data; @@ -150,7 +300,7 @@ function is_equal(val1, val2) { if (!is_equal(val1[key], val2[key])) return false; for (let key in val2) - if (!val1[key]) + if (val1[key] == null) return false; return true; } else { @@ -165,4 +315,4 @@ function vlist_new(cb) { }, vlist_proto); } -export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac }; +export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac, phy_open }; diff --git a/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh b/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh index 145848189..6311846d1 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh +++ b/feeds/ipq807x_v5.4/hostapd/files/hostapd.sh @@ -725,8 +725,7 @@ hostapd_set_bss_options() { [ -n "$wpa_strict_rekey" ] && append bss_conf "wpa_strict_rekey=$wpa_strict_rekey" "$N" } - set_default nasid "${macaddr//\:}" - append bss_conf "nas_identifier=$nasid" "$N" + [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N" [ -n "$acct_server" ] && { append bss_conf "acct_server_addr=$acct_server" "$N" diff --git a/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc b/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc index f9f0c31ba..ebf732bea 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/hostapd.uc @@ -1,6 +1,6 @@ let libubus = require("ubus"); import { open, readfile } from "fs"; -import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac, phy_open } from "common"; let ubus = libubus.connect(); @@ -31,7 +31,7 @@ function iface_remove(cfg) wdev_remove(bss.ifname); } -function iface_gen_config(phy, config) +function iface_gen_config(phy, config, start_disabled) { let str = `data: ${join("\n", config.radio.data)} @@ -41,18 +41,92 @@ channel=${config.radio.channel} for (let i = 0; i < length(config.bss); i++) { let bss = config.bss[i]; let type = i > 0 ? "bss" : "interface"; + let nasid = bss.nasid ?? replace(bss.bssid, ":", ""); str += ` ${type}=${bss.ifname} +bssid=${bss.bssid} ${join("\n", bss.data)} +nas_identifier=${nasid} +`; + if (start_disabled) + str += ` +start_disabled=1 `; } return str; } -function iface_restart(phy, config, old_config) +function iface_freq_info(iface, config, params) { + let freq = params.frequency; + if (!freq) + return null; + + let sec_offset = params.sec_chan_offset; + if (sec_offset != -1 && sec_offset != 1) + sec_offset = 0; + + let width = 0; + for (let line in config.radio.data) { + if (!sec_offset && match(line, /^ht_capab=.*HT40/)) { + sec_offset = null; // auto-detect + continue; + } + + let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth)=(\d+)/); + if (!val) + continue; + + val = int(val[2]); + if (val > width) + width = val; + } + + if (freq < 4000) + width = 0; + + return hostapd.freq_info(freq, sec_offset, width); +} + +function iface_add(phy, config, phy_status) +{ + let config_inline = iface_gen_config(phy, config, !!phy_status); + + let bss = config.bss[0]; + let ret = hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`); + if (ret < 0) + return false; + + if (!phy_status) + return true; + + let iface = hostapd.interfaces[bss.ifname]; + if (!iface) + return false; + + let freq_info = iface_freq_info(iface, config, phy_status); + + return iface.start(freq_info) >= 0; +} + +function iface_config_macaddr_list(config) +{ + let macaddr_list = {}; + for (let i = 0; i < length(config.bss); i++) { + let bss = config.bss[i]; + if (!bss.default_macaddr) + macaddr_list[bss.bssid] = i; + } + + return macaddr_list; +} + +function iface_restart(phydev, config, old_config) +{ + let phy = phydev.name; + iface_remove(old_config); iface_remove(config); @@ -61,15 +135,29 @@ function iface_restart(phy, config, old_config) return; } + phydev.macaddr_init(iface_config_macaddr_list(config)); + for (let i = 0; i < length(config.bss); i++) { + let bss = config.bss[i]; + if (bss.default_macaddr) + bss.bssid = phydev.macaddr_next(); + } + let bss = config.bss[0]; let err = wdev_create(phy, bss.ifname, { mode: "ap" }); if (err) hostapd.printf(`Failed to create ${bss.ifname} on phy ${phy}: ${err}`); - let config_inline = iface_gen_config(phy, config); let ubus = hostapd.data.ubus; + let phy_status = ubus.call("wpa_supplicant", "phy_status", { phy: phy }); + if (phy_status && phy_status.state == "COMPLETED") { + if (iface_add(phy, config, phy_status)) + return; + + hostapd.printf(`Failed to bring up phy ${phy} ifname=${bss.ifname} with supplicant provided frequency`); + } + ubus.call("wpa_supplicant", "phy_set_state", { phy: phy, stop: true }); - if (hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`) < 0) + if (!iface_add(phy, config)) hostapd.printf(`hostapd.add_iface failed for phy ${phy} ifname=${bss.ifname}`); ubus.call("wpa_supplicant", "phy_set_state", { phy: phy, stop: false }); } @@ -111,8 +199,65 @@ function bss_reload_psk(bss, config, old_config) hostapd.printf(`Reload WPA PSK file for bss ${config.ifname}: ${ret}`); } -function iface_reload_config(phy, config, old_config) +function remove_file_fields(config) { + return filter(config, (line) => !hostapd.data.file_fields[split(line, "=")[0]]); +} + +function bss_remove_file_fields(config) +{ + let new_cfg = {}; + + for (let key in config) + new_cfg[key] = config[key]; + new_cfg.data = remove_file_fields(new_cfg.data); + new_cfg.hash = {}; + for (let key in config.hash) + new_cfg.hash[key] = config.hash[key]; + delete new_cfg.hash.wpa_psk_file; + delete new_cfg.hash.vlan_file; + + return new_cfg; +} + +function bss_config_hash(config) +{ + return hostapd.sha1(remove_file_fields(config) + ""); +} + +function bss_find_existing(config, prev_config, prev_hash) +{ + let hash = bss_config_hash(config.data); + + for (let i = 0; i < length(prev_config.bss); i++) { + if (!prev_hash[i] || hash != prev_hash[i]) + continue; + + prev_hash[i] = null; + return i; + } + + return -1; +} + +function get_config_bss(config, idx) +{ + if (!config.bss[idx]) { + hostapd.printf(`Invalid bss index ${idx}`); + return null; + } + + let ifname = config.bss[idx].ifname; + if (!ifname) + hostapd.printf(`Could not find bss ${config.bss[idx].ifname}`); + + return hostapd.bss[ifname]; +} + +function iface_reload_config(phydev, config, old_config) +{ + let phy = phydev.name; + if (!old_config || !is_equal(old_config.radio, config.radio)) return false; @@ -122,82 +267,230 @@ function iface_reload_config(phy, config, old_config) if (!old_config.bss || !old_config.bss[0]) return false; - if (config.bss[0].ifname != old_config.bss[0].ifname) - return false; - - let iface_name = config.bss[0].ifname; + let iface_name = old_config.bss[0].ifname; let iface = hostapd.interfaces[iface_name]; - if (!iface) + if (!iface) { + hostapd.printf(`Could not find previous interface ${iface_name}`); return false; + } let first_bss = hostapd.bss[iface_name]; - if (!first_bss) + if (!first_bss) { + hostapd.printf(`Could not find bss of previous interface ${iface_name}`); return false; + } + + let macaddr_list = iface_config_macaddr_list(config); + let bss_list = []; + let bss_list_cfg = []; + let prev_bss_hash = []; + + for (let bss in old_config.bss) { + let hash = bss_config_hash(bss.data); + push(prev_bss_hash, bss_config_hash(bss.data)); + } + + // Step 1: find (possibly renamed) interfaces with the same config + // and store them in the new order (with gaps) + for (let i = 0; i < length(config.bss); i++) { + let prev; + + // For fullmac devices, the first interface needs to be preserved, + // since it's treated as the master + if (!i && phy_is_fullmac(phy)) { + prev = 0; + prev_bss_hash[0] = null; + } else { + prev = bss_find_existing(config.bss[i], old_config, prev_bss_hash); + } + if (prev < 0) + continue; + + let cur_config = config.bss[i]; + let prev_config = old_config.bss[prev]; + + let prev_bss = get_config_bss(old_config, prev); + if (!prev_bss) + return false; + + // try to preserve MAC address of this BSS by reassigning another + // BSS if necessary + if (cur_config.default_macaddr && + !macaddr_list[prev_config.bssid]) { + macaddr_list[prev_config.bssid] = i; + cur_config.bssid = prev_config.bssid; + } + + bss_list[i] = prev_bss; + bss_list_cfg[i] = old_config.bss[prev]; + } + + if (config.mbssid && !bss_list_cfg[0]) { + hostapd.printf("First BSS changed with MBSSID enabled"); + return false; + } + + // Step 2: if none were found, rename and preserve the first one + if (length(bss_list) == 0) { + // can't change the bssid of the first bss + if (config.bss[0].bssid != old_config.bss[0].bssid) { + if (!config.bss[0].default_macaddr) { + hostapd.printf(`BSSID of first interface changed: ${lc(old_config.bss[0].bssid)} -> ${lc(config.bss[0].bssid)}`); + return false; + } + + config.bss[0].bssid = old_config.bss[0].bssid; + } + + let prev_bss = get_config_bss(old_config, 0); + if (!prev_bss) + return false; + + macaddr_list[config.bss[0].bssid] = 0; + bss_list[0] = prev_bss; + bss_list_cfg[0] = old_config.bss[0]; + prev_bss_hash[0] = null; + } + + // Step 3: delete all unused old interfaces + for (let i = 0; i < length(prev_bss_hash); i++) { + if (!prev_bss_hash[i]) + continue; + + let prev_bss = get_config_bss(old_config, i); + if (!prev_bss) + return false; + + let ifname = old_config.bss[i].ifname; + hostapd.printf(`Remove bss '${ifname}' on phy '${phy}'`); + prev_bss.delete(); + wdev_remove(ifname); + } + + // Step 4: rename preserved interfaces, use temporary name on duplicates + let rename_list = []; + for (let i = 0; i < length(bss_list); i++) { + if (!bss_list[i]) + continue; + + let old_ifname = bss_list_cfg[i].ifname; + let new_ifname = config.bss[i].ifname; + if (old_ifname == new_ifname) + continue; + + if (hostapd.bss[new_ifname]) { + new_ifname = "tmp_" + substr(hostapd.sha1(new_ifname), 0, 8); + push(rename_list, i); + } + + hostapd.printf(`Rename bss ${old_ifname} to ${new_ifname}`); + if (!bss_list[i].rename(new_ifname)) { + hostapd.printf(`Failed to rename bss ${old_ifname} to ${new_ifname}`); + return false; + } + + bss_list_cfg[i].ifname = new_ifname; + } + + // Step 5: rename interfaces with temporary names + for (let i in rename_list) { + let new_ifname = config.bss[i].ifname; + if (!bss_list[i].rename(new_ifname)) { + hostapd.printf(`Failed to rename bss to ${new_ifname}`); + return false; + } + bss_list_cfg[i].ifname = new_ifname; + } + + // Step 6: assign BSSID for newly created interfaces + let macaddr_data = { + num_global: config.num_global_macaddr ?? 1, + mbssid: config.mbssid ?? 0, + }; + macaddr_list = phydev.macaddr_init(macaddr_list, macaddr_data); + for (let i = 0; i < length(config.bss); i++) { + if (bss_list[i]) + continue; + let bsscfg = config.bss[i]; + + let mac_idx = macaddr_list[bsscfg.bssid]; + if (mac_idx < 0) + macaddr_list[bsscfg.bssid] = i; + if (mac_idx == i) + continue; + + // statically assigned bssid of the new interface is in conflict + // with the bssid of a reused interface. reassign the reused interface + if (!bsscfg.default_macaddr) { + // can't update bssid of the first BSS, need to restart + if (!mac_idx < 0) + return false; + + bsscfg = config.bss[mac_idx]; + } + + let addr = phydev.macaddr_next(i); + if (!addr) { + hostapd.printf(`Failed to generate mac address for phy ${phy}`); + return false; + } + bsscfg.bssid = addr; + } let config_inline = iface_gen_config(phy, config); - bss_reload_psk(first_bss, config.bss[0], old_config.bss[0]); - if (!is_equal(config.bss[0], old_config.bss[0])) { - if (phy_is_fullmac(phy)) - return false; + // Step 7: fill in the gaps with new interfaces + for (let i = 0; i < length(config.bss); i++) { + let ifname = config.bss[i].ifname; + let bss = bss_list[i]; - if (config.bss[0].bssid != old_config.bss[0].bssid) + if (bss) + continue; + + hostapd.printf(`Add bss ${ifname} on phy ${phy}`); + bss_list[i] = iface.add_bss(config_inline, i); + if (!bss_list[i]) { + hostapd.printf(`Failed to add new bss ${ifname} on phy ${phy}`); return false; + } + } + + // Step 8: update interface bss order + if (!iface.set_bss_order(bss_list)) { + hostapd.printf(`Failed to update BSS order on phy '${phy}'`); + return false; + } + + // Step 9: update config + for (let i = 0; i < length(config.bss); i++) { + if (!bss_list_cfg[i]) + continue; + + let ifname = config.bss[i].ifname; + let bss = bss_list[i]; + + if (is_equal(config.bss[i], bss_list_cfg[i])) + continue; + + if (is_equal(bss_remove_file_fields(config.bss[i]), + bss_remove_file_fields(bss_list_cfg[i]))) { + hostapd.printf(`Update config data files for bss ${ifname}`); + if (bss.set_config(config_inline, i, true) < 0) { + hostapd.printf(`Could not update config data files for bss ${ifname}`); + return false; + } else { + bss.ctrl("RELOAD_WPA_PSK"); + continue; + } + } + + bss_reload_psk(bss, config.bss[i], bss_list_cfg[i]); + if (is_equal(config.bss[i], bss_list_cfg[i])) + continue; hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); - if (first_bss.set_config(config_inline, 0) < 0) { - hostapd.printf(`Failed to set config`); - return false; - } - } - - let new_cfg = array_to_obj(config.bss, "ifname", 1); - let old_cfg = array_to_obj(old_config.bss, "ifname", 1); - - for (let name in old_cfg) { - let bss = hostapd.bss[name]; - if (!bss) { - hostapd.printf(`bss '${name}' not found`); - return false; - } - - if (!new_cfg[name]) { - hostapd.printf(`Remove bss '${name}' on phy '${phy}'`); - bss.delete(); - wdev_remove(name); - continue; - } - - let new_cfg_data = new_cfg[name]; - delete new_cfg[name]; - - if (is_equal(old_cfg[name], new_cfg_data)) - continue; - - hostapd.printf(`Reload config for bss '${name}' on phy '${phy}'`); - let idx = find_array_idx(config.bss, "ifname", name); - if (idx < 0) { - hostapd.printf(`bss index not found`); - return false; - } - - if (bss.set_config(config_inline, idx) < 0) { - hostapd.printf(`Failed to set config`); - return false; - } - } - - for (let name in new_cfg) { - hostapd.printf(`Add bss '${name}' on phy '${phy}'`); - - let idx = find_array_idx(config.bss, "ifname", name); - if (idx < 0) { - hostapd.printf(`bss index not found`); - return false; - } - - if (iface.add_bss(config_inline, idx) < 0) { - hostapd.printf(`Failed to add bss`); + if (bss.set_config(config_inline, i) < 0) { + hostapd.printf(`Failed to set config for bss ${ifname}`); return false; } } @@ -205,6 +498,14 @@ function iface_reload_config(phy, config, old_config) return true; } +function iface_update_supplicant_macaddr(phy, config) +{ + let macaddr_list = []; + for (let i = 0; i < length(config.bss); i++) + push(macaddr_list, config.bss[i].bssid); + ubus.call("wpa_supplicant", "phy_set_macaddr_list", { phy: phy, macaddr: macaddr_list }); +} + function iface_set_config(phy, config) { let old_config = hostapd.data.config[phy]; @@ -214,14 +515,28 @@ function iface_set_config(phy, config) if (!config) return iface_remove(old_config); - let ret = iface_reload_config(phy, config, old_config); - if (ret) { - hostapd.printf(`Reloaded settings for phy ${phy}`); - return 0; + let phydev = phy_open(phy); + if (!phydev) { + hostapd.printf(`Failed to open phy ${phy}`); + return false; + } + + try { + let ret = iface_reload_config(phydev, config, old_config); + if (ret) { + iface_update_supplicant_macaddr(phy, config); + hostapd.printf(`Reloaded settings for phy ${phy}`); + return 0; + } + } catch (e) { + hostapd.printf(`Error reloading config: ${e}\n${e.stacktrace[0].context}`); } hostapd.printf(`Restart interface for phy ${phy}`); - return iface_restart(phy, config, old_config); + let ret = iface_restart(phydev, config, old_config); + iface_update_supplicant_macaddr(phy, config); + + return ret; } function config_add_bss(config, name) @@ -268,16 +583,28 @@ function iface_load_config(filename) continue; } + if (val[0] == "#num_global_macaddr" || + val[0] == "mbssid") + config[val[0]] = int(val[1]); + push(config.radio.data, line); } while ((line = trim(f.read("line"))) != null) { + if (line == "#default_macaddr") + bss.default_macaddr = true; + let val = split(line, "=", 2); if (!val[0]) continue; - if (val[0] == "bssid") - bss.bssid = val[1]; + if (val[0] == "bssid") { + bss.bssid = lc(val[1]); + continue; + } + + if (val[0] == "nas_identifier") + bss.nasid = val[1]; if (val[0] == "bss") { bss = config_add_bss(config, val[1]); @@ -294,28 +621,33 @@ function iface_load_config(filename) return config; } - +function ex_wrap(func) { + return (req) => { + try { + let ret = func(req); + return ret; + } catch(e) { + hostapd.printf(`Exception in ubus function: ${e}\n${e.stacktrace[0].context}`); + } + return libubus.STATUS_UNKNOWN_ERROR; + }; +} let main_obj = { reload: { args: { phy: "", }, - call: function(req) { - try { - let phy_list = req.args.phy ? [ req.args.phy ] : keys(hostapd.data.config); - for (let phy_name in phy_list) { - let phy = hostapd.data.config[phy_name]; - let config = iface_load_config(phy.orig_file); - iface_set_config(phy_name, config); - } - } catch(e) { - hostapd.printf(`Error reloading config: ${e}\n${e.stacktrace[0].context}`); - return libubus.STATUS_INVALID_ARGUMENT; + call: ex_wrap(function(req) { + let phy_list = req.args.phy ? [ req.args.phy ] : keys(hostapd.data.config); + for (let phy_name in phy_list) { + let phy = hostapd.data.config[phy_name]; + let config = iface_load_config(phy.orig_file); + iface_set_config(phy_name, config); } return 0; - } + }) }, apsta_state: { args: { @@ -326,7 +658,7 @@ let main_obj = { csa: true, csa_count: 0, }, - call: function(req) { + call: ex_wrap(function(req) { if (req.args.up == null || !req.args.phy) return libubus.STATUS_INVALID_ARGUMENT; @@ -344,34 +676,10 @@ let main_obj = { return 0; } - let freq = req.args.frequency; - if (!freq) + if (!req.args.frequency) return libubus.STATUS_INVALID_ARGUMENT; - let sec_offset = req.args.sec_chan_offset; - if (sec_offset != -1 && sec_offset != 1) - sec_offset = 0; - - let width = 0; - for (let line in config.radio.data) { - if (!sec_offset && match(line, /^ht_capab=.*HT40/)) { - sec_offset = null; // auto-detect - continue; - } - - let val = match(line, /^(vht_oper_chwidth|he_oper_chwidth)=(\d+)/); - if (!val) - continue; - - val = int(val[2]); - if (val > width) - width = val; - } - - if (freq < 4000) - width = 0; - - let freq_info = hostapd.freq_info(freq, sec_offset, width); + let freq_info = iface_freq_info(iface, config, req.args); if (!freq_info) return libubus.STATUS_UNKNOWN_ERROR; @@ -380,14 +688,34 @@ let main_obj = { freq_info.csa_count = req.args.csa_count ?? 10; ret = iface.switch_channel(freq_info); } else { - iface.stop(); ret = iface.start(freq_info); } if (!ret) return libubus.STATUS_UNKNOWN_ERROR; return 0; - } + }) + }, + config_get_macaddr_list: { + args: { + phy: "" + }, + call: ex_wrap(function(req) { + let phy = req.args.phy; + if (!phy) + return libubus.STATUS_INVALID_ARGUMENT; + + let ret = { + macaddr: [], + }; + + let config = hostapd.data.config[phy]; + if (!config) + return ret; + + ret.macaddr = map(config.bss, (bss) => bss.bssid); + return ret; + }) }, config_set: { args: { @@ -395,7 +723,7 @@ let main_obj = { config: "", prev_config: "", }, - call: function(req) { + call: ex_wrap(function(req) { let phy = req.args.phy; let file = req.args.config; let prev_file = req.args.prev_config; @@ -403,34 +731,29 @@ let main_obj = { if (!phy) return libubus.STATUS_INVALID_ARGUMENT; - try { - if (prev_file && !hostapd.data.config[phy]) { - let config = iface_load_config(prev_file); - if (config) - config.radio.data = []; - hostapd.data.config[phy] = config; - } - - let config = iface_load_config(file); - - hostapd.printf(`Set new config for phy ${phy}: ${file}`); - iface_set_config(phy, config); - } catch(e) { - hostapd.printf(`Error loading config: ${e}\n${e.stacktrace[0].context}`); - return libubus.STATUS_INVALID_ARGUMENT; + if (prev_file && !hostapd.data.config[phy]) { + let config = iface_load_config(prev_file); + if (config) + config.radio.data = []; + hostapd.data.config[phy] = config; } + let config = iface_load_config(file); + + hostapd.printf(`Set new config for phy ${phy}: ${file}`); + iface_set_config(phy, config); + return { pid: hostapd.getpid() }; - } + }) }, config_add: { args: { iface: "", config: "", }, - call: function(req) { + call: ex_wrap(function(req) { if (!req.args.iface || !req.args.config) return libubus.STATUS_INVALID_ARGUMENT; @@ -440,19 +763,19 @@ let main_obj = { return { pid: hostapd.getpid() }; - } + }) }, config_remove: { args: { iface: "" }, - call: function(req) { + call: ex_wrap(function(req) { if (!req.args.iface) return libubus.STATUS_INVALID_ARGUMENT; hostapd.remove_iface(req.args.iface); return 0; - } + }) }, }; diff --git a/feeds/ipq807x_v5.4/hostapd/files/wdev.uc b/feeds/ipq807x_v5.4/hostapd/files/wdev.uc index 5b321423e..8a031b40b 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/wdev.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/wdev.uc @@ -1,11 +1,14 @@ #!/usr/bin/env ucode 'use strict'; -import { vlist_new, is_equal, wdev_create, wdev_remove } from "/usr/share/hostap/common.uc"; +import { vlist_new, is_equal, wdev_create, wdev_remove, phy_open } from "/usr/share/hostap/common.uc"; import { readfile, writefile, basename, readlink, glob } from "fs"; +let libubus = require("ubus"); let keep_devices = {}; let phy = shift(ARGV); -let new_config = shift(ARGV); +let command = shift(ARGV); +let phydev; + const mesh_params = [ "mesh_retry_timeout", "mesh_confirm_timeout", "mesh_holding_timeout", "mesh_max_peer_links", "mesh_max_retries", "mesh_ttl", "mesh_element_ttl", "mesh_hwmp_max_preq_retries", @@ -33,6 +36,11 @@ function iface_start(wdev) system([ "ip", "link", "set", "dev", ifname, "down" ]); wdev_remove(ifname); } + let wdev_config = {}; + for (let key in wdev) + wdev_config[key] = wdev[key]; + if (!wdev_config.macaddr && wdev.mode != "monitor") + wdev_config.macaddr = phydev.macaddr_next(); wdev_create(phy, ifname, wdev); system([ "ip", "link", "set", "dev", ifname, "up" ]); if (wdev.freq) @@ -47,7 +55,7 @@ function iface_start(wdev) system(cmd); } else if (wdev.mode == "mesh") { let cmd = [ "iw", "dev", ifname, "mesh", "join", wdev.ssid, "freq", wdev.freq, wdev.htmode ]; - for (let key in [ "beacon-interval", "mcast-rate" ]) + for (let key in [ "mcast-rate", "beacon-interval" ]) if (wdev[key]) push(cmd, key, wdev[key]); system(cmd); @@ -114,43 +122,86 @@ function add_existing(phy, config) } } +function usage() +{ + warn(`Usage: ${basename(sourcepath())} [] -let statefile = `/var/run/wdev-${phy}.json`; - -for (let dev in ARGV) - keep_devices[dev] = true; - -if (!phy || !new_config) { - warn(`Usage: ${basename(sourcepath())} [ [ - get phy MAC address for vif index +`); exit(1); } -if (!readfile(`/sys/class/ieee80211/${phy}/index`)) { +const commands = { + set_config: function(args) { + let statefile = `/var/run/wdev-${phy}.json`; + + let new_config = shift(args); + for (let dev in ARGV) + keep_devices[dev] = true; + + if (!new_config) + usage(); + + new_config = json(new_config); + if (!new_config) { + warn("Invalid configuration\n"); + exit(1); + } + + let old_config = readfile(statefile); + if (old_config) + old_config = json(old_config); + + let config = vlist_new(iface_cb); + if (type(old_config) == "object") + config.data = old_config; + + add_existing(phy, config.data); + add_ifname(config.data); + drop_inactive(config.data); + + let ubus = libubus.connect(); + let data = ubus.call("hostapd", "config_get_macaddr_list", { phy: phy }); + let macaddr_list = []; + if (type(data) == "object" && data.macaddr) + macaddr_list = data.macaddr; + ubus.disconnect(); + phydev.macaddr_init(macaddr_list); + + add_ifname(new_config); + config.update(new_config); + + drop_inactive(config.data); + delete_ifname(config.data); + writefile(statefile, sprintf("%J", config.data)); + }, + get_macaddr: function(args) { + let data = {}; + + for (let arg in args) { + arg = split(arg, "=", 2); + data[arg[0]] = arg[1]; + } + + let macaddr = phydev.macaddr_generate(data); + if (!macaddr) { + warn(`Could not get MAC address for phy ${phy}\n`); + exit(1); + } + + print(macaddr + "\n"); + }, +}; + +if (!phy || !command | !commands[command]) + usage(); + +phydev = phy_open(phy); +if (!phydev) { warn(`PHY ${phy} does not exist\n`); exit(1); } -new_config = json(new_config); -if (!new_config) { - warn("Invalid configuration\n"); - exit(1); -} - -let old_config = readfile(statefile); -if (old_config) - old_config = json(old_config); - -let config = vlist_new(iface_cb); -if (type(old_config) == "object") - config.data = old_config; - -add_existing(phy, config.data); -add_ifname(config.data); -drop_inactive(config.data); - -add_ifname(new_config); -config.update(new_config); - -drop_inactive(config.data); -delete_ifname(config.data); -writefile(statefile, sprintf("%J", config.data)); +commands[command](ARGV); diff --git a/feeds/ipq807x_v5.4/hostapd/files/wpa_supplicant.uc b/feeds/ipq807x_v5.4/hostapd/files/wpa_supplicant.uc index e3a3afcff..cb5f41b1a 100644 --- a/feeds/ipq807x_v5.4/hostapd/files/wpa_supplicant.uc +++ b/feeds/ipq807x_v5.4/hostapd/files/wpa_supplicant.uc @@ -1,11 +1,12 @@ let libubus = require("ubus"); import { open, readfile } from "fs"; -import { wdev_create, wdev_remove, is_equal, vlist_new } from "common"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_open } from "common"; let ubus = libubus.connect(); wpas.data.config = {}; wpas.data.iface_phy = {}; +wpas.data.macaddr_list = {}; function iface_stop(iface) { @@ -20,16 +21,23 @@ function iface_stop(iface) iface.running = false; } -function iface_start(phy, iface) +function iface_start(phydev, iface, macaddr_list) { + let phy = phydev.name; + if (iface.running) return; let ifname = iface.config.iface; + let wdev_config = {}; + for (let field in iface.config) + wdev_config[field] = iface.config[field]; + if (!wdev_config.macaddr) + wdev_config.macaddr = phydev.macaddr_next(); wpas.data.iface_phy[ifname] = phy; wdev_remove(ifname); - let ret = wdev_create(phy, ifname, iface.config); + let ret = wdev_create(phy, ifname, wdev_config); if (ret) wpas.printf(`Failed to create device ${ifname}: ${ret}`); wpas.add_iface(iface.config); @@ -43,6 +51,11 @@ function iface_cb(new_if, old_if) return; } + if (new_if && old_if) + wpas.printf(`Update configuration for interface ${old_if.config.iface}`); + else if (old_if) + wpas.printf(`Remove interface ${old_if.config.iface}`); + if (old_if) iface_stop(old_if); } @@ -73,9 +86,22 @@ function set_config(phy_name, config_list) function start_pending(phy_name) { let phy = wpas.data.config[phy_name]; + let ubus = wpas.data.ubus; + + if (!phy || !phy.data) + return; + + let phydev = phy_open(phy_name); + if (!phydev) { + wpas.printf(`Could not open phy ${phy_name}`); + return; + } + + let macaddr_list = wpas.data.macaddr_list[phy_name]; + phydev.macaddr_init(macaddr_list); for (let ifname in phy.data) - iface_start(phy_name, phy.data[ifname]); + iface_start(phydev, phy.data[ifname]); } let main_obj = { @@ -106,6 +132,55 @@ let main_obj = { return 0; } }, + phy_set_macaddr_list: { + args: { + phy: "", + macaddr: [], + }, + call: function(req) { + let phy = req.args.phy; + if (!phy) + return libubus.STATUS_INVALID_ARGUMENT; + + wpas.data.macaddr_list[phy] = req.args.macaddr; + return 0; + } + }, + phy_status: { + args: { + phy: "" + }, + call: function(req) { + if (!req.args.phy) + return libubus.STATUS_INVALID_ARGUMENT; + + let phy = wpas.data.config[req.args.phy]; + if (!phy) + return libubus.STATUS_NOT_FOUND; + + for (let ifname in phy.data) { + try { + let iface = wpas.interfaces[ifname]; + if (!iface) + continue; + + let status = iface.status(); + if (!status) + continue; + + if (status.state == "INTERFACE_DISABLED") + continue; + + status.ifname = ifname; + return status; + } catch (e) { + continue; + } + } + + return libubus.STATUS_NOT_FOUND; + } + }, config_set: { args: { phy: "", @@ -116,6 +191,7 @@ let main_obj = { if (!req.args.phy) return libubus.STATUS_INVALID_ARGUMENT; + wpas.printf(`Set new config for phy ${req.args.phy}`); try { if (req.args.config) set_config(req.args.phy, req.args.config); @@ -188,6 +264,7 @@ function iface_hostapd_notify(phy, ifname, iface, state) switch (state) { case "DISCONNECTED": case "AUTHENTICATING": + case "SCANNING": msg.up = false; break; case "INTERFACE_DISABLED": diff --git a/feeds/ipq807x_v5.4/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch b/feeds/ipq807x_v5.4/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch new file mode 100644 index 000000000..ebe0ef12a --- /dev/null +++ b/feeds/ipq807x_v5.4/hostapd/patches/040-nl80211-Add-frequency-info-in-start-AP-command.patch @@ -0,0 +1,43 @@ +From: Harshitha Prem +Date: Wed, 22 Feb 2023 09:29:01 +0530 +Subject: [PATCH] nl80211: Add frequency info in start AP command + +When ACS is configured in multiple BSS case, sometimes a virtual AP +interface does not come up as the channel context information between +different BSSs of the same band does not match. + +Same behavior is observed in case of multiple band/hardware under a +single wiphy, when we bring up multiple virtual interface in various +bands simultaneously and the kernel maps a random channel as it has more +than one channel context, e.g., say a 2.4 GHz channel to a 5 GHz virtual +AP interface when the start AP command is sent. This is because the +frequency information is not present in the command. + +Add the frequency information into the start AP netlink command so that +the kernel maps the appropriate channel context by parsing it instead of +using a previous set channel information. + +Signed-off-by: Harshitha Prem +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -167,6 +167,8 @@ static int nl80211_send_frame_cmd(struct + const u16 *csa_offs, size_t csa_offs_len); + static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, + int report); ++static int nl80211_put_freq_params(struct nl_msg *msg, ++ const struct hostapd_freq_params *freq); + + #define IFIDX_ANY -1 + +@@ -4717,6 +4719,9 @@ static int wpa_driver_nl80211_set_ap(voi + nla_nest_end(msg, spr); + } + ++ if (params->freq && nl80211_put_freq_params(msg, params->freq) < 0) ++ goto fail; ++ + if (params->freq && params->freq->he_enabled) { + struct nlattr *bss_color; + diff --git a/feeds/ipq807x_v5.4/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch b/feeds/ipq807x_v5.4/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch new file mode 100644 index 000000000..f30159840 --- /dev/null +++ b/feeds/ipq807x_v5.4/hostapd/patches/041-driver_nl80211-fix-setting-QoS-map-on-secondary-BSSs.patch @@ -0,0 +1,20 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 10:53:50 +0200 +Subject: [PATCH] driver_nl80211: fix setting QoS map on secondary BSSs + +The setting is per-BSS, not per PHY + +Signed-off-by: Felix Fietkau +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -10045,7 +10045,7 @@ static int nl80211_set_qos_map(void *pri + wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", + qos_map_set, qos_map_set_len); + +- if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || ++ if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_QOS_MAP)) || + nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { + nlmsg_free(msg); + return -ENOBUFS; diff --git a/feeds/ipq807x_v5.4/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch b/feeds/ipq807x_v5.4/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch new file mode 100644 index 000000000..a1a5b2821 --- /dev/null +++ b/feeds/ipq807x_v5.4/hostapd/patches/042-driver_nl80211-update-drv-ifindex-on-removing-the-fi.patch @@ -0,0 +1,18 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 11:28:03 +0200 +Subject: [PATCH] driver_nl80211: update drv->ifindex on removing the first + BSS + +Signed-off-by: Felix Fietkau +--- + +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -8003,6 +8003,7 @@ static int wpa_driver_nl80211_if_remove( + if (drv->first_bss->next) { + drv->first_bss = drv->first_bss->next; + drv->ctx = drv->first_bss->ctx; ++ drv->ifindex = drv->first_bss->ifindex; + os_free(bss); + } else { + wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); diff --git a/feeds/ipq807x_v5.4/hostapd/patches/601-ucode_support.patch b/feeds/ipq807x_v5.4/hostapd/patches/601-ucode_support.patch index d542f3b2b..52a762417 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/601-ucode_support.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/601-ucode_support.patch @@ -287,7 +287,33 @@ --- a/src/drivers/driver.h +++ b/src/drivers/driver.h -@@ -5827,6 +5827,7 @@ union wpa_event_data { +@@ -3357,6 +3357,25 @@ struct wpa_driver_ops { + const char *ifname); + + /** ++ * if_rename - Rename a virtual interface ++ * @priv: Private driver interface data ++ * @type: Interface type ++ * @ifname: Interface name of the virtual interface to be renamed ++ * (NULL when renaming the AP BSS interface) ++ * @new_name: New interface name of the virtual interface ++ * Returns: 0 on success, -1 on failure ++ */ ++ int (*if_rename)(void *priv, enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name); ++ ++ /** ++ * set_first_bss - Make a virtual interface the first (primary) bss ++ * @priv: Private driver interface data ++ * Returns: 0 on success, -1 on failure ++ */ ++ int (*set_first_bss)(void *priv); ++ ++ /** + * set_sta_vlan - Bind a station into a specific interface (AP only) + * @priv: Private driver interface data + * @ifname: Interface (main or virtual BSS or VLAN) +@@ -5827,6 +5846,7 @@ union wpa_event_data { /** * struct ch_switch @@ -295,7 +321,7 @@ * @freq: Frequency of new channel in MHz * @ht_enabled: Whether this is an HT channel * @ch_offset: Secondary channel offset -@@ -5835,6 +5836,7 @@ union wpa_event_data { +@@ -5835,6 +5855,7 @@ union wpa_event_data { * @cf2: Center frequency 2 */ struct ch_switch { @@ -348,3 +374,187 @@ switch (event) { case EVENT_AUTH: #ifdef CONFIG_FST +--- a/src/ap/ap_drv_ops.h ++++ b/src/ap/ap_drv_ops.h +@@ -367,6 +367,23 @@ static inline int hostapd_drv_stop_ap(st + return hapd->driver->stop_ap(hapd->drv_priv); + } + ++static inline int hostapd_drv_if_rename(struct hostapd_data *hapd, ++ enum wpa_driver_if_type type, ++ const char *ifname, ++ const char *new_name) ++{ ++ if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv) ++ return -1; ++ return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name); ++} ++ ++static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd) ++{ ++ if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv) ++ return 0; ++ return hapd->driver->set_first_bss(hapd->drv_priv); ++} ++ + static inline int hostapd_drv_channel_info(struct hostapd_data *hapd, + struct wpa_channel_info *ci) + { +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -1222,7 +1222,7 @@ static void wpa_driver_nl80211_event_rtm + } + wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", + namebuf, ifname); +- if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { ++ if (drv->first_bss->ifindex != ifi->ifi_index) { + wpa_printf(MSG_DEBUG, + "nl80211: Not the main interface (%s) - do not indicate interface down", + drv->first_bss->ifname); +@@ -1258,7 +1258,7 @@ static void wpa_driver_nl80211_event_rtm + } + wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", + namebuf, ifname); +- if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { ++ if (drv->first_bss->ifindex != ifi->ifi_index) { + wpa_printf(MSG_DEBUG, + "nl80211: Not the main interface (%s) - do not indicate interface up", + drv->first_bss->ifname); +@@ -7609,6 +7609,7 @@ static void *i802_init(struct hostapd_da + char master_ifname[IFNAMSIZ]; + int ifindex, br_ifindex = 0; + int br_added = 0; ++ int err; + + bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, + params->global_priv, 1, +@@ -7668,21 +7669,17 @@ static void *i802_init(struct hostapd_da + (params->num_bridge == 0 || !params->bridge[0])) + add_ifidx(drv, br_ifindex, drv->ifindex); + +- if (bss->added_if_into_bridge || bss->already_in_bridge) { +- int err; +- +- drv->rtnl_sk = nl_socket_alloc(); +- if (drv->rtnl_sk == NULL) { +- wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); +- goto failed; +- } ++ drv->rtnl_sk = nl_socket_alloc(); ++ if (drv->rtnl_sk == NULL) { ++ wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); ++ goto failed; ++ } + +- err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); +- if (err) { +- wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", +- nl_geterror(err)); +- goto failed; +- } ++ err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); ++ if (err) { ++ wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", ++ nl_geterror(err)); ++ goto failed; + } + + if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { +@@ -8041,6 +8038,50 @@ static int wpa_driver_nl80211_if_remove( + return 0; + } + ++static int wpa_driver_nl80211_if_rename(struct i802_bss *bss, ++ enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name) ++{ ++ struct wpa_driver_nl80211_data *drv = bss->drv; ++ struct ifinfomsg ifi = { ++ .ifi_family = AF_UNSPEC, ++ .ifi_index = bss->ifindex, ++ }; ++ struct nl_msg *msg; ++ int res = -ENOMEM; ++ ++ if (ifname) ++ ifi.ifi_index = if_nametoindex(ifname); ++ ++ msg = nlmsg_alloc_simple(RTM_SETLINK, 0); ++ if (!msg) ++ return res; ++ ++ if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0) ++ goto out; ++ ++ if (nla_put_string(msg, IFLA_IFNAME, new_name)) ++ goto out; ++ ++ res = nl_send_auto_complete(drv->rtnl_sk, msg); ++ if (res < 0) ++ goto out; ++ ++ res = nl_wait_for_ack(drv->rtnl_sk); ++ if (res) { ++ wpa_printf(MSG_INFO, ++ "nl80211: Renaming device %s to %s failed: %s", ++ ifname ? ifname : bss->ifname, new_name, nl_geterror(res)); ++ goto out; ++ } ++ ++ if (type == WPA_IF_AP_BSS && !ifname) ++ os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname)); ++ ++out: ++ nlmsg_free(msg); ++ return res; ++} + + static int cookie_handler(struct nl_msg *msg, void *arg) + { +@@ -9385,6 +9426,37 @@ static int driver_nl80211_if_remove(void + } + + ++static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type, ++ const char *ifname, const char *new_name) ++{ ++ struct i802_bss *bss = priv; ++ return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name); ++} ++ ++ ++static int driver_nl80211_set_first_bss(void *priv) ++{ ++ struct i802_bss *bss = priv, *tbss; ++ struct wpa_driver_nl80211_data *drv = bss->drv; ++ ++ if (drv->first_bss == bss) ++ return 0; ++ ++ for (tbss = drv->first_bss; tbss; tbss = tbss->next) { ++ if (tbss->next != bss) ++ continue; ++ ++ tbss->next = bss->next; ++ bss->next = drv->first_bss; ++ drv->first_bss = bss; ++ drv->ctx = bss->ctx; ++ return 0; ++ } ++ ++ return -1; ++} ++ ++ + static int driver_nl80211_send_mlme(void *priv, const u8 *data, + size_t data_len, int noack, + unsigned int freq, +@@ -11967,6 +12039,8 @@ const struct wpa_driver_ops wpa_driver_n + .set_acl = wpa_driver_nl80211_set_acl, + .if_add = wpa_driver_nl80211_if_add, + .if_remove = driver_nl80211_if_remove, ++ .if_rename = driver_nl80211_if_rename, ++ .set_first_bss = driver_nl80211_set_first_bss, + .send_mlme = driver_nl80211_send_mlme, + .get_hw_feature_data = nl80211_get_hw_feature_data, + .sta_add = wpa_driver_nl80211_sta_add, diff --git a/feeds/ipq807x_v5.4/hostapd/patches/901-cfg-section.patch b/feeds/ipq807x_v5.4/hostapd/patches/901-cfg-section.patch index b640f17db..9122a4236 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/901-cfg-section.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/901-cfg-section.patch @@ -19,18 +19,6 @@ enum hostapd_logger_level logger_syslog_level, logger_stdout_level; ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -424,6 +424,9 @@ hostapd_bss_get_status(struct ubus_conte - hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); - blobmsg_close_table(&b, dfs_table); - -+ if (hapd->conf->uci_section) -+ blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); -+ - ubus_send_reply(ctx, req, b.head); - - return 0; --- a/src/ap/ap_config.c +++ b/src/ap/ap_config.c @@ -785,6 +785,7 @@ void hostapd_config_free_bss(struct host diff --git a/feeds/ipq807x_v5.4/hostapd/patches/920-sta_driver_data.patch b/feeds/ipq807x_v5.4/hostapd/patches/920-sta_driver_data.patch index 6bf5e5661..4d11051d1 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/920-sta_driver_data.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/920-sta_driver_data.patch @@ -50,42 +50,4 @@ return NL_SKIP; } ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -306,6 +306,36 @@ hostapd_bss_get_clients(struct ubus_cont - blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); - blobmsg_close_table(&b, r); - blobmsg_add_u32(&b, "signal", sta_driver_data.signal); -+ -+ r = blobmsg_open_table(&b, "mcs"); -+ if (sta_driver_data.rx_hemcs) { -+ blobmsg_add_u32(&b, "he", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_hemcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_hemcs); -+ } else if (sta_driver_data.rx_vhtmcs) { -+ blobmsg_add_u32(&b, "vht", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vhtmcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vhtmcs); -+ } else { -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); -+ } -+ blobmsg_close_table(&b, r); -+ -+ r = blobmsg_open_table(&b, "nss"); -+ if (sta_driver_data.rx_he_nss) { -+ blobmsg_add_u32(&b, "he", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_he_nss); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_he_nss); -+ } else if (sta_driver_data.rx_vht_nss) { -+ blobmsg_add_u32(&b, "vht", 1); -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vht_nss); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vht_nss); -+ } else { -+ blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); -+ blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); -+ } -+ blobmsg_close_table(&b, r); - } - - hostapd_parse_capab_blobmsg(sta); + diff --git a/feeds/ipq807x_v5.4/hostapd/patches/999-ssi_signal.patch b/feeds/ipq807x_v5.4/hostapd/patches/999-ssi_signal.patch index bdd0a0ede..cc7873284 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/999-ssi_signal.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/999-ssi_signal.patch @@ -61,28 +61,6 @@ }; ---- a/src/ap/ubus.c -+++ b/src/ap/ubus.c -@@ -336,6 +336,9 @@ hostapd_bss_get_clients(struct ubus_cont - blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); - } - blobmsg_close_table(&b, r); -+ -+ if (sta->signal_mgmt) -+ blobmsg_add_u32(&b, "signal_mgmt", sta->signal_mgmt); - } - - hostapd_parse_capab_blobmsg(sta); -@@ -457,6 +460,9 @@ hostapd_bss_get_status(struct ubus_conte - if (hapd->conf->uci_section) - blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); - -+ if (hapd->signal_mgmt) -+ blobmsg_add_u32(&b, "signal_mgmt", hapd->signal_mgmt); -+ - ubus_send_reply(ctx, req, b.head); - - return 0; --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -451,6 +451,7 @@ struct hostapd_data { diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c index 65f9fb834..6013304a0 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c +++ b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c @@ -306,6 +306,39 @@ hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); blobmsg_close_table(&b, r); blobmsg_add_u32(&b, "signal", sta_driver_data.signal); + + r = blobmsg_open_table(&b, "mcs"); + if (sta_driver_data.rx_hemcs) { + blobmsg_add_u32(&b, "he", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_hemcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_hemcs); + } else if (sta_driver_data.rx_vhtmcs) { + blobmsg_add_u32(&b, "vht", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vhtmcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vhtmcs); + } else { + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); + } + blobmsg_close_table(&b, r); + + r = blobmsg_open_table(&b, "nss"); + if (sta_driver_data.rx_he_nss) { + blobmsg_add_u32(&b, "he", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_he_nss); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_he_nss); + } else if (sta_driver_data.rx_vht_nss) { + blobmsg_add_u32(&b, "vht", 1); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_vht_nss); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_vht_nss); + } else { + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_mcs); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_mcs); + } + blobmsg_close_table(&b, r); + + if (sta->signal_mgmt) + blobmsg_add_u32(&b, "signal_mgmt", sta->signal_mgmt); } hostapd_parse_capab_blobmsg(sta); @@ -424,6 +457,12 @@ hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); blobmsg_close_table(&b, dfs_table); + if (hapd->conf->uci_section) + blobmsg_add_string(&b, "uci_section", hapd->conf->uci_section); + + if (hapd->signal_mgmt) + blobmsg_add_u32(&b, "signal_mgmt", hapd->signal_mgmt); + ubus_send_reply(ctx, req, b.head); return 0; diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c.orig b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c.orig new file mode 100644 index 000000000..befa3bc84 --- /dev/null +++ b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c.orig @@ -0,0 +1,1845 @@ +/* + * hostapd / ubus support + * Copyright (c) 2013, Felix Fietkau + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#include "utils/includes.h" +#include "utils/common.h" +#include "utils/eloop.h" +#include "utils/wpabuf.h" +#include "common/ieee802_11_defs.h" +#include "common/hw_features_common.h" +#include "hostapd.h" +#include "neighbor_db.h" +#include "wps_hostapd.h" +#include "sta_info.h" +#include "ubus.h" +#include "ap_drv_ops.h" +#include "beacon.h" +#include "rrm.h" +#include "wnm_ap.h" +#include "taxonomy.h" +#include "airtime_policy.h" +#include "hw_features.h" + +static struct ubus_context *ctx; +static struct blob_buf b; +static int ctx_ref; + +static inline struct hostapd_data *get_hapd_from_object(struct ubus_object *obj) +{ + return container_of(obj, struct hostapd_data, ubus.obj); +} + +struct ubus_banned_client { + struct avl_node avl; + u8 addr[ETH_ALEN]; +}; + +static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx) +{ + if (ubus_reconnect(ctx, NULL)) { + eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL); + return; + } + + ubus_add_uloop(ctx); +} + +static void hostapd_ubus_connection_lost(struct ubus_context *ctx) +{ + uloop_fd_delete(&ctx->sock); + eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL); +} + +static bool hostapd_ubus_init(void) +{ + if (ctx) + return true; + + eloop_add_uloop(); + ctx = ubus_connect(NULL); + if (!ctx) + return false; + + ctx->connection_lost = hostapd_ubus_connection_lost; + ubus_add_uloop(ctx); + + return true; +} + +static void hostapd_ubus_ref_inc(void) +{ + ctx_ref++; +} + +static void hostapd_ubus_ref_dec(void) +{ + ctx_ref--; + if (!ctx) + return; + + if (ctx_ref) + return; + + uloop_fd_delete(&ctx->sock); + ubus_free(ctx); + ctx = NULL; +} + +void hostapd_ubus_add_iface(struct hostapd_iface *iface) +{ + if (!hostapd_ubus_init()) + return; +} + +void hostapd_ubus_free_iface(struct hostapd_iface *iface) +{ + if (!ctx) + return; +} + +static void hostapd_notify_ubus(struct ubus_object *obj, char *bssname, char *event) +{ + char *event_type; + + if (!ctx || !obj) + return; + + if (asprintf(&event_type, "bss.%s", event) < 0) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "name", bssname); + ubus_notify(ctx, obj, event_type, b.head, -1); + free(event_type); +} + +static void +hostapd_bss_del_ban(void *eloop_data, void *user_ctx) +{ + struct ubus_banned_client *ban = eloop_data; + struct hostapd_data *hapd = user_ctx; + + avl_delete(&hapd->ubus.banned, &ban->avl); + free(ban); +} + +static void +hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time) +{ + struct ubus_banned_client *ban; + + if (time < 0) + time = 0; + + ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl); + if (!ban) { + if (!time) + return; + + ban = os_zalloc(sizeof(*ban)); + memcpy(ban->addr, addr, sizeof(ban->addr)); + ban->avl.key = ban->addr; + avl_insert(&hapd->ubus.banned, &ban->avl); + } else { + eloop_cancel_timeout(hostapd_bss_del_ban, ban, hapd); + if (!time) { + hostapd_bss_del_ban(ban, hapd); + return; + } + } + + eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd); +} + +static int +hostapd_bss_reload(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + return hostapd_reload_config(hapd->iface); +} + + +static void +hostapd_parse_vht_map_blobmsg(uint16_t map) +{ + char label[4]; + int16_t val; + int i; + + for (i = 0; i < 8; i++) { + snprintf(label, 4, "%dss", i + 1); + + val = (map & (BIT(1) | BIT(0))) + 7; + blobmsg_add_u16(&b, label, val == 10 ? -1 : val); + map = map >> 2; + } +} + +static void +hostapd_parse_vht_capab_blobmsg(struct ieee80211_vht_capabilities *vhtc) +{ + void *supported_mcs; + void *map; + int i; + + static const struct { + const char *name; + uint32_t flag; + } vht_capas[] = { + { "su_beamformee", VHT_CAP_SU_BEAMFORMEE_CAPABLE }, + { "mu_beamformee", VHT_CAP_MU_BEAMFORMEE_CAPABLE }, + }; + + for (i = 0; i < ARRAY_SIZE(vht_capas); i++) + blobmsg_add_u8(&b, vht_capas[i].name, + !!(vhtc->vht_capabilities_info & vht_capas[i].flag)); + + supported_mcs = blobmsg_open_table(&b, "mcs_map"); + + /* RX map */ + map = blobmsg_open_table(&b, "rx"); + hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc->vht_supported_mcs_set.rx_map)); + blobmsg_close_table(&b, map); + + /* TX map */ + map = blobmsg_open_table(&b, "tx"); + hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc->vht_supported_mcs_set.tx_map)); + blobmsg_close_table(&b, map); + + blobmsg_close_table(&b, supported_mcs); +} + +static void +hostapd_parse_capab_blobmsg(struct sta_info *sta) +{ + void *r, *v; + + v = blobmsg_open_table(&b, "capabilities"); + + if (sta->vht_capabilities) { + r = blobmsg_open_table(&b, "vht"); + hostapd_parse_vht_capab_blobmsg(sta->vht_capabilities); + blobmsg_close_table(&b, r); + } + + /* ToDo: Add HT / HE capability parsing */ + + blobmsg_close_table(&b, v); +} + +static int +hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct hostap_sta_driver_data sta_driver_data; + struct sta_info *sta; + void *list, *c; + char mac_buf[20]; + static const struct { + const char *name; + uint32_t flag; + } sta_flags[] = { + { "auth", WLAN_STA_AUTH }, + { "assoc", WLAN_STA_ASSOC }, + { "authorized", WLAN_STA_AUTHORIZED }, + { "preauth", WLAN_STA_PREAUTH }, + { "wds", WLAN_STA_WDS }, + { "wmm", WLAN_STA_WMM }, + { "ht", WLAN_STA_HT }, + { "vht", WLAN_STA_VHT }, + { "he", WLAN_STA_HE }, + { "wps", WLAN_STA_WPS }, + { "mfp", WLAN_STA_MFP }, + }; + + blob_buf_init(&b, 0); + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + list = blobmsg_open_table(&b, "clients"); + for (sta = hapd->sta_list; sta; sta = sta->next) { + void *r; + int i; + + sprintf(mac_buf, MACSTR, MAC2STR(sta->addr)); + c = blobmsg_open_table(&b, mac_buf); + for (i = 0; i < ARRAY_SIZE(sta_flags); i++) + blobmsg_add_u8(&b, sta_flags[i].name, + !!(sta->flags & sta_flags[i].flag)); + + r = blobmsg_open_array(&b, "rrm"); + for (i = 0; i < ARRAY_SIZE(sta->rrm_enabled_capa); i++) + blobmsg_add_u32(&b, "", sta->rrm_enabled_capa[i]); + blobmsg_close_array(&b, r); + blobmsg_add_u32(&b, "aid", sta->aid); +#ifdef CONFIG_TAXONOMY + r = blobmsg_alloc_string_buffer(&b, "signature", 1024); + if (retrieve_sta_taxonomy(hapd, sta, r, 1024) > 0) + blobmsg_add_string_buffer(&b); +#endif + + /* Driver information */ + if (hostapd_drv_read_sta_data(hapd, &sta_driver_data, sta->addr) >= 0) { + r = blobmsg_open_table(&b, "bytes"); + blobmsg_add_u64(&b, "rx", sta_driver_data.rx_bytes); + blobmsg_add_u64(&b, "tx", sta_driver_data.tx_bytes); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "airtime"); + blobmsg_add_u64(&b, "rx", sta_driver_data.rx_airtime); + blobmsg_add_u64(&b, "tx", sta_driver_data.tx_airtime); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "packets"); + blobmsg_add_u32(&b, "rx", sta_driver_data.rx_packets); + blobmsg_add_u32(&b, "tx", sta_driver_data.tx_packets); + blobmsg_close_table(&b, r); + r = blobmsg_open_table(&b, "rate"); + /* Rate in kbits */ + blobmsg_add_u32(&b, "rx", sta_driver_data.current_rx_rate * 100); + blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100); + blobmsg_close_table(&b, r); + blobmsg_add_u32(&b, "signal", sta_driver_data.signal); + } + + hostapd_parse_capab_blobmsg(sta); + + blobmsg_close_table(&b, c); + } + blobmsg_close_array(&b, list); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_bss_get_features(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + blob_buf_init(&b, 0); + blobmsg_add_u8(&b, "ht_supported", ht_supported(hapd->iface->hw_features)); + blobmsg_add_u8(&b, "vht_supported", vht_supported(hapd->iface->hw_features)); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +/* Imported from iw/util.c + * https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/util.c?id=4b25ae3537af48dbf9d0abf94132e5ba01b32c18#n200 + */ +int ieee80211_frequency_to_channel(int freq) +{ + /* see 802.11-2007 17.3.8.3.2 and Annex J */ + if (freq == 2484) + return 14; + /* see 802.11ax D6.1 27.3.23.2 and Annex E */ + else if (freq == 5935) + return 2; + else if (freq < 2484) + return (freq - 2407) / 5; + else if (freq >= 4910 && freq <= 4980) + return (freq - 4000) / 5; + else if (freq < 5950) + return (freq - 5000) / 5; + else if (freq <= 45000) /* DMG band lower limit */ + /* see 802.11ax D6.1 27.3.23.2 */ + return (freq - 5950) / 5; + else if (freq >= 58320 && freq <= 70200) + return (freq - 56160) / 2160; + else + return 0; +} + +static int +hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + void *airtime_table, *dfs_table, *rrm_table, *wnm_table; + struct os_reltime now; + char ssid[SSID_MAX_LEN + 1]; + char phy_name[17]; + size_t ssid_len = SSID_MAX_LEN; + u8 channel = 0, op_class = 0; + + if (hapd->conf->ssid.ssid_len < SSID_MAX_LEN) + ssid_len = hapd->conf->ssid.ssid_len; + + ieee80211_freq_to_channel_ext(hapd->iface->freq, + hapd->iconf->secondary_channel, + hostapd_get_oper_chwidth(hapd->iconf), + &op_class, &channel); + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "status", hostapd_state_text(hapd->iface->state)); + blobmsg_printf(&b, "bssid", MACSTR, MAC2STR(hapd->conf->bssid)); + + memset(ssid, 0, SSID_MAX_LEN + 1); + memcpy(ssid, hapd->conf->ssid.ssid, ssid_len); + blobmsg_add_string(&b, "ssid", ssid); + + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + blobmsg_add_u32(&b, "channel", channel); + blobmsg_add_u32(&b, "op_class", op_class); + blobmsg_add_u32(&b, "beacon_interval", hapd->iconf->beacon_int); + + snprintf(phy_name, 17, "%s", hapd->iface->phy); + blobmsg_add_string(&b, "phy", phy_name); + + /* RRM */ + rrm_table = blobmsg_open_table(&b, "rrm"); + blobmsg_add_u64(&b, "neighbor_report_tx", hapd->openwrt_stats.rrm.neighbor_report_tx); + blobmsg_close_table(&b, rrm_table); + + /* WNM */ + wnm_table = blobmsg_open_table(&b, "wnm"); + blobmsg_add_u64(&b, "bss_transition_query_rx", hapd->openwrt_stats.wnm.bss_transition_query_rx); + blobmsg_add_u64(&b, "bss_transition_request_tx", hapd->openwrt_stats.wnm.bss_transition_request_tx); + blobmsg_add_u64(&b, "bss_transition_response_rx", hapd->openwrt_stats.wnm.bss_transition_response_rx); + blobmsg_close_table(&b, wnm_table); + + /* Airtime */ + airtime_table = blobmsg_open_table(&b, "airtime"); + blobmsg_add_u64(&b, "time", hapd->iface->last_channel_time); + blobmsg_add_u64(&b, "time_busy", hapd->iface->last_channel_time_busy); + blobmsg_add_u16(&b, "utilization", hapd->iface->channel_utilization); + blobmsg_close_table(&b, airtime_table); + + /* DFS */ + dfs_table = blobmsg_open_table(&b, "dfs"); + blobmsg_add_u32(&b, "cac_seconds", hapd->iface->dfs_cac_ms / 1000); + blobmsg_add_u8(&b, "cac_active", !!(hapd->iface->cac_started)); + os_reltime_age(&hapd->iface->dfs_cac_start, &now); + blobmsg_add_u32(&b, "cac_seconds_left", + hapd->iface->cac_started ? hapd->iface->dfs_cac_ms / 1000 - now.sec : 0); + blobmsg_close_table(&b, dfs_table); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +enum { + NOTIFY_RESPONSE, + __NOTIFY_MAX +}; + +static const struct blobmsg_policy notify_policy[__NOTIFY_MAX] = { + [NOTIFY_RESPONSE] = { "notify_response", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_notify_response(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__NOTIFY_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct wpabuf *elems; + const char *pos; + size_t len; + + blobmsg_parse(notify_policy, __NOTIFY_MAX, tb, + blob_data(msg), blob_len(msg)); + + if (!tb[NOTIFY_RESPONSE]) + return UBUS_STATUS_INVALID_ARGUMENT; + + hapd->ubus.notify_response = blobmsg_get_u32(tb[NOTIFY_RESPONSE]); + + return UBUS_STATUS_OK; +} + +enum { + DEL_CLIENT_ADDR, + DEL_CLIENT_REASON, + DEL_CLIENT_DEAUTH, + DEL_CLIENT_BAN_TIME, + __DEL_CLIENT_MAX +}; + +static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = { + [DEL_CLIENT_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 }, + [DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 }, + [DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__DEL_CLIENT_MAX]; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct sta_info *sta; + bool deauth = false; + int reason; + u8 addr[ETH_ALEN]; + + blobmsg_parse(del_policy, __DEL_CLIENT_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[DEL_CLIENT_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[DEL_CLIENT_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[DEL_CLIENT_REASON]) + reason = blobmsg_get_u32(tb[DEL_CLIENT_REASON]); + + if (tb[DEL_CLIENT_DEAUTH]) + deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]); + + sta = ap_get_sta(hapd, addr); + if (sta) { + if (deauth) { + hostapd_drv_sta_deauth(hapd, addr, reason); + ap_sta_deauthenticate(hapd, sta, reason); + } else { + hostapd_drv_sta_disassoc(hapd, addr, reason); + ap_sta_disassociate(hapd, sta, reason); + } + } + + if (tb[DEL_CLIENT_BAN_TIME]) + hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME])); + + return 0; +} + +static void +blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const u8 *addr) +{ + char *s; + + s = blobmsg_alloc_string_buffer(buf, name, 20); + sprintf(s, MACSTR, MAC2STR(addr)); + blobmsg_add_string_buffer(buf); +} + +static int +hostapd_bss_list_bans(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct ubus_banned_client *ban; + void *c; + + blob_buf_init(&b, 0); + c = blobmsg_open_array(&b, "clients"); + avl_for_each_element(&hapd->ubus.banned, ban, avl) + blobmsg_add_macaddr(&b, NULL, ban->addr); + blobmsg_close_array(&b, c); + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +#ifdef CONFIG_WPS +static int +hostapd_bss_wps_start(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = hostapd_wps_button_pushed(hapd, NULL); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} + + +static const char * pbc_status_enum_str(enum pbc_status status) +{ + switch (status) { + case WPS_PBC_STATUS_DISABLE: + return "Disabled"; + case WPS_PBC_STATUS_ACTIVE: + return "Active"; + case WPS_PBC_STATUS_TIMEOUT: + return "Timed-out"; + case WPS_PBC_STATUS_OVERLAP: + return "Overlap"; + default: + return "Unknown"; + } +} + +static int +hostapd_bss_wps_status(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + blob_buf_init(&b, 0); + + blobmsg_add_string(&b, "pbc_status", pbc_status_enum_str(hapd->wps_stats.pbc_status)); + blobmsg_add_string(&b, "last_wps_result", + (hapd->wps_stats.status == WPS_STATUS_SUCCESS ? + "Success": + (hapd->wps_stats.status == WPS_STATUS_FAILURE ? + "Failed" : "None"))); + + /* If status == Failure - Add possible Reasons */ + if(hapd->wps_stats.status == WPS_STATUS_FAILURE && + hapd->wps_stats.failure_reason > 0) + blobmsg_add_string(&b, "reason", wps_ei_str(hapd->wps_stats.failure_reason)); + + if (hapd->wps_stats.status) + blobmsg_printf(&b, "peer_address", MACSTR, MAC2STR(hapd->wps_stats.peer_addr)); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_bss_wps_cancel(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = hostapd_wps_cancel(hapd); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} +#endif /* CONFIG_WPS */ + +static int +hostapd_bss_update_beacon(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rc; + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + + rc = ieee802_11_set_beacon(hapd); + + if (rc != 0) + return UBUS_STATUS_NOT_SUPPORTED; + + return 0; +} + +enum { + CONFIG_IFACE, + CONFIG_FILE, + __CONFIG_MAX +}; + +enum { + CSA_FREQ, + CSA_BCN_COUNT, + CSA_CENTER_FREQ1, + CSA_CENTER_FREQ2, + CSA_BANDWIDTH, + CSA_SEC_CHANNEL_OFFSET, + CSA_HT, + CSA_VHT, + CSA_HE, + CSA_BLOCK_TX, + CSA_FORCE, + __CSA_MAX +}; + +static const struct blobmsg_policy csa_policy[__CSA_MAX] = { + [CSA_FREQ] = { "freq", BLOBMSG_TYPE_INT32 }, + [CSA_BCN_COUNT] = { "bcn_count", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ1] = { "center_freq1", BLOBMSG_TYPE_INT32 }, + [CSA_CENTER_FREQ2] = { "center_freq2", BLOBMSG_TYPE_INT32 }, + [CSA_BANDWIDTH] = { "bandwidth", BLOBMSG_TYPE_INT32 }, + [CSA_SEC_CHANNEL_OFFSET] = { "sec_channel_offset", BLOBMSG_TYPE_INT32 }, + [CSA_HT] = { "ht", BLOBMSG_TYPE_BOOL }, + [CSA_VHT] = { "vht", BLOBMSG_TYPE_BOOL }, + [CSA_HE] = { "he", BLOBMSG_TYPE_BOOL }, + [CSA_BLOCK_TX] = { "block_tx", BLOBMSG_TYPE_BOOL }, + [CSA_FORCE] = { "force", BLOBMSG_TYPE_BOOL }, +}; + + +static void switch_chan_fallback_cb(void *eloop_data, void *user_ctx) +{ + struct hostapd_iface *iface = eloop_data; + struct hostapd_freq_params *freq_params = user_ctx; + + hostapd_switch_channel_fallback(iface, freq_params); +} + +#ifdef NEED_AP_MLME +static int +hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__CSA_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_config *iconf = hapd->iface->conf; + struct hostapd_freq_params *freq_params; + struct hostapd_hw_modes *mode = hapd->iface->current_mode; + struct csa_settings css = { + .freq_params = { + .ht_enabled = iconf->ieee80211n, + .vht_enabled = iconf->ieee80211ac, + .he_enabled = iconf->ieee80211ax, + .sec_channel_offset = iconf->secondary_channel, + } + }; + u8 chwidth = hostapd_get_oper_chwidth(iconf); + u8 seg0 = 0, seg1 = 0; + int ret = UBUS_STATUS_OK; + int i; + + blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[CSA_FREQ]) + return UBUS_STATUS_INVALID_ARGUMENT; + + switch (iconf->vht_oper_chwidth) { + case CHANWIDTH_USE_HT: + if (iconf->secondary_channel) + css.freq_params.bandwidth = 40; + else + css.freq_params.bandwidth = 20; + break; + case CHANWIDTH_160MHZ: + css.freq_params.bandwidth = 160; + break; + default: + css.freq_params.bandwidth = 80; + break; + } + + css.freq_params.freq = blobmsg_get_u32(tb[CSA_FREQ]); + +#define SET_CSA_SETTING(name, field, type) \ + do { \ + if (tb[name]) \ + css.field = blobmsg_get_ ## type(tb[name]); \ + } while(0) + + SET_CSA_SETTING(CSA_BCN_COUNT, cs_count, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ1, freq_params.center_freq1, u32); + SET_CSA_SETTING(CSA_CENTER_FREQ2, freq_params.center_freq2, u32); + SET_CSA_SETTING(CSA_BANDWIDTH, freq_params.bandwidth, u32); + SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET, freq_params.sec_channel_offset, u32); + SET_CSA_SETTING(CSA_HT, freq_params.ht_enabled, bool); + SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool); + SET_CSA_SETTING(CSA_HE, freq_params.he_enabled, bool); + SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool); + + css.freq_params.channel = hostapd_hw_get_channel(hapd, css.freq_params.freq); + if (!css.freq_params.channel) + return UBUS_STATUS_NOT_SUPPORTED; + + switch (css.freq_params.bandwidth) { + case 160: + chwidth = CHANWIDTH_160MHZ; + break; + case 80: + chwidth = css.freq_params.center_freq2 ? CHANWIDTH_80P80MHZ : CHANWIDTH_80MHZ; + break; + default: + chwidth = CHANWIDTH_USE_HT; + break; + } + + hostapd_set_freq_params(&css.freq_params, iconf->hw_mode, + css.freq_params.freq, + css.freq_params.channel, iconf->enable_edmg, + iconf->edmg_channel, + css.freq_params.ht_enabled, + css.freq_params.vht_enabled, + css.freq_params.he_enabled, + css.freq_params.sec_channel_offset, + chwidth, seg0, seg1, + iconf->vht_capab, + mode ? &mode->he_capab[IEEE80211_MODE_AP] : + NULL); + + for (i = 0; i < hapd->iface->num_bss; i++) { + struct hostapd_data *bss = hapd->iface->bss[i]; + + if (hostapd_switch_channel(bss, &css) != 0) + ret = UBUS_STATUS_NOT_SUPPORTED; + } + + if (!ret || !tb[CSA_FORCE] || !blobmsg_get_bool(tb[CSA_FORCE])) + return ret; + + freq_params = malloc(sizeof(*freq_params)); + memcpy(freq_params, &css.freq_params, sizeof(*freq_params)); + eloop_register_timeout(0, 1, switch_chan_fallback_cb, + hapd->iface, freq_params); + + return 0; +#undef SET_CSA_SETTING +} +#endif + +enum { + VENDOR_ELEMENTS, + __VENDOR_ELEMENTS_MAX +}; + +static const struct blobmsg_policy ve_policy[__VENDOR_ELEMENTS_MAX] = { + /* vendor elements are provided as hex-string */ + [VENDOR_ELEMENTS] = { "vendor_elements", BLOBMSG_TYPE_STRING }, +}; + +static int +hostapd_vendor_elements(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__VENDOR_ELEMENTS_MAX]; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_bss_config *bss = hapd->conf; + struct wpabuf *elems; + const char *pos; + size_t len; + + blobmsg_parse(ve_policy, __VENDOR_ELEMENTS_MAX, tb, + blob_data(msg), blob_len(msg)); + + if (!tb[VENDOR_ELEMENTS]) + return UBUS_STATUS_INVALID_ARGUMENT; + + pos = blobmsg_data(tb[VENDOR_ELEMENTS]); + len = os_strlen(pos); + if (len & 0x01) + return UBUS_STATUS_INVALID_ARGUMENT; + + len /= 2; + if (len == 0) { + wpabuf_free(bss->vendor_elements); + bss->vendor_elements = NULL; + return 0; + } + + elems = wpabuf_alloc(len); + if (elems == NULL) + return 1; + + if (hexstr2bin(pos, wpabuf_put(elems, len), len)) { + wpabuf_free(elems); + return UBUS_STATUS_INVALID_ARGUMENT; + } + + wpabuf_free(bss->vendor_elements); + bss->vendor_elements = elems; + + /* update beacons if vendor elements were set successfully */ + if (ieee802_11_update_beacons(hapd->iface) != 0) + return UBUS_STATUS_NOT_SUPPORTED; + return UBUS_STATUS_OK; +} + +static void +hostapd_rrm_print_nr(struct hostapd_neighbor_entry *nr) +{ + const u8 *data; + char *str; + int len; + + blobmsg_printf(&b, "", MACSTR, MAC2STR(nr->bssid)); + + str = blobmsg_alloc_string_buffer(&b, "", nr->ssid.ssid_len + 1); + memcpy(str, nr->ssid.ssid, nr->ssid.ssid_len); + str[nr->ssid.ssid_len] = 0; + blobmsg_add_string_buffer(&b); + + len = wpabuf_len(nr->nr); + str = blobmsg_alloc_string_buffer(&b, "", 2 * len + 1); + wpa_snprintf_hex(str, 2 * len + 1, wpabuf_head_u8(nr->nr), len); + blobmsg_add_string_buffer(&b); +} + +enum { + BSS_MGMT_EN_NEIGHBOR, + BSS_MGMT_EN_BEACON, +#ifdef CONFIG_WNM_AP + BSS_MGMT_EN_BSS_TRANSITION, +#endif + __BSS_MGMT_EN_MAX +}; + +static bool +__hostapd_bss_mgmt_enable_f(struct hostapd_data *hapd, int flag) +{ + struct hostapd_bss_config *bss = hapd->conf; + uint32_t flags; + + switch (flag) { + case BSS_MGMT_EN_NEIGHBOR: + if (bss->radio_measurements[0] & + WLAN_RRM_CAPS_NEIGHBOR_REPORT) + return false; + + bss->radio_measurements[0] |= + WLAN_RRM_CAPS_NEIGHBOR_REPORT; + hostapd_neighbor_set_own_report(hapd); + return true; + case BSS_MGMT_EN_BEACON: + flags = WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE | + WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE | + WLAN_RRM_CAPS_BEACON_REPORT_TABLE; + + if (bss->radio_measurements[0] & flags == flags) + return false; + + bss->radio_measurements[0] |= (u8) flags; + return true; +#ifdef CONFIG_WNM_AP + case BSS_MGMT_EN_BSS_TRANSITION: + if (bss->bss_transition) + return false; + + bss->bss_transition = 1; + return true; +#endif + } +} + +static void +__hostapd_bss_mgmt_enable(struct hostapd_data *hapd, uint32_t flags) +{ + bool update = false; + int i; + + for (i = 0; i < __BSS_MGMT_EN_MAX; i++) { + if (!(flags & (1 << i))) + continue; + + update |= __hostapd_bss_mgmt_enable_f(hapd, i); + } + + if (update) + ieee802_11_update_beacons(hapd->iface); +} + + +static const struct blobmsg_policy bss_mgmt_enable_policy[__BSS_MGMT_EN_MAX] = { + [BSS_MGMT_EN_NEIGHBOR] = { "neighbor_report", BLOBMSG_TYPE_BOOL }, + [BSS_MGMT_EN_BEACON] = { "beacon_report", BLOBMSG_TYPE_BOOL }, +#ifdef CONFIG_WNM_AP + [BSS_MGMT_EN_BSS_TRANSITION] = { "bss_transition", BLOBMSG_TYPE_BOOL }, +#endif +}; + +static int +hostapd_bss_mgmt_enable(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) + +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct blob_attr *tb[__BSS_MGMT_EN_MAX]; + struct blob_attr *cur; + uint32_t flags = 0; + int i; + bool neigh = false, beacon = false; + + blobmsg_parse(bss_mgmt_enable_policy, __BSS_MGMT_EN_MAX, tb, blob_data(msg), blob_len(msg)); + + for (i = 0; i < ARRAY_SIZE(tb); i++) { + if (!tb[i] || !blobmsg_get_bool(tb[i])) + continue; + + flags |= (1 << i); + } + + __hostapd_bss_mgmt_enable(hapd, flags); +} + + +static void +hostapd_rrm_nr_enable(struct hostapd_data *hapd) +{ + __hostapd_bss_mgmt_enable(hapd, 1 << BSS_MGMT_EN_NEIGHBOR); +} + +static int +hostapd_rrm_nr_get_own(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_neighbor_entry *nr; + void *c; + + hostapd_rrm_nr_enable(hapd); + + nr = hostapd_neighbor_get(hapd, hapd->own_addr, NULL); + if (!nr) + return UBUS_STATUS_NOT_FOUND; + + blob_buf_init(&b, 0); + + c = blobmsg_open_array(&b, "value"); + hostapd_rrm_print_nr(nr); + blobmsg_close_array(&b, c); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +static int +hostapd_rrm_nr_list(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct hostapd_neighbor_entry *nr; + void *c; + + hostapd_rrm_nr_enable(hapd); + blob_buf_init(&b, 0); + + c = blobmsg_open_array(&b, "list"); + dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) { + void *cur; + + if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN)) + continue; + + cur = blobmsg_open_array(&b, NULL); + hostapd_rrm_print_nr(nr); + blobmsg_close_array(&b, cur); + } + blobmsg_close_array(&b, c); + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + +enum { + NR_SET_LIST, + __NR_SET_LIST_MAX +}; + +static const struct blobmsg_policy nr_set_policy[__NR_SET_LIST_MAX] = { + [NR_SET_LIST] = { "list", BLOBMSG_TYPE_ARRAY }, +}; + + +static void +hostapd_rrm_nr_clear(struct hostapd_data *hapd) +{ + struct hostapd_neighbor_entry *nr; + +restart: + dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) { + if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN)) + continue; + + hostapd_neighbor_remove(hapd, nr->bssid, &nr->ssid); + goto restart; + } +} + +static int +hostapd_rrm_nr_set(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + static const struct blobmsg_policy nr_e_policy[] = { + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + }; + struct hostapd_data *hapd = get_hapd_from_object(obj); + struct blob_attr *tb_l[__NR_SET_LIST_MAX]; + struct blob_attr *tb[ARRAY_SIZE(nr_e_policy)]; + struct blob_attr *cur; + int rem; + + hostapd_rrm_nr_enable(hapd); + + blobmsg_parse(nr_set_policy, __NR_SET_LIST_MAX, tb_l, blob_data(msg), blob_len(msg)); + if (!tb_l[NR_SET_LIST]) + return UBUS_STATUS_INVALID_ARGUMENT; + + hostapd_rrm_nr_clear(hapd); + blobmsg_for_each_attr(cur, tb_l[NR_SET_LIST], rem) { + struct wpa_ssid_value ssid; + struct wpabuf *data; + u8 bssid[ETH_ALEN]; + char *s, *nr_s; + + blobmsg_parse_array(nr_e_policy, ARRAY_SIZE(nr_e_policy), tb, blobmsg_data(cur), blobmsg_data_len(cur)); + if (!tb[0] || !tb[1] || !tb[2]) + goto invalid; + + /* Neighbor Report binary */ + nr_s = blobmsg_get_string(tb[2]); + data = wpabuf_parse_bin(nr_s); + if (!data) + goto invalid; + + /* BSSID */ + s = blobmsg_get_string(tb[0]); + if (strlen(s) == 0) { + /* Copy BSSID from neighbor report */ + if (hwaddr_compact_aton(nr_s, bssid)) + goto invalid; + } else if (hwaddr_aton(s, bssid)) { + goto invalid; + } + + /* SSID */ + s = blobmsg_get_string(tb[1]); + if (strlen(s) == 0) { + /* Copy SSID from hostapd BSS conf */ + memcpy(&ssid, &hapd->conf->ssid, sizeof(ssid)); + } else { + ssid.ssid_len = strlen(s); + if (ssid.ssid_len > sizeof(ssid.ssid)) + goto invalid; + + memcpy(&ssid, s, ssid.ssid_len); + } + + hostapd_neighbor_set(hapd, bssid, &ssid, data, NULL, NULL, 0, 0); + wpabuf_free(data); + continue; + +invalid: + return UBUS_STATUS_INVALID_ARGUMENT; + } + + return 0; +} + +enum { + BEACON_REQ_ADDR, + BEACON_REQ_MODE, + BEACON_REQ_OP_CLASS, + BEACON_REQ_CHANNEL, + BEACON_REQ_DURATION, + BEACON_REQ_BSSID, + BEACON_REQ_SSID, + __BEACON_REQ_MAX, +}; + +static const struct blobmsg_policy beacon_req_policy[__BEACON_REQ_MAX] = { + [BEACON_REQ_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [BEACON_REQ_OP_CLASS] { "op_class", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_CHANNEL] { "channel", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_DURATION] { "duration", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_MODE] { "mode", BLOBMSG_TYPE_INT32 }, + [BEACON_REQ_BSSID] { "bssid", BLOBMSG_TYPE_STRING }, + [BEACON_REQ_SSID] { "ssid", BLOBMSG_TYPE_STRING }, +}; + +static int +hostapd_rrm_beacon_req(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__BEACON_REQ_MAX]; + struct blob_attr *cur; + struct wpabuf *req; + u8 bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + u8 addr[ETH_ALEN]; + int mode, rem, ret; + int buf_len = 13; + + blobmsg_parse(beacon_req_policy, __BEACON_REQ_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[BEACON_REQ_ADDR] || !tb[BEACON_REQ_MODE] || !tb[BEACON_REQ_DURATION] || + !tb[BEACON_REQ_OP_CLASS] || !tb[BEACON_REQ_CHANNEL]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BEACON_REQ_SSID]) + buf_len += blobmsg_data_len(tb[BEACON_REQ_SSID]) + 2 - 1; + + mode = blobmsg_get_u32(tb[BEACON_REQ_MODE]); + if (hwaddr_aton(blobmsg_data(tb[BEACON_REQ_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BEACON_REQ_BSSID] && + hwaddr_aton(blobmsg_data(tb[BEACON_REQ_BSSID]), bssid)) + return UBUS_STATUS_INVALID_ARGUMENT; + + req = wpabuf_alloc(buf_len); + if (!req) + return UBUS_STATUS_UNKNOWN_ERROR; + + /* 1: regulatory class */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_OP_CLASS])); + + /* 2: channel number */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_CHANNEL])); + + /* 3-4: randomization interval */ + wpabuf_put_le16(req, 0); + + /* 5-6: duration */ + wpabuf_put_le16(req, blobmsg_get_u32(tb[BEACON_REQ_DURATION])); + + /* 7: mode */ + wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_MODE])); + + /* 8-13: BSSID */ + wpabuf_put_data(req, bssid, ETH_ALEN); + + if ((cur = tb[BEACON_REQ_SSID]) != NULL) { + wpabuf_put_u8(req, WLAN_EID_SSID); + wpabuf_put_u8(req, blobmsg_data_len(cur) - 1); + wpabuf_put_data(req, blobmsg_data(cur), blobmsg_data_len(cur) - 1); + } + + ret = hostapd_send_beacon_req(hapd, addr, 0, req); + if (ret < 0) + return -ret; + + return 0; +} + + +#ifdef CONFIG_WNM_AP + +static int +hostapd_bss_tr_send(struct hostapd_data *hapd, u8 *addr, bool disassoc_imminent, bool abridged, + u16 disassoc_timer, u8 validity_period, u8 dialog_token, + struct blob_attr *neighbors) +{ + struct blob_attr *cur; + struct sta_info *sta; + int nr_len = 0; + int rem; + u8 *nr = NULL; + u8 req_mode = 0; + + sta = ap_get_sta(hapd, addr); + if (!sta) + return UBUS_STATUS_NOT_FOUND; + + if (neighbors) { + u8 *nr_cur; + + if (blobmsg_check_array(neighbors, + BLOBMSG_TYPE_STRING) < 0) + return UBUS_STATUS_INVALID_ARGUMENT; + + blobmsg_for_each_attr(cur, neighbors, rem) { + int len = strlen(blobmsg_get_string(cur)); + + if (len % 2) + return UBUS_STATUS_INVALID_ARGUMENT; + + nr_len += (len / 2) + 2; + } + + if (nr_len) { + nr = os_zalloc(nr_len); + if (!nr) + return UBUS_STATUS_UNKNOWN_ERROR; + } + + nr_cur = nr; + blobmsg_for_each_attr(cur, neighbors, rem) { + int len = strlen(blobmsg_get_string(cur)) / 2; + + *nr_cur++ = WLAN_EID_NEIGHBOR_REPORT; + *nr_cur++ = (u8) len; + if (hexstr2bin(blobmsg_data(cur), nr_cur, len)) { + free(nr); + return UBUS_STATUS_INVALID_ARGUMENT; + } + + nr_cur += len; + } + } + + if (nr) + req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED; + + if (abridged) + req_mode |= WNM_BSS_TM_REQ_ABRIDGED; + + if (disassoc_imminent) + req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT; + + if (wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer, validity_period, NULL, + dialog_token, NULL, nr, nr_len, NULL, 0)) + return UBUS_STATUS_UNKNOWN_ERROR; + + return 0; +} + +enum { + BSS_TR_ADDR, + BSS_TR_DA_IMMINENT, + BSS_TR_DA_TIMER, + BSS_TR_VALID_PERIOD, + BSS_TR_NEIGHBORS, + BSS_TR_ABRIDGED, + BSS_TR_DIALOG_TOKEN, + __BSS_TR_DISASSOC_MAX +}; + +static const struct blobmsg_policy bss_tr_policy[__BSS_TR_DISASSOC_MAX] = { + [BSS_TR_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [BSS_TR_DA_IMMINENT] = { "disassociation_imminent", BLOBMSG_TYPE_BOOL }, + [BSS_TR_DA_TIMER] = { "disassociation_timer", BLOBMSG_TYPE_INT32 }, + [BSS_TR_VALID_PERIOD] = { "validity_period", BLOBMSG_TYPE_INT32 }, + [BSS_TR_NEIGHBORS] = { "neighbors", BLOBMSG_TYPE_ARRAY }, + [BSS_TR_ABRIDGED] = { "abridged", BLOBMSG_TYPE_BOOL }, + [BSS_TR_DIALOG_TOKEN] = { "dialog_token", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_transition_request(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__BSS_TR_DISASSOC_MAX]; + struct sta_info *sta; + u32 da_timer = 0; + u32 valid_period = 0; + u8 addr[ETH_ALEN]; + u32 dialog_token = 1; + bool abridged; + bool da_imminent; + + blobmsg_parse(bss_tr_policy, __BSS_TR_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[BSS_TR_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[BSS_TR_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[BSS_TR_DA_TIMER]) + da_timer = blobmsg_get_u32(tb[BSS_TR_DA_TIMER]); + + if (tb[BSS_TR_VALID_PERIOD]) + valid_period = blobmsg_get_u32(tb[BSS_TR_VALID_PERIOD]); + + if (tb[BSS_TR_DIALOG_TOKEN]) + dialog_token = blobmsg_get_u32(tb[BSS_TR_DIALOG_TOKEN]); + + da_imminent = !!(tb[BSS_TR_DA_IMMINENT] && blobmsg_get_bool(tb[BSS_TR_DA_IMMINENT])); + abridged = !!(tb[BSS_TR_ABRIDGED] && blobmsg_get_bool(tb[BSS_TR_ABRIDGED])); + + return hostapd_bss_tr_send(hapd, addr, da_imminent, abridged, da_timer, valid_period, + dialog_token, tb[BSS_TR_NEIGHBORS]); +} + +enum { + WNM_DISASSOC_ADDR, + WNM_DISASSOC_DURATION, + WNM_DISASSOC_NEIGHBORS, + WNM_DISASSOC_ABRIDGED, + __WNM_DISASSOC_MAX, +}; + +static const struct blobmsg_policy wnm_disassoc_policy[__WNM_DISASSOC_MAX] = { + [WNM_DISASSOC_ADDR] = { "addr", BLOBMSG_TYPE_STRING }, + [WNM_DISASSOC_DURATION] { "duration", BLOBMSG_TYPE_INT32 }, + [WNM_DISASSOC_NEIGHBORS] { "neighbors", BLOBMSG_TYPE_ARRAY }, + [WNM_DISASSOC_ABRIDGED] { "abridged", BLOBMSG_TYPE_BOOL }, +}; + +static int +hostapd_wnm_disassoc_imminent(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__WNM_DISASSOC_MAX]; + struct sta_info *sta; + int duration = 10; + u8 addr[ETH_ALEN]; + bool abridged; + + blobmsg_parse(wnm_disassoc_policy, __WNM_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[WNM_DISASSOC_ADDR]) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (hwaddr_aton(blobmsg_data(tb[WNM_DISASSOC_ADDR]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + if (tb[WNM_DISASSOC_DURATION]) + duration = blobmsg_get_u32(tb[WNM_DISASSOC_DURATION]); + + abridged = !!(tb[WNM_DISASSOC_ABRIDGED] && blobmsg_get_bool(tb[WNM_DISASSOC_ABRIDGED])); + + return hostapd_bss_tr_send(hapd, addr, true, abridged, duration, duration, + 1, tb[WNM_DISASSOC_NEIGHBORS]); +} +#endif + +#ifdef CONFIG_AIRTIME_POLICY +enum { + UPDATE_AIRTIME_STA, + UPDATE_AIRTIME_WEIGHT, + __UPDATE_AIRTIME_MAX, +}; + + +static const struct blobmsg_policy airtime_policy[__UPDATE_AIRTIME_MAX] = { + [UPDATE_AIRTIME_STA] = { "sta", BLOBMSG_TYPE_STRING }, + [UPDATE_AIRTIME_WEIGHT] = { "weight", BLOBMSG_TYPE_INT32 }, +}; + +static int +hostapd_bss_update_airtime(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *ureq, const char *method, + struct blob_attr *msg) +{ + struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); + struct blob_attr *tb[__UPDATE_AIRTIME_MAX]; + struct sta_info *sta = NULL; + u8 addr[ETH_ALEN]; + int weight; + + blobmsg_parse(airtime_policy, __UPDATE_AIRTIME_MAX, tb, blob_data(msg), blob_len(msg)); + + if (!tb[UPDATE_AIRTIME_WEIGHT]) + return UBUS_STATUS_INVALID_ARGUMENT; + + weight = blobmsg_get_u32(tb[UPDATE_AIRTIME_WEIGHT]); + + if (!tb[UPDATE_AIRTIME_STA]) { + if (!weight) + return UBUS_STATUS_INVALID_ARGUMENT; + + hapd->conf->airtime_weight = weight; + return 0; + } + + if (hwaddr_aton(blobmsg_data(tb[UPDATE_AIRTIME_STA]), addr)) + return UBUS_STATUS_INVALID_ARGUMENT; + + sta = ap_get_sta(hapd, addr); + if (!sta) + return UBUS_STATUS_NOT_FOUND; + + sta->dyn_airtime_weight = weight; + airtime_policy_new_sta(hapd, sta); + + return 0; +} +#endif + + +static const struct ubus_method bss_methods[] = { + UBUS_METHOD_NOARG("reload", hostapd_bss_reload), + UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients), + UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status), + UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy), +#ifdef CONFIG_AIRTIME_POLICY + UBUS_METHOD("update_airtime", hostapd_bss_update_airtime, airtime_policy), +#endif + UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans), +#ifdef CONFIG_WPS + UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start), + UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status), + UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel), +#endif + UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon), + UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features), +#ifdef NEED_AP_MLME + UBUS_METHOD("switch_chan", hostapd_switch_chan, csa_policy), +#endif + UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements, ve_policy), + UBUS_METHOD("notify_response", hostapd_notify_response, notify_policy), + UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable, bss_mgmt_enable_policy), + UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own), + UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list), + UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set, nr_set_policy), + UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req, beacon_req_policy), +#ifdef CONFIG_WNM_AP + UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent, wnm_disassoc_policy), + UBUS_METHOD("bss_transition_request", hostapd_bss_transition_request, bss_tr_policy), +#endif +}; + +static struct ubus_object_type bss_object_type = + UBUS_OBJECT_TYPE("hostapd_bss", bss_methods); + +static int avl_compare_macaddr(const void *k1, const void *k2, void *ptr) +{ + return memcmp(k1, k2, ETH_ALEN); +} + +void hostapd_ubus_add_bss(struct hostapd_data *hapd) +{ + struct ubus_object *obj = &hapd->ubus.obj; + char *name; + int ret; + +#ifdef CONFIG_MESH + if (hapd->conf->mesh & MESH_ENABLED) + return; +#endif + + if (!hostapd_ubus_init()) + return; + + if (asprintf(&name, "hostapd.%s", hapd->conf->iface) < 0) + return; + + avl_init(&hapd->ubus.banned, avl_compare_macaddr, false, NULL); + obj->name = name; + obj->type = &bss_object_type; + obj->methods = bss_object_type.methods; + obj->n_methods = bss_object_type.n_methods; + ret = ubus_add_object(ctx, obj); + hostapd_ubus_ref_inc(); +} + +void hostapd_ubus_free_bss(struct hostapd_data *hapd) +{ + struct ubus_object *obj = &hapd->ubus.obj; + char *name = (char *) obj->name; + +#ifdef CONFIG_MESH + if (hapd->conf->mesh & MESH_ENABLED) + return; +#endif + + if (!ctx) + return; + + if (obj->id) { + ubus_remove_object(ctx, obj); + hostapd_ubus_ref_dec(); + } + + free(name); +} + +static void +hostapd_ubus_vlan_action(struct hostapd_data *hapd, struct hostapd_vlan *vlan, + const char *action) +{ + struct vlan_description *desc = &vlan->vlan_desc; + void *c; + int i; + + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "ifname", vlan->ifname); + blobmsg_add_string(&b, "bridge", vlan->bridge); + blobmsg_add_u32(&b, "vlan_id", vlan->vlan_id); + + if (desc->notempty) { + blobmsg_add_u32(&b, "untagged", desc->untagged); + c = blobmsg_open_array(&b, "tagged"); + for (i = 0; i < ARRAY_SIZE(desc->tagged) && desc->tagged[i]; i++) + blobmsg_add_u32(&b, "", desc->tagged[i]); + blobmsg_close_array(&b, c); + } + + ubus_notify(ctx, &hapd->ubus.obj, action, b.head, -1); +} + +void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) +{ + hostapd_ubus_vlan_action(hapd, vlan, "vlan_add"); +} + +void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan) +{ + hostapd_ubus_vlan_action(hapd, vlan, "vlan_remove"); +} + +struct ubus_event_req { + struct ubus_notify_request nreq; + int resp; +}; + +static void +ubus_event_cb(struct ubus_notify_request *req, int idx, int ret) +{ + struct ubus_event_req *ureq = container_of(req, struct ubus_event_req, nreq); + + ureq->resp = ret; +} + +int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req) +{ + struct ubus_banned_client *ban; + const char *types[HOSTAPD_UBUS_TYPE_MAX] = { + [HOSTAPD_UBUS_PROBE_REQ] = "probe", + [HOSTAPD_UBUS_AUTH_REQ] = "auth", + [HOSTAPD_UBUS_ASSOC_REQ] = "assoc", + }; + const char *type = "mgmt"; + struct ubus_event_req ureq = {}; + const u8 *addr; + + if (req->mgmt_frame) + addr = req->mgmt_frame->sa; + else + addr = req->addr; + + ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl); + if (ban) + return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; + + if (!hapd->ubus.obj.has_subscribers) + return WLAN_STATUS_SUCCESS; + + if (req->type < ARRAY_SIZE(types)) + type = types[req->type]; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + if (req->mgmt_frame) + blobmsg_add_macaddr(&b, "target", req->mgmt_frame->da); + if (req->ssi_signal) + blobmsg_add_u32(&b, "signal", req->ssi_signal); + blobmsg_add_u32(&b, "freq", hapd->iface->freq); + + if (req->elems) { + if(req->elems->ht_capabilities) + { + struct ieee80211_ht_capabilities *ht_capabilities; + void *ht_cap, *ht_cap_mcs_set, *mcs_set; + + + ht_capabilities = (struct ieee80211_ht_capabilities*) req->elems->ht_capabilities; + ht_cap = blobmsg_open_table(&b, "ht_capabilities"); + blobmsg_add_u16(&b, "ht_capabilities_info", ht_capabilities->ht_capabilities_info); + ht_cap_mcs_set = blobmsg_open_table(&b, "supported_mcs_set"); + blobmsg_add_u16(&b, "a_mpdu_params", ht_capabilities->a_mpdu_params); + blobmsg_add_u16(&b, "ht_extended_capabilities", ht_capabilities->ht_extended_capabilities); + blobmsg_add_u32(&b, "tx_bf_capability_info", ht_capabilities->tx_bf_capability_info); + blobmsg_add_u16(&b, "asel_capabilities", ht_capabilities->asel_capabilities); + mcs_set = blobmsg_open_array(&b, "supported_mcs_set"); + for (int i = 0; i < 16; i++) { + blobmsg_add_u16(&b, NULL, (u16) ht_capabilities->supported_mcs_set[i]); + } + blobmsg_close_array(&b, mcs_set); + blobmsg_close_table(&b, ht_cap_mcs_set); + blobmsg_close_table(&b, ht_cap); + } + if(req->elems->vht_capabilities) + { + struct ieee80211_vht_capabilities *vht_capabilities; + void *vht_cap, *vht_cap_mcs_set; + + vht_capabilities = (struct ieee80211_vht_capabilities*) req->elems->vht_capabilities; + vht_cap = blobmsg_open_table(&b, "vht_capabilities"); + blobmsg_add_u32(&b, "vht_capabilities_info", vht_capabilities->vht_capabilities_info); + vht_cap_mcs_set = blobmsg_open_table(&b, "vht_supported_mcs_set"); + blobmsg_add_u16(&b, "rx_map", vht_capabilities->vht_supported_mcs_set.rx_map); + blobmsg_add_u16(&b, "rx_highest", vht_capabilities->vht_supported_mcs_set.rx_highest); + blobmsg_add_u16(&b, "tx_map", vht_capabilities->vht_supported_mcs_set.tx_map); + blobmsg_add_u16(&b, "tx_highest", vht_capabilities->vht_supported_mcs_set.tx_highest); + blobmsg_close_table(&b, vht_cap_mcs_set); + blobmsg_close_table(&b, vht_cap); + } + } + + if (!hapd->ubus.notify_response) { + ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); + return WLAN_STATUS_SUCCESS; + } + + if (ubus_notify_async(ctx, &hapd->ubus.obj, type, b.head, &ureq.nreq)) + return WLAN_STATUS_SUCCESS; + + ureq.nreq.status_cb = ubus_event_cb; + ubus_complete_request(ctx, &ureq.nreq.req, 100); + + if (ureq.resp) + return ureq.resp; + + return WLAN_STATUS_SUCCESS; +} + +void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *addr) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + + ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); +} + + +void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", sta->addr); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + if (sta->bandwidth[0] || sta->bandwidth[1]) { + void *r = blobmsg_open_array(&b, "rate-limit"); + + blobmsg_add_u32(&b, "", sta->bandwidth[0]); + blobmsg_add_u32(&b, "", sta->bandwidth[1]); + blobmsg_close_array(&b, r); + } + + ubus_notify(ctx, &hapd->ubus.obj, "sta-authorized", b.head, -1); +} + +void hostapd_ubus_notify_beacon_report( + struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, + struct rrm_measurement_beacon_report *rep, size_t len) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr || !rep) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u16(&b, "op-class", rep->op_class); + blobmsg_add_u16(&b, "channel", rep->channel); + blobmsg_add_u64(&b, "start-time", rep->start_time); + blobmsg_add_u16(&b, "duration", rep->duration); + blobmsg_add_u16(&b, "report-info", rep->report_info); + blobmsg_add_u16(&b, "rcpi", rep->rcpi); + blobmsg_add_u16(&b, "rsni", rep->rsni); + blobmsg_add_macaddr(&b, "bssid", rep->bssid); + blobmsg_add_u16(&b, "antenna-id", rep->antenna_id); + blobmsg_add_u16(&b, "parent-tsf", rep->parent_tsf); + + ubus_notify(ctx, &hapd->ubus.obj, "beacon-report", b.head, -1); +} + +void hostapd_ubus_notify_radar_detected(struct hostapd_iface *iface, int frequency, + int chan_width, int cf1, int cf2) +{ + struct hostapd_data *hapd; + int i; + + blob_buf_init(&b, 0); + blobmsg_add_u16(&b, "frequency", frequency); + blobmsg_add_u16(&b, "width", chan_width); + blobmsg_add_u16(&b, "center1", cf1); + blobmsg_add_u16(&b, "center2", cf2); + + for (i = 0; i < iface->num_bss; i++) { + hapd = iface->bss[i]; + ubus_notify(ctx, &hapd->ubus.obj, "radar-detected", b.head, -1); + } +} + +#ifdef CONFIG_WNM_AP +static void hostapd_ubus_notify_bss_transition_add_candidate_list( + const u8 *candidate_list, u16 candidate_list_len) +{ + char *cl_str; + int i; + + if (candidate_list_len == 0) + return; + + cl_str = blobmsg_alloc_string_buffer(&b, "candidate-list", candidate_list_len * 2 + 1); + for (i = 0; i < candidate_list_len; i++) + snprintf(&cl_str[i*2], 3, "%02X", candidate_list[i]); + blobmsg_add_string_buffer(&b); + +} +#endif + +void hostapd_ubus_notify_bss_transition_response( + struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 status_code, + u8 bss_termination_delay, const u8 *target_bssid, + const u8 *candidate_list, u16 candidate_list_len) +{ +#ifdef CONFIG_WNM_AP + u16 i; + + if (!hapd->ubus.obj.has_subscribers) + return; + + if (!addr) + return; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u8(&b, "dialog-token", dialog_token); + blobmsg_add_u8(&b, "status-code", status_code); + blobmsg_add_u8(&b, "bss-termination-delay", bss_termination_delay); + if (target_bssid) + blobmsg_add_macaddr(&b, "target-bssid", target_bssid); + + hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list, candidate_list_len); + + ubus_notify(ctx, &hapd->ubus.obj, "bss-transition-response", b.head, -1); +#endif +} + +int hostapd_ubus_notify_bss_transition_query( + struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, + const u8 *candidate_list, u16 candidate_list_len) +{ +#ifdef CONFIG_WNM_AP + struct ubus_event_req ureq = {}; + char *cl_str; + u16 i; + + if (!hapd->ubus.obj.has_subscribers) + return 0; + + if (!addr) + return 0; + + blob_buf_init(&b, 0); + blobmsg_add_macaddr(&b, "address", addr); + blobmsg_add_u8(&b, "dialog-token", dialog_token); + blobmsg_add_u8(&b, "reason", reason); + hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list, candidate_list_len); + + if (!hapd->ubus.notify_response) { + ubus_notify(ctx, &hapd->ubus.obj, "bss-transition-query", b.head, -1); + return 0; + } + + if (ubus_notify_async(ctx, &hapd->ubus.obj, "bss-transition-query", b.head, &ureq.nreq)) + return 0; + + ureq.nreq.status_cb = ubus_event_cb; + ubus_complete_request(ctx, &ureq.nreq.req, 100); + + return ureq.resp; +#endif +} diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ucode.c b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ucode.c index 02413c70b..9ffdbd96a 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ucode.c +++ b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ucode.c @@ -7,6 +7,8 @@ #include "beacon.h" #include "hw_features.h" #include "ap_drv_ops.h" +#include "dfs.h" +#include "acs.h" #include static uc_resource_type_t *global_type, *bss_type, *iface_type; @@ -109,6 +111,94 @@ uc_hostapd_remove_iface(uc_vm_t *vm, size_t nargs) return NULL; } +static struct hostapd_vlan * +bss_conf_find_vlan(struct hostapd_bss_config *bss, int id) +{ + struct hostapd_vlan *vlan; + + for (vlan = bss->vlan; vlan; vlan = vlan->next) + if (vlan->vlan_id == id) + return vlan; + + return NULL; +} + +static int +bss_conf_rename_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan, + const char *ifname) +{ + if (!strcmp(ifname, vlan->ifname)) + return 0; + + hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, vlan->ifname, ifname); + os_strlcpy(vlan->ifname, ifname, sizeof(vlan->ifname)); + + return 0; +} + +static int +bss_reload_vlans(struct hostapd_data *hapd, struct hostapd_bss_config *bss) +{ + struct hostapd_bss_config *old_bss = hapd->conf; + struct hostapd_vlan *vlan, *vlan_new, *wildcard; + char ifname[IFNAMSIZ + 1], vlan_ifname[IFNAMSIZ + 1], *pos; + int ret; + + vlan = bss_conf_find_vlan(old_bss, VLAN_ID_WILDCARD); + wildcard = bss_conf_find_vlan(bss, VLAN_ID_WILDCARD); + if (!!vlan != !!wildcard) + return -1; + + if (vlan && wildcard && strcmp(vlan->ifname, wildcard->ifname) != 0) + strcpy(vlan->ifname, wildcard->ifname); + else + wildcard = NULL; + + for (vlan = bss->vlan; vlan; vlan = vlan->next) { + if (vlan->vlan_id == VLAN_ID_WILDCARD || + vlan->dynamic_vlan > 0) + continue; + + if (!bss_conf_find_vlan(old_bss, vlan->vlan_id)) + return -1; + } + + for (vlan = old_bss->vlan; vlan; vlan = vlan->next) { + if (vlan->vlan_id == VLAN_ID_WILDCARD) + continue; + + if (vlan->dynamic_vlan == 0) { + vlan_new = bss_conf_find_vlan(bss, vlan->vlan_id); + if (!vlan_new) + return -1; + + if (bss_conf_rename_vlan(hapd, vlan, vlan_new->ifname)) + return -1; + + continue; + } + + if (!wildcard) + continue; + + os_strlcpy(ifname, wildcard->ifname, sizeof(ifname)); + pos = os_strchr(ifname, '#'); + if (!pos) + return -1; + + *pos++ = '\0'; + ret = os_snprintf(vlan_ifname, sizeof(vlan_ifname), "%s%d%s", + ifname, vlan->vlan_id, pos); + if (os_snprintf_error(sizeof(vlan_ifname), ret)) + return -1; + + if (bss_conf_rename_vlan(hapd, vlan, vlan_ifname)) + return -1; + } + + return 0; +} + static uc_value_t * uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) { @@ -118,6 +208,7 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) struct hostapd_config *conf; uc_value_t *file = uc_fn_arg(0); uc_value_t *index = uc_fn_arg(1); + uc_value_t *files_only = uc_fn_arg(2); unsigned int i, idx = 0; int ret = -1; @@ -129,9 +220,28 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) iface = hapd->iface; conf = interfaces->config_read_cb(ucv_string_get(file)); - if (!conf || idx > conf->num_bss || !conf->bss[idx]) + if (!conf) goto out; + if (idx > conf->num_bss || !conf->bss[idx]) + goto free; + + if (ucv_boolean_get(files_only)) { + struct hostapd_bss_config *bss = conf->bss[idx]; + struct hostapd_bss_config *old_bss = hapd->conf; + +#define swap_field(name) \ + do { \ + void *ptr = old_bss->name; \ + old_bss->name = bss->name; \ + bss->name = ptr; \ + } while (0) + + swap_field(ssid.wpa_psk_file); + ret = bss_reload_vlans(hapd, bss); + goto done; + } + hostapd_bss_deinit_no_free(hapd); hostapd_drv_stop_ap(hapd); hostapd_free_hapd_data(hapd); @@ -142,12 +252,14 @@ uc_hostapd_bss_set_config(uc_vm_t *vm, size_t nargs) iface->conf->bss[i] = conf->bss[idx]; hapd->conf = conf->bss[idx]; conf->bss[idx] = old_bss; - hostapd_config_free(conf); - hostapd_setup_bss(hapd, hapd == iface->bss[0], !iface->conf->multiple_bssid); + hostapd_setup_bss(hapd, hapd == iface->bss[0], true); + hostapd_ucode_update_interfaces(); +done: ret = 0; - +free: + hostapd_config_free(conf); out: return ucv_int64_new(ret); } @@ -178,10 +290,15 @@ uc_hostapd_bss_delete(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface; int i, idx; - if (!hapd || hapd == hapd->iface->bss[0]) + if (!hapd) return NULL; iface = hapd->iface; + if (iface->num_bss == 1) { + wpa_printf(MSG_ERROR, "trying to delete last bss of an iface: %s\n", hapd->conf->iface); + return NULL; + } + for (idx = 0; idx < iface->num_bss; idx++) if (iface->bss[idx] == hapd) break; @@ -191,8 +308,13 @@ uc_hostapd_bss_delete(uc_vm_t *vm, size_t nargs) for (i = idx + 1; i < iface->num_bss; i++) iface->bss[i - 1] = iface->bss[i]; + iface->num_bss--; + iface->bss[0]->interface_added = 0; + hostapd_drv_set_first_bss(iface->bss[0]); + hapd->interface_added = 1; + hostapd_drv_stop_ap(hapd); hostapd_bss_deinit(hapd); hostapd_remove_iface_bss_conf(iface->conf, hapd->conf); @@ -266,6 +388,58 @@ out: return ret; } +static uc_value_t * +uc_hostapd_iface_set_bss_order(uc_vm_t *vm, size_t nargs) +{ + struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); + uc_value_t *bss_list = uc_fn_arg(0); + struct hostapd_data **new_bss; + struct hostapd_bss_config **new_conf; + + if (!iface) + return NULL; + + if (ucv_type(bss_list) != UC_ARRAY || + ucv_array_length(bss_list) != iface->num_bss) + return NULL; + + new_bss = calloc(iface->num_bss, sizeof(*new_bss)); + new_conf = calloc(iface->num_bss, sizeof(*new_conf)); + for (size_t i = 0; i < iface->num_bss; i++) { + struct hostapd_data *bss; + + bss = ucv_resource_data(ucv_array_get(bss_list, i), "hostapd.bss"); + if (bss->iface != iface) + goto free; + + for (size_t k = 0; k < i; k++) + if (new_bss[k] == bss) + goto free; + + new_bss[i] = bss; + new_conf[i] = bss->conf; + } + + new_bss[0]->interface_added = 0; + for (size_t i = 1; i < iface->num_bss; i++) + new_bss[i]->interface_added = 1; + + free(iface->bss); + iface->bss = new_bss; + + free(iface->conf->bss); + iface->conf->bss = new_conf; + iface->conf->num_bss = iface->num_bss; + hostapd_drv_set_first_bss(iface->bss[0]); + + return ucv_boolean_new(true); + +free: + free(new_bss); + free(new_conf); + return NULL; +} + static uc_value_t * uc_hostapd_bss_ctrl(uc_vm_t *vm, size_t nargs) { @@ -297,12 +471,32 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); int i; + switch (iface->state) { + case HAPD_IFACE_ENABLED: + case HAPD_IFACE_DISABLED: + break; +#ifdef CONFIG_ACS + case HAPD_IFACE_ACS: + acs_cleanup(iface); + iface->scan_cb = NULL; + /* fallthrough */ +#endif + default: + hostapd_disable_iface(iface); + break; + } + + if (iface->state != HAPD_IFACE_ENABLED) + hostapd_disable_iface(iface); + for (i = 0; i < iface->num_bss; i++) { struct hostapd_data *hapd = iface->bss[i]; hostapd_drv_stop_ap(hapd); - hapd->started = 0; + hapd->beacon_set_done = 0; } + + return NULL; } static uc_value_t * @@ -311,67 +505,85 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs) struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface"); uc_value_t *info = uc_fn_arg(0); struct hostapd_config *conf; + bool changed = false; uint64_t intval; int i; if (!iface) return NULL; - if (!info) + if (!info) { + iface->freq = 0; goto out; + } if (ucv_type(info) != UC_OBJECT) return NULL; +#define UPDATE_VAL(field, name) \ + if ((intval = ucv_int64_get(ucv_object_get(info, name, NULL))) && \ + !errno && intval != conf->field) do { \ + conf->field = intval; \ + changed = true; \ + } while(0) + conf = iface->conf; - if ((intval = ucv_int64_get(ucv_object_get(info, "op_class", NULL))) && !errno) - conf->op_class = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "hw_mode", NULL))) && !errno) - conf->hw_mode = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "channel", NULL))) && !errno) - conf->channel = intval; - if ((intval = ucv_int64_get(ucv_object_get(info, "sec_channel", NULL))) && !errno) - conf->secondary_channel = intval; -#ifdef CONFIG_IEEE80211AC - if ((intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL))) && !errno) { - conf->vht_oper_centr_freq_seg0_idx = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_centr_freq_seg0_idx = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_centr_freq_seg0_idx = intval; -#endif - } - if ((intval = ucv_int64_get(ucv_object_get(info, "center_seg1_idx", NULL))) && !errno) { - conf->vht_oper_centr_freq_seg1_idx = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_centr_freq_seg1_idx = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_centr_freq_seg1_idx = intval; -#endif - } + UPDATE_VAL(op_class, "op_class"); + UPDATE_VAL(hw_mode, "hw_mode"); + UPDATE_VAL(channel, "channel"); + UPDATE_VAL(secondary_channel, "sec_channel"); + if (!changed && + (iface->bss[0]->beacon_set_done || + iface->state == HAPD_IFACE_DFS)) + return ucv_boolean_new(true); + + intval = ucv_int64_get(ucv_object_get(info, "center_seg0_idx", NULL)); + if (!errno) + hostapd_set_oper_centr_freq_seg0_idx(conf, intval); + + intval = ucv_int64_get(ucv_object_get(info, "center_seg1_idx", NULL)); + if (!errno) + hostapd_set_oper_centr_freq_seg1_idx(conf, intval); + intval = ucv_int64_get(ucv_object_get(info, "oper_chwidth", NULL)); - if (!errno) { - conf->vht_oper_chwidth = intval; -#ifdef CONFIG_IEEE80211AX - conf->he_oper_chwidth = intval; -#endif -#ifdef CONFIG_IEEE80211BE - conf->eht_oper_chwidth = intval; -#endif - } -#endif + if (!errno) + hostapd_set_oper_chwidth(conf, intval); + + intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL)); + if (!errno) + iface->freq = intval; + else + iface->freq = 0; + conf->acs = 0; out: - if (conf->channel) + switch (iface->state) { + case HAPD_IFACE_DISABLED: + break; + case HAPD_IFACE_ENABLED: + if (!hostapd_is_dfs_required(iface) || + hostapd_is_dfs_chan_available(iface)) + break; + wpa_printf(MSG_INFO, "DFS CAC required on new channel, restart interface"); + /* fallthrough */ + default: + hostapd_disable_iface(iface); + break; + } + + if (conf->channel && !iface->freq) iface->freq = hostapd_hw_get_freq(iface->bss[0], conf->channel); + if (iface->state != HAPD_IFACE_ENABLED) { + hostapd_enable_iface(iface); + return ucv_boolean_new(true); + } + for (i = 0; i < iface->num_bss; i++) { struct hostapd_data *hapd = iface->bss[i]; int ret; - hapd->started = 1; + hapd->conf->start_disabled = 0; hostapd_set_freq(hapd, conf->hw_mode, iface->freq, conf->channel, conf->enable_edmg, @@ -436,6 +648,55 @@ uc_hostapd_iface_switch_channel(uc_vm_t *vm, size_t nargs) return ucv_boolean_new(!ret); } +static uc_value_t * +uc_hostapd_bss_rename(uc_vm_t *vm, size_t nargs) +{ + struct hostapd_data *hapd = uc_fn_thisval("hostapd.bss"); + uc_value_t *ifname_arg = uc_fn_arg(0); + char prev_ifname[IFNAMSIZ + 1]; + struct sta_info *sta; + const char *ifname; + int ret; + + if (!hapd || ucv_type(ifname_arg) != UC_STRING) + return NULL; + + os_strlcpy(prev_ifname, hapd->conf->iface, sizeof(prev_ifname)); + ifname = ucv_string_get(ifname_arg); + + hostapd_ubus_free_bss(hapd); + if (interfaces->ctrl_iface_deinit) + interfaces->ctrl_iface_deinit(hapd); + + ret = hostapd_drv_if_rename(hapd, WPA_IF_AP_BSS, NULL, ifname); + if (ret) + goto out; + + for (sta = hapd->sta_list; sta; sta = sta->next) { + char cur_name[IFNAMSIZ + 1], new_name[IFNAMSIZ + 1]; + + if (!(sta->flags & WLAN_STA_WDS) || sta->pending_wds_enable) + continue; + + snprintf(cur_name, sizeof(cur_name), "%s.sta%d", prev_ifname, sta->aid); + snprintf(new_name, sizeof(new_name), "%s.sta%d", ifname, sta->aid); + hostapd_drv_if_rename(hapd, WPA_IF_AP_VLAN, cur_name, new_name); + } + + if (!strncmp(hapd->conf->ssid.vlan, hapd->conf->iface, sizeof(hapd->conf->ssid.vlan))) + os_strlcpy(hapd->conf->ssid.vlan, ifname, sizeof(hapd->conf->ssid.vlan)); + os_strlcpy(hapd->conf->iface, ifname, sizeof(hapd->conf->iface)); + hostapd_ubus_add_bss(hapd); + + hostapd_ucode_update_interfaces(); +out: + if (interfaces->ctrl_iface_init) + interfaces->ctrl_iface_init(hapd); + + return ret ? NULL : ucv_boolean_new(true); +} + + int hostapd_ucode_init(struct hapd_interfaces *ifaces) { static const uc_function_list_t global_fns[] = { @@ -449,9 +710,11 @@ int hostapd_ucode_init(struct hapd_interfaces *ifaces) static const uc_function_list_t bss_fns[] = { { "ctrl", uc_hostapd_bss_ctrl }, { "set_config", uc_hostapd_bss_set_config }, + { "rename", uc_hostapd_bss_rename }, { "delete", uc_hostapd_bss_delete }, }; static const uc_function_list_t iface_fns[] = { + { "set_bss_order", uc_hostapd_iface_set_bss_order }, { "add_bss", uc_hostapd_iface_add_bss }, { "stop", uc_hostapd_iface_stop }, { "start", uc_hostapd_iface_start }, diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/utils/ucode.c b/feeds/ipq807x_v5.4/hostapd/src/src/utils/ucode.c index b106d856f..998cf5574 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/src/utils/ucode.c +++ b/feeds/ipq807x_v5.4/hostapd/src/src/utils/ucode.c @@ -129,7 +129,10 @@ uc_value_t *uc_wpa_freq_info(uc_vm_t *vm, size_t nargs) tmp_channel &= ~((8 << width) - 1); center_idx = tmp_channel + center_ofs + (4 << width) - 1; - ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(center_idx)); + if (freq_val < 3000) + ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(0)); + else + ucv_object_add(ret, "center_seg0_idx", ucv_int64_new(center_idx)); center_idx = (center_idx - channel) * 5 + freq_val; ucv_object_add(ret, "center_freq1", ucv_int64_new(center_idx)); @@ -295,9 +298,15 @@ uc_value_t *wpa_ucode_registry_get(uc_value_t *reg, int idx) uc_value_t *wpa_ucode_registry_remove(uc_value_t *reg, int idx) { uc_value_t *val = wpa_ucode_registry_get(reg, idx); + void **dataptr; - if (val) - ucv_array_set(reg, idx - 1, NULL); + if (!val) + return NULL; + + ucv_array_set(reg, idx - 1, NULL); + dataptr = ucv_resource_dataptr(val, NULL); + if (dataptr) + *dataptr = NULL; return val; } diff --git a/feeds/ipq807x_v5.4/hostapd/src/wpa_supplicant/ucode.c b/feeds/ipq807x_v5.4/hostapd/src/wpa_supplicant/ucode.c index d0a78d162..55d22584f 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/wpa_supplicant/ucode.c +++ b/feeds/ipq807x_v5.4/hostapd/src/wpa_supplicant/ucode.c @@ -2,6 +2,7 @@ #include "utils/common.h" #include "utils/ucode.h" #include "drivers/driver.h" +#include "ap/hostapd.h" #include "wpa_supplicant_i.h" #include "wps_supplicant.h" #include "bss.h" @@ -211,12 +212,13 @@ uc_wpas_iface_status(uc_vm_t *vm, size_t nargs) ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION); if (ie && ie[1] >= 2) { const struct ieee80211_ht_operation *ht_oper; + int sec; ht_oper = (const void *) (ie + 2); - if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) + sec = ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; + if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) sec_chan = 1; - else if (ht_oper->ht_param & - HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) sec_chan = -1; } @@ -224,6 +226,15 @@ uc_wpas_iface_status(uc_vm_t *vm, size_t nargs) ucv_object_add(ret, "frequency", ucv_int64_new(bss->freq)); } +#ifdef CONFIG_MESH + if (wpa_s->ifmsh) { + struct hostapd_iface *ifmsh = wpa_s->ifmsh; + + ucv_object_add(ret, "sec_chan_offset", ucv_int64_new(ifmsh->conf->secondary_channel)); + ucv_object_add(ret, "frequency", ucv_int64_new(ifmsh->freq)); + } +#endif + return ret; } diff --git a/feeds/ipq807x_v5.4/ipq60xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x_v5.4/ipq60xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch new file mode 100644 index 000000000..44d468a36 --- /dev/null +++ b/feeds/ipq807x_v5.4/ipq60xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -0,0 +1,60 @@ +From: Andy Ren +Date: Mon, 7 Nov 2022 09:42:42 -0800 +Subject: [PATCH] net/core: Allow live renaming when an interface is up + +Allow a network interface to be renamed when the interface +is up. + +As described in the netconsole documentation [1], when netconsole is +used as a built-in, it will bring up the specified interface as soon as +possible. As a result, user space will not be able to rename the +interface since the kernel disallows renaming of interfaces that are +administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set +by the kernel. + +The original solution [2] to this problem was to add a new parameter to +the netconsole configuration parameters that allows renaming of +the interface used by netconsole while it is administratively up. +However, during the discussion that followed, it became apparent that we +have no reason to keep the current restriction and instead we should +allow user space to rename interfaces regardless of their administrative +state: + +1. The restriction was put in place over 20 years ago when renaming was +only possible via IOCTL and before rtnetlink started notifying user +space about such changes like it does today. + +2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version +5.2 and no regressions were reported. + +3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about +the administrative state of interface. + +Therefore, allow user space to rename running interfaces by removing the +restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in +possible triage by emitting a message to the kernel log that an +interface was renamed while UP. + +[1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst +[2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/ + +Signed-off-by: Andy Ren +Reviewed-by: Ido Schimmel +Reviewed-by: David Ahern +Signed-off-by: David S. Miller +--- + +Index: linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +=================================================================== +--- linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d.orig/net/core/dev.c ++++ linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +@@ -1125,7 +1125,8 @@ int dev_change_name(struct net_device *d + } + + if (oldname[0] && !strchr(oldname, '%')) +- netdev_info(dev, "renamed from %s\n", oldname); ++ netdev_info(dev, "renamed from %s%s\n", oldname, ++ dev->flags & IFF_UP ? " (while UP)" : ""); + + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; diff --git a/feeds/ipq807x_v5.4/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x_v5.4/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch new file mode 100644 index 000000000..1a97d2759 --- /dev/null +++ b/feeds/ipq807x_v5.4/ipq807x/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -0,0 +1,67 @@ +From: Andy Ren +Date: Mon, 7 Nov 2022 09:42:42 -0800 +Subject: [PATCH] net/core: Allow live renaming when an interface is up + +Allow a network interface to be renamed when the interface +is up. + +As described in the netconsole documentation [1], when netconsole is +used as a built-in, it will bring up the specified interface as soon as +possible. As a result, user space will not be able to rename the +interface since the kernel disallows renaming of interfaces that are +administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set +by the kernel. + +The original solution [2] to this problem was to add a new parameter to +the netconsole configuration parameters that allows renaming of +the interface used by netconsole while it is administratively up. +However, during the discussion that followed, it became apparent that we +have no reason to keep the current restriction and instead we should +allow user space to rename interfaces regardless of their administrative +state: + +1. The restriction was put in place over 20 years ago when renaming was +only possible via IOCTL and before rtnetlink started notifying user +space about such changes like it does today. + +2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version +5.2 and no regressions were reported. + +3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about +the administrative state of interface. + +Therefore, allow user space to rename running interfaces by removing the +restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in +possible triage by emitting a message to the kernel log that an +interface was renamed while UP. + +[1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst +[2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/ + +Signed-off-by: Andy Ren +Reviewed-by: Ido Schimmel +Reviewed-by: David Ahern +Signed-off-by: David S. Miller +--- + +--- a/net/core/dev.c ++++ b/net/core/dev.c +@@ -1152,8 +1152,6 @@ int dev_change_name(struct net_device *d + BUG_ON(!dev_net(dev)); + + net = dev_net(dev); +- if (dev->flags & IFF_UP) +- return -EBUSY; + + write_seqcount_begin(&devnet_rename_seq); + +@@ -1171,7 +1169,8 @@ int dev_change_name(struct net_device *d + } + + if (oldname[0] && !strchr(oldname, '%')) +- netdev_info(dev, "renamed from %s\n", oldname); ++ netdev_info(dev, "renamed from %s%s\n", oldname, ++ dev->flags & IFF_UP ? " (while UP)" : ""); + + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; diff --git a/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch new file mode 100644 index 000000000..1a97d2759 --- /dev/null +++ b/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -0,0 +1,67 @@ +From: Andy Ren +Date: Mon, 7 Nov 2022 09:42:42 -0800 +Subject: [PATCH] net/core: Allow live renaming when an interface is up + +Allow a network interface to be renamed when the interface +is up. + +As described in the netconsole documentation [1], when netconsole is +used as a built-in, it will bring up the specified interface as soon as +possible. As a result, user space will not be able to rename the +interface since the kernel disallows renaming of interfaces that are +administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set +by the kernel. + +The original solution [2] to this problem was to add a new parameter to +the netconsole configuration parameters that allows renaming of +the interface used by netconsole while it is administratively up. +However, during the discussion that followed, it became apparent that we +have no reason to keep the current restriction and instead we should +allow user space to rename interfaces regardless of their administrative +state: + +1. The restriction was put in place over 20 years ago when renaming was +only possible via IOCTL and before rtnetlink started notifying user +space about such changes like it does today. + +2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version +5.2 and no regressions were reported. + +3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about +the administrative state of interface. + +Therefore, allow user space to rename running interfaces by removing the +restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in +possible triage by emitting a message to the kernel log that an +interface was renamed while UP. + +[1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst +[2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/ + +Signed-off-by: Andy Ren +Reviewed-by: Ido Schimmel +Reviewed-by: David Ahern +Signed-off-by: David S. Miller +--- + +--- a/net/core/dev.c ++++ b/net/core/dev.c +@@ -1152,8 +1152,6 @@ int dev_change_name(struct net_device *d + BUG_ON(!dev_net(dev)); + + net = dev_net(dev); +- if (dev->flags & IFF_UP) +- return -EBUSY; + + write_seqcount_begin(&devnet_rename_seq); + +@@ -1171,7 +1169,8 @@ int dev_change_name(struct net_device *d + } + + if (oldname[0] && !strchr(oldname, '%')) +- netdev_info(dev, "renamed from %s\n", oldname); ++ netdev_info(dev, "renamed from %s%s\n", oldname, ++ dev->flags & IFF_UP ? " (while UP)" : ""); + + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; diff --git a/feeds/ipq807x_v5.4/mac80211/files/lib/netifd/wireless/mac80211.sh b/feeds/ipq807x_v5.4/mac80211/files/lib/netifd/wireless/mac80211.sh index dcf41441e..70c2348ad 100644 --- a/feeds/ipq807x_v5.4/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/feeds/ipq807x_v5.4/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -488,6 +488,7 @@ ${channel:+channel=$channel} ${channel_list:+chanlist=$channel_list} ${hostapd_noscan:+noscan=1} ${tx_burst:+tx_queue_data2_burst=$tx_burst} +#num_global_macaddr=$num_global_macaddr $base_cfg EOF @@ -528,6 +529,7 @@ mac80211_hostapd_setup_bss() { cat >> /var/run/hostapd-$phy.conf < /dev/null ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'", "config": [] }' > /dev/null - wdev_tool "$phy" '{}' + wdev_tool "$phy" set_config '{}' } drv_mac80211_setup() { @@ -1116,7 +1072,7 @@ drv_mac80211_setup() { mac80211_prepare_iw_htmode active_ifnames= - for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif ${multiple_bssid} + 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" @@ -1125,7 +1081,7 @@ drv_mac80211_setup() { [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy" json_set_namespace wdev_uc prev - wdev_tool "$phy" "$(json_dump)" $active_ifnames + wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames json_set_namespace "$prev" for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower diff --git a/feeds/ipq807x_v5.4/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch b/feeds/ipq807x_v5.4/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch new file mode 100644 index 000000000..aab3e6381 --- /dev/null +++ b/feeds/ipq807x_v5.4/mac80211/patches/pending/300-cfg80211-allow-grace-period-for-DFS-available-after-.patch @@ -0,0 +1,148 @@ +From: Felix Fietkau +Date: Thu, 14 Sep 2023 13:17:16 +0200 +Subject: [PATCH] cfg80211: allow grace period for DFS available after beacon + shutdown + +Fixes reconfiguring an AP on a DFS channel in non-ETSI regdomain + +Fixes: b35a51c7dd25 ("cfg80211: Make pre-CAC results valid only for ETSI domain") +Signed-off-by: Felix Fietkau +--- + +--- a/include/net/cfg80211.h ++++ b/include/net/cfg80211.h +@@ -162,6 +162,8 @@ enum ieee80211_channel_flags { + * @dfs_state: current state of this channel. Only relevant if radar is required + * on this channel. + * @dfs_state_entered: timestamp (jiffies) when the dfs state was entered. ++ * @dfs_state_last_available: timestamp (jiffies) of the last time when the ++ * channel was available. + * @dfs_cac_ms: DFS CAC time in milliseconds, this is valid for DFS channels. + */ + struct ieee80211_channel { +@@ -178,6 +180,7 @@ struct ieee80211_channel { + int orig_mag, orig_mpwr; + enum nl80211_dfs_state dfs_state; + unsigned long dfs_state_entered; ++ unsigned long dfs_state_last_available; + unsigned int dfs_cac_ms; + }; + +--- a/net/wireless/ap.c ++++ b/net/wireless/ap.c +@@ -25,6 +25,8 @@ int __cfg80211_stop_ap(struct cfg80211_r + if (!wdev->beacon_interval) + return -ENOENT; + ++ cfg80211_update_last_available(wdev->wiphy, &wdev->chandef); ++ + err = rdev_stop_ap(rdev, dev); + if (!err) { + wdev->conn_owner_nlportid = 0; +@@ -35,9 +37,6 @@ int __cfg80211_stop_ap(struct cfg80211_r + if (notify) + nl80211_send_ap_stopped(wdev); + +- /* Should we apply the grace period during beaconing interface +- * shutdown also? +- */ + cfg80211_sched_dfs_chan_update(rdev); + } + +--- a/net/wireless/chan.c ++++ b/net/wireless/chan.c +@@ -411,6 +411,8 @@ static void cfg80211_set_chans_dfs_state + + c->dfs_state = dfs_state; + c->dfs_state_entered = jiffies; ++ if (dfs_state == NL80211_DFS_AVAILABLE) ++ c->dfs_state_last_available = jiffies; + } + } + +@@ -769,6 +771,49 @@ static bool cfg80211_get_chans_dfs_avail + return true; + } + ++static void ++__cfg80211_update_last_available(struct wiphy *wiphy, ++ u32 center_freq, ++ u32 bandwidth) ++{ ++ struct ieee80211_channel *c; ++ u32 freq, start_freq, end_freq; ++ ++ start_freq = cfg80211_get_start_freq(center_freq, bandwidth); ++ end_freq = cfg80211_get_end_freq(center_freq, bandwidth); ++ ++ /* ++ * Check entire range of channels for the bandwidth. ++ * If any channel in between is disabled or has not ++ * had gone through CAC return false ++ */ ++ for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { ++ c = ieee80211_get_channel_khz(wiphy, freq); ++ if (!c) ++ return; ++ ++ c->dfs_state_last_available = jiffies; ++ } ++} ++ ++void cfg80211_update_last_available(struct wiphy *wiphy, ++ const struct cfg80211_chan_def *chandef) ++{ ++ int width; ++ ++ width = cfg80211_chandef_get_width(chandef); ++ if (width < 0) ++ return; ++ ++ __cfg80211_update_last_available(wiphy, MHZ_TO_KHZ(chandef->center_freq1), ++ width); ++ if (chandef->width != NL80211_CHAN_WIDTH_80P80) ++ return; ++ ++ __cfg80211_update_last_available(wiphy, MHZ_TO_KHZ(chandef->center_freq2), ++ width); ++} ++ + static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy, + const struct cfg80211_chan_def *chandef) + { +--- a/net/wireless/core.h ++++ b/net/wireless/core.h +@@ -483,6 +483,8 @@ void cfg80211_set_dfs_state(struct wiphy + enum nl80211_dfs_state dfs_state); + + void cfg80211_dfs_channels_update_work(struct work_struct *work); ++void cfg80211_update_last_available(struct wiphy *wiphy, ++ const struct cfg80211_chan_def *chandef); + + unsigned int + cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, +--- a/net/wireless/mlme.c ++++ b/net/wireless/mlme.c +@@ -858,6 +858,8 @@ void cfg80211_dfs_channels_update_work(s + if (c->dfs_state == NL80211_DFS_UNAVAILABLE) { + time_dfs_update = IEEE80211_DFS_MIN_NOP_TIME_MS; + radar_event = NL80211_RADAR_NOP_FINISHED; ++ timeout = c->dfs_state_entered + ++ msecs_to_jiffies(time_dfs_update); + } else { + if (regulatory_pre_cac_allowed(wiphy) || + cfg80211_any_wiphy_oper_chan(wiphy, c)) +@@ -865,11 +867,10 @@ void cfg80211_dfs_channels_update_work(s + + time_dfs_update = REG_PRE_CAC_EXPIRY_GRACE_MS; + radar_event = NL80211_RADAR_PRE_CAC_EXPIRED; ++ timeout = c->dfs_state_last_available + ++ msecs_to_jiffies(time_dfs_update); + } + +- timeout = c->dfs_state_entered + +- msecs_to_jiffies(time_dfs_update); +- + if (time_after_eq(jiffies, timeout)) { + c->dfs_state = NL80211_DFS_USABLE; + c->dfs_state_entered = jiffies; From 3d41a22fbaf5151472d6d524732c5e71ddc16cd4 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 18 Sep 2023 09:56:50 +0200 Subject: [PATCH 27/32] ucentral-client: update to latest HEAD 3bbcd36 handle rrm command Signed-off-by: John Crispin --- feeds/ucentral/ucentral-client/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-client/Makefile b/feeds/ucentral/ucentral-client/Makefile index 477c31bfc..1587629fd 100644 --- a/feeds/ucentral/ucentral-client/Makefile +++ b/feeds/ucentral/ucentral-client/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-client PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-client.git -PKG_MIRROR_HASH:=208bc53ea0194a59ff4dc78c32033a393017b0b883aa4d7741595b61ad3a4fd3 +PKG_MIRROR_HASH:=49d19d1cddb538f233a7c1d588b5c765929a8fe28a1524d0455c4b516dcd0310 PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-06-22 -PKG_SOURCE_VERSION:=d898a7afb595d6c2350d38d027bf142e72060662 +PKG_SOURCE_VERSION:=3bbcd36c6111e08df6c8f13e0079826ec417cc85 PKG_LICENSE:=BSD-3-Clause PKG_MAINTAINER:=John Crispin From 194eba2d21ce1b23ec048143a84bf299153b321c Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 18 Sep 2023 15:57:41 +0200 Subject: [PATCH 28/32] ucentral-schema: update to latest HEAD e99eaf9 add rrm cmd handler Signed-off-by: John Crispin --- feeds/ucentral/ucentral-schema/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feeds/ucentral/ucentral-schema/Makefile b/feeds/ucentral/ucentral-schema/Makefile index 8d34c2509..3c471ad77 100644 --- a/feeds/ucentral/ucentral-schema/Makefile +++ b/feeds/ucentral/ucentral-schema/Makefile @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema PKG_RELEASE:=1 PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git -PKG_MIRROR_HASH:=9d1acf9dde96d42283892a8cbcb8ae5afd040ea0d351a381b9e13bf60ed8398c +PKG_MIRROR_HASH:=62571bb529e8b350bafdc63db3d7e02effa3edf5e5f19bfe8ced96c7cfb08b0e PKG_SOURCE_PROTO:=git PKG_SOURCE_DATE:=2022-05-29 -PKG_SOURCE_VERSION:=f113e6192784f968668aec8aa19fe356b304aa14 +PKG_SOURCE_VERSION:=e99eaf9bdbbe68639b4632d7fec171d89c379dc5 PKG_MAINTAINER:=John Crispin PKG_LICENSE:=BSD-3-Clause From 2818722b196374c19c3f3490c21994282047bbd2 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 18 Sep 2023 09:59:46 +0200 Subject: [PATCH 29/32] usteer2: improve gateway command handling Signed-off-by: John Crispin --- .../ucentral/usteer2/files/usr/bin/usteer.uc | 2 +- .../usteer2/files/usr/share/usteer/command.uc | 55 ++++++++------ .../usteer2/files/usr/share/usteer/local.uc | 76 ++++++++++++------- .../files/usr/share/usteer/neighbor.uc | 53 +++++++++++++ .../usteer2/files/usr/share/usteer/phy.uc | 10 +-- .../usteer2/files/usr/share/usteer/station.uc | 25 +++--- 6 files changed, 152 insertions(+), 69 deletions(-) create mode 100644 feeds/ucentral/usteer2/files/usr/share/usteer/neighbor.uc diff --git a/feeds/ucentral/usteer2/files/usr/bin/usteer.uc b/feeds/ucentral/usteer2/files/usr/bin/usteer.uc index 799892657..0131fa5c8 100755 --- a/feeds/ucentral/usteer2/files/usr/bin/usteer.uc +++ b/feeds/ucentral/usteer2/files/usr/bin/usteer.uc @@ -68,7 +68,7 @@ global.start = function() { global.uci = require('uci').cursor(); global.ubus.conn = require('ubus').connect(); - for (let module in [ 'config', 'event', 'phy', 'local', 'station', 'command', 'policy' ]) { + for (let module in [ 'config', 'event', 'phy', 'neighbor', 'local', 'station', 'command', 'policy' ]) { printf('loading ' + module + '\n'); global[module] = require(module); if (exists(global[module], 'init')) diff --git a/feeds/ucentral/usteer2/files/usr/share/usteer/command.uc b/feeds/ucentral/usteer2/files/usr/share/usteer/command.uc index d879e5175..f93d96c1a 100644 --- a/feeds/ucentral/usteer2/files/usr/share/usteer/command.uc +++ b/feeds/ucentral/usteer2/files/usr/share/usteer/command.uc @@ -1,64 +1,75 @@ -function result(error, text, data) { +function result(error, event, text, data) { let res = { error: error, text: text || 'unknown', - ...(data ? { data } : {}), + ...(data ? data : {}), }; + if (event) + global.event.send('rrm.bss.command', res); return res; } const actions = { - // ubus call usteer2 command '{"action": "kick", "addr": "1c:57:dc:37:3c:b1", "params": {"reason": 5, "ban_time": 30}}' + // ubus call usteer2 command '{"action": "kick", "addr": "1c:57:dc:37:3c:b1", "reason": 5, "ban_time": 30 }' kick: function(msg) { - if (global.station.kick(msg)) - return result(1, 'station ' + msg.mac + ' is unknown'); + if (!global.station.kick(msg)) + return result(1, msg.event, 'station ' + msg.addr + ' is unknown', { action: 'kick', addr: msg.addr }); - return result(0, 'station ' + msg.mac + ' was kicked'); + return result(0, 0, 'station ' + msg.addr + ' was kicked', { action: 'kick', addr: msg.addr }); }, - // ubus call usteer2 command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": {"channel": 36}}' - // ubus call usteer2 command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": {"ssid": "Cockney"}}' + // ubus call usteer2 command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "channel": 1}' + // ubus call usteer2 command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "ssid": "Pluto" }' // ubus call usteer2 get_beacon_request '{"addr": "4e:7f:3e:2c:8a:68"}' beacon_request: function(msg) { if (!global.station.beacon_request(msg)) - return result(1, 'station ' + msg.addr + ' is unknown'); + return result(1, msg.event, 'station ' + msg.addr + ' is unknown', { action: 'beacon_request', addr: msg.addr }); - return result(0, 'station ' + msg.addr + ' beacon-request sent'); + return result(0, 0, 'station ' + msg.addr + ' beacon-request sent', { action: 'beacon_request', addr: msg.addr }); }, - // ubus call usteer2 command '{"action": "channel_switch", "addr": "34:eF:b6:aF:48:b1", "params": {"channel": 4, "band": "2G"}}' + // ubus call usteer2 command '{"action": "channel_switch", "bssid": "34:eF:b6:aF:48:b1", "channel": 4 }' channel_switch: function(msg) { if (!global.local.switch_chan(msg)) - return result(1, 'BSS ' + msg.bssid + ' failed to trigger channel switch'); + return result(1, msg.event, 'BSS ' + msg.bssid + ' failed to trigger channel switch', { action: 'channel_switch', bssid: msg.bssid }); - return result(0, 'BSS ' + msg.bssid + ' triggered channel switch'); + return result(0, msg.event, 'BSS ' + msg.bssid + ' triggered channel switch', { action: 'channel_switch', bssid: msg.bssid }); }, - // ubus call usteer2 command '{"action": "tx_power", "phy": "platform/soc/c000000.wifi+1", "params": {"level": 20}}' + // ubus call usteer2 command '{"action": "tx_power", "bssid": "34:eF:b6:aF:48:b1", "level": 20}' tx_power: function(msg) { if (!global.phy.txpower(msg)) - return result(1, 'PHY ' + msg,phy + ' failed to set TX power'); - - return result(0, 'PHY ' + msg.phy + ' changed TX power'); + return result(1, msg.event, 'BSS ' + msg.bssid + ' failed to set TX power', { action: 'tx_power', bssid: msg.bssid }); + + let level = global.local.txpower(msg.bssid) / 100; + return result(0, msg.event, 'BSS ' + msg.bssid + ' changed TX power', { action: 'tx_power', bssid: msg.bssid, level }); }, - // ubus call usteer2 command '{"action": "bss_transition", "addr": "4e:7f:3e:2c:8a:68", "params": { "neighbors": ["34:ef:b6:af:48:b1"]}}' + // ubus call usteer2 command '{"action": "bss_transition", "addr": "4e:7f:3e:2c:8a:68", "neighbors": ["34:ef:b6:af:48:b1"] }' bss_transition: function(msg) { if (!global.station.bss_transition(msg)) - return result(1, 'BSS transition ' + msg.addr + ' failed to trigger'); + return result(1, msg.event, 'BSS transition ' + msg.addr + ' failed to trigger', { action: 'bss_transition', addr: msg.addr }); - return result(0, 'BSS transition ' + msg.addr + ' triggered'); + return result(0, 0, 'BSS transition ' + msg.addr + ' triggered'); + }, + + // ubus call usteer2 command '{"action": "neighbors", "neighbors": [ [ "00:11:22:33:44:55", "OpenWifi", "34efb6af48b1af4900005301070603010300" ], [ "aa:bb:cc:dd:ee:ff", "OpenWifi2", "34efb6af48b1af4900005301070603010300" ] ] }' + neighbors: function(msg) { + if (!global.neighbor.remote(msg)) + return result(1, msg.event, 'Failed to set neighbors', { action: 'neighbors' }); + return result(0, 0, 'applied neighbor reports'); }, }; return { handle: function(msg) { if (!actions[msg.action]) - return result(1, 'unknown action ' + msg.action); + return result(1, msg.event, 'unknown action ' + msg.action); try { return actions[msg.action](msg); } catch(e) { - return result(1, 'action ' + msg.action + ' failed to execute'); + printf('%.J\n', e.stacktrace[0].context); + return result(1, msg.event, 'action ' + msg.action + ' failed to execute'); } }, }; diff --git a/feeds/ucentral/usteer2/files/usr/share/usteer/local.uc b/feeds/ucentral/usteer2/files/usr/share/usteer/local.uc index ca73aa9d3..405178f82 100644 --- a/feeds/ucentral/usteer2/files/usr/share/usteer/local.uc +++ b/feeds/ucentral/usteer2/files/usr/share/usteer/local.uc @@ -6,7 +6,16 @@ let state = {}; let hapd = {}; let handlers = {}; -function channel_to_freq(band, channel) { +function channel_to_freq(cur_freq, channel) { + + let band; + if (cur_freq <= 2484) + band = '2G'; + else if (cur_freq <= 5885) + band = '5G'; + else + band = '6G'; + if (band == '2G' && channel >= 1 && channel <= 13) return 2407 + channel * 5; else if (band == '2G' && channel == 14) @@ -58,23 +67,6 @@ function hapd_update() { return 5000; } -function hapd_nr_set(iface) { - let list = []; - for (let k, v in hapd) { - if (k == iface || v.ssid != hapd[iface].ssid) - continue; - push(list, v.rrm_nr); - - global.ubus.conn.call('hostapd.' + iface, 'rrm_nr_set', { list }); - } -} - -function hapd_nr_update(ssid) { - for (let k, v in hapd) - if (v.ssid == ssid) - hapd_nr_set(k); -} - function hapd_subunsub(path, sub) { /* check if this is a hostapd instance */ let name = split(path, '.'); @@ -88,6 +80,7 @@ function hapd_subunsub(path, sub) { /* the hostapd instance disappeared */ if (!sub) { global.event.send('rrm.bss.del', { bssid: hapd[name] }); + global.neighbor.local_del(name); delete hapd[name]; delete state[name]; return; @@ -122,14 +115,15 @@ function hapd_subunsub(path, sub) { /* ask hostapd for the local neighbourhood report data */ let rrm = global.ubus.conn.call(path, 'rrm_nr_get_own'); - if (rrm && rrm.value) + if (rrm && rrm.value) { hapd[name].rrm_nr = rrm.value; + global.neighbor.local_add(name, rrm.value); + } + global.neighbor.update(); + /* trigger an initial channel survey */ - channel_survey(name); - - /* update the neighborhood reports */ - hapd_nr_update(hapd[name].ssid); + //channel_survey(name); /* send an event */ global.event.send('rrm.bss.add', { @@ -137,7 +131,8 @@ function hapd_subunsub(path, sub) { ssid: hapd[name].ssid, freq: hapd[name].freq, channel: hapd[name].channel, - op_class: hapd[name].op_class + op_class: hapd[name].op_class, + rrm_nr: hapd[name].rrm_nr, }); } @@ -169,6 +164,10 @@ function ucentral_handle_event(req) { printf('%.J\n', req); } +function channel_switch_handler(type, data) { + global.event.send('rrm.bss.channel-switch', { bssid: data.bssid, freq: data.freq }); +} + return { status: function() { return hapd; @@ -193,7 +192,8 @@ return { ucentral_subunsub(true); } - uloop_timeout(hapd_update, 5000); +// uloop_timeout(hapd_update, 5000); + global.local.register_handler('channel-switch', channel_switch_handler); }, register_handler: function(event, handler) { @@ -203,16 +203,36 @@ return { }, switch_chan: function(msg) { - if (!msg.addr || !msg.params?.band || !msg.params?.channel) + if (!msg.bssid || !msg.channel) return false; for (let bss, v in hapd) { - if (v.bssid != lc(msg.addr)) + if (v.bssid != lc(msg.bssid)) continue; return global.ubus.conn.call('hostapd.' + bss, 'switch_chan', { - freq: channel_to_freq(msg.param.band, mag.param.channel), + freq: channel_to_freq(v.freq, msg.channel), bcn_count: 10 }) == null; } return false; }, + + bssid_to_phy: function(bssid) { + for (let bss, v in hapd) { + if (v.bssid != lc(bssid)) + continue; + let iface = global.nl80211.request(global.nl80211.const.NL80211_CMD_GET_INTERFACE, 0, { dev: bss }); + return iface.wiphy; + } + return -1; + }, + + txpower: function(bssid) { + for (let bss, v in hapd) { + if (v.bssid != lc(bssid)) + continue; + let iface = global.nl80211.request(global.nl80211.const.NL80211_CMD_GET_INTERFACE, 0, { dev: bss }); + return iface.wiphy_tx_power_level; + } + return 0; + }, }; diff --git a/feeds/ucentral/usteer2/files/usr/share/usteer/neighbor.uc b/feeds/ucentral/usteer2/files/usr/share/usteer/neighbor.uc new file mode 100644 index 000000000..8b9ed1919 --- /dev/null +++ b/feeds/ucentral/usteer2/files/usr/share/usteer/neighbor.uc @@ -0,0 +1,53 @@ +let local = { }; +let remote = [ ]; + +return { + init: function() { + + }, + + local_add: function(dev, data) { + local[dev] = data; + }, + + local_del: function(dev) { + delete local[dev]; + }, + + get: function(dev) { + let result = []; + + for (let k, v in remote) { + if (local[dev][1] != v[1]) + continue; + push(result, v); + } + for (let k, v in local) { + if (k == dev || local[dev][1] != v[1]) + continue; + push(result, v); + } + + return result; + }, + + update: function() { + for (let dev in local) { + let list = this.get(dev); + global.ubus.conn.call('hostapd.' + dev, 'rrm_nr_set', { list }); + } + }, + + remote: function(msg) { + for (let neighbor in msg.neighbors) { + if (type(neighbor) != 'array' || length(neighbor) != 3) + return false; + for (let i = 0; i < 3; i++) + if (type(neighbor[i]) != 'string') + return false; + } + remote = msg.neighbors; + this.update(); + return true; + } +}; diff --git a/feeds/ucentral/usteer2/files/usr/share/usteer/phy.uc b/feeds/ucentral/usteer2/files/usr/share/usteer/phy.uc index ed3d1bb5f..2f7d14f38 100644 --- a/feeds/ucentral/usteer2/files/usr/share/usteer/phy.uc +++ b/feeds/ucentral/usteer2/files/usr/share/usteer/phy.uc @@ -147,12 +147,12 @@ return { }, txpower: function(msg) { - if (!msg.phy || !msg.params?.level) + if (!msg.bssid || !msg.level) return false; - if (!this.phys[msg.phy]) - return false; - - global.nl80211.request(global.nl80211.const.NL80211_CMD_SET_WIPHY, 0, { wiphy: this.phys[msg.phy].index, wiphy_tx_power_setting: 2, wiphy_tx_power_level: msg.params.level * 100}); + let wiphy = global.local.bssid_to_phy(msg.bssid); + if (wiphy < 0) + return false; + global.nl80211.request(global.nl80211.const.NL80211_CMD_SET_WIPHY, 0, { wiphy, wiphy_tx_power_setting: 2, wiphy_tx_power_level: msg.level * 100}); return true; }, }; diff --git a/feeds/ucentral/usteer2/files/usr/share/usteer/station.uc b/feeds/ucentral/usteer2/files/usr/share/usteer/station.uc index c59289dd0..38b3a04b1 100644 --- a/feeds/ucentral/usteer2/files/usr/share/usteer/station.uc +++ b/feeds/ucentral/usteer2/files/usr/share/usteer/station.uc @@ -164,7 +164,7 @@ return { }, beacon_request: function(msg) { - if (!msg.addr || (!msg.params?.channel && !msg.params?.ssid)) + if (!msg.addr || (!msg.channel && !msg.ssid)) return false; let station = stations[msg.addr]; @@ -185,20 +185,20 @@ return { let payload = { addr: msg.addr, mode: msg.params?.mode || 1, - op_class: msg.params?.op_class || 128, - duration: msg.params?.duration || 100, + op_class: msg.op_class || 128, + duration: msg.duration || 100, }; - if (msg.params.channel) - payload.channel = msg.params.channel; + if (msg.channel) + payload.channel = msg.channel; else - payload.ssid = msg.params.ssid; + payload.ssid = msg.ssid; global.ubus.conn.call(`hostapd.${station.device}`, 'rrm_beacon_req', payload); return true; }, kick: function(msg) { - if (!msg.addr || !msg.params?.ban_time || !msg.params?.reason) + if (!msg.addr || !msg.ban_time || !msg.reason) return false; if (!exists(stations, msg.addr)) @@ -206,9 +206,9 @@ return { let payload = { addr: msg.addr, - reason: msg.params.reason, + reason: msg.reason, deauth: 1, - ban_time: msg.params.ban_time + ban_time: msg.ban_time }; /* tell hostapd to kick a station via ubus */ @@ -223,17 +223,16 @@ return { return stations; }, - // ubus call usteer2 command '{"action": "bss_transition", "addr": "4e:7f:3e:2c:8a:68", "params": { "neighbors": ["36:ef:b6:af:48:b1"]}}' bss_transition: function(msg) { - if (!msg.addr || !msg.params?.neighbors) + if (!msg.addr || !msg.neighbors) return false; if (!stations[msg.addr]) return false; let neighbors = []; for (let i = 0; i < 5; i++) - if (msg.params?.neighbors[i]) - push(neighbors, replace(msg.params?.neighbors[i], ':', '')); + if (msg.neighbors[i]) + push(neighbors, replace(msg.neighbors[i], ':', '')); let ret = global.ubus.conn.call(`hostapd.${stations[msg.addr].device}`, 'wnm_disassoc_imminent', { addr: msg.addr, duration: 20, abridged: 1, neighbors }) == null; From 6a6af16f48b344546016215b4875b47c8cd6cf30 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 18 Sep 2023 15:55:33 +0200 Subject: [PATCH 30/32] hostapd: add CSA event Signed-off-by: John Crispin --- .../hostapd/patches/600-ubus_support.patch | 142 ++++++++++++------ feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c | 13 ++ feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.h | 1 + .../hostapd/patches/600-ubus_support.patch | 142 ++++++++++++------ feeds/wifi-ax/hostapd/src/src/ap/ubus.c | 13 ++ feeds/wifi-ax/hostapd/src/src/ap/ubus.h | 1 + 6 files changed, 226 insertions(+), 86 deletions(-) diff --git a/feeds/ipq807x_v5.4/hostapd/patches/600-ubus_support.patch b/feeds/ipq807x_v5.4/hostapd/patches/600-ubus_support.patch index afcb8eb47..245e9b8e4 100644 --- a/feeds/ipq807x_v5.4/hostapd/patches/600-ubus_support.patch +++ b/feeds/ipq807x_v5.4/hostapd/patches/600-ubus_support.patch @@ -1,5 +1,7 @@ ---- a/hostapd/Makefile -+++ b/hostapd/Makefile +Index: hostapd-2021-02-20-59e9794c/hostapd/Makefile +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/hostapd/Makefile ++++ hostapd-2021-02-20-59e9794c/hostapd/Makefile @@ -166,6 +166,12 @@ OBJS += ../src/common/hw_features_common OBJS += ../src/eapol_auth/eapol_auth_sm.o @@ -13,8 +15,10 @@ ifdef CONFIG_CODE_COVERAGE CFLAGS += -O0 -fprofile-arcs -ftest-coverage ---- a/src/ap/hostapd.h -+++ b/src/ap/hostapd.h +Index: hostapd-2021-02-20-59e9794c/src/ap/hostapd.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/hostapd.h ++++ hostapd-2021-02-20-59e9794c/src/ap/hostapd.h @@ -17,6 +17,7 @@ #include "utils/list.h" #include "ap_config.h" @@ -39,8 +43,10 @@ void hostapd_interface_deinit(struct hostapd_iface *iface); void hostapd_interface_free(struct hostapd_iface *iface); struct hostapd_iface * hostapd_alloc_iface(void); ---- a/src/ap/hostapd.c -+++ b/src/ap/hostapd.c +Index: hostapd-2021-02-20-59e9794c/src/ap/hostapd.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/hostapd.c ++++ hostapd-2021-02-20-59e9794c/src/ap/hostapd.c @@ -376,6 +376,7 @@ void hostapd_free_hapd_data(struct hosta hapd->beacon_set_done = 0; @@ -82,8 +88,10 @@ hostapd_interface_deinit(iface); wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", __func__, driver, drv_priv); ---- a/src/ap/ieee802_11.c -+++ b/src/ap/ieee802_11.c +Index: hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/ieee802_11.c ++++ hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c @@ -3421,13 +3421,18 @@ static void handle_auth(struct hostapd_d u16 auth_alg, auth_transaction, status_code; u16 resp = WLAN_STATUS_SUCCESS; @@ -170,8 +178,10 @@ sta = ap_get_sta(hapd, mgmt->sa); if (sta == NULL) { wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " ---- a/src/ap/beacon.c -+++ b/src/ap/beacon.c +Index: hostapd-2021-02-20-59e9794c/src/ap/beacon.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/beacon.c ++++ hostapd-2021-02-20-59e9794c/src/ap/beacon.c @@ -823,6 +823,12 @@ void handle_probe_req(struct hostapd_dat u16 csa_offs[2]; size_t csa_offs_len; @@ -198,8 +208,10 @@ /* TODO: verify that supp_rates contains at least one matching rate * with AP configuration */ ---- a/src/ap/drv_callbacks.c -+++ b/src/ap/drv_callbacks.c +Index: hostapd-2021-02-20-59e9794c/src/ap/drv_callbacks.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/drv_callbacks.c ++++ hostapd-2021-02-20-59e9794c/src/ap/drv_callbacks.c @@ -145,6 +145,10 @@ int hostapd_notif_assoc(struct hostapd_d u16 reason = WLAN_REASON_UNSPECIFIED; int status = WLAN_STATUS_SUCCESS; @@ -224,8 +236,22 @@ #ifdef CONFIG_P2P if (elems.p2p) { wpabuf_free(sta->p2p_ie); ---- a/src/ap/sta_info.c -+++ b/src/ap/sta_info.c +@@ -981,9 +991,11 @@ void hostapd_event_ch_switch(struct host + + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED + "freq=%d dfs=%d", freq, is_dfs); ++ hostapd_ubus_notify_csa(hapd, freq); + } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED + "freq=%d dfs=%d", freq, is_dfs); ++ hostapd_ubus_notify_csa(hapd, freq); + } else if (is_dfs && + hostapd_is_dfs_required(hapd->iface) && + !hostapd_is_dfs_chan_available(hapd->iface) && +Index: hostapd-2021-02-20-59e9794c/src/ap/sta_info.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/sta_info.c ++++ hostapd-2021-02-20-59e9794c/src/ap/sta_info.c @@ -458,6 +458,7 @@ void ap_handle_timer(void *eloop_ctx, vo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "deauthenticated due to " @@ -304,8 +330,10 @@ if (hapd->msg_ctx_parent && hapd->msg_ctx_parent != hapd->msg_ctx) ---- a/src/ap/wpa_auth_glue.c -+++ b/src/ap/wpa_auth_glue.c +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_glue.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_glue.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_glue.c @@ -265,6 +265,7 @@ static void hostapd_wpa_auth_psk_failure struct hostapd_data *hapd = ctx; wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR, @@ -314,8 +342,10 @@ } ---- a/wpa_supplicant/Makefile -+++ b/wpa_supplicant/Makefile +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/Makefile +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/Makefile ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/Makefile @@ -169,6 +169,13 @@ ifdef CONFIG_EAPOL_TEST CFLAGS += -Werror -DEAPOL_TEST endif @@ -340,8 +370,10 @@ endif CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY ---- a/wpa_supplicant/wpa_supplicant.c -+++ b/wpa_supplicant/wpa_supplicant.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wpa_supplicant.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant.c @@ -6943,6 +6943,8 @@ struct wpa_supplicant * wpa_supplicant_a } #endif /* CONFIG_P2P */ @@ -373,8 +405,10 @@ return 0; } ---- a/wpa_supplicant/wpa_supplicant_i.h -+++ b/wpa_supplicant/wpa_supplicant_i.h +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant_i.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wpa_supplicant_i.h ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant_i.h @@ -19,6 +19,7 @@ #include "wps/wps_defs.h" #include "config_ssid.h" @@ -400,8 +434,10 @@ #ifdef CONFIG_MATCH_IFACE int matched; #endif /* CONFIG_MATCH_IFACE */ ---- a/wpa_supplicant/wps_supplicant.c -+++ b/wpa_supplicant/wps_supplicant.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wps_supplicant.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wps_supplicant.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wps_supplicant.c @@ -33,6 +33,7 @@ #include "p2p/p2p.h" #include "p2p_supplicant.h" @@ -419,8 +455,10 @@ if (wpa_s->conf->wps_cred_processing == 1) return 0; ---- a/wpa_supplicant/main.c -+++ b/wpa_supplicant/main.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/main.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/main.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/main.c @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) for (;;) { @@ -440,8 +478,10 @@ case 'o': params.override_driver = optarg; break; ---- a/src/ap/rrm.c -+++ b/src/ap/rrm.c +Index: hostapd-2021-02-20-59e9794c/src/ap/rrm.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/rrm.c ++++ hostapd-2021-02-20-59e9794c/src/ap/rrm.c @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report return; wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s", @@ -452,8 +492,10 @@ } ---- a/src/ap/vlan_init.c -+++ b/src/ap/vlan_init.c +Index: hostapd-2021-02-20-59e9794c/src/ap/vlan_init.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/vlan_init.c ++++ hostapd-2021-02-20-59e9794c/src/ap/vlan_init.c @@ -22,6 +22,7 @@ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, int existsok) @@ -490,8 +532,10 @@ return hostapd_vlan_if_remove(hapd, vlan->ifname); } ---- a/src/ap/dfs.c -+++ b/src/ap/dfs.c +Index: hostapd-2021-02-20-59e9794c/src/ap/dfs.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/dfs.c ++++ hostapd-2021-02-20-59e9794c/src/ap/dfs.c @@ -1226,6 +1226,8 @@ int hostapd_dfs_nop_finished(struct host "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", freq, ht_enabled, chan_offset, chan_width, cf1, cf2); @@ -501,8 +545,10 @@ /* Proceed only if DFS is not offloaded to the driver */ if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) return 0; ---- a/src/ap/airtime_policy.c -+++ b/src/ap/airtime_policy.c +Index: hostapd-2021-02-20-59e9794c/src/ap/airtime_policy.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/airtime_policy.c ++++ hostapd-2021-02-20-59e9794c/src/ap/airtime_policy.c @@ -108,8 +108,14 @@ static void set_sta_weights(struct hosta { struct sta_info *sta; @@ -532,8 +578,10 @@ if (weight) return sta_set_airtime_weight(hapd, sta, weight); } ---- a/src/ap/sta_info.h -+++ b/src/ap/sta_info.h +Index: hostapd-2021-02-20-59e9794c/src/ap/sta_info.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/sta_info.h ++++ hostapd-2021-02-20-59e9794c/src/ap/sta_info.h @@ -323,6 +323,7 @@ struct sta_info { #endif /* CONFIG_TESTING_OPTIONS */ #ifdef CONFIG_AIRTIME_POLICY @@ -542,8 +590,10 @@ struct os_reltime backlogged_until; #endif /* CONFIG_AIRTIME_POLICY */ ---- a/src/ap/wnm_ap.c -+++ b/src/ap/wnm_ap.c +Index: hostapd-2021-02-20-59e9794c/src/ap/wnm_ap.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wnm_ap.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wnm_ap.c @@ -442,7 +442,8 @@ static void ieee802_11_rx_bss_trans_mgmt wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries", pos, end - pos); @@ -582,8 +632,10 @@ wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries", pos, end - pos); } ---- a/src/utils/eloop.c -+++ b/src/utils/eloop.c +Index: hostapd-2021-02-20-59e9794c/src/utils/eloop.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/utils/eloop.c ++++ hostapd-2021-02-20-59e9794c/src/utils/eloop.c @@ -77,6 +77,9 @@ struct eloop_sock_table { struct eloop_data { int max_sock; @@ -632,8 +684,10 @@ void eloop_terminate(void) { ---- a/src/utils/eloop.h -+++ b/src/utils/eloop.h +Index: hostapd-2021-02-20-59e9794c/src/utils/eloop.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/utils/eloop.h ++++ hostapd-2021-02-20-59e9794c/src/utils/eloop.h @@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo */ typedef void (*eloop_signal_handler)(int sig, void *signal_ctx); @@ -663,8 +717,10 @@ /** * eloop_run - Start the event loop * +Index: hostapd-2021-02-20-59e9794c/src/utils/uloop.c +=================================================================== --- /dev/null -+++ b/src/utils/uloop.c ++++ hostapd-2021-02-20-59e9794c/src/utils/uloop.c @@ -0,0 +1,64 @@ +#include +#include "includes.h" diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c index 6013304a0..1ec7c846a 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c +++ b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.c @@ -1737,6 +1737,19 @@ void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 * ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); } +void hostapd_ubus_notify_csa(struct hostapd_data *hapd, int freq) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + blobmsg_add_u32(&b, "freq", freq); + blobmsg_printf(&b, "bssid", MACSTR, MAC2STR(hapd->conf->bssid)); + + ubus_notify(ctx, &hapd->ubus.obj, "channel-switch", b.head, -1); +} + void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta) { diff --git a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.h b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.h index af48a0964..ce23ee3a5 100644 --- a/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.h +++ b/feeds/ipq807x_v5.4/hostapd/src/src/ap/ubus.h @@ -65,6 +65,7 @@ void hostapd_ubus_free(struct hapd_interfaces *interfaces); int hostapd_ubus_notify_bss_transition_query( struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, const u8 *candidate_list, u16 candidate_list_len); +void hostapd_ubus_notify_csa(struct hostapd_data *hapd, int freq); #else diff --git a/feeds/wifi-ax/hostapd/patches/600-ubus_support.patch b/feeds/wifi-ax/hostapd/patches/600-ubus_support.patch index afcb8eb47..245e9b8e4 100644 --- a/feeds/wifi-ax/hostapd/patches/600-ubus_support.patch +++ b/feeds/wifi-ax/hostapd/patches/600-ubus_support.patch @@ -1,5 +1,7 @@ ---- a/hostapd/Makefile -+++ b/hostapd/Makefile +Index: hostapd-2021-02-20-59e9794c/hostapd/Makefile +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/hostapd/Makefile ++++ hostapd-2021-02-20-59e9794c/hostapd/Makefile @@ -166,6 +166,12 @@ OBJS += ../src/common/hw_features_common OBJS += ../src/eapol_auth/eapol_auth_sm.o @@ -13,8 +15,10 @@ ifdef CONFIG_CODE_COVERAGE CFLAGS += -O0 -fprofile-arcs -ftest-coverage ---- a/src/ap/hostapd.h -+++ b/src/ap/hostapd.h +Index: hostapd-2021-02-20-59e9794c/src/ap/hostapd.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/hostapd.h ++++ hostapd-2021-02-20-59e9794c/src/ap/hostapd.h @@ -17,6 +17,7 @@ #include "utils/list.h" #include "ap_config.h" @@ -39,8 +43,10 @@ void hostapd_interface_deinit(struct hostapd_iface *iface); void hostapd_interface_free(struct hostapd_iface *iface); struct hostapd_iface * hostapd_alloc_iface(void); ---- a/src/ap/hostapd.c -+++ b/src/ap/hostapd.c +Index: hostapd-2021-02-20-59e9794c/src/ap/hostapd.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/hostapd.c ++++ hostapd-2021-02-20-59e9794c/src/ap/hostapd.c @@ -376,6 +376,7 @@ void hostapd_free_hapd_data(struct hosta hapd->beacon_set_done = 0; @@ -82,8 +88,10 @@ hostapd_interface_deinit(iface); wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", __func__, driver, drv_priv); ---- a/src/ap/ieee802_11.c -+++ b/src/ap/ieee802_11.c +Index: hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/ieee802_11.c ++++ hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c @@ -3421,13 +3421,18 @@ static void handle_auth(struct hostapd_d u16 auth_alg, auth_transaction, status_code; u16 resp = WLAN_STATUS_SUCCESS; @@ -170,8 +178,10 @@ sta = ap_get_sta(hapd, mgmt->sa); if (sta == NULL) { wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " ---- a/src/ap/beacon.c -+++ b/src/ap/beacon.c +Index: hostapd-2021-02-20-59e9794c/src/ap/beacon.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/beacon.c ++++ hostapd-2021-02-20-59e9794c/src/ap/beacon.c @@ -823,6 +823,12 @@ void handle_probe_req(struct hostapd_dat u16 csa_offs[2]; size_t csa_offs_len; @@ -198,8 +208,10 @@ /* TODO: verify that supp_rates contains at least one matching rate * with AP configuration */ ---- a/src/ap/drv_callbacks.c -+++ b/src/ap/drv_callbacks.c +Index: hostapd-2021-02-20-59e9794c/src/ap/drv_callbacks.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/drv_callbacks.c ++++ hostapd-2021-02-20-59e9794c/src/ap/drv_callbacks.c @@ -145,6 +145,10 @@ int hostapd_notif_assoc(struct hostapd_d u16 reason = WLAN_REASON_UNSPECIFIED; int status = WLAN_STATUS_SUCCESS; @@ -224,8 +236,22 @@ #ifdef CONFIG_P2P if (elems.p2p) { wpabuf_free(sta->p2p_ie); ---- a/src/ap/sta_info.c -+++ b/src/ap/sta_info.c +@@ -981,9 +991,11 @@ void hostapd_event_ch_switch(struct host + + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED + "freq=%d dfs=%d", freq, is_dfs); ++ hostapd_ubus_notify_csa(hapd, freq); + } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED + "freq=%d dfs=%d", freq, is_dfs); ++ hostapd_ubus_notify_csa(hapd, freq); + } else if (is_dfs && + hostapd_is_dfs_required(hapd->iface) && + !hostapd_is_dfs_chan_available(hapd->iface) && +Index: hostapd-2021-02-20-59e9794c/src/ap/sta_info.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/sta_info.c ++++ hostapd-2021-02-20-59e9794c/src/ap/sta_info.c @@ -458,6 +458,7 @@ void ap_handle_timer(void *eloop_ctx, vo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "deauthenticated due to " @@ -304,8 +330,10 @@ if (hapd->msg_ctx_parent && hapd->msg_ctx_parent != hapd->msg_ctx) ---- a/src/ap/wpa_auth_glue.c -+++ b/src/ap/wpa_auth_glue.c +Index: hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_glue.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wpa_auth_glue.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wpa_auth_glue.c @@ -265,6 +265,7 @@ static void hostapd_wpa_auth_psk_failure struct hostapd_data *hapd = ctx; wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR, @@ -314,8 +342,10 @@ } ---- a/wpa_supplicant/Makefile -+++ b/wpa_supplicant/Makefile +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/Makefile +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/Makefile ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/Makefile @@ -169,6 +169,13 @@ ifdef CONFIG_EAPOL_TEST CFLAGS += -Werror -DEAPOL_TEST endif @@ -340,8 +370,10 @@ endif CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY ---- a/wpa_supplicant/wpa_supplicant.c -+++ b/wpa_supplicant/wpa_supplicant.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wpa_supplicant.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant.c @@ -6943,6 +6943,8 @@ struct wpa_supplicant * wpa_supplicant_a } #endif /* CONFIG_P2P */ @@ -373,8 +405,10 @@ return 0; } ---- a/wpa_supplicant/wpa_supplicant_i.h -+++ b/wpa_supplicant/wpa_supplicant_i.h +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant_i.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wpa_supplicant_i.h ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wpa_supplicant_i.h @@ -19,6 +19,7 @@ #include "wps/wps_defs.h" #include "config_ssid.h" @@ -400,8 +434,10 @@ #ifdef CONFIG_MATCH_IFACE int matched; #endif /* CONFIG_MATCH_IFACE */ ---- a/wpa_supplicant/wps_supplicant.c -+++ b/wpa_supplicant/wps_supplicant.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/wps_supplicant.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/wps_supplicant.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/wps_supplicant.c @@ -33,6 +33,7 @@ #include "p2p/p2p.h" #include "p2p_supplicant.h" @@ -419,8 +455,10 @@ if (wpa_s->conf->wps_cred_processing == 1) return 0; ---- a/wpa_supplicant/main.c -+++ b/wpa_supplicant/main.c +Index: hostapd-2021-02-20-59e9794c/wpa_supplicant/main.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/wpa_supplicant/main.c ++++ hostapd-2021-02-20-59e9794c/wpa_supplicant/main.c @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) for (;;) { @@ -440,8 +478,10 @@ case 'o': params.override_driver = optarg; break; ---- a/src/ap/rrm.c -+++ b/src/ap/rrm.c +Index: hostapd-2021-02-20-59e9794c/src/ap/rrm.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/rrm.c ++++ hostapd-2021-02-20-59e9794c/src/ap/rrm.c @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report return; wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s", @@ -452,8 +492,10 @@ } ---- a/src/ap/vlan_init.c -+++ b/src/ap/vlan_init.c +Index: hostapd-2021-02-20-59e9794c/src/ap/vlan_init.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/vlan_init.c ++++ hostapd-2021-02-20-59e9794c/src/ap/vlan_init.c @@ -22,6 +22,7 @@ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, int existsok) @@ -490,8 +532,10 @@ return hostapd_vlan_if_remove(hapd, vlan->ifname); } ---- a/src/ap/dfs.c -+++ b/src/ap/dfs.c +Index: hostapd-2021-02-20-59e9794c/src/ap/dfs.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/dfs.c ++++ hostapd-2021-02-20-59e9794c/src/ap/dfs.c @@ -1226,6 +1226,8 @@ int hostapd_dfs_nop_finished(struct host "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", freq, ht_enabled, chan_offset, chan_width, cf1, cf2); @@ -501,8 +545,10 @@ /* Proceed only if DFS is not offloaded to the driver */ if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) return 0; ---- a/src/ap/airtime_policy.c -+++ b/src/ap/airtime_policy.c +Index: hostapd-2021-02-20-59e9794c/src/ap/airtime_policy.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/airtime_policy.c ++++ hostapd-2021-02-20-59e9794c/src/ap/airtime_policy.c @@ -108,8 +108,14 @@ static void set_sta_weights(struct hosta { struct sta_info *sta; @@ -532,8 +578,10 @@ if (weight) return sta_set_airtime_weight(hapd, sta, weight); } ---- a/src/ap/sta_info.h -+++ b/src/ap/sta_info.h +Index: hostapd-2021-02-20-59e9794c/src/ap/sta_info.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/sta_info.h ++++ hostapd-2021-02-20-59e9794c/src/ap/sta_info.h @@ -323,6 +323,7 @@ struct sta_info { #endif /* CONFIG_TESTING_OPTIONS */ #ifdef CONFIG_AIRTIME_POLICY @@ -542,8 +590,10 @@ struct os_reltime backlogged_until; #endif /* CONFIG_AIRTIME_POLICY */ ---- a/src/ap/wnm_ap.c -+++ b/src/ap/wnm_ap.c +Index: hostapd-2021-02-20-59e9794c/src/ap/wnm_ap.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/ap/wnm_ap.c ++++ hostapd-2021-02-20-59e9794c/src/ap/wnm_ap.c @@ -442,7 +442,8 @@ static void ieee802_11_rx_bss_trans_mgmt wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries", pos, end - pos); @@ -582,8 +632,10 @@ wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries", pos, end - pos); } ---- a/src/utils/eloop.c -+++ b/src/utils/eloop.c +Index: hostapd-2021-02-20-59e9794c/src/utils/eloop.c +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/utils/eloop.c ++++ hostapd-2021-02-20-59e9794c/src/utils/eloop.c @@ -77,6 +77,9 @@ struct eloop_sock_table { struct eloop_data { int max_sock; @@ -632,8 +684,10 @@ void eloop_terminate(void) { ---- a/src/utils/eloop.h -+++ b/src/utils/eloop.h +Index: hostapd-2021-02-20-59e9794c/src/utils/eloop.h +=================================================================== +--- hostapd-2021-02-20-59e9794c.orig/src/utils/eloop.h ++++ hostapd-2021-02-20-59e9794c/src/utils/eloop.h @@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo */ typedef void (*eloop_signal_handler)(int sig, void *signal_ctx); @@ -663,8 +717,10 @@ /** * eloop_run - Start the event loop * +Index: hostapd-2021-02-20-59e9794c/src/utils/uloop.c +=================================================================== --- /dev/null -+++ b/src/utils/uloop.c ++++ hostapd-2021-02-20-59e9794c/src/utils/uloop.c @@ -0,0 +1,64 @@ +#include +#include "includes.h" diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ubus.c b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c index 154876a84..c179b38e6 100644 --- a/feeds/wifi-ax/hostapd/src/src/ap/ubus.c +++ b/feeds/wifi-ax/hostapd/src/src/ap/ubus.c @@ -1737,6 +1737,19 @@ void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 * ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1); } +void hostapd_ubus_notify_csa(struct hostapd_data *hapd, int freq) +{ + if (!hapd->ubus.obj.has_subscribers) + return; + + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "ifname", hapd->conf->iface); + blobmsg_add_u32(&b, "freq", freq); + blobmsg_printf(&b, "bssid", MACSTR, MAC2STR(hapd->conf->bssid)); + + ubus_notify(ctx, &hapd->ubus.obj, "channel-switch", b.head, -1); +} + void hostapd_ubus_notify_authorized(struct hostapd_data *hapd, struct sta_info *sta) { diff --git a/feeds/wifi-ax/hostapd/src/src/ap/ubus.h b/feeds/wifi-ax/hostapd/src/src/ap/ubus.h index af48a0964..ce23ee3a5 100644 --- a/feeds/wifi-ax/hostapd/src/src/ap/ubus.h +++ b/feeds/wifi-ax/hostapd/src/src/ap/ubus.h @@ -65,6 +65,7 @@ void hostapd_ubus_free(struct hapd_interfaces *interfaces); int hostapd_ubus_notify_bss_transition_query( struct hostapd_data *hapd, const u8 *addr, u8 dialog_token, u8 reason, const u8 *candidate_list, u16 candidate_list_len); +void hostapd_ubus_notify_csa(struct hostapd_data *hapd, int freq); #else From 52884b2835f3d5a1c3d678279ca9764caa9c3763 Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 15 Sep 2023 10:07:29 +0800 Subject: [PATCH 31/32] ipq807x: CIG wf660ag: support both EMMC and SPI NOR+EMCC H/W Using one firmware to support the board which has EMMC only and SPI NOR+EMMC equipped Fixes: WIFI-12941 Signed-off-by: Ken --- .../ipq807x/base-files/etc/board.d/02_network | 7 ++++--- .../etc/hotplug.d/firmware/10-ath11k-caldata | 5 +++-- .../base-files/lib/upgrade/platform.sh | 20 ++++++++++++------- .../files/etc/init.d/certificates | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network index 7c341f149..2e60031a8 100755 --- a/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network +++ b/feeds/ipq807x/ipq807x/base-files/etc/board.d/02_network @@ -215,9 +215,10 @@ qcom_setup_macs() ucidef_set_label_macaddr $wan_mac ;; cig,wf660a) - mmc_dev=$(echo $(find_mmc_part "0:APPSBLENV") | sed 's/^.\{5\}//') - [ -z mmc_dev ] && return - mac=$(grep BaseMacAddress= /dev/$mmc_dev | cut -dx -f2) + mmc_dev=$(find_mtd_chardev "0:APPSBLENV") + [ -z "$mmc_dev" ] && mmc_dev=$(find_mmc_part "0:APPSBLENV") + [ -z "$mmc_dev" ] && return + mac=$(grep BaseMacAddress= $mmc_dev | cut -dx -f2) [ -z "$mac" ] && return; wan_mac=$(macaddr_canonicalize $mac) ucidef_set_network_device_mac eth0 $wan_mac diff --git a/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata index 8dc88c875..3386069b6 100755 --- a/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata +++ b/feeds/ipq807x/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata @@ -61,8 +61,9 @@ ath11k_generate_macs_pax1800() { ath11k_generate_macs_wf660a() { touch /lib/firmware/ath11k-macs - mmc_dev=$(find_mmc_part 0:APPSBLENV) - [ -n $mmc_dev ] && mac=$(grep BaseMacAddress= $mmc_dev | cut -dx -f2) + mmc_dev=$(find_mtd_chardev "0:APPSBLENV") + [ -z "$mmc_dev" ] && mmc_dev=$(find_mmc_part "0:APPSBLENV") + [ -n "$mmc_dev" ] && mac=$(grep BaseMacAddress= $mmc_dev | cut -dx -f2) eth=$(macaddr_canonicalize $mac) mac1=$(macaddr_add $eth 1) mac2=$(macaddr_add $eth 2) diff --git a/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh b/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh index cdd6593e1..d7c690bc6 100755 --- a/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh +++ b/feeds/ipq807x/ipq807x/base-files/lib/upgrade/platform.sh @@ -52,7 +52,7 @@ do_flash_emmc() { tar Oxf $tar_file ${board_dir}/$part | dd of=${emmcblock} } -emmc_do_upgrade_bootconfig() { +spi_nor_emmc_do_upgrade_bootconfig() { local tar_file="$1" local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$') @@ -84,11 +84,17 @@ emmc_do_upgrade_bootconfig() { fi for part in "0:BOOTCONFIG" "0:BOOTCONFIG1"; do - local emmcblock=$(find_mmc_part $part) - echo erase ${emmcblock} - dd if=/dev/zero of=${emmcblock} 2> /dev/null - echo update $emmcblock - dd if=/tmp/bootconfig of=${emmcblock} 2> /dev/null + local mtdchar=$(echo $(find_mtd_chardev $part) | sed 's/^.\{5\}//') + if [ -n "$mtdchar" ]; then + echo start to update $mtdchar + mtd -qq write /proc/boot_info/getbinary_bootconfig "/dev/${mtdchar}" 2>/dev/null && echo update mtd $mtdchar + else + emmcblock=$(find_mmc_part $part) + echo erase ${emmcblock} + dd if=/dev/zero of=${emmcblock} 2> /dev/null + echo update $emmcblock + dd if=/tmp/bootconfig of=${emmcblock} 2> /dev/null + fi done } @@ -175,7 +181,7 @@ platform_do_upgrade() { qca_do_upgrade $1 ;; cig,wf660a) - emmc_do_upgrade_bootconfig $1 + spi_nor_emmc_do_upgrade_bootconfig $1 ;; motorola,q14) emmc_do_upgrade $1 diff --git a/feeds/tip/certificates/files/etc/init.d/certificates b/feeds/tip/certificates/files/etc/init.d/certificates index 2b1aa9807..c810644d1 100755 --- a/feeds/tip/certificates/files/etc/init.d/certificates +++ b/feeds/tip/certificates/files/etc/init.d/certificates @@ -34,7 +34,7 @@ boot() { case "$(board_name)" in cig,wf660a) mmc_dev=$(echo $(find_mmc_part "0:ETHPHYFW") | sed 's/^.\{5\}//') - [ -n $mmc_dev ] && mount -t ext4 /dev/$mmc_dev /certificates + [ -n "$mmc_dev" ] && mount -t ext4 /dev/$mmc_dev /certificates ;; esac From 007cfe9c16e9bea45852055d98b3664259758499 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 19 Sep 2023 06:44:06 +0200 Subject: [PATCH 32/32] ipq807x: update ifname rename patches Signed-off-by: John Crispin --- ...ive-renaming-when-an-interface-is-up.patch | 60 +++++++++++++++++++ ...ive-renaming-when-an-interface-is-up.patch | 17 ++---- 2 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 feeds/ipq807x_v5.4/ipq50xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch diff --git a/feeds/ipq807x_v5.4/ipq50xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x_v5.4/ipq50xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch new file mode 100644 index 000000000..44d468a36 --- /dev/null +++ b/feeds/ipq807x_v5.4/ipq50xx/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -0,0 +1,60 @@ +From: Andy Ren +Date: Mon, 7 Nov 2022 09:42:42 -0800 +Subject: [PATCH] net/core: Allow live renaming when an interface is up + +Allow a network interface to be renamed when the interface +is up. + +As described in the netconsole documentation [1], when netconsole is +used as a built-in, it will bring up the specified interface as soon as +possible. As a result, user space will not be able to rename the +interface since the kernel disallows renaming of interfaces that are +administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set +by the kernel. + +The original solution [2] to this problem was to add a new parameter to +the netconsole configuration parameters that allows renaming of +the interface used by netconsole while it is administratively up. +However, during the discussion that followed, it became apparent that we +have no reason to keep the current restriction and instead we should +allow user space to rename interfaces regardless of their administrative +state: + +1. The restriction was put in place over 20 years ago when renaming was +only possible via IOCTL and before rtnetlink started notifying user +space about such changes like it does today. + +2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version +5.2 and no regressions were reported. + +3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about +the administrative state of interface. + +Therefore, allow user space to rename running interfaces by removing the +restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in +possible triage by emitting a message to the kernel log that an +interface was renamed while UP. + +[1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst +[2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/ + +Signed-off-by: Andy Ren +Reviewed-by: Ido Schimmel +Reviewed-by: David Ahern +Signed-off-by: David S. Miller +--- + +Index: linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +=================================================================== +--- linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d.orig/net/core/dev.c ++++ linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +@@ -1125,7 +1125,8 @@ int dev_change_name(struct net_device *d + } + + if (oldname[0] && !strchr(oldname, '%')) +- netdev_info(dev, "renamed from %s\n", oldname); ++ netdev_info(dev, "renamed from %s%s\n", oldname, ++ dev->flags & IFF_UP ? " (while UP)" : ""); + + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; diff --git a/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch b/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch index 1a97d2759..44d468a36 100644 --- a/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch +++ b/feeds/ipq807x_v5.4/ipq807x/patches/238-net-core-Allow-live-renaming-when-an-interface-is-up.patch @@ -44,18 +44,11 @@ Reviewed-by: David Ahern Signed-off-by: David S. Miller --- ---- a/net/core/dev.c -+++ b/net/core/dev.c -@@ -1152,8 +1152,6 @@ int dev_change_name(struct net_device *d - BUG_ON(!dev_net(dev)); - - net = dev_net(dev); -- if (dev->flags & IFF_UP) -- return -EBUSY; - - write_seqcount_begin(&devnet_rename_seq); - -@@ -1171,7 +1169,8 @@ int dev_change_name(struct net_device *d +Index: linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +=================================================================== +--- linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d.orig/net/core/dev.c ++++ linux-5.4.164-qsdk-26349818b464f8c7b52d59ce73579d9f3dd6bd5d/net/core/dev.c +@@ -1125,7 +1125,8 @@ int dev_change_name(struct net_device *d } if (oldname[0] && !strchr(oldname, '%'))