]>
Commit | Line | Data |
---|---|---|
2ef1be68 | 1 | #include <net/if.h> |
3d1e8704 | 2 | #include <errno.h> |
d5ac8ad3 | 3 | #include <string.h> |
2ef1be68 | 4 | |
3d1e8704 LCC |
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> | |
3d1e8704 | 10 | |
f408e01b | 11 | #include "nl80211.h" |
3d1e8704 LCC |
12 | #include "iw.h" |
13 | ||
4698bfc2 JB |
14 | SECTION(station); |
15 | ||
3d1e8704 LCC |
16 | enum plink_state { |
17 | LISTEN, | |
18 | OPN_SNT, | |
19 | OPN_RCVD, | |
20 | CNF_RCVD, | |
21 | ESTAB, | |
22 | HOLDING, | |
23 | BLOCKED | |
24 | }; | |
25 | ||
8012ad28 MP |
26 | static void print_power_mode(struct nlattr *a) |
27 | { | |
28 | enum nl80211_mesh_power_mode pm = nla_get_u32(a); | |
29 | ||
30 | switch (pm) { | |
31 | case NL80211_MESH_POWER_ACTIVE: | |
32 | printf("ACTIVE"); | |
33 | break; | |
34 | case NL80211_MESH_POWER_LIGHT_SLEEP: | |
35 | printf("LIGHT SLEEP"); | |
36 | break; | |
37 | case NL80211_MESH_POWER_DEEP_SLEEP: | |
38 | printf("DEEP SLEEP"); | |
39 | break; | |
40 | default: | |
41 | printf("UNKNOWN"); | |
42 | break; | |
43 | } | |
44 | } | |
3d1e8704 | 45 | |
568c7057 AE |
46 | void parse_tid_stats(struct nlattr *tid_stats_attr) |
47 | { | |
48 | struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1], *tidattr, *info; | |
49 | static struct nla_policy stats_policy[NL80211_TID_STATS_MAX + 1] = { | |
50 | [NL80211_TID_STATS_RX_MSDU] = { .type = NLA_U64 }, | |
51 | [NL80211_TID_STATS_TX_MSDU] = { .type = NLA_U64 }, | |
52 | [NL80211_TID_STATS_TX_MSDU_RETRIES] = { .type = NLA_U64 }, | |
53 | [NL80211_TID_STATS_TX_MSDU_FAILED] = { .type = NLA_U64 }, | |
54 | }; | |
55 | int rem, i = 0; | |
56 | ||
57 | printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed"); | |
58 | nla_for_each_nested(tidattr, tid_stats_attr, rem) { | |
59 | if (nla_parse_nested(stats_info, NL80211_TID_STATS_MAX, | |
60 | tidattr, stats_policy)) { | |
61 | printf("failed to parse nested stats attributes!"); | |
62 | return; | |
63 | } | |
64 | printf("\n\t\t%d", i++); | |
65 | info = stats_info[NL80211_TID_STATS_RX_MSDU]; | |
66 | if (info) | |
67 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
68 | info = stats_info[NL80211_TID_STATS_TX_MSDU]; | |
69 | if (info) | |
70 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
71 | info = stats_info[NL80211_TID_STATS_TX_MSDU_RETRIES]; | |
72 | if (info) | |
73 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
74 | info = stats_info[NL80211_TID_STATS_TX_MSDU_FAILED]; | |
75 | if (info) | |
76 | printf("\t\t%llu", (unsigned long long)nla_get_u64(info)); | |
77 | } | |
78 | } | |
79 | ||
80 | void parse_bss_param(struct nlattr *bss_param_attr) | |
81 | { | |
82 | struct nlattr *bss_param_info[NL80211_STA_BSS_PARAM_MAX + 1], *info; | |
83 | static struct nla_policy bss_poilcy[NL80211_STA_BSS_PARAM_MAX + 1] = { | |
84 | [NL80211_STA_BSS_PARAM_CTS_PROT] = { .type = NLA_FLAG }, | |
85 | [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
86 | [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME] = { .type = NLA_FLAG }, | |
87 | [NL80211_STA_BSS_PARAM_DTIM_PERIOD] = { .type = NLA_U8 }, | |
88 | [NL80211_STA_BSS_PARAM_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
89 | }; | |
90 | ||
91 | if (nla_parse_nested(bss_param_info, NL80211_STA_BSS_PARAM_MAX, | |
92 | bss_param_attr, bss_poilcy)) { | |
93 | printf("failed to parse nested bss param attributes!"); | |
94 | } | |
95 | ||
96 | info = bss_param_info[NL80211_STA_BSS_PARAM_DTIM_PERIOD]; | |
97 | if (info) | |
98 | printf("\n\tDTIM period:\t%u", nla_get_u8(info)); | |
99 | info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]; | |
100 | if (info) | |
101 | printf("\n\tbeacon interval:%u", nla_get_u16(info)); | |
102 | info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT]; | |
103 | if (info) { | |
104 | printf("\n\tCTS protection:"); | |
105 | if (nla_get_u16(info)) | |
106 | printf("\tyes"); | |
107 | else | |
108 | printf("\tno"); | |
109 | } | |
110 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE]; | |
111 | if (info) { | |
112 | printf("\n\tshort preamble:"); | |
113 | if (nla_get_u16(info)) | |
114 | printf("\tyes"); | |
115 | else | |
116 | printf("\tno"); | |
117 | } | |
118 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME]; | |
119 | if (info) { | |
120 | printf("\n\tshort slot time:"); | |
121 | if (nla_get_u16(info)) | |
122 | printf("yes"); | |
123 | else | |
124 | printf("no"); | |
125 | } | |
126 | } | |
127 | ||
e94f0201 | 128 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) |
64179590 JB |
129 | { |
130 | int rate = 0; | |
131 | char *pos = buf; | |
132 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; | |
133 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
134 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
135 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
136 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
137 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
138 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
139 | }; | |
140 | ||
141 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
142 | bitrate_attr, rate_policy)) { | |
143 | snprintf(buf, buflen, "failed to parse nested rate attributes!"); | |
144 | return; | |
145 | } | |
146 | ||
147 | if (rinfo[NL80211_RATE_INFO_BITRATE32]) | |
148 | rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]); | |
149 | else if (rinfo[NL80211_RATE_INFO_BITRATE]) | |
150 | rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]); | |
151 | if (rate > 0) | |
152 | pos += snprintf(pos, buflen - (pos - buf), | |
153 | "%d.%d MBit/s", rate / 10, rate % 10); | |
154 | ||
155 | if (rinfo[NL80211_RATE_INFO_MCS]) | |
156 | pos += snprintf(pos, buflen - (pos - buf), | |
157 | " MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS])); | |
158 | if (rinfo[NL80211_RATE_INFO_VHT_MCS]) | |
159 | pos += snprintf(pos, buflen - (pos - buf), | |
160 | " VHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_MCS])); | |
161 | if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH]) | |
162 | pos += snprintf(pos, buflen - (pos - buf), " 40MHz"); | |
163 | if (rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH]) | |
164 | pos += snprintf(pos, buflen - (pos - buf), " 80MHz"); | |
165 | if (rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH]) | |
166 | pos += snprintf(pos, buflen - (pos - buf), " 80P80MHz"); | |
167 | if (rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH]) | |
168 | pos += snprintf(pos, buflen - (pos - buf), " 160MHz"); | |
169 | if (rinfo[NL80211_RATE_INFO_SHORT_GI]) | |
170 | pos += snprintf(pos, buflen - (pos - buf), " short GI"); | |
171 | if (rinfo[NL80211_RATE_INFO_VHT_NSS]) | |
172 | pos += snprintf(pos, buflen - (pos - buf), | |
173 | " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS])); | |
174 | } | |
175 | ||
7d23bc2d FF |
176 | static char *get_chain_signal(struct nlattr *attr_list) |
177 | { | |
178 | struct nlattr *attr; | |
179 | static char buf[64]; | |
180 | char *cur = buf; | |
181 | int i = 0, rem; | |
182 | const char *prefix; | |
183 | ||
184 | if (!attr_list) | |
185 | return ""; | |
186 | ||
187 | nla_for_each_nested(attr, attr_list, rem) { | |
188 | if (i++ > 0) | |
189 | prefix = ", "; | |
190 | else | |
191 | prefix = "["; | |
192 | ||
193 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
194 | (int8_t) nla_get_u8(attr)); | |
195 | } | |
196 | ||
197 | if (i) | |
198 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
199 | ||
200 | return buf; | |
201 | } | |
202 | ||
3d1e8704 LCC |
203 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
204 | { | |
205 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
206 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
207 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
208 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 209 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
210 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
211 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
212 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
213 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
214 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
215 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
216 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
217 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 218 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 219 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 220 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 221 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 222 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
223 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
224 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
225 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
226 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
227 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
228 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
229 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
230 | [NL80211_STA_INFO_STA_FLAGS] = |
231 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
232 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
233 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
234 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
235 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
236 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
237 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
238 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
3d1e8704 | 239 | }; |
7d23bc2d | 240 | char *chain; |
3d1e8704 LCC |
241 | |
242 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
243 | genlmsg_attrlen(gnlh, 0), NULL); | |
244 | ||
245 | /* | |
246 | * TODO: validate the interface and mac address! | |
247 | * Otherwise, there's a race condition as soon as | |
248 | * the kernel starts sending station notifications. | |
249 | */ | |
250 | ||
251 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 252 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
253 | return NL_SKIP; |
254 | } | |
255 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
256 | tb[NL80211_ATTR_STA_INFO], | |
257 | stats_policy)) { | |
5fe70c0e | 258 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
259 | return NL_SKIP; |
260 | } | |
261 | ||
262 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
263 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 264 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
265 | |
266 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 267 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 268 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
269 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
270 | printf("\n\trx bytes:\t%llu", | |
271 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
272 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 273 | printf("\n\trx bytes:\t%u", |
568c7057 | 274 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 275 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 276 | printf("\n\trx packets:\t%u", |
859677cb | 277 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
278 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
279 | printf("\n\ttx bytes:\t%llu", | |
280 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
281 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 282 | printf("\n\ttx bytes:\t%u", |
568c7057 | 283 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 284 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 285 | printf("\n\ttx packets:\t%u", |
859677cb | 286 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
287 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
288 | printf("\n\ttx retries:\t%u", | |
289 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
290 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
291 | printf("\n\ttx failed:\t%u", | |
292 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
293 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
294 | printf("\n\tbeacon loss:\t%u", | |
295 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
296 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
297 | printf("\n\tbeacon rx:\t%llu", | |
298 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
299 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
300 | printf("\n\trx drop misc:\t%llu", | |
301 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
302 | |
303 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 304 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
305 | printf("\n\tsignal: \t%d %sdBm", |
306 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
307 | chain); | |
308 | ||
309 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 310 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
311 | printf("\n\tsignal avg:\t%d %sdBm", |
312 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
313 | chain); | |
314 | ||
568c7057 AE |
315 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
316 | printf("\n\tbeacon signal avg:\t%d dBm", | |
317 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); | |
ea3ade85 | 318 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
319 | printf("\n\tToffset:\t%llu us", |
320 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
321 | |
322 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
323 | char buf[100]; |
324 | ||
e94f0201 | 325 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 326 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
327 | } |
328 | ||
e94f0201 FF |
329 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
330 | char buf[100]; | |
331 | ||
332 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
333 | printf("\n\trx bitrate:\t%s", buf); | |
334 | } | |
335 | ||
cf8a2aab AQ |
336 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
337 | uint32_t thr; | |
338 | ||
339 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
340 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
341 | thr = thr * 1000 / 1024; | |
342 | ||
343 | printf("\n\texpected throughput:\t%u.%uMbps", | |
344 | thr / 1000, thr % 1000); | |
345 | } | |
346 | ||
3d1e8704 | 347 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 348 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
349 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
350 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 351 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
352 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
353 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 354 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
355 | case LISTEN: |
356 | strcpy(state_name, "LISTEN"); | |
357 | break; | |
358 | case OPN_SNT: | |
359 | strcpy(state_name, "OPN_SNT"); | |
360 | break; | |
361 | case OPN_RCVD: | |
362 | strcpy(state_name, "OPN_RCVD"); | |
363 | break; | |
364 | case CNF_RCVD: | |
365 | strcpy(state_name, "CNF_RCVD"); | |
366 | break; | |
367 | case ESTAB: | |
368 | strcpy(state_name, "ESTAB"); | |
369 | break; | |
370 | case HOLDING: | |
371 | strcpy(state_name, "HOLDING"); | |
372 | break; | |
373 | case BLOCKED: | |
374 | strcpy(state_name, "BLOCKED"); | |
375 | break; | |
376 | default: | |
377 | strcpy(state_name, "UNKNOWN"); | |
378 | break; | |
379 | } | |
fbb181fa | 380 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 381 | } |
8012ad28 MP |
382 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
383 | printf("\n\tmesh local PS mode:\t"); | |
384 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
385 | } | |
386 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
387 | printf("\n\tmesh peer PS mode:\t"); | |
388 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
389 | } | |
390 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
391 | printf("\n\tmesh non-peer PS mode:\t"); | |
392 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
393 | } | |
3d1e8704 | 394 | |
b638215d HS |
395 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
396 | sta_flags = (struct nl80211_sta_flag_update *) | |
397 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
398 | ||
399 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
400 | printf("\n\tauthorized:\t"); | |
401 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
402 | printf("yes"); | |
403 | else | |
404 | printf("no"); | |
405 | } | |
406 | ||
407 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
408 | printf("\n\tauthenticated:\t"); | |
409 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
410 | printf("yes"); | |
411 | else | |
412 | printf("no"); | |
413 | } | |
414 | ||
568c7057 AE |
415 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
416 | printf("\n\tassociated:\t"); | |
417 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
418 | printf("yes"); | |
419 | else | |
420 | printf("no"); | |
421 | } | |
422 | ||
b638215d HS |
423 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
424 | printf("\n\tpreamble:\t"); | |
425 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
426 | printf("short"); | |
427 | else | |
428 | printf("long"); | |
429 | } | |
430 | ||
431 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
432 | printf("\n\tWMM/WME:\t"); | |
433 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
434 | printf("yes"); | |
435 | else | |
436 | printf("no"); | |
437 | } | |
438 | ||
439 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
440 | printf("\n\tMFP:\t\t"); | |
441 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
442 | printf("yes"); | |
443 | else | |
444 | printf("no"); | |
445 | } | |
446 | ||
447 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 448 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
449 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
450 | printf("yes"); | |
451 | else | |
452 | printf("no"); | |
453 | } | |
454 | } | |
455 | ||
568c7057 AE |
456 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
457 | !strcmp((char *)arg, "-v")) | |
458 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
459 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
460 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
461 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
462 | printf("\n\tconnected time:\t%u seconds", | |
463 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
464 | ||
3d1e8704 LCC |
465 | printf("\n"); |
466 | return NL_SKIP; | |
467 | } | |
468 | ||
7c37a24d | 469 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 470 | struct nl_msg *msg, |
05514f95 JB |
471 | int argc, char **argv, |
472 | enum id_input id) | |
3d1e8704 | 473 | { |
3d1e8704 LCC |
474 | unsigned char mac_addr[ETH_ALEN]; |
475 | ||
b1ca19a8 | 476 | if (argc < 1) |
5e75fd04 | 477 | return 1; |
3d1e8704 LCC |
478 | |
479 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
480 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 481 | return 2; |
3d1e8704 LCC |
482 | } |
483 | ||
484 | argc--; | |
485 | argv++; | |
486 | ||
b1ca19a8 | 487 | if (argc) |
5e75fd04 | 488 | return 1; |
3d1e8704 LCC |
489 | |
490 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 491 | |
34b23014 | 492 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 493 | |
70391ccf | 494 | return 0; |
3d1e8704 | 495 | nla_put_failure: |
70391ccf | 496 | return -ENOBUFS; |
3d1e8704 | 497 | } |
b1ca19a8 | 498 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
499 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
500 | "Get information for a specific station."); | |
b1ca19a8 | 501 | COMMAND(station, del, "<MAC address>", |
70cf4544 JB |
502 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_get, |
503 | "Remove the given station entry (use with caution!)"); | |
3d1e8704 | 504 | |
1633ddf7 JB |
505 | static const struct cmd *station_set_plink; |
506 | static const struct cmd *station_set_vlan; | |
8012ad28 | 507 | static const struct cmd *station_set_mesh_power_mode; |
1633ddf7 JB |
508 | |
509 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
510 | { | |
511 | if (argc < 2) | |
512 | return NULL; | |
513 | if (strcmp(argv[1], "plink_action") == 0) | |
514 | return station_set_plink; | |
515 | if (strcmp(argv[1], "vlan") == 0) | |
516 | return station_set_vlan; | |
8012ad28 MP |
517 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
518 | return station_set_mesh_power_mode; | |
1633ddf7 JB |
519 | return NULL; |
520 | } | |
521 | ||
ce0fc33a | 522 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 523 | struct nl_msg *msg, |
05514f95 JB |
524 | int argc, char **argv, |
525 | enum id_input id) | |
3d1e8704 | 526 | { |
3d1e8704 LCC |
527 | unsigned char plink_action; |
528 | unsigned char mac_addr[ETH_ALEN]; | |
529 | ||
b1ca19a8 | 530 | if (argc < 3) |
5e75fd04 | 531 | return 1; |
3d1e8704 LCC |
532 | |
533 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
534 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 535 | return 2; |
3d1e8704 LCC |
536 | } |
537 | argc--; | |
538 | argv++; | |
539 | ||
b1ca19a8 JB |
540 | if (strcmp("plink_action", argv[0]) != 0) |
541 | return 1; | |
3d1e8704 LCC |
542 | argc--; |
543 | argv++; | |
544 | ||
545 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 546 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 547 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 548 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
549 | else { |
550 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 551 | return 2; |
3d1e8704 LCC |
552 | } |
553 | argc--; | |
554 | argv++; | |
555 | ||
b1ca19a8 | 556 | if (argc) |
5e75fd04 | 557 | return 1; |
3d1e8704 LCC |
558 | |
559 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
560 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
561 | ||
70391ccf | 562 | return 0; |
3d1e8704 | 563 | nla_put_failure: |
70391ccf | 564 | return -ENOBUFS; |
3d1e8704 | 565 | } |
1633ddf7 | 566 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 567 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
568 | "Set mesh peer link action for this station (peer).", |
569 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 570 | |
ce0fc33a | 571 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
572 | struct nl_msg *msg, |
573 | int argc, char **argv, | |
574 | enum id_input id) | |
ce0fc33a FF |
575 | { |
576 | unsigned char mac_addr[ETH_ALEN]; | |
577 | unsigned long sta_vlan = 0; | |
578 | char *err = NULL; | |
579 | ||
580 | if (argc < 3) | |
581 | return 1; | |
582 | ||
583 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
584 | fprintf(stderr, "invalid mac address\n"); | |
585 | return 2; | |
586 | } | |
587 | argc--; | |
588 | argv++; | |
589 | ||
590 | if (strcmp("vlan", argv[0]) != 0) | |
591 | return 1; | |
592 | argc--; | |
593 | argv++; | |
594 | ||
595 | sta_vlan = strtoul(argv[0], &err, 0); | |
596 | if (err && *err) { | |
597 | fprintf(stderr, "invalid vlan id\n"); | |
598 | return 2; | |
599 | } | |
600 | argc--; | |
601 | argv++; | |
602 | ||
603 | if (argc) | |
604 | return 1; | |
605 | ||
606 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
607 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
608 | ||
609 | return 0; | |
610 | nla_put_failure: | |
611 | return -ENOBUFS; | |
612 | } | |
1633ddf7 | 613 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 614 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
615 | "Set an AP VLAN for this station.", |
616 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 617 | |
8012ad28 | 618 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
619 | struct nl_msg *msg, |
620 | int argc, char **argv, | |
621 | enum id_input id) | |
622 | { | |
623 | unsigned char mesh_power_mode; | |
624 | unsigned char mac_addr[ETH_ALEN]; | |
625 | ||
626 | if (argc < 3) | |
627 | return 1; | |
628 | ||
629 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
630 | fprintf(stderr, "invalid mac address\n"); | |
631 | return 2; | |
632 | } | |
633 | argc--; | |
634 | argv++; | |
635 | ||
636 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
637 | return 1; | |
638 | argc--; | |
639 | argv++; | |
640 | ||
641 | if (strcmp("active", argv[0]) == 0) | |
642 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
643 | else if (strcmp("light", argv[0]) == 0) | |
644 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
645 | else if (strcmp("deep", argv[0]) == 0) | |
646 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
647 | else { | |
648 | fprintf(stderr, "unknown mesh power mode\n"); | |
649 | return 2; | |
650 | } | |
651 | argc--; | |
652 | argv++; | |
653 | ||
654 | if (argc) | |
655 | return 1; | |
656 | ||
657 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
658 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
659 | ||
660 | return 0; | |
661 | nla_put_failure: | |
662 | return -ENOBUFS; | |
663 | } | |
664 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
665 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
666 | handle_station_set_mesh_power_mode, | |
667 | "Set link-specific mesh power mode for this station", | |
668 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 669 | |
7c37a24d | 670 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 671 | struct nl_msg *msg, |
05514f95 JB |
672 | int argc, char **argv, |
673 | enum id_input id) | |
3d1e8704 | 674 | { |
568c7057 | 675 | register_handler(print_sta_handler, *argv); |
70391ccf | 676 | return 0; |
3d1e8704 | 677 | } |
568c7057 | 678 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
679 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
680 | "List all stations known, e.g. the AP on managed interfaces"); |