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