1*92022041SSam Saccone #ifndef __IW_H 2*92022041SSam Saccone #define __IW_H 3*92022041SSam Saccone 4*92022041SSam Saccone #include <stdbool.h> 5*92022041SSam Saccone #include <netlink/netlink.h> 6*92022041SSam Saccone #include <netlink/genl/genl.h> 7*92022041SSam Saccone #include <netlink/genl/family.h> 8*92022041SSam Saccone #include <netlink/genl/ctrl.h> 9*92022041SSam Saccone #include <endian.h> 10*92022041SSam Saccone 11*92022041SSam Saccone #include "nl80211.h" 12*92022041SSam Saccone #include "ieee80211.h" 13*92022041SSam Saccone 14*92022041SSam Saccone #ifndef NL_CAPABILITY_VERSION_3_5_0 15*92022041SSam Saccone #define nla_nest_start(msg, attrtype) \ 16*92022041SSam Saccone nla_nest_start(msg, NLA_F_NESTED | (attrtype)) 17*92022041SSam Saccone #endif 18*92022041SSam Saccone 19*92022041SSam Saccone /* support for extack if compilation headers are too old */ 20*92022041SSam Saccone #ifndef NETLINK_EXT_ACK 21*92022041SSam Saccone #define NETLINK_EXT_ACK 11 22*92022041SSam Saccone enum nlmsgerr_attrs { 23*92022041SSam Saccone NLMSGERR_ATTR_UNUSED, 24*92022041SSam Saccone NLMSGERR_ATTR_MSG, 25*92022041SSam Saccone NLMSGERR_ATTR_OFFS, 26*92022041SSam Saccone NLMSGERR_ATTR_COOKIE, 27*92022041SSam Saccone 28*92022041SSam Saccone __NLMSGERR_ATTR_MAX, 29*92022041SSam Saccone NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 30*92022041SSam Saccone }; 31*92022041SSam Saccone #endif 32*92022041SSam Saccone #ifndef NLM_F_CAPPED 33*92022041SSam Saccone #define NLM_F_CAPPED 0x100 34*92022041SSam Saccone #endif 35*92022041SSam Saccone #ifndef NLM_F_ACK_TLVS 36*92022041SSam Saccone #define NLM_F_ACK_TLVS 0x200 37*92022041SSam Saccone #endif 38*92022041SSam Saccone #ifndef SOL_NETLINK 39*92022041SSam Saccone #define SOL_NETLINK 270 40*92022041SSam Saccone #endif 41*92022041SSam Saccone 42*92022041SSam Saccone #define ETH_ALEN 6 43*92022041SSam Saccone #define VHT_MUMIMO_GROUP_LEN 24 44*92022041SSam Saccone 45*92022041SSam Saccone /* libnl 1.x compatibility code */ 46*92022041SSam Saccone #if !defined(CONFIG_LIBNL20) && !defined(CONFIG_LIBNL30) 47*92022041SSam Saccone # define nl_sock nl_handle 48*92022041SSam Saccone #endif 49*92022041SSam Saccone 50*92022041SSam Saccone struct nl80211_state { 51*92022041SSam Saccone struct nl_sock *nl_sock; 52*92022041SSam Saccone int nl80211_id; 53*92022041SSam Saccone }; 54*92022041SSam Saccone 55*92022041SSam Saccone enum command_identify_by { 56*92022041SSam Saccone CIB_NONE, 57*92022041SSam Saccone CIB_PHY, 58*92022041SSam Saccone CIB_NETDEV, 59*92022041SSam Saccone CIB_WDEV, 60*92022041SSam Saccone }; 61*92022041SSam Saccone 62*92022041SSam Saccone enum id_input { 63*92022041SSam Saccone II_NONE, 64*92022041SSam Saccone II_NETDEV, 65*92022041SSam Saccone II_PHY_NAME, 66*92022041SSam Saccone II_PHY_IDX, 67*92022041SSam Saccone II_WDEV, 68*92022041SSam Saccone }; 69*92022041SSam Saccone 70*92022041SSam Saccone #define HANDLER_RET_USAGE 1 71*92022041SSam Saccone #define HANDLER_RET_DONE 3 72*92022041SSam Saccone 73*92022041SSam Saccone struct cmd { 74*92022041SSam Saccone const char *name; 75*92022041SSam Saccone const char *args; 76*92022041SSam Saccone const char *help; 77*92022041SSam Saccone const enum nl80211_commands cmd; 78*92022041SSam Saccone int nl_msg_flags; 79*92022041SSam Saccone int hidden; 80*92022041SSam Saccone const enum command_identify_by idby; 81*92022041SSam Saccone /* 82*92022041SSam Saccone * The handler should return a negative error code, 83*92022041SSam Saccone * zero on success, 1 if the arguments were wrong. 84*92022041SSam Saccone * Return 2 iff you provide the error message yourself. 85*92022041SSam Saccone */ 86*92022041SSam Saccone int (*handler)(struct nl80211_state *state, 87*92022041SSam Saccone struct nl_msg *msg, 88*92022041SSam Saccone int argc, char **argv, 89*92022041SSam Saccone enum id_input id); 90*92022041SSam Saccone const struct cmd *(*selector)(int argc, char **argv); 91*92022041SSam Saccone const struct cmd *parent; 92*92022041SSam Saccone }; 93*92022041SSam Saccone 94*92022041SSam Saccone struct chanmode { 95*92022041SSam Saccone const char *name; 96*92022041SSam Saccone unsigned int width; 97*92022041SSam Saccone int freq1_diff; 98*92022041SSam Saccone int chantype; /* for older kernel */ 99*92022041SSam Saccone }; 100*92022041SSam Saccone 101*92022041SSam Saccone struct chandef { 102*92022041SSam Saccone enum nl80211_chan_width width; 103*92022041SSam Saccone 104*92022041SSam Saccone unsigned int control_freq; 105*92022041SSam Saccone unsigned int center_freq1; 106*92022041SSam Saccone unsigned int center_freq2; 107*92022041SSam Saccone }; 108*92022041SSam Saccone 109*92022041SSam Saccone #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0])) 110*92022041SSam Saccone #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y)) 111*92022041SSam Saccone 112*92022041SSam Saccone #define __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel)\ 113*92022041SSam Saccone static struct cmd \ 114*92022041SSam Saccone __cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden = {\ 115*92022041SSam Saccone .name = (_name), \ 116*92022041SSam Saccone .args = (_args), \ 117*92022041SSam Saccone .cmd = (_nlcmd), \ 118*92022041SSam Saccone .nl_msg_flags = (_flags), \ 119*92022041SSam Saccone .hidden = (_hidden), \ 120*92022041SSam Saccone .idby = (_idby), \ 121*92022041SSam Saccone .handler = (_handler), \ 122*92022041SSam Saccone .help = (_help), \ 123*92022041SSam Saccone .parent = _section, \ 124*92022041SSam Saccone .selector = (_sel), \ 125*92022041SSam Saccone }; \ 126*92022041SSam Saccone static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \ 127*92022041SSam Saccone __attribute__((used,section("__cmd"))) = \ 128*92022041SSam Saccone &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden 129*92022041SSam Saccone #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\ 130*92022041SSam Saccone __COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\ 131*92022041SSam Saccone static const struct cmd *_alias = &__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden 132*92022041SSam Saccone #define COMMAND(section, name, args, cmd, flags, idby, handler, help) \ 133*92022041SSam Saccone __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, NULL) 134*92022041SSam Saccone #define COMMAND_ALIAS(section, name, args, cmd, flags, idby, handler, help, selector, alias)\ 135*92022041SSam Saccone __ACMD(&(__section ## _ ## section), name, #name, args, cmd, flags, 0, idby, handler, help, selector, alias) 136*92022041SSam Saccone #define HIDDEN(section, name, args, cmd, flags, idby, handler) \ 137*92022041SSam Saccone __COMMAND(&(__section ## _ ## section), name, #name, args, cmd, flags, 1, idby, handler, NULL, NULL) 138*92022041SSam Saccone 139*92022041SSam Saccone #define TOPLEVEL(_name, _args, _nlcmd, _flags, _idby, _handler, _help) \ 140*92022041SSam Saccone struct cmd __section ## _ ## _name = { \ 141*92022041SSam Saccone .name = (#_name), \ 142*92022041SSam Saccone .args = (_args), \ 143*92022041SSam Saccone .cmd = (_nlcmd), \ 144*92022041SSam Saccone .nl_msg_flags = (_flags), \ 145*92022041SSam Saccone .idby = (_idby), \ 146*92022041SSam Saccone .handler = (_handler), \ 147*92022041SSam Saccone .help = (_help), \ 148*92022041SSam Saccone }; \ 149*92022041SSam Saccone static struct cmd *__section ## _ ## _name ## _p \ 150*92022041SSam Saccone __attribute__((used,section("__cmd"))) = &__section ## _ ## _name 151*92022041SSam Saccone 152*92022041SSam Saccone #define SECTION(_name) \ 153*92022041SSam Saccone struct cmd __section ## _ ## _name = { \ 154*92022041SSam Saccone .name = (#_name), \ 155*92022041SSam Saccone .hidden = 1, \ 156*92022041SSam Saccone }; \ 157*92022041SSam Saccone static struct cmd *__section ## _ ## _name ## _p \ 158*92022041SSam Saccone __attribute__((used,section("__cmd"))) = &__section ## _ ## _name 159*92022041SSam Saccone 160*92022041SSam Saccone #define DECLARE_SECTION(_name) \ 161*92022041SSam Saccone extern struct cmd __section ## _ ## _name; 162*92022041SSam Saccone 163*92022041SSam Saccone struct vendor_event { 164*92022041SSam Saccone unsigned int vendor_id, subcmd; 165*92022041SSam Saccone void (*callback)(unsigned int vendor_id, unsigned int subcmd, 166*92022041SSam Saccone struct nlattr *data); 167*92022041SSam Saccone }; 168*92022041SSam Saccone 169*92022041SSam Saccone #define VENDOR_EVENT(_id, _subcmd, _callback) \ 170*92022041SSam Saccone static const struct vendor_event \ 171*92022041SSam Saccone vendor_event_ ## _id ## _ ## _subcmd = { \ 172*92022041SSam Saccone .vendor_id = _id, \ 173*92022041SSam Saccone .subcmd = _subcmd, \ 174*92022041SSam Saccone .callback = _callback, \ 175*92022041SSam Saccone }, * const vendor_event_ ## _id ## _ ## _subcmd ## _p \ 176*92022041SSam Saccone __attribute__((used,section("vendor_event"))) = \ 177*92022041SSam Saccone &vendor_event_ ## _id ## _ ## _subcmd 178*92022041SSam Saccone 179*92022041SSam Saccone extern const char iw_version[]; 180*92022041SSam Saccone 181*92022041SSam Saccone extern int iw_debug; 182*92022041SSam Saccone 183*92022041SSam Saccone int handle_cmd(struct nl80211_state *state, enum id_input idby, 184*92022041SSam Saccone int argc, char **argv); 185*92022041SSam Saccone 186*92022041SSam Saccone struct print_event_args { 187*92022041SSam Saccone struct timeval ts; /* internal */ 188*92022041SSam Saccone bool have_ts; /* must be set false */ 189*92022041SSam Saccone bool frame, time, reltime, ctime; 190*92022041SSam Saccone }; 191*92022041SSam Saccone 192*92022041SSam Saccone __u32 listen_events(struct nl80211_state *state, 193*92022041SSam Saccone const int n_waits, const __u32 *waits); 194*92022041SSam Saccone int __prepare_listen_events(struct nl80211_state *state); 195*92022041SSam Saccone __u32 __do_listen_events(struct nl80211_state *state, 196*92022041SSam Saccone const int n_waits, const __u32 *waits, 197*92022041SSam Saccone const int n_prints, const __u32 *prints, 198*92022041SSam Saccone struct print_event_args *args); 199*92022041SSam Saccone 200*92022041SSam Saccone int valid_handler(struct nl_msg *msg, void *arg); 201*92022041SSam Saccone void register_handler(int (*handler)(struct nl_msg *, void *), void *data); 202*92022041SSam Saccone 203*92022041SSam Saccone int mac_addr_a2n(unsigned char *mac_addr, char *arg); 204*92022041SSam Saccone void mac_addr_n2a(char *mac_addr, const unsigned char *arg); 205*92022041SSam Saccone int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len, 206*92022041SSam Saccone unsigned char **mask); 207*92022041SSam Saccone unsigned char *parse_hex(char *hex, size_t *outlen); 208*92022041SSam Saccone 209*92022041SSam Saccone int parse_keys(struct nl_msg *msg, char **argv[], int *argc); 210*92022041SSam Saccone int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv, int *parsed); 211*92022041SSam Saccone enum nl80211_chan_width str_to_bw(const char *str); 212*92022041SSam Saccone int parse_txq_stats(char *buf, int buflen, struct nlattr *tid_stats_attr, int header, 213*92022041SSam Saccone int tid, const char *indent); 214*92022041SSam Saccone int put_chandef(struct nl_msg *msg, struct chandef *chandef); 215*92022041SSam Saccone 216*92022041SSam Saccone void print_ht_mcs(const __u8 *mcs); 217*92022041SSam Saccone void print_ampdu_length(__u8 exponent); 218*92022041SSam Saccone void print_ampdu_spacing(__u8 spacing); 219*92022041SSam Saccone void print_ht_capability(__u16 cap); 220*92022041SSam Saccone void print_vht_info(__u32 capa, const __u8 *mcs); 221*92022041SSam Saccone void print_he_capability(const uint8_t *ie, int len); 222*92022041SSam Saccone void print_he_info(struct nlattr *nl_iftype); 223*92022041SSam Saccone void print_eht_info(struct nlattr *nl_iftype, int band); 224*92022041SSam Saccone 225*92022041SSam Saccone char *channel_width_name(enum nl80211_chan_width width); 226*92022041SSam Saccone const char *iftype_name(enum nl80211_iftype iftype); 227*92022041SSam Saccone void print_iftype_list(const char *name, const char *pfx, struct nlattr *attr); 228*92022041SSam Saccone void print_iftype_line(struct nlattr *attr); 229*92022041SSam Saccone const char *command_name(enum nl80211_commands cmd); 230*92022041SSam Saccone int ieee80211_channel_to_frequency(int chan, enum nl80211_band band); 231*92022041SSam Saccone int ieee80211_frequency_to_channel(int freq); 232*92022041SSam Saccone 233*92022041SSam Saccone void print_ssid_escaped(const uint8_t len, const uint8_t *data); 234*92022041SSam Saccone 235*92022041SSam Saccone int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group); 236*92022041SSam Saccone 237*92022041SSam Saccone char *reg_initiator_to_string(__u8 initiator); 238*92022041SSam Saccone 239*92022041SSam Saccone const char *get_reason_str(uint16_t reason); 240*92022041SSam Saccone const char *get_status_str(uint16_t status); 241*92022041SSam Saccone 242*92022041SSam Saccone enum print_ie_type { 243*92022041SSam Saccone PRINT_SCAN, 244*92022041SSam Saccone PRINT_LINK, 245*92022041SSam Saccone }; 246*92022041SSam Saccone 247*92022041SSam Saccone #define BIT(x) (1ULL<<(x)) 248*92022041SSam Saccone 249*92022041SSam Saccone void print_ies(unsigned char *ie, int ielen, bool unknown, 250*92022041SSam Saccone enum print_ie_type ptype); 251*92022041SSam Saccone 252*92022041SSam Saccone void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen); 253*92022041SSam Saccone void iw_hexdump(const char *prefix, const __u8 *data, size_t len); 254*92022041SSam Saccone 255*92022041SSam Saccone int get_cf1(const struct chanmode *chanmode, unsigned long freq); 256*92022041SSam Saccone 257*92022041SSam Saccone int parse_random_mac_addr(struct nl_msg *msg, char *addrs); 258*92022041SSam Saccone 259*92022041SSam Saccone #define SCHED_SCAN_OPTIONS "[interval <in_msecs> | scan_plans [<interval_secs:iterations>*] <interval_secs>] " \ 260*92022041SSam Saccone "[delay <in_secs>] [freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] " \ 261*92022041SSam Saccone "[randomise[=<addr>/<mask>]] [coloc] [flush]" 262*92022041SSam Saccone int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv); 263*92022041SSam Saccone 264*92022041SSam Saccone void nan_bf(uint8_t idx, uint8_t *bf, uint16_t bf_len, const uint8_t *buf, 265*92022041SSam Saccone size_t len); 266*92022041SSam Saccone 267*92022041SSam Saccone char *hex2bin(const char *hex, char *buf); 268*92022041SSam Saccone 269*92022041SSam Saccone int set_bitrates(struct nl_msg *msg, int argc, char **argv, 270*92022041SSam Saccone enum nl80211_attrs attr); 271*92022041SSam Saccone 272*92022041SSam Saccone 273*92022041SSam Saccone /* sections */ 274*92022041SSam Saccone DECLARE_SECTION(ap); 275*92022041SSam Saccone DECLARE_SECTION(auth); 276*92022041SSam Saccone DECLARE_SECTION(cac); 277*92022041SSam Saccone DECLARE_SECTION(channels); 278*92022041SSam Saccone DECLARE_SECTION(coalesce); 279*92022041SSam Saccone DECLARE_SECTION(commands); 280*92022041SSam Saccone DECLARE_SECTION(connect); 281*92022041SSam Saccone DECLARE_SECTION(cqm); 282*92022041SSam Saccone DECLARE_SECTION(del); 283*92022041SSam Saccone DECLARE_SECTION(dev); 284*92022041SSam Saccone DECLARE_SECTION(disconnect); 285*92022041SSam Saccone DECLARE_SECTION(event); 286*92022041SSam Saccone DECLARE_SECTION(features); 287*92022041SSam Saccone DECLARE_SECTION(ftm); 288*92022041SSam Saccone DECLARE_SECTION(get); 289*92022041SSam Saccone DECLARE_SECTION(help); 290*92022041SSam Saccone DECLARE_SECTION(hwsim); 291*92022041SSam Saccone DECLARE_SECTION(ibss); 292*92022041SSam Saccone DECLARE_SECTION(info); 293*92022041SSam Saccone DECLARE_SECTION(interface); 294*92022041SSam Saccone DECLARE_SECTION(link); 295*92022041SSam Saccone DECLARE_SECTION(list); 296*92022041SSam Saccone DECLARE_SECTION(measurement); 297*92022041SSam Saccone DECLARE_SECTION(mesh); 298*92022041SSam Saccone DECLARE_SECTION(mesh_param); 299*92022041SSam Saccone DECLARE_SECTION(mgmt); 300*92022041SSam Saccone DECLARE_SECTION(mpath); 301*92022041SSam Saccone DECLARE_SECTION(mpp); 302*92022041SSam Saccone DECLARE_SECTION(nan); 303*92022041SSam Saccone DECLARE_SECTION(ocb); 304*92022041SSam Saccone DECLARE_SECTION(offchannel); 305*92022041SSam Saccone DECLARE_SECTION(p2p); 306*92022041SSam Saccone DECLARE_SECTION(phy); 307*92022041SSam Saccone DECLARE_SECTION(reg); 308*92022041SSam Saccone DECLARE_SECTION(roc); 309*92022041SSam Saccone DECLARE_SECTION(scan); 310*92022041SSam Saccone DECLARE_SECTION(set); 311*92022041SSam Saccone DECLARE_SECTION(station); 312*92022041SSam Saccone DECLARE_SECTION(survey); 313*92022041SSam Saccone DECLARE_SECTION(switch); 314*92022041SSam Saccone DECLARE_SECTION(vendor); 315*92022041SSam Saccone DECLARE_SECTION(wowlan); 316*92022041SSam Saccone 317*92022041SSam Saccone #endif /* __IW_H */ 318