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"
58 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20) || defined(CONFIG_WNM) || defined(CONFIG_WPS)
59 #define ATHEROS_USE_RAW_RECEIVE
63 struct atheros_driver_data {
64 struct hostapd_data *hapd; /* back pointer */
66 char iface[IFNAMSIZ + 1];
68 struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
69 struct l2_packet_data *sock_recv; /* raw packet recv socket */
70 int ioctl_sock; /* socket for ioctl() use */
71 struct netlink_data *netlink;
73 u8 acct_mac[ETH_ALEN];
74 struct hostap_sta_driver_data acct_data;
76 struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
77 struct wpabuf *wpa_ie;
78 struct wpabuf *wps_beacon_ie;
79 struct wpabuf *wps_probe_resp_ie;
80 u8 own_addr[ETH_ALEN];
83 static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
85 static int atheros_set_privacy(void *priv, int enabled);
87 static const char * athr_get_ioctl_name(int op)
90 case IEEE80211_IOCTL_SETPARAM:
92 case IEEE80211_IOCTL_GETPARAM:
94 case IEEE80211_IOCTL_SETKEY:
96 case IEEE80211_IOCTL_SETWMMPARAMS:
97 return "SETWMMPARAMS";
98 case IEEE80211_IOCTL_DELKEY:
100 case IEEE80211_IOCTL_GETWMMPARAMS:
101 return "GETWMMPARAMS";
102 case IEEE80211_IOCTL_SETMLME:
104 case IEEE80211_IOCTL_GETCHANINFO:
105 return "GETCHANINFO";
106 case IEEE80211_IOCTL_SETOPTIE:
108 case IEEE80211_IOCTL_GETOPTIE:
110 case IEEE80211_IOCTL_ADDMAC:
112 case IEEE80211_IOCTL_DELMAC:
114 case IEEE80211_IOCTL_GETCHANLIST:
115 return "GETCHANLIST";
116 case IEEE80211_IOCTL_SETCHANLIST:
117 return "SETCHANLIST";
118 case IEEE80211_IOCTL_KICKMAC:
120 case IEEE80211_IOCTL_CHANSWITCH:
122 case IEEE80211_IOCTL_GETMODE:
124 case IEEE80211_IOCTL_SETMODE:
126 case IEEE80211_IOCTL_GET_APPIEBUF:
127 return "GET_APPIEBUF";
128 case IEEE80211_IOCTL_SET_APPIEBUF:
129 return "SET_APPIEBUF";
130 case IEEE80211_IOCTL_SET_ACPARAMS:
131 return "SET_ACPARAMS";
132 case IEEE80211_IOCTL_FILTERFRAME:
133 return "FILTERFRAME";
134 case IEEE80211_IOCTL_SET_RTPARAMS:
135 return "SET_RTPARAMS";
136 case IEEE80211_IOCTL_SET_MEDENYENTRY:
137 return "SET_MEDENYENTRY";
138 case IEEE80211_IOCTL_GET_MACADDR:
139 return "GET_MACADDR";
140 case IEEE80211_IOCTL_SET_HBRPARAMS:
141 return "SET_HBRPARAMS";
142 case IEEE80211_IOCTL_SET_RXTIMEOUT:
143 return "SET_RXTIMEOUT";
144 case IEEE80211_IOCTL_STA_STATS:
146 case IEEE80211_IOCTL_GETWPAIE:
154 static const char * athr_get_param_name(int op)
157 case IEEE80211_IOC_MCASTCIPHER:
158 return "MCASTCIPHER";
159 case IEEE80211_PARAM_MCASTKEYLEN:
160 return "MCASTKEYLEN";
161 case IEEE80211_PARAM_UCASTCIPHERS:
162 return "UCASTCIPHERS";
163 case IEEE80211_PARAM_KEYMGTALGS:
165 case IEEE80211_PARAM_RSNCAPS:
167 case IEEE80211_PARAM_WPA:
169 case IEEE80211_PARAM_AUTHMODE:
171 case IEEE80211_PARAM_PRIVACY:
173 case IEEE80211_PARAM_COUNTERMEASURES:
174 return "COUNTERMEASURES";
182 set80211priv(struct atheros_driver_data *drv, int op, void *data, int len)
185 int do_inline = len < IFNAMSIZ;
187 /* Certain ioctls must use the non-inlined method */
188 if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
189 op == IEEE80211_IOCTL_FILTERFRAME)
192 memset(&iwr, 0, sizeof(iwr));
193 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
196 * Argument data fits inline; put it there.
198 memcpy(iwr.u.name, data, len);
201 * Argument data too big for inline transfer; setup a
202 * parameter block instead; the kernel will transfer
203 * the data for the driver.
205 iwr.u.data.pointer = data;
206 iwr.u.data.length = len;
209 if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
210 wpa_printf(MSG_DEBUG, "atheros: %s: %s: ioctl op=0x%x "
211 "(%s) len=%d failed: %d (%s)",
212 __func__, drv->iface, op,
213 athr_get_ioctl_name(op),
214 len, errno, strerror(errno));
221 set80211param(struct atheros_driver_data *drv, int op, int arg)
225 memset(&iwr, 0, sizeof(iwr));
226 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
228 memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
230 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
232 "%s: %s: Failed to set parameter (op %d (%s) arg %d): ioctl[IEEE80211_IOCTL_SETPARAM]: %s",
233 __func__, drv->iface, op, athr_get_param_name(op),
234 arg, strerror(errno));
240 #ifndef CONFIG_NO_STDOUT_DEBUG
242 ether_sprintf(const u8 *addr)
244 static char buf[sizeof(MACSTR)];
247 snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
249 snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
252 #endif /* CONFIG_NO_STDOUT_DEBUG */
255 * Configure WPA parameters.
258 atheros_configure_wpa(struct atheros_driver_data *drv,
259 struct wpa_bss_params *params)
263 switch (params->wpa_group) {
264 case WPA_CIPHER_CCMP:
265 v = IEEE80211_CIPHER_AES_CCM;
267 #ifdef ATH_GCM_SUPPORT
268 case WPA_CIPHER_CCMP_256:
269 v = IEEE80211_CIPHER_AES_CCM_256;
271 case WPA_CIPHER_GCMP:
272 v = IEEE80211_CIPHER_AES_GCM;
274 case WPA_CIPHER_GCMP_256:
275 v = IEEE80211_CIPHER_AES_GCM_256;
277 #endif /* ATH_GCM_SUPPORT */
278 case WPA_CIPHER_TKIP:
279 v = IEEE80211_CIPHER_TKIP;
281 case WPA_CIPHER_WEP104:
282 v = IEEE80211_CIPHER_WEP;
284 case WPA_CIPHER_WEP40:
285 v = IEEE80211_CIPHER_WEP;
287 case WPA_CIPHER_NONE:
288 v = IEEE80211_CIPHER_NONE;
291 wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
295 wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
296 if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
297 wpa_printf(MSG_INFO, "Unable to set group key cipher to %u", v);
300 if (v == IEEE80211_CIPHER_WEP) {
301 /* key length is done only for specific ciphers */
302 v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
303 if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
305 "Unable to set group key length to %u", v);
311 if (params->wpa_pairwise & WPA_CIPHER_CCMP)
312 v |= 1<<IEEE80211_CIPHER_AES_CCM;
313 #ifdef ATH_GCM_SUPPORT
314 if (params->wpa_pairwise & WPA_CIPHER_CCMP_256)
315 v |= 1<<IEEE80211_CIPHER_AES_CCM_256;
316 if (params->wpa_pairwise & WPA_CIPHER_GCMP)
317 v |= 1<<IEEE80211_CIPHER_AES_GCM;
318 if (params->wpa_pairwise & WPA_CIPHER_GCMP_256)
319 v |= 1<<IEEE80211_CIPHER_AES_GCM_256;
320 #endif /* ATH_GCM_SUPPORT */
321 if (params->wpa_pairwise & WPA_CIPHER_TKIP)
322 v |= 1<<IEEE80211_CIPHER_TKIP;
323 if (params->wpa_pairwise & WPA_CIPHER_NONE)
324 v |= 1<<IEEE80211_CIPHER_NONE;
325 wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
326 if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
328 "Unable to set pairwise key ciphers to 0x%x", v);
332 wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
333 __func__, params->wpa_key_mgmt);
334 if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS,
335 params->wpa_key_mgmt)) {
337 "Unable to set key management algorithms to 0x%x",
338 params->wpa_key_mgmt);
343 if (params->rsn_preauth)
345 #ifdef CONFIG_IEEE80211W
346 if (params->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
348 if (params->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
351 #endif /* CONFIG_IEEE80211W */
353 wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
354 if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
355 wpa_printf(MSG_INFO, "Unable to set RSN capabilities to 0x%x",
360 wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, params->wpa);
361 if (set80211param(drv, IEEE80211_PARAM_WPA, params->wpa)) {
362 wpa_printf(MSG_INFO, "Unable to set WPA to %u", params->wpa);
369 atheros_set_ieee8021x(void *priv, struct wpa_bss_params *params)
371 struct atheros_driver_data *drv = priv;
373 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
375 if (!params->enabled) {
376 /* XXX restore state */
377 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
378 IEEE80211_AUTH_AUTO) < 0)
380 /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
381 return atheros_set_privacy(drv, 0);
383 if (!params->wpa && !params->ieee802_1x) {
384 wpa_printf(MSG_WARNING, "No 802.1X or WPA enabled!");
387 if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
388 wpa_printf(MSG_WARNING, "Error configuring WPA state!");
391 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
392 (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
393 wpa_printf(MSG_WARNING, "Error enabling WPA/802.1X!");
401 atheros_set_privacy(void *priv, int enabled)
403 struct atheros_driver_data *drv = priv;
405 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
407 return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
411 atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
413 struct atheros_driver_data *drv = priv;
414 struct ieee80211req_mlme mlme;
417 wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
418 __func__, ether_sprintf(addr), authorized);
421 mlme.im_op = IEEE80211_MLME_AUTHORIZE;
423 mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
425 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
426 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
428 wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
429 __func__, authorized ? "" : "un", MAC2STR(addr));
436 atheros_sta_set_flags(void *priv, const u8 *addr,
437 unsigned int total_flags, unsigned int flags_or,
438 unsigned int flags_and)
440 /* For now, only support setting Authorized flag */
441 if (flags_or & WPA_STA_AUTHORIZED)
442 return atheros_set_sta_authorized(priv, addr, 1);
443 if (!(flags_and & WPA_STA_AUTHORIZED))
444 return atheros_set_sta_authorized(priv, addr, 0);
449 atheros_del_key(void *priv, const u8 *addr, int key_idx)
451 struct atheros_driver_data *drv = priv;
452 struct ieee80211req_del_key wk;
455 wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
456 __func__, ether_sprintf(addr), key_idx);
458 memset(&wk, 0, sizeof(wk));
460 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
461 wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
463 wk.idk_keyix = key_idx;
466 ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
468 wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
469 " key_idx %d)", __func__, ether_sprintf(addr),
477 atheros_set_key(const char *ifname, void *priv, enum wpa_alg alg,
478 const u8 *addr, int key_idx, int set_tx, const u8 *seq,
479 size_t seq_len, const u8 *key, size_t key_len)
481 struct atheros_driver_data *drv = priv;
482 struct ieee80211req_key wk;
486 if (alg == WPA_ALG_NONE)
487 return atheros_del_key(drv, addr, key_idx);
489 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
490 __func__, alg, ether_sprintf(addr), key_idx);
494 cipher = IEEE80211_CIPHER_WEP;
497 cipher = IEEE80211_CIPHER_TKIP;
500 cipher = IEEE80211_CIPHER_AES_CCM;
502 #ifdef ATH_GCM_SUPPORT
503 case WPA_ALG_CCMP_256:
504 cipher = IEEE80211_CIPHER_AES_CCM_256;
507 cipher = IEEE80211_CIPHER_AES_GCM;
509 case WPA_ALG_GCMP_256:
510 cipher = IEEE80211_CIPHER_AES_GCM_256;
512 #endif /* ATH_GCM_SUPPORT */
513 #ifdef CONFIG_IEEE80211W
515 cipher = IEEE80211_CIPHER_AES_CMAC;
517 #ifdef ATH_GCM_SUPPORT
518 case WPA_ALG_BIP_CMAC_256:
519 cipher = IEEE80211_CIPHER_AES_CMAC_256;
521 case WPA_ALG_BIP_GMAC_128:
522 cipher = IEEE80211_CIPHER_AES_GMAC;
524 case WPA_ALG_BIP_GMAC_256:
525 cipher = IEEE80211_CIPHER_AES_GMAC_256;
527 #endif /* ATH_GCM_SUPPORT */
528 #endif /* CONFIG_IEEE80211W */
530 wpa_printf(MSG_INFO, "%s: unknown/unsupported algorithm %d",
535 if (key_len > sizeof(wk.ik_keydata)) {
536 wpa_printf(MSG_INFO, "%s: key length %lu too big", __func__,
537 (unsigned long) key_len);
541 memset(&wk, 0, sizeof(wk));
543 wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
544 if (addr == NULL || is_broadcast_ether_addr(addr)) {
545 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
546 wk.ik_keyix = key_idx;
548 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
550 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
551 wk.ik_keyix = IEEE80211_KEYIX_NONE;
553 wk.ik_keylen = key_len;
554 memcpy(wk.ik_keydata, key, key_len);
556 ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
558 wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
559 " key_idx %d alg %d key_len %lu set_tx %d)",
560 __func__, ether_sprintf(wk.ik_macaddr), key_idx,
561 alg, (unsigned long) key_len, set_tx);
569 atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
572 struct atheros_driver_data *drv = priv;
573 struct ieee80211req_key wk;
575 wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
576 __func__, ether_sprintf(addr), idx);
578 memset(&wk, 0, sizeof(wk));
580 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
582 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
585 if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
586 wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
587 "(addr " MACSTR " key_idx %d)",
588 __func__, MAC2STR(wk.ik_macaddr), idx);
592 #ifdef WORDS_BIGENDIAN
595 * wk.ik_keytsc is in host byte order (big endian), need to
596 * swap it to match with the byte order used in WPA.
599 #ifndef WPA_KEY_RSC_LEN
600 #define WPA_KEY_RSC_LEN 8
602 u8 tmp[WPA_KEY_RSC_LEN];
603 memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
604 for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
605 seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
608 #else /* WORDS_BIGENDIAN */
609 memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
610 #endif /* WORDS_BIGENDIAN */
616 atheros_flush(void *priv)
618 u8 allsta[IEEE80211_ADDR_LEN];
619 memset(allsta, 0xff, IEEE80211_ADDR_LEN);
620 return atheros_sta_deauth(priv, NULL, allsta,
621 IEEE80211_REASON_AUTH_LEAVE);
626 atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
629 struct atheros_driver_data *drv = priv;
630 struct ieee80211req_sta_stats stats;
632 memset(data, 0, sizeof(*data));
635 * Fetch statistics for station from the system.
637 memset(&stats, 0, sizeof(stats));
638 memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
639 if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
640 &stats, sizeof(stats))) {
641 wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
642 MACSTR ")", __func__, MAC2STR(addr));
643 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
644 memcpy(data, &drv->acct_data, sizeof(*data));
649 "Failed to get station stats information element");
653 data->rx_packets = stats.is_stats.ns_rx_data;
654 data->rx_bytes = stats.is_stats.ns_rx_bytes;
655 data->tx_packets = stats.is_stats.ns_tx_data;
656 data->tx_bytes = stats.is_stats.ns_tx_bytes;
662 atheros_sta_clear_stats(void *priv, const u8 *addr)
664 struct atheros_driver_data *drv = priv;
665 struct ieee80211req_mlme mlme;
668 wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
670 mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
671 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
672 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
675 wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
676 MACSTR ")", __func__, MAC2STR(addr));
684 atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
686 struct atheros_driver_data *drv = priv;
688 struct ieee80211req_getset_appiebuf *app_ie;
690 wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
691 (unsigned long) ie_len);
692 wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
694 wpabuf_free(drv->wpa_ie);
695 drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
697 app_ie = (struct ieee80211req_getset_appiebuf *) buf;
698 os_memcpy(&(app_ie->app_buf[0]), ie, ie_len);
699 app_ie->app_buflen = ie_len;
701 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
703 /* append WPS IE for Beacon */
704 if (drv->wps_beacon_ie != NULL) {
705 os_memcpy(&(app_ie->app_buf[ie_len]),
706 wpabuf_head(drv->wps_beacon_ie),
707 wpabuf_len(drv->wps_beacon_ie));
708 app_ie->app_buflen = ie_len + wpabuf_len(drv->wps_beacon_ie);
710 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
711 app_ie->app_buf, app_ie->app_buflen);
712 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
713 sizeof(struct ieee80211req_getset_appiebuf) +
716 /* append WPS IE for Probe Response */
717 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;
718 if (drv->wps_probe_resp_ie != NULL) {
719 os_memcpy(&(app_ie->app_buf[ie_len]),
720 wpabuf_head(drv->wps_probe_resp_ie),
721 wpabuf_len(drv->wps_probe_resp_ie));
722 app_ie->app_buflen = ie_len +
723 wpabuf_len(drv->wps_probe_resp_ie);
725 app_ie->app_buflen = ie_len;
726 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
727 app_ie->app_buf, app_ie->app_buflen);
728 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
729 sizeof(struct ieee80211req_getset_appiebuf) +
735 atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
738 struct atheros_driver_data *drv = priv;
739 struct ieee80211req_mlme mlme;
742 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
743 __func__, ether_sprintf(addr), reason_code);
745 mlme.im_op = IEEE80211_MLME_DEAUTH;
746 mlme.im_reason = reason_code;
747 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
748 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
750 wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
752 __func__, MAC2STR(addr), reason_code);
759 atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
762 struct atheros_driver_data *drv = priv;
763 struct ieee80211req_mlme mlme;
766 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
767 __func__, ether_sprintf(addr), reason_code);
769 mlme.im_op = IEEE80211_MLME_DISASSOC;
770 mlme.im_reason = reason_code;
771 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
772 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
774 wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
775 MACSTR " reason %d)",
776 __func__, MAC2STR(addr), reason_code);
782 static int atheros_set_qos_map(void *ctx, const u8 *qos_map_set,
785 #ifdef CONFIG_ATHEROS_QOS_MAP
786 struct atheros_driver_data *drv = ctx;
787 struct ieee80211req_athdbg req;
788 struct ieee80211_qos_map *qos_map = &req.data.qos_map;
792 if (qos_map_set_len < 16 || qos_map_set_len > 58 ||
793 qos_map_set_len & 1) {
794 wpa_printf(MSG_ERROR, "Invalid QoS Map");
797 memset(&req, 0, sizeof(struct ieee80211req_athdbg));
798 req.cmd = IEEE80211_DBGREQ_SETQOSMAPCONF;
799 os_memset(&iwr, 0, sizeof(iwr));
800 os_strlcpy(iwr.ifr_name, drv->iface, sizeof(iwr.ifr_name));
801 iwr.u.data.pointer = (void *) &req;
802 iwr.u.data.length = sizeof(struct ieee80211req_athdbg);
806 qos_map->num_dscp_except = (qos_map_set_len - 16) / 2;
807 if (qos_map->num_dscp_except) {
808 for (i = 0; i < qos_map->num_dscp_except; i++) {
809 qos_map->dscp_exception[i].dscp = qos_map_set[i * 2];
810 qos_map->dscp_exception[i].up = qos_map_set[i * 2 + 1];
814 up_start = qos_map_set_len - 16;
815 for (i = 0; i < IEEE80211_MAX_QOS_UP_RANGE; i++) {
816 qos_map->up[i].low = qos_map_set[up_start + (i * 2)];
817 qos_map->up[i].high = qos_map_set[up_start + (i * 2) + 1];
820 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_DBGREQ, &iwr) < 0) {
821 wpa_printf(MSG_ERROR,
822 "%s: %s: Failed to set QoS Map: ioctl[IEEE80211_IOCTL_DBGREQ]: %s",
823 __func__, drv->iface, strerror(errno));
826 #endif /* CONFIG_ATHEROS_QOS_MAP */
831 #ifdef ATHEROS_USE_RAW_RECEIVE
832 static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
835 struct atheros_driver_data *drv = ctx;
836 const struct ieee80211_mgmt *mgmt;
837 union wpa_event_data event;
842 if (len < IEEE80211_HDRLEN)
845 mgmt = (const struct ieee80211_mgmt *) buf;
847 fc = le_to_host16(mgmt->frame_control);
849 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
852 stype = WLAN_FC_GET_STYPE(fc);
854 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
857 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
858 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
861 os_memset(&event, 0, sizeof(event));
862 event.rx_probe_req.sa = mgmt->sa;
863 event.rx_probe_req.da = mgmt->da;
864 event.rx_probe_req.bssid = mgmt->bssid;
865 event.rx_probe_req.ie = mgmt->u.probe_req.variable;
866 event.rx_probe_req.ie_len =
867 len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
868 wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
872 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
873 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
879 case WLAN_FC_STYPE_ASSOC_REQ:
880 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req))
882 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
883 iebuf = mgmt->u.assoc_req.variable;
884 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 0);
886 case WLAN_FC_STYPE_REASSOC_REQ:
887 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req))
889 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
890 iebuf = mgmt->u.reassoc_req.variable;
891 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 1);
893 case WLAN_FC_STYPE_ACTION:
894 os_memset(&event, 0, sizeof(event));
895 event.rx_mgmt.frame = buf;
896 event.rx_mgmt.frame_len = len;
897 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
899 case WLAN_FC_STYPE_AUTH:
900 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth))
902 os_memset(&event, 0, sizeof(event));
903 os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
904 os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
905 event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
906 event.auth.status_code =
907 le_to_host16(mgmt->u.auth.status_code);
908 event.auth.auth_transaction =
909 le_to_host16(mgmt->u.auth.auth_transaction);
910 event.auth.ies = mgmt->u.auth.variable;
911 event.auth.ies_len = len - IEEE80211_HDRLEN -
912 sizeof(mgmt->u.auth);
913 wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
919 #endif /* ATHEROS_USE_RAW_RECEIVE */
921 static int atheros_receive_pkt(struct atheros_driver_data *drv)
924 struct ieee80211req_set_filter filt;
926 wpa_printf(MSG_DEBUG, "%s Enter", __func__);
927 filt.app_filterype = 0;
929 filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
930 #endif /* CONFIG_WPS */
931 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_IEEE80211R)
932 filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
933 IEEE80211_FILTER_TYPE_AUTH |
934 IEEE80211_FILTER_TYPE_ACTION);
935 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
937 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
938 #endif /* CONFIG_WNM */
940 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
941 #endif /* CONFIG_HS20 */
942 if (filt.app_filterype) {
943 ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
944 sizeof(struct ieee80211req_set_filter));
949 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
950 drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
951 atheros_raw_receive, drv, 1);
952 if (drv->sock_raw == NULL)
954 #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
958 static int atheros_reset_appfilter(struct atheros_driver_data *drv)
960 struct ieee80211req_set_filter filt;
961 filt.app_filterype = 0;
962 return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
963 sizeof(struct ieee80211req_set_filter));
968 atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
970 struct atheros_driver_data *drv = priv;
972 struct ieee80211req_getset_appiebuf *beac_ie;
974 wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
975 (unsigned long) len, frametype);
976 wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
978 beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
979 beac_ie->app_frmtype = frametype;
980 beac_ie->app_buflen = len;
981 os_memcpy(&(beac_ie->app_buf[0]), ie, len);
983 /* append the WPA/RSN IE if it is set already */
984 if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
985 (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
986 (drv->wpa_ie != NULL)) {
987 wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
989 os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
990 wpabuf_len(drv->wpa_ie));
991 beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
994 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
995 beac_ie->app_buf, beac_ie->app_buflen);
996 return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
997 sizeof(struct ieee80211req_getset_appiebuf) +
998 beac_ie->app_buflen);
1002 atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1003 const struct wpabuf *proberesp,
1004 const struct wpabuf *assocresp)
1006 struct atheros_driver_data *drv = priv;
1008 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1009 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1011 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1013 wpabuf_free(drv->wps_beacon_ie);
1014 drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1015 wpabuf_free(drv->wps_probe_resp_ie);
1016 drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1018 atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1019 assocresp ? wpabuf_len(assocresp) : 0,
1020 IEEE80211_APPIE_FRAME_ASSOC_RESP);
1021 if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1022 beacon ? wpabuf_len(beacon) : 0,
1023 IEEE80211_APPIE_FRAME_BEACON))
1025 return atheros_set_wps_ie(priv,
1026 proberesp ? wpabuf_head(proberesp) : NULL,
1027 proberesp ? wpabuf_len(proberesp): 0,
1028 IEEE80211_APPIE_FRAME_PROBE_RESP);
1030 #else /* CONFIG_WPS */
1031 #define atheros_set_ap_wps_ie NULL
1032 #endif /* CONFIG_WPS */
1034 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
1036 atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
1037 u16 status_code, const u8 *ie, size_t len)
1039 struct atheros_driver_data *drv = priv;
1040 struct ieee80211req_mlme mlme;
1043 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1044 __func__, ether_sprintf(addr), status_code);
1046 mlme.im_op = IEEE80211_MLME_AUTH;
1047 mlme.im_reason = status_code;
1049 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1050 mlme.im_optie_len = len;
1052 if (len < IEEE80211_MAX_OPT_IE) {
1053 os_memcpy(mlme.im_optie, ie, len);
1055 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1056 "opt_ie STA (addr " MACSTR " reason %d, "
1058 __func__, MAC2STR(addr), status_code,
1063 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1065 wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1067 __func__, MAC2STR(addr), status_code);
1073 atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1074 int reassoc, u16 status_code, const u8 *ie, size_t len)
1076 struct atheros_driver_data *drv = priv;
1077 struct ieee80211req_mlme mlme;
1080 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1081 __func__, ether_sprintf(addr), status_code, reassoc);
1084 mlme.im_op = IEEE80211_MLME_REASSOC;
1086 mlme.im_op = IEEE80211_MLME_ASSOC;
1087 mlme.im_reason = status_code;
1088 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1089 mlme.im_optie_len = len;
1091 if (len < IEEE80211_MAX_OPT_IE) {
1092 os_memcpy(mlme.im_optie, ie, len);
1094 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1095 "opt_ie STA (addr " MACSTR " reason %d, "
1097 __func__, MAC2STR(addr), status_code,
1102 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1104 wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1106 __func__, MAC2STR(addr), status_code);
1110 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
1113 atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1115 struct hostapd_data *hapd = drv->hapd;
1116 struct ieee80211req_wpaie ie;
1121 * Fetch negotiated WPA/RSN parameters from the system.
1123 memset(&ie, 0, sizeof(ie));
1124 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1125 if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1127 * See ATH_WPS_IE comment in the beginning of the file for a
1128 * possible cause for the failure..
1130 wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1131 __func__, strerror(errno));
1134 wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1135 ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1136 wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1137 ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1139 wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1140 ie.wps_ie, IEEE80211_MAX_OPT_IE);
1141 #endif /* ATH_WPS_IE */
1143 /* atheros seems to return some random data if WPA/RSN IE is not set.
1144 * Assume the IE was not included if the IE type is unknown. */
1145 if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1147 if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1148 /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1149 * set. This is needed for WPA2. */
1151 if (iebuf[0] != WLAN_EID_RSN)
1158 /* if WPS IE is present, preference is given to WPS */
1160 (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
1162 ielen = ie.wps_ie[1];
1164 #endif /* ATH_WPS_IE */
1172 drv_event_assoc(hapd, addr, iebuf, ielen, 0);
1174 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
1175 /* Cached accounting data is not valid anymore. */
1176 memset(drv->acct_mac, 0, ETH_ALEN);
1177 memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1182 atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1183 char *custom, char *end)
1185 #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
1186 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1188 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1191 pos = strstr(custom, "addr=");
1193 wpa_printf(MSG_DEBUG,
1194 "MLME-MICHAELMICFAILURE.indication "
1195 "without sender address ignored");
1199 if (hwaddr_aton(pos, addr) == 0) {
1200 union wpa_event_data data;
1201 os_memset(&data, 0, sizeof(data));
1202 data.michael_mic_failure.unicast = 1;
1203 data.michael_mic_failure.src = addr;
1204 wpa_supplicant_event(drv->hapd,
1205 EVENT_MICHAEL_MIC_FAILURE, &data);
1207 wpa_printf(MSG_DEBUG,
1208 "MLME-MICHAELMICFAILURE.indication "
1209 "with invalid MAC address");
1211 } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1215 while ((key = strchr(key, '\n')) != NULL) {
1217 value = strchr(key, '=');
1221 val = strtoul(value, NULL, 10);
1222 if (strcmp(key, "mac") == 0)
1223 hwaddr_aton(value, drv->acct_mac);
1224 else if (strcmp(key, "rx_packets") == 0)
1225 drv->acct_data.rx_packets = val;
1226 else if (strcmp(key, "tx_packets") == 0)
1227 drv->acct_data.tx_packets = val;
1228 else if (strcmp(key, "rx_bytes") == 0)
1229 drv->acct_data.rx_bytes = val;
1230 else if (strcmp(key, "tx_bytes") == 0)
1231 drv->acct_data.tx_bytes = val;
1235 } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1236 /* Some atheros kernels send push button as a wireless event */
1237 /* PROBLEM! this event is received for ALL BSSs ...
1238 * so all are enabled for WPS... ugh.
1240 wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
1241 } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
1243 * Atheros driver uses a hack to pass Probe Request frames as a
1244 * binary data in the custom wireless event. The old way (using
1245 * packet sniffing) didn't work when bridging.
1246 * Format: "Manage.prob_req <frame len>" | zero padding | frame
1248 int len = atoi(custom + 16);
1249 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1250 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1254 atheros_raw_receive(drv, NULL,
1255 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1256 #endif /* CONFIG_WPS */
1257 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
1258 } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1259 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1261 int len = atoi(custom + 17);
1262 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1263 wpa_printf(MSG_DEBUG,
1264 "Invalid Manage.assoc_req event length %d",
1268 atheros_raw_receive(drv, NULL,
1269 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1270 } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
1271 /* Format: "Manage.auth <frame len>" | zero padding | frame */
1272 int len = atoi(custom + 12);
1274 custom + MGMT_FRAM_TAG_SIZE + len > end) {
1275 wpa_printf(MSG_DEBUG,
1276 "Invalid Manage.auth event length %d", len);
1279 atheros_raw_receive(drv, NULL,
1280 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1281 #endif /* CONFIG_IEEE80211W || CONFIG_IEEE80211R */
1282 #ifdef ATHEROS_USE_RAW_RECEIVE
1283 } else if (strncmp(custom, "Manage.action ", 14) == 0) {
1284 /* Format: "Manage.assoc_req <frame len>" | zero padding | frame
1286 int len = atoi(custom + 14);
1287 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1288 wpa_printf(MSG_DEBUG,
1289 "Invalid Manage.action event length %d",
1293 atheros_raw_receive(drv, NULL,
1294 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1295 #endif /* ATHEROS_USE_RAW_RECEIVE */
1300 * Handle size of data problem. WEXT only allows data of 256 bytes for custom
1301 * events, and p2p data can be much bigger. So the athr driver sends a small
1302 * event telling me to collect the big data with an ioctl.
1303 * On the first event, send all pending events to supplicant.
1305 static void fetch_pending_big_events(struct atheros_driver_data *drv)
1307 union wpa_event_data event;
1308 const struct ieee80211_mgmt *mgmt;
1309 u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1313 u32 freq, frame_type;
1316 os_memset(&iwr, 0, sizeof(iwr));
1317 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1319 iwr.u.data.pointer = (void *) tbuf;
1320 iwr.u.data.length = sizeof(tbuf);
1321 iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1323 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1325 if (errno == ENOSPC) {
1326 wpa_printf(MSG_DEBUG, "%s:%d exit",
1327 __func__, __LINE__);
1330 wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1331 "P2P_FETCH_FRAME] failed: %s",
1332 __func__, strerror(errno));
1335 data_len = iwr.u.data.length;
1336 wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1337 (u8 *) tbuf, data_len);
1338 if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1339 wpa_printf(MSG_DEBUG, "athr: frame too short");
1342 os_memcpy(&freq, tbuf, sizeof(freq));
1343 os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1344 sizeof(frame_type));
1345 mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1346 data_len -= sizeof(freq) + sizeof(frame_type);
1348 if (frame_type == IEEE80211_EV_RX_MGMT) {
1349 fc = le_to_host16(mgmt->frame_control);
1350 stype = WLAN_FC_GET_STYPE(fc);
1352 wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1353 "freq=%u len=%u", stype, freq, (int) data_len);
1355 if (stype == WLAN_FC_STYPE_ACTION) {
1356 os_memset(&event, 0, sizeof(event));
1357 event.rx_mgmt.frame = (const u8 *) mgmt;
1358 event.rx_mgmt.frame_len = data_len;
1359 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1364 wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1365 __func__, frame_type);
1372 atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1373 int opcode, char *buf, int len)
1376 case IEEE80211_EV_RX_MGMT:
1377 wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1378 fetch_pending_big_events(drv);
1386 atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1387 char *data, int len)
1389 struct iw_event iwe_buf, *iwe = &iwe_buf;
1390 char *pos, *end, *custom, *buf;
1395 while (pos + IW_EV_LCP_LEN <= end) {
1396 /* Event data may be unaligned, so make a local, aligned copy
1397 * before processing. */
1398 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1399 wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1400 iwe->cmd, iwe->len);
1401 if (iwe->len <= IW_EV_LCP_LEN)
1404 custom = pos + IW_EV_POINT_LEN;
1405 if (drv->we_version > 18 &&
1406 (iwe->cmd == IWEVMICHAELMICFAILURE ||
1407 iwe->cmd == IWEVASSOCREQIE ||
1408 iwe->cmd == IWEVCUSTOM)) {
1409 /* WE-19 removed the pointer from struct iw_point */
1410 char *dpos = (char *) &iwe_buf.u.data.length;
1411 int dlen = dpos - (char *) &iwe_buf;
1412 memcpy(dpos, pos + IW_EV_LCP_LEN,
1413 sizeof(struct iw_event) - dlen);
1415 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1416 custom += IW_EV_POINT_OFF;
1421 drv_event_disassoc(drv->hapd,
1422 (u8 *) iwe->u.addr.sa_data);
1424 case IWEVREGISTERED:
1425 atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1427 case IWEVASSOCREQIE:
1428 /* Driver hack.. Use IWEVASSOCREQIE to bypass
1429 * IWEVCUSTOM size limitations. Need to handle this
1430 * just like IWEVCUSTOM.
1433 if (custom + iwe->u.data.length > end)
1435 buf = malloc(iwe->u.data.length + 1);
1438 memcpy(buf, custom, iwe->u.data.length);
1439 buf[iwe->u.data.length] = '\0';
1441 if (iwe->u.data.flags != 0) {
1442 atheros_wireless_event_atheros_custom(
1443 drv, (int) iwe->u.data.flags,
1446 atheros_wireless_event_wireless_custom(
1447 drv, buf, buf + iwe->u.data.length);
1459 atheros_wireless_event_rtm_newlink(void *ctx,
1460 struct ifinfomsg *ifi, u8 *buf, size_t len)
1462 struct atheros_driver_data *drv = ctx;
1463 int attrlen, rta_len;
1464 struct rtattr *attr;
1466 if (ifi->ifi_index != drv->ifindex)
1470 attr = (struct rtattr *) buf;
1472 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1473 while (RTA_OK(attr, attrlen)) {
1474 if (attr->rta_type == IFLA_WIRELESS) {
1475 atheros_wireless_event_wireless(
1476 drv, ((char *) attr) + rta_len,
1477 attr->rta_len - rta_len);
1479 attr = RTA_NEXT(attr, attrlen);
1485 atheros_get_we_version(struct atheros_driver_data *drv)
1487 struct iw_range *range;
1492 drv->we_version = 0;
1495 * Use larger buffer than struct iw_range in order to allow the
1496 * structure to grow in the future.
1498 buflen = sizeof(struct iw_range) + 500;
1499 range = os_zalloc(buflen);
1503 memset(&iwr, 0, sizeof(iwr));
1504 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1505 iwr.u.data.pointer = (caddr_t) range;
1506 iwr.u.data.length = buflen;
1508 minlen = ((char *) &range->enc_capa) - (char *) range +
1509 sizeof(range->enc_capa);
1511 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1512 wpa_printf(MSG_ERROR, "ioctl[SIOCGIWRANGE]: %s",
1516 } else if (iwr.u.data.length >= minlen &&
1517 range->we_version_compiled >= 18) {
1518 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1519 "WE(source)=%d enc_capa=0x%x",
1520 range->we_version_compiled,
1521 range->we_version_source,
1523 drv->we_version = range->we_version_compiled;
1532 atheros_wireless_event_init(struct atheros_driver_data *drv)
1534 struct netlink_config *cfg;
1536 atheros_get_we_version(drv);
1538 cfg = os_zalloc(sizeof(*cfg));
1542 cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1543 drv->netlink = netlink_init(cfg);
1544 if (drv->netlink == NULL) {
1554 atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1555 int encrypt, const u8 *own_addr, u32 flags)
1557 struct atheros_driver_data *drv = priv;
1558 unsigned char buf[3000];
1559 unsigned char *bp = buf;
1560 struct l2_ethhdr *eth;
1565 * Prepend the Ethernet header. If the caller left us
1566 * space at the front we could just insert it but since
1567 * we don't know we copy to a local buffer. Given the frequency
1568 * and size of frames this probably doesn't matter.
1570 len = data_len + sizeof(struct l2_ethhdr);
1571 if (len > sizeof(buf)) {
1574 wpa_printf(MSG_INFO,
1575 "EAPOL frame discarded, cannot malloc temp buffer of size %lu!",
1576 (unsigned long) len);
1580 eth = (struct l2_ethhdr *) bp;
1581 memcpy(eth->h_dest, addr, ETH_ALEN);
1582 memcpy(eth->h_source, own_addr, ETH_ALEN);
1583 eth->h_proto = host_to_be16(ETH_P_EAPOL);
1584 memcpy(eth+1, data, data_len);
1586 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1588 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1596 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1598 struct atheros_driver_data *drv = ctx;
1599 drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1600 len - sizeof(struct l2_ethhdr));
1604 atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1606 struct atheros_driver_data *drv;
1609 char brname[IFNAMSIZ];
1611 drv = os_zalloc(sizeof(struct atheros_driver_data));
1613 wpa_printf(MSG_INFO,
1614 "Could not allocate memory for atheros driver data");
1619 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1620 if (drv->ioctl_sock < 0) {
1621 wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s",
1625 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1627 memset(&ifr, 0, sizeof(ifr));
1628 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1629 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1630 wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
1634 drv->ifindex = ifr.ifr_ifindex;
1636 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1637 handle_read, drv, 1);
1638 if (drv->sock_xmit == NULL)
1640 if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1642 os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
1643 if (params->bridge[0]) {
1644 wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1646 drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1647 ETH_P_EAPOL, handle_read, drv,
1649 if (drv->sock_recv == NULL)
1651 } else if (linux_br_get(brname, drv->iface) == 0) {
1652 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1653 "EAPOL receive", brname);
1654 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1655 handle_read, drv, 1);
1656 if (drv->sock_recv == NULL)
1659 drv->sock_recv = drv->sock_xmit;
1661 memset(&iwr, 0, sizeof(iwr));
1662 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1664 iwr.u.mode = IW_MODE_MASTER;
1666 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1667 wpa_printf(MSG_ERROR,
1668 "Could not set interface to master mode! ioctl[SIOCSIWMODE]: %s",
1673 /* mark down during setup */
1674 linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1675 atheros_set_privacy(drv, 0); /* default to no privacy */
1677 if (atheros_receive_pkt(drv))
1680 if (atheros_wireless_event_init(drv))
1685 atheros_reset_appfilter(drv);
1687 l2_packet_deinit(drv->sock_raw);
1688 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1689 l2_packet_deinit(drv->sock_recv);
1690 if (drv->sock_xmit != NULL)
1691 l2_packet_deinit(drv->sock_xmit);
1692 if (drv->ioctl_sock >= 0)
1693 close(drv->ioctl_sock);
1700 atheros_deinit(void *priv)
1702 struct atheros_driver_data *drv = priv;
1704 atheros_reset_appfilter(drv);
1706 if (drv->wpa_ie || drv->wps_beacon_ie || drv->wps_probe_resp_ie) {
1707 wpabuf_free(drv->wpa_ie);
1708 wpabuf_free(drv->wps_beacon_ie);
1709 wpabuf_free(drv->wps_probe_resp_ie);
1710 atheros_set_opt_ie(priv, NULL, 0);
1712 netlink_deinit(drv->netlink);
1713 (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1714 if (drv->ioctl_sock >= 0)
1715 close(drv->ioctl_sock);
1716 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1717 l2_packet_deinit(drv->sock_recv);
1718 if (drv->sock_xmit != NULL)
1719 l2_packet_deinit(drv->sock_xmit);
1721 l2_packet_deinit(drv->sock_raw);
1726 atheros_set_ssid(void *priv, const u8 *buf, int len)
1728 struct atheros_driver_data *drv = priv;
1731 memset(&iwr, 0, sizeof(iwr));
1732 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1733 iwr.u.essid.flags = 1; /* SSID active */
1734 iwr.u.essid.pointer = (caddr_t) buf;
1735 iwr.u.essid.length = len + 1;
1737 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1738 wpa_printf(MSG_ERROR, "ioctl[SIOCSIWESSID,len=%d]: %s",
1739 len, strerror(errno));
1746 atheros_get_ssid(void *priv, u8 *buf, int len)
1748 struct atheros_driver_data *drv = priv;
1752 memset(&iwr, 0, sizeof(iwr));
1753 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1754 iwr.u.essid.pointer = (caddr_t) buf;
1755 iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1756 IW_ESSID_MAX_SIZE : len;
1758 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1759 wpa_printf(MSG_ERROR, "ioctl[SIOCGIWESSID]: %s",
1763 ret = iwr.u.essid.length;
1769 atheros_set_countermeasures(void *priv, int enabled)
1771 struct atheros_driver_data *drv = priv;
1772 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1773 return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1777 atheros_commit(void *priv)
1779 struct atheros_driver_data *drv = priv;
1780 return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1783 static int atheros_set_authmode(void *priv, int auth_algs)
1787 if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1788 (auth_algs & WPA_AUTH_ALG_SHARED))
1789 authmode = IEEE80211_AUTH_AUTO;
1790 else if (auth_algs & WPA_AUTH_ALG_OPEN)
1791 authmode = IEEE80211_AUTH_OPEN;
1792 else if (auth_algs & WPA_AUTH_ALG_SHARED)
1793 authmode = IEEE80211_AUTH_SHARED;
1797 return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1800 static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1803 * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1804 * set_generic_elem, and hapd_set_ssid.
1807 wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1808 "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1809 "wpa_version=0x%x privacy=%d interworking=%d",
1810 params->pairwise_ciphers, params->group_cipher,
1811 params->key_mgmt_suites, params->auth_algs,
1812 params->wpa_version, params->privacy, params->interworking);
1813 wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1814 params->ssid, params->ssid_len);
1816 wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1817 MAC2STR(params->hessid));
1818 wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1819 params->beacon_ies);
1820 wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1821 params->proberesp_ies);
1822 wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1823 params->assocresp_ies);
1825 #if defined(CONFIG_HS20) && (defined(IEEE80211_PARAM_OSEN) || defined(CONFIG_ATHEROS_OSEN))
1827 struct wpa_bss_params bss_params;
1829 os_memset(&bss_params, 0, sizeof(struct wpa_bss_params));
1830 bss_params.enabled = 1;
1832 bss_params.wpa_pairwise = WPA_CIPHER_CCMP;
1833 bss_params.wpa_group = WPA_CIPHER_CCMP;
1834 bss_params.ieee802_1x = 1;
1836 if (atheros_set_privacy(priv, 1) ||
1837 set80211param(priv, IEEE80211_PARAM_OSEN, 1))
1840 return atheros_set_ieee8021x(priv, &bss_params);
1842 #endif /* CONFIG_HS20 && IEEE80211_PARAM_OSEN */
1848 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
1850 static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1851 int noack, unsigned int freq)
1853 struct atheros_driver_data *drv = priv;
1855 const struct ieee80211_mgmt *mgmt;
1856 struct ieee80211req_mgmtbuf *mgmt_frm;
1858 mgmt = (const struct ieee80211_mgmt *) frm;
1859 wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1860 (unsigned long) data_len, MAC2STR(mgmt->da));
1861 mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1862 memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1863 mgmt_frm->buflen = data_len;
1864 if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1865 wpa_printf(MSG_INFO, "atheros: Too long frame for "
1866 "atheros_send_mgmt (%u)", (unsigned int) data_len);
1869 os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1870 return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1871 sizeof(struct ieee80211req_mgmtbuf) + data_len);
1873 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
1876 #ifdef CONFIG_IEEE80211R
1878 static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1881 struct atheros_driver_data *drv = priv;
1883 struct ieee80211req_res req;
1884 struct ieee80211req_res_addts *addts = &req.u.addts;
1886 wpa_printf(MSG_DEBUG, "%s", __func__);
1887 req.type = IEEE80211_RESREQ_ADDTS;
1888 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1889 os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
1890 retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1891 sizeof(struct ieee80211req_res));
1893 wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
1894 "retv = %d", __func__, retv);
1897 os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
1898 return addts->status;
1902 static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
1904 struct atheros_driver_data *drv = priv;
1905 struct ieee80211req_res req;
1906 struct ieee80211req_res_addnode *addnode = &req.u.addnode;
1908 wpa_printf(MSG_DEBUG, "%s", __func__);
1909 req.type = IEEE80211_RESREQ_ADDNODE;
1910 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1911 addnode->auth_alg = auth_alg;
1912 return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1913 sizeof(struct ieee80211req_res));
1916 #endif /* CONFIG_IEEE80211R */
1919 /* Use only to set a big param, get will not work. */
1921 set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
1925 os_memset(&iwr, 0, sizeof(iwr));
1926 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1928 iwr.u.data.pointer = (void *) data;
1929 iwr.u.data.length = len;
1930 iwr.u.data.flags = op;
1931 wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
1932 __func__, op, op, athr_get_param_name(op), len);
1934 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
1935 wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
1936 "value=0x%x,0x%x failed: %d (%s)",
1937 __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
1938 iwr.u.mode, iwr.u.data.length,
1939 iwr.u.data.flags, errno, strerror(errno));
1946 static int atheros_send_action(void *priv, unsigned int freq,
1948 const u8 *dst, const u8 *src,
1950 const u8 *data, size_t data_len, int no_cck)
1952 struct atheros_driver_data *drv = priv;
1953 struct ieee80211_p2p_send_action *act;
1956 act = os_zalloc(sizeof(*act) + data_len);
1960 os_memcpy(act->dst_addr, dst, ETH_ALEN);
1961 os_memcpy(act->src_addr, src, ETH_ALEN);
1962 os_memcpy(act->bssid, bssid, ETH_ALEN);
1963 os_memcpy(act + 1, data, data_len);
1964 wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
1965 MACSTR ", bssid=" MACSTR,
1966 __func__, act->freq, wait, MAC2STR(act->dst_addr),
1967 MAC2STR(act->src_addr), MAC2STR(act->bssid));
1968 wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
1969 wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
1971 res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
1972 act, sizeof(*act) + data_len);
1978 #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
1979 static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
1980 u8 *ie, u16 *len, enum wnm_oper oper)
1982 #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
1983 u8 buf[IEEE80211_APPIE_MAX];
1984 struct ieee80211req_getset_appiebuf *tfs_ie;
1987 wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
1988 drv->iface, oper, MAC2STR(peer));
1991 case WNM_SLEEP_TFS_REQ_IE_SET:
1992 if (*len > IEEE80211_APPIE_MAX -
1993 sizeof(struct ieee80211req_getset_appiebuf)) {
1994 wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
1997 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
1998 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
1999 tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
2001 /* Command header for driver */
2002 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2004 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2006 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2009 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
2011 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2012 IEEE80211_APPIE_MAX)) {
2013 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2014 "%s", __func__, strerror(errno));
2018 case WNM_SLEEP_TFS_RESP_IE_ADD:
2019 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2020 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2021 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2022 sizeof(struct ieee80211req_getset_appiebuf);
2023 /* Command header for driver */
2024 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2026 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2028 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2030 if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2031 IEEE80211_APPIE_MAX)) {
2032 wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2033 "%s", __func__, strerror(errno));
2037 *len = tfs_ie->app_buflen;
2038 os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2039 wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2042 case WNM_SLEEP_TFS_RESP_IE_NONE:
2045 case WNM_SLEEP_TFS_IE_DEL:
2046 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2047 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2048 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2049 sizeof(struct ieee80211req_getset_appiebuf);
2050 /* Command header for driver */
2051 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2053 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2055 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2057 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2058 IEEE80211_APPIE_MAX)) {
2059 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2060 "%s", __func__, strerror(errno));
2065 wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2073 static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2074 const u8 *peer, enum wnm_oper oper)
2081 wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2082 oper, MAC2STR(peer));
2084 dlen = ETH_ALEN + 2 + 2;
2085 data = os_malloc(dlen);
2089 /* Command header for driver */
2091 os_memcpy(pos, peer, ETH_ALEN);
2095 os_memcpy(pos, &val, 2);
2099 os_memcpy(pos, &val, 2);
2101 ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2109 static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2110 u8 *buf, u16 *buf_len)
2112 struct atheros_driver_data *drv = priv;
2115 case WNM_SLEEP_ENTER_CONFIRM:
2116 case WNM_SLEEP_ENTER_FAIL:
2117 case WNM_SLEEP_EXIT_CONFIRM:
2118 case WNM_SLEEP_EXIT_FAIL:
2119 return atheros_wnm_sleep(drv, peer, oper);
2120 case WNM_SLEEP_TFS_REQ_IE_SET:
2121 case WNM_SLEEP_TFS_RESP_IE_ADD:
2122 case WNM_SLEEP_TFS_RESP_IE_NONE:
2123 case WNM_SLEEP_TFS_IE_DEL:
2124 return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2126 wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2131 #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2134 const struct wpa_driver_ops wpa_driver_atheros_ops = {
2136 .hapd_init = atheros_init,
2137 .hapd_deinit = atheros_deinit,
2138 .set_ieee8021x = atheros_set_ieee8021x,
2139 .set_privacy = atheros_set_privacy,
2140 .set_key = atheros_set_key,
2141 .get_seqnum = atheros_get_seqnum,
2142 .flush = atheros_flush,
2143 .set_generic_elem = atheros_set_opt_ie,
2144 .sta_set_flags = atheros_sta_set_flags,
2145 .read_sta_data = atheros_read_sta_driver_data,
2146 .hapd_send_eapol = atheros_send_eapol,
2147 .sta_disassoc = atheros_sta_disassoc,
2148 .sta_deauth = atheros_sta_deauth,
2149 .hapd_set_ssid = atheros_set_ssid,
2150 .hapd_get_ssid = atheros_get_ssid,
2151 .set_countermeasures = atheros_set_countermeasures,
2152 .sta_clear_stats = atheros_sta_clear_stats,
2153 .commit = atheros_commit,
2154 .set_ap_wps_ie = atheros_set_ap_wps_ie,
2155 .set_authmode = atheros_set_authmode,
2156 .set_ap = atheros_set_ap,
2157 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
2158 .sta_assoc = atheros_sta_assoc,
2159 .sta_auth = atheros_sta_auth,
2160 .send_mlme = atheros_send_mgmt,
2161 #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
2162 #ifdef CONFIG_IEEE80211R
2163 .add_tspec = atheros_add_tspec,
2164 .add_sta_node = atheros_add_sta_node,
2165 #endif /* CONFIG_IEEE80211R */
2166 .send_action = atheros_send_action,
2167 #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
2168 .wnm_oper = atheros_wnm_oper,
2169 #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2170 .set_qos_map = atheros_set_qos_map,