]> git.ipfire.org Git - thirdparty/iw.git/blame - info.c
iw: add radar detect widths to phy info
[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
79f99b9a
JB
52static int print_phy_handler(struct nl_msg *msg, void *arg)
53{
54 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
55 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
56
57 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
58
59 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
60 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
61 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
62 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
63 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
64 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
65 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
c1081c20 66 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
79f99b9a
JB
67 };
68
69 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
70 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
71 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
72 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
73 };
74
75 struct nlattr *nl_band;
76 struct nlattr *nl_freq;
77 struct nlattr *nl_rate;
6367e71a 78 struct nlattr *nl_mode;
9990c1e9 79 struct nlattr *nl_cmd;
9a4a14bd 80 struct nlattr *nl_if, *nl_ftype;
79f99b9a 81 int bandidx = 1;
9a4a14bd 82 int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if;
79f99b9a
JB
83 int open;
84
85 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
86 genlmsg_attrlen(gnlh, 0), NULL);
87
88 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
89 return NL_SKIP;
90
d631650b
JB
91 if (tb_msg[NL80211_ATTR_WIPHY_NAME])
92 printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME]));
93
79f99b9a 94 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
d631650b 95 printf("\tBand %d:\n", bandidx);
79f99b9a
JB
96 bandidx++;
97
98 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
99 nla_len(nl_band), NULL);
100
3dd781cc 101 if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) {
357c1a5d
LR
102 __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]);
103 print_ht_capability(cap);
3dd781cc
JB
104 }
105 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) {
0950993f
LR
106 __u8 exponent = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]);
107 print_ampdu_length(exponent);
3dd781cc
JB
108 }
109 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) {
0950993f
LR
110 __u8 spacing = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]);
111 print_ampdu_spacing(spacing);
3dd781cc
JB
112 }
113 if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] &&
7ddfb679
JB
114 nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16)
115 print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]));
54eb1613
JB
116 if (tb_band[NL80211_BAND_ATTR_VHT_CAPA] &&
117 tb_band[NL80211_BAND_ATTR_VHT_MCS_SET])
118 print_vht_info(nla_get_u32(tb_band[NL80211_BAND_ATTR_VHT_CAPA]),
119 nla_data(tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]));
3dd781cc 120
d631650b 121 printf("\t\tFrequencies:\n");
79f99b9a
JB
122
123 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
379f8397 124 uint32_t freq;
79f99b9a
JB
125 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
126 nla_len(nl_freq), freq_policy);
127 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
128 continue;
379f8397
JB
129 freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
130 printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq));
c1081c20 131
d102c0b6
JB
132 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
133 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
134 printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]));
c1081c20 135
79f99b9a 136 open = 0;
ee9cd987 137 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) {
79f99b9a 138 print_flag("disabled", &open);
ee9cd987
JB
139 goto next;
140 }
79f99b9a
JB
141 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
142 print_flag("passive scanning", &open);
143 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
144 print_flag("no IBSS", &open);
145 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
146 print_flag("radar detection", &open);
ee9cd987 147 next:
79f99b9a
JB
148 if (open)
149 printf(")");
150 printf("\n");
151 }
152
75dddccc 153 printf("\t\tBitrates (non-HT):\n");
79f99b9a
JB
154
155 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
156 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
157 nla_len(nl_rate), rate_policy);
158 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
159 continue;
d631650b 160 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
79f99b9a
JB
161 open = 0;
162 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
163 print_flag("short preamble supported", &open);
164 if (open)
165 printf(")");
166 printf("\n");
167 }
168 }
169
41be37f2
JB
170 if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])
171 printf("\tmax # scan SSIDs: %d\n",
172 nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]));
f9c112b6
JB
173 if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])
174 printf("\tmax scan IEs length: %d bytes\n",
8eaa9ee5 175 nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]));
41be37f2 176
625aa4ae
JB
177 if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
178 unsigned int frag;
179
180 frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
181 if (frag != (unsigned int)-1)
182 printf("\tFragmentation threshold: %d\n", frag);
183 }
184
185 if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
186 unsigned int rts;
187
188 rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
189 if (rts != (unsigned int)-1)
190 printf("\tRTS threshold: %d\n", rts);
191 }
192
b2f92dd0
LT
193 if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
194 unsigned char coverage;
195
196 coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
197 /* See handle_distance() for an explanation where the '450' comes from */
198 printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
199 }
200
810e05c3
JB
201 if (tb_msg[NL80211_ATTR_CIPHER_SUITES]) {
202 int num = nla_len(tb_msg[NL80211_ATTR_CIPHER_SUITES]) / sizeof(__u32);
203 int i;
204 __u32 *ciphers = nla_data(tb_msg[NL80211_ATTR_CIPHER_SUITES]);
205 if (num > 0) {
206 printf("\tSupported Ciphers:\n");
207 for (i = 0; i < num; i++)
208 printf("\t\t* %s\n",
209 cipher_name(ciphers[i]));
210 }
211 }
212
afce7986
BR
213 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] &&
214 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])
215 printf("\tAvailable Antennas: TX %#x RX %#x\n",
216 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]),
217 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]));
218
219 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
220 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])
221 printf("\tConfigured Antennas: TX %#x RX %#x\n",
222 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
223 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
224
9a4a14bd
JB
225 if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
226 printf("\tSupported interface modes:\n");
227 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
8ef6df4f 228 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
9a4a14bd 229 }
6367e71a 230
1c5b4a82
JB
231 if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) {
232 printf("\tsoftware interface modes (can always be added):\n");
233 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode)
234 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
235 }
236
237 if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) {
238 struct nlattr *nl_combi;
239 int rem_combi;
f5f6f15f 240 bool have_combinations = false;
1c5b4a82
JB
241
242 nla_for_each_nested(nl_combi, tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS], rem_combi) {
243 static struct nla_policy iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
244 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
245 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
246 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
247 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
c5df9eb6 248 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
1c5b4a82
JB
249 };
250 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
251 static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
252 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
253 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
254 };
255 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
256 struct nlattr *nl_limit;
257 int err, rem_limit;
258 bool comma = false;
259
f5f6f15f
JB
260 if (!have_combinations) {
261 printf("\tvalid interface combinations:\n");
262 have_combinations = true;
263 }
264
1c5b4a82
JB
265 printf("\t\t * ");
266
267 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
268 nl_combi, iface_combination_policy);
269 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
270 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
271 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) {
272 printf(" <failed to parse>\n");
273 goto broken_combination;
274 }
275
276 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) {
277 bool ift_comma = false;
278
279 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
280 nl_limit, iface_limit_policy);
281 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) {
282 printf("<failed to parse>\n");
283 goto broken_combination;
284 }
285
286 if (comma)
287 printf(", ");
288 comma = true;
289 printf("#{");
290
291 nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) {
292 printf("%s %s", ift_comma ? "," : "",
293 iftype_name(nla_type(nl_mode)));
294 ift_comma = true;
295 }
296 printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX]));
297 }
298 printf(",\n\t\t ");
299
c5df9eb6 300 printf("total <= %d, #channels <= %d%s",
1c5b4a82
JB
301 nla_get_u32(tb_comb[NL80211_IFACE_COMB_MAXNUM]),
302 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]),
303 tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH] ?
304 ", STA/AP BI must match" : "");
c5df9eb6
SW
305 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) {
306 unsigned long widths = nla_get_u32(tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]);
307
308 if (widths) {
309 int width;
310 bool first = true;
311
312 printf(", radar detect widths: {");
313 for (width = 0; width < 32; width++)
314 if (widths & (1 << width)) {
315 printf("%s %s",
316 first ? "":",",
317 channel_width_name(width));
318 first = false;
319 }
320 printf(" }\n");
321 }
322 }
323 printf("\n");
1c5b4a82
JB
324broken_combination:
325 ;
326 }
f5f6f15f
JB
327
328 if (!have_combinations)
329 printf("\tinterface combinations are not supported\n");
1c5b4a82
JB
330 }
331
9a4a14bd
JB
332 if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) {
333 printf("\tSupported commands:\n");
334 nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd)
335 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd)));
336 }
6367e71a 337
9a4a14bd
JB
338 if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) {
339 printf("\tSupported TX frame types:\n");
340 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) {
341 bool printed = false;
342 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
343 if (!printed)
344 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
345 printed = true;
58e34341 346 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
347 }
348 if (printed)
349 printf("\n");
350 }
351 }
9990c1e9 352
9a4a14bd
JB
353 if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) {
354 printf("\tSupported RX frame types:\n");
355 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) {
356 bool printed = false;
357 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
358 if (!printed)
359 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
360 printed = true;
58e34341 361 printf(" 0x%.2x", nla_get_u16(nl_ftype));
9a4a14bd
JB
362 }
363 if (printed)
364 printf("\n");
365 }
366 }
9990c1e9 367
3ff24563 368 if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN])
83f10169 369 printf("\tDevice supports RSN-IBSS.\n");
3ff24563
JB
370
371 if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) {
372 struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG];
373 static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
374 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
375 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
376 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = {
378 .minlen = sizeof(struct nl80211_wowlan_pattern_support),
379 },
3a6636b1
JB
380 [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
3ff24563
JB
385 };
386 struct nl80211_wowlan_pattern_support *pat;
387 int err;
388
389 err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG,
390 tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED],
391 wowlan_policy);
392 printf("\tWoWLAN support:");
393 if (err) {
394 printf(" <failed to parse>\n");
395 } else {
396 printf("\n");
397 if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY])
3a6636b1 398 printf("\t\t * wake up on anything (device continues operating normally)\n");
3ff24563 399 if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT])
3a6636b1 400 printf("\t\t * wake up on disconnect\n");
3ff24563 401 if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT])
3a6636b1 402 printf("\t\t * wake up on magic packet\n");
3ff24563
JB
403 if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
404 pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
3a6636b1 405 printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes\n",
3ff24563
JB
406 pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len);
407 }
3a6636b1
JB
408 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
409 printf("\t\t * can do GTK rekeying\n");
410 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
411 printf("\t\t * wake up on GTK rekey failure\n");
412 if (tb_wowlan[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
413 printf("\t\t * wake up on EAP identity request\n");
414 if (tb_wowlan[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
415 printf("\t\t * wake up on 4-way handshake\n");
416 if (tb_wowlan[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
417 printf("\t\t * wake up on rfkill release\n");
3ff24563 418 }
83f10169
JB
419 }
420
2e4f65ca
JB
421 if (tb_msg[NL80211_ATTR_ROAM_SUPPORT])
422 printf("\tDevice supports roaming.\n");
423
8b469995
JB
424 if (tb_msg[NL80211_ATTR_SUPPORT_AP_UAPSD])
425 printf("\tDevice supports AP-side u-APSD.\n");
426
a82abc2c
BG
427 if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) {
428 struct ieee80211_ht_cap *cm;
429 printf("\tHT Capability overrides:\n");
430 if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) {
431 cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
432 printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx"
433 " %02hhx %02hhx %02hhx %02hhx\n",
434 cm->mcs.rx_mask[0], cm->mcs.rx_mask[1],
435 cm->mcs.rx_mask[2], cm->mcs.rx_mask[3],
436 cm->mcs.rx_mask[4], cm->mcs.rx_mask[5],
437 cm->mcs.rx_mask[6], cm->mcs.rx_mask[7],
438 cm->mcs.rx_mask[8], cm->mcs.rx_mask[9]);
439 if (cm->cap_info & htole16(IEEE80211_HT_CAP_MAX_AMSDU))
440 printf("\t\t * maximum A-MSDU length\n");
441 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SUP_WIDTH_20_40))
442 printf("\t\t * supported channel width\n");
443 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SGI_40))
444 printf("\t\t * short GI for 40 MHz\n");
445 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_FACTOR)
446 printf("\t\t * max A-MPDU length exponent\n");
447 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_DENSITY)
448 printf("\t\t * min MPDU start spacing\n");
449 } else {
450 printf("\tERROR: capabilities mask is too short, expected: %d, received: %d\n",
451 (int)(sizeof(*cm)),
452 (int)(nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK])));
453 }
454 }
455
632004a0 456 if (tb_msg[NL80211_ATTR_FEATURE_FLAGS]) {
d28df6b4
JB
457 unsigned int features = nla_get_u32(tb_msg[NL80211_ATTR_FEATURE_FLAGS]);
458
459 if (features & NL80211_FEATURE_SK_TX_STATUS)
632004a0 460 printf("\tDevice supports TX status socket option.\n");
d28df6b4 461 if (features & NL80211_FEATURE_HT_IBSS)
632004a0 462 printf("\tDevice supports HT-IBSS.\n");
d28df6b4
JB
463 if (features & NL80211_FEATURE_INACTIVITY_TIMER)
464 printf("\tDevice has client inactivity timer.\n");
465 if (features & NL80211_FEATURE_CELL_BASE_REG_HINTS)
466 printf("\tDevice accepts cell base station regulatory hints.\n");
467 if (features & NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL)
468 printf("\tP2P Device uses a channel (of the concurrent ones)\n");
fe862239
SL
469 if (features & NL80211_FEATURE_LOW_PRIORITY_SCAN)
470 printf("\tDevice supports low priority scan.\n");
471 if (features & NL80211_FEATURE_SCAN_FLUSH)
472 printf("\tDevice supports scan flush.\n");
afa2be2f
AQ
473 if (features & NL80211_FEATURE_AP_SCAN)
474 printf("\tDevice supports AP scan.\n");
632004a0
JB
475 }
476
79f99b9a
JB
477 return NL_SKIP;
478}
479
7c37a24d
JB
480static int handle_info(struct nl80211_state *state,
481 struct nl_cb *cb,
d631650b 482 struct nl_msg *msg,
05514f95
JB
483 int argc, char **argv,
484 enum id_input id)
79f99b9a 485{
79f99b9a 486 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL);
79f99b9a 487
70391ccf 488 return 0;
79f99b9a 489}
4698bfc2 490__COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info,
1633ddf7 491 "Show capabilities for the specified wireless device.", NULL);
ea35fc0b
JB
492TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info,
493 "List all wireless devices and their capabilities.");
01ae06f9 494TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL);
bcdff0b2
JB
495
496static int handle_commands(struct nl80211_state *state,
497 struct nl_cb *cb, struct nl_msg *msg,
498 int argc, char **argv, enum id_input id)
499{
500 int i;
501 for (i = 1; i < NL80211_CMD_MAX; i++)
502 printf("%d (0x%x): %s\n", i, i, command_name(i));
503 /* don't send netlink messages */
504 return 2;
505}
506TOPLEVEL(commands, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_NONE, handle_commands,
507 "list all known commands and their decimal & hex value");