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