]>
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 /* support for extack if compilation headers are too old */
15 #ifndef NETLINK_EXT_ACK
16 #define NETLINK_EXT_ACK 11
24 NLMSGERR_ATTR_MAX
= __NLMSGERR_ATTR_MAX
- 1
28 #define NLM_F_CAPPED 0x100
30 #ifndef NLM_F_ACK_TLVS
31 #define NLM_F_ACK_TLVS 0x200
34 #define SOL_NETLINK 270
38 #define VHT_MUMIMO_GROUP_LEN 24
40 /* libnl 1.x compatibility code */
41 #if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30)
42 # define nl_sock nl_handle
45 struct nl80211_state
{
46 struct nl_sock
*nl_sock
;
50 enum command_identify_by
{
65 #define HANDLER_RET_USAGE 1
66 #define HANDLER_RET_DONE 3
72 const enum nl80211_commands cmd
;
75 const enum command_identify_by idby
;
77 * The handler should return a negative error code,
78 * zero on success, 1 if the arguments were wrong.
79 * Return 2 iff you provide the error message yourself.
81 int (*handler
)(struct nl80211_state
*state
,
83 int argc
, char **argv
,
85 const struct cmd
*(*selector
)(int argc
, char **argv
);
86 const struct cmd
*parent
;
93 int chantype
; /* for older kernel */
97 enum nl80211_chan_width width
;
99 unsigned int control_freq
;
100 unsigned int center_freq1
;
101 unsigned int center_freq2
;
104 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
105 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
107 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\
109 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden = {\
113 .nl_msg_flags = (_flags), \
114 .hidden = (_hidden), \
116 .handler = (_handler), \
118 .parent = _section, \
119 .selector = (_sel), \
121 static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \
122 __attribute__((used,section("__cmd"))) = \
123 &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
124 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
125 __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
126 static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
127 #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
128 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL)
129 #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\
130 __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias)
131 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
132 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
134 #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
135 struct cmd __section ## _ ## _name = { \
139 .nl_msg_flags = (_flags), \
141 .handler = (_handler), \
144 static struct cmd *__section ## _ ## _name ## _p \
145 __attribute__((used,section("__cmd"))) = &__section ## _ ## _name
147 #define SECTION(_name) \
148 struct cmd __section ## _ ## _name = { \
152 static struct cmd *__section ## _ ## _name ## _p \
153 __attribute__((used,section("__cmd"))) = &__section ## _ ## _name
155 #define DECLARE_SECTION(_name) \
156 extern struct cmd __section ## _ ## _name;
158 extern const char iw_version
[];
162 int handle_cmd(struct nl80211_state
*state
, enum id_input idby
,
163 int argc
, char **argv
);
165 struct print_event_args
{
166 struct timeval ts
; /* internal */
167 bool have_ts
; /* must be set false */
168 bool frame
, time
, reltime
;
171 __u32
listen_events(struct nl80211_state
*state
,
172 const int n_waits
, const __u32
*waits
);
173 int __prepare_listen_events(struct nl80211_state
*state
);
174 __u32
__do_listen_events(struct nl80211_state
*state
,
175 const int n_waits
, const __u32
*waits
,
176 const int n_prints
, const __u32
*prints
,
177 struct print_event_args
*args
);
179 int valid_handler(struct nl_msg
*msg
, void *arg
);
180 void register_handler(int (*handler
)(struct nl_msg
*, void *), void *data
);
182 int mac_addr_a2n(unsigned char *mac_addr
, char *arg
);
183 void mac_addr_n2a(char *mac_addr
, const unsigned char *arg
);
184 int parse_hex_mask(char *hexmask
, unsigned char **result
, size_t *result_len
,
185 unsigned char **mask
);
186 unsigned char *parse_hex(char *hex
, size_t *outlen
);
188 int parse_keys(struct nl_msg
*msg
, char **argv
[], int *argc
);
189 int parse_freqchan(struct chandef
*chandef
, bool chan
, int argc
, char **argv
, int *parsed
);
190 enum nl80211_chan_width
str_to_bw(const char *str
);
191 int parse_txq_stats(char *buf
, int buflen
, struct nlattr
*tid_stats_attr
, int header
,
192 int tid
, const char *indent
);
193 int put_chandef(struct nl_msg
*msg
, struct chandef
*chandef
);
195 void print_ht_mcs(const __u8
*mcs
);
196 void print_ampdu_length(__u8 exponent
);
197 void print_ampdu_spacing(__u8 spacing
);
198 void print_ht_capability(__u16 cap
);
199 void print_vht_info(__u32 capa
, const __u8
*mcs
);
200 void print_he_info(struct nlattr
*nl_iftype
);
202 char *channel_width_name(enum nl80211_chan_width width
);
203 const char *iftype_name(enum nl80211_iftype iftype
);
204 const char *command_name(enum nl80211_commands cmd
);
205 int ieee80211_channel_to_frequency(int chan
, enum nl80211_band band
);
206 int ieee80211_frequency_to_channel(int freq
);
208 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
);
210 int nl_get_multicast_id(struct nl_sock
*sock
, const char *family
, const char *group
);
212 char *reg_initiator_to_string(__u8 initiator
);
214 const char *get_reason_str(uint16_t reason
);
215 const char *get_status_str(uint16_t status
);
222 #define BIT(x) (1ULL<<(x))
224 void print_ies(unsigned char *ie
, int ielen
, bool unknown
,
225 enum print_ie_type ptype
);
227 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
);
228 void iw_hexdump(const char *prefix
, const __u8
*data
, size_t len
);
230 int get_cf1(const struct chanmode
*chanmode
, unsigned long freq
);
232 int parse_random_mac_addr(struct nl_msg
*msg
, char *addrs
);
234 #define SCHED_SCAN_OPTIONS "[interval <in_msecs> | scan_plans [<interval_secs:iterations>*] <interval_secs>] " \
235 "[delay <in_secs>] [freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] " \
236 "[randomise[=<addr>/<mask>]]"
237 int parse_sched_scan(struct nl_msg
*msg
, int *argc
, char ***argv
);
239 DECLARE_SECTION(switch);
240 DECLARE_SECTION(set
);
241 DECLARE_SECTION(get
);
243 void nan_bf(uint8_t idx
, uint8_t *bf
, uint16_t bf_len
, const uint8_t *buf
,
246 char *hex2bin(const char *hex
, char *buf
);