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