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>
35 #include "hw_features.h"
38 #include "radiotap_iter.h"
41 /* libnl 2.0 compatibility code */
42 #define nl_handle_alloc_cb nl_socket_alloc_cb
43 #define nl_handle_destroy nl_socket_free
44 #endif /* CONFIG_LIBNL20 */
46 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
48 enum ieee80211_msg_type {
49 ieee80211_msg_normal = 0,
50 ieee80211_msg_tx_callback_ack = 1,
51 ieee80211_msg_tx_callback_fail = 2,
54 struct i802_driver_data {
55 struct hostapd_data *hapd;
57 char iface[IFNAMSIZ + 1];
59 int ioctl_sock; /* socket for ioctl() use */
60 int wext_sock; /* socket for wireless events */
61 int eapol_sock; /* socket for EAPOL frames */
62 int monitor_sock; /* socket for monitor */
65 int default_if_indices[16];
70 struct nl_handle *nl_handle;
71 struct nl_cache *nl_cache;
73 struct genl_family *nl80211;
74 int dtim_period, beacon_int;
75 unsigned int beacon_set:1;
76 unsigned int ieee802_1x_active:1;
83 static int i802_sta_deauth(void *priv, const u8 *addr, int reason);
84 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason);
87 static void add_ifidx(struct i802_driver_data *drv, int ifidx)
92 for (i = 0; i < drv->num_if_indices; i++) {
93 if (drv->if_indices[i] == 0) {
94 drv->if_indices[i] = ifidx;
99 if (drv->if_indices != drv->default_if_indices)
100 old = drv->if_indices;
104 drv->if_indices = realloc(old,
105 sizeof(int) * (drv->num_if_indices + 1));
106 if (!drv->if_indices) {
108 drv->if_indices = drv->default_if_indices;
110 drv->if_indices = old;
111 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
113 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
116 drv->if_indices[drv->num_if_indices] = ifidx;
117 drv->num_if_indices++;
121 static void del_ifidx(struct i802_driver_data *drv, int ifidx)
125 for (i = 0; i < drv->num_if_indices; i++) {
126 if (drv->if_indices[i] == ifidx) {
127 drv->if_indices[i] = 0;
134 static int have_ifidx(struct i802_driver_data *drv, int ifidx)
138 if (ifidx == drv->bridge)
141 for (i = 0; i < drv->num_if_indices; i++)
142 if (drv->if_indices[i] == ifidx)
150 static int ack_handler(struct nl_msg *msg, void *arg)
157 static int finish_handler(struct nl_msg *msg, void *arg)
164 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
172 static int send_and_recv_msgs(struct i802_driver_data *drv,
174 int (*valid_handler)(struct nl_msg *, void *),
180 cb = nl_cb_clone(drv->nl_cb);
184 err = nl_send_auto_complete(drv->nl_handle, msg);
190 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
191 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
192 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
195 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
196 valid_handler, valid_data);
199 nl_recvmsgs(drv->nl_handle, cb);
206 static int hostapd_set_iface_flags(struct i802_driver_data *drv,
207 const char *ifname, int dev_up)
211 if (drv->ioctl_sock < 0)
214 memset(&ifr, 0, sizeof(ifr));
215 os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
217 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
218 perror("ioctl[SIOCGIFFLAGS]");
219 wpa_printf(MSG_DEBUG, "Could not read interface flags (%s)",
225 ifr.ifr_flags |= IFF_UP;
227 ifr.ifr_flags &= ~IFF_UP;
229 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
230 perror("ioctl[SIOCSIFFLAGS]");
238 static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
239 const char *alg, const u8 *addr, int idx, const u8 *key,
240 size_t key_len, int txkey)
249 if (strcmp(alg, "none") == 0) {
250 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
251 0, NL80211_CMD_DEL_KEY, 0);
253 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
254 0, NL80211_CMD_NEW_KEY, 0);
255 NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
256 if (strcmp(alg, "WEP") == 0) {
258 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
261 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
263 } else if (strcmp(alg, "TKIP") == 0)
264 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
265 else if (strcmp(alg, "CCMP") == 0)
266 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
267 else if (strcmp(alg, "IGTK") == 0)
268 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC06);
270 wpa_printf(MSG_ERROR, "%s: Unsupported encryption "
271 "algorithm '%s'", __func__, alg);
278 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
279 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
280 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
282 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
287 * If we failed or don't need to set the default TX key (below),
290 if (ret || !txkey || addr)
297 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
298 0, NL80211_CMD_SET_KEY, 0);
299 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
300 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
301 if (strcmp(alg, "IGTK") == 0)
302 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
304 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
306 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
315 static int i802_set_encryption(const char *iface, void *priv, const char *alg,
316 const u8 *addr, int idx, const u8 *key,
317 size_t key_len, int txkey)
319 struct i802_driver_data *drv = priv;
322 ret = nl_set_encr(if_nametoindex(iface), drv, alg, addr, idx, key,
331 static inline int min_int(int a, int b)
339 static int get_key_handler(struct nl_msg *msg, void *arg)
341 struct nlattr *tb[NL80211_ATTR_MAX + 1];
342 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
344 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
345 genlmsg_attrlen(gnlh, 0), NULL);
348 * TODO: validate the key index and mac address!
349 * Otherwise, there's a race condition as soon as
350 * the kernel starts sending key notifications.
353 if (tb[NL80211_ATTR_KEY_SEQ])
354 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
355 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
360 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
363 struct i802_driver_data *drv = priv;
370 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
371 0, NL80211_CMD_GET_KEY, 0);
374 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
375 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
376 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
380 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
386 static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
389 struct i802_driver_data *drv = priv;
391 u8 rates[NL80211_MAX_SUPP_RATES];
399 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
400 NL80211_CMD_SET_BSS, 0);
402 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
403 rates[rates_len++] = basic_rates[i] / 5;
405 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
407 /* TODO: multi-BSS support */
408 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
410 return send_and_recv_msgs(drv, msg, NULL, NULL);
416 static int i802_send_frame(void *priv, const void *data, size_t len,
417 int encrypt, int flags)
420 0x00, 0x00, /* radiotap version */
421 0x0e, 0x00, /* radiotap length */
422 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
423 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
425 0x00, 0x00, /* RX and TX flags to indicate that */
426 0x00, 0x00, /* this is the injected frame directly */
428 struct i802_driver_data *drv = priv;
429 struct iovec iov[2] = {
431 .iov_base = &rtap_hdr,
432 .iov_len = sizeof(rtap_hdr),
435 .iov_base = (void*)data,
439 struct msghdr msg = {
450 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
452 return sendmsg(drv->monitor_sock, &msg, flags);
455 static int i802_send_mgmt_frame(void *priv, const void *data, size_t len,
458 struct ieee80211_mgmt *mgmt;
459 int do_not_encrypt = 0;
462 mgmt = (struct ieee80211_mgmt *) data;
463 fc = le_to_host16(mgmt->frame_control);
465 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
466 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
468 * Only one of the authentication frame types is encrypted.
469 * In order for static WEP encryption to work properly (i.e.,
470 * to not encrypt the frame), we need to tell mac80211 about
471 * the frames that must not be encrypted.
473 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
474 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
475 if (auth_alg == WLAN_AUTH_OPEN ||
476 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_trans != 3))
480 return i802_send_frame(priv, data, len, !do_not_encrypt, flags);
483 /* Set kernel driver on given frequency (MHz) */
484 static int i802_set_freq2(void *priv, struct hostapd_freq_params *freq)
486 struct i802_driver_data *drv = priv;
493 drv->last_freq = freq->freq;
494 drv->last_freq_ht = freq->ht_enabled;
496 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
497 NL80211_CMD_SET_WIPHY, 0);
499 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
500 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
501 if (freq->ht_enabled) {
502 switch (freq->sec_channel_offset) {
504 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
505 NL80211_CHAN_HT40MINUS);
508 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
509 NL80211_CHAN_HT40PLUS);
512 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
518 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
525 static int i802_set_rts(void *priv, int rts)
527 struct i802_driver_data *drv = priv;
530 memset(&iwr, 0, sizeof(iwr));
531 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
532 iwr.u.rts.value = rts;
535 if (ioctl(drv->ioctl_sock, SIOCSIWRTS, &iwr) < 0) {
536 perror("ioctl[SIOCSIWRTS]");
544 static int i802_get_rts(void *priv, int *rts)
546 struct i802_driver_data *drv = priv;
549 memset(&iwr, 0, sizeof(iwr));
550 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
552 if (ioctl(drv->ioctl_sock, SIOCGIWRTS, &iwr) < 0) {
553 perror("ioctl[SIOCGIWRTS]");
557 *rts = iwr.u.rts.value;
563 static int i802_set_frag(void *priv, int frag)
565 struct i802_driver_data *drv = priv;
568 memset(&iwr, 0, sizeof(iwr));
569 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
570 iwr.u.frag.value = frag;
571 iwr.u.frag.fixed = 1;
573 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
574 perror("ioctl[SIOCSIWFRAG]");
582 static int i802_get_frag(void *priv, int *frag)
584 struct i802_driver_data *drv = priv;
587 memset(&iwr, 0, sizeof(iwr));
588 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
590 if (ioctl(drv->ioctl_sock, SIOCGIWFRAG, &iwr) < 0) {
591 perror("ioctl[SIOCGIWFRAG]");
595 *frag = iwr.u.frag.value;
601 static int i802_set_retry(void *priv, int short_retry, int long_retry)
603 struct i802_driver_data *drv = priv;
606 memset(&iwr, 0, sizeof(iwr));
607 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
609 iwr.u.retry.value = short_retry;
610 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
611 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
612 perror("ioctl[SIOCSIWRETRY(short)]");
616 iwr.u.retry.value = long_retry;
617 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
618 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
619 perror("ioctl[SIOCSIWRETRY(long)]");
627 static int i802_get_retry(void *priv, int *short_retry, int *long_retry)
629 struct i802_driver_data *drv = priv;
632 memset(&iwr, 0, sizeof(iwr));
633 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
635 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
636 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
637 perror("ioctl[SIOCGIWFRAG(short)]");
640 *short_retry = iwr.u.retry.value;
642 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
643 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
644 perror("ioctl[SIOCGIWFRAG(long)]");
647 *long_retry = iwr.u.retry.value;
653 static int i802_flush(void *priv)
655 struct i802_driver_data *drv = priv;
662 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
663 0, NL80211_CMD_DEL_STATION, 0);
666 * XXX: FIX! this needs to flush all VLANs too
668 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
669 if_nametoindex(drv->iface));
671 return send_and_recv_msgs(drv, msg, NULL, NULL);
677 static int get_sta_handler(struct nl_msg *msg, void *arg)
679 struct nlattr *tb[NL80211_ATTR_MAX + 1];
680 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
681 struct hostap_sta_driver_data *data = arg;
682 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
683 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
684 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
685 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
686 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
689 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
690 genlmsg_attrlen(gnlh, 0), NULL);
693 * TODO: validate the interface and mac address!
694 * Otherwise, there's a race condition as soon as
695 * the kernel starts sending station notifications.
698 if (!tb[NL80211_ATTR_STA_INFO]) {
699 wpa_printf(MSG_DEBUG, "sta stats missing!");
702 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
703 tb[NL80211_ATTR_STA_INFO],
705 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
709 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
710 data->inactive_msec =
711 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
712 if (stats[NL80211_STA_INFO_RX_BYTES])
713 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
714 if (stats[NL80211_STA_INFO_TX_BYTES])
715 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
720 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
723 struct i802_driver_data *drv = priv;
730 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
731 0, NL80211_CMD_GET_STATION, 0);
733 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
734 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
736 return send_and_recv_msgs(drv, msg, get_sta_handler, data);
742 static int i802_send_eapol(void *priv, const u8 *addr, const u8 *data,
743 size_t data_len, int encrypt, const u8 *own_addr)
745 struct i802_driver_data *drv = priv;
746 struct ieee80211_hdr *hdr;
751 int qos = sta->flags & WLAN_STA_WME;
756 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
758 hdr = os_zalloc(len);
760 printf("malloc() failed for i802_send_data(len=%lu)\n",
761 (unsigned long) len);
766 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
767 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
769 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
770 #if 0 /* To be enabled if qos determination is added above */
772 hdr->frame_control |=
773 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
777 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
778 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
779 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
780 pos = (u8 *) (hdr + 1);
782 #if 0 /* To be enabled if qos determination is added above */
784 /* add an empty QoS header if needed */
791 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
792 pos += sizeof(rfc1042_header);
793 WPA_PUT_BE16(pos, ETH_P_PAE);
795 memcpy(pos, data, data_len);
797 res = i802_send_frame(drv, (u8 *) hdr, len, encrypt, 0);
801 perror("i802_send_eapol: send");
802 printf("i802_send_eapol - packet len: %lu - failed\n",
803 (unsigned long) len);
810 static int i802_sta_add2(const char *ifname, void *priv,
811 struct hostapd_sta_add_params *params)
813 struct i802_driver_data *drv = priv;
821 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
822 0, NL80211_CMD_NEW_STATION, 0);
824 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
825 if_nametoindex(drv->iface));
826 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr);
827 NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid);
828 NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len,
830 NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
831 params->listen_interval);
833 #ifdef CONFIG_IEEE80211N
834 if (params->ht_capabilities) {
835 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
836 params->ht_capabilities->length,
837 ¶ms->ht_capabilities->data);
839 #endif /* CONFIG_IEEE80211N */
841 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
849 static int i802_sta_remove(void *priv, const u8 *addr)
851 struct i802_driver_data *drv = priv;
859 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
860 0, NL80211_CMD_DEL_STATION, 0);
862 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
863 if_nametoindex(drv->iface));
864 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
866 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
875 static int i802_sta_set_flags(void *priv, const u8 *addr,
876 int total_flags, int flags_or, int flags_and)
878 struct i802_driver_data *drv = priv;
879 struct nl_msg *msg, *flags = NULL;
885 flags = nlmsg_alloc();
891 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
892 0, NL80211_CMD_SET_STATION, 0);
894 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
895 if_nametoindex(drv->iface));
896 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
898 if (total_flags & WLAN_STA_AUTHORIZED || !drv->ieee802_1x_active)
899 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
901 if (total_flags & WLAN_STA_WME)
902 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
904 if (total_flags & WLAN_STA_SHORT_PREAMBLE)
905 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
907 if (total_flags & WLAN_STA_MFP)
908 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
910 if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
911 goto nla_put_failure;
915 return send_and_recv_msgs(drv, msg, NULL, NULL);
922 static int i802_set_regulatory_domain(void *priv, unsigned int rd)
928 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
929 int cw_min, int cw_max, int burst_time)
931 struct i802_driver_data *drv = priv;
933 struct nlattr *txq, *params;
939 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
940 0, NL80211_CMD_SET_WIPHY, 0);
942 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
944 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
946 goto nla_put_failure;
948 /* We are only sending parameters for a single TXQ at a time */
949 params = nla_nest_start(msg, 1);
951 goto nla_put_failure;
953 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue);
954 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
955 * 32 usec, so need to convert the value here. */
956 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32);
957 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min);
958 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max);
959 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs);
961 nla_nest_end(msg, params);
963 nla_nest_end(msg, txq);
965 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
972 static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
976 /* stop listening for EAPOL on this interface */
977 del_ifidx(drv, ifidx);
981 goto nla_put_failure;
983 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
984 0, NL80211_CMD_DEL_INTERFACE, 0);
985 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
987 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
990 printf("Failed to remove interface.\n");
994 static int nl80211_create_iface(struct i802_driver_data *drv,
996 enum nl80211_iftype iftype,
999 struct nl_msg *msg, *flags = NULL;
1005 msg = nlmsg_alloc();
1009 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1010 0, NL80211_CMD_NEW_INTERFACE, 0);
1011 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1012 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
1013 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
1015 if (iftype == NL80211_IFTYPE_MONITOR) {
1018 flags = nlmsg_alloc();
1020 goto nla_put_failure;
1022 NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
1024 err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
1029 goto nla_put_failure;
1032 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1035 printf("Failed to create interface %s.\n", ifname);
1039 ifidx = if_nametoindex(ifname);
1044 /* start listening for EAPOL on this interface */
1045 add_ifidx(drv, ifidx);
1049 case NL80211_IFTYPE_AP:
1050 os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
1051 memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
1052 ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1054 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
1055 nl80211_remove_iface(drv, ifidx);
1059 case NL80211_IFTYPE_WDS:
1060 memset(&iwr, 0, sizeof(iwr));
1061 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1062 iwr.u.addr.sa_family = ARPHRD_ETHER;
1063 memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
1064 if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
1077 static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
1082 * The kernel supports that when the low-level driver does,
1083 * but we currently don't because we need per-BSS data that
1084 * currently we can't handle easily.
1088 ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
1091 if (hostapd_set_iface_flags(priv, ifname, 1)) {
1092 nl80211_remove_iface(priv, ifidx);
1099 static int i802_bss_remove(void *priv, const char *ifname)
1101 nl80211_remove_iface(priv, if_nametoindex(ifname));
1106 static int i802_set_beacon(const char *iface, void *priv,
1107 u8 *head, size_t head_len,
1108 u8 *tail, size_t tail_len)
1110 struct i802_driver_data *drv = priv;
1112 u8 cmd = NL80211_CMD_NEW_BEACON;
1115 msg = nlmsg_alloc();
1119 if (drv->beacon_set)
1120 cmd = NL80211_CMD_SET_BEACON;
1122 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1124 NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
1125 NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
1126 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1127 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
1129 if (!drv->dtim_period)
1130 drv->dtim_period = 2;
1131 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1133 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1135 drv->beacon_set = 1;
1142 static int i802_del_beacon(struct i802_driver_data *drv)
1146 msg = nlmsg_alloc();
1150 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1151 0, NL80211_CMD_DEL_BEACON, 0);
1152 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1154 return send_and_recv_msgs(drv, msg, NULL, NULL);
1160 static int i802_set_ieee8021x(const char *ifname, void *priv, int enabled)
1162 struct i802_driver_data *drv = priv;
1165 * FIXME: This needs to be per interface (BSS)
1167 drv->ieee802_1x_active = enabled;
1172 static int i802_set_privacy(const char *ifname, void *priv, int enabled)
1174 struct i802_driver_data *drv = priv;
1177 memset(&iwr, 0, sizeof(iwr));
1179 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1180 iwr.u.param.flags = IW_AUTH_PRIVACY_INVOKED;
1181 iwr.u.param.value = enabled;
1183 ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr);
1185 /* ignore errors, the kernel/driver might not care */
1190 static int i802_set_internal_bridge(void *priv, int value)
1196 static int i802_set_beacon_int(void *priv, int value)
1198 struct i802_driver_data *drv = priv;
1201 drv->beacon_int = value;
1203 if (!drv->beacon_set)
1206 msg = nlmsg_alloc();
1210 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1211 0, NL80211_CMD_SET_BEACON, 0);
1212 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1214 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
1216 return send_and_recv_msgs(drv, msg, NULL, NULL);
1222 static int i802_set_dtim_period(const char *iface, void *priv, int value)
1224 struct i802_driver_data *drv = priv;
1227 msg = nlmsg_alloc();
1231 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1232 0, NL80211_CMD_SET_BEACON, 0);
1233 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1235 drv->dtim_period = value;
1236 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1238 return send_and_recv_msgs(drv, msg, NULL, NULL);
1244 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
1246 struct i802_driver_data *drv = priv;
1249 msg = nlmsg_alloc();
1253 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
1254 NL80211_CMD_SET_BSS, 0);
1257 NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
1259 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
1261 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
1263 /* TODO: multi-BSS support */
1264 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1266 return send_and_recv_msgs(drv, msg, NULL, NULL);
1272 static int i802_set_cts_protect(void *priv, int value)
1274 return i802_set_bss(priv, value, -1, -1);
1278 static int i802_set_preamble(void *priv, int value)
1280 return i802_set_bss(priv, -1, value, -1);
1284 static int i802_set_short_slot_time(void *priv, int value)
1286 return i802_set_bss(priv, -1, -1, value);
1290 static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
1293 case HOSTAPD_IF_VLAN:
1294 return NL80211_IFTYPE_AP_VLAN;
1295 case HOSTAPD_IF_WDS:
1296 return NL80211_IFTYPE_WDS;
1302 static int i802_if_add(const char *iface, void *priv,
1303 enum hostapd_driver_if_type type, char *ifname,
1306 if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
1312 static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
1313 char *ifname, const u8 *addr)
1315 /* unused at the moment */
1320 static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
1321 const char *ifname, const u8 *addr)
1323 nl80211_remove_iface(priv, if_nametoindex(ifname));
1328 struct phy_info_arg {
1330 struct hostapd_hw_modes *modes;
1333 static int phy_info_handler(struct nl_msg *msg, void *arg)
1335 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1336 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1337 struct phy_info_arg *phy_info = arg;
1339 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1341 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1342 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1343 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1344 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1345 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
1346 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
1347 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1348 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1351 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1352 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1353 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1354 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
1357 struct nlattr *nl_band;
1358 struct nlattr *nl_freq;
1359 struct nlattr *nl_rate;
1360 int rem_band, rem_freq, rem_rate;
1361 struct hostapd_hw_modes *mode;
1362 int idx, mode_is_set;
1364 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1365 genlmsg_attrlen(gnlh, 0), NULL);
1367 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1370 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
1371 mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
1374 phy_info->modes = mode;
1378 mode = &phy_info->modes[*(phy_info->num_modes)];
1379 memset(mode, 0, sizeof(*mode));
1380 *(phy_info->num_modes) += 1;
1382 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1383 nla_len(nl_band), NULL);
1385 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1386 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1387 nla_len(nl_freq), freq_policy);
1388 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1390 mode->num_channels++;
1393 mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
1394 if (!mode->channels)
1399 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1400 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1401 nla_len(nl_freq), freq_policy);
1402 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1405 mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1406 mode->channels[idx].flag = 0;
1409 /* crude heuristic */
1410 if (mode->channels[idx].freq < 4000)
1411 mode->mode = HOSTAPD_MODE_IEEE80211B;
1413 mode->mode = HOSTAPD_MODE_IEEE80211A;
1417 /* crude heuristic */
1418 if (mode->channels[idx].freq < 4000)
1419 if (mode->channels[idx].freq == 2848)
1420 mode->channels[idx].chan = 14;
1422 mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
1424 mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
1426 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1427 mode->channels[idx].flag |=
1428 HOSTAPD_CHAN_DISABLED;
1429 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
1430 mode->channels[idx].flag |=
1431 HOSTAPD_CHAN_PASSIVE_SCAN;
1432 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
1433 mode->channels[idx].flag |=
1434 HOSTAPD_CHAN_NO_IBSS;
1435 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1436 mode->channels[idx].flag |=
1439 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
1440 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1441 mode->channels[idx].max_tx_power =
1442 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100;
1447 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1448 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1449 nla_len(nl_rate), rate_policy);
1450 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1455 mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
1461 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1462 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1463 nla_len(nl_rate), rate_policy);
1464 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1466 mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
1468 /* crude heuristic */
1469 if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
1470 mode->rates[idx].rate > 200)
1471 mode->mode = HOSTAPD_MODE_IEEE80211G;
1473 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
1474 mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
1483 static struct hostapd_hw_modes *i802_add_11b(struct hostapd_hw_modes *modes,
1487 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1488 int i, mode11g_idx = -1;
1490 /* If only 802.11g mode is included, use it to construct matching
1491 * 802.11b mode data. */
1493 for (m = 0; m < *num_modes; m++) {
1494 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1495 return modes; /* 802.11b already included */
1496 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1500 if (mode11g_idx < 0)
1501 return modes; /* 2.4 GHz band not supported at all */
1503 nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes));
1505 return modes; /* Could not add 802.11b mode */
1507 mode = &nmodes[*num_modes];
1508 os_memset(mode, 0, sizeof(*mode));
1512 mode->mode = HOSTAPD_MODE_IEEE80211B;
1514 mode11g = &modes[mode11g_idx];
1515 mode->num_channels = mode11g->num_channels;
1516 mode->channels = os_malloc(mode11g->num_channels *
1517 sizeof(struct hostapd_channel_data));
1518 if (mode->channels == NULL) {
1520 return modes; /* Could not add 802.11b mode */
1522 os_memcpy(mode->channels, mode11g->channels,
1523 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1525 mode->num_rates = 0;
1526 mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
1527 if (mode->rates == NULL) {
1528 os_free(mode->channels);
1530 return modes; /* Could not add 802.11b mode */
1533 for (i = 0; i < mode11g->num_rates; i++) {
1534 if (mode11g->rates[i].rate > 110 ||
1535 mode11g->rates[i].flags &
1536 (HOSTAPD_RATE_ERP | HOSTAPD_RATE_OFDM))
1538 mode->rates[mode->num_rates] = mode11g->rates[i];
1540 if (mode->num_rates == 4)
1544 if (mode->num_rates == 0) {
1545 os_free(mode->channels);
1546 os_free(mode->rates);
1548 return modes; /* No 802.11b rates */
1551 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1557 static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
1561 struct i802_driver_data *drv = priv;
1563 struct phy_info_arg result = {
1564 .num_modes = num_modes,
1571 msg = nlmsg_alloc();
1575 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1576 0, NL80211_CMD_GET_WIPHY, 0);
1578 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1580 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
1581 return i802_add_11b(result.modes, num_modes);
1587 static int i802_set_sta_vlan(void *priv, const u8 *addr,
1588 const char *ifname, int vlan_id)
1590 struct i802_driver_data *drv = priv;
1593 msg = nlmsg_alloc();
1597 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1598 0, NL80211_CMD_SET_STATION, 0);
1600 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1601 if_nametoindex(drv->iface));
1602 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
1603 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1604 if_nametoindex(ifname));
1606 return send_and_recv_msgs(drv, msg, NULL, NULL);
1612 static int i802_set_country(void *priv, const char *country)
1614 struct i802_driver_data *drv = priv;
1618 msg = nlmsg_alloc();
1622 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1623 0, NL80211_CMD_REQ_SET_REG, 0);
1625 alpha2[0] = country[0];
1626 alpha2[1] = country[1];
1628 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
1630 return send_and_recv_msgs(drv, msg, NULL, NULL);
1636 static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
1639 struct ieee80211_hdr *hdr;
1640 u16 fc, type, stype;
1642 hdr = (struct ieee80211_hdr *) buf;
1643 fc = le_to_host16(hdr->frame_control);
1645 type = WLAN_FC_GET_TYPE(fc);
1646 stype = WLAN_FC_GET_STYPE(fc);
1649 case WLAN_FC_TYPE_MGMT:
1650 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
1651 ok ? "ACK" : "fail");
1652 hostapd_mgmt_tx_cb(hapd, buf, len, stype, ok);
1654 case WLAN_FC_TYPE_CTRL:
1655 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
1656 ok ? "ACK" : "fail");
1658 case WLAN_FC_TYPE_DATA:
1659 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
1660 ok ? "ACK" : "fail");
1661 hostapd_tx_status(hapd, hdr->addr1, buf, len, ok);
1664 printf("unknown TX callback frame type %d\n", type);
1670 static void handle_frame(struct i802_driver_data *drv,
1671 struct hostapd_iface *iface, u8 *buf, size_t len,
1672 struct hostapd_frame_info *hfi,
1673 enum ieee80211_msg_type msg_type)
1675 struct ieee80211_hdr *hdr;
1676 u16 fc, type, stype;
1677 size_t data_len = len;
1678 struct hostapd_data *hapd = NULL;
1679 int broadcast_bssid = 0;
1684 * PS-Poll frames are 16 bytes. All other frames are
1685 * 24 bytes or longer.
1690 hdr = (struct ieee80211_hdr *) buf;
1691 fc = le_to_host16(hdr->frame_control);
1693 type = WLAN_FC_GET_TYPE(fc);
1694 stype = WLAN_FC_GET_STYPE(fc);
1697 case WLAN_FC_TYPE_DATA:
1700 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
1709 case WLAN_FC_TYPE_CTRL:
1710 /* discard non-ps-poll frames */
1711 if (stype != WLAN_FC_STYPE_PSPOLL)
1715 case WLAN_FC_TYPE_MGMT:
1723 /* find interface frame belongs to */
1724 for (i = 0; i < iface->num_bss; i++) {
1725 if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
1726 hapd = iface->bss[i];
1732 hapd = iface->bss[0];
1734 if (bssid[0] != 0xff || bssid[1] != 0xff ||
1735 bssid[2] != 0xff || bssid[3] != 0xff ||
1736 bssid[4] != 0xff || bssid[5] != 0xff) {
1738 * Unknown BSSID - drop frame if this is not from
1739 * passive scanning or a beacon (at least ProbeReq
1740 * frames to other APs may be allowed through RX
1741 * filtering in the wlan hw/driver)
1743 if ((type != WLAN_FC_TYPE_MGMT ||
1744 stype != WLAN_FC_STYPE_BEACON))
1747 broadcast_bssid = 1;
1751 case ieee80211_msg_normal:
1752 /* continue processing */
1754 case ieee80211_msg_tx_callback_ack:
1755 handle_tx_callback(hapd, buf, data_len, 1);
1757 case ieee80211_msg_tx_callback_fail:
1758 handle_tx_callback(hapd, buf, data_len, 0);
1763 case WLAN_FC_TYPE_MGMT:
1764 if (stype != WLAN_FC_STYPE_BEACON &&
1765 stype != WLAN_FC_STYPE_PROBE_REQ)
1766 wpa_printf(MSG_MSGDUMP, "MGMT");
1767 if (broadcast_bssid) {
1768 for (i = 0; i < iface->num_bss; i++)
1769 hostapd_mgmt_rx(iface->bss[i], buf, data_len,
1772 hostapd_mgmt_rx(hapd, buf, data_len, stype, hfi);
1774 case WLAN_FC_TYPE_CTRL:
1775 /* can only get here with PS-Poll frames */
1776 wpa_printf(MSG_DEBUG, "CTRL");
1777 hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
1779 case WLAN_FC_TYPE_DATA:
1780 hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
1786 static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
1788 struct i802_driver_data *drv = eloop_ctx;
1789 struct hostapd_data *hapd = drv->hapd;
1790 struct sockaddr_ll lladdr;
1791 unsigned char buf[3000];
1793 socklen_t fromlen = sizeof(lladdr);
1795 len = recvfrom(sock, buf, sizeof(buf), 0,
1796 (struct sockaddr *)&lladdr, &fromlen);
1802 if (have_ifidx(drv, lladdr.sll_ifindex))
1803 hostapd_eapol_receive(hapd, lladdr.sll_addr, buf, len);
1807 static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
1809 struct i802_driver_data *drv = eloop_ctx;
1811 unsigned char buf[3000];
1812 struct hostapd_data *hapd = drv->hapd;
1813 struct ieee80211_radiotap_iterator iter;
1815 struct hostapd_frame_info hfi;
1816 int injected = 0, failed = 0, msg_type, rxflags = 0;
1818 len = recv(sock, buf, sizeof(buf), 0);
1824 if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
1825 printf("received invalid radiotap frame\n");
1829 memset(&hfi, 0, sizeof(hfi));
1832 ret = ieee80211_radiotap_iterator_next(&iter);
1836 printf("received invalid radiotap frame (%d)\n", ret);
1839 switch (iter.this_arg_index) {
1840 case IEEE80211_RADIOTAP_FLAGS:
1841 if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
1844 case IEEE80211_RADIOTAP_RX_FLAGS:
1847 case IEEE80211_RADIOTAP_TX_FLAGS:
1849 failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
1850 IEEE80211_RADIOTAP_F_TX_FAIL;
1852 case IEEE80211_RADIOTAP_DATA_RETRIES:
1854 case IEEE80211_RADIOTAP_CHANNEL:
1855 /* TODO convert from freq/flags to channel number
1860 case IEEE80211_RADIOTAP_RATE:
1861 hfi.datarate = *iter.this_arg * 5;
1863 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1864 hfi.ssi_signal = *iter.this_arg;
1869 if (rxflags && injected)
1873 msg_type = ieee80211_msg_normal;
1875 msg_type = ieee80211_msg_tx_callback_fail;
1877 msg_type = ieee80211_msg_tx_callback_ack;
1879 handle_frame(drv, hapd->iface, buf + iter.max_length,
1880 len - iter.max_length, &hfi, msg_type);
1884 static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
1887 struct sockaddr_ll ll;
1891 snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
1892 buf[IFNAMSIZ - 1] = '\0';
1894 drv->monitor_ifidx =
1895 nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
1897 if (drv->monitor_ifidx < 0)
1900 if (hostapd_set_iface_flags(drv, buf, 1))
1903 memset(&ll, 0, sizeof(ll));
1904 ll.sll_family = AF_PACKET;
1905 ll.sll_ifindex = drv->monitor_ifidx;
1906 drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1907 if (drv->monitor_sock < 0) {
1908 perror("socket[PF_PACKET,SOCK_RAW]");
1912 if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
1914 perror("monitor socket bind");
1918 optlen = sizeof(optval);
1921 (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
1922 perror("Failed to set socket priority");
1926 if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
1928 printf("Could not register monitor read socket\n");
1934 nl80211_remove_iface(drv, drv->monitor_ifidx);
1939 static int nl80211_set_master_mode(struct i802_driver_data *drv,
1945 msg = nlmsg_alloc();
1949 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1950 0, NL80211_CMD_SET_INTERFACE, 0);
1951 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1952 if_nametoindex(ifname));
1953 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
1955 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1959 wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
1965 static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
1968 struct sockaddr_ll addr;
1970 drv->ioctl_sock = -1;
1972 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1973 if (drv->ioctl_sock < 0) {
1974 perror("socket[PF_INET,SOCK_DGRAM]");
1978 /* start listening for EAPOL on the default AP interface */
1979 add_ifidx(drv, if_nametoindex(drv->iface));
1981 if (hostapd_set_iface_flags(drv, drv->iface, 0))
1985 os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
1986 memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
1987 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1989 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
1990 perror("ioctl(SIOCSIFHWADDR)");
1996 * initialise generic netlink and nl80211
1998 drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
2000 printf("Failed to allocate netlink callbacks.\n");
2004 drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
2005 if (!drv->nl_handle) {
2006 printf("Failed to allocate netlink handle.\n");
2010 if (genl_connect(drv->nl_handle)) {
2011 printf("Failed to connect to generic netlink.\n");
2015 #ifdef CONFIG_LIBNL20
2016 if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
2017 printf("Failed to allocate generic netlink cache.\n");
2020 #else /* CONFIG_LIBNL20 */
2021 drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
2022 if (!drv->nl_cache) {
2023 printf("Failed to allocate generic netlink cache.\n");
2026 #endif /* CONFIG_LIBNL20 */
2028 drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
2029 if (!drv->nl80211) {
2030 printf("nl80211 not found.\n");
2034 /* Initialise a monitor interface */
2035 if (nl80211_create_monitor_interface(drv))
2038 if (nl80211_set_master_mode(drv, drv->iface))
2041 if (hostapd_set_iface_flags(drv, drv->iface, 1))
2044 memset(&addr, 0, sizeof(addr));
2045 addr.sll_family = AF_PACKET;
2046 addr.sll_ifindex = ifr.ifr_ifindex;
2047 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
2050 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
2051 if (drv->eapol_sock < 0) {
2052 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
2056 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
2058 printf("Could not register read socket for eapol\n");
2062 memset(&ifr, 0, sizeof(ifr));
2063 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
2064 if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
2065 perror("ioctl(SIOCGIFHWADDR)");
2069 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
2070 printf("Invalid HW-addr family 0x%04x\n",
2071 ifr.ifr_hwaddr.sa_family);
2074 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
2079 nl80211_remove_iface(drv, drv->monitor_ifidx);
2084 static int i802_get_inact_sec(void *priv, const u8 *addr)
2086 struct hostap_sta_driver_data data;
2089 data.inactive_msec = (unsigned long) -1;
2090 ret = i802_read_sta_data(priv, &data, addr);
2091 if (ret || data.inactive_msec == (unsigned long) -1)
2093 return data.inactive_msec / 1000;
2097 static int i802_sta_clear_stats(void *priv, const u8 *addr)
2107 hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
2110 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
2112 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
2115 pos = strstr(custom, "addr=");
2117 wpa_printf(MSG_DEBUG,
2118 "MLME-MICHAELMICFAILURE.indication "
2119 "without sender address ignored");
2123 if (hwaddr_aton(pos, addr) == 0) {
2124 hostapd_michael_mic_failure(drv->hapd, addr);
2126 wpa_printf(MSG_DEBUG,
2127 "MLME-MICHAELMICFAILURE.indication "
2128 "with invalid MAC address");
2134 static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
2135 char *data, int len)
2137 struct iw_event iwe_buf, *iwe = &iwe_buf;
2138 char *pos, *end, *custom, *buf;
2143 while (pos + IW_EV_LCP_LEN <= end) {
2144 /* Event data may be unaligned, so make a local, aligned copy
2145 * before processing. */
2146 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
2147 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
2148 iwe->cmd, iwe->len);
2149 if (iwe->len <= IW_EV_LCP_LEN)
2152 custom = pos + IW_EV_POINT_LEN;
2153 if (drv->we_version > 18 &&
2154 (iwe->cmd == IWEVMICHAELMICFAILURE ||
2155 iwe->cmd == IWEVCUSTOM)) {
2156 /* WE-19 removed the pointer from struct iw_point */
2157 char *dpos = (char *) &iwe_buf.u.data.length;
2158 int dlen = dpos - (char *) &iwe_buf;
2159 memcpy(dpos, pos + IW_EV_LCP_LEN,
2160 sizeof(struct iw_event) - dlen);
2162 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
2163 custom += IW_EV_POINT_OFF;
2168 if (custom + iwe->u.data.length > end)
2170 buf = malloc(iwe->u.data.length + 1);
2173 memcpy(buf, custom, iwe->u.data.length);
2174 buf[iwe->u.data.length] = '\0';
2175 hostapd_wireless_event_wireless_custom(drv, buf);
2185 static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
2186 struct nlmsghdr *h, int len)
2188 struct ifinfomsg *ifi;
2189 int attrlen, nlmsg_len, rta_len;
2190 struct rtattr *attr;
2192 if (len < (int) sizeof(*ifi))
2195 ifi = NLMSG_DATA(h);
2197 /* TODO: use ifi->ifi_index to filter out wireless events from other
2200 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
2202 attrlen = h->nlmsg_len - nlmsg_len;
2206 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
2208 rta_len = RTA_ALIGN(sizeof(struct rtattr));
2209 while (RTA_OK(attr, attrlen)) {
2210 if (attr->rta_type == IFLA_WIRELESS) {
2211 hostapd_wireless_event_wireless(
2212 drv, ((char *) attr) + rta_len,
2213 attr->rta_len - rta_len);
2215 attr = RTA_NEXT(attr, attrlen);
2220 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
2225 struct sockaddr_nl from;
2228 struct i802_driver_data *drv = eloop_ctx;
2230 fromlen = sizeof(from);
2231 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
2232 (struct sockaddr *) &from, &fromlen);
2234 if (errno != EINTR && errno != EAGAIN)
2235 perror("recvfrom(netlink)");
2239 h = (struct nlmsghdr *) buf;
2240 while (left >= (int) sizeof(*h)) {
2244 plen = len - sizeof(*h);
2245 if (len > left || plen < 0) {
2246 printf("Malformed netlink message: "
2247 "len=%d left=%d plen=%d\n",
2252 switch (h->nlmsg_type) {
2254 hostapd_wireless_event_rtm_newlink(drv, h, plen);
2258 len = NLMSG_ALIGN(len);
2260 h = (struct nlmsghdr *) ((char *) h + len);
2264 printf("%d extra bytes in the end of netlink message\n", left);
2269 static int hostap_get_we_version(struct i802_driver_data *drv)
2271 struct iw_range *range;
2276 drv->we_version = 0;
2279 * Use larger buffer than struct iw_range in order to allow the
2280 * structure to grow in the future.
2282 buflen = sizeof(struct iw_range) + 500;
2283 range = os_zalloc(buflen);
2287 memset(&iwr, 0, sizeof(iwr));
2288 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
2289 iwr.u.data.pointer = (caddr_t) range;
2290 iwr.u.data.length = buflen;
2292 minlen = ((char *) &range->enc_capa) - (char *) range +
2293 sizeof(range->enc_capa);
2295 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
2296 perror("ioctl[SIOCGIWRANGE]");
2299 } else if (iwr.u.data.length >= minlen &&
2300 range->we_version_compiled >= 18) {
2301 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
2302 "WE(source)=%d enc_capa=0x%x",
2303 range->we_version_compiled,
2304 range->we_version_source,
2306 drv->we_version = range->we_version_compiled;
2314 static int i802_wireless_event_init(void *priv)
2316 struct i802_driver_data *drv = priv;
2318 struct sockaddr_nl local;
2320 hostap_get_we_version(drv);
2322 drv->wext_sock = -1;
2324 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
2326 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
2330 memset(&local, 0, sizeof(local));
2331 local.nl_family = AF_NETLINK;
2332 local.nl_groups = RTMGRP_LINK;
2333 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
2334 perror("bind(netlink)");
2339 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
2347 static void i802_wireless_event_deinit(void *priv)
2349 struct i802_driver_data *drv = priv;
2350 if (drv->wext_sock < 0)
2352 eloop_unregister_read_sock(drv->wext_sock);
2353 close(drv->wext_sock);
2357 static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
2359 struct i802_driver_data *drv = priv;
2360 struct ieee80211_mgmt mgmt;
2362 memset(&mgmt, 0, sizeof(mgmt));
2363 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2364 WLAN_FC_STYPE_DEAUTH);
2365 memcpy(mgmt.da, addr, ETH_ALEN);
2366 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2367 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2368 mgmt.u.deauth.reason_code = host_to_le16(reason);
2369 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2370 sizeof(mgmt.u.deauth), 0);
2374 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
2376 struct i802_driver_data *drv = priv;
2377 struct ieee80211_mgmt mgmt;
2379 memset(&mgmt, 0, sizeof(mgmt));
2380 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2381 WLAN_FC_STYPE_DISASSOC);
2382 memcpy(mgmt.da, addr, ETH_ALEN);
2383 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2384 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2385 mgmt.u.disassoc.reason_code = host_to_le16(reason);
2386 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2387 sizeof(mgmt.u.disassoc), 0);
2391 static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
2393 struct i802_driver_data *drv;
2395 drv = os_zalloc(sizeof(struct i802_driver_data));
2397 printf("Could not allocate memory for i802 driver data\n");
2402 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
2404 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
2405 drv->if_indices = drv->default_if_indices;
2406 drv->bridge = if_nametoindex(hapd->conf->bridge);
2408 if (i802_init_sockets(drv, bssid))
2419 static void *i802_init(struct hostapd_data *hapd)
2421 return i802_init_bssid(hapd, NULL);
2425 static void i802_deinit(void *priv)
2427 struct i802_driver_data *drv = priv;
2429 if (drv->last_freq_ht) {
2430 /* Clear HT flags from the driver */
2431 struct hostapd_freq_params freq;
2432 os_memset(&freq, 0, sizeof(freq));
2433 freq.freq = drv->last_freq;
2434 i802_set_freq2(priv, &freq);
2437 i802_del_beacon(drv);
2439 /* remove monitor interface */
2440 nl80211_remove_iface(drv, drv->monitor_ifidx);
2442 (void) hostapd_set_iface_flags(drv, drv->iface, 0);
2444 if (drv->monitor_sock >= 0) {
2445 eloop_unregister_read_sock(drv->monitor_sock);
2446 close(drv->monitor_sock);
2448 if (drv->ioctl_sock >= 0)
2449 close(drv->ioctl_sock);
2450 if (drv->eapol_sock >= 0) {
2451 eloop_unregister_read_sock(drv->eapol_sock);
2452 close(drv->eapol_sock);
2455 genl_family_put(drv->nl80211);
2456 nl_cache_free(drv->nl_cache);
2457 nl_handle_destroy(drv->nl_handle);
2458 nl_cb_put(drv->nl_cb);
2460 if (drv->if_indices != drv->default_if_indices)
2461 free(drv->if_indices);
2467 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
2470 .init_bssid = i802_init_bssid,
2471 .deinit = i802_deinit,
2472 .wireless_event_init = i802_wireless_event_init,
2473 .wireless_event_deinit = i802_wireless_event_deinit,
2474 .set_ieee8021x = i802_set_ieee8021x,
2475 .set_privacy = i802_set_privacy,
2476 .set_encryption = i802_set_encryption,
2477 .get_seqnum = i802_get_seqnum,
2478 .flush = i802_flush,
2479 .read_sta_data = i802_read_sta_data,
2480 .send_eapol = i802_send_eapol,
2481 .sta_set_flags = i802_sta_set_flags,
2482 .sta_deauth = i802_sta_deauth,
2483 .sta_disassoc = i802_sta_disassoc,
2484 .sta_remove = i802_sta_remove,
2485 .send_mgmt_frame = i802_send_mgmt_frame,
2486 .sta_add2 = i802_sta_add2,
2487 .get_inact_sec = i802_get_inact_sec,
2488 .sta_clear_stats = i802_sta_clear_stats,
2489 .set_freq2 = i802_set_freq2,
2490 .set_rts = i802_set_rts,
2491 .get_rts = i802_get_rts,
2492 .set_frag = i802_set_frag,
2493 .get_frag = i802_get_frag,
2494 .set_retry = i802_set_retry,
2495 .get_retry = i802_get_retry,
2496 .set_rate_sets = i802_set_rate_sets,
2497 .set_regulatory_domain = i802_set_regulatory_domain,
2498 .set_beacon = i802_set_beacon,
2499 .set_internal_bridge = i802_set_internal_bridge,
2500 .set_beacon_int = i802_set_beacon_int,
2501 .set_dtim_period = i802_set_dtim_period,
2502 .set_cts_protect = i802_set_cts_protect,
2503 .set_preamble = i802_set_preamble,
2504 .set_short_slot_time = i802_set_short_slot_time,
2505 .set_tx_queue_params = i802_set_tx_queue_params,
2506 .bss_add = i802_bss_add,
2507 .bss_remove = i802_bss_remove,
2508 .if_add = i802_if_add,
2509 .if_update = i802_if_update,
2510 .if_remove = i802_if_remove,
2511 .get_hw_feature_data = i802_get_hw_feature_data,
2512 .set_sta_vlan = i802_set_sta_vlan,
2513 .set_country = i802_set_country,