5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8 #include <netlink/msg.h>
9 #include <netlink/attr.h>
26 static void print_power_mode(struct nlattr
*a
)
28 enum nl80211_mesh_power_mode pm
= nla_get_u32(a
);
31 case NL80211_MESH_POWER_ACTIVE
:
34 case NL80211_MESH_POWER_LIGHT_SLEEP
:
35 printf("LIGHT SLEEP");
37 case NL80211_MESH_POWER_DEEP_SLEEP
:
46 int parse_txq_stats(char *buf
, int buflen
, struct nlattr
*tid_stats_attr
, int header
,
47 int tid
, const char *indent
)
49 struct nlattr
*txqstats_info
[NL80211_TXQ_STATS_MAX
+ 1], *txqinfo
;
50 static struct nla_policy txqstats_policy
[NL80211_TXQ_STATS_MAX
+ 1] = {
51 [NL80211_TXQ_STATS_BACKLOG_BYTES
] = { .type
= NLA_U32
},
52 [NL80211_TXQ_STATS_BACKLOG_PACKETS
] = { .type
= NLA_U32
},
53 [NL80211_TXQ_STATS_FLOWS
] = { .type
= NLA_U32
},
54 [NL80211_TXQ_STATS_DROPS
] = { .type
= NLA_U32
},
55 [NL80211_TXQ_STATS_ECN_MARKS
] = { .type
= NLA_U32
},
56 [NL80211_TXQ_STATS_OVERLIMIT
] = { .type
= NLA_U32
},
57 [NL80211_TXQ_STATS_COLLISIONS
] = { .type
= NLA_U32
},
58 [NL80211_TXQ_STATS_TX_BYTES
] = { .type
= NLA_U32
},
59 [NL80211_TXQ_STATS_TX_PACKETS
] = { .type
= NLA_U32
},
62 if (nla_parse_nested(txqstats_info
, NL80211_TXQ_STATS_MAX
, tid_stats_attr
,
64 printf("failed to parse nested TXQ stats attributes!");
69 pos
+= snprintf(buf
, buflen
, "\n%s\t%s\tqsz-byt\t"
70 "qsz-pkt\tflows\tdrops\tmarks\toverlmt\t"
71 "hashcol\ttx-bytes\ttx-packets", indent
,
72 tid
>= 0 ? "TID" : "");
74 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "\n%s\t", indent
);
76 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "%d", tid
);
78 #define PRINT_STAT(key, spacer) do { \
79 txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \
80 pos += snprintf(pos, buflen - (pos - buf), spacer); \
82 pos += snprintf(pos, buflen - (pos - buf), "%u", \
83 nla_get_u32(txqinfo)); \
87 PRINT_STAT(BACKLOG_BYTES
, "\t");
88 PRINT_STAT(BACKLOG_PACKETS
, "\t");
89 PRINT_STAT(FLOWS
, "\t");
90 PRINT_STAT(DROPS
, "\t");
91 PRINT_STAT(ECN_MARKS
, "\t");
92 PRINT_STAT(OVERLIMIT
, "\t");
93 PRINT_STAT(COLLISIONS
, "\t");
94 PRINT_STAT(TX_BYTES
, "\t");
95 PRINT_STAT(TX_PACKETS
, "\t\t");
103 static void parse_tid_stats(struct nlattr
*tid_stats_attr
)
105 struct nlattr
*stats_info
[NL80211_TID_STATS_MAX
+ 1], *tidattr
, *info
;
106 static struct nla_policy stats_policy
[NL80211_TID_STATS_MAX
+ 1] = {
107 [NL80211_TID_STATS_RX_MSDU
] = { .type
= NLA_U64
},
108 [NL80211_TID_STATS_TX_MSDU
] = { .type
= NLA_U64
},
109 [NL80211_TID_STATS_TX_MSDU_RETRIES
] = { .type
= NLA_U64
},
110 [NL80211_TID_STATS_TX_MSDU_FAILED
] = { .type
= NLA_U64
},
111 [NL80211_TID_STATS_TXQ_STATS
] = { .type
= NLA_NESTED
},
114 char txqbuf
[2000] = {}, *pos
= txqbuf
;
115 int buflen
= sizeof(txqbuf
), foundtxq
= 0;
117 printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed");
118 nla_for_each_nested(tidattr
, tid_stats_attr
, rem
) {
119 if (nla_parse_nested(stats_info
, NL80211_TID_STATS_MAX
,
120 tidattr
, stats_policy
)) {
121 printf("failed to parse nested stats attributes!");
124 printf("\n\t\t%d", i
);
125 info
= stats_info
[NL80211_TID_STATS_RX_MSDU
];
127 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
128 info
= stats_info
[NL80211_TID_STATS_TX_MSDU
];
130 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
131 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_RETRIES
];
133 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
134 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_FAILED
];
136 printf("\t\t%llu", (unsigned long long)nla_get_u64(info
));
137 info
= stats_info
[NL80211_TID_STATS_TXQ_STATS
];
139 pos
+= parse_txq_stats(pos
, buflen
- (pos
- txqbuf
), info
, !foundtxq
, i
, "\t");
147 printf("\n\tTXQs:%s", txqbuf
);
150 static void parse_bss_param(struct nlattr
*bss_param_attr
)
152 struct nlattr
*bss_param_info
[NL80211_STA_BSS_PARAM_MAX
+ 1], *info
;
153 static struct nla_policy bss_poilcy
[NL80211_STA_BSS_PARAM_MAX
+ 1] = {
154 [NL80211_STA_BSS_PARAM_CTS_PROT
] = { .type
= NLA_FLAG
},
155 [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
156 [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
] = { .type
= NLA_FLAG
},
157 [NL80211_STA_BSS_PARAM_DTIM_PERIOD
] = { .type
= NLA_U8
},
158 [NL80211_STA_BSS_PARAM_BEACON_INTERVAL
] = { .type
= NLA_U16
},
161 if (nla_parse_nested(bss_param_info
, NL80211_STA_BSS_PARAM_MAX
,
162 bss_param_attr
, bss_poilcy
)) {
163 printf("failed to parse nested bss param attributes!");
166 info
= bss_param_info
[NL80211_STA_BSS_PARAM_DTIM_PERIOD
];
168 printf("\n\tDTIM period:\t%u", nla_get_u8(info
));
169 info
= bss_param_info
[NL80211_STA_BSS_PARAM_BEACON_INTERVAL
];
171 printf("\n\tbeacon interval:%u", nla_get_u16(info
));
172 info
= bss_param_info
[NL80211_STA_BSS_PARAM_CTS_PROT
];
174 printf("\n\tCTS protection:");
175 if (nla_get_u16(info
))
180 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
];
182 printf("\n\tshort preamble:");
183 if (nla_get_u16(info
))
188 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
];
190 printf("\n\tshort slot time:");
191 if (nla_get_u16(info
))
198 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
)
202 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
203 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
204 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
205 [NL80211_RATE_INFO_BITRATE32
] = { .type
= NLA_U32
},
206 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
207 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
208 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
211 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
212 bitrate_attr
, rate_policy
)) {
213 snprintf(buf
, buflen
, "failed to parse nested rate attributes!");
217 if (rinfo
[NL80211_RATE_INFO_BITRATE32
])
218 rate
= nla_get_u32(rinfo
[NL80211_RATE_INFO_BITRATE32
]);
219 else if (rinfo
[NL80211_RATE_INFO_BITRATE
])
220 rate
= nla_get_u16(rinfo
[NL80211_RATE_INFO_BITRATE
]);
222 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
223 "%d.%d MBit/s", rate
/ 10, rate
% 10);
225 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "(unknown)");
227 if (rinfo
[NL80211_RATE_INFO_MCS
])
228 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
229 " MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_MCS
]));
230 if (rinfo
[NL80211_RATE_INFO_VHT_MCS
])
231 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
232 " VHT-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_MCS
]));
233 if (rinfo
[NL80211_RATE_INFO_40_MHZ_WIDTH
])
234 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 40MHz");
235 if (rinfo
[NL80211_RATE_INFO_80_MHZ_WIDTH
])
236 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80MHz");
237 if (rinfo
[NL80211_RATE_INFO_80P80_MHZ_WIDTH
])
238 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80P80MHz");
239 if (rinfo
[NL80211_RATE_INFO_160_MHZ_WIDTH
])
240 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 160MHz");
241 if (rinfo
[NL80211_RATE_INFO_SHORT_GI
])
242 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " short GI");
243 if (rinfo
[NL80211_RATE_INFO_VHT_NSS
])
244 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
245 " VHT-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_NSS
]));
246 if (rinfo
[NL80211_RATE_INFO_HE_MCS
])
247 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
248 " HE-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_MCS
]));
249 if (rinfo
[NL80211_RATE_INFO_HE_NSS
])
250 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
251 " HE-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_NSS
]));
252 if (rinfo
[NL80211_RATE_INFO_HE_GI
])
253 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
254 " HE-GI %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_GI
]));
255 if (rinfo
[NL80211_RATE_INFO_HE_DCM
])
256 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
257 " HE-DCM %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_DCM
]));
260 static char *get_chain_signal(struct nlattr
*attr_list
)
271 nla_for_each_nested(attr
, attr_list
, rem
) {
277 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
278 (int8_t) nla_get_u8(attr
));
282 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
287 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
289 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
290 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
291 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
292 char mac_addr
[20], state_name
[10], dev
[20];
293 struct nl80211_sta_flag_update
*sta_flags
;
294 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
295 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
296 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
297 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
298 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
299 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
300 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
301 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
302 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
303 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
304 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
305 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
306 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
307 [NL80211_STA_INFO_LLID
] = { .type
= NLA_U16
},
308 [NL80211_STA_INFO_PLID
] = { .type
= NLA_U16
},
309 [NL80211_STA_INFO_PLINK_STATE
] = { .type
= NLA_U8
},
310 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
311 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
312 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
313 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
314 [NL80211_STA_INFO_STA_FLAGS
] =
315 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
316 [NL80211_STA_INFO_LOCAL_PM
] = { .type
= NLA_U32
},
317 [NL80211_STA_INFO_PEER_PM
] = { .type
= NLA_U32
},
318 [NL80211_STA_INFO_NONPEER_PM
] = { .type
= NLA_U32
},
319 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
320 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
321 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
322 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
323 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
324 [NL80211_STA_INFO_TX_DURATION
] = { .type
= NLA_U64
},
325 [NL80211_STA_INFO_ACK_SIGNAL
] = {.type
= NLA_U8
},
326 [NL80211_STA_INFO_ACK_SIGNAL_AVG
] = { .type
= NLA_U8
},
330 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
331 genlmsg_attrlen(gnlh
, 0), NULL
);
334 * TODO: validate the interface and mac address!
335 * Otherwise, there's a race condition as soon as
336 * the kernel starts sending station notifications.
339 if (!tb
[NL80211_ATTR_STA_INFO
]) {
340 fprintf(stderr
, "sta stats missing!\n");
343 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
344 tb
[NL80211_ATTR_STA_INFO
],
346 fprintf(stderr
, "failed to parse nested attributes!\n");
350 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
351 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
352 printf("Station %s (on %s)", mac_addr
, dev
);
354 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
355 printf("\n\tinactive time:\t%u ms",
356 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
357 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
358 printf("\n\trx bytes:\t%llu",
359 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
360 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
361 printf("\n\trx bytes:\t%u",
362 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
363 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
364 printf("\n\trx packets:\t%u",
365 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
366 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
367 printf("\n\ttx bytes:\t%llu",
368 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
369 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
370 printf("\n\ttx bytes:\t%u",
371 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
372 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
373 printf("\n\ttx packets:\t%u",
374 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
375 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
376 printf("\n\ttx retries:\t%u",
377 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
378 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
379 printf("\n\ttx failed:\t%u",
380 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
381 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
382 printf("\n\tbeacon loss:\t%u",
383 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
384 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
385 printf("\n\tbeacon rx:\t%llu",
386 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
387 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
388 printf("\n\trx drop misc:\t%llu",
389 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
391 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
392 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
393 printf("\n\tsignal: \t%d %sdBm",
394 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
397 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
398 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
399 printf("\n\tsignal avg:\t%d %sdBm",
400 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
403 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
404 printf("\n\tbeacon signal avg:\t%d dBm",
405 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
406 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
407 printf("\n\tToffset:\t%llu us",
408 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
410 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
413 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
414 printf("\n\ttx bitrate:\t%s", buf
);
417 if (sinfo
[NL80211_STA_INFO_TX_DURATION
])
418 printf("\n\ttx duration:\t%lld us",
419 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_DURATION
]));
421 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
424 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
425 printf("\n\trx bitrate:\t%s", buf
);
428 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
429 printf("\n\trx duration:\t%lld us",
430 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
432 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL
])
433 printf("\n\tlast ack signal:%d dBm",
434 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL
]));
436 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
])
437 printf("\n\tavg ack signal:\t%d dBm",
438 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
]));
440 if (sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]) {
441 printf("\n\tairtime weight: %d", nla_get_u16(sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]));
444 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
447 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
448 /* convert in Mbps but scale by 1000 to save kbps units */
449 thr
= thr
* 1000 / 1024;
451 printf("\n\texpected throughput:\t%u.%uMbps",
452 thr
/ 1000, thr
% 1000);
455 if (sinfo
[NL80211_STA_INFO_LLID
])
456 printf("\n\tmesh llid:\t%d",
457 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
458 if (sinfo
[NL80211_STA_INFO_PLID
])
459 printf("\n\tmesh plid:\t%d",
460 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
461 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
462 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
464 strcpy(state_name
, "LISTEN");
467 strcpy(state_name
, "OPN_SNT");
470 strcpy(state_name
, "OPN_RCVD");
473 strcpy(state_name
, "CNF_RCVD");
476 strcpy(state_name
, "ESTAB");
479 strcpy(state_name
, "HOLDING");
482 strcpy(state_name
, "BLOCKED");
485 strcpy(state_name
, "UNKNOWN");
488 printf("\n\tmesh plink:\t%s", state_name
);
490 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
491 printf("\n\tmesh local PS mode:\t");
492 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
494 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
495 printf("\n\tmesh peer PS mode:\t");
496 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
498 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
499 printf("\n\tmesh non-peer PS mode:\t");
500 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
503 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
504 sta_flags
= (struct nl80211_sta_flag_update
*)
505 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
507 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
508 printf("\n\tauthorized:\t");
509 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
515 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
516 printf("\n\tauthenticated:\t");
517 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
523 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
524 printf("\n\tassociated:\t");
525 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
531 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
532 printf("\n\tpreamble:\t");
533 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
539 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
540 printf("\n\tWMM/WME:\t");
541 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
547 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
548 printf("\n\tMFP:\t\t");
549 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
555 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
556 printf("\n\tTDLS peer:\t");
557 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
564 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
565 !strcmp((char *)arg
, "-v"))
566 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
567 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
568 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
569 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
570 printf("\n\tconnected time:\t%u seconds",
571 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
577 static int handle_station_get(struct nl80211_state
*state
,
579 int argc
, char **argv
,
582 unsigned char mac_addr
[ETH_ALEN
];
587 if (mac_addr_a2n(mac_addr
, argv
[0])) {
588 fprintf(stderr
, "invalid mac address\n");
598 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
600 register_handler(print_sta_handler
, NULL
);
606 COMMAND(station
, get
, "<MAC address>",
607 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
608 "Get information for a specific station.");
610 static int handle_station_del(struct nl80211_state
*state
,
612 int argc
, char **argv
,
616 unsigned char mac_addr
[ETH_ALEN
];
623 if (mac_addr_a2n(mac_addr
, argv
[0])) {
624 fprintf(stderr
, "invalid mac address\n");
630 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
632 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
636 subtype
= strtod(argv
[0], &end
);
640 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
645 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
649 reason_code
= strtod(argv
[0], &end
);
653 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
661 register_handler(print_sta_handler
, NULL
);
667 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
668 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
669 "Remove the given station entry (use with caution!)\n"
670 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
672 static const struct cmd
*station_set_plink
;
673 static const struct cmd
*station_set_vlan
;
674 static const struct cmd
*station_set_mesh_power_mode
;
675 static const struct cmd
*station_set_airtime_weight
;
676 static const struct cmd
*station_set_txpwr
;
678 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
682 if (strcmp(argv
[1], "plink_action") == 0)
683 return station_set_plink
;
684 if (strcmp(argv
[1], "vlan") == 0)
685 return station_set_vlan
;
686 if (strcmp(argv
[1], "mesh_power_mode") == 0)
687 return station_set_mesh_power_mode
;
688 if (strcmp(argv
[1], "airtime_weight") == 0)
689 return station_set_airtime_weight
;
690 if (strcmp(argv
[1], "txpwr") == 0)
691 return station_set_txpwr
;
695 static int handle_station_set_plink(struct nl80211_state
*state
,
697 int argc
, char **argv
,
700 unsigned char plink_action
;
701 unsigned char mac_addr
[ETH_ALEN
];
706 if (mac_addr_a2n(mac_addr
, argv
[0])) {
707 fprintf(stderr
, "invalid mac address\n");
713 if (strcmp("plink_action", argv
[0]) != 0)
718 if (strcmp("open", argv
[0]) == 0)
719 plink_action
= NL80211_PLINK_ACTION_OPEN
;
720 else if (strcmp("block", argv
[0]) == 0)
721 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
723 fprintf(stderr
, "plink action not supported\n");
732 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
733 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
739 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
740 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
741 "Set mesh peer link action for this station (peer).",
742 select_station_cmd
, station_set_plink
);
744 static int handle_station_set_vlan(struct nl80211_state
*state
,
746 int argc
, char **argv
,
749 unsigned char mac_addr
[ETH_ALEN
];
750 unsigned long sta_vlan
= 0;
756 if (mac_addr_a2n(mac_addr
, argv
[0])) {
757 fprintf(stderr
, "invalid mac address\n");
763 if (strcmp("vlan", argv
[0]) != 0)
768 sta_vlan
= strtoul(argv
[0], &err
, 0);
770 fprintf(stderr
, "invalid vlan id\n");
779 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
780 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
786 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
787 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
788 "Set an AP VLAN for this station.",
789 select_station_cmd
, station_set_vlan
);
791 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
793 int argc
, char **argv
,
796 unsigned char mesh_power_mode
;
797 unsigned char mac_addr
[ETH_ALEN
];
802 if (mac_addr_a2n(mac_addr
, argv
[0])) {
803 fprintf(stderr
, "invalid mac address\n");
809 if (strcmp("mesh_power_mode", argv
[0]) != 0)
814 if (strcmp("active", argv
[0]) == 0)
815 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
816 else if (strcmp("light", argv
[0]) == 0)
817 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
818 else if (strcmp("deep", argv
[0]) == 0)
819 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
821 fprintf(stderr
, "unknown mesh power mode\n");
830 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
831 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
837 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
838 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
839 handle_station_set_mesh_power_mode
,
840 "Set link-specific mesh power mode for this station",
841 select_station_cmd
, station_set_mesh_power_mode
);
843 static int handle_station_set_airtime_weight(struct nl80211_state
*state
,
845 int argc
, char **argv
,
848 unsigned char mac_addr
[ETH_ALEN
];
849 unsigned long airtime_weight
= 0;
855 if (mac_addr_a2n(mac_addr
, argv
[0])) {
856 fprintf(stderr
, "invalid mac address\n");
862 if (strcmp("airtime_weight", argv
[0]) != 0)
867 airtime_weight
= strtoul(argv
[0], &err
, 0);
869 fprintf(stderr
, "invalid airtime weight\n");
878 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
879 NLA_PUT_U16(msg
, NL80211_ATTR_AIRTIME_WEIGHT
, airtime_weight
);
886 COMMAND_ALIAS(station
, set
, "<MAC address> airtime_weight <weight>",
887 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_airtime_weight
,
888 "Set airtime weight for this station.",
889 select_station_cmd
, station_set_airtime_weight
);
891 static int handle_station_set_txpwr(struct nl80211_state
*state
,
893 int argc
, char **argv
,
896 enum nl80211_tx_power_setting type
;
897 unsigned char mac_addr
[ETH_ALEN
];
901 if (argc
!= 3 && argc
!= 4)
904 if (mac_addr_a2n(mac_addr
, argv
[0])) {
905 fprintf(stderr
, "invalid mac address\n");
909 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
913 if (strcmp("txpwr", argv
[0]) != 0)
918 if (!strcmp(argv
[0], "auto"))
919 type
= NL80211_TX_POWER_AUTOMATIC
;
920 else if (!strcmp(argv
[0], "limit"))
921 type
= NL80211_TX_POWER_LIMITED
;
923 printf("Invalid parameter: %s\n", argv
[0]);
927 NLA_PUT_U8(msg
, NL80211_ATTR_STA_TX_POWER_SETTING
, type
);
929 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
931 printf("Missing TX power level argument.\n");
938 sta_txpwr
= strtoul(argv
[0], &err
, 0);
939 NLA_PUT_U16(msg
, NL80211_ATTR_STA_TX_POWER
, sta_txpwr
);
952 COMMAND_ALIAS(station
, set
, "<MAC address> txpwr <auto|limit> [<tx power dBm>]",
953 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_txpwr
,
954 "Set Tx power for this station.",
955 select_station_cmd
, station_set_txpwr
);
957 static int handle_station_dump(struct nl80211_state
*state
,
959 int argc
, char **argv
,
962 register_handler(print_sta_handler
, *argv
);
965 COMMAND(station
, dump
, "[-v]",
966 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
967 "List all stations known, e.g. the AP on managed interfaces");