]> git.ipfire.org Git - thirdparty/iw.git/blob - iw.h
add link command
[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 #ifndef CONFIG_LIBNL20
15 # define nl_sock nl_handle
16 #endif
17
18 struct nl80211_state {
19 struct nl_sock *nl_sock;
20 struct nl_cache *nl_cache;
21 struct genl_family *nl80211;
22
23 const char *ifname;
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 *section;
41 const char *name;
42 const char *args;
43 const char *help;
44 const enum nl80211_commands cmd;
45 int nl_msg_flags;
46 int hidden;
47 const enum command_identify_by idby;
48 /*
49 * The handler should return a negative error code,
50 * zero on success, 1 if the arguments were wrong
51 * and the usage message should and 2 otherwise.
52 */
53 int (*handler)(struct nl80211_state *state,
54 struct nl_cb *cb,
55 struct nl_msg *msg,
56 int argc, char **argv);
57 };
58
59 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
60
61 #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help)\
62 static const struct cmd \
63 __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden\
64 __attribute__((used)) __attribute__((section("__cmd"))) = { \
65 .section = (_section), \
66 .name = (_name), \
67 .args = (_args), \
68 .cmd = (_nlcmd), \
69 .nl_msg_flags = (_flags), \
70 .hidden = (_hidden), \
71 .idby = (_idby), \
72 .handler = (_handler), \
73 .help = (_help), \
74 }
75 #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \
76 __COMMAND(#section, name, #name, args, cmd, flags, 0, idby, handler, help)
77 #define HIDDEN(section, name, args, cmd, flags, idby, handler) \
78 __COMMAND(#section, name, #name, args, cmd, flags, 1, idby, handler, NULL)
79 #define TOPLEVEL(name, args, cmd, flags, idby, handler, help) \
80 __COMMAND(NULL, name, #name, args, cmd, flags, 0, idby, handler, help)
81 extern struct cmd __start___cmd;
82 extern struct cmd __stop___cmd;
83
84 extern const char iw_version[];
85
86 extern int iw_debug;
87
88 int handle_cmd(struct nl80211_state *state, enum id_input idby,
89 int argc, char **argv);
90
91 struct print_event_args {
92 bool frame, time;
93 };
94
95 __u32 listen_events(struct nl80211_state *state,
96 const int n_waits, const __u32 *waits);
97 __u32 __listen_events(struct nl80211_state *state,
98 const int n_waits, const __u32 *waits,
99 struct print_event_args *args);
100
101
102 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
103 void mac_addr_n2a(char *mac_addr, unsigned char *arg);
104
105 int parse_keys(struct nl_msg *msg, char **argv, int argc);
106
107 const char *iftype_name(enum nl80211_iftype iftype);
108 int ieee80211_channel_to_frequency(int chan);
109 int ieee80211_frequency_to_channel(int freq);
110
111 void print_ssid_escaped(const uint8_t len, const uint8_t *data);
112
113 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
114
115 char *reg_initiator_to_string(__u8 initiator);
116
117 const char *get_reason_str(uint16_t reason);
118 const char *get_status_str(uint16_t status);
119
120 int set_interface_up(const char *ifname);
121
122 enum print_ie_type {
123 PRINT_SCAN,
124 PRINT_LINK,
125 };
126
127 #define BIT(x) (1ULL<<(x))
128
129 void print_ies(unsigned char *ie, int ielen, bool unknown,
130 enum print_ie_type ptype);
131
132 #endif /* __IW_H */