]> git.ipfire.org Git - thirdparty/iw.git/blame - iw.h
iw: fix off-by-one
[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
3d1e8704
LCC
14#define ETH_ALEN 6
15
ded667b0
YY
16/* libnl 1.x compatibility code */
17#if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30)
57077d64 18# define nl_sock nl_handle
dfd13ee5 19#endif
57077d64
PE
20
21struct nl80211_state {
22 struct nl_sock *nl_sock;
f09cee6d 23 int nl80211_id;
cad53b3f
JB
24};
25
bd396f2a
JB
26enum command_identify_by {
27 CIB_NONE,
28 CIB_PHY,
29 CIB_NETDEV,
290a3dd4 30 CIB_WDEV,
7c37a24d
JB
31};
32
33enum id_input {
34 II_NONE,
35 II_NETDEV,
36 II_PHY_NAME,
37 II_PHY_IDX,
290a3dd4 38 II_WDEV,
bd396f2a 39};
45c7212c 40
bd396f2a 41struct cmd {
bd396f2a
JB
42 const char *name;
43 const char *args;
01ae06f9 44 const char *help;
bd396f2a
JB
45 const enum nl80211_commands cmd;
46 int nl_msg_flags;
ce5af55c 47 int hidden;
bd396f2a 48 const enum command_identify_by idby;
5e75fd04
JB
49 /*
50 * The handler should return a negative error code,
51 * zero on success, 1 if the arguments were wrong
52 * and the usage message should and 2 otherwise.
53 */
7c37a24d 54 int (*handler)(struct nl80211_state *state,
bd396f2a 55 struct nl_msg *msg,
05514f95
JB
56 int argc, char **argv,
57 enum id_input id);
1633ddf7 58 const struct cmd *(*selector)(int argc, char **argv);
4698bfc2 59 const struct cmd *parent;
bd396f2a 60};
3d1e8704 61
7d736016 62#define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
3ff24563 63#define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
7d736016 64
1633ddf7 65#define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\
78bebb71 66 static struct cmd \
9b92e691
JB
67 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
68 __attribute__((used)) __attribute__((section("__cmd"))) = { \
9b92e691
JB
69 .name = (_name), \
70 .args = (_args), \
71 .cmd = (_nlcmd), \
72 .nl_msg_flags = (_flags), \
73 .hidden = (_hidden), \
74 .idby = (_idby), \
75 .handler = (_handler), \
01ae06f9 76 .help = (_help), \
4698bfc2 77 .parent = _section, \
1633ddf7
JB
78 .selector = (_sel), \
79 }
80#define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
81 __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
82 static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
01ae06f9 83#define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
1633ddf7
JB
84 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL)
85#define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\
86 __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias)
01ae06f9 87#define HIDDEN(section, name, args, cmd, flags, idby, handler) \
1633ddf7 88 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
4698bfc2
JB
89
90#define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
78bebb71 91 struct cmd \
4698bfc2
JB
92 __section ## _ ## _name \
93 __attribute__((used)) __attribute__((section("__cmd"))) = { \
94 .name = (#_name), \
95 .args = (_args), \
96 .cmd = (_nlcmd), \
97 .nl_msg_flags = (_flags), \
98 .idby = (_idby), \
99 .handler = (_handler), \
100 .help = (_help), \
101 }
102#define SECTION(_name) \
78bebb71 103 struct cmd __section ## _ ## _name \
4698bfc2
JB
104 __attribute__((used)) __attribute__((section("__cmd"))) = { \
105 .name = (#_name), \
106 .hidden = 1, \
107 }
108
109#define DECLARE_SECTION(_name) \
78bebb71 110 extern struct cmd __section ## _ ## _name;
14a0380d 111
133b069f 112extern const char iw_version[];
7c37a24d 113
957a0f07
JB
114extern int iw_debug;
115
7c37a24d
JB
116int handle_cmd(struct nl80211_state *state, enum id_input idby,
117 int argc, char **argv);
7fabd346
JB
118
119struct print_event_args {
981b21ad
JB
120 struct timeval ts; /* internal */
121 bool have_ts; /* must be set false */
122 bool frame, time, reltime;
7fabd346
JB
123};
124
72041aa0
JB
125__u32 listen_events(struct nl80211_state *state,
126 const int n_waits, const __u32 *waits);
ee374e4d
JB
127int __prepare_listen_events(struct nl80211_state *state);
128__u32 __do_listen_events(struct nl80211_state *state,
129 const int n_waits, const __u32 *waits,
130 struct print_event_args *args);
7c37a24d 131
34b23014
JB
132int valid_handler(struct nl_msg *msg, void *arg);
133void register_handler(int (*handler)(struct nl_msg *, void *), void *data);
7c37a24d 134
3d1e8704 135int mac_addr_a2n(unsigned char *mac_addr, char *arg);
febeb0c0 136void mac_addr_n2a(char *mac_addr, unsigned char *arg);
3ff24563
JB
137int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
138 unsigned char **mask);
236d4191 139unsigned char *parse_hex(char *hex, size_t *outlen);
3d1e8704 140
51e9bd80
JB
141int parse_keys(struct nl_msg *msg, char **argv, int argc);
142
7ddfb679 143void print_ht_mcs(const __u8 *mcs);
0950993f
LR
144void print_ampdu_length(__u8 exponent);
145void print_ampdu_spacing(__u8 spacing);
357c1a5d 146void print_ht_capability(__u16 cap);
54eb1613 147void print_vht_info(__u32 capa, const __u8 *mcs);
deb3501c 148
c5df9eb6 149char *channel_width_name(enum nl80211_chan_width width);
541ef425 150const char *iftype_name(enum nl80211_iftype iftype);
9990c1e9 151const char *command_name(enum nl80211_commands cmd);
58b46da2 152int ieee80211_channel_to_frequency(int chan, enum nl80211_band band);
379f8397 153int ieee80211_frequency_to_channel(int freq);
541ef425 154
748f8489
JB
155void print_ssid_escaped(const uint8_t len, const uint8_t *data);
156
57077d64 157int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
2c61ba61 158
601c6ab2
LR
159char *reg_initiator_to_string(__u8 initiator);
160
27c49ed6 161const char *get_reason_str(uint16_t reason);
22c7d879 162const char *get_status_str(uint16_t status);
27c49ed6 163
febeb0c0
JB
164enum print_ie_type {
165 PRINT_SCAN,
166 PRINT_LINK,
167};
168
169#define BIT(x) (1ULL<<(x))
170
171void print_ies(unsigned char *ie, int ielen, bool unknown,
172 enum print_ie_type ptype);
173
e94f0201 174void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
492354de 175void iw_hexdump(const char *prefix, const __u8 *data, size_t len);
4698bfc2 176
b1622287 177#define SCHED_SCAN_OPTIONS "interval <in_msecs> [delay <in_secs>] " \
5130bba0 178 "[freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] [randomise[=<addr>/<mask>]]"
b1622287
LC
179int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
180
4698bfc2
JB
181DECLARE_SECTION(set);
182DECLARE_SECTION(get);
183
cad53b3f 184#endif /* __IW_H */