]>
git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
5 #include <netlink/netlink.h>
6 #include <netlink/genl/genl.h>
7 #include <netlink/genl/family.h>
8 #include <netlink/genl/ctrl.h>
12 #include "ieee80211.h"
14 #ifndef NL_CAPABILITY_VERSION_3_5_0
15 #define nla_nest_start(msg, attrtype) \
16 nla_nest_start(msg, NLA_F_NESTED | (attrtype))
19 /* support for extack if compilation headers are too old */
20 #ifndef NETLINK_EXT_ACK
21 #define NETLINK_EXT_ACK 11
29 NLMSGERR_ATTR_MAX
= __NLMSGERR_ATTR_MAX
- 1
33 #define NLM_F_CAPPED 0x100
35 #ifndef NLM_F_ACK_TLVS
36 #define NLM_F_ACK_TLVS 0x200
39 #define SOL_NETLINK 270
43 #define VHT_MUMIMO_GROUP_LEN 24
45 /* libnl 1.x compatibility code */
46 #if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30)
47 # define nl_sock nl_handle
50 struct nl80211_state
{
51 struct nl_sock
*nl_sock
;
55 enum command_identify_by
{
70 #define HANDLER_RET_USAGE 1
71 #define HANDLER_RET_DONE 3
77 const enum nl80211_commands cmd
;
80 const enum command_identify_by idby
;
82 * The handler should return a negative error code,
83 * zero on success, 1 if the arguments were wrong.
84 * Return 2 iff you provide the error message yourself.
86 int (*handler
)(struct nl80211_state
*state
,
88 int argc
, char **argv
,
90 const struct cmd
*(*selector
)(int argc
, char **argv
);
91 const struct cmd
*parent
;
98 int chantype
; /* for older kernel */
102 enum nl80211_chan_width width
;
104 unsigned int control_freq
;
105 unsigned int control_freq_offset
;
106 unsigned int center_freq1
;
107 unsigned int center_freq1_offset
;
108 unsigned int center_freq2
;
111 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
112 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
114 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\
116 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden = {\
120 .nl_msg_flags = (_flags), \
121 .hidden = (_hidden), \
123 .handler = (_handler), \
125 .parent = _section, \
126 .selector = (_sel), \
128 static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \
129 __attribute__((used,section("__cmd"))) = \
130 &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
131 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
132 __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
133 static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
134 #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
135 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL)
136 #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\
137 __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias)
138 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
139 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
141 #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
142 struct cmd __section ## _ ## _name = { \
146 .nl_msg_flags = (_flags), \
148 .handler = (_handler), \
151 static struct cmd *__section ## _ ## _name ## _p \
152 __attribute__((used,section("__cmd"))) = &__section ## _ ## _name
154 #define SECTION(_name) \
155 struct cmd __section ## _ ## _name = { \
159 static struct cmd *__section ## _ ## _name ## _p \
160 __attribute__((used,section("__cmd"))) = &__section ## _ ## _name
162 #define DECLARE_SECTION(_name) \
163 extern struct cmd __section ## _ ## _name;
165 struct vendor_event
{
166 unsigned int vendor_id
, subcmd
;
167 void (*callback
)(unsigned int vendor_id
, unsigned int subcmd
,
168 struct nlattr
*data
);
171 #define VENDOR_EVENT(_id, _subcmd, _callback) \
172 static const struct vendor_event \
173 vendor_event_ ## _id ## _ ## _subcmd = { \
176 .callback = _callback, \
177 }, * const vendor_event_ ## _id ## _ ## _subcmd ## _p \
178 __attribute__((used,section("vendor_event"))) = \
179 &vendor_event_ ## _id ## _ ## _subcmd
181 extern const char iw_version
[];
185 int handle_cmd(struct nl80211_state
*state
, enum id_input idby
,
186 int argc
, char **argv
);
188 struct print_event_args
{
189 struct timeval ts
; /* internal */
190 bool have_ts
; /* must be set false */
191 bool frame
, time
, reltime
, ctime
;
194 __u32
listen_events(struct nl80211_state
*state
,
195 const int n_waits
, const __u32
*waits
);
196 int __prepare_listen_events(struct nl80211_state
*state
);
197 __u32
__do_listen_events(struct nl80211_state
*state
,
198 const int n_waits
, const __u32
*waits
,
199 const int n_prints
, const __u32
*prints
,
200 struct print_event_args
*args
);
202 int valid_handler(struct nl_msg
*msg
, void *arg
);
203 void register_handler(int (*handler
)(struct nl_msg
*, void *), void *data
);
205 int mac_addr_a2n(unsigned char *mac_addr
, char *arg
);
206 void mac_addr_n2a(char *mac_addr
, const unsigned char *arg
);
207 int parse_hex_mask(char *hexmask
, unsigned char **result
, size_t *result_len
,
208 unsigned char **mask
);
209 unsigned char *parse_hex(char *hex
, size_t *outlen
);
211 int parse_keys(struct nl_msg
*msg
, char **argv
[], int *argc
);
212 int parse_freqchan(struct chandef
*chandef
, bool chan
, int argc
, char **argv
,
213 int *parsed
, bool freq_in_khz
);
214 enum nl80211_chan_width
str_to_bw(const char *str
);
215 int parse_txq_stats(char *buf
, int buflen
, struct nlattr
*tid_stats_attr
, int header
,
216 int tid
, const char *indent
);
217 int put_chandef(struct nl_msg
*msg
, struct chandef
*chandef
);
219 void print_ht_mcs(const __u8
*mcs
);
220 void print_ampdu_length(__u8 exponent
);
221 void print_ampdu_spacing(__u8 spacing
);
222 void print_ht_capability(__u16 cap
);
223 void print_vht_info(__u32 capa
, const __u8
*mcs
);
224 void print_he_capability(const uint8_t *ie
, int len
);
225 void print_he_info(struct nlattr
*nl_iftype
);
226 void print_eht_info(struct nlattr
*nl_iftype
, int band
);
227 void print_s1g_capability(const uint8_t *caps
);
229 char *channel_width_name(enum nl80211_chan_width width
);
230 const char *iftype_name(enum nl80211_iftype iftype
);
231 void print_iftype_list(const char *name
, const char *pfx
, struct nlattr
*attr
);
232 void print_iftype_line(struct nlattr
*attr
);
233 const char *command_name(enum nl80211_commands cmd
);
234 int ieee80211_channel_to_frequency(int chan
, enum nl80211_band band
);
235 int ieee80211_frequency_to_channel(int freq
);
237 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
);
239 int nl_get_multicast_id(struct nl_sock
*sock
, const char *family
, const char *group
);
241 char *reg_initiator_to_string(__u8 initiator
);
243 const char *get_reason_str(uint16_t reason
);
244 const char *get_status_str(uint16_t status
);
253 #define BIT(x) (1ULL<<(x))
255 void print_ies(unsigned char *ie
, int ielen
, bool unknown
,
256 enum print_ie_type ptype
);
258 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
);
259 void iw_hexdump(const char *prefix
, const __u8
*data
, size_t len
);
261 int get_cf1(const struct chanmode
*chanmode
, unsigned long freq
);
263 int parse_random_mac_addr(struct nl_msg
*msg
, char *addrs
);
265 char *s1g_ss_max_support(__u8 maxss
);
266 char *s1g_ss_min_support(__u8 minss
);
268 #define SCHED_SCAN_OPTIONS "[interval <in_msecs> | scan_plans [<interval_secs:iterations>*] <interval_secs>] " \
269 "[delay <in_secs>] [freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] " \
270 "[randomise[=<addr>/<mask>]] [coloc] [flush]"
271 int parse_sched_scan(struct nl_msg
*msg
, int *argc
, char ***argv
);
273 void nan_bf(uint8_t idx
, uint8_t *bf
, uint16_t bf_len
, const uint8_t *buf
,
276 char *hex2bin(const char *hex
, char *buf
);
278 int set_bitrates(struct nl_msg
*msg
, int argc
, char **argv
,
279 enum nl80211_attrs attr
);
281 int calc_s1g_ch_center_freq(__u8 ch_index
, __u8 s1g_oper_class
);
285 DECLARE_SECTION(auth
);
286 DECLARE_SECTION(cac
);
287 DECLARE_SECTION(channels
);
288 DECLARE_SECTION(coalesce
);
289 DECLARE_SECTION(commands
);
290 DECLARE_SECTION(connect
);
291 DECLARE_SECTION(cqm
);
292 DECLARE_SECTION(del
);
293 DECLARE_SECTION(dev
);
294 DECLARE_SECTION(disconnect
);
295 DECLARE_SECTION(event
);
296 DECLARE_SECTION(features
);
297 DECLARE_SECTION(ftm
);
298 DECLARE_SECTION(get
);
299 DECLARE_SECTION(help
);
300 DECLARE_SECTION(hwsim
);
301 DECLARE_SECTION(ibss
);
302 DECLARE_SECTION(info
);
303 DECLARE_SECTION(interface
);
304 DECLARE_SECTION(link
);
305 DECLARE_SECTION(list
);
306 DECLARE_SECTION(measurement
);
307 DECLARE_SECTION(mesh
);
308 DECLARE_SECTION(mesh_param
);
309 DECLARE_SECTION(mgmt
);
310 DECLARE_SECTION(mpath
);
311 DECLARE_SECTION(mpp
);
312 DECLARE_SECTION(nan
);
313 DECLARE_SECTION(ocb
);
314 DECLARE_SECTION(offchannel
);
315 DECLARE_SECTION(p2p
);
316 DECLARE_SECTION(phy
);
317 DECLARE_SECTION(reg
);
318 DECLARE_SECTION(roc
);
319 DECLARE_SECTION(scan
);
320 DECLARE_SECTION(set
);
321 DECLARE_SECTION(station
);
322 DECLARE_SECTION(survey
);
323 DECLARE_SECTION(switch);
324 DECLARE_SECTION(vendor
);
325 DECLARE_SECTION(wowlan
);