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