]> git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
use C99 initialiser for cmd struct
[thirdparty/iw.git] / iw.h
1 #ifndef __IW_H
2 #define __IW_H
3
4 #include <netlink/netlink.h>
5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8
9 #include "nl80211.h"
10
11 #define ETH_ALEN 6
12
13 #ifndef CONFIG_LIBNL20
14 # define nl_sock nl_handle
15 #endif
16
17 struct nl80211_state {
18 struct nl_sock *nl_sock;
19 struct nl_cache *nl_cache;
20 struct genl_family *nl80211;
21 };
22
23 enum command_identify_by {
24 CIB_NONE,
25 CIB_PHY,
26 CIB_NETDEV,
27 };
28
29 enum id_input {
30 II_NONE,
31 II_NETDEV,
32 II_PHY_NAME,
33 II_PHY_IDX,
34 };
35
36 struct cmd {
37 const char *section;
38 const char *name;
39 const char *args;
40 const enum nl80211_commands cmd;
41 int nl_msg_flags;
42 int hidden;
43 const enum command_identify_by idby;
44 /*
45 * The handler should return a negative error code,
46 * zero on success, 1 if the arguments were wrong
47 * and the usage message should and 2 otherwise.
48 */
49 int (*handler)(struct nl80211_state *state,
50 struct nl_cb *cb,
51 struct nl_msg *msg,
52 int argc, char **argv);
53 };
54
55 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
56
57 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler)\
58 static const struct cmd \
59 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
60 __attribute__((used)) __attribute__((section("__cmd"))) = { \
61 .section = (_section), \
62 .name = (_name), \
63 .args = (_args), \
64 .cmd = (_nlcmd), \
65 .nl_msg_flags = (_flags), \
66 .hidden = (_hidden), \
67 .idby = (_idby), \
68 .handler = (_handler), \
69 }
70 #define COMMAND(section, name, args, cmd, flags, idby, handler) \
71 __COMMAND(#section, name, #name, args, cmd, flags, 0, idby, handler)
72 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
73 __COMMAND(#section, name, #name, args, cmd, flags, 1, idby, handler)
74 #define TOPLEVEL(name, args, cmd, flags, idby, handler) \
75 __COMMAND(NULL, name, #name, args, cmd, flags, 0, idby, handler)
76 extern struct cmd __start___cmd;
77 extern struct cmd __stop___cmd;
78
79 extern const char iw_version[];
80
81 extern int iw_debug;
82
83 int handle_cmd(struct nl80211_state *state, enum id_input idby,
84 int argc, char **argv);
85 __u32 listen_events(struct nl80211_state *state,
86 const int n_waits, const __u32 *waits);
87
88
89 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
90 int mac_addr_n2a(char *mac_addr, unsigned char *arg);
91
92 const char *iftype_name(enum nl80211_iftype iftype);
93 int ieee80211_channel_to_frequency(int chan);
94 int ieee80211_frequency_to_channel(int freq);
95
96 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
97
98 char *reg_initiator_to_string(__u8 initiator);
99
100 const char *get_reason_str(uint16_t reason);
101 const char *get_status_str(uint16_t status);
102
103 #endif /* __IW_H */