OSDN Git Service

Accumulative patch from commit dc013f1e37df3462085cf01a13f0c432f146ad7a
[android-x86/external-wpa_supplicant_8.git] / src / drivers / driver_atheros.c
index b17d1a6..c2f5934 100644 (file)
@@ -5,14 +5,8 @@
  * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
  * Copyright (c) 2009, Atheros Communications
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "includes.h"
 #include <sys/ioctl.h>
 
 #include "common.h"
+#include "eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "l2_packet/l2_packet.h"
+#include "p2p/p2p.h"
+
+#include "common.h"
 #ifndef _BYTE_ORDER
 #ifdef WORDS_BIGENDIAN
 #define _BYTE_ORDER _BIG_ENDIAN
 
 #ifdef CONFIG_WPS
 #include <netpacket/packet.h>
+#endif /* CONFIG_WPS */
 
 #ifndef ETH_P_80211_RAW
 #define ETH_P_80211_RAW 0x0019
 #endif
-#endif /* CONFIG_WPS */
 
 #include "linux_wext.h"
 
@@ -73,6 +73,7 @@ struct atheros_driver_data {
        struct wpabuf *wpa_ie;
        struct wpabuf *wps_beacon_ie;
        struct wpabuf *wps_probe_resp_ie;
+       u8      own_addr[ETH_ALEN];
 };
 
 static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
@@ -323,8 +324,7 @@ atheros_configure_wpa(struct atheros_driver_data *drv,
        }
 #endif /* CONFIG_IEEE80211W */
 
-       wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
-                  __func__, params->rsn_preauth);
+       wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
        if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
                printf("Unable to set RSN capabilities to 0x%x\n", v);
                return -1;
@@ -732,8 +732,8 @@ atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
 }
 
 #ifdef CONFIG_WPS
-static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
-                               size_t len)
+static void atheros_raw_recv_wps(void *ctx, const u8 *src_addr, const u8 *buf,
+                                size_t len)
 {
        struct atheros_driver_data *drv = ctx;
        const struct ieee80211_mgmt *mgmt;
@@ -762,28 +762,231 @@ static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
 }
 #endif /* CONFIG_WPS */
 
-static int atheros_receive_probe_req(struct atheros_driver_data *drv)
+#ifdef CONFIG_IEEE80211R
+static void atheros_raw_recv_11r(void *ctx, const u8 *src_addr, const u8 *buf,
+                                size_t len)
+{
+       struct atheros_driver_data *drv = ctx;
+       union wpa_event_data event;
+       const struct ieee80211_mgmt *mgmt;
+       u16 fc;
+       u16 stype;
+       int ielen;
+       const u8 *iebuf;
+
+       /* Do 11R processing for ASSOC/AUTH/FT ACTION frames */
+       if (len < IEEE80211_HDRLEN)
+               return;
+       mgmt = (const struct ieee80211_mgmt *) buf;
+
+       fc = le_to_host16(mgmt->frame_control);
+
+       if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
+               return;
+       stype = WLAN_FC_GET_STYPE(fc);
+
+       wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
+                  (int) len);
+
+       if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
+               wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
+                          __func__);
+               return;
+       }
+       switch (stype) {
+       case WLAN_FC_STYPE_ASSOC_REQ:
+               if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.assoc_req))
+                       break;
+               ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
+               iebuf = mgmt->u.assoc_req.variable;
+               drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 0);
+               break;
+       case WLAN_FC_STYPE_REASSOC_REQ:
+               if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.reassoc_req))
+                       break;
+               ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
+               iebuf = mgmt->u.reassoc_req.variable;
+               drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 1);
+               break;
+       case WLAN_FC_STYPE_ACTION:
+               if (&mgmt->u.action.category > buf + len)
+                       break;
+               os_memset(&event, 0, sizeof(event));
+               event.rx_action.da = mgmt->da;
+               event.rx_action.sa = mgmt->sa;
+               event.rx_action.bssid = mgmt->bssid;
+               event.rx_action.category = mgmt->u.action.category;
+               event.rx_action.data = &mgmt->u.action.category;
+               event.rx_action.len = buf + len - event.rx_action.data;
+               wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
+               break;
+       case WLAN_FC_STYPE_AUTH:
+               if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.auth))
+                       break;
+               os_memset(&event, 0, sizeof(event));
+               os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
+               os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
+               event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
+               event.auth.status_code =
+                       le_to_host16(mgmt->u.auth.status_code);
+               event.auth.auth_transaction =
+                       le_to_host16(mgmt->u.auth.auth_transaction);
+               event.auth.ies = mgmt->u.auth.variable;
+               event.auth.ies_len = len - IEEE80211_HDRLEN -
+                       sizeof(mgmt->u.auth);
+               wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
+               break;
+       default:
+               break;
+       }
+}
+#endif /* CONFIG_IEEE80211R */
+
+#ifdef CONFIG_HS20
+static void atheros_raw_recv_hs20(void *ctx, const u8 *src_addr, const u8 *buf,
+                                size_t len)
+{
+       struct atheros_driver_data *drv = ctx;
+       const struct ieee80211_mgmt *mgmt;
+       u16 fc;
+       union wpa_event_data event;
+
+       /* Send the Action frame for HS20 processing */
+
+       if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.action.category) +
+           sizeof(mgmt->u.action.u.public_action))
+               return;
+
+       mgmt = (const struct ieee80211_mgmt *) buf;
+
+       fc = le_to_host16(mgmt->frame_control);
+       if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
+           WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION ||
+           mgmt->u.action.category != WLAN_ACTION_PUBLIC)
+               return;
+
+       wpa_printf(MSG_DEBUG, "%s:Received Public Action frame", __func__);
+
+       os_memset(&event, 0, sizeof(event));
+       event.rx_mgmt.frame = (const u8 *) mgmt;
+       event.rx_mgmt.frame_len = len;
+       wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
+}
+#endif /* CONFIG_HS20 */
+
+#if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
+static void atheros_raw_recv_11v(void *ctx, const u8 *src_addr, const u8 *buf,
+                                size_t len)
+{
+       struct atheros_driver_data *drv = ctx;
+       union wpa_event_data event;
+       const struct ieee80211_mgmt *mgmt;
+       u16 fc;
+       u16 stype;
+
+       /* Do 11R processing for WNM ACTION frames */
+       if (len < IEEE80211_HDRLEN)
+               return;
+       mgmt = (const struct ieee80211_mgmt *) buf;
+
+       fc = le_to_host16(mgmt->frame_control);
+
+       if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
+               return;
+       stype = WLAN_FC_GET_STYPE(fc);
+
+       wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
+                  (int) len);
+
+       if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
+               wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
+                          __func__);
+               return;
+       }
+
+       switch (stype) {
+       case WLAN_FC_STYPE_ACTION:
+               if (&mgmt->u.action.category > buf + len)
+                       break;
+               os_memset(&event, 0, sizeof(event));
+               event.rx_action.da = mgmt->da;
+               event.rx_action.sa = mgmt->sa;
+               event.rx_action.bssid = mgmt->bssid;
+               event.rx_action.category = mgmt->u.action.category;
+               event.rx_action.data = &mgmt->u.action.category;
+               event.rx_action.len = buf + len - event.rx_action.data;
+               wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
+               break;
+       default:
+               break;
+       }
+}
+#endif /* CONFIG_WNM */
+
+#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_WNM)
+static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
+                               size_t len)
 {
-       int ret = 0;
 #ifdef CONFIG_WPS
+       atheros_raw_recv_wps(ctx, src_addr, buf, len);
+#endif /* CONFIG_WPS */
+#ifdef CONFIG_IEEE80211R
+       atheros_raw_recv_11r(ctx, src_addr, buf, len);
+#endif /* CONFIG_IEEE80211R */
+#if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
+       atheros_raw_recv_11v(ctx, src_addr, buf, len);
+#endif /* CONFIG_WNM */
+#ifdef CONFIG_HS20
+       atheros_raw_recv_hs20(ctx, src_addr, buf, len);
+#endif /* CONFIG_HS20 */
+}
+#endif /* CONFIG_WPS || CONFIG_IEEE80211R */
+
+static int atheros_receive_pkt(struct atheros_driver_data *drv)
+{
+       int ret = 0;
        struct ieee80211req_set_filter filt;
 
        wpa_printf(MSG_DEBUG, "%s Enter", __func__);
-       filt.app_filterype = IEEE80211_FILTER_TYPE_PROBE_REQ;
-
-       ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
-                          sizeof(struct ieee80211req_set_filter));
-       if (ret)
-               return ret;
+       filt.app_filterype = 0;
+#ifdef CONFIG_WPS
+       filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
+#endif /* CONFIG_WPS */
+#ifdef CONFIG_IEEE80211R
+       filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
+                              IEEE80211_FILTER_TYPE_AUTH |
+                              IEEE80211_FILTER_TYPE_ACTION);
+#endif
+#ifdef CONFIG_WNM
+       filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
+#endif /* CONFIG_WNM */
+#ifdef CONFIG_HS20
+       filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
+#endif /* CONFIG_HS20 */
+       if (filt.app_filterype) {
+               ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
+                                  sizeof(struct ieee80211req_set_filter));
+               if (ret)
+                       return ret;
+       }
 
+#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
        drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
                                       atheros_raw_receive, drv, 1);
        if (drv->sock_raw == NULL)
                return -1;
-#endif /* CONFIG_WPS */
+#endif /* CONFIG_WPS || CONFIG_IEEE80211R */
        return ret;
 }
 
+static int atheros_reset_appfilter(struct atheros_driver_data *drv)
+{
+       struct ieee80211req_set_filter filt;
+       filt.app_filterype = 0;
+       return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
+                           sizeof(struct ieee80211req_set_filter));
+}
+
 #ifdef CONFIG_WPS
 static int
 atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
@@ -852,6 +1055,84 @@ atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
 #define atheros_set_ap_wps_ie NULL
 #endif /* CONFIG_WPS */
 
+#ifdef CONFIG_IEEE80211R
+static int
+atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
+                u16 status_code, const u8 *ie, size_t len)
+{
+       struct atheros_driver_data *drv = priv;
+       struct ieee80211req_mlme mlme;
+       int ret;
+
+       wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
+                  __func__, ether_sprintf(addr), status_code);
+
+       mlme.im_op = IEEE80211_MLME_AUTH;
+       mlme.im_reason = status_code;
+       mlme.im_seq = seq;
+       os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+       mlme.im_optie_len = len;
+       if (len) {
+               if (len < IEEE80211_MAX_OPT_IE) {
+                       os_memcpy(mlme.im_optie, ie, len);
+               } else {
+                       wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
+                                  "opt_ie STA (addr " MACSTR " reason %d, "
+                                  "ie_len %d)",
+                                  __func__, MAC2STR(addr), status_code,
+                                  (int) len);
+                       return -1;
+               }
+       }
+       ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
+       if (ret < 0) {
+               wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
+                          " reason %d)",
+                          __func__, MAC2STR(addr), status_code);
+       }
+       return ret;
+}
+
+static int
+atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
+                 int reassoc, u16 status_code, const u8 *ie, size_t len)
+{
+       struct atheros_driver_data *drv = priv;
+       struct ieee80211req_mlme mlme;
+       int ret;
+
+       wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
+                  __func__, ether_sprintf(addr), status_code, reassoc);
+
+       if (reassoc)
+               mlme.im_op = IEEE80211_MLME_REASSOC;
+       else
+               mlme.im_op = IEEE80211_MLME_ASSOC;
+       mlme.im_reason = status_code;
+       os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+       mlme.im_optie_len = len;
+       if (len) {
+               if (len < IEEE80211_MAX_OPT_IE) {
+                       os_memcpy(mlme.im_optie, ie, len);
+               } else {
+                       wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
+                                  "opt_ie STA (addr " MACSTR " reason %d, "
+                                  "ie_len %d)",
+                                  __func__, MAC2STR(addr), status_code,
+                                  (int) len);
+                       return -1;
+               }
+       }
+       ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
+       if (ret < 0) {
+               wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
+                          " reason %d)",
+                          __func__, MAC2STR(addr), status_code);
+       }
+       return ret;
+}
+#endif /* CONFIG_IEEE80211R */
+
 static void
 atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
 {
@@ -980,6 +1261,9 @@ atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
                 * so all are enabled for WPS... ugh.
                 */
                wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
+#endif /* CONFIG_WPS */
+#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
+#define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
        } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
                /*
                 * Atheros driver uses a hack to pass Probe Request frames as a
@@ -987,16 +1271,134 @@ atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
                 * packet sniffing) didn't work when bridging.
                 * Format: "Manage.prob_req <frame len>" | zero padding | frame
                 */
-#define WPS_FRAM_TAG_SIZE 30 /* hardcoded in driver */
                int len = atoi(custom + 16);
-               if (len < 0 || custom + WPS_FRAM_TAG_SIZE + len > end) {
+               if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
                        wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
                                   "length %d", len);
                        return;
                }
                atheros_raw_receive(drv, NULL,
-                                   (u8 *) custom + WPS_FRAM_TAG_SIZE, len);
-#endif /* CONFIG_WPS */
+                                   (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
+       } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
+               /* Format: "Manage.assoc_req <frame len>" | zero padding |
+                * frame */
+               int len = atoi(custom + 17);
+               if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
+                       wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
+                                  "assoc_req/auth event length %d", len);
+                       return;
+               }
+               atheros_raw_receive(drv, NULL,
+                                   (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
+       } else if (strncmp(custom, "Manage.action ", 14) == 0) {
+               /* Format: "Manage.assoc_req <frame len>" | zero padding |
+                * frame */
+               int len = atoi(custom + 14);
+               if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
+                       wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
+                                  "assoc_req/auth event length %d", len);
+                       return;
+               }
+               atheros_raw_receive(drv, NULL,
+                                   (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
+       } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
+               /* Format: "Manage.auth <frame len>" | zero padding | frame
+                */
+               int len = atoi(custom + 12);
+               if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
+                       wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
+                                  "assoc_req/auth event length %d", len);
+                       return;
+               }
+               atheros_raw_receive(drv, NULL,
+                                   (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
+#endif /* CONFIG_WPS or CONFIG_IEEE80211R */
+       }
+}
+
+/*
+* Handle size of data problem. WEXT only allows data of 256 bytes for custom
+* events, and p2p data can be much bigger. So the athr driver sends a small
+* event telling me to collect the big data with an ioctl.
+* On the first event, send all pending events to supplicant.
+*/
+static void fetch_pending_big_events(struct atheros_driver_data *drv)
+{
+       union wpa_event_data event;
+       const struct ieee80211_mgmt *mgmt;
+       u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
+       u16 fc, stype;
+       struct iwreq iwr;
+       size_t data_len;
+       u32 freq, frame_type;
+
+       while (1) {
+               os_memset(&iwr, 0, sizeof(iwr));
+               os_strncpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+
+               iwr.u.data.pointer = (void *) tbuf;
+               iwr.u.data.length = sizeof(tbuf);
+               iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
+
+               if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
+                   < 0) {
+                       if (errno == ENOSPC) {
+                               wpa_printf(MSG_DEBUG, "%s:%d exit",
+                                          __func__, __LINE__);
+                               return;
+                       }
+                       wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
+                                  "P2P_FETCH_FRAME] failed: %s",
+                                  __func__, strerror(errno));
+                       return;
+               }
+               data_len = iwr.u.data.length;
+               wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
+                           (u8 *) tbuf, data_len);
+               if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
+                       wpa_printf(MSG_DEBUG, "athr: frame too short");
+                       continue;
+               }
+               os_memcpy(&freq, tbuf, sizeof(freq));
+               os_memcpy(&frame_type, &tbuf[sizeof(freq)],
+                         sizeof(frame_type));
+               mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
+               data_len -= sizeof(freq) + sizeof(frame_type);
+
+               if (frame_type == IEEE80211_EV_RX_MGMT) {
+                       fc = le_to_host16(mgmt->frame_control);
+                       stype = WLAN_FC_GET_STYPE(fc);
+
+                       wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
+                               "freq=%u len=%u", stype, freq, (int) data_len);
+
+                       if (stype == WLAN_FC_STYPE_ACTION) {
+                               os_memset(&event, 0, sizeof(event));
+                               event.rx_mgmt.frame = (const u8 *) mgmt;
+                               event.rx_mgmt.frame_len = data_len;
+                               wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
+                                                    &event);
+                               continue;
+                       }
+               } else {
+                       wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
+                                  __func__, frame_type);
+                       continue;
+               }
+       }
+}
+
+static void
+atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
+                                     int opcode, char *buf, int len)
+{
+       switch (opcode) {
+       case IEEE80211_EV_RX_MGMT:
+               wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
+               fetch_pending_big_events(drv);
+               break;
+       default:
+               break;
        }
 }
 
@@ -1055,8 +1457,15 @@ atheros_wireless_event_wireless(struct atheros_driver_data *drv,
                                return;         /* XXX */
                        memcpy(buf, custom, iwe->u.data.length);
                        buf[iwe->u.data.length] = '\0';
-                       atheros_wireless_event_wireless_custom(
-                               drv, buf, buf + iwe->u.data.length);
+
+                       if (iwe->u.data.flags != 0) {
+                               atheros_wireless_event_atheros_custom(
+                                       drv, (int) iwe->u.data.flags,
+                                       buf, len);
+                       } else {
+                               atheros_wireless_event_wireless_custom(
+                                       drv, buf, buf + iwe->u.data.length);
+                       }
                        free(buf);
                        break;
                }
@@ -1245,6 +1654,7 @@ atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
                goto bad;
        if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
                goto bad;
+       os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
        if (params->bridge[0]) {
                wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
                           params->bridge[0]);
@@ -1278,13 +1688,17 @@ atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
        linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
        atheros_set_privacy(drv, 0); /* default to no privacy */
 
-       atheros_receive_probe_req(drv);
+       if (atheros_receive_pkt(drv))
+               goto bad;
 
        if (atheros_wireless_event_init(drv))
                goto bad;
 
        return drv;
 bad:
+       atheros_reset_appfilter(drv);
+       if (drv->sock_raw)
+               l2_packet_deinit(drv->sock_raw);
        if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
                l2_packet_deinit(drv->sock_recv);
        if (drv->sock_xmit != NULL)
@@ -1302,6 +1716,7 @@ atheros_deinit(void *priv)
 {
        struct atheros_driver_data *drv = priv;
 
+       atheros_reset_appfilter(drv);
        netlink_deinit(drv->netlink);
        (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
        if (drv->ioctl_sock >= 0)
@@ -1348,7 +1763,6 @@ atheros_get_ssid(void *priv, u8 *buf, int len)
        memset(&iwr, 0, sizeof(iwr));
        os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
        iwr.u.essid.pointer = (caddr_t) buf;
-       iwr.u.essid.length = len;
        iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
                IW_ESSID_MAX_SIZE : len;
 
@@ -1421,6 +1835,290 @@ static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
        return 0;
 }
 
+
+#ifdef CONFIG_IEEE80211R
+
+static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
+                            int noack)
+{
+       struct atheros_driver_data *drv = priv;
+       u8 buf[1510];
+       const struct ieee80211_mgmt *mgmt;
+       struct ieee80211req_mgmtbuf *mgmt_frm;
+
+       mgmt = (const struct ieee80211_mgmt *) frm;
+       wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
+                  (unsigned long) data_len, MAC2STR(mgmt->da));
+       mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
+       memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
+       mgmt_frm->buflen = data_len;
+       if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
+               wpa_printf(MSG_INFO, "atheros: Too long frame for "
+                          "atheros_send_mgmt (%u)", (unsigned int) data_len);
+               return -1;
+       }
+       os_memcpy(&mgmt_frm->buf[0], frm, data_len);
+       return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
+                           sizeof(struct ieee80211req_mgmtbuf) + data_len);
+}
+
+
+static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
+                            size_t tspec_ielen)
+{
+       struct atheros_driver_data *drv = priv;
+       int retv;
+       struct ieee80211req_res req;
+       struct ieee80211req_res_addts *addts = &req.u.addts;
+
+       wpa_printf(MSG_DEBUG, "%s", __func__);
+       req.type = IEEE80211_RESREQ_ADDTS;
+       os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
+       os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
+       retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
+                           sizeof(struct ieee80211req_res));
+       if (retv < 0) {
+               wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
+                          "retv = %d", __func__, retv);
+               return -1;
+       }
+       os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
+       return addts->status;
+}
+
+
+static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
+{
+       struct atheros_driver_data *drv = priv;
+       struct ieee80211req_res req;
+       struct ieee80211req_res_addnode *addnode = &req.u.addnode;
+
+       wpa_printf(MSG_DEBUG, "%s", __func__);
+       req.type = IEEE80211_RESREQ_ADDNODE;
+       os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
+       addnode->auth_alg = auth_alg;
+       return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
+                           sizeof(struct ieee80211req_res));
+}
+
+#endif /* CONFIG_IEEE80211R */
+
+
+/* Use only to set a big param, get will not work. */
+static int
+set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
+{
+       struct iwreq iwr;
+
+       os_memset(&iwr, 0, sizeof(iwr));
+       os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
+
+       iwr.u.data.pointer = (void *) data;
+       iwr.u.data.length = len;
+       iwr.u.data.flags = op;
+       wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
+                  __func__, op, op, athr_get_param_name(op), len);
+
+       if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
+               wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
+                          "value=0x%x,0x%x failed: %d (%s)",
+                          __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
+                          iwr.u.mode, iwr.u.data.length,
+                          iwr.u.data.flags, errno, strerror(errno));
+               return -1;
+       }
+       return 0;
+}
+
+
+static int atheros_send_action(void *priv, unsigned int freq,
+                              unsigned int wait,
+                              const u8 *dst, const u8 *src,
+                              const u8 *bssid,
+                              const u8 *data, size_t data_len, int no_cck)
+{
+       struct atheros_driver_data *drv = priv;
+       struct ieee80211_p2p_send_action *act;
+       int res;
+
+       act = os_zalloc(sizeof(*act) + data_len);
+       if (act == NULL)
+               return -1;
+       act->freq = freq;
+       os_memcpy(act->dst_addr, dst, ETH_ALEN);
+       os_memcpy(act->src_addr, src, ETH_ALEN);
+       os_memcpy(act->bssid, bssid, ETH_ALEN);
+       os_memcpy(act + 1, data, data_len);
+       wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
+                  MACSTR ", bssid=" MACSTR,
+                  __func__, act->freq, wait, MAC2STR(act->dst_addr),
+                  MAC2STR(act->src_addr), MAC2STR(act->bssid));
+       wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
+       wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
+
+       res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
+                         act, sizeof(*act) + data_len);
+       os_free(act);
+       return res;
+}
+
+
+#ifdef CONFIG_WNM
+static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
+                       u8 *ie, u16 *len, enum wnm_oper oper)
+{
+#define IEEE80211_APPIE_MAX    1024 /* max appie buffer size */
+       u8 buf[IEEE80211_APPIE_MAX];
+       struct ieee80211req_getset_appiebuf *tfs_ie;
+       u16 val;
+
+       wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
+                  drv->iface, oper, MAC2STR(peer));
+
+       switch (oper) {
+       case WNM_SLEEP_TFS_REQ_IE_SET:
+               if (*len > IEEE80211_APPIE_MAX -
+                   sizeof(struct ieee80211req_getset_appiebuf)) {
+                       wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
+                       return -1;
+               }
+               tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
+               tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
+               tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
+
+               /* Command header for driver */
+               os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
+               val = oper;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
+               val = *len;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
+
+               /* copy the ie */
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
+
+               if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
+                                IEEE80211_APPIE_MAX)) {
+                       wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
+                                  "%s", __func__, strerror(errno));
+                       return -1;
+               }
+               break;
+       case WNM_SLEEP_TFS_RESP_IE_ADD:
+               tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
+               tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
+               tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
+                       sizeof(struct ieee80211req_getset_appiebuf);
+               /* Command header for driver */
+               os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
+               val = oper;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
+               val = 0;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
+
+               if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
+                                IEEE80211_APPIE_MAX)) {
+                       wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
+                                  "%s", __func__, strerror(errno));
+                       return -1;
+               }
+
+               *len = tfs_ie->app_buflen;
+               os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
+               wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
+                          *len);
+               break;
+       case WNM_SLEEP_TFS_RESP_IE_NONE:
+               *len = 0;
+               break;
+       case WNM_SLEEP_TFS_IE_DEL:
+               tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
+               tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
+               tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
+                       sizeof(struct ieee80211req_getset_appiebuf);
+               /* Command header for driver */
+               os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
+               val = oper;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
+               val = 0;
+               os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
+
+               if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
+                                IEEE80211_APPIE_MAX)) {
+                       wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
+                                  "%s", __func__, strerror(errno));
+                       return -1;
+               }
+               break;
+       default:
+               wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
+               break;
+       }
+
+       return 0;
+}
+
+
+static int atheros_wnm_sleep(struct atheros_driver_data *drv,
+                            const u8 *peer, enum wnm_oper oper)
+{
+       u8 *data, *pos;
+       size_t dlen;
+       int ret;
+       u16 val;
+
+       wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
+                  oper, MAC2STR(peer));
+
+       dlen = ETH_ALEN + 2 + 2;
+       data = os_malloc(dlen);
+       if (data == NULL)
+               return -1;
+
+       /* Command header for driver */
+       pos = data;
+       os_memcpy(pos, peer, ETH_ALEN);
+       pos += ETH_ALEN;
+
+       val = oper;
+       os_memcpy(pos, &val, 2);
+       pos += 2;
+
+       val = 0;
+       os_memcpy(pos, &val, 2);
+
+       ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
+
+       os_free(data);
+
+       return ret;
+}
+
+
+static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
+                           u8 *buf, u16 *buf_len)
+{
+       struct atheros_driver_data *drv = priv;
+
+       switch (oper) {
+       case WNM_SLEEP_ENTER_CONFIRM:
+       case WNM_SLEEP_ENTER_FAIL:
+       case WNM_SLEEP_EXIT_CONFIRM:
+       case WNM_SLEEP_EXIT_FAIL:
+               return atheros_wnm_sleep(drv, peer, oper);
+       case WNM_SLEEP_TFS_REQ_IE_SET:
+       case WNM_SLEEP_TFS_RESP_IE_ADD:
+       case WNM_SLEEP_TFS_RESP_IE_NONE:
+       case WNM_SLEEP_TFS_IE_DEL:
+               return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
+       default:
+               wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
+                          oper);
+               return -1;
+       }
+}
+#endif /* CONFIG_WNM */
+
+
 const struct wpa_driver_ops wpa_driver_atheros_ops = {
        .name                   = "atheros",
        .hapd_init              = atheros_init,
@@ -1444,4 +2142,15 @@ const struct wpa_driver_ops wpa_driver_atheros_ops = {
        .set_ap_wps_ie          = atheros_set_ap_wps_ie,
        .set_authmode           = atheros_set_authmode,
        .set_ap                 = atheros_set_ap,
+#ifdef CONFIG_IEEE80211R
+       .sta_assoc              = atheros_sta_assoc,
+       .sta_auth               = atheros_sta_auth,
+       .send_mlme              = atheros_send_mgmt,
+       .add_tspec              = atheros_add_tspec,
+       .add_sta_node           = atheros_add_sta_node,
+#endif /* CONFIG_IEEE80211R */
+       .send_action            = atheros_send_action,
+#ifdef CONFIG_WNM
+       .wnm_oper               = atheros_wnm_oper,
+#endif /* CONFIG_WNM */
 };