]> git.ipfire.org Git - thirdparty/iw.git/blame - info.c
iw: fix help text for event command
[thirdparty/iw.git] / info.c
CommitLineData
21878f36 1#include <stdbool.h>
79f99b9a 2#include <errno.h>
2ef1be68 3
79f99b9a
JB
4#include <netlink/genl/genl.h>
5#include <netlink/genl/family.h>
6#include <netlink/genl/ctrl.h>
7#include <netlink/msg.h>
8#include <netlink/attr.h>
79f99b9a 9
f408e01b 10#include "nl80211.h"
79f99b9a
JB
11#include "iw.h"
12
13static void print_flag(const char *name, int *open)
14{
15 if (!*open)
16 printf(" (");
17 else
18 printf(", ");
69283122 19 printf("%s", name);
79f99b9a
JB
20 *open = 1;
21}
22
810e05c3
JB
23static char *cipher_name(__u32 c)
24{
25 static char buf[20];
26
27 switch (c) {
28 case 0x000fac01:
29 return "WEP40 (00-0f-ac:1)";
30 case 0x000fac05:
31 return "WEP104 (00-0f-ac:5)";
32 case 0x000fac02:
33 return "TKIP (00-0f-ac:2)";
34 case 0x000fac04:
35 return "CCMP (00-0f-ac:4)";
36 case 0x000fac06:
37 return "CMAC (00-0f-ac:6)";
a8b3da9d
VK
38 case 0x000fac08:
39 return "GCMP (00-0f-ac:8)";
810e05c3
JB
40 case 0x00147201:
41 return "WPI-SMS4 (00-14-72:1)";
42 default:
43 sprintf(buf, "%.2x-%.2x-%.2x:%d",
44 c >> 24, (c >> 16) & 0xff,
45 (c >> 8) & 0xff, c & 0xff);
46
47 return buf;
48 }
49}
50
48aaf2d9
SW
51static char *dfs_state_name(enum nl80211_dfs_state state)
52{
53 switch (state) {
54 case NL80211_DFS_USABLE:
55 return "usable";
56 case NL80211_DFS_AVAILABLE:
57 return "available";
58 case NL80211_DFS_UNAVAILABLE:
59 return "unavailable";
60 default:
61 return "unknown";
62 }
63}
64
f0e30bd5
JD
65static int ext_feature_isset(const unsigned char *ext_features, int ext_features_len,
66 enum nl80211_ext_feature_index ftidx)
67{
68 unsigned char ft_byte;
69
70 if ((int) ftidx / 8 >= ext_features_len)
71 return 0;
72
73 ft_byte = ext_features[ftidx / 8];
74 return (ft_byte & BIT(ftidx % 8)) != 0;
75}
76
79f99b9a
JB
77static int print_phy_handler(struct nl_msg *msg, void *arg)
78{
79 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
80 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
81
82 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
83
84 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
85 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
86 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
87 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
f0c48e7b
IP
88 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
89 [__NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
79f99b9a 90 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
c1081c20 91 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
79f99b9a
JB
92 };
93
94 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
95 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
96 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
97 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
98 };
99
100 struct nlattr *nl_band;
101 struct nlattr *nl_freq;
102 struct nlattr *nl_rate;
6367e71a 103 struct nlattr *nl_mode;
9990c1e9 104 struct nlattr *nl_cmd;
9a4a14bd 105 struct nlattr *nl_if, *nl_ftype;
9a4a14bd 106 int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if;
79f99b9a 107 int open;
fb70e110
JB
108 /*
109 * static variables only work here, other applications need to use the
110 * callback pointer and store them there so they can be multithreaded
111 * and/or have multiple netlink sockets, etc.
112 */
113 static int64_t phy_id = -1;
114 static int last_band = -1;
115 static bool band_had_freq = false;
116 bool print_name = true;
79f99b9a
JB
117
118 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
119 genlmsg_attrlen(gnlh, 0), NULL);
120
fb70e110
JB
121 if (tb_msg[NL80211_ATTR_WIPHY]) {
122 if (nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]) == phy_id)
123 print_name = false;
124 else
125 last_band = -1;
126 phy_id = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]);
127 }
128 if (print_name && tb_msg[NL80211_ATTR_WIPHY_NAME])
d631650b
JB
129 printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME]));
130
fb70e110
JB
131 /* needed for split dump */
132 if (tb_msg[NL80211_ATTR_WIPHY_BANDS]) {
133 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
134 if (last_band != nl_band->nla_type) {
135 printf("\tBand %d:\n", nl_band->nla_type + 1);
136 band_had_freq = false;
ee9cd987 137 }
fb70e110 138 last_band = nl_band->nla_type;
48aaf2d9 139
fb70e110
JB
140 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
141 nla_len(nl_band), NULL);
48aaf2d9 142
fb70e110
JB
143 if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) {
144 __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]);
145 print_ht_capability(cap);
146 }
147 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) {
148 __u8 exponent = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]);
149 print_ampdu_length(exponent);
150 }
151 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) {
152 __u8 spacing = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]);
153 print_ampdu_spacing(spacing);
154 }
155 if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] &&
156 nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16)
157 print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]));
158 if (tb_band[NL80211_BAND_ATTR_VHT_CAPA] &&
159 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET])
160 print_vht_info(nla_get_u32(tb_band[NL80211_BAND_ATTR_VHT_CAPA]),
161 nla_data(tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]));
162
163 if (tb_band[NL80211_BAND_ATTR_FREQS]) {
164 if (!band_had_freq) {
165 printf("\t\tFrequencies:\n");
166 band_had_freq = true;
167 }
168 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
169 uint32_t freq;
170 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
171 nla_len(nl_freq), freq_policy);
172 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
173 continue;
174 freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
175 printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq));
176
177 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
178 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
179 printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]));
180
181 open = 0;
182 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) {
183 print_flag("disabled", &open);
184 goto next;
185 }
f0c48e7b
IP
186
187 /* If both flags are set assume an new kernel */
188 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR] && tb_freq[__NL80211_FREQUENCY_ATTR_NO_IBSS]) {
189 print_flag("no IR", &open);
190 } else if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) {
191 print_flag("passive scan", &open);
192 } else if (tb_freq[__NL80211_FREQUENCY_ATTR_NO_IBSS]){
193 print_flag("no ibss", &open);
194 }
195
fb70e110
JB
196 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
197 print_flag("radar detection", &open);
198next:
199 if (open)
200 printf(")");
201 printf("\n");
202
4b99e6a6
ZK
203 if (!tb_freq[NL80211_FREQUENCY_ATTR_DISABLED] && tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
204 enum nl80211_dfs_state state = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
205 unsigned long time;
206
207 printf("\t\t\t DFS state: %s", dfs_state_name(state));
208 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]) {
209 time = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]);
210 printf(" (for %lu sec)", time/1000);
211 }
212 printf("\n");
8220747f
JD
213 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME])
214 printf("\t\t\t DFS CAC time: %u ms\n",
215 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]));
fb70e110 216 }
4b99e6a6 217
48aaf2d9 218 }
48aaf2d9 219 }
79f99b9a 220
fb70e110
JB
221 if (tb_band[NL80211_BAND_ATTR_RATES]) {
222 printf("\t\tBitrates (non-HT):\n");
223 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
224 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
225 nla_len(nl_rate), rate_policy);
226 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
227 continue;
228 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
229 open = 0;
230 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
231 print_flag("short preamble supported", &open);
232 if (open)
233 printf(")");
234 printf("\n");
235 }
236 }
79f99b9a
JB
237 }
238 }
239
41be37f2
JB
240 if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
241 printf("\tmax # scan SSIDs: %d\n",
242 nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]));
f9c112b6
JB
243 if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])
244 printf("\tmax scan IEs length: %d bytes\n",
8eaa9ee5 245 nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]));
3fce58aa
LC
246 if (tb_msg[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
247 printf("\tmax # sched scan SSIDs: %d\n",
248 nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]));
249 if (tb_msg[NL80211_ATTR_MAX_MATCH_SETS])
250 printf("\tmax # match sets: %d\n",
251 nla_get_u8(tb_msg[NL80211_ATTR_MAX_MATCH_SETS]));
41be37f2 252
625aa4ae
JB
253 if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
254 unsigned int frag;
255
256 frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
257 if (frag != (unsigned int)-1)
258 printf("\tFragmentation threshold: %d\n", frag);
259 }
260
261 if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
262 unsigned int rts;
263
264 rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
265 if (rts != (unsigned int)-1)
266 printf("\tRTS threshold: %d\n", rts);
267 }
268
c993e6e7
UR
269 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT] ||
270 tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]) {
271 unsigned char retry_short = 0, retry_long = 0;
272
273 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT])
274 retry_short = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT]);
275 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG])
276 retry_long = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]);
277 if (retry_short == retry_long) {
278 printf("\tRetry short long limit: %d\n", retry_short);
279 } else {
280 printf("\tRetry short limit: %d\n", retry_short);
281 printf("\tRetry long limit: %d\n", retry_long);
282 }
283 }
284
b2f92dd0
LT
285 if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
286 unsigned char coverage;
287
288 coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
289 /* See handle_distance() for an explanation where the '450' comes from */
290 printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
291 }
292
810e05c3
JB
293 if (tb_msg[NL80211_ATTR_CIPHER_SUITES]) {
294 int num = nla_len(tb_msg[NL80211_ATTR_CIPHER_SUITES]) / sizeof(__u32);
295 int i;
296 __u32 *ciphers = nla_data(tb_msg[NL80211_ATTR_CIPHER_SUITES]);
297 if (num > 0) {
298 printf("\tSupported Ciphers:\n");
299 for (i = 0; i < num; i++)
300 printf("\t\t* %s\n",
301 cipher_name(ciphers[i]));
302 }
303 }
304
afce7986
BR
305 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] &&
306 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])
307 printf("\tAvailable Antennas: TX %#x RX %#x\n",
308 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]),
309 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]));
310
311 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
312 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])
313 printf("\tConfigured Antennas: TX %#x RX %#x\n",
314 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
315 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
316
9a4a14bd
JB
317 if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
318 printf("\tSupported interface modes:\n");
319 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
8ef6df4f 320 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
9a4a14bd 321 }
6367e71a 322
1c5b4a82
JB
323 if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) {
324 printf("\tsoftware interface modes (can always be added):\n");
325 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode)
326 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
327 }
328
329 if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) {
330 struct nlattr *nl_combi;
331 int rem_combi;
f5f6f15f 332 bool have_combinations = false;
1c5b4a82
JB
333
334 nla_for_each_nested(nl_combi, tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS], rem_combi) {
335 static struct nla_policy iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
336 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
337 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
338 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
339 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
c5df9eb6 340 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1c5b4a82
JB
341 };
342 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
343 static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
344 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
345 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
346 };
347 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
348 struct nlattr *nl_limit;
349 int err, rem_limit;
350 bool comma = false;
351
f5f6f15f
JB
352 if (!have_combinations) {
353 printf("\tvalid interface combinations:\n");
354 have_combinations = true;
355 }
356
1c5b4a82
JB
357 printf("\t\t * ");
358
359 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
360 nl_combi, iface_combination_policy);
361 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
362 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
363 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) {
364 printf(" <failed to parse>\n");
365 goto broken_combination;
366 }
367
368 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) {
369 bool ift_comma = false;
370
371 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
372 nl_limit, iface_limit_policy);
373 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) {
374 printf("<failed to parse>\n");
375 goto broken_combination;
376 }
377
378 if (comma)
379 printf(", ");
380 comma = true;
381 printf("#{");
382
383 nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) {
384 printf("%s %s", ift_comma ? "," : "",
385 iftype_name(nla_type(nl_mode)));
386 ift_comma = true;
387 }
388 printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX]));
389 }
390 printf(",\n\t\t ");
391
c5df9eb6 392 printf("total <= %d, #channels <= %d%s",
1c5b4a82
JB
393 nla_get_u32(tb_comb[NL80211_IFACE_COMB_MAXNUM]),
394 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]),
395 tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH] ?
396 ", STA/AP BI must match" : "");
c5df9eb6
SW
397 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) {
398 unsigned long widths = nla_get_u32(tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]);
399
400 if (widths) {
401 int width;
402 bool first = true;
403
404 printf(", radar detect widths: {");
405 for (width = 0; width < 32; width++)
406 if (widths & (1 << width)) {
407 printf("%s %s",
408 first ? "":",",
409 channel_width_name(width));
410 first = false;
411 }
412 printf(" }\n");
413 }
414 }
415 printf("\n");
1c5b4a82
JB
416broken_combination:
417 ;
418 }
f5f6f15f
JB
419
420 if (!have_combinations)
421 printf("\tinterface combinations are not supported\n");
1c5b4a82
JB
422 }
423
9a4a14bd
JB
424 if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) {
425 printf("\tSupported commands:\n");
426 nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd)
427 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd)));
428 }
6367e71a 429
9a4a14bd
JB
430 if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) {
431 printf("\tSupported TX frame types:\n");
432 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) {
433 bool printed = false;
434 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
435 if (!printed)
436 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
437 printed = true;
58e34341 438 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
439 }
440 if (printed)
441 printf("\n");
442 }
443 }
9990c1e9 444
9a4a14bd
JB
445 if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) {
446 printf("\tSupported RX frame types:\n");
447 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) {
448 bool printed = false;
449 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
450 if (!printed)
451 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
452 printed = true;
58e34341 453 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
454 }
455 if (printed)
456 printf("\n");
457 }
458 }
9990c1e9 459
3ff24563 460 if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN])
83f10169 461 printf("\tDevice supports RSN-IBSS.\n");
3ff24563
JB
462
463 if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) {
464 struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG];
465 static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
466 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
467 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
468 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
1c8f49c5 469 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .minlen = 12 },
3a6636b1
JB
470 [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED] = { .type = NLA_FLAG },
471 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
472 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
473 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
474 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
4888e6ba 475 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_U32 },
819b78cc 476 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
3ff24563 477 };
c82868da 478 struct nl80211_pattern_support *pat;
3ff24563
JB
479 int err;
480
481 err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG,
482 tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED],
483 wowlan_policy);
484 printf("\tWoWLAN support:");
485 if (err) {
486 printf(" <failed to parse>\n");
487 } else {
488 printf("\n");
489 if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY])
3a6636b1 490 printf("\t\t * wake up on anything (device continues operating normally)\n");
3ff24563 491 if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT])
3a6636b1 492 printf("\t\t * wake up on disconnect\n");
3ff24563 493 if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT])
3a6636b1 494 printf("\t\t * wake up on magic packet\n");
3ff24563
JB
495 if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
496 pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
1c8f49c5
AK
497 printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n"
498 "\t\t maximum packet offset %u bytes\n",
499 pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len,
500 (nla_len(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) <
501 sizeof(*pat)) ? 0 : pat->max_pkt_offset);
3ff24563 502 }
3a6636b1
JB
503 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
504 printf("\t\t * can do GTK rekeying\n");
505 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
506 printf("\t\t * wake up on GTK rekey failure\n");
507 if (tb_wowlan[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
508 printf("\t\t * wake up on EAP identity request\n");
509 if (tb_wowlan[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
510 printf("\t\t * wake up on 4-way handshake\n");
511 if (tb_wowlan[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
512 printf("\t\t * wake up on rfkill release\n");
d516c5bc 513 if (tb_wowlan[NL80211_WOWLAN_TRIG_NET_DETECT])
4888e6ba
LC
514 printf("\t\t * wake up on network detection, up to %d match sets\n",
515 nla_get_u32(tb_wowlan[NL80211_WOWLAN_TRIG_NET_DETECT]));
819b78cc
JB
516 if (tb_wowlan[NL80211_WOWLAN_TRIG_TCP_CONNECTION])
517 printf("\t\t * wake up on TCP connection\n");
3ff24563 518 }
83f10169
JB
519 }
520
2e4f65ca
JB
521 if (tb_msg[NL80211_ATTR_ROAM_SUPPORT])
522 printf("\tDevice supports roaming.\n");
523
8b469995
JB
524 if (tb_msg[NL80211_ATTR_SUPPORT_AP_UAPSD])
525 printf("\tDevice supports AP-side u-APSD.\n");
526
a82abc2c
BG
527 if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) {
528 struct ieee80211_ht_cap *cm;
529 printf("\tHT Capability overrides:\n");
530 if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) {
531 cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
532 printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx"
533 " %02hhx %02hhx %02hhx %02hhx\n",
534 cm->mcs.rx_mask[0], cm->mcs.rx_mask[1],
535 cm->mcs.rx_mask[2], cm->mcs.rx_mask[3],
536 cm->mcs.rx_mask[4], cm->mcs.rx_mask[5],
537 cm->mcs.rx_mask[6], cm->mcs.rx_mask[7],
538 cm->mcs.rx_mask[8], cm->mcs.rx_mask[9]);
539 if (cm->cap_info & htole16(IEEE80211_HT_CAP_MAX_AMSDU))
540 printf("\t\t * maximum A-MSDU length\n");
541 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SUP_WIDTH_20_40))
542 printf("\t\t * supported channel width\n");
543 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SGI_40))
544 printf("\t\t * short GI for 40 MHz\n");
545 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_FACTOR)
546 printf("\t\t * max A-MPDU length exponent\n");
547 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_DENSITY)
548 printf("\t\t * min MPDU start spacing\n");
549 } else {
550 printf("\tERROR: capabilities mask is too short, expected: %d, received: %d\n",
551 (int)(sizeof(*cm)),
552 (int)(nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK])));
553 }
554 }
555
632004a0 556 if (tb_msg[NL80211_ATTR_FEATURE_FLAGS]) {
d28df6b4
JB
557 unsigned int features = nla_get_u32(tb_msg[NL80211_ATTR_FEATURE_FLAGS]);
558
559 if (features & NL80211_FEATURE_SK_TX_STATUS)
632004a0 560 printf("\tDevice supports TX status socket option.\n");
d28df6b4 561 if (features & NL80211_FEATURE_HT_IBSS)
632004a0 562 printf("\tDevice supports HT-IBSS.\n");
d28df6b4
JB
563 if (features & NL80211_FEATURE_INACTIVITY_TIMER)
564 printf("\tDevice has client inactivity timer.\n");
565 if (features & NL80211_FEATURE_CELL_BASE_REG_HINTS)
566 printf("\tDevice accepts cell base station regulatory hints.\n");
567 if (features & NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL)
568 printf("\tP2P Device uses a channel (of the concurrent ones)\n");
5973e65b
JB
569 if (features & NL80211_FEATURE_SAE)
570 printf("\tDevice supports SAE with AUTHENTICATE command\n");
fe862239
SL
571 if (features & NL80211_FEATURE_LOW_PRIORITY_SCAN)
572 printf("\tDevice supports low priority scan.\n");
573 if (features & NL80211_FEATURE_SCAN_FLUSH)
574 printf("\tDevice supports scan flush.\n");
afa2be2f
AQ
575 if (features & NL80211_FEATURE_AP_SCAN)
576 printf("\tDevice supports AP scan.\n");
5973e65b
JB
577 if (features & NL80211_FEATURE_VIF_TXPOWER)
578 printf("\tDevice supports per-vif TX power setting\n");
579 if (features & NL80211_FEATURE_NEED_OBSS_SCAN)
580 printf("\tUserspace should do OBSS scan and generate 20/40 coex reports\n");
581 if (features & NL80211_FEATURE_P2P_GO_CTWIN)
582 printf("\tP2P GO supports CT window setting\n");
583 if (features & NL80211_FEATURE_P2P_GO_OPPPS)
584 printf("\tP2P GO supports opportunistic powersave setting\n");
585 if (features & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
586 printf("\tDriver supports full state transitions for AP/GO clients\n");
587 if (features & NL80211_FEATURE_USERSPACE_MPM)
588 printf("\tDriver supports a userspace MPM\n");
589 if (features & NL80211_FEATURE_ACTIVE_MONITOR)
590 printf("\tDevice supports active monitor (which will ACK incoming frames)\n");
591 if (features & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
592 printf("\tDriver/device bandwidth changes during BSS lifetime (AP/GO mode)\n");
593 if (features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
594 printf("\tDevice adds DS IE to probe requests\n");
595 if (features & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
596 printf("\tDevice adds WFA TPC Report IE to probe requests\n");
597 if (features & NL80211_FEATURE_QUIET)
598 printf("\tDevice supports quiet requests from AP\n");
599 if (features & NL80211_FEATURE_TX_POWER_INSERTION)
600 printf("\tDevice can update TPC Report IE\n");
e642142d
LB
601 if (features & NL80211_FEATURE_ACKTO_ESTIMATION)
602 printf("\tDevice supports ACK timeout estimation.\n");
5973e65b
JB
603 if (features & NL80211_FEATURE_STATIC_SMPS)
604 printf("\tDevice supports static SMPS\n");
605 if (features & NL80211_FEATURE_DYNAMIC_SMPS)
606 printf("\tDevice supports dynamic SMPS\n");
e15ec749
JB
607 if (features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
608 printf("\tDevice supports WMM-AC admission (TSPECs)\n");
ced5522d
BG
609 if (features & NL80211_FEATURE_MAC_ON_CREATE)
610 printf("\tDevice supports configuring vdev MAC-addr on create.\n");
c2f0d689
AN
611 if (features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)
612 printf("\tDevice supports TDLS channel switching\n");
632004a0
JB
613 }
614
f0e30bd5
JD
615 if (tb_msg[NL80211_ATTR_EXT_FEATURES]) {
616 struct nlattr *tb = tb_msg[NL80211_ATTR_EXT_FEATURES];
617
618 if (ext_feature_isset(nla_data(tb), nla_len(tb),
619 NL80211_EXT_FEATURE_VHT_IBSS))
620 printf("\tDevice supports VHT-IBSS.\n");
621 }
622
9b4a1989
JB
623 if (tb_msg[NL80211_ATTR_TDLS_SUPPORT])
624 printf("\tDevice supports T-DLS.\n");
625
aa0f5dbe
AK
626 if (tb_msg[NL80211_ATTR_COALESCE_RULE]) {
627 struct nl80211_coalesce_rule_support *rule;
628 struct nl80211_pattern_support *pat;
629
630 printf("\tCoalesce support:\n");
631 rule = nla_data(tb_msg[NL80211_ATTR_COALESCE_RULE]);
632 pat = &rule->pat;
633 printf("\t\t * Maximum %u coalesce rules supported\n"
634 "\t\t * Each rule contains upto %u patterns of %u-%u bytes,\n"
635 "\t\t maximum packet offset %u bytes\n"
636 "\t\t * Maximum supported coalescing delay %u msecs\n",
637 rule->max_rules, pat->max_patterns, pat->min_pattern_len,
638 pat->max_pattern_len, pat->max_pkt_offset, rule->max_delay);
639 }
640
79f99b9a
JB
641 return NL_SKIP;
642}
643
c142fa28
JB
644static bool nl80211_has_split_wiphy = false;
645
7c37a24d 646static int handle_info(struct nl80211_state *state,
d631650b 647 struct nl_msg *msg,
05514f95
JB
648 int argc, char **argv,
649 enum id_input id)
79f99b9a 650{
c142fa28
JB
651 char *feat_args[] = { "features", "-q" };
652 int err;
653
654 err = handle_cmd(state, CIB_NONE, 2, feat_args);
655 if (!err && nl80211_has_split_wiphy) {
656 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
657 nlmsg_hdr(msg)->nlmsg_flags |= NLM_F_DUMP;
658 }
659
34b23014 660 register_handler(print_phy_handler, NULL);
79f99b9a 661
70391ccf 662 return 0;
79f99b9a 663}
c142fa28 664__COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info,
1633ddf7 665 "Show capabilities for the specified wireless device.", NULL);
ea35fc0b
JB
666TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info,
667 "List all wireless devices and their capabilities.");
01ae06f9 668TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL);
bcdff0b2 669
34b23014 670static int handle_commands(struct nl80211_state *state, struct nl_msg *msg,
bcdff0b2
JB
671 int argc, char **argv, enum id_input id)
672{
673 int i;
516ef62a 674 for (i = 1; i <= NL80211_CMD_MAX; i++)
bcdff0b2
JB
675 printf("%d (0x%x): %s\n", i, i, command_name(i));
676 /* don't send netlink messages */
677 return 2;
678}
679TOPLEVEL(commands, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_NONE, handle_commands,
680 "list all known commands and their decimal & hex value");
fb70e110
JB
681
682static int print_feature_handler(struct nl_msg *msg, void *arg)
683{
684 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
685 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
c142fa28
JB
686 bool print = (unsigned long)arg;
687#define maybe_printf(...) do { if (print) printf(__VA_ARGS__); } while (0)
fb70e110
JB
688
689 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
690 genlmsg_attrlen(gnlh, 0), NULL);
691
692 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) {
693 uint32_t feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
694
c142fa28
JB
695 maybe_printf("nl80211 features: 0x%x\n", feat);
696 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) {
697 maybe_printf("\t* split wiphy dump\n");
698 nl80211_has_split_wiphy = true;
699 }
fb70e110
JB
700 }
701
702 return NL_SKIP;
703}
704
34b23014 705static int handle_features(struct nl80211_state *state, struct nl_msg *msg,
fb70e110
JB
706 int argc, char **argv, enum id_input id)
707{
c142fa28 708 unsigned long print = argc == 0 || strcmp(argv[0], "-q");
34b23014 709 register_handler(print_feature_handler, (void *)print);
fb70e110
JB
710 return 0;
711}
712
c142fa28 713TOPLEVEL(features, "", NL80211_CMD_GET_PROTOCOL_FEATURES, 0, CIB_NONE,
fb70e110 714 handle_features, "");