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