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