]> git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
315a145728a3cdd781f70a74bbaad4ab27fbb206
[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 CIB_NETDEV_RAW,
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 *section;
39 const char *name;
40 const char *args;
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 };
55
56 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
57
58 #define __COMMAND(sect, name, args, nlcmd, flags, hidden, idby, handler)\
59 static const struct cmd \
60 __cmd_ ## handler ## _ ## nlcmd ## _ ## idby ## _ ## hidden \
61 __attribute__((used)) __attribute__((section("__cmd"))) \
62 = { sect, name, args, nlcmd, flags, hidden, idby, handler }
63 #define COMMAND(section, name, args, cmd, flags, idby, handler) \
64 __COMMAND(#section, #name, args, cmd, flags, 0, idby, handler)
65 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
66 __COMMAND(#section, #name, args, cmd, flags, 1, idby, handler)
67 #define TOPLEVEL(name, args, cmd, flags, idby, handler) \
68 __COMMAND(NULL, #name, args, cmd, flags, 0, idby, handler)
69 extern struct cmd __start___cmd;
70 extern struct cmd __stop___cmd;
71
72
73 int handle_cmd(struct nl80211_state *state, enum id_input idby,
74 int argc, char **argv);
75
76
77 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
78 int mac_addr_n2a(char *mac_addr, unsigned char *arg);
79
80 const char *iftype_name(enum nl80211_iftype iftype);
81 int ieee80211_channel_to_frequency(int chan);
82 int ieee80211_frequency_to_channel(int freq);
83
84 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
85
86 char *reg_initiator_to_string(__u8 initiator);
87
88 #endif /* __IW_H */