]>
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 }, | |
045c1c6f | 239 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
3d1e8704 | 240 | }; |
7d23bc2d | 241 | char *chain; |
3d1e8704 LCC |
242 | |
243 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
244 | genlmsg_attrlen(gnlh, 0), NULL); | |
245 | ||
246 | /* | |
247 | * TODO: validate the interface and mac address! | |
248 | * Otherwise, there's a race condition as soon as | |
249 | * the kernel starts sending station notifications. | |
250 | */ | |
251 | ||
252 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 253 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
254 | return NL_SKIP; |
255 | } | |
256 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
257 | tb[NL80211_ATTR_STA_INFO], | |
258 | stats_policy)) { | |
5fe70c0e | 259 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
260 | return NL_SKIP; |
261 | } | |
262 | ||
263 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
264 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 265 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
266 | |
267 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 268 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 269 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
270 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
271 | printf("\n\trx bytes:\t%llu", | |
272 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
273 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 274 | printf("\n\trx bytes:\t%u", |
568c7057 | 275 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 276 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 277 | printf("\n\trx packets:\t%u", |
859677cb | 278 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
279 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
280 | printf("\n\ttx bytes:\t%llu", | |
281 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
282 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 283 | printf("\n\ttx bytes:\t%u", |
568c7057 | 284 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 285 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 286 | printf("\n\ttx packets:\t%u", |
859677cb | 287 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
288 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
289 | printf("\n\ttx retries:\t%u", | |
290 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
291 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
292 | printf("\n\ttx failed:\t%u", | |
293 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
294 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
295 | printf("\n\tbeacon loss:\t%u", | |
296 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
297 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
298 | printf("\n\tbeacon rx:\t%llu", | |
299 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
300 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
301 | printf("\n\trx drop misc:\t%llu", | |
302 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
303 | |
304 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 305 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
306 | printf("\n\tsignal: \t%d %sdBm", |
307 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
308 | chain); | |
309 | ||
310 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 311 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
312 | printf("\n\tsignal avg:\t%d %sdBm", |
313 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
314 | chain); | |
315 | ||
568c7057 AE |
316 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
317 | printf("\n\tbeacon signal avg:\t%d dBm", | |
318 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); | |
ea3ade85 | 319 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
320 | printf("\n\tToffset:\t%llu us", |
321 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
322 | |
323 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
324 | char buf[100]; |
325 | ||
e94f0201 | 326 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 327 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
328 | } |
329 | ||
e94f0201 FF |
330 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
331 | char buf[100]; | |
332 | ||
333 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
334 | printf("\n\trx bitrate:\t%s", buf); | |
335 | } | |
336 | ||
045c1c6f MSS |
337 | if (sinfo[NL80211_STA_INFO_RX_DURATION]) |
338 | printf("\n\trx duration:\t%lld us", | |
339 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION])); | |
340 | ||
cf8a2aab AQ |
341 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
342 | uint32_t thr; | |
343 | ||
344 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
345 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
346 | thr = thr * 1000 / 1024; | |
347 | ||
348 | printf("\n\texpected throughput:\t%u.%uMbps", | |
349 | thr / 1000, thr % 1000); | |
350 | } | |
351 | ||
3d1e8704 | 352 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 353 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
354 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
355 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 356 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
357 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
358 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 359 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
360 | case LISTEN: |
361 | strcpy(state_name, "LISTEN"); | |
362 | break; | |
363 | case OPN_SNT: | |
364 | strcpy(state_name, "OPN_SNT"); | |
365 | break; | |
366 | case OPN_RCVD: | |
367 | strcpy(state_name, "OPN_RCVD"); | |
368 | break; | |
369 | case CNF_RCVD: | |
370 | strcpy(state_name, "CNF_RCVD"); | |
371 | break; | |
372 | case ESTAB: | |
373 | strcpy(state_name, "ESTAB"); | |
374 | break; | |
375 | case HOLDING: | |
376 | strcpy(state_name, "HOLDING"); | |
377 | break; | |
378 | case BLOCKED: | |
379 | strcpy(state_name, "BLOCKED"); | |
380 | break; | |
381 | default: | |
382 | strcpy(state_name, "UNKNOWN"); | |
383 | break; | |
384 | } | |
fbb181fa | 385 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 386 | } |
8012ad28 MP |
387 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
388 | printf("\n\tmesh local PS mode:\t"); | |
389 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
390 | } | |
391 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
392 | printf("\n\tmesh peer PS mode:\t"); | |
393 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
394 | } | |
395 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
396 | printf("\n\tmesh non-peer PS mode:\t"); | |
397 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
398 | } | |
3d1e8704 | 399 | |
b638215d HS |
400 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
401 | sta_flags = (struct nl80211_sta_flag_update *) | |
402 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
403 | ||
404 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
405 | printf("\n\tauthorized:\t"); | |
406 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
407 | printf("yes"); | |
408 | else | |
409 | printf("no"); | |
410 | } | |
411 | ||
412 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
413 | printf("\n\tauthenticated:\t"); | |
414 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
415 | printf("yes"); | |
416 | else | |
417 | printf("no"); | |
418 | } | |
419 | ||
568c7057 AE |
420 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
421 | printf("\n\tassociated:\t"); | |
422 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
423 | printf("yes"); | |
424 | else | |
425 | printf("no"); | |
426 | } | |
427 | ||
b638215d HS |
428 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
429 | printf("\n\tpreamble:\t"); | |
430 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
431 | printf("short"); | |
432 | else | |
433 | printf("long"); | |
434 | } | |
435 | ||
436 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
437 | printf("\n\tWMM/WME:\t"); | |
438 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
439 | printf("yes"); | |
440 | else | |
441 | printf("no"); | |
442 | } | |
443 | ||
444 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
445 | printf("\n\tMFP:\t\t"); | |
446 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
447 | printf("yes"); | |
448 | else | |
449 | printf("no"); | |
450 | } | |
451 | ||
452 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 453 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
454 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
455 | printf("yes"); | |
456 | else | |
457 | printf("no"); | |
458 | } | |
459 | } | |
460 | ||
568c7057 AE |
461 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
462 | !strcmp((char *)arg, "-v")) | |
463 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
464 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
465 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
466 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
467 | printf("\n\tconnected time:\t%u seconds", | |
468 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
469 | ||
3d1e8704 LCC |
470 | printf("\n"); |
471 | return NL_SKIP; | |
472 | } | |
473 | ||
7c37a24d | 474 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 475 | struct nl_msg *msg, |
05514f95 JB |
476 | int argc, char **argv, |
477 | enum id_input id) | |
3d1e8704 | 478 | { |
3d1e8704 LCC |
479 | unsigned char mac_addr[ETH_ALEN]; |
480 | ||
b1ca19a8 | 481 | if (argc < 1) |
5e75fd04 | 482 | return 1; |
3d1e8704 LCC |
483 | |
484 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
485 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 486 | return 2; |
3d1e8704 LCC |
487 | } |
488 | ||
489 | argc--; | |
490 | argv++; | |
491 | ||
b1ca19a8 | 492 | if (argc) |
5e75fd04 | 493 | return 1; |
3d1e8704 LCC |
494 | |
495 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 496 | |
34b23014 | 497 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 498 | |
70391ccf | 499 | return 0; |
3d1e8704 | 500 | nla_put_failure: |
70391ccf | 501 | return -ENOBUFS; |
3d1e8704 | 502 | } |
b1ca19a8 | 503 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
504 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
505 | "Get information for a specific station."); | |
d738686c RM |
506 | |
507 | static int handle_station_del(struct nl80211_state *state, | |
508 | struct nl_msg *msg, | |
509 | int argc, char **argv, | |
510 | enum id_input id) | |
511 | { | |
512 | char *end; | |
513 | unsigned char mac_addr[ETH_ALEN]; | |
514 | int subtype; | |
515 | int reason_code; | |
516 | ||
517 | if (argc < 1) | |
518 | return 1; | |
519 | ||
520 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
521 | fprintf(stderr, "invalid mac address\n"); | |
522 | return 2; | |
523 | } | |
524 | ||
525 | argc--; | |
526 | argv++; | |
527 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
528 | ||
529 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
530 | argv++; | |
531 | argc--; | |
532 | ||
533 | subtype = strtod(argv[0], &end); | |
534 | if (*end != '\0') | |
535 | return 1; | |
536 | ||
537 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
538 | argv++; | |
539 | argc--; | |
540 | } | |
541 | ||
542 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
543 | argv++; | |
544 | argc--; | |
545 | ||
546 | reason_code = strtod(argv[0], &end); | |
547 | if (*end != '\0') | |
548 | return 1; | |
549 | ||
550 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
551 | argv++; | |
552 | argc--; | |
553 | } | |
554 | ||
555 | if (argc) | |
556 | return 1; | |
557 | ||
558 | register_handler(print_sta_handler, NULL); | |
559 | ||
560 | return 0; | |
561 | nla_put_failure: | |
562 | return -ENOBUFS; | |
563 | } | |
564 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
565 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
566 | "Remove the given station entry (use with caution!)\n" | |
567 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 568 | |
1633ddf7 JB |
569 | static const struct cmd *station_set_plink; |
570 | static const struct cmd *station_set_vlan; | |
8012ad28 | 571 | static const struct cmd *station_set_mesh_power_mode; |
1633ddf7 JB |
572 | |
573 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
574 | { | |
575 | if (argc < 2) | |
576 | return NULL; | |
577 | if (strcmp(argv[1], "plink_action") == 0) | |
578 | return station_set_plink; | |
579 | if (strcmp(argv[1], "vlan") == 0) | |
580 | return station_set_vlan; | |
8012ad28 MP |
581 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
582 | return station_set_mesh_power_mode; | |
1633ddf7 JB |
583 | return NULL; |
584 | } | |
585 | ||
ce0fc33a | 586 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 587 | struct nl_msg *msg, |
05514f95 JB |
588 | int argc, char **argv, |
589 | enum id_input id) | |
3d1e8704 | 590 | { |
3d1e8704 LCC |
591 | unsigned char plink_action; |
592 | unsigned char mac_addr[ETH_ALEN]; | |
593 | ||
b1ca19a8 | 594 | if (argc < 3) |
5e75fd04 | 595 | return 1; |
3d1e8704 LCC |
596 | |
597 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
598 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 599 | return 2; |
3d1e8704 LCC |
600 | } |
601 | argc--; | |
602 | argv++; | |
603 | ||
b1ca19a8 JB |
604 | if (strcmp("plink_action", argv[0]) != 0) |
605 | return 1; | |
3d1e8704 LCC |
606 | argc--; |
607 | argv++; | |
608 | ||
609 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 610 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 611 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 612 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
613 | else { |
614 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 615 | return 2; |
3d1e8704 LCC |
616 | } |
617 | argc--; | |
618 | argv++; | |
619 | ||
b1ca19a8 | 620 | if (argc) |
5e75fd04 | 621 | return 1; |
3d1e8704 LCC |
622 | |
623 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
624 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
625 | ||
70391ccf | 626 | return 0; |
3d1e8704 | 627 | nla_put_failure: |
70391ccf | 628 | return -ENOBUFS; |
3d1e8704 | 629 | } |
1633ddf7 | 630 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 631 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
632 | "Set mesh peer link action for this station (peer).", |
633 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 634 | |
ce0fc33a | 635 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
636 | struct nl_msg *msg, |
637 | int argc, char **argv, | |
638 | enum id_input id) | |
ce0fc33a FF |
639 | { |
640 | unsigned char mac_addr[ETH_ALEN]; | |
641 | unsigned long sta_vlan = 0; | |
642 | char *err = NULL; | |
643 | ||
644 | if (argc < 3) | |
645 | return 1; | |
646 | ||
647 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
648 | fprintf(stderr, "invalid mac address\n"); | |
649 | return 2; | |
650 | } | |
651 | argc--; | |
652 | argv++; | |
653 | ||
654 | if (strcmp("vlan", argv[0]) != 0) | |
655 | return 1; | |
656 | argc--; | |
657 | argv++; | |
658 | ||
659 | sta_vlan = strtoul(argv[0], &err, 0); | |
660 | if (err && *err) { | |
661 | fprintf(stderr, "invalid vlan id\n"); | |
662 | return 2; | |
663 | } | |
664 | argc--; | |
665 | argv++; | |
666 | ||
667 | if (argc) | |
668 | return 1; | |
669 | ||
670 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
671 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
672 | ||
673 | return 0; | |
674 | nla_put_failure: | |
675 | return -ENOBUFS; | |
676 | } | |
1633ddf7 | 677 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 678 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
679 | "Set an AP VLAN for this station.", |
680 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 681 | |
8012ad28 | 682 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
683 | struct nl_msg *msg, |
684 | int argc, char **argv, | |
685 | enum id_input id) | |
686 | { | |
687 | unsigned char mesh_power_mode; | |
688 | unsigned char mac_addr[ETH_ALEN]; | |
689 | ||
690 | if (argc < 3) | |
691 | return 1; | |
692 | ||
693 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
694 | fprintf(stderr, "invalid mac address\n"); | |
695 | return 2; | |
696 | } | |
697 | argc--; | |
698 | argv++; | |
699 | ||
700 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
701 | return 1; | |
702 | argc--; | |
703 | argv++; | |
704 | ||
705 | if (strcmp("active", argv[0]) == 0) | |
706 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
707 | else if (strcmp("light", argv[0]) == 0) | |
708 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
709 | else if (strcmp("deep", argv[0]) == 0) | |
710 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
711 | else { | |
712 | fprintf(stderr, "unknown mesh power mode\n"); | |
713 | return 2; | |
714 | } | |
715 | argc--; | |
716 | argv++; | |
717 | ||
718 | if (argc) | |
719 | return 1; | |
720 | ||
721 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
722 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
723 | ||
724 | return 0; | |
725 | nla_put_failure: | |
726 | return -ENOBUFS; | |
727 | } | |
728 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
729 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
730 | handle_station_set_mesh_power_mode, | |
731 | "Set link-specific mesh power mode for this station", | |
732 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 733 | |
7c37a24d | 734 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 735 | struct nl_msg *msg, |
05514f95 JB |
736 | int argc, char **argv, |
737 | enum id_input id) | |
3d1e8704 | 738 | { |
568c7057 | 739 | register_handler(print_sta_handler, *argv); |
70391ccf | 740 | return 0; |
3d1e8704 | 741 | } |
568c7057 | 742 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
743 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
744 | "List all stations known, e.g. the AP on managed interfaces"); |