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