blob: 7d301f790f8d9ea67eedfd7fce2f8bf853064cd4 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
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
7 *
Dmitry Shmidt04949592012-07-19 12:16:46 -07008 * This software may be distributed under the terms of the BSD license.
9 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010 */
11
12#include "includes.h"
13#include <net/if.h>
14#include <sys/ioctl.h>
15
16#include "common.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070017#include "eloop.h"
18#include "common/ieee802_11_defs.h"
19#include "l2_packet/l2_packet.h"
20#include "p2p/p2p.h"
21
22#include "common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#ifndef _BYTE_ORDER
24#ifdef WORDS_BIGENDIAN
25#define _BYTE_ORDER _BIG_ENDIAN
26#else
27#define _BYTE_ORDER _LITTLE_ENDIAN
28#endif
29#endif /* _BYTE_ORDER */
30
31/*
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.
34 */
35#define ATH_WPS_IE
36
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#include "ieee80211_external.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038
39
40#ifdef CONFIG_WPS
41#include <netpacket/packet.h>
Dmitry Shmidt04949592012-07-19 12:16:46 -070042#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043
44#ifndef ETH_P_80211_RAW
45#define ETH_P_80211_RAW 0x0019
46#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080048#include "linux_wext.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049
50#include "driver.h"
51#include "eloop.h"
52#include "priv_netlink.h"
53#include "l2_packet/l2_packet.h"
54#include "common/ieee802_11_defs.h"
55#include "netlink.h"
56#include "linux_ioctl.h"
57
58
59struct atheros_driver_data {
60 struct hostapd_data *hapd; /* back pointer */
61
62 char iface[IFNAMSIZ + 1];
63 int ifindex;
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;
68 int we_version;
69 u8 acct_mac[ETH_ALEN];
70 struct hostap_sta_driver_data acct_data;
71
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;
Dmitry Shmidt04949592012-07-19 12:16:46 -070076 u8 own_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077};
78
79static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
80 int reason_code);
81static int atheros_set_privacy(void *priv, int enabled);
82
83static const char * athr_get_ioctl_name(int op)
84{
85 switch (op) {
86 case IEEE80211_IOCTL_SETPARAM:
87 return "SETPARAM";
88 case IEEE80211_IOCTL_GETPARAM:
89 return "GETPARAM";
90 case IEEE80211_IOCTL_SETKEY:
91 return "SETKEY";
92 case IEEE80211_IOCTL_SETWMMPARAMS:
93 return "SETWMMPARAMS";
94 case IEEE80211_IOCTL_DELKEY:
95 return "DELKEY";
96 case IEEE80211_IOCTL_GETWMMPARAMS:
97 return "GETWMMPARAMS";
98 case IEEE80211_IOCTL_SETMLME:
99 return "SETMLME";
100 case IEEE80211_IOCTL_GETCHANINFO:
101 return "GETCHANINFO";
102 case IEEE80211_IOCTL_SETOPTIE:
103 return "SETOPTIE";
104 case IEEE80211_IOCTL_GETOPTIE:
105 return "GETOPTIE";
106 case IEEE80211_IOCTL_ADDMAC:
107 return "ADDMAC";
108 case IEEE80211_IOCTL_DELMAC:
109 return "DELMAC";
110 case IEEE80211_IOCTL_GETCHANLIST:
111 return "GETCHANLIST";
112 case IEEE80211_IOCTL_SETCHANLIST:
113 return "SETCHANLIST";
114 case IEEE80211_IOCTL_KICKMAC:
115 return "KICKMAC";
116 case IEEE80211_IOCTL_CHANSWITCH:
117 return "CHANSWITCH";
118 case IEEE80211_IOCTL_GETMODE:
119 return "GETMODE";
120 case IEEE80211_IOCTL_SETMODE:
121 return "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:
141 return "STA_STATS";
142 case IEEE80211_IOCTL_GETWPAIE:
143 return "GETWPAIE";
144 default:
145 return "??";
146 }
147}
148
149
150static const char * athr_get_param_name(int op)
151{
152 switch (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:
160 return "KEYMGTALGS";
161 case IEEE80211_PARAM_RSNCAPS:
162 return "RSNCAPS";
163 case IEEE80211_PARAM_WPA:
164 return "WPA";
165 case IEEE80211_PARAM_AUTHMODE:
166 return "AUTHMODE";
167 case IEEE80211_PARAM_PRIVACY:
168 return "PRIVACY";
169 case IEEE80211_PARAM_COUNTERMEASURES:
170 return "COUNTERMEASURES";
171 default:
172 return "??";
173 }
174}
175
176
177static int
178set80211priv(struct atheros_driver_data *drv, int op, void *data, int len)
179{
180 struct iwreq iwr;
181 int do_inline = len < IFNAMSIZ;
182
183 /* Certain ioctls must use the non-inlined method */
184 if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
185 op == IEEE80211_IOCTL_FILTERFRAME)
186 do_inline = 0;
187
188 memset(&iwr, 0, sizeof(iwr));
189 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
190 if (do_inline) {
191 /*
192 * Argument data fits inline; put it there.
193 */
194 memcpy(iwr.u.name, data, len);
195 } else {
196 /*
197 * Argument data too big for inline transfer; setup a
198 * parameter block instead; the kernel will transfer
199 * the data for the driver.
200 */
201 iwr.u.data.pointer = data;
202 iwr.u.data.length = len;
203 }
204
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));
211 return -1;
212 }
213 return 0;
214}
215
216static int
217set80211param(struct atheros_driver_data *drv, int op, int arg)
218{
219 struct iwreq iwr;
220
221 memset(&iwr, 0, sizeof(iwr));
222 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
223 iwr.u.mode = op;
224 memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
225
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);
231 return -1;
232 }
233 return 0;
234}
235
236#ifndef CONFIG_NO_STDOUT_DEBUG
237static const char *
238ether_sprintf(const u8 *addr)
239{
240 static char buf[sizeof(MACSTR)];
241
242 if (addr != NULL)
243 snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
244 else
245 snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
246 return buf;
247}
248#endif /* CONFIG_NO_STDOUT_DEBUG */
249
250/*
251 * Configure WPA parameters.
252 */
253static int
254atheros_configure_wpa(struct atheros_driver_data *drv,
255 struct wpa_bss_params *params)
256{
257 int v;
258
259 switch (params->wpa_group) {
260 case WPA_CIPHER_CCMP:
261 v = IEEE80211_CIPHER_AES_CCM;
262 break;
263 case WPA_CIPHER_TKIP:
264 v = IEEE80211_CIPHER_TKIP;
265 break;
266 case WPA_CIPHER_WEP104:
267 v = IEEE80211_CIPHER_WEP;
268 break;
269 case WPA_CIPHER_WEP40:
270 v = IEEE80211_CIPHER_WEP;
271 break;
272 case WPA_CIPHER_NONE:
273 v = IEEE80211_CIPHER_NONE;
274 break;
275 default:
276 wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
277 params->wpa_group);
278 return -1;
279 }
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);
283 return -1;
284 }
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);
290 return -1;
291 }
292 }
293
294 v = 0;
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);
304 return -1;
305 }
306
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);
313 return -1;
314 }
315
316 v = 0;
317 if (params->rsn_preauth)
318 v |= BIT(0);
319#ifdef CONFIG_IEEE80211W
320 if (params->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
321 v |= BIT(7);
322 if (params->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
323 v |= BIT(6);
324 }
325#endif /* CONFIG_IEEE80211W */
326
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700327 wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
329 printf("Unable to set RSN capabilities to 0x%x\n", v);
330 return -1;
331 }
332
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);
336 return -1;
337 }
338 return 0;
339}
340
341static int
342atheros_set_ieee8021x(void *priv, struct wpa_bss_params *params)
343{
344 struct atheros_driver_data *drv = priv;
345
346 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
347
348 if (!params->enabled) {
349 /* XXX restore state */
350 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
351 IEEE80211_AUTH_AUTO) < 0)
352 return -1;
353 /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
354 return atheros_set_privacy(drv, 0);
355 }
356 if (!params->wpa && !params->ieee802_1x) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800357 wpa_printf(MSG_WARNING, "No 802.1X or WPA enabled!");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358 return -1;
359 }
360 if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800361 wpa_printf(MSG_WARNING, "Error configuring WPA state!");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 return -1;
363 }
364 if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
365 (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800366 wpa_printf(MSG_WARNING, "Error enabling WPA/802.1X!");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367 return -1;
368 }
369
370 return 0;
371}
372
373static int
374atheros_set_privacy(void *priv, int enabled)
375{
376 struct atheros_driver_data *drv = priv;
377
378 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
379
380 return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
381}
382
383static int
384atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
385{
386 struct atheros_driver_data *drv = priv;
387 struct ieee80211req_mlme mlme;
388 int ret;
389
390 wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
391 __func__, ether_sprintf(addr), authorized);
392
393 if (authorized)
394 mlme.im_op = IEEE80211_MLME_AUTHORIZE;
395 else
396 mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
397 mlme.im_reason = 0;
398 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
399 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
400 if (ret < 0) {
401 wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
402 __func__, authorized ? "" : "un", MAC2STR(addr));
403 }
404
405 return ret;
406}
407
408static int
409atheros_sta_set_flags(void *priv, const u8 *addr,
410 int total_flags, int flags_or, int flags_and)
411{
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);
417 return 0;
418}
419
420static int
421atheros_del_key(void *priv, const u8 *addr, int key_idx)
422{
423 struct atheros_driver_data *drv = priv;
424 struct ieee80211req_del_key wk;
425 int ret;
426
427 wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
428 __func__, ether_sprintf(addr), key_idx);
429
430 memset(&wk, 0, sizeof(wk));
431 if (addr != NULL) {
432 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
433 wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
434 } else {
435 wk.idk_keyix = key_idx;
436 }
437
438 ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
439 if (ret < 0) {
440 wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
441 " key_idx %d)", __func__, ether_sprintf(addr),
442 key_idx);
443 }
444
445 return ret;
446}
447
448static int
449atheros_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)
452{
453 struct atheros_driver_data *drv = priv;
454 struct ieee80211req_key wk;
455 u_int8_t cipher;
456 int ret;
457
458 if (alg == WPA_ALG_NONE)
459 return atheros_del_key(drv, addr, key_idx);
460
461 wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
462 __func__, alg, ether_sprintf(addr), key_idx);
463
464 switch (alg) {
465 case WPA_ALG_WEP:
466 cipher = IEEE80211_CIPHER_WEP;
467 break;
468 case WPA_ALG_TKIP:
469 cipher = IEEE80211_CIPHER_TKIP;
470 break;
471 case WPA_ALG_CCMP:
472 cipher = IEEE80211_CIPHER_AES_CCM;
473 break;
474#ifdef CONFIG_IEEE80211W
475 case WPA_ALG_IGTK:
476 cipher = IEEE80211_CIPHER_AES_CMAC;
477 break;
478#endif /* CONFIG_IEEE80211W */
479 default:
480 printf("%s: unknown/unsupported algorithm %d\n",
481 __func__, alg);
482 return -1;
483 }
484
485 if (key_len > sizeof(wk.ik_keydata)) {
486 printf("%s: key length %lu too big\n", __func__,
487 (unsigned long) key_len);
488 return -3;
489 }
490
491 memset(&wk, 0, sizeof(wk));
492 wk.ik_type = cipher;
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;
497 if (set_tx)
498 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
499 } else {
500 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
501 wk.ik_keyix = IEEE80211_KEYIX_NONE;
502 }
503 wk.ik_keylen = key_len;
504 memcpy(wk.ik_keydata, key, key_len);
505
506 ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
507 if (ret < 0) {
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);
512 }
513
514 return ret;
515}
516
517
518static int
519atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
520 u8 *seq)
521{
522 struct atheros_driver_data *drv = priv;
523 struct ieee80211req_key wk;
524
525 wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
526 __func__, ether_sprintf(addr), idx);
527
528 memset(&wk, 0, sizeof(wk));
529 if (addr == NULL)
530 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
531 else
532 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
533 wk.ik_keyix = idx;
534
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);
539 return -1;
540 }
541
542#ifdef WORDS_BIGENDIAN
543 {
544 /*
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.
547 */
548 int i;
549#ifndef WPA_KEY_RSC_LEN
550#define WPA_KEY_RSC_LEN 8
551#endif
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];
556 }
557 }
558#else /* WORDS_BIGENDIAN */
559 memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
560#endif /* WORDS_BIGENDIAN */
561 return 0;
562}
563
564
565static int
566atheros_flush(void *priv)
567{
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);
572}
573
574
575static int
576atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
577 const u8 *addr)
578{
579 struct atheros_driver_data *drv = priv;
580 struct ieee80211req_sta_stats stats;
581
582 memset(data, 0, sizeof(*data));
583
584 /*
585 * Fetch statistics for station from the system.
586 */
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));
595 return 0;
596 }
597
598 printf("Failed to get station stats information element.\n");
599 return -1;
600 }
601
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;
606 return 0;
607}
608
609
610static int
611atheros_sta_clear_stats(void *priv, const u8 *addr)
612{
613 struct atheros_driver_data *drv = priv;
614 struct ieee80211req_mlme mlme;
615 int ret;
616
617 wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
618
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,
622 sizeof(mlme));
623 if (ret < 0) {
624 wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
625 MACSTR ")", __func__, MAC2STR(addr));
626 }
627
628 return ret;
629}
630
631
632static int
633atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
634{
635 struct atheros_driver_data *drv = priv;
636 u8 buf[512];
637 struct ieee80211req_getset_appiebuf *app_ie;
638
639 wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
640 (unsigned long) ie_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800641 wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642
643 wpabuf_free(drv->wpa_ie);
644 drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
645
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;
649
650 app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
651
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);
658 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800659 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
660 app_ie->app_buf, app_ie->app_buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
662 sizeof(struct ieee80211req_getset_appiebuf) +
663 app_ie->app_buflen);
664
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);
673 } else
674 app_ie->app_buflen = ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800675 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
676 app_ie->app_buf, app_ie->app_buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
678 sizeof(struct ieee80211req_getset_appiebuf) +
679 app_ie->app_buflen);
680 return 0;
681}
682
683static int
684atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
685 int reason_code)
686{
687 struct atheros_driver_data *drv = priv;
688 struct ieee80211req_mlme mlme;
689 int ret;
690
691 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
692 __func__, ether_sprintf(addr), reason_code);
693
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));
698 if (ret < 0) {
699 wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
700 " reason %d)",
701 __func__, MAC2STR(addr), reason_code);
702 }
703
704 return ret;
705}
706
707static int
708atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
709 int reason_code)
710{
711 struct atheros_driver_data *drv = priv;
712 struct ieee80211req_mlme mlme;
713 int ret;
714
715 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
716 __func__, ether_sprintf(addr), reason_code);
717
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));
722 if (ret < 0) {
723 wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
724 MACSTR " reason %d)",
725 __func__, MAC2STR(addr), reason_code);
726 }
727
728 return ret;
729}
730
731#ifdef CONFIG_WPS
Dmitry Shmidt04949592012-07-19 12:16:46 -0700732static void atheros_raw_recv_wps(void *ctx, const u8 *src_addr, const u8 *buf,
733 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734{
735 struct atheros_driver_data *drv = ctx;
736 const struct ieee80211_mgmt *mgmt;
737 u16 fc;
738 union wpa_event_data event;
739
740 /* Send Probe Request information to WPS processing */
741
742 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
743 return;
744 mgmt = (const struct ieee80211_mgmt *) buf;
745
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)
749 return;
750
751 os_memset(&event, 0, sizeof(event));
752 event.rx_probe_req.sa = mgmt->sa;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800753 event.rx_probe_req.da = mgmt->da;
754 event.rx_probe_req.bssid = mgmt->bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755 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);
759}
760#endif /* CONFIG_WPS */
761
Dmitry Shmidt04949592012-07-19 12:16:46 -0700762#ifdef CONFIG_IEEE80211R
763static void atheros_raw_recv_11r(void *ctx, const u8 *src_addr, const u8 *buf,
764 size_t len)
765{
766 struct atheros_driver_data *drv = ctx;
767 union wpa_event_data event;
768 const struct ieee80211_mgmt *mgmt;
769 u16 fc;
770 u16 stype;
771 int ielen;
772 const u8 *iebuf;
773
774 /* Do 11R processing for ASSOC/AUTH/FT ACTION frames */
775 if (len < IEEE80211_HDRLEN)
776 return;
777 mgmt = (const struct ieee80211_mgmt *) buf;
778
779 fc = le_to_host16(mgmt->frame_control);
780
781 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
782 return;
783 stype = WLAN_FC_GET_STYPE(fc);
784
785 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
786 (int) len);
787
788 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
789 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
790 __func__);
791 return;
792 }
793 switch (stype) {
794 case WLAN_FC_STYPE_ASSOC_REQ:
795 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.assoc_req))
796 break;
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);
800 break;
801 case WLAN_FC_STYPE_REASSOC_REQ:
802 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.reassoc_req))
803 break;
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);
807 break;
808 case WLAN_FC_STYPE_ACTION:
809 if (&mgmt->u.action.category > buf + len)
810 break;
811 os_memset(&event, 0, sizeof(event));
812 event.rx_action.da = mgmt->da;
813 event.rx_action.sa = mgmt->sa;
814 event.rx_action.bssid = mgmt->bssid;
815 event.rx_action.category = mgmt->u.action.category;
816 event.rx_action.data = &mgmt->u.action.category;
817 event.rx_action.len = buf + len - event.rx_action.data;
818 wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
819 break;
820 case WLAN_FC_STYPE_AUTH:
821 if (len - IEEE80211_HDRLEN < sizeof(mgmt->u.auth))
822 break;
823 os_memset(&event, 0, sizeof(event));
824 os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
825 os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
826 event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
827 event.auth.status_code =
828 le_to_host16(mgmt->u.auth.status_code);
829 event.auth.auth_transaction =
830 le_to_host16(mgmt->u.auth.auth_transaction);
831 event.auth.ies = mgmt->u.auth.variable;
832 event.auth.ies_len = len - IEEE80211_HDRLEN -
833 sizeof(mgmt->u.auth);
834 wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
835 break;
836 default:
837 break;
838 }
839}
840#endif /* CONFIG_IEEE80211R */
841
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700842#ifdef CONFIG_HS20
843static void atheros_raw_recv_hs20(void *ctx, const u8 *src_addr, const u8 *buf,
844 size_t len)
845{
846 struct atheros_driver_data *drv = ctx;
847 const struct ieee80211_mgmt *mgmt;
848 u16 fc;
849 union wpa_event_data event;
850
851 /* Send the Action frame for HS20 processing */
852
853 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.action.category) +
854 sizeof(mgmt->u.action.u.public_action))
855 return;
856
857 mgmt = (const struct ieee80211_mgmt *) buf;
858
859 fc = le_to_host16(mgmt->frame_control);
860 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
861 WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION ||
862 mgmt->u.action.category != WLAN_ACTION_PUBLIC)
863 return;
864
865 wpa_printf(MSG_DEBUG, "%s:Received Public Action frame", __func__);
866
867 os_memset(&event, 0, sizeof(event));
868 event.rx_mgmt.frame = (const u8 *) mgmt;
869 event.rx_mgmt.frame_len = len;
870 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
871}
Dmitry Shmidt051af732013-10-22 13:52:46 -0700872
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700873#endif /* CONFIG_HS20 */
874
Dmitry Shmidt051af732013-10-22 13:52:46 -0700875
876static int atheros_set_qos_map(void *ctx, const u8 *qos_map_set,
877 u8 qos_map_set_len)
878{
879#ifdef CONFIG_ATHEROS_QOS_MAP
880 struct atheros_driver_data *drv = ctx;
881 struct ieee80211req_athdbg req;
882 struct ieee80211_qos_map *qos_map = &req.data.qos_map;
883 struct iwreq iwr;
884 int i, up_start;
885
886 if (qos_map_set_len < 16 || qos_map_set_len > 58 ||
887 qos_map_set_len & 1) {
888 wpa_printf(MSG_ERROR, "Invalid QoS Map");
889 return -1;
890 } else {
891 memset(&req, 0, sizeof(struct ieee80211req_athdbg));
892 req.cmd = IEEE80211_DBGREQ_SETQOSMAPCONF;
893 os_memset(&iwr, 0, sizeof(iwr));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700894 os_strlcpy(iwr.ifr_name, drv->iface, sizeof(iwr.ifr_name));
Dmitry Shmidt051af732013-10-22 13:52:46 -0700895 iwr.u.data.pointer = (void *) &req;
896 iwr.u.data.length = sizeof(struct ieee80211req_athdbg);
897 }
898
899 qos_map->valid = 1;
900 qos_map->num_dscp_except = (qos_map_set_len - 16) / 2;
901 if (qos_map->num_dscp_except) {
902 for (i = 0; i < qos_map->num_dscp_except; i++) {
903 qos_map->dscp_exception[i].dscp = qos_map_set[i * 2];
904 qos_map->dscp_exception[i].up = qos_map_set[i * 2 + 1];
905 }
906 }
907
908 up_start = qos_map_set_len - 16;
909 for (i = 0; i < IEEE80211_MAX_QOS_UP_RANGE; i++) {
910 qos_map->up[i].low = qos_map_set[up_start + (i * 2)];
911 qos_map->up[i].high = qos_map_set[up_start + (i * 2) + 1];
912 }
913
914 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_DBGREQ, &iwr) < 0) {
915 perror("ioctl[IEEE80211_IOCTL_DBGREQ]");
916 wpa_printf(MSG_DEBUG, "%s: %s: Failed to set QoS Map",
917 __func__, drv->iface);
918 return -1;
919 }
920#endif /* CONFIG_ATHEROS_QOS_MAP */
921
922 return 0;
923}
924
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800925#if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700926static void atheros_raw_recv_11v(void *ctx, const u8 *src_addr, const u8 *buf,
927 size_t len)
928{
929 struct atheros_driver_data *drv = ctx;
930 union wpa_event_data event;
931 const struct ieee80211_mgmt *mgmt;
932 u16 fc;
933 u16 stype;
934
935 /* Do 11R processing for WNM ACTION frames */
936 if (len < IEEE80211_HDRLEN)
937 return;
938 mgmt = (const struct ieee80211_mgmt *) buf;
939
940 fc = le_to_host16(mgmt->frame_control);
941
942 if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
943 return;
944 stype = WLAN_FC_GET_STYPE(fc);
945
946 wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
947 (int) len);
948
949 if (os_memcmp(drv->own_addr, mgmt->bssid, ETH_ALEN) != 0) {
950 wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
951 __func__);
952 return;
953 }
954
955 switch (stype) {
956 case WLAN_FC_STYPE_ACTION:
957 if (&mgmt->u.action.category > buf + len)
958 break;
959 os_memset(&event, 0, sizeof(event));
960 event.rx_action.da = mgmt->da;
961 event.rx_action.sa = mgmt->sa;
962 event.rx_action.bssid = mgmt->bssid;
963 event.rx_action.category = mgmt->u.action.category;
964 event.rx_action.data = &mgmt->u.action.category;
965 event.rx_action.len = buf + len - event.rx_action.data;
966 wpa_supplicant_event(drv->hapd, EVENT_RX_ACTION, &event);
967 break;
968 default:
969 break;
970 }
971}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800972#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700973
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800974#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_WNM)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700975static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
976 size_t len)
977{
978#ifdef CONFIG_WPS
979 atheros_raw_recv_wps(ctx, src_addr, buf, len);
980#endif /* CONFIG_WPS */
981#ifdef CONFIG_IEEE80211R
982 atheros_raw_recv_11r(ctx, src_addr, buf, len);
983#endif /* CONFIG_IEEE80211R */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800984#if defined(CONFIG_WNM) && !defined(CONFIG_IEEE80211R)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700985 atheros_raw_recv_11v(ctx, src_addr, buf, len);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800986#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700987#ifdef CONFIG_HS20
988 atheros_raw_recv_hs20(ctx, src_addr, buf, len);
989#endif /* CONFIG_HS20 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700990}
991#endif /* CONFIG_WPS || CONFIG_IEEE80211R */
992
993static int atheros_receive_pkt(struct atheros_driver_data *drv)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994{
995 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 struct ieee80211req_set_filter filt;
997
998 wpa_printf(MSG_DEBUG, "%s Enter", __func__);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700999 filt.app_filterype = 0;
1000#ifdef CONFIG_WPS
1001 filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
1002#endif /* CONFIG_WPS */
1003#ifdef CONFIG_IEEE80211R
1004 filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001005 IEEE80211_FILTER_TYPE_AUTH |
1006 IEEE80211_FILTER_TYPE_ACTION);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001007#endif
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001008#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001009 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001010#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001011#ifdef CONFIG_HS20
1012 filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
1013#endif /* CONFIG_HS20 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001014 if (filt.app_filterype) {
1015 ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
1016 sizeof(struct ieee80211req_set_filter));
1017 if (ret)
1018 return ret;
1019 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020
Dmitry Shmidt04949592012-07-19 12:16:46 -07001021#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022 drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
1023 atheros_raw_receive, drv, 1);
1024 if (drv->sock_raw == NULL)
1025 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001026#endif /* CONFIG_WPS || CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027 return ret;
1028}
1029
Dmitry Shmidt04949592012-07-19 12:16:46 -07001030static int atheros_reset_appfilter(struct atheros_driver_data *drv)
1031{
1032 struct ieee80211req_set_filter filt;
1033 filt.app_filterype = 0;
1034 return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
1035 sizeof(struct ieee80211req_set_filter));
1036}
1037
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038#ifdef CONFIG_WPS
1039static int
1040atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
1041{
1042 struct atheros_driver_data *drv = priv;
1043 u8 buf[512];
1044 struct ieee80211req_getset_appiebuf *beac_ie;
1045
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
1047 (unsigned long) len, frametype);
1048 wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049
1050 beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
1051 beac_ie->app_frmtype = frametype;
1052 beac_ie->app_buflen = len;
1053 os_memcpy(&(beac_ie->app_buf[0]), ie, len);
1054
1055 /* append the WPA/RSN IE if it is set already */
1056 if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
1057 (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
1058 (drv->wpa_ie != NULL)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001059 wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
1060 drv->wpa_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
1062 wpabuf_len(drv->wpa_ie));
1063 beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
1064 }
1065
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001066 wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
1067 beac_ie->app_buf, beac_ie->app_buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068 return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
1069 sizeof(struct ieee80211req_getset_appiebuf) +
1070 beac_ie->app_buflen);
1071}
1072
1073static int
1074atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1075 const struct wpabuf *proberesp,
1076 const struct wpabuf *assocresp)
1077{
1078 struct atheros_driver_data *drv = priv;
1079
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001080 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1081 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1082 proberesp);
1083 wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1084 assocresp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085 wpabuf_free(drv->wps_beacon_ie);
1086 drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1087 wpabuf_free(drv->wps_probe_resp_ie);
1088 drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1089
1090 atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1091 assocresp ? wpabuf_len(assocresp) : 0,
1092 IEEE80211_APPIE_FRAME_ASSOC_RESP);
1093 if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1094 beacon ? wpabuf_len(beacon) : 0,
1095 IEEE80211_APPIE_FRAME_BEACON))
1096 return -1;
1097 return atheros_set_wps_ie(priv,
1098 proberesp ? wpabuf_head(proberesp) : NULL,
1099 proberesp ? wpabuf_len(proberesp): 0,
1100 IEEE80211_APPIE_FRAME_PROBE_RESP);
1101}
1102#else /* CONFIG_WPS */
1103#define atheros_set_ap_wps_ie NULL
1104#endif /* CONFIG_WPS */
1105
Dmitry Shmidt04949592012-07-19 12:16:46 -07001106#ifdef CONFIG_IEEE80211R
1107static int
1108atheros_sta_auth(void *priv, const u8 *own_addr, const u8 *addr, u16 seq,
1109 u16 status_code, const u8 *ie, size_t len)
1110{
1111 struct atheros_driver_data *drv = priv;
1112 struct ieee80211req_mlme mlme;
1113 int ret;
1114
1115 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1116 __func__, ether_sprintf(addr), status_code);
1117
1118 mlme.im_op = IEEE80211_MLME_AUTH;
1119 mlme.im_reason = status_code;
1120 mlme.im_seq = seq;
1121 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1122 mlme.im_optie_len = len;
1123 if (len) {
1124 if (len < IEEE80211_MAX_OPT_IE) {
1125 os_memcpy(mlme.im_optie, ie, len);
1126 } else {
1127 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1128 "opt_ie STA (addr " MACSTR " reason %d, "
1129 "ie_len %d)",
1130 __func__, MAC2STR(addr), status_code,
1131 (int) len);
1132 return -1;
1133 }
1134 }
1135 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1136 if (ret < 0) {
1137 wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1138 " reason %d)",
1139 __func__, MAC2STR(addr), status_code);
1140 }
1141 return ret;
1142}
1143
1144static int
1145atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1146 int reassoc, u16 status_code, const u8 *ie, size_t len)
1147{
1148 struct atheros_driver_data *drv = priv;
1149 struct ieee80211req_mlme mlme;
1150 int ret;
1151
1152 wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1153 __func__, ether_sprintf(addr), status_code, reassoc);
1154
1155 if (reassoc)
1156 mlme.im_op = IEEE80211_MLME_REASSOC;
1157 else
1158 mlme.im_op = IEEE80211_MLME_ASSOC;
1159 mlme.im_reason = status_code;
1160 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1161 mlme.im_optie_len = len;
1162 if (len) {
1163 if (len < IEEE80211_MAX_OPT_IE) {
1164 os_memcpy(mlme.im_optie, ie, len);
1165 } else {
1166 wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1167 "opt_ie STA (addr " MACSTR " reason %d, "
1168 "ie_len %d)",
1169 __func__, MAC2STR(addr), status_code,
1170 (int) len);
1171 return -1;
1172 }
1173 }
1174 ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1175 if (ret < 0) {
1176 wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1177 " reason %d)",
1178 __func__, MAC2STR(addr), status_code);
1179 }
1180 return ret;
1181}
1182#endif /* CONFIG_IEEE80211R */
1183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184static void
1185atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1186{
1187 struct hostapd_data *hapd = drv->hapd;
1188 struct ieee80211req_wpaie ie;
1189 int ielen = 0;
1190 u8 *iebuf = NULL;
1191
1192 /*
1193 * Fetch negotiated WPA/RSN parameters from the system.
1194 */
1195 memset(&ie, 0, sizeof(ie));
1196 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1197 if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1198 /*
1199 * See ATH_WPS_IE comment in the beginning of the file for a
1200 * possible cause for the failure..
1201 */
1202 wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1203 __func__, strerror(errno));
1204 goto no_ie;
1205 }
1206 wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1207 ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1208 wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1209 ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1210#ifdef ATH_WPS_IE
1211 wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1212 ie.wps_ie, IEEE80211_MAX_OPT_IE);
1213#endif /* ATH_WPS_IE */
1214 iebuf = ie.wpa_ie;
1215 /* atheros seems to return some random data if WPA/RSN IE is not set.
1216 * Assume the IE was not included if the IE type is unknown. */
1217 if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1218 iebuf[1] = 0;
1219 if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1220 /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1221 * set. This is needed for WPA2. */
1222 iebuf = ie.rsn_ie;
1223 if (iebuf[0] != WLAN_EID_RSN)
1224 iebuf[1] = 0;
1225 }
1226
1227 ielen = iebuf[1];
1228
1229#ifdef ATH_WPS_IE
1230 /* if WPS IE is present, preference is given to WPS */
1231 if (ie.wps_ie &&
1232 (ie.wps_ie[1] > 0 && (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC))) {
1233 iebuf = ie.wps_ie;
1234 ielen = ie.wps_ie[1];
1235 }
1236#endif /* ATH_WPS_IE */
1237
1238 if (ielen == 0)
1239 iebuf = NULL;
1240 else
1241 ielen += 2;
1242
1243no_ie:
1244 drv_event_assoc(hapd, addr, iebuf, ielen, 0);
1245
1246 if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
1247 /* Cached accounting data is not valid anymore. */
1248 memset(drv->acct_mac, 0, ETH_ALEN);
1249 memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1250 }
1251}
1252
1253static void
1254atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1255 char *custom, char *end)
1256{
1257 wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1258
1259 if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1260 char *pos;
1261 u8 addr[ETH_ALEN];
1262 pos = strstr(custom, "addr=");
1263 if (pos == NULL) {
1264 wpa_printf(MSG_DEBUG,
1265 "MLME-MICHAELMICFAILURE.indication "
1266 "without sender address ignored");
1267 return;
1268 }
1269 pos += 5;
1270 if (hwaddr_aton(pos, addr) == 0) {
1271 union wpa_event_data data;
1272 os_memset(&data, 0, sizeof(data));
1273 data.michael_mic_failure.unicast = 1;
1274 data.michael_mic_failure.src = addr;
1275 wpa_supplicant_event(drv->hapd,
1276 EVENT_MICHAEL_MIC_FAILURE, &data);
1277 } else {
1278 wpa_printf(MSG_DEBUG,
1279 "MLME-MICHAELMICFAILURE.indication "
1280 "with invalid MAC address");
1281 }
1282 } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1283 char *key, *value;
1284 u32 val;
1285 key = custom;
1286 while ((key = strchr(key, '\n')) != NULL) {
1287 key++;
1288 value = strchr(key, '=');
1289 if (value == NULL)
1290 continue;
1291 *value++ = '\0';
1292 val = strtoul(value, NULL, 10);
1293 if (strcmp(key, "mac") == 0)
1294 hwaddr_aton(value, drv->acct_mac);
1295 else if (strcmp(key, "rx_packets") == 0)
1296 drv->acct_data.rx_packets = val;
1297 else if (strcmp(key, "tx_packets") == 0)
1298 drv->acct_data.tx_packets = val;
1299 else if (strcmp(key, "rx_bytes") == 0)
1300 drv->acct_data.rx_bytes = val;
1301 else if (strcmp(key, "tx_bytes") == 0)
1302 drv->acct_data.tx_bytes = val;
1303 key = value;
1304 }
1305#ifdef CONFIG_WPS
1306 } else if (strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1307 /* Some atheros kernels send push button as a wireless event */
1308 /* PROBLEM! this event is received for ALL BSSs ...
1309 * so all are enabled for WPS... ugh.
1310 */
1311 wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001312#endif /* CONFIG_WPS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001313#if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_HS20)
1314#define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 } else if (strncmp(custom, "Manage.prob_req ", 16) == 0) {
1316 /*
1317 * Atheros driver uses a hack to pass Probe Request frames as a
1318 * binary data in the custom wireless event. The old way (using
1319 * packet sniffing) didn't work when bridging.
1320 * Format: "Manage.prob_req <frame len>" | zero padding | frame
1321 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 int len = atoi(custom + 16);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001323 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1325 "length %d", len);
1326 return;
1327 }
1328 atheros_raw_receive(drv, NULL,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001329 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001330 } else if (strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1331 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1332 * frame */
1333 int len = atoi(custom + 17);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001334 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001335 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1336 "assoc_req/auth event length %d", len);
1337 return;
1338 }
1339 atheros_raw_receive(drv, NULL,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001340 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001341 } else if (strncmp(custom, "Manage.action ", 14) == 0) {
1342 /* Format: "Manage.assoc_req <frame len>" | zero padding |
1343 * frame */
1344 int len = atoi(custom + 14);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001345 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001346 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1347 "assoc_req/auth event length %d", len);
1348 return;
1349 }
1350 atheros_raw_receive(drv, NULL,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001351 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001352 } else if (strncmp(custom, "Manage.auth ", 12) == 0) {
1353 /* Format: "Manage.auth <frame len>" | zero padding | frame
1354 */
1355 int len = atoi(custom + 12);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001356 if (len < 0 || custom + MGMT_FRAM_TAG_SIZE + len > end) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001357 wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req/"
1358 "assoc_req/auth event length %d", len);
1359 return;
1360 }
1361 atheros_raw_receive(drv, NULL,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001362 (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001363#endif /* CONFIG_WPS or CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364 }
1365}
1366
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001367/*
1368* Handle size of data problem. WEXT only allows data of 256 bytes for custom
1369* events, and p2p data can be much bigger. So the athr driver sends a small
1370* event telling me to collect the big data with an ioctl.
1371* On the first event, send all pending events to supplicant.
1372*/
1373static void fetch_pending_big_events(struct atheros_driver_data *drv)
1374{
1375 union wpa_event_data event;
1376 const struct ieee80211_mgmt *mgmt;
1377 u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1378 u16 fc, stype;
1379 struct iwreq iwr;
1380 size_t data_len;
1381 u32 freq, frame_type;
1382
1383 while (1) {
1384 os_memset(&iwr, 0, sizeof(iwr));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001385 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001386
1387 iwr.u.data.pointer = (void *) tbuf;
1388 iwr.u.data.length = sizeof(tbuf);
1389 iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1390
1391 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1392 < 0) {
1393 if (errno == ENOSPC) {
1394 wpa_printf(MSG_DEBUG, "%s:%d exit",
1395 __func__, __LINE__);
1396 return;
1397 }
1398 wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1399 "P2P_FETCH_FRAME] failed: %s",
1400 __func__, strerror(errno));
1401 return;
1402 }
1403 data_len = iwr.u.data.length;
1404 wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1405 (u8 *) tbuf, data_len);
1406 if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1407 wpa_printf(MSG_DEBUG, "athr: frame too short");
1408 continue;
1409 }
1410 os_memcpy(&freq, tbuf, sizeof(freq));
1411 os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1412 sizeof(frame_type));
1413 mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1414 data_len -= sizeof(freq) + sizeof(frame_type);
1415
1416 if (frame_type == IEEE80211_EV_RX_MGMT) {
1417 fc = le_to_host16(mgmt->frame_control);
1418 stype = WLAN_FC_GET_STYPE(fc);
1419
1420 wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1421 "freq=%u len=%u", stype, freq, (int) data_len);
1422
1423 if (stype == WLAN_FC_STYPE_ACTION) {
1424 os_memset(&event, 0, sizeof(event));
1425 event.rx_mgmt.frame = (const u8 *) mgmt;
1426 event.rx_mgmt.frame_len = data_len;
1427 wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1428 &event);
1429 continue;
1430 }
1431 } else {
1432 wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1433 __func__, frame_type);
1434 continue;
1435 }
1436 }
1437}
1438
1439static void
1440atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1441 int opcode, char *buf, int len)
1442{
1443 switch (opcode) {
1444 case IEEE80211_EV_RX_MGMT:
1445 wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1446 fetch_pending_big_events(drv);
1447 break;
1448 default:
1449 break;
1450 }
1451}
1452
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001453static void
1454atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1455 char *data, int len)
1456{
1457 struct iw_event iwe_buf, *iwe = &iwe_buf;
1458 char *pos, *end, *custom, *buf;
1459
1460 pos = data;
1461 end = data + len;
1462
1463 while (pos + IW_EV_LCP_LEN <= end) {
1464 /* Event data may be unaligned, so make a local, aligned copy
1465 * before processing. */
1466 memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1467 wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1468 iwe->cmd, iwe->len);
1469 if (iwe->len <= IW_EV_LCP_LEN)
1470 return;
1471
1472 custom = pos + IW_EV_POINT_LEN;
1473 if (drv->we_version > 18 &&
1474 (iwe->cmd == IWEVMICHAELMICFAILURE ||
1475 iwe->cmd == IWEVASSOCREQIE ||
1476 iwe->cmd == IWEVCUSTOM)) {
1477 /* WE-19 removed the pointer from struct iw_point */
1478 char *dpos = (char *) &iwe_buf.u.data.length;
1479 int dlen = dpos - (char *) &iwe_buf;
1480 memcpy(dpos, pos + IW_EV_LCP_LEN,
1481 sizeof(struct iw_event) - dlen);
1482 } else {
1483 memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1484 custom += IW_EV_POINT_OFF;
1485 }
1486
1487 switch (iwe->cmd) {
1488 case IWEVEXPIRED:
1489 drv_event_disassoc(drv->hapd,
1490 (u8 *) iwe->u.addr.sa_data);
1491 break;
1492 case IWEVREGISTERED:
1493 atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1494 break;
1495 case IWEVASSOCREQIE:
1496 /* Driver hack.. Use IWEVASSOCREQIE to bypass
1497 * IWEVCUSTOM size limitations. Need to handle this
1498 * just like IWEVCUSTOM.
1499 */
1500 case IWEVCUSTOM:
1501 if (custom + iwe->u.data.length > end)
1502 return;
1503 buf = malloc(iwe->u.data.length + 1);
1504 if (buf == NULL)
1505 return; /* XXX */
1506 memcpy(buf, custom, iwe->u.data.length);
1507 buf[iwe->u.data.length] = '\0';
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001508
1509 if (iwe->u.data.flags != 0) {
1510 atheros_wireless_event_atheros_custom(
1511 drv, (int) iwe->u.data.flags,
1512 buf, len);
1513 } else {
1514 atheros_wireless_event_wireless_custom(
1515 drv, buf, buf + iwe->u.data.length);
1516 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 free(buf);
1518 break;
1519 }
1520
1521 pos += iwe->len;
1522 }
1523}
1524
1525
1526static void
1527atheros_wireless_event_rtm_newlink(void *ctx,
1528 struct ifinfomsg *ifi, u8 *buf, size_t len)
1529{
1530 struct atheros_driver_data *drv = ctx;
1531 int attrlen, rta_len;
1532 struct rtattr *attr;
1533
1534 if (ifi->ifi_index != drv->ifindex)
1535 return;
1536
1537 attrlen = len;
1538 attr = (struct rtattr *) buf;
1539
1540 rta_len = RTA_ALIGN(sizeof(struct rtattr));
1541 while (RTA_OK(attr, attrlen)) {
1542 if (attr->rta_type == IFLA_WIRELESS) {
1543 atheros_wireless_event_wireless(
1544 drv, ((char *) attr) + rta_len,
1545 attr->rta_len - rta_len);
1546 }
1547 attr = RTA_NEXT(attr, attrlen);
1548 }
1549}
1550
1551
1552static int
1553atheros_get_we_version(struct atheros_driver_data *drv)
1554{
1555 struct iw_range *range;
1556 struct iwreq iwr;
1557 int minlen;
1558 size_t buflen;
1559
1560 drv->we_version = 0;
1561
1562 /*
1563 * Use larger buffer than struct iw_range in order to allow the
1564 * structure to grow in the future.
1565 */
1566 buflen = sizeof(struct iw_range) + 500;
1567 range = os_zalloc(buflen);
1568 if (range == NULL)
1569 return -1;
1570
1571 memset(&iwr, 0, sizeof(iwr));
1572 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1573 iwr.u.data.pointer = (caddr_t) range;
1574 iwr.u.data.length = buflen;
1575
1576 minlen = ((char *) &range->enc_capa) - (char *) range +
1577 sizeof(range->enc_capa);
1578
1579 if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1580 perror("ioctl[SIOCGIWRANGE]");
1581 free(range);
1582 return -1;
1583 } else if (iwr.u.data.length >= minlen &&
1584 range->we_version_compiled >= 18) {
1585 wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1586 "WE(source)=%d enc_capa=0x%x",
1587 range->we_version_compiled,
1588 range->we_version_source,
1589 range->enc_capa);
1590 drv->we_version = range->we_version_compiled;
1591 }
1592
Jouni Malinen75ecf522011-06-27 15:19:46 -07001593 os_free(range);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594 return 0;
1595}
1596
1597
1598static int
1599atheros_wireless_event_init(struct atheros_driver_data *drv)
1600{
1601 struct netlink_config *cfg;
1602
1603 atheros_get_we_version(drv);
1604
1605 cfg = os_zalloc(sizeof(*cfg));
1606 if (cfg == NULL)
1607 return -1;
1608 cfg->ctx = drv;
1609 cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1610 drv->netlink = netlink_init(cfg);
1611 if (drv->netlink == NULL) {
1612 os_free(cfg);
1613 return -1;
1614 }
1615
1616 return 0;
1617}
1618
1619
1620static int
1621atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1622 int encrypt, const u8 *own_addr, u32 flags)
1623{
1624 struct atheros_driver_data *drv = priv;
1625 unsigned char buf[3000];
1626 unsigned char *bp = buf;
1627 struct l2_ethhdr *eth;
1628 size_t len;
1629 int status;
1630
1631 /*
1632 * Prepend the Ethernet header. If the caller left us
1633 * space at the front we could just insert it but since
1634 * we don't know we copy to a local buffer. Given the frequency
1635 * and size of frames this probably doesn't matter.
1636 */
1637 len = data_len + sizeof(struct l2_ethhdr);
1638 if (len > sizeof(buf)) {
1639 bp = malloc(len);
1640 if (bp == NULL) {
1641 printf("EAPOL frame discarded, cannot malloc temp "
1642 "buffer of size %lu!\n", (unsigned long) len);
1643 return -1;
1644 }
1645 }
1646 eth = (struct l2_ethhdr *) bp;
1647 memcpy(eth->h_dest, addr, ETH_ALEN);
1648 memcpy(eth->h_source, own_addr, ETH_ALEN);
1649 eth->h_proto = host_to_be16(ETH_P_EAPOL);
1650 memcpy(eth+1, data, data_len);
1651
1652 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1653
1654 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1655
1656 if (bp != buf)
1657 free(bp);
1658 return status;
1659}
1660
1661static void
1662handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1663{
1664 struct atheros_driver_data *drv = ctx;
1665 drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1666 len - sizeof(struct l2_ethhdr));
1667}
1668
1669static void *
1670atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1671{
1672 struct atheros_driver_data *drv;
1673 struct ifreq ifr;
1674 struct iwreq iwr;
1675 char brname[IFNAMSIZ];
1676
1677 drv = os_zalloc(sizeof(struct atheros_driver_data));
1678 if (drv == NULL) {
1679 printf("Could not allocate memory for atheros driver data\n");
1680 return NULL;
1681 }
1682
1683 drv->hapd = hapd;
1684 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1685 if (drv->ioctl_sock < 0) {
1686 perror("socket[PF_INET,SOCK_DGRAM]");
1687 goto bad;
1688 }
1689 memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1690
1691 memset(&ifr, 0, sizeof(ifr));
1692 os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1693 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1694 perror("ioctl(SIOCGIFINDEX)");
1695 goto bad;
1696 }
1697 drv->ifindex = ifr.ifr_ifindex;
1698
1699 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1700 handle_read, drv, 1);
1701 if (drv->sock_xmit == NULL)
1702 goto bad;
1703 if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1704 goto bad;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001705 os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706 if (params->bridge[0]) {
1707 wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1708 params->bridge[0]);
1709 drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1710 ETH_P_EAPOL, handle_read, drv,
1711 1);
1712 if (drv->sock_recv == NULL)
1713 goto bad;
1714 } else if (linux_br_get(brname, drv->iface) == 0) {
1715 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1716 "EAPOL receive", brname);
1717 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1718 handle_read, drv, 1);
1719 if (drv->sock_recv == NULL)
1720 goto bad;
1721 } else
1722 drv->sock_recv = drv->sock_xmit;
1723
1724 memset(&iwr, 0, sizeof(iwr));
1725 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1726
1727 iwr.u.mode = IW_MODE_MASTER;
1728
1729 if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1730 perror("ioctl[SIOCSIWMODE]");
1731 printf("Could not set interface to master mode!\n");
1732 goto bad;
1733 }
1734
1735 /* mark down during setup */
1736 linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1737 atheros_set_privacy(drv, 0); /* default to no privacy */
1738
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001739 if (atheros_receive_pkt(drv))
1740 goto bad;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741
1742 if (atheros_wireless_event_init(drv))
1743 goto bad;
1744
1745 return drv;
1746bad:
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001747 atheros_reset_appfilter(drv);
1748 if (drv->sock_raw)
1749 l2_packet_deinit(drv->sock_raw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1751 l2_packet_deinit(drv->sock_recv);
1752 if (drv->sock_xmit != NULL)
1753 l2_packet_deinit(drv->sock_xmit);
1754 if (drv->ioctl_sock >= 0)
1755 close(drv->ioctl_sock);
1756 if (drv != NULL)
1757 free(drv);
1758 return NULL;
1759}
1760
1761
1762static void
1763atheros_deinit(void *priv)
1764{
1765 struct atheros_driver_data *drv = priv;
1766
Dmitry Shmidt04949592012-07-19 12:16:46 -07001767 atheros_reset_appfilter(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 netlink_deinit(drv->netlink);
1769 (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1770 if (drv->ioctl_sock >= 0)
1771 close(drv->ioctl_sock);
1772 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1773 l2_packet_deinit(drv->sock_recv);
1774 if (drv->sock_xmit != NULL)
1775 l2_packet_deinit(drv->sock_xmit);
1776 if (drv->sock_raw)
1777 l2_packet_deinit(drv->sock_raw);
1778 wpabuf_free(drv->wpa_ie);
1779 wpabuf_free(drv->wps_beacon_ie);
1780 wpabuf_free(drv->wps_probe_resp_ie);
1781 free(drv);
1782}
1783
1784static int
1785atheros_set_ssid(void *priv, const u8 *buf, int len)
1786{
1787 struct atheros_driver_data *drv = priv;
1788 struct iwreq iwr;
1789
1790 memset(&iwr, 0, sizeof(iwr));
1791 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1792 iwr.u.essid.flags = 1; /* SSID active */
1793 iwr.u.essid.pointer = (caddr_t) buf;
1794 iwr.u.essid.length = len + 1;
1795
1796 if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1797 perror("ioctl[SIOCSIWESSID]");
1798 printf("len=%d\n", len);
1799 return -1;
1800 }
1801 return 0;
1802}
1803
1804static int
1805atheros_get_ssid(void *priv, u8 *buf, int len)
1806{
1807 struct atheros_driver_data *drv = priv;
1808 struct iwreq iwr;
1809 int ret = 0;
1810
1811 memset(&iwr, 0, sizeof(iwr));
1812 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1813 iwr.u.essid.pointer = (caddr_t) buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001814 iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1815 IW_ESSID_MAX_SIZE : len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816
1817 if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1818 perror("ioctl[SIOCGIWESSID]");
1819 ret = -1;
1820 } else
1821 ret = iwr.u.essid.length;
1822
1823 return ret;
1824}
1825
1826static int
1827atheros_set_countermeasures(void *priv, int enabled)
1828{
1829 struct atheros_driver_data *drv = priv;
1830 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1831 return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1832}
1833
1834static int
1835atheros_commit(void *priv)
1836{
1837 struct atheros_driver_data *drv = priv;
1838 return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1839}
1840
Jouni Malinen75ecf522011-06-27 15:19:46 -07001841static int atheros_set_authmode(void *priv, int auth_algs)
1842{
1843 int authmode;
1844
1845 if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1846 (auth_algs & WPA_AUTH_ALG_SHARED))
1847 authmode = IEEE80211_AUTH_AUTO;
1848 else if (auth_algs & WPA_AUTH_ALG_OPEN)
1849 authmode = IEEE80211_AUTH_OPEN;
1850 else if (auth_algs & WPA_AUTH_ALG_SHARED)
1851 authmode = IEEE80211_AUTH_SHARED;
1852 else
1853 return -1;
1854
1855 return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1856}
1857
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001858static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1859{
1860 /*
1861 * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1862 * set_generic_elem, and hapd_set_ssid.
1863 */
1864
1865 wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1866 "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1867 "wpa_version=0x%x privacy=%d interworking=%d",
1868 params->pairwise_ciphers, params->group_cipher,
1869 params->key_mgmt_suites, params->auth_algs,
1870 params->wpa_version, params->privacy, params->interworking);
1871 wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1872 params->ssid, params->ssid_len);
1873 if (params->hessid)
1874 wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1875 MAC2STR(params->hessid));
1876 wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1877 params->beacon_ies);
1878 wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1879 params->proberesp_ies);
1880 wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1881 params->assocresp_ies);
1882
1883 return 0;
1884}
1885
Dmitry Shmidt04949592012-07-19 12:16:46 -07001886
1887#ifdef CONFIG_IEEE80211R
1888
1889static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1890 int noack)
1891{
1892 struct atheros_driver_data *drv = priv;
1893 u8 buf[1510];
1894 const struct ieee80211_mgmt *mgmt;
1895 struct ieee80211req_mgmtbuf *mgmt_frm;
1896
1897 mgmt = (const struct ieee80211_mgmt *) frm;
1898 wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1899 (unsigned long) data_len, MAC2STR(mgmt->da));
1900 mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1901 memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1902 mgmt_frm->buflen = data_len;
1903 if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1904 wpa_printf(MSG_INFO, "atheros: Too long frame for "
1905 "atheros_send_mgmt (%u)", (unsigned int) data_len);
1906 return -1;
1907 }
1908 os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1909 return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1910 sizeof(struct ieee80211req_mgmtbuf) + data_len);
1911}
1912
1913
1914static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1915 size_t tspec_ielen)
1916{
1917 struct atheros_driver_data *drv = priv;
1918 int retv;
1919 struct ieee80211req_res req;
1920 struct ieee80211req_res_addts *addts = &req.u.addts;
1921
1922 wpa_printf(MSG_DEBUG, "%s", __func__);
1923 req.type = IEEE80211_RESREQ_ADDTS;
1924 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1925 os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
1926 retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1927 sizeof(struct ieee80211req_res));
1928 if (retv < 0) {
1929 wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
1930 "retv = %d", __func__, retv);
1931 return -1;
1932 }
1933 os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
1934 return addts->status;
1935}
1936
1937
1938static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
1939{
1940 struct atheros_driver_data *drv = priv;
1941 struct ieee80211req_res req;
1942 struct ieee80211req_res_addnode *addnode = &req.u.addnode;
1943
1944 wpa_printf(MSG_DEBUG, "%s", __func__);
1945 req.type = IEEE80211_RESREQ_ADDNODE;
1946 os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
1947 addnode->auth_alg = auth_alg;
1948 return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
1949 sizeof(struct ieee80211req_res));
1950}
1951
1952#endif /* CONFIG_IEEE80211R */
1953
1954
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001955/* Use only to set a big param, get will not work. */
1956static int
1957set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
1958{
1959 struct iwreq iwr;
1960
1961 os_memset(&iwr, 0, sizeof(iwr));
1962 os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1963
1964 iwr.u.data.pointer = (void *) data;
1965 iwr.u.data.length = len;
1966 iwr.u.data.flags = op;
1967 wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
1968 __func__, op, op, athr_get_param_name(op), len);
1969
1970 if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
1971 wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
1972 "value=0x%x,0x%x failed: %d (%s)",
1973 __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
1974 iwr.u.mode, iwr.u.data.length,
1975 iwr.u.data.flags, errno, strerror(errno));
1976 return -1;
1977 }
1978 return 0;
1979}
1980
1981
1982static int atheros_send_action(void *priv, unsigned int freq,
1983 unsigned int wait,
1984 const u8 *dst, const u8 *src,
1985 const u8 *bssid,
1986 const u8 *data, size_t data_len, int no_cck)
1987{
1988 struct atheros_driver_data *drv = priv;
1989 struct ieee80211_p2p_send_action *act;
1990 int res;
1991
1992 act = os_zalloc(sizeof(*act) + data_len);
1993 if (act == NULL)
1994 return -1;
1995 act->freq = freq;
1996 os_memcpy(act->dst_addr, dst, ETH_ALEN);
1997 os_memcpy(act->src_addr, src, ETH_ALEN);
1998 os_memcpy(act->bssid, bssid, ETH_ALEN);
1999 os_memcpy(act + 1, data, data_len);
2000 wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
2001 MACSTR ", bssid=" MACSTR,
2002 __func__, act->freq, wait, MAC2STR(act->dst_addr),
2003 MAC2STR(act->src_addr), MAC2STR(act->bssid));
2004 wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
2005 wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
2006
2007 res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
2008 act, sizeof(*act) + data_len);
2009 os_free(act);
2010 return res;
2011}
2012
2013
Dmitry Shmidt56052862013-10-04 10:23:25 -07002014#if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002015static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
2016 u8 *ie, u16 *len, enum wnm_oper oper)
2017{
2018#define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
2019 u8 buf[IEEE80211_APPIE_MAX];
2020 struct ieee80211req_getset_appiebuf *tfs_ie;
2021 u16 val;
2022
2023 wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
2024 drv->iface, oper, MAC2STR(peer));
2025
2026 switch (oper) {
2027 case WNM_SLEEP_TFS_REQ_IE_SET:
2028 if (*len > IEEE80211_APPIE_MAX -
2029 sizeof(struct ieee80211req_getset_appiebuf)) {
2030 wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
2031 return -1;
2032 }
2033 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2034 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2035 tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
2036
2037 /* Command header for driver */
2038 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2039 val = oper;
2040 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2041 val = *len;
2042 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2043
2044 /* copy the ie */
2045 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
2046
2047 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2048 IEEE80211_APPIE_MAX)) {
2049 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2050 "%s", __func__, strerror(errno));
2051 return -1;
2052 }
2053 break;
2054 case WNM_SLEEP_TFS_RESP_IE_ADD:
2055 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2056 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2057 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2058 sizeof(struct ieee80211req_getset_appiebuf);
2059 /* Command header for driver */
2060 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2061 val = oper;
2062 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2063 val = 0;
2064 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2065
2066 if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2067 IEEE80211_APPIE_MAX)) {
2068 wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2069 "%s", __func__, strerror(errno));
2070 return -1;
2071 }
2072
2073 *len = tfs_ie->app_buflen;
2074 os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2075 wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2076 *len);
2077 break;
2078 case WNM_SLEEP_TFS_RESP_IE_NONE:
2079 *len = 0;
2080 break;
2081 case WNM_SLEEP_TFS_IE_DEL:
2082 tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2083 tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2084 tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2085 sizeof(struct ieee80211req_getset_appiebuf);
2086 /* Command header for driver */
2087 os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2088 val = oper;
2089 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2090 val = 0;
2091 os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2092
2093 if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2094 IEEE80211_APPIE_MAX)) {
2095 wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2096 "%s", __func__, strerror(errno));
2097 return -1;
2098 }
2099 break;
2100 default:
2101 wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2102 break;
2103 }
2104
2105 return 0;
2106}
2107
2108
2109static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2110 const u8 *peer, enum wnm_oper oper)
2111{
2112 u8 *data, *pos;
2113 size_t dlen;
2114 int ret;
2115 u16 val;
2116
2117 wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2118 oper, MAC2STR(peer));
2119
2120 dlen = ETH_ALEN + 2 + 2;
2121 data = os_malloc(dlen);
2122 if (data == NULL)
2123 return -1;
2124
2125 /* Command header for driver */
2126 pos = data;
2127 os_memcpy(pos, peer, ETH_ALEN);
2128 pos += ETH_ALEN;
2129
2130 val = oper;
2131 os_memcpy(pos, &val, 2);
2132 pos += 2;
2133
2134 val = 0;
2135 os_memcpy(pos, &val, 2);
2136
2137 ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2138
2139 os_free(data);
2140
2141 return ret;
2142}
2143
2144
2145static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2146 u8 *buf, u16 *buf_len)
2147{
2148 struct atheros_driver_data *drv = priv;
2149
2150 switch (oper) {
2151 case WNM_SLEEP_ENTER_CONFIRM:
2152 case WNM_SLEEP_ENTER_FAIL:
2153 case WNM_SLEEP_EXIT_CONFIRM:
2154 case WNM_SLEEP_EXIT_FAIL:
2155 return atheros_wnm_sleep(drv, peer, oper);
2156 case WNM_SLEEP_TFS_REQ_IE_SET:
2157 case WNM_SLEEP_TFS_RESP_IE_ADD:
2158 case WNM_SLEEP_TFS_RESP_IE_NONE:
2159 case WNM_SLEEP_TFS_IE_DEL:
2160 return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2161 default:
2162 wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2163 oper);
2164 return -1;
2165 }
2166}
Dmitry Shmidt56052862013-10-04 10:23:25 -07002167#endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002168
2169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170const struct wpa_driver_ops wpa_driver_atheros_ops = {
2171 .name = "atheros",
2172 .hapd_init = atheros_init,
2173 .hapd_deinit = atheros_deinit,
2174 .set_ieee8021x = atheros_set_ieee8021x,
2175 .set_privacy = atheros_set_privacy,
2176 .set_key = atheros_set_key,
2177 .get_seqnum = atheros_get_seqnum,
2178 .flush = atheros_flush,
2179 .set_generic_elem = atheros_set_opt_ie,
2180 .sta_set_flags = atheros_sta_set_flags,
2181 .read_sta_data = atheros_read_sta_driver_data,
2182 .hapd_send_eapol = atheros_send_eapol,
2183 .sta_disassoc = atheros_sta_disassoc,
2184 .sta_deauth = atheros_sta_deauth,
2185 .hapd_set_ssid = atheros_set_ssid,
2186 .hapd_get_ssid = atheros_get_ssid,
2187 .set_countermeasures = atheros_set_countermeasures,
2188 .sta_clear_stats = atheros_sta_clear_stats,
2189 .commit = atheros_commit,
2190 .set_ap_wps_ie = atheros_set_ap_wps_ie,
Jouni Malinen75ecf522011-06-27 15:19:46 -07002191 .set_authmode = atheros_set_authmode,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002192 .set_ap = atheros_set_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002193#ifdef CONFIG_IEEE80211R
2194 .sta_assoc = atheros_sta_assoc,
2195 .sta_auth = atheros_sta_auth,
2196 .send_mlme = atheros_send_mgmt,
2197 .add_tspec = atheros_add_tspec,
2198 .add_sta_node = atheros_add_sta_node,
2199#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002200 .send_action = atheros_send_action,
Dmitry Shmidt56052862013-10-04 10:23:25 -07002201#if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002202 .wnm_oper = atheros_wnm_oper,
Dmitry Shmidt56052862013-10-04 10:23:25 -07002203#endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002204 .set_qos_map = atheros_set_qos_map,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205};