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 wpa_printf(MSG_WARNING, "No 802.1X or WPA enabled!");
360 if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
361 wpa_printf(MSG_WARNING, "Error configuring WPA state!");
364 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
365 (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
366 wpa_printf(MSG_WARNING, "Error enabling WPA/802.1X!");
374 atheros_set_privacy(void *priv, int enabled)
376 struct atheros_driver_data *drv = priv;
378 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
380 return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
384 atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
386 struct atheros_driver_data *drv = priv;
387 struct ieee80211req_mlme mlme;
390 wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
391 __func__, ether_sprintf(addr), authorized);
394 mlme.im_op = IEEE80211_MLME_AUTHORIZE;
396 mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
398 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
399 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
401 wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
402 __func__, authorized ? "" : "un", MAC2STR(addr));
409 atheros_sta_set_flags(void *priv, const u8 *addr,
410 int total_flags, int flags_or, int flags_and)
412 /* For now, only support setting Authorized flag */
413 if (flags_or & WPA_STA_AUTHORIZED)
414 return atheros_set_sta_authorized(priv, addr, 1);
415 if (!(flags_and & WPA_STA_AUTHORIZED))
416 return atheros_set_sta_authorized(priv, addr, 0);
421 atheros_del_key(void *priv, const u8 *addr, int key_idx)
423 struct atheros_driver_data *drv = priv;
424 struct ieee80211req_del_key wk;
427 wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
428 __func__, ether_sprintf(addr), key_idx);
430 memset(&wk, 0, sizeof(wk));
432 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
433 wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
435 wk.idk_keyix = key_idx;
438 ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
440 wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
441 " key_idx %d)", __func__, ether_sprintf(addr),
449 atheros_set_key(const char *ifname, void *priv, enum wpa_alg alg,
450 const u8 *addr, int key_idx, int set_tx, const u8 *seq,
451 size_t seq_len, const u8 *key, size_t key_len)
453 struct atheros_driver_data *drv = priv;
454 struct ieee80211req_key wk;
458 if (alg == WPA_ALG_NONE)
459 return atheros_del_key(drv, addr, key_idx);
461 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
462 __func__, alg, ether_sprintf(addr), key_idx);
466 cipher = IEEE80211_CIPHER_WEP;
469 cipher = IEEE80211_CIPHER_TKIP;
472 cipher = IEEE80211_CIPHER_AES_CCM;
474 #ifdef CONFIG_IEEE80211W
476 cipher = IEEE80211_CIPHER_AES_CMAC;
478 #endif /* CONFIG_IEEE80211W */
480 printf("%s: unknown/unsupported algorithm %d\n",
485 if (key_len > sizeof(wk.ik_keydata)) {
486 printf("%s: key length %lu too big\n", __func__,
487 (unsigned long) key_len);
491 memset(&wk, 0, sizeof(wk));
493 wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
494 if (addr == NULL || is_broadcast_ether_addr(addr)) {
495 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
496 wk.ik_keyix = key_idx;
498 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
500 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
501 wk.ik_keyix = IEEE80211_KEYIX_NONE;
503 wk.ik_keylen = key_len;
504 memcpy(wk.ik_keydata, key, key_len);
506 ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
508 wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
509 " key_idx %d alg %d key_len %lu set_tx %d)",
510 __func__, ether_sprintf(wk.ik_macaddr), key_idx,
511 alg, (unsigned long) key_len, set_tx);
519 atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
522 struct atheros_driver_data *drv = priv;
523 struct ieee80211req_key wk;
525 wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
526 __func__, ether_sprintf(addr), idx);
528 memset(&wk, 0, sizeof(wk));
530 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
532 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
535 if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
536 wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
537 "(addr " MACSTR " key_idx %d)",
538 __func__, MAC2STR(wk.ik_macaddr), idx);
542 #ifdef WORDS_BIGENDIAN
545 * wk.ik_keytsc is in host byte order (big endian), need to
546 * swap it to match with the byte order used in WPA.
549 #ifndef WPA_KEY_RSC_LEN
550 #define WPA_KEY_RSC_LEN 8
552 u8 tmp[WPA_KEY_RSC_LEN];
553 memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
554 for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
555 seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
558 #else /* WORDS_BIGENDIAN */
559 memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
560 #endif /* WORDS_BIGENDIAN */
566 atheros_flush(void *priv)
568 u8 allsta[IEEE80211_ADDR_LEN];
569 memset(allsta, 0xff, IEEE80211_ADDR_LEN);
570 return atheros_sta_deauth(priv, NULL, allsta,
571 IEEE80211_REASON_AUTH_LEAVE);
576 atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
579 struct atheros_driver_data *drv = priv;
580 struct ieee80211req_sta_stats stats;
582 memset(data, 0, sizeof(*data));
585 * Fetch statistics for station from the system.
587 memset(&stats, 0, sizeof(stats));
588 memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
589 if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
590 &stats, sizeof(stats))) {
591 wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
592 MACSTR ")", __func__, MAC2STR(addr));
593 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
594 memcpy(data, &drv->acct_data, sizeof(*data));
598 printf("Failed to get station stats information element.\n");
602 data->rx_packets = stats.is_stats.ns_rx_data;
603 data->rx_bytes = stats.is_stats.ns_rx_bytes;
604 data->tx_packets = stats.is_stats.ns_tx_data;
605 data->tx_bytes = stats.is_stats.ns_tx_bytes;
611 atheros_sta_clear_stats(void *priv, const u8 *addr)
613 struct atheros_driver_data *drv = priv;
614 struct ieee80211req_mlme mlme;
617 wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
619 mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
620 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
621 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
624 wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
625 MACSTR ")", __func__, MAC2STR(addr));
633 atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
635 struct atheros_driver_data *drv = priv;
637 struct ieee80211req_getset_appiebuf *app_ie;
639 wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
640 (unsigned long) ie_len);
641 wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
643 wpabuf_free(drv->wpa_ie);
644 drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
646 app_ie = (struct ieee80211req_getset_appiebuf *) buf;
647 os_memcpy(&(app_ie->app_buf[0]), ie, ie_len);
648 app_ie->app_buflen = ie_len;
650 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
652 /* append WPS IE for Beacon */
653 if (drv->wps_beacon_ie != NULL) {
654 os_memcpy(&(app_ie->app_buf[ie_len]),
655 wpabuf_head(drv->wps_beacon_ie),
656 wpabuf_len(drv->wps_beacon_ie));
657 app_ie->app_buflen = ie_len + wpabuf_len(drv->wps_beacon_ie);
659 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
660 app_ie->app_buf, app_ie->app_buflen);
661 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
662 sizeof(struct ieee80211req_getset_appiebuf) +
665 /* append WPS IE for Probe Response */
666 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;
667 if (drv->wps_probe_resp_ie != NULL) {
668 os_memcpy(&(app_ie->app_buf[ie_len]),
669 wpabuf_head(drv->wps_probe_resp_ie),
670 wpabuf_len(drv->wps_probe_resp_ie));
671 app_ie->app_buflen = ie_len +
672 wpabuf_len(drv->wps_probe_resp_ie);
674 app_ie->app_buflen = ie_len;
675 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
676 app_ie->app_buf, app_ie->app_buflen);
677 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
678 sizeof(struct ieee80211req_getset_appiebuf) +
684 atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
687 struct atheros_driver_data *drv = priv;
688 struct ieee80211req_mlme mlme;
691 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
692 __func__, ether_sprintf(addr), reason_code);
694 mlme.im_op = IEEE80211_MLME_DEAUTH;
695 mlme.im_reason = reason_code;
696 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
697 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
699 wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
701 __func__, MAC2STR(addr), reason_code);
708 atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
711 struct atheros_driver_data *drv = priv;
712 struct ieee80211req_mlme mlme;
715 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
716 __func__, ether_sprintf(addr), reason_code);
718 mlme.im_op = IEEE80211_MLME_DISASSOC;
719 mlme.im_reason = reason_code;
720 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
721 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
723 wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
724 MACSTR " reason %d)",
725 __func__, MAC2STR(addr), reason_code);
732 static void atheros_raw_recv_wps(void *ctx, const u8 *src_addr, const u8 *buf,
735 struct atheros_driver_data *drv = ctx;
736 const struct ieee80211_mgmt *mgmt;
738 union wpa_event_data event;
740 /* Send Probe Request information to WPS processing */
742 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
744 mgmt = (const struct ieee80211_mgmt *) buf;
746 fc = le_to_host16(mgmt->frame_control);
747 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
748 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_PROBE_REQ)
751 os_memset(&event, 0, sizeof(event));
752 event.rx_probe_req.sa = mgmt->sa;
753 event.rx_probe_req.da = mgmt->da;
754 event.rx_probe_req.bssid = mgmt->bssid;
755 event.rx_probe_req.ie = mgmt->u.probe_req.variable;
756 event.rx_probe_req.ie_len =
757 len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
758 wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
760 #endif /* CONFIG_WPS */
762 #ifdef CONFIG_IEEE80211R
763 static void atheros_raw_recv_11r(void *ctx, const u8 *src_addr, const u8 *buf,
766 struct atheros_driver_data *drv = ctx;
767 union wpa_event_data event;
768 const struct ieee80211_mgmt *mgmt;
774 /* Do 11R processing for ASSOC/AUTH/FT ACTION frames */
775 if (len < IEEE80211_HDRLEN)
777 mgmt = (const struct ieee80211_mgmt *) buf;
779 fc = le_to_host16(mgmt->frame_control);
781 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
783 stype = WLAN_FC_GET_STYPE(fc);
785 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
788 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
789 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
794 case WLAN_FC_STYPE_ASSOC_REQ:
795 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.assoc_req))
797 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
798 iebuf = mgmt->u.assoc_req.variable;
799 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 0);
801 case WLAN_FC_STYPE_REASSOC_REQ:
802 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.reassoc_req))
804 ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
805 iebuf = mgmt->u.reassoc_req.variable;
806 drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, 1);
808 case WLAN_FC_STYPE_ACTION:
809 os_memset(&event, 0, sizeof(event));
810 event.rx_mgmt.frame = buf;
811 event.rx_mgmt.frame_len = len;
812 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
814 case WLAN_FC_STYPE_AUTH:
815 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.auth))
817 os_memset(&event, 0, sizeof(event));
818 os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
819 os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
820 event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
821 event.auth.status_code =
822 le_to_host16(mgmt->u.auth.status_code);
823 event.auth.auth_transaction =
824 le_to_host16(mgmt->u.auth.auth_transaction);
825 event.auth.ies = mgmt->u.auth.variable;
826 event.auth.ies_len = len - IEEE80211_HDRLEN -
827 sizeof(mgmt->u.auth);
828 wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
834 #endif /* CONFIG_IEEE80211R */
837 static void atheros_raw_recv_hs20(void *ctx, const u8 *src_addr, const u8 *buf,
840 struct atheros_driver_data *drv = ctx;
841 const struct ieee80211_mgmt *mgmt;
843 union wpa_event_data event;
845 /* Send the Action frame for HS20 processing */
847 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.action.category) +
848 sizeof(mgmt->u.action.u.public_action))
851 mgmt = (const struct ieee80211_mgmt *) buf;
853 fc = le_to_host16(mgmt->frame_control);
854 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
855 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION ||
856 mgmt->u.action.category != WLAN_ACTION_PUBLIC)
859 wpa_printf(MSG_DEBUG, "%s:Received Public Action frame", __func__);
861 os_memset(&event, 0, sizeof(event));
862 event.rx_mgmt.frame = (const u8 *) mgmt;
863 event.rx_mgmt.frame_len = len;
864 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
867 #endif /* CONFIG_HS20 */
870 static int atheros_set_qos_map(void *ctx, const u8 *qos_map_set,
873 #ifdef CONFIG_ATHEROS_QOS_MAP
874 struct atheros_driver_data *drv = ctx;
875 struct ieee80211req_athdbg req;
876 struct ieee80211_qos_map *qos_map = &req.data.qos_map;
880 if (qos_map_set_len < 16 || qos_map_set_len > 58 ||
881 qos_map_set_len & 1) {
882 wpa_printf(MSG_ERROR, "Invalid QoS Map");
885 memset(&req, 0, sizeof(struct ieee80211req_athdbg));
886 req.cmd = IEEE80211_DBGREQ_SETQOSMAPCONF;
887 os_memset(&iwr, 0, sizeof(iwr));
888 os_strlcpy(iwr.ifr_name, drv->iface, sizeof(iwr.ifr_name));
889 iwr.u.data.pointer = (void *) &req;
890 iwr.u.data.length = sizeof(struct ieee80211req_athdbg);
894 qos_map->num_dscp_except = (qos_map_set_len - 16) / 2;
895 if (qos_map->num_dscp_except) {
896 for (i = 0; i < qos_map->num_dscp_except; i++) {
897 qos_map->dscp_exception[i].dscp = qos_map_set[i * 2];
898 qos_map->dscp_exception[i].up = qos_map_set[i * 2 + 1];
902 up_start = qos_map_set_len - 16;
903 for (i = 0; i < IEEE80211_MAX_QOS_UP_RANGE; i++) {
904 qos_map->up[i].low = qos_map_set[up_start + (i * 2)];
905 qos_map->up[i].high = qos_map_set[up_start + (i * 2) + 1];
908 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_DBGREQ, &iwr) < 0) {
909 perror("ioctl[IEEE80211_IOCTL_DBGREQ]");
910 wpa_printf(MSG_DEBUG, "%s: %s: Failed to set QoS Map",
911 __func__, drv->iface);
914 #endif /* CONFIG_ATHEROS_QOS_MAP */
919 #if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
920 static void atheros_raw_recv_11v(void *ctx, const u8 *src_addr, const u8 *buf,
923 struct atheros_driver_data *drv = ctx;
924 union wpa_event_data event;
925 const struct ieee80211_mgmt *mgmt;
929 /* Do 11R processing for WNM ACTION frames */
930 if (len < IEEE80211_HDRLEN)
932 mgmt = (const struct ieee80211_mgmt *) buf;
934 fc = le_to_host16(mgmt->frame_control);
936 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
938 stype = WLAN_FC_GET_STYPE(fc);
940 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
943 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
944 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
950 case WLAN_FC_STYPE_ACTION:
951 os_memset(&event, 0, sizeof(event));
952 event.rx_mgmt.frame = buf;
953 event.rx_mgmt.frame_len = len;
954 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
960 #endif /* CONFIG_WNM */
962 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_WNM)
963 static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
967 atheros_raw_recv_wps(ctx, src_addr, buf, len);
968 #endif /* CONFIG_WPS */
969 #ifdef CONFIG_IEEE80211R
970 atheros_raw_recv_11r(ctx, src_addr, buf, len);
971 #endif /* CONFIG_IEEE80211R */
972 #if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
973 atheros_raw_recv_11v(ctx, src_addr, buf, len);
974 #endif /* CONFIG_WNM */
976 atheros_raw_recv_hs20(ctx, src_addr, buf, len);
977 #endif /* CONFIG_HS20 */
979 #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
981 static int atheros_receive_pkt(struct atheros_driver_data *drv)
984 struct ieee80211req_set_filter filt;
986 wpa_printf(MSG_DEBUG, "%s Enter", __func__);
987 filt.app_filterype = 0;
989 filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
990 #endif /* CONFIG_WPS */
991 #ifdef CONFIG_IEEE80211R
992 filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
993 IEEE80211_FILTER_TYPE_AUTH |
994 IEEE80211_FILTER_TYPE_ACTION);
997 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
998 #endif /* CONFIG_WNM */
1000 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
1001 #endif /* CONFIG_HS20 */
1002 if (filt.app_filterype) {
1003 ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
1004 sizeof(struct ieee80211req_set_filter));
1009 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
1010 drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
1011 atheros_raw_receive, drv, 1);
1012 if (drv->sock_raw == NULL)
1014 #endif /* CONFIG_WPS || CONFIG_IEEE80211R */
1018 static int atheros_reset_appfilter(struct atheros_driver_data *drv)
1020 struct ieee80211req_set_filter filt;
1021 filt.app_filterype = 0;
1022 return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
1023 sizeof(struct ieee80211req_set_filter));
1028 atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
1030 struct atheros_driver_data *drv = priv;
1032 struct ieee80211req_getset_appiebuf *beac_ie;
1034 wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
1035 (unsigned long) len, frametype);
1036 wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
1038 beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
1039 beac_ie->app_frmtype = frametype;
1040 beac_ie->app_buflen = len;
1041 os_memcpy(&(beac_ie->app_buf[0]), ie, len);
1043 /* append the WPA/RSN IE if it is set already */
1044 if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
1045 (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
1046 (drv->wpa_ie != NULL)) {
1047 wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
1049 os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
1050 wpabuf_len(drv->wpa_ie));
1051 beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
1054 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
1055 beac_ie->app_buf, beac_ie->app_buflen);
1056 return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
1057 sizeof(struct ieee80211req_getset_appiebuf) +
1058 beac_ie->app_buflen);
1062 atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1063 const struct wpabuf *proberesp,
1064 const struct wpabuf *assocresp)
1066 struct atheros_driver_data *drv = priv;
1068 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1069 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1071 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1073 wpabuf_free(drv->wps_beacon_ie);
1074 drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1075 wpabuf_free(drv->wps_probe_resp_ie);
1076 drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1078 atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1079 assocresp ? wpabuf_len(assocresp) : 0,
1080 IEEE80211_APPIE_FRAME_ASSOC_RESP);
1081 if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1082 beacon ? wpabuf_len(beacon) : 0,
1083 IEEE80211_APPIE_FRAME_BEACON))
1085 return atheros_set_wps_ie(priv,
1086 proberesp ? wpabuf_head(proberesp) : NULL,
1087 proberesp ? wpabuf_len(proberesp): 0,
1088 IEEE80211_APPIE_FRAME_PROBE_RESP);
1090 #else /* CONFIG_WPS */
1091 #define atheros_set_ap_wps_ie NULL
1092 #endif /* CONFIG_WPS */
1094 #ifdef CONFIG_IEEE80211R
1096 atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
1097 u16 status_code, const u8 *ie, size_t len)
1099 struct atheros_driver_data *drv = priv;
1100 struct ieee80211req_mlme mlme;
1103 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1104 __func__, ether_sprintf(addr), status_code);
1106 mlme.im_op = IEEE80211_MLME_AUTH;
1107 mlme.im_reason = status_code;
1109 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1110 mlme.im_optie_len = len;
1112 if (len < IEEE80211_MAX_OPT_IE) {
1113 os_memcpy(mlme.im_optie, ie, len);
1115 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1116 "opt_ie STA (addr " MACSTR " reason %d, "
1118 __func__, MAC2STR(addr), status_code,
1123 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1125 wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1127 __func__, MAC2STR(addr), status_code);
1133 atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1134 int reassoc, u16 status_code, const u8 *ie, size_t len)
1136 struct atheros_driver_data *drv = priv;
1137 struct ieee80211req_mlme mlme;
1140 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1141 __func__, ether_sprintf(addr), status_code, reassoc);
1144 mlme.im_op = IEEE80211_MLME_REASSOC;
1146 mlme.im_op = IEEE80211_MLME_ASSOC;
1147 mlme.im_reason = status_code;
1148 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1149 mlme.im_optie_len = len;
1151 if (len < IEEE80211_MAX_OPT_IE) {
1152 os_memcpy(mlme.im_optie, ie, len);
1154 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1155 "opt_ie STA (addr " MACSTR " reason %d, "
1157 __func__, MAC2STR(addr), status_code,
1162 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1164 wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1166 __func__, MAC2STR(addr), status_code);
1170 #endif /* CONFIG_IEEE80211R */
1173 atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1175 struct hostapd_data *hapd = drv->hapd;
1176 struct ieee80211req_wpaie ie;
1181 * Fetch negotiated WPA/RSN parameters from the system.
1183 memset(&ie, 0, sizeof(ie));
1184 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1185 if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1187 * See ATH_WPS_IE comment in the beginning of the file for a
1188 * possible cause for the failure..
1190 wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1191 __func__, strerror(errno));
1194 wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1195 ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1196 wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1197 ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1199 wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1200 ie.wps_ie, IEEE80211_MAX_OPT_IE);
1201 #endif /* ATH_WPS_IE */
1203 /* atheros seems to return some random data if WPA/RSN IE is not set.
1204 * Assume the IE was not included if the IE type is unknown. */
1205 if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1207 if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1208 /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1209 * set. This is needed for WPA2. */
1211 if (iebuf[0] != WLAN_EID_RSN)
1218 /* if WPS IE is present, preference is given to WPS */
1220 (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
1222 ielen = ie.wps_ie[1];
1224 #endif /* ATH_WPS_IE */
1232 drv_event_assoc(hapd, addr, iebuf, ielen, 0);
1234 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
1235 /* Cached accounting data is not valid anymore. */
1236 memset(drv->acct_mac, 0, ETH_ALEN);
1237 memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1242 atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1243 char *custom, char *end)
1245 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1247 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1250 pos = strstr(custom, "addr=");
1252 wpa_printf(MSG_DEBUG,
1253 "MLME-MICHAELMICFAILURE.indication "
1254 "without sender address ignored");
1258 if (hwaddr_aton(pos, addr) == 0) {
1259 union wpa_event_data data;
1260 os_memset(&data, 0, sizeof(data));
1261 data.michael_mic_failure.unicast = 1;
1262 data.michael_mic_failure.src = addr;
1263 wpa_supplicant_event(drv->hapd,
1264 EVENT_MICHAEL_MIC_FAILURE, &data);
1266 wpa_printf(MSG_DEBUG,
1267 "MLME-MICHAELMICFAILURE.indication "
1268 "with invalid MAC address");
1270 } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1274 while ((key = strchr(key, '\n')) != NULL) {
1276 value = strchr(key, '=');
1280 val = strtoul(value, NULL, 10);
1281 if (strcmp(key, "mac") == 0)
1282 hwaddr_aton(value, drv->acct_mac);
1283 else if (strcmp(key, "rx_packets") == 0)
1284 drv->acct_data.rx_packets = val;
1285 else if (strcmp(key, "tx_packets") == 0)
1286 drv->acct_data.tx_packets = val;
1287 else if (strcmp(key, "rx_bytes") == 0)
1288 drv->acct_data.rx_bytes = val;
1289 else if (strcmp(key, "tx_bytes") == 0)
1290 drv->acct_data.tx_bytes = val;
1294 } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1295 /* Some atheros kernels send push button as a wireless event */
1296 /* PROBLEM! this event is received for ALL BSSs ...
1297 * so all are enabled for WPS... ugh.
1299 wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
1300 #endif /* CONFIG_WPS */
1301 #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
1302 #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
1303 } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
1305 * Atheros driver uses a hack to pass Probe Request frames as a
1306 * binary data in the custom wireless event. The old way (using
1307 * packet sniffing) didn't work when bridging.
1308 * Format: "Manage.prob_req <frame len>" | zero padding | frame
1310 int len = atoi(custom + 16);
1311 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1312 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1316 atheros_raw_receive(drv, NULL,
1317 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1318 } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1319 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1321 int len = atoi(custom + 17);
1322 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1323 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1324 "assoc_req/auth event length %d", len);
1327 atheros_raw_receive(drv, NULL,
1328 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1329 } else if (strncmp(custom, "Manage.action ", 14) == 0) {
1330 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1332 int len = atoi(custom + 14);
1333 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1334 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1335 "assoc_req/auth event length %d", len);
1338 atheros_raw_receive(drv, NULL,
1339 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1340 } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
1341 /* Format: "Manage.auth <frame len>" | zero padding | frame
1343 int len = atoi(custom + 12);
1344 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
1345 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1346 "assoc_req/auth event length %d", len);
1349 atheros_raw_receive(drv, NULL,
1350 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1351 #endif /* CONFIG_WPS or CONFIG_IEEE80211R */
1356 * Handle size of data problem. WEXT only allows data of 256 bytes for custom
1357 * events, and p2p data can be much bigger. So the athr driver sends a small
1358 * event telling me to collect the big data with an ioctl.
1359 * On the first event, send all pending events to supplicant.
1361 static void fetch_pending_big_events(struct atheros_driver_data *drv)
1363 union wpa_event_data event;
1364 const struct ieee80211_mgmt *mgmt;
1365 u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1369 u32 freq, frame_type;
1372 os_memset(&iwr, 0, sizeof(iwr));
1373 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1375 iwr.u.data.pointer = (void *) tbuf;
1376 iwr.u.data.length = sizeof(tbuf);
1377 iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1379 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1381 if (errno == ENOSPC) {
1382 wpa_printf(MSG_DEBUG, "%s:%d exit",
1383 __func__, __LINE__);
1386 wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1387 "P2P_FETCH_FRAME] failed: %s",
1388 __func__, strerror(errno));
1391 data_len = iwr.u.data.length;
1392 wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1393 (u8 *) tbuf, data_len);
1394 if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1395 wpa_printf(MSG_DEBUG, "athr: frame too short");
1398 os_memcpy(&freq, tbuf, sizeof(freq));
1399 os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1400 sizeof(frame_type));
1401 mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1402 data_len -= sizeof(freq) + sizeof(frame_type);
1404 if (frame_type == IEEE80211_EV_RX_MGMT) {
1405 fc = le_to_host16(mgmt->frame_control);
1406 stype = WLAN_FC_GET_STYPE(fc);
1408 wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1409 "freq=%u len=%u", stype, freq, (int) data_len);
1411 if (stype == WLAN_FC_STYPE_ACTION) {
1412 os_memset(&event, 0, sizeof(event));
1413 event.rx_mgmt.frame = (const u8 *) mgmt;
1414 event.rx_mgmt.frame_len = data_len;
1415 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1420 wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1421 __func__, frame_type);
1428 atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1429 int opcode, char *buf, int len)
1432 case IEEE80211_EV_RX_MGMT:
1433 wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1434 fetch_pending_big_events(drv);
1442 atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1443 char *data, int len)
1445 struct iw_event iwe_buf, *iwe = &iwe_buf;
1446 char *pos, *end, *custom, *buf;
1451 while (pos + IW_EV_LCP_LEN <= end) {
1452 /* Event data may be unaligned, so make a local, aligned copy
1453 * before processing. */
1454 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1455 wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1456 iwe->cmd, iwe->len);
1457 if (iwe->len <= IW_EV_LCP_LEN)
1460 custom = pos + IW_EV_POINT_LEN;
1461 if (drv->we_version > 18 &&
1462 (iwe->cmd == IWEVMICHAELMICFAILURE ||
1463 iwe->cmd == IWEVASSOCREQIE ||
1464 iwe->cmd == IWEVCUSTOM)) {
1465 /* WE-19 removed the pointer from struct iw_point */
1466 char *dpos = (char *) &iwe_buf.u.data.length;
1467 int dlen = dpos - (char *) &iwe_buf;
1468 memcpy(dpos, pos + IW_EV_LCP_LEN,
1469 sizeof(struct iw_event) - dlen);
1471 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1472 custom += IW_EV_POINT_OFF;
1477 drv_event_disassoc(drv->hapd,
1478 (u8 *) iwe->u.addr.sa_data);
1480 case IWEVREGISTERED:
1481 atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1483 case IWEVASSOCREQIE:
1484 /* Driver hack.. Use IWEVASSOCREQIE to bypass
1485 * IWEVCUSTOM size limitations. Need to handle this
1486 * just like IWEVCUSTOM.
1489 if (custom + iwe->u.data.length > end)
1491 buf = malloc(iwe->u.data.length + 1);
1494 memcpy(buf, custom, iwe->u.data.length);
1495 buf[iwe->u.data.length] = '\0';
1497 if (iwe->u.data.flags != 0) {
1498 atheros_wireless_event_atheros_custom(
1499 drv, (int) iwe->u.data.flags,
1502 atheros_wireless_event_wireless_custom(
1503 drv, buf, buf + iwe->u.data.length);
1515 atheros_wireless_event_rtm_newlink(void *ctx,
1516 struct ifinfomsg *ifi, u8 *buf, size_t len)
1518 struct atheros_driver_data *drv = ctx;
1519 int attrlen, rta_len;
1520 struct rtattr *attr;
1522 if (ifi->ifi_index != drv->ifindex)
1526 attr = (struct rtattr *) buf;
1528 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1529 while (RTA_OK(attr, attrlen)) {
1530 if (attr->rta_type == IFLA_WIRELESS) {
1531 atheros_wireless_event_wireless(
1532 drv, ((char *) attr) + rta_len,
1533 attr->rta_len - rta_len);
1535 attr = RTA_NEXT(attr, attrlen);
1541 atheros_get_we_version(struct atheros_driver_data *drv)
1543 struct iw_range *range;
1548 drv->we_version = 0;
1551 * Use larger buffer than struct iw_range in order to allow the
1552 * structure to grow in the future.
1554 buflen = sizeof(struct iw_range) + 500;
1555 range = os_zalloc(buflen);
1559 memset(&iwr, 0, sizeof(iwr));
1560 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1561 iwr.u.data.pointer = (caddr_t) range;
1562 iwr.u.data.length = buflen;
1564 minlen = ((char *) &range->enc_capa) - (char *) range +
1565 sizeof(range->enc_capa);
1567 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1568 perror("ioctl[SIOCGIWRANGE]");
1571 } else if (iwr.u.data.length >= minlen &&
1572 range->we_version_compiled >= 18) {
1573 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1574 "WE(source)=%d enc_capa=0x%x",
1575 range->we_version_compiled,
1576 range->we_version_source,
1578 drv->we_version = range->we_version_compiled;
1587 atheros_wireless_event_init(struct atheros_driver_data *drv)
1589 struct netlink_config *cfg;
1591 atheros_get_we_version(drv);
1593 cfg = os_zalloc(sizeof(*cfg));
1597 cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1598 drv->netlink = netlink_init(cfg);
1599 if (drv->netlink == NULL) {
1609 atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1610 int encrypt, const u8 *own_addr, u32 flags)
1612 struct atheros_driver_data *drv = priv;
1613 unsigned char buf[3000];
1614 unsigned char *bp = buf;
1615 struct l2_ethhdr *eth;
1620 * Prepend the Ethernet header. If the caller left us
1621 * space at the front we could just insert it but since
1622 * we don't know we copy to a local buffer. Given the frequency
1623 * and size of frames this probably doesn't matter.
1625 len = data_len + sizeof(struct l2_ethhdr);
1626 if (len > sizeof(buf)) {
1629 printf("EAPOL frame discarded, cannot malloc temp "
1630 "buffer of size %lu!\n", (unsigned long) len);
1634 eth = (struct l2_ethhdr *) bp;
1635 memcpy(eth->h_dest, addr, ETH_ALEN);
1636 memcpy(eth->h_source, own_addr, ETH_ALEN);
1637 eth->h_proto = host_to_be16(ETH_P_EAPOL);
1638 memcpy(eth+1, data, data_len);
1640 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1642 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1650 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1652 struct atheros_driver_data *drv = ctx;
1653 drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1654 len - sizeof(struct l2_ethhdr));
1658 atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1660 struct atheros_driver_data *drv;
1663 char brname[IFNAMSIZ];
1665 drv = os_zalloc(sizeof(struct atheros_driver_data));
1667 printf("Could not allocate memory for atheros driver data\n");
1672 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1673 if (drv->ioctl_sock < 0) {
1674 perror("socket[PF_INET,SOCK_DGRAM]");
1677 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1679 memset(&ifr, 0, sizeof(ifr));
1680 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1681 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1682 perror("ioctl(SIOCGIFINDEX)");
1685 drv->ifindex = ifr.ifr_ifindex;
1687 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1688 handle_read, drv, 1);
1689 if (drv->sock_xmit == NULL)
1691 if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1693 os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
1694 if (params->bridge[0]) {
1695 wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1697 drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1698 ETH_P_EAPOL, handle_read, drv,
1700 if (drv->sock_recv == NULL)
1702 } else if (linux_br_get(brname, drv->iface) == 0) {
1703 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1704 "EAPOL receive", brname);
1705 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1706 handle_read, drv, 1);
1707 if (drv->sock_recv == NULL)
1710 drv->sock_recv = drv->sock_xmit;
1712 memset(&iwr, 0, sizeof(iwr));
1713 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1715 iwr.u.mode = IW_MODE_MASTER;
1717 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1718 perror("ioctl[SIOCSIWMODE]");
1719 printf("Could not set interface to master mode!\n");
1723 /* mark down during setup */
1724 linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1725 atheros_set_privacy(drv, 0); /* default to no privacy */
1727 if (atheros_receive_pkt(drv))
1730 if (atheros_wireless_event_init(drv))
1735 atheros_reset_appfilter(drv);
1737 l2_packet_deinit(drv->sock_raw);
1738 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1739 l2_packet_deinit(drv->sock_recv);
1740 if (drv->sock_xmit != NULL)
1741 l2_packet_deinit(drv->sock_xmit);
1742 if (drv->ioctl_sock >= 0)
1743 close(drv->ioctl_sock);
1751 atheros_deinit(void *priv)
1753 struct atheros_driver_data *drv = priv;
1755 atheros_reset_appfilter(drv);
1756 netlink_deinit(drv->netlink);
1757 (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1758 if (drv->ioctl_sock >= 0)
1759 close(drv->ioctl_sock);
1760 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1761 l2_packet_deinit(drv->sock_recv);
1762 if (drv->sock_xmit != NULL)
1763 l2_packet_deinit(drv->sock_xmit);
1765 l2_packet_deinit(drv->sock_raw);
1766 wpabuf_free(drv->wpa_ie);
1767 wpabuf_free(drv->wps_beacon_ie);
1768 wpabuf_free(drv->wps_probe_resp_ie);
1773 atheros_set_ssid(void *priv, const u8 *buf, int len)
1775 struct atheros_driver_data *drv = priv;
1778 memset(&iwr, 0, sizeof(iwr));
1779 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1780 iwr.u.essid.flags = 1; /* SSID active */
1781 iwr.u.essid.pointer = (caddr_t) buf;
1782 iwr.u.essid.length = len + 1;
1784 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1785 perror("ioctl[SIOCSIWESSID]");
1786 printf("len=%d\n", len);
1793 atheros_get_ssid(void *priv, u8 *buf, int len)
1795 struct atheros_driver_data *drv = priv;
1799 memset(&iwr, 0, sizeof(iwr));
1800 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1801 iwr.u.essid.pointer = (caddr_t) buf;
1802 iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1803 IW_ESSID_MAX_SIZE : len;
1805 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1806 perror("ioctl[SIOCGIWESSID]");
1809 ret = iwr.u.essid.length;
1815 atheros_set_countermeasures(void *priv, int enabled)
1817 struct atheros_driver_data *drv = priv;
1818 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1819 return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1823 atheros_commit(void *priv)
1825 struct atheros_driver_data *drv = priv;
1826 return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1829 static int atheros_set_authmode(void *priv, int auth_algs)
1833 if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1834 (auth_algs & WPA_AUTH_ALG_SHARED))
1835 authmode = IEEE80211_AUTH_AUTO;
1836 else if (auth_algs & WPA_AUTH_ALG_OPEN)
1837 authmode = IEEE80211_AUTH_OPEN;
1838 else if (auth_algs & WPA_AUTH_ALG_SHARED)
1839 authmode = IEEE80211_AUTH_SHARED;
1843 return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1846 static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1849 * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1850 * set_generic_elem, and hapd_set_ssid.
1853 wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1854 "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1855 "wpa_version=0x%x privacy=%d interworking=%d",
1856 params->pairwise_ciphers, params->group_cipher,
1857 params->key_mgmt_suites, params->auth_algs,
1858 params->wpa_version, params->privacy, params->interworking);
1859 wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1860 params->ssid, params->ssid_len);
1862 wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1863 MAC2STR(params->hessid));
1864 wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1865 params->beacon_ies);
1866 wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1867 params->proberesp_ies);
1868 wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1869 params->assocresp_ies);
1875 #ifdef CONFIG_IEEE80211R
1877 static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1880 struct atheros_driver_data *drv = priv;
1882 const struct ieee80211_mgmt *mgmt;
1883 struct ieee80211req_mgmtbuf *mgmt_frm;
1885 mgmt = (const struct ieee80211_mgmt *) frm;
1886 wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1887 (unsigned long) data_len, MAC2STR(mgmt->da));
1888 mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1889 memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1890 mgmt_frm->buflen = data_len;
1891 if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1892 wpa_printf(MSG_INFO, "atheros: Too long frame for "
1893 "atheros_send_mgmt (%u)", (unsigned int) data_len);
1896 os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1897 return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1898 sizeof(struct ieee80211req_mgmtbuf) + data_len);
1902 static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1905 struct atheros_driver_data *drv = priv;
1907 struct ieee80211req_res req;
1908 struct ieee80211req_res_addts *addts = &req.u.addts;
1910 wpa_printf(MSG_DEBUG, "%s", __func__);
1911 req.type = IEEE80211_RESREQ_ADDTS;
1912 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1913 os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
1914 retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1915 sizeof(struct ieee80211req_res));
1917 wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
1918 "retv = %d", __func__, retv);
1921 os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
1922 return addts->status;
1926 static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
1928 struct atheros_driver_data *drv = priv;
1929 struct ieee80211req_res req;
1930 struct ieee80211req_res_addnode *addnode = &req.u.addnode;
1932 wpa_printf(MSG_DEBUG, "%s", __func__);
1933 req.type = IEEE80211_RESREQ_ADDNODE;
1934 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1935 addnode->auth_alg = auth_alg;
1936 return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1937 sizeof(struct ieee80211req_res));
1940 #endif /* CONFIG_IEEE80211R */
1943 /* Use only to set a big param, get will not work. */
1945 set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
1949 os_memset(&iwr, 0, sizeof(iwr));
1950 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1952 iwr.u.data.pointer = (void *) data;
1953 iwr.u.data.length = len;
1954 iwr.u.data.flags = op;
1955 wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
1956 __func__, op, op, athr_get_param_name(op), len);
1958 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
1959 wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
1960 "value=0x%x,0x%x failed: %d (%s)",
1961 __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
1962 iwr.u.mode, iwr.u.data.length,
1963 iwr.u.data.flags, errno, strerror(errno));
1970 static int atheros_send_action(void *priv, unsigned int freq,
1972 const u8 *dst, const u8 *src,
1974 const u8 *data, size_t data_len, int no_cck)
1976 struct atheros_driver_data *drv = priv;
1977 struct ieee80211_p2p_send_action *act;
1980 act = os_zalloc(sizeof(*act) + data_len);
1984 os_memcpy(act->dst_addr, dst, ETH_ALEN);
1985 os_memcpy(act->src_addr, src, ETH_ALEN);
1986 os_memcpy(act->bssid, bssid, ETH_ALEN);
1987 os_memcpy(act + 1, data, data_len);
1988 wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
1989 MACSTR ", bssid=" MACSTR,
1990 __func__, act->freq, wait, MAC2STR(act->dst_addr),
1991 MAC2STR(act->src_addr), MAC2STR(act->bssid));
1992 wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
1993 wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
1995 res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
1996 act, sizeof(*act) + data_len);
2002 #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
2003 static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
2004 u8 *ie, u16 *len, enum wnm_oper oper)
2006 #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
2007 u8 buf[IEEE80211_APPIE_MAX];
2008 struct ieee80211req_getset_appiebuf *tfs_ie;
2011 wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
2012 drv->iface, oper, MAC2STR(peer));
2015 case WNM_SLEEP_TFS_REQ_IE_SET:
2016 if (*len > IEEE80211_APPIE_MAX -
2017 sizeof(struct ieee80211req_getset_appiebuf)) {
2018 wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
2021 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2022 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2023 tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
2025 /* Command header for driver */
2026 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2028 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2030 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2033 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
2035 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2036 IEEE80211_APPIE_MAX)) {
2037 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2038 "%s", __func__, strerror(errno));
2042 case WNM_SLEEP_TFS_RESP_IE_ADD:
2043 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2044 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2045 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2046 sizeof(struct ieee80211req_getset_appiebuf);
2047 /* Command header for driver */
2048 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2050 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2052 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2054 if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2055 IEEE80211_APPIE_MAX)) {
2056 wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2057 "%s", __func__, strerror(errno));
2061 *len = tfs_ie->app_buflen;
2062 os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2063 wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2066 case WNM_SLEEP_TFS_RESP_IE_NONE:
2069 case WNM_SLEEP_TFS_IE_DEL:
2070 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2071 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2072 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2073 sizeof(struct ieee80211req_getset_appiebuf);
2074 /* Command header for driver */
2075 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2077 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2079 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2081 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2082 IEEE80211_APPIE_MAX)) {
2083 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2084 "%s", __func__, strerror(errno));
2089 wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2097 static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2098 const u8 *peer, enum wnm_oper oper)
2105 wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2106 oper, MAC2STR(peer));
2108 dlen = ETH_ALEN + 2 + 2;
2109 data = os_malloc(dlen);
2113 /* Command header for driver */
2115 os_memcpy(pos, peer, ETH_ALEN);
2119 os_memcpy(pos, &val, 2);
2123 os_memcpy(pos, &val, 2);
2125 ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2133 static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2134 u8 *buf, u16 *buf_len)
2136 struct atheros_driver_data *drv = priv;
2139 case WNM_SLEEP_ENTER_CONFIRM:
2140 case WNM_SLEEP_ENTER_FAIL:
2141 case WNM_SLEEP_EXIT_CONFIRM:
2142 case WNM_SLEEP_EXIT_FAIL:
2143 return atheros_wnm_sleep(drv, peer, oper);
2144 case WNM_SLEEP_TFS_REQ_IE_SET:
2145 case WNM_SLEEP_TFS_RESP_IE_ADD:
2146 case WNM_SLEEP_TFS_RESP_IE_NONE:
2147 case WNM_SLEEP_TFS_IE_DEL:
2148 return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2150 wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2155 #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2158 const struct wpa_driver_ops wpa_driver_atheros_ops = {
2160 .hapd_init = atheros_init,
2161 .hapd_deinit = atheros_deinit,
2162 .set_ieee8021x = atheros_set_ieee8021x,
2163 .set_privacy = atheros_set_privacy,
2164 .set_key = atheros_set_key,
2165 .get_seqnum = atheros_get_seqnum,
2166 .flush = atheros_flush,
2167 .set_generic_elem = atheros_set_opt_ie,
2168 .sta_set_flags = atheros_sta_set_flags,
2169 .read_sta_data = atheros_read_sta_driver_data,
2170 .hapd_send_eapol = atheros_send_eapol,
2171 .sta_disassoc = atheros_sta_disassoc,
2172 .sta_deauth = atheros_sta_deauth,
2173 .hapd_set_ssid = atheros_set_ssid,
2174 .hapd_get_ssid = atheros_get_ssid,
2175 .set_countermeasures = atheros_set_countermeasures,
2176 .sta_clear_stats = atheros_sta_clear_stats,
2177 .commit = atheros_commit,
2178 .set_ap_wps_ie = atheros_set_ap_wps_ie,
2179 .set_authmode = atheros_set_authmode,
2180 .set_ap = atheros_set_ap,
2181 #ifdef CONFIG_IEEE80211R
2182 .sta_assoc = atheros_sta_assoc,
2183 .sta_auth = atheros_sta_auth,
2184 .send_mlme = atheros_send_mgmt,
2185 .add_tspec = atheros_add_tspec,
2186 .add_sta_node = atheros_add_sta_node,
2187 #endif /* CONFIG_IEEE80211R */
2188 .send_action = atheros_send_action,
2189 #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
2190 .wnm_oper = atheros_wnm_oper,
2191 #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2192 .set_qos_map = atheros_set_qos_map,