2 * hostapd / Driver interaction with Atheros driver
3 * Copyright (c) 2004, Sam Leffler <sam@errno.com>
4 * Copyright (c) 2004, Video54 Technologies
5 * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
6 * Copyright (c) 2009, Atheros Communications
8 * This software may be distributed under the terms of the BSD license.
9 * See README for more details.
14 #include <sys/ioctl.h>
18 #include "common/ieee802_11_defs.h"
19 #include "l2_packet/l2_packet.h"
24 #ifdef WORDS_BIGENDIAN
25 #define _BYTE_ORDER _BIG_ENDIAN
27 #define _BYTE_ORDER _LITTLE_ENDIAN
29 #endif /* _BYTE_ORDER */
32 * Note, the ATH_WPS_IE setting must match with the driver build.. If the
33 * driver does not include this, the IEEE80211_IOCTL_GETWPAIE ioctl will fail.
37 #include "ieee80211_external.h"
41 #include <netpacket/packet.h>
42 #endif /* CONFIG_WPS */
44 #ifndef ETH_P_80211_RAW
45 #define ETH_P_80211_RAW 0x0019
48 #include "linux_wext.h"
52 #include "priv_netlink.h"
53 #include "l2_packet/l2_packet.h"
54 #include "common/ieee802_11_defs.h"
56 #include "linux_ioctl.h"
59 struct atheros_driver_data {
60 struct hostapd_data *hapd; /* back pointer */
62 char iface[IFNAMSIZ + 1];
64 struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
65 struct l2_packet_data *sock_recv; /* raw packet recv socket */
66 int ioctl_sock; /* socket for ioctl() use */
67 struct netlink_data *netlink;
69 u8 acct_mac[ETH_ALEN];
70 struct hostap_sta_driver_data acct_data;
72 struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
73 struct wpabuf *wpa_ie;
74 struct wpabuf *wps_beacon_ie;
75 struct wpabuf *wps_probe_resp_ie;
76 u8 own_addr[ETH_ALEN];
79 static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
81 static int atheros_set_privacy(void *priv, int enabled);
83 static const char * athr_get_ioctl_name(int op)
86 case IEEE80211_IOCTL_SETPARAM:
88 case IEEE80211_IOCTL_GETPARAM:
90 case IEEE80211_IOCTL_SETKEY:
92 case IEEE80211_IOCTL_SETWMMPARAMS:
93 return "SETWMMPARAMS";
94 case IEEE80211_IOCTL_DELKEY:
96 case IEEE80211_IOCTL_GETWMMPARAMS:
97 return "GETWMMPARAMS";
98 case IEEE80211_IOCTL_SETMLME:
100 case IEEE80211_IOCTL_GETCHANINFO:
101 return "GETCHANINFO";
102 case IEEE80211_IOCTL_SETOPTIE:
104 case IEEE80211_IOCTL_GETOPTIE:
106 case IEEE80211_IOCTL_ADDMAC:
108 case IEEE80211_IOCTL_DELMAC:
110 case IEEE80211_IOCTL_GETCHANLIST:
111 return "GETCHANLIST";
112 case IEEE80211_IOCTL_SETCHANLIST:
113 return "SETCHANLIST";
114 case IEEE80211_IOCTL_KICKMAC:
116 case IEEE80211_IOCTL_CHANSWITCH:
118 case IEEE80211_IOCTL_GETMODE:
120 case IEEE80211_IOCTL_SETMODE:
122 case IEEE80211_IOCTL_GET_APPIEBUF:
123 return "GET_APPIEBUF";
124 case IEEE80211_IOCTL_SET_APPIEBUF:
125 return "SET_APPIEBUF";
126 case IEEE80211_IOCTL_SET_ACPARAMS:
127 return "SET_ACPARAMS";
128 case IEEE80211_IOCTL_FILTERFRAME:
129 return "FILTERFRAME";
130 case IEEE80211_IOCTL_SET_RTPARAMS:
131 return "SET_RTPARAMS";
132 case IEEE80211_IOCTL_SET_MEDENYENTRY:
133 return "SET_MEDENYENTRY";
134 case IEEE80211_IOCTL_GET_MACADDR:
135 return "GET_MACADDR";
136 case IEEE80211_IOCTL_SET_HBRPARAMS:
137 return "SET_HBRPARAMS";
138 case IEEE80211_IOCTL_SET_RXTIMEOUT:
139 return "SET_RXTIMEOUT";
140 case IEEE80211_IOCTL_STA_STATS:
142 case IEEE80211_IOCTL_GETWPAIE:
150 static const char * athr_get_param_name(int op)
153 case IEEE80211_IOC_MCASTCIPHER:
154 return "MCASTCIPHER";
155 case IEEE80211_PARAM_MCASTKEYLEN:
156 return "MCASTKEYLEN";
157 case IEEE80211_PARAM_UCASTCIPHERS:
158 return "UCASTCIPHERS";
159 case IEEE80211_PARAM_KEYMGTALGS:
161 case IEEE80211_PARAM_RSNCAPS:
163 case IEEE80211_PARAM_WPA:
165 case IEEE80211_PARAM_AUTHMODE:
167 case IEEE80211_PARAM_PRIVACY:
169 case IEEE80211_PARAM_COUNTERMEASURES:
170 return "COUNTERMEASURES";
178 set80211priv(struct atheros_driver_data *drv, int op, void *data, int len)
181 int do_inline = len < IFNAMSIZ;
183 /* Certain ioctls must use the non-inlined method */
184 if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
185 op == IEEE80211_IOCTL_FILTERFRAME)
188 memset(&iwr, 0, sizeof(iwr));
189 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
192 * Argument data fits inline; put it there.
194 memcpy(iwr.u.name, data, len);
197 * Argument data too big for inline transfer; setup a
198 * parameter block instead; the kernel will transfer
199 * the data for the driver.
201 iwr.u.data.pointer = data;
202 iwr.u.data.length = len;
205 if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
206 wpa_printf(MSG_DEBUG, "atheros: %s: %s: ioctl op=0x%x "
207 "(%s) len=%d failed: %d (%s)",
208 __func__, drv->iface, op,
209 athr_get_ioctl_name(op),
210 len, errno, strerror(errno));
217 set80211param(struct atheros_driver_data *drv, int op, int arg)
221 memset(&iwr, 0, sizeof(iwr));
222 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
224 memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
226 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
227 perror("ioctl[IEEE80211_IOCTL_SETPARAM]");
228 wpa_printf(MSG_DEBUG, "%s: %s: Failed to set parameter (op %d "
229 "(%s) arg %d)", __func__, drv->iface, op,
230 athr_get_param_name(op), arg);
236 #ifndef CONFIG_NO_STDOUT_DEBUG
238 ether_sprintf(const u8 *addr)
240 static char buf[sizeof(MACSTR)];
243 snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
245 snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
248 #endif /* CONFIG_NO_STDOUT_DEBUG */
251 * Configure WPA parameters.
254 atheros_configure_wpa(struct atheros_driver_data *drv,
255 struct wpa_bss_params *params)
259 switch (params->wpa_group) {
260 case WPA_CIPHER_CCMP:
261 v = IEEE80211_CIPHER_AES_CCM;
263 case WPA_CIPHER_TKIP:
264 v = IEEE80211_CIPHER_TKIP;
266 case WPA_CIPHER_WEP104:
267 v = IEEE80211_CIPHER_WEP;
269 case WPA_CIPHER_WEP40:
270 v = IEEE80211_CIPHER_WEP;
272 case WPA_CIPHER_NONE:
273 v = IEEE80211_CIPHER_NONE;
276 wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
280 wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
281 if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
282 printf("Unable to set group key cipher to %u\n", v);
285 if (v == IEEE80211_CIPHER_WEP) {
286 /* key length is done only for specific ciphers */
287 v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
288 if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
289 printf("Unable to set group key length to %u\n", v);
295 if (params->wpa_pairwise & WPA_CIPHER_CCMP)
296 v |= 1<<IEEE80211_CIPHER_AES_CCM;
297 if (params->wpa_pairwise & WPA_CIPHER_TKIP)
298 v |= 1<<IEEE80211_CIPHER_TKIP;
299 if (params->wpa_pairwise & WPA_CIPHER_NONE)
300 v |= 1<<IEEE80211_CIPHER_NONE;
301 wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
302 if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
303 printf("Unable to set pairwise key ciphers to 0x%x\n", v);
307 wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
308 __func__, params->wpa_key_mgmt);
309 if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS,
310 params->wpa_key_mgmt)) {
311 printf("Unable to set key management algorithms to 0x%x\n",
312 params->wpa_key_mgmt);
317 if (params->rsn_preauth)
319 #ifdef CONFIG_IEEE80211W
320 if (params->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
322 if (params->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
325 #endif /* CONFIG_IEEE80211W */
327 wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
328 if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
329 printf("Unable to set RSN capabilities to 0x%x\n", v);
333 wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, params->wpa);
334 if (set80211param(drv, IEEE80211_PARAM_WPA, params->wpa)) {
335 printf("Unable to set WPA to %u\n", params->wpa);
342 atheros_set_ieee8021x(void *priv, struct wpa_bss_params *params)
344 struct atheros_driver_data *drv = priv;
346 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
348 if (!params->enabled) {
349 /* XXX restore state */
350 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
351 IEEE80211_AUTH_AUTO) < 0)
353 /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
354 return atheros_set_privacy(drv, 0);
356 if (!params->wpa && !params->ieee802_1x) {
357 hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
358 HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
361 if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
362 hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
363 HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
366 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
367 (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
368 hostapd_logger(drv->hapd, NULL, HOSTAPD_MODULE_DRIVER,
369 HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
377 atheros_set_privacy(void *priv, int enabled)
379 struct atheros_driver_data *drv = priv;
381 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
383 return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
387 atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
389 struct atheros_driver_data *drv = priv;
390 struct ieee80211req_mlme mlme;
393 wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
394 __func__, ether_sprintf(addr), authorized);
397 mlme.im_op = IEEE80211_MLME_AUTHORIZE;
399 mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
401 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
402 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
404 wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
405 __func__, authorized ? "" : "un", MAC2STR(addr));
412 atheros_sta_set_flags(void *priv, const u8 *addr,
413 int total_flags, int flags_or, int flags_and)
415 /* For now, only support setting Authorized flag */
416 if (flags_or & WPA_STA_AUTHORIZED)
417 return atheros_set_sta_authorized(priv, addr, 1);
418 if (!(flags_and & WPA_STA_AUTHORIZED))
419 return atheros_set_sta_authorized(priv, addr, 0);
424 atheros_del_key(void *priv, const u8 *addr, int key_idx)
426 struct atheros_driver_data *drv = priv;
427 struct ieee80211req_del_key wk;
430 wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
431 __func__, ether_sprintf(addr), key_idx);
433 memset(&wk, 0, sizeof(wk));
435 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
436 wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
438 wk.idk_keyix = key_idx;
441 ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
443 wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
444 " key_idx %d)", __func__, ether_sprintf(addr),
452 atheros_set_key(const char *ifname, void *priv, enum wpa_alg alg,
453 const u8 *addr, int key_idx, int set_tx, const u8 *seq,
454 size_t seq_len, const u8 *key, size_t key_len)
456 struct atheros_driver_data *drv = priv;
457 struct ieee80211req_key wk;
461 if (alg == WPA_ALG_NONE)
462 return atheros_del_key(drv, addr, key_idx);
464 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
465 __func__, alg, ether_sprintf(addr), key_idx);
469 cipher = IEEE80211_CIPHER_WEP;
472 cipher = IEEE80211_CIPHER_TKIP;
475 cipher = IEEE80211_CIPHER_AES_CCM;
477 #ifdef CONFIG_IEEE80211W
479 cipher = IEEE80211_CIPHER_AES_CMAC;
481 #endif /* CONFIG_IEEE80211W */
483 printf("%s: unknown/unsupported algorithm %d\n",
488 if (key_len > sizeof(wk.ik_keydata)) {
489 printf("%s: key length %lu too big\n", __func__,
490 (unsigned long) key_len);
494 memset(&wk, 0, sizeof(wk));
496 wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
497 if (addr == NULL || is_broadcast_ether_addr(addr)) {
498 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
499 wk.ik_keyix = key_idx;
501 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
503 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
504 wk.ik_keyix = IEEE80211_KEYIX_NONE;
506 wk.ik_keylen = key_len;
507 memcpy(wk.ik_keydata, key, key_len);
509 ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
511 wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
512 " key_idx %d alg %d key_len %lu set_tx %d)",
513 __func__, ether_sprintf(wk.ik_macaddr), key_idx,
514 alg, (unsigned long) key_len, set_tx);
522 atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
525 struct atheros_driver_data *drv = priv;
526 struct ieee80211req_key wk;
528 wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
529 __func__, ether_sprintf(addr), idx);
531 memset(&wk, 0, sizeof(wk));
533 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
535 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
538 if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
539 wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
540 "(addr " MACSTR " key_idx %d)",
541 __func__, MAC2STR(wk.ik_macaddr), idx);
545 #ifdef WORDS_BIGENDIAN
548 * wk.ik_keytsc is in host byte order (big endian), need to
549 * swap it to match with the byte order used in WPA.
552 #ifndef WPA_KEY_RSC_LEN
553 #define WPA_KEY_RSC_LEN 8
555 u8 tmp[WPA_KEY_RSC_LEN];
556 memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
557 for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
558 seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
561 #else /* WORDS_BIGENDIAN */
562 memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
563 #endif /* WORDS_BIGENDIAN */
569 atheros_flush(void *priv)
571 u8 allsta[IEEE80211_ADDR_LEN];
572 memset(allsta, 0xff, IEEE80211_ADDR_LEN);
573 return atheros_sta_deauth(priv, NULL, allsta,
574 IEEE80211_REASON_AUTH_LEAVE);
579 atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
582 struct atheros_driver_data *drv = priv;
583 struct ieee80211req_sta_stats stats;
585 memset(data, 0, sizeof(*data));
588 * Fetch statistics for station from the system.
590 memset(&stats, 0, sizeof(stats));
591 memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
592 if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
593 &stats, sizeof(stats))) {
594 wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
595 MACSTR ")", __func__, MAC2STR(addr));
596 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
597 memcpy(data, &drv->acct_data, sizeof(*data));
601 printf("Failed to get station stats information element.\n");
605 data->rx_packets = stats.is_stats.ns_rx_data;
606 data->rx_bytes = stats.is_stats.ns_rx_bytes;
607 data->tx_packets = stats.is_stats.ns_tx_data;
608 data->tx_bytes = stats.is_stats.ns_tx_bytes;
614 atheros_sta_clear_stats(void *priv, const u8 *addr)
616 struct atheros_driver_data *drv = priv;
617 struct ieee80211req_mlme mlme;
620 wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
622 mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
623 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
624 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
627 wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
628 MACSTR ")", __func__, MAC2STR(addr));
636 atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
638 struct atheros_driver_data *drv = priv;
640 struct ieee80211req_getset_appiebuf *app_ie;
642 wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
643 (unsigned long) ie_len);
644 wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
646 wpabuf_free(drv->wpa_ie);
647 drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
649 app_ie = (struct ieee80211req_getset_appiebuf *) buf;
650 os_memcpy(&(app_ie->app_buf[0]), ie, ie_len);
651 app_ie->app_buflen = ie_len;
653 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
655 /* append WPS IE for Beacon */
656 if (drv->wps_beacon_ie != NULL) {
657 os_memcpy(&(app_ie->app_buf[ie_len]),
658 wpabuf_head(drv->wps_beacon_ie),
659 wpabuf_len(drv->wps_beacon_ie));
660 app_ie->app_buflen = ie_len + wpabuf_len(drv->wps_beacon_ie);
662 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
663 app_ie->app_buf, app_ie->app_buflen);
664 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
665 sizeof(struct ieee80211req_getset_appiebuf) +
668 /* append WPS IE for Probe Response */
669 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;
670 if (drv->wps_probe_resp_ie != NULL) {
671 os_memcpy(&(app_ie->app_buf[ie_len]),
672 wpabuf_head(drv->wps_probe_resp_ie),
673 wpabuf_len(drv->wps_probe_resp_ie));
674 app_ie->app_buflen = ie_len +
675 wpabuf_len(drv->wps_probe_resp_ie);
677 app_ie->app_buflen = ie_len;
678 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
679 app_ie->app_buf, app_ie->app_buflen);
680 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
681 sizeof(struct ieee80211req_getset_appiebuf) +
687 atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
690 struct atheros_driver_data *drv = priv;
691 struct ieee80211req_mlme mlme;
694 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
695 __func__, ether_sprintf(addr), reason_code);
697 mlme.im_op = IEEE80211_MLME_DEAUTH;
698 mlme.im_reason = reason_code;
699 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
700 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
702 wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
704 __func__, MAC2STR(addr), reason_code);
711 atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
714 struct atheros_driver_data *drv = priv;
715 struct ieee80211req_mlme mlme;
718 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
719 __func__, ether_sprintf(addr), reason_code);
721 mlme.im_op = IEEE80211_MLME_DISASSOC;
722 mlme.im_reason = reason_code;
723 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
724 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
726 wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
727 MACSTR " reason %d)",
728 __func__, MAC2STR(addr), reason_code);
735 static void atheros_raw_recv_wps(void *ctx, const u8 *src_addr, const u8 *buf,
738 struct atheros_driver_data *drv = ctx;
739 const struct ieee80211_mgmt *mgmt;
741 union wpa_event_data event;
743 /* Send Probe Request information to WPS processing */
745 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
747 mgmt = (const struct ieee80211_mgmt *) buf;
749 fc = le_to_host16(mgmt->frame_control);
750 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
751 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_PROBE_REQ)
754 os_memset(&event, 0, sizeof(event));
755 event.rx_probe_req.sa = mgmt->sa;
756 event.rx_probe_req.da = mgmt->da;
757 event.rx_probe_req.bssid = mgmt->bssid;
758 event.rx_probe_req.ie = mgmt->u.probe_req.variable;
759 event.rx_probe_req.ie_len =
760 len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
761 wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
763 #endif /* CONFIG_WPS */
765 #ifdef CONFIG_IEEE80211R
766 static void atheros_raw_recv_11r(void *ctx, const u8 *src_addr, const u8 *buf,
769 struct atheros_driver_data *drv = ctx;
770 union wpa_event_data event;
771 const struct ieee80211_mgmt *mgmt;
777 /* Do 11R processing for ASSOC/AUTH/FT ACTION frames */
778 if (len < IEEE80211_HDRLEN)
780 mgmt = (const struct ieee80211_mgmt *) buf;
782 fc = le_to_host16(mgmt->frame_control);
784 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
786 stype = WLAN_FC_GET_STYPE(fc);
788 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
791 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
792 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
797 case WLAN_FC_STYPE_ASSOC_REQ:
798 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.assoc_req))
800 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
801 iebuf = mgmt->u.assoc_req.variable;
802 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 0);
804 case WLAN_FC_STYPE_REASSOC_REQ:
805 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.reassoc_req))
807 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
808 iebuf = mgmt->u.reassoc_req.variable;
809 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 1);
811 case WLAN_FC_STYPE_ACTION:
812 if (&mgmt->u.action.category > buf + len)
814 os_memset(&event, 0, sizeof(event));
815 event.rx_action.da = mgmt->da;
816 event.rx_action.sa = mgmt->sa;
817 event.rx_action.bssid = mgmt->bssid;
818 event.rx_action.category = mgmt->u.action.category;
819 event.rx_action.data = &mgmt->u.action.category;
820 event.rx_action.len = buf + len - event.rx_action.data;
821 wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
823 case WLAN_FC_STYPE_AUTH:
824 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.auth))
826 os_memset(&event, 0, sizeof(event));
827 os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
828 os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
829 event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
830 event.auth.status_code =
831 le_to_host16(mgmt->u.auth.status_code);
832 event.auth.auth_transaction =
833 le_to_host16(mgmt->u.auth.auth_transaction);
834 event.auth.ies = mgmt->u.auth.variable;
835 event.auth.ies_len = len - IEEE80211_HDRLEN -
836 sizeof(mgmt->u.auth);
837 wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
843 #endif /* CONFIG_IEEE80211R */
846 static void atheros_raw_recv_hs20(void *ctx, const u8 *src_addr, const u8 *buf,
849 struct atheros_driver_data *drv = ctx;
850 const struct ieee80211_mgmt *mgmt;
852 union wpa_event_data event;
854 /* Send the Action frame for HS20 processing */
856 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.action.category) +
857 sizeof(mgmt->u.action.u.public_action))
860 mgmt = (const struct ieee80211_mgmt *) buf;
862 fc = le_to_host16(mgmt->frame_control);
863 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
864 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION ||
865 mgmt->u.action.category != WLAN_ACTION_PUBLIC)
868 wpa_printf(MSG_DEBUG, "%s:Received Public Action frame", __func__);
870 os_memset(&event, 0, sizeof(event));
871 event.rx_mgmt.frame = (const u8 *) mgmt;
872 event.rx_mgmt.frame_len = len;
873 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
875 #endif /* CONFIG_HS20 */
877 #if defined(CONFIG_IEEE80211V) && !defined(CONFIG_IEEE80211R)
878 static void atheros_raw_recv_11v(void *ctx, const u8 *src_addr, const u8 *buf,
881 struct atheros_driver_data *drv = ctx;
882 union wpa_event_data event;
883 const struct ieee80211_mgmt *mgmt;
887 /* Do 11R processing for WNM ACTION frames */
888 if (len < IEEE80211_HDRLEN)
890 mgmt = (const struct ieee80211_mgmt *) buf;
892 fc = le_to_host16(mgmt->frame_control);
894 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
896 stype = WLAN_FC_GET_STYPE(fc);
898 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
901 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
902 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
908 case WLAN_FC_STYPE_ACTION:
909 if (&mgmt->u.action.category > buf + len)
911 os_memset(&event, 0, sizeof(event));
912 event.rx_action.da = mgmt->da;
913 event.rx_action.sa = mgmt->sa;
914 event.rx_action.bssid = mgmt->bssid;
915 event.rx_action.category = mgmt->u.action.category;
916 event.rx_action.data = &mgmt->u.action.category;
917 event.rx_action.len = buf + len - event.rx_action.data;
918 wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
924 #endif /* CONFIG_IEEE80211V */
926 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211V)
927 static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
931 atheros_raw_recv_wps(ctx, src_addr, buf, len);
932 #endif /* CONFIG_WPS */
933 #ifdef CONFIG_IEEE80211R
934 atheros_raw_recv_11r(ctx, src_addr, buf, len);
935 #endif /* CONFIG_IEEE80211R */
936 #if defined(CONFIG_IEEE80211V) && !defined(CONFIG_IEEE80211R)
937 atheros_raw_recv_11v(ctx, src_addr, buf, len);
938 #endif /* CONFIG_IEEE80211V */
940 atheros_raw_recv_hs20(ctx, src_addr, buf, len);
941 #endif /* CONFIG_HS20 */
943 #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
945 static int atheros_receive_pkt(struct atheros_driver_data *drv)
948 struct ieee80211req_set_filter filt;
950 wpa_printf(MSG_DEBUG, "%s Enter", __func__);
951 filt.app_filterype = 0;
953 filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
954 #endif /* CONFIG_WPS */
955 #ifdef CONFIG_IEEE80211R
956 filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
957 IEEE80211_FILTER_TYPE_AUTH |
958 IEEE80211_FILTER_TYPE_ACTION);
960 #ifdef CONFIG_IEEE80211V
961 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
962 #endif /* CONFIG_IEEE80211V */
964 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
965 #endif /* CONFIG_HS20 */
966 if (filt.app_filterype) {
967 ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
968 sizeof(struct ieee80211req_set_filter));
973 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
974 drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
975 atheros_raw_receive, drv, 1);
976 if (drv->sock_raw == NULL)
978 #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
979 if (l2_packet_get_own_addr(drv->sock_xmit, drv->own_addr))
984 static int atheros_reset_appfilter(struct atheros_driver_data *drv)
986 struct ieee80211req_set_filter filt;
987 filt.app_filterype = 0;
988 return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
989 sizeof(struct ieee80211req_set_filter));
994 atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
996 struct atheros_driver_data *drv = priv;
998 struct ieee80211req_getset_appiebuf *beac_ie;
1000 wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
1001 (unsigned long) len, frametype);
1002 wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
1004 beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
1005 beac_ie->app_frmtype = frametype;
1006 beac_ie->app_buflen = len;
1007 os_memcpy(&(beac_ie->app_buf[0]), ie, len);
1009 /* append the WPA/RSN IE if it is set already */
1010 if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
1011 (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
1012 (drv->wpa_ie != NULL)) {
1013 wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
1015 os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
1016 wpabuf_len(drv->wpa_ie));
1017 beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
1020 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
1021 beac_ie->app_buf, beac_ie->app_buflen);
1022 return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
1023 sizeof(struct ieee80211req_getset_appiebuf) +
1024 beac_ie->app_buflen);
1028 atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1029 const struct wpabuf *proberesp,
1030 const struct wpabuf *assocresp)
1032 struct atheros_driver_data *drv = priv;
1034 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1035 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1037 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1039 wpabuf_free(drv->wps_beacon_ie);
1040 drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1041 wpabuf_free(drv->wps_probe_resp_ie);
1042 drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1044 atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1045 assocresp ? wpabuf_len(assocresp) : 0,
1046 IEEE80211_APPIE_FRAME_ASSOC_RESP);
1047 if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1048 beacon ? wpabuf_len(beacon) : 0,
1049 IEEE80211_APPIE_FRAME_BEACON))
1051 return atheros_set_wps_ie(priv,
1052 proberesp ? wpabuf_head(proberesp) : NULL,
1053 proberesp ? wpabuf_len(proberesp): 0,
1054 IEEE80211_APPIE_FRAME_PROBE_RESP);
1056 #else /* CONFIG_WPS */
1057 #define atheros_set_ap_wps_ie NULL
1058 #endif /* CONFIG_WPS */
1060 #ifdef CONFIG_IEEE80211R
1062 atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
1063 u16 status_code, const u8 *ie, size_t len)
1065 struct atheros_driver_data *drv = priv;
1066 struct ieee80211req_mlme mlme;
1069 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1070 __func__, ether_sprintf(addr), status_code);
1072 mlme.im_op = IEEE80211_MLME_AUTH;
1073 mlme.im_reason = status_code;
1075 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1076 mlme.im_optie_len = len;
1078 if (len < IEEE80211_MAX_OPT_IE) {
1079 os_memcpy(mlme.im_optie, ie, len);
1081 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1082 "opt_ie STA (addr " MACSTR " reason %d, "
1084 __func__, MAC2STR(addr), status_code,
1089 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1091 wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1093 __func__, MAC2STR(addr), status_code);
1099 atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1100 int reassoc, u16 status_code, const u8 *ie, size_t len)
1102 struct atheros_driver_data *drv = priv;
1103 struct ieee80211req_mlme mlme;
1106 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1107 __func__, ether_sprintf(addr), status_code, reassoc);
1110 mlme.im_op = IEEE80211_MLME_REASSOC;
1112 mlme.im_op = IEEE80211_MLME_ASSOC;
1113 mlme.im_reason = status_code;
1114 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1115 mlme.im_optie_len = len;
1117 if (len < IEEE80211_MAX_OPT_IE) {
1118 os_memcpy(mlme.im_optie, ie, len);
1120 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1121 "opt_ie STA (addr " MACSTR " reason %d, "
1123 __func__, MAC2STR(addr), status_code,
1128 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1130 wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1132 __func__, MAC2STR(addr), status_code);
1136 #endif /* CONFIG_IEEE80211R */
1139 atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1141 struct hostapd_data *hapd = drv->hapd;
1142 struct ieee80211req_wpaie ie;
1147 * Fetch negotiated WPA/RSN parameters from the system.
1149 memset(&ie, 0, sizeof(ie));
1150 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1151 if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1153 * See ATH_WPS_IE comment in the beginning of the file for a
1154 * possible cause for the failure..
1156 wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1157 __func__, strerror(errno));
1160 wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1161 ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1162 wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1163 ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1165 wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1166 ie.wps_ie, IEEE80211_MAX_OPT_IE);
1167 #endif /* ATH_WPS_IE */
1169 /* atheros seems to return some random data if WPA/RSN IE is not set.
1170 * Assume the IE was not included if the IE type is unknown. */
1171 if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1173 if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1174 /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1175 * set. This is needed for WPA2. */
1177 if (iebuf[0] != WLAN_EID_RSN)
1184 /* if WPS IE is present, preference is given to WPS */
1186 (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
1188 ielen = ie.wps_ie[1];
1190 #endif /* ATH_WPS_IE */
1198 drv_event_assoc(hapd, addr, iebuf, ielen, 0);
1200 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
1201 /* Cached accounting data is not valid anymore. */
1202 memset(drv->acct_mac, 0, ETH_ALEN);
1203 memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1208 atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1209 char *custom, char *end)
1211 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1213 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1216 pos = strstr(custom, "addr=");
1218 wpa_printf(MSG_DEBUG,
1219 "MLME-MICHAELMICFAILURE.indication "
1220 "without sender address ignored");
1224 if (hwaddr_aton(pos, addr) == 0) {
1225 union wpa_event_data data;
1226 os_memset(&data, 0, sizeof(data));
1227 data.michael_mic_failure.unicast = 1;
1228 data.michael_mic_failure.src = addr;
1229 wpa_supplicant_event(drv->hapd,
1230 EVENT_MICHAEL_MIC_FAILURE, &data);
1232 wpa_printf(MSG_DEBUG,
1233 "MLME-MICHAELMICFAILURE.indication "
1234 "with invalid MAC address");
1236 } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1240 while ((key = strchr(key, '\n')) != NULL) {
1242 value = strchr(key, '=');
1246 val = strtoul(value, NULL, 10);
1247 if (strcmp(key, "mac") == 0)
1248 hwaddr_aton(value, drv->acct_mac);
1249 else if (strcmp(key, "rx_packets") == 0)
1250 drv->acct_data.rx_packets = val;
1251 else if (strcmp(key, "tx_packets") == 0)
1252 drv->acct_data.tx_packets = val;
1253 else if (strcmp(key, "rx_bytes") == 0)
1254 drv->acct_data.rx_bytes = val;
1255 else if (strcmp(key, "tx_bytes") == 0)
1256 drv->acct_data.tx_bytes = val;
1260 } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1261 /* Some atheros kernels send push button as a wireless event */
1262 /* PROBLEM! this event is received for ALL BSSs ...
1263 * so all are enabled for WPS... ugh.
1265 wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
1266 #endif /* CONFIG_WPS */
1267 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
1268 #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
1269 } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
1271 * Atheros driver uses a hack to pass Probe Request frames as a
1272 * binary data in the custom wireless event. The old way (using
1273 * packet sniffing) didn't work when bridging.
1274 * Format: "Manage.prob_req <frame len>" | zero padding | frame
1276 int len = atoi(custom + 16);
1277 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1278 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1282 atheros_raw_receive(drv, NULL,
1283 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1284 } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1285 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1287 int len = atoi(custom + 17);
1288 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1289 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1290 "assoc_req/auth event length %d", len);
1293 atheros_raw_receive(drv, NULL,
1294 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1295 } else if (strncmp(custom, "Manage.action ", 14) == 0) {
1296 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1298 int len = atoi(custom + 14);
1299 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1300 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1301 "assoc_req/auth event length %d", len);
1304 atheros_raw_receive(drv, NULL,
1305 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1306 } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
1307 /* Format: "Manage.auth <frame len>" | zero padding | frame
1309 int len = atoi(custom + 12);
1310 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1311 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1312 "assoc_req/auth event length %d", len);
1315 atheros_raw_receive(drv, NULL,
1316 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1317 #endif /* CONFIG_WPS or CONFIG_IEEE80211R */
1322 * Handle size of data problem. WEXT only allows data of 256 bytes for custom
1323 * events, and p2p data can be much bigger. So the athr driver sends a small
1324 * event telling me to collect the big data with an ioctl.
1325 * On the first event, send all pending events to supplicant.
1327 static void fetch_pending_big_events(struct atheros_driver_data *drv)
1329 union wpa_event_data event;
1330 const struct ieee80211_mgmt *mgmt;
1331 u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1335 u32 freq, frame_type;
1338 os_memset(&iwr, 0, sizeof(iwr));
1339 os_strncpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1341 iwr.u.data.pointer = (void *) tbuf;
1342 iwr.u.data.length = sizeof(tbuf);
1343 iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1345 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1347 if (errno == ENOSPC) {
1348 wpa_printf(MSG_DEBUG, "%s:%d exit",
1349 __func__, __LINE__);
1352 wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1353 "P2P_FETCH_FRAME] failed: %s",
1354 __func__, strerror(errno));
1357 data_len = iwr.u.data.length;
1358 wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1359 (u8 *) tbuf, data_len);
1360 if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1361 wpa_printf(MSG_DEBUG, "athr: frame too short");
1364 os_memcpy(&freq, tbuf, sizeof(freq));
1365 os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1366 sizeof(frame_type));
1367 mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1368 data_len -= sizeof(freq) + sizeof(frame_type);
1370 if (frame_type == IEEE80211_EV_RX_MGMT) {
1371 fc = le_to_host16(mgmt->frame_control);
1372 stype = WLAN_FC_GET_STYPE(fc);
1374 wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1375 "freq=%u len=%u", stype, freq, (int) data_len);
1377 if (stype == WLAN_FC_STYPE_ACTION) {
1378 os_memset(&event, 0, sizeof(event));
1379 event.rx_mgmt.frame = (const u8 *) mgmt;
1380 event.rx_mgmt.frame_len = data_len;
1381 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1386 wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1387 __func__, frame_type);
1394 atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1395 int opcode, char *buf, int len)
1398 case IEEE80211_EV_RX_MGMT:
1399 wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1400 fetch_pending_big_events(drv);
1408 atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1409 char *data, int len)
1411 struct iw_event iwe_buf, *iwe = &iwe_buf;
1412 char *pos, *end, *custom, *buf;
1417 while (pos + IW_EV_LCP_LEN <= end) {
1418 /* Event data may be unaligned, so make a local, aligned copy
1419 * before processing. */
1420 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1421 wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1422 iwe->cmd, iwe->len);
1423 if (iwe->len <= IW_EV_LCP_LEN)
1426 custom = pos + IW_EV_POINT_LEN;
1427 if (drv->we_version > 18 &&
1428 (iwe->cmd == IWEVMICHAELMICFAILURE ||
1429 iwe->cmd == IWEVASSOCREQIE ||
1430 iwe->cmd == IWEVCUSTOM)) {
1431 /* WE-19 removed the pointer from struct iw_point */
1432 char *dpos = (char *) &iwe_buf.u.data.length;
1433 int dlen = dpos - (char *) &iwe_buf;
1434 memcpy(dpos, pos + IW_EV_LCP_LEN,
1435 sizeof(struct iw_event) - dlen);
1437 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1438 custom += IW_EV_POINT_OFF;
1443 drv_event_disassoc(drv->hapd,
1444 (u8 *) iwe->u.addr.sa_data);
1446 case IWEVREGISTERED:
1447 atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1449 case IWEVASSOCREQIE:
1450 /* Driver hack.. Use IWEVASSOCREQIE to bypass
1451 * IWEVCUSTOM size limitations. Need to handle this
1452 * just like IWEVCUSTOM.
1455 if (custom + iwe->u.data.length > end)
1457 buf = malloc(iwe->u.data.length + 1);
1460 memcpy(buf, custom, iwe->u.data.length);
1461 buf[iwe->u.data.length] = '\0';
1463 if (iwe->u.data.flags != 0) {
1464 atheros_wireless_event_atheros_custom(
1465 drv, (int) iwe->u.data.flags,
1468 atheros_wireless_event_wireless_custom(
1469 drv, buf, buf + iwe->u.data.length);
1481 atheros_wireless_event_rtm_newlink(void *ctx,
1482 struct ifinfomsg *ifi, u8 *buf, size_t len)
1484 struct atheros_driver_data *drv = ctx;
1485 int attrlen, rta_len;
1486 struct rtattr *attr;
1488 if (ifi->ifi_index != drv->ifindex)
1492 attr = (struct rtattr *) buf;
1494 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1495 while (RTA_OK(attr, attrlen)) {
1496 if (attr->rta_type == IFLA_WIRELESS) {
1497 atheros_wireless_event_wireless(
1498 drv, ((char *) attr) + rta_len,
1499 attr->rta_len - rta_len);
1501 attr = RTA_NEXT(attr, attrlen);
1507 atheros_get_we_version(struct atheros_driver_data *drv)
1509 struct iw_range *range;
1514 drv->we_version = 0;
1517 * Use larger buffer than struct iw_range in order to allow the
1518 * structure to grow in the future.
1520 buflen = sizeof(struct iw_range) + 500;
1521 range = os_zalloc(buflen);
1525 memset(&iwr, 0, sizeof(iwr));
1526 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1527 iwr.u.data.pointer = (caddr_t) range;
1528 iwr.u.data.length = buflen;
1530 minlen = ((char *) &range->enc_capa) - (char *) range +
1531 sizeof(range->enc_capa);
1533 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1534 perror("ioctl[SIOCGIWRANGE]");
1537 } else if (iwr.u.data.length >= minlen &&
1538 range->we_version_compiled >= 18) {
1539 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1540 "WE(source)=%d enc_capa=0x%x",
1541 range->we_version_compiled,
1542 range->we_version_source,
1544 drv->we_version = range->we_version_compiled;
1553 atheros_wireless_event_init(struct atheros_driver_data *drv)
1555 struct netlink_config *cfg;
1557 atheros_get_we_version(drv);
1559 cfg = os_zalloc(sizeof(*cfg));
1563 cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1564 drv->netlink = netlink_init(cfg);
1565 if (drv->netlink == NULL) {
1575 atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1576 int encrypt, const u8 *own_addr, u32 flags)
1578 struct atheros_driver_data *drv = priv;
1579 unsigned char buf[3000];
1580 unsigned char *bp = buf;
1581 struct l2_ethhdr *eth;
1586 * Prepend the Ethernet header. If the caller left us
1587 * space at the front we could just insert it but since
1588 * we don't know we copy to a local buffer. Given the frequency
1589 * and size of frames this probably doesn't matter.
1591 len = data_len + sizeof(struct l2_ethhdr);
1592 if (len > sizeof(buf)) {
1595 printf("EAPOL frame discarded, cannot malloc temp "
1596 "buffer of size %lu!\n", (unsigned long) len);
1600 eth = (struct l2_ethhdr *) bp;
1601 memcpy(eth->h_dest, addr, ETH_ALEN);
1602 memcpy(eth->h_source, own_addr, ETH_ALEN);
1603 eth->h_proto = host_to_be16(ETH_P_EAPOL);
1604 memcpy(eth+1, data, data_len);
1606 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1608 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1616 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1618 struct atheros_driver_data *drv = ctx;
1619 drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1620 len - sizeof(struct l2_ethhdr));
1624 atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1626 struct atheros_driver_data *drv;
1629 char brname[IFNAMSIZ];
1631 drv = os_zalloc(sizeof(struct atheros_driver_data));
1633 printf("Could not allocate memory for atheros driver data\n");
1638 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1639 if (drv->ioctl_sock < 0) {
1640 perror("socket[PF_INET,SOCK_DGRAM]");
1643 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1645 memset(&ifr, 0, sizeof(ifr));
1646 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1647 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1648 perror("ioctl(SIOCGIFINDEX)");
1651 drv->ifindex = ifr.ifr_ifindex;
1653 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1654 handle_read, drv, 1);
1655 if (drv->sock_xmit == NULL)
1657 if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1659 if (params->bridge[0]) {
1660 wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1662 drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1663 ETH_P_EAPOL, handle_read, drv,
1665 if (drv->sock_recv == NULL)
1667 } else if (linux_br_get(brname, drv->iface) == 0) {
1668 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1669 "EAPOL receive", brname);
1670 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1671 handle_read, drv, 1);
1672 if (drv->sock_recv == NULL)
1675 drv->sock_recv = drv->sock_xmit;
1677 memset(&iwr, 0, sizeof(iwr));
1678 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1680 iwr.u.mode = IW_MODE_MASTER;
1682 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1683 perror("ioctl[SIOCSIWMODE]");
1684 printf("Could not set interface to master mode!\n");
1688 /* mark down during setup */
1689 linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1690 atheros_set_privacy(drv, 0); /* default to no privacy */
1692 atheros_receive_pkt(drv);
1694 if (atheros_wireless_event_init(drv))
1699 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1700 l2_packet_deinit(drv->sock_recv);
1701 if (drv->sock_xmit != NULL)
1702 l2_packet_deinit(drv->sock_xmit);
1703 if (drv->ioctl_sock >= 0)
1704 close(drv->ioctl_sock);
1712 atheros_deinit(void *priv)
1714 struct atheros_driver_data *drv = priv;
1716 atheros_reset_appfilter(drv);
1717 netlink_deinit(drv->netlink);
1718 (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1719 if (drv->ioctl_sock >= 0)
1720 close(drv->ioctl_sock);
1721 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1722 l2_packet_deinit(drv->sock_recv);
1723 if (drv->sock_xmit != NULL)
1724 l2_packet_deinit(drv->sock_xmit);
1726 l2_packet_deinit(drv->sock_raw);
1727 wpabuf_free(drv->wpa_ie);
1728 wpabuf_free(drv->wps_beacon_ie);
1729 wpabuf_free(drv->wps_probe_resp_ie);
1734 atheros_set_ssid(void *priv, const u8 *buf, int len)
1736 struct atheros_driver_data *drv = priv;
1739 memset(&iwr, 0, sizeof(iwr));
1740 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1741 iwr.u.essid.flags = 1; /* SSID active */
1742 iwr.u.essid.pointer = (caddr_t) buf;
1743 iwr.u.essid.length = len + 1;
1745 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1746 perror("ioctl[SIOCSIWESSID]");
1747 printf("len=%d\n", len);
1754 atheros_get_ssid(void *priv, u8 *buf, int len)
1756 struct atheros_driver_data *drv = priv;
1760 memset(&iwr, 0, sizeof(iwr));
1761 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1762 iwr.u.essid.pointer = (caddr_t) buf;
1763 iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1764 IW_ESSID_MAX_SIZE : len;
1766 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1767 perror("ioctl[SIOCGIWESSID]");
1770 ret = iwr.u.essid.length;
1776 atheros_set_countermeasures(void *priv, int enabled)
1778 struct atheros_driver_data *drv = priv;
1779 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1780 return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1784 atheros_commit(void *priv)
1786 struct atheros_driver_data *drv = priv;
1787 return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1790 static int atheros_set_authmode(void *priv, int auth_algs)
1794 if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1795 (auth_algs & WPA_AUTH_ALG_SHARED))
1796 authmode = IEEE80211_AUTH_AUTO;
1797 else if (auth_algs & WPA_AUTH_ALG_OPEN)
1798 authmode = IEEE80211_AUTH_OPEN;
1799 else if (auth_algs & WPA_AUTH_ALG_SHARED)
1800 authmode = IEEE80211_AUTH_SHARED;
1804 return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1807 static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1810 * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1811 * set_generic_elem, and hapd_set_ssid.
1814 wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1815 "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1816 "wpa_version=0x%x privacy=%d interworking=%d",
1817 params->pairwise_ciphers, params->group_cipher,
1818 params->key_mgmt_suites, params->auth_algs,
1819 params->wpa_version, params->privacy, params->interworking);
1820 wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1821 params->ssid, params->ssid_len);
1823 wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1824 MAC2STR(params->hessid));
1825 wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1826 params->beacon_ies);
1827 wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1828 params->proberesp_ies);
1829 wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1830 params->assocresp_ies);
1836 #ifdef CONFIG_IEEE80211R
1838 static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1841 struct atheros_driver_data *drv = priv;
1843 const struct ieee80211_mgmt *mgmt;
1844 struct ieee80211req_mgmtbuf *mgmt_frm;
1846 mgmt = (const struct ieee80211_mgmt *) frm;
1847 wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1848 (unsigned long) data_len, MAC2STR(mgmt->da));
1849 mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1850 memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1851 mgmt_frm->buflen = data_len;
1852 if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1853 wpa_printf(MSG_INFO, "atheros: Too long frame for "
1854 "atheros_send_mgmt (%u)", (unsigned int) data_len);
1857 os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1858 return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1859 sizeof(struct ieee80211req_mgmtbuf) + data_len);
1863 static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1866 struct atheros_driver_data *drv = priv;
1868 struct ieee80211req_res req;
1869 struct ieee80211req_res_addts *addts = &req.u.addts;
1871 wpa_printf(MSG_DEBUG, "%s", __func__);
1872 req.type = IEEE80211_RESREQ_ADDTS;
1873 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1874 os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
1875 retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1876 sizeof(struct ieee80211req_res));
1878 wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
1879 "retv = %d", __func__, retv);
1882 os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
1883 return addts->status;
1887 static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
1889 struct atheros_driver_data *drv = priv;
1890 struct ieee80211req_res req;
1891 struct ieee80211req_res_addnode *addnode = &req.u.addnode;
1893 wpa_printf(MSG_DEBUG, "%s", __func__);
1894 req.type = IEEE80211_RESREQ_ADDNODE;
1895 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1896 addnode->auth_alg = auth_alg;
1897 return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1898 sizeof(struct ieee80211req_res));
1901 #endif /* CONFIG_IEEE80211R */
1904 /* Use only to set a big param, get will not work. */
1906 set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
1910 os_memset(&iwr, 0, sizeof(iwr));
1911 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1913 iwr.u.data.pointer = (void *) data;
1914 iwr.u.data.length = len;
1915 iwr.u.data.flags = op;
1916 wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
1917 __func__, op, op, athr_get_param_name(op), len);
1919 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
1920 wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
1921 "value=0x%x,0x%x failed: %d (%s)",
1922 __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
1923 iwr.u.mode, iwr.u.data.length,
1924 iwr.u.data.flags, errno, strerror(errno));
1931 static int atheros_send_action(void *priv, unsigned int freq,
1933 const u8 *dst, const u8 *src,
1935 const u8 *data, size_t data_len, int no_cck)
1937 struct atheros_driver_data *drv = priv;
1938 struct ieee80211_p2p_send_action *act;
1941 act = os_zalloc(sizeof(*act) + data_len);
1945 os_memcpy(act->dst_addr, dst, ETH_ALEN);
1946 os_memcpy(act->src_addr, src, ETH_ALEN);
1947 os_memcpy(act->bssid, bssid, ETH_ALEN);
1948 os_memcpy(act + 1, data, data_len);
1949 wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
1950 MACSTR ", bssid=" MACSTR,
1951 __func__, act->freq, wait, MAC2STR(act->dst_addr),
1952 MAC2STR(act->src_addr), MAC2STR(act->bssid));
1953 wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
1954 wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
1956 res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
1957 act, sizeof(*act) + data_len);
1963 #ifdef CONFIG_IEEE80211V
1964 static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
1965 u8 *ie, u16 *len, enum wnm_oper oper)
1967 #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
1968 u8 buf[IEEE80211_APPIE_MAX];
1969 struct ieee80211req_getset_appiebuf *tfs_ie;
1972 wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
1973 drv->iface, oper, MAC2STR(peer));
1976 case WNM_SLEEP_TFS_REQ_IE_SET:
1977 if (*len > IEEE80211_APPIE_MAX -
1978 sizeof(struct ieee80211req_getset_appiebuf)) {
1979 wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
1982 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
1983 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
1984 tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
1986 /* Command header for driver */
1987 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
1989 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
1991 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
1994 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
1996 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
1997 IEEE80211_APPIE_MAX)) {
1998 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
1999 "%s", __func__, strerror(errno));
2003 case WNM_SLEEP_TFS_RESP_IE_ADD:
2004 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2005 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2006 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2007 sizeof(struct ieee80211req_getset_appiebuf);
2008 /* Command header for driver */
2009 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2011 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2013 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2015 if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2016 IEEE80211_APPIE_MAX)) {
2017 wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2018 "%s", __func__, strerror(errno));
2022 *len = tfs_ie->app_buflen;
2023 os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2024 wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2027 case WNM_SLEEP_TFS_RESP_IE_NONE:
2030 case WNM_SLEEP_TFS_IE_DEL:
2031 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2032 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2033 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2034 sizeof(struct ieee80211req_getset_appiebuf);
2035 /* Command header for driver */
2036 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2038 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2040 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2042 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2043 IEEE80211_APPIE_MAX)) {
2044 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2045 "%s", __func__, strerror(errno));
2050 wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2058 static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2059 const u8 *peer, enum wnm_oper oper)
2066 wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2067 oper, MAC2STR(peer));
2069 dlen = ETH_ALEN + 2 + 2;
2070 data = os_malloc(dlen);
2074 /* Command header for driver */
2076 os_memcpy(pos, peer, ETH_ALEN);
2080 os_memcpy(pos, &val, 2);
2084 os_memcpy(pos, &val, 2);
2086 ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2094 static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2095 u8 *buf, u16 *buf_len)
2097 struct atheros_driver_data *drv = priv;
2100 case WNM_SLEEP_ENTER_CONFIRM:
2101 case WNM_SLEEP_ENTER_FAIL:
2102 case WNM_SLEEP_EXIT_CONFIRM:
2103 case WNM_SLEEP_EXIT_FAIL:
2104 return atheros_wnm_sleep(drv, peer, oper);
2105 case WNM_SLEEP_TFS_REQ_IE_SET:
2106 case WNM_SLEEP_TFS_RESP_IE_ADD:
2107 case WNM_SLEEP_TFS_RESP_IE_NONE:
2108 case WNM_SLEEP_TFS_IE_DEL:
2109 return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2111 wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2116 #endif /* CONFIG_IEEE80211V */
2119 const struct wpa_driver_ops wpa_driver_atheros_ops = {
2121 .hapd_init = atheros_init,
2122 .hapd_deinit = atheros_deinit,
2123 .set_ieee8021x = atheros_set_ieee8021x,
2124 .set_privacy = atheros_set_privacy,
2125 .set_key = atheros_set_key,
2126 .get_seqnum = atheros_get_seqnum,
2127 .flush = atheros_flush,
2128 .set_generic_elem = atheros_set_opt_ie,
2129 .sta_set_flags = atheros_sta_set_flags,
2130 .read_sta_data = atheros_read_sta_driver_data,
2131 .hapd_send_eapol = atheros_send_eapol,
2132 .sta_disassoc = atheros_sta_disassoc,
2133 .sta_deauth = atheros_sta_deauth,
2134 .hapd_set_ssid = atheros_set_ssid,
2135 .hapd_get_ssid = atheros_get_ssid,
2136 .set_countermeasures = atheros_set_countermeasures,
2137 .sta_clear_stats = atheros_sta_clear_stats,
2138 .commit = atheros_commit,
2139 .set_ap_wps_ie = atheros_set_ap_wps_ie,
2140 .set_authmode = atheros_set_authmode,
2141 .set_ap = atheros_set_ap,
2142 #ifdef CONFIG_IEEE80211R
2143 .sta_assoc = atheros_sta_assoc,
2144 .sta_auth = atheros_sta_auth,
2145 .send_mlme = atheros_send_mgmt,
2146 .add_tspec = atheros_add_tspec,
2147 .add_sta_node = atheros_add_sta_node,
2148 #endif /* CONFIG_IEEE80211R */
2149 .send_action = atheros_send_action,
2150 #ifdef CONFIG_IEEE80211V
2151 .wnm_oper = atheros_wnm_oper,
2152 #endif /* CONFIG_IEEE80211V */