9 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
14 struct ieee80211_beacon_channel
{
20 static int parse_beacon_hint_chan(struct nlattr
*tb
,
21 struct ieee80211_beacon_channel
*chan
)
23 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
24 static struct nla_policy beacon_freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
25 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
26 [NL80211_FREQUENCY_ATTR_NO_IR
] = { .type
= NLA_FLAG
},
27 [__NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
30 if (nla_parse_nested(tb_freq
,
31 NL80211_FREQUENCY_ATTR_MAX
,
36 chan
->center_freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
38 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IR
])
40 if (tb_freq
[__NL80211_FREQUENCY_ATTR_NO_IBSS
])
46 static void print_frame(struct print_event_args
*args
, struct nlattr
*attr
)
55 printf(" [no frame]");
59 frame
= nla_data(attr
);
63 printf(" [invalid frame: ");
67 mac_addr_n2a(macbuf
, frame
+ 10);
68 printf(" %s -> ", macbuf
);
69 mac_addr_n2a(macbuf
, frame
+ 4);
72 switch (frame
[0] & 0xfc) {
73 case 0x10: /* assoc resp */
74 case 0x30: /* reassoc resp */
76 tmp
= (frame
[27] << 8) + frame
[26];
77 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
79 case 0x00: /* assoc req */
80 case 0x20: /* reassoc req */
84 tmp
= (frame
[29] << 8) + frame
[28];
85 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
87 case 0xa0: /* disassoc */
88 case 0xc0: /* deauth */
90 tmp
= (frame
[25] << 8) + frame
[24];
91 printf(" reason %d: %s", tmp
, get_reason_str(tmp
));
101 for (i
= 0; i
< len
; i
++)
102 printf(" %.02x", frame
[i
]);
106 static void parse_cqm_event(struct nlattr
**attrs
)
108 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
109 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
110 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
111 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
113 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
114 struct nlattr
*cqm_attr
= attrs
[NL80211_ATTR_CQM
];
116 printf("CQM event: ");
119 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, cqm_attr
, cqm_policy
)) {
120 printf("missing data!\n");
124 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]) {
125 enum nl80211_cqm_rssi_threshold_event rssi_event
;
126 int32_t rssi_level
= -1;
127 bool found_one
= false;
129 rssi_event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
130 if (cqm
[NL80211_ATTR_CQM_RSSI_LEVEL
])
131 rssi_level
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_LEVEL
]);
133 switch (rssi_event
) {
134 case NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
:
135 printf("RSSI (%i dBm) went above threshold\n", rssi_level
);
138 case NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
:
139 printf("RSSI (%i dBm) went below threshold\n", rssi_level
);
142 case NL80211_CQM_RSSI_BEACON_LOSS_EVENT
:
143 printf("Beacon loss detected\n");
149 printf("Unknown event type: %i\n", rssi_event
);
150 } else if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
151 if (attrs
[NL80211_ATTR_MAC
]) {
155 frames
= nla_get_u32(cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]);
156 mac_addr_n2a(buf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
157 printf("peer %s didn't ACK %d packets\n", buf
, frames
);
159 printf("PKT-LOSS-EVENT did not have MAC attribute!\n");
161 } else if (cqm
[NL80211_ATTR_CQM_BEACON_LOSS_EVENT
]) {
162 printf("beacon loss\n");
164 printf("unknown event\n");
168 static const char * key_type_str(enum nl80211_key_type key_type
)
172 case NL80211_KEYTYPE_GROUP
:
174 case NL80211_KEYTYPE_PAIRWISE
:
176 case NL80211_KEYTYPE_PEERKEY
:
179 snprintf(buf
, sizeof(buf
), "unknown(%d)", key_type
);
184 static void parse_mic_failure(struct nlattr
**attrs
)
186 printf("Michael MIC failure event:");
188 if (attrs
[NL80211_ATTR_MAC
]) {
189 char addr
[3 * ETH_ALEN
];
190 mac_addr_n2a(addr
, nla_data(attrs
[NL80211_ATTR_MAC
]));
191 printf(" source MAC address %s", addr
);
194 if (attrs
[NL80211_ATTR_KEY_SEQ
] &&
195 nla_len(attrs
[NL80211_ATTR_KEY_SEQ
]) == 6) {
196 unsigned char *seq
= nla_data(attrs
[NL80211_ATTR_KEY_SEQ
]);
197 printf(" seq=%02x%02x%02x%02x%02x%02x",
198 seq
[0], seq
[1], seq
[2], seq
[3], seq
[4], seq
[5]);
200 if (attrs
[NL80211_ATTR_KEY_TYPE
]) {
201 enum nl80211_key_type key_type
=
202 nla_get_u32(attrs
[NL80211_ATTR_KEY_TYPE
]);
203 printf(" Key Type %s", key_type_str(key_type
));
206 if (attrs
[NL80211_ATTR_KEY_IDX
]) {
207 __u8 key_id
= nla_get_u8(attrs
[NL80211_ATTR_KEY_IDX
]);
208 printf(" Key Id %d", key_id
);
214 static void parse_wowlan_wake_event(struct nlattr
**attrs
)
216 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
],
217 *tb_match
[NUM_NL80211_ATTR
];
219 printf("WoWLAN wakeup\n");
220 if (!attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
221 printf("\twakeup not due to WoWLAN\n");
225 nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
226 nla_data(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
227 nla_len(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]), NULL
);
229 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
])
230 printf("\t* was disconnected\n");
231 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
232 printf("\t* magic packet received\n");
233 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
])
234 printf("\t* pattern index: %u\n",
235 nla_get_u32(tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]));
236 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
237 printf("\t* GTK rekey failure\n");
238 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
239 printf("\t* EAP identity request\n");
240 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
241 printf("\t* 4-way handshake\n");
242 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
243 printf("\t* RF-kill released\n");
244 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
]) {
245 struct nlattr
*match
, *freq
;
246 int rem_nst
, rem_nst2
;
248 printf("\t* network detected\n");
249 nla_for_each_nested(match
,
250 tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
],
252 nla_parse_nested(tb_match
, NL80211_ATTR_MAX
, match
,
254 printf("\t\tSSID: \"");
255 print_ssid_escaped(nla_len(tb_match
[NL80211_ATTR_SSID
]),
256 nla_data(tb_match
[NL80211_ATTR_SSID
]));
258 if (tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
260 nla_for_each_nested(freq
,
261 tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
],
263 printf(" %d", nla_get_u32(freq
));
268 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]) {
269 uint8_t *d
= nla_data(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]);
270 int l
= nla_len(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]);
272 printf("\t* packet (might be truncated): ");
273 for (i
= 0; i
< l
; i
++) {
276 printf("%.2x", d
[i
]);
280 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]) {
281 uint8_t *d
= nla_data(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]);
282 int l
= nla_len(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]);
284 printf("\t* packet (might be truncated): ");
285 for (i
= 0; i
< l
; i
++) {
288 printf("%.2x", d
[i
]);
292 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
])
293 printf("\t* TCP connection wakeup received\n");
294 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
])
295 printf("\t* TCP connection lost\n");
296 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
])
297 printf("\t* TCP connection ran out of tokens\n");
298 if (tb
[NL80211_WOWLAN_TRIG_UNPROTECTED_DEAUTH_DISASSOC
])
299 printf("\t* unprotected deauth/disassoc\n");
302 extern struct vendor_event
*__start_vendor_event
[];
303 extern struct vendor_event
*__stop_vendor_event
;
305 // Dummy to force the section to exist
306 VENDOR_EVENT(0xffffffff, 0xffffffff, NULL
);
308 static void parse_vendor_event(struct nlattr
**attrs
, bool dump
)
310 __u32 vendor_id
, subcmd
;
313 if (!attrs
[NL80211_ATTR_VENDOR_ID
] ||
314 !attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
317 vendor_id
= nla_get_u32(attrs
[NL80211_ATTR_VENDOR_ID
]);
318 subcmd
= nla_get_u32(attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
320 printf("vendor event %.6x:%d", vendor_id
, subcmd
);
322 for (i
= 0; i
< &__stop_vendor_event
- __start_vendor_event
; i
++) {
323 struct vendor_event
*ev
= __start_vendor_event
[i
];
328 if (ev
->vendor_id
!= vendor_id
)
330 if (ev
->subcmd
!= subcmd
)
335 ev
->callback(vendor_id
, subcmd
, attrs
[NL80211_ATTR_VENDOR_DATA
]);
339 if (dump
&& attrs
[NL80211_ATTR_VENDOR_DATA
])
340 iw_hexdump("vendor event",
341 nla_data(attrs
[NL80211_ATTR_VENDOR_DATA
]),
342 nla_len(attrs
[NL80211_ATTR_VENDOR_DATA
]));
347 static void parse_nan_term(struct nlattr
**attrs
)
349 struct nlattr
*func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
351 static struct nla_policy
352 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
353 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
354 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
355 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
356 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
357 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
358 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
359 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
360 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
361 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
362 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
363 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
364 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
365 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
366 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
367 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
370 if (!attrs
[NL80211_ATTR_COOKIE
]) {
371 printf("Bad NAN func termination format - cookie is missing\n");
375 if (nla_parse_nested(func
, NL80211_NAN_FUNC_ATTR_MAX
,
376 attrs
[NL80211_ATTR_NAN_FUNC
],
378 printf("NAN: failed to parse nan func\n");
382 if (!func
[NL80211_NAN_FUNC_INSTANCE_ID
]) {
383 printf("Bad NAN func termination format-instance id missing\n");
387 if (!func
[NL80211_NAN_FUNC_TERM_REASON
]) {
388 printf("Bad NAN func termination format - reason is missing\n");
391 printf("NAN(cookie=0x%llx): Termination event: id = %d, reason = ",
392 (long long int)nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]),
393 nla_get_u8(func
[NL80211_NAN_FUNC_INSTANCE_ID
]));
394 switch (nla_get_u8(func
[NL80211_NAN_FUNC_TERM_REASON
])) {
395 case NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST
:
396 printf("user request\n");
398 case NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED
:
401 case NL80211_NAN_FUNC_TERM_REASON_ERROR
:
409 static const char *ftm_fail_reason(unsigned int reason
)
411 #define FTM_FAIL_REASON(x) case NL80211_PMSR_FTM_FAILURE_##x: return #x
413 FTM_FAIL_REASON(UNSPECIFIED
);
414 FTM_FAIL_REASON(NO_RESPONSE
);
415 FTM_FAIL_REASON(REJECTED
);
416 FTM_FAIL_REASON(WRONG_CHANNEL
);
417 FTM_FAIL_REASON(PEER_NOT_CAPABLE
);
418 FTM_FAIL_REASON(INVALID_TIMESTAMP
);
419 FTM_FAIL_REASON(PEER_BUSY
);
420 FTM_FAIL_REASON(BAD_CHANGED_PARAMS
);
426 static void parse_pmsr_ftm_data(struct nlattr
*data
)
428 struct nlattr
*ftm
[NL80211_PMSR_FTM_RESP_ATTR_MAX
+ 1];
431 nla_parse_nested(ftm
, NL80211_PMSR_FTM_RESP_ATTR_MAX
, data
, NULL
);
433 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]) {
434 printf(" failed: %s (%d)",
435 ftm_fail_reason(nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
])),
436 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]));
437 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
])
438 printf(" retry after %us",
439 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
]));
446 #define PFTM(tp, attr, sign) \
448 if (ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr]) \
449 printf(" " #attr ": %lld\n", \
450 (sign long long)nla_get_##tp( \
451 ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr])); \
454 PFTM(u32
, BURST_INDEX
, unsigned);
455 PFTM(u32
, NUM_FTMR_ATTEMPTS
, unsigned);
456 PFTM(u32
, NUM_FTMR_SUCCESSES
, unsigned);
457 PFTM(u8
, NUM_BURSTS_EXP
, unsigned);
458 PFTM(u8
, BURST_DURATION
, unsigned);
459 PFTM(u8
, FTMS_PER_BURST
, unsigned);
460 PFTM(u32
, RSSI_AVG
, signed);
461 PFTM(u32
, RSSI_SPREAD
, unsigned);
462 PFTM(u64
, RTT_AVG
, signed);
463 PFTM(u64
, RTT_VARIANCE
, unsigned);
464 PFTM(u64
, RTT_SPREAD
, unsigned);
465 PFTM(u64
, DIST_AVG
, signed);
466 PFTM(u64
, DIST_VARIANCE
, unsigned);
467 PFTM(u64
, DIST_SPREAD
, unsigned);
469 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
]) {
472 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
],
474 printf(" TX bitrate: %s\n", buf
);
477 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
]) {
480 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
],
482 printf(" RX bitrate: %s\n", buf
);
485 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
])
487 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]),
488 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]));
490 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
])
491 iw_hexdump(" civic location",
492 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]),
493 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]));
496 static const char *pmsr_status(unsigned int status
)
498 #define PMSR_STATUS(x) case NL80211_PMSR_STATUS_##x: return #x
500 PMSR_STATUS(SUCCESS
);
501 PMSR_STATUS(REFUSED
);
502 PMSR_STATUS(TIMEOUT
);
503 PMSR_STATUS(FAILURE
);
510 static void parse_pmsr_peer(struct nlattr
*peer
)
512 struct nlattr
*tb
[NL80211_PMSR_PEER_ATTR_MAX
+ 1];
513 struct nlattr
*resp
[NL80211_PMSR_RESP_ATTR_MAX
+ 1];
514 struct nlattr
*data
[NL80211_PMSR_TYPE_MAX
+ 1];
518 err
= nla_parse_nested(tb
, NL80211_PMSR_PEER_ATTR_MAX
, peer
, NULL
);
520 printf(" Peer: failed to parse!\n");
524 if (!tb
[NL80211_PMSR_PEER_ATTR_ADDR
]) {
525 printf(" Peer: no MAC address\n");
529 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_PMSR_PEER_ATTR_ADDR
]));
530 printf(" Peer %s:", macbuf
);
532 if (!tb
[NL80211_PMSR_PEER_ATTR_RESP
]) {
533 printf(" no response!\n");
537 err
= nla_parse_nested(resp
, NL80211_PMSR_RESP_ATTR_MAX
,
538 tb
[NL80211_PMSR_PEER_ATTR_RESP
], NULL
);
540 printf(" failed to parse response!\n");
544 if (resp
[NL80211_PMSR_RESP_ATTR_STATUS
])
545 printf(" status=%d (%s)",
546 nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
]),
547 pmsr_status(nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
])));
548 if (resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
])
550 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
]));
551 if (resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
])
553 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
]));
554 if (resp
[NL80211_PMSR_RESP_ATTR_FINAL
])
557 if (!resp
[NL80211_PMSR_RESP_ATTR_DATA
]) {
558 printf(" - no data!\n");
564 nla_parse_nested(data
, NL80211_PMSR_TYPE_MAX
,
565 resp
[NL80211_PMSR_RESP_ATTR_DATA
], NULL
);
567 if (data
[NL80211_PMSR_TYPE_FTM
])
568 parse_pmsr_ftm_data(data
[NL80211_PMSR_TYPE_FTM
]);
571 static void parse_pmsr_result(struct nlattr
**tb
,
572 struct print_event_args
*pargs
)
574 struct nlattr
*pmsr
[NL80211_PMSR_ATTR_MAX
+ 1];
576 unsigned long long cookie
;
579 if (!tb
[NL80211_ATTR_COOKIE
]) {
580 printf("Peer measurements: no cookie!\n");
583 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
585 if (!tb
[NL80211_ATTR_PEER_MEASUREMENTS
]) {
586 printf("Peer measurements: no measurement data!\n");
590 err
= nla_parse_nested(pmsr
, NL80211_PMSR_ATTR_MAX
,
591 tb
[NL80211_ATTR_PEER_MEASUREMENTS
], NULL
);
593 printf("Peer measurements: failed to parse measurement data!\n");
597 if (!pmsr
[NL80211_PMSR_ATTR_PEERS
]) {
598 printf("Peer measurements: no peer data!\n");
602 printf("Peer measurements (cookie %llu):\n", cookie
);
604 nla_for_each_nested(peer
, pmsr
[NL80211_PMSR_ATTR_PEERS
], i
)
605 parse_pmsr_peer(peer
);
608 static void parse_nan_match(struct nlattr
**attrs
)
612 struct nlattr
*match
[NL80211_NAN_MATCH_ATTR_MAX
+ 1];
613 struct nlattr
*local_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
614 struct nlattr
*peer_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
616 static struct nla_policy
617 nan_match_policy
[NL80211_NAN_MATCH_ATTR_MAX
+ 1] = {
618 [NL80211_NAN_MATCH_FUNC_LOCAL
] = { .type
= NLA_NESTED
},
619 [NL80211_NAN_MATCH_FUNC_PEER
] = { .type
= NLA_NESTED
},
622 static struct nla_policy
623 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
624 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
625 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
626 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
627 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
628 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
629 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
630 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
631 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
632 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
633 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
634 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
635 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
636 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
637 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
638 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
641 cookie
= nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]);
642 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
644 if (nla_parse_nested(match
, NL80211_NAN_MATCH_ATTR_MAX
,
645 attrs
[NL80211_ATTR_NAN_MATCH
],
647 printf("NAN: failed to parse nan match event\n");
651 if (nla_parse_nested(local_func
, NL80211_NAN_FUNC_ATTR_MAX
,
652 match
[NL80211_NAN_MATCH_FUNC_LOCAL
],
654 printf("NAN: failed to parse nan local func\n");
658 if (nla_parse_nested(peer_func
, NL80211_NAN_FUNC_ATTR_MAX
,
659 match
[NL80211_NAN_MATCH_FUNC_PEER
],
661 printf("NAN: failed to parse nan local func\n");
665 if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
666 NL80211_NAN_FUNC_PUBLISH
) {
668 "NAN(cookie=0x%llx): DiscoveryResult, peer_id=%d, local_id=%d, peer_mac=%s",
670 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
671 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
673 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
674 printf(", info=%.*s",
675 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
676 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
677 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
678 NL80211_NAN_FUNC_SUBSCRIBE
) {
680 "NAN(cookie=0x%llx): Replied, peer_id=%d, local_id=%d, peer_mac=%s",
682 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
683 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
685 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
686 NL80211_NAN_FUNC_FOLLOW_UP
) {
688 "NAN(cookie=0x%llx): FollowUpReceive, peer_id=%d, local_id=%d, peer_mac=%s",
690 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
691 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
693 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
694 printf(", info=%.*s",
695 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
696 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
698 printf("NaN: Malformed event");
704 static void parse_new_peer_candidate(struct nlattr
**attrs
)
706 char macbuf
[ETH_ALEN
* 3];
709 printf("new peer candidate");
710 if (attrs
[NL80211_ATTR_MAC
]) {
711 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
712 printf(" %s", macbuf
);
714 if (attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]) {
715 sig_dbm
= nla_get_u32(attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]);
716 printf(" %d dBm", sig_dbm
);
722 static void parse_recv_interface(struct nlattr
**attrs
, int command
)
725 case NL80211_CMD_NEW_INTERFACE
:
726 printf("new interface");
728 case NL80211_CMD_DEL_INTERFACE
:
729 printf("del interface");
731 case NL80211_CMD_SET_INTERFACE
:
732 printf("set interface");
735 printf("unknown interface command (%i) received\n", command
);
739 if (attrs
[NL80211_ATTR_IFTYPE
]) {
741 switch (nla_get_u32(attrs
[NL80211_ATTR_IFTYPE
])) {
742 case NL80211_IFTYPE_STATION
:
745 case NL80211_IFTYPE_AP
:
746 printf("access point");
748 case NL80211_IFTYPE_MESH_POINT
:
749 printf("mesh point");
751 case NL80211_IFTYPE_ADHOC
:
754 case NL80211_IFTYPE_MONITOR
:
757 case NL80211_IFTYPE_AP_VLAN
:
760 case NL80211_IFTYPE_WDS
:
763 case NL80211_IFTYPE_P2P_CLIENT
:
764 printf("P2P-client");
766 case NL80211_IFTYPE_P2P_GO
:
769 case NL80211_IFTYPE_P2P_DEVICE
:
770 printf("P2P-Device");
772 case NL80211_IFTYPE_OCB
:
775 case NL80211_IFTYPE_NAN
:
779 printf("unknown (%d)",
780 nla_get_u32(attrs
[NL80211_ATTR_IFTYPE
]));
785 if (attrs
[NL80211_ATTR_MESH_ID
]) {
787 print_ssid_escaped(nla_len(attrs
[NL80211_ATTR_MESH_ID
]),
788 nla_data(attrs
[NL80211_ATTR_MESH_ID
]));
791 if (attrs
[NL80211_ATTR_4ADDR
]) {
792 printf(" use 4addr %d", nla_get_u8(attrs
[NL80211_ATTR_4ADDR
]));
798 static void parse_sta_opmode_changed(struct nlattr
**attrs
)
800 char macbuf
[ETH_ALEN
*3];
802 printf("sta opmode changed");
804 if (attrs
[NL80211_ATTR_MAC
]) {
805 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
806 printf(" %s", macbuf
);
809 if (attrs
[NL80211_ATTR_SMPS_MODE
])
810 printf(" smps mode %d", nla_get_u8(attrs
[NL80211_ATTR_SMPS_MODE
]));
812 if (attrs
[NL80211_ATTR_CHANNEL_WIDTH
])
813 printf(" chan width %d", nla_get_u8(attrs
[NL80211_ATTR_CHANNEL_WIDTH
]));
815 if (attrs
[NL80211_ATTR_NSS
])
816 printf(" nss %d", nla_get_u8(attrs
[NL80211_ATTR_NSS
]));
821 static void parse_ch_switch_notify(struct nlattr
**attrs
, int command
)
824 case NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
:
825 printf("channel switch started");
827 case NL80211_CMD_CH_SWITCH_NOTIFY
:
828 printf("channel switch");
831 printf("unknown channel switch command (%i) received\n", command
);
835 if (attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
836 printf(" (count=%d)", nla_get_u32(attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]));
838 if (attrs
[NL80211_ATTR_WIPHY_FREQ
])
839 printf(" freq=%d", nla_get_u32(attrs
[NL80211_ATTR_WIPHY_FREQ
]));
841 if (attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
843 switch(nla_get_u32(attrs
[NL80211_ATTR_CHANNEL_WIDTH
])) {
844 case NL80211_CHAN_WIDTH_20_NOHT
:
845 case NL80211_CHAN_WIDTH_20
:
846 printf("\"20 MHz\"");
848 case NL80211_CHAN_WIDTH_40
:
849 printf("\"40 MHz\"");
851 case NL80211_CHAN_WIDTH_80
:
852 printf("\"80 MHz\"");
854 case NL80211_CHAN_WIDTH_80P80
:
855 printf("\"80+80 MHz\"");
857 case NL80211_CHAN_WIDTH_160
:
858 printf("\"160 MHz\"");
860 case NL80211_CHAN_WIDTH_5
:
863 case NL80211_CHAN_WIDTH_10
:
864 printf("\"10 MHz\"");
867 printf("\"unknown\"");
871 if (attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
873 switch(nla_get_u32(attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])) {
874 case NL80211_CHAN_NO_HT
:
877 case NL80211_CHAN_HT20
:
880 case NL80211_CHAN_HT40MINUS
:
883 case NL80211_CHAN_HT40PLUS
:
889 if (attrs
[NL80211_ATTR_CENTER_FREQ1
])
890 printf(" freq1=%d", nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ1
]));
892 if (attrs
[NL80211_ATTR_CENTER_FREQ2
])
893 printf(" freq2=%d", nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ2
]));
898 static void parse_assoc_comeback(struct nlattr
**attrs
, int command
)
901 char macbuf
[6 * 3] = "<unset>";
903 if (attrs
[NL80211_ATTR_MAC
])
904 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
906 if (attrs
[NL80211_ATTR_TIMEOUT
])
907 timeout
= nla_get_u32(attrs
[NL80211_ATTR_TIMEOUT
]);
909 printf("assoc comeback bssid %s timeout %d\n",
913 static int print_event(struct nl_msg
*msg
, void *arg
)
915 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
916 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1], *nst
;
917 struct print_event_args
*args
= arg
;
921 struct ieee80211_beacon_channel chan_before_beacon
, chan_after_beacon
;
926 if (args
->time
|| args
->reltime
|| args
->ctime
) {
927 unsigned long long usecs
, previous
;
929 previous
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
930 gettimeofday(&args
->ts
, NULL
);
931 usecs
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
934 if (!args
->have_ts
) {
936 args
->have_ts
= true;
942 struct tm
*tm
= localtime(&args
->ts
.tv_sec
);
946 strftime(buf
, sizeof(buf
), "%Y-%m-%d %H:%M:%S", tm
);
947 printf("[%s.%06lu]: ", buf
, (unsigned long )args
->ts
.tv_usec
);
949 printf("%llu.%06llu: ", usecs
/1000000, usecs
% 1000000);
953 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
954 genlmsg_attrlen(gnlh
, 0), NULL
);
956 if (tb
[NL80211_ATTR_IFINDEX
] && tb
[NL80211_ATTR_WIPHY
]) {
957 /* if_indextoname may fails on delete interface/wiphy event */
958 if (if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
))
959 printf("%s (phy #%d): ", ifname
, nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
961 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
962 } else if (tb
[NL80211_ATTR_WDEV
] && tb
[NL80211_ATTR_WIPHY
]) {
963 printf("wdev 0x%llx (phy #%d): ",
964 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]),
965 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
966 } else if (tb
[NL80211_ATTR_IFINDEX
]) {
967 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
968 printf("%s: ", ifname
);
969 } else if (tb
[NL80211_ATTR_WDEV
]) {
970 printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]));
971 } else if (tb
[NL80211_ATTR_WIPHY
]) {
972 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
976 case NL80211_CMD_NEW_WIPHY
:
977 printf("renamed to %s\n", nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]));
979 case NL80211_CMD_TRIGGER_SCAN
:
980 printf("scan started\n");
982 case NL80211_CMD_NEW_SCAN_RESULTS
:
983 printf("scan finished:");
985 case NL80211_CMD_SCAN_ABORTED
:
986 if (gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)
987 printf("scan aborted:");
988 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
989 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem_nst
)
990 printf(" %d", nla_get_u32(nst
));
993 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
994 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem_nst
) {
996 print_ssid_escaped(nla_len(nst
), nla_data(nst
));
1002 case NL80211_CMD_START_SCHED_SCAN
:
1003 printf("scheduled scan started\n");
1005 case NL80211_CMD_SCHED_SCAN_STOPPED
:
1006 printf("sched scan stopped\n");
1008 case NL80211_CMD_SCHED_SCAN_RESULTS
:
1009 printf("got scheduled scan results\n");
1011 case NL80211_CMD_WIPHY_REG_CHANGE
:
1012 case NL80211_CMD_REG_CHANGE
:
1013 if (gnlh
->cmd
== NL80211_CMD_WIPHY_REG_CHANGE
)
1014 printf("regulatory domain change (phy): ");
1016 printf("regulatory domain change: ");
1018 reg_type
= nla_get_u8(tb
[NL80211_ATTR_REG_TYPE
]);
1021 case NL80211_REGDOM_TYPE_COUNTRY
:
1022 printf("set to %s by %s request",
1023 nla_get_string(tb
[NL80211_ATTR_REG_ALPHA2
]),
1024 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
1025 if (tb
[NL80211_ATTR_WIPHY
])
1026 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
1028 case NL80211_REGDOM_TYPE_WORLD
:
1029 printf("set to world roaming by %s request",
1030 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
1032 case NL80211_REGDOM_TYPE_CUSTOM_WORLD
:
1033 printf("custom world roaming rules in place on phy%d by %s request",
1034 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]),
1035 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
1037 case NL80211_REGDOM_TYPE_INTERSECTION
:
1038 printf("intersection used due to a request made by %s",
1039 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
1040 if (tb
[NL80211_ATTR_WIPHY
])
1041 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
1044 printf("unknown source (upgrade this utility)");
1050 case NL80211_CMD_REG_BEACON_HINT
:
1052 wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1054 memset(&chan_before_beacon
, 0, sizeof(chan_before_beacon
));
1055 memset(&chan_after_beacon
, 0, sizeof(chan_after_beacon
));
1057 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_BEFORE
],
1058 &chan_before_beacon
))
1060 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_AFTER
],
1061 &chan_after_beacon
))
1064 if (chan_before_beacon
.center_freq
!= chan_after_beacon
.center_freq
)
1067 /* A beacon hint is sent _only_ if something _did_ change */
1068 printf("beacon hint:\n");
1070 printf("phy%d %d MHz [%d]:\n",
1072 chan_before_beacon
.center_freq
,
1073 ieee80211_frequency_to_channel(chan_before_beacon
.center_freq
));
1075 if (chan_before_beacon
.no_ir
&& !chan_after_beacon
.no_ir
) {
1076 if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
)
1077 printf("\to Initiating radiation enabled\n");
1079 printf("\to active scan enabled\n");
1080 } else if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
) {
1081 printf("\to ibss enabled\n");
1085 case NL80211_CMD_NEW_STATION
:
1086 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1087 printf("new station %s\n", macbuf
);
1089 case NL80211_CMD_DEL_STATION
:
1090 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1091 printf("del station %s\n", macbuf
);
1093 case NL80211_CMD_JOIN_IBSS
:
1094 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1095 printf("IBSS %s joined\n", macbuf
);
1097 case NL80211_CMD_AUTHENTICATE
:
1099 if (tb
[NL80211_ATTR_FRAME
])
1100 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1101 else if (tb
[NL80211_ATTR_TIMED_OUT
])
1102 printf(": timed out");
1104 printf(": unknown event");
1107 case NL80211_CMD_ASSOCIATE
:
1109 if (tb
[NL80211_ATTR_FRAME
])
1110 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1111 else if (tb
[NL80211_ATTR_TIMED_OUT
])
1112 printf(": timed out");
1114 printf(": unknown event");
1117 case NL80211_CMD_DEAUTHENTICATE
:
1119 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1122 case NL80211_CMD_DISASSOCIATE
:
1124 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1127 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1128 printf("unprotected deauth");
1129 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1132 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1133 printf("unprotected disassoc");
1134 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1137 case NL80211_CMD_CONNECT
:
1139 if (tb
[NL80211_ATTR_TIMED_OUT
])
1140 printf("timed out");
1141 else if (!tb
[NL80211_ATTR_STATUS_CODE
])
1142 printf("unknown connect status");
1143 else if (nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]) == 0)
1144 printf("connected");
1146 status
= nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]);
1147 printf("failed to connect");
1149 if (tb
[NL80211_ATTR_MAC
]) {
1150 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1151 printf(" to %s", macbuf
);
1154 printf(", status: %d: %s", status
, get_status_str(status
));
1157 case NL80211_CMD_ROAM
:
1159 if (tb
[NL80211_ATTR_MAC
]) {
1160 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1161 printf(" to %s", macbuf
);
1165 case NL80211_CMD_DISCONNECT
:
1166 printf("disconnected");
1167 if (tb
[NL80211_ATTR_DISCONNECTED_BY_AP
])
1170 printf(" (local request)");
1171 if (tb
[NL80211_ATTR_REASON_CODE
])
1172 printf(" reason: %d: %s", nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]),
1173 get_reason_str(nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
])));
1176 case NL80211_CMD_REMAIN_ON_CHANNEL
:
1177 printf("remain on freq %d (%dms, cookie %llx)\n",
1178 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1179 nla_get_u32(tb
[NL80211_ATTR_DURATION
]),
1180 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1182 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
1183 printf("done with remain on freq %d (cookie %llx)\n",
1184 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1185 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1187 case NL80211_CMD_FRAME_WAIT_CANCEL
:
1188 printf("frame wait cancel on freq %d (cookie %llx)\n",
1189 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1190 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1192 case NL80211_CMD_NOTIFY_CQM
:
1193 parse_cqm_event(tb
);
1195 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
1196 parse_mic_failure(tb
);
1198 case NL80211_CMD_FRAME_TX_STATUS
:
1199 printf("mgmt TX status (cookie %llx): %s\n",
1200 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
1201 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
1203 case NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS
:
1204 printf("ctrl. port TX status (cookie %llx): %s\n",
1205 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
1206 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
1208 case NL80211_CMD_PMKSA_CANDIDATE
:
1209 printf("PMKSA candidate found\n");
1211 case NL80211_CMD_SET_WOWLAN
:
1212 parse_wowlan_wake_event(tb
);
1214 case NL80211_CMD_PROBE_CLIENT
:
1215 if (tb
[NL80211_ATTR_MAC
])
1216 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1218 strcpy(macbuf
, "??");
1219 printf("probe client %s (cookie %llx): %s\n",
1221 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
1222 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
1224 case NL80211_CMD_VENDOR
:
1225 parse_vendor_event(tb
, args
->frame
);
1227 case NL80211_CMD_RADAR_DETECT
: {
1228 enum nl80211_radar_event event_type
;
1231 if (!tb
[NL80211_ATTR_RADAR_EVENT
] ||
1232 !tb
[NL80211_ATTR_WIPHY_FREQ
]) {
1233 printf("BAD radar event\n");
1237 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1238 event_type
= nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
]);
1240 switch (event_type
) {
1241 case NL80211_RADAR_DETECTED
:
1242 printf("%d MHz: radar detected\n", freq
);
1244 case NL80211_RADAR_CAC_FINISHED
:
1245 printf("%d MHz: CAC finished\n", freq
);
1247 case NL80211_RADAR_CAC_ABORTED
:
1248 printf("%d MHz: CAC was aborted\n", freq
);
1250 case NL80211_RADAR_NOP_FINISHED
:
1251 printf("%d MHz: NOP finished\n", freq
);
1253 case NL80211_RADAR_PRE_CAC_EXPIRED
:
1254 printf("%d MHz: PRE-CAC expired\n", freq
);
1256 case NL80211_RADAR_CAC_STARTED
:
1257 printf("%d MHz: CAC started\n", freq
);
1260 printf("%d MHz: unknown radar event\n", freq
);
1264 case NL80211_CMD_DEL_WIPHY
:
1265 printf("delete wiphy\n");
1267 case NL80211_CMD_PEER_MEASUREMENT_RESULT
:
1268 parse_pmsr_result(tb
, args
);
1270 case NL80211_CMD_PEER_MEASUREMENT_COMPLETE
:
1271 printf("peer measurement complete\n");
1273 case NL80211_CMD_DEL_NAN_FUNCTION
:
1276 case NL80211_CMD_NAN_MATCH
:
1277 parse_nan_match(tb
);
1279 case NL80211_CMD_NEW_PEER_CANDIDATE
:
1280 parse_new_peer_candidate(tb
);
1282 case NL80211_CMD_NEW_INTERFACE
:
1283 case NL80211_CMD_SET_INTERFACE
:
1284 case NL80211_CMD_DEL_INTERFACE
:
1285 parse_recv_interface(tb
, gnlh
->cmd
);
1287 case NL80211_CMD_STA_OPMODE_CHANGED
:
1288 parse_sta_opmode_changed(tb
);
1290 case NL80211_CMD_STOP_AP
:
1291 printf("stop ap\n");
1293 case NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
:
1294 case NL80211_CMD_CH_SWITCH_NOTIFY
:
1295 parse_ch_switch_notify(tb
, gnlh
->cmd
);
1297 case NL80211_CMD_ASSOC_COMEBACK
: /* 147 */
1298 parse_assoc_comeback(tb
, gnlh
->cmd
);
1301 printf("unknown event %d (%s)\n",
1302 gnlh
->cmd
, command_name(gnlh
->cmd
));
1311 int n_cmds
, n_prints
;
1313 const __u32
*prints
;
1315 struct print_event_args
*pargs
;
1318 static int wait_event(struct nl_msg
*msg
, void *arg
)
1320 struct wait_event
*wait
= arg
;
1321 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1325 for (i
= 0; i
< wait
->n_prints
; i
++) {
1326 if (gnlh
->cmd
== wait
->prints
[i
])
1327 print_event(msg
, wait
->pargs
);
1331 for (i
= 0; i
< wait
->n_cmds
; i
++) {
1332 if (gnlh
->cmd
== wait
->cmds
[i
])
1333 wait
->cmd
= gnlh
->cmd
;
1339 int __prepare_listen_events(struct nl80211_state
*state
)
1343 /* Configuration multicast group */
1344 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "config");
1348 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1352 /* Scan multicast group */
1353 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "scan");
1355 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1360 /* Regulatory multicast group */
1361 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "regulatory");
1363 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1368 /* MLME multicast group */
1369 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "mlme");
1371 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1376 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "vendor");
1378 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1383 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "nan");
1385 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1393 __u32
__do_listen_events(struct nl80211_state
*state
,
1394 const int n_waits
, const __u32
*waits
,
1395 const int n_prints
, const __u32
*prints
,
1396 struct print_event_args
*args
)
1398 struct nl_cb
*cb
= nl_cb_alloc(iw_debug
? NL_CB_DEBUG
: NL_CB_DEFAULT
);
1399 struct wait_event wait_ev
;
1402 fprintf(stderr
, "failed to allocate netlink callbacks\n");
1406 /* no sequence checking for multicast messages */
1407 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
1408 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, valid_handler
, NULL
);
1410 if (n_waits
&& waits
) {
1411 wait_ev
.cmds
= waits
;
1412 wait_ev
.n_cmds
= n_waits
;
1413 wait_ev
.prints
= prints
;
1414 wait_ev
.n_prints
= n_prints
;
1415 wait_ev
.pargs
= args
;
1416 register_handler(wait_event
, &wait_ev
);
1418 register_handler(print_event
, args
);
1422 while (!wait_ev
.cmd
)
1423 nl_recvmsgs(state
->nl_sock
, cb
);
1430 __u32
listen_events(struct nl80211_state
*state
,
1431 const int n_waits
, const __u32
*waits
)
1435 ret
= __prepare_listen_events(state
);
1439 return __do_listen_events(state
, n_waits
, waits
, 0, NULL
, NULL
);
1442 static int print_events(struct nl80211_state
*state
,
1444 int argc
, char **argv
,
1447 struct print_event_args args
;
1448 int num_time_formats
= 0;
1451 memset(&args
, 0, sizeof(args
));
1457 if (strcmp(argv
[0], "-f") == 0)
1459 else if (strcmp(argv
[0], "-t") == 0) {
1462 } else if (strcmp(argv
[0], "-T") == 0) {
1465 } else if (strcmp(argv
[0], "-r") == 0) {
1467 args
.reltime
= true;
1474 if (num_time_formats
> 1)
1480 ret
= __prepare_listen_events(state
);
1484 return __do_listen_events(state
, 0, NULL
, 0, NULL
, &args
);
1486 TOPLEVEL(event
, "[-t|-T|-r] [-f]", 0, 0, CIB_NONE
, print_events
,
1487 "Monitor events from the kernel.\n"
1488 "-t - print timestamp\n"
1489 "-T - print absolute, human-readable timestamp\n"
1490 "-r - print relative timestamp\n"
1491 "-f - print full frame for auth/assoc etc.");