Description: Fix 6 GHz Wi-Fi channels enumeration in NetworkManager 
 This patch fixes the enumeration of 6 GHz Wi-Fi channels in NetworkManager, 
 ensuring that the correct channels are reported and handled by the system. 
 It adds a new table for 6 GHz channels and updates the relevant functions to accommodate this new band.
Origin: other, https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2110
From: Antoine Lassagne <antoine.lassagne@canonical.com>
Date: Tue, 15 Jul 2025 14:05:53 +0200
Subject: [PATCH] wifi: fix 6 GHz channels enumeration

---
 src/libnm-core-impl/nm-utils.c | 60 +++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c
index 761f74bdf..ea75ce9eb 100644
--- a/src/libnm-core-impl/nm-utils.c
+++ b/src/libnm-core-impl/nm-utils.c
@@ -3694,6 +3694,25 @@ struct cf_pair {
     guint32 freq;
 };
 
+static const struct cf_pair table_6ghz[] = {
+    /* 6GHz band */
+    {1, 5955},   {5, 5975},   {9, 5995},   {13, 6015},  {17, 6035},  {21, 6055},  {25, 6075},
+    {29, 6095},  {33, 6115},  {37, 6135},  {41, 6155},  {45, 6175},  {49, 6195},  {53, 6215},
+    {57, 6235},  {61, 6255},  {65, 6275},  {69, 6295},  {73, 6315},  {77, 6335},  {81, 6355},
+    {85, 6375},  {89, 6395},  {93, 6415},  {97, 6435},  {101, 6455}, {105, 6475}, {109, 6495},
+    {113, 6515}, {117, 6535}, {121, 6555}, {125, 6575}, {129, 6595}, {133, 6615}, {137, 6635},
+    {141, 6655}, {145, 6675}, {149, 6695}, {153, 6715}, {157, 6735}, {161, 6755}, {165, 6775},
+    {169, 6795}, {173, 6815}, {177, 6835}, {181, 6855}, {185, 6875}, {189, 6895}, {193, 6915},
+    {197, 6935}, {201, 6955}, {205, 6975}, {209, 6995}, {213, 7015}, {217, 7035}, {221, 7055},
+    {225, 7075}, {229, 7095}, {233, 7115}, {0, 0}};
+
+static const guint table_6ghz_freqs[G_N_ELEMENTS(table_6ghz)] = {
+    /* 6GHz band */
+    5955, 5975, 5995, 6015, 6035, 6055, 6075, 6095, 6115, 6135, 6155, 6175, 6195, 6215, 6235,
+    6255, 6275, 6295, 6315, 6335, 6355, 6375, 6395, 6415, 6435, 6455, 6475, 6495, 6515, 6535,
+    6555, 6575, 6595, 6615, 6635, 6655, 6675, 6695, 6715, 6735, 6755, 6775, 6795, 6815, 6835,
+    6855, 6875, 6895, 6915, 6935, 6955, 6975, 6995, 7015, 7035, 7055, 7075, 7095, 7115, 0};
+
 static const struct cf_pair a_table[] = {
     /* A band */
     {7, 5035},   {8, 5040},   {9, 5045},   {11, 5055},  {12, 5060},  {16, 5080},  {34, 5170},
@@ -3761,6 +3780,12 @@ nm_utils_wifi_freq_to_channel(guint32 freq)
 {
     int i = 0;
 
+    if (freq >= 5955) {
+        while (table_6ghz[i].freq && (table_6ghz[i].freq != freq))
+            i++;
+        return table_6ghz[i].chan;
+    }
+
     if (freq > 4900) {
         while (a_table[i].freq && (a_table[i].freq != freq))
             i++;
@@ -3783,7 +3808,9 @@ nm_utils_wifi_freq_to_channel(guint32 freq)
 const char *
 nm_utils_wifi_freq_to_band(guint32 freq)
 {
-    if (freq >= 4915 && freq <= 5825)
+    if (freq >= 5935 && freq <= 7115)
+        return "6ghz";
+    else if (freq >= 4915 && freq <= 5825)
         return "a";
     else if (freq >= 2412 && freq <= 2484)
         return "bg";
@@ -3825,6 +3852,14 @@ nm_utils_wifi_channel_to_freq(guint32 channel, const char *band)
         return ((guint32) -1);
     }
 
+    if (nm_streq(band, "6ghz")) {
+        for (i = 0; bg_table[i].chan; i++) {
+            if (bg_table[i].chan == channel)
+                return bg_table[i].freq;
+        }
+        return ((guint32) -1);
+    }
+
     return 0;
 }
 
@@ -3843,6 +3878,7 @@ nm_utils_wifi_find_next_channel(guint32 channel, int direction, char *band)
 {
     size_t                a_size  = G_N_ELEMENTS(a_table);
     size_t                bg_size = G_N_ELEMENTS(bg_table);
+    size_t                size_6ghz = G_N_ELEMENTS(table_6ghz);
     const struct cf_pair *pair;
 
     if (nm_streq(band, "a")) {
@@ -3857,6 +3893,12 @@ nm_utils_wifi_find_next_channel(guint32 channel, int direction, char *band)
         if (channel > bg_table[bg_size - 2].chan)
             return bg_table[bg_size - 2].chan;
         pair = &bg_table[0];
+    } else if (nm_streq0(band, "6ghz")) {
+        if (channel < table_6ghz[0].chan)
+            return table_6ghz[0].chan;
+        if (channel > table_6ghz[size_6ghz - 2].chan)
+            return table_6ghz[size_6ghz - 2].chan;
+        pair = &table_6ghz[0];
     } else
         g_return_val_if_reached(0);
 
@@ -3947,6 +3989,22 @@ nm_utils_wifi_5ghz_freqs(void)
     return a_table_freqs;
 }
 
+/**
+ * nm_utils_wifi_6ghz_freqs:
+ *
+ * Utility function to return 6 GHz Wi-Fi frequencies (802.11ax, 802.11be band).
+ *
+ * Returns: zero-terminated array of frequencies numbers (in MHz)
+ *
+ * Since: 1.xx
+ **/
+const guint *
+nm_utils_wifi_6ghz_freqs(void)
+{
+    _nm_assert_wifi_freqs(table_6ghz, table_6ghz_freqs);
+    return table_6ghz_freqs;
+}
+
 /**
  * nm_utils_wifi_strength_bars:
  * @strength: the access point strength, from 0 to 100
-- 
2.43.0

