diff --git a/board/aarch64/acer-connect-vero-w6m/rootfs/usr/share/product/acer,connect-vero-w/etc/factory-config.cfg b/board/aarch64/acer-connect-vero-w6m/rootfs/usr/share/product/acer,connect-vero-w/etc/factory-config.cfg index 0f90e73ee4..9f7909ef90 100644 --- a/board/aarch64/acer-connect-vero-w6m/rootfs/usr/share/product/acer,connect-vero-w/etc/factory-config.cfg +++ b/board/aarch64/acer-connect-vero-w6m/rootfs/usr/share/product/acer,connect-vero-w/etc/factory-config.cfg @@ -463,7 +463,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r2-pro/rootfs/usr/share/product/sinovoip,rk3568-bpi-r2pro/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r2-pro/rootfs/usr/share/product/sinovoip,rk3568-bpi-r2pro/etc/factory-config.cfg index d82f7d4ff5..27dbf5d96a 100644 --- a/board/aarch64/bananapi-bpi-r2-pro/rootfs/usr/share/product/sinovoip,rk3568-bpi-r2pro/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r2-pro/rootfs/usr/share/product/sinovoip,rk3568-bpi-r2pro/etc/factory-config.cfg @@ -394,7 +394,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/factory-config.cfg index 2da62c0c61..5cee66d38f 100644 --- a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/factory-config.cfg @@ -457,7 +457,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3mini/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3mini/etc/factory-config.cfg index 163fd0d616..19975fa25b 100644 --- a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3mini/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3mini/etc/factory-config.cfg @@ -423,7 +423,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4-2g5/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4-2g5/etc/factory-config.cfg index 9f6d1f4080..4f55aee1aa 100644 --- a/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4-2g5/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4-2g5/etc/factory-config.cfg @@ -387,7 +387,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4/etc/factory-config.cfg index 5da72910d1..bed49c1bde 100644 --- a/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r4/rootfs/usr/share/product/bananapi,bpi-r4/etc/factory-config.cfg @@ -379,7 +379,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/bananapi-bpi-r64/rootfs/usr/share/product/bananapi,bpi-r64/etc/factory-config.cfg b/board/aarch64/bananapi-bpi-r64/rootfs/usr/share/product/bananapi,bpi-r64/etc/factory-config.cfg index 4bcef2615f..407b97cc83 100644 --- a/board/aarch64/bananapi-bpi-r64/rootfs/usr/share/product/bananapi,bpi-r64/etc/factory-config.cfg +++ b/board/aarch64/bananapi-bpi-r64/rootfs/usr/share/product/bananapi,bpi-r64/etc/factory-config.cfg @@ -423,7 +423,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s-plus/etc/factory-config.cfg b/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s-plus/etc/factory-config.cfg index 5c9ae36e72..3cc6d11eb9 100644 --- a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s-plus/etc/factory-config.cfg +++ b/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s-plus/etc/factory-config.cfg @@ -370,7 +370,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/factory-config.cfg b/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/factory-config.cfg index 0b6f0629d0..3dc5e819fc 100644 --- a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/factory-config.cfg +++ b/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/factory-config.cfg @@ -363,7 +363,7 @@ ] }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/factory-config.cfg b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/factory-config.cfg index 0ee5dc2f7c..e1e0ef46d7 100644 --- a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/factory-config.cfg +++ b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/factory-config.cfg @@ -259,7 +259,7 @@ "infix-system:motd-banner": "Li0tLS0tLS0uCnwgIC4gLiAgfCBJbmZpeCBPUyDigJQgSW1tdXRhYmxlLkZyaWVuZGx5LlNlY3VyZQp8LS4gdiAuLXwgaHR0cHM6Ly9rZXJuZWxraXQub3JnCictJy0tLSctJwo=" }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,400/etc/factory-config.cfg b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,400/etc/factory-config.cfg index ad90e65157..7458acf418 100644 --- a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,400/etc/factory-config.cfg +++ b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,400/etc/factory-config.cfg @@ -273,7 +273,7 @@ "infix-system:motd-banner": "Li0tLS0tLS0uCnwgIC4gLiAgfCBJbmZpeCBPUyDigJQgSW1tdXRhYmxlLkZyaWVuZGx5LlNlY3VyZQp8LS4gdiAuLXwgaHR0cHM6Ly9rZXJuZWxraXQub3JnCictJy0tLSctJwo=" }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/arm/bananapi-bpi-m1/rootfs/usr/share/product/lemaker,bananapi/etc/factory-config.cfg b/board/arm/bananapi-bpi-m1/rootfs/usr/share/product/lemaker,bananapi/etc/factory-config.cfg index 1b558937fd..a2f89ec008 100644 --- a/board/arm/bananapi-bpi-m1/rootfs/usr/share/product/lemaker,bananapi/etc/factory-config.cfg +++ b/board/arm/bananapi-bpi-m1/rootfs/usr/share/product/lemaker,bananapi/etc/factory-config.cfg @@ -272,7 +272,7 @@ "infix-system:motd-banner": "Li0tLS0tLS0uCnwgIC4gLiAgfCBJbmZpeCBPUyDigJQgSW1tdXRhYmxlLkZyaWVuZGx5LlNlY3VyZQp8LS4gdiAuLXwgaHR0cHM6Ly9rZXJuZWxraXQub3JnCictJy0tLSctJwo=" }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/arm/raspberrypi-rpi2/rootfs/usr/share/product/raspberrypi,2-model-b/etc/factory-config.cfg b/board/arm/raspberrypi-rpi2/rootfs/usr/share/product/raspberrypi,2-model-b/etc/factory-config.cfg index 52b2e3c9d0..f3e1673176 100644 --- a/board/arm/raspberrypi-rpi2/rootfs/usr/share/product/raspberrypi,2-model-b/etc/factory-config.cfg +++ b/board/arm/raspberrypi-rpi2/rootfs/usr/share/product/raspberrypi,2-model-b/etc/factory-config.cfg @@ -254,7 +254,7 @@ "infix-system:motd-banner": "Li0tLS0tLS0uCnwgIC4gLiAgfCBJbmZpeCBPUyDigJQgSW1tdXRhYmxlLkZyaWVuZGx5LlNlY3VyZQp8LS4gdiAuLXwgaHR0cHM6Ly9rZXJuZWxraXQub3JnCictJy0tLSctJwo=" }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/board/common/qemu/ddi/Config.in.in b/board/common/qemu/ddi/Config.in.in index 79a35f28f8..8b4306dce9 100644 --- a/board/common/qemu/ddi/Config.in.in +++ b/board/common/qemu/ddi/Config.in.in @@ -331,6 +331,21 @@ config IX_QEMU_NET_MODEL endmenu +menu "Wireless" + +config IX_QEMU_WIFI_RADIOS + int "Number of virtual Wi-Fi radios" + default 0 + help + Number of simulated 802.11 radios (mac80211_hwsim) to create + in the guest. With 0, the default, the guest has no radios. + + Set a small number, e.g. 2, for local AP and station + experiments. The radios only reach each other inside this + one guest. + +endmenu + config IX_QEMU_EXTRA string "Extra QEMU options" diff --git a/board/common/qemu/ddi/run.sh b/board/common/qemu/ddi/run.sh index 8afeb86b2b..132847c394 100755 --- a/board/common/qemu/ddi/run.sh +++ b/board/common/qemu/ddi/run.sh @@ -513,6 +513,15 @@ gen_net() gen_net_tap } +gen_wifi() +{ + echo "${IX_QEMU_WIFI_RADIOS:-0}" >"$qdir"/wifi + + q sect fw_cfg + q param name opt/wifi + q param file "$qdir"/wifi +} + gen_gdb() { # Create a UNIX socket on the host that is connected to a virtio @@ -563,6 +572,7 @@ EOF gen_serial gen_disks gen_net + gen_wifi gen_gdb if [ "$IX_QEMU_LOADER_QEMU" ]; then diff --git a/board/riscv64/bananapi-bpi-f3/rootfs/usr/share/product/bananapi,bpi-f3/etc/factory-config.cfg b/board/riscv64/bananapi-bpi-f3/rootfs/usr/share/product/bananapi,bpi-f3/etc/factory-config.cfg index 063e6c89dd..0d8a8dc17e 100644 --- a/board/riscv64/bananapi-bpi-f3/rootfs/usr/share/product/bananapi,bpi-f3/etc/factory-config.cfg +++ b/board/riscv64/bananapi-bpi-f3/rootfs/usr/share/product/bananapi,bpi-f3/etc/factory-config.cfg @@ -324,7 +324,7 @@ "infix-system:motd-banner": "Li0tLS0tLS0uCnwgIC4gLiAgfCBJbmZpeCBPUyDigJQgSW1tdXRhYmxlLkZyaWVuZGx5LlNlY3VyZQp8LS4gdiAuLXwgaHR0cHM6Ly9rZXJuZWxraXQub3JnCictJy0tLSctJwo=" }, "infix-meta:meta": { - "version": "1.12" + "version": "1.13" }, "infix-services:mdns": { "enabled": true diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 68f3870176..6aea9295c0 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -31,6 +31,16 @@ All notable changes to the project are documented in this file. ones on every boot. Requires a bootloader from v26.11.0 or later - Support for Qualcomm WCN6855 Wi-Fi cards, e.g., the QCNFA765, with 2.4, 5 and 6 GHz bands and 802.11ax, see [Wi-Fi][wifi] +- Wi-Fi: a band, channel, channel width, interface mode or number of + access points the radio does not support is now refused with an error + when configured, see [Wi-Fi][wifi]. The modes a radio supports are + in its operational data, as are the channels of each band +- Wi-Fi: a radio without a band no longer accepts a channel, channel + width or legacy rates. They had no effect there and are dropped from + the configuration on upgrade +- WebUI: the Wi-Fi radio forms offer only the bands the radio supports, + and the channel is picked from the channels of the selected band. + The country code is set in one place on the interfaces page - NanoPi R2S Plus: Infix can now be installed on the eMMC - NanoPi R2S Plus: both USB ports can now be locked and unlocked - NanoPi R2S Plus: support for the optional RTL8822CS Wi-Fi module @@ -108,6 +118,8 @@ All notable changes to the project are documented in this file. - LLDP: a device with a Wi-Fi interface announced its WLAN access point capability as disabled +- Wi-Fi: the supported channels of a radio listed only the last + channel of each band, and the 6 GHz band could be missing - A change to a VLAN filtering bridge with spanning tree enabled was not applied once its ports were members of a VLAN - Disabling spanning tree on a bridge left its ports disabled, and the diff --git a/doc/wifi.md b/doc/wifi.md index 49f8ba5af5..2b7ed7695c 100644 --- a/doc/wifi.md +++ b/doc/wifi.md @@ -156,7 +156,9 @@ admin@example:/config/hardware/component/radio0/wifi-radio/> leave **⚠ Must match your physical location for legal compliance! ⚠** -- `band`: 2.4GHz, 5GHz, or 6GHz (required for AP mode). Automatically enables +- `band`: 2.4GHz, 5GHz, or 6GHz (required for AP mode). Only a radio used + for a station can go without a band, and then `channel`, `channel-width` + and `legacy-rates` cannot be set either. Automatically enables appropriate Wi-Fi standards: - 2.4GHz: 802.11n/ax - 5GHz: 802.11n/ac/ax @@ -187,6 +189,13 @@ Each band strikes a different balance between range and capacity. The lists below are the common allocations, and your regulatory domain may allow fewer. +A band, channel, or channel width that the radio does not support is +refused when the configuration is applied, as is more access points +than the radio can carry, or an interface in a mode the radio lacks, +e.g. a mesh point on a radio without 802.11s support. The error names +the radio or interface and the setting. +Use `show hardware` to see what each radio supports. + **2.4 GHz** Channels 1-13 are available in most of the world, 1-11 in the US and diff --git a/src/confd/configure.ac b/src/confd/configure.ac index 02c17a3b0d..5a1ada679d 100644 --- a/src/confd/configure.ac +++ b/src/confd/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.61) # confd version is same as system YANG model version, step on breaking changes -AC_INIT([confd], [1.12], [https://github.com/kernelkit/infix/issues]) +AC_INIT([confd], [1.13], [https://github.com/kernelkit/infix/issues]) AM_INIT_AUTOMAKE(1.11 foreign subdir-objects) AM_SILENT_RULES(yes) @@ -26,6 +26,7 @@ AC_CONFIG_FILES([ share/migrate/1.10/Makefile share/migrate/1.11/Makefile share/migrate/1.12/Makefile + share/migrate/1.13/Makefile yang/Makefile yang/confd/Makefile yang/test-mode/Makefile diff --git a/src/confd/share/migrate/1.13/10-wifi-radio-band.sh b/src/confd/share/migrate/1.13/10-wifi-radio-band.sh new file mode 100755 index 0000000000..5554bfc973 --- /dev/null +++ b/src/confd/share/migrate/1.13/10-wifi-radio-band.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# A Wi-Fi radio without a band no longer takes a channel, channel-width +# or legacy-rates. They had no effect there, drop them. + +file=$1 +temp=${file}.tmp + +jq ' + if .["ietf-hardware:hardware"].component then + .["ietf-hardware:hardware"].component |= map( + if has("infix-hardware:wifi-radio") and (.["infix-hardware:wifi-radio"] | has("band") | not) then + .["infix-hardware:wifi-radio"] |= del(.channel, .["channel-width"], .["legacy-rates"]) + else . end) + else . end +' "$file" > "$temp" && mv "$temp" "$file" diff --git a/src/confd/share/migrate/1.13/Makefile.am b/src/confd/share/migrate/1.13/Makefile.am new file mode 100644 index 0000000000..fa4a72319b --- /dev/null +++ b/src/confd/share/migrate/1.13/Makefile.am @@ -0,0 +1,2 @@ +migratedir = $(pkgdatadir)/migrate/1.13 +dist_migrate_DATA = 10-wifi-radio-band.sh diff --git a/src/confd/share/migrate/Makefile.am b/src/confd/share/migrate/Makefile.am index 780e2a7c5c..d53bb0d19b 100644 --- a/src/confd/share/migrate/Makefile.am +++ b/src/confd/share/migrate/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 +SUBDIRS = 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 migratedir = $(pkgdatadir)/migrate diff --git a/src/confd/src/hardware.c b/src/confd/src/hardware.c index 1ea75374d4..7efe3c37f5 100644 --- a/src/confd/src/hardware.c +++ b/src/confd/src/hardware.c @@ -145,6 +145,12 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l wifi_country_change(config, diff, event); + if (event == SR_EV_CHANGE) { + rc = wifi_radios_validate(session, config, diff); + if (rc) + return rc; + } + difs = lydx_get_descendant(diff, "hardware", "component", NULL); LYX_LIST_FOR_EACH(difs, dif, "component") { const char *name = lydx_get_cattr(dif, "name"); diff --git a/src/confd/src/hardware.h b/src/confd/src/hardware.h index 524893f148..acf92bebae 100644 --- a/src/confd/src/hardware.h +++ b/src/confd/src/hardware.h @@ -28,6 +28,7 @@ void wifi_gen_ssid_config(FILE *hostapd, struct lyd_node *cif, struct lyd_node * const char *band, struct confd *confd); /* hw-wifi.c */ +int wifi_radios_validate(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff); void wifi_country_change(struct lyd_node *config, struct lyd_node *diff, sr_event_t event); int wifi_radio_change(struct lyd_node *config, struct lyd_node *cif, sr_event_t event, struct confd *confd); diff --git a/src/confd/src/hw-wifi.c b/src/confd/src/hw-wifi.c index f389b659cd..440c5252b5 100644 --- a/src/confd/src/hw-wifi.c +++ b/src/confd/src/hw-wifi.c @@ -598,6 +598,249 @@ static void wifi_gen_helpers(FILE *fp, glob_t *gl) fprintf(fp, " \\\n\t-- Wi-Fi neighbor exchange\n"); } +/* + * The hardware component list as yangerd has it. NULL when yangerd + * does not answer, as during boot, and nothing can be checked. + */ +static json_t *wifi_oper_components(void) +{ + json_t *root, *list; + FILE *pp; + + pp = popenf("r", "yangerctl get /ietf-hardware:hardware 2>/dev/null"); + if (!pp) + return NULL; + + root = json_loadf(pp, 0, NULL); + pclose(pp); + + list = json_object_get(json_object_get(root, "ietf-hardware:hardware"), "component"); + json_incref(list); + json_decref(root); + + return list; +} + +/* What the hardware reports for a radio, NULL when it is not present */ +static json_t *wifi_oper_radio(json_t *components, const char *name) +{ + json_t *comp; + size_t i; + + json_array_foreach(components, i, comp) { + const char *nm = json_string_value(json_object_get(comp, "name")); + + if (nm && !strcmp(nm, name)) + return json_object_get(comp, "infix-hardware:wifi-radio"); + } + + return NULL; +} + +/* yangerd names the bands "5 GHz", the configuration "5GHz" */ +static json_t *wifi_oper_band(json_t *oper, const char *band) +{ + json_t *entry; + size_t i; + + json_array_foreach(json_object_get(oper, "bands"), i, entry) { + const char *nm = json_string_value(json_object_get(entry, "name")); + const char *b = band; + + while (nm && *nm && *b) { + if (*nm == ' ') + nm++; + else if (*nm++ != *b++) + break; + } + if (nm && !*nm && !*b) + return entry; + } + + return NULL; +} + +static bool wifi_channel_in_band(const char *band, int ch) +{ + if (!strcmp(band, "2.4GHz")) + return ch >= 1 && ch <= 14; + if (!strcmp(band, "5GHz")) + return ch >= 32 && ch <= 177; + + return ch >= 1 && ch <= 233; +} + +static bool wifi_channel_supported(json_t *oper, json_t *oband, int ch) +{ + json_t *list = json_object_get(oper, "supported-channels"); + json_t *entry; + size_t i; + + if (oband) + list = json_object_get(oband, "channels"); + else if (!json_array_size(list)) + return true; + + json_array_foreach(list, i, entry) { + if (json_integer_value(entry) == ch) + return true; + } + + return false; +} + +/* The first interface on the radio in a mode the radio does not list, if any */ +static const char *wifi_unsupported_mode(struct lyd_node *cifs, const char *radio, json_t *oper, + const char **mode) +{ + json_t *modes = json_object_get(oper, "supported-modes"); + struct lyd_node *cif; + + if (!json_array_size(modes)) + return NULL; + + LYX_LIST_FOR_EACH(cifs, cif, "interface") { + const char *r = lydx_get_cattr(lydx_get_child(cif, "wifi"), "radio"); + bool found = false; + json_t *entry; + size_t i; + + if (!r || strcmp(r, radio)) + continue; + + switch (wifi_get_mode(cif)) { + case wifi_ap: + *mode = "access-point"; + break; + case wifi_mesh: + *mode = "mesh-point"; + break; + case wifi_station: + *mode = "station"; + break; + default: + continue; + } + + json_array_foreach(modes, i, entry) { + if (json_is_string(entry) && !strcmp(json_string_value(entry), *mode)) + found = true; + } + if (!found) + return lydx_get_cattr(cif, "name"); + } + + return NULL; +} + +/* Refuse radio settings the hardware reports it cannot do */ +static int wifi_radio_validate(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff, + const char *name, struct lyd_node *radio, json_t *components) +{ + json_t *oper = wifi_oper_radio(components, name); + const char *band, *channel, *width; + struct lyd_node *cifs = lydx_get_descendant(config, "interfaces", "interface", NULL); + const char *ifname, *mode; + json_t *oband = NULL, *max; + int ch = 0, aps; + + if (!oper) + return SR_ERR_OK; + + ifname = wifi_unsupported_mode(cifs, name, oper, &mode); + if (ifname) { + sr_session_set_error_message(session, "%s: %s mode is not supported by %s", + ifname, mode, name); + return SR_ERR_INVAL_ARG; + } + + if (!radio) + return SR_ERR_OK; + + band = lydx_get_cattr(radio, "band"); + channel = lydx_get_cattr(radio, "channel"); + width = lydx_get_cattr(radio, "channel-width"); + if (channel && strcmp(channel, "auto")) + ch = atoi(channel); + + if (band && json_array_size(json_object_get(oper, "bands"))) { + oband = wifi_oper_band(oper, band); + if (!oband) { + sr_session_set_error_message(session, "%s: band %s is not supported by this radio", + name, band); + return SR_ERR_INVAL_ARG; + } + } + + if (ch && band && !wifi_channel_in_band(band, ch)) { + sr_session_set_error_message(session, "%s: channel %d is not a %s channel", name, ch, band); + return SR_ERR_INVAL_ARG; + } + + /* The channel list follows the country code, which is not applied yet when it changes */ + if (ch && !lydx_get_xpathf(diff, XPATH_BASE_ "/infix-hardware:wifi/country-code") && + !wifi_channel_supported(oper, oband, ch)) { + sr_session_set_error_message(session, "%s: channel %d is not available on this radio " + "with the current country code", name, ch); + return SR_ERR_INVAL_ARG; + } + + if (oband && width && strcmp(width, "auto") && strcmp(width, "20MHz")) { + bool ht = json_is_true(json_object_get(oband, "ht-capable")); + bool vht = json_is_true(json_object_get(oband, "vht-capable")); + bool he = json_is_true(json_object_get(oband, "he-capable")); + + if (!he && !(strcmp(width, "40MHz") ? vht : ht)) { + sr_session_set_error_message(session, "%s: channel width %s is not supported " + "by this radio on %s", name, width, band); + return SR_ERR_INVAL_ARG; + } + } + + max = json_object_get(json_object_get(oper, "max-interfaces"), "ap"); + aps = wifi_radio_ap_count(cifs, name); + if (json_is_integer(max) && aps > json_integer_value(max)) { + sr_session_set_error_message(session, "%s: %d access points configured, this radio " + "supports %lld", name, aps, json_integer_value(max)); + return SR_ERR_INVAL_ARG; + } + + return SR_ERR_OK; +} + +/* Check every changed radio against the hardware, with a single query */ +int wifi_radios_validate(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff) +{ + struct lyd_node *difs, *dif, *cif; + json_t *components = NULL; + int rc = SR_ERR_OK; + + difs = lydx_get_descendant(diff, "hardware", "component", NULL); + LYX_LIST_FOR_EACH(difs, dif, "component") { + const char *name = lydx_get_cattr(dif, "name"); + const char *class; + + cif = lydx_get_xpathf(config, "/hardware/component[name='%s']", name); + class = lydx_get_cattr(cif, "class"); + if (!class || strcmp(class, "infix-hardware:wifi")) + continue; + + if (!components) { + components = wifi_oper_components(); + if (!components) + break; + } + + rc = wifi_radio_validate(session, config, diff, name, + lydx_get_child(cif, "wifi-radio"), components); + if (rc) + break; + } + json_decref(components); + + return rc; +} + /* * The country code is one setting for every radio. Apply the * regulatory domain here, not from hostapd, so a radio without an diff --git a/src/confd/yang/confd/infix-hardware.yang b/src/confd/yang/confd/infix-hardware.yang index 971300e3b8..c2cad48e8c 100644 --- a/src/confd/yang/confd/infix-hardware.yang +++ b/src/confd/yang/confd/infix-hardware.yang @@ -26,7 +26,10 @@ module infix-hardware { revision 2026-11-04 { description "Add cpu container with the cores and clock frequencies of the CPU. Restrict the VPD vendor-extension list to - administrators, it may hold the factory password hash."; + administrators, it may hold the factory password hash. + Add supported-modes to the Wi-Fi radio, and the channels of + each band. A Wi-Fi radio without a band takes no channel, + channel-width or legacy-rates."; reference "internal"; } @@ -806,11 +809,15 @@ module infix-hardware { } } default "auto"; + must ". = 'auto' or ../band" { + error-message "A channel requires the band to be set."; + } description "Operating channel number. Required for Access Point mode. Not used in Station mode (station uses AP's channel). + A specific channel requires the band to be set. Channel availability depends on: - Configured band (2.4/5/6 GHz) @@ -848,6 +855,9 @@ module infix-hardware { must "../band != '2.4GHz' or . = 'auto' or . = '20MHz' or . = '40MHz'" { error-message "80/160 MHz channel width requires 5 GHz or 6 GHz band."; } + must ". = 'auto' or ../band" { + error-message "A channel width requires the band to be set."; + } description "Channel bandwidth. @@ -861,6 +871,9 @@ module infix-hardware { leaf legacy-rates { type boolean; default false; + must ". = 'false' or ../band" { + error-message "Legacy rates require the band to be set."; + } description "Allow legacy 802.11b rates (1, 2, 5.5, 11 Mbps) on 2.4 GHz. @@ -964,6 +977,20 @@ module infix-hardware { "Wi-Fi driver name (e.g., mt798x-wmac, ath10k)."; } + leaf-list supported-modes { + config false; + type enumeration { + enum access-point; + enum station; + enum mesh-point; + } + description + "Interface modes this radio supports. + + An interface on the radio can only be configured for one of + these modes."; + } + container max-interfaces { config false; description @@ -1017,6 +1044,12 @@ module infix-hardware { description "High Efficiency (802.11ax/Wi-Fi 6) support."; } + + leaf-list channels { + type uint16; + description + "Channels of this band usable in the current regulatory domain."; + } } /* diff --git a/src/webui/internal/handlers/configure_hardware.go b/src/webui/internal/handlers/configure_hardware.go index 3cb5cd3ab0..0c24f6d293 100644 --- a/src/webui/internal/handlers/configure_hardware.go +++ b/src/webui/internal/handlers/configure_hardware.go @@ -59,6 +59,7 @@ type hwCompCfgRow struct { DescAdminState string DescBand string DescChannel string + RadioCaps string } // hwAvailable is a detected-but-unconfigured component shown in the Add @@ -82,6 +83,7 @@ type cfgHardwarePageData struct { CountryOptions []schema.IdentityOption DescCountry string BandOptions []schema.IdentityOption + RadioCaps string Desc map[string]string Error string } @@ -147,6 +149,7 @@ func (h *ConfigureHardwareHandler) Overview(w http.ResponseWriter, r *http.Reque } data.CountryCode = cfgWrap.wifiCountryCode() + data.RadioCaps = wifiRadioCaps(operWrap.Hardware.Component) configured := make(map[string]bool, len(cfgWrap.Hardware.Component)) for _, c := range cfgWrap.Hardware.Component { configured[c.Name] = true @@ -211,6 +214,7 @@ func (h *ConfigureHardwareHandler) buildRow(c hwComponentJSON, class string, dat row.BandOptions = data.BandOptions row.DescBand = data.Desc["band"] row.DescChannel = data.Desc["channel"] + row.RadioCaps = data.RadioCaps if c.WiFiRadio != nil { row.Band = c.WiFiRadio.Band row.Channel = wifiChannelString(c.WiFiRadio.Channel) @@ -321,6 +325,11 @@ func (h *ConfigureHardwareHandler) SaveWiFiCountry(w http.ResponseWriter, r *htt renderSaveError(w, err) return } + // The interfaces page shows the code in its radio forms too. + if r.FormValue("page") == "interfaces" { + renderSavedRedirect(w, "WiFi country code saved", "/configure/interfaces") + return + } renderSaved(w, "WiFi country code saved") } @@ -358,14 +367,14 @@ func parseWiFiRadio(r *http.Request) (map[string]any, error) { radio["band"] = band } if ch := strings.TrimSpace(r.FormValue("channel")); ch != "" { - // YANG union: uint16 (1..196) or the literal "auto". Coerce - // numeric input so the RESTCONF payload type-matches the union. + // YANG union: uint16 or the literal "auto". Coerce numeric + // input so the RESTCONF payload type-matches the union. if ch == "auto" { radio["channel"] = "auto" } else { n, err := strconv.Atoi(ch) - if err != nil || n < 1 || n > 196 { - return nil, fmt.Errorf("channel must be 'auto' or a number 1–196") + if err != nil { + return nil, fmt.Errorf("channel must be 'auto' or a number") } radio["channel"] = n } diff --git a/src/webui/internal/handlers/configure_interfaces.go b/src/webui/internal/handlers/configure_interfaces.go index a7d6062579..24b1f48a07 100644 --- a/src/webui/internal/handlers/configure_interfaces.go +++ b/src/webui/internal/handlers/configure_interfaces.go @@ -200,8 +200,12 @@ type cfgIfacePageData struct { WizardSymKeys []symKeyEntry // for WiFi PSK picker (Name + decoded cleartext) WizardWifiRadios []wifiRadioOption // configured (in candidate) WizardAvailableRadios []string // detected (operational) but not yet in candidate - WizardCountryOptions []schema.IdentityOption + WizardCountry string // box-wide country code in the candidate + WizardCountryApplied string // the one in effect, the channel lists follow it + WifiCountryOptions []schema.IdentityOption + HasWifiRadio bool // a radio is detected WizardBandOptions []schema.IdentityOption + WizardRadioCaps string // per-radio bands and channels, JSON STPProtoOptions []schema.IdentityOption LagModeOptions []schema.IdentityOption @@ -215,10 +219,9 @@ type cfgIfacePageData struct { WiFiSecOptionsAP []schema.IdentityOption WiFiSecOptionsSta []schema.IdentityOption WiFiQuerierOptions []schema.IdentityOption - // CountryOptions / BandOptions reused by the mirrored radio editor - // on WiFi interface rows (same enums as the wizard). - CountryOptions []schema.IdentityOption - BandOptions []schema.IdentityOption + // BandOptions reused by the mirrored radio editor on WiFi + // interface rows (same enum as the wizard). + BandOptions []schema.IdentityOption // PSKKeys is the keystore symmetric-keys list for the WiFi security // secret picker (mirrors WizardSymKeys without the cleartext). PSKKeys []symKeyEntry @@ -300,6 +303,7 @@ func (h *ConfigureInterfacesHandler) Overview(w http.ResponseWriter, r *http.Req "vxlan-remote": descOr(mgr, ifPath+"/infix-interfaces:vxlan/remote", "Remote unicast or multicast address for the VXLAN overlay."), "vxlan-vni": descOr(mgr, ifPath+"/infix-interfaces:vxlan/vni", "VXLAN Network Identifier (0–16777215). Pick a unique VNI per overlay segment."), "vxlan-port": descOr(mgr, ifPath+"/infix-interfaces:vxlan/remote-port", "Destination UDP port. IANA-assigned VXLAN port is 4789 (default)."), + "wifi-country": schema.DescriptionOf(mgr, hwWiFiCountryPath), "wg-key": descOr(mgr, ifPath+"/infix-interfaces:wireguard/private-key", "Reference to the WireGuard private key (X25519/Curve25519) stored in the keystore."), "wg-port": descOr(mgr, ifPath+"/infix-interfaces:wireguard/listen-port", "Local UDP port to listen on for incoming WireGuard traffic (default 51820)."), "wifi-radio": descOr(mgr, ifPath+"/infix-interfaces:wifi/radio", "Parent WiFi radio (hardware component, class=wifi). Configure the radio's band, channel, and country code in Configure › Hardware first."), @@ -364,19 +368,12 @@ func (h *ConfigureInterfacesHandler) Overview(w http.ResponseWriter, r *http.Req // by the inline "+ New radio" form in the WiFi fieldset and by // the WiFi interface row's mirrored radio editor. const radioSchemaPath = "/ietf-hardware:hardware/component/infix-hardware:wifi-radio" - data.WizardCountryOptions = schema.OptionsFor(mgr, hwWiFiCountryPath) data.WizardBandOptions = schema.OptionsFor(mgr, radioSchemaPath+"/band") - data.CountryOptions = data.WizardCountryOptions + data.WifiCountryOptions = schema.OptionsFor(mgr, hwWiFiCountryPath) data.BandOptions = data.WizardBandOptions - // Cross-module typedef enums (iwcc:country-code, wifi-band) - // don't always resolve through goyang's Entry tree, so the - // schema lookup can return empty. Fall back to a small set so - // the WiFi radio editor at least shows pickable values. - if len(data.CountryOptions) == 0 { - for _, cc := range []string{"00", "US", "GB", "DE", "SE", "FI", "JP", "AU"} { - data.CountryOptions = append(data.CountryOptions, schema.IdentityOption{Value: cc, Label: cc}) - } - } + // Cross-module typedef enums (wifi-band) don't always resolve + // through goyang's Entry tree, so the schema lookup can return + // empty. Fall back so the radio editor shows pickable values. if len(data.BandOptions) == 0 { data.BandOptions = []schema.IdentityOption{ {Value: "2.4GHz", Label: "2.4 GHz"}, @@ -516,12 +513,16 @@ func (h *ConfigureInterfacesHandler) Overview(w http.ResponseWriter, r *http.Req if shortClass(c.Class) != classWiFi { continue } + data.HasWifiRadio = true if configuredRadioNames[c.Name] { continue } data.WizardAvailableRadios = append(data.WizardAvailableRadios, c.Name) } sort.Strings(data.WizardAvailableRadios) + data.WizardRadioCaps = wifiRadioCaps(hw.Hardware.Component) + data.WizardCountry = hwCand.wifiCountryCode() + data.WizardCountryApplied = hw.wifiCountryCode() data.Interfaces = h.buildRows(ifaces, operWrap.Interfaces.Interface, profiles) // Copy page-level descriptions + DHCP option enums onto each row so the @@ -1093,7 +1094,6 @@ func (h *ConfigureInterfacesHandler) WizardCreateRadio(w http.ResponseWriter, r return } name := strings.TrimSpace(r.FormValue("radio-name")) - country := strings.TrimSpace(r.FormValue("country-code")) band := strings.TrimSpace(r.FormValue("band")) channel := strings.TrimSpace(r.FormValue("channel")) if name == "" { @@ -1111,8 +1111,8 @@ func (h *ConfigureInterfacesHandler) WizardCreateRadio(w http.ResponseWriter, r radio["channel"] = "auto" } else { n, err := strconv.Atoi(channel) - if err != nil || n < 1 || n > 196 { - renderSaveError(w, fmt.Errorf("channel must be 'auto' or a number 1–196")) + if err != nil { + renderSaveError(w, fmt.Errorf("channel must be 'auto' or a number")) return } radio["channel"] = n @@ -1122,16 +1122,6 @@ func (h *ConfigureInterfacesHandler) WizardCreateRadio(w http.ResponseWriter, r "class": "infix-hardware:wifi", "infix-hardware:wifi-radio": radio, } - // The country code is one setting for every radio; the form offers - // it here so a first radio can be set up in one go. - if country != "" { - cc := map[string]any{"infix-hardware:country-code": country} - if err := h.RC.Put(r.Context(), candidatePath+hwWiFiCountryPath, cc); err != nil { - log.Printf("wizard create radio %q: country: %v", name, err) - renderSaveError(w, err) - return - } - } body := map[string]any{"ietf-hardware:component": []map[string]any{comp}} path := candidatePath + "/ietf-hardware:hardware/component=" + url.PathEscape(name) if err := h.RC.Put(r.Context(), path, body); err != nil { @@ -1831,14 +1821,9 @@ func (h *ConfigureInterfacesHandler) SaveWifi(w http.ResponseWriter, r *http.Req // candidate untouched. p := restconf.NewYangPatch(candidatePath) // Hardware half: the radio's band and channel when the form carried - // them, and the box-wide country code when it was picked. A form - // whose user only touched the WiFi side leaves hardware alone. + // them. A form whose user only touched the WiFi side leaves + // hardware alone. hw := map[string]any{} - if strings.TrimSpace(r.FormValue("country-code")) != "" { - hw["infix-hardware:wifi"] = map[string]any{ - "country-code": strings.TrimSpace(r.FormValue("country-code")), - } - } if strings.TrimSpace(r.FormValue("band")) != "" || strings.TrimSpace(r.FormValue("channel")) != "" { rc, err := parseWiFiRadio(r) if err != nil { @@ -2172,7 +2157,7 @@ func (h *ConfigureInterfacesHandler) buildRows(ifaces []ifaceJSON, oper []ifaceJ row := cfgIfaceRow{ ifaceJSON: iface, TypeSlug: slug, - TypeDisplay: typeDisplay(slug), + TypeDisplay: slug, AdminEnabled: iface.Enabled == nil || *iface.Enabled, IsBridge: slug == "bridge", IsBridgePort: iface.BridgePort != nil, @@ -2623,32 +2608,6 @@ func typeSlug(yangType string) string { return s } -func typeDisplay(slug string) string { - switch slug { - case "bridge": - return "Bridge" - case "lag": - return "LAG" - case "ethernet": - return "Ethernet" - case "vlan": - return "VLAN" - case "loopback": - return "Loopback" - case "dummy": - return "Dummy" - case "wireguard": - return "WireGuard" - case "veth": - return "veth" - case "gre", "gretap": - return strings.ToUpper(slug) - case "vxlan": - return "VXLAN" - } - return slug -} - func typeOrder(slug string) int { switch slug { case "bridge": @@ -2765,7 +2724,7 @@ func buildIfaceTypeList(mgr *schema.Manager) []ifaceTypeOption { opts = append(opts, ifaceTypeOption{ Slug: name, Value: ifTypePrefix + name, - Label: typeDisplay(name), + Label: name, }) } sort.SliceStable(opts, func(i, j int) bool { diff --git a/src/webui/internal/handlers/wifi.go b/src/webui/internal/handlers/wifi.go index 3a2e497c4a..34e29d53b0 100644 --- a/src/webui/internal/handlers/wifi.go +++ b/src/webui/internal/handlers/wifi.go @@ -4,12 +4,14 @@ package handlers import ( "context" + "encoding/json" "errors" "fmt" "html/template" "log" "net/http" "net/url" + "strings" "sync" "time" @@ -39,6 +41,36 @@ type wifiBandJSON struct { HTCapable bool `json:"ht-capable"` VHTCapable bool `json:"vht-capable"` HECapable bool `json:"he-capable"` + Channels []int `json:"channels"` +} + +// wifiRadioCaps maps each detected radio to the channels of every band it +// supports, as JSON for the radio forms' data-wifi-caps attribute. The +// band keys match the configured band names. +func wifiRadioCaps(comps []hwComponentJSON) string { + caps := map[string]map[string][]int{} + for _, c := range comps { + if c.WiFiRadio == nil || len(c.WiFiRadio.Bands) == 0 { + continue + } + bands := map[string][]int{} + for _, b := range c.WiFiRadio.Bands { + if b.Name == "" { + continue + } + ch := b.Channels + if ch == nil { + ch = []int{} + } + bands[strings.ReplaceAll(b.Name, " ", "")] = ch + } + caps[c.Name] = bands + } + out, err := json.Marshal(caps) + if err != nil { + return "{}" + } + return string(out) } // hwComponentWiFiJSON is a minimal hardware component used for the wifi page. diff --git a/src/webui/internal/handlers/wifi_save_test.go b/src/webui/internal/handlers/wifi_save_test.go index 230bb5ac9c..84da83e1f7 100644 --- a/src/webui/internal/handlers/wifi_save_test.go +++ b/src/webui/internal/handlers/wifi_save_test.go @@ -28,7 +28,7 @@ func TestSaveWifiOnePatchForBothHalves(t *testing.T) { w, rc := postSaveWifi(t, url.Values{ "mode": {"access-point"}, "radio": {"radio0"}, "ssid": {"lab"}, "sec-mode": {"wpa2-wpa3-personal"}, "secret": {"psk"}, - "country-code": {"SE"}, "band": {"5GHz"}, "channel": {"36"}, + "band": {"5GHz"}, "channel": {"36"}, }) if w.Code != http.StatusOK { t.Fatalf("status %d: %s", w.Code, w.Body.String()) @@ -68,7 +68,7 @@ func TestSaveWifiWithoutRadioFieldsPatchesWifiOnly(t *testing.T) { func TestSaveWifiBadRadioWritesNothing(t *testing.T) { w, rc := postSaveWifi(t, url.Values{ "mode": {"access-point"}, "radio": {"radio0"}, "ssid": {"lab"}, - "country-code": {"SE"}, "channel": {"999"}, + "channel": {"abc"}, }) if w.Code != http.StatusUnprocessableEntity { t.Fatalf("status %d", w.Code) @@ -78,22 +78,3 @@ func TestSaveWifiBadRadioWritesNothing(t *testing.T) { } } -func TestSaveWifiCountryGoesToBoxWideLeaf(t *testing.T) { - w, rc := postSaveWifi(t, url.Values{ - "mode": {"access-point"}, "radio": {"radio0"}, "ssid": {"lab"}, - "sec-mode": {"wpa2-wpa3-personal"}, "secret": {"psk"}, - "country-code": {"SE"}, "band": {"5GHz"}, "channel": {"36"}, - }) - if w.Code != http.StatusOK { - t.Fatalf("status %d: %s", w.Code, w.Body.String()) - } - hw := rc.Patches[0].Edits[0].Value.(map[string]any)["ietf-hardware:hardware"].(map[string]any) - wifi, _ := hw["infix-hardware:wifi"].(map[string]any) - if wifi["country-code"] != "SE" { - t.Errorf("country not on the box-wide leaf: %v", hw) - } - comps := hw["component"].([]map[string]any) - if _, has := comps[0]["infix-hardware:wifi-radio"].(map[string]any)["country-code"]; has { - t.Errorf("country still on the radio: %v", comps[0]) - } -} diff --git a/src/webui/static/js/app.js b/src/webui/static/js/app.js index 21fcac64c3..6de96618a1 100644 --- a/src/webui/static/js/app.js +++ b/src/webui/static/js/app.js @@ -1309,7 +1309,57 @@ function setBlockEnabled(el, on) { form.querySelectorAll('input, textarea').forEach(function (i) { i.value = ''; }); form.querySelectorAll('select').forEach(function (s) { s.selectedIndex = 0; }); resetMaskedInputs(form); + syncWifiRadioForm(form); + } + // WiFi radio forms: offer only the bands the radio has, and only the + // channels of the selected band. data-wifi-caps on the form is + // {radio: {band: [channel, ...]}}; the radio is data-wifi-radio or the + // form's radio-name select. Without a band the channel stays 'auto'. + // want is the channel to select; keep adds it when the band lacks it. + function syncWifiRadioForm(form, want, keep) { + var bandSel = form.querySelector('select[name="band"]'); + var chanSel = form.querySelector('select[name="channel"]'); + if (!bandSel || !chanSel) return; + var caps = {}; + try { caps = JSON.parse(form.getAttribute('data-wifi-caps') || '{}'); } catch (e) {} + var nameSel = form.querySelector('select[name="radio-name"]'); + var radio = form.getAttribute('data-wifi-radio') || (nameSel ? nameSel.value : ''); + var bands = caps[radio]; + Array.prototype.forEach.call(bandSel.options, function (o) { + var off = !!(bands && o.value && !bands[o.value]); + if (off && o.selected && !keep) bandSel.value = ''; + off = off && !o.selected; + o.hidden = off; + o.disabled = off; + }); + if (want === undefined) want = chanSel.value; + var list = (bandSel.value && bands && bands[bandSel.value]) || []; + var values = ['auto'].concat(list.map(String)); + if (keep && bandSel.value && want && values.indexOf(String(want)) < 0) values.push(String(want)); + chanSel.textContent = ''; + values.forEach(function (v) { + var o = document.createElement('option'); + o.value = v; + o.textContent = v; + chanSel.appendChild(o); + }); + chanSel.value = values.indexOf(String(want)) < 0 ? 'auto' : String(want); + } + function syncWifiRadioForms(root) { + (root || document).querySelectorAll('[data-wifi-caps]').forEach(function (form) { + var chanSel = form.querySelector('select[name="channel"]'); + var want = chanSel ? (chanSel.getAttribute('data-value') || chanSel.value) : undefined; + syncWifiRadioForm(form, want, true); + }); } + document.addEventListener('change', function (e) { + var t = e.target; + if (!t || !t.closest || !t.matches('select[name="band"], select[name="radio-name"]')) return; + var form = t.closest('[data-wifi-caps]'); + if (form) syncWifiRadioForm(form); + }); + document.addEventListener('DOMContentLoaded', function () { syncWifiRadioForms(); }); + document.addEventListener('htmx:afterSwap', function (e) { syncWifiRadioForms(e.target); }); // Strip the `.cfg-secret-shown` (eye-toggled "show") class from any // masked inputs inside `root`. Called whenever a fold-out form // transitions (open / clear / prefill / after-save) so a previous @@ -1363,6 +1413,9 @@ function setBlockEnabled(el, on) { radioNameSel.selectedIndex = 0; } } + if (form.hasAttribute('data-wifi-caps')) { + syncWifiRadioForm(form, opt.getAttribute('data-channel') || 'auto', true); + } } document.addEventListener('click', function (e) { var addBtn = e.target.closest && e.target.closest('[data-add-form]'); diff --git a/src/webui/templates/pages/configure-hardware.html b/src/webui/templates/pages/configure-hardware.html index 71ccba7892..14f5b8edfb 100644 --- a/src/webui/templates/pages/configure-hardware.html +++ b/src/webui/templates/pages/configure-hardware.html @@ -23,7 +23,7 @@ {{if .CountryOptions}}
WiFi
-
+ @@ -32,10 +32,7 @@ {{range .CountryOptions}}{{end}} - +
Country code{{template "field-info" .DescCountry}} - - -
@@ -183,7 +180,8 @@ {{define "wifi-radio-form"}} {{$p := printf "/ietf-hardware:hardware/component=%s" .Name}} {{$rp := printf "%s/infix-hardware:wifi-radio" $p}} -
+ @@ -204,9 +202,10 @@
Band{{template "field-info" .DescBand}}
Channel{{template "field-info" .DescChannel}} - + - -