| Channel{{template "field-info" .DescChannel}} |
-
+
|
-
-
+
diff --git a/src/yangerd/internal/collector/hardware.go b/src/yangerd/internal/collector/hardware.go
index 87747a92d2..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,11 +1000,32 @@ 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 >= 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
@@ -1010,6 +1034,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{}) {
@@ -1048,6 +1091,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..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])
}
@@ -917,3 +921,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/bands_test.go b/src/yangerd/internal/nl80211/bands_test.go
index 35a64779bc..0be9175fb7 100644
--- a/src/yangerd/internal/nl80211/bands_test.go
+++ b/src/yangerd/internal/nl80211/bands_test.go
@@ -1,6 +1,12 @@
package nl80211
-import "testing"
+import (
+ "strings"
+ "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".
@@ -10,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)
}
}
@@ -33,3 +40,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..a9d625b82a 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)
}
@@ -259,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
@@ -289,9 +294,9 @@ 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
- }
+ 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
@@ -318,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
}
@@ -340,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) {
@@ -376,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 {
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..f3fa08d895
--- /dev/null
+++ b/test/case/interfaces/wifi_radio_validation/test.adoc
@@ -0,0 +1,32 @@
+=== 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
+. 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
new file mode 100755
index 0000000000..09d8277fcf
--- /dev/null
+++ b/test/case/interfaces/wifi_radio_validation/test.py
@@ -0,0 +1,75 @@
+#!/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 radio_oper(target):
+ data = target.get_data("/ietf-hardware:hardware/component[name='radio0']")
+ radio = data["hardware"]["component"]["radio0"]
+ 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:
+ 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("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")
+
+ 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 @@
+
+
+
+
+
|