]> git.ipfire.org Git - thirdparty/iw.git/blame - info.c
iw: support setting vif MAC during creation
[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");
8220747f
JD
202 if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME])
203 printf("\t\t\t DFS CAC time: %u ms\n",
204 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]));
fb70e110 205 }
4b99e6a6 206
48aaf2d9 207 }
48aaf2d9 208 }
79f99b9a 209
fb70e110
JB
210 if (tb_band[NL80211_BAND_ATTR_RATES]) {
211 printf("\t\tBitrates (non-HT):\n");
212 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
213 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
214 nla_len(nl_rate), rate_policy);
215 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
216 continue;
217 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
218 open = 0;
219 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
220 print_flag("short preamble supported", &open);
221 if (open)
222 printf(")");
223 printf("\n");
224 }
225 }
79f99b9a
JB
226 }
227 }
228
41be37f2
JB
229 if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
230 printf("\tmax # scan SSIDs: %d\n",
231 nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]));
f9c112b6
JB
232 if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])
233 printf("\tmax scan IEs length: %d bytes\n",
8eaa9ee5 234 nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]));
41be37f2 235
625aa4ae
JB
236 if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
237 unsigned int frag;
238
239 frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
240 if (frag != (unsigned int)-1)
241 printf("\tFragmentation threshold: %d\n", frag);
242 }
243
244 if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
245 unsigned int rts;
246
247 rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
248 if (rts != (unsigned int)-1)
249 printf("\tRTS threshold: %d\n", rts);
250 }
251
c993e6e7
UR
252 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT] ||
253 tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]) {
254 unsigned char retry_short = 0, retry_long = 0;
255
256 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT])
257 retry_short = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT]);
258 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG])
259 retry_long = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]);
260 if (retry_short == retry_long) {
261 printf("\tRetry short long limit: %d\n", retry_short);
262 } else {
263 printf("\tRetry short limit: %d\n", retry_short);
264 printf("\tRetry long limit: %d\n", retry_long);
265 }
266 }
267
b2f92dd0
LT
268 if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
269 unsigned char coverage;
270
271 coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
272 /* See handle_distance() for an explanation where the '450' comes from */
273 printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
274 }
275
810e05c3
JB
276 if (tb_msg[NL80211_ATTR_CIPHER_SUITES]) {
277 int num = nla_len(tb_msg[NL80211_ATTR_CIPHER_SUITES]) / sizeof(__u32);
278 int i;
279 __u32 *ciphers = nla_data(tb_msg[NL80211_ATTR_CIPHER_SUITES]);
280 if (num > 0) {
281 printf("\tSupported Ciphers:\n");
282 for (i = 0; i < num; i++)
283 printf("\t\t* %s\n",
284 cipher_name(ciphers[i]));
285 }
286 }
287
afce7986
BR
288 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] &&
289 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])
290 printf("\tAvailable Antennas: TX %#x RX %#x\n",
291 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]),
292 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]));
293
294 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
295 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])
296 printf("\tConfigured Antennas: TX %#x RX %#x\n",
297 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
298 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
299
9a4a14bd
JB
300 if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
301 printf("\tSupported interface modes:\n");
302 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
8ef6df4f 303 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
9a4a14bd 304 }
6367e71a 305
1c5b4a82
JB
306 if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) {
307 printf("\tsoftware interface modes (can always be added):\n");
308 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode)
309 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
310 }
311
312 if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) {
313 struct nlattr *nl_combi;
314 int rem_combi;
f5f6f15f 315 bool have_combinations = false;
1c5b4a82
JB
316
317 nla_for_each_nested(nl_combi, tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS], rem_combi) {
318 static struct nla_policy iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
319 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
320 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
321 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
322 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
c5df9eb6 323 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1c5b4a82
JB
324 };
325 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
326 static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
327 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
328 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
329 };
330 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
331 struct nlattr *nl_limit;
332 int err, rem_limit;
333 bool comma = false;
334
f5f6f15f
JB
335 if (!have_combinations) {
336 printf("\tvalid interface combinations:\n");
337 have_combinations = true;
338 }
339
1c5b4a82
JB
340 printf("\t\t * ");
341
342 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
343 nl_combi, iface_combination_policy);
344 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
345 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
346 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) {
347 printf(" <failed to parse>\n");
348 goto broken_combination;
349 }
350
351 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) {
352 bool ift_comma = false;
353
354 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
355 nl_limit, iface_limit_policy);
356 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) {
357 printf("<failed to parse>\n");
358 goto broken_combination;
359 }
360
361 if (comma)
362 printf(", ");
363 comma = true;
364 printf("#{");
365
366 nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) {
367 printf("%s %s", ift_comma ? "," : "",
368 iftype_name(nla_type(nl_mode)));
369 ift_comma = true;
370 }
371 printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX]));
372 }
373 printf(",\n\t\t ");
374
c5df9eb6 375 printf("total <= %d, #channels <= %d%s",
1c5b4a82
JB
376 nla_get_u32(tb_comb[NL80211_IFACE_COMB_MAXNUM]),
377 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]),
378 tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH] ?
379 ", STA/AP BI must match" : "");
c5df9eb6
SW
380 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) {
381 unsigned long widths = nla_get_u32(tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]);
382
383 if (widths) {
384 int width;
385 bool first = true;
386
387 printf(", radar detect widths: {");
388 for (width = 0; width < 32; width++)
389 if (widths & (1 << width)) {
390 printf("%s %s",
391 first ? "":",",
392 channel_width_name(width));
393 first = false;
394 }
395 printf(" }\n");
396 }
397 }
398 printf("\n");
1c5b4a82
JB
399broken_combination:
400 ;
401 }
f5f6f15f
JB
402
403 if (!have_combinations)
404 printf("\tinterface combinations are not supported\n");
1c5b4a82
JB
405 }
406
9a4a14bd
JB
407 if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) {
408 printf("\tSupported commands:\n");
409 nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd)
410 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd)));
411 }
6367e71a 412
9a4a14bd
JB
413 if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) {
414 printf("\tSupported TX frame types:\n");
415 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) {
416 bool printed = false;
417 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
418 if (!printed)
419 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
420 printed = true;
58e34341 421 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
422 }
423 if (printed)
424 printf("\n");
425 }
426 }
9990c1e9 427
9a4a14bd
JB
428 if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) {
429 printf("\tSupported RX frame types:\n");
430 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) {
431 bool printed = false;
432 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
433 if (!printed)
434 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
435 printed = true;
58e34341 436 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
437 }
438 if (printed)
439 printf("\n");
440 }
441 }
9990c1e9 442
3ff24563 443 if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN])
83f10169 444 printf("\tDevice supports RSN-IBSS.\n");
3ff24563
JB
445
446 if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) {
447 struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG];
448 static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
449 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
450 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
451 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
1c8f49c5 452 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .minlen = 12 },
3a6636b1
JB
453 [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED] = { .type = NLA_FLAG },
454 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
455 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
456 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
457 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
819b78cc 458 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
3ff24563 459 };
c82868da 460 struct nl80211_pattern_support *pat;
3ff24563
JB
461 int err;
462
463 err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG,
464 tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED],
465 wowlan_policy);
466 printf("\tWoWLAN support:");
467 if (err) {
468 printf(" <failed to parse>\n");
469 } else {
470 printf("\n");
471 if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY])
3a6636b1 472 printf("\t\t * wake up on anything (device continues operating normally)\n");
3ff24563 473 if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT])
3a6636b1 474 printf("\t\t * wake up on disconnect\n");
3ff24563 475 if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT])
3a6636b1 476 printf("\t\t * wake up on magic packet\n");
3ff24563
JB
477 if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
478 pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
1c8f49c5
AK
479 printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n"
480 "\t\t maximum packet offset %u bytes\n",
481 pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len,
482 (nla_len(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) <
483 sizeof(*pat)) ? 0 : pat->max_pkt_offset);
3ff24563 484 }
3a6636b1
JB
485 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
486 printf("\t\t * can do GTK rekeying\n");
487 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
488 printf("\t\t * wake up on GTK rekey failure\n");
489 if (tb_wowlan[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
490 printf("\t\t * wake up on EAP identity request\n");
491 if (tb_wowlan[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
492 printf("\t\t * wake up on 4-way handshake\n");
493 if (tb_wowlan[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
494 printf("\t\t * wake up on rfkill release\n");
819b78cc
JB
495 if (tb_wowlan[NL80211_WOWLAN_TRIG_TCP_CONNECTION])
496 printf("\t\t * wake up on TCP connection\n");
3ff24563 497 }
83f10169
JB
498 }
499
2e4f65ca
JB
500 if (tb_msg[NL80211_ATTR_ROAM_SUPPORT])
501 printf("\tDevice supports roaming.\n");
502
8b469995
JB
503 if (tb_msg[NL80211_ATTR_SUPPORT_AP_UAPSD])
504 printf("\tDevice supports AP-side u-APSD.\n");
505
a82abc2c
BG
506 if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) {
507 struct ieee80211_ht_cap *cm;
508 printf("\tHT Capability overrides:\n");
509 if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) {
510 cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
511 printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx"
512 " %02hhx %02hhx %02hhx %02hhx\n",
513 cm->mcs.rx_mask[0], cm->mcs.rx_mask[1],
514 cm->mcs.rx_mask[2], cm->mcs.rx_mask[3],
515 cm->mcs.rx_mask[4], cm->mcs.rx_mask[5],
516 cm->mcs.rx_mask[6], cm->mcs.rx_mask[7],
517 cm->mcs.rx_mask[8], cm->mcs.rx_mask[9]);
518 if (cm->cap_info & htole16(IEEE80211_HT_CAP_MAX_AMSDU))
519 printf("\t\t * maximum A-MSDU length\n");
520 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SUP_WIDTH_20_40))
521 printf("\t\t * supported channel width\n");
522 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SGI_40))
523 printf("\t\t * short GI for 40 MHz\n");
524 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_FACTOR)
525 printf("\t\t * max A-MPDU length exponent\n");
526 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_DENSITY)
527 printf("\t\t * min MPDU start spacing\n");
528 } else {
529 printf("\tERROR: capabilities mask is too short, expected: %d, received: %d\n",
530 (int)(sizeof(*cm)),
531 (int)(nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK])));
532 }
533 }
534
632004a0 535 if (tb_msg[NL80211_ATTR_FEATURE_FLAGS]) {
d28df6b4
JB
536 unsigned int features = nla_get_u32(tb_msg[NL80211_ATTR_FEATURE_FLAGS]);
537
538 if (features & NL80211_FEATURE_SK_TX_STATUS)
632004a0 539 printf("\tDevice supports TX status socket option.\n");
d28df6b4 540 if (features & NL80211_FEATURE_HT_IBSS)
632004a0 541 printf("\tDevice supports HT-IBSS.\n");
d28df6b4
JB
542 if (features & NL80211_FEATURE_INACTIVITY_TIMER)
543 printf("\tDevice has client inactivity timer.\n");
544 if (features & NL80211_FEATURE_CELL_BASE_REG_HINTS)
545 printf("\tDevice accepts cell base station regulatory hints.\n");
546 if (features & NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL)
547 printf("\tP2P Device uses a channel (of the concurrent ones)\n");
5973e65b
JB
548 if (features & NL80211_FEATURE_SAE)
549 printf("\tDevice supports SAE with AUTHENTICATE command\n");
fe862239
SL
550 if (features & NL80211_FEATURE_LOW_PRIORITY_SCAN)
551 printf("\tDevice supports low priority scan.\n");
552 if (features & NL80211_FEATURE_SCAN_FLUSH)
553 printf("\tDevice supports scan flush.\n");
afa2be2f
AQ
554 if (features & NL80211_FEATURE_AP_SCAN)
555 printf("\tDevice supports AP scan.\n");
5973e65b
JB
556 if (features & NL80211_FEATURE_VIF_TXPOWER)
557 printf("\tDevice supports per-vif TX power setting\n");
558 if (features & NL80211_FEATURE_NEED_OBSS_SCAN)
559 printf("\tUserspace should do OBSS scan and generate 20/40 coex reports\n");
560 if (features & NL80211_FEATURE_P2P_GO_CTWIN)
561 printf("\tP2P GO supports CT window setting\n");
562 if (features & NL80211_FEATURE_P2P_GO_OPPPS)
563 printf("\tP2P GO supports opportunistic powersave setting\n");
564 if (features & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
565 printf("\tDriver supports full state transitions for AP/GO clients\n");
566 if (features & NL80211_FEATURE_USERSPACE_MPM)
567 printf("\tDriver supports a userspace MPM\n");
568 if (features & NL80211_FEATURE_ACTIVE_MONITOR)
569 printf("\tDevice supports active monitor (which will ACK incoming frames)\n");
570 if (features & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
571 printf("\tDriver/device bandwidth changes during BSS lifetime (AP/GO mode)\n");
572 if (features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
573 printf("\tDevice adds DS IE to probe requests\n");
574 if (features & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
575 printf("\tDevice adds WFA TPC Report IE to probe requests\n");
576 if (features & NL80211_FEATURE_QUIET)
577 printf("\tDevice supports quiet requests from AP\n");
578 if (features & NL80211_FEATURE_TX_POWER_INSERTION)
579 printf("\tDevice can update TPC Report IE\n");
e642142d
LB
580 if (features & NL80211_FEATURE_ACKTO_ESTIMATION)
581 printf("\tDevice supports ACK timeout estimation.\n");
5973e65b
JB
582 if (features & NL80211_FEATURE_STATIC_SMPS)
583 printf("\tDevice supports static SMPS\n");
584 if (features & NL80211_FEATURE_DYNAMIC_SMPS)
585 printf("\tDevice supports dynamic SMPS\n");
ced5522d
BG
586 if (features & NL80211_FEATURE_MAC_ON_CREATE)
587 printf("\tDevice supports configuring vdev MAC-addr on create.\n");
632004a0
JB
588 }
589
9b4a1989
JB
590 if (tb_msg[NL80211_ATTR_TDLS_SUPPORT])
591 printf("\tDevice supports T-DLS.\n");
592
aa0f5dbe
AK
593 if (tb_msg[NL80211_ATTR_COALESCE_RULE]) {
594 struct nl80211_coalesce_rule_support *rule;
595 struct nl80211_pattern_support *pat;
596
597 printf("\tCoalesce support:\n");
598 rule = nla_data(tb_msg[NL80211_ATTR_COALESCE_RULE]);
599 pat = &rule->pat;
600 printf("\t\t * Maximum %u coalesce rules supported\n"
601 "\t\t * Each rule contains upto %u patterns of %u-%u bytes,\n"
602 "\t\t maximum packet offset %u bytes\n"
603 "\t\t * Maximum supported coalescing delay %u msecs\n",
604 rule->max_rules, pat->max_patterns, pat->min_pattern_len,
605 pat->max_pattern_len, pat->max_pkt_offset, rule->max_delay);
606 }
607
79f99b9a
JB
608 return NL_SKIP;
609}
610
c142fa28
JB
611static bool nl80211_has_split_wiphy = false;
612
7c37a24d
JB
613static int handle_info(struct nl80211_state *state,
614 struct nl_cb *cb,
d631650b 615 struct nl_msg *msg,
05514f95
JB
616 int argc, char **argv,
617 enum id_input id)
79f99b9a 618{
c142fa28
JB
619 char *feat_args[] = { "features", "-q" };
620 int err;
621
622 err = handle_cmd(state, CIB_NONE, 2, feat_args);
623 if (!err && nl80211_has_split_wiphy) {
624 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
625 nlmsg_hdr(msg)->nlmsg_flags |= NLM_F_DUMP;
626 }
627
79f99b9a 628 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL);
79f99b9a 629
70391ccf 630 return 0;
79f99b9a 631}
c142fa28 632__COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info,
1633ddf7 633 "Show capabilities for the specified wireless device.", NULL);
ea35fc0b
JB
634TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info,
635 "List all wireless devices and their capabilities.");
01ae06f9 636TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL);
bcdff0b2
JB
637
638static int handle_commands(struct nl80211_state *state,
639 struct nl_cb *cb, struct nl_msg *msg,
640 int argc, char **argv, enum id_input id)
641{
642 int i;
643 for (i = 1; i < NL80211_CMD_MAX; i++)
644 printf("%d (0x%x): %s\n", i, i, command_name(i));
645 /* don't send netlink messages */
646 return 2;
647}
648TOPLEVEL(commands, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_NONE, handle_commands,
649 "list all known commands and their decimal & hex value");
fb70e110
JB
650
651static int print_feature_handler(struct nl_msg *msg, void *arg)
652{
653 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
654 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
c142fa28
JB
655 bool print = (unsigned long)arg;
656#define maybe_printf(...) do { if (print) printf(__VA_ARGS__); } while (0)
fb70e110
JB
657
658 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
659 genlmsg_attrlen(gnlh, 0), NULL);
660
661 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) {
662 uint32_t feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
663
c142fa28
JB
664 maybe_printf("nl80211 features: 0x%x\n", feat);
665 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) {
666 maybe_printf("\t* split wiphy dump\n");
667 nl80211_has_split_wiphy = true;
668 }
fb70e110
JB
669 }
670
671 return NL_SKIP;
672}
673
674static int handle_features(struct nl80211_state *state,
675 struct nl_cb *cb, struct nl_msg *msg,
676 int argc, char **argv, enum id_input id)
677{
c142fa28
JB
678 unsigned long print = argc == 0 || strcmp(argv[0], "-q");
679 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_feature_handler, (void *)print);
fb70e110
JB
680 return 0;
681}
682
c142fa28 683TOPLEVEL(features, "", NL80211_CMD_GET_PROTOCOL_FEATURES, 0, CIB_NONE,
fb70e110 684 handle_features, "");