]>
Commit | Line | Data |
---|---|---|
957a0f07 JB |
1 | #include <stdint.h> |
2 | #include <stdbool.h> | |
3 | #include <net/if.h> | |
4 | #include <errno.h> | |
7c4e86ca | 5 | #include <inttypes.h> |
957a0f07 JB |
6 | #include "iw.h" |
7 | ||
8 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
9 | { | |
10 | return NL_OK; | |
11 | } | |
12 | ||
0168589d LR |
13 | struct ieee80211_beacon_channel { |
14 | __u16 center_freq; | |
f0c48e7b | 15 | bool no_ir; |
0168589d LR |
16 | bool no_ibss; |
17 | }; | |
18 | ||
19 | static int parse_beacon_hint_chan(struct nlattr *tb, | |
20 | struct ieee80211_beacon_channel *chan) | |
21 | { | |
22 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
23 | static struct nla_policy beacon_freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
24 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
f0c48e7b IP |
25 | [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, |
26 | [__NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
0168589d LR |
27 | }; |
28 | ||
29 | if (nla_parse_nested(tb_freq, | |
30 | NL80211_FREQUENCY_ATTR_MAX, | |
31 | tb, | |
32 | beacon_freq_policy)) | |
33 | return -EINVAL; | |
34 | ||
35 | chan->center_freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); | |
36 | ||
f0c48e7b IP |
37 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR]) |
38 | chan->no_ir = true; | |
39 | if (tb_freq[__NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
0168589d LR |
40 | chan->no_ibss = true; |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
957a0f07 JB |
45 | static void print_frame(struct print_event_args *args, struct nlattr *attr) |
46 | { | |
47 | uint8_t *frame; | |
48 | size_t len; | |
0ee571d5 | 49 | unsigned int i; |
957a0f07 JB |
50 | char macbuf[6*3]; |
51 | uint16_t tmp; | |
52 | ||
572e47a3 | 53 | if (!attr) { |
957a0f07 | 54 | printf(" [no frame]"); |
572e47a3 AK |
55 | return; |
56 | } | |
957a0f07 JB |
57 | |
58 | frame = nla_data(attr); | |
59 | len = nla_len(attr); | |
60 | ||
61 | if (len < 26) { | |
62 | printf(" [invalid frame: "); | |
63 | goto print_frame; | |
64 | } | |
65 | ||
66 | mac_addr_n2a(macbuf, frame + 10); | |
67 | printf(" %s -> ", macbuf); | |
68 | mac_addr_n2a(macbuf, frame + 4); | |
69 | printf("%s", macbuf); | |
70 | ||
71 | switch (frame[0] & 0xfc) { | |
72 | case 0x10: /* assoc resp */ | |
73 | case 0x30: /* reassoc resp */ | |
74 | /* status */ | |
75 | tmp = (frame[27] << 8) + frame[26]; | |
76 | printf(" status: %d: %s", tmp, get_status_str(tmp)); | |
77 | break; | |
78 | case 0x00: /* assoc req */ | |
79 | case 0x20: /* reassoc req */ | |
80 | break; | |
81 | case 0xb0: /* auth */ | |
82 | /* status */ | |
83 | tmp = (frame[29] << 8) + frame[28]; | |
84 | printf(" status: %d: %s", tmp, get_status_str(tmp)); | |
85 | break; | |
957a0f07 JB |
86 | case 0xa0: /* disassoc */ |
87 | case 0xc0: /* deauth */ | |
88 | /* reason */ | |
89 | tmp = (frame[25] << 8) + frame[24]; | |
90 | printf(" reason %d: %s", tmp, get_reason_str(tmp)); | |
91 | break; | |
92 | } | |
93 | ||
94 | if (!args->frame) | |
95 | return; | |
96 | ||
97 | printf(" [frame:"); | |
98 | ||
99 | print_frame: | |
100 | for (i = 0; i < len; i++) | |
101 | printf(" %.02x", frame[i]); | |
102 | printf("]"); | |
103 | } | |
104 | ||
f19444fe | 105 | static void parse_cqm_event(struct nlattr **attrs) |
7988b229 JO |
106 | { |
107 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
108 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
109 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
110 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
111 | }; | |
112 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; | |
f19444fe | 113 | struct nlattr *cqm_attr = attrs[NL80211_ATTR_CQM]; |
7988b229 | 114 | |
e5497f12 | 115 | printf("CQM event: "); |
7988b229 | 116 | |
f19444fe JB |
117 | if (!cqm_attr || |
118 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, cqm_attr, cqm_policy)) { | |
7988b229 JO |
119 | printf("missing data!\n"); |
120 | return; | |
121 | } | |
122 | ||
123 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]) { | |
124 | enum nl80211_cqm_rssi_threshold_event rssi_event; | |
e5497f12 BG |
125 | bool found_one = false; |
126 | ||
7988b229 | 127 | rssi_event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); |
e5497f12 BG |
128 | |
129 | switch (rssi_event) { | |
130 | case NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH: | |
f19444fe | 131 | printf("RSSI went above threshold\n"); |
e5497f12 BG |
132 | found_one = true; |
133 | break; | |
134 | case NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW: | |
f19444fe | 135 | printf("RSSI went below threshold\n"); |
e5497f12 BG |
136 | found_one = true; |
137 | break; | |
138 | case NL80211_CQM_RSSI_BEACON_LOSS_EVENT: | |
139 | printf("Beacon loss detected\n"); | |
140 | found_one = true; | |
141 | break; | |
142 | } | |
143 | ||
144 | if (!found_one) | |
145 | printf("Unknown event type: %i\n", rssi_event); | |
a3ca7c69 BG |
146 | } else if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]) { |
147 | if (attrs[NL80211_ATTR_MAC]) { | |
148 | uint32_t frames; | |
149 | char buf[3*6]; | |
150 | ||
151 | frames = nla_get_u32(cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]); | |
152 | mac_addr_n2a(buf, nla_data(attrs[NL80211_ATTR_MAC])); | |
153 | printf("peer %s didn't ACK %d packets\n", buf, frames); | |
154 | } else { | |
155 | printf("PKT-LOSS-EVENT did not have MAC attribute!\n"); | |
156 | } | |
157 | } else if (cqm[NL80211_ATTR_CQM_BEACON_LOSS_EVENT]) { | |
158 | printf("beacon loss\n"); | |
159 | } else { | |
f19444fe | 160 | printf("unknown event\n"); |
a3ca7c69 | 161 | } |
7988b229 JO |
162 | } |
163 | ||
8612433d JM |
164 | static const char * key_type_str(enum nl80211_key_type key_type) |
165 | { | |
166 | static char buf[30]; | |
167 | switch (key_type) { | |
168 | case NL80211_KEYTYPE_GROUP: | |
169 | return "Group"; | |
170 | case NL80211_KEYTYPE_PAIRWISE: | |
171 | return "Pairwise"; | |
172 | case NL80211_KEYTYPE_PEERKEY: | |
173 | return "PeerKey"; | |
174 | default: | |
175 | snprintf(buf, sizeof(buf), "unknown(%d)", key_type); | |
176 | return buf; | |
177 | } | |
178 | } | |
179 | ||
180 | static void parse_mic_failure(struct nlattr **attrs) | |
181 | { | |
182 | printf("Michael MIC failure event:"); | |
183 | ||
184 | if (attrs[NL80211_ATTR_MAC]) { | |
185 | char addr[3 * ETH_ALEN]; | |
186 | mac_addr_n2a(addr, nla_data(attrs[NL80211_ATTR_MAC])); | |
187 | printf(" source MAC address %s", addr); | |
188 | } | |
189 | ||
190 | if (attrs[NL80211_ATTR_KEY_SEQ] && | |
191 | nla_len(attrs[NL80211_ATTR_KEY_SEQ]) == 6) { | |
192 | unsigned char *seq = nla_data(attrs[NL80211_ATTR_KEY_SEQ]); | |
193 | printf(" seq=%02x%02x%02x%02x%02x%02x", | |
194 | seq[0], seq[1], seq[2], seq[3], seq[4], seq[5]); | |
195 | } | |
196 | if (attrs[NL80211_ATTR_KEY_TYPE]) { | |
197 | enum nl80211_key_type key_type = | |
198 | nla_get_u32(attrs[NL80211_ATTR_KEY_TYPE]); | |
199 | printf(" Key Type %s", key_type_str(key_type)); | |
200 | } | |
201 | ||
202 | if (attrs[NL80211_ATTR_KEY_IDX]) { | |
203 | __u8 key_id = nla_get_u8(attrs[NL80211_ATTR_KEY_IDX]); | |
204 | printf(" Key Id %d", key_id); | |
205 | } | |
206 | ||
207 | printf("\n"); | |
208 | } | |
7988b229 | 209 | |
819b78cc JB |
210 | static void parse_wowlan_wake_event(struct nlattr **attrs) |
211 | { | |
d516c5bc LC |
212 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG], |
213 | *tb_match[NUM_NL80211_ATTR]; | |
819b78cc JB |
214 | |
215 | printf("WoWLAN wakeup\n"); | |
216 | if (!attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { | |
217 | printf("\twakeup not due to WoWLAN\n"); | |
218 | return; | |
219 | } | |
220 | ||
221 | nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
222 | nla_data(attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
223 | nla_len(attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), NULL); | |
224 | ||
225 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) | |
226 | printf("\t* was disconnected\n"); | |
227 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) | |
228 | printf("\t* magic packet received\n"); | |
229 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) | |
230 | printf("\t* pattern index: %u\n", | |
231 | nla_get_u32(tb[NL80211_WOWLAN_TRIG_PKT_PATTERN])); | |
232 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) | |
233 | printf("\t* GTK rekey failure\n"); | |
234 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) | |
235 | printf("\t* EAP identity request\n"); | |
236 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) | |
237 | printf("\t* 4-way handshake\n"); | |
238 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) | |
239 | printf("\t* RF-kill released\n"); | |
d516c5bc LC |
240 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS]) { |
241 | struct nlattr *match, *freq; | |
242 | int rem_nst, rem_nst2; | |
243 | ||
244 | printf("\t* network detected\n"); | |
245 | nla_for_each_nested(match, | |
246 | tb[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS], | |
247 | rem_nst) { | |
b7e8163a DS |
248 | nla_parse_nested(tb_match, NL80211_ATTR_MAX, match, |
249 | NULL); | |
d516c5bc LC |
250 | printf("\t\tSSID: \""); |
251 | print_ssid_escaped(nla_len(tb_match[NL80211_ATTR_SSID]), | |
252 | nla_data(tb_match[NL80211_ATTR_SSID])); | |
253 | printf("\""); | |
254 | if (tb_match[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
255 | printf(" freq(s):"); | |
256 | nla_for_each_nested(freq, | |
257 | tb_match[NL80211_ATTR_SCAN_FREQUENCIES], | |
258 | rem_nst2) | |
259 | printf(" %d", nla_get_u32(freq)); | |
260 | } | |
261 | printf("\n"); | |
262 | } | |
263 | } | |
819b78cc JB |
264 | if (tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211]) { |
265 | uint8_t *d = nla_data(tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211]); | |
266 | int l = nla_len(tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211]); | |
267 | int i; | |
268 | printf("\t* packet (might be truncated): "); | |
269 | for (i = 0; i < l; i++) { | |
270 | if (i > 0) | |
271 | printf(":"); | |
272 | printf("%.2x", d[i]); | |
273 | } | |
274 | printf("\n"); | |
275 | } | |
276 | if (tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023]) { | |
277 | uint8_t *d = nla_data(tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023]); | |
278 | int l = nla_len(tb[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023]); | |
279 | int i; | |
280 | printf("\t* packet (might be truncated): "); | |
281 | for (i = 0; i < l; i++) { | |
282 | if (i > 0) | |
283 | printf(":"); | |
284 | printf("%.2x", d[i]); | |
285 | } | |
286 | printf("\n"); | |
287 | } | |
288 | if (tb[NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH]) | |
289 | printf("\t* TCP connection wakeup received\n"); | |
290 | if (tb[NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST]) | |
291 | printf("\t* TCP connection lost\n"); | |
292 | if (tb[NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS]) | |
293 | printf("\t* TCP connection ran out of tokens\n"); | |
294 | } | |
295 | ||
7c4e86ca RZ |
296 | static void parse_nan_term(struct nlattr **attrs) |
297 | { | |
298 | struct nlattr *func[NL80211_NAN_FUNC_ATTR_MAX + 1]; | |
299 | ||
300 | static struct nla_policy | |
301 | nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
302 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | |
303 | [NL80211_NAN_FUNC_SERVICE_ID] = { }, | |
304 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
305 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
306 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
307 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
308 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
309 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { }, | |
310 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, | |
311 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
312 | [NL80211_NAN_FUNC_SERVICE_INFO] = { }, | |
313 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
314 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
315 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
316 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8}, | |
317 | }; | |
318 | ||
319 | if (!attrs[NL80211_ATTR_COOKIE]) { | |
320 | printf("Bad NAN func termination format - cookie is missing\n"); | |
321 | return; | |
322 | } | |
323 | ||
324 | if (nla_parse_nested(func, NL80211_NAN_FUNC_ATTR_MAX, | |
325 | attrs[NL80211_ATTR_NAN_FUNC], | |
326 | nan_func_policy)) { | |
327 | printf("NAN: failed to parse nan func\n"); | |
328 | return; | |
329 | } | |
330 | ||
331 | if (!func[NL80211_NAN_FUNC_INSTANCE_ID]) { | |
332 | printf("Bad NAN func termination format-instance id missing\n"); | |
333 | return; | |
334 | } | |
335 | ||
336 | if (!func[NL80211_NAN_FUNC_TERM_REASON]) { | |
337 | printf("Bad NAN func termination format - reason is missing\n"); | |
338 | return; | |
339 | } | |
340 | printf("NAN(cookie=0x%llx): Termination event: id = %d, reason = ", | |
341 | (long long int)nla_get_u64(attrs[NL80211_ATTR_COOKIE]), | |
342 | nla_get_u8(func[NL80211_NAN_FUNC_INSTANCE_ID])); | |
343 | switch (nla_get_u8(func[NL80211_NAN_FUNC_TERM_REASON])) { | |
344 | case NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST: | |
345 | printf("user request\n"); | |
346 | break; | |
347 | case NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED: | |
348 | printf("expired\n"); | |
349 | break; | |
350 | case NL80211_NAN_FUNC_TERM_REASON_ERROR: | |
351 | printf("error\n"); | |
352 | break; | |
353 | default: | |
354 | printf("unknown\n"); | |
355 | } | |
356 | } | |
357 | ||
8ddb960e JB |
358 | static const char *ftm_fail_reason(unsigned int reason) |
359 | { | |
360 | #define FTM_FAIL_REASON(x) case NL80211_PMSR_FTM_FAILURE_##x: return #x | |
361 | switch (reason) { | |
362 | FTM_FAIL_REASON(UNSPECIFIED); | |
363 | FTM_FAIL_REASON(NO_RESPONSE); | |
364 | FTM_FAIL_REASON(REJECTED); | |
365 | FTM_FAIL_REASON(WRONG_CHANNEL); | |
366 | FTM_FAIL_REASON(PEER_NOT_CAPABLE); | |
367 | FTM_FAIL_REASON(INVALID_TIMESTAMP); | |
368 | FTM_FAIL_REASON(PEER_BUSY); | |
369 | FTM_FAIL_REASON(BAD_CHANGED_PARAMS); | |
370 | default: | |
371 | return "unknown"; | |
372 | } | |
373 | } | |
374 | ||
375 | static void parse_pmsr_ftm_data(struct nlattr *data) | |
376 | { | |
377 | struct nlattr *ftm[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1]; | |
378 | ||
379 | printf(" FTM"); | |
380 | nla_parse_nested(ftm, NL80211_PMSR_FTM_RESP_ATTR_MAX, data, NULL); | |
381 | ||
382 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON]) { | |
383 | printf(" failed: %s (%d)", | |
384 | ftm_fail_reason(nla_get_u32(ftm[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON])), | |
385 | nla_get_u32(ftm[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON])); | |
386 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME]) | |
387 | printf(" retry after %us", | |
388 | nla_get_u32(ftm[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME])); | |
389 | printf("\n"); | |
390 | return; | |
391 | } | |
392 | ||
393 | printf("\n"); | |
394 | ||
395 | #define PFTM(tp, attr, sign) \ | |
396 | do { \ | |
397 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr]) \ | |
398 | printf(" " #attr ": %lld\n", \ | |
399 | (sign long long)nla_get_##tp( \ | |
400 | ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr])); \ | |
401 | } while (0) | |
402 | ||
403 | PFTM(u32, BURST_INDEX, unsigned); | |
404 | PFTM(u32, NUM_FTMR_ATTEMPTS, unsigned); | |
405 | PFTM(u32, NUM_FTMR_SUCCESSES, unsigned); | |
406 | PFTM(u8, NUM_BURSTS_EXP, unsigned); | |
407 | PFTM(u8, BURST_DURATION, unsigned); | |
408 | PFTM(u8, FTMS_PER_BURST, unsigned); | |
409 | PFTM(u32, RSSI_AVG, signed); | |
410 | PFTM(u32, RSSI_SPREAD, unsigned); | |
411 | PFTM(u64, RTT_AVG, signed); | |
412 | PFTM(u64, RTT_VARIANCE, unsigned); | |
413 | PFTM(u64, RTT_SPREAD, unsigned); | |
414 | PFTM(u64, DIST_AVG, signed); | |
415 | PFTM(u64, DIST_VARIANCE, unsigned); | |
416 | PFTM(u64, DIST_SPREAD, unsigned); | |
417 | ||
418 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE]) { | |
419 | char buf[100]; | |
420 | ||
421 | parse_bitrate(ftm[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE], | |
422 | buf, sizeof(buf)); | |
423 | printf(" TX bitrate: %s\n", buf); | |
424 | } | |
425 | ||
426 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE]) { | |
427 | char buf[100]; | |
428 | ||
429 | parse_bitrate(ftm[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE], | |
430 | buf, sizeof(buf)); | |
431 | printf(" RX bitrate: %s\n", buf); | |
432 | } | |
433 | ||
434 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_LCI]) | |
435 | iw_hexdump(" LCI", | |
436 | nla_data(ftm[NL80211_PMSR_FTM_RESP_ATTR_LCI]), | |
437 | nla_len(ftm[NL80211_PMSR_FTM_RESP_ATTR_LCI])); | |
438 | ||
439 | if (ftm[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]) | |
440 | iw_hexdump(" civic location", | |
441 | nla_data(ftm[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]), | |
442 | nla_len(ftm[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC])); | |
443 | } | |
444 | ||
445 | static const char *pmsr_status(unsigned int status) | |
446 | { | |
447 | #define PMSR_STATUS(x) case NL80211_PMSR_STATUS_##x: return #x | |
448 | switch (status) { | |
449 | PMSR_STATUS(SUCCESS); | |
450 | PMSR_STATUS(REFUSED); | |
451 | PMSR_STATUS(TIMEOUT); | |
452 | PMSR_STATUS(FAILURE); | |
453 | default: | |
454 | return "unknown"; | |
455 | } | |
456 | #undef PMSR_STATUS | |
457 | } | |
458 | ||
459 | static void parse_pmsr_peer(struct nlattr *peer) | |
460 | { | |
461 | struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1]; | |
462 | struct nlattr *resp[NL80211_PMSR_RESP_ATTR_MAX + 1]; | |
463 | struct nlattr *data[NL80211_PMSR_TYPE_MAX + 1]; | |
464 | char macbuf[6*3]; | |
465 | int err; | |
466 | ||
467 | err = nla_parse_nested(tb, NL80211_PMSR_PEER_ATTR_MAX, peer, NULL); | |
468 | if (err) { | |
469 | printf(" Peer: failed to parse!\n"); | |
470 | return; | |
471 | } | |
472 | ||
473 | if (!tb[NL80211_PMSR_PEER_ATTR_ADDR]) { | |
474 | printf(" Peer: no MAC address\n"); | |
475 | return; | |
476 | } | |
477 | ||
478 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_PMSR_PEER_ATTR_ADDR])); | |
479 | printf(" Peer %s:", macbuf); | |
480 | ||
481 | if (!tb[NL80211_PMSR_PEER_ATTR_RESP]) { | |
482 | printf(" no response!\n"); | |
483 | return; | |
484 | } | |
485 | ||
486 | err = nla_parse_nested(resp, NL80211_PMSR_RESP_ATTR_MAX, | |
487 | tb[NL80211_PMSR_PEER_ATTR_RESP], NULL); | |
488 | if (err) { | |
489 | printf(" failed to parse response!\n"); | |
490 | return; | |
491 | } | |
492 | ||
493 | if (resp[NL80211_PMSR_RESP_ATTR_STATUS]) | |
494 | printf(" status=%d (%s)", | |
495 | nla_get_u32(resp[NL80211_PMSR_RESP_ATTR_STATUS]), | |
496 | pmsr_status(nla_get_u32(resp[NL80211_PMSR_RESP_ATTR_STATUS]))); | |
497 | if (resp[NL80211_PMSR_RESP_ATTR_HOST_TIME]) | |
498 | printf(" @%llu", | |
499 | (unsigned long long)nla_get_u64(resp[NL80211_PMSR_RESP_ATTR_HOST_TIME])); | |
500 | if (resp[NL80211_PMSR_RESP_ATTR_AP_TSF]) | |
501 | printf(" tsf=%llu", | |
502 | (unsigned long long)nla_get_u64(resp[NL80211_PMSR_RESP_ATTR_AP_TSF])); | |
503 | if (resp[NL80211_PMSR_RESP_ATTR_FINAL]) | |
504 | printf(" (final)"); | |
505 | ||
506 | if (!resp[NL80211_PMSR_RESP_ATTR_DATA]) { | |
507 | printf(" - no data!\n"); | |
508 | return; | |
509 | } | |
510 | ||
511 | printf("\n"); | |
512 | ||
513 | nla_parse_nested(data, NL80211_PMSR_TYPE_MAX, | |
514 | resp[NL80211_PMSR_RESP_ATTR_DATA], NULL); | |
515 | ||
516 | if (data[NL80211_PMSR_TYPE_FTM]) | |
517 | parse_pmsr_ftm_data(data[NL80211_PMSR_TYPE_FTM]); | |
518 | } | |
519 | ||
520 | static void parse_pmsr_result(struct nlattr **tb, | |
521 | struct print_event_args *pargs) | |
522 | { | |
523 | struct nlattr *pmsr[NL80211_PMSR_ATTR_MAX + 1]; | |
524 | struct nlattr *peer; | |
525 | unsigned long long cookie; | |
526 | int err, i; | |
527 | ||
528 | if (!tb[NL80211_ATTR_COOKIE]) { | |
529 | printf("Peer measurements: no cookie!\n"); | |
530 | return; | |
531 | } | |
532 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
533 | ||
534 | if (!tb[NL80211_ATTR_PEER_MEASUREMENTS]) { | |
535 | printf("Peer measurements: no measurement data!\n"); | |
536 | return; | |
537 | } | |
538 | ||
539 | err = nla_parse_nested(pmsr, NL80211_PMSR_ATTR_MAX, | |
540 | tb[NL80211_ATTR_PEER_MEASUREMENTS], NULL); | |
541 | if (err) { | |
542 | printf("Peer measurements: failed to parse measurement data!\n"); | |
543 | return; | |
544 | } | |
545 | ||
546 | if (!pmsr[NL80211_PMSR_ATTR_PEERS]) { | |
547 | printf("Peer measurements: no peer data!\n"); | |
548 | return; | |
549 | } | |
550 | ||
551 | printf("Peer measurements (cookie %llu):\n", cookie); | |
552 | ||
553 | nla_for_each_nested(peer, pmsr[NL80211_PMSR_ATTR_PEERS], i) | |
554 | parse_pmsr_peer(peer); | |
555 | } | |
556 | ||
7c4e86ca RZ |
557 | static void parse_nan_match(struct nlattr **attrs) |
558 | { | |
559 | char macbuf[6*3]; | |
560 | __u64 cookie; | |
561 | struct nlattr *match[NL80211_NAN_MATCH_ATTR_MAX + 1]; | |
562 | struct nlattr *local_func[NL80211_NAN_FUNC_ATTR_MAX + 1]; | |
563 | struct nlattr *peer_func[NL80211_NAN_FUNC_ATTR_MAX + 1]; | |
564 | ||
565 | static struct nla_policy | |
566 | nan_match_policy[NL80211_NAN_MATCH_ATTR_MAX + 1] = { | |
567 | [NL80211_NAN_MATCH_FUNC_LOCAL] = { .type = NLA_NESTED }, | |
568 | [NL80211_NAN_MATCH_FUNC_PEER] = { .type = NLA_NESTED }, | |
569 | }; | |
570 | ||
571 | static struct nla_policy | |
572 | nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
573 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | |
574 | [NL80211_NAN_FUNC_SERVICE_ID] = { }, | |
575 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
576 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
577 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
578 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
579 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
580 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { }, | |
581 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, | |
582 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
583 | [NL80211_NAN_FUNC_SERVICE_INFO] = { }, | |
584 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
585 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
586 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
587 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8}, | |
588 | }; | |
589 | ||
590 | cookie = nla_get_u64(attrs[NL80211_ATTR_COOKIE]); | |
591 | mac_addr_n2a(macbuf, nla_data(attrs[NL80211_ATTR_MAC])); | |
592 | ||
593 | if (nla_parse_nested(match, NL80211_NAN_MATCH_ATTR_MAX, | |
594 | attrs[NL80211_ATTR_NAN_MATCH], | |
595 | nan_match_policy)) { | |
596 | printf("NAN: failed to parse nan match event\n"); | |
597 | return; | |
598 | } | |
599 | ||
600 | if (nla_parse_nested(local_func, NL80211_NAN_FUNC_ATTR_MAX, | |
601 | match[NL80211_NAN_MATCH_FUNC_LOCAL], | |
602 | nan_func_policy)) { | |
603 | printf("NAN: failed to parse nan local func\n"); | |
604 | return; | |
605 | } | |
606 | ||
607 | if (nla_parse_nested(peer_func, NL80211_NAN_FUNC_ATTR_MAX, | |
608 | match[NL80211_NAN_MATCH_FUNC_PEER], | |
609 | nan_func_policy)) { | |
610 | printf("NAN: failed to parse nan local func\n"); | |
611 | return; | |
612 | } | |
613 | ||
614 | if (nla_get_u8(peer_func[NL80211_NAN_FUNC_TYPE]) == | |
615 | NL80211_NAN_FUNC_PUBLISH) { | |
616 | printf( | |
adfc1022 | 617 | "NAN(cookie=0x%llx): DiscoveryResult, peer_id=%d, local_id=%d, peer_mac=%s", |
7c4e86ca RZ |
618 | cookie, |
619 | nla_get_u8(peer_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
620 | nla_get_u8(local_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
621 | macbuf); | |
622 | if (peer_func[NL80211_NAN_FUNC_SERVICE_INFO]) | |
adfc1022 | 623 | printf(", info=%.*s", |
7c4e86ca RZ |
624 | nla_len(peer_func[NL80211_NAN_FUNC_SERVICE_INFO]), |
625 | (char *)nla_data(peer_func[NL80211_NAN_FUNC_SERVICE_INFO])); | |
626 | } else if (nla_get_u8(peer_func[NL80211_NAN_FUNC_TYPE]) == | |
627 | NL80211_NAN_FUNC_SUBSCRIBE) { | |
628 | printf( | |
adfc1022 | 629 | "NAN(cookie=0x%llx): Replied, peer_id=%d, local_id=%d, peer_mac=%s", |
7c4e86ca RZ |
630 | cookie, |
631 | nla_get_u8(peer_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
632 | nla_get_u8(local_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
633 | macbuf); | |
634 | } else if (nla_get_u8(peer_func[NL80211_NAN_FUNC_TYPE]) == | |
635 | NL80211_NAN_FUNC_FOLLOW_UP) { | |
636 | printf( | |
adfc1022 | 637 | "NAN(cookie=0x%llx): FollowUpReceive, peer_id=%d, local_id=%d, peer_mac=%s", |
7c4e86ca RZ |
638 | cookie, |
639 | nla_get_u8(peer_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
640 | nla_get_u8(local_func[NL80211_NAN_FUNC_INSTANCE_ID]), | |
641 | macbuf); | |
642 | if (peer_func[NL80211_NAN_FUNC_SERVICE_INFO]) | |
adfc1022 | 643 | printf(", info=%.*s", |
7c4e86ca RZ |
644 | nla_len(peer_func[NL80211_NAN_FUNC_SERVICE_INFO]), |
645 | (char *)nla_data(peer_func[NL80211_NAN_FUNC_SERVICE_INFO])); | |
646 | } else { | |
adfc1022 | 647 | printf("NaN: Malformed event"); |
7c4e86ca | 648 | } |
adfc1022 AO |
649 | |
650 | printf("\n"); | |
7c4e86ca RZ |
651 | } |
652 | ||
d98f794f MT |
653 | static void parse_new_peer_candidate(struct nlattr **attrs) |
654 | { | |
655 | char macbuf[ETH_ALEN * 3]; | |
656 | int32_t sig_dbm; | |
657 | ||
658 | printf("new peer candidate"); | |
659 | if (attrs[NL80211_ATTR_MAC]) { | |
660 | mac_addr_n2a(macbuf, nla_data(attrs[NL80211_ATTR_MAC])); | |
661 | printf(" %s", macbuf); | |
662 | } | |
663 | if (attrs[NL80211_ATTR_RX_SIGNAL_DBM]) { | |
664 | sig_dbm = nla_get_u32(attrs[NL80211_ATTR_RX_SIGNAL_DBM]); | |
665 | printf(" %d dBm", sig_dbm); | |
666 | } | |
667 | ||
668 | printf("\n"); | |
669 | } | |
670 | ||
7d17ba94 MT |
671 | static void parse_set_interface(struct nlattr **attrs) |
672 | { | |
673 | printf("set interface"); | |
674 | ||
675 | if (attrs[NL80211_ATTR_IFTYPE]) { | |
676 | printf(" type "); | |
677 | switch (nla_get_u32(attrs[NL80211_ATTR_IFTYPE])) { | |
678 | case NL80211_IFTYPE_STATION: | |
679 | printf("station"); | |
680 | break; | |
681 | case NL80211_IFTYPE_AP: | |
682 | printf("access point"); | |
683 | break; | |
684 | case NL80211_IFTYPE_MESH_POINT: | |
685 | printf("mesh point"); | |
686 | break; | |
687 | case NL80211_IFTYPE_ADHOC: | |
688 | printf("IBSS"); | |
689 | break; | |
690 | case NL80211_IFTYPE_MONITOR: | |
691 | printf("monitor"); | |
692 | break; | |
693 | case NL80211_IFTYPE_AP_VLAN: | |
694 | printf("AP-VLAN"); | |
695 | break; | |
696 | case NL80211_IFTYPE_WDS: | |
697 | printf("WDS"); | |
698 | break; | |
699 | case NL80211_IFTYPE_P2P_CLIENT: | |
700 | printf("P2P-client"); | |
701 | break; | |
702 | case NL80211_IFTYPE_P2P_GO: | |
703 | printf("P2P-GO"); | |
704 | break; | |
705 | case NL80211_IFTYPE_P2P_DEVICE: | |
706 | printf("P2P-Device"); | |
707 | break; | |
708 | case NL80211_IFTYPE_OCB: | |
709 | printf("OCB"); | |
710 | break; | |
711 | case NL80211_IFTYPE_NAN: | |
712 | printf("NAN"); | |
713 | break; | |
714 | default: | |
715 | printf("unknown (%d)", | |
716 | nla_get_u32(attrs[NL80211_ATTR_IFTYPE])); | |
717 | break; | |
718 | } | |
719 | } | |
720 | ||
721 | if (attrs[NL80211_ATTR_MESH_ID]) { | |
722 | printf(" meshid "); | |
723 | print_ssid_escaped(nla_len(attrs[NL80211_ATTR_MESH_ID]), | |
724 | nla_data(attrs[NL80211_ATTR_MESH_ID])); | |
725 | } | |
726 | ||
727 | if (attrs[NL80211_ATTR_4ADDR]) { | |
728 | printf(" use 4addr %d", nla_get_u8(attrs[NL80211_ATTR_4ADDR])); | |
729 | } | |
730 | ||
731 | printf("\n"); | |
732 | } | |
733 | ||
957a0f07 JB |
734 | static int print_event(struct nl_msg *msg, void *arg) |
735 | { | |
736 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
748f8489 | 737 | struct nlattr *tb[NL80211_ATTR_MAX + 1], *nst; |
957a0f07 JB |
738 | struct print_event_args *args = arg; |
739 | char ifname[100]; | |
740 | char macbuf[6*3]; | |
741 | __u8 reg_type; | |
0168589d LR |
742 | struct ieee80211_beacon_channel chan_before_beacon, chan_after_beacon; |
743 | __u32 wiphy_idx = 0; | |
748f8489 | 744 | int rem_nst; |
f1a666a6 | 745 | __u16 status; |
957a0f07 | 746 | |
981b21ad JB |
747 | if (args->time || args->reltime) { |
748 | unsigned long long usecs, previous; | |
749 | ||
750 | previous = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; | |
751 | gettimeofday(&args->ts, NULL); | |
752 | usecs = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; | |
753 | if (args->reltime) { | |
754 | if (!args->have_ts) { | |
755 | usecs = 0; | |
756 | args->have_ts = true; | |
757 | } else | |
758 | usecs -= previous; | |
759 | } | |
760 | printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000); | |
957a0f07 JB |
761 | } |
762 | ||
763 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
764 | genlmsg_attrlen(gnlh, 0), NULL); | |
765 | ||
766 | if (tb[NL80211_ATTR_IFINDEX] && tb[NL80211_ATTR_WIPHY]) { | |
767 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), ifname); | |
768 | printf("%s (phy #%d): ", ifname, nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
d8880179 JB |
769 | } else if (tb[NL80211_ATTR_WDEV] && tb[NL80211_ATTR_WIPHY]) { |
770 | printf("wdev 0x%llx (phy #%d): ", | |
771 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_WDEV]), | |
772 | nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
957a0f07 JB |
773 | } else if (tb[NL80211_ATTR_IFINDEX]) { |
774 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), ifname); | |
775 | printf("%s: ", ifname); | |
d8880179 JB |
776 | } else if (tb[NL80211_ATTR_WDEV]) { |
777 | printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb[NL80211_ATTR_WDEV])); | |
957a0f07 JB |
778 | } else if (tb[NL80211_ATTR_WIPHY]) { |
779 | printf("phy #%d: ", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
780 | } | |
781 | ||
782 | switch (gnlh->cmd) { | |
783 | case NL80211_CMD_NEW_WIPHY: | |
784 | printf("renamed to %s\n", nla_get_string(tb[NL80211_ATTR_WIPHY_NAME])); | |
785 | break; | |
e67be815 JB |
786 | case NL80211_CMD_TRIGGER_SCAN: |
787 | printf("scan started\n"); | |
788 | break; | |
957a0f07 | 789 | case NL80211_CMD_NEW_SCAN_RESULTS: |
748f8489 | 790 | printf("scan finished:"); |
6ab936f0 | 791 | /* fall through */ |
957a0f07 | 792 | case NL80211_CMD_SCAN_ABORTED: |
748f8489 JB |
793 | if (gnlh->cmd == NL80211_CMD_SCAN_ABORTED) |
794 | printf("scan aborted:"); | |
795 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
796 | nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem_nst) | |
797 | printf(" %d", nla_get_u32(nst)); | |
798 | printf(","); | |
799 | } | |
800 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { | |
801 | nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_SSIDS], rem_nst) { | |
802 | printf(" \""); | |
803 | print_ssid_escaped(nla_len(nst), nla_data(nst)); | |
804 | printf("\""); | |
805 | } | |
806 | } | |
807 | printf("\n"); | |
957a0f07 | 808 | break; |
3fce58aa LC |
809 | case NL80211_CMD_START_SCHED_SCAN: |
810 | printf("scheduled scan started\n"); | |
811 | break; | |
812 | case NL80211_CMD_SCHED_SCAN_STOPPED: | |
813 | printf("sched scan stopped\n"); | |
814 | break; | |
815 | case NL80211_CMD_SCHED_SCAN_RESULTS: | |
816 | printf("got scheduled scan results\n"); | |
817 | break; | |
957a0f07 JB |
818 | case NL80211_CMD_REG_CHANGE: |
819 | printf("regulatory domain change: "); | |
820 | ||
821 | reg_type = nla_get_u8(tb[NL80211_ATTR_REG_TYPE]); | |
822 | ||
823 | switch (reg_type) { | |
824 | case NL80211_REGDOM_TYPE_COUNTRY: | |
825 | printf("set to %s by %s request", | |
826 | nla_get_string(tb[NL80211_ATTR_REG_ALPHA2]), | |
827 | reg_initiator_to_string(nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR]))); | |
828 | if (tb[NL80211_ATTR_WIPHY]) | |
829 | printf(" on phy%d", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
830 | break; | |
831 | case NL80211_REGDOM_TYPE_WORLD: | |
832 | printf("set to world roaming by %s request", | |
833 | reg_initiator_to_string(nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR]))); | |
834 | break; | |
835 | case NL80211_REGDOM_TYPE_CUSTOM_WORLD: | |
836 | printf("custom world roaming rules in place on phy%d by %s request", | |
837 | nla_get_u32(tb[NL80211_ATTR_WIPHY]), | |
838 | reg_initiator_to_string(nla_get_u32(tb[NL80211_ATTR_REG_INITIATOR]))); | |
839 | break; | |
840 | case NL80211_REGDOM_TYPE_INTERSECTION: | |
841 | printf("intersection used due to a request made by %s", | |
842 | reg_initiator_to_string(nla_get_u32(tb[NL80211_ATTR_REG_INITIATOR]))); | |
843 | if (tb[NL80211_ATTR_WIPHY]) | |
844 | printf(" on phy%d", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
845 | break; | |
846 | default: | |
847 | printf("unknown source (upgrade this utility)"); | |
848 | break; | |
849 | } | |
850 | ||
851 | printf("\n"); | |
0168589d LR |
852 | break; |
853 | case NL80211_CMD_REG_BEACON_HINT: | |
854 | ||
855 | wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
856 | ||
857 | memset(&chan_before_beacon, 0, sizeof(chan_before_beacon)); | |
858 | memset(&chan_after_beacon, 0, sizeof(chan_after_beacon)); | |
859 | ||
ce3b2ed9 JB |
860 | if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_BEFORE], |
861 | &chan_before_beacon)) | |
862 | break; | |
863 | if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_AFTER], | |
864 | &chan_after_beacon)) | |
865 | break; | |
0168589d LR |
866 | |
867 | if (chan_before_beacon.center_freq != chan_after_beacon.center_freq) | |
868 | break; | |
869 | ||
870 | /* A beacon hint is sent _only_ if something _did_ change */ | |
871 | printf("beacon hint:\n"); | |
872 | ||
873 | printf("phy%d %d MHz [%d]:\n", | |
874 | wiphy_idx, | |
875 | chan_before_beacon.center_freq, | |
876 | ieee80211_frequency_to_channel(chan_before_beacon.center_freq)); | |
877 | ||
f0c48e7b IP |
878 | if (chan_before_beacon.no_ir && !chan_after_beacon.no_ir) { |
879 | if (chan_before_beacon.no_ibss && !chan_after_beacon.no_ibss) | |
880 | printf("\to Initiating radiation enabled\n"); | |
881 | else | |
882 | printf("\to active scan enabled\n"); | |
883 | } else if (chan_before_beacon.no_ibss && !chan_after_beacon.no_ibss) { | |
884 | printf("\to ibss enabled\n"); | |
885 | } | |
0168589d | 886 | |
cec6d6a7 JB |
887 | break; |
888 | case NL80211_CMD_NEW_STATION: | |
889 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
890 | printf("new station %s\n", macbuf); | |
957a0f07 | 891 | break; |
27bf109b AQ |
892 | case NL80211_CMD_DEL_STATION: |
893 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
894 | printf("del station %s\n", macbuf); | |
895 | break; | |
957a0f07 JB |
896 | case NL80211_CMD_JOIN_IBSS: |
897 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
898 | printf("IBSS %s joined\n", macbuf); | |
899 | break; | |
900 | case NL80211_CMD_AUTHENTICATE: | |
901 | printf("auth"); | |
aea5dbd2 JB |
902 | if (tb[NL80211_ATTR_FRAME]) |
903 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
904 | else if (tb[NL80211_ATTR_TIMED_OUT]) | |
905 | printf(": timed out"); | |
906 | else | |
907 | printf(": unknown event"); | |
957a0f07 JB |
908 | printf("\n"); |
909 | break; | |
910 | case NL80211_CMD_ASSOCIATE: | |
911 | printf("assoc"); | |
aea5dbd2 JB |
912 | if (tb[NL80211_ATTR_FRAME]) |
913 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
914 | else if (tb[NL80211_ATTR_TIMED_OUT]) | |
915 | printf(": timed out"); | |
916 | else | |
917 | printf(": unknown event"); | |
957a0f07 JB |
918 | printf("\n"); |
919 | break; | |
920 | case NL80211_CMD_DEAUTHENTICATE: | |
921 | printf("deauth"); | |
922 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
923 | printf("\n"); | |
924 | break; | |
925 | case NL80211_CMD_DISASSOCIATE: | |
926 | printf("disassoc"); | |
927 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
928 | printf("\n"); | |
929 | break; | |
99802e56 JB |
930 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
931 | printf("unprotected deauth"); | |
932 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
933 | printf("\n"); | |
934 | break; | |
935 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
936 | printf("unprotected disassoc"); | |
937 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
938 | printf("\n"); | |
939 | break; | |
f1a666a6 JB |
940 | case NL80211_CMD_CONNECT: |
941 | status = 0; | |
27ea56b6 JB |
942 | if (tb[NL80211_ATTR_TIMED_OUT]) |
943 | printf("timed out"); | |
944 | else if (!tb[NL80211_ATTR_STATUS_CODE]) | |
f1a666a6 JB |
945 | printf("unknown connect status"); |
946 | else if (nla_get_u16(tb[NL80211_ATTR_STATUS_CODE]) == 0) | |
947 | printf("connected"); | |
948 | else { | |
949 | status = nla_get_u16(tb[NL80211_ATTR_STATUS_CODE]); | |
950 | printf("failed to connect"); | |
951 | } | |
952 | if (tb[NL80211_ATTR_MAC]) { | |
953 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
954 | printf(" to %s", macbuf); | |
955 | } | |
956 | if (status) | |
957 | printf(", status: %d: %s", status, get_status_str(status)); | |
958 | printf("\n"); | |
959 | break; | |
960 | case NL80211_CMD_ROAM: | |
961 | printf("roamed"); | |
962 | if (tb[NL80211_ATTR_MAC]) { | |
963 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
964 | printf(" to %s", macbuf); | |
965 | } | |
966 | printf("\n"); | |
967 | break; | |
968 | case NL80211_CMD_DISCONNECT: | |
969 | printf("disconnected"); | |
970 | if (tb[NL80211_ATTR_DISCONNECTED_BY_AP]) | |
971 | printf(" (by AP)"); | |
972 | else | |
973 | printf(" (local request)"); | |
974 | if (tb[NL80211_ATTR_REASON_CODE]) | |
975 | printf(" reason: %d: %s", nla_get_u16(tb[NL80211_ATTR_REASON_CODE]), | |
976 | get_reason_str(nla_get_u16(tb[NL80211_ATTR_REASON_CODE]))); | |
977 | printf("\n"); | |
978 | break; | |
6829308d JB |
979 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
980 | printf("remain on freq %d (%dms, cookie %llx)\n", | |
981 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]), | |
982 | nla_get_u32(tb[NL80211_ATTR_DURATION]), | |
983 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE])); | |
984 | break; | |
985 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: | |
986 | printf("done with remain on freq %d (cookie %llx)\n", | |
987 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]), | |
988 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE])); | |
989 | break; | |
7988b229 | 990 | case NL80211_CMD_NOTIFY_CQM: |
f19444fe | 991 | parse_cqm_event(tb); |
7988b229 | 992 | break; |
8612433d JM |
993 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
994 | parse_mic_failure(tb); | |
995 | break; | |
cbff7089 JB |
996 | case NL80211_CMD_FRAME_TX_STATUS: |
997 | printf("mgmt TX status (cookie %llx): %s\n", | |
998 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE]), | |
999 | tb[NL80211_ATTR_ACK] ? "acked" : "no ack"); | |
1000 | break; | |
0bf2c6a0 | 1001 | case NL80211_CMD_PMKSA_CANDIDATE: |
b6688cb8 JB |
1002 | printf("PMKSA candidate found\n"); |
1003 | break; | |
819b78cc JB |
1004 | case NL80211_CMD_SET_WOWLAN: |
1005 | parse_wowlan_wake_event(tb); | |
1006 | break; | |
4310994d BG |
1007 | case NL80211_CMD_PROBE_CLIENT: |
1008 | if (tb[NL80211_ATTR_MAC]) | |
1009 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
1010 | else | |
1011 | strcpy(macbuf, "??"); | |
1012 | printf("probe client %s (cookie %llx): %s\n", | |
1013 | macbuf, | |
1014 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE]), | |
1015 | tb[NL80211_ATTR_ACK] ? "acked" : "no ack"); | |
1016 | break; | |
e8b3b312 JB |
1017 | case NL80211_CMD_VENDOR: |
1018 | printf("vendor event %.6x:%d\n", | |
1019 | nla_get_u32(tb[NL80211_ATTR_VENDOR_ID]), | |
1020 | nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD])); | |
492354de JD |
1021 | if (args->frame && tb[NL80211_ATTR_VENDOR_DATA]) |
1022 | iw_hexdump("vendor event", | |
1023 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
1024 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
e8b3b312 | 1025 | break; |
03fb59d0 BB |
1026 | case NL80211_CMD_RADAR_DETECT: { |
1027 | enum nl80211_radar_event event_type; | |
1028 | uint32_t freq; | |
1029 | ||
1030 | if (!tb[NL80211_ATTR_RADAR_EVENT] || | |
1031 | !tb[NL80211_ATTR_WIPHY_FREQ]) { | |
1032 | printf("BAD radar event\n"); | |
1033 | break; | |
1034 | } | |
1035 | ||
1036 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1037 | event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]); | |
1038 | ||
1039 | switch (event_type) { | |
1040 | case NL80211_RADAR_DETECTED: | |
1041 | printf("%d MHz: radar detected\n", freq); | |
1042 | break; | |
1043 | case NL80211_RADAR_CAC_FINISHED: | |
1044 | printf("%d MHz: CAC finished\n", freq); | |
1045 | break; | |
1046 | case NL80211_RADAR_CAC_ABORTED: | |
1047 | printf("%d MHz: CAC was aborted\n", freq); | |
1048 | break; | |
1049 | case NL80211_RADAR_NOP_FINISHED: | |
1050 | printf("%d MHz: NOP finished\n", freq); | |
1051 | break; | |
1052 | default: | |
1053 | printf("%d MHz: unknown radar event\n", freq); | |
1054 | } | |
085f4f08 | 1055 | } |
085f4f08 | 1056 | break; |
a3ca7c69 BG |
1057 | case NL80211_CMD_DEL_WIPHY: |
1058 | printf("delete wiphy\n"); | |
1059 | break; | |
8ddb960e JB |
1060 | case NL80211_CMD_PEER_MEASUREMENT_RESULT: |
1061 | parse_pmsr_result(tb, args); | |
1062 | break; | |
1063 | case NL80211_CMD_PEER_MEASUREMENT_COMPLETE: | |
1064 | printf("peer measurement complete\n"); | |
1065 | break; | |
7c4e86ca RZ |
1066 | case NL80211_CMD_DEL_NAN_FUNCTION: |
1067 | parse_nan_term(tb); | |
1068 | break; | |
1069 | case NL80211_CMD_NAN_MATCH: { | |
1070 | parse_nan_match(tb); | |
1071 | break; | |
1072 | } | |
d98f794f MT |
1073 | case NL80211_CMD_NEW_PEER_CANDIDATE: |
1074 | parse_new_peer_candidate(tb); | |
1075 | break; | |
7d17ba94 MT |
1076 | case NL80211_CMD_SET_INTERFACE: |
1077 | parse_set_interface(tb); | |
1078 | break; | |
957a0f07 | 1079 | default: |
7c712c89 JB |
1080 | printf("unknown event %d (%s)\n", |
1081 | gnlh->cmd, command_name(gnlh->cmd)); | |
957a0f07 JB |
1082 | break; |
1083 | } | |
1084 | ||
374e8a26 | 1085 | fflush(stdout); |
957a0f07 JB |
1086 | return NL_SKIP; |
1087 | } | |
1088 | ||
1089 | struct wait_event { | |
2e192cea | 1090 | int n_cmds, n_prints; |
957a0f07 | 1091 | const __u32 *cmds; |
2e192cea | 1092 | const __u32 *prints; |
957a0f07 | 1093 | __u32 cmd; |
7fabd346 | 1094 | struct print_event_args *pargs; |
957a0f07 JB |
1095 | }; |
1096 | ||
1097 | static int wait_event(struct nl_msg *msg, void *arg) | |
1098 | { | |
1099 | struct wait_event *wait = arg; | |
1100 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1101 | int i; | |
1102 | ||
2e192cea JB |
1103 | if (wait->pargs) { |
1104 | for (i = 0; i < wait->n_prints; i++) { | |
1105 | if (gnlh->cmd == wait->prints[i]) | |
7e7c544f | 1106 | print_event(msg, wait->pargs); |
957a0f07 JB |
1107 | } |
1108 | } | |
1109 | ||
2e192cea JB |
1110 | for (i = 0; i < wait->n_cmds; i++) { |
1111 | if (gnlh->cmd == wait->cmds[i]) | |
1112 | wait->cmd = gnlh->cmd; | |
1113 | } | |
1114 | ||
957a0f07 JB |
1115 | return NL_SKIP; |
1116 | } | |
1117 | ||
ee374e4d | 1118 | int __prepare_listen_events(struct nl80211_state *state) |
957a0f07 JB |
1119 | { |
1120 | int mcid, ret; | |
957a0f07 JB |
1121 | |
1122 | /* Configuration multicast group */ | |
1123 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "config"); | |
1124 | if (mcid < 0) | |
1125 | return mcid; | |
1126 | ||
1127 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1128 | if (ret) | |
1129 | return ret; | |
1130 | ||
1131 | /* Scan multicast group */ | |
1132 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "scan"); | |
1133 | if (mcid >= 0) { | |
1134 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1135 | if (ret) | |
1136 | return ret; | |
1137 | } | |
1138 | ||
1139 | /* Regulatory multicast group */ | |
1140 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "regulatory"); | |
1141 | if (mcid >= 0) { | |
1142 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1143 | if (ret) | |
1144 | return ret; | |
1145 | } | |
1146 | ||
1147 | /* MLME multicast group */ | |
1148 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "mlme"); | |
1149 | if (mcid >= 0) { | |
1150 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1151 | if (ret) | |
1152 | return ret; | |
1153 | } | |
1154 | ||
e8b3b312 JB |
1155 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "vendor"); |
1156 | if (mcid >= 0) { | |
1157 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1158 | if (ret) | |
1159 | return ret; | |
1160 | } | |
1161 | ||
7c4e86ca RZ |
1162 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "nan"); |
1163 | if (mcid >= 0) { | |
1164 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
1165 | if (ret) | |
1166 | return ret; | |
1167 | } | |
1168 | ||
105aed57 JB |
1169 | return 0; |
1170 | } | |
1171 | ||
ee374e4d JB |
1172 | __u32 __do_listen_events(struct nl80211_state *state, |
1173 | const int n_waits, const __u32 *waits, | |
2e192cea | 1174 | const int n_prints, const __u32 *prints, |
ee374e4d | 1175 | struct print_event_args *args) |
105aed57 JB |
1176 | { |
1177 | struct nl_cb *cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT); | |
1178 | struct wait_event wait_ev; | |
105aed57 JB |
1179 | |
1180 | if (!cb) { | |
1181 | fprintf(stderr, "failed to allocate netlink callbacks\n"); | |
1182 | return -ENOMEM; | |
1183 | } | |
1184 | ||
957a0f07 JB |
1185 | /* no sequence checking for multicast messages */ |
1186 | nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
34b23014 | 1187 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, valid_handler, NULL); |
957a0f07 JB |
1188 | |
1189 | if (n_waits && waits) { | |
1190 | wait_ev.cmds = waits; | |
1191 | wait_ev.n_cmds = n_waits; | |
2e192cea JB |
1192 | wait_ev.prints = prints; |
1193 | wait_ev.n_prints = n_prints; | |
7fabd346 | 1194 | wait_ev.pargs = args; |
34b23014 | 1195 | register_handler(wait_event, &wait_ev); |
7fabd346 | 1196 | } else |
34b23014 | 1197 | register_handler(print_event, args); |
957a0f07 JB |
1198 | |
1199 | wait_ev.cmd = 0; | |
1200 | ||
1201 | while (!wait_ev.cmd) | |
1202 | nl_recvmsgs(state->nl_sock, cb); | |
1203 | ||
1204 | nl_cb_put(cb); | |
1205 | ||
1206 | return wait_ev.cmd; | |
1207 | } | |
1208 | ||
1209 | __u32 listen_events(struct nl80211_state *state, | |
1210 | const int n_waits, const __u32 *waits) | |
1211 | { | |
ee374e4d JB |
1212 | int ret; |
1213 | ||
1214 | ret = __prepare_listen_events(state); | |
1215 | if (ret) | |
1216 | return ret; | |
1217 | ||
2e192cea | 1218 | return __do_listen_events(state, n_waits, waits, 0, NULL, NULL); |
957a0f07 JB |
1219 | } |
1220 | ||
1221 | static int print_events(struct nl80211_state *state, | |
957a0f07 | 1222 | struct nl_msg *msg, |
05514f95 JB |
1223 | int argc, char **argv, |
1224 | enum id_input id) | |
957a0f07 JB |
1225 | { |
1226 | struct print_event_args args; | |
ee374e4d | 1227 | int ret; |
957a0f07 JB |
1228 | |
1229 | memset(&args, 0, sizeof(args)); | |
1230 | ||
1231 | argc--; | |
1232 | argv++; | |
1233 | ||
1234 | while (argc > 0) { | |
1235 | if (strcmp(argv[0], "-f") == 0) | |
1236 | args.frame = true; | |
1237 | else if (strcmp(argv[0], "-t") == 0) | |
1238 | args.time = true; | |
981b21ad JB |
1239 | else if (strcmp(argv[0], "-r") == 0) |
1240 | args.reltime = true; | |
957a0f07 JB |
1241 | else |
1242 | return 1; | |
1243 | argc--; | |
1244 | argv++; | |
1245 | } | |
1246 | ||
981b21ad JB |
1247 | if (args.time && args.reltime) |
1248 | return 1; | |
1249 | ||
957a0f07 JB |
1250 | if (argc) |
1251 | return 1; | |
1252 | ||
ee374e4d JB |
1253 | ret = __prepare_listen_events(state); |
1254 | if (ret) | |
1255 | return ret; | |
1256 | ||
2e192cea | 1257 | return __do_listen_events(state, 0, NULL, 0, NULL, &args); |
957a0f07 | 1258 | } |
ef65e9cc | 1259 | TOPLEVEL(event, "[-t|-r] [-f]", 0, 0, CIB_NONE, print_events, |
01ae06f9 JB |
1260 | "Monitor events from the kernel.\n" |
1261 | "-t - print timestamp\n" | |
68dd562b | 1262 | "-r - print relative timestamp\n" |
01ae06f9 | 1263 | "-f - print full frame for auth/assoc etc."); |