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