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