diff mbox series

iw: add support to parse 6 GHz channel

Message ID 20250620073240.2770468-1-quic_surapk@quicinc.com
State New
Headers show
Series iw: add support to parse 6 GHz channel | expand

Commit Message

Suraj P Kizhakkethil June 20, 2025, 7:32 a.m. UTC
From: Pradeep Kumar Chitrapu <quic_pradeepc@quicinc.com>

Currently, 6 GHz band channel parsing is not supported for
set/switch channel commands. Channel numbers of 6 GHz band
overlaps with those of 2 GHz or 5 GHz bands and therefore needs
additional argument to indicate 6 GHz band. Add support to
parse 6 GHz channels for set/switch channel commands by an
optional argument "6GHz" in the set/switch channel commands.

Examples:

For 6 GHz band,
iw dev wlan0 set channel 49 6GHz 80MHz

For 5 GHz band,
iw dev wlan0 set channel 36 80MHz

Signed-off-by: Pradeep Kumar Chitrapu <quic_pradeepc@quicinc.com>
Signed-off-by: Suraj P Kizhakkethil <quic_surapk@quicinc.com>
---
 interface.c |  6 ++++--
 iw.h        |  2 +-
 util.c      | 14 ++++++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)


base-commit: 1558e6021ec5ae0f6fcb1c31e20d0d4dacebd82b
diff mbox series

Patch

diff --git a/interface.c b/interface.c
index 0d4ff04..0bddda2 100644
--- a/interface.c
+++ b/interface.c
@@ -771,8 +771,10 @@  COMMAND(switch, freq,
 	"<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]] [beacons <count>] [block-tx]",
 	NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_freq,
 	"Switch the operating channel by sending a channel switch announcement (CSA).");
-COMMAND(switch, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]",
-	NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_chan, NULL);
+COMMAND(switch, channel, "<channel> [6GHz] [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]",
+	NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_chan,
+	"Switch the operating channel by sending a channel switch announcement (CSA)."
+	"6 GHz channels expects '6GHz' in argument. Defaults to 5 GHz or 2 GHz channels");
 
 
 static int toggle_tid_param(const char *argv0, const char *argv1,
diff --git a/iw.h b/iw.h
index a423431..e0f548d 100644
--- a/iw.h
+++ b/iw.h
@@ -229,7 +229,7 @@  int parse_keys(struct nl_msg *msg, char **argv[], int *argc);
 	pfx _PARSE_FREQ_KHZ_ARGS_OPT1 sfx "\n" \
 	pfx _PARSE_FREQ_KHZ_ARGS_OPT2 sfx
 #define PARSE_CHAN_ARGS(pfx) \
-	pfx "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz] [punct <bitmap>]"
+	pfx "<channel> [6GHz] [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz] [punct <bitmap>]"
 int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv,
 		    int *parsed, bool freq_in_khz);
 enum nl80211_chan_width str_to_bw(const char *str);
diff --git a/util.c b/util.c
index 3345d95..8bf1c7f 100644
--- a/util.c
+++ b/util.c
@@ -593,7 +593,8 @@  static int parse_freqs(struct chandef *chandef, int argc, char **argv,
  * user by giving "NOHT" instead.
  *
  * The working specifier if chan is set are:
- *   <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]
+ *   <channel> [6GHz] [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]
+ * channel number defaults to 5 GHz or 2 GHz band unless 6GHz is specified.
  *
  * And if frequency is set:
  *   <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]
@@ -697,7 +698,12 @@  int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv,
 	if (chan) {
 		enum nl80211_band band;
 
-		band = freq <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
+		if (argc > 1 && strcasecmp(argv[1], "6GHz") == 0) {
+			band = NL80211_BAND_6GHZ;
+			_parsed += 1;
+		} else {
+			band = freq <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
+		}
 		freq = ieee80211_channel_to_frequency(freq, band);
 	}
 	chandef->control_freq = freq;
@@ -707,9 +713,9 @@  int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv,
 	chandef->center_freq1_offset = freq_offset;
 
 	/* Try to parse HT mode definitions */
-	if (argc > 1) {
+	if ((argc - _parsed) > 0) {
 		for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
-			if (strcasecmp(chanmode[i].name, argv[1]) == 0) {
+			if (strcasecmp(chanmode[i].name, argv[_parsed]) == 0) {
 				chanmode_selected = &chanmode[i];
 				_parsed += 1;
 				break;