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