blob: 1b34f780aa7a4c9a956dd58eb6f4d00d6371c5cb [file] [log] [blame]
developer42c7a432024-07-12 14:39:29 +08001From cce989770bf3375bbe4398a5ce80d9a9718460a3 Mon Sep 17 00:00:00 2001
2From: Johannes Berg <johannes.berg@intel.com>
3Date: Fri, 17 May 2024 12:04:06 +0200
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 01/13] iw: refactor frequency help
developer42c7a432024-07-12 14:39:29 +08005
6The channel parsing is the same in most places, refactor
7the help strings for that to not duplicate them in all
8the commands using them. This also corrects the help for
9a number of commands that never saw 320 MHz support.
10
11Reviewed-by: Miriam Rachel Korenblit <miriam.rachel.korenblit@intel.com>
12Signed-off-by: Johannes Berg <johannes.berg@intel.com>
13---
14 ap.c | 10 ++++++----
15 iw.h | 13 +++++++++++++
16 phy.c | 38 +++++++++++++-------------------------
17 util.c | 4 ++--
18 4 files changed, 34 insertions(+), 31 deletions(-)
19
20diff --git a/ap.c b/ap.c
21index 748576d..bf72fe2 100644
22--- a/ap.c
23+++ b/ap.c
24@@ -144,12 +144,14 @@ static int handle_start_ap(struct nl80211_state *state,
25 nla_put_failure:
26 return -ENOSPC;
27 }
28-COMMAND(ap, start, "",
29- NL80211_CMD_NEW_BEACON, 0, CIB_NETDEV, handle_start_ap,
30- "<SSID> <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]"
31+COMMAND(ap, start,
32+ "<SSID> "
33+ PARSE_FREQ_ARGS("<SSID> ",
34 " <beacon interval in TU> <DTIM period> [hidden-ssid|zeroed-ssid] head"
35 " <beacon head in hexadecimal> [tail <beacon tail in hexadecimal>]"
36- " [inactivity-time <inactivity time in seconds>] [key0:abcde d:1:6162636465]\n");
37+ " [inactivity-time <inactivity time in seconds>] [key0:abcde d:1:6162636465]"),
38+ NL80211_CMD_NEW_BEACON, 0, CIB_NETDEV, handle_start_ap,
39+ "Start an AP. Note that this usually requires hostapd or similar.\n");
40
41 static int handle_stop_ap(struct nl80211_state *state,
42 struct nl_msg *msg,
43diff --git a/iw.h b/iw.h
44index 7e9107e..82eee7c 100644
45--- a/iw.h
46+++ b/iw.h
47@@ -209,6 +209,19 @@ int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
48 unsigned char *parse_hex(char *hex, size_t *outlen);
49
50 int parse_keys(struct nl_msg *msg, char **argv[], int *argc);
51+
52+#define _PARSE_FREQ_ARGS_OPT1 "<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]"
53+#define _PARSE_FREQ_ARGS_OPT2 "<control freq> [5|10|20|40|80|80+80|160|320] [<center1_freq> [<center2_freq>]]"
54+#define PARSE_FREQ_ARGS(pfx, sfx) \
55+ pfx _PARSE_FREQ_ARGS_OPT1 sfx "\n" \
56+ pfx _PARSE_FREQ_ARGS_OPT2 sfx
57+#define _PARSE_FREQ_KHZ_ARGS_OPT1 "<freq in KHz> [1MHz|2MHz|4MHz|8MHz|16MHz]"
58+#define _PARSE_FREQ_KHZ_ARGS_OPT2 "<control freq in KHz> [1|2|4|8|16] [<center1_freq> [<center2_freq>]]"
59+#define PARSE_FREQ_KHZ_ARGS(pfx, sfx) \
60+ pfx _PARSE_FREQ_KHZ_ARGS_OPT1 sfx "\n" \
61+ pfx _PARSE_FREQ_KHZ_ARGS_OPT2 sfx
62+#define PARSE_CHAN_ARGS(pfx) \
63+ pfx "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]"
64 int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv,
65 int *parsed, bool freq_in_khz);
66 enum nl80211_chan_width str_to_bw(const char *str);
67diff --git a/phy.c b/phy.c
68index 4722125..584b103 100644
69--- a/phy.c
70+++ b/phy.c
71@@ -198,15 +198,10 @@ static int handle_freq(struct nl80211_state *state, struct nl_msg *msg,
72 return put_chandef(msg, &chandef);
73 }
74
75-COMMAND(set, freq,
76- "<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]\n"
77- "<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
78+COMMAND(set, freq, PARSE_FREQ_ARGS("", ""),
79 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq,
80- "Set frequency/channel the hardware is using, including HT\n"
81- "configuration.");
82-COMMAND(set, freq,
83- "<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]\n"
84- "<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
85+ "Set frequency/channel configuration the hardware is using.");
86+COMMAND(set, freq, PARSE_FREQ_ARGS("", ""),
87 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq, NULL);
88
89 static int handle_freq_khz(struct nl80211_state *state, struct nl_msg *msg,
90@@ -223,15 +218,11 @@ static int handle_freq_khz(struct nl80211_state *state, struct nl_msg *msg,
91 return put_chandef(msg, &chandef);
92 }
93
94-COMMAND(set, freq_khz,
95- "<freq> [1MHz|2MHz|4MHz|8MHz|16MHz]\n"
96- "<control freq> [1|2|4|8|16] [<center1_freq> [<center2_freq>]]",
97+COMMAND(set, freq_khz, PARSE_FREQ_KHZ_ARGS("", ""),
98 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_freq_khz,
99 "Set frequency in kHz the hardware is using\n"
100 "configuration.");
101-COMMAND(set, freq_khz,
102- "<freq> [1MHz|2MHz|4MHz|8MHz|16MHz]\n"
103- "<control freq> [1|2|4|8|16] [<center1_freq> [<center2_freq>]]",
104+COMMAND(set, freq_khz, PARSE_FREQ_KHZ_ARGS("", ""),
105 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq_khz, NULL);
106
107 static int handle_chan(struct nl80211_state *state, struct nl_msg *msg,
108@@ -247,9 +238,9 @@ static int handle_chan(struct nl80211_state *state, struct nl_msg *msg,
109
110 return put_chandef(msg, &chandef);
111 }
112-COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz]",
113+COMMAND(set, channel, PARSE_CHAN_ARGS(""),
114 NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_chan, NULL);
115-COMMAND(set, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz]",
116+COMMAND(set, channel, PARSE_CHAN_ARGS(""),
117 NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_chan, NULL);
118
119
120@@ -403,22 +394,19 @@ err_out:
121 free(cac_trigger_argv);
122 return err;
123 }
124-TOPLEVEL(cac, "channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
125- "freq <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
126- "freq <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
127+TOPLEVEL(cac, PARSE_CHAN_ARGS("channel ") "\n"
128+ PARSE_FREQ_ARGS("freq ", ""),
129 0, 0, CIB_NETDEV, handle_cac, NULL);
130 COMMAND(cac, trigger,
131- "channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
132- "freq <frequency> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
133- "freq <frequency> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
134+ PARSE_CHAN_ARGS("channel ") "\n"
135+ PARSE_FREQ_ARGS("freq ", ""),
136 NL80211_CMD_RADAR_DETECT, 0, CIB_NETDEV, handle_cac_trigger,
137 "Start or trigger a channel availability check (CAC) looking to look for\n"
138 "radars on the given channel.");
139
140 COMMAND(cac, background,
141- "channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
142- "freq <frequency> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]\n"
143- "freq <frequency> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]",
144+ PARSE_CHAN_ARGS("channel ") "\n"
145+ PARSE_FREQ_ARGS("freq ", ""),
146 NL80211_CMD_RADAR_DETECT, 0, CIB_NETDEV, handle_cac_background,
147 "Start background channel availability check (CAC) looking to look for\n"
148 "radars on the given channel.");
149diff --git a/util.c b/util.c
150index d36dbdc..f358317 100644
151--- a/util.c
152+++ b/util.c
153@@ -593,11 +593,11 @@ static int parse_freqs(struct chandef *chandef, int argc, char **argv,
154 * user by giving "NOHT" instead.
155 *
156 * The working specifier if chan is set are:
157- * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz]
158+ * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]
159 *
160 * And if frequency is set:
161 * <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz|320MHz]
162- * <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
163+ * <control freq> [5|10|20|40|80|80+80|160|320] [<center1_freq> [<center2_freq>]]
164 *
165 * If the mode/channel width is not given the NOHT is assumed.
166 *
167--
1682.18.0
169