]> git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
iw: add extack support
[thirdparty/iw.git] / iw.h
1 #ifndef __IW_H
2 #define __IW_H
3
4 #include <stdbool.h>
5 #include <netlink/netlink.h>
6 #include <netlink/genl/genl.h>
7 #include <netlink/genl/family.h>
8 #include <netlink/genl/ctrl.h>
9 #include <endian.h>
10
11 #include "nl80211.h"
12 #include "ieee80211.h"
13
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
33
34 #define ETH_ALEN 6
35 #define VHT_MUMIMO_GROUP_LEN 24
36
37 /* libnl 1.x compatibility code */
38 #if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30)
39 # define nl_sock nl_handle
40 #endif
41
42 struct nl80211_state {
43 struct nl_sock *nl_sock;
44 int nl80211_id;
45 };
46
47 enum command_identify_by {
48 CIB_NONE,
49 CIB_PHY,
50 CIB_NETDEV,
51 CIB_WDEV,
52 };
53
54 enum id_input {
55 II_NONE,
56 II_NETDEV,
57 II_PHY_NAME,
58 II_PHY_IDX,
59 II_WDEV,
60 };
61
62 #define HANDLER_RET_USAGE 1
63 #define HANDLER_RET_DONE 3
64
65 struct cmd {
66 const char *name;
67 const char *args;
68 const char *help;
69 const enum nl80211_commands cmd;
70 int nl_msg_flags;
71 int hidden;
72 const enum command_identify_by idby;
73 /*
74 * The handler should return a negative error code,
75 * zero on success, 1 if the arguments were wrong.
76 * Return 2 iff you provide the error message yourself.
77 */
78 int (*handler)(struct nl80211_state *state,
79 struct nl_msg *msg,
80 int argc, char **argv,
81 enum id_input id);
82 const struct cmd *(*selector)(int argc, char **argv);
83 const struct cmd *parent;
84 };
85
86 struct chanmode {
87 const char *name;
88 unsigned int width;
89 int freq1_diff;
90 int chantype; /* for older kernel */
91 };
92
93 struct chandef {
94 enum nl80211_chan_width width;
95
96 unsigned int control_freq;
97 unsigned int center_freq1;
98 unsigned int center_freq2;
99 };
100
101 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
102 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
103
104 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\
105 static struct cmd \
106 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
107 __attribute__((used)) __attribute__((section("__cmd"))) = { \
108 .name = (_name), \
109 .args = (_args), \
110 .cmd = (_nlcmd), \
111 .nl_msg_flags = (_flags), \
112 .hidden = (_hidden), \
113 .idby = (_idby), \
114 .handler = (_handler), \
115 .help = (_help), \
116 .parent = _section, \
117 .selector = (_sel), \
118 }
119 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
120 __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
121 static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
122 #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
123 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL)
124 #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\
125 __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias)
126 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
127 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
128
129 #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
130 struct cmd \
131 __section ## _ ## _name \
132 __attribute__((used)) __attribute__((section("__cmd"))) = { \
133 .name = (#_name), \
134 .args = (_args), \
135 .cmd = (_nlcmd), \
136 .nl_msg_flags = (_flags), \
137 .idby = (_idby), \
138 .handler = (_handler), \
139 .help = (_help), \
140 }
141 #define SECTION(_name) \
142 struct cmd __section ## _ ## _name \
143 __attribute__((used)) __attribute__((section("__cmd"))) = { \
144 .name = (#_name), \
145 .hidden = 1, \
146 }
147
148 #define DECLARE_SECTION(_name) \
149 extern struct cmd __section ## _ ## _name;
150
151 extern const char iw_version[];
152
153 extern int iw_debug;
154
155 int handle_cmd(struct nl80211_state *state, enum id_input idby,
156 int argc, char **argv);
157
158 struct print_event_args {
159 struct timeval ts; /* internal */
160 bool have_ts; /* must be set false */
161 bool frame, time, reltime;
162 };
163
164 __u32 listen_events(struct nl80211_state *state,
165 const int n_waits, const __u32 *waits);
166 int __prepare_listen_events(struct nl80211_state *state);
167 __u32 __do_listen_events(struct nl80211_state *state,
168 const int n_waits, const __u32 *waits,
169 struct print_event_args *args);
170
171 int valid_handler(struct nl_msg *msg, void *arg);
172 void register_handler(int (*handler)(struct nl_msg *, void *), void *data);
173
174 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
175 void mac_addr_n2a(char *mac_addr, unsigned char *arg);
176 int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
177 unsigned char **mask);
178 unsigned char *parse_hex(char *hex, size_t *outlen);
179
180 int parse_keys(struct nl_msg *msg, char **argv, int argc);
181 int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv, int *parsed);
182 enum nl80211_chan_width str_to_bw(const char *str);
183 int put_chandef(struct nl_msg *msg, struct chandef *chandef);
184
185 void print_ht_mcs(const __u8 *mcs);
186 void print_ampdu_length(__u8 exponent);
187 void print_ampdu_spacing(__u8 spacing);
188 void print_ht_capability(__u16 cap);
189 void print_vht_info(__u32 capa, const __u8 *mcs);
190
191 char *channel_width_name(enum nl80211_chan_width width);
192 const char *iftype_name(enum nl80211_iftype iftype);
193 const char *command_name(enum nl80211_commands cmd);
194 int ieee80211_channel_to_frequency(int chan, enum nl80211_band band);
195 int ieee80211_frequency_to_channel(int freq);
196
197 void print_ssid_escaped(const uint8_t len, const uint8_t *data);
198
199 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
200
201 char *reg_initiator_to_string(__u8 initiator);
202
203 const char *get_reason_str(uint16_t reason);
204 const char *get_status_str(uint16_t status);
205
206 enum print_ie_type {
207 PRINT_SCAN,
208 PRINT_LINK,
209 };
210
211 #define BIT(x) (1ULL<<(x))
212
213 void print_ies(unsigned char *ie, int ielen, bool unknown,
214 enum print_ie_type ptype);
215
216 void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
217 void iw_hexdump(const char *prefix, const __u8 *data, size_t len);
218
219 int get_cf1(const struct chanmode *chanmode, unsigned long freq);
220
221 #define SCHED_SCAN_OPTIONS "[interval <in_msecs> | scan_plans [<interval_secs:iterations>*] <interval_secs>] " \
222 "[delay <in_secs>] [freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] " \
223 "[randomise[=<addr>/<mask>]]"
224 int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
225
226 DECLARE_SECTION(switch);
227 DECLARE_SECTION(set);
228 DECLARE_SECTION(get);
229
230 #endif /* __IW_H */