blob: 66887e38a81abc7d8e942dca72df13fadac53e47 [file] [log] [blame]
Luis R. Rodriguez21878f32009-02-02 15:39:06 -08001#include <stdbool.h>
Johannes Berg79f99b92008-01-16 00:21:59 +01002#include <errno.h>
Johannes Berg2ef1be62008-04-02 17:40:11 +02003#include <net/if.h>
4
Johannes Berg79f99b92008-01-16 00:21:59 +01005#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>
Johannes Berg79f99b92008-01-16 00:21:59 +010010
Johannes Bergf408e012008-09-18 19:32:11 +020011#include "nl80211.h"
Johannes Berg79f99b92008-01-16 00:21:59 +010012#include "iw.h"
13
14static void print_flag(const char *name, int *open)
15{
16 if (!*open)
17 printf(" (");
18 else
19 printf(", ");
Johannes Berg69283122008-11-23 20:55:23 +010020 printf("%s", name);
Johannes Berg79f99b92008-01-16 00:21:59 +010021 *open = 1;
22}
23
Johannes Berg810e05c2011-10-05 17:38:39 +020024static 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)";
Vladimir Kondratieva8b3da92012-07-05 14:36:20 +030039 case 0x000fac08:
40 return "GCMP (00-0f-ac:8)";
Johannes Berg810e05c2011-10-05 17:38:39 +020041 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
Simon Wunderlich48aaf2d2013-02-08 18:16:22 +010052static 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
Johannes Berg79f99b92008-01-16 00:21:59 +010066static 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 },
Ilan Peerf0c48e72013-11-14 09:15:34 +020077 [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG },
78 [__NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
Johannes Berg79f99b92008-01-16 00:21:59 +010079 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
Johannes Bergc1081c22008-11-23 12:11:26 +010080 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
Johannes Berg79f99b92008-01-16 00:21:59 +010081 };
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;
Johannes Berg6367e712008-09-05 23:01:11 +020092 struct nlattr *nl_mode;
Marcel Holtmann9990c1e2009-11-14 20:10:21 +010093 struct nlattr *nl_cmd;
Johannes Berg9a4a14b2010-08-24 12:26:56 +020094 struct nlattr *nl_if, *nl_ftype;
Johannes Berg9a4a14b2010-08-24 12:26:56 +020095 int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if;
Johannes Berg79f99b92008-01-16 00:21:59 +010096 int open;
Johannes Bergfb70e112013-02-14 16:32:53 +010097 /*
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;
Johannes Berg79f99b92008-01-16 00:21:59 +0100106
107 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
108 genlmsg_attrlen(gnlh, 0), NULL);
109
Johannes Bergfb70e112013-02-14 16:32:53 +0100110 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])
Johannes Bergd6316502008-09-16 17:05:33 +0200118 printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME]));
119
Johannes Bergfb70e112013-02-14 16:32:53 +0100120 /* 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;
Johannes Bergee9cd982009-01-18 18:13:54 +0100126 }
Johannes Bergfb70e112013-02-14 16:32:53 +0100127 last_band = nl_band->nla_type;
Simon Wunderlich48aaf2d2013-02-08 18:16:22 +0100128
Johannes Bergfb70e112013-02-14 16:32:53 +0100129 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
130 nla_len(nl_band), NULL);
Simon Wunderlich48aaf2d2013-02-08 18:16:22 +0100131
Johannes Bergfb70e112013-02-14 16:32:53 +0100132 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;
Simon Wunderlich48aaf2d2013-02-08 18:16:22 +0100156 }
Johannes Bergfb70e112013-02-14 16:32:53 +0100157 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 }
Ilan Peerf0c48e72013-11-14 09:15:34 +0200175
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
Johannes Bergfb70e112013-02-14 16:32:53 +0100185 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
186 print_flag("radar detection", &open);
187next:
188 if (open)
189 printf(")");
190 printf("\n");
191
Zefir Kurtisi4b99e6a2013-03-26 12:09:49 +0100192 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;
Johannes Bergfb70e112013-02-14 16:32:53 +0100195
Zefir Kurtisi4b99e6a2013-03-26 12:09:49 +0100196 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");
Janusz Dziedzic82207472014-05-09 10:19:55 +0200202 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]));
Johannes Bergfb70e112013-02-14 16:32:53 +0100205 }
Zefir Kurtisi4b99e6a2013-03-26 12:09:49 +0100206
Johannes Bergfb70e112013-02-14 16:32:53 +0100207 }
208 }
209
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(")");
Simon Wunderlich48aaf2d2013-02-08 18:16:22 +0100223 printf("\n");
224 }
Johannes Bergfb70e112013-02-14 16:32:53 +0100225 }
Johannes Berg79f99b92008-01-16 00:21:59 +0100226 }
227 }
228
Johannes Berg41be37f2008-09-19 17:34:55 +0200229 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]));
Johannes Bergf9c112b2010-03-24 23:28:03 -0700232 if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])
233 printf("\tmax scan IEs length: %d bytes\n",
Johannes Berg8eaa9ee2010-09-26 09:12:07 +0200234 nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]));
Luciano Coelho3fce58a2015-03-17 16:11:48 +0200235 if (tb_msg[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS])
236 printf("\tmax # sched scan SSIDs: %d\n",
237 nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]));
238 if (tb_msg[NL80211_ATTR_MAX_MATCH_SETS])
239 printf("\tmax # match sets: %d\n",
240 nla_get_u8(tb_msg[NL80211_ATTR_MAX_MATCH_SETS]));
Johannes Berg41be37f2008-09-19 17:34:55 +0200241
Johannes Berg625aa4a2009-08-11 11:26:42 +0200242 if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
243 unsigned int frag;
244
245 frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
246 if (frag != (unsigned int)-1)
247 printf("\tFragmentation threshold: %d\n", frag);
248 }
249
250 if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
251 unsigned int rts;
252
253 rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
254 if (rts != (unsigned int)-1)
255 printf("\tRTS threshold: %d\n", rts);
256 }
257
Ujjal Royc993e6e2014-03-07 12:23:38 +0530258 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT] ||
259 tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]) {
260 unsigned char retry_short = 0, retry_long = 0;
261
262 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT])
263 retry_short = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_SHORT]);
264 if (tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG])
265 retry_long = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_RETRY_LONG]);
266 if (retry_short == retry_long) {
267 printf("\tRetry short long limit: %d\n", retry_short);
268 } else {
269 printf("\tRetry short limit: %d\n", retry_short);
270 printf("\tRetry long limit: %d\n", retry_long);
271 }
272 }
273
Lukáš Turekb2f92dd2010-02-17 21:13:23 -0500274 if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
275 unsigned char coverage;
276
277 coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
278 /* See handle_distance() for an explanation where the '450' comes from */
279 printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
280 }
281
Johannes Berg810e05c2011-10-05 17:38:39 +0200282 if (tb_msg[NL80211_ATTR_CIPHER_SUITES]) {
283 int num = nla_len(tb_msg[NL80211_ATTR_CIPHER_SUITES]) / sizeof(__u32);
284 int i;
285 __u32 *ciphers = nla_data(tb_msg[NL80211_ATTR_CIPHER_SUITES]);
286 if (num > 0) {
287 printf("\tSupported Ciphers:\n");
288 for (i = 0; i < num; i++)
289 printf("\t\t* %s\n",
290 cipher_name(ciphers[i]));
291 }
292 }
293
Bruno Randolfafce7982010-12-22 10:54:39 +0900294 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] &&
295 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])
296 printf("\tAvailable Antennas: TX %#x RX %#x\n",
297 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]),
298 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]));
299
300 if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
301 tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])
302 printf("\tConfigured Antennas: TX %#x RX %#x\n",
303 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
304 nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
305
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200306 if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
307 printf("\tSupported interface modes:\n");
308 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
Johannes Berg8ef6df42011-02-21 22:12:54 +0100309 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200310 }
Johannes Berg6367e712008-09-05 23:01:11 +0200311
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200312 if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) {
313 printf("\tsoftware interface modes (can always be added):\n");
314 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode)
315 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
316 }
317
318 if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) {
319 struct nlattr *nl_combi;
320 int rem_combi;
Johannes Bergf5f6f152011-06-29 13:20:31 +0200321 bool have_combinations = false;
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200322
323 nla_for_each_nested(nl_combi, tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS], rem_combi) {
324 static struct nla_policy iface_combination_policy[NUM_NL80211_IFACE_COMB] = {
325 [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED },
326 [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 },
327 [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG },
328 [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 },
Simon Wunderlichc5df9eb2013-02-08 18:16:21 +0100329 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 },
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200330 };
331 struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB];
332 static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = {
333 [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED },
334 [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 },
335 };
336 struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT];
337 struct nlattr *nl_limit;
338 int err, rem_limit;
339 bool comma = false;
340
Johannes Bergf5f6f152011-06-29 13:20:31 +0200341 if (!have_combinations) {
342 printf("\tvalid interface combinations:\n");
343 have_combinations = true;
344 }
345
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200346 printf("\t\t * ");
347
348 err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB,
349 nl_combi, iface_combination_policy);
350 if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] ||
351 !tb_comb[NL80211_IFACE_COMB_MAXNUM] ||
352 !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) {
353 printf(" <failed to parse>\n");
354 goto broken_combination;
355 }
356
357 nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) {
358 bool ift_comma = false;
359
360 err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
361 nl_limit, iface_limit_policy);
362 if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) {
363 printf("<failed to parse>\n");
364 goto broken_combination;
365 }
366
367 if (comma)
368 printf(", ");
369 comma = true;
370 printf("#{");
371
372 nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) {
373 printf("%s %s", ift_comma ? "," : "",
374 iftype_name(nla_type(nl_mode)));
375 ift_comma = true;
376 }
377 printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX]));
378 }
379 printf(",\n\t\t ");
380
Simon Wunderlichc5df9eb2013-02-08 18:16:21 +0100381 printf("total <= %d, #channels <= %d%s",
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200382 nla_get_u32(tb_comb[NL80211_IFACE_COMB_MAXNUM]),
383 nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]),
384 tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH] ?
385 ", STA/AP BI must match" : "");
Simon Wunderlichc5df9eb2013-02-08 18:16:21 +0100386 if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) {
387 unsigned long widths = nla_get_u32(tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]);
388
389 if (widths) {
390 int width;
391 bool first = true;
392
393 printf(", radar detect widths: {");
394 for (width = 0; width < 32; width++)
395 if (widths & (1 << width)) {
396 printf("%s %s",
397 first ? "":",",
398 channel_width_name(width));
399 first = false;
400 }
401 printf(" }\n");
402 }
403 }
404 printf("\n");
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200405broken_combination:
406 ;
407 }
Johannes Bergf5f6f152011-06-29 13:20:31 +0200408
409 if (!have_combinations)
410 printf("\tinterface combinations are not supported\n");
Johannes Berg1c5b4a82011-05-13 16:53:51 +0200411 }
412
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200413 if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) {
414 printf("\tSupported commands:\n");
415 nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd)
416 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd)));
417 }
Johannes Berg6367e712008-09-05 23:01:11 +0200418
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200419 if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) {
420 printf("\tSupported TX frame types:\n");
421 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) {
422 bool printed = false;
423 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
424 if (!printed)
425 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
426 printed = true;
Johannes Berg58e34342012-03-13 09:48:23 +0100427 printf(" 0x%.2x", nla_get_u16(nl_ftype));
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200428 }
429 if (printed)
430 printf("\n");
431 }
432 }
Marcel Holtmann9990c1e2009-11-14 20:10:21 +0100433
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200434 if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) {
435 printf("\tSupported RX frame types:\n");
436 nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) {
437 bool printed = false;
438 nla_for_each_nested(nl_ftype, nl_if, rem_ftype) {
439 if (!printed)
440 printf("\t\t * %s:", iftype_name(nla_type(nl_if)));
441 printed = true;
Johannes Berg58e34342012-03-13 09:48:23 +0100442 printf(" 0x%.2x", nla_get_u16(nl_ftype));
Johannes Berg9a4a14b2010-08-24 12:26:56 +0200443 }
444 if (printed)
445 printf("\n");
446 }
447 }
Marcel Holtmann9990c1e2009-11-14 20:10:21 +0100448
Johannes Berg3ff24562011-04-12 13:04:50 +0200449 if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN])
Johannes Berg83f10162011-02-24 15:11:57 +0100450 printf("\tDevice supports RSN-IBSS.\n");
Johannes Berg3ff24562011-04-12 13:04:50 +0200451
452 if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) {
453 struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG];
454 static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
455 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
456 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
457 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
Amitkumar Karwar1c8f49c2013-02-19 16:44:44 -0800458 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .minlen = 12 },
Johannes Berg3a6636b2011-07-12 13:08:37 +0200459 [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED] = { .type = NLA_FLAG },
460 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
461 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
462 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
463 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Luciano Coelho4888e6b2015-01-13 16:19:15 +0200464 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_U32 },
Johannes Berg819b78c2013-02-19 23:31:27 +0100465 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Johannes Berg3ff24562011-04-12 13:04:50 +0200466 };
Amitkumar Karwarc82868d2013-06-28 12:53:44 -0700467 struct nl80211_pattern_support *pat;
Johannes Berg3ff24562011-04-12 13:04:50 +0200468 int err;
469
470 err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG,
471 tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED],
472 wowlan_policy);
473 printf("\tWoWLAN support:");
474 if (err) {
475 printf(" <failed to parse>\n");
476 } else {
477 printf("\n");
478 if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY])
Johannes Berg3a6636b2011-07-12 13:08:37 +0200479 printf("\t\t * wake up on anything (device continues operating normally)\n");
Johannes Berg3ff24562011-04-12 13:04:50 +0200480 if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT])
Johannes Berg3a6636b2011-07-12 13:08:37 +0200481 printf("\t\t * wake up on disconnect\n");
Johannes Berg3ff24562011-04-12 13:04:50 +0200482 if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT])
Johannes Berg3a6636b2011-07-12 13:08:37 +0200483 printf("\t\t * wake up on magic packet\n");
Johannes Berg3ff24562011-04-12 13:04:50 +0200484 if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
485 pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]);
Amitkumar Karwar1c8f49c2013-02-19 16:44:44 -0800486 printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes,\n"
487 "\t\t maximum packet offset %u bytes\n",
488 pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len,
489 (nla_len(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) <
490 sizeof(*pat)) ? 0 : pat->max_pkt_offset);
Johannes Berg3ff24562011-04-12 13:04:50 +0200491 }
Johannes Berg3a6636b2011-07-12 13:08:37 +0200492 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
493 printf("\t\t * can do GTK rekeying\n");
494 if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE])
495 printf("\t\t * wake up on GTK rekey failure\n");
496 if (tb_wowlan[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST])
497 printf("\t\t * wake up on EAP identity request\n");
498 if (tb_wowlan[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE])
499 printf("\t\t * wake up on 4-way handshake\n");
500 if (tb_wowlan[NL80211_WOWLAN_TRIG_RFKILL_RELEASE])
501 printf("\t\t * wake up on rfkill release\n");
Luciano Coelhod516c5b2014-11-28 23:05:55 +0200502 if (tb_wowlan[NL80211_WOWLAN_TRIG_NET_DETECT])
Luciano Coelho4888e6b2015-01-13 16:19:15 +0200503 printf("\t\t * wake up on network detection, up to %d match sets\n",
504 nla_get_u32(tb_wowlan[NL80211_WOWLAN_TRIG_NET_DETECT]));
Johannes Berg819b78c2013-02-19 23:31:27 +0100505 if (tb_wowlan[NL80211_WOWLAN_TRIG_TCP_CONNECTION])
506 printf("\t\t * wake up on TCP connection\n");
Johannes Berg3ff24562011-04-12 13:04:50 +0200507 }
Johannes Berg83f10162011-02-24 15:11:57 +0100508 }
509
Johannes Berg2e4f65c2011-10-04 14:00:47 +0200510 if (tb_msg[NL80211_ATTR_ROAM_SUPPORT])
511 printf("\tDevice supports roaming.\n");
512
Johannes Berg8b469992011-11-04 11:53:18 +0100513 if (tb_msg[NL80211_ATTR_SUPPORT_AP_UAPSD])
514 printf("\tDevice supports AP-side u-APSD.\n");
515
Ben Greeara82abc22011-11-28 10:40:22 -0800516 if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) {
517 struct ieee80211_ht_cap *cm;
518 printf("\tHT Capability overrides:\n");
519 if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) {
520 cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]);
521 printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx"
522 " %02hhx %02hhx %02hhx %02hhx\n",
523 cm->mcs.rx_mask[0], cm->mcs.rx_mask[1],
524 cm->mcs.rx_mask[2], cm->mcs.rx_mask[3],
525 cm->mcs.rx_mask[4], cm->mcs.rx_mask[5],
526 cm->mcs.rx_mask[6], cm->mcs.rx_mask[7],
527 cm->mcs.rx_mask[8], cm->mcs.rx_mask[9]);
528 if (cm->cap_info & htole16(IEEE80211_HT_CAP_MAX_AMSDU))
529 printf("\t\t * maximum A-MSDU length\n");
530 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SUP_WIDTH_20_40))
531 printf("\t\t * supported channel width\n");
532 if (cm->cap_info & htole16(IEEE80211_HT_CAP_SGI_40))
533 printf("\t\t * short GI for 40 MHz\n");
534 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_FACTOR)
535 printf("\t\t * max A-MPDU length exponent\n");
536 if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_DENSITY)
537 printf("\t\t * min MPDU start spacing\n");
538 } else {
539 printf("\tERROR: capabilities mask is too short, expected: %d, received: %d\n",
540 (int)(sizeof(*cm)),
541 (int)(nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK])));
542 }
543 }
544
Johannes Berg632004a2011-12-14 15:08:34 +0100545 if (tb_msg[NL80211_ATTR_FEATURE_FLAGS]) {
Johannes Bergd28df6b2012-10-16 20:12:37 +0200546 unsigned int features = nla_get_u32(tb_msg[NL80211_ATTR_FEATURE_FLAGS]);
547
548 if (features & NL80211_FEATURE_SK_TX_STATUS)
Johannes Berg632004a2011-12-14 15:08:34 +0100549 printf("\tDevice supports TX status socket option.\n");
Johannes Bergd28df6b2012-10-16 20:12:37 +0200550 if (features & NL80211_FEATURE_HT_IBSS)
Johannes Berg632004a2011-12-14 15:08:34 +0100551 printf("\tDevice supports HT-IBSS.\n");
Johannes Bergd28df6b2012-10-16 20:12:37 +0200552 if (features & NL80211_FEATURE_INACTIVITY_TIMER)
553 printf("\tDevice has client inactivity timer.\n");
554 if (features & NL80211_FEATURE_CELL_BASE_REG_HINTS)
555 printf("\tDevice accepts cell base station regulatory hints.\n");
556 if (features & NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL)
557 printf("\tP2P Device uses a channel (of the concurrent ones)\n");
Johannes Berg5973e652014-10-09 16:30:38 +0200558 if (features & NL80211_FEATURE_SAE)
559 printf("\tDevice supports SAE with AUTHENTICATE command\n");
Sam Lefflerfe862232012-10-17 12:20:04 -0700560 if (features & NL80211_FEATURE_LOW_PRIORITY_SCAN)
561 printf("\tDevice supports low priority scan.\n");
562 if (features & NL80211_FEATURE_SCAN_FLUSH)
563 printf("\tDevice supports scan flush.\n");
Antonio Quartulliafa2be22012-10-26 16:41:47 +0200564 if (features & NL80211_FEATURE_AP_SCAN)
565 printf("\tDevice supports AP scan.\n");
Johannes Berg5973e652014-10-09 16:30:38 +0200566 if (features & NL80211_FEATURE_VIF_TXPOWER)
567 printf("\tDevice supports per-vif TX power setting\n");
568 if (features & NL80211_FEATURE_NEED_OBSS_SCAN)
569 printf("\tUserspace should do OBSS scan and generate 20/40 coex reports\n");
570 if (features & NL80211_FEATURE_P2P_GO_CTWIN)
571 printf("\tP2P GO supports CT window setting\n");
572 if (features & NL80211_FEATURE_P2P_GO_OPPPS)
573 printf("\tP2P GO supports opportunistic powersave setting\n");
574 if (features & NL80211_FEATURE_FULL_AP_CLIENT_STATE)
575 printf("\tDriver supports full state transitions for AP/GO clients\n");
576 if (features & NL80211_FEATURE_USERSPACE_MPM)
577 printf("\tDriver supports a userspace MPM\n");
578 if (features & NL80211_FEATURE_ACTIVE_MONITOR)
579 printf("\tDevice supports active monitor (which will ACK incoming frames)\n");
580 if (features & NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)
581 printf("\tDriver/device bandwidth changes during BSS lifetime (AP/GO mode)\n");
582 if (features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES)
583 printf("\tDevice adds DS IE to probe requests\n");
584 if (features & NL80211_FEATURE_WFA_TPC_IE_IN_PROBES)
585 printf("\tDevice adds WFA TPC Report IE to probe requests\n");
586 if (features & NL80211_FEATURE_QUIET)
587 printf("\tDevice supports quiet requests from AP\n");
588 if (features & NL80211_FEATURE_TX_POWER_INSERTION)
589 printf("\tDevice can update TPC Report IE\n");
Lorenzo Bianconie6421422014-09-07 19:32:20 +0200590 if (features & NL80211_FEATURE_ACKTO_ESTIMATION)
591 printf("\tDevice supports ACK timeout estimation.\n");
Johannes Berg5973e652014-10-09 16:30:38 +0200592 if (features & NL80211_FEATURE_STATIC_SMPS)
593 printf("\tDevice supports static SMPS\n");
594 if (features & NL80211_FEATURE_DYNAMIC_SMPS)
595 printf("\tDevice supports dynamic SMPS\n");
Johannes Berge15ec742014-10-29 17:10:39 +0100596 if (features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
597 printf("\tDevice supports WMM-AC admission (TSPECs)\n");
Ben Greearced55222014-10-24 08:35:42 -0700598 if (features & NL80211_FEATURE_MAC_ON_CREATE)
599 printf("\tDevice supports configuring vdev MAC-addr on create.\n");
Arik Nemtsovc2f0d682014-12-01 18:00:22 +0200600 if (features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)
601 printf("\tDevice supports TDLS channel switching\n");
Johannes Berg632004a2011-12-14 15:08:34 +0100602 }
603
Johannes Berg9b4a1982014-01-06 17:22:00 +0100604 if (tb_msg[NL80211_ATTR_TDLS_SUPPORT])
605 printf("\tDevice supports T-DLS.\n");
606
Amitkumar Karwaraa0f5db2013-06-28 12:53:45 -0700607 if (tb_msg[NL80211_ATTR_COALESCE_RULE]) {
608 struct nl80211_coalesce_rule_support *rule;
609 struct nl80211_pattern_support *pat;
610
611 printf("\tCoalesce support:\n");
612 rule = nla_data(tb_msg[NL80211_ATTR_COALESCE_RULE]);
613 pat = &rule->pat;
614 printf("\t\t * Maximum %u coalesce rules supported\n"
615 "\t\t * Each rule contains upto %u patterns of %u-%u bytes,\n"
616 "\t\t maximum packet offset %u bytes\n"
617 "\t\t * Maximum supported coalescing delay %u msecs\n",
618 rule->max_rules, pat->max_patterns, pat->min_pattern_len,
619 pat->max_pattern_len, pat->max_pkt_offset, rule->max_delay);
620 }
621
Johannes Berg79f99b92008-01-16 00:21:59 +0100622 return NL_SKIP;
623}
624
Johannes Bergc142fa22013-05-02 09:22:58 +0200625static bool nl80211_has_split_wiphy = false;
626
Johannes Berg7c37a242009-04-08 13:13:28 +0200627static int handle_info(struct nl80211_state *state,
628 struct nl_cb *cb,
Johannes Bergd6316502008-09-16 17:05:33 +0200629 struct nl_msg *msg,
Johannes Berg05514f92012-07-19 11:50:50 +0200630 int argc, char **argv,
631 enum id_input id)
Johannes Berg79f99b92008-01-16 00:21:59 +0100632{
Johannes Bergc142fa22013-05-02 09:22:58 +0200633 char *feat_args[] = { "features", "-q" };
634 int err;
635
636 err = handle_cmd(state, CIB_NONE, 2, feat_args);
637 if (!err && nl80211_has_split_wiphy) {
638 nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
639 nlmsg_hdr(msg)->nlmsg_flags |= NLM_F_DUMP;
640 }
641
Johannes Berg79f99b92008-01-16 00:21:59 +0100642 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL);
Johannes Berg79f99b92008-01-16 00:21:59 +0100643
Johannes Berg70391cc2008-09-16 18:35:06 +0200644 return 0;
Johannes Berg79f99b92008-01-16 00:21:59 +0100645}
Johannes Bergc142fa22013-05-02 09:22:58 +0200646__COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info,
Johannes Berg1633ddf2010-11-24 08:16:47 +0100647 "Show capabilities for the specified wireless device.", NULL);
Johannes Bergea35fc02009-05-05 14:56:21 +0200648TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info,
649 "List all wireless devices and their capabilities.");
Johannes Berg01ae06f2009-05-05 14:48:16 +0200650TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL);
Johannes Bergbcdff0b2012-11-15 15:15:10 +0100651
652static int handle_commands(struct nl80211_state *state,
653 struct nl_cb *cb, struct nl_msg *msg,
654 int argc, char **argv, enum id_input id)
655{
656 int i;
657 for (i = 1; i < NL80211_CMD_MAX; i++)
658 printf("%d (0x%x): %s\n", i, i, command_name(i));
659 /* don't send netlink messages */
660 return 2;
661}
662TOPLEVEL(commands, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_NONE, handle_commands,
663 "list all known commands and their decimal & hex value");
Johannes Bergfb70e112013-02-14 16:32:53 +0100664
665static int print_feature_handler(struct nl_msg *msg, void *arg)
666{
667 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
668 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
Johannes Bergc142fa22013-05-02 09:22:58 +0200669 bool print = (unsigned long)arg;
670#define maybe_printf(...) do { if (print) printf(__VA_ARGS__); } while (0)
Johannes Bergfb70e112013-02-14 16:32:53 +0100671
672 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
673 genlmsg_attrlen(gnlh, 0), NULL);
674
675 if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) {
676 uint32_t feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]);
677
Johannes Bergc142fa22013-05-02 09:22:58 +0200678 maybe_printf("nl80211 features: 0x%x\n", feat);
679 if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) {
680 maybe_printf("\t* split wiphy dump\n");
681 nl80211_has_split_wiphy = true;
682 }
Johannes Bergfb70e112013-02-14 16:32:53 +0100683 }
684
685 return NL_SKIP;
686}
687
688static int handle_features(struct nl80211_state *state,
689 struct nl_cb *cb, struct nl_msg *msg,
690 int argc, char **argv, enum id_input id)
691{
Johannes Bergc142fa22013-05-02 09:22:58 +0200692 unsigned long print = argc == 0 || strcmp(argv[0], "-q");
693 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_feature_handler, (void *)print);
Johannes Bergfb70e112013-02-14 16:32:53 +0100694 return 0;
695}
696
Johannes Bergc142fa22013-05-02 09:22:58 +0200697TOPLEVEL(features, "", NL80211_CMD_GET_PROTOCOL_FEATURES, 0, CIB_NONE,
Johannes Bergfb70e112013-02-14 16:32:53 +0100698 handle_features, "");