]>
Commit | Line | Data |
---|---|---|
cad53b3f JB |
1 | #ifndef __IW_H |
2 | #define __IW_H | |
3 | ||
7fabd346 | 4 | #include <stdbool.h> |
45d543f0 | 5 | #include <netlink/netlink.h> |
cad53b3f JB |
6 | #include <netlink/genl/genl.h> |
7 | #include <netlink/genl/family.h> | |
8 | #include <netlink/genl/ctrl.h> | |
a82abc2c | 9 | #include <endian.h> |
cad53b3f | 10 | |
f408e01b | 11 | #include "nl80211.h" |
a82abc2c | 12 | #include "ieee80211.h" |
f408e01b | 13 | |
3a807325 JB |
14 | /* support for extack if compilation headers are too old */ |
15 | #ifndef NETLINK_EXT_ACK | |
16 | #define NETLINK_EXT_ACK 11 | |
17 | enum nlmsgerr_attrs { | |
18 | NLMSGERR_ATTR_UNUSED, | |
19 | NLMSGERR_ATTR_MSG, | |
20 | NLMSGERR_ATTR_OFFS, | |
21 | NLMSGERR_ATTR_COOKIE, | |
22 | ||
23 | __NLMSGERR_ATTR_MAX, | |
24 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 | |
25 | }; | |
26 | #endif | |
27 | #ifndef NLM_F_CAPPED | |
28 | #define NLM_F_CAPPED 0x100 | |
29 | #endif | |
30 | #ifndef NLM_F_ACK_TLVS | |
31 | #define NLM_F_ACK_TLVS 0x200 | |
32 | #endif | |
86da57ad JB |
33 | #ifndef SOL_NETLINK |
34 | #define SOL_NETLINK 270 | |
35 | #endif | |
3a807325 | 36 | |
3d1e8704 | 37 | #define ETH_ALEN 6 |
386bacb2 | 38 | #define VHT_MUMIMO_GROUP_LEN 24 |
3d1e8704 | 39 | |
ded667b0 YY |
40 | /* libnl 1.x compatibility code */ |
41 | #if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30) | |
57077d64 | 42 | # define nl_sock nl_handle |
dfd13ee5 | 43 | #endif |
57077d64 PE |
44 | |
45 | struct nl80211_state { | |
46 | struct nl_sock *nl_sock; | |
f09cee6d | 47 | int nl80211_id; |
cad53b3f JB |
48 | }; |
49 | ||
bd396f2a JB |
50 | enum command_identify_by { |
51 | CIB_NONE, | |
52 | CIB_PHY, | |
53 | CIB_NETDEV, | |
290a3dd4 | 54 | CIB_WDEV, |
7c37a24d JB |
55 | }; |
56 | ||
57 | enum id_input { | |
58 | II_NONE, | |
59 | II_NETDEV, | |
60 | II_PHY_NAME, | |
61 | II_PHY_IDX, | |
290a3dd4 | 62 | II_WDEV, |
bd396f2a | 63 | }; |
45c7212c | 64 | |
b2c4bf45 | 65 | #define HANDLER_RET_USAGE 1 |
94af668b JB |
66 | #define HANDLER_RET_DONE 3 |
67 | ||
bd396f2a | 68 | struct cmd { |
bd396f2a JB |
69 | const char *name; |
70 | const char *args; | |
01ae06f9 | 71 | const char *help; |
bd396f2a JB |
72 | const enum nl80211_commands cmd; |
73 | int nl_msg_flags; | |
ce5af55c | 74 | int hidden; |
bd396f2a | 75 | const enum command_identify_by idby; |
5e75fd04 JB |
76 | /* |
77 | * The handler should return a negative error code, | |
86a9801f OO |
78 | * zero on success, 1 if the arguments were wrong. |
79 | * Return 2 iff you provide the error message yourself. | |
5e75fd04 | 80 | */ |
7c37a24d | 81 | int (*handler)(struct nl80211_state *state, |
bd396f2a | 82 | struct nl_msg *msg, |
05514f95 JB |
83 | int argc, char **argv, |
84 | enum id_input id); | |
1633ddf7 | 85 | const struct cmd *(*selector)(int argc, char **argv); |
4698bfc2 | 86 | const struct cmd *parent; |
bd396f2a | 87 | }; |
3d1e8704 | 88 | |
c1b2b633 SE |
89 | struct chanmode { |
90 | const char *name; | |
91 | unsigned int width; | |
92 | int freq1_diff; | |
93 | int chantype; /* for older kernel */ | |
94 | }; | |
95 | ||
997c60fd BB |
96 | struct chandef { |
97 | enum nl80211_chan_width width; | |
98 | ||
99 | unsigned int control_freq; | |
100 | unsigned int center_freq1; | |
101 | unsigned int center_freq2; | |
102 | }; | |
103 | ||
7d736016 | 104 | #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0])) |
3ff24563 | 105 | #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y)) |
7d736016 | 106 | |
1633ddf7 | 107 | #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\ |
78bebb71 | 108 | static struct cmd \ |
338059ac | 109 | __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden = {\ |
9b92e691 JB |
110 | .name = (_name), \ |
111 | .args = (_args), \ | |
112 | .cmd = (_nlcmd), \ | |
113 | .nl_msg_flags = (_flags), \ | |
114 | .hidden = (_hidden), \ | |
115 | .idby = (_idby), \ | |
116 | .handler = (_handler), \ | |
01ae06f9 | 117 | .help = (_help), \ |
4698bfc2 | 118 | .parent = _section, \ |
1633ddf7 | 119 | .selector = (_sel), \ |
338059ac JB |
120 | }; \ |
121 | static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \ | |
122 | __attribute__((used,section("__cmd"))) = \ | |
123 | &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden | |
1633ddf7 JB |
124 | #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\ |
125 | __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\ | |
126 | static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden | |
01ae06f9 | 127 | #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \ |
1633ddf7 JB |
128 | __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL) |
129 | #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\ | |
130 | __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias) | |
01ae06f9 | 131 | #define HIDDEN(section, name, args, cmd, flags, idby, handler) \ |
1633ddf7 | 132 | __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL) |
4698bfc2 JB |
133 | |
134 | #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \ | |
338059ac | 135 | struct cmd __section ## _ ## _name = { \ |
4698bfc2 JB |
136 | .name = (#_name), \ |
137 | .args = (_args), \ | |
138 | .cmd = (_nlcmd), \ | |
139 | .nl_msg_flags = (_flags), \ | |
140 | .idby = (_idby), \ | |
141 | .handler = (_handler), \ | |
142 | .help = (_help), \ | |
338059ac JB |
143 | }; \ |
144 | static struct cmd *__section ## _ ## _name ## _p \ | |
145 | __attribute__((used,section("__cmd"))) = &__section ## _ ## _name | |
146 | ||
4698bfc2 | 147 | #define SECTION(_name) \ |
338059ac | 148 | struct cmd __section ## _ ## _name = { \ |
4698bfc2 JB |
149 | .name = (#_name), \ |
150 | .hidden = 1, \ | |
338059ac JB |
151 | }; \ |
152 | static struct cmd *__section ## _ ## _name ## _p \ | |
153 | __attribute__((used,section("__cmd"))) = &__section ## _ ## _name | |
4698bfc2 JB |
154 | |
155 | #define DECLARE_SECTION(_name) \ | |
78bebb71 | 156 | extern struct cmd __section ## _ ## _name; |
14a0380d | 157 | |
8e58fe92 JB |
158 | struct vendor_event { |
159 | unsigned int vendor_id, subcmd; | |
160 | void (*callback)(unsigned int vendor_id, unsigned int subcmd, | |
161 | struct nlattr *data); | |
162 | }; | |
163 | ||
164 | #define VENDOR_EVENT(_id, _subcmd, _callback) \ | |
f71bd68b | 165 | static const struct vendor_event \ |
8e58fe92 JB |
166 | vendor_event_ ## _id ## _ ## _subcmd = { \ |
167 | .vendor_id = _id, \ | |
168 | .subcmd = _subcmd, \ | |
169 | .callback = _callback, \ | |
170 | }, * const vendor_event_ ## _id ## _ ## _subcmd ## _p \ | |
171 | __attribute__((used,section("vendor_event"))) = \ | |
172 | &vendor_event_ ## _id ## _ ## _subcmd | |
173 | ||
133b069f | 174 | extern const char iw_version[]; |
7c37a24d | 175 | |
957a0f07 JB |
176 | extern int iw_debug; |
177 | ||
7c37a24d JB |
178 | int handle_cmd(struct nl80211_state *state, enum id_input idby, |
179 | int argc, char **argv); | |
7fabd346 JB |
180 | |
181 | struct print_event_args { | |
981b21ad JB |
182 | struct timeval ts; /* internal */ |
183 | bool have_ts; /* must be set false */ | |
c3df363e | 184 | bool frame, time, reltime, ctime; |
7fabd346 JB |
185 | }; |
186 | ||
72041aa0 JB |
187 | __u32 listen_events(struct nl80211_state *state, |
188 | const int n_waits, const __u32 *waits); | |
ee374e4d JB |
189 | int __prepare_listen_events(struct nl80211_state *state); |
190 | __u32 __do_listen_events(struct nl80211_state *state, | |
191 | const int n_waits, const __u32 *waits, | |
2e192cea | 192 | const int n_prints, const __u32 *prints, |
ee374e4d | 193 | struct print_event_args *args); |
7c37a24d | 194 | |
34b23014 JB |
195 | int valid_handler(struct nl_msg *msg, void *arg); |
196 | void register_handler(int (*handler)(struct nl_msg *, void *), void *data); | |
7c37a24d | 197 | |
3d1e8704 | 198 | int mac_addr_a2n(unsigned char *mac_addr, char *arg); |
7f87d3cf | 199 | void mac_addr_n2a(char *mac_addr, const unsigned char *arg); |
3ff24563 JB |
200 | int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len, |
201 | unsigned char **mask); | |
236d4191 | 202 | unsigned char *parse_hex(char *hex, size_t *outlen); |
3d1e8704 | 203 | |
0e39f109 | 204 | int parse_keys(struct nl_msg *msg, char **argv[], int *argc); |
997c60fd | 205 | int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv, int *parsed); |
c37f6c64 | 206 | enum nl80211_chan_width str_to_bw(const char *str); |
910792c0 THJ |
207 | int parse_txq_stats(char *buf, int buflen, struct nlattr *tid_stats_attr, int header, |
208 | int tid, const char *indent); | |
997c60fd | 209 | int put_chandef(struct nl_msg *msg, struct chandef *chandef); |
51e9bd80 | 210 | |
7ddfb679 | 211 | void print_ht_mcs(const __u8 *mcs); |
0950993f LR |
212 | void print_ampdu_length(__u8 exponent); |
213 | void print_ampdu_spacing(__u8 spacing); | |
357c1a5d | 214 | void print_ht_capability(__u16 cap); |
54eb1613 | 215 | void print_vht_info(__u32 capa, const __u8 *mcs); |
17e8564a | 216 | void print_he_capability(const uint8_t *ie, int len); |
c741be9f | 217 | void print_he_info(struct nlattr *nl_iftype); |
deb3501c | 218 | |
c5df9eb6 | 219 | char *channel_width_name(enum nl80211_chan_width width); |
541ef425 | 220 | const char *iftype_name(enum nl80211_iftype iftype); |
a6cedc6d JB |
221 | void print_iftype_list(const char *name, const char *pfx, struct nlattr *attr); |
222 | void print_iftype_line(struct nlattr *attr); | |
9990c1e9 | 223 | const char *command_name(enum nl80211_commands cmd); |
58b46da2 | 224 | int ieee80211_channel_to_frequency(int chan, enum nl80211_band band); |
379f8397 | 225 | int ieee80211_frequency_to_channel(int freq); |
541ef425 | 226 | |
748f8489 JB |
227 | void print_ssid_escaped(const uint8_t len, const uint8_t *data); |
228 | ||
57077d64 | 229 | int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group); |
2c61ba61 | 230 | |
601c6ab2 LR |
231 | char *reg_initiator_to_string(__u8 initiator); |
232 | ||
27c49ed6 | 233 | const char *get_reason_str(uint16_t reason); |
22c7d879 | 234 | const char *get_status_str(uint16_t status); |
27c49ed6 | 235 | |
febeb0c0 JB |
236 | enum print_ie_type { |
237 | PRINT_SCAN, | |
238 | PRINT_LINK, | |
239 | }; | |
240 | ||
241 | #define BIT(x) (1ULL<<(x)) | |
242 | ||
243 | void print_ies(unsigned char *ie, int ielen, bool unknown, | |
244 | enum print_ie_type ptype); | |
245 | ||
e94f0201 | 246 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen); |
492354de | 247 | void iw_hexdump(const char *prefix, const __u8 *data, size_t len); |
4698bfc2 | 248 | |
c1b2b633 SE |
249 | int get_cf1(const struct chanmode *chanmode, unsigned long freq); |
250 | ||
3c0117c1 JB |
251 | int parse_random_mac_addr(struct nl_msg *msg, char *addrs); |
252 | ||
9ae0d103 AS |
253 | #define SCHED_SCAN_OPTIONS "[interval <in_msecs> | scan_plans [<interval_secs:iterations>*] <interval_secs>] " \ |
254 | "[delay <in_secs>] [freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] " \ | |
5ec60ed9 | 255 | "[randomise[=<addr>/<mask>]] [coloc] [flush]" |
b1622287 LC |
256 | int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv); |
257 | ||
63d6aac5 RZ |
258 | void nan_bf(uint8_t idx, uint8_t *bf, uint16_t bf_len, const uint8_t *buf, |
259 | size_t len); | |
260 | ||
60b6c638 IP |
261 | char *hex2bin(const char *hex, char *buf); |
262 | ||
4d2749a6 TC |
263 | int set_bitrates(struct nl_msg *msg, int argc, char **argv, |
264 | enum nl80211_attrs attr); | |
265 | ||
3d3d8fc9 JB |
266 | |
267 | /* sections */ | |
268 | DECLARE_SECTION(ap); | |
269 | DECLARE_SECTION(auth); | |
270 | DECLARE_SECTION(cac); | |
271 | DECLARE_SECTION(channels); | |
272 | DECLARE_SECTION(coalesce); | |
273 | DECLARE_SECTION(commands); | |
274 | DECLARE_SECTION(connect); | |
275 | DECLARE_SECTION(cqm); | |
276 | DECLARE_SECTION(del); | |
277 | DECLARE_SECTION(dev); | |
278 | DECLARE_SECTION(disconnect); | |
279 | DECLARE_SECTION(event); | |
280 | DECLARE_SECTION(features); | |
281 | DECLARE_SECTION(ftm); | |
282 | DECLARE_SECTION(get); | |
283 | DECLARE_SECTION(help); | |
284 | DECLARE_SECTION(hwsim); | |
285 | DECLARE_SECTION(ibss); | |
286 | DECLARE_SECTION(info); | |
287 | DECLARE_SECTION(interface); | |
288 | DECLARE_SECTION(link); | |
289 | DECLARE_SECTION(list); | |
290 | DECLARE_SECTION(measurement); | |
291 | DECLARE_SECTION(mesh); | |
292 | DECLARE_SECTION(mesh_param); | |
293 | DECLARE_SECTION(mgmt); | |
294 | DECLARE_SECTION(mpath); | |
295 | DECLARE_SECTION(mpp); | |
296 | DECLARE_SECTION(nan); | |
297 | DECLARE_SECTION(ocb); | |
298 | DECLARE_SECTION(offchannel); | |
299 | DECLARE_SECTION(p2p); | |
300 | DECLARE_SECTION(phy); | |
301 | DECLARE_SECTION(reg); | |
302 | DECLARE_SECTION(roc); | |
303 | DECLARE_SECTION(scan); | |
304 | DECLARE_SECTION(set); | |
305 | DECLARE_SECTION(station); | |
306 | DECLARE_SECTION(survey); | |
307 | DECLARE_SECTION(switch); | |
308 | DECLARE_SECTION(vendor); | |
309 | DECLARE_SECTION(wowlan); | |
310 | ||
cad53b3f | 311 | #endif /* __IW_H */ |