]>
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> | |
3708f614 | 10 | #include <time.h> |
3d1e8704 | 11 | |
f408e01b | 12 | #include "nl80211.h" |
3d1e8704 LCC |
13 | #include "iw.h" |
14 | ||
4698bfc2 JB |
15 | SECTION(station); |
16 | ||
3d1e8704 LCC |
17 | enum plink_state { |
18 | LISTEN, | |
19 | OPN_SNT, | |
20 | OPN_RCVD, | |
21 | CNF_RCVD, | |
22 | ESTAB, | |
23 | HOLDING, | |
24 | BLOCKED | |
25 | }; | |
26 | ||
8012ad28 MP |
27 | static void print_power_mode(struct nlattr *a) |
28 | { | |
29 | enum nl80211_mesh_power_mode pm = nla_get_u32(a); | |
30 | ||
31 | switch (pm) { | |
32 | case NL80211_MESH_POWER_ACTIVE: | |
33 | printf("ACTIVE"); | |
34 | break; | |
35 | case NL80211_MESH_POWER_LIGHT_SLEEP: | |
36 | printf("LIGHT SLEEP"); | |
37 | break; | |
38 | case NL80211_MESH_POWER_DEEP_SLEEP: | |
39 | printf("DEEP SLEEP"); | |
40 | break; | |
41 | default: | |
42 | printf("UNKNOWN"); | |
43 | break; | |
44 | } | |
45 | } | |
3d1e8704 | 46 | |
910792c0 THJ |
47 | int parse_txq_stats(char *buf, int buflen, struct nlattr *tid_stats_attr, int header, |
48 | int tid, const char *indent) | |
49 | { | |
50 | struct nlattr *txqstats_info[NL80211_TXQ_STATS_MAX + 1], *txqinfo; | |
51 | static struct nla_policy txqstats_policy[NL80211_TXQ_STATS_MAX + 1] = { | |
52 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, | |
53 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, | |
54 | [NL80211_TXQ_STATS_FLOWS] = { .type = NLA_U32 }, | |
55 | [NL80211_TXQ_STATS_DROPS] = { .type = NLA_U32 }, | |
56 | [NL80211_TXQ_STATS_ECN_MARKS] = { .type = NLA_U32 }, | |
57 | [NL80211_TXQ_STATS_OVERLIMIT] = { .type = NLA_U32 }, | |
58 | [NL80211_TXQ_STATS_COLLISIONS] = { .type = NLA_U32 }, | |
59 | [NL80211_TXQ_STATS_TX_BYTES] = { .type = NLA_U32 }, | |
60 | [NL80211_TXQ_STATS_TX_PACKETS] = { .type = NLA_U32 }, | |
61 | }; | |
62 | char *pos = buf; | |
63 | if (nla_parse_nested(txqstats_info, NL80211_TXQ_STATS_MAX, tid_stats_attr, | |
64 | txqstats_policy)) { | |
65 | printf("failed to parse nested TXQ stats attributes!"); | |
66 | return 0; | |
67 | } | |
68 | ||
69 | if (header) | |
70 | pos += snprintf(buf, buflen, "\n%s\t%s\tqsz-byt\t" | |
71 | "qsz-pkt\tflows\tdrops\tmarks\toverlmt\t" | |
72 | "hashcol\ttx-bytes\ttx-packets", indent, | |
73 | tid >= 0 ? "TID" : ""); | |
74 | ||
75 | pos += snprintf(pos, buflen - (pos - buf), "\n%s\t", indent); | |
76 | if (tid >= 0) | |
77 | pos += snprintf(pos, buflen - (pos - buf), "%d", tid); | |
78 | ||
79 | #define PRINT_STAT(key, spacer) do { \ | |
80 | txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \ | |
81 | pos += snprintf(pos, buflen - (pos - buf), spacer); \ | |
82 | if (txqinfo) \ | |
83 | pos += snprintf(pos, buflen - (pos - buf), "%u", \ | |
84 | nla_get_u32(txqinfo)); \ | |
85 | } while (0) | |
86 | ||
87 | ||
88 | PRINT_STAT(BACKLOG_BYTES, "\t"); | |
89 | PRINT_STAT(BACKLOG_PACKETS, "\t"); | |
90 | PRINT_STAT(FLOWS, "\t"); | |
91 | PRINT_STAT(DROPS, "\t"); | |
92 | PRINT_STAT(ECN_MARKS, "\t"); | |
93 | PRINT_STAT(OVERLIMIT, "\t"); | |
94 | PRINT_STAT(COLLISIONS, "\t"); | |
95 | PRINT_STAT(TX_BYTES, "\t"); | |
96 | PRINT_STAT(TX_PACKETS, "\t\t"); | |
97 | ||
98 | #undef PRINT_STAT | |
99 | ||
100 | return pos - buf; | |
101 | ||
102 | } | |
bcdceae1 JB |
103 | |
104 | static void parse_tid_stats(struct nlattr *tid_stats_attr) | |
568c7057 AE |
105 | { |
106 | struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1], *tidattr, *info; | |
107 | static struct nla_policy stats_policy[NL80211_TID_STATS_MAX + 1] = { | |
108 | [NL80211_TID_STATS_RX_MSDU] = { .type = NLA_U64 }, | |
109 | [NL80211_TID_STATS_TX_MSDU] = { .type = NLA_U64 }, | |
110 | [NL80211_TID_STATS_TX_MSDU_RETRIES] = { .type = NLA_U64 }, | |
111 | [NL80211_TID_STATS_TX_MSDU_FAILED] = { .type = NLA_U64 }, | |
910792c0 | 112 | [NL80211_TID_STATS_TXQ_STATS] = { .type = NLA_NESTED }, |
568c7057 AE |
113 | }; |
114 | int rem, i = 0; | |
910792c0 THJ |
115 | char txqbuf[2000] = {}, *pos = txqbuf; |
116 | int buflen = sizeof(txqbuf), foundtxq = 0; | |
568c7057 AE |
117 | |
118 | printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed"); | |
119 | nla_for_each_nested(tidattr, tid_stats_attr, rem) { | |
120 | if (nla_parse_nested(stats_info, NL80211_TID_STATS_MAX, | |
121 | tidattr, stats_policy)) { | |
122 | printf("failed to parse nested stats attributes!"); | |
123 | return; | |
124 | } | |
910792c0 | 125 | printf("\n\t\t%d", i); |
568c7057 AE |
126 | info = stats_info[NL80211_TID_STATS_RX_MSDU]; |
127 | if (info) | |
128 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
129 | info = stats_info[NL80211_TID_STATS_TX_MSDU]; | |
130 | if (info) | |
131 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
132 | info = stats_info[NL80211_TID_STATS_TX_MSDU_RETRIES]; | |
133 | if (info) | |
134 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
135 | info = stats_info[NL80211_TID_STATS_TX_MSDU_FAILED]; | |
136 | if (info) | |
137 | printf("\t\t%llu", (unsigned long long)nla_get_u64(info)); | |
910792c0 THJ |
138 | info = stats_info[NL80211_TID_STATS_TXQ_STATS]; |
139 | if (info) { | |
140 | pos += parse_txq_stats(pos, buflen - (pos - txqbuf), info, !foundtxq, i, "\t"); | |
141 | foundtxq = 1; | |
142 | } | |
143 | ||
144 | i++; | |
568c7057 | 145 | } |
910792c0 THJ |
146 | |
147 | if (foundtxq) | |
148 | printf("\n\tTXQs:%s", txqbuf); | |
568c7057 AE |
149 | } |
150 | ||
bcdceae1 | 151 | static void parse_bss_param(struct nlattr *bss_param_attr) |
568c7057 AE |
152 | { |
153 | struct nlattr *bss_param_info[NL80211_STA_BSS_PARAM_MAX + 1], *info; | |
154 | static struct nla_policy bss_poilcy[NL80211_STA_BSS_PARAM_MAX + 1] = { | |
155 | [NL80211_STA_BSS_PARAM_CTS_PROT] = { .type = NLA_FLAG }, | |
156 | [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
157 | [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME] = { .type = NLA_FLAG }, | |
158 | [NL80211_STA_BSS_PARAM_DTIM_PERIOD] = { .type = NLA_U8 }, | |
159 | [NL80211_STA_BSS_PARAM_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
160 | }; | |
161 | ||
162 | if (nla_parse_nested(bss_param_info, NL80211_STA_BSS_PARAM_MAX, | |
163 | bss_param_attr, bss_poilcy)) { | |
164 | printf("failed to parse nested bss param attributes!"); | |
165 | } | |
166 | ||
167 | info = bss_param_info[NL80211_STA_BSS_PARAM_DTIM_PERIOD]; | |
168 | if (info) | |
169 | printf("\n\tDTIM period:\t%u", nla_get_u8(info)); | |
170 | info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]; | |
171 | if (info) | |
172 | printf("\n\tbeacon interval:%u", nla_get_u16(info)); | |
173 | info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT]; | |
174 | if (info) { | |
175 | printf("\n\tCTS protection:"); | |
176 | if (nla_get_u16(info)) | |
177 | printf("\tyes"); | |
178 | else | |
179 | printf("\tno"); | |
180 | } | |
181 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE]; | |
182 | if (info) { | |
183 | printf("\n\tshort preamble:"); | |
184 | if (nla_get_u16(info)) | |
185 | printf("\tyes"); | |
186 | else | |
187 | printf("\tno"); | |
188 | } | |
189 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME]; | |
190 | if (info) { | |
191 | printf("\n\tshort slot time:"); | |
192 | if (nla_get_u16(info)) | |
193 | printf("yes"); | |
194 | else | |
195 | printf("no"); | |
196 | } | |
197 | } | |
198 | ||
e94f0201 | 199 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) |
64179590 JB |
200 | { |
201 | int rate = 0; | |
202 | char *pos = buf; | |
203 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; | |
204 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
205 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
206 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
207 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
208 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
209 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
210 | }; | |
211 | ||
212 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
213 | bitrate_attr, rate_policy)) { | |
214 | snprintf(buf, buflen, "failed to parse nested rate attributes!"); | |
215 | return; | |
216 | } | |
217 | ||
218 | if (rinfo[NL80211_RATE_INFO_BITRATE32]) | |
219 | rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]); | |
220 | else if (rinfo[NL80211_RATE_INFO_BITRATE]) | |
221 | rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]); | |
222 | if (rate > 0) | |
223 | pos += snprintf(pos, buflen - (pos - buf), | |
224 | "%d.%d MBit/s", rate / 10, rate % 10); | |
5ce1f6c7 MH |
225 | else |
226 | pos += snprintf(pos, buflen - (pos - buf), "(unknown)"); | |
64179590 JB |
227 | |
228 | if (rinfo[NL80211_RATE_INFO_MCS]) | |
229 | pos += snprintf(pos, buflen - (pos - buf), | |
230 | " MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS])); | |
231 | if (rinfo[NL80211_RATE_INFO_VHT_MCS]) | |
232 | pos += snprintf(pos, buflen - (pos - buf), | |
233 | " VHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_MCS])); | |
234 | if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH]) | |
235 | pos += snprintf(pos, buflen - (pos - buf), " 40MHz"); | |
236 | if (rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH]) | |
237 | pos += snprintf(pos, buflen - (pos - buf), " 80MHz"); | |
238 | if (rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH]) | |
239 | pos += snprintf(pos, buflen - (pos - buf), " 80P80MHz"); | |
240 | if (rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH]) | |
241 | pos += snprintf(pos, buflen - (pos - buf), " 160MHz"); | |
242 | if (rinfo[NL80211_RATE_INFO_SHORT_GI]) | |
243 | pos += snprintf(pos, buflen - (pos - buf), " short GI"); | |
244 | if (rinfo[NL80211_RATE_INFO_VHT_NSS]) | |
245 | pos += snprintf(pos, buflen - (pos - buf), | |
246 | " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS])); | |
848d97d9 JC |
247 | if (rinfo[NL80211_RATE_INFO_HE_MCS]) |
248 | pos += snprintf(pos, buflen - (pos - buf), | |
249 | " HE-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_MCS])); | |
250 | if (rinfo[NL80211_RATE_INFO_HE_NSS]) | |
251 | pos += snprintf(pos, buflen - (pos - buf), | |
252 | " HE-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_NSS])); | |
253 | if (rinfo[NL80211_RATE_INFO_HE_GI]) | |
254 | pos += snprintf(pos, buflen - (pos - buf), | |
255 | " HE-GI %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_GI])); | |
256 | if (rinfo[NL80211_RATE_INFO_HE_DCM]) | |
257 | pos += snprintf(pos, buflen - (pos - buf), | |
258 | " HE-DCM %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_DCM])); | |
97dd4dad JC |
259 | if (rinfo[NL80211_RATE_INFO_HE_RU_ALLOC]) |
260 | pos += snprintf(pos, buflen - (pos - buf), | |
261 | " HE-RU-ALLOC %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_RU_ALLOC])); | |
64179590 JB |
262 | } |
263 | ||
7d23bc2d FF |
264 | static char *get_chain_signal(struct nlattr *attr_list) |
265 | { | |
266 | struct nlattr *attr; | |
267 | static char buf[64]; | |
268 | char *cur = buf; | |
269 | int i = 0, rem; | |
270 | const char *prefix; | |
271 | ||
272 | if (!attr_list) | |
273 | return ""; | |
274 | ||
275 | nla_for_each_nested(attr, attr_list, rem) { | |
276 | if (i++ > 0) | |
277 | prefix = ", "; | |
278 | else | |
279 | prefix = "["; | |
280 | ||
281 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
282 | (int8_t) nla_get_u8(attr)); | |
283 | } | |
284 | ||
285 | if (i) | |
286 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
287 | ||
288 | return buf; | |
289 | } | |
290 | ||
3d1e8704 LCC |
291 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
292 | { | |
293 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
294 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
295 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
296 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 297 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
298 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
299 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
300 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
301 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
302 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
303 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
304 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
305 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 306 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 307 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 308 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 309 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 310 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
311 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
312 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
313 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
314 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
315 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
316 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
317 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
318 | [NL80211_STA_INFO_STA_FLAGS] = |
319 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
320 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
321 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
322 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
323 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
324 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
325 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
326 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
045c1c6f | 327 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
a85d693f | 328 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
d2272671 BP |
329 | [NL80211_STA_INFO_ACK_SIGNAL] = {.type = NLA_U8 }, |
330 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 }, | |
700f7d95 | 331 | [NL80211_STA_INFO_AIRTIME_LINK_METRIC] = { .type = NLA_U32 }, |
0ba98b90 MT |
332 | [NL80211_STA_INFO_CONNECTED_TO_AS] = { .type = NLA_U8 }, |
333 | [NL80211_STA_INFO_CONNECTED_TO_GATE] = { .type = NLA_U8 }, | |
3d1e8704 | 334 | }; |
7d23bc2d | 335 | char *chain; |
3708f614 BG |
336 | struct timeval now; |
337 | unsigned long long now_ms; | |
338 | ||
339 | gettimeofday(&now, NULL); | |
5d9d1b86 | 340 | now_ms = now.tv_sec * 1000ULL; |
3708f614 | 341 | now_ms += (now.tv_usec / 1000); |
3d1e8704 LCC |
342 | |
343 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
344 | genlmsg_attrlen(gnlh, 0), NULL); | |
345 | ||
346 | /* | |
347 | * TODO: validate the interface and mac address! | |
348 | * Otherwise, there's a race condition as soon as | |
349 | * the kernel starts sending station notifications. | |
350 | */ | |
351 | ||
352 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 353 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
354 | return NL_SKIP; |
355 | } | |
356 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
357 | tb[NL80211_ATTR_STA_INFO], | |
358 | stats_policy)) { | |
5fe70c0e | 359 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
360 | return NL_SKIP; |
361 | } | |
362 | ||
363 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
364 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 365 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
366 | |
367 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 368 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 369 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
370 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
371 | printf("\n\trx bytes:\t%llu", | |
372 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
373 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 374 | printf("\n\trx bytes:\t%u", |
568c7057 | 375 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 376 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 377 | printf("\n\trx packets:\t%u", |
859677cb | 378 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
379 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
380 | printf("\n\ttx bytes:\t%llu", | |
381 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
382 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 383 | printf("\n\ttx bytes:\t%u", |
568c7057 | 384 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 385 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 386 | printf("\n\ttx packets:\t%u", |
859677cb | 387 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
388 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
389 | printf("\n\ttx retries:\t%u", | |
390 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
391 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
392 | printf("\n\ttx failed:\t%u", | |
393 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
394 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
395 | printf("\n\tbeacon loss:\t%u", | |
396 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
397 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
398 | printf("\n\tbeacon rx:\t%llu", | |
399 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
400 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
401 | printf("\n\trx drop misc:\t%llu", | |
402 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
403 | |
404 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 405 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
406 | printf("\n\tsignal: \t%d %sdBm", |
407 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
408 | chain); | |
409 | ||
410 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 411 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
412 | printf("\n\tsignal avg:\t%d %sdBm", |
413 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
414 | chain); | |
415 | ||
568c7057 AE |
416 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
417 | printf("\n\tbeacon signal avg:\t%d dBm", | |
0fc92835 | 418 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); |
ea3ade85 | 419 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
420 | printf("\n\tToffset:\t%llu us", |
421 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
422 | |
423 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
424 | char buf[100]; |
425 | ||
e94f0201 | 426 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 427 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
428 | } |
429 | ||
a85d693f THJ |
430 | if (sinfo[NL80211_STA_INFO_TX_DURATION]) |
431 | printf("\n\ttx duration:\t%lld us", | |
432 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_DURATION])); | |
433 | ||
e94f0201 FF |
434 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
435 | char buf[100]; | |
436 | ||
437 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
438 | printf("\n\trx bitrate:\t%s", buf); | |
439 | } | |
440 | ||
045c1c6f MSS |
441 | if (sinfo[NL80211_STA_INFO_RX_DURATION]) |
442 | printf("\n\trx duration:\t%lld us", | |
443 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION])); | |
444 | ||
d2272671 BP |
445 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL]) |
446 | printf("\n\tlast ack signal:%d dBm", | |
447 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL])); | |
448 | ||
449 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG]) | |
450 | printf("\n\tavg ack signal:\t%d dBm", | |
451 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG])); | |
452 | ||
a85d693f THJ |
453 | if (sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT]) { |
454 | printf("\n\tairtime weight: %d", nla_get_u16(sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT])); | |
455 | } | |
456 | ||
cf8a2aab AQ |
457 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
458 | uint32_t thr; | |
459 | ||
460 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
461 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
462 | thr = thr * 1000 / 1024; | |
463 | ||
464 | printf("\n\texpected throughput:\t%u.%uMbps", | |
465 | thr / 1000, thr % 1000); | |
466 | } | |
467 | ||
3d1e8704 | 468 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 469 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
470 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
471 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 472 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
473 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
474 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 475 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
476 | case LISTEN: |
477 | strcpy(state_name, "LISTEN"); | |
478 | break; | |
479 | case OPN_SNT: | |
480 | strcpy(state_name, "OPN_SNT"); | |
481 | break; | |
482 | case OPN_RCVD: | |
483 | strcpy(state_name, "OPN_RCVD"); | |
484 | break; | |
485 | case CNF_RCVD: | |
486 | strcpy(state_name, "CNF_RCVD"); | |
487 | break; | |
488 | case ESTAB: | |
489 | strcpy(state_name, "ESTAB"); | |
490 | break; | |
491 | case HOLDING: | |
492 | strcpy(state_name, "HOLDING"); | |
493 | break; | |
494 | case BLOCKED: | |
495 | strcpy(state_name, "BLOCKED"); | |
496 | break; | |
497 | default: | |
498 | strcpy(state_name, "UNKNOWN"); | |
499 | break; | |
500 | } | |
fbb181fa | 501 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 502 | } |
700f7d95 MT |
503 | if (sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC]) |
504 | printf("\n\tmesh airtime link metric: %d", | |
505 | nla_get_u32(sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC])); | |
506 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) | |
507 | printf("\n\tmesh connected to gate:\t%s", | |
508 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) ? | |
509 | "yes" : "no"); | |
510 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) | |
511 | printf("\n\tmesh connected to auth server:\t%s", | |
512 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) ? | |
513 | "yes" : "no"); | |
514 | ||
8012ad28 MP |
515 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
516 | printf("\n\tmesh local PS mode:\t"); | |
517 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
518 | } | |
519 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
520 | printf("\n\tmesh peer PS mode:\t"); | |
521 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
522 | } | |
523 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
524 | printf("\n\tmesh non-peer PS mode:\t"); | |
525 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
526 | } | |
3d1e8704 | 527 | |
b638215d HS |
528 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
529 | sta_flags = (struct nl80211_sta_flag_update *) | |
530 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
531 | ||
532 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
533 | printf("\n\tauthorized:\t"); | |
534 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
535 | printf("yes"); | |
536 | else | |
537 | printf("no"); | |
538 | } | |
539 | ||
540 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
541 | printf("\n\tauthenticated:\t"); | |
542 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
543 | printf("yes"); | |
544 | else | |
545 | printf("no"); | |
546 | } | |
547 | ||
568c7057 AE |
548 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
549 | printf("\n\tassociated:\t"); | |
550 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
551 | printf("yes"); | |
552 | else | |
553 | printf("no"); | |
554 | } | |
555 | ||
b638215d HS |
556 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
557 | printf("\n\tpreamble:\t"); | |
558 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
559 | printf("short"); | |
560 | else | |
561 | printf("long"); | |
562 | } | |
563 | ||
564 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
565 | printf("\n\tWMM/WME:\t"); | |
566 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
567 | printf("yes"); | |
568 | else | |
569 | printf("no"); | |
570 | } | |
571 | ||
572 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
573 | printf("\n\tMFP:\t\t"); | |
574 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
575 | printf("yes"); | |
576 | else | |
577 | printf("no"); | |
578 | } | |
579 | ||
580 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 581 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
582 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
583 | printf("yes"); | |
584 | else | |
585 | printf("no"); | |
586 | } | |
587 | } | |
588 | ||
568c7057 AE |
589 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
590 | !strcmp((char *)arg, "-v")) | |
591 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
592 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
593 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
594 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
595 | printf("\n\tconnected time:\t%u seconds", | |
596 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
0b39c408 BG |
597 | if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) { |
598 | unsigned long long bt; | |
3708f614 BG |
599 | struct timespec now_ts; |
600 | unsigned long long boot_ns; | |
601 | unsigned long long assoc_at_ms; | |
602 | ||
603 | clock_gettime(CLOCK_BOOTTIME, &now_ts); | |
5d9d1b86 | 604 | boot_ns = now_ts.tv_sec * 1000000000ULL; |
3708f614 BG |
605 | boot_ns += now_ts.tv_nsec; |
606 | ||
0b39c408 | 607 | bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]); |
3708f614 | 608 | printf("\n\tassociated at [boottime]:\t%llu.%.3llus", |
0b39c408 | 609 | bt/1000000000, (bt%1000000000)/1000000); |
3708f614 BG |
610 | assoc_at_ms = now_ms - ((boot_ns - bt) / 1000000); |
611 | printf("\n\tassociated at:\t%llu ms", assoc_at_ms); | |
0b39c408 | 612 | } |
087d778f | 613 | |
3708f614 | 614 | printf("\n\tcurrent time:\t%llu ms\n", now_ms); |
3d1e8704 LCC |
615 | return NL_SKIP; |
616 | } | |
617 | ||
7c37a24d | 618 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 619 | struct nl_msg *msg, |
05514f95 JB |
620 | int argc, char **argv, |
621 | enum id_input id) | |
3d1e8704 | 622 | { |
3d1e8704 LCC |
623 | unsigned char mac_addr[ETH_ALEN]; |
624 | ||
b1ca19a8 | 625 | if (argc < 1) |
5e75fd04 | 626 | return 1; |
3d1e8704 LCC |
627 | |
628 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
629 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 630 | return 2; |
3d1e8704 LCC |
631 | } |
632 | ||
633 | argc--; | |
634 | argv++; | |
635 | ||
b1ca19a8 | 636 | if (argc) |
5e75fd04 | 637 | return 1; |
3d1e8704 LCC |
638 | |
639 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 640 | |
34b23014 | 641 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 642 | |
70391ccf | 643 | return 0; |
3d1e8704 | 644 | nla_put_failure: |
70391ccf | 645 | return -ENOBUFS; |
3d1e8704 | 646 | } |
b1ca19a8 | 647 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
648 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
649 | "Get information for a specific station."); | |
d738686c RM |
650 | |
651 | static int handle_station_del(struct nl80211_state *state, | |
652 | struct nl_msg *msg, | |
653 | int argc, char **argv, | |
654 | enum id_input id) | |
655 | { | |
656 | char *end; | |
657 | unsigned char mac_addr[ETH_ALEN]; | |
658 | int subtype; | |
659 | int reason_code; | |
660 | ||
661 | if (argc < 1) | |
662 | return 1; | |
663 | ||
664 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
665 | fprintf(stderr, "invalid mac address\n"); | |
666 | return 2; | |
667 | } | |
668 | ||
669 | argc--; | |
670 | argv++; | |
671 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
672 | ||
673 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
674 | argv++; | |
675 | argc--; | |
676 | ||
677 | subtype = strtod(argv[0], &end); | |
678 | if (*end != '\0') | |
679 | return 1; | |
680 | ||
681 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
682 | argv++; | |
683 | argc--; | |
684 | } | |
685 | ||
686 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
687 | argv++; | |
688 | argc--; | |
689 | ||
690 | reason_code = strtod(argv[0], &end); | |
691 | if (*end != '\0') | |
692 | return 1; | |
693 | ||
694 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
695 | argv++; | |
696 | argc--; | |
697 | } | |
698 | ||
699 | if (argc) | |
700 | return 1; | |
701 | ||
702 | register_handler(print_sta_handler, NULL); | |
703 | ||
704 | return 0; | |
705 | nla_put_failure: | |
706 | return -ENOBUFS; | |
707 | } | |
708 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
709 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
710 | "Remove the given station entry (use with caution!)\n" | |
711 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 712 | |
1633ddf7 JB |
713 | static const struct cmd *station_set_plink; |
714 | static const struct cmd *station_set_vlan; | |
8012ad28 | 715 | static const struct cmd *station_set_mesh_power_mode; |
82903243 | 716 | static const struct cmd *station_set_airtime_weight; |
5bdf11e3 | 717 | static const struct cmd *station_set_txpwr; |
1633ddf7 JB |
718 | |
719 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
720 | { | |
721 | if (argc < 2) | |
722 | return NULL; | |
723 | if (strcmp(argv[1], "plink_action") == 0) | |
724 | return station_set_plink; | |
725 | if (strcmp(argv[1], "vlan") == 0) | |
726 | return station_set_vlan; | |
8012ad28 MP |
727 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
728 | return station_set_mesh_power_mode; | |
82903243 THJ |
729 | if (strcmp(argv[1], "airtime_weight") == 0) |
730 | return station_set_airtime_weight; | |
5bdf11e3 ARN |
731 | if (strcmp(argv[1], "txpwr") == 0) |
732 | return station_set_txpwr; | |
1633ddf7 JB |
733 | return NULL; |
734 | } | |
735 | ||
ce0fc33a | 736 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 737 | struct nl_msg *msg, |
05514f95 JB |
738 | int argc, char **argv, |
739 | enum id_input id) | |
3d1e8704 | 740 | { |
3d1e8704 LCC |
741 | unsigned char plink_action; |
742 | unsigned char mac_addr[ETH_ALEN]; | |
743 | ||
b1ca19a8 | 744 | if (argc < 3) |
5e75fd04 | 745 | return 1; |
3d1e8704 LCC |
746 | |
747 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
748 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 749 | return 2; |
3d1e8704 LCC |
750 | } |
751 | argc--; | |
752 | argv++; | |
753 | ||
b1ca19a8 JB |
754 | if (strcmp("plink_action", argv[0]) != 0) |
755 | return 1; | |
3d1e8704 LCC |
756 | argc--; |
757 | argv++; | |
758 | ||
759 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 760 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 761 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 762 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
763 | else { |
764 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 765 | return 2; |
3d1e8704 LCC |
766 | } |
767 | argc--; | |
768 | argv++; | |
769 | ||
b1ca19a8 | 770 | if (argc) |
5e75fd04 | 771 | return 1; |
3d1e8704 LCC |
772 | |
773 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
774 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
775 | ||
70391ccf | 776 | return 0; |
3d1e8704 | 777 | nla_put_failure: |
70391ccf | 778 | return -ENOBUFS; |
3d1e8704 | 779 | } |
1633ddf7 | 780 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 781 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
782 | "Set mesh peer link action for this station (peer).", |
783 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 784 | |
ce0fc33a | 785 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
786 | struct nl_msg *msg, |
787 | int argc, char **argv, | |
788 | enum id_input id) | |
ce0fc33a FF |
789 | { |
790 | unsigned char mac_addr[ETH_ALEN]; | |
791 | unsigned long sta_vlan = 0; | |
792 | char *err = NULL; | |
793 | ||
794 | if (argc < 3) | |
795 | return 1; | |
796 | ||
797 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
798 | fprintf(stderr, "invalid mac address\n"); | |
799 | return 2; | |
800 | } | |
801 | argc--; | |
802 | argv++; | |
803 | ||
804 | if (strcmp("vlan", argv[0]) != 0) | |
805 | return 1; | |
806 | argc--; | |
807 | argv++; | |
808 | ||
809 | sta_vlan = strtoul(argv[0], &err, 0); | |
810 | if (err && *err) { | |
811 | fprintf(stderr, "invalid vlan id\n"); | |
812 | return 2; | |
813 | } | |
814 | argc--; | |
815 | argv++; | |
816 | ||
817 | if (argc) | |
818 | return 1; | |
819 | ||
820 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
821 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
822 | ||
823 | return 0; | |
824 | nla_put_failure: | |
825 | return -ENOBUFS; | |
826 | } | |
1633ddf7 | 827 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 828 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
829 | "Set an AP VLAN for this station.", |
830 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 831 | |
8012ad28 | 832 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
833 | struct nl_msg *msg, |
834 | int argc, char **argv, | |
835 | enum id_input id) | |
836 | { | |
837 | unsigned char mesh_power_mode; | |
838 | unsigned char mac_addr[ETH_ALEN]; | |
839 | ||
840 | if (argc < 3) | |
841 | return 1; | |
842 | ||
843 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
844 | fprintf(stderr, "invalid mac address\n"); | |
845 | return 2; | |
846 | } | |
847 | argc--; | |
848 | argv++; | |
849 | ||
850 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
851 | return 1; | |
852 | argc--; | |
853 | argv++; | |
854 | ||
855 | if (strcmp("active", argv[0]) == 0) | |
856 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
857 | else if (strcmp("light", argv[0]) == 0) | |
858 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
859 | else if (strcmp("deep", argv[0]) == 0) | |
860 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
861 | else { | |
862 | fprintf(stderr, "unknown mesh power mode\n"); | |
863 | return 2; | |
864 | } | |
865 | argc--; | |
866 | argv++; | |
867 | ||
868 | if (argc) | |
869 | return 1; | |
870 | ||
871 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
872 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
873 | ||
874 | return 0; | |
875 | nla_put_failure: | |
876 | return -ENOBUFS; | |
877 | } | |
878 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
879 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
880 | handle_station_set_mesh_power_mode, | |
881 | "Set link-specific mesh power mode for this station", | |
882 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 883 | |
82903243 THJ |
884 | static int handle_station_set_airtime_weight(struct nl80211_state *state, |
885 | struct nl_msg *msg, | |
886 | int argc, char **argv, | |
887 | enum id_input id) | |
888 | { | |
889 | unsigned char mac_addr[ETH_ALEN]; | |
890 | unsigned long airtime_weight = 0; | |
891 | char *err = NULL; | |
892 | ||
893 | if (argc < 3) | |
894 | return 1; | |
895 | ||
896 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
897 | fprintf(stderr, "invalid mac address\n"); | |
898 | return 2; | |
899 | } | |
900 | argc--; | |
901 | argv++; | |
902 | ||
903 | if (strcmp("airtime_weight", argv[0]) != 0) | |
904 | return 1; | |
905 | argc--; | |
906 | argv++; | |
907 | ||
908 | airtime_weight = strtoul(argv[0], &err, 0); | |
909 | if (err && *err) { | |
910 | fprintf(stderr, "invalid airtime weight\n"); | |
911 | return 2; | |
912 | } | |
913 | argc--; | |
914 | argv++; | |
915 | ||
916 | if (argc) | |
917 | return 1; | |
918 | ||
919 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
920 | NLA_PUT_U16(msg, NL80211_ATTR_AIRTIME_WEIGHT, airtime_weight); | |
921 | ||
922 | return 0; | |
923 | nla_put_failure: | |
924 | return -ENOBUFS; | |
925 | ||
926 | } | |
927 | COMMAND_ALIAS(station, set, "<MAC address> airtime_weight <weight>", | |
928 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_airtime_weight, | |
929 | "Set airtime weight for this station.", | |
930 | select_station_cmd, station_set_airtime_weight); | |
931 | ||
5bdf11e3 ARN |
932 | static int handle_station_set_txpwr(struct nl80211_state *state, |
933 | struct nl_msg *msg, | |
934 | int argc, char **argv, | |
935 | enum id_input id) | |
936 | { | |
937 | enum nl80211_tx_power_setting type; | |
938 | unsigned char mac_addr[ETH_ALEN]; | |
939 | int sta_txpwr = 0; | |
940 | char *err = NULL; | |
941 | ||
942 | if (argc != 3 && argc != 4) | |
943 | return 1; | |
944 | ||
945 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
946 | fprintf(stderr, "invalid mac address\n"); | |
947 | return 2; | |
948 | } | |
949 | ||
950 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
951 | argc--; | |
952 | argv++; | |
953 | ||
954 | if (strcmp("txpwr", argv[0]) != 0) | |
955 | return 1; | |
956 | argc--; | |
957 | argv++; | |
958 | ||
959 | if (!strcmp(argv[0], "auto")) | |
960 | type = NL80211_TX_POWER_AUTOMATIC; | |
961 | else if (!strcmp(argv[0], "limit")) | |
962 | type = NL80211_TX_POWER_LIMITED; | |
963 | else { | |
964 | printf("Invalid parameter: %s\n", argv[0]); | |
965 | return 2; | |
966 | } | |
967 | ||
968 | NLA_PUT_U8(msg, NL80211_ATTR_STA_TX_POWER_SETTING, type); | |
969 | ||
970 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
971 | if (argc != 2) { | |
972 | printf("Missing TX power level argument.\n"); | |
973 | return 2; | |
974 | } | |
975 | ||
976 | argc--; | |
977 | argv++; | |
978 | ||
979 | sta_txpwr = strtoul(argv[0], &err, 0); | |
980 | NLA_PUT_U16(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); | |
981 | } | |
982 | ||
983 | argc--; | |
984 | argv++; | |
985 | ||
986 | if (argc) | |
987 | return 1; | |
988 | ||
989 | return 0; | |
990 | nla_put_failure: | |
991 | return -ENOBUFS; | |
992 | } | |
993 | COMMAND_ALIAS(station, set, "<MAC address> txpwr <auto|limit> [<tx power dBm>]", | |
994 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, | |
995 | "Set Tx power for this station.", | |
996 | select_station_cmd, station_set_txpwr); | |
997 | ||
7c37a24d | 998 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 999 | struct nl_msg *msg, |
05514f95 JB |
1000 | int argc, char **argv, |
1001 | enum id_input id) | |
3d1e8704 | 1002 | { |
568c7057 | 1003 | register_handler(print_sta_handler, *argv); |
70391ccf | 1004 | return 0; |
3d1e8704 | 1005 | } |
568c7057 | 1006 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
1007 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
1008 | "List all stations known, e.g. the AP on managed interfaces"); |