]>
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"); | |
e3287a1f JB |
242 | if (rinfo[NL80211_RATE_INFO_320_MHZ_WIDTH]) |
243 | pos += snprintf(pos, buflen - (pos - buf), " 320MHz"); | |
e2224c72 BD |
244 | if (rinfo[NL80211_RATE_INFO_1_MHZ_WIDTH]) |
245 | pos += snprintf(pos, buflen - (pos - buf), " 1MHz"); | |
246 | if (rinfo[NL80211_RATE_INFO_2_MHZ_WIDTH]) | |
247 | pos += snprintf(pos, buflen - (pos - buf), " 2MHz"); | |
248 | if (rinfo[NL80211_RATE_INFO_4_MHZ_WIDTH]) | |
249 | pos += snprintf(pos, buflen - (pos - buf), " 4MHz"); | |
250 | if (rinfo[NL80211_RATE_INFO_8_MHZ_WIDTH]) | |
251 | pos += snprintf(pos, buflen - (pos - buf), " 8MHz"); | |
252 | if (rinfo[NL80211_RATE_INFO_16_MHZ_WIDTH]) | |
253 | pos += snprintf(pos, buflen - (pos - buf), " 16MHz"); | |
64179590 JB |
254 | if (rinfo[NL80211_RATE_INFO_SHORT_GI]) |
255 | pos += snprintf(pos, buflen - (pos - buf), " short GI"); | |
256 | if (rinfo[NL80211_RATE_INFO_VHT_NSS]) | |
257 | pos += snprintf(pos, buflen - (pos - buf), | |
258 | " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS])); | |
848d97d9 JC |
259 | if (rinfo[NL80211_RATE_INFO_HE_MCS]) |
260 | pos += snprintf(pos, buflen - (pos - buf), | |
261 | " HE-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_MCS])); | |
262 | if (rinfo[NL80211_RATE_INFO_HE_NSS]) | |
263 | pos += snprintf(pos, buflen - (pos - buf), | |
264 | " HE-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_NSS])); | |
265 | if (rinfo[NL80211_RATE_INFO_HE_GI]) | |
266 | pos += snprintf(pos, buflen - (pos - buf), | |
267 | " HE-GI %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_GI])); | |
268 | if (rinfo[NL80211_RATE_INFO_HE_DCM]) | |
269 | pos += snprintf(pos, buflen - (pos - buf), | |
270 | " HE-DCM %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_DCM])); | |
97dd4dad JC |
271 | if (rinfo[NL80211_RATE_INFO_HE_RU_ALLOC]) |
272 | pos += snprintf(pos, buflen - (pos - buf), | |
273 | " HE-RU-ALLOC %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_RU_ALLOC])); | |
e3287a1f JB |
274 | if (rinfo[NL80211_RATE_INFO_EHT_MCS]) |
275 | pos += snprintf(pos, buflen - (pos - buf), | |
276 | " EHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_EHT_MCS])); | |
277 | if (rinfo[NL80211_RATE_INFO_EHT_NSS]) | |
278 | pos += snprintf(pos, buflen - (pos - buf), | |
279 | " EHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_EHT_NSS])); | |
280 | if (rinfo[NL80211_RATE_INFO_EHT_GI]) | |
281 | pos += snprintf(pos, buflen - (pos - buf), | |
282 | " EHT-GI %d", nla_get_u8(rinfo[NL80211_RATE_INFO_EHT_GI])); | |
283 | if (rinfo[NL80211_RATE_INFO_EHT_RU_ALLOC]) | |
284 | pos += snprintf(pos, buflen - (pos - buf), | |
285 | " EHT-RU-ALLOC %d", nla_get_u8(rinfo[NL80211_RATE_INFO_EHT_RU_ALLOC])); | |
64179590 JB |
286 | } |
287 | ||
7d23bc2d FF |
288 | static char *get_chain_signal(struct nlattr *attr_list) |
289 | { | |
290 | struct nlattr *attr; | |
291 | static char buf[64]; | |
292 | char *cur = buf; | |
293 | int i = 0, rem; | |
294 | const char *prefix; | |
295 | ||
296 | if (!attr_list) | |
297 | return ""; | |
298 | ||
299 | nla_for_each_nested(attr, attr_list, rem) { | |
300 | if (i++ > 0) | |
301 | prefix = ", "; | |
302 | else | |
303 | prefix = "["; | |
304 | ||
305 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
306 | (int8_t) nla_get_u8(attr)); | |
307 | } | |
308 | ||
309 | if (i) | |
310 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
311 | ||
312 | return buf; | |
313 | } | |
314 | ||
3d1e8704 LCC |
315 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
316 | { | |
317 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
318 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
319 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
320 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 321 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
322 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
323 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
324 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
325 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
326 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
327 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
328 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
329 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 330 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 331 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 332 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 333 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 334 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
335 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
336 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
337 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
338 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
339 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
340 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
341 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
342 | [NL80211_STA_INFO_STA_FLAGS] = |
343 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
344 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
345 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
346 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
347 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
348 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
349 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
350 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
045c1c6f | 351 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
a85d693f | 352 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
d2272671 BP |
353 | [NL80211_STA_INFO_ACK_SIGNAL] = {.type = NLA_U8 }, |
354 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 }, | |
700f7d95 | 355 | [NL80211_STA_INFO_AIRTIME_LINK_METRIC] = { .type = NLA_U32 }, |
0ba98b90 MT |
356 | [NL80211_STA_INFO_CONNECTED_TO_AS] = { .type = NLA_U8 }, |
357 | [NL80211_STA_INFO_CONNECTED_TO_GATE] = { .type = NLA_U8 }, | |
3d1e8704 | 358 | }; |
7d23bc2d | 359 | char *chain; |
3708f614 BG |
360 | struct timeval now; |
361 | unsigned long long now_ms; | |
362 | ||
363 | gettimeofday(&now, NULL); | |
5d9d1b86 | 364 | now_ms = now.tv_sec * 1000ULL; |
3708f614 | 365 | now_ms += (now.tv_usec / 1000); |
3d1e8704 LCC |
366 | |
367 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
368 | genlmsg_attrlen(gnlh, 0), NULL); | |
369 | ||
370 | /* | |
371 | * TODO: validate the interface and mac address! | |
372 | * Otherwise, there's a race condition as soon as | |
373 | * the kernel starts sending station notifications. | |
374 | */ | |
375 | ||
376 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 377 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
378 | return NL_SKIP; |
379 | } | |
380 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
381 | tb[NL80211_ATTR_STA_INFO], | |
382 | stats_policy)) { | |
5fe70c0e | 383 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
384 | return NL_SKIP; |
385 | } | |
386 | ||
387 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
388 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 389 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
390 | |
391 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 392 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 393 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
394 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
395 | printf("\n\trx bytes:\t%llu", | |
396 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
397 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 398 | printf("\n\trx bytes:\t%u", |
568c7057 | 399 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 400 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 401 | printf("\n\trx packets:\t%u", |
859677cb | 402 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
403 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
404 | printf("\n\ttx bytes:\t%llu", | |
405 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
406 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 407 | printf("\n\ttx bytes:\t%u", |
568c7057 | 408 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 409 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 410 | printf("\n\ttx packets:\t%u", |
859677cb | 411 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
412 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
413 | printf("\n\ttx retries:\t%u", | |
414 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
415 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
416 | printf("\n\ttx failed:\t%u", | |
417 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
418 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
419 | printf("\n\tbeacon loss:\t%u", | |
420 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
421 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
422 | printf("\n\tbeacon rx:\t%llu", | |
423 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
424 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
425 | printf("\n\trx drop misc:\t%llu", | |
426 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
427 | |
428 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 429 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
430 | printf("\n\tsignal: \t%d %sdBm", |
431 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
432 | chain); | |
433 | ||
434 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 435 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
436 | printf("\n\tsignal avg:\t%d %sdBm", |
437 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
438 | chain); | |
439 | ||
568c7057 AE |
440 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
441 | printf("\n\tbeacon signal avg:\t%d dBm", | |
0fc92835 | 442 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); |
ea3ade85 | 443 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
444 | printf("\n\tToffset:\t%llu us", |
445 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
446 | |
447 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
448 | char buf[100]; |
449 | ||
e94f0201 | 450 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 451 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
452 | } |
453 | ||
a85d693f THJ |
454 | if (sinfo[NL80211_STA_INFO_TX_DURATION]) |
455 | printf("\n\ttx duration:\t%lld us", | |
456 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_DURATION])); | |
457 | ||
e94f0201 FF |
458 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
459 | char buf[100]; | |
460 | ||
461 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
462 | printf("\n\trx bitrate:\t%s", buf); | |
463 | } | |
464 | ||
045c1c6f MSS |
465 | if (sinfo[NL80211_STA_INFO_RX_DURATION]) |
466 | printf("\n\trx duration:\t%lld us", | |
467 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION])); | |
468 | ||
d2272671 BP |
469 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL]) |
470 | printf("\n\tlast ack signal:%d dBm", | |
471 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL])); | |
472 | ||
473 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG]) | |
474 | printf("\n\tavg ack signal:\t%d dBm", | |
475 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG])); | |
476 | ||
a85d693f THJ |
477 | if (sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT]) { |
478 | printf("\n\tairtime weight: %d", nla_get_u16(sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT])); | |
479 | } | |
480 | ||
cf8a2aab AQ |
481 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
482 | uint32_t thr; | |
483 | ||
484 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
485 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
486 | thr = thr * 1000 / 1024; | |
487 | ||
488 | printf("\n\texpected throughput:\t%u.%uMbps", | |
489 | thr / 1000, thr % 1000); | |
490 | } | |
491 | ||
3d1e8704 | 492 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 493 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
494 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
495 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 496 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
497 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
498 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 499 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
500 | case LISTEN: |
501 | strcpy(state_name, "LISTEN"); | |
502 | break; | |
503 | case OPN_SNT: | |
504 | strcpy(state_name, "OPN_SNT"); | |
505 | break; | |
506 | case OPN_RCVD: | |
507 | strcpy(state_name, "OPN_RCVD"); | |
508 | break; | |
509 | case CNF_RCVD: | |
510 | strcpy(state_name, "CNF_RCVD"); | |
511 | break; | |
512 | case ESTAB: | |
513 | strcpy(state_name, "ESTAB"); | |
514 | break; | |
515 | case HOLDING: | |
516 | strcpy(state_name, "HOLDING"); | |
517 | break; | |
518 | case BLOCKED: | |
519 | strcpy(state_name, "BLOCKED"); | |
520 | break; | |
521 | default: | |
522 | strcpy(state_name, "UNKNOWN"); | |
523 | break; | |
524 | } | |
fbb181fa | 525 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 526 | } |
700f7d95 MT |
527 | if (sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC]) |
528 | printf("\n\tmesh airtime link metric: %d", | |
529 | nla_get_u32(sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC])); | |
530 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) | |
531 | printf("\n\tmesh connected to gate:\t%s", | |
532 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) ? | |
533 | "yes" : "no"); | |
534 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) | |
535 | printf("\n\tmesh connected to auth server:\t%s", | |
536 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) ? | |
537 | "yes" : "no"); | |
538 | ||
8012ad28 MP |
539 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
540 | printf("\n\tmesh local PS mode:\t"); | |
541 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
542 | } | |
543 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
544 | printf("\n\tmesh peer PS mode:\t"); | |
545 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
546 | } | |
547 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
548 | printf("\n\tmesh non-peer PS mode:\t"); | |
549 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
550 | } | |
3d1e8704 | 551 | |
b638215d HS |
552 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
553 | sta_flags = (struct nl80211_sta_flag_update *) | |
554 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
555 | ||
556 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
557 | printf("\n\tauthorized:\t"); | |
558 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
559 | printf("yes"); | |
560 | else | |
561 | printf("no"); | |
562 | } | |
563 | ||
564 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
565 | printf("\n\tauthenticated:\t"); | |
566 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
567 | printf("yes"); | |
568 | else | |
569 | printf("no"); | |
570 | } | |
571 | ||
568c7057 AE |
572 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
573 | printf("\n\tassociated:\t"); | |
574 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
575 | printf("yes"); | |
576 | else | |
577 | printf("no"); | |
578 | } | |
579 | ||
b638215d HS |
580 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
581 | printf("\n\tpreamble:\t"); | |
582 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
583 | printf("short"); | |
584 | else | |
585 | printf("long"); | |
586 | } | |
587 | ||
588 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
589 | printf("\n\tWMM/WME:\t"); | |
590 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
591 | printf("yes"); | |
592 | else | |
593 | printf("no"); | |
594 | } | |
595 | ||
596 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
597 | printf("\n\tMFP:\t\t"); | |
598 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
599 | printf("yes"); | |
600 | else | |
601 | printf("no"); | |
602 | } | |
603 | ||
604 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 605 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
606 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
607 | printf("yes"); | |
608 | else | |
609 | printf("no"); | |
610 | } | |
611 | } | |
612 | ||
568c7057 AE |
613 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
614 | !strcmp((char *)arg, "-v")) | |
615 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
616 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
617 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
618 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
619 | printf("\n\tconnected time:\t%u seconds", | |
620 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
0b39c408 BG |
621 | if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) { |
622 | unsigned long long bt; | |
3708f614 BG |
623 | struct timespec now_ts; |
624 | unsigned long long boot_ns; | |
625 | unsigned long long assoc_at_ms; | |
626 | ||
627 | clock_gettime(CLOCK_BOOTTIME, &now_ts); | |
5d9d1b86 | 628 | boot_ns = now_ts.tv_sec * 1000000000ULL; |
3708f614 BG |
629 | boot_ns += now_ts.tv_nsec; |
630 | ||
0b39c408 | 631 | bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]); |
3708f614 | 632 | printf("\n\tassociated at [boottime]:\t%llu.%.3llus", |
0b39c408 | 633 | bt/1000000000, (bt%1000000000)/1000000); |
3708f614 BG |
634 | assoc_at_ms = now_ms - ((boot_ns - bt) / 1000000); |
635 | printf("\n\tassociated at:\t%llu ms", assoc_at_ms); | |
0b39c408 | 636 | } |
087d778f | 637 | |
3708f614 | 638 | printf("\n\tcurrent time:\t%llu ms\n", now_ms); |
3d1e8704 LCC |
639 | return NL_SKIP; |
640 | } | |
641 | ||
7c37a24d | 642 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 643 | struct nl_msg *msg, |
05514f95 JB |
644 | int argc, char **argv, |
645 | enum id_input id) | |
3d1e8704 | 646 | { |
3d1e8704 LCC |
647 | unsigned char mac_addr[ETH_ALEN]; |
648 | ||
b1ca19a8 | 649 | if (argc < 1) |
5e75fd04 | 650 | return 1; |
3d1e8704 LCC |
651 | |
652 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
653 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 654 | return 2; |
3d1e8704 LCC |
655 | } |
656 | ||
657 | argc--; | |
658 | argv++; | |
659 | ||
b1ca19a8 | 660 | if (argc) |
5e75fd04 | 661 | return 1; |
3d1e8704 LCC |
662 | |
663 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 664 | |
34b23014 | 665 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 666 | |
70391ccf | 667 | return 0; |
3d1e8704 | 668 | nla_put_failure: |
70391ccf | 669 | return -ENOBUFS; |
3d1e8704 | 670 | } |
b1ca19a8 | 671 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
672 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
673 | "Get information for a specific station."); | |
d738686c RM |
674 | |
675 | static int handle_station_del(struct nl80211_state *state, | |
676 | struct nl_msg *msg, | |
677 | int argc, char **argv, | |
678 | enum id_input id) | |
679 | { | |
680 | char *end; | |
681 | unsigned char mac_addr[ETH_ALEN]; | |
682 | int subtype; | |
683 | int reason_code; | |
684 | ||
685 | if (argc < 1) | |
686 | return 1; | |
687 | ||
688 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
689 | fprintf(stderr, "invalid mac address\n"); | |
690 | return 2; | |
691 | } | |
692 | ||
693 | argc--; | |
694 | argv++; | |
695 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
696 | ||
697 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
698 | argv++; | |
699 | argc--; | |
700 | ||
701 | subtype = strtod(argv[0], &end); | |
702 | if (*end != '\0') | |
703 | return 1; | |
704 | ||
705 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
706 | argv++; | |
707 | argc--; | |
708 | } | |
709 | ||
710 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
711 | argv++; | |
712 | argc--; | |
713 | ||
714 | reason_code = strtod(argv[0], &end); | |
715 | if (*end != '\0') | |
716 | return 1; | |
717 | ||
718 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
719 | argv++; | |
720 | argc--; | |
721 | } | |
722 | ||
723 | if (argc) | |
724 | return 1; | |
725 | ||
726 | register_handler(print_sta_handler, NULL); | |
727 | ||
728 | return 0; | |
729 | nla_put_failure: | |
730 | return -ENOBUFS; | |
731 | } | |
732 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
733 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
734 | "Remove the given station entry (use with caution!)\n" | |
735 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 736 | |
1633ddf7 JB |
737 | static const struct cmd *station_set_plink; |
738 | static const struct cmd *station_set_vlan; | |
8012ad28 | 739 | static const struct cmd *station_set_mesh_power_mode; |
82903243 | 740 | static const struct cmd *station_set_airtime_weight; |
5bdf11e3 | 741 | static const struct cmd *station_set_txpwr; |
1633ddf7 JB |
742 | |
743 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
744 | { | |
745 | if (argc < 2) | |
746 | return NULL; | |
747 | if (strcmp(argv[1], "plink_action") == 0) | |
748 | return station_set_plink; | |
749 | if (strcmp(argv[1], "vlan") == 0) | |
750 | return station_set_vlan; | |
8012ad28 MP |
751 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
752 | return station_set_mesh_power_mode; | |
82903243 THJ |
753 | if (strcmp(argv[1], "airtime_weight") == 0) |
754 | return station_set_airtime_weight; | |
5bdf11e3 ARN |
755 | if (strcmp(argv[1], "txpwr") == 0) |
756 | return station_set_txpwr; | |
1633ddf7 JB |
757 | return NULL; |
758 | } | |
759 | ||
ce0fc33a | 760 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 761 | struct nl_msg *msg, |
05514f95 JB |
762 | int argc, char **argv, |
763 | enum id_input id) | |
3d1e8704 | 764 | { |
3d1e8704 LCC |
765 | unsigned char plink_action; |
766 | unsigned char mac_addr[ETH_ALEN]; | |
767 | ||
b1ca19a8 | 768 | if (argc < 3) |
5e75fd04 | 769 | return 1; |
3d1e8704 LCC |
770 | |
771 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
772 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 773 | return 2; |
3d1e8704 LCC |
774 | } |
775 | argc--; | |
776 | argv++; | |
777 | ||
b1ca19a8 JB |
778 | if (strcmp("plink_action", argv[0]) != 0) |
779 | return 1; | |
3d1e8704 LCC |
780 | argc--; |
781 | argv++; | |
782 | ||
783 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 784 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 785 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 786 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
787 | else { |
788 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 789 | return 2; |
3d1e8704 LCC |
790 | } |
791 | argc--; | |
792 | argv++; | |
793 | ||
b1ca19a8 | 794 | if (argc) |
5e75fd04 | 795 | return 1; |
3d1e8704 LCC |
796 | |
797 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
798 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
799 | ||
70391ccf | 800 | return 0; |
3d1e8704 | 801 | nla_put_failure: |
70391ccf | 802 | return -ENOBUFS; |
3d1e8704 | 803 | } |
1633ddf7 | 804 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 805 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
806 | "Set mesh peer link action for this station (peer).", |
807 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 808 | |
ce0fc33a | 809 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
810 | struct nl_msg *msg, |
811 | int argc, char **argv, | |
812 | enum id_input id) | |
ce0fc33a FF |
813 | { |
814 | unsigned char mac_addr[ETH_ALEN]; | |
815 | unsigned long sta_vlan = 0; | |
816 | char *err = NULL; | |
817 | ||
818 | if (argc < 3) | |
819 | return 1; | |
820 | ||
821 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
822 | fprintf(stderr, "invalid mac address\n"); | |
823 | return 2; | |
824 | } | |
825 | argc--; | |
826 | argv++; | |
827 | ||
828 | if (strcmp("vlan", argv[0]) != 0) | |
829 | return 1; | |
830 | argc--; | |
831 | argv++; | |
832 | ||
833 | sta_vlan = strtoul(argv[0], &err, 0); | |
834 | if (err && *err) { | |
835 | fprintf(stderr, "invalid vlan id\n"); | |
836 | return 2; | |
837 | } | |
838 | argc--; | |
839 | argv++; | |
840 | ||
841 | if (argc) | |
842 | return 1; | |
843 | ||
844 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
845 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
846 | ||
847 | return 0; | |
848 | nla_put_failure: | |
849 | return -ENOBUFS; | |
850 | } | |
1633ddf7 | 851 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 852 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
853 | "Set an AP VLAN for this station.", |
854 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 855 | |
8012ad28 | 856 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
857 | struct nl_msg *msg, |
858 | int argc, char **argv, | |
859 | enum id_input id) | |
860 | { | |
861 | unsigned char mesh_power_mode; | |
862 | unsigned char mac_addr[ETH_ALEN]; | |
863 | ||
864 | if (argc < 3) | |
865 | return 1; | |
866 | ||
867 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
868 | fprintf(stderr, "invalid mac address\n"); | |
869 | return 2; | |
870 | } | |
871 | argc--; | |
872 | argv++; | |
873 | ||
874 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
875 | return 1; | |
876 | argc--; | |
877 | argv++; | |
878 | ||
879 | if (strcmp("active", argv[0]) == 0) | |
880 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
881 | else if (strcmp("light", argv[0]) == 0) | |
882 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
883 | else if (strcmp("deep", argv[0]) == 0) | |
884 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
885 | else { | |
886 | fprintf(stderr, "unknown mesh power mode\n"); | |
887 | return 2; | |
888 | } | |
889 | argc--; | |
890 | argv++; | |
891 | ||
892 | if (argc) | |
893 | return 1; | |
894 | ||
895 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
896 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
897 | ||
898 | return 0; | |
899 | nla_put_failure: | |
900 | return -ENOBUFS; | |
901 | } | |
902 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
903 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
904 | handle_station_set_mesh_power_mode, | |
905 | "Set link-specific mesh power mode for this station", | |
906 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 907 | |
82903243 THJ |
908 | static int handle_station_set_airtime_weight(struct nl80211_state *state, |
909 | struct nl_msg *msg, | |
910 | int argc, char **argv, | |
911 | enum id_input id) | |
912 | { | |
913 | unsigned char mac_addr[ETH_ALEN]; | |
914 | unsigned long airtime_weight = 0; | |
915 | char *err = NULL; | |
916 | ||
917 | if (argc < 3) | |
918 | return 1; | |
919 | ||
920 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
921 | fprintf(stderr, "invalid mac address\n"); | |
922 | return 2; | |
923 | } | |
924 | argc--; | |
925 | argv++; | |
926 | ||
927 | if (strcmp("airtime_weight", argv[0]) != 0) | |
928 | return 1; | |
929 | argc--; | |
930 | argv++; | |
931 | ||
932 | airtime_weight = strtoul(argv[0], &err, 0); | |
933 | if (err && *err) { | |
934 | fprintf(stderr, "invalid airtime weight\n"); | |
935 | return 2; | |
936 | } | |
937 | argc--; | |
938 | argv++; | |
939 | ||
940 | if (argc) | |
941 | return 1; | |
942 | ||
943 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
944 | NLA_PUT_U16(msg, NL80211_ATTR_AIRTIME_WEIGHT, airtime_weight); | |
945 | ||
946 | return 0; | |
947 | nla_put_failure: | |
948 | return -ENOBUFS; | |
949 | ||
950 | } | |
951 | COMMAND_ALIAS(station, set, "<MAC address> airtime_weight <weight>", | |
952 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_airtime_weight, | |
953 | "Set airtime weight for this station.", | |
954 | select_station_cmd, station_set_airtime_weight); | |
955 | ||
5bdf11e3 ARN |
956 | static int handle_station_set_txpwr(struct nl80211_state *state, |
957 | struct nl_msg *msg, | |
958 | int argc, char **argv, | |
959 | enum id_input id) | |
960 | { | |
961 | enum nl80211_tx_power_setting type; | |
962 | unsigned char mac_addr[ETH_ALEN]; | |
963 | int sta_txpwr = 0; | |
964 | char *err = NULL; | |
965 | ||
966 | if (argc != 3 && argc != 4) | |
967 | return 1; | |
968 | ||
969 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
970 | fprintf(stderr, "invalid mac address\n"); | |
971 | return 2; | |
972 | } | |
973 | ||
974 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
975 | argc--; | |
976 | argv++; | |
977 | ||
978 | if (strcmp("txpwr", argv[0]) != 0) | |
979 | return 1; | |
980 | argc--; | |
981 | argv++; | |
982 | ||
983 | if (!strcmp(argv[0], "auto")) | |
984 | type = NL80211_TX_POWER_AUTOMATIC; | |
985 | else if (!strcmp(argv[0], "limit")) | |
986 | type = NL80211_TX_POWER_LIMITED; | |
987 | else { | |
988 | printf("Invalid parameter: %s\n", argv[0]); | |
989 | return 2; | |
990 | } | |
991 | ||
992 | NLA_PUT_U8(msg, NL80211_ATTR_STA_TX_POWER_SETTING, type); | |
993 | ||
994 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
995 | if (argc != 2) { | |
996 | printf("Missing TX power level argument.\n"); | |
997 | return 2; | |
998 | } | |
999 | ||
1000 | argc--; | |
1001 | argv++; | |
1002 | ||
1003 | sta_txpwr = strtoul(argv[0], &err, 0); | |
1004 | NLA_PUT_U16(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); | |
1005 | } | |
1006 | ||
1007 | argc--; | |
1008 | argv++; | |
1009 | ||
1010 | if (argc) | |
1011 | return 1; | |
1012 | ||
1013 | return 0; | |
1014 | nla_put_failure: | |
1015 | return -ENOBUFS; | |
1016 | } | |
1017 | COMMAND_ALIAS(station, set, "<MAC address> txpwr <auto|limit> [<tx power dBm>]", | |
1018 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, | |
1019 | "Set Tx power for this station.", | |
1020 | select_station_cmd, station_set_txpwr); | |
1021 | ||
7c37a24d | 1022 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 1023 | struct nl_msg *msg, |
05514f95 JB |
1024 | int argc, char **argv, |
1025 | enum id_input id) | |
3d1e8704 | 1026 | { |
568c7057 | 1027 | register_handler(print_sta_handler, *argv); |
70391ccf | 1028 | return 0; |
3d1e8704 | 1029 | } |
568c7057 | 1030 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
1031 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
1032 | "List all stations known, e.g. the AP on managed interfaces"); |