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 int32_t rssi_level
= -1;
126 bool found_one
= false;
128 rssi_event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
129 if (cqm
[NL80211_ATTR_CQM_RSSI_LEVEL
])
130 rssi_level
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_LEVEL
]);
132 switch (rssi_event
) {
133 case NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
:
134 printf("RSSI (%i dBm) went above threshold\n", rssi_level
);
137 case NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
:
138 printf("RSSI (%i dBm) went below threshold\n", rssi_level
);
141 case NL80211_CQM_RSSI_BEACON_LOSS_EVENT
:
142 printf("Beacon loss detected\n");
148 printf("Unknown event type: %i\n", rssi_event
);
149 } else if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
150 if (attrs
[NL80211_ATTR_MAC
]) {
154 frames
= nla_get_u32(cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]);
155 mac_addr_n2a(buf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
156 printf("peer %s didn't ACK %d packets\n", buf
, frames
);
158 printf("PKT-LOSS-EVENT did not have MAC attribute!\n");
160 } else if (cqm
[NL80211_ATTR_CQM_BEACON_LOSS_EVENT
]) {
161 printf("beacon loss\n");
163 printf("unknown event\n");
167 static const char * key_type_str(enum nl80211_key_type key_type
)
171 case NL80211_KEYTYPE_GROUP
:
173 case NL80211_KEYTYPE_PAIRWISE
:
175 case NL80211_KEYTYPE_PEERKEY
:
178 snprintf(buf
, sizeof(buf
), "unknown(%d)", key_type
);
183 static void parse_mic_failure(struct nlattr
**attrs
)
185 printf("Michael MIC failure event:");
187 if (attrs
[NL80211_ATTR_MAC
]) {
188 char addr
[3 * ETH_ALEN
];
189 mac_addr_n2a(addr
, nla_data(attrs
[NL80211_ATTR_MAC
]));
190 printf(" source MAC address %s", addr
);
193 if (attrs
[NL80211_ATTR_KEY_SEQ
] &&
194 nla_len(attrs
[NL80211_ATTR_KEY_SEQ
]) == 6) {
195 unsigned char *seq
= nla_data(attrs
[NL80211_ATTR_KEY_SEQ
]);
196 printf(" seq=%02x%02x%02x%02x%02x%02x",
197 seq
[0], seq
[1], seq
[2], seq
[3], seq
[4], seq
[5]);
199 if (attrs
[NL80211_ATTR_KEY_TYPE
]) {
200 enum nl80211_key_type key_type
=
201 nla_get_u32(attrs
[NL80211_ATTR_KEY_TYPE
]);
202 printf(" Key Type %s", key_type_str(key_type
));
205 if (attrs
[NL80211_ATTR_KEY_IDX
]) {
206 __u8 key_id
= nla_get_u8(attrs
[NL80211_ATTR_KEY_IDX
]);
207 printf(" Key Id %d", key_id
);
213 static void parse_wowlan_wake_event(struct nlattr
**attrs
)
215 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
],
216 *tb_match
[NUM_NL80211_ATTR
];
218 printf("WoWLAN wakeup\n");
219 if (!attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
220 printf("\twakeup not due to WoWLAN\n");
224 nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
225 nla_data(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
226 nla_len(attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]), NULL
);
228 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
])
229 printf("\t* was disconnected\n");
230 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
231 printf("\t* magic packet received\n");
232 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
])
233 printf("\t* pattern index: %u\n",
234 nla_get_u32(tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]));
235 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
236 printf("\t* GTK rekey failure\n");
237 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
238 printf("\t* EAP identity request\n");
239 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
240 printf("\t* 4-way handshake\n");
241 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
242 printf("\t* RF-kill released\n");
243 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
]) {
244 struct nlattr
*match
, *freq
;
245 int rem_nst
, rem_nst2
;
247 printf("\t* network detected\n");
248 nla_for_each_nested(match
,
249 tb
[NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
],
251 nla_parse_nested(tb_match
, NL80211_ATTR_MAX
, match
,
253 printf("\t\tSSID: \"");
254 print_ssid_escaped(nla_len(tb_match
[NL80211_ATTR_SSID
]),
255 nla_data(tb_match
[NL80211_ATTR_SSID
]));
257 if (tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
259 nla_for_each_nested(freq
,
260 tb_match
[NL80211_ATTR_SCAN_FREQUENCIES
],
262 printf(" %d", nla_get_u32(freq
));
267 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]) {
268 uint8_t *d
= nla_data(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]);
269 int l
= nla_len(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
]);
271 printf("\t* packet (might be truncated): ");
272 for (i
= 0; i
< l
; i
++) {
275 printf("%.2x", d
[i
]);
279 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]) {
280 uint8_t *d
= nla_data(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]);
281 int l
= nla_len(tb
[NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
]);
283 printf("\t* packet (might be truncated): ");
284 for (i
= 0; i
< l
; i
++) {
287 printf("%.2x", d
[i
]);
291 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
])
292 printf("\t* TCP connection wakeup received\n");
293 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
])
294 printf("\t* TCP connection lost\n");
295 if (tb
[NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
])
296 printf("\t* TCP connection ran out of tokens\n");
299 static void parse_nan_term(struct nlattr
**attrs
)
301 struct nlattr
*func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
303 static struct nla_policy
304 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
305 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
306 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
307 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
308 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
309 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
310 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
311 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
312 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
313 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
314 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
315 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
316 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
317 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
318 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
319 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
322 if (!attrs
[NL80211_ATTR_COOKIE
]) {
323 printf("Bad NAN func termination format - cookie is missing\n");
327 if (nla_parse_nested(func
, NL80211_NAN_FUNC_ATTR_MAX
,
328 attrs
[NL80211_ATTR_NAN_FUNC
],
330 printf("NAN: failed to parse nan func\n");
334 if (!func
[NL80211_NAN_FUNC_INSTANCE_ID
]) {
335 printf("Bad NAN func termination format-instance id missing\n");
339 if (!func
[NL80211_NAN_FUNC_TERM_REASON
]) {
340 printf("Bad NAN func termination format - reason is missing\n");
343 printf("NAN(cookie=0x%llx): Termination event: id = %d, reason = ",
344 (long long int)nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]),
345 nla_get_u8(func
[NL80211_NAN_FUNC_INSTANCE_ID
]));
346 switch (nla_get_u8(func
[NL80211_NAN_FUNC_TERM_REASON
])) {
347 case NL80211_NAN_FUNC_TERM_REASON_USER_REQUEST
:
348 printf("user request\n");
350 case NL80211_NAN_FUNC_TERM_REASON_TTL_EXPIRED
:
353 case NL80211_NAN_FUNC_TERM_REASON_ERROR
:
361 static const char *ftm_fail_reason(unsigned int reason
)
363 #define FTM_FAIL_REASON(x) case NL80211_PMSR_FTM_FAILURE_##x: return #x
365 FTM_FAIL_REASON(UNSPECIFIED
);
366 FTM_FAIL_REASON(NO_RESPONSE
);
367 FTM_FAIL_REASON(REJECTED
);
368 FTM_FAIL_REASON(WRONG_CHANNEL
);
369 FTM_FAIL_REASON(PEER_NOT_CAPABLE
);
370 FTM_FAIL_REASON(INVALID_TIMESTAMP
);
371 FTM_FAIL_REASON(PEER_BUSY
);
372 FTM_FAIL_REASON(BAD_CHANGED_PARAMS
);
378 static void parse_pmsr_ftm_data(struct nlattr
*data
)
380 struct nlattr
*ftm
[NL80211_PMSR_FTM_RESP_ATTR_MAX
+ 1];
383 nla_parse_nested(ftm
, NL80211_PMSR_FTM_RESP_ATTR_MAX
, data
, NULL
);
385 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]) {
386 printf(" failed: %s (%d)",
387 ftm_fail_reason(nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
])),
388 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON
]));
389 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
])
390 printf(" retry after %us",
391 nla_get_u32(ftm
[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME
]));
398 #define PFTM(tp, attr, sign) \
400 if (ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr]) \
401 printf(" " #attr ": %lld\n", \
402 (sign long long)nla_get_##tp( \
403 ftm[NL80211_PMSR_FTM_RESP_ATTR_##attr])); \
406 PFTM(u32
, BURST_INDEX
, unsigned);
407 PFTM(u32
, NUM_FTMR_ATTEMPTS
, unsigned);
408 PFTM(u32
, NUM_FTMR_SUCCESSES
, unsigned);
409 PFTM(u8
, NUM_BURSTS_EXP
, unsigned);
410 PFTM(u8
, BURST_DURATION
, unsigned);
411 PFTM(u8
, FTMS_PER_BURST
, unsigned);
412 PFTM(u32
, RSSI_AVG
, signed);
413 PFTM(u32
, RSSI_SPREAD
, unsigned);
414 PFTM(u64
, RTT_AVG
, signed);
415 PFTM(u64
, RTT_VARIANCE
, unsigned);
416 PFTM(u64
, RTT_SPREAD
, unsigned);
417 PFTM(u64
, DIST_AVG
, signed);
418 PFTM(u64
, DIST_VARIANCE
, unsigned);
419 PFTM(u64
, DIST_SPREAD
, unsigned);
421 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
]) {
424 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE
],
426 printf(" TX bitrate: %s\n", buf
);
429 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
]) {
432 parse_bitrate(ftm
[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE
],
434 printf(" RX bitrate: %s\n", buf
);
437 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
])
439 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]),
440 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_LCI
]));
442 if (ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
])
443 iw_hexdump(" civic location",
444 nla_data(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]),
445 nla_len(ftm
[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC
]));
448 static const char *pmsr_status(unsigned int status
)
450 #define PMSR_STATUS(x) case NL80211_PMSR_STATUS_##x: return #x
452 PMSR_STATUS(SUCCESS
);
453 PMSR_STATUS(REFUSED
);
454 PMSR_STATUS(TIMEOUT
);
455 PMSR_STATUS(FAILURE
);
462 static void parse_pmsr_peer(struct nlattr
*peer
)
464 struct nlattr
*tb
[NL80211_PMSR_PEER_ATTR_MAX
+ 1];
465 struct nlattr
*resp
[NL80211_PMSR_RESP_ATTR_MAX
+ 1];
466 struct nlattr
*data
[NL80211_PMSR_TYPE_MAX
+ 1];
470 err
= nla_parse_nested(tb
, NL80211_PMSR_PEER_ATTR_MAX
, peer
, NULL
);
472 printf(" Peer: failed to parse!\n");
476 if (!tb
[NL80211_PMSR_PEER_ATTR_ADDR
]) {
477 printf(" Peer: no MAC address\n");
481 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_PMSR_PEER_ATTR_ADDR
]));
482 printf(" Peer %s:", macbuf
);
484 if (!tb
[NL80211_PMSR_PEER_ATTR_RESP
]) {
485 printf(" no response!\n");
489 err
= nla_parse_nested(resp
, NL80211_PMSR_RESP_ATTR_MAX
,
490 tb
[NL80211_PMSR_PEER_ATTR_RESP
], NULL
);
492 printf(" failed to parse response!\n");
496 if (resp
[NL80211_PMSR_RESP_ATTR_STATUS
])
497 printf(" status=%d (%s)",
498 nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
]),
499 pmsr_status(nla_get_u32(resp
[NL80211_PMSR_RESP_ATTR_STATUS
])));
500 if (resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
])
502 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_HOST_TIME
]));
503 if (resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
])
505 (unsigned long long)nla_get_u64(resp
[NL80211_PMSR_RESP_ATTR_AP_TSF
]));
506 if (resp
[NL80211_PMSR_RESP_ATTR_FINAL
])
509 if (!resp
[NL80211_PMSR_RESP_ATTR_DATA
]) {
510 printf(" - no data!\n");
516 nla_parse_nested(data
, NL80211_PMSR_TYPE_MAX
,
517 resp
[NL80211_PMSR_RESP_ATTR_DATA
], NULL
);
519 if (data
[NL80211_PMSR_TYPE_FTM
])
520 parse_pmsr_ftm_data(data
[NL80211_PMSR_TYPE_FTM
]);
523 static void parse_pmsr_result(struct nlattr
**tb
,
524 struct print_event_args
*pargs
)
526 struct nlattr
*pmsr
[NL80211_PMSR_ATTR_MAX
+ 1];
528 unsigned long long cookie
;
531 if (!tb
[NL80211_ATTR_COOKIE
]) {
532 printf("Peer measurements: no cookie!\n");
535 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
537 if (!tb
[NL80211_ATTR_PEER_MEASUREMENTS
]) {
538 printf("Peer measurements: no measurement data!\n");
542 err
= nla_parse_nested(pmsr
, NL80211_PMSR_ATTR_MAX
,
543 tb
[NL80211_ATTR_PEER_MEASUREMENTS
], NULL
);
545 printf("Peer measurements: failed to parse measurement data!\n");
549 if (!pmsr
[NL80211_PMSR_ATTR_PEERS
]) {
550 printf("Peer measurements: no peer data!\n");
554 printf("Peer measurements (cookie %llu):\n", cookie
);
556 nla_for_each_nested(peer
, pmsr
[NL80211_PMSR_ATTR_PEERS
], i
)
557 parse_pmsr_peer(peer
);
560 static void parse_nan_match(struct nlattr
**attrs
)
564 struct nlattr
*match
[NL80211_NAN_MATCH_ATTR_MAX
+ 1];
565 struct nlattr
*local_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
566 struct nlattr
*peer_func
[NL80211_NAN_FUNC_ATTR_MAX
+ 1];
568 static struct nla_policy
569 nan_match_policy
[NL80211_NAN_MATCH_ATTR_MAX
+ 1] = {
570 [NL80211_NAN_MATCH_FUNC_LOCAL
] = { .type
= NLA_NESTED
},
571 [NL80211_NAN_MATCH_FUNC_PEER
] = { .type
= NLA_NESTED
},
574 static struct nla_policy
575 nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
576 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
577 [NL80211_NAN_FUNC_SERVICE_ID
] = { },
578 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
579 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
580 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
581 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
582 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
583 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { },
584 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
585 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
586 [NL80211_NAN_FUNC_SERVICE_INFO
] = { },
587 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
588 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
589 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
590 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
593 cookie
= nla_get_u64(attrs
[NL80211_ATTR_COOKIE
]);
594 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
596 if (nla_parse_nested(match
, NL80211_NAN_MATCH_ATTR_MAX
,
597 attrs
[NL80211_ATTR_NAN_MATCH
],
599 printf("NAN: failed to parse nan match event\n");
603 if (nla_parse_nested(local_func
, NL80211_NAN_FUNC_ATTR_MAX
,
604 match
[NL80211_NAN_MATCH_FUNC_LOCAL
],
606 printf("NAN: failed to parse nan local func\n");
610 if (nla_parse_nested(peer_func
, NL80211_NAN_FUNC_ATTR_MAX
,
611 match
[NL80211_NAN_MATCH_FUNC_PEER
],
613 printf("NAN: failed to parse nan local func\n");
617 if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
618 NL80211_NAN_FUNC_PUBLISH
) {
620 "NAN(cookie=0x%llx): DiscoveryResult, peer_id=%d, local_id=%d, peer_mac=%s",
622 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
623 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
625 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
626 printf(", info=%.*s",
627 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
628 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
629 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
630 NL80211_NAN_FUNC_SUBSCRIBE
) {
632 "NAN(cookie=0x%llx): Replied, peer_id=%d, local_id=%d, peer_mac=%s",
634 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
635 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
637 } else if (nla_get_u8(peer_func
[NL80211_NAN_FUNC_TYPE
]) ==
638 NL80211_NAN_FUNC_FOLLOW_UP
) {
640 "NAN(cookie=0x%llx): FollowUpReceive, peer_id=%d, local_id=%d, peer_mac=%s",
642 nla_get_u8(peer_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
643 nla_get_u8(local_func
[NL80211_NAN_FUNC_INSTANCE_ID
]),
645 if (peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
])
646 printf(", info=%.*s",
647 nla_len(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]),
648 (char *)nla_data(peer_func
[NL80211_NAN_FUNC_SERVICE_INFO
]));
650 printf("NaN: Malformed event");
656 static void parse_new_peer_candidate(struct nlattr
**attrs
)
658 char macbuf
[ETH_ALEN
* 3];
661 printf("new peer candidate");
662 if (attrs
[NL80211_ATTR_MAC
]) {
663 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
664 printf(" %s", macbuf
);
666 if (attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]) {
667 sig_dbm
= nla_get_u32(attrs
[NL80211_ATTR_RX_SIGNAL_DBM
]);
668 printf(" %d dBm", sig_dbm
);
674 static void parse_recv_interface(struct nlattr
**attrs
, int command
)
677 case NL80211_CMD_NEW_INTERFACE
:
678 printf("new interface");
680 case NL80211_CMD_DEL_INTERFACE
:
681 printf("del interface");
683 case NL80211_CMD_SET_INTERFACE
:
684 printf("set interface");
687 printf("unknown interface command (%i) received\n", command
);
691 if (attrs
[NL80211_ATTR_IFTYPE
]) {
693 switch (nla_get_u32(attrs
[NL80211_ATTR_IFTYPE
])) {
694 case NL80211_IFTYPE_STATION
:
697 case NL80211_IFTYPE_AP
:
698 printf("access point");
700 case NL80211_IFTYPE_MESH_POINT
:
701 printf("mesh point");
703 case NL80211_IFTYPE_ADHOC
:
706 case NL80211_IFTYPE_MONITOR
:
709 case NL80211_IFTYPE_AP_VLAN
:
712 case NL80211_IFTYPE_WDS
:
715 case NL80211_IFTYPE_P2P_CLIENT
:
716 printf("P2P-client");
718 case NL80211_IFTYPE_P2P_GO
:
721 case NL80211_IFTYPE_P2P_DEVICE
:
722 printf("P2P-Device");
724 case NL80211_IFTYPE_OCB
:
727 case NL80211_IFTYPE_NAN
:
731 printf("unknown (%d)",
732 nla_get_u32(attrs
[NL80211_ATTR_IFTYPE
]));
737 if (attrs
[NL80211_ATTR_MESH_ID
]) {
739 print_ssid_escaped(nla_len(attrs
[NL80211_ATTR_MESH_ID
]),
740 nla_data(attrs
[NL80211_ATTR_MESH_ID
]));
743 if (attrs
[NL80211_ATTR_4ADDR
]) {
744 printf(" use 4addr %d", nla_get_u8(attrs
[NL80211_ATTR_4ADDR
]));
750 static void parse_sta_opmode_changed(struct nlattr
**attrs
)
752 char macbuf
[ETH_ALEN
*3];
754 printf("sta opmode changed");
756 if (attrs
[NL80211_ATTR_MAC
]) {
757 mac_addr_n2a(macbuf
, nla_data(attrs
[NL80211_ATTR_MAC
]));
758 printf(" %s", macbuf
);
761 if (attrs
[NL80211_ATTR_SMPS_MODE
])
762 printf(" smps mode %d", nla_get_u8(attrs
[NL80211_ATTR_SMPS_MODE
]));
764 if (attrs
[NL80211_ATTR_CHANNEL_WIDTH
])
765 printf(" chan width %d", nla_get_u8(attrs
[NL80211_ATTR_CHANNEL_WIDTH
]));
767 if (attrs
[NL80211_ATTR_NSS
])
768 printf(" nss %d", nla_get_u8(attrs
[NL80211_ATTR_NSS
]));
773 static void parse_ch_switch_notify(struct nlattr
**attrs
, int command
)
776 case NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
:
777 printf("channel switch started");
779 case NL80211_CMD_CH_SWITCH_NOTIFY
:
780 printf("channel switch");
783 printf("unknown channel switch command (%i) received\n", command
);
787 if (attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
788 printf(" (count=%d)", nla_get_u32(attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]));
790 if (attrs
[NL80211_ATTR_WIPHY_FREQ
])
791 printf(" freq=%d", nla_get_u32(attrs
[NL80211_ATTR_WIPHY_FREQ
]));
793 if (attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
795 switch(nla_get_u32(attrs
[NL80211_ATTR_CHANNEL_WIDTH
])) {
796 case NL80211_CHAN_WIDTH_20_NOHT
:
797 case NL80211_CHAN_WIDTH_20
:
798 printf("\"20 MHz\"");
800 case NL80211_CHAN_WIDTH_40
:
801 printf("\"40 MHz\"");
803 case NL80211_CHAN_WIDTH_80
:
804 printf("\"80 MHz\"");
806 case NL80211_CHAN_WIDTH_80P80
:
807 printf("\"80+80 MHz\"");
809 case NL80211_CHAN_WIDTH_160
:
810 printf("\"160 MHz\"");
812 case NL80211_CHAN_WIDTH_5
:
815 case NL80211_CHAN_WIDTH_10
:
816 printf("\"10 MHz\"");
819 printf("\"unknown\"");
823 if (attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
825 switch(nla_get_u32(attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])) {
826 case NL80211_CHAN_NO_HT
:
829 case NL80211_CHAN_HT20
:
832 case NL80211_CHAN_HT40MINUS
:
835 case NL80211_CHAN_HT40PLUS
:
841 if (attrs
[NL80211_ATTR_CENTER_FREQ1
])
842 printf(" freq1=%d", nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ1
]));
844 if (attrs
[NL80211_ATTR_CENTER_FREQ2
])
845 printf(" freq2=%d", nla_get_u32(attrs
[NL80211_ATTR_CENTER_FREQ2
]));
850 static int print_event(struct nl_msg
*msg
, void *arg
)
852 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
853 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1], *nst
;
854 struct print_event_args
*args
= arg
;
858 struct ieee80211_beacon_channel chan_before_beacon
, chan_after_beacon
;
863 if (args
->time
|| args
->reltime
) {
864 unsigned long long usecs
, previous
;
866 previous
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
867 gettimeofday(&args
->ts
, NULL
);
868 usecs
= 1000000ULL * args
->ts
.tv_sec
+ args
->ts
.tv_usec
;
870 if (!args
->have_ts
) {
872 args
->have_ts
= true;
876 printf("%llu.%06llu: ", usecs
/1000000, usecs
% 1000000);
879 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
880 genlmsg_attrlen(gnlh
, 0), NULL
);
882 if (tb
[NL80211_ATTR_IFINDEX
] && tb
[NL80211_ATTR_WIPHY
]) {
883 /* if_indextoname may fails on delete interface/wiphy event */
884 if (if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
))
885 printf("%s (phy #%d): ", ifname
, nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
887 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
888 } else if (tb
[NL80211_ATTR_WDEV
] && tb
[NL80211_ATTR_WIPHY
]) {
889 printf("wdev 0x%llx (phy #%d): ",
890 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]),
891 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
892 } else if (tb
[NL80211_ATTR_IFINDEX
]) {
893 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), ifname
);
894 printf("%s: ", ifname
);
895 } else if (tb
[NL80211_ATTR_WDEV
]) {
896 printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_WDEV
]));
897 } else if (tb
[NL80211_ATTR_WIPHY
]) {
898 printf("phy #%d: ", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
902 case NL80211_CMD_NEW_WIPHY
:
903 printf("renamed to %s\n", nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]));
905 case NL80211_CMD_TRIGGER_SCAN
:
906 printf("scan started\n");
908 case NL80211_CMD_NEW_SCAN_RESULTS
:
909 printf("scan finished:");
911 case NL80211_CMD_SCAN_ABORTED
:
912 if (gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)
913 printf("scan aborted:");
914 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
915 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem_nst
)
916 printf(" %d", nla_get_u32(nst
));
919 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
920 nla_for_each_nested(nst
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem_nst
) {
922 print_ssid_escaped(nla_len(nst
), nla_data(nst
));
928 case NL80211_CMD_START_SCHED_SCAN
:
929 printf("scheduled scan started\n");
931 case NL80211_CMD_SCHED_SCAN_STOPPED
:
932 printf("sched scan stopped\n");
934 case NL80211_CMD_SCHED_SCAN_RESULTS
:
935 printf("got scheduled scan results\n");
937 case NL80211_CMD_WIPHY_REG_CHANGE
:
938 case NL80211_CMD_REG_CHANGE
:
939 if (gnlh
->cmd
== NL80211_CMD_WIPHY_REG_CHANGE
)
940 printf("regulatory domain change (phy): ");
942 printf("regulatory domain change: ");
944 reg_type
= nla_get_u8(tb
[NL80211_ATTR_REG_TYPE
]);
947 case NL80211_REGDOM_TYPE_COUNTRY
:
948 printf("set to %s by %s request",
949 nla_get_string(tb
[NL80211_ATTR_REG_ALPHA2
]),
950 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
951 if (tb
[NL80211_ATTR_WIPHY
])
952 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
954 case NL80211_REGDOM_TYPE_WORLD
:
955 printf("set to world roaming by %s request",
956 reg_initiator_to_string(nla_get_u8(tb
[NL80211_ATTR_REG_INITIATOR
])));
958 case NL80211_REGDOM_TYPE_CUSTOM_WORLD
:
959 printf("custom world roaming rules in place on phy%d by %s request",
960 nla_get_u32(tb
[NL80211_ATTR_WIPHY
]),
961 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
963 case NL80211_REGDOM_TYPE_INTERSECTION
:
964 printf("intersection used due to a request made by %s",
965 reg_initiator_to_string(nla_get_u32(tb
[NL80211_ATTR_REG_INITIATOR
])));
966 if (tb
[NL80211_ATTR_WIPHY
])
967 printf(" on phy%d", nla_get_u32(tb
[NL80211_ATTR_WIPHY
]));
970 printf("unknown source (upgrade this utility)");
976 case NL80211_CMD_REG_BEACON_HINT
:
978 wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
980 memset(&chan_before_beacon
, 0, sizeof(chan_before_beacon
));
981 memset(&chan_after_beacon
, 0, sizeof(chan_after_beacon
));
983 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_BEFORE
],
984 &chan_before_beacon
))
986 if (parse_beacon_hint_chan(tb
[NL80211_ATTR_FREQ_AFTER
],
990 if (chan_before_beacon
.center_freq
!= chan_after_beacon
.center_freq
)
993 /* A beacon hint is sent _only_ if something _did_ change */
994 printf("beacon hint:\n");
996 printf("phy%d %d MHz [%d]:\n",
998 chan_before_beacon
.center_freq
,
999 ieee80211_frequency_to_channel(chan_before_beacon
.center_freq
));
1001 if (chan_before_beacon
.no_ir
&& !chan_after_beacon
.no_ir
) {
1002 if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
)
1003 printf("\to Initiating radiation enabled\n");
1005 printf("\to active scan enabled\n");
1006 } else if (chan_before_beacon
.no_ibss
&& !chan_after_beacon
.no_ibss
) {
1007 printf("\to ibss enabled\n");
1011 case NL80211_CMD_NEW_STATION
:
1012 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1013 printf("new station %s\n", macbuf
);
1015 case NL80211_CMD_DEL_STATION
:
1016 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1017 printf("del station %s\n", macbuf
);
1019 case NL80211_CMD_JOIN_IBSS
:
1020 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1021 printf("IBSS %s joined\n", macbuf
);
1023 case NL80211_CMD_AUTHENTICATE
:
1025 if (tb
[NL80211_ATTR_FRAME
])
1026 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1027 else if (tb
[NL80211_ATTR_TIMED_OUT
])
1028 printf(": timed out");
1030 printf(": unknown event");
1033 case NL80211_CMD_ASSOCIATE
:
1035 if (tb
[NL80211_ATTR_FRAME
])
1036 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1037 else if (tb
[NL80211_ATTR_TIMED_OUT
])
1038 printf(": timed out");
1040 printf(": unknown event");
1043 case NL80211_CMD_DEAUTHENTICATE
:
1045 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1048 case NL80211_CMD_DISASSOCIATE
:
1050 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1053 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1054 printf("unprotected deauth");
1055 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1058 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1059 printf("unprotected disassoc");
1060 print_frame(args
, tb
[NL80211_ATTR_FRAME
]);
1063 case NL80211_CMD_CONNECT
:
1065 if (tb
[NL80211_ATTR_TIMED_OUT
])
1066 printf("timed out");
1067 else if (!tb
[NL80211_ATTR_STATUS_CODE
])
1068 printf("unknown connect status");
1069 else if (nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]) == 0)
1070 printf("connected");
1072 status
= nla_get_u16(tb
[NL80211_ATTR_STATUS_CODE
]);
1073 printf("failed to connect");
1075 if (tb
[NL80211_ATTR_MAC
]) {
1076 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1077 printf(" to %s", macbuf
);
1080 printf(", status: %d: %s", status
, get_status_str(status
));
1083 case NL80211_CMD_ROAM
:
1085 if (tb
[NL80211_ATTR_MAC
]) {
1086 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1087 printf(" to %s", macbuf
);
1091 case NL80211_CMD_DISCONNECT
:
1092 printf("disconnected");
1093 if (tb
[NL80211_ATTR_DISCONNECTED_BY_AP
])
1096 printf(" (local request)");
1097 if (tb
[NL80211_ATTR_REASON_CODE
])
1098 printf(" reason: %d: %s", nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]),
1099 get_reason_str(nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
])));
1102 case NL80211_CMD_REMAIN_ON_CHANNEL
:
1103 printf("remain on freq %d (%dms, cookie %llx)\n",
1104 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1105 nla_get_u32(tb
[NL80211_ATTR_DURATION
]),
1106 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1108 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
1109 printf("done with remain on freq %d (cookie %llx)\n",
1110 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1111 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1113 case NL80211_CMD_FRAME_WAIT_CANCEL
:
1114 printf("frame wait cancel on freq %d (cookie %llx)\n",
1115 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]),
1116 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]));
1118 case NL80211_CMD_NOTIFY_CQM
:
1119 parse_cqm_event(tb
);
1121 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
1122 parse_mic_failure(tb
);
1124 case NL80211_CMD_FRAME_TX_STATUS
:
1125 printf("mgmt TX status (cookie %llx): %s\n",
1126 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
1127 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
1129 case NL80211_CMD_PMKSA_CANDIDATE
:
1130 printf("PMKSA candidate found\n");
1132 case NL80211_CMD_SET_WOWLAN
:
1133 parse_wowlan_wake_event(tb
);
1135 case NL80211_CMD_PROBE_CLIENT
:
1136 if (tb
[NL80211_ATTR_MAC
])
1137 mac_addr_n2a(macbuf
, nla_data(tb
[NL80211_ATTR_MAC
]));
1139 strcpy(macbuf
, "??");
1140 printf("probe client %s (cookie %llx): %s\n",
1142 (unsigned long long)nla_get_u64(tb
[NL80211_ATTR_COOKIE
]),
1143 tb
[NL80211_ATTR_ACK
] ? "acked" : "no ack");
1145 case NL80211_CMD_VENDOR
:
1146 printf("vendor event %.6x:%d\n",
1147 nla_get_u32(tb
[NL80211_ATTR_VENDOR_ID
]),
1148 nla_get_u32(tb
[NL80211_ATTR_VENDOR_SUBCMD
]));
1149 if (args
->frame
&& tb
[NL80211_ATTR_VENDOR_DATA
])
1150 iw_hexdump("vendor event",
1151 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
1152 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
1154 case NL80211_CMD_RADAR_DETECT
: {
1155 enum nl80211_radar_event event_type
;
1158 if (!tb
[NL80211_ATTR_RADAR_EVENT
] ||
1159 !tb
[NL80211_ATTR_WIPHY_FREQ
]) {
1160 printf("BAD radar event\n");
1164 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1165 event_type
= nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
]);
1167 switch (event_type
) {
1168 case NL80211_RADAR_DETECTED
:
1169 printf("%d MHz: radar detected\n", freq
);
1171 case NL80211_RADAR_CAC_FINISHED
:
1172 printf("%d MHz: CAC finished\n", freq
);
1174 case NL80211_RADAR_CAC_ABORTED
:
1175 printf("%d MHz: CAC was aborted\n", freq
);
1177 case NL80211_RADAR_NOP_FINISHED
:
1178 printf("%d MHz: NOP finished\n", freq
);
1181 printf("%d MHz: unknown radar event\n", freq
);
1185 case NL80211_CMD_DEL_WIPHY
:
1186 printf("delete wiphy\n");
1188 case NL80211_CMD_PEER_MEASUREMENT_RESULT
:
1189 parse_pmsr_result(tb
, args
);
1191 case NL80211_CMD_PEER_MEASUREMENT_COMPLETE
:
1192 printf("peer measurement complete\n");
1194 case NL80211_CMD_DEL_NAN_FUNCTION
:
1197 case NL80211_CMD_NAN_MATCH
:
1198 parse_nan_match(tb
);
1200 case NL80211_CMD_NEW_PEER_CANDIDATE
:
1201 parse_new_peer_candidate(tb
);
1203 case NL80211_CMD_NEW_INTERFACE
:
1204 case NL80211_CMD_SET_INTERFACE
:
1205 case NL80211_CMD_DEL_INTERFACE
:
1206 parse_recv_interface(tb
, gnlh
->cmd
);
1208 case NL80211_CMD_STA_OPMODE_CHANGED
:
1209 parse_sta_opmode_changed(tb
);
1211 case NL80211_CMD_STOP_AP
:
1212 printf("stop ap\n");
1214 case NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
:
1215 case NL80211_CMD_CH_SWITCH_NOTIFY
:
1216 parse_ch_switch_notify(tb
, gnlh
->cmd
);
1219 printf("unknown event %d (%s)\n",
1220 gnlh
->cmd
, command_name(gnlh
->cmd
));
1229 int n_cmds
, n_prints
;
1231 const __u32
*prints
;
1233 struct print_event_args
*pargs
;
1236 static int wait_event(struct nl_msg
*msg
, void *arg
)
1238 struct wait_event
*wait
= arg
;
1239 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1243 for (i
= 0; i
< wait
->n_prints
; i
++) {
1244 if (gnlh
->cmd
== wait
->prints
[i
])
1245 print_event(msg
, wait
->pargs
);
1249 for (i
= 0; i
< wait
->n_cmds
; i
++) {
1250 if (gnlh
->cmd
== wait
->cmds
[i
])
1251 wait
->cmd
= gnlh
->cmd
;
1257 int __prepare_listen_events(struct nl80211_state
*state
)
1261 /* Configuration multicast group */
1262 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "config");
1266 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1270 /* Scan multicast group */
1271 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "scan");
1273 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1278 /* Regulatory multicast group */
1279 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "regulatory");
1281 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1286 /* MLME multicast group */
1287 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "mlme");
1289 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1294 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "vendor");
1296 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1301 mcid
= nl_get_multicast_id(state
->nl_sock
, "nl80211", "nan");
1303 ret
= nl_socket_add_membership(state
->nl_sock
, mcid
);
1311 __u32
__do_listen_events(struct nl80211_state
*state
,
1312 const int n_waits
, const __u32
*waits
,
1313 const int n_prints
, const __u32
*prints
,
1314 struct print_event_args
*args
)
1316 struct nl_cb
*cb
= nl_cb_alloc(iw_debug
? NL_CB_DEBUG
: NL_CB_DEFAULT
);
1317 struct wait_event wait_ev
;
1320 fprintf(stderr
, "failed to allocate netlink callbacks\n");
1324 /* no sequence checking for multicast messages */
1325 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
1326 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, valid_handler
, NULL
);
1328 if (n_waits
&& waits
) {
1329 wait_ev
.cmds
= waits
;
1330 wait_ev
.n_cmds
= n_waits
;
1331 wait_ev
.prints
= prints
;
1332 wait_ev
.n_prints
= n_prints
;
1333 wait_ev
.pargs
= args
;
1334 register_handler(wait_event
, &wait_ev
);
1336 register_handler(print_event
, args
);
1340 while (!wait_ev
.cmd
)
1341 nl_recvmsgs(state
->nl_sock
, cb
);
1348 __u32
listen_events(struct nl80211_state
*state
,
1349 const int n_waits
, const __u32
*waits
)
1353 ret
= __prepare_listen_events(state
);
1357 return __do_listen_events(state
, n_waits
, waits
, 0, NULL
, NULL
);
1360 static int print_events(struct nl80211_state
*state
,
1362 int argc
, char **argv
,
1365 struct print_event_args args
;
1368 memset(&args
, 0, sizeof(args
));
1374 if (strcmp(argv
[0], "-f") == 0)
1376 else if (strcmp(argv
[0], "-t") == 0)
1378 else if (strcmp(argv
[0], "-r") == 0)
1379 args
.reltime
= true;
1386 if (args
.time
&& args
.reltime
)
1392 ret
= __prepare_listen_events(state
);
1396 return __do_listen_events(state
, 0, NULL
, 0, NULL
, &args
);
1398 TOPLEVEL(event
, "[-t|-r] [-f]", 0, 0, CIB_NONE
, print_events
,
1399 "Monitor events from the kernel.\n"
1400 "-t - print timestamp\n"
1401 "-r - print relative timestamp\n"
1402 "-f - print full frame for auth/assoc etc.");