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