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