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