]>
Commit | Line | Data |
---|---|---|
957a0f07 JB |
1 | #include <stdint.h> |
2 | #include <stdbool.h> | |
3 | #include <net/if.h> | |
4 | #include <errno.h> | |
5 | #include "iw.h" | |
6 | ||
7 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
8 | { | |
9 | return NL_OK; | |
10 | } | |
11 | ||
0168589d LR |
12 | struct ieee80211_beacon_channel { |
13 | __u16 center_freq; | |
14 | bool passive_scan; | |
15 | bool no_ibss; | |
16 | }; | |
17 | ||
18 | static int parse_beacon_hint_chan(struct nlattr *tb, | |
19 | struct ieee80211_beacon_channel *chan) | |
20 | { | |
21 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
22 | static struct nla_policy beacon_freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
23 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
24 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
25 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
26 | }; | |
27 | ||
28 | if (nla_parse_nested(tb_freq, | |
29 | NL80211_FREQUENCY_ATTR_MAX, | |
30 | tb, | |
31 | beacon_freq_policy)) | |
32 | return -EINVAL; | |
33 | ||
34 | chan->center_freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); | |
35 | ||
36 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) | |
37 | chan->passive_scan = true; | |
38 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
39 | chan->no_ibss = true; | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
957a0f07 JB |
44 | static void print_frame(struct print_event_args *args, struct nlattr *attr) |
45 | { | |
46 | uint8_t *frame; | |
47 | size_t len; | |
48 | int i; | |
49 | char macbuf[6*3]; | |
50 | uint16_t tmp; | |
51 | ||
52 | if (!attr) | |
53 | printf(" [no frame]"); | |
54 | ||
55 | frame = nla_data(attr); | |
56 | len = nla_len(attr); | |
57 | ||
58 | if (len < 26) { | |
59 | printf(" [invalid frame: "); | |
60 | goto print_frame; | |
61 | } | |
62 | ||
63 | mac_addr_n2a(macbuf, frame + 10); | |
64 | printf(" %s -> ", macbuf); | |
65 | mac_addr_n2a(macbuf, frame + 4); | |
66 | printf("%s", macbuf); | |
67 | ||
68 | switch (frame[0] & 0xfc) { | |
69 | case 0x10: /* assoc resp */ | |
70 | case 0x30: /* reassoc resp */ | |
71 | /* status */ | |
72 | tmp = (frame[27] << 8) + frame[26]; | |
73 | printf(" status: %d: %s", tmp, get_status_str(tmp)); | |
74 | break; | |
75 | case 0x00: /* assoc req */ | |
76 | case 0x20: /* reassoc req */ | |
77 | break; | |
78 | case 0xb0: /* auth */ | |
79 | /* status */ | |
80 | tmp = (frame[29] << 8) + frame[28]; | |
81 | printf(" status: %d: %s", tmp, get_status_str(tmp)); | |
82 | break; | |
83 | break; | |
84 | case 0xa0: /* disassoc */ | |
85 | case 0xc0: /* deauth */ | |
86 | /* reason */ | |
87 | tmp = (frame[25] << 8) + frame[24]; | |
88 | printf(" reason %d: %s", tmp, get_reason_str(tmp)); | |
89 | break; | |
90 | } | |
91 | ||
92 | if (!args->frame) | |
93 | return; | |
94 | ||
95 | printf(" [frame:"); | |
96 | ||
97 | print_frame: | |
98 | for (i = 0; i < len; i++) | |
99 | printf(" %.02x", frame[i]); | |
100 | printf("]"); | |
101 | } | |
102 | ||
f19444fe | 103 | static void parse_cqm_event(struct nlattr **attrs) |
7988b229 JO |
104 | { |
105 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
106 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
107 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
108 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
109 | }; | |
110 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; | |
f19444fe | 111 | struct nlattr *cqm_attr = attrs[NL80211_ATTR_CQM]; |
7988b229 JO |
112 | |
113 | printf("connection quality monitor event: "); | |
114 | ||
f19444fe JB |
115 | if (!cqm_attr || |
116 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, cqm_attr, cqm_policy)) { | |
7988b229 JO |
117 | printf("missing data!\n"); |
118 | return; | |
119 | } | |
120 | ||
121 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]) { | |
122 | enum nl80211_cqm_rssi_threshold_event rssi_event; | |
123 | rssi_event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); | |
124 | if (rssi_event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) | |
f19444fe | 125 | printf("RSSI went above threshold\n"); |
7988b229 | 126 | else |
f19444fe JB |
127 | printf("RSSI went below threshold\n"); |
128 | } else if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT] && | |
129 | attrs[NL80211_ATTR_MAC]) { | |
130 | uint32_t frames; | |
131 | char buf[3*6]; | |
132 | ||
133 | frames = nla_get_u32(cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]); | |
134 | mac_addr_n2a(buf, nla_data(attrs[NL80211_ATTR_MAC])); | |
135 | printf("peer %s didn't ACK %d packets\n", buf, frames); | |
136 | } else | |
137 | printf("unknown event\n"); | |
7988b229 JO |
138 | } |
139 | ||
140 | ||
957a0f07 JB |
141 | static int print_event(struct nl_msg *msg, void *arg) |
142 | { | |
143 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
748f8489 | 144 | struct nlattr *tb[NL80211_ATTR_MAX + 1], *nst; |
957a0f07 JB |
145 | struct print_event_args *args = arg; |
146 | char ifname[100]; | |
147 | char macbuf[6*3]; | |
148 | __u8 reg_type; | |
0168589d LR |
149 | struct ieee80211_beacon_channel chan_before_beacon, chan_after_beacon; |
150 | __u32 wiphy_idx = 0; | |
748f8489 | 151 | int rem_nst; |
f1a666a6 | 152 | __u16 status; |
957a0f07 | 153 | |
981b21ad JB |
154 | if (args->time || args->reltime) { |
155 | unsigned long long usecs, previous; | |
156 | ||
157 | previous = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; | |
158 | gettimeofday(&args->ts, NULL); | |
159 | usecs = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; | |
160 | if (args->reltime) { | |
161 | if (!args->have_ts) { | |
162 | usecs = 0; | |
163 | args->have_ts = true; | |
164 | } else | |
165 | usecs -= previous; | |
166 | } | |
167 | printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000); | |
957a0f07 JB |
168 | } |
169 | ||
170 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
171 | genlmsg_attrlen(gnlh, 0), NULL); | |
172 | ||
173 | if (tb[NL80211_ATTR_IFINDEX] && tb[NL80211_ATTR_WIPHY]) { | |
174 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), ifname); | |
175 | printf("%s (phy #%d): ", ifname, nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
176 | } else if (tb[NL80211_ATTR_IFINDEX]) { | |
177 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), ifname); | |
178 | printf("%s: ", ifname); | |
179 | } else if (tb[NL80211_ATTR_WIPHY]) { | |
180 | printf("phy #%d: ", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
181 | } | |
182 | ||
183 | switch (gnlh->cmd) { | |
184 | case NL80211_CMD_NEW_WIPHY: | |
185 | printf("renamed to %s\n", nla_get_string(tb[NL80211_ATTR_WIPHY_NAME])); | |
186 | break; | |
e67be815 JB |
187 | case NL80211_CMD_TRIGGER_SCAN: |
188 | printf("scan started\n"); | |
189 | break; | |
957a0f07 | 190 | case NL80211_CMD_NEW_SCAN_RESULTS: |
748f8489 | 191 | printf("scan finished:"); |
957a0f07 | 192 | case NL80211_CMD_SCAN_ABORTED: |
748f8489 JB |
193 | if (gnlh->cmd == NL80211_CMD_SCAN_ABORTED) |
194 | printf("scan aborted:"); | |
195 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
196 | nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem_nst) | |
197 | printf(" %d", nla_get_u32(nst)); | |
198 | printf(","); | |
199 | } | |
200 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { | |
201 | nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_SSIDS], rem_nst) { | |
202 | printf(" \""); | |
203 | print_ssid_escaped(nla_len(nst), nla_data(nst)); | |
204 | printf("\""); | |
205 | } | |
206 | } | |
207 | printf("\n"); | |
957a0f07 JB |
208 | break; |
209 | case NL80211_CMD_REG_CHANGE: | |
210 | printf("regulatory domain change: "); | |
211 | ||
212 | reg_type = nla_get_u8(tb[NL80211_ATTR_REG_TYPE]); | |
213 | ||
214 | switch (reg_type) { | |
215 | case NL80211_REGDOM_TYPE_COUNTRY: | |
216 | printf("set to %s by %s request", | |
217 | nla_get_string(tb[NL80211_ATTR_REG_ALPHA2]), | |
218 | reg_initiator_to_string(nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR]))); | |
219 | if (tb[NL80211_ATTR_WIPHY]) | |
220 | printf(" on phy%d", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
221 | break; | |
222 | case NL80211_REGDOM_TYPE_WORLD: | |
223 | printf("set to world roaming by %s request", | |
224 | reg_initiator_to_string(nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR]))); | |
225 | break; | |
226 | case NL80211_REGDOM_TYPE_CUSTOM_WORLD: | |
227 | printf("custom world roaming rules in place on phy%d by %s request", | |
228 | nla_get_u32(tb[NL80211_ATTR_WIPHY]), | |
229 | reg_initiator_to_string(nla_get_u32(tb[NL80211_ATTR_REG_INITIATOR]))); | |
230 | break; | |
231 | case NL80211_REGDOM_TYPE_INTERSECTION: | |
232 | printf("intersection used due to a request made by %s", | |
233 | reg_initiator_to_string(nla_get_u32(tb[NL80211_ATTR_REG_INITIATOR]))); | |
234 | if (tb[NL80211_ATTR_WIPHY]) | |
235 | printf(" on phy%d", nla_get_u32(tb[NL80211_ATTR_WIPHY])); | |
236 | break; | |
237 | default: | |
238 | printf("unknown source (upgrade this utility)"); | |
239 | break; | |
240 | } | |
241 | ||
242 | printf("\n"); | |
0168589d LR |
243 | break; |
244 | case NL80211_CMD_REG_BEACON_HINT: | |
245 | ||
246 | wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
247 | ||
248 | memset(&chan_before_beacon, 0, sizeof(chan_before_beacon)); | |
249 | memset(&chan_after_beacon, 0, sizeof(chan_after_beacon)); | |
250 | ||
ce3b2ed9 JB |
251 | if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_BEFORE], |
252 | &chan_before_beacon)) | |
253 | break; | |
254 | if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_AFTER], | |
255 | &chan_after_beacon)) | |
256 | break; | |
0168589d LR |
257 | |
258 | if (chan_before_beacon.center_freq != chan_after_beacon.center_freq) | |
259 | break; | |
260 | ||
261 | /* A beacon hint is sent _only_ if something _did_ change */ | |
262 | printf("beacon hint:\n"); | |
263 | ||
264 | printf("phy%d %d MHz [%d]:\n", | |
265 | wiphy_idx, | |
266 | chan_before_beacon.center_freq, | |
267 | ieee80211_frequency_to_channel(chan_before_beacon.center_freq)); | |
268 | ||
269 | if (chan_before_beacon.passive_scan && !chan_after_beacon.passive_scan) | |
270 | printf("\to active scanning enabled\n"); | |
271 | if (chan_before_beacon.no_ibss && !chan_after_beacon.no_ibss) | |
272 | printf("\to beaconing enabled\n"); | |
273 | ||
cec6d6a7 JB |
274 | break; |
275 | case NL80211_CMD_NEW_STATION: | |
276 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
277 | printf("new station %s\n", macbuf); | |
957a0f07 JB |
278 | break; |
279 | case NL80211_CMD_JOIN_IBSS: | |
280 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
281 | printf("IBSS %s joined\n", macbuf); | |
282 | break; | |
283 | case NL80211_CMD_AUTHENTICATE: | |
284 | printf("auth"); | |
aea5dbd2 JB |
285 | if (tb[NL80211_ATTR_FRAME]) |
286 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
287 | else if (tb[NL80211_ATTR_TIMED_OUT]) | |
288 | printf(": timed out"); | |
289 | else | |
290 | printf(": unknown event"); | |
957a0f07 JB |
291 | printf("\n"); |
292 | break; | |
293 | case NL80211_CMD_ASSOCIATE: | |
294 | printf("assoc"); | |
aea5dbd2 JB |
295 | if (tb[NL80211_ATTR_FRAME]) |
296 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
297 | else if (tb[NL80211_ATTR_TIMED_OUT]) | |
298 | printf(": timed out"); | |
299 | else | |
300 | printf(": unknown event"); | |
957a0f07 JB |
301 | printf("\n"); |
302 | break; | |
303 | case NL80211_CMD_DEAUTHENTICATE: | |
304 | printf("deauth"); | |
305 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
306 | printf("\n"); | |
307 | break; | |
308 | case NL80211_CMD_DISASSOCIATE: | |
309 | printf("disassoc"); | |
310 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
311 | printf("\n"); | |
312 | break; | |
99802e56 JB |
313 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
314 | printf("unprotected deauth"); | |
315 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
316 | printf("\n"); | |
317 | break; | |
318 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
319 | printf("unprotected disassoc"); | |
320 | print_frame(args, tb[NL80211_ATTR_FRAME]); | |
321 | printf("\n"); | |
322 | break; | |
f1a666a6 JB |
323 | case NL80211_CMD_CONNECT: |
324 | status = 0; | |
325 | if (!tb[NL80211_ATTR_STATUS_CODE]) | |
326 | printf("unknown connect status"); | |
327 | else if (nla_get_u16(tb[NL80211_ATTR_STATUS_CODE]) == 0) | |
328 | printf("connected"); | |
329 | else { | |
330 | status = nla_get_u16(tb[NL80211_ATTR_STATUS_CODE]); | |
331 | printf("failed to connect"); | |
332 | } | |
333 | if (tb[NL80211_ATTR_MAC]) { | |
334 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
335 | printf(" to %s", macbuf); | |
336 | } | |
337 | if (status) | |
338 | printf(", status: %d: %s", status, get_status_str(status)); | |
339 | printf("\n"); | |
340 | break; | |
341 | case NL80211_CMD_ROAM: | |
342 | printf("roamed"); | |
343 | if (tb[NL80211_ATTR_MAC]) { | |
344 | mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC])); | |
345 | printf(" to %s", macbuf); | |
346 | } | |
347 | printf("\n"); | |
348 | break; | |
349 | case NL80211_CMD_DISCONNECT: | |
350 | printf("disconnected"); | |
351 | if (tb[NL80211_ATTR_DISCONNECTED_BY_AP]) | |
352 | printf(" (by AP)"); | |
353 | else | |
354 | printf(" (local request)"); | |
355 | if (tb[NL80211_ATTR_REASON_CODE]) | |
356 | printf(" reason: %d: %s", nla_get_u16(tb[NL80211_ATTR_REASON_CODE]), | |
357 | get_reason_str(nla_get_u16(tb[NL80211_ATTR_REASON_CODE]))); | |
358 | printf("\n"); | |
359 | break; | |
6829308d JB |
360 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
361 | printf("remain on freq %d (%dms, cookie %llx)\n", | |
362 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]), | |
363 | nla_get_u32(tb[NL80211_ATTR_DURATION]), | |
364 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE])); | |
365 | break; | |
366 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: | |
367 | printf("done with remain on freq %d (cookie %llx)\n", | |
368 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]), | |
369 | (unsigned long long)nla_get_u64(tb[NL80211_ATTR_COOKIE])); | |
370 | break; | |
7988b229 | 371 | case NL80211_CMD_NOTIFY_CQM: |
f19444fe | 372 | parse_cqm_event(tb); |
7988b229 | 373 | break; |
957a0f07 JB |
374 | default: |
375 | printf("unknown event %d\n", gnlh->cmd); | |
376 | break; | |
377 | } | |
378 | ||
374e8a26 | 379 | fflush(stdout); |
957a0f07 JB |
380 | return NL_SKIP; |
381 | } | |
382 | ||
383 | struct wait_event { | |
384 | int n_cmds; | |
385 | const __u32 *cmds; | |
386 | __u32 cmd; | |
7fabd346 | 387 | struct print_event_args *pargs; |
957a0f07 JB |
388 | }; |
389 | ||
390 | static int wait_event(struct nl_msg *msg, void *arg) | |
391 | { | |
392 | struct wait_event *wait = arg; | |
393 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
394 | int i; | |
395 | ||
396 | for (i = 0; i < wait->n_cmds; i++) { | |
397 | if (gnlh->cmd == wait->cmds[i]) { | |
398 | wait->cmd = gnlh->cmd; | |
7e7c544f JB |
399 | if (wait->pargs) |
400 | print_event(msg, wait->pargs); | |
957a0f07 JB |
401 | } |
402 | } | |
403 | ||
404 | return NL_SKIP; | |
405 | } | |
406 | ||
ee374e4d | 407 | int __prepare_listen_events(struct nl80211_state *state) |
957a0f07 JB |
408 | { |
409 | int mcid, ret; | |
957a0f07 JB |
410 | |
411 | /* Configuration multicast group */ | |
412 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "config"); | |
413 | if (mcid < 0) | |
414 | return mcid; | |
415 | ||
416 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
417 | if (ret) | |
418 | return ret; | |
419 | ||
420 | /* Scan multicast group */ | |
421 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "scan"); | |
422 | if (mcid >= 0) { | |
423 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
424 | if (ret) | |
425 | return ret; | |
426 | } | |
427 | ||
428 | /* Regulatory multicast group */ | |
429 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "regulatory"); | |
430 | if (mcid >= 0) { | |
431 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
432 | if (ret) | |
433 | return ret; | |
434 | } | |
435 | ||
436 | /* MLME multicast group */ | |
437 | mcid = nl_get_multicast_id(state->nl_sock, "nl80211", "mlme"); | |
438 | if (mcid >= 0) { | |
439 | ret = nl_socket_add_membership(state->nl_sock, mcid); | |
440 | if (ret) | |
441 | return ret; | |
442 | } | |
443 | ||
105aed57 JB |
444 | return 0; |
445 | } | |
446 | ||
ee374e4d JB |
447 | __u32 __do_listen_events(struct nl80211_state *state, |
448 | const int n_waits, const __u32 *waits, | |
449 | struct print_event_args *args) | |
105aed57 JB |
450 | { |
451 | struct nl_cb *cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT); | |
452 | struct wait_event wait_ev; | |
105aed57 JB |
453 | |
454 | if (!cb) { | |
455 | fprintf(stderr, "failed to allocate netlink callbacks\n"); | |
456 | return -ENOMEM; | |
457 | } | |
458 | ||
957a0f07 JB |
459 | /* no sequence checking for multicast messages */ |
460 | nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
461 | ||
462 | if (n_waits && waits) { | |
463 | wait_ev.cmds = waits; | |
464 | wait_ev.n_cmds = n_waits; | |
7fabd346 | 465 | wait_ev.pargs = args; |
957a0f07 | 466 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, wait_event, &wait_ev); |
7fabd346 | 467 | } else |
957a0f07 | 468 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_event, args); |
957a0f07 JB |
469 | |
470 | wait_ev.cmd = 0; | |
471 | ||
472 | while (!wait_ev.cmd) | |
473 | nl_recvmsgs(state->nl_sock, cb); | |
474 | ||
475 | nl_cb_put(cb); | |
476 | ||
477 | return wait_ev.cmd; | |
478 | } | |
479 | ||
480 | __u32 listen_events(struct nl80211_state *state, | |
481 | const int n_waits, const __u32 *waits) | |
482 | { | |
ee374e4d JB |
483 | int ret; |
484 | ||
485 | ret = __prepare_listen_events(state); | |
486 | if (ret) | |
487 | return ret; | |
488 | ||
489 | return __do_listen_events(state, n_waits, waits, NULL); | |
957a0f07 JB |
490 | } |
491 | ||
492 | static int print_events(struct nl80211_state *state, | |
493 | struct nl_cb *cb, | |
494 | struct nl_msg *msg, | |
495 | int argc, char **argv) | |
496 | { | |
497 | struct print_event_args args; | |
ee374e4d | 498 | int ret; |
957a0f07 JB |
499 | |
500 | memset(&args, 0, sizeof(args)); | |
501 | ||
502 | argc--; | |
503 | argv++; | |
504 | ||
505 | while (argc > 0) { | |
506 | if (strcmp(argv[0], "-f") == 0) | |
507 | args.frame = true; | |
508 | else if (strcmp(argv[0], "-t") == 0) | |
509 | args.time = true; | |
981b21ad JB |
510 | else if (strcmp(argv[0], "-r") == 0) |
511 | args.reltime = true; | |
957a0f07 JB |
512 | else |
513 | return 1; | |
514 | argc--; | |
515 | argv++; | |
516 | } | |
517 | ||
981b21ad JB |
518 | if (args.time && args.reltime) |
519 | return 1; | |
520 | ||
957a0f07 JB |
521 | if (argc) |
522 | return 1; | |
523 | ||
ee374e4d JB |
524 | ret = __prepare_listen_events(state); |
525 | if (ret) | |
526 | return ret; | |
527 | ||
528 | return __do_listen_events(state, 0, NULL, &args); | |
957a0f07 | 529 | } |
981b21ad | 530 | TOPLEVEL(event, "[-t] [-r] [-f]", 0, 0, CIB_NONE, print_events, |
01ae06f9 JB |
531 | "Monitor events from the kernel.\n" |
532 | "-t - print timestamp\n" | |
981b21ad | 533 | "-r - print relative timstamp\n" |
01ae06f9 | 534 | "-f - print full frame for auth/assoc etc."); |