]> git.ipfire.org Git - thirdparty/iw.git/blame - iw.h
iw: Add antenna configuration commands
[thirdparty/iw.git] / iw.h
CommitLineData
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>
9
f408e01b
JB
10#include "nl80211.h"
11
3d1e8704
LCC
12#define ETH_ALEN 6
13
57077d64
PE
14#ifndef CONFIG_LIBNL20
15# define nl_sock nl_handle
dfd13ee5 16#endif
57077d64
PE
17
18struct nl80211_state {
19 struct nl_sock *nl_sock;
cad53b3f
JB
20 struct nl_cache *nl_cache;
21 struct genl_family *nl80211;
22};
23
bd396f2a
JB
24enum command_identify_by {
25 CIB_NONE,
26 CIB_PHY,
27 CIB_NETDEV,
7c37a24d
JB
28};
29
30enum id_input {
31 II_NONE,
32 II_NETDEV,
33 II_PHY_NAME,
34 II_PHY_IDX,
bd396f2a 35};
45c7212c 36
bd396f2a 37struct cmd {
bd396f2a
JB
38 const char *name;
39 const char *args;
01ae06f9 40 const char *help;
bd396f2a
JB
41 const enum nl80211_commands cmd;
42 int nl_msg_flags;
ce5af55c 43 int hidden;
bd396f2a 44 const enum command_identify_by idby;
5e75fd04
JB
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 */
7c37a24d
JB
50 int (*handler)(struct nl80211_state *state,
51 struct nl_cb *cb,
bd396f2a
JB
52 struct nl_msg *msg,
53 int argc, char **argv);
4698bfc2 54 const struct cmd *parent;
bd396f2a 55};
3d1e8704 56
7d736016
JB
57#define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
58
01ae06f9 59#define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help)\
78bebb71 60 static struct cmd \
9b92e691
JB
61 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
62 __attribute__((used)) __attribute__((section("__cmd"))) = { \
9b92e691
JB
63 .name = (_name), \
64 .args = (_args), \
65 .cmd = (_nlcmd), \
66 .nl_msg_flags = (_flags), \
67 .hidden = (_hidden), \
68 .idby = (_idby), \
69 .handler = (_handler), \
01ae06f9 70 .help = (_help), \
4698bfc2 71 .parent = _section, \
9b92e691 72 }
01ae06f9 73#define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
4698bfc2 74 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help)
01ae06f9 75#define HIDDEN(section, name, args, cmd, flags, idby, handler) \
4698bfc2
JB
76 __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL)
77
78#define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \
78bebb71 79 struct cmd \
4698bfc2
JB
80 __section ## _ ## _name \
81 __attribute__((used)) __attribute__((section("__cmd"))) = { \
82 .name = (#_name), \
83 .args = (_args), \
84 .cmd = (_nlcmd), \
85 .nl_msg_flags = (_flags), \
86 .idby = (_idby), \
87 .handler = (_handler), \
88 .help = (_help), \
89 }
90#define SECTION(_name) \
78bebb71 91 struct cmd __section ## _ ## _name \
4698bfc2
JB
92 __attribute__((used)) __attribute__((section("__cmd"))) = { \
93 .name = (#_name), \
94 .hidden = 1, \
95 }
96
97#define DECLARE_SECTION(_name) \
78bebb71 98 extern struct cmd __section ## _ ## _name;
14a0380d 99
133b069f 100extern const char iw_version[];
7c37a24d 101
957a0f07
JB
102extern int iw_debug;
103
7c37a24d
JB
104int handle_cmd(struct nl80211_state *state, enum id_input idby,
105 int argc, char **argv);
7fabd346
JB
106
107struct print_event_args {
981b21ad
JB
108 struct timeval ts; /* internal */
109 bool have_ts; /* must be set false */
110 bool frame, time, reltime;
7fabd346
JB
111};
112
72041aa0
JB
113__u32 listen_events(struct nl80211_state *state,
114 const int n_waits, const __u32 *waits);
ee374e4d
JB
115int __prepare_listen_events(struct nl80211_state *state);
116__u32 __do_listen_events(struct nl80211_state *state,
117 const int n_waits, const __u32 *waits,
118 struct print_event_args *args);
7c37a24d
JB
119
120
3d1e8704 121int mac_addr_a2n(unsigned char *mac_addr, char *arg);
febeb0c0 122void mac_addr_n2a(char *mac_addr, unsigned char *arg);
236d4191 123unsigned char *parse_hex(char *hex, size_t *outlen);
3d1e8704 124
51e9bd80
JB
125int parse_keys(struct nl_msg *msg, char **argv, int argc);
126
7ddfb679 127void print_ht_mcs(const __u8 *mcs);
0950993f
LR
128void print_ampdu_length(__u8 exponent);
129void print_ampdu_spacing(__u8 spacing);
357c1a5d 130void print_ht_capability(__u16 cap);
deb3501c 131
541ef425 132const char *iftype_name(enum nl80211_iftype iftype);
9990c1e9 133const char *command_name(enum nl80211_commands cmd);
379f8397
JB
134int ieee80211_channel_to_frequency(int chan);
135int ieee80211_frequency_to_channel(int freq);
541ef425 136
748f8489
JB
137void print_ssid_escaped(const uint8_t len, const uint8_t *data);
138
57077d64 139int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
2c61ba61 140
601c6ab2
LR
141char *reg_initiator_to_string(__u8 initiator);
142
27c49ed6 143const char *get_reason_str(uint16_t reason);
22c7d879 144const char *get_status_str(uint16_t status);
27c49ed6 145
febeb0c0
JB
146enum print_ie_type {
147 PRINT_SCAN,
148 PRINT_LINK,
149};
150
151#define BIT(x) (1ULL<<(x))
152
153void print_ies(unsigned char *ie, int ielen, bool unknown,
154 enum print_ie_type ptype);
155
4698bfc2
JB
156
157DECLARE_SECTION(set);
158DECLARE_SECTION(get);
159
cad53b3f 160#endif /* __IW_H */