7 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
12 struct ieee80211_beacon_channel
{
18 static int parse_beacon_hint_chan(struct nlattr
*tb
,
19 struct ieee80211_beacon_channel
*chan
)
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_NO_IR
] = { .type
= NLA_FLAG
},
25 [__NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
28 if (nla_parse_nested(tb_freq
,
29 NL80211_FREQUENCY_ATTR_MAX
,
34 chan
->center_freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
36 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IR
])
38 if (tb_freq
[__NL80211_FREQUENCY_ATTR_NO_IBSS
])
44 static void print_frame(struct print_event_args
*args
, struct nlattr
*attr
)
53 printf(" [no frame]");
57 frame
= nla_data(attr
);
61 printf(" [invalid frame: ");
65 mac_addr_n2a(macbuf
, frame
+ 10);
66 printf(" %s -> ", macbuf
);
67 mac_addr_n2a(macbuf
, frame
+ 4);
70 switch (frame
[0] & 0xfc) {
71 case 0x10: /* assoc resp */
72 case 0x30: /* reassoc resp */
74 tmp
= (frame
[27] << 8) + frame
[26];
75 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
77 case 0x00: /* assoc req */
78 case 0x20: /* reassoc req */
82 tmp
= (frame
[29] << 8) + frame
[28];
83 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
85 case 0xa0: /* disassoc */
86 case 0xc0: /* deauth */
88 tmp
= (frame
[25] << 8) + frame
[24];
89 printf(" reason %d: %s", tmp
, get_reason_str(tmp
));
99 for (i
= 0; i
< len
; i
++)
100 printf(" %.02x", frame
[i
]);
104 static void parse_cqm_event(struct nlattr
**attrs
)
106 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
107 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
108 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
109 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
111 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
112 struct nlattr
*cqm_attr
= attrs
[NL80211_ATTR_CQM
];
114 printf("CQM event: ");
117 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, cqm_attr
, cqm_policy
)) {
118 printf("missing data!\n");
122 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]) {
123 enum nl80211_cqm_rssi_threshold_event rssi_event
;
124 bool found_one
= false;
126 rssi_event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
128 switch (rssi_event
) {
129 case NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
:
130 printf("RSSI went above threshold\n");
133 case NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
:
134 printf("RSSI went below threshold\n");
137 case NL80211_CQM_RSSI_BEACON_LOSS_EVENT
:
138 printf("Beacon loss detected\n");
144 printf("Unknown event type: %i\n", rssi_event
);
145 } else if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
146 if (attrs
[NL80211_ATTR_MAC
]) {
150 frames
= nla_get_u32(cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]);
151 mac_addr_n2a(buf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
152 printf("peer %s didn't ACK %d packets\n", buf
, frames
);
154 printf("PKT-LOSS-EVENT did not have MAC attribute!\n");
156 } else if (cqm
[NL80211_ATTR_CQM_BEACON_LOSS_EVENT
]) {
157 printf("beacon loss\n");
159 printf("unknown event\n");
163 static const char * key_type_str(enum nl80211_key_type key_type
)
167 case NL80211_KEYTYPE_GROUP
:
169 case NL80211_KEYTYPE_PAIRWISE
:
171 case NL80211_KEYTYPE_PEERKEY
:
174 snprintf(buf
, sizeof(buf
), "unknown(%d)", key_type
);
179 static void parse_mic_failure(struct nlattr
**attrs
)
181 printf("Michael MIC failure event:");
183 if (attrs
[NL80211_ATTR_MAC
]) {
184 char addr
[3 * ETH_ALEN
];
185 mac_addr_n2a(addr
, nla_data(attrs
[NL80211_ATTR_MAC
]));
186 printf(" source MAC address %s", addr
);
189 if (attrs
[NL80211_ATTR_KEY_SEQ
] &&
190 nla_len(attrs
[NL80211_ATTR_KEY_SEQ
]) == 6) {
191 unsigned char *seq
= nla_data(attrs
[NL80211_ATTR_KEY_SEQ
]);
192 printf(" seq=%02x%02x%02x%02x%02x%02x",
193 seq
[0], seq
[1], seq
[2], seq
[3], seq
[4], seq
[5]);
195 if (attrs
[NL80211_ATTR_KEY_TYPE
]) {
196 enum nl80211_key_type key_type
=
197 nla_get_u32(attrs
[NL80211_ATTR_KEY_TYPE
]);
198 printf(" Key Type %s", key_type_str(key_type
));
201 if (attrs
[NL80211_ATTR_KEY_IDX
]) {
202 __u8 key_id
= nla_get_u8(attrs
[NL80211_ATTR_KEY_IDX
]);
203 printf(" Key Id %d", key_id
);
209 static void parse_wowlan_wake_event(struct nlattr
**attrs
)
211 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
],
212 *tb_match
[NUM_NL80211_ATTR
];
214 printf("WoWLAN wakeup\n");
215 if (!attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
216 printf("\twakeup not due to WoWLAN\n");
220 nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
221 nla_data(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
222 nla_len(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]), NULL
);
224 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
])
225 printf("\t* was disconnected\n");
226 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
227 printf("\t* magic packet received\n");
228 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
])
229 printf("\t* pattern index: %u\n",
230 nla_get_u32(tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]));
231 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
232 printf("\t* GTK rekey failure\n");
233 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
234 printf("\t* EAP identity request\n");
235 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
236 printf("\t* 4-way handshake\n");
237 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
238 printf("\t* RF-kill released\n");
239 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
]) {
240 struct nlattr
*match
, *freq
;
241 int rem_nst
, rem_nst2
;
243 printf("\t* network detected\n");
244 nla_for_each_nested(match
,
245 tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
],
247 nla_parse(tb_match
, NUM_NL80211_ATTR
, nla_data(match
),
250 printf("\t\tSSID: \"");
251 print_ssid_escaped(nla_len(tb_match
[NL80211_ATTR_SSID
]),
252 nla_data(tb_match
[NL80211_ATTR_SSID
]));
254 if (tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
256 nla_for_each_nested(freq
,
257 tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
],
259 printf(" %d", nla_get_u32(freq
));
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
]);
268 printf("\t* packet (might be truncated): ");
269 for (i
= 0; i
< l
; i
++) {
272 printf("%.2x", d
[i
]);
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
]);
280 printf("\t* packet (might be truncated): ");
281 for (i
= 0; i
< l
; i
++) {
284 printf("%.2x", d
[i
]);
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");
296 static int print_event(struct nl_msg
*msg
, void *arg
)
298 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
299 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1], *nst
;
300 struct print_event_args
*args
= arg
;
304 struct ieee80211_beacon_channel chan_before_beacon
, chan_after_beacon
;
309 if (args
->time
|| args
->reltime
) {
310 unsigned long long usecs
, previous
;
312 previous
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
313 gettimeofday(&args
->ts
, NULL
);
314 usecs
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
316 if (!args
->have_ts
) {
318 args
->have_ts
= true;
322 printf("%llu.%06llu: ", usecs
/1000000, usecs
% 1000000);
325 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
326 genlmsg_attrlen(gnlh
, 0), NULL
);
328 if (tb
[NL80211_ATTR_IFINDEX
] && tb
[NL80211_ATTR_WIPHY
]) {
329 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
330 printf("%s (phy #%d): ", ifname
, nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
331 } else if (tb
[NL80211_ATTR_WDEV
] && tb
[NL80211_ATTR_WIPHY
]) {
332 printf("wdev 0x%llx (phy #%d): ",
333 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]),
334 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
335 } else if (tb
[NL80211_ATTR_IFINDEX
]) {
336 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
337 printf("%s: ", ifname
);
338 } else if (tb
[NL80211_ATTR_WDEV
]) {
339 printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]));
340 } else if (tb
[NL80211_ATTR_WIPHY
]) {
341 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
345 case NL80211_CMD_NEW_WIPHY
:
346 printf("renamed to %s\n", nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]));
348 case NL80211_CMD_TRIGGER_SCAN
:
349 printf("scan started\n");
351 case NL80211_CMD_NEW_SCAN_RESULTS
:
352 printf("scan finished:");
353 case NL80211_CMD_SCAN_ABORTED
:
354 if (gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)
355 printf("scan aborted:");
356 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
357 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem_nst
)
358 printf(" %d", nla_get_u32(nst
));
361 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
362 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem_nst
) {
364 print_ssid_escaped(nla_len(nst
), nla_data(nst
));
370 case NL80211_CMD_START_SCHED_SCAN
:
371 printf("scheduled scan started\n");
373 case NL80211_CMD_SCHED_SCAN_STOPPED
:
374 printf("sched scan stopped\n");
376 case NL80211_CMD_SCHED_SCAN_RESULTS
:
377 printf("got scheduled scan results\n");
379 case NL80211_CMD_REG_CHANGE
:
380 printf("regulatory domain change: ");
382 reg_type
= nla_get_u8(tb
[NL80211_ATTR_REG_TYPE
]);
385 case NL80211_REGDOM_TYPE_COUNTRY
:
386 printf("set to %s by %s request",
387 nla_get_string(tb
[NL80211_ATTR_REG_ALPHA2
]),
388 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
389 if (tb
[NL80211_ATTR_WIPHY
])
390 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
392 case NL80211_REGDOM_TYPE_WORLD
:
393 printf("set to world roaming by %s request",
394 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
396 case NL80211_REGDOM_TYPE_CUSTOM_WORLD
:
397 printf("custom world roaming rules in place on phy%d by %s request",
398 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]),
399 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
401 case NL80211_REGDOM_TYPE_INTERSECTION
:
402 printf("intersection used due to a request made by %s",
403 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
404 if (tb
[NL80211_ATTR_WIPHY
])
405 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
408 printf("unknown source (upgrade this utility)");
414 case NL80211_CMD_REG_BEACON_HINT
:
416 wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
418 memset(&chan_before_beacon
, 0, sizeof(chan_before_beacon
));
419 memset(&chan_after_beacon
, 0, sizeof(chan_after_beacon
));
421 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_BEFORE
],
422 &chan_before_beacon
))
424 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_AFTER
],
428 if (chan_before_beacon
.center_freq
!= chan_after_beacon
.center_freq
)
431 /* A beacon hint is sent _only_ if something _did_ change */
432 printf("beacon hint:\n");
434 printf("phy%d %d MHz [%d]:\n",
436 chan_before_beacon
.center_freq
,
437 ieee80211_frequency_to_channel(chan_before_beacon
.center_freq
));
439 if (chan_before_beacon
.no_ir
&& !chan_after_beacon
.no_ir
) {
440 if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
)
441 printf("\to Initiating radiation enabled\n");
443 printf("\to active scan enabled\n");
444 } else if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
) {
445 printf("\to ibss enabled\n");
449 case NL80211_CMD_NEW_STATION
:
450 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
451 printf("new station %s\n", macbuf
);
453 case NL80211_CMD_DEL_STATION
:
454 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
455 printf("del station %s\n", macbuf
);
457 case NL80211_CMD_JOIN_IBSS
:
458 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
459 printf("IBSS %s joined\n", macbuf
);
461 case NL80211_CMD_AUTHENTICATE
:
463 if (tb
[NL80211_ATTR_FRAME
])
464 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
465 else if (tb
[NL80211_ATTR_TIMED_OUT
])
466 printf(": timed out");
468 printf(": unknown event");
471 case NL80211_CMD_ASSOCIATE
:
473 if (tb
[NL80211_ATTR_FRAME
])
474 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
475 else if (tb
[NL80211_ATTR_TIMED_OUT
])
476 printf(": timed out");
478 printf(": unknown event");
481 case NL80211_CMD_DEAUTHENTICATE
:
483 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
486 case NL80211_CMD_DISASSOCIATE
:
488 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
491 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
492 printf("unprotected deauth");
493 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
496 case NL80211_CMD_UNPROT_DISASSOCIATE
:
497 printf("unprotected disassoc");
498 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
501 case NL80211_CMD_CONNECT
:
503 if (!tb
[NL80211_ATTR_STATUS_CODE
])
504 printf("unknown connect status");
505 else if (nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]) == 0)
508 status
= nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]);
509 printf("failed to connect");
511 if (tb
[NL80211_ATTR_MAC
]) {
512 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
513 printf(" to %s", macbuf
);
516 printf(", status: %d: %s", status
, get_status_str(status
));
519 case NL80211_CMD_ROAM
:
521 if (tb
[NL80211_ATTR_MAC
]) {
522 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
523 printf(" to %s", macbuf
);
527 case NL80211_CMD_DISCONNECT
:
528 printf("disconnected");
529 if (tb
[NL80211_ATTR_DISCONNECTED_BY_AP
])
532 printf(" (local request)");
533 if (tb
[NL80211_ATTR_REASON_CODE
])
534 printf(" reason: %d: %s", nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]),
535 get_reason_str(nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
])));
538 case NL80211_CMD_REMAIN_ON_CHANNEL
:
539 printf("remain on freq %d (%dms, cookie %llx)\n",
540 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
541 nla_get_u32(tb
[NL80211_ATTR_DURATION
]),
542 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
544 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
545 printf("done with remain on freq %d (cookie %llx)\n",
546 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
547 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
549 case NL80211_CMD_NOTIFY_CQM
:
552 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
553 parse_mic_failure(tb
);
555 case NL80211_CMD_FRAME_TX_STATUS
:
556 printf("mgmt TX status (cookie %llx): %s\n",
557 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
558 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
560 case NL80211_CMD_PMKSA_CANDIDATE
:
561 printf("PMKSA candidate found\n");
563 case NL80211_CMD_SET_WOWLAN
:
564 parse_wowlan_wake_event(tb
);
566 case NL80211_CMD_PROBE_CLIENT
:
567 if (tb
[NL80211_ATTR_MAC
])
568 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
570 strcpy(macbuf
, "??");
571 printf("probe client %s (cookie %llx): %s\n",
573 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
574 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
576 case NL80211_CMD_VENDOR
:
577 printf("vendor event %.6x:%d\n",
578 nla_get_u32(tb
[NL80211_ATTR_VENDOR_ID
]),
579 nla_get_u32(tb
[NL80211_ATTR_VENDOR_SUBCMD
]));
580 if (args
->frame
&& tb
[NL80211_ATTR_VENDOR_DATA
])
581 iw_hexdump("vendor event",
582 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
583 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
585 case NL80211_CMD_RADAR_DETECT
:
586 printf("radar event ");
587 if (tb
[NL80211_ATTR_RADAR_EVENT
]) {
588 switch (nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
])) {
589 case NL80211_RADAR_DETECTED
:
590 printf("(radar detected)");
592 case NL80211_RADAR_CAC_FINISHED
:
593 printf("(cac finished)");
595 case NL80211_RADAR_CAC_ABORTED
:
596 printf("(cac aborted)");
598 case NL80211_RADAR_NOP_FINISHED
:
599 printf("(nop finished)");
610 case NL80211_CMD_DEL_WIPHY
:
611 printf("delete wiphy\n");
614 printf("unknown event %d (%s)\n",
615 gnlh
->cmd
, command_name(gnlh
->cmd
));
627 struct print_event_args
*pargs
;
630 static int wait_event(struct nl_msg
*msg
, void *arg
)
632 struct wait_event
*wait
= arg
;
633 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
636 for (i
= 0; i
< wait
->n_cmds
; i
++) {
637 if (gnlh
->cmd
== wait
->cmds
[i
]) {
638 wait
->cmd
= gnlh
->cmd
;
640 print_event(msg
, wait
->pargs
);
647 int __prepare_listen_events(struct nl80211_state
*state
)
651 /* Configuration multicast group */
652 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "config");
656 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
660 /* Scan multicast group */
661 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "scan");
663 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
668 /* Regulatory multicast group */
669 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "regulatory");
671 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
676 /* MLME multicast group */
677 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "mlme");
679 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
684 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "vendor");
686 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
694 __u32
__do_listen_events(struct nl80211_state
*state
,
695 const int n_waits
, const __u32
*waits
,
696 struct print_event_args
*args
)
698 struct nl_cb
*cb
= nl_cb_alloc(iw_debug
? NL_CB_DEBUG
: NL_CB_DEFAULT
);
699 struct wait_event wait_ev
;
702 fprintf(stderr
, "failed to allocate netlink callbacks\n");
706 /* no sequence checking for multicast messages */
707 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
708 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, valid_handler
, NULL
);
710 if (n_waits
&& waits
) {
711 wait_ev
.cmds
= waits
;
712 wait_ev
.n_cmds
= n_waits
;
713 wait_ev
.pargs
= args
;
714 register_handler(wait_event
, &wait_ev
);
716 register_handler(print_event
, args
);
721 nl_recvmsgs(state
->nl_sock
, cb
);
728 __u32
listen_events(struct nl80211_state
*state
,
729 const int n_waits
, const __u32
*waits
)
733 ret
= __prepare_listen_events(state
);
737 return __do_listen_events(state
, n_waits
, waits
, NULL
);
740 static int print_events(struct nl80211_state
*state
,
742 int argc
, char **argv
,
745 struct print_event_args args
;
748 memset(&args
, 0, sizeof(args
));
754 if (strcmp(argv
[0], "-f") == 0)
756 else if (strcmp(argv
[0], "-t") == 0)
758 else if (strcmp(argv
[0], "-r") == 0)
766 if (args
.time
&& args
.reltime
)
772 ret
= __prepare_listen_events(state
);
776 return __do_listen_events(state
, 0, NULL
, &args
);
778 TOPLEVEL(event
, "[-t] [-r] [-f]", 0, 0, CIB_NONE
, print_events
,
779 "Monitor events from the kernel.\n"
780 "-t - print timestamp\n"
781 "-r - print relative timstamp\n"
782 "-f - print full frame for auth/assoc etc.");