8 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
13 struct ieee80211_beacon_channel
{
19 static int parse_beacon_hint_chan(struct nlattr
*tb
,
20 struct ieee80211_beacon_channel
*chan
)
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
},
25 [NL80211_FREQUENCY_ATTR_NO_IR
] = { .type
= NLA_FLAG
},
26 [__NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
29 if (nla_parse_nested(tb_freq
,
30 NL80211_FREQUENCY_ATTR_MAX
,
35 chan
->center_freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
37 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IR
])
39 if (tb_freq
[__NL80211_FREQUENCY_ATTR_NO_IBSS
])
45 static void print_frame(struct print_event_args
*args
, struct nlattr
*attr
)
54 printf(" [no frame]");
58 frame
= nla_data(attr
);
62 printf(" [invalid frame: ");
66 mac_addr_n2a(macbuf
, frame
+ 10);
67 printf(" %s -> ", macbuf
);
68 mac_addr_n2a(macbuf
, frame
+ 4);
71 switch (frame
[0] & 0xfc) {
72 case 0x10: /* assoc resp */
73 case 0x30: /* reassoc resp */
75 tmp
= (frame
[27] << 8) + frame
[26];
76 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
78 case 0x00: /* assoc req */
79 case 0x20: /* reassoc req */
83 tmp
= (frame
[29] << 8) + frame
[28];
84 printf(" status: %d: %s", tmp
, get_status_str(tmp
));
86 case 0xa0: /* disassoc */
87 case 0xc0: /* deauth */
89 tmp
= (frame
[25] << 8) + frame
[24];
90 printf(" reason %d: %s", tmp
, get_reason_str(tmp
));
100 for (i
= 0; i
< len
; i
++)
101 printf(" %.02x", frame
[i
]);
105 static void parse_cqm_event(struct nlattr
**attrs
)
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
},
112 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
113 struct nlattr
*cqm_attr
= attrs
[NL80211_ATTR_CQM
];
115 printf("CQM event: ");
118 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, cqm_attr
, cqm_policy
)) {
119 printf("missing data!\n");
123 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]) {
124 enum nl80211_cqm_rssi_threshold_event rssi_event
;
125 bool found_one
= false;
127 rssi_event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
129 switch (rssi_event
) {
130 case NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
:
131 printf("RSSI went above threshold\n");
134 case NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
:
135 printf("RSSI went below threshold\n");
138 case NL80211_CQM_RSSI_BEACON_LOSS_EVENT
:
139 printf("Beacon loss detected\n");
145 printf("Unknown event type: %i\n", rssi_event
);
146 } else if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
147 if (attrs
[NL80211_ATTR_MAC
]) {
151 frames
= nla_get_u32(cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]);
152 mac_addr_n2a(buf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
153 printf("peer %s didn't ACK %d packets\n", buf
, frames
);
155 printf("PKT-LOSS-EVENT did not have MAC attribute!\n");
157 } else if (cqm
[NL80211_ATTR_CQM_BEACON_LOSS_EVENT
]) {
158 printf("beacon loss\n");
160 printf("unknown event\n");
164 static const char * key_type_str(enum nl80211_key_type key_type
)
168 case NL80211_KEYTYPE_GROUP
:
170 case NL80211_KEYTYPE_PAIRWISE
:
172 case NL80211_KEYTYPE_PEERKEY
:
175 snprintf(buf
, sizeof(buf
), "unknown(%d)", key_type
);
180 static void parse_mic_failure(struct nlattr
**attrs
)
182 printf("Michael MIC failure event:");
184 if (attrs
[NL80211_ATTR_MAC
]) {
185 char addr
[3 * ETH_ALEN
];
186 mac_addr_n2a(addr
, nla_data(attrs
[NL80211_ATTR_MAC
]));
187 printf(" source MAC address %s", addr
);
190 if (attrs
[NL80211_ATTR_KEY_SEQ
] &&
191 nla_len(attrs
[NL80211_ATTR_KEY_SEQ
]) == 6) {
192 unsigned char *seq
= nla_data(attrs
[NL80211_ATTR_KEY_SEQ
]);
193 printf(" seq=%02x%02x%02x%02x%02x%02x",
194 seq
[0], seq
[1], seq
[2], seq
[3], seq
[4], seq
[5]);
196 if (attrs
[NL80211_ATTR_KEY_TYPE
]) {
197 enum nl80211_key_type key_type
=
198 nla_get_u32(attrs
[NL80211_ATTR_KEY_TYPE
]);
199 printf(" Key Type %s", key_type_str(key_type
));
202 if (attrs
[NL80211_ATTR_KEY_IDX
]) {
203 __u8 key_id
= nla_get_u8(attrs
[NL80211_ATTR_KEY_IDX
]);
204 printf(" Key Id %d", key_id
);
210 static void parse_wowlan_wake_event(struct nlattr
**attrs
)
212 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
],
213 *tb_match
[NUM_NL80211_ATTR
];
215 printf("WoWLAN wakeup\n");
216 if (!attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
217 printf("\twakeup not due to WoWLAN\n");
221 nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
222 nla_data(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
223 nla_len(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]), NULL
);
225 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
])
226 printf("\t* was disconnected\n");
227 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
228 printf("\t* magic packet received\n");
229 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
])
230 printf("\t* pattern index: %u\n",
231 nla_get_u32(tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]));
232 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
233 printf("\t* GTK rekey failure\n");
234 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
235 printf("\t* EAP identity request\n");
236 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
237 printf("\t* 4-way handshake\n");
238 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
239 printf("\t* RF-kill released\n");
240 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
]) {
241 struct nlattr
*match
, *freq
;
242 int rem_nst
, rem_nst2
;
244 printf("\t* network detected\n");
245 nla_for_each_nested(match
,
246 tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
],
248 nla_parse_nested(tb_match
, NL80211_ATTR_MAX
, 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 void parse_nan_term(struct nlattr
**attrs
)
298 struct nlattr
*func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
300 static struct nla_policy
301 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
302 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
303 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
304 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
305 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
306 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
307 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
308 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
309 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
310 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
311 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
312 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
313 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
314 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
315 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
316 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
319 if (!attrs
[NL80211_ATTR_COOKIE
]) {
320 printf("Bad NAN func termination format - cookie is missing\n");
324 if (nla_parse_nested(func
, NL80211_NAN_FUNC_ATTR_MAX
,
325 attrs
[NL80211_ATTR_NAN_FUNC
],
327 printf("NAN: failed to parse nan func\n");
331 if (!func
[NL80211_NAN_FUNC_INSTANCE_ID
]) {
332 printf("Bad NAN func termination format-instance id missing\n");
336 if (!func
[NL80211_NAN_FUNC_TERM_REASON
]) {
337 printf("Bad NAN func termination format - reason is missing\n");
340 printf("NAN(cookie=0x%llx): Termination event: id = %d, reason = ",
341 (long long int)nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]),
342 nla_get_u8(func
[NL80211_NAN_FUNC_INSTANCE_ID
]));
343 switch (nla_get_u8(func
[NL80211_NAN_FUNC_TERM_REASON
])) {
344 case NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST
:
345 printf("user request\n");
347 case NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED
:
350 case NL80211_NAN_FUNC_TERM_REASON_ERROR
:
358 static const char *ftm_fail_reason(unsigned int reason
)
360 #define FTM_FAIL_REASON(x) case NL80211_PMSR_FTM_FAILURE_##x: return #x
362 FTM_FAIL_REASON(UNSPECIFIED
);
363 FTM_FAIL_REASON(NO_RESPONSE
);
364 FTM_FAIL_REASON(REJECTED
);
365 FTM_FAIL_REASON(WRONG_CHANNEL
);
366 FTM_FAIL_REASON(PEER_NOT_CAPABLE
);
367 FTM_FAIL_REASON(INVALID_TIMESTAMP
);
368 FTM_FAIL_REASON(PEER_BUSY
);
369 FTM_FAIL_REASON(BAD_CHANGED_PARAMS
);
375 static void parse_pmsr_ftm_data(struct nlattr
*data
)
377 struct nlattr
*ftm
[NL80211_PMSR_FTM_RESP_ATTR_MAX
+ 1];
380 nla_parse_nested(ftm
, NL80211_PMSR_FTM_RESP_ATTR_MAX
, data
, NULL
);
382 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]) {
383 printf(" failed: %s (%d)",
384 ftm_fail_reason(nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
])),
385 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]));
386 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
])
387 printf(" retry after %us",
388 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
]));
395 #define PFTM(tp, attr, sign) \
397 if (ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr]) \
398 printf(" " #attr ": %lld\n", \
399 (sign long long)nla_get_##tp( \
400 ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr])); \
403 PFTM(u32
, BURST_INDEX
, unsigned);
404 PFTM(u32
, NUM_FTMR_ATTEMPTS
, unsigned);
405 PFTM(u32
, NUM_FTMR_SUCCESSES
, unsigned);
406 PFTM(u8
, NUM_BURSTS_EXP
, unsigned);
407 PFTM(u8
, BURST_DURATION
, unsigned);
408 PFTM(u8
, FTMS_PER_BURST
, unsigned);
409 PFTM(u32
, RSSI_AVG
, signed);
410 PFTM(u32
, RSSI_SPREAD
, unsigned);
411 PFTM(u64
, RTT_AVG
, signed);
412 PFTM(u64
, RTT_VARIANCE
, unsigned);
413 PFTM(u64
, RTT_SPREAD
, unsigned);
414 PFTM(u64
, DIST_AVG
, signed);
415 PFTM(u64
, DIST_VARIANCE
, unsigned);
416 PFTM(u64
, DIST_SPREAD
, unsigned);
418 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
]) {
421 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
],
423 printf(" TX bitrate: %s\n", buf
);
426 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
]) {
429 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
],
431 printf(" RX bitrate: %s\n", buf
);
434 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
])
436 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]),
437 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]));
439 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
])
440 iw_hexdump(" civic location",
441 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]),
442 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]));
445 static const char *pmsr_status(unsigned int status
)
447 #define PMSR_STATUS(x) case NL80211_PMSR_STATUS_##x: return #x
449 PMSR_STATUS(SUCCESS
);
450 PMSR_STATUS(REFUSED
);
451 PMSR_STATUS(TIMEOUT
);
452 PMSR_STATUS(FAILURE
);
459 static void parse_pmsr_peer(struct nlattr
*peer
)
461 struct nlattr
*tb
[NL80211_PMSR_PEER_ATTR_MAX
+ 1];
462 struct nlattr
*resp
[NL80211_PMSR_RESP_ATTR_MAX
+ 1];
463 struct nlattr
*data
[NL80211_PMSR_TYPE_MAX
+ 1];
467 err
= nla_parse_nested(tb
, NL80211_PMSR_PEER_ATTR_MAX
, peer
, NULL
);
469 printf(" Peer: failed to parse!\n");
473 if (!tb
[NL80211_PMSR_PEER_ATTR_ADDR
]) {
474 printf(" Peer: no MAC address\n");
478 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_PMSR_PEER_ATTR_ADDR
]));
479 printf(" Peer %s:", macbuf
);
481 if (!tb
[NL80211_PMSR_PEER_ATTR_RESP
]) {
482 printf(" no response!\n");
486 err
= nla_parse_nested(resp
, NL80211_PMSR_RESP_ATTR_MAX
,
487 tb
[NL80211_PMSR_PEER_ATTR_RESP
], NULL
);
489 printf(" failed to parse response!\n");
493 if (resp
[NL80211_PMSR_RESP_ATTR_STATUS
])
494 printf(" status=%d (%s)",
495 nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
]),
496 pmsr_status(nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
])));
497 if (resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
])
499 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
]));
500 if (resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
])
502 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
]));
503 if (resp
[NL80211_PMSR_RESP_ATTR_FINAL
])
506 if (!resp
[NL80211_PMSR_RESP_ATTR_DATA
]) {
507 printf(" - no data!\n");
513 nla_parse_nested(data
, NL80211_PMSR_TYPE_MAX
,
514 resp
[NL80211_PMSR_RESP_ATTR_DATA
], NULL
);
516 if (data
[NL80211_PMSR_TYPE_FTM
])
517 parse_pmsr_ftm_data(data
[NL80211_PMSR_TYPE_FTM
]);
520 static void parse_pmsr_result(struct nlattr
**tb
,
521 struct print_event_args
*pargs
)
523 struct nlattr
*pmsr
[NL80211_PMSR_ATTR_MAX
+ 1];
525 unsigned long long cookie
;
528 if (!tb
[NL80211_ATTR_COOKIE
]) {
529 printf("Peer measurements: no cookie!\n");
532 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
534 if (!tb
[NL80211_ATTR_PEER_MEASUREMENTS
]) {
535 printf("Peer measurements: no measurement data!\n");
539 err
= nla_parse_nested(pmsr
, NL80211_PMSR_ATTR_MAX
,
540 tb
[NL80211_ATTR_PEER_MEASUREMENTS
], NULL
);
542 printf("Peer measurements: failed to parse measurement data!\n");
546 if (!pmsr
[NL80211_PMSR_ATTR_PEERS
]) {
547 printf("Peer measurements: no peer data!\n");
551 printf("Peer measurements (cookie %llu):\n", cookie
);
553 nla_for_each_nested(peer
, pmsr
[NL80211_PMSR_ATTR_PEERS
], i
)
554 parse_pmsr_peer(peer
);
557 static void parse_nan_match(struct nlattr
**attrs
)
561 struct nlattr
*match
[NL80211_NAN_MATCH_ATTR_MAX
+ 1];
562 struct nlattr
*local_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
563 struct nlattr
*peer_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
565 static struct nla_policy
566 nan_match_policy
[NL80211_NAN_MATCH_ATTR_MAX
+ 1] = {
567 [NL80211_NAN_MATCH_FUNC_LOCAL
] = { .type
= NLA_NESTED
},
568 [NL80211_NAN_MATCH_FUNC_PEER
] = { .type
= NLA_NESTED
},
571 static struct nla_policy
572 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
573 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
574 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
575 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
576 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
577 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
578 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
579 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
580 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
581 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
582 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
583 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
584 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
585 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
586 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
587 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
590 cookie
= nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]);
591 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
593 if (nla_parse_nested(match
, NL80211_NAN_MATCH_ATTR_MAX
,
594 attrs
[NL80211_ATTR_NAN_MATCH
],
596 printf("NAN: failed to parse nan match event\n");
600 if (nla_parse_nested(local_func
, NL80211_NAN_FUNC_ATTR_MAX
,
601 match
[NL80211_NAN_MATCH_FUNC_LOCAL
],
603 printf("NAN: failed to parse nan local func\n");
607 if (nla_parse_nested(peer_func
, NL80211_NAN_FUNC_ATTR_MAX
,
608 match
[NL80211_NAN_MATCH_FUNC_PEER
],
610 printf("NAN: failed to parse nan local func\n");
614 if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
615 NL80211_NAN_FUNC_PUBLISH
) {
617 "NAN(cookie=0x%llx): DiscoveryResult, peer_id=%d, local_id=%d, peer_mac=%s",
619 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
620 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
622 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
623 printf(", info=%.*s",
624 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
625 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
626 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
627 NL80211_NAN_FUNC_SUBSCRIBE
) {
629 "NAN(cookie=0x%llx): Replied, peer_id=%d, local_id=%d, peer_mac=%s",
631 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
632 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
634 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
635 NL80211_NAN_FUNC_FOLLOW_UP
) {
637 "NAN(cookie=0x%llx): FollowUpReceive, peer_id=%d, local_id=%d, peer_mac=%s",
639 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
640 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
642 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
643 printf(", info=%.*s",
644 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
645 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
647 printf("NaN: Malformed event");
653 static void parse_new_peer_candidate(struct nlattr
**attrs
)
655 char macbuf
[ETH_ALEN
* 3];
658 printf("new peer candidate");
659 if (attrs
[NL80211_ATTR_MAC
]) {
660 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
661 printf(" %s", macbuf
);
663 if (attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]) {
664 sig_dbm
= nla_get_u32(attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]);
665 printf(" %d dBm", sig_dbm
);
671 static int print_event(struct nl_msg
*msg
, void *arg
)
673 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
674 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1], *nst
;
675 struct print_event_args
*args
= arg
;
679 struct ieee80211_beacon_channel chan_before_beacon
, chan_after_beacon
;
684 if (args
->time
|| args
->reltime
) {
685 unsigned long long usecs
, previous
;
687 previous
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
688 gettimeofday(&args
->ts
, NULL
);
689 usecs
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
691 if (!args
->have_ts
) {
693 args
->have_ts
= true;
697 printf("%llu.%06llu: ", usecs
/1000000, usecs
% 1000000);
700 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
701 genlmsg_attrlen(gnlh
, 0), NULL
);
703 if (tb
[NL80211_ATTR_IFINDEX
] && tb
[NL80211_ATTR_WIPHY
]) {
704 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
705 printf("%s (phy #%d): ", ifname
, nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
706 } else if (tb
[NL80211_ATTR_WDEV
] && tb
[NL80211_ATTR_WIPHY
]) {
707 printf("wdev 0x%llx (phy #%d): ",
708 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]),
709 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
710 } else if (tb
[NL80211_ATTR_IFINDEX
]) {
711 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
712 printf("%s: ", ifname
);
713 } else if (tb
[NL80211_ATTR_WDEV
]) {
714 printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]));
715 } else if (tb
[NL80211_ATTR_WIPHY
]) {
716 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
720 case NL80211_CMD_NEW_WIPHY
:
721 printf("renamed to %s\n", nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]));
723 case NL80211_CMD_TRIGGER_SCAN
:
724 printf("scan started\n");
726 case NL80211_CMD_NEW_SCAN_RESULTS
:
727 printf("scan finished:");
729 case NL80211_CMD_SCAN_ABORTED
:
730 if (gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)
731 printf("scan aborted:");
732 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
733 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem_nst
)
734 printf(" %d", nla_get_u32(nst
));
737 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
738 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem_nst
) {
740 print_ssid_escaped(nla_len(nst
), nla_data(nst
));
746 case NL80211_CMD_START_SCHED_SCAN
:
747 printf("scheduled scan started\n");
749 case NL80211_CMD_SCHED_SCAN_STOPPED
:
750 printf("sched scan stopped\n");
752 case NL80211_CMD_SCHED_SCAN_RESULTS
:
753 printf("got scheduled scan results\n");
755 case NL80211_CMD_REG_CHANGE
:
756 printf("regulatory domain change: ");
758 reg_type
= nla_get_u8(tb
[NL80211_ATTR_REG_TYPE
]);
761 case NL80211_REGDOM_TYPE_COUNTRY
:
762 printf("set to %s by %s request",
763 nla_get_string(tb
[NL80211_ATTR_REG_ALPHA2
]),
764 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
765 if (tb
[NL80211_ATTR_WIPHY
])
766 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
768 case NL80211_REGDOM_TYPE_WORLD
:
769 printf("set to world roaming by %s request",
770 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
772 case NL80211_REGDOM_TYPE_CUSTOM_WORLD
:
773 printf("custom world roaming rules in place on phy%d by %s request",
774 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]),
775 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
777 case NL80211_REGDOM_TYPE_INTERSECTION
:
778 printf("intersection used due to a request made by %s",
779 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
780 if (tb
[NL80211_ATTR_WIPHY
])
781 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
784 printf("unknown source (upgrade this utility)");
790 case NL80211_CMD_REG_BEACON_HINT
:
792 wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
794 memset(&chan_before_beacon
, 0, sizeof(chan_before_beacon
));
795 memset(&chan_after_beacon
, 0, sizeof(chan_after_beacon
));
797 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_BEFORE
],
798 &chan_before_beacon
))
800 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_AFTER
],
804 if (chan_before_beacon
.center_freq
!= chan_after_beacon
.center_freq
)
807 /* A beacon hint is sent _only_ if something _did_ change */
808 printf("beacon hint:\n");
810 printf("phy%d %d MHz [%d]:\n",
812 chan_before_beacon
.center_freq
,
813 ieee80211_frequency_to_channel(chan_before_beacon
.center_freq
));
815 if (chan_before_beacon
.no_ir
&& !chan_after_beacon
.no_ir
) {
816 if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
)
817 printf("\to Initiating radiation enabled\n");
819 printf("\to active scan enabled\n");
820 } else if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
) {
821 printf("\to ibss enabled\n");
825 case NL80211_CMD_NEW_STATION
:
826 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
827 printf("new station %s\n", macbuf
);
829 case NL80211_CMD_DEL_STATION
:
830 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
831 printf("del station %s\n", macbuf
);
833 case NL80211_CMD_JOIN_IBSS
:
834 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
835 printf("IBSS %s joined\n", macbuf
);
837 case NL80211_CMD_AUTHENTICATE
:
839 if (tb
[NL80211_ATTR_FRAME
])
840 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
841 else if (tb
[NL80211_ATTR_TIMED_OUT
])
842 printf(": timed out");
844 printf(": unknown event");
847 case NL80211_CMD_ASSOCIATE
:
849 if (tb
[NL80211_ATTR_FRAME
])
850 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
851 else if (tb
[NL80211_ATTR_TIMED_OUT
])
852 printf(": timed out");
854 printf(": unknown event");
857 case NL80211_CMD_DEAUTHENTICATE
:
859 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
862 case NL80211_CMD_DISASSOCIATE
:
864 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
867 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
868 printf("unprotected deauth");
869 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
872 case NL80211_CMD_UNPROT_DISASSOCIATE
:
873 printf("unprotected disassoc");
874 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
877 case NL80211_CMD_CONNECT
:
879 if (tb
[NL80211_ATTR_TIMED_OUT
])
881 else if (!tb
[NL80211_ATTR_STATUS_CODE
])
882 printf("unknown connect status");
883 else if (nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]) == 0)
886 status
= nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]);
887 printf("failed to connect");
889 if (tb
[NL80211_ATTR_MAC
]) {
890 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
891 printf(" to %s", macbuf
);
894 printf(", status: %d: %s", status
, get_status_str(status
));
897 case NL80211_CMD_ROAM
:
899 if (tb
[NL80211_ATTR_MAC
]) {
900 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
901 printf(" to %s", macbuf
);
905 case NL80211_CMD_DISCONNECT
:
906 printf("disconnected");
907 if (tb
[NL80211_ATTR_DISCONNECTED_BY_AP
])
910 printf(" (local request)");
911 if (tb
[NL80211_ATTR_REASON_CODE
])
912 printf(" reason: %d: %s", nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]),
913 get_reason_str(nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
])));
916 case NL80211_CMD_REMAIN_ON_CHANNEL
:
917 printf("remain on freq %d (%dms, cookie %llx)\n",
918 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
919 nla_get_u32(tb
[NL80211_ATTR_DURATION
]),
920 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
922 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
923 printf("done with remain on freq %d (cookie %llx)\n",
924 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
925 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
927 case NL80211_CMD_NOTIFY_CQM
:
930 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
931 parse_mic_failure(tb
);
933 case NL80211_CMD_FRAME_TX_STATUS
:
934 printf("mgmt TX status (cookie %llx): %s\n",
935 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
936 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
938 case NL80211_CMD_PMKSA_CANDIDATE
:
939 printf("PMKSA candidate found\n");
941 case NL80211_CMD_SET_WOWLAN
:
942 parse_wowlan_wake_event(tb
);
944 case NL80211_CMD_PROBE_CLIENT
:
945 if (tb
[NL80211_ATTR_MAC
])
946 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
948 strcpy(macbuf
, "??");
949 printf("probe client %s (cookie %llx): %s\n",
951 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
952 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
954 case NL80211_CMD_VENDOR
:
955 printf("vendor event %.6x:%d\n",
956 nla_get_u32(tb
[NL80211_ATTR_VENDOR_ID
]),
957 nla_get_u32(tb
[NL80211_ATTR_VENDOR_SUBCMD
]));
958 if (args
->frame
&& tb
[NL80211_ATTR_VENDOR_DATA
])
959 iw_hexdump("vendor event",
960 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
961 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
963 case NL80211_CMD_RADAR_DETECT
: {
964 enum nl80211_radar_event event_type
;
967 if (!tb
[NL80211_ATTR_RADAR_EVENT
] ||
968 !tb
[NL80211_ATTR_WIPHY_FREQ
]) {
969 printf("BAD radar event\n");
973 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
974 event_type
= nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
]);
976 switch (event_type
) {
977 case NL80211_RADAR_DETECTED
:
978 printf("%d MHz: radar detected\n", freq
);
980 case NL80211_RADAR_CAC_FINISHED
:
981 printf("%d MHz: CAC finished\n", freq
);
983 case NL80211_RADAR_CAC_ABORTED
:
984 printf("%d MHz: CAC was aborted\n", freq
);
986 case NL80211_RADAR_NOP_FINISHED
:
987 printf("%d MHz: NOP finished\n", freq
);
990 printf("%d MHz: unknown radar event\n", freq
);
994 case NL80211_CMD_DEL_WIPHY
:
995 printf("delete wiphy\n");
997 case NL80211_CMD_PEER_MEASUREMENT_RESULT
:
998 parse_pmsr_result(tb
, args
);
1000 case NL80211_CMD_PEER_MEASUREMENT_COMPLETE
:
1001 printf("peer measurement complete\n");
1003 case NL80211_CMD_DEL_NAN_FUNCTION
:
1006 case NL80211_CMD_NAN_MATCH
: {
1007 parse_nan_match(tb
);
1010 case NL80211_CMD_NEW_PEER_CANDIDATE
:
1011 parse_new_peer_candidate(tb
);
1014 printf("unknown event %d (%s)\n",
1015 gnlh
->cmd
, command_name(gnlh
->cmd
));
1024 int n_cmds
, n_prints
;
1026 const __u32
*prints
;
1028 struct print_event_args
*pargs
;
1031 static int wait_event(struct nl_msg
*msg
, void *arg
)
1033 struct wait_event
*wait
= arg
;
1034 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1038 for (i
= 0; i
< wait
->n_prints
; i
++) {
1039 if (gnlh
->cmd
== wait
->prints
[i
])
1040 print_event(msg
, wait
->pargs
);
1044 for (i
= 0; i
< wait
->n_cmds
; i
++) {
1045 if (gnlh
->cmd
== wait
->cmds
[i
])
1046 wait
->cmd
= gnlh
->cmd
;
1052 int __prepare_listen_events(struct nl80211_state
*state
)
1056 /* Configuration multicast group */
1057 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "config");
1061 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1065 /* Scan multicast group */
1066 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "scan");
1068 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1073 /* Regulatory multicast group */
1074 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "regulatory");
1076 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1081 /* MLME multicast group */
1082 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "mlme");
1084 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1089 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "vendor");
1091 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1096 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "nan");
1098 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1106 __u32
__do_listen_events(struct nl80211_state
*state
,
1107 const int n_waits
, const __u32
*waits
,
1108 const int n_prints
, const __u32
*prints
,
1109 struct print_event_args
*args
)
1111 struct nl_cb
*cb
= nl_cb_alloc(iw_debug
? NL_CB_DEBUG
: NL_CB_DEFAULT
);
1112 struct wait_event wait_ev
;
1115 fprintf(stderr
, "failed to allocate netlink callbacks\n");
1119 /* no sequence checking for multicast messages */
1120 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
1121 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, valid_handler
, NULL
);
1123 if (n_waits
&& waits
) {
1124 wait_ev
.cmds
= waits
;
1125 wait_ev
.n_cmds
= n_waits
;
1126 wait_ev
.prints
= prints
;
1127 wait_ev
.n_prints
= n_prints
;
1128 wait_ev
.pargs
= args
;
1129 register_handler(wait_event
, &wait_ev
);
1131 register_handler(print_event
, args
);
1135 while (!wait_ev
.cmd
)
1136 nl_recvmsgs(state
->nl_sock
, cb
);
1143 __u32
listen_events(struct nl80211_state
*state
,
1144 const int n_waits
, const __u32
*waits
)
1148 ret
= __prepare_listen_events(state
);
1152 return __do_listen_events(state
, n_waits
, waits
, 0, NULL
, NULL
);
1155 static int print_events(struct nl80211_state
*state
,
1157 int argc
, char **argv
,
1160 struct print_event_args args
;
1163 memset(&args
, 0, sizeof(args
));
1169 if (strcmp(argv
[0], "-f") == 0)
1171 else if (strcmp(argv
[0], "-t") == 0)
1173 else if (strcmp(argv
[0], "-r") == 0)
1174 args
.reltime
= true;
1181 if (args
.time
&& args
.reltime
)
1187 ret
= __prepare_listen_events(state
);
1191 return __do_listen_events(state
, 0, NULL
, 0, NULL
, &args
);
1193 TOPLEVEL(event
, "[-t|-r] [-f]", 0, 0, CIB_NONE
, print_events
,
1194 "Monitor events from the kernel.\n"
1195 "-t - print timestamp\n"
1196 "-r - print relative timestamp\n"
1197 "-f - print full frame for auth/assoc etc.");