]> git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
3379a7fd673bca5fe7f08cf75dd25f917d79a2dd
[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 };
31
32 enum id_input {
33 II_NONE,
34 II_NETDEV,
35 II_PHY_NAME,
36 II_PHY_IDX,
37 };
38
39 struct cmd {
40 const char *name;
41 const char *args;
42 const char *help;
43 const enum nl80211_commands cmd;
44 int nl_msg_flags;
45 int hidden;
46 const enum command_identify_by idby;
47 /*
48 * The handler should return a negative error code,
49 * zero on success, 1 if the arguments were wrong
50 * and the usage message should and 2 otherwise.
51 */
52 int (*handler)(struct nl80211_state *state,
53 struct nl_cb *cb,
54 struct nl_msg *msg,
55 int argc, char **argv);
56 const struct cmd *(*selector)(int argc, char **argv);
57 const struct cmd *parent;
58 };
59
60 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
61 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
62
63 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\
64 static struct cmd \
65 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
66 __attribute__((used)) __attribute__((section("__cmd"))) = { \
67 .name = (_name), \
68 .args = (_args), \
69 .cmd = (_nlcmd), \
70 .nl_msg_flags = (_flags), \
71 .hidden = (_hidden), \
72 .idby = (_idby), \
73 .handler = (_handler), \
74 .help = (_help), \
75 .parent = _section, \
76 .selector = (_sel), \
77 }
78 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
79 __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
80 static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
81 #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
82 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL)
83 #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\
84 __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias)
85 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
86 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL)
87
88 #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
89 struct cmd \
90 __section ## _ ## _name \
91 __attribute__((used)) __attribute__((section("__cmd"))) = { \
92 .name = (#_name), \
93 .args = (_args), \
94 .cmd = (_nlcmd), \
95 .nl_msg_flags = (_flags), \
96 .idby = (_idby), \
97 .handler = (_handler), \
98 .help = (_help), \
99 }
100 #define SECTION(_name) \
101 struct cmd __section ## _ ## _name \
102 __attribute__((used)) __attribute__((section("__cmd"))) = { \
103 .name = (#_name), \
104 .hidden = 1, \
105 }
106
107 #define DECLARE_SECTION(_name) \
108 extern struct cmd __section ## _ ## _name;
109
110 extern const char iw_version[];
111
112 extern int iw_debug;
113
114 int handle_cmd(struct nl80211_state *state, enum id_input idby,
115 int argc, char **argv);
116
117 struct print_event_args {
118 struct timeval ts; /* internal */
119 bool have_ts; /* must be set false */
120 bool frame, time, reltime;
121 };
122
123 __u32 listen_events(struct nl80211_state *state,
124 const int n_waits, const __u32 *waits);
125 int __prepare_listen_events(struct nl80211_state *state);
126 __u32 __do_listen_events(struct nl80211_state *state,
127 const int n_waits, const __u32 *waits,
128 struct print_event_args *args);
129
130
131 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
132 void mac_addr_n2a(char *mac_addr, unsigned char *arg);
133 int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
134 unsigned char **mask);
135 unsigned char *parse_hex(char *hex, size_t *outlen);
136
137 int parse_keys(struct nl_msg *msg, char **argv, int argc);
138
139 void print_ht_mcs(const __u8 *mcs);
140 void print_ampdu_length(__u8 exponent);
141 void print_ampdu_spacing(__u8 spacing);
142 void print_ht_capability(__u16 cap);
143
144 const char *iftype_name(enum nl80211_iftype iftype);
145 const char *command_name(enum nl80211_commands cmd);
146 int ieee80211_channel_to_frequency(int chan);
147 int ieee80211_frequency_to_channel(int freq);
148
149 void print_ssid_escaped(const uint8_t len, const uint8_t *data);
150
151 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
152
153 char *reg_initiator_to_string(__u8 initiator);
154
155 const char *get_reason_str(uint16_t reason);
156 const char *get_status_str(uint16_t status);
157
158 enum print_ie_type {
159 PRINT_SCAN,
160 PRINT_LINK,
161 };
162
163 #define BIT(x) (1ULL<<(x))
164
165 void print_ies(unsigned char *ie, int ielen, bool unknown,
166 enum print_ie_type ptype);
167
168
169 DECLARE_SECTION(set);
170 DECLARE_SECTION(get);
171
172 #endif /* __IW_H */