2 * hostapd / Kernel driver communication via nl80211
3 * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Alternatively, this software may be distributed under the terms of BSD
15 * See README and COPYING for more details.
20 #include <sys/ioctl.h>
21 #include <netlink/genl/genl.h>
22 #include <netlink/genl/family.h>
23 #include <netlink/genl/ctrl.h>
24 #include <netlink/msg.h>
25 #include <netlink/attr.h>
26 #include "nl80211_copy.h"
28 #include <netpacket/packet.h>
29 #include "wireless_copy.h"
30 #include <net/if_arp.h>
34 #include "ieee802_1x.h"
36 #include "ieee802_11.h"
37 #include "hw_features.h"
40 #include "radiotap_iter.h"
43 /* libnl 2.0 compatibility code */
44 #define nl_handle_alloc_cb nl_socket_alloc_cb
45 #define nl_handle_destroy nl_socket_free
46 #endif /* CONFIG_LIBNL20 */
48 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
50 enum ieee80211_msg_type {
51 ieee80211_msg_normal = 0,
52 ieee80211_msg_tx_callback_ack = 1,
53 ieee80211_msg_tx_callback_fail = 2,
56 struct i802_driver_data {
57 struct hostapd_data *hapd;
59 char iface[IFNAMSIZ + 1];
61 int ioctl_sock; /* socket for ioctl() use */
62 int wext_sock; /* socket for wireless events */
63 int eapol_sock; /* socket for EAPOL frames */
64 int monitor_sock; /* socket for monitor */
67 int default_if_indices[16];
72 struct nl_handle *nl_handle;
73 struct nl_cache *nl_cache;
75 struct genl_family *nl80211;
76 int dtim_period, beacon_int;
77 unsigned int beacon_set:1;
78 unsigned int ieee802_1x_active:1;
85 static int i802_sta_deauth(void *priv, const u8 *addr, int reason);
86 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason);
89 static void add_ifidx(struct i802_driver_data *drv, int ifidx)
94 for (i = 0; i < drv->num_if_indices; i++) {
95 if (drv->if_indices[i] == 0) {
96 drv->if_indices[i] = ifidx;
101 if (drv->if_indices != drv->default_if_indices)
102 old = drv->if_indices;
106 drv->if_indices = realloc(old,
107 sizeof(int) * (drv->num_if_indices + 1));
108 if (!drv->if_indices) {
110 drv->if_indices = drv->default_if_indices;
112 drv->if_indices = old;
113 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
115 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
118 drv->if_indices[drv->num_if_indices] = ifidx;
119 drv->num_if_indices++;
123 static void del_ifidx(struct i802_driver_data *drv, int ifidx)
127 for (i = 0; i < drv->num_if_indices; i++) {
128 if (drv->if_indices[i] == ifidx) {
129 drv->if_indices[i] = 0;
136 static int have_ifidx(struct i802_driver_data *drv, int ifidx)
140 if (ifidx == drv->bridge)
143 for (i = 0; i < drv->num_if_indices; i++)
144 if (drv->if_indices[i] == ifidx)
152 static int ack_handler(struct nl_msg *msg, void *arg)
159 static int finish_handler(struct nl_msg *msg, void *arg)
166 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
174 static int send_and_recv_msgs(struct i802_driver_data *drv,
176 int (*valid_handler)(struct nl_msg *, void *),
182 cb = nl_cb_clone(drv->nl_cb);
186 err = nl_send_auto_complete(drv->nl_handle, msg);
192 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
193 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
194 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
197 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
198 valid_handler, valid_data);
201 nl_recvmsgs(drv->nl_handle, cb);
208 static int hostapd_set_iface_flags(struct i802_driver_data *drv,
209 const char *ifname, int dev_up)
213 if (drv->ioctl_sock < 0)
216 memset(&ifr, 0, sizeof(ifr));
217 os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
219 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
220 perror("ioctl[SIOCGIFFLAGS]");
221 wpa_printf(MSG_DEBUG, "Could not read interface flags (%s)",
227 ifr.ifr_flags |= IFF_UP;
229 ifr.ifr_flags &= ~IFF_UP;
231 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
232 perror("ioctl[SIOCSIFFLAGS]");
240 static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
241 const char *alg, const u8 *addr, int idx, const u8 *key,
242 size_t key_len, int txkey)
251 if (strcmp(alg, "none") == 0) {
252 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
253 0, NL80211_CMD_DEL_KEY, 0);
255 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
256 0, NL80211_CMD_NEW_KEY, 0);
257 NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
258 if (strcmp(alg, "WEP") == 0) {
260 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
263 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
265 } else if (strcmp(alg, "TKIP") == 0)
266 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
267 else if (strcmp(alg, "CCMP") == 0)
268 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
269 else if (strcmp(alg, "IGTK") == 0)
270 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC06);
272 wpa_printf(MSG_ERROR, "%s: Unsupported encryption "
273 "algorithm '%s'", __func__, alg);
280 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
281 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
282 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
284 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
289 * If we failed or don't need to set the default TX key (below),
292 if (ret || !txkey || addr)
299 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
300 0, NL80211_CMD_SET_KEY, 0);
301 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
302 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
303 if (strcmp(alg, "IGTK") == 0)
304 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
306 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
308 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
317 static int i802_set_encryption(const char *iface, void *priv, const char *alg,
318 const u8 *addr, int idx, const u8 *key,
319 size_t key_len, int txkey)
321 struct i802_driver_data *drv = priv;
324 ret = nl_set_encr(if_nametoindex(iface), drv, alg, addr, idx, key,
333 static inline int min_int(int a, int b)
341 static int get_key_handler(struct nl_msg *msg, void *arg)
343 struct nlattr *tb[NL80211_ATTR_MAX + 1];
344 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
346 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
347 genlmsg_attrlen(gnlh, 0), NULL);
350 * TODO: validate the key index and mac address!
351 * Otherwise, there's a race condition as soon as
352 * the kernel starts sending key notifications.
355 if (tb[NL80211_ATTR_KEY_SEQ])
356 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
357 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
362 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
365 struct i802_driver_data *drv = priv;
372 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
373 0, NL80211_CMD_GET_KEY, 0);
376 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
377 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
378 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
382 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
388 static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
391 struct i802_driver_data *drv = priv;
393 u8 rates[NL80211_MAX_SUPP_RATES];
401 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
402 NL80211_CMD_SET_BSS, 0);
404 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
405 rates[rates_len++] = basic_rates[i] / 5;
407 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
409 /* TODO: multi-BSS support */
410 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
412 return send_and_recv_msgs(drv, msg, NULL, NULL);
418 static int i802_send_frame(void *priv, const void *data, size_t len,
419 int encrypt, int flags)
422 0x00, 0x00, /* radiotap version */
423 0x0e, 0x00, /* radiotap length */
424 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
425 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
427 0x00, 0x00, /* RX and TX flags to indicate that */
428 0x00, 0x00, /* this is the injected frame directly */
430 struct i802_driver_data *drv = priv;
431 struct iovec iov[2] = {
433 .iov_base = &rtap_hdr,
434 .iov_len = sizeof(rtap_hdr),
437 .iov_base = (void*)data,
441 struct msghdr msg = {
452 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
454 return sendmsg(drv->monitor_sock, &msg, flags);
457 static int i802_send_mgmt_frame(void *priv, const void *data, size_t len,
460 struct ieee80211_mgmt *mgmt;
461 int do_not_encrypt = 0;
464 mgmt = (struct ieee80211_mgmt *) data;
465 fc = le_to_host16(mgmt->frame_control);
467 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
468 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
470 * Only one of the authentication frame types is encrypted.
471 * In order for static WEP encryption to work properly (i.e.,
472 * to not encrypt the frame), we need to tell mac80211 about
473 * the frames that must not be encrypted.
475 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
476 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
477 if (auth_alg == WLAN_AUTH_OPEN ||
478 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_trans != 3))
482 return i802_send_frame(priv, data, len, !do_not_encrypt, flags);
485 /* Set kernel driver on given frequency (MHz) */
486 static int i802_set_freq2(void *priv, struct hostapd_freq_params *freq)
488 struct i802_driver_data *drv = priv;
495 drv->last_freq = freq->freq;
496 drv->last_freq_ht = freq->ht_enabled;
498 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
499 NL80211_CMD_SET_WIPHY, 0);
501 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
502 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
503 if (freq->ht_enabled) {
504 switch (freq->sec_channel_offset) {
506 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
507 NL80211_CHAN_HT40MINUS);
510 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
511 NL80211_CHAN_HT40PLUS);
514 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
520 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
527 static int i802_set_rts(void *priv, int rts)
529 struct i802_driver_data *drv = priv;
532 memset(&iwr, 0, sizeof(iwr));
533 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
534 iwr.u.rts.value = rts;
537 if (ioctl(drv->ioctl_sock, SIOCSIWRTS, &iwr) < 0) {
538 perror("ioctl[SIOCSIWRTS]");
546 static int i802_get_rts(void *priv, int *rts)
548 struct i802_driver_data *drv = priv;
551 memset(&iwr, 0, sizeof(iwr));
552 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
554 if (ioctl(drv->ioctl_sock, SIOCGIWRTS, &iwr) < 0) {
555 perror("ioctl[SIOCGIWRTS]");
559 *rts = iwr.u.rts.value;
565 static int i802_set_frag(void *priv, int frag)
567 struct i802_driver_data *drv = priv;
570 memset(&iwr, 0, sizeof(iwr));
571 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
572 iwr.u.frag.value = frag;
573 iwr.u.frag.fixed = 1;
575 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
576 perror("ioctl[SIOCSIWFRAG]");
584 static int i802_get_frag(void *priv, int *frag)
586 struct i802_driver_data *drv = priv;
589 memset(&iwr, 0, sizeof(iwr));
590 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
592 if (ioctl(drv->ioctl_sock, SIOCGIWFRAG, &iwr) < 0) {
593 perror("ioctl[SIOCGIWFRAG]");
597 *frag = iwr.u.frag.value;
603 static int i802_set_retry(void *priv, int short_retry, int long_retry)
605 struct i802_driver_data *drv = priv;
608 memset(&iwr, 0, sizeof(iwr));
609 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
611 iwr.u.retry.value = short_retry;
612 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
613 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
614 perror("ioctl[SIOCSIWRETRY(short)]");
618 iwr.u.retry.value = long_retry;
619 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
620 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
621 perror("ioctl[SIOCSIWRETRY(long)]");
629 static int i802_get_retry(void *priv, int *short_retry, int *long_retry)
631 struct i802_driver_data *drv = priv;
634 memset(&iwr, 0, sizeof(iwr));
635 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
637 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
638 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
639 perror("ioctl[SIOCGIWFRAG(short)]");
642 *short_retry = iwr.u.retry.value;
644 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
645 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
646 perror("ioctl[SIOCGIWFRAG(long)]");
649 *long_retry = iwr.u.retry.value;
655 static int i802_flush(void *priv)
657 struct i802_driver_data *drv = priv;
664 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
665 0, NL80211_CMD_DEL_STATION, 0);
668 * XXX: FIX! this needs to flush all VLANs too
670 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
671 if_nametoindex(drv->iface));
673 return send_and_recv_msgs(drv, msg, NULL, NULL);
679 static int get_sta_handler(struct nl_msg *msg, void *arg)
681 struct nlattr *tb[NL80211_ATTR_MAX + 1];
682 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
683 struct hostap_sta_driver_data *data = arg;
684 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
685 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
686 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
687 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
688 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
691 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
692 genlmsg_attrlen(gnlh, 0), NULL);
695 * TODO: validate the interface and mac address!
696 * Otherwise, there's a race condition as soon as
697 * the kernel starts sending station notifications.
700 if (!tb[NL80211_ATTR_STA_INFO]) {
701 wpa_printf(MSG_DEBUG, "sta stats missing!");
704 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
705 tb[NL80211_ATTR_STA_INFO],
707 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
711 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
712 data->inactive_msec =
713 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
714 if (stats[NL80211_STA_INFO_RX_BYTES])
715 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
716 if (stats[NL80211_STA_INFO_TX_BYTES])
717 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
722 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
725 struct i802_driver_data *drv = priv;
732 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
733 0, NL80211_CMD_GET_STATION, 0);
735 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
736 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
738 return send_and_recv_msgs(drv, msg, get_sta_handler, data);
744 static int i802_send_eapol(void *priv, const u8 *addr, const u8 *data,
745 size_t data_len, int encrypt, const u8 *own_addr)
747 struct i802_driver_data *drv = priv;
748 struct ieee80211_hdr *hdr;
753 int qos = sta->flags & WLAN_STA_WME;
758 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
760 hdr = os_zalloc(len);
762 printf("malloc() failed for i802_send_data(len=%lu)\n",
763 (unsigned long) len);
768 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
769 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
771 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
772 #if 0 /* To be enabled if qos determination is added above */
774 hdr->frame_control |=
775 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
779 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
780 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
781 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
782 pos = (u8 *) (hdr + 1);
784 #if 0 /* To be enabled if qos determination is added above */
786 /* add an empty QoS header if needed */
793 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
794 pos += sizeof(rfc1042_header);
795 WPA_PUT_BE16(pos, ETH_P_PAE);
797 memcpy(pos, data, data_len);
799 res = i802_send_frame(drv, (u8 *) hdr, len, encrypt, 0);
803 perror("i802_send_eapol: send");
804 printf("i802_send_eapol - packet len: %lu - failed\n",
805 (unsigned long) len);
812 static int i802_sta_add2(const char *ifname, void *priv,
813 struct hostapd_sta_add_params *params)
815 struct i802_driver_data *drv = priv;
823 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
824 0, NL80211_CMD_NEW_STATION, 0);
826 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
827 if_nametoindex(drv->iface));
828 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr);
829 NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid);
830 NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len,
832 NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
833 params->listen_interval);
835 #ifdef CONFIG_IEEE80211N
836 if (params->ht_capabilities) {
837 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
838 params->ht_capabilities->length,
839 ¶ms->ht_capabilities->data);
841 #endif /* CONFIG_IEEE80211N */
843 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
851 static int i802_sta_remove(void *priv, const u8 *addr)
853 struct i802_driver_data *drv = priv;
861 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
862 0, NL80211_CMD_DEL_STATION, 0);
864 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
865 if_nametoindex(drv->iface));
866 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
868 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
877 static int i802_sta_set_flags(void *priv, const u8 *addr,
878 int total_flags, int flags_or, int flags_and)
880 struct i802_driver_data *drv = priv;
881 struct nl_msg *msg, *flags = NULL;
887 flags = nlmsg_alloc();
893 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
894 0, NL80211_CMD_SET_STATION, 0);
896 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
897 if_nametoindex(drv->iface));
898 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
900 if (total_flags & WLAN_STA_AUTHORIZED || !drv->ieee802_1x_active)
901 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
903 if (total_flags & WLAN_STA_WME)
904 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
906 if (total_flags & WLAN_STA_SHORT_PREAMBLE)
907 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
909 if (total_flags & WLAN_STA_MFP)
910 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
912 if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
913 goto nla_put_failure;
917 return send_and_recv_msgs(drv, msg, NULL, NULL);
924 static int i802_set_regulatory_domain(void *priv, unsigned int rd)
930 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
931 int cw_min, int cw_max, int burst_time)
933 struct i802_driver_data *drv = priv;
935 struct nlattr *txq, *params;
941 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
942 0, NL80211_CMD_SET_WIPHY, 0);
944 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
946 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
948 goto nla_put_failure;
950 /* We are only sending parameters for a single TXQ at a time */
951 params = nla_nest_start(msg, 1);
953 goto nla_put_failure;
955 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue);
956 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
957 * 32 usec, so need to convert the value here. */
958 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32);
959 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min);
960 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max);
961 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs);
963 nla_nest_end(msg, params);
965 nla_nest_end(msg, txq);
967 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
974 static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
978 /* stop listening for EAPOL on this interface */
979 del_ifidx(drv, ifidx);
983 goto nla_put_failure;
985 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
986 0, NL80211_CMD_DEL_INTERFACE, 0);
987 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
989 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
992 printf("Failed to remove interface.\n");
996 static int nl80211_create_iface(struct i802_driver_data *drv,
998 enum nl80211_iftype iftype,
1001 struct nl_msg *msg, *flags = NULL;
1007 msg = nlmsg_alloc();
1011 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1012 0, NL80211_CMD_NEW_INTERFACE, 0);
1013 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1014 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
1015 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
1017 if (iftype == NL80211_IFTYPE_MONITOR) {
1020 flags = nlmsg_alloc();
1022 goto nla_put_failure;
1024 NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
1026 err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
1031 goto nla_put_failure;
1034 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1037 printf("Failed to create interface %s.\n", ifname);
1041 ifidx = if_nametoindex(ifname);
1046 /* start listening for EAPOL on this interface */
1047 add_ifidx(drv, ifidx);
1051 case NL80211_IFTYPE_AP:
1052 os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
1053 memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
1054 ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1056 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
1057 nl80211_remove_iface(drv, ifidx);
1061 case NL80211_IFTYPE_WDS:
1062 memset(&iwr, 0, sizeof(iwr));
1063 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1064 iwr.u.addr.sa_family = ARPHRD_ETHER;
1065 memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
1066 if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
1079 static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
1084 * The kernel supports that when the low-level driver does,
1085 * but we currently don't because we need per-BSS data that
1086 * currently we can't handle easily.
1090 ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
1093 if (hostapd_set_iface_flags(priv, ifname, 1)) {
1094 nl80211_remove_iface(priv, ifidx);
1101 static int i802_bss_remove(void *priv, const char *ifname)
1103 nl80211_remove_iface(priv, if_nametoindex(ifname));
1108 static int i802_set_beacon(const char *iface, void *priv,
1109 u8 *head, size_t head_len,
1110 u8 *tail, size_t tail_len)
1112 struct i802_driver_data *drv = priv;
1114 u8 cmd = NL80211_CMD_NEW_BEACON;
1117 msg = nlmsg_alloc();
1121 if (drv->beacon_set)
1122 cmd = NL80211_CMD_SET_BEACON;
1124 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1126 NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
1127 NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
1128 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1129 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
1131 if (!drv->dtim_period)
1132 drv->dtim_period = 2;
1133 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1135 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1137 drv->beacon_set = 1;
1144 static int i802_del_beacon(struct i802_driver_data *drv)
1148 msg = nlmsg_alloc();
1152 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1153 0, NL80211_CMD_DEL_BEACON, 0);
1154 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1156 return send_and_recv_msgs(drv, msg, NULL, NULL);
1162 static int i802_set_ieee8021x(const char *ifname, void *priv, int enabled)
1164 struct i802_driver_data *drv = priv;
1167 * FIXME: This needs to be per interface (BSS)
1169 drv->ieee802_1x_active = enabled;
1174 static int i802_set_privacy(const char *ifname, void *priv, int enabled)
1176 struct i802_driver_data *drv = priv;
1179 memset(&iwr, 0, sizeof(iwr));
1181 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1182 iwr.u.param.flags = IW_AUTH_PRIVACY_INVOKED;
1183 iwr.u.param.value = enabled;
1185 ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr);
1187 /* ignore errors, the kernel/driver might not care */
1192 static int i802_set_internal_bridge(void *priv, int value)
1198 static int i802_set_beacon_int(void *priv, int value)
1200 struct i802_driver_data *drv = priv;
1203 drv->beacon_int = value;
1205 if (!drv->beacon_set)
1208 msg = nlmsg_alloc();
1212 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1213 0, NL80211_CMD_SET_BEACON, 0);
1214 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1216 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
1218 return send_and_recv_msgs(drv, msg, NULL, NULL);
1224 static int i802_set_dtim_period(const char *iface, void *priv, int value)
1226 struct i802_driver_data *drv = priv;
1229 msg = nlmsg_alloc();
1233 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1234 0, NL80211_CMD_SET_BEACON, 0);
1235 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1237 drv->dtim_period = value;
1238 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1240 return send_and_recv_msgs(drv, msg, NULL, NULL);
1246 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
1248 struct i802_driver_data *drv = priv;
1251 msg = nlmsg_alloc();
1255 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
1256 NL80211_CMD_SET_BSS, 0);
1259 NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
1261 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
1263 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
1265 /* TODO: multi-BSS support */
1266 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1268 return send_and_recv_msgs(drv, msg, NULL, NULL);
1274 static int i802_set_cts_protect(void *priv, int value)
1276 return i802_set_bss(priv, value, -1, -1);
1280 static int i802_set_preamble(void *priv, int value)
1282 return i802_set_bss(priv, -1, value, -1);
1286 static int i802_set_short_slot_time(void *priv, int value)
1288 return i802_set_bss(priv, -1, -1, value);
1292 static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
1295 case HOSTAPD_IF_VLAN:
1296 return NL80211_IFTYPE_AP_VLAN;
1297 case HOSTAPD_IF_WDS:
1298 return NL80211_IFTYPE_WDS;
1304 static int i802_if_add(const char *iface, void *priv,
1305 enum hostapd_driver_if_type type, char *ifname,
1308 if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
1314 static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
1315 char *ifname, const u8 *addr)
1317 /* unused at the moment */
1322 static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
1323 const char *ifname, const u8 *addr)
1325 nl80211_remove_iface(priv, if_nametoindex(ifname));
1330 struct phy_info_arg {
1332 struct hostapd_hw_modes *modes;
1335 static int phy_info_handler(struct nl_msg *msg, void *arg)
1337 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1338 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1339 struct phy_info_arg *phy_info = arg;
1341 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1343 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1344 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1345 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1346 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1347 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
1348 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
1349 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1350 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1353 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1354 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1355 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1356 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
1359 struct nlattr *nl_band;
1360 struct nlattr *nl_freq;
1361 struct nlattr *nl_rate;
1362 int rem_band, rem_freq, rem_rate;
1363 struct hostapd_hw_modes *mode;
1364 int idx, mode_is_set;
1366 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1367 genlmsg_attrlen(gnlh, 0), NULL);
1369 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1372 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
1373 mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
1376 phy_info->modes = mode;
1380 mode = &phy_info->modes[*(phy_info->num_modes)];
1381 memset(mode, 0, sizeof(*mode));
1382 *(phy_info->num_modes) += 1;
1384 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1385 nla_len(nl_band), NULL);
1387 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1388 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1389 nla_len(nl_freq), freq_policy);
1390 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1392 mode->num_channels++;
1395 mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
1396 if (!mode->channels)
1401 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1402 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1403 nla_len(nl_freq), freq_policy);
1404 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1407 mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1408 mode->channels[idx].flag = 0;
1411 /* crude heuristic */
1412 if (mode->channels[idx].freq < 4000)
1413 mode->mode = HOSTAPD_MODE_IEEE80211B;
1415 mode->mode = HOSTAPD_MODE_IEEE80211A;
1419 /* crude heuristic */
1420 if (mode->channels[idx].freq < 4000)
1421 if (mode->channels[idx].freq == 2848)
1422 mode->channels[idx].chan = 14;
1424 mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
1426 mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
1428 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1429 mode->channels[idx].flag |=
1430 HOSTAPD_CHAN_DISABLED;
1431 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
1432 mode->channels[idx].flag |=
1433 HOSTAPD_CHAN_PASSIVE_SCAN;
1434 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
1435 mode->channels[idx].flag |=
1436 HOSTAPD_CHAN_NO_IBSS;
1437 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1438 mode->channels[idx].flag |=
1441 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
1442 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1443 mode->channels[idx].max_tx_power =
1444 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100;
1449 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1450 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1451 nla_len(nl_rate), rate_policy);
1452 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1457 mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
1463 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1464 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1465 nla_len(nl_rate), rate_policy);
1466 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1468 mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
1470 /* crude heuristic */
1471 if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
1472 mode->rates[idx].rate > 200)
1473 mode->mode = HOSTAPD_MODE_IEEE80211G;
1475 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
1476 mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
1485 static struct hostapd_hw_modes *i802_add_11b(struct hostapd_hw_modes *modes,
1489 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1490 int i, mode11g_idx = -1;
1492 /* If only 802.11g mode is included, use it to construct matching
1493 * 802.11b mode data. */
1495 for (m = 0; m < *num_modes; m++) {
1496 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1497 return modes; /* 802.11b already included */
1498 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1502 if (mode11g_idx < 0)
1503 return modes; /* 2.4 GHz band not supported at all */
1505 nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes));
1507 return modes; /* Could not add 802.11b mode */
1509 mode = &nmodes[*num_modes];
1510 os_memset(mode, 0, sizeof(*mode));
1514 mode->mode = HOSTAPD_MODE_IEEE80211B;
1516 mode11g = &modes[mode11g_idx];
1517 mode->num_channels = mode11g->num_channels;
1518 mode->channels = os_malloc(mode11g->num_channels *
1519 sizeof(struct hostapd_channel_data));
1520 if (mode->channels == NULL) {
1522 return modes; /* Could not add 802.11b mode */
1524 os_memcpy(mode->channels, mode11g->channels,
1525 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1527 mode->num_rates = 0;
1528 mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
1529 if (mode->rates == NULL) {
1530 os_free(mode->channels);
1532 return modes; /* Could not add 802.11b mode */
1535 for (i = 0; i < mode11g->num_rates; i++) {
1536 if (mode11g->rates[i].rate > 110 ||
1537 mode11g->rates[i].flags &
1538 (HOSTAPD_RATE_ERP | HOSTAPD_RATE_OFDM))
1540 mode->rates[mode->num_rates] = mode11g->rates[i];
1542 if (mode->num_rates == 4)
1546 if (mode->num_rates == 0) {
1547 os_free(mode->channels);
1548 os_free(mode->rates);
1550 return modes; /* No 802.11b rates */
1553 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1559 static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
1563 struct i802_driver_data *drv = priv;
1565 struct phy_info_arg result = {
1566 .num_modes = num_modes,
1573 msg = nlmsg_alloc();
1577 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1578 0, NL80211_CMD_GET_WIPHY, 0);
1580 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1582 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
1583 return i802_add_11b(result.modes, num_modes);
1589 static int i802_set_sta_vlan(void *priv, const u8 *addr,
1590 const char *ifname, int vlan_id)
1592 struct i802_driver_data *drv = priv;
1595 msg = nlmsg_alloc();
1599 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1600 0, NL80211_CMD_SET_STATION, 0);
1602 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1603 if_nametoindex(drv->iface));
1604 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
1605 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1606 if_nametoindex(ifname));
1608 return send_and_recv_msgs(drv, msg, NULL, NULL);
1614 static int i802_set_country(void *priv, const char *country)
1616 struct i802_driver_data *drv = priv;
1620 msg = nlmsg_alloc();
1624 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1625 0, NL80211_CMD_REQ_SET_REG, 0);
1627 alpha2[0] = country[0];
1628 alpha2[1] = country[1];
1630 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
1632 return send_and_recv_msgs(drv, msg, NULL, NULL);
1638 static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
1641 struct ieee80211_hdr *hdr;
1642 u16 fc, type, stype;
1644 hdr = (struct ieee80211_hdr *) buf;
1645 fc = le_to_host16(hdr->frame_control);
1647 type = WLAN_FC_GET_TYPE(fc);
1648 stype = WLAN_FC_GET_STYPE(fc);
1651 case WLAN_FC_TYPE_MGMT:
1652 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
1653 ok ? "ACK" : "fail");
1654 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1656 case WLAN_FC_TYPE_CTRL:
1657 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
1658 ok ? "ACK" : "fail");
1660 case WLAN_FC_TYPE_DATA:
1661 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
1662 ok ? "ACK" : "fail");
1663 hostapd_tx_status(hapd, hdr->addr1, buf, len, ok);
1666 printf("unknown TX callback frame type %d\n", type);
1672 static void handle_frame(struct i802_driver_data *drv,
1673 struct hostapd_iface *iface, u8 *buf, size_t len,
1674 struct hostapd_frame_info *hfi,
1675 enum ieee80211_msg_type msg_type)
1677 struct ieee80211_hdr *hdr;
1678 u16 fc, type, stype;
1679 size_t data_len = len;
1680 struct hostapd_data *hapd = NULL;
1681 int broadcast_bssid = 0;
1686 * PS-Poll frames are 16 bytes. All other frames are
1687 * 24 bytes or longer.
1692 hdr = (struct ieee80211_hdr *) buf;
1693 fc = le_to_host16(hdr->frame_control);
1695 type = WLAN_FC_GET_TYPE(fc);
1696 stype = WLAN_FC_GET_STYPE(fc);
1699 case WLAN_FC_TYPE_DATA:
1702 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
1711 case WLAN_FC_TYPE_CTRL:
1712 /* discard non-ps-poll frames */
1713 if (stype != WLAN_FC_STYPE_PSPOLL)
1717 case WLAN_FC_TYPE_MGMT:
1725 /* find interface frame belongs to */
1726 for (i = 0; i < iface->num_bss; i++) {
1727 if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
1728 hapd = iface->bss[i];
1734 hapd = iface->bss[0];
1736 if (bssid[0] != 0xff || bssid[1] != 0xff ||
1737 bssid[2] != 0xff || bssid[3] != 0xff ||
1738 bssid[4] != 0xff || bssid[5] != 0xff) {
1740 * Unknown BSSID - drop frame if this is not from
1741 * passive scanning or a beacon (at least ProbeReq
1742 * frames to other APs may be allowed through RX
1743 * filtering in the wlan hw/driver)
1745 if ((type != WLAN_FC_TYPE_MGMT ||
1746 stype != WLAN_FC_STYPE_BEACON))
1749 broadcast_bssid = 1;
1753 case ieee80211_msg_normal:
1754 /* continue processing */
1756 case ieee80211_msg_tx_callback_ack:
1757 handle_tx_callback(hapd, buf, data_len, 1);
1759 case ieee80211_msg_tx_callback_fail:
1760 handle_tx_callback(hapd, buf, data_len, 0);
1765 case WLAN_FC_TYPE_MGMT:
1766 if (stype != WLAN_FC_STYPE_BEACON &&
1767 stype != WLAN_FC_STYPE_PROBE_REQ)
1768 wpa_printf(MSG_MSGDUMP, "MGMT");
1769 if (broadcast_bssid) {
1770 for (i = 0; i < iface->num_bss; i++)
1771 ieee802_11_mgmt(iface->bss[i], buf, data_len,
1774 ieee802_11_mgmt(hapd, buf, data_len, stype, hfi);
1776 case WLAN_FC_TYPE_CTRL:
1777 /* can only get here with PS-Poll frames */
1778 wpa_printf(MSG_DEBUG, "CTRL");
1779 hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
1781 case WLAN_FC_TYPE_DATA:
1782 hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
1788 static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
1790 struct i802_driver_data *drv = eloop_ctx;
1791 struct hostapd_data *hapd = drv->hapd;
1792 struct sockaddr_ll lladdr;
1793 unsigned char buf[3000];
1795 socklen_t fromlen = sizeof(lladdr);
1797 len = recvfrom(sock, buf, sizeof(buf), 0,
1798 (struct sockaddr *)&lladdr, &fromlen);
1804 if (have_ifidx(drv, lladdr.sll_ifindex))
1805 ieee802_1x_receive(hapd, lladdr.sll_addr, buf, len);
1809 static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
1811 struct i802_driver_data *drv = eloop_ctx;
1813 unsigned char buf[3000];
1814 struct hostapd_data *hapd = drv->hapd;
1815 struct ieee80211_radiotap_iterator iter;
1817 struct hostapd_frame_info hfi;
1818 int injected = 0, failed = 0, msg_type, rxflags = 0;
1820 len = recv(sock, buf, sizeof(buf), 0);
1826 if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
1827 printf("received invalid radiotap frame\n");
1831 memset(&hfi, 0, sizeof(hfi));
1834 ret = ieee80211_radiotap_iterator_next(&iter);
1838 printf("received invalid radiotap frame (%d)\n", ret);
1841 switch (iter.this_arg_index) {
1842 case IEEE80211_RADIOTAP_FLAGS:
1843 if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
1846 case IEEE80211_RADIOTAP_RX_FLAGS:
1849 case IEEE80211_RADIOTAP_TX_FLAGS:
1851 failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
1852 IEEE80211_RADIOTAP_F_TX_FAIL;
1854 case IEEE80211_RADIOTAP_DATA_RETRIES:
1856 case IEEE80211_RADIOTAP_CHANNEL:
1857 /* TODO convert from freq/flags to channel number
1862 case IEEE80211_RADIOTAP_RATE:
1863 hfi.datarate = *iter.this_arg * 5;
1865 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1866 hfi.ssi_signal = *iter.this_arg;
1871 if (rxflags && injected)
1875 msg_type = ieee80211_msg_normal;
1877 msg_type = ieee80211_msg_tx_callback_fail;
1879 msg_type = ieee80211_msg_tx_callback_ack;
1881 handle_frame(drv, hapd->iface, buf + iter.max_length,
1882 len - iter.max_length, &hfi, msg_type);
1886 static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
1889 struct sockaddr_ll ll;
1893 snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
1894 buf[IFNAMSIZ - 1] = '\0';
1896 drv->monitor_ifidx =
1897 nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
1899 if (drv->monitor_ifidx < 0)
1902 if (hostapd_set_iface_flags(drv, buf, 1))
1905 memset(&ll, 0, sizeof(ll));
1906 ll.sll_family = AF_PACKET;
1907 ll.sll_ifindex = drv->monitor_ifidx;
1908 drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1909 if (drv->monitor_sock < 0) {
1910 perror("socket[PF_PACKET,SOCK_RAW]");
1914 if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
1916 perror("monitor socket bind");
1920 optlen = sizeof(optval);
1923 (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
1924 perror("Failed to set socket priority");
1928 if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
1930 printf("Could not register monitor read socket\n");
1936 nl80211_remove_iface(drv, drv->monitor_ifidx);
1941 static int nl80211_set_master_mode(struct i802_driver_data *drv,
1947 msg = nlmsg_alloc();
1951 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1952 0, NL80211_CMD_SET_INTERFACE, 0);
1953 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1954 if_nametoindex(ifname));
1955 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
1957 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1961 wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
1967 static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
1970 struct sockaddr_ll addr;
1972 drv->ioctl_sock = -1;
1974 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1975 if (drv->ioctl_sock < 0) {
1976 perror("socket[PF_INET,SOCK_DGRAM]");
1980 /* start listening for EAPOL on the default AP interface */
1981 add_ifidx(drv, if_nametoindex(drv->iface));
1983 if (hostapd_set_iface_flags(drv, drv->iface, 0))
1987 os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
1988 memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
1989 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1991 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
1992 perror("ioctl(SIOCSIFHWADDR)");
1998 * initialise generic netlink and nl80211
2000 drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
2002 printf("Failed to allocate netlink callbacks.\n");
2006 drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
2007 if (!drv->nl_handle) {
2008 printf("Failed to allocate netlink handle.\n");
2012 if (genl_connect(drv->nl_handle)) {
2013 printf("Failed to connect to generic netlink.\n");
2017 #ifdef CONFIG_LIBNL20
2018 if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
2019 printf("Failed to allocate generic netlink cache.\n");
2022 #else /* CONFIG_LIBNL20 */
2023 drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
2024 if (!drv->nl_cache) {
2025 printf("Failed to allocate generic netlink cache.\n");
2028 #endif /* CONFIG_LIBNL20 */
2030 drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
2031 if (!drv->nl80211) {
2032 printf("nl80211 not found.\n");
2036 /* Initialise a monitor interface */
2037 if (nl80211_create_monitor_interface(drv))
2040 if (nl80211_set_master_mode(drv, drv->iface))
2043 if (hostapd_set_iface_flags(drv, drv->iface, 1))
2046 memset(&addr, 0, sizeof(addr));
2047 addr.sll_family = AF_PACKET;
2048 addr.sll_ifindex = ifr.ifr_ifindex;
2049 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
2052 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
2053 if (drv->eapol_sock < 0) {
2054 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
2058 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
2060 printf("Could not register read socket for eapol\n");
2064 memset(&ifr, 0, sizeof(ifr));
2065 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
2066 if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
2067 perror("ioctl(SIOCGIFHWADDR)");
2071 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
2072 printf("Invalid HW-addr family 0x%04x\n",
2073 ifr.ifr_hwaddr.sa_family);
2076 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
2081 nl80211_remove_iface(drv, drv->monitor_ifidx);
2086 static int i802_get_inact_sec(void *priv, const u8 *addr)
2088 struct hostap_sta_driver_data data;
2091 data.inactive_msec = (unsigned long) -1;
2092 ret = i802_read_sta_data(priv, &data, addr);
2093 if (ret || data.inactive_msec == (unsigned long) -1)
2095 return data.inactive_msec / 1000;
2099 static int i802_sta_clear_stats(void *priv, const u8 *addr)
2109 hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
2112 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
2114 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
2117 pos = strstr(custom, "addr=");
2119 wpa_printf(MSG_DEBUG,
2120 "MLME-MICHAELMICFAILURE.indication "
2121 "without sender address ignored");
2125 if (hwaddr_aton(pos, addr) == 0) {
2126 ieee80211_michael_mic_failure(drv->hapd, addr, 1);
2128 wpa_printf(MSG_DEBUG,
2129 "MLME-MICHAELMICFAILURE.indication "
2130 "with invalid MAC address");
2136 static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
2137 char *data, int len)
2139 struct iw_event iwe_buf, *iwe = &iwe_buf;
2140 char *pos, *end, *custom, *buf;
2145 while (pos + IW_EV_LCP_LEN <= end) {
2146 /* Event data may be unaligned, so make a local, aligned copy
2147 * before processing. */
2148 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
2149 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
2150 iwe->cmd, iwe->len);
2151 if (iwe->len <= IW_EV_LCP_LEN)
2154 custom = pos + IW_EV_POINT_LEN;
2155 if (drv->we_version > 18 &&
2156 (iwe->cmd == IWEVMICHAELMICFAILURE ||
2157 iwe->cmd == IWEVCUSTOM)) {
2158 /* WE-19 removed the pointer from struct iw_point */
2159 char *dpos = (char *) &iwe_buf.u.data.length;
2160 int dlen = dpos - (char *) &iwe_buf;
2161 memcpy(dpos, pos + IW_EV_LCP_LEN,
2162 sizeof(struct iw_event) - dlen);
2164 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
2165 custom += IW_EV_POINT_OFF;
2170 if (custom + iwe->u.data.length > end)
2172 buf = malloc(iwe->u.data.length + 1);
2175 memcpy(buf, custom, iwe->u.data.length);
2176 buf[iwe->u.data.length] = '\0';
2177 hostapd_wireless_event_wireless_custom(drv, buf);
2187 static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
2188 struct nlmsghdr *h, int len)
2190 struct ifinfomsg *ifi;
2191 int attrlen, nlmsg_len, rta_len;
2192 struct rtattr *attr;
2194 if (len < (int) sizeof(*ifi))
2197 ifi = NLMSG_DATA(h);
2199 /* TODO: use ifi->ifi_index to filter out wireless events from other
2202 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
2204 attrlen = h->nlmsg_len - nlmsg_len;
2208 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
2210 rta_len = RTA_ALIGN(sizeof(struct rtattr));
2211 while (RTA_OK(attr, attrlen)) {
2212 if (attr->rta_type == IFLA_WIRELESS) {
2213 hostapd_wireless_event_wireless(
2214 drv, ((char *) attr) + rta_len,
2215 attr->rta_len - rta_len);
2217 attr = RTA_NEXT(attr, attrlen);
2222 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
2227 struct sockaddr_nl from;
2230 struct i802_driver_data *drv = eloop_ctx;
2232 fromlen = sizeof(from);
2233 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
2234 (struct sockaddr *) &from, &fromlen);
2236 if (errno != EINTR && errno != EAGAIN)
2237 perror("recvfrom(netlink)");
2241 h = (struct nlmsghdr *) buf;
2242 while (left >= (int) sizeof(*h)) {
2246 plen = len - sizeof(*h);
2247 if (len > left || plen < 0) {
2248 printf("Malformed netlink message: "
2249 "len=%d left=%d plen=%d\n",
2254 switch (h->nlmsg_type) {
2256 hostapd_wireless_event_rtm_newlink(drv, h, plen);
2260 len = NLMSG_ALIGN(len);
2262 h = (struct nlmsghdr *) ((char *) h + len);
2266 printf("%d extra bytes in the end of netlink message\n", left);
2271 static int hostap_get_we_version(struct i802_driver_data *drv)
2273 struct iw_range *range;
2278 drv->we_version = 0;
2281 * Use larger buffer than struct iw_range in order to allow the
2282 * structure to grow in the future.
2284 buflen = sizeof(struct iw_range) + 500;
2285 range = os_zalloc(buflen);
2289 memset(&iwr, 0, sizeof(iwr));
2290 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
2291 iwr.u.data.pointer = (caddr_t) range;
2292 iwr.u.data.length = buflen;
2294 minlen = ((char *) &range->enc_capa) - (char *) range +
2295 sizeof(range->enc_capa);
2297 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
2298 perror("ioctl[SIOCGIWRANGE]");
2301 } else if (iwr.u.data.length >= minlen &&
2302 range->we_version_compiled >= 18) {
2303 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
2304 "WE(source)=%d enc_capa=0x%x",
2305 range->we_version_compiled,
2306 range->we_version_source,
2308 drv->we_version = range->we_version_compiled;
2316 static int i802_wireless_event_init(void *priv)
2318 struct i802_driver_data *drv = priv;
2320 struct sockaddr_nl local;
2322 hostap_get_we_version(drv);
2324 drv->wext_sock = -1;
2326 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
2328 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
2332 memset(&local, 0, sizeof(local));
2333 local.nl_family = AF_NETLINK;
2334 local.nl_groups = RTMGRP_LINK;
2335 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
2336 perror("bind(netlink)");
2341 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
2349 static void i802_wireless_event_deinit(void *priv)
2351 struct i802_driver_data *drv = priv;
2352 if (drv->wext_sock < 0)
2354 eloop_unregister_read_sock(drv->wext_sock);
2355 close(drv->wext_sock);
2359 static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
2361 struct i802_driver_data *drv = priv;
2362 struct ieee80211_mgmt mgmt;
2364 memset(&mgmt, 0, sizeof(mgmt));
2365 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2366 WLAN_FC_STYPE_DEAUTH);
2367 memcpy(mgmt.da, addr, ETH_ALEN);
2368 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2369 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2370 mgmt.u.deauth.reason_code = host_to_le16(reason);
2371 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2372 sizeof(mgmt.u.deauth), 0);
2376 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
2378 struct i802_driver_data *drv = priv;
2379 struct ieee80211_mgmt mgmt;
2381 memset(&mgmt, 0, sizeof(mgmt));
2382 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2383 WLAN_FC_STYPE_DISASSOC);
2384 memcpy(mgmt.da, addr, ETH_ALEN);
2385 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2386 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2387 mgmt.u.disassoc.reason_code = host_to_le16(reason);
2388 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2389 sizeof(mgmt.u.disassoc), 0);
2393 static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
2395 struct i802_driver_data *drv;
2397 drv = os_zalloc(sizeof(struct i802_driver_data));
2399 printf("Could not allocate memory for i802 driver data\n");
2404 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
2406 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
2407 drv->if_indices = drv->default_if_indices;
2408 drv->bridge = if_nametoindex(hapd->conf->bridge);
2410 if (i802_init_sockets(drv, bssid))
2421 static void *i802_init(struct hostapd_data *hapd)
2423 return i802_init_bssid(hapd, NULL);
2427 static void i802_deinit(void *priv)
2429 struct i802_driver_data *drv = priv;
2431 if (drv->last_freq_ht) {
2432 /* Clear HT flags from the driver */
2433 struct hostapd_freq_params freq;
2434 os_memset(&freq, 0, sizeof(freq));
2435 freq.freq = drv->last_freq;
2436 i802_set_freq2(priv, &freq);
2439 i802_del_beacon(drv);
2441 /* remove monitor interface */
2442 nl80211_remove_iface(drv, drv->monitor_ifidx);
2444 (void) hostapd_set_iface_flags(drv, drv->iface, 0);
2446 if (drv->monitor_sock >= 0) {
2447 eloop_unregister_read_sock(drv->monitor_sock);
2448 close(drv->monitor_sock);
2450 if (drv->ioctl_sock >= 0)
2451 close(drv->ioctl_sock);
2452 if (drv->eapol_sock >= 0) {
2453 eloop_unregister_read_sock(drv->eapol_sock);
2454 close(drv->eapol_sock);
2457 genl_family_put(drv->nl80211);
2458 nl_cache_free(drv->nl_cache);
2459 nl_handle_destroy(drv->nl_handle);
2460 nl_cb_put(drv->nl_cb);
2462 if (drv->if_indices != drv->default_if_indices)
2463 free(drv->if_indices);
2469 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
2472 .init_bssid = i802_init_bssid,
2473 .deinit = i802_deinit,
2474 .wireless_event_init = i802_wireless_event_init,
2475 .wireless_event_deinit = i802_wireless_event_deinit,
2476 .set_ieee8021x = i802_set_ieee8021x,
2477 .set_privacy = i802_set_privacy,
2478 .set_encryption = i802_set_encryption,
2479 .get_seqnum = i802_get_seqnum,
2480 .flush = i802_flush,
2481 .read_sta_data = i802_read_sta_data,
2482 .send_eapol = i802_send_eapol,
2483 .sta_set_flags = i802_sta_set_flags,
2484 .sta_deauth = i802_sta_deauth,
2485 .sta_disassoc = i802_sta_disassoc,
2486 .sta_remove = i802_sta_remove,
2487 .send_mgmt_frame = i802_send_mgmt_frame,
2488 .sta_add2 = i802_sta_add2,
2489 .get_inact_sec = i802_get_inact_sec,
2490 .sta_clear_stats = i802_sta_clear_stats,
2491 .set_freq2 = i802_set_freq2,
2492 .set_rts = i802_set_rts,
2493 .get_rts = i802_get_rts,
2494 .set_frag = i802_set_frag,
2495 .get_frag = i802_get_frag,
2496 .set_retry = i802_set_retry,
2497 .get_retry = i802_get_retry,
2498 .set_rate_sets = i802_set_rate_sets,
2499 .set_regulatory_domain = i802_set_regulatory_domain,
2500 .set_beacon = i802_set_beacon,
2501 .set_internal_bridge = i802_set_internal_bridge,
2502 .set_beacon_int = i802_set_beacon_int,
2503 .set_dtim_period = i802_set_dtim_period,
2504 .set_cts_protect = i802_set_cts_protect,
2505 .set_preamble = i802_set_preamble,
2506 .set_short_slot_time = i802_set_short_slot_time,
2507 .set_tx_queue_params = i802_set_tx_queue_params,
2508 .bss_add = i802_bss_add,
2509 .bss_remove = i802_bss_remove,
2510 .if_add = i802_if_add,
2511 .if_update = i802_if_update,
2512 .if_remove = i802_if_remove,
2513 .get_hw_feature_data = i802_get_hw_feature_data,
2514 .set_sta_vlan = i802_set_sta_vlan,
2515 .set_country = i802_set_country,