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 <linux/nl80211.h>
28 #include <linux/if_packet.h>
29 #include <linux/if_ether.h> /* The L2 protocols */
30 #include "wireless_copy.h"
31 #include <net/if_arp.h>
35 #include "ieee802_1x.h"
37 #include "ieee802_11.h"
39 #include "hw_features.h"
42 #include "radiotap_iter.h"
44 enum ieee80211_msg_type {
45 ieee80211_msg_normal = 0,
46 ieee80211_msg_tx_callback_ack = 1,
47 ieee80211_msg_tx_callback_fail = 2,
50 struct i802_driver_data {
51 struct hostapd_data *hapd;
53 char iface[IFNAMSIZ + 1];
55 int ioctl_sock; /* socket for ioctl() use */
56 int wext_sock; /* socket for wireless events */
57 int eapol_sock; /* socket for EAPOL frames */
58 int monitor_sock; /* socket for monitor */
61 int default_if_indices[16];
66 struct nl_handle *nl_handle;
67 struct nl_cache *nl_cache;
69 struct genl_family *nl80211;
70 int dtim_period, beacon_int;
71 unsigned int beacon_set:1;
72 unsigned int ieee802_1x_active:1;
79 static void add_ifidx(struct i802_driver_data *drv, int ifidx)
84 for (i = 0; i < drv->num_if_indices; i++) {
85 if (drv->if_indices[i] == 0) {
86 drv->if_indices[i] = ifidx;
91 if (drv->if_indices != drv->default_if_indices)
92 old = drv->if_indices;
96 drv->if_indices = realloc(old,
97 sizeof(int) * (drv->num_if_indices + 1));
98 if (!drv->if_indices) {
100 drv->if_indices = drv->default_if_indices;
102 drv->if_indices = old;
103 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
105 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
108 drv->if_indices[drv->num_if_indices] = ifidx;
109 drv->num_if_indices++;
113 static void del_ifidx(struct i802_driver_data *drv, int ifidx)
117 for (i = 0; i < drv->num_if_indices; i++) {
118 if (drv->if_indices[i] == ifidx) {
119 drv->if_indices[i] = 0;
126 static int have_ifidx(struct i802_driver_data *drv, int ifidx)
130 if (ifidx == drv->bridge)
133 for (i = 0; i < drv->num_if_indices; i++)
134 if (drv->if_indices[i] == ifidx)
142 static int ack_handler(struct nl_msg *msg, void *arg)
149 static int finish_handler(struct nl_msg *msg, void *arg)
156 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
164 static int send_and_recv_msgs(struct i802_driver_data *drv,
166 int (*valid_handler)(struct nl_msg *, void *),
172 cb = nl_cb_clone(drv->nl_cb);
176 err = nl_send_auto_complete(drv->nl_handle, msg);
182 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
183 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
184 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
187 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
188 valid_handler, valid_data);
191 nl_recvmsgs(drv->nl_handle, cb);
198 static int hostapd_set_iface_flags(struct i802_driver_data *drv,
199 const char *ifname, int dev_up)
203 if (drv->ioctl_sock < 0)
206 memset(&ifr, 0, sizeof(ifr));
207 os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
209 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
210 perror("ioctl[SIOCGIFFLAGS]");
211 wpa_printf(MSG_DEBUG, "Could not read interface flags (%s)",
217 ifr.ifr_flags |= IFF_UP;
219 ifr.ifr_flags &= ~IFF_UP;
221 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
222 perror("ioctl[SIOCSIFFLAGS]");
230 static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
231 const char *alg, const u8 *addr, int idx, const u8 *key,
232 size_t key_len, int txkey)
241 if (strcmp(alg, "none") == 0) {
242 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
243 0, NL80211_CMD_DEL_KEY, 0);
245 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
246 0, NL80211_CMD_NEW_KEY, 0);
247 NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
248 if (strcmp(alg, "WEP") == 0) {
250 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
253 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
255 } else if (strcmp(alg, "TKIP") == 0)
256 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
257 else if (strcmp(alg, "CCMP") == 0)
258 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
259 else if (strcmp(alg, "IGTK") == 0)
260 NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC06);
262 wpa_printf(MSG_ERROR, "%s: Unsupported encryption "
263 "algorithm '%s'", __func__, alg);
270 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
271 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
272 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
274 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
279 * If we failed or don't need to set the default TX key (below),
282 if (ret || !txkey || addr)
289 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
290 0, NL80211_CMD_SET_KEY, 0);
291 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
292 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
293 #ifdef NL80211_MFP_PENDING
294 if (strcmp(alg, "IGTK") == 0)
295 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
297 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
298 #else /* NL80211_MFP_PENDING */
299 NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
300 #endif /* NL80211_MFP_PENDING */
302 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
311 static int i802_set_encryption(const char *iface, void *priv, const char *alg,
312 const u8 *addr, int idx, const u8 *key,
313 size_t key_len, int txkey)
315 struct i802_driver_data *drv = priv;
318 ret = nl_set_encr(if_nametoindex(iface), drv, alg, addr, idx, key,
323 if (strcmp(alg, "IGTK") == 0) {
324 ret = nl_set_encr(drv->monitor_ifidx, drv, alg, addr, idx, key,
332 static inline int min_int(int a, int b)
340 static int get_key_handler(struct nl_msg *msg, void *arg)
342 struct nlattr *tb[NL80211_ATTR_MAX + 1];
343 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
345 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
346 genlmsg_attrlen(gnlh, 0), NULL);
349 * TODO: validate the key index and mac address!
350 * Otherwise, there's a race condition as soon as
351 * the kernel starts sending key notifications.
354 if (tb[NL80211_ATTR_KEY_SEQ])
355 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
356 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
361 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
364 struct i802_driver_data *drv = priv;
371 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
372 0, NL80211_CMD_GET_KEY, 0);
375 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
376 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
377 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
381 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
387 static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
390 #ifdef NL80211_ATTR_BSS_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);
415 #else /* NL80211_ATTR_BSS_BASIC_RATES */
417 #endif /* NL80211_ATTR_BSS_BASIC_RATES */
421 static int i802_send_frame(void *priv, const void *data, size_t len,
422 int encrypt, int flags)
425 0x00, 0x00, /* radiotap version */
426 0x0e, 0x00, /* radiotap length */
427 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
428 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
430 0x00, 0x00, /* RX and TX flags to indicate that */
431 0x00, 0x00, /* this is the injected frame directly */
433 struct i802_driver_data *drv = priv;
434 struct iovec iov[2] = {
436 .iov_base = &rtap_hdr,
437 .iov_len = sizeof(rtap_hdr),
440 .iov_base = (void*)data,
444 struct msghdr msg = {
455 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
457 return sendmsg(drv->monitor_sock, &msg, flags);
460 static int i802_send_mgmt_frame(void *priv, const void *data, size_t len,
463 return i802_send_frame(priv, data, len, 1, flags);
466 /* Set kernel driver on given frequency (MHz) */
467 static int i802_set_freq2(void *priv, struct hostapd_freq_params *freq)
469 #ifdef NL80211_ATTR_WIPHY_FREQ
470 struct i802_driver_data *drv = priv;
477 drv->last_freq = freq->freq;
478 drv->last_freq_ht = freq->ht_enabled;
480 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
481 NL80211_CMD_SET_WIPHY, 0);
483 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
484 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
485 if (freq->ht_enabled) {
486 switch (freq->sec_channel_offset) {
488 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
489 NL80211_SEC_CHAN_BELOW);
492 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
493 NL80211_SEC_CHAN_ABOVE);
496 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
497 NL80211_SEC_CHAN_DISABLED);
502 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
506 #else /* NL80211_ATTR_WIPHY_FREQ */
507 struct i802_driver_data *drv = priv;
510 memset(&iwr, 0, sizeof(iwr));
511 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
512 iwr.u.freq.m = freq->freq;
515 if (ioctl(drv->ioctl_sock, SIOCSIWFREQ, &iwr) < 0) {
516 perror("ioctl[SIOCSIWFREQ]");
521 #endif /* NL80211_ATTR_WIPHY_FREQ */
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->hapd->conf->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->hapd->conf->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->hapd->conf->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->hapd->conf->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->hapd->conf->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->hapd->conf->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 #ifdef NL80211_ATTR_HT_CAPABILITY
835 if (params->ht_capabilities) {
836 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
837 params->ht_capabilities->length,
838 ¶ms->ht_capabilities->data);
840 #endif /* NL80211_ATTR_HT_CAPABILITY */
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 #ifdef NL80211_MFP_PENDING
910 if (total_flags & WLAN_STA_MFP)
911 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
912 #endif /* NL80211_MFP_PENDING */
914 if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
915 goto nla_put_failure;
919 return send_and_recv_msgs(drv, msg, NULL, NULL);
926 static int i802_set_regulatory_domain(void *priv, unsigned int rd)
932 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
933 int cw_min, int cw_max, int burst_time)
935 #ifdef NL80211_ATTR_WIPHY_TXQ_PARAMS
936 struct i802_driver_data *drv = priv;
938 struct nlattr *txq, *params;
944 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
945 0, NL80211_CMD_SET_WIPHY, 0);
947 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
949 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
951 goto nla_put_failure;
953 /* We are only sending parameters for a single TXQ at a time */
954 params = nla_nest_start(msg, 1);
956 goto nla_put_failure;
958 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue);
959 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
960 * 32 usec, so need to convert the value here. */
961 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32);
962 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min);
963 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max);
964 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs);
966 nla_nest_end(msg, params);
968 nla_nest_end(msg, txq);
970 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
974 #else /* NL80211_ATTR_WIPHY_TXQ_PARAMS */
976 #endif /* NL80211_ATTR_WIPHY_TXQ_PARAMS */
980 static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
984 /* stop listening for EAPOL on this interface */
985 del_ifidx(drv, ifidx);
989 goto nla_put_failure;
991 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
992 0, NL80211_CMD_DEL_INTERFACE, 0);
993 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
995 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
998 printf("Failed to remove interface.\n");
1002 static int nl80211_create_iface(struct i802_driver_data *drv,
1004 enum nl80211_iftype iftype,
1007 struct nl_msg *msg, *flags = NULL;
1013 msg = nlmsg_alloc();
1017 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1018 0, NL80211_CMD_NEW_INTERFACE, 0);
1019 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1020 if_nametoindex(drv->hapd->conf->iface));
1021 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
1022 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
1024 if (iftype == NL80211_IFTYPE_MONITOR) {
1027 flags = nlmsg_alloc();
1029 goto nla_put_failure;
1031 NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
1033 err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
1038 goto nla_put_failure;
1041 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1044 printf("Failed to create interface %s.\n", ifname);
1048 ifidx = if_nametoindex(ifname);
1053 /* start listening for EAPOL on this interface */
1054 add_ifidx(drv, ifidx);
1058 case NL80211_IFTYPE_AP:
1059 os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
1060 memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
1061 ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1063 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
1064 nl80211_remove_iface(drv, ifidx);
1068 case NL80211_IFTYPE_WDS:
1069 memset(&iwr, 0, sizeof(iwr));
1070 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1071 iwr.u.addr.sa_family = ARPHRD_ETHER;
1072 memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
1073 if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
1086 static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
1091 * The kernel supports that when the low-level driver does,
1092 * but we currently don't because we need per-BSS data that
1093 * currently we can't handle easily.
1097 ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
1100 if (hostapd_set_iface_flags(priv, ifname, 1)) {
1101 nl80211_remove_iface(priv, ifidx);
1108 static int i802_bss_remove(void *priv, const char *ifname)
1110 nl80211_remove_iface(priv, if_nametoindex(ifname));
1115 static int i802_set_beacon(const char *iface, void *priv,
1116 u8 *head, size_t head_len,
1117 u8 *tail, size_t tail_len)
1119 struct i802_driver_data *drv = priv;
1121 u8 cmd = NL80211_CMD_NEW_BEACON;
1124 msg = nlmsg_alloc();
1128 if (drv->beacon_set)
1129 cmd = NL80211_CMD_SET_BEACON;
1131 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1133 NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
1134 NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
1135 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1136 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
1138 if (!drv->dtim_period)
1139 drv->dtim_period = 2;
1140 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1142 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1144 drv->beacon_set = 1;
1151 static int i802_del_beacon(struct i802_driver_data *drv)
1155 msg = nlmsg_alloc();
1159 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1160 0, NL80211_CMD_DEL_BEACON, 0);
1161 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1163 return send_and_recv_msgs(drv, msg, NULL, NULL);
1169 static int i802_set_ieee8021x(const char *ifname, void *priv, int enabled)
1171 struct i802_driver_data *drv = priv;
1174 * FIXME: This needs to be per interface (BSS)
1176 drv->ieee802_1x_active = enabled;
1181 static int i802_set_privacy(const char *ifname, void *priv, int enabled)
1183 struct i802_driver_data *drv = priv;
1186 memset(&iwr, 0, sizeof(iwr));
1188 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1189 iwr.u.param.flags = IW_AUTH_PRIVACY_INVOKED;
1190 iwr.u.param.value = enabled;
1192 ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr);
1194 /* ignore errors, the kernel/driver might not care */
1199 static int i802_set_internal_bridge(void *priv, int value)
1205 static int i802_set_beacon_int(void *priv, int value)
1207 struct i802_driver_data *drv = priv;
1210 drv->beacon_int = value;
1212 if (!drv->beacon_set)
1215 msg = nlmsg_alloc();
1219 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1220 0, NL80211_CMD_SET_BEACON, 0);
1221 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1223 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
1225 return send_and_recv_msgs(drv, msg, NULL, NULL);
1231 static int i802_set_dtim_period(const char *iface, void *priv, int value)
1233 struct i802_driver_data *drv = priv;
1236 msg = nlmsg_alloc();
1240 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1241 0, NL80211_CMD_SET_BEACON, 0);
1242 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1244 drv->dtim_period = value;
1245 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1247 return send_and_recv_msgs(drv, msg, NULL, NULL);
1253 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
1255 #ifdef NL80211_CMD_SET_BSS
1256 struct i802_driver_data *drv = priv;
1259 msg = nlmsg_alloc();
1263 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
1264 NL80211_CMD_SET_BSS, 0);
1267 NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
1269 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
1271 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
1273 /* TODO: multi-BSS support */
1274 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1276 return send_and_recv_msgs(drv, msg, NULL, NULL);
1279 #else /* NL80211_CMD_SET_BSS */
1281 #endif /* NL80211_CMD_SET_BSS */
1285 static int i802_set_cts_protect(void *priv, int value)
1287 return i802_set_bss(priv, value, -1, -1);
1291 static int i802_set_preamble(void *priv, int value)
1293 return i802_set_bss(priv, -1, value, -1);
1297 static int i802_set_short_slot_time(void *priv, int value)
1299 return i802_set_bss(priv, -1, -1, value);
1303 static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
1306 case HOSTAPD_IF_VLAN:
1307 return NL80211_IFTYPE_AP_VLAN;
1308 case HOSTAPD_IF_WDS:
1309 return NL80211_IFTYPE_WDS;
1315 static int i802_if_add(const char *iface, void *priv,
1316 enum hostapd_driver_if_type type, char *ifname,
1319 if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
1325 static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
1326 char *ifname, const u8 *addr)
1328 /* unused at the moment */
1333 static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
1334 const char *ifname, const u8 *addr)
1336 nl80211_remove_iface(priv, if_nametoindex(ifname));
1341 struct phy_info_arg {
1343 struct hostapd_hw_modes *modes;
1346 static int phy_info_handler(struct nl_msg *msg, void *arg)
1348 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1349 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1350 struct phy_info_arg *phy_info = arg;
1352 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1354 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1355 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1356 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1357 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1358 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
1359 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
1360 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1361 #ifdef NL80211_FREQUENCY_ATTR_MAX_TX_POWER
1362 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1363 #endif /* NL80211_FREQUENCY_ATTR_MAX_TX_POWER */
1366 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1367 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1368 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1369 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
1372 struct nlattr *nl_band;
1373 struct nlattr *nl_freq;
1374 struct nlattr *nl_rate;
1375 int rem_band, rem_freq, rem_rate;
1376 struct hostapd_hw_modes *mode;
1377 int idx, mode_is_set;
1379 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1380 genlmsg_attrlen(gnlh, 0), NULL);
1382 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1385 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
1386 mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
1389 phy_info->modes = mode;
1393 mode = &phy_info->modes[*(phy_info->num_modes)];
1394 memset(mode, 0, sizeof(*mode));
1395 *(phy_info->num_modes) += 1;
1397 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1398 nla_len(nl_band), NULL);
1400 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1401 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1402 nla_len(nl_freq), freq_policy);
1403 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1405 mode->num_channels++;
1408 mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
1409 if (!mode->channels)
1414 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1415 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1416 nla_len(nl_freq), freq_policy);
1417 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1420 mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1421 mode->channels[idx].flag = 0;
1424 /* crude heuristic */
1425 if (mode->channels[idx].freq < 4000)
1426 mode->mode = HOSTAPD_MODE_IEEE80211B;
1428 mode->mode = HOSTAPD_MODE_IEEE80211A;
1432 /* crude heuristic */
1433 if (mode->channels[idx].freq < 4000)
1434 if (mode->channels[idx].freq == 2848)
1435 mode->channels[idx].chan = 14;
1437 mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
1439 mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
1441 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1442 mode->channels[idx].flag |=
1443 HOSTAPD_CHAN_DISABLED;
1444 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
1445 mode->channels[idx].flag |=
1446 HOSTAPD_CHAN_PASSIVE_SCAN;
1447 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
1448 mode->channels[idx].flag |=
1449 HOSTAPD_CHAN_NO_IBSS;
1450 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1451 mode->channels[idx].flag |=
1454 #ifdef NL80211_FREQUENCY_ATTR_MAX_TX_POWER
1455 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
1456 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1457 mode->channels[idx].max_tx_power =
1458 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100;
1459 #endif /* NL80211_FREQUENCY_ATTR_MAX_TX_POWER */
1464 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1465 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1466 nla_len(nl_rate), rate_policy);
1467 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1472 mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
1478 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1479 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1480 nla_len(nl_rate), rate_policy);
1481 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1483 mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
1485 /* crude heuristic */
1486 if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
1487 mode->rates[idx].rate > 200)
1488 mode->mode = HOSTAPD_MODE_IEEE80211G;
1490 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
1491 mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
1500 static struct hostapd_hw_modes *i802_add_11b(struct hostapd_hw_modes *modes,
1504 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1505 int i, mode11g_idx = -1;
1507 /* If only 802.11g mode is included, use it to construct matching
1508 * 802.11b mode data. */
1510 for (m = 0; m < *num_modes; m++) {
1511 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1512 return modes; /* 802.11b already included */
1513 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1517 if (mode11g_idx < 0)
1518 return modes; /* 2.4 GHz band not supported at all */
1520 nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes));
1522 return modes; /* Could not add 802.11b mode */
1524 mode = &nmodes[*num_modes];
1525 os_memset(mode, 0, sizeof(*mode));
1529 mode->mode = HOSTAPD_MODE_IEEE80211B;
1531 mode11g = &modes[mode11g_idx];
1532 mode->num_channels = mode11g->num_channels;
1533 mode->channels = os_malloc(mode11g->num_channels *
1534 sizeof(struct hostapd_channel_data));
1535 if (mode->channels == NULL) {
1537 return modes; /* Could not add 802.11b mode */
1539 os_memcpy(mode->channels, mode11g->channels,
1540 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1542 mode->num_rates = 0;
1543 mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
1544 if (mode->rates == NULL) {
1545 os_free(mode->channels);
1547 return modes; /* Could not add 802.11b mode */
1550 for (i = 0; i < mode11g->num_rates; i++) {
1551 if (mode11g->rates[i].rate > 110 ||
1552 mode11g->rates[i].flags &
1553 (HOSTAPD_RATE_ERP | HOSTAPD_RATE_OFDM))
1555 mode->rates[mode->num_rates] = mode11g->rates[i];
1557 if (mode->num_rates == 4)
1561 if (mode->num_rates == 0) {
1562 os_free(mode->channels);
1563 os_free(mode->rates);
1565 return modes; /* No 802.11b rates */
1568 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1574 static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
1578 struct i802_driver_data *drv = priv;
1580 struct phy_info_arg result = {
1581 .num_modes = num_modes,
1588 msg = nlmsg_alloc();
1592 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1593 0, NL80211_CMD_GET_WIPHY, 0);
1595 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1597 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
1598 return i802_add_11b(result.modes, num_modes);
1604 static int i802_set_sta_vlan(void *priv, const u8 *addr,
1605 const char *ifname, int vlan_id)
1607 struct i802_driver_data *drv = priv;
1610 msg = nlmsg_alloc();
1614 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1615 0, NL80211_CMD_SET_STATION, 0);
1617 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1618 if_nametoindex(drv->iface));
1619 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
1620 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1621 if_nametoindex(ifname));
1623 return send_and_recv_msgs(drv, msg, NULL, NULL);
1629 static int i802_set_country(void *priv, const char *country)
1631 struct i802_driver_data *drv = priv;
1635 msg = nlmsg_alloc();
1639 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1640 0, NL80211_CMD_REQ_SET_REG, 0);
1642 alpha2[0] = country[0];
1643 alpha2[1] = country[1];
1645 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
1647 return send_and_recv_msgs(drv, msg, NULL, NULL);
1653 static void handle_unknown_sta(struct hostapd_data *hapd, u8 *ta)
1655 struct sta_info *sta;
1657 sta = ap_get_sta(hapd, ta);
1658 if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
1659 printf("Data/PS-poll frame from not associated STA "
1660 MACSTR "\n", MAC2STR(ta));
1661 if (sta && (sta->flags & WLAN_STA_AUTH))
1662 hostapd_sta_disassoc(
1664 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1668 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1673 static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
1676 struct ieee80211_hdr *hdr;
1677 u16 fc, type, stype;
1678 struct sta_info *sta;
1680 hdr = (struct ieee80211_hdr *) buf;
1681 fc = le_to_host16(hdr->frame_control);
1683 type = WLAN_FC_GET_TYPE(fc);
1684 stype = WLAN_FC_GET_STYPE(fc);
1687 case WLAN_FC_TYPE_MGMT:
1688 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
1689 ok ? "ACK" : "fail");
1690 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1692 case WLAN_FC_TYPE_CTRL:
1693 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
1694 ok ? "ACK" : "fail");
1696 case WLAN_FC_TYPE_DATA:
1697 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
1698 ok ? "ACK" : "fail");
1699 sta = ap_get_sta(hapd, hdr->addr1);
1700 if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
1701 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
1702 "activity poll", MAC2STR(sta->addr),
1703 ok ? "ACKed" : "did not ACK");
1705 sta->flags &= ~WLAN_STA_PENDING_POLL;
1708 ieee802_1x_tx_status(hapd, sta, buf, len, ok);
1711 printf("unknown TX callback frame type %d\n", type);
1717 static void handle_frame(struct hostapd_iface *iface, u8 *buf, size_t len,
1718 struct hostapd_frame_info *hfi,
1719 enum ieee80211_msg_type msg_type)
1721 struct ieee80211_hdr *hdr;
1722 u16 fc, type, stype;
1723 size_t data_len = len;
1724 struct hostapd_data *hapd = NULL;
1725 int broadcast_bssid = 0;
1730 * PS-Poll frames are 16 bytes. All other frames are
1731 * 24 bytes or longer.
1736 hdr = (struct ieee80211_hdr *) buf;
1737 fc = le_to_host16(hdr->frame_control);
1739 type = WLAN_FC_GET_TYPE(fc);
1740 stype = WLAN_FC_GET_STYPE(fc);
1743 case WLAN_FC_TYPE_DATA:
1746 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
1755 case WLAN_FC_TYPE_CTRL:
1756 /* discard non-ps-poll frames */
1757 if (stype != WLAN_FC_STYPE_PSPOLL)
1761 case WLAN_FC_TYPE_MGMT:
1769 /* find interface frame belongs to */
1770 for (i = 0; i < iface->num_bss; i++) {
1771 if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
1772 hapd = iface->bss[i];
1778 hapd = iface->bss[0];
1780 if (bssid[0] != 0xff || bssid[1] != 0xff ||
1781 bssid[2] != 0xff || bssid[3] != 0xff ||
1782 bssid[4] != 0xff || bssid[5] != 0xff) {
1784 * Unknown BSSID - drop frame if this is not from
1785 * passive scanning or a beacon (at least ProbeReq
1786 * frames to other APs may be allowed through RX
1787 * filtering in the wlan hw/driver)
1789 if ((type != WLAN_FC_TYPE_MGMT ||
1790 stype != WLAN_FC_STYPE_BEACON))
1793 broadcast_bssid = 1;
1797 case ieee80211_msg_normal:
1798 /* continue processing */
1800 case ieee80211_msg_tx_callback_ack:
1801 handle_tx_callback(hapd, buf, data_len, 1);
1803 case ieee80211_msg_tx_callback_fail:
1804 handle_tx_callback(hapd, buf, data_len, 0);
1809 case WLAN_FC_TYPE_MGMT:
1810 if (stype != WLAN_FC_STYPE_BEACON &&
1811 stype != WLAN_FC_STYPE_PROBE_REQ)
1812 wpa_printf(MSG_MSGDUMP, "MGMT");
1813 if (broadcast_bssid) {
1814 for (i = 0; i < iface->num_bss; i++)
1815 ieee802_11_mgmt(iface->bss[i], buf, data_len,
1818 ieee802_11_mgmt(hapd, buf, data_len, stype, hfi);
1820 case WLAN_FC_TYPE_CTRL:
1821 /* can only get here with PS-Poll frames */
1822 wpa_printf(MSG_DEBUG, "CTRL");
1823 handle_unknown_sta(hapd, hdr->addr2);
1825 case WLAN_FC_TYPE_DATA:
1826 wpa_printf(MSG_DEBUG, "DATA");
1827 handle_unknown_sta(hapd, hdr->addr2);
1833 static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
1835 struct i802_driver_data *drv = eloop_ctx;
1836 struct hostapd_data *hapd = drv->hapd;
1837 struct sockaddr_ll lladdr;
1838 unsigned char buf[3000];
1840 socklen_t fromlen = sizeof(lladdr);
1842 len = recvfrom(sock, buf, sizeof(buf), 0,
1843 (struct sockaddr *)&lladdr, &fromlen);
1849 if (have_ifidx(drv, lladdr.sll_ifindex))
1850 ieee802_1x_receive(hapd, lladdr.sll_addr, buf, len);
1854 static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
1856 struct i802_driver_data *drv = eloop_ctx;
1858 unsigned char buf[3000];
1859 struct hostapd_data *hapd = drv->hapd;
1860 struct ieee80211_radiotap_iterator iter;
1862 struct hostapd_frame_info hfi;
1863 int injected = 0, failed = 0, msg_type, rxflags = 0;
1865 len = recv(sock, buf, sizeof(buf), 0);
1871 if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
1872 printf("received invalid radiotap frame\n");
1876 memset(&hfi, 0, sizeof(hfi));
1879 ret = ieee80211_radiotap_iterator_next(&iter);
1883 printf("received invalid radiotap frame (%d)\n", ret);
1886 switch (iter.this_arg_index) {
1887 case IEEE80211_RADIOTAP_FLAGS:
1888 if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
1891 case IEEE80211_RADIOTAP_RX_FLAGS:
1894 case IEEE80211_RADIOTAP_TX_FLAGS:
1896 failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
1897 IEEE80211_RADIOTAP_F_TX_FAIL;
1899 case IEEE80211_RADIOTAP_DATA_RETRIES:
1901 case IEEE80211_RADIOTAP_CHANNEL:
1902 /* TODO convert from freq/flags to channel number
1907 case IEEE80211_RADIOTAP_RATE:
1908 hfi.datarate = *iter.this_arg * 5;
1910 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1911 hfi.ssi_signal = *iter.this_arg;
1916 if (rxflags && injected)
1920 msg_type = ieee80211_msg_normal;
1922 msg_type = ieee80211_msg_tx_callback_fail;
1924 msg_type = ieee80211_msg_tx_callback_ack;
1926 handle_frame(hapd->iface, buf + iter.max_length,
1927 len - iter.max_length, &hfi, msg_type);
1931 static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
1934 struct sockaddr_ll ll;
1938 snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
1939 buf[IFNAMSIZ - 1] = '\0';
1941 drv->monitor_ifidx =
1942 nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
1944 if (drv->monitor_ifidx < 0)
1947 if (hostapd_set_iface_flags(drv, buf, 1))
1950 memset(&ll, 0, sizeof(ll));
1951 ll.sll_family = AF_PACKET;
1952 ll.sll_ifindex = drv->monitor_ifidx;
1953 drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1954 if (drv->monitor_sock < 0) {
1955 perror("socket[PF_PACKET,SOCK_RAW]");
1959 if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
1961 perror("monitor socket bind");
1965 optlen = sizeof(optval);
1968 (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
1969 perror("Failed to set socket priority");
1973 if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
1975 printf("Could not register monitor read socket\n");
1981 nl80211_remove_iface(drv, drv->monitor_ifidx);
1986 static int nl80211_set_master_mode(struct i802_driver_data *drv,
1992 msg = nlmsg_alloc();
1996 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1997 0, NL80211_CMD_SET_INTERFACE, 0);
1998 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1999 if_nametoindex(ifname));
2000 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
2002 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2006 wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
2012 static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
2015 struct sockaddr_ll addr;
2017 drv->ioctl_sock = -1;
2019 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
2020 if (drv->ioctl_sock < 0) {
2021 perror("socket[PF_INET,SOCK_DGRAM]");
2025 /* start listening for EAPOL on the default AP interface */
2026 add_ifidx(drv, if_nametoindex(drv->iface));
2028 if (hostapd_set_iface_flags(drv, drv->iface, 0))
2032 os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
2033 memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
2034 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
2036 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
2037 perror("ioctl(SIOCSIFHWADDR)");
2043 * initialise generic netlink and nl80211
2045 drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
2047 printf("Failed to allocate netlink callbacks.\n");
2051 drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
2052 if (!drv->nl_handle) {
2053 printf("Failed to allocate netlink handle.\n");
2057 if (genl_connect(drv->nl_handle)) {
2058 printf("Failed to connect to generic netlink.\n");
2062 drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
2063 if (!drv->nl_cache) {
2064 printf("Failed to allocate generic netlink cache.\n");
2068 drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
2069 if (!drv->nl80211) {
2070 printf("nl80211 not found.\n");
2074 /* Initialise a monitor interface */
2075 if (nl80211_create_monitor_interface(drv))
2078 if (nl80211_set_master_mode(drv, drv->iface))
2081 if (hostapd_set_iface_flags(drv, drv->iface, 1))
2084 memset(&addr, 0, sizeof(addr));
2085 addr.sll_family = AF_PACKET;
2086 addr.sll_ifindex = ifr.ifr_ifindex;
2087 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
2090 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
2091 if (drv->eapol_sock < 0) {
2092 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
2096 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
2098 printf("Could not register read socket for eapol\n");
2102 memset(&ifr, 0, sizeof(ifr));
2103 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
2104 if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
2105 perror("ioctl(SIOCGIFHWADDR)");
2109 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
2110 printf("Invalid HW-addr family 0x%04x\n",
2111 ifr.ifr_hwaddr.sa_family);
2114 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
2119 nl80211_remove_iface(drv, drv->monitor_ifidx);
2124 static int i802_get_inact_sec(void *priv, const u8 *addr)
2126 struct hostap_sta_driver_data data;
2129 data.inactive_msec = (unsigned long) -1;
2130 ret = i802_read_sta_data(priv, &data, addr);
2131 if (ret || data.inactive_msec == (unsigned long) -1)
2133 return data.inactive_msec / 1000;
2137 static int i802_sta_clear_stats(void *priv, const u8 *addr)
2147 hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
2150 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
2152 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
2155 pos = strstr(custom, "addr=");
2157 wpa_printf(MSG_DEBUG,
2158 "MLME-MICHAELMICFAILURE.indication "
2159 "without sender address ignored");
2163 if (hwaddr_aton(pos, addr) == 0) {
2164 ieee80211_michael_mic_failure(drv->hapd, addr, 1);
2166 wpa_printf(MSG_DEBUG,
2167 "MLME-MICHAELMICFAILURE.indication "
2168 "with invalid MAC address");
2174 static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
2175 char *data, int len)
2177 struct iw_event iwe_buf, *iwe = &iwe_buf;
2178 char *pos, *end, *custom, *buf;
2183 while (pos + IW_EV_LCP_LEN <= end) {
2184 /* Event data may be unaligned, so make a local, aligned copy
2185 * before processing. */
2186 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
2187 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
2188 iwe->cmd, iwe->len);
2189 if (iwe->len <= IW_EV_LCP_LEN)
2192 custom = pos + IW_EV_POINT_LEN;
2193 if (drv->we_version > 18 &&
2194 (iwe->cmd == IWEVMICHAELMICFAILURE ||
2195 iwe->cmd == IWEVCUSTOM)) {
2196 /* WE-19 removed the pointer from struct iw_point */
2197 char *dpos = (char *) &iwe_buf.u.data.length;
2198 int dlen = dpos - (char *) &iwe_buf;
2199 memcpy(dpos, pos + IW_EV_LCP_LEN,
2200 sizeof(struct iw_event) - dlen);
2202 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
2203 custom += IW_EV_POINT_OFF;
2208 if (custom + iwe->u.data.length > end)
2210 buf = malloc(iwe->u.data.length + 1);
2213 memcpy(buf, custom, iwe->u.data.length);
2214 buf[iwe->u.data.length] = '\0';
2215 hostapd_wireless_event_wireless_custom(drv, buf);
2225 static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
2226 struct nlmsghdr *h, int len)
2228 struct ifinfomsg *ifi;
2229 int attrlen, nlmsg_len, rta_len;
2230 struct rtattr *attr;
2232 if (len < (int) sizeof(*ifi))
2235 ifi = NLMSG_DATA(h);
2237 /* TODO: use ifi->ifi_index to filter out wireless events from other
2240 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
2242 attrlen = h->nlmsg_len - nlmsg_len;
2246 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
2248 rta_len = RTA_ALIGN(sizeof(struct rtattr));
2249 while (RTA_OK(attr, attrlen)) {
2250 if (attr->rta_type == IFLA_WIRELESS) {
2251 hostapd_wireless_event_wireless(
2252 drv, ((char *) attr) + rta_len,
2253 attr->rta_len - rta_len);
2255 attr = RTA_NEXT(attr, attrlen);
2260 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
2265 struct sockaddr_nl from;
2268 struct i802_driver_data *drv = eloop_ctx;
2270 fromlen = sizeof(from);
2271 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
2272 (struct sockaddr *) &from, &fromlen);
2274 if (errno != EINTR && errno != EAGAIN)
2275 perror("recvfrom(netlink)");
2279 h = (struct nlmsghdr *) buf;
2280 while (left >= (int) sizeof(*h)) {
2284 plen = len - sizeof(*h);
2285 if (len > left || plen < 0) {
2286 printf("Malformed netlink message: "
2287 "len=%d left=%d plen=%d\n",
2292 switch (h->nlmsg_type) {
2294 hostapd_wireless_event_rtm_newlink(drv, h, plen);
2298 len = NLMSG_ALIGN(len);
2300 h = (struct nlmsghdr *) ((char *) h + len);
2304 printf("%d extra bytes in the end of netlink message\n", left);
2309 static int hostap_get_we_version(struct i802_driver_data *drv)
2311 struct iw_range *range;
2316 drv->we_version = 0;
2319 * Use larger buffer than struct iw_range in order to allow the
2320 * structure to grow in the future.
2322 buflen = sizeof(struct iw_range) + 500;
2323 range = os_zalloc(buflen);
2327 memset(&iwr, 0, sizeof(iwr));
2328 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
2329 iwr.u.data.pointer = (caddr_t) range;
2330 iwr.u.data.length = buflen;
2332 minlen = ((char *) &range->enc_capa) - (char *) range +
2333 sizeof(range->enc_capa);
2335 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
2336 perror("ioctl[SIOCGIWRANGE]");
2339 } else if (iwr.u.data.length >= minlen &&
2340 range->we_version_compiled >= 18) {
2341 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
2342 "WE(source)=%d enc_capa=0x%x",
2343 range->we_version_compiled,
2344 range->we_version_source,
2346 drv->we_version = range->we_version_compiled;
2354 static int i802_wireless_event_init(void *priv)
2356 struct i802_driver_data *drv = priv;
2358 struct sockaddr_nl local;
2360 hostap_get_we_version(drv);
2362 drv->wext_sock = -1;
2364 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
2366 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
2370 memset(&local, 0, sizeof(local));
2371 local.nl_family = AF_NETLINK;
2372 local.nl_groups = RTMGRP_LINK;
2373 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
2374 perror("bind(netlink)");
2379 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
2387 static void i802_wireless_event_deinit(void *priv)
2389 struct i802_driver_data *drv = priv;
2390 if (drv->wext_sock < 0)
2392 eloop_unregister_read_sock(drv->wext_sock);
2393 close(drv->wext_sock);
2397 static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
2399 struct i802_driver_data *drv = priv;
2400 struct ieee80211_mgmt mgmt;
2402 memset(&mgmt, 0, sizeof(mgmt));
2403 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2404 WLAN_FC_STYPE_DEAUTH);
2405 memcpy(mgmt.da, addr, ETH_ALEN);
2406 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2407 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2408 mgmt.u.deauth.reason_code = host_to_le16(reason);
2409 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2410 sizeof(mgmt.u.deauth), 0);
2414 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
2416 struct i802_driver_data *drv = priv;
2417 struct ieee80211_mgmt mgmt;
2419 memset(&mgmt, 0, sizeof(mgmt));
2420 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2421 WLAN_FC_STYPE_DISASSOC);
2422 memcpy(mgmt.da, addr, ETH_ALEN);
2423 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2424 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2425 mgmt.u.disassoc.reason_code = host_to_le16(reason);
2426 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2427 sizeof(mgmt.u.disassoc), 0);
2431 static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
2433 struct i802_driver_data *drv;
2435 drv = os_zalloc(sizeof(struct i802_driver_data));
2437 printf("Could not allocate memory for i802 driver data\n");
2442 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
2444 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
2445 drv->if_indices = drv->default_if_indices;
2446 drv->bridge = if_nametoindex(hapd->conf->bridge);
2448 if (i802_init_sockets(drv, bssid))
2459 static void *i802_init(struct hostapd_data *hapd)
2461 return i802_init_bssid(hapd, NULL);
2465 static void i802_deinit(void *priv)
2467 struct i802_driver_data *drv = priv;
2469 if (drv->last_freq_ht) {
2470 /* Clear HT flags from the driver */
2471 struct hostapd_freq_params freq;
2472 os_memset(&freq, 0, sizeof(freq));
2473 freq.freq = drv->last_freq;
2474 i802_set_freq2(priv, &freq);
2477 i802_del_beacon(drv);
2479 /* remove monitor interface */
2480 nl80211_remove_iface(drv, drv->monitor_ifidx);
2482 (void) hostapd_set_iface_flags(drv, drv->iface, 0);
2484 if (drv->monitor_sock >= 0) {
2485 eloop_unregister_read_sock(drv->monitor_sock);
2486 close(drv->monitor_sock);
2488 if (drv->ioctl_sock >= 0)
2489 close(drv->ioctl_sock);
2490 if (drv->eapol_sock >= 0) {
2491 eloop_unregister_read_sock(drv->eapol_sock);
2492 close(drv->eapol_sock);
2495 genl_family_put(drv->nl80211);
2496 nl_cache_free(drv->nl_cache);
2497 nl_handle_destroy(drv->nl_handle);
2498 nl_cb_put(drv->nl_cb);
2500 if (drv->if_indices != drv->default_if_indices)
2501 free(drv->if_indices);
2507 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
2510 .init_bssid = i802_init_bssid,
2511 .deinit = i802_deinit,
2512 .wireless_event_init = i802_wireless_event_init,
2513 .wireless_event_deinit = i802_wireless_event_deinit,
2514 .set_ieee8021x = i802_set_ieee8021x,
2515 .set_privacy = i802_set_privacy,
2516 .set_encryption = i802_set_encryption,
2517 .get_seqnum = i802_get_seqnum,
2518 .flush = i802_flush,
2519 .read_sta_data = i802_read_sta_data,
2520 .send_eapol = i802_send_eapol,
2521 .sta_set_flags = i802_sta_set_flags,
2522 .sta_deauth = i802_sta_deauth,
2523 .sta_disassoc = i802_sta_disassoc,
2524 .sta_remove = i802_sta_remove,
2525 .send_mgmt_frame = i802_send_mgmt_frame,
2526 .sta_add2 = i802_sta_add2,
2527 .get_inact_sec = i802_get_inact_sec,
2528 .sta_clear_stats = i802_sta_clear_stats,
2529 .set_freq2 = i802_set_freq2,
2530 .set_rts = i802_set_rts,
2531 .get_rts = i802_get_rts,
2532 .set_frag = i802_set_frag,
2533 .get_frag = i802_get_frag,
2534 .set_retry = i802_set_retry,
2535 .get_retry = i802_get_retry,
2536 .set_rate_sets = i802_set_rate_sets,
2537 .set_regulatory_domain = i802_set_regulatory_domain,
2538 .set_beacon = i802_set_beacon,
2539 .set_internal_bridge = i802_set_internal_bridge,
2540 .set_beacon_int = i802_set_beacon_int,
2541 .set_dtim_period = i802_set_dtim_period,
2542 .set_cts_protect = i802_set_cts_protect,
2543 .set_preamble = i802_set_preamble,
2544 .set_short_slot_time = i802_set_short_slot_time,
2545 .set_tx_queue_params = i802_set_tx_queue_params,
2546 .bss_add = i802_bss_add,
2547 .bss_remove = i802_bss_remove,
2548 .if_add = i802_if_add,
2549 .if_update = i802_if_update,
2550 .if_remove = i802_if_remove,
2551 .get_hw_feature_data = i802_get_hw_feature_data,
2552 .set_sta_vlan = i802_set_sta_vlan,
2553 .set_country = i802_set_country,