From f79e4c71775806b84f5fac20a2c241284f8f950a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 11:11:43 +0100 Subject: [PATCH 01/11] yangerd: report all supported channels of a radio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A split wiphy dump carries one frequency per message and each one replaced the band's list, so only the last frequency of a band was kept. 2484 MHz is channel 14, and 5 GHz reaches channel 177. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 2 ++ src/yangerd/internal/collector/hardware.go | 6 ++-- src/yangerd/internal/nl80211/bands_test.go | 35 +++++++++++++++++++++- src/yangerd/internal/nl80211/nl80211.go | 4 +-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 68f3870176..5f5f3a2bf3 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -108,6 +108,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/src/yangerd/internal/collector/hardware.go b/src/yangerd/internal/collector/hardware.go index 87747a92d2..45273ab51d 100644 --- a/src/yangerd/internal/collector/hardware.go +++ b/src/yangerd/internal/collector/hardware.go @@ -999,9 +999,11 @@ func convertPhyInfo(phyInfo map[string]interface{}) map[string]interface{} { func channelFromFrequency(freq int) (int, bool) { switch { - case freq >= 2412 && freq <= 2484: + case freq == 2484: + return 14, true + case freq >= 2412 && freq <= 2472: return (freq - 2407) / 5, true - case freq >= 5170 && freq <= 5825: + case freq >= 5160 && freq <= 5885: return (freq - 5000) / 5, true case freq >= 5955 && freq <= 7115: return (freq - 5950) / 5, true diff --git a/src/yangerd/internal/nl80211/bands_test.go b/src/yangerd/internal/nl80211/bands_test.go index 35a64779bc..de3e21ca18 100644 --- a/src/yangerd/internal/nl80211/bands_test.go +++ b/src/yangerd/internal/nl80211/bands_test.go @@ -1,6 +1,11 @@ package nl80211 -import "testing" +import ( + "testing" + + "github.com/mdlayher/netlink" + "golang.org/x/sys/unix" +) // Only 2.4, 5 and 6 GHz are reported; hwsim's S1G and 60 GHz bands are // dropped rather than listed as "Unknown". @@ -33,3 +38,31 @@ func TestManufacturerFor(t *testing.T) { } } } + +// A split wiphy dump carries one frequency per message. +func TestMergeBandsAcrossMessages(t *testing.T) { + bands := map[uint16]*bandInfo{} + + for _, freq := range []uint32{2412, 2417, 2422} { + ae := netlink.NewAttributeEncoder() + ae.Nested(0, func(band *netlink.AttributeEncoder) error { + band.Nested(unix.NL80211_BAND_ATTR_FREQS, func(freqs *netlink.AttributeEncoder) error { + freqs.Nested(0, func(entry *netlink.AttributeEncoder) error { + entry.Uint32(unix.NL80211_FREQUENCY_ATTR_FREQ, freq) + return nil + }) + return nil + }) + return nil + }) + data, err := ae.Encode() + if err != nil { + t.Fatal(err) + } + mergeBands(bands, data) + } + + if got := len(bands[0].frequencies); got != 3 { + t.Fatalf("frequencies = %v, want 3 entries", bands[0].frequencies) + } +} diff --git a/src/yangerd/internal/nl80211/nl80211.go b/src/yangerd/internal/nl80211/nl80211.go index cec04842ee..aa7d8740ad 100644 --- a/src/yangerd/internal/nl80211/nl80211.go +++ b/src/yangerd/internal/nl80211/nl80211.go @@ -289,9 +289,7 @@ func mergeBandAttrs(bi *bandInfo, data []byte) { for nad.Next() { switch nad.Type() { case unix.NL80211_BAND_ATTR_FREQS: - if freqs := parseBandFrequencies(nad.Bytes()); len(freqs) > 0 { - bi.frequencies = freqs - } + bi.frequencies = append(bi.frequencies, parseBandFrequencies(nad.Bytes())...) case unix.NL80211_BAND_ATTR_HT_CAPA: if nad.Uint16() != 0 { bi.htCapable = true From ef8b37b7f1b5f8be23a67354f0f5d925fa552fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 11:11:43 +0100 Subject: [PATCH 02/11] confd: refuse Wi-Fi radio settings the hardware cannot do MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hostapd fails to start on a band, channel or width the radio lacks and the operator only sees an access point that never comes up. Ask yangerd once per change, and skip the check when it does not answer, as at boot. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 3 + doc/wifi.md | 5 ++ src/confd/src/hardware.c | 6 ++ src/confd/src/hardware.h | 1 + src/confd/src/hw-wifi.c | 185 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 5f5f3a2bf3..6d612fa10f 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -31,6 +31,9 @@ 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 or number of access points the + radio does not support is now refused with an error when configured, + see [Wi-Fi][wifi] - 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 diff --git a/doc/wifi.md b/doc/wifi.md index 49f8ba5af5..4d4c9e2a21 100644 --- a/doc/wifi.md +++ b/doc/wifi.md @@ -187,6 +187,11 @@ 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. The error names the radio 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/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..9054c8ebf7 100644 --- a/src/confd/src/hw-wifi.c +++ b/src/confd/src/hw-wifi.c @@ -598,6 +598,191 @@ 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, int ch) +{ + json_t *list = json_object_get(oper, "supported-channels"); + json_t *entry; + size_t i; + + if (!json_array_size(list)) + return true; + + json_array_foreach(list, i, entry) { + if (json_integer_value(entry) == ch) + return true; + } + + return false; +} + +/* 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; + json_t *oband = NULL, *max; + int ch = 0, aps; + + if (!oper || !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, 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(lydx_get_descendant(config, "interfaces", "interface", NULL), 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 From 1b3b975464d70398a0d96802d631ad3efbc48a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 11:11:43 +0100 Subject: [PATCH 03/11] test: verify unsupported Wi-Fi channels are refused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Walström --- test/case/interfaces/wifi.yaml | 3 + .../wifi_radio_validation/Readme.adoc | 1 + .../wifi_radio_validation/test.adoc | 31 +++++++++ .../interfaces/wifi_radio_validation/test.py | 68 +++++++++++++++++++ .../wifi_radio_validation/topology.dot | 30 ++++++++ .../wifi_radio_validation/topology.svg | 47 +++++++++++++ 6 files changed, 180 insertions(+) create mode 120000 test/case/interfaces/wifi_radio_validation/Readme.adoc create mode 100644 test/case/interfaces/wifi_radio_validation/test.adoc create mode 100755 test/case/interfaces/wifi_radio_validation/test.py create mode 100644 test/case/interfaces/wifi_radio_validation/topology.dot create mode 100644 test/case/interfaces/wifi_radio_validation/topology.svg diff --git a/test/case/interfaces/wifi.yaml b/test/case/interfaces/wifi.yaml index 7586609bf8..015635e8bd 100644 --- a/test/case/interfaces/wifi.yaml +++ b/test/case/interfaces/wifi.yaml @@ -19,3 +19,6 @@ - name: WiFi channel survey on a connected radio case: wifi_channel_survey/test.py + +- name: WiFi radio settings the hardware cannot do are refused + case: wifi_radio_validation/test.py diff --git a/test/case/interfaces/wifi_radio_validation/Readme.adoc b/test/case/interfaces/wifi_radio_validation/Readme.adoc new file mode 120000 index 0000000000..ae32c84120 --- /dev/null +++ b/test/case/interfaces/wifi_radio_validation/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/interfaces/wifi_radio_validation/test.adoc b/test/case/interfaces/wifi_radio_validation/test.adoc new file mode 100644 index 0000000000..a9d34ffb34 --- /dev/null +++ b/test/case/interfaces/wifi_radio_validation/test.adoc @@ -0,0 +1,31 @@ +=== WiFi radio settings the hardware cannot do are refused + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/interfaces/wifi_radio_validation] + +==== Description + +A radio reports the channels it supports. A channel outside the +configured band and a channel the country code does not allow must be +refused when configured, with an error that names the radio and the +setting. A setting the radio does support must still be accepted +afterwards. + +Topology: +.... + host ==(mgmt)== target ))) ~ cell ~ +.... + +==== Topology + +image::topology.svg[WiFi radio settings the hardware cannot do are refused topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to target DUT +. Configure radio0 for 2.4GHz channel 1 with country code SE +. Verify radio0 supports channel 13 but not channel 14 +. Reject channel 36 in band 2.4GHz on radio0 +. Reject channel 14 in band 2.4GHz on radio0 +. Configure radio0 for 2.4GHz channel 13 + + diff --git a/test/case/interfaces/wifi_radio_validation/test.py b/test/case/interfaces/wifi_radio_validation/test.py new file mode 100755 index 0000000000..9320d973c7 --- /dev/null +++ b/test/case/interfaces/wifi_radio_validation/test.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +r""" +WiFi radio settings the hardware cannot do are refused + +A radio reports the channels it supports. A channel outside the +configured band and a channel the country code does not allow must be +refused when configured, with an error that names the radio and the +setting. A setting the radio does support must still be accepted +afterwards. + +Topology: +.... + host ==(mgmt)== target ))) ~ cell ~ +.... +""" +import infamy +import infamy.wifi as wifi +from infamy.util import until + + +def must_reject(target, radio, reason): + """The commit must fail, and the error must name the reason""" + try: + target.put_config_dicts({"ietf-hardware": wifi.hardware(radio)}) + except Exception as err: + text = getattr(getattr(err, "response", None), "text", None) or str(err) + assert reason in text, f"rejected for another reason:\n{text}" + print(f"Rejected as expected: {reason}") + return + raise AssertionError("configuration was accepted") + + +def supported_channels(target): + data = target.get_data("/ietf-hardware:hardware/component[name='radio0']") + radio = data["hardware"]["component"]["radio0"] + radio = radio.get("infix-hardware:wifi-radio") or radio.get("wifi-radio") or {} + return radio.get("supported-channels", []) + + +with infamy.Test() as test: + with test.step("Set up topology and attach to target DUT"): + env = infamy.Env() + target = env.attach("target", "mgmt") + wifi.skip_unless_supported(test, target) + + with test.step("Configure radio0 for 2.4GHz channel 1 with country code SE"): + target.put_config_dicts({ + "ietf-hardware": wifi.hardware(wifi.radio("radio0", band="2.4GHz", channel=1)), + }) + + with test.step("Verify radio0 supports channel 13 but not channel 14"): + until(lambda: 13 in supported_channels(target) and + 14 not in supported_channels(target), attempts=30) + + with test.step("Reject channel 36 in band 2.4GHz on radio0"): + must_reject(target, wifi.radio("radio0", band="2.4GHz", channel=36), + "radio0: channel 36 is not a 2.4GHz channel") + + with test.step("Reject channel 14 in band 2.4GHz on radio0"): + must_reject(target, wifi.radio("radio0", band="2.4GHz", channel=14), + "radio0: channel 14 is not available on this radio") + + with test.step("Configure radio0 for 2.4GHz channel 13"): + target.put_config_dicts({ + "ietf-hardware": wifi.hardware(wifi.radio("radio0", band="2.4GHz", channel=13)), + }) + + test.succeed() diff --git a/test/case/interfaces/wifi_radio_validation/topology.dot b/test/case/interfaces/wifi_radio_validation/topology.dot new file mode 100644 index 0000000000..2b9f1fe40c --- /dev/null +++ b/test/case/interfaces/wifi_radio_validation/topology.dot @@ -0,0 +1,30 @@ +graph "wifi-radio-validation" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt }", + pos="0,0!", + requires="controller", + ]; + + target [ + label="{ mgmt | wifi } | target", + pos="6,0!", + requires="infix", + ]; + + cell [ + label="cell", + pos="9,0!", + requires="wifi-radio", + ]; + + host:mgmt -- target:mgmt [requires="mgmt", color="lightgray"] + + target:wifi -- cell [requires="wifi2.4GHz", style="dashed"] +} diff --git a/test/case/interfaces/wifi_radio_validation/topology.svg b/test/case/interfaces/wifi_radio_validation/topology.svg new file mode 100644 index 0000000000..6e9c18d2f5 --- /dev/null +++ b/test/case/interfaces/wifi_radio_validation/topology.svg @@ -0,0 +1,47 @@ + + + + + + +wifi-radio-validation + + + +host + +host + +mgmt + + + +target + +mgmt + +wifi + +target + + + +host:mgmt--target:mgmt + + + + +cell + +cell + + + +target:wifi--cell + + + + From 72a3ce2be1de589922ebb7b3ffa8e5d0b592ec3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 11:30:43 +0100 Subject: [PATCH 04/11] yangerd: report the interface modes a radio supports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Needed to tell whether a radio can carry a mesh point before an interface is created on it. Signed-off-by: Mattias Walström --- src/confd/yang/confd/infix-hardware.yang | 17 +++++++++++++- src/yangerd/internal/collector/hardware.go | 23 +++++++++++++++++++ .../internal/collector/hardware_test.go | 14 +++++++++++ src/yangerd/internal/nl80211/nl80211.go | 4 ++++ .../wifi_radio_validation/test.adoc | 1 + .../interfaces/wifi_radio_validation/test.py | 13 ++++++++--- 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/confd/yang/confd/infix-hardware.yang b/src/confd/yang/confd/infix-hardware.yang index 971300e3b8..54f7ecd2f9 100644 --- a/src/confd/yang/confd/infix-hardware.yang +++ b/src/confd/yang/confd/infix-hardware.yang @@ -26,7 +26,8 @@ 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."; reference "internal"; } @@ -964,6 +965,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 diff --git a/src/yangerd/internal/collector/hardware.go b/src/yangerd/internal/collector/hardware.go index 45273ab51d..5419955044 100644 --- a/src/yangerd/internal/collector/hardware.go +++ b/src/yangerd/internal/collector/hardware.go @@ -1012,6 +1012,25 @@ func channelFromFrequency(freq int) (int, bool) { } } +// supportedModes maps the nl80211 interface types of a radio to the +// modes an interface can be configured for. +func supportedModes(iftypes interface{}) []interface{} { + names := map[string]string{ + "AP": "access-point", + "mesh_point": "mesh-point", + "station": "station", + } + modes := make([]interface{}, 0, len(names)) + + raw, _ := iftypes.([]interface{}) + for _, t := range raw { + if s, ok := t.(string); ok && names[s] != "" { + modes = append(modes, names[s]) + } + } + return modes +} + // radioCapabilities lists the radios and the PHY info they were built // from so the sensors can be matched to them. func (c *HardwareCollector) radioCapabilities(ctx context.Context) ([]interface{}, map[string]map[string]interface{}) { @@ -1050,6 +1069,10 @@ func (c *HardwareCollector) radioCapabilities(ctx context.Context) ([]interface{ wifiRadioData["max-interfaces"] = maxIf } + if modes := supportedModes(iwInfo["supported_iftypes"]); len(modes) > 0 { + wifiRadioData["supported-modes"] = modes + } + setIfPresent(wifiRadioData, "max-txpower", iwInfo, "max_txpower") supportedChannelsMap := make(map[int]bool) diff --git a/src/yangerd/internal/collector/hardware_test.go b/src/yangerd/internal/collector/hardware_test.go index 27445e5b5a..f7a9dd6acf 100644 --- a/src/yangerd/internal/collector/hardware_test.go +++ b/src/yangerd/internal/collector/hardware_test.go @@ -917,3 +917,17 @@ func TestHardwareRadioDriverSensor(t *testing.T) { t.Fatalf("iwlwifi sensor not adopted by radio0: %v", got) } } + +func TestSupportedModes(t *testing.T) { + got := supportedModes([]interface{}{"AP", "AP_VLAN", "mesh_point", "monitor", "station"}) + want := []interface{}{"access-point", "mesh-point", "station"} + + if len(got) != len(want) { + t.Fatalf("supportedModes = %v, want %v", got, want) + } + for i := range want { + if got[i] != want[i] { + t.Fatalf("supportedModes = %v, want %v", got, want) + } + } +} diff --git a/src/yangerd/internal/nl80211/nl80211.go b/src/yangerd/internal/nl80211/nl80211.go index aa7d8740ad..cd699de526 100644 --- a/src/yangerd/internal/nl80211/nl80211.go +++ b/src/yangerd/internal/nl80211/nl80211.go @@ -172,6 +172,10 @@ func (c *Client) PhyInfo(phyName string) (map[string]interface{}, error) { if combs := parseInterfaceCombinations(ad.Bytes()); len(combs) > 0 { info["interface_combinations"] = combs } + case unix.NL80211_ATTR_SUPPORTED_IFTYPES: + if types := parseIfaceLimitTypes(ad.Bytes()); len(types) > 0 { + info["supported_iftypes"] = types + } case unix.NL80211_ATTR_WIPHY_TX_POWER_LEVEL: info["max_txpower"] = int(ad.Uint32() / 100) } diff --git a/test/case/interfaces/wifi_radio_validation/test.adoc b/test/case/interfaces/wifi_radio_validation/test.adoc index a9d34ffb34..f3fa08d895 100644 --- a/test/case/interfaces/wifi_radio_validation/test.adoc +++ b/test/case/interfaces/wifi_radio_validation/test.adoc @@ -24,6 +24,7 @@ image::topology.svg[WiFi radio settings the hardware cannot do are refused topol . Set up topology and attach to target DUT . Configure radio0 for 2.4GHz channel 1 with country code SE . Verify radio0 supports channel 13 but not channel 14 +. Verify radio0 supports access-point, station and mesh-point modes . Reject channel 36 in band 2.4GHz on radio0 . Reject channel 14 in band 2.4GHz on radio0 . Configure radio0 for 2.4GHz channel 13 diff --git a/test/case/interfaces/wifi_radio_validation/test.py b/test/case/interfaces/wifi_radio_validation/test.py index 9320d973c7..09d8277fcf 100755 --- a/test/case/interfaces/wifi_radio_validation/test.py +++ b/test/case/interfaces/wifi_radio_validation/test.py @@ -30,11 +30,14 @@ def must_reject(target, radio, reason): raise AssertionError("configuration was accepted") -def supported_channels(target): +def radio_oper(target): data = target.get_data("/ietf-hardware:hardware/component[name='radio0']") radio = data["hardware"]["component"]["radio0"] - radio = radio.get("infix-hardware:wifi-radio") or radio.get("wifi-radio") or {} - return radio.get("supported-channels", []) + return radio.get("infix-hardware:wifi-radio") or radio.get("wifi-radio") or {} + + +def supported_channels(target): + return radio_oper(target).get("supported-channels", []) with infamy.Test() as test: @@ -52,6 +55,10 @@ def supported_channels(target): until(lambda: 13 in supported_channels(target) and 14 not in supported_channels(target), attempts=30) + with test.step("Verify radio0 supports access-point, station and mesh-point modes"): + modes = radio_oper(target).get("supported-modes", []) + assert {"access-point", "station", "mesh-point"} <= set(modes), modes + with test.step("Reject channel 36 in band 2.4GHz on radio0"): must_reject(target, wifi.radio("radio0", band="2.4GHz", channel=36), "radio0: channel 36 is not a 2.4GHz channel") From 03a25feecb7a40ae24c3ea7ec2eb80c12979a17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 11:30:43 +0100 Subject: [PATCH 05/11] confd: refuse a Wi-Fi interface mode the radio lacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A mesh point on a radio without 802.11s support was accepted and the interface never came up. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 7 ++--- doc/wifi.md | 4 ++- src/confd/src/hw-wifi.c | 60 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 6d612fa10f..6b1a6159b9 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -31,9 +31,10 @@ 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 or number of access points the - radio does not support is now refused with an error when configured, - 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 - 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 diff --git a/doc/wifi.md b/doc/wifi.md index 4d4c9e2a21..30ff0c3932 100644 --- a/doc/wifi.md +++ b/doc/wifi.md @@ -189,7 +189,9 @@ 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. The error names the radio and the setting. +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** diff --git a/src/confd/src/hw-wifi.c b/src/confd/src/hw-wifi.c index 9054c8ebf7..1aae2601ff 100644 --- a/src/confd/src/hw-wifi.c +++ b/src/confd/src/hw-wifi.c @@ -687,16 +687,72 @@ static bool wifi_channel_supported(json_t *oper, int ch) 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 || !radio) + 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"); @@ -740,7 +796,7 @@ static int wifi_radio_validate(sr_session_ctx_t *session, struct lyd_node *confi } max = json_object_get(json_object_get(oper, "max-interfaces"), "ap"); - aps = wifi_radio_ap_count(lydx_get_descendant(config, "interfaces", "interface", NULL), name); + 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)); From 112b38820261e865ecbeaaedd12d53335b71e8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 14:36:54 +0100 Subject: [PATCH 06/11] qemu: virtual Wi-Fi radios for DDI images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The run script for DDI images never passed opt/wifi to the guest, so make run on x86 lost the option to start with mac80211_hwsim radios. Signed-off-by: Mattias Walström --- board/common/qemu/ddi/Config.in.in | 15 +++++++++++++++ board/common/qemu/ddi/run.sh | 10 ++++++++++ 2 files changed, 25 insertions(+) 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 From da4e2a514c82f3841b2c769e663c0a9c7f8fc814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 15:29:27 +0100 Subject: [PATCH 07/11] yangerd: report the channels of each band MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flat channel list cannot tell 2.4 GHz channel 1 from 6 GHz channel 1. A band the country code disables every channel of was dropped, so 6 GHz looked unsupported in the world domain. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 2 +- src/confd/yang/confd/infix-hardware.yang | 9 ++++- src/yangerd/internal/collector/hardware.go | 22 ++++++++++++ .../internal/collector/hardware_test.go | 6 +++- src/yangerd/internal/nl80211/bands_test.go | 6 ++-- src/yangerd/internal/nl80211/nl80211.go | 35 ++++++++++--------- 6 files changed, 58 insertions(+), 22 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 6b1a6159b9..37d646804e 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -34,7 +34,7 @@ All notable changes to the project are documented in this file. - 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 + in its operational data, as are the channels of each band - 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 diff --git a/src/confd/yang/confd/infix-hardware.yang b/src/confd/yang/confd/infix-hardware.yang index 54f7ecd2f9..9cc07b819f 100644 --- a/src/confd/yang/confd/infix-hardware.yang +++ b/src/confd/yang/confd/infix-hardware.yang @@ -27,7 +27,8 @@ module infix-hardware { 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. - Add supported-modes to the Wi-Fi radio."; + Add supported-modes to the Wi-Fi radio, and the channels of + each band."; reference "internal"; } @@ -1032,6 +1033,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/yangerd/internal/collector/hardware.go b/src/yangerd/internal/collector/hardware.go index 5419955044..7ba56510e2 100644 --- a/src/yangerd/internal/collector/hardware.go +++ b/src/yangerd/internal/collector/hardware.go @@ -951,6 +951,9 @@ func convertPhyInfo(phyInfo map[string]interface{}) map[string]interface{} { if v, ok := band["he_capable"].(bool); ok && v { bandData["he-capable"] = true } + if channels := bandChannels(band); len(channels) > 0 { + bandData["channels"] = channels + } bands = append(bands, bandData) } result["bands"] = bands @@ -997,6 +1000,25 @@ func convertPhyInfo(phyInfo map[string]interface{}) map[string]interface{} { return result } +func bandChannels(band map[string]interface{}) []interface{} { + freqsRaw, _ := band["frequencies"].([]interface{}) + seen := make(map[int]bool, len(freqsRaw)) + channels := make([]int, 0, len(freqsRaw)) + for _, freqRaw := range freqsRaw { + if ch, ok := channelFromFrequency(toInt(freqRaw)); ok && !seen[ch] { + seen[ch] = true + channels = append(channels, ch) + } + } + sort.Ints(channels) + + out := make([]interface{}, 0, len(channels)) + for _, ch := range channels { + out = append(out, ch) + } + return out +} + func channelFromFrequency(freq int) (int, bool) { switch { case freq == 2484: diff --git a/src/yangerd/internal/collector/hardware_test.go b/src/yangerd/internal/collector/hardware_test.go index f7a9dd6acf..ccc3b43448 100644 --- a/src/yangerd/internal/collector/hardware_test.go +++ b/src/yangerd/internal/collector/hardware_test.go @@ -555,11 +555,15 @@ func TestHardwareUniqueNames(t *testing.T) { func TestHardwareBandNameOptional(t *testing.T) { out := convertPhyInfo(map[string]interface{}{ "bands": []interface{}{ - map[string]interface{}{"band": 1, "name": "2.4 GHz"}, + map[string]interface{}{"band": 1, "name": "2.4 GHz", + "frequencies": []interface{}{2437, 2412, 2484}}, map[string]interface{}{"band": 2}, }, }) bands := out["bands"].([]interface{}) + if got := fmt.Sprint(bands[0].(map[string]interface{})["channels"]); got != "[1 6 14]" { + t.Fatalf("channels = %s, want [1 6 14]", got) + } if bands[0].(map[string]interface{})["name"] != "2.4 GHz" { t.Fatalf("known band name lost: %v", bands[0]) } diff --git a/src/yangerd/internal/nl80211/bands_test.go b/src/yangerd/internal/nl80211/bands_test.go index de3e21ca18..0be9175fb7 100644 --- a/src/yangerd/internal/nl80211/bands_test.go +++ b/src/yangerd/internal/nl80211/bands_test.go @@ -1,6 +1,7 @@ package nl80211 import ( + "strings" "testing" "github.com/mdlayher/netlink" @@ -15,14 +16,15 @@ func TestFinalizeBandsDropsUnsupported(t *testing.T) { 1: {frequencies: []interface{}{5180, 5200}, vhtCapable: true}, 2: {frequencies: []interface{}{58320, 60480}}, 4: {frequencies: []interface{}{902, 904}}, + 3: {disabled: []interface{}{5955, 5975}, heCapable: true}, } var names []string for _, raw := range finalizeBands(bands) { names = append(names, raw.(map[string]interface{})["name"].(string)) } - if len(names) != 2 || names[0] != "2.4 GHz" || names[1] != "5 GHz" { - t.Fatalf("bands = %v, want [2.4 GHz 5 GHz]", names) + if got := strings.Join(names, ","); got != "2.4 GHz,5 GHz,6 GHz" { + t.Fatalf("bands = %v, want 2.4, 5 and the disabled 6 GHz", names) } } diff --git a/src/yangerd/internal/nl80211/nl80211.go b/src/yangerd/internal/nl80211/nl80211.go index cd699de526..a9d625b82a 100644 --- a/src/yangerd/internal/nl80211/nl80211.go +++ b/src/yangerd/internal/nl80211/nl80211.go @@ -263,7 +263,8 @@ func parseWiphyIdent(data []byte) (int, string) { } type bandInfo struct { - frequencies []interface{} + frequencies []interface{} // usable in the regulatory domain + disabled []interface{} htCapable bool vhtCapable bool heCapable bool @@ -293,7 +294,9 @@ func mergeBandAttrs(bi *bandInfo, data []byte) { for nad.Next() { switch nad.Type() { case unix.NL80211_BAND_ATTR_FREQS: - bi.frequencies = append(bi.frequencies, parseBandFrequencies(nad.Bytes())...) + enabled, disabled := parseBandFrequencies(nad.Bytes()) + bi.frequencies = append(bi.frequencies, enabled...) + bi.disabled = append(bi.disabled, disabled...) case unix.NL80211_BAND_ATTR_HT_CAPA: if nad.Uint16() != 0 { bi.htCapable = true @@ -320,13 +323,13 @@ func finalizeBands(m map[uint16]*bandInfo) []interface{} { out := make([]interface{}, 0, len(keys)) for _, k := range keys { bi := m[uint16(k)] - if len(bi.frequencies) == 0 && !bi.htCapable && !bi.vhtCapable && !bi.heCapable { + if len(bi.frequencies) == 0 && len(bi.disabled) == 0 && !bi.htCapable && !bi.vhtCapable && !bi.heCapable { continue } // Infix supports 2.4, 5 and 6 GHz only. Hardware may expose // others, like S1G and 60 GHz on hwsim, that are neither // configured nor reported. - name := detectBandName(bi.frequencies) + name := detectBandName(append(append([]interface{}{}, bi.frequencies...), bi.disabled...)) if name == "Unknown" { continue } @@ -342,22 +345,24 @@ func finalizeBands(m map[uint16]*bandInfo) []interface{} { return out } -func parseBandFrequencies(data []byte) []interface{} { - out := make([]interface{}, 0) - +func parseBandFrequencies(data []byte) (enabled, disabled []interface{}) { ad, err := netlink.NewAttributeDecoder(data) if err != nil { - return out + return nil, nil } for ad.Next() { - freq, ok := parseFrequencyEntry(ad.Bytes()) - if ok { - out = append(out, freq) + freq, off := parseFrequencyEntry(ad.Bytes()) + switch { + case freq == 0: + case off: + disabled = append(disabled, freq) + default: + enabled = append(enabled, freq) } } - return out + return enabled, disabled } func parseFrequencyEntry(data []byte) (int, bool) { @@ -378,11 +383,7 @@ func parseFrequencyEntry(data []byte) (int, bool) { } } - if disabled || freq == 0 { - return 0, false - } - - return freq, true + return freq, disabled } func detectBandName(freqs []interface{}) string { From 433341b5b73b3eccdcaf79ce08ee3c7d0e574d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 15:29:27 +0100 Subject: [PATCH 08/11] confd: check a Wi-Fi channel against its own band MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flat list accepted a channel number on 6 GHz that the radio only has on 2.4 GHz. Signed-off-by: Mattias Walström --- src/confd/src/hw-wifi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/confd/src/hw-wifi.c b/src/confd/src/hw-wifi.c index 1aae2601ff..440c5252b5 100644 --- a/src/confd/src/hw-wifi.c +++ b/src/confd/src/hw-wifi.c @@ -670,13 +670,15 @@ static bool wifi_channel_in_band(const char *band, int ch) return ch >= 1 && ch <= 233; } -static bool wifi_channel_supported(json_t *oper, int ch) +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 (!json_array_size(list)) + if (oband) + list = json_object_get(oband, "channels"); + else if (!json_array_size(list)) return true; json_array_foreach(list, i, entry) { @@ -777,7 +779,7 @@ static int wifi_radio_validate(sr_session_ctx_t *session, struct lyd_node *confi /* 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, ch)) { + !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; From 5db227c8a3e5141935256387fbe1bf9e8b2f4a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 15:29:27 +0100 Subject: [PATCH 09/11] yang: a Wi-Fi radio without a band takes no channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only a station radio goes without a band, and it follows its access point, so a channel, width or legacy rates did nothing there. Signed-off-by: Mattias Walström --- .../acer,connect-vero-w/etc/factory-config.cfg | 2 +- .../etc/factory-config.cfg | 2 +- .../bananapi,bpi-r3/etc/factory-config.cfg | 2 +- .../bananapi,bpi-r3mini/etc/factory-config.cfg | 2 +- .../bananapi,bpi-r4-2g5/etc/factory-config.cfg | 2 +- .../bananapi,bpi-r4/etc/factory-config.cfg | 2 +- .../bananapi,bpi-r64/etc/factory-config.cfg | 2 +- .../etc/factory-config.cfg | 2 +- .../friendlyarm,nanopi-r2s/etc/factory-config.cfg | 2 +- .../raspberrypi,4-model-b/etc/factory-config.cfg | 2 +- .../raspberrypi,400/etc/factory-config.cfg | 2 +- .../lemaker,bananapi/etc/factory-config.cfg | 2 +- .../raspberrypi,2-model-b/etc/factory-config.cfg | 2 +- .../bananapi,bpi-f3/etc/factory-config.cfg | 2 +- doc/ChangeLog.md | 3 +++ doc/wifi.md | 4 +++- src/confd/configure.ac | 3 ++- .../share/migrate/1.13/10-wifi-radio-band.sh | 15 +++++++++++++++ src/confd/share/migrate/1.13/Makefile.am | 2 ++ src/confd/share/migrate/Makefile.am | 2 +- src/confd/yang/confd/infix-hardware.yang | 13 ++++++++++++- 21 files changed, 52 insertions(+), 18 deletions(-) create mode 100755 src/confd/share/migrate/1.13/10-wifi-radio-band.sh create mode 100644 src/confd/share/migrate/1.13/Makefile.am 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/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 37d646804e..02c2a355ab 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -35,6 +35,9 @@ All notable changes to the project are documented in this file. 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 - 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 diff --git a/doc/wifi.md b/doc/wifi.md index 30ff0c3932..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 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/yang/confd/infix-hardware.yang b/src/confd/yang/confd/infix-hardware.yang index 9cc07b819f..c2cad48e8c 100644 --- a/src/confd/yang/confd/infix-hardware.yang +++ b/src/confd/yang/confd/infix-hardware.yang @@ -28,7 +28,8 @@ module infix-hardware { the CPU. Restrict the VPD vendor-extension list to administrators, it may hold the factory password hash. Add supported-modes to the Wi-Fi radio, and the channels of - each band."; + each band. A Wi-Fi radio without a band takes no channel, + channel-width or legacy-rates."; reference "internal"; } @@ -808,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) @@ -850,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. @@ -863,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. From 0a22b4a14f0f2506de34d22ecb633324cd8b5a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 20 Nov 2026 15:29:27 +0100 Subject: [PATCH 10/11] webui: offer only the bands and channels a Wi-Fi radio supports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A free-text channel and every band of the model let the operator pick what confd then refuses. The lists follow the applied country code, so it becomes one setting on the interfaces page, saved on change, and the forms say when it is not applied yet. Signed-off-by: Mattias Walström --- doc/ChangeLog.md | 3 + .../internal/handlers/configure_hardware.go | 17 ++++-- .../internal/handlers/configure_interfaces.go | 57 +++++++----------- src/webui/internal/handlers/wifi.go | 32 ++++++++++ src/webui/internal/handlers/wifi_save_test.go | 23 +------- src/webui/static/js/app.js | 53 +++++++++++++++++ .../templates/pages/configure-hardware.html | 17 +++--- .../templates/pages/configure-interfaces.html | 59 +++++++++++-------- 8 files changed, 167 insertions(+), 94 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 02c2a355ab..6aea9295c0 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -38,6 +38,9 @@ All notable changes to the project are documented in this file. - 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 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..9bae83f108 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 { 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}} - + - -