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