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_WNM) && !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_WNM */
926 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_WNM)
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_WNM) && !defined(CONFIG_IEEE80211R)
937 atheros_raw_recv_11v(ctx, src_addr, buf, len);
938 #endif /* CONFIG_WNM */
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);
961 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
962 #endif /* CONFIG_WNM */
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 */
982 static int atheros_reset_appfilter(struct atheros_driver_data *drv)
984 struct ieee80211req_set_filter filt;
985 filt.app_filterype = 0;
986 return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
987 sizeof(struct ieee80211req_set_filter));
992 atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
994 struct atheros_driver_data *drv = priv;
996 struct ieee80211req_getset_appiebuf *beac_ie;
998 wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
999 (unsigned long) len, frametype);
1000 wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
1002 beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
1003 beac_ie->app_frmtype = frametype;
1004 beac_ie->app_buflen = len;
1005 os_memcpy(&(beac_ie->app_buf[0]), ie, len);
1007 /* append the WPA/RSN IE if it is set already */
1008 if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
1009 (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
1010 (drv->wpa_ie != NULL)) {
1011 wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
1013 os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
1014 wpabuf_len(drv->wpa_ie));
1015 beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
1018 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
1019 beac_ie->app_buf, beac_ie->app_buflen);
1020 return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
1021 sizeof(struct ieee80211req_getset_appiebuf) +
1022 beac_ie->app_buflen);
1026 atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1027 const struct wpabuf *proberesp,
1028 const struct wpabuf *assocresp)
1030 struct atheros_driver_data *drv = priv;
1032 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1033 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1035 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1037 wpabuf_free(drv->wps_beacon_ie);
1038 drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1039 wpabuf_free(drv->wps_probe_resp_ie);
1040 drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1042 atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1043 assocresp ? wpabuf_len(assocresp) : 0,
1044 IEEE80211_APPIE_FRAME_ASSOC_RESP);
1045 if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1046 beacon ? wpabuf_len(beacon) : 0,
1047 IEEE80211_APPIE_FRAME_BEACON))
1049 return atheros_set_wps_ie(priv,
1050 proberesp ? wpabuf_head(proberesp) : NULL,
1051 proberesp ? wpabuf_len(proberesp): 0,
1052 IEEE80211_APPIE_FRAME_PROBE_RESP);
1054 #else /* CONFIG_WPS */
1055 #define atheros_set_ap_wps_ie NULL
1056 #endif /* CONFIG_WPS */
1058 #ifdef CONFIG_IEEE80211R
1060 atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
1061 u16 status_code, const u8 *ie, size_t len)
1063 struct atheros_driver_data *drv = priv;
1064 struct ieee80211req_mlme mlme;
1067 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1068 __func__, ether_sprintf(addr), status_code);
1070 mlme.im_op = IEEE80211_MLME_AUTH;
1071 mlme.im_reason = status_code;
1073 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1074 mlme.im_optie_len = len;
1076 if (len < IEEE80211_MAX_OPT_IE) {
1077 os_memcpy(mlme.im_optie, ie, len);
1079 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1080 "opt_ie STA (addr " MACSTR " reason %d, "
1082 __func__, MAC2STR(addr), status_code,
1087 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1089 wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1091 __func__, MAC2STR(addr), status_code);
1097 atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1098 int reassoc, u16 status_code, const u8 *ie, size_t len)
1100 struct atheros_driver_data *drv = priv;
1101 struct ieee80211req_mlme mlme;
1104 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1105 __func__, ether_sprintf(addr), status_code, reassoc);
1108 mlme.im_op = IEEE80211_MLME_REASSOC;
1110 mlme.im_op = IEEE80211_MLME_ASSOC;
1111 mlme.im_reason = status_code;
1112 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1113 mlme.im_optie_len = len;
1115 if (len < IEEE80211_MAX_OPT_IE) {
1116 os_memcpy(mlme.im_optie, ie, len);
1118 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1119 "opt_ie STA (addr " MACSTR " reason %d, "
1121 __func__, MAC2STR(addr), status_code,
1126 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1128 wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1130 __func__, MAC2STR(addr), status_code);
1134 #endif /* CONFIG_IEEE80211R */
1137 atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1139 struct hostapd_data *hapd = drv->hapd;
1140 struct ieee80211req_wpaie ie;
1145 * Fetch negotiated WPA/RSN parameters from the system.
1147 memset(&ie, 0, sizeof(ie));
1148 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1149 if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1151 * See ATH_WPS_IE comment in the beginning of the file for a
1152 * possible cause for the failure..
1154 wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1155 __func__, strerror(errno));
1158 wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1159 ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1160 wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1161 ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1163 wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1164 ie.wps_ie, IEEE80211_MAX_OPT_IE);
1165 #endif /* ATH_WPS_IE */
1167 /* atheros seems to return some random data if WPA/RSN IE is not set.
1168 * Assume the IE was not included if the IE type is unknown. */
1169 if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1171 if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1172 /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1173 * set. This is needed for WPA2. */
1175 if (iebuf[0] != WLAN_EID_RSN)
1182 /* if WPS IE is present, preference is given to WPS */
1184 (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
1186 ielen = ie.wps_ie[1];
1188 #endif /* ATH_WPS_IE */
1196 drv_event_assoc(hapd, addr, iebuf, ielen, 0);
1198 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
1199 /* Cached accounting data is not valid anymore. */
1200 memset(drv->acct_mac, 0, ETH_ALEN);
1201 memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1206 atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1207 char *custom, char *end)
1209 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1211 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1214 pos = strstr(custom, "addr=");
1216 wpa_printf(MSG_DEBUG,
1217 "MLME-MICHAELMICFAILURE.indication "
1218 "without sender address ignored");
1222 if (hwaddr_aton(pos, addr) == 0) {
1223 union wpa_event_data data;
1224 os_memset(&data, 0, sizeof(data));
1225 data.michael_mic_failure.unicast = 1;
1226 data.michael_mic_failure.src = addr;
1227 wpa_supplicant_event(drv->hapd,
1228 EVENT_MICHAEL_MIC_FAILURE, &data);
1230 wpa_printf(MSG_DEBUG,
1231 "MLME-MICHAELMICFAILURE.indication "
1232 "with invalid MAC address");
1234 } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1238 while ((key = strchr(key, '\n')) != NULL) {
1240 value = strchr(key, '=');
1244 val = strtoul(value, NULL, 10);
1245 if (strcmp(key, "mac") == 0)
1246 hwaddr_aton(value, drv->acct_mac);
1247 else if (strcmp(key, "rx_packets") == 0)
1248 drv->acct_data.rx_packets = val;
1249 else if (strcmp(key, "tx_packets") == 0)
1250 drv->acct_data.tx_packets = val;
1251 else if (strcmp(key, "rx_bytes") == 0)
1252 drv->acct_data.rx_bytes = val;
1253 else if (strcmp(key, "tx_bytes") == 0)
1254 drv->acct_data.tx_bytes = val;
1258 } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1259 /* Some atheros kernels send push button as a wireless event */
1260 /* PROBLEM! this event is received for ALL BSSs ...
1261 * so all are enabled for WPS... ugh.
1263 wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
1264 #endif /* CONFIG_WPS */
1265 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
1266 #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
1267 } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
1269 * Atheros driver uses a hack to pass Probe Request frames as a
1270 * binary data in the custom wireless event. The old way (using
1271 * packet sniffing) didn't work when bridging.
1272 * Format: "Manage.prob_req <frame len>" | zero padding | frame
1274 int len = atoi(custom + 16);
1275 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1276 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1280 atheros_raw_receive(drv, NULL,
1281 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1282 } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1283 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1285 int len = atoi(custom + 17);
1286 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1287 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1288 "assoc_req/auth event length %d", len);
1291 atheros_raw_receive(drv, NULL,
1292 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1293 } else if (strncmp(custom, "Manage.action ", 14) == 0) {
1294 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1296 int len = atoi(custom + 14);
1297 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1298 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1299 "assoc_req/auth event length %d", len);
1302 atheros_raw_receive(drv, NULL,
1303 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1304 } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
1305 /* Format: "Manage.auth <frame len>" | zero padding | frame
1307 int len = atoi(custom + 12);
1308 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1309 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1310 "assoc_req/auth event length %d", len);
1313 atheros_raw_receive(drv, NULL,
1314 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1315 #endif /* CONFIG_WPS or CONFIG_IEEE80211R */
1320 * Handle size of data problem. WEXT only allows data of 256 bytes for custom
1321 * events, and p2p data can be much bigger. So the athr driver sends a small
1322 * event telling me to collect the big data with an ioctl.
1323 * On the first event, send all pending events to supplicant.
1325 static void fetch_pending_big_events(struct atheros_driver_data *drv)
1327 union wpa_event_data event;
1328 const struct ieee80211_mgmt *mgmt;
1329 u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1333 u32 freq, frame_type;
1336 os_memset(&iwr, 0, sizeof(iwr));
1337 os_strncpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1339 iwr.u.data.pointer = (void *) tbuf;
1340 iwr.u.data.length = sizeof(tbuf);
1341 iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1343 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1345 if (errno == ENOSPC) {
1346 wpa_printf(MSG_DEBUG, "%s:%d exit",
1347 __func__, __LINE__);
1350 wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1351 "P2P_FETCH_FRAME] failed: %s",
1352 __func__, strerror(errno));
1355 data_len = iwr.u.data.length;
1356 wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1357 (u8 *) tbuf, data_len);
1358 if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1359 wpa_printf(MSG_DEBUG, "athr: frame too short");
1362 os_memcpy(&freq, tbuf, sizeof(freq));
1363 os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1364 sizeof(frame_type));
1365 mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1366 data_len -= sizeof(freq) + sizeof(frame_type);
1368 if (frame_type == IEEE80211_EV_RX_MGMT) {
1369 fc = le_to_host16(mgmt->frame_control);
1370 stype = WLAN_FC_GET_STYPE(fc);
1372 wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1373 "freq=%u len=%u", stype, freq, (int) data_len);
1375 if (stype == WLAN_FC_STYPE_ACTION) {
1376 os_memset(&event, 0, sizeof(event));
1377 event.rx_mgmt.frame = (const u8 *) mgmt;
1378 event.rx_mgmt.frame_len = data_len;
1379 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1384 wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1385 __func__, frame_type);
1392 atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1393 int opcode, char *buf, int len)
1396 case IEEE80211_EV_RX_MGMT:
1397 wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1398 fetch_pending_big_events(drv);
1406 atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1407 char *data, int len)
1409 struct iw_event iwe_buf, *iwe = &iwe_buf;
1410 char *pos, *end, *custom, *buf;
1415 while (pos + IW_EV_LCP_LEN <= end) {
1416 /* Event data may be unaligned, so make a local, aligned copy
1417 * before processing. */
1418 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1419 wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1420 iwe->cmd, iwe->len);
1421 if (iwe->len <= IW_EV_LCP_LEN)
1424 custom = pos + IW_EV_POINT_LEN;
1425 if (drv->we_version > 18 &&
1426 (iwe->cmd == IWEVMICHAELMICFAILURE ||
1427 iwe->cmd == IWEVASSOCREQIE ||
1428 iwe->cmd == IWEVCUSTOM)) {
1429 /* WE-19 removed the pointer from struct iw_point */
1430 char *dpos = (char *) &iwe_buf.u.data.length;
1431 int dlen = dpos - (char *) &iwe_buf;
1432 memcpy(dpos, pos + IW_EV_LCP_LEN,
1433 sizeof(struct iw_event) - dlen);
1435 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1436 custom += IW_EV_POINT_OFF;
1441 drv_event_disassoc(drv->hapd,
1442 (u8 *) iwe->u.addr.sa_data);
1444 case IWEVREGISTERED:
1445 atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1447 case IWEVASSOCREQIE:
1448 /* Driver hack.. Use IWEVASSOCREQIE to bypass
1449 * IWEVCUSTOM size limitations. Need to handle this
1450 * just like IWEVCUSTOM.
1453 if (custom + iwe->u.data.length > end)
1455 buf = malloc(iwe->u.data.length + 1);
1458 memcpy(buf, custom, iwe->u.data.length);
1459 buf[iwe->u.data.length] = '\0';
1461 if (iwe->u.data.flags != 0) {
1462 atheros_wireless_event_atheros_custom(
1463 drv, (int) iwe->u.data.flags,
1466 atheros_wireless_event_wireless_custom(
1467 drv, buf, buf + iwe->u.data.length);
1479 atheros_wireless_event_rtm_newlink(void *ctx,
1480 struct ifinfomsg *ifi, u8 *buf, size_t len)
1482 struct atheros_driver_data *drv = ctx;
1483 int attrlen, rta_len;
1484 struct rtattr *attr;
1486 if (ifi->ifi_index != drv->ifindex)
1490 attr = (struct rtattr *) buf;
1492 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1493 while (RTA_OK(attr, attrlen)) {
1494 if (attr->rta_type == IFLA_WIRELESS) {
1495 atheros_wireless_event_wireless(
1496 drv, ((char *) attr) + rta_len,
1497 attr->rta_len - rta_len);
1499 attr = RTA_NEXT(attr, attrlen);
1505 atheros_get_we_version(struct atheros_driver_data *drv)
1507 struct iw_range *range;
1512 drv->we_version = 0;
1515 * Use larger buffer than struct iw_range in order to allow the
1516 * structure to grow in the future.
1518 buflen = sizeof(struct iw_range) + 500;
1519 range = os_zalloc(buflen);
1523 memset(&iwr, 0, sizeof(iwr));
1524 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1525 iwr.u.data.pointer = (caddr_t) range;
1526 iwr.u.data.length = buflen;
1528 minlen = ((char *) &range->enc_capa) - (char *) range +
1529 sizeof(range->enc_capa);
1531 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1532 perror("ioctl[SIOCGIWRANGE]");
1535 } else if (iwr.u.data.length >= minlen &&
1536 range->we_version_compiled >= 18) {
1537 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1538 "WE(source)=%d enc_capa=0x%x",
1539 range->we_version_compiled,
1540 range->we_version_source,
1542 drv->we_version = range->we_version_compiled;
1551 atheros_wireless_event_init(struct atheros_driver_data *drv)
1553 struct netlink_config *cfg;
1555 atheros_get_we_version(drv);
1557 cfg = os_zalloc(sizeof(*cfg));
1561 cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1562 drv->netlink = netlink_init(cfg);
1563 if (drv->netlink == NULL) {
1573 atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1574 int encrypt, const u8 *own_addr, u32 flags)
1576 struct atheros_driver_data *drv = priv;
1577 unsigned char buf[3000];
1578 unsigned char *bp = buf;
1579 struct l2_ethhdr *eth;
1584 * Prepend the Ethernet header. If the caller left us
1585 * space at the front we could just insert it but since
1586 * we don't know we copy to a local buffer. Given the frequency
1587 * and size of frames this probably doesn't matter.
1589 len = data_len + sizeof(struct l2_ethhdr);
1590 if (len > sizeof(buf)) {
1593 printf("EAPOL frame discarded, cannot malloc temp "
1594 "buffer of size %lu!\n", (unsigned long) len);
1598 eth = (struct l2_ethhdr *) bp;
1599 memcpy(eth->h_dest, addr, ETH_ALEN);
1600 memcpy(eth->h_source, own_addr, ETH_ALEN);
1601 eth->h_proto = host_to_be16(ETH_P_EAPOL);
1602 memcpy(eth+1, data, data_len);
1604 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1606 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1614 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1616 struct atheros_driver_data *drv = ctx;
1617 drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1618 len - sizeof(struct l2_ethhdr));
1622 atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1624 struct atheros_driver_data *drv;
1627 char brname[IFNAMSIZ];
1629 drv = os_zalloc(sizeof(struct atheros_driver_data));
1631 printf("Could not allocate memory for atheros driver data\n");
1636 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1637 if (drv->ioctl_sock < 0) {
1638 perror("socket[PF_INET,SOCK_DGRAM]");
1641 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1643 memset(&ifr, 0, sizeof(ifr));
1644 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1645 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1646 perror("ioctl(SIOCGIFINDEX)");
1649 drv->ifindex = ifr.ifr_ifindex;
1651 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1652 handle_read, drv, 1);
1653 if (drv->sock_xmit == NULL)
1655 if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1657 os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
1658 if (params->bridge[0]) {
1659 wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1661 drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1662 ETH_P_EAPOL, handle_read, drv,
1664 if (drv->sock_recv == NULL)
1666 } else if (linux_br_get(brname, drv->iface) == 0) {
1667 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1668 "EAPOL receive", brname);
1669 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1670 handle_read, drv, 1);
1671 if (drv->sock_recv == NULL)
1674 drv->sock_recv = drv->sock_xmit;
1676 memset(&iwr, 0, sizeof(iwr));
1677 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1679 iwr.u.mode = IW_MODE_MASTER;
1681 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1682 perror("ioctl[SIOCSIWMODE]");
1683 printf("Could not set interface to master mode!\n");
1687 /* mark down during setup */
1688 linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1689 atheros_set_privacy(drv, 0); /* default to no privacy */
1691 if (atheros_receive_pkt(drv))
1694 if (atheros_wireless_event_init(drv))
1699 atheros_reset_appfilter(drv);
1701 l2_packet_deinit(drv->sock_raw);
1702 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1703 l2_packet_deinit(drv->sock_recv);
1704 if (drv->sock_xmit != NULL)
1705 l2_packet_deinit(drv->sock_xmit);
1706 if (drv->ioctl_sock >= 0)
1707 close(drv->ioctl_sock);
1715 atheros_deinit(void *priv)
1717 struct atheros_driver_data *drv = priv;
1719 atheros_reset_appfilter(drv);
1720 netlink_deinit(drv->netlink);
1721 (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1722 if (drv->ioctl_sock >= 0)
1723 close(drv->ioctl_sock);
1724 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1725 l2_packet_deinit(drv->sock_recv);
1726 if (drv->sock_xmit != NULL)
1727 l2_packet_deinit(drv->sock_xmit);
1729 l2_packet_deinit(drv->sock_raw);
1730 wpabuf_free(drv->wpa_ie);
1731 wpabuf_free(drv->wps_beacon_ie);
1732 wpabuf_free(drv->wps_probe_resp_ie);
1737 atheros_set_ssid(void *priv, const u8 *buf, int len)
1739 struct atheros_driver_data *drv = priv;
1742 memset(&iwr, 0, sizeof(iwr));
1743 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1744 iwr.u.essid.flags = 1; /* SSID active */
1745 iwr.u.essid.pointer = (caddr_t) buf;
1746 iwr.u.essid.length = len + 1;
1748 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1749 perror("ioctl[SIOCSIWESSID]");
1750 printf("len=%d\n", len);
1757 atheros_get_ssid(void *priv, u8 *buf, int len)
1759 struct atheros_driver_data *drv = priv;
1763 memset(&iwr, 0, sizeof(iwr));
1764 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1765 iwr.u.essid.pointer = (caddr_t) buf;
1766 iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1767 IW_ESSID_MAX_SIZE : len;
1769 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1770 perror("ioctl[SIOCGIWESSID]");
1773 ret = iwr.u.essid.length;
1779 atheros_set_countermeasures(void *priv, int enabled)
1781 struct atheros_driver_data *drv = priv;
1782 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1783 return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1787 atheros_commit(void *priv)
1789 struct atheros_driver_data *drv = priv;
1790 return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1793 static int atheros_set_authmode(void *priv, int auth_algs)
1797 if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1798 (auth_algs & WPA_AUTH_ALG_SHARED))
1799 authmode = IEEE80211_AUTH_AUTO;
1800 else if (auth_algs & WPA_AUTH_ALG_OPEN)
1801 authmode = IEEE80211_AUTH_OPEN;
1802 else if (auth_algs & WPA_AUTH_ALG_SHARED)
1803 authmode = IEEE80211_AUTH_SHARED;
1807 return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1810 static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1813 * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1814 * set_generic_elem, and hapd_set_ssid.
1817 wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1818 "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1819 "wpa_version=0x%x privacy=%d interworking=%d",
1820 params->pairwise_ciphers, params->group_cipher,
1821 params->key_mgmt_suites, params->auth_algs,
1822 params->wpa_version, params->privacy, params->interworking);
1823 wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1824 params->ssid, params->ssid_len);
1826 wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1827 MAC2STR(params->hessid));
1828 wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1829 params->beacon_ies);
1830 wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1831 params->proberesp_ies);
1832 wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1833 params->assocresp_ies);
1839 #ifdef CONFIG_IEEE80211R
1841 static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1844 struct atheros_driver_data *drv = priv;
1846 const struct ieee80211_mgmt *mgmt;
1847 struct ieee80211req_mgmtbuf *mgmt_frm;
1849 mgmt = (const struct ieee80211_mgmt *) frm;
1850 wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1851 (unsigned long) data_len, MAC2STR(mgmt->da));
1852 mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1853 memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1854 mgmt_frm->buflen = data_len;
1855 if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1856 wpa_printf(MSG_INFO, "atheros: Too long frame for "
1857 "atheros_send_mgmt (%u)", (unsigned int) data_len);
1860 os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1861 return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1862 sizeof(struct ieee80211req_mgmtbuf) + data_len);
1866 static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1869 struct atheros_driver_data *drv = priv;
1871 struct ieee80211req_res req;
1872 struct ieee80211req_res_addts *addts = &req.u.addts;
1874 wpa_printf(MSG_DEBUG, "%s", __func__);
1875 req.type = IEEE80211_RESREQ_ADDTS;
1876 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1877 os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
1878 retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1879 sizeof(struct ieee80211req_res));
1881 wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
1882 "retv = %d", __func__, retv);
1885 os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
1886 return addts->status;
1890 static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
1892 struct atheros_driver_data *drv = priv;
1893 struct ieee80211req_res req;
1894 struct ieee80211req_res_addnode *addnode = &req.u.addnode;
1896 wpa_printf(MSG_DEBUG, "%s", __func__);
1897 req.type = IEEE80211_RESREQ_ADDNODE;
1898 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1899 addnode->auth_alg = auth_alg;
1900 return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1901 sizeof(struct ieee80211req_res));
1904 #endif /* CONFIG_IEEE80211R */
1907 /* Use only to set a big param, get will not work. */
1909 set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
1913 os_memset(&iwr, 0, sizeof(iwr));
1914 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1916 iwr.u.data.pointer = (void *) data;
1917 iwr.u.data.length = len;
1918 iwr.u.data.flags = op;
1919 wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
1920 __func__, op, op, athr_get_param_name(op), len);
1922 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
1923 wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
1924 "value=0x%x,0x%x failed: %d (%s)",
1925 __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
1926 iwr.u.mode, iwr.u.data.length,
1927 iwr.u.data.flags, errno, strerror(errno));
1934 static int atheros_send_action(void *priv, unsigned int freq,
1936 const u8 *dst, const u8 *src,
1938 const u8 *data, size_t data_len, int no_cck)
1940 struct atheros_driver_data *drv = priv;
1941 struct ieee80211_p2p_send_action *act;
1944 act = os_zalloc(sizeof(*act) + data_len);
1948 os_memcpy(act->dst_addr, dst, ETH_ALEN);
1949 os_memcpy(act->src_addr, src, ETH_ALEN);
1950 os_memcpy(act->bssid, bssid, ETH_ALEN);
1951 os_memcpy(act + 1, data, data_len);
1952 wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
1953 MACSTR ", bssid=" MACSTR,
1954 __func__, act->freq, wait, MAC2STR(act->dst_addr),
1955 MAC2STR(act->src_addr), MAC2STR(act->bssid));
1956 wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
1957 wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
1959 res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
1960 act, sizeof(*act) + data_len);
1967 static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
1968 u8 *ie, u16 *len, enum wnm_oper oper)
1970 #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
1971 u8 buf[IEEE80211_APPIE_MAX];
1972 struct ieee80211req_getset_appiebuf *tfs_ie;
1975 wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
1976 drv->iface, oper, MAC2STR(peer));
1979 case WNM_SLEEP_TFS_REQ_IE_SET:
1980 if (*len > IEEE80211_APPIE_MAX -
1981 sizeof(struct ieee80211req_getset_appiebuf)) {
1982 wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
1985 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
1986 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
1987 tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
1989 /* Command header for driver */
1990 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
1992 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
1994 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
1997 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
1999 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2000 IEEE80211_APPIE_MAX)) {
2001 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2002 "%s", __func__, strerror(errno));
2006 case WNM_SLEEP_TFS_RESP_IE_ADD:
2007 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2008 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2009 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2010 sizeof(struct ieee80211req_getset_appiebuf);
2011 /* Command header for driver */
2012 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2014 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2016 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2018 if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2019 IEEE80211_APPIE_MAX)) {
2020 wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2021 "%s", __func__, strerror(errno));
2025 *len = tfs_ie->app_buflen;
2026 os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2027 wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2030 case WNM_SLEEP_TFS_RESP_IE_NONE:
2033 case WNM_SLEEP_TFS_IE_DEL:
2034 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2035 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2036 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2037 sizeof(struct ieee80211req_getset_appiebuf);
2038 /* Command header for driver */
2039 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2041 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2043 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2045 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2046 IEEE80211_APPIE_MAX)) {
2047 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2048 "%s", __func__, strerror(errno));
2053 wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2061 static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2062 const u8 *peer, enum wnm_oper oper)
2069 wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2070 oper, MAC2STR(peer));
2072 dlen = ETH_ALEN + 2 + 2;
2073 data = os_malloc(dlen);
2077 /* Command header for driver */
2079 os_memcpy(pos, peer, ETH_ALEN);
2083 os_memcpy(pos, &val, 2);
2087 os_memcpy(pos, &val, 2);
2089 ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2097 static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2098 u8 *buf, u16 *buf_len)
2100 struct atheros_driver_data *drv = priv;
2103 case WNM_SLEEP_ENTER_CONFIRM:
2104 case WNM_SLEEP_ENTER_FAIL:
2105 case WNM_SLEEP_EXIT_CONFIRM:
2106 case WNM_SLEEP_EXIT_FAIL:
2107 return atheros_wnm_sleep(drv, peer, oper);
2108 case WNM_SLEEP_TFS_REQ_IE_SET:
2109 case WNM_SLEEP_TFS_RESP_IE_ADD:
2110 case WNM_SLEEP_TFS_RESP_IE_NONE:
2111 case WNM_SLEEP_TFS_IE_DEL:
2112 return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2114 wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2119 #endif /* CONFIG_WNM */
2122 const struct wpa_driver_ops wpa_driver_atheros_ops = {
2124 .hapd_init = atheros_init,
2125 .hapd_deinit = atheros_deinit,
2126 .set_ieee8021x = atheros_set_ieee8021x,
2127 .set_privacy = atheros_set_privacy,
2128 .set_key = atheros_set_key,
2129 .get_seqnum = atheros_get_seqnum,
2130 .flush = atheros_flush,
2131 .set_generic_elem = atheros_set_opt_ie,
2132 .sta_set_flags = atheros_sta_set_flags,
2133 .read_sta_data = atheros_read_sta_driver_data,
2134 .hapd_send_eapol = atheros_send_eapol,
2135 .sta_disassoc = atheros_sta_disassoc,
2136 .sta_deauth = atheros_sta_deauth,
2137 .hapd_set_ssid = atheros_set_ssid,
2138 .hapd_get_ssid = atheros_get_ssid,
2139 .set_countermeasures = atheros_set_countermeasures,
2140 .sta_clear_stats = atheros_sta_clear_stats,
2141 .commit = atheros_commit,
2142 .set_ap_wps_ie = atheros_set_ap_wps_ie,
2143 .set_authmode = atheros_set_authmode,
2144 .set_ap = atheros_set_ap,
2145 #ifdef CONFIG_IEEE80211R
2146 .sta_assoc = atheros_sta_assoc,
2147 .sta_auth = atheros_sta_auth,
2148 .send_mlme = atheros_send_mgmt,
2149 .add_tspec = atheros_add_tspec,
2150 .add_sta_node = atheros_add_sta_node,
2151 #endif /* CONFIG_IEEE80211R */
2152 .send_action = atheros_send_action,
2154 .wnm_oper = atheros_wnm_oper,
2155 #endif /* CONFIG_WNM */