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 struct ieee80211_mgmt *mgmt;
464 int do_not_encrypt = 0;
467 mgmt = (struct ieee80211_mgmt *) data;
468 fc = le_to_host16(mgmt->frame_control);
470 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
471 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
473 * Only one of the authentication frame types is encrypted.
474 * In order for static WEP encryption to work properly (i.e.,
475 * to not encrypt the frame), we need to tell mac80211 about
476 * the frames that must not be encrypted.
478 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
479 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
480 if (auth_alg == WLAN_AUTH_OPEN ||
481 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_trans != 3))
485 return i802_send_frame(priv, data, len, !do_not_encrypt, flags);
488 /* Set kernel driver on given frequency (MHz) */
489 static int i802_set_freq2(void *priv, struct hostapd_freq_params *freq)
491 #ifdef NL80211_ATTR_WIPHY_FREQ
492 struct i802_driver_data *drv = priv;
499 drv->last_freq = freq->freq;
500 drv->last_freq_ht = freq->ht_enabled;
502 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
503 NL80211_CMD_SET_WIPHY, 0);
505 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
506 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
507 if (freq->ht_enabled) {
508 switch (freq->sec_channel_offset) {
510 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
511 NL80211_SEC_CHAN_BELOW);
514 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
515 NL80211_SEC_CHAN_ABOVE);
518 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET,
519 NL80211_SEC_CHAN_DISABLED);
524 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
528 #else /* NL80211_ATTR_WIPHY_FREQ */
529 struct i802_driver_data *drv = priv;
532 memset(&iwr, 0, sizeof(iwr));
533 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
534 iwr.u.freq.m = freq->freq;
537 if (ioctl(drv->ioctl_sock, SIOCSIWFREQ, &iwr) < 0) {
538 perror("ioctl[SIOCSIWFREQ]");
543 #endif /* NL80211_ATTR_WIPHY_FREQ */
547 static int i802_set_rts(void *priv, int rts)
549 struct i802_driver_data *drv = priv;
552 memset(&iwr, 0, sizeof(iwr));
553 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
554 iwr.u.rts.value = rts;
557 if (ioctl(drv->ioctl_sock, SIOCSIWRTS, &iwr) < 0) {
558 perror("ioctl[SIOCSIWRTS]");
566 static int i802_get_rts(void *priv, int *rts)
568 struct i802_driver_data *drv = priv;
571 memset(&iwr, 0, sizeof(iwr));
572 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
574 if (ioctl(drv->ioctl_sock, SIOCGIWRTS, &iwr) < 0) {
575 perror("ioctl[SIOCGIWRTS]");
579 *rts = iwr.u.rts.value;
585 static int i802_set_frag(void *priv, int frag)
587 struct i802_driver_data *drv = priv;
590 memset(&iwr, 0, sizeof(iwr));
591 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
592 iwr.u.frag.value = frag;
593 iwr.u.frag.fixed = 1;
595 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
596 perror("ioctl[SIOCSIWFRAG]");
604 static int i802_get_frag(void *priv, int *frag)
606 struct i802_driver_data *drv = priv;
609 memset(&iwr, 0, sizeof(iwr));
610 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
612 if (ioctl(drv->ioctl_sock, SIOCGIWFRAG, &iwr) < 0) {
613 perror("ioctl[SIOCGIWFRAG]");
617 *frag = iwr.u.frag.value;
623 static int i802_set_retry(void *priv, int short_retry, int long_retry)
625 struct i802_driver_data *drv = priv;
628 memset(&iwr, 0, sizeof(iwr));
629 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
631 iwr.u.retry.value = short_retry;
632 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
633 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
634 perror("ioctl[SIOCSIWRETRY(short)]");
638 iwr.u.retry.value = long_retry;
639 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
640 if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
641 perror("ioctl[SIOCSIWRETRY(long)]");
649 static int i802_get_retry(void *priv, int *short_retry, int *long_retry)
651 struct i802_driver_data *drv = priv;
654 memset(&iwr, 0, sizeof(iwr));
655 os_strlcpy(iwr.ifr_name, drv->hapd->conf->iface, IFNAMSIZ);
657 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
658 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
659 perror("ioctl[SIOCGIWFRAG(short)]");
662 *short_retry = iwr.u.retry.value;
664 iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
665 if (ioctl(drv->ioctl_sock, SIOCGIWRETRY, &iwr) < 0) {
666 perror("ioctl[SIOCGIWFRAG(long)]");
669 *long_retry = iwr.u.retry.value;
675 static int i802_flush(void *priv)
677 struct i802_driver_data *drv = priv;
684 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
685 0, NL80211_CMD_DEL_STATION, 0);
688 * XXX: FIX! this needs to flush all VLANs too
690 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
691 if_nametoindex(drv->iface));
693 return send_and_recv_msgs(drv, msg, NULL, NULL);
699 static int get_sta_handler(struct nl_msg *msg, void *arg)
701 struct nlattr *tb[NL80211_ATTR_MAX + 1];
702 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
703 struct hostap_sta_driver_data *data = arg;
704 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
705 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
706 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
707 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
708 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
711 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
712 genlmsg_attrlen(gnlh, 0), NULL);
715 * TODO: validate the interface and mac address!
716 * Otherwise, there's a race condition as soon as
717 * the kernel starts sending station notifications.
720 if (!tb[NL80211_ATTR_STA_INFO]) {
721 wpa_printf(MSG_DEBUG, "sta stats missing!");
724 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
725 tb[NL80211_ATTR_STA_INFO],
727 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
731 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
732 data->inactive_msec =
733 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
734 if (stats[NL80211_STA_INFO_RX_BYTES])
735 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
736 if (stats[NL80211_STA_INFO_TX_BYTES])
737 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
742 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
745 struct i802_driver_data *drv = priv;
752 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
753 0, NL80211_CMD_GET_STATION, 0);
755 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
756 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
758 return send_and_recv_msgs(drv, msg, get_sta_handler, data);
764 static int i802_send_eapol(void *priv, const u8 *addr, const u8 *data,
765 size_t data_len, int encrypt, const u8 *own_addr)
767 struct i802_driver_data *drv = priv;
768 struct ieee80211_hdr *hdr;
773 int qos = sta->flags & WLAN_STA_WME;
778 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
780 hdr = os_zalloc(len);
782 printf("malloc() failed for i802_send_data(len=%lu)\n",
783 (unsigned long) len);
788 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
789 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
791 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
792 #if 0 /* To be enabled if qos determination is added above */
794 hdr->frame_control |=
795 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
799 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
800 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
801 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
802 pos = (u8 *) (hdr + 1);
804 #if 0 /* To be enabled if qos determination is added above */
806 /* add an empty QoS header if needed */
813 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
814 pos += sizeof(rfc1042_header);
815 WPA_PUT_BE16(pos, ETH_P_PAE);
817 memcpy(pos, data, data_len);
819 res = i802_send_frame(drv, (u8 *) hdr, len, encrypt, 0);
823 perror("i802_send_eapol: send");
824 printf("i802_send_eapol - packet len: %lu - failed\n",
825 (unsigned long) len);
832 static int i802_sta_add2(const char *ifname, void *priv,
833 struct hostapd_sta_add_params *params)
835 struct i802_driver_data *drv = priv;
843 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
844 0, NL80211_CMD_NEW_STATION, 0);
846 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
847 if_nametoindex(drv->iface));
848 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr);
849 NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid);
850 NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len,
852 NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
853 params->listen_interval);
855 #ifdef CONFIG_IEEE80211N
856 #ifdef NL80211_ATTR_HT_CAPABILITY
857 if (params->ht_capabilities) {
858 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
859 params->ht_capabilities->length,
860 ¶ms->ht_capabilities->data);
862 #endif /* NL80211_ATTR_HT_CAPABILITY */
863 #endif /* CONFIG_IEEE80211N */
865 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
873 static int i802_sta_remove(void *priv, const u8 *addr)
875 struct i802_driver_data *drv = priv;
883 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
884 0, NL80211_CMD_DEL_STATION, 0);
886 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
887 if_nametoindex(drv->iface));
888 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
890 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
899 static int i802_sta_set_flags(void *priv, const u8 *addr,
900 int total_flags, int flags_or, int flags_and)
902 struct i802_driver_data *drv = priv;
903 struct nl_msg *msg, *flags = NULL;
909 flags = nlmsg_alloc();
915 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
916 0, NL80211_CMD_SET_STATION, 0);
918 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
919 if_nametoindex(drv->iface));
920 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
922 if (total_flags & WLAN_STA_AUTHORIZED || !drv->ieee802_1x_active)
923 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
925 if (total_flags & WLAN_STA_WME)
926 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
928 if (total_flags & WLAN_STA_SHORT_PREAMBLE)
929 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
931 #ifdef NL80211_MFP_PENDING
932 if (total_flags & WLAN_STA_MFP)
933 NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
934 #endif /* NL80211_MFP_PENDING */
936 if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
937 goto nla_put_failure;
941 return send_and_recv_msgs(drv, msg, NULL, NULL);
948 static int i802_set_regulatory_domain(void *priv, unsigned int rd)
954 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
955 int cw_min, int cw_max, int burst_time)
957 #ifdef NL80211_ATTR_WIPHY_TXQ_PARAMS
958 struct i802_driver_data *drv = priv;
960 struct nlattr *txq, *params;
966 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
967 0, NL80211_CMD_SET_WIPHY, 0);
969 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
971 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
973 goto nla_put_failure;
975 /* We are only sending parameters for a single TXQ at a time */
976 params = nla_nest_start(msg, 1);
978 goto nla_put_failure;
980 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue);
981 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
982 * 32 usec, so need to convert the value here. */
983 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32);
984 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min);
985 NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max);
986 NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs);
988 nla_nest_end(msg, params);
990 nla_nest_end(msg, txq);
992 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
996 #else /* NL80211_ATTR_WIPHY_TXQ_PARAMS */
998 #endif /* NL80211_ATTR_WIPHY_TXQ_PARAMS */
1002 static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
1006 /* stop listening for EAPOL on this interface */
1007 del_ifidx(drv, ifidx);
1009 msg = nlmsg_alloc();
1011 goto nla_put_failure;
1013 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1014 0, NL80211_CMD_DEL_INTERFACE, 0);
1015 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
1017 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
1020 printf("Failed to remove interface.\n");
1024 static int nl80211_create_iface(struct i802_driver_data *drv,
1026 enum nl80211_iftype iftype,
1029 struct nl_msg *msg, *flags = NULL;
1035 msg = nlmsg_alloc();
1039 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1040 0, NL80211_CMD_NEW_INTERFACE, 0);
1041 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1042 if_nametoindex(drv->hapd->conf->iface));
1043 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
1044 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
1046 if (iftype == NL80211_IFTYPE_MONITOR) {
1049 flags = nlmsg_alloc();
1051 goto nla_put_failure;
1053 NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
1055 err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
1060 goto nla_put_failure;
1063 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1066 printf("Failed to create interface %s.\n", ifname);
1070 ifidx = if_nametoindex(ifname);
1075 /* start listening for EAPOL on this interface */
1076 add_ifidx(drv, ifidx);
1080 case NL80211_IFTYPE_AP:
1081 os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
1082 memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
1083 ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
1085 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
1086 nl80211_remove_iface(drv, ifidx);
1090 case NL80211_IFTYPE_WDS:
1091 memset(&iwr, 0, sizeof(iwr));
1092 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1093 iwr.u.addr.sa_family = ARPHRD_ETHER;
1094 memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
1095 if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
1108 static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
1113 * The kernel supports that when the low-level driver does,
1114 * but we currently don't because we need per-BSS data that
1115 * currently we can't handle easily.
1119 ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
1122 if (hostapd_set_iface_flags(priv, ifname, 1)) {
1123 nl80211_remove_iface(priv, ifidx);
1130 static int i802_bss_remove(void *priv, const char *ifname)
1132 nl80211_remove_iface(priv, if_nametoindex(ifname));
1137 static int i802_set_beacon(const char *iface, void *priv,
1138 u8 *head, size_t head_len,
1139 u8 *tail, size_t tail_len)
1141 struct i802_driver_data *drv = priv;
1143 u8 cmd = NL80211_CMD_NEW_BEACON;
1146 msg = nlmsg_alloc();
1150 if (drv->beacon_set)
1151 cmd = NL80211_CMD_SET_BEACON;
1153 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1155 NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
1156 NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
1157 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1158 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
1160 if (!drv->dtim_period)
1161 drv->dtim_period = 2;
1162 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1164 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
1166 drv->beacon_set = 1;
1173 static int i802_del_beacon(struct i802_driver_data *drv)
1177 msg = nlmsg_alloc();
1181 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1182 0, NL80211_CMD_DEL_BEACON, 0);
1183 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1185 return send_and_recv_msgs(drv, msg, NULL, NULL);
1191 static int i802_set_ieee8021x(const char *ifname, void *priv, int enabled)
1193 struct i802_driver_data *drv = priv;
1196 * FIXME: This needs to be per interface (BSS)
1198 drv->ieee802_1x_active = enabled;
1203 static int i802_set_privacy(const char *ifname, void *priv, int enabled)
1205 struct i802_driver_data *drv = priv;
1208 memset(&iwr, 0, sizeof(iwr));
1210 os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
1211 iwr.u.param.flags = IW_AUTH_PRIVACY_INVOKED;
1212 iwr.u.param.value = enabled;
1214 ioctl(drv->ioctl_sock, SIOCSIWAUTH, &iwr);
1216 /* ignore errors, the kernel/driver might not care */
1221 static int i802_set_internal_bridge(void *priv, int value)
1227 static int i802_set_beacon_int(void *priv, int value)
1229 struct i802_driver_data *drv = priv;
1232 drv->beacon_int = value;
1234 if (!drv->beacon_set)
1237 msg = nlmsg_alloc();
1241 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1242 0, NL80211_CMD_SET_BEACON, 0);
1243 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1245 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
1247 return send_and_recv_msgs(drv, msg, NULL, NULL);
1253 static int i802_set_dtim_period(const char *iface, void *priv, int value)
1255 struct i802_driver_data *drv = priv;
1258 msg = nlmsg_alloc();
1262 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1263 0, NL80211_CMD_SET_BEACON, 0);
1264 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
1266 drv->dtim_period = value;
1267 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
1269 return send_and_recv_msgs(drv, msg, NULL, NULL);
1275 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
1277 #ifdef NL80211_CMD_SET_BSS
1278 struct i802_driver_data *drv = priv;
1281 msg = nlmsg_alloc();
1285 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
1286 NL80211_CMD_SET_BSS, 0);
1289 NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
1291 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
1293 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
1295 /* TODO: multi-BSS support */
1296 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1298 return send_and_recv_msgs(drv, msg, NULL, NULL);
1301 #else /* NL80211_CMD_SET_BSS */
1303 #endif /* NL80211_CMD_SET_BSS */
1307 static int i802_set_cts_protect(void *priv, int value)
1309 return i802_set_bss(priv, value, -1, -1);
1313 static int i802_set_preamble(void *priv, int value)
1315 return i802_set_bss(priv, -1, value, -1);
1319 static int i802_set_short_slot_time(void *priv, int value)
1321 return i802_set_bss(priv, -1, -1, value);
1325 static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
1328 case HOSTAPD_IF_VLAN:
1329 return NL80211_IFTYPE_AP_VLAN;
1330 case HOSTAPD_IF_WDS:
1331 return NL80211_IFTYPE_WDS;
1337 static int i802_if_add(const char *iface, void *priv,
1338 enum hostapd_driver_if_type type, char *ifname,
1341 if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
1347 static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
1348 char *ifname, const u8 *addr)
1350 /* unused at the moment */
1355 static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
1356 const char *ifname, const u8 *addr)
1358 nl80211_remove_iface(priv, if_nametoindex(ifname));
1363 struct phy_info_arg {
1365 struct hostapd_hw_modes *modes;
1368 static int phy_info_handler(struct nl_msg *msg, void *arg)
1370 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1371 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1372 struct phy_info_arg *phy_info = arg;
1374 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
1376 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
1377 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
1378 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
1379 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
1380 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
1381 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
1382 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
1383 #ifdef NL80211_FREQUENCY_ATTR_MAX_TX_POWER
1384 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
1385 #endif /* NL80211_FREQUENCY_ATTR_MAX_TX_POWER */
1388 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
1389 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
1390 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
1391 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
1394 struct nlattr *nl_band;
1395 struct nlattr *nl_freq;
1396 struct nlattr *nl_rate;
1397 int rem_band, rem_freq, rem_rate;
1398 struct hostapd_hw_modes *mode;
1399 int idx, mode_is_set;
1401 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1402 genlmsg_attrlen(gnlh, 0), NULL);
1404 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
1407 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
1408 mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
1411 phy_info->modes = mode;
1415 mode = &phy_info->modes[*(phy_info->num_modes)];
1416 memset(mode, 0, sizeof(*mode));
1417 *(phy_info->num_modes) += 1;
1419 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
1420 nla_len(nl_band), NULL);
1422 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1423 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1424 nla_len(nl_freq), freq_policy);
1425 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1427 mode->num_channels++;
1430 mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
1431 if (!mode->channels)
1436 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
1437 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
1438 nla_len(nl_freq), freq_policy);
1439 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
1442 mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
1443 mode->channels[idx].flag = 0;
1446 /* crude heuristic */
1447 if (mode->channels[idx].freq < 4000)
1448 mode->mode = HOSTAPD_MODE_IEEE80211B;
1450 mode->mode = HOSTAPD_MODE_IEEE80211A;
1454 /* crude heuristic */
1455 if (mode->channels[idx].freq < 4000)
1456 if (mode->channels[idx].freq == 2848)
1457 mode->channels[idx].chan = 14;
1459 mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
1461 mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
1463 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1464 mode->channels[idx].flag |=
1465 HOSTAPD_CHAN_DISABLED;
1466 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
1467 mode->channels[idx].flag |=
1468 HOSTAPD_CHAN_PASSIVE_SCAN;
1469 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
1470 mode->channels[idx].flag |=
1471 HOSTAPD_CHAN_NO_IBSS;
1472 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
1473 mode->channels[idx].flag |=
1476 #ifdef NL80211_FREQUENCY_ATTR_MAX_TX_POWER
1477 if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
1478 !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
1479 mode->channels[idx].max_tx_power =
1480 nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100;
1481 #endif /* NL80211_FREQUENCY_ATTR_MAX_TX_POWER */
1486 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1487 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1488 nla_len(nl_rate), rate_policy);
1489 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1494 mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
1500 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
1501 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
1502 nla_len(nl_rate), rate_policy);
1503 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
1505 mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
1507 /* crude heuristic */
1508 if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
1509 mode->rates[idx].rate > 200)
1510 mode->mode = HOSTAPD_MODE_IEEE80211G;
1512 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
1513 mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
1522 static struct hostapd_hw_modes *i802_add_11b(struct hostapd_hw_modes *modes,
1526 struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
1527 int i, mode11g_idx = -1;
1529 /* If only 802.11g mode is included, use it to construct matching
1530 * 802.11b mode data. */
1532 for (m = 0; m < *num_modes; m++) {
1533 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
1534 return modes; /* 802.11b already included */
1535 if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1539 if (mode11g_idx < 0)
1540 return modes; /* 2.4 GHz band not supported at all */
1542 nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes));
1544 return modes; /* Could not add 802.11b mode */
1546 mode = &nmodes[*num_modes];
1547 os_memset(mode, 0, sizeof(*mode));
1551 mode->mode = HOSTAPD_MODE_IEEE80211B;
1553 mode11g = &modes[mode11g_idx];
1554 mode->num_channels = mode11g->num_channels;
1555 mode->channels = os_malloc(mode11g->num_channels *
1556 sizeof(struct hostapd_channel_data));
1557 if (mode->channels == NULL) {
1559 return modes; /* Could not add 802.11b mode */
1561 os_memcpy(mode->channels, mode11g->channels,
1562 mode11g->num_channels * sizeof(struct hostapd_channel_data));
1564 mode->num_rates = 0;
1565 mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
1566 if (mode->rates == NULL) {
1567 os_free(mode->channels);
1569 return modes; /* Could not add 802.11b mode */
1572 for (i = 0; i < mode11g->num_rates; i++) {
1573 if (mode11g->rates[i].rate > 110 ||
1574 mode11g->rates[i].flags &
1575 (HOSTAPD_RATE_ERP | HOSTAPD_RATE_OFDM))
1577 mode->rates[mode->num_rates] = mode11g->rates[i];
1579 if (mode->num_rates == 4)
1583 if (mode->num_rates == 0) {
1584 os_free(mode->channels);
1585 os_free(mode->rates);
1587 return modes; /* No 802.11b rates */
1590 wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
1596 static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
1600 struct i802_driver_data *drv = priv;
1602 struct phy_info_arg result = {
1603 .num_modes = num_modes,
1610 msg = nlmsg_alloc();
1614 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1615 0, NL80211_CMD_GET_WIPHY, 0);
1617 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
1619 if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
1620 return i802_add_11b(result.modes, num_modes);
1626 static int i802_set_sta_vlan(void *priv, const u8 *addr,
1627 const char *ifname, int vlan_id)
1629 struct i802_driver_data *drv = priv;
1632 msg = nlmsg_alloc();
1636 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1637 0, NL80211_CMD_SET_STATION, 0);
1639 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1640 if_nametoindex(drv->iface));
1641 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
1642 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
1643 if_nametoindex(ifname));
1645 return send_and_recv_msgs(drv, msg, NULL, NULL);
1651 static int i802_set_country(void *priv, const char *country)
1653 struct i802_driver_data *drv = priv;
1657 msg = nlmsg_alloc();
1661 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
1662 0, NL80211_CMD_REQ_SET_REG, 0);
1664 alpha2[0] = country[0];
1665 alpha2[1] = country[1];
1667 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
1669 return send_and_recv_msgs(drv, msg, NULL, NULL);
1675 static void handle_unknown_sta(struct hostapd_data *hapd, u8 *ta)
1677 struct sta_info *sta;
1679 sta = ap_get_sta(hapd, ta);
1680 if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
1681 printf("Data/PS-poll frame from not associated STA "
1682 MACSTR "\n", MAC2STR(ta));
1683 if (sta && (sta->flags & WLAN_STA_AUTH))
1684 hostapd_sta_disassoc(
1686 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1690 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1695 static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
1698 struct ieee80211_hdr *hdr;
1699 u16 fc, type, stype;
1700 struct sta_info *sta;
1702 hdr = (struct ieee80211_hdr *) buf;
1703 fc = le_to_host16(hdr->frame_control);
1705 type = WLAN_FC_GET_TYPE(fc);
1706 stype = WLAN_FC_GET_STYPE(fc);
1709 case WLAN_FC_TYPE_MGMT:
1710 wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
1711 ok ? "ACK" : "fail");
1712 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1714 case WLAN_FC_TYPE_CTRL:
1715 wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
1716 ok ? "ACK" : "fail");
1718 case WLAN_FC_TYPE_DATA:
1719 wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
1720 ok ? "ACK" : "fail");
1721 sta = ap_get_sta(hapd, hdr->addr1);
1722 if (sta && sta->flags & WLAN_STA_PENDING_POLL) {
1723 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
1724 "activity poll", MAC2STR(sta->addr),
1725 ok ? "ACKed" : "did not ACK");
1727 sta->flags &= ~WLAN_STA_PENDING_POLL;
1730 ieee802_1x_tx_status(hapd, sta, buf, len, ok);
1733 printf("unknown TX callback frame type %d\n", type);
1739 static void handle_frame(struct hostapd_iface *iface, u8 *buf, size_t len,
1740 struct hostapd_frame_info *hfi,
1741 enum ieee80211_msg_type msg_type)
1743 struct ieee80211_hdr *hdr;
1744 u16 fc, type, stype;
1745 size_t data_len = len;
1746 struct hostapd_data *hapd = NULL;
1747 int broadcast_bssid = 0;
1752 * PS-Poll frames are 16 bytes. All other frames are
1753 * 24 bytes or longer.
1758 hdr = (struct ieee80211_hdr *) buf;
1759 fc = le_to_host16(hdr->frame_control);
1761 type = WLAN_FC_GET_TYPE(fc);
1762 stype = WLAN_FC_GET_STYPE(fc);
1765 case WLAN_FC_TYPE_DATA:
1768 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
1777 case WLAN_FC_TYPE_CTRL:
1778 /* discard non-ps-poll frames */
1779 if (stype != WLAN_FC_STYPE_PSPOLL)
1783 case WLAN_FC_TYPE_MGMT:
1791 /* find interface frame belongs to */
1792 for (i = 0; i < iface->num_bss; i++) {
1793 if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
1794 hapd = iface->bss[i];
1800 hapd = iface->bss[0];
1802 if (bssid[0] != 0xff || bssid[1] != 0xff ||
1803 bssid[2] != 0xff || bssid[3] != 0xff ||
1804 bssid[4] != 0xff || bssid[5] != 0xff) {
1806 * Unknown BSSID - drop frame if this is not from
1807 * passive scanning or a beacon (at least ProbeReq
1808 * frames to other APs may be allowed through RX
1809 * filtering in the wlan hw/driver)
1811 if ((type != WLAN_FC_TYPE_MGMT ||
1812 stype != WLAN_FC_STYPE_BEACON))
1815 broadcast_bssid = 1;
1819 case ieee80211_msg_normal:
1820 /* continue processing */
1822 case ieee80211_msg_tx_callback_ack:
1823 handle_tx_callback(hapd, buf, data_len, 1);
1825 case ieee80211_msg_tx_callback_fail:
1826 handle_tx_callback(hapd, buf, data_len, 0);
1831 case WLAN_FC_TYPE_MGMT:
1832 if (stype != WLAN_FC_STYPE_BEACON &&
1833 stype != WLAN_FC_STYPE_PROBE_REQ)
1834 wpa_printf(MSG_MSGDUMP, "MGMT");
1835 if (broadcast_bssid) {
1836 for (i = 0; i < iface->num_bss; i++)
1837 ieee802_11_mgmt(iface->bss[i], buf, data_len,
1840 ieee802_11_mgmt(hapd, buf, data_len, stype, hfi);
1842 case WLAN_FC_TYPE_CTRL:
1843 /* can only get here with PS-Poll frames */
1844 wpa_printf(MSG_DEBUG, "CTRL");
1845 handle_unknown_sta(hapd, hdr->addr2);
1847 case WLAN_FC_TYPE_DATA:
1848 wpa_printf(MSG_DEBUG, "DATA");
1849 handle_unknown_sta(hapd, hdr->addr2);
1855 static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
1857 struct i802_driver_data *drv = eloop_ctx;
1858 struct hostapd_data *hapd = drv->hapd;
1859 struct sockaddr_ll lladdr;
1860 unsigned char buf[3000];
1862 socklen_t fromlen = sizeof(lladdr);
1864 len = recvfrom(sock, buf, sizeof(buf), 0,
1865 (struct sockaddr *)&lladdr, &fromlen);
1871 if (have_ifidx(drv, lladdr.sll_ifindex))
1872 ieee802_1x_receive(hapd, lladdr.sll_addr, buf, len);
1876 static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
1878 struct i802_driver_data *drv = eloop_ctx;
1880 unsigned char buf[3000];
1881 struct hostapd_data *hapd = drv->hapd;
1882 struct ieee80211_radiotap_iterator iter;
1884 struct hostapd_frame_info hfi;
1885 int injected = 0, failed = 0, msg_type, rxflags = 0;
1887 len = recv(sock, buf, sizeof(buf), 0);
1893 if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
1894 printf("received invalid radiotap frame\n");
1898 memset(&hfi, 0, sizeof(hfi));
1901 ret = ieee80211_radiotap_iterator_next(&iter);
1905 printf("received invalid radiotap frame (%d)\n", ret);
1908 switch (iter.this_arg_index) {
1909 case IEEE80211_RADIOTAP_FLAGS:
1910 if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
1913 case IEEE80211_RADIOTAP_RX_FLAGS:
1916 case IEEE80211_RADIOTAP_TX_FLAGS:
1918 failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
1919 IEEE80211_RADIOTAP_F_TX_FAIL;
1921 case IEEE80211_RADIOTAP_DATA_RETRIES:
1923 case IEEE80211_RADIOTAP_CHANNEL:
1924 /* TODO convert from freq/flags to channel number
1929 case IEEE80211_RADIOTAP_RATE:
1930 hfi.datarate = *iter.this_arg * 5;
1932 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1933 hfi.ssi_signal = *iter.this_arg;
1938 if (rxflags && injected)
1942 msg_type = ieee80211_msg_normal;
1944 msg_type = ieee80211_msg_tx_callback_fail;
1946 msg_type = ieee80211_msg_tx_callback_ack;
1948 handle_frame(hapd->iface, buf + iter.max_length,
1949 len - iter.max_length, &hfi, msg_type);
1953 static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
1956 struct sockaddr_ll ll;
1960 snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
1961 buf[IFNAMSIZ - 1] = '\0';
1963 drv->monitor_ifidx =
1964 nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
1966 if (drv->monitor_ifidx < 0)
1969 if (hostapd_set_iface_flags(drv, buf, 1))
1972 memset(&ll, 0, sizeof(ll));
1973 ll.sll_family = AF_PACKET;
1974 ll.sll_ifindex = drv->monitor_ifidx;
1975 drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1976 if (drv->monitor_sock < 0) {
1977 perror("socket[PF_PACKET,SOCK_RAW]");
1981 if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
1983 perror("monitor socket bind");
1987 optlen = sizeof(optval);
1990 (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
1991 perror("Failed to set socket priority");
1995 if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
1997 printf("Could not register monitor read socket\n");
2003 nl80211_remove_iface(drv, drv->monitor_ifidx);
2008 static int nl80211_set_master_mode(struct i802_driver_data *drv,
2014 msg = nlmsg_alloc();
2018 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
2019 0, NL80211_CMD_SET_INTERFACE, 0);
2020 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
2021 if_nametoindex(ifname));
2022 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
2024 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2028 wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
2034 static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
2037 struct sockaddr_ll addr;
2039 drv->ioctl_sock = -1;
2041 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
2042 if (drv->ioctl_sock < 0) {
2043 perror("socket[PF_INET,SOCK_DGRAM]");
2047 /* start listening for EAPOL on the default AP interface */
2048 add_ifidx(drv, if_nametoindex(drv->iface));
2050 if (hostapd_set_iface_flags(drv, drv->iface, 0))
2054 os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
2055 memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
2056 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
2058 if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
2059 perror("ioctl(SIOCSIFHWADDR)");
2065 * initialise generic netlink and nl80211
2067 drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
2069 printf("Failed to allocate netlink callbacks.\n");
2073 drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
2074 if (!drv->nl_handle) {
2075 printf("Failed to allocate netlink handle.\n");
2079 if (genl_connect(drv->nl_handle)) {
2080 printf("Failed to connect to generic netlink.\n");
2084 drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
2085 if (!drv->nl_cache) {
2086 printf("Failed to allocate generic netlink cache.\n");
2090 drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
2091 if (!drv->nl80211) {
2092 printf("nl80211 not found.\n");
2096 /* Initialise a monitor interface */
2097 if (nl80211_create_monitor_interface(drv))
2100 if (nl80211_set_master_mode(drv, drv->iface))
2103 if (hostapd_set_iface_flags(drv, drv->iface, 1))
2106 memset(&addr, 0, sizeof(addr));
2107 addr.sll_family = AF_PACKET;
2108 addr.sll_ifindex = ifr.ifr_ifindex;
2109 wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
2112 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
2113 if (drv->eapol_sock < 0) {
2114 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
2118 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
2120 printf("Could not register read socket for eapol\n");
2124 memset(&ifr, 0, sizeof(ifr));
2125 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
2126 if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
2127 perror("ioctl(SIOCGIFHWADDR)");
2131 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
2132 printf("Invalid HW-addr family 0x%04x\n",
2133 ifr.ifr_hwaddr.sa_family);
2136 memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
2141 nl80211_remove_iface(drv, drv->monitor_ifidx);
2146 static int i802_get_inact_sec(void *priv, const u8 *addr)
2148 struct hostap_sta_driver_data data;
2151 data.inactive_msec = (unsigned long) -1;
2152 ret = i802_read_sta_data(priv, &data, addr);
2153 if (ret || data.inactive_msec == (unsigned long) -1)
2155 return data.inactive_msec / 1000;
2159 static int i802_sta_clear_stats(void *priv, const u8 *addr)
2169 hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
2172 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
2174 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
2177 pos = strstr(custom, "addr=");
2179 wpa_printf(MSG_DEBUG,
2180 "MLME-MICHAELMICFAILURE.indication "
2181 "without sender address ignored");
2185 if (hwaddr_aton(pos, addr) == 0) {
2186 ieee80211_michael_mic_failure(drv->hapd, addr, 1);
2188 wpa_printf(MSG_DEBUG,
2189 "MLME-MICHAELMICFAILURE.indication "
2190 "with invalid MAC address");
2196 static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
2197 char *data, int len)
2199 struct iw_event iwe_buf, *iwe = &iwe_buf;
2200 char *pos, *end, *custom, *buf;
2205 while (pos + IW_EV_LCP_LEN <= end) {
2206 /* Event data may be unaligned, so make a local, aligned copy
2207 * before processing. */
2208 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
2209 wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
2210 iwe->cmd, iwe->len);
2211 if (iwe->len <= IW_EV_LCP_LEN)
2214 custom = pos + IW_EV_POINT_LEN;
2215 if (drv->we_version > 18 &&
2216 (iwe->cmd == IWEVMICHAELMICFAILURE ||
2217 iwe->cmd == IWEVCUSTOM)) {
2218 /* WE-19 removed the pointer from struct iw_point */
2219 char *dpos = (char *) &iwe_buf.u.data.length;
2220 int dlen = dpos - (char *) &iwe_buf;
2221 memcpy(dpos, pos + IW_EV_LCP_LEN,
2222 sizeof(struct iw_event) - dlen);
2224 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
2225 custom += IW_EV_POINT_OFF;
2230 if (custom + iwe->u.data.length > end)
2232 buf = malloc(iwe->u.data.length + 1);
2235 memcpy(buf, custom, iwe->u.data.length);
2236 buf[iwe->u.data.length] = '\0';
2237 hostapd_wireless_event_wireless_custom(drv, buf);
2247 static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
2248 struct nlmsghdr *h, int len)
2250 struct ifinfomsg *ifi;
2251 int attrlen, nlmsg_len, rta_len;
2252 struct rtattr *attr;
2254 if (len < (int) sizeof(*ifi))
2257 ifi = NLMSG_DATA(h);
2259 /* TODO: use ifi->ifi_index to filter out wireless events from other
2262 nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
2264 attrlen = h->nlmsg_len - nlmsg_len;
2268 attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
2270 rta_len = RTA_ALIGN(sizeof(struct rtattr));
2271 while (RTA_OK(attr, attrlen)) {
2272 if (attr->rta_type == IFLA_WIRELESS) {
2273 hostapd_wireless_event_wireless(
2274 drv, ((char *) attr) + rta_len,
2275 attr->rta_len - rta_len);
2277 attr = RTA_NEXT(attr, attrlen);
2282 static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
2287 struct sockaddr_nl from;
2290 struct i802_driver_data *drv = eloop_ctx;
2292 fromlen = sizeof(from);
2293 left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
2294 (struct sockaddr *) &from, &fromlen);
2296 if (errno != EINTR && errno != EAGAIN)
2297 perror("recvfrom(netlink)");
2301 h = (struct nlmsghdr *) buf;
2302 while (left >= (int) sizeof(*h)) {
2306 plen = len - sizeof(*h);
2307 if (len > left || plen < 0) {
2308 printf("Malformed netlink message: "
2309 "len=%d left=%d plen=%d\n",
2314 switch (h->nlmsg_type) {
2316 hostapd_wireless_event_rtm_newlink(drv, h, plen);
2320 len = NLMSG_ALIGN(len);
2322 h = (struct nlmsghdr *) ((char *) h + len);
2326 printf("%d extra bytes in the end of netlink message\n", left);
2331 static int hostap_get_we_version(struct i802_driver_data *drv)
2333 struct iw_range *range;
2338 drv->we_version = 0;
2341 * Use larger buffer than struct iw_range in order to allow the
2342 * structure to grow in the future.
2344 buflen = sizeof(struct iw_range) + 500;
2345 range = os_zalloc(buflen);
2349 memset(&iwr, 0, sizeof(iwr));
2350 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
2351 iwr.u.data.pointer = (caddr_t) range;
2352 iwr.u.data.length = buflen;
2354 minlen = ((char *) &range->enc_capa) - (char *) range +
2355 sizeof(range->enc_capa);
2357 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
2358 perror("ioctl[SIOCGIWRANGE]");
2361 } else if (iwr.u.data.length >= minlen &&
2362 range->we_version_compiled >= 18) {
2363 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
2364 "WE(source)=%d enc_capa=0x%x",
2365 range->we_version_compiled,
2366 range->we_version_source,
2368 drv->we_version = range->we_version_compiled;
2376 static int i802_wireless_event_init(void *priv)
2378 struct i802_driver_data *drv = priv;
2380 struct sockaddr_nl local;
2382 hostap_get_we_version(drv);
2384 drv->wext_sock = -1;
2386 s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
2388 perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
2392 memset(&local, 0, sizeof(local));
2393 local.nl_family = AF_NETLINK;
2394 local.nl_groups = RTMGRP_LINK;
2395 if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
2396 perror("bind(netlink)");
2401 eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
2409 static void i802_wireless_event_deinit(void *priv)
2411 struct i802_driver_data *drv = priv;
2412 if (drv->wext_sock < 0)
2414 eloop_unregister_read_sock(drv->wext_sock);
2415 close(drv->wext_sock);
2419 static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
2421 struct i802_driver_data *drv = priv;
2422 struct ieee80211_mgmt mgmt;
2424 memset(&mgmt, 0, sizeof(mgmt));
2425 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2426 WLAN_FC_STYPE_DEAUTH);
2427 memcpy(mgmt.da, addr, ETH_ALEN);
2428 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2429 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2430 mgmt.u.deauth.reason_code = host_to_le16(reason);
2431 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2432 sizeof(mgmt.u.deauth), 0);
2436 static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
2438 struct i802_driver_data *drv = priv;
2439 struct ieee80211_mgmt mgmt;
2441 memset(&mgmt, 0, sizeof(mgmt));
2442 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2443 WLAN_FC_STYPE_DISASSOC);
2444 memcpy(mgmt.da, addr, ETH_ALEN);
2445 memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
2446 memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
2447 mgmt.u.disassoc.reason_code = host_to_le16(reason);
2448 return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
2449 sizeof(mgmt.u.disassoc), 0);
2453 static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
2455 struct i802_driver_data *drv;
2457 drv = os_zalloc(sizeof(struct i802_driver_data));
2459 printf("Could not allocate memory for i802 driver data\n");
2464 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
2466 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
2467 drv->if_indices = drv->default_if_indices;
2468 drv->bridge = if_nametoindex(hapd->conf->bridge);
2470 if (i802_init_sockets(drv, bssid))
2481 static void *i802_init(struct hostapd_data *hapd)
2483 return i802_init_bssid(hapd, NULL);
2487 static void i802_deinit(void *priv)
2489 struct i802_driver_data *drv = priv;
2491 if (drv->last_freq_ht) {
2492 /* Clear HT flags from the driver */
2493 struct hostapd_freq_params freq;
2494 os_memset(&freq, 0, sizeof(freq));
2495 freq.freq = drv->last_freq;
2496 i802_set_freq2(priv, &freq);
2499 i802_del_beacon(drv);
2501 /* remove monitor interface */
2502 nl80211_remove_iface(drv, drv->monitor_ifidx);
2504 (void) hostapd_set_iface_flags(drv, drv->iface, 0);
2506 if (drv->monitor_sock >= 0) {
2507 eloop_unregister_read_sock(drv->monitor_sock);
2508 close(drv->monitor_sock);
2510 if (drv->ioctl_sock >= 0)
2511 close(drv->ioctl_sock);
2512 if (drv->eapol_sock >= 0) {
2513 eloop_unregister_read_sock(drv->eapol_sock);
2514 close(drv->eapol_sock);
2517 genl_family_put(drv->nl80211);
2518 nl_cache_free(drv->nl_cache);
2519 nl_handle_destroy(drv->nl_handle);
2520 nl_cb_put(drv->nl_cb);
2522 if (drv->if_indices != drv->default_if_indices)
2523 free(drv->if_indices);
2529 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
2532 .init_bssid = i802_init_bssid,
2533 .deinit = i802_deinit,
2534 .wireless_event_init = i802_wireless_event_init,
2535 .wireless_event_deinit = i802_wireless_event_deinit,
2536 .set_ieee8021x = i802_set_ieee8021x,
2537 .set_privacy = i802_set_privacy,
2538 .set_encryption = i802_set_encryption,
2539 .get_seqnum = i802_get_seqnum,
2540 .flush = i802_flush,
2541 .read_sta_data = i802_read_sta_data,
2542 .send_eapol = i802_send_eapol,
2543 .sta_set_flags = i802_sta_set_flags,
2544 .sta_deauth = i802_sta_deauth,
2545 .sta_disassoc = i802_sta_disassoc,
2546 .sta_remove = i802_sta_remove,
2547 .send_mgmt_frame = i802_send_mgmt_frame,
2548 .sta_add2 = i802_sta_add2,
2549 .get_inact_sec = i802_get_inact_sec,
2550 .sta_clear_stats = i802_sta_clear_stats,
2551 .set_freq2 = i802_set_freq2,
2552 .set_rts = i802_set_rts,
2553 .get_rts = i802_get_rts,
2554 .set_frag = i802_set_frag,
2555 .get_frag = i802_get_frag,
2556 .set_retry = i802_set_retry,
2557 .get_retry = i802_get_retry,
2558 .set_rate_sets = i802_set_rate_sets,
2559 .set_regulatory_domain = i802_set_regulatory_domain,
2560 .set_beacon = i802_set_beacon,
2561 .set_internal_bridge = i802_set_internal_bridge,
2562 .set_beacon_int = i802_set_beacon_int,
2563 .set_dtim_period = i802_set_dtim_period,
2564 .set_cts_protect = i802_set_cts_protect,
2565 .set_preamble = i802_set_preamble,
2566 .set_short_slot_time = i802_set_short_slot_time,
2567 .set_tx_queue_params = i802_set_tx_queue_params,
2568 .bss_add = i802_bss_add,
2569 .bss_remove = i802_bss_remove,
2570 .if_add = i802_if_add,
2571 .if_update = i802_if_update,
2572 .if_remove = i802_if_remove,
2573 .get_hw_feature_data = i802_get_hw_feature_data,
2574 .set_sta_vlan = i802_set_sta_vlan,
2575 .set_country = i802_set_country,