1206b73d0SCy Schubert /*
2206b73d0SCy Schubert * hostapd / Driver interaction with Atheros driver
3206b73d0SCy Schubert * Copyright (c) 2004, Sam Leffler <sam@errno.com>
4206b73d0SCy Schubert * Copyright (c) 2004, Video54 Technologies
5206b73d0SCy Schubert * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
6206b73d0SCy Schubert * Copyright (c) 2009, Atheros Communications
7206b73d0SCy Schubert *
8206b73d0SCy Schubert * This software may be distributed under the terms of the BSD license.
9206b73d0SCy Schubert * See README for more details.
10206b73d0SCy Schubert */
11206b73d0SCy Schubert
12206b73d0SCy Schubert #include "includes.h"
13206b73d0SCy Schubert #include <net/if.h>
14206b73d0SCy Schubert #include <sys/ioctl.h>
15206b73d0SCy Schubert
16206b73d0SCy Schubert #include "common.h"
17206b73d0SCy Schubert #include "eloop.h"
18206b73d0SCy Schubert #include "common/ieee802_11_defs.h"
19206b73d0SCy Schubert #include "l2_packet/l2_packet.h"
20206b73d0SCy Schubert
21206b73d0SCy Schubert #include "common.h"
22206b73d0SCy Schubert #ifndef _BYTE_ORDER
23206b73d0SCy Schubert #ifdef WORDS_BIGENDIAN
24206b73d0SCy Schubert #define _BYTE_ORDER _BIG_ENDIAN
25206b73d0SCy Schubert #else
26206b73d0SCy Schubert #define _BYTE_ORDER _LITTLE_ENDIAN
27206b73d0SCy Schubert #endif
28206b73d0SCy Schubert #endif /* _BYTE_ORDER */
29206b73d0SCy Schubert
30206b73d0SCy Schubert /*
31206b73d0SCy Schubert * Note, the ATH_WPS_IE setting must match with the driver build.. If the
32206b73d0SCy Schubert * driver does not include this, the IEEE80211_IOCTL_GETWPAIE ioctl will fail.
33206b73d0SCy Schubert */
34206b73d0SCy Schubert #define ATH_WPS_IE
35206b73d0SCy Schubert
36206b73d0SCy Schubert #include "ieee80211_external.h"
37206b73d0SCy Schubert
38206b73d0SCy Schubert /* Avoid conflicting definition from the driver header files with
39206b73d0SCy Schubert * common/wpa_common.h */
40206b73d0SCy Schubert #undef WPA_OUI_TYPE
41206b73d0SCy Schubert
42206b73d0SCy Schubert
43206b73d0SCy Schubert #ifdef CONFIG_WPS
44206b73d0SCy Schubert #include <netpacket/packet.h>
45206b73d0SCy Schubert #endif /* CONFIG_WPS */
46206b73d0SCy Schubert
47206b73d0SCy Schubert #ifndef ETH_P_80211_RAW
48206b73d0SCy Schubert #define ETH_P_80211_RAW 0x0019
49206b73d0SCy Schubert #endif
50206b73d0SCy Schubert
51206b73d0SCy Schubert #include "linux_wext.h"
52206b73d0SCy Schubert
53206b73d0SCy Schubert #include "driver.h"
54206b73d0SCy Schubert #include "eloop.h"
55206b73d0SCy Schubert #include "priv_netlink.h"
56206b73d0SCy Schubert #include "l2_packet/l2_packet.h"
57206b73d0SCy Schubert #include "common/ieee802_11_defs.h"
58206b73d0SCy Schubert #include "netlink.h"
59206b73d0SCy Schubert #include "linux_ioctl.h"
60206b73d0SCy Schubert
61206b73d0SCy Schubert
62206b73d0SCy Schubert struct atheros_driver_data {
63206b73d0SCy Schubert struct hostapd_data *hapd; /* back pointer */
64206b73d0SCy Schubert
65206b73d0SCy Schubert char iface[IFNAMSIZ + 1];
66206b73d0SCy Schubert int ifindex;
67206b73d0SCy Schubert struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
68206b73d0SCy Schubert struct l2_packet_data *sock_recv; /* raw packet recv socket */
69206b73d0SCy Schubert int ioctl_sock; /* socket for ioctl() use */
70206b73d0SCy Schubert struct netlink_data *netlink;
71206b73d0SCy Schubert int we_version;
72206b73d0SCy Schubert int fils_en; /* FILS enable/disable in driver */
73206b73d0SCy Schubert u8 acct_mac[ETH_ALEN];
74206b73d0SCy Schubert struct hostap_sta_driver_data acct_data;
75206b73d0SCy Schubert
76206b73d0SCy Schubert struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
77206b73d0SCy Schubert struct wpabuf *wpa_ie;
78206b73d0SCy Schubert struct wpabuf *wps_beacon_ie;
79206b73d0SCy Schubert struct wpabuf *wps_probe_resp_ie;
80206b73d0SCy Schubert u8 own_addr[ETH_ALEN];
81206b73d0SCy Schubert };
82206b73d0SCy Schubert
83206b73d0SCy Schubert static int atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
84*a90b9d01SCy Schubert u16 reason_code, int link_id);
85206b73d0SCy Schubert static int atheros_set_privacy(void *priv, int enabled);
86206b73d0SCy Schubert
athr_get_ioctl_name(int op)87206b73d0SCy Schubert static const char * athr_get_ioctl_name(int op)
88206b73d0SCy Schubert {
89206b73d0SCy Schubert switch (op) {
90206b73d0SCy Schubert case IEEE80211_IOCTL_SETPARAM:
91206b73d0SCy Schubert return "SETPARAM";
92206b73d0SCy Schubert case IEEE80211_IOCTL_GETPARAM:
93206b73d0SCy Schubert return "GETPARAM";
94206b73d0SCy Schubert case IEEE80211_IOCTL_SETKEY:
95206b73d0SCy Schubert return "SETKEY";
96206b73d0SCy Schubert case IEEE80211_IOCTL_SETWMMPARAMS:
97206b73d0SCy Schubert return "SETWMMPARAMS";
98206b73d0SCy Schubert case IEEE80211_IOCTL_DELKEY:
99206b73d0SCy Schubert return "DELKEY";
100206b73d0SCy Schubert case IEEE80211_IOCTL_GETWMMPARAMS:
101206b73d0SCy Schubert return "GETWMMPARAMS";
102206b73d0SCy Schubert case IEEE80211_IOCTL_SETMLME:
103206b73d0SCy Schubert return "SETMLME";
104206b73d0SCy Schubert case IEEE80211_IOCTL_GETCHANINFO:
105206b73d0SCy Schubert return "GETCHANINFO";
106206b73d0SCy Schubert case IEEE80211_IOCTL_SETOPTIE:
107206b73d0SCy Schubert return "SETOPTIE";
108206b73d0SCy Schubert case IEEE80211_IOCTL_GETOPTIE:
109206b73d0SCy Schubert return "GETOPTIE";
110206b73d0SCy Schubert case IEEE80211_IOCTL_ADDMAC:
111206b73d0SCy Schubert return "ADDMAC";
112206b73d0SCy Schubert case IEEE80211_IOCTL_DELMAC:
113206b73d0SCy Schubert return "DELMAC";
114206b73d0SCy Schubert case IEEE80211_IOCTL_GETCHANLIST:
115206b73d0SCy Schubert return "GETCHANLIST";
116206b73d0SCy Schubert case IEEE80211_IOCTL_SETCHANLIST:
117206b73d0SCy Schubert return "SETCHANLIST";
118206b73d0SCy Schubert case IEEE80211_IOCTL_KICKMAC:
119206b73d0SCy Schubert return "KICKMAC";
120206b73d0SCy Schubert case IEEE80211_IOCTL_CHANSWITCH:
121206b73d0SCy Schubert return "CHANSWITCH";
122206b73d0SCy Schubert case IEEE80211_IOCTL_GETMODE:
123206b73d0SCy Schubert return "GETMODE";
124206b73d0SCy Schubert case IEEE80211_IOCTL_SETMODE:
125206b73d0SCy Schubert return "SETMODE";
126206b73d0SCy Schubert case IEEE80211_IOCTL_GET_APPIEBUF:
127206b73d0SCy Schubert return "GET_APPIEBUF";
128206b73d0SCy Schubert case IEEE80211_IOCTL_SET_APPIEBUF:
129206b73d0SCy Schubert return "SET_APPIEBUF";
130206b73d0SCy Schubert case IEEE80211_IOCTL_SET_ACPARAMS:
131206b73d0SCy Schubert return "SET_ACPARAMS";
132206b73d0SCy Schubert case IEEE80211_IOCTL_FILTERFRAME:
133206b73d0SCy Schubert return "FILTERFRAME";
134206b73d0SCy Schubert case IEEE80211_IOCTL_SET_RTPARAMS:
135206b73d0SCy Schubert return "SET_RTPARAMS";
136206b73d0SCy Schubert case IEEE80211_IOCTL_SET_MEDENYENTRY:
137206b73d0SCy Schubert return "SET_MEDENYENTRY";
138206b73d0SCy Schubert case IEEE80211_IOCTL_GET_MACADDR:
139206b73d0SCy Schubert return "GET_MACADDR";
140206b73d0SCy Schubert case IEEE80211_IOCTL_SET_HBRPARAMS:
141206b73d0SCy Schubert return "SET_HBRPARAMS";
142206b73d0SCy Schubert case IEEE80211_IOCTL_SET_RXTIMEOUT:
143206b73d0SCy Schubert return "SET_RXTIMEOUT";
144206b73d0SCy Schubert case IEEE80211_IOCTL_STA_STATS:
145206b73d0SCy Schubert return "STA_STATS";
146206b73d0SCy Schubert case IEEE80211_IOCTL_GETWPAIE:
147206b73d0SCy Schubert return "GETWPAIE";
148206b73d0SCy Schubert default:
149206b73d0SCy Schubert return "??";
150206b73d0SCy Schubert }
151206b73d0SCy Schubert }
152206b73d0SCy Schubert
153206b73d0SCy Schubert
athr_get_param_name(int op)154206b73d0SCy Schubert static const char * athr_get_param_name(int op)
155206b73d0SCy Schubert {
156206b73d0SCy Schubert switch (op) {
157206b73d0SCy Schubert case IEEE80211_IOC_MCASTCIPHER:
158206b73d0SCy Schubert return "MCASTCIPHER";
159206b73d0SCy Schubert case IEEE80211_PARAM_MCASTKEYLEN:
160206b73d0SCy Schubert return "MCASTKEYLEN";
161206b73d0SCy Schubert case IEEE80211_PARAM_UCASTCIPHERS:
162206b73d0SCy Schubert return "UCASTCIPHERS";
163206b73d0SCy Schubert case IEEE80211_PARAM_KEYMGTALGS:
164206b73d0SCy Schubert return "KEYMGTALGS";
165206b73d0SCy Schubert case IEEE80211_PARAM_RSNCAPS:
166206b73d0SCy Schubert return "RSNCAPS";
167206b73d0SCy Schubert case IEEE80211_PARAM_WPA:
168206b73d0SCy Schubert return "WPA";
169206b73d0SCy Schubert case IEEE80211_PARAM_AUTHMODE:
170206b73d0SCy Schubert return "AUTHMODE";
171206b73d0SCy Schubert case IEEE80211_PARAM_PRIVACY:
172206b73d0SCy Schubert return "PRIVACY";
173206b73d0SCy Schubert case IEEE80211_PARAM_COUNTERMEASURES:
174206b73d0SCy Schubert return "COUNTERMEASURES";
175206b73d0SCy Schubert default:
176206b73d0SCy Schubert return "??";
177206b73d0SCy Schubert }
178206b73d0SCy Schubert }
179206b73d0SCy Schubert
180206b73d0SCy Schubert
181206b73d0SCy Schubert #ifdef CONFIG_FILS
182206b73d0SCy Schubert static int
get80211param(struct atheros_driver_data * drv,int op,int * data)183206b73d0SCy Schubert get80211param(struct atheros_driver_data *drv, int op, int *data)
184206b73d0SCy Schubert {
185206b73d0SCy Schubert struct iwreq iwr;
186206b73d0SCy Schubert
187206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
188206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
189206b73d0SCy Schubert iwr.u.mode = op;
190206b73d0SCy Schubert
191206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_GETPARAM, &iwr) < 0)
192206b73d0SCy Schubert return -1;
193206b73d0SCy Schubert
194206b73d0SCy Schubert *data = iwr.u.mode;
195206b73d0SCy Schubert return 0;
196206b73d0SCy Schubert }
197206b73d0SCy Schubert #endif /* CONFIG_FILS */
198206b73d0SCy Schubert
199206b73d0SCy Schubert
200206b73d0SCy Schubert static int
set80211priv(struct atheros_driver_data * drv,int op,void * data,int len)201206b73d0SCy Schubert set80211priv(struct atheros_driver_data *drv, int op, void *data, int len)
202206b73d0SCy Schubert {
203206b73d0SCy Schubert struct iwreq iwr;
204206b73d0SCy Schubert int do_inline = len < IFNAMSIZ;
205206b73d0SCy Schubert
206206b73d0SCy Schubert /* Certain ioctls must use the non-inlined method */
207206b73d0SCy Schubert if (op == IEEE80211_IOCTL_SET_APPIEBUF ||
208206b73d0SCy Schubert op == IEEE80211_IOCTL_FILTERFRAME)
209206b73d0SCy Schubert do_inline = 0;
210206b73d0SCy Schubert
211206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
212206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
213206b73d0SCy Schubert if (do_inline) {
214206b73d0SCy Schubert /*
215206b73d0SCy Schubert * Argument data fits inline; put it there.
216206b73d0SCy Schubert */
217206b73d0SCy Schubert os_memcpy(iwr.u.name, data, len);
218206b73d0SCy Schubert } else {
219206b73d0SCy Schubert /*
220206b73d0SCy Schubert * Argument data too big for inline transfer; setup a
221206b73d0SCy Schubert * parameter block instead; the kernel will transfer
222206b73d0SCy Schubert * the data for the driver.
223206b73d0SCy Schubert */
224206b73d0SCy Schubert iwr.u.data.pointer = data;
225206b73d0SCy Schubert iwr.u.data.length = len;
226206b73d0SCy Schubert }
227206b73d0SCy Schubert
228206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
229206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: %s: %s: ioctl op=0x%x "
230206b73d0SCy Schubert "(%s) len=%d failed: %d (%s)",
231206b73d0SCy Schubert __func__, drv->iface, op,
232206b73d0SCy Schubert athr_get_ioctl_name(op),
233206b73d0SCy Schubert len, errno, strerror(errno));
234206b73d0SCy Schubert return -1;
235206b73d0SCy Schubert }
236206b73d0SCy Schubert return 0;
237206b73d0SCy Schubert }
238206b73d0SCy Schubert
239206b73d0SCy Schubert static int
set80211param(struct atheros_driver_data * drv,int op,int arg)240206b73d0SCy Schubert set80211param(struct atheros_driver_data *drv, int op, int arg)
241206b73d0SCy Schubert {
242206b73d0SCy Schubert struct iwreq iwr;
243206b73d0SCy Schubert
244206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
245206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
246206b73d0SCy Schubert iwr.u.mode = op;
247206b73d0SCy Schubert os_memcpy(iwr.u.name + sizeof(__u32), &arg, sizeof(arg));
248206b73d0SCy Schubert
249206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
250206b73d0SCy Schubert wpa_printf(MSG_INFO,
251206b73d0SCy Schubert "%s: %s: Failed to set parameter (op %d (%s) arg %d): ioctl[IEEE80211_IOCTL_SETPARAM]: %s",
252206b73d0SCy Schubert __func__, drv->iface, op, athr_get_param_name(op),
253206b73d0SCy Schubert arg, strerror(errno));
254206b73d0SCy Schubert return -1;
255206b73d0SCy Schubert }
256206b73d0SCy Schubert return 0;
257206b73d0SCy Schubert }
258206b73d0SCy Schubert
259206b73d0SCy Schubert #ifndef CONFIG_NO_STDOUT_DEBUG
260206b73d0SCy Schubert static const char *
ether_sprintf(const u8 * addr)261206b73d0SCy Schubert ether_sprintf(const u8 *addr)
262206b73d0SCy Schubert {
263206b73d0SCy Schubert static char buf[sizeof(MACSTR)];
264206b73d0SCy Schubert
265206b73d0SCy Schubert if (addr != NULL)
266206b73d0SCy Schubert os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
267206b73d0SCy Schubert else
268206b73d0SCy Schubert os_snprintf(buf, sizeof(buf), MACSTR, 0, 0, 0, 0, 0, 0);
269206b73d0SCy Schubert return buf;
270206b73d0SCy Schubert }
271206b73d0SCy Schubert #endif /* CONFIG_NO_STDOUT_DEBUG */
272206b73d0SCy Schubert
273206b73d0SCy Schubert /*
274206b73d0SCy Schubert * Configure WPA parameters.
275206b73d0SCy Schubert */
276206b73d0SCy Schubert static int
atheros_configure_wpa(struct atheros_driver_data * drv,struct wpa_bss_params * params)277206b73d0SCy Schubert atheros_configure_wpa(struct atheros_driver_data *drv,
278206b73d0SCy Schubert struct wpa_bss_params *params)
279206b73d0SCy Schubert {
280206b73d0SCy Schubert int v;
281206b73d0SCy Schubert
282206b73d0SCy Schubert switch (params->wpa_group) {
283206b73d0SCy Schubert case WPA_CIPHER_CCMP:
284206b73d0SCy Schubert v = IEEE80211_CIPHER_AES_CCM;
285206b73d0SCy Schubert break;
286206b73d0SCy Schubert #ifdef ATH_GCM_SUPPORT
287206b73d0SCy Schubert case WPA_CIPHER_CCMP_256:
288206b73d0SCy Schubert v = IEEE80211_CIPHER_AES_CCM_256;
289206b73d0SCy Schubert break;
290206b73d0SCy Schubert case WPA_CIPHER_GCMP:
291206b73d0SCy Schubert v = IEEE80211_CIPHER_AES_GCM;
292206b73d0SCy Schubert break;
293206b73d0SCy Schubert case WPA_CIPHER_GCMP_256:
294206b73d0SCy Schubert v = IEEE80211_CIPHER_AES_GCM_256;
295206b73d0SCy Schubert break;
296206b73d0SCy Schubert #endif /* ATH_GCM_SUPPORT */
297206b73d0SCy Schubert case WPA_CIPHER_TKIP:
298206b73d0SCy Schubert v = IEEE80211_CIPHER_TKIP;
299206b73d0SCy Schubert break;
300206b73d0SCy Schubert case WPA_CIPHER_WEP104:
301206b73d0SCy Schubert v = IEEE80211_CIPHER_WEP;
302206b73d0SCy Schubert break;
303206b73d0SCy Schubert case WPA_CIPHER_WEP40:
304206b73d0SCy Schubert v = IEEE80211_CIPHER_WEP;
305206b73d0SCy Schubert break;
306206b73d0SCy Schubert case WPA_CIPHER_NONE:
307206b73d0SCy Schubert v = IEEE80211_CIPHER_NONE;
308206b73d0SCy Schubert break;
309206b73d0SCy Schubert default:
310206b73d0SCy Schubert wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
311206b73d0SCy Schubert params->wpa_group);
312206b73d0SCy Schubert return -1;
313206b73d0SCy Schubert }
314206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
315206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
316206b73d0SCy Schubert wpa_printf(MSG_INFO, "Unable to set group key cipher to %u", v);
317206b73d0SCy Schubert return -1;
318206b73d0SCy Schubert }
319206b73d0SCy Schubert if (v == IEEE80211_CIPHER_WEP) {
320206b73d0SCy Schubert /* key length is done only for specific ciphers */
321206b73d0SCy Schubert v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
322206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
323206b73d0SCy Schubert wpa_printf(MSG_INFO,
324206b73d0SCy Schubert "Unable to set group key length to %u", v);
325206b73d0SCy Schubert return -1;
326206b73d0SCy Schubert }
327206b73d0SCy Schubert }
328206b73d0SCy Schubert
329206b73d0SCy Schubert v = 0;
330206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_CCMP)
331206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_AES_CCM;
332206b73d0SCy Schubert #ifdef ATH_GCM_SUPPORT
333206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_CCMP_256)
334206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_AES_CCM_256;
335206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_GCMP)
336206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_AES_GCM;
337206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_GCMP_256)
338206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_AES_GCM_256;
339206b73d0SCy Schubert #endif /* ATH_GCM_SUPPORT */
340206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_TKIP)
341206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_TKIP;
342206b73d0SCy Schubert if (params->wpa_pairwise & WPA_CIPHER_NONE)
343206b73d0SCy Schubert v |= 1<<IEEE80211_CIPHER_NONE;
344206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
345206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
346206b73d0SCy Schubert wpa_printf(MSG_INFO,
347206b73d0SCy Schubert "Unable to set pairwise key ciphers to 0x%x", v);
348206b73d0SCy Schubert return -1;
349206b73d0SCy Schubert }
350206b73d0SCy Schubert
351206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
352206b73d0SCy Schubert __func__, params->wpa_key_mgmt);
353206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS,
354206b73d0SCy Schubert params->wpa_key_mgmt)) {
355206b73d0SCy Schubert wpa_printf(MSG_INFO,
356206b73d0SCy Schubert "Unable to set key management algorithms to 0x%x",
357206b73d0SCy Schubert params->wpa_key_mgmt);
358206b73d0SCy Schubert return -1;
359206b73d0SCy Schubert }
360206b73d0SCy Schubert
361206b73d0SCy Schubert v = 0;
362206b73d0SCy Schubert if (params->rsn_preauth)
363206b73d0SCy Schubert v |= BIT(0);
364206b73d0SCy Schubert if (params->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
365206b73d0SCy Schubert v |= BIT(7);
366206b73d0SCy Schubert if (params->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
367206b73d0SCy Schubert v |= BIT(6);
368206b73d0SCy Schubert }
369206b73d0SCy Schubert
370206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", __func__, v);
371206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
372206b73d0SCy Schubert wpa_printf(MSG_INFO, "Unable to set RSN capabilities to 0x%x",
373206b73d0SCy Schubert v);
374206b73d0SCy Schubert return -1;
375206b73d0SCy Schubert }
376206b73d0SCy Schubert
377206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, params->wpa);
378206b73d0SCy Schubert if (set80211param(drv, IEEE80211_PARAM_WPA, params->wpa)) {
379206b73d0SCy Schubert wpa_printf(MSG_INFO, "Unable to set WPA to %u", params->wpa);
380206b73d0SCy Schubert return -1;
381206b73d0SCy Schubert }
382206b73d0SCy Schubert return 0;
383206b73d0SCy Schubert }
384206b73d0SCy Schubert
385206b73d0SCy Schubert static int
atheros_set_ieee8021x(void * priv,struct wpa_bss_params * params)386206b73d0SCy Schubert atheros_set_ieee8021x(void *priv, struct wpa_bss_params *params)
387206b73d0SCy Schubert {
388206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
389206b73d0SCy Schubert
390206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
391206b73d0SCy Schubert
392206b73d0SCy Schubert if (!params->enabled) {
393206b73d0SCy Schubert /* XXX restore state */
394206b73d0SCy Schubert if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
395206b73d0SCy Schubert IEEE80211_AUTH_AUTO) < 0)
396206b73d0SCy Schubert return -1;
397206b73d0SCy Schubert /* IEEE80211_AUTH_AUTO ends up enabling Privacy; clear that */
398206b73d0SCy Schubert return atheros_set_privacy(drv, 0);
399206b73d0SCy Schubert }
400206b73d0SCy Schubert if (!params->wpa && !params->ieee802_1x) {
401206b73d0SCy Schubert wpa_printf(MSG_WARNING, "No 802.1X or WPA enabled!");
402206b73d0SCy Schubert return -1;
403206b73d0SCy Schubert }
404206b73d0SCy Schubert if (params->wpa && atheros_configure_wpa(drv, params) != 0) {
405206b73d0SCy Schubert wpa_printf(MSG_WARNING, "Error configuring WPA state!");
406206b73d0SCy Schubert return -1;
407206b73d0SCy Schubert }
408206b73d0SCy Schubert if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
409206b73d0SCy Schubert (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
410206b73d0SCy Schubert wpa_printf(MSG_WARNING, "Error enabling WPA/802.1X!");
411206b73d0SCy Schubert return -1;
412206b73d0SCy Schubert }
413206b73d0SCy Schubert
414206b73d0SCy Schubert return 0;
415206b73d0SCy Schubert }
416206b73d0SCy Schubert
417206b73d0SCy Schubert static int
atheros_set_privacy(void * priv,int enabled)418206b73d0SCy Schubert atheros_set_privacy(void *priv, int enabled)
419206b73d0SCy Schubert {
420206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
421206b73d0SCy Schubert
422206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
423206b73d0SCy Schubert
424206b73d0SCy Schubert return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
425206b73d0SCy Schubert }
426206b73d0SCy Schubert
427206b73d0SCy Schubert static int
atheros_set_sta_authorized(void * priv,const u8 * addr,int authorized)428206b73d0SCy Schubert atheros_set_sta_authorized(void *priv, const u8 *addr, int authorized)
429206b73d0SCy Schubert {
430206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
431206b73d0SCy Schubert struct ieee80211req_mlme mlme;
432206b73d0SCy Schubert int ret;
433206b73d0SCy Schubert
434206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
435206b73d0SCy Schubert __func__, ether_sprintf(addr), authorized);
436206b73d0SCy Schubert
437206b73d0SCy Schubert if (authorized)
438206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_AUTHORIZE;
439206b73d0SCy Schubert else
440206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
441206b73d0SCy Schubert mlme.im_reason = 0;
442206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
443206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
444206b73d0SCy Schubert if (ret < 0) {
445206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
446206b73d0SCy Schubert __func__, authorized ? "" : "un", MAC2STR(addr));
447206b73d0SCy Schubert }
448206b73d0SCy Schubert
449206b73d0SCy Schubert return ret;
450206b73d0SCy Schubert }
451206b73d0SCy Schubert
452206b73d0SCy Schubert static int
atheros_sta_set_flags(void * priv,const u8 * addr,unsigned int total_flags,unsigned int flags_or,unsigned int flags_and)453206b73d0SCy Schubert atheros_sta_set_flags(void *priv, const u8 *addr,
454206b73d0SCy Schubert unsigned int total_flags, unsigned int flags_or,
455206b73d0SCy Schubert unsigned int flags_and)
456206b73d0SCy Schubert {
457206b73d0SCy Schubert /* For now, only support setting Authorized flag */
458206b73d0SCy Schubert if (flags_or & WPA_STA_AUTHORIZED)
459206b73d0SCy Schubert return atheros_set_sta_authorized(priv, addr, 1);
460206b73d0SCy Schubert if (!(flags_and & WPA_STA_AUTHORIZED))
461206b73d0SCy Schubert return atheros_set_sta_authorized(priv, addr, 0);
462206b73d0SCy Schubert return 0;
463206b73d0SCy Schubert }
464206b73d0SCy Schubert
465206b73d0SCy Schubert static int
atheros_del_key(void * priv,const u8 * addr,int key_idx)466206b73d0SCy Schubert atheros_del_key(void *priv, const u8 *addr, int key_idx)
467206b73d0SCy Schubert {
468206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
469206b73d0SCy Schubert struct ieee80211req_del_key wk;
470206b73d0SCy Schubert int ret;
471206b73d0SCy Schubert
472206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
473206b73d0SCy Schubert __func__, ether_sprintf(addr), key_idx);
474206b73d0SCy Schubert
475206b73d0SCy Schubert os_memset(&wk, 0, sizeof(wk));
476206b73d0SCy Schubert if (addr != NULL) {
477206b73d0SCy Schubert os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
478206b73d0SCy Schubert wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
479206b73d0SCy Schubert } else {
480206b73d0SCy Schubert wk.idk_keyix = key_idx;
481206b73d0SCy Schubert }
482206b73d0SCy Schubert
483206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
484206b73d0SCy Schubert if (ret < 0) {
485206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
486206b73d0SCy Schubert " key_idx %d)", __func__, ether_sprintf(addr),
487206b73d0SCy Schubert key_idx);
488206b73d0SCy Schubert }
489206b73d0SCy Schubert
490206b73d0SCy Schubert return ret;
491206b73d0SCy Schubert }
492206b73d0SCy Schubert
493206b73d0SCy Schubert static int
atheros_set_key(void * priv,struct wpa_driver_set_key_params * params)494c1d255d3SCy Schubert atheros_set_key(void *priv, struct wpa_driver_set_key_params *params)
495206b73d0SCy Schubert {
496206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
497206b73d0SCy Schubert struct ieee80211req_key wk;
498206b73d0SCy Schubert u_int8_t cipher;
499206b73d0SCy Schubert int ret;
500c1d255d3SCy Schubert enum wpa_alg alg = params->alg;
501c1d255d3SCy Schubert const u8 *addr = params->addr;
502c1d255d3SCy Schubert int key_idx = params->key_idx;
503c1d255d3SCy Schubert int set_tx = params->set_tx;
504c1d255d3SCy Schubert const u8 *key = params->key;
505c1d255d3SCy Schubert size_t key_len = params->key_len;
506206b73d0SCy Schubert
507206b73d0SCy Schubert if (alg == WPA_ALG_NONE)
508206b73d0SCy Schubert return atheros_del_key(drv, addr, key_idx);
509206b73d0SCy Schubert
510206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
511206b73d0SCy Schubert __func__, alg, ether_sprintf(addr), key_idx);
512206b73d0SCy Schubert
513206b73d0SCy Schubert switch (alg) {
514206b73d0SCy Schubert case WPA_ALG_WEP:
515206b73d0SCy Schubert cipher = IEEE80211_CIPHER_WEP;
516206b73d0SCy Schubert break;
517206b73d0SCy Schubert case WPA_ALG_TKIP:
518206b73d0SCy Schubert cipher = IEEE80211_CIPHER_TKIP;
519206b73d0SCy Schubert break;
520206b73d0SCy Schubert case WPA_ALG_CCMP:
521206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_CCM;
522206b73d0SCy Schubert break;
523206b73d0SCy Schubert #ifdef ATH_GCM_SUPPORT
524206b73d0SCy Schubert case WPA_ALG_CCMP_256:
525206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_CCM_256;
526206b73d0SCy Schubert break;
527206b73d0SCy Schubert case WPA_ALG_GCMP:
528206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_GCM;
529206b73d0SCy Schubert break;
530206b73d0SCy Schubert case WPA_ALG_GCMP_256:
531206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_GCM_256;
532206b73d0SCy Schubert break;
533206b73d0SCy Schubert #endif /* ATH_GCM_SUPPORT */
534c1d255d3SCy Schubert case WPA_ALG_BIP_CMAC_128:
535206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_CMAC;
536206b73d0SCy Schubert break;
537206b73d0SCy Schubert #ifdef ATH_GCM_SUPPORT
538206b73d0SCy Schubert case WPA_ALG_BIP_CMAC_256:
539206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_CMAC_256;
540206b73d0SCy Schubert break;
541206b73d0SCy Schubert case WPA_ALG_BIP_GMAC_128:
542206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_GMAC;
543206b73d0SCy Schubert break;
544206b73d0SCy Schubert case WPA_ALG_BIP_GMAC_256:
545206b73d0SCy Schubert cipher = IEEE80211_CIPHER_AES_GMAC_256;
546206b73d0SCy Schubert break;
547206b73d0SCy Schubert #endif /* ATH_GCM_SUPPORT */
548206b73d0SCy Schubert default:
549206b73d0SCy Schubert wpa_printf(MSG_INFO, "%s: unknown/unsupported algorithm %d",
550206b73d0SCy Schubert __func__, alg);
551206b73d0SCy Schubert return -1;
552206b73d0SCy Schubert }
553206b73d0SCy Schubert
554206b73d0SCy Schubert if (key_len > sizeof(wk.ik_keydata)) {
555206b73d0SCy Schubert wpa_printf(MSG_INFO, "%s: key length %lu too big", __func__,
556206b73d0SCy Schubert (unsigned long) key_len);
557206b73d0SCy Schubert return -3;
558206b73d0SCy Schubert }
559206b73d0SCy Schubert
560206b73d0SCy Schubert os_memset(&wk, 0, sizeof(wk));
561206b73d0SCy Schubert wk.ik_type = cipher;
562206b73d0SCy Schubert wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
563206b73d0SCy Schubert if (addr == NULL || is_broadcast_ether_addr(addr)) {
564206b73d0SCy Schubert os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
565206b73d0SCy Schubert wk.ik_keyix = key_idx;
566206b73d0SCy Schubert if (set_tx)
567206b73d0SCy Schubert wk.ik_flags |= IEEE80211_KEY_DEFAULT;
568206b73d0SCy Schubert } else {
569206b73d0SCy Schubert os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
570206b73d0SCy Schubert wk.ik_keyix = IEEE80211_KEYIX_NONE;
571206b73d0SCy Schubert }
572206b73d0SCy Schubert wk.ik_keylen = key_len;
573206b73d0SCy Schubert os_memcpy(wk.ik_keydata, key, key_len);
574206b73d0SCy Schubert
575206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
576206b73d0SCy Schubert if (ret < 0) {
577206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
578206b73d0SCy Schubert " key_idx %d alg %d key_len %lu set_tx %d)",
579206b73d0SCy Schubert __func__, ether_sprintf(wk.ik_macaddr), key_idx,
580206b73d0SCy Schubert alg, (unsigned long) key_len, set_tx);
581206b73d0SCy Schubert }
582206b73d0SCy Schubert
583206b73d0SCy Schubert return ret;
584206b73d0SCy Schubert }
585206b73d0SCy Schubert
586206b73d0SCy Schubert
587206b73d0SCy Schubert static int
atheros_get_seqnum(const char * ifname,void * priv,const u8 * addr,int idx,int link_id,u8 * seq)588206b73d0SCy Schubert atheros_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
589*a90b9d01SCy Schubert int link_id, u8 *seq)
590206b73d0SCy Schubert {
591206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
592206b73d0SCy Schubert struct ieee80211req_key wk;
593206b73d0SCy Schubert
594206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
595206b73d0SCy Schubert __func__, ether_sprintf(addr), idx);
596206b73d0SCy Schubert
597206b73d0SCy Schubert os_memset(&wk, 0, sizeof(wk));
598206b73d0SCy Schubert if (addr == NULL)
599206b73d0SCy Schubert os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
600206b73d0SCy Schubert else
601206b73d0SCy Schubert os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
602206b73d0SCy Schubert wk.ik_keyix = idx;
603206b73d0SCy Schubert
604206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
605206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
606206b73d0SCy Schubert "(addr " MACSTR " key_idx %d)",
607206b73d0SCy Schubert __func__, MAC2STR(wk.ik_macaddr), idx);
608206b73d0SCy Schubert return -1;
609206b73d0SCy Schubert }
610206b73d0SCy Schubert
611206b73d0SCy Schubert #ifdef WORDS_BIGENDIAN
612206b73d0SCy Schubert {
613206b73d0SCy Schubert /*
614206b73d0SCy Schubert * wk.ik_keytsc is in host byte order (big endian), need to
615206b73d0SCy Schubert * swap it to match with the byte order used in WPA.
616206b73d0SCy Schubert */
617206b73d0SCy Schubert int i;
618206b73d0SCy Schubert #ifndef WPA_KEY_RSC_LEN
619206b73d0SCy Schubert #define WPA_KEY_RSC_LEN 8
620206b73d0SCy Schubert #endif
621206b73d0SCy Schubert u8 tmp[WPA_KEY_RSC_LEN];
622206b73d0SCy Schubert os_memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
623206b73d0SCy Schubert for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
624206b73d0SCy Schubert seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
625206b73d0SCy Schubert }
626206b73d0SCy Schubert }
627206b73d0SCy Schubert #else /* WORDS_BIGENDIAN */
628206b73d0SCy Schubert os_memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
629206b73d0SCy Schubert #endif /* WORDS_BIGENDIAN */
630206b73d0SCy Schubert return 0;
631206b73d0SCy Schubert }
632206b73d0SCy Schubert
633206b73d0SCy Schubert
634206b73d0SCy Schubert static int
atheros_flush(void * priv,int link_id)635*a90b9d01SCy Schubert atheros_flush(void *priv, int link_id)
636206b73d0SCy Schubert {
637206b73d0SCy Schubert u8 allsta[IEEE80211_ADDR_LEN];
638206b73d0SCy Schubert os_memset(allsta, 0xff, IEEE80211_ADDR_LEN);
639206b73d0SCy Schubert return atheros_sta_deauth(priv, NULL, allsta,
640*a90b9d01SCy Schubert IEEE80211_REASON_AUTH_LEAVE, -1);
641206b73d0SCy Schubert }
642206b73d0SCy Schubert
643206b73d0SCy Schubert
644206b73d0SCy Schubert static int
atheros_read_sta_driver_data(void * priv,struct hostap_sta_driver_data * data,const u8 * addr)645206b73d0SCy Schubert atheros_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
646206b73d0SCy Schubert const u8 *addr)
647206b73d0SCy Schubert {
648206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
649206b73d0SCy Schubert struct ieee80211req_sta_stats stats;
650206b73d0SCy Schubert
651206b73d0SCy Schubert os_memset(data, 0, sizeof(*data));
652206b73d0SCy Schubert
653206b73d0SCy Schubert /*
654206b73d0SCy Schubert * Fetch statistics for station from the system.
655206b73d0SCy Schubert */
656206b73d0SCy Schubert os_memset(&stats, 0, sizeof(stats));
657206b73d0SCy Schubert os_memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
658206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_STA_STATS,
659206b73d0SCy Schubert &stats, sizeof(stats))) {
660206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
661206b73d0SCy Schubert MACSTR ")", __func__, MAC2STR(addr));
662*a90b9d01SCy Schubert if (ether_addr_equal(addr, drv->acct_mac)) {
663206b73d0SCy Schubert os_memcpy(data, &drv->acct_data, sizeof(*data));
664206b73d0SCy Schubert return 0;
665206b73d0SCy Schubert }
666206b73d0SCy Schubert
667206b73d0SCy Schubert wpa_printf(MSG_INFO,
668206b73d0SCy Schubert "Failed to get station stats information element");
669206b73d0SCy Schubert return -1;
670206b73d0SCy Schubert }
671206b73d0SCy Schubert
672206b73d0SCy Schubert data->rx_packets = stats.is_stats.ns_rx_data;
673206b73d0SCy Schubert data->rx_bytes = stats.is_stats.ns_rx_bytes;
674206b73d0SCy Schubert data->tx_packets = stats.is_stats.ns_tx_data;
675206b73d0SCy Schubert data->tx_bytes = stats.is_stats.ns_tx_bytes;
676206b73d0SCy Schubert return 0;
677206b73d0SCy Schubert }
678206b73d0SCy Schubert
679206b73d0SCy Schubert
680206b73d0SCy Schubert static int
atheros_sta_clear_stats(void * priv,const u8 * addr)681206b73d0SCy Schubert atheros_sta_clear_stats(void *priv, const u8 *addr)
682206b73d0SCy Schubert {
683206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
684206b73d0SCy Schubert struct ieee80211req_mlme mlme;
685206b73d0SCy Schubert int ret;
686206b73d0SCy Schubert
687206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
688206b73d0SCy Schubert
689206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
690206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
691206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
692206b73d0SCy Schubert sizeof(mlme));
693206b73d0SCy Schubert if (ret < 0) {
694206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
695206b73d0SCy Schubert MACSTR ")", __func__, MAC2STR(addr));
696206b73d0SCy Schubert }
697206b73d0SCy Schubert
698206b73d0SCy Schubert return ret;
699206b73d0SCy Schubert }
700206b73d0SCy Schubert
701206b73d0SCy Schubert
702206b73d0SCy Schubert static int
atheros_set_opt_ie(void * priv,const u8 * ie,size_t ie_len)703206b73d0SCy Schubert atheros_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
704206b73d0SCy Schubert {
705206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
706206b73d0SCy Schubert u8 buf[512];
707206b73d0SCy Schubert struct ieee80211req_getset_appiebuf *app_ie;
708206b73d0SCy Schubert
709206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
710206b73d0SCy Schubert (unsigned long) ie_len);
711206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "atheros: set_generic_elem", ie, ie_len);
712206b73d0SCy Schubert
713206b73d0SCy Schubert wpabuf_free(drv->wpa_ie);
714206b73d0SCy Schubert if (ie)
715206b73d0SCy Schubert drv->wpa_ie = wpabuf_alloc_copy(ie, ie_len);
716206b73d0SCy Schubert else
717206b73d0SCy Schubert drv->wpa_ie = NULL;
718206b73d0SCy Schubert
719206b73d0SCy Schubert app_ie = (struct ieee80211req_getset_appiebuf *) buf;
720206b73d0SCy Schubert if (ie)
721206b73d0SCy Schubert os_memcpy(&(app_ie->app_buf[0]), ie, ie_len);
722206b73d0SCy Schubert app_ie->app_buflen = ie_len;
723206b73d0SCy Schubert
724206b73d0SCy Schubert app_ie->app_frmtype = IEEE80211_APPIE_FRAME_BEACON;
725206b73d0SCy Schubert
726206b73d0SCy Schubert /* append WPS IE for Beacon */
727206b73d0SCy Schubert if (drv->wps_beacon_ie != NULL) {
728206b73d0SCy Schubert os_memcpy(&(app_ie->app_buf[ie_len]),
729206b73d0SCy Schubert wpabuf_head(drv->wps_beacon_ie),
730206b73d0SCy Schubert wpabuf_len(drv->wps_beacon_ie));
731206b73d0SCy Schubert app_ie->app_buflen = ie_len + wpabuf_len(drv->wps_beacon_ie);
732206b73d0SCy Schubert }
733206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(Beacon)",
734206b73d0SCy Schubert app_ie->app_buf, app_ie->app_buflen);
735206b73d0SCy Schubert set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
736206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf) +
737206b73d0SCy Schubert app_ie->app_buflen);
738206b73d0SCy Schubert
739206b73d0SCy Schubert /* append WPS IE for Probe Response */
740206b73d0SCy Schubert app_ie->app_frmtype = IEEE80211_APPIE_FRAME_PROBE_RESP;
741206b73d0SCy Schubert if (drv->wps_probe_resp_ie != NULL) {
742206b73d0SCy Schubert os_memcpy(&(app_ie->app_buf[ie_len]),
743206b73d0SCy Schubert wpabuf_head(drv->wps_probe_resp_ie),
744206b73d0SCy Schubert wpabuf_len(drv->wps_probe_resp_ie));
745206b73d0SCy Schubert app_ie->app_buflen = ie_len +
746206b73d0SCy Schubert wpabuf_len(drv->wps_probe_resp_ie);
747206b73d0SCy Schubert } else
748206b73d0SCy Schubert app_ie->app_buflen = ie_len;
749206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF(ProbeResp)",
750206b73d0SCy Schubert app_ie->app_buf, app_ie->app_buflen);
751206b73d0SCy Schubert set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, app_ie,
752206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf) +
753206b73d0SCy Schubert app_ie->app_buflen);
754206b73d0SCy Schubert return 0;
755206b73d0SCy Schubert }
756206b73d0SCy Schubert
757206b73d0SCy Schubert static int
atheros_sta_deauth(void * priv,const u8 * own_addr,const u8 * addr,u16 reason_code,int link_id)758206b73d0SCy Schubert atheros_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
759*a90b9d01SCy Schubert u16 reason_code, int link_id)
760206b73d0SCy Schubert {
761206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
762206b73d0SCy Schubert struct ieee80211req_mlme mlme;
763206b73d0SCy Schubert int ret;
764206b73d0SCy Schubert
765206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
766206b73d0SCy Schubert __func__, ether_sprintf(addr), reason_code);
767206b73d0SCy Schubert
768206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_DEAUTH;
769206b73d0SCy Schubert mlme.im_reason = reason_code;
770206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
771206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
772206b73d0SCy Schubert if (ret < 0) {
773206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
774206b73d0SCy Schubert " reason %d)",
775206b73d0SCy Schubert __func__, MAC2STR(addr), reason_code);
776206b73d0SCy Schubert }
777206b73d0SCy Schubert
778206b73d0SCy Schubert return ret;
779206b73d0SCy Schubert }
780206b73d0SCy Schubert
781206b73d0SCy Schubert static int
atheros_sta_disassoc(void * priv,const u8 * own_addr,const u8 * addr,u16 reason_code)782206b73d0SCy Schubert atheros_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
783206b73d0SCy Schubert u16 reason_code)
784206b73d0SCy Schubert {
785206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
786206b73d0SCy Schubert struct ieee80211req_mlme mlme;
787206b73d0SCy Schubert int ret;
788206b73d0SCy Schubert
789206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
790206b73d0SCy Schubert __func__, ether_sprintf(addr), reason_code);
791206b73d0SCy Schubert
792206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_DISASSOC;
793206b73d0SCy Schubert mlme.im_reason = reason_code;
794206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
795206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
796206b73d0SCy Schubert if (ret < 0) {
797206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
798206b73d0SCy Schubert MACSTR " reason %d)",
799206b73d0SCy Schubert __func__, MAC2STR(addr), reason_code);
800206b73d0SCy Schubert }
801206b73d0SCy Schubert
802206b73d0SCy Schubert return ret;
803206b73d0SCy Schubert }
804206b73d0SCy Schubert
atheros_set_qos_map(void * ctx,const u8 * qos_map_set,u8 qos_map_set_len)805206b73d0SCy Schubert static int atheros_set_qos_map(void *ctx, const u8 *qos_map_set,
806206b73d0SCy Schubert u8 qos_map_set_len)
807206b73d0SCy Schubert {
808206b73d0SCy Schubert #ifdef CONFIG_ATHEROS_QOS_MAP
809206b73d0SCy Schubert struct atheros_driver_data *drv = ctx;
810206b73d0SCy Schubert struct ieee80211req_athdbg req;
811206b73d0SCy Schubert struct ieee80211_qos_map *qos_map = &req.data.qos_map;
812206b73d0SCy Schubert struct iwreq iwr;
813206b73d0SCy Schubert int i, up_start;
814206b73d0SCy Schubert
815206b73d0SCy Schubert if (qos_map_set_len < 16 || qos_map_set_len > 58 ||
816206b73d0SCy Schubert qos_map_set_len & 1) {
817206b73d0SCy Schubert wpa_printf(MSG_ERROR, "Invalid QoS Map");
818206b73d0SCy Schubert return -1;
819206b73d0SCy Schubert } else {
820206b73d0SCy Schubert os_memset(&req, 0, sizeof(struct ieee80211req_athdbg));
821206b73d0SCy Schubert req.cmd = IEEE80211_DBGREQ_SETQOSMAPCONF;
822206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
823206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, sizeof(iwr.ifr_name));
824206b73d0SCy Schubert iwr.u.data.pointer = (void *) &req;
825206b73d0SCy Schubert iwr.u.data.length = sizeof(struct ieee80211req_athdbg);
826206b73d0SCy Schubert }
827206b73d0SCy Schubert
828206b73d0SCy Schubert qos_map->valid = 1;
829206b73d0SCy Schubert qos_map->num_dscp_except = (qos_map_set_len - 16) / 2;
830206b73d0SCy Schubert if (qos_map->num_dscp_except) {
831206b73d0SCy Schubert for (i = 0; i < qos_map->num_dscp_except; i++) {
832206b73d0SCy Schubert qos_map->dscp_exception[i].dscp = qos_map_set[i * 2];
833206b73d0SCy Schubert qos_map->dscp_exception[i].up = qos_map_set[i * 2 + 1];
834206b73d0SCy Schubert }
835206b73d0SCy Schubert }
836206b73d0SCy Schubert
837206b73d0SCy Schubert up_start = qos_map_set_len - 16;
838206b73d0SCy Schubert for (i = 0; i < IEEE80211_MAX_QOS_UP_RANGE; i++) {
839206b73d0SCy Schubert qos_map->up[i].low = qos_map_set[up_start + (i * 2)];
840206b73d0SCy Schubert qos_map->up[i].high = qos_map_set[up_start + (i * 2) + 1];
841206b73d0SCy Schubert }
842206b73d0SCy Schubert
843206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_DBGREQ, &iwr) < 0) {
844206b73d0SCy Schubert wpa_printf(MSG_ERROR,
845206b73d0SCy Schubert "%s: %s: Failed to set QoS Map: ioctl[IEEE80211_IOCTL_DBGREQ]: %s",
846206b73d0SCy Schubert __func__, drv->iface, strerror(errno));
847206b73d0SCy Schubert return -1;
848206b73d0SCy Schubert }
849206b73d0SCy Schubert #endif /* CONFIG_ATHEROS_QOS_MAP */
850206b73d0SCy Schubert
851206b73d0SCy Schubert return 0;
852206b73d0SCy Schubert }
853206b73d0SCy Schubert
854c1d255d3SCy Schubert
atheros_raw_receive(void * ctx,const u8 * src_addr,const u8 * buf,size_t len)855206b73d0SCy Schubert static void atheros_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
856206b73d0SCy Schubert size_t len)
857206b73d0SCy Schubert {
858206b73d0SCy Schubert struct atheros_driver_data *drv = ctx;
859206b73d0SCy Schubert const struct ieee80211_mgmt *mgmt;
860206b73d0SCy Schubert union wpa_event_data event;
861206b73d0SCy Schubert u16 fc, stype;
862206b73d0SCy Schubert int ielen;
863206b73d0SCy Schubert const u8 *iebuf;
864206b73d0SCy Schubert
865206b73d0SCy Schubert if (len < IEEE80211_HDRLEN)
866206b73d0SCy Schubert return;
867206b73d0SCy Schubert
868206b73d0SCy Schubert mgmt = (const struct ieee80211_mgmt *) buf;
869206b73d0SCy Schubert
870206b73d0SCy Schubert fc = le_to_host16(mgmt->frame_control);
871206b73d0SCy Schubert
872206b73d0SCy Schubert if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT)
873206b73d0SCy Schubert return;
874206b73d0SCy Schubert
875206b73d0SCy Schubert stype = WLAN_FC_GET_STYPE(fc);
876206b73d0SCy Schubert
877206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: subtype 0x%x len %d", __func__, stype,
878206b73d0SCy Schubert (int) len);
879206b73d0SCy Schubert
880206b73d0SCy Schubert if (stype == WLAN_FC_STYPE_PROBE_REQ) {
881206b73d0SCy Schubert if (len < IEEE80211_HDRLEN)
882206b73d0SCy Schubert return;
883206b73d0SCy Schubert
884206b73d0SCy Schubert os_memset(&event, 0, sizeof(event));
885206b73d0SCy Schubert event.rx_probe_req.sa = mgmt->sa;
886206b73d0SCy Schubert event.rx_probe_req.da = mgmt->da;
887206b73d0SCy Schubert event.rx_probe_req.bssid = mgmt->bssid;
888206b73d0SCy Schubert event.rx_probe_req.ie = buf + IEEE80211_HDRLEN;
889206b73d0SCy Schubert event.rx_probe_req.ie_len = len - IEEE80211_HDRLEN;
890206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_RX_PROBE_REQ, &event);
891206b73d0SCy Schubert return;
892206b73d0SCy Schubert }
893206b73d0SCy Schubert
894206b73d0SCy Schubert if (stype == WLAN_FC_STYPE_ACTION &&
895*a90b9d01SCy Schubert (ether_addr_equal(drv->own_addr, mgmt->bssid) ||
896206b73d0SCy Schubert is_broadcast_ether_addr(mgmt->bssid))) {
897206b73d0SCy Schubert os_memset(&event, 0, sizeof(event));
898206b73d0SCy Schubert event.rx_mgmt.frame = buf;
899206b73d0SCy Schubert event.rx_mgmt.frame_len = len;
900206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
901206b73d0SCy Schubert return;
902206b73d0SCy Schubert }
903206b73d0SCy Schubert
904*a90b9d01SCy Schubert if (!ether_addr_equal(drv->own_addr, mgmt->bssid)) {
905206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: BSSID does not match - ignore",
906206b73d0SCy Schubert __func__);
907206b73d0SCy Schubert return;
908206b73d0SCy Schubert }
909206b73d0SCy Schubert
910206b73d0SCy Schubert switch (stype) {
911206b73d0SCy Schubert case WLAN_FC_STYPE_ASSOC_REQ:
912206b73d0SCy Schubert if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req))
913206b73d0SCy Schubert break;
914206b73d0SCy Schubert ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
915206b73d0SCy Schubert iebuf = mgmt->u.assoc_req.variable;
916*a90b9d01SCy Schubert drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, NULL, 0,
917*a90b9d01SCy Schubert NULL, -1, 0);
918206b73d0SCy Schubert break;
919206b73d0SCy Schubert case WLAN_FC_STYPE_REASSOC_REQ:
920206b73d0SCy Schubert if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req))
921206b73d0SCy Schubert break;
922206b73d0SCy Schubert ielen = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
923206b73d0SCy Schubert iebuf = mgmt->u.reassoc_req.variable;
924*a90b9d01SCy Schubert drv_event_assoc(drv->hapd, mgmt->sa, iebuf, ielen, NULL, 0,
925*a90b9d01SCy Schubert NULL, -1, 1);
926206b73d0SCy Schubert break;
927206b73d0SCy Schubert case WLAN_FC_STYPE_AUTH:
928206b73d0SCy Schubert if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth))
929206b73d0SCy Schubert break;
930206b73d0SCy Schubert os_memset(&event, 0, sizeof(event));
931206b73d0SCy Schubert if (le_to_host16(mgmt->u.auth.auth_alg) == WLAN_AUTH_SAE) {
932206b73d0SCy Schubert event.rx_mgmt.frame = buf;
933206b73d0SCy Schubert event.rx_mgmt.frame_len = len;
934206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT, &event);
935206b73d0SCy Schubert break;
936206b73d0SCy Schubert }
937206b73d0SCy Schubert os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN);
938206b73d0SCy Schubert os_memcpy(event.auth.bssid, mgmt->bssid, ETH_ALEN);
939206b73d0SCy Schubert event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg);
940206b73d0SCy Schubert event.auth.status_code =
941206b73d0SCy Schubert le_to_host16(mgmt->u.auth.status_code);
942206b73d0SCy Schubert event.auth.auth_transaction =
943206b73d0SCy Schubert le_to_host16(mgmt->u.auth.auth_transaction);
944206b73d0SCy Schubert event.auth.ies = mgmt->u.auth.variable;
945206b73d0SCy Schubert event.auth.ies_len = len - IEEE80211_HDRLEN -
946206b73d0SCy Schubert sizeof(mgmt->u.auth);
947206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_AUTH, &event);
948206b73d0SCy Schubert break;
949206b73d0SCy Schubert default:
950206b73d0SCy Schubert break;
951206b73d0SCy Schubert }
952206b73d0SCy Schubert }
953c1d255d3SCy Schubert
954206b73d0SCy Schubert
atheros_receive_pkt(struct atheros_driver_data * drv)955206b73d0SCy Schubert static int atheros_receive_pkt(struct atheros_driver_data *drv)
956206b73d0SCy Schubert {
957206b73d0SCy Schubert int ret = 0;
958206b73d0SCy Schubert struct ieee80211req_set_filter filt;
959206b73d0SCy Schubert
960206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s Enter", __func__);
961206b73d0SCy Schubert filt.app_filterype = 0;
962206b73d0SCy Schubert #ifdef CONFIG_WPS
963206b73d0SCy Schubert filt.app_filterype |= IEEE80211_FILTER_TYPE_PROBE_REQ;
964206b73d0SCy Schubert #endif /* CONFIG_WPS */
965206b73d0SCy Schubert filt.app_filterype |= (IEEE80211_FILTER_TYPE_ASSOC_REQ |
966206b73d0SCy Schubert IEEE80211_FILTER_TYPE_AUTH |
967206b73d0SCy Schubert IEEE80211_FILTER_TYPE_ACTION);
968206b73d0SCy Schubert #ifdef CONFIG_WNM
969206b73d0SCy Schubert filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
970206b73d0SCy Schubert #endif /* CONFIG_WNM */
971206b73d0SCy Schubert #ifdef CONFIG_HS20
972206b73d0SCy Schubert filt.app_filterype |= IEEE80211_FILTER_TYPE_ACTION;
973206b73d0SCy Schubert #endif /* CONFIG_HS20 */
974206b73d0SCy Schubert if (filt.app_filterype) {
975206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
976206b73d0SCy Schubert sizeof(struct ieee80211req_set_filter));
977206b73d0SCy Schubert if (ret)
978206b73d0SCy Schubert return ret;
979206b73d0SCy Schubert }
980206b73d0SCy Schubert
981206b73d0SCy Schubert #if defined(CONFIG_WPS) || defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
982206b73d0SCy Schubert drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
983206b73d0SCy Schubert atheros_raw_receive, drv, 1);
984206b73d0SCy Schubert if (drv->sock_raw == NULL)
985206b73d0SCy Schubert return -1;
986206b73d0SCy Schubert #endif /* CONFIG_WPS || CONFIG_IEEE80211R || CONFIG_FILS */
987206b73d0SCy Schubert return ret;
988206b73d0SCy Schubert }
989206b73d0SCy Schubert
atheros_reset_appfilter(struct atheros_driver_data * drv)990206b73d0SCy Schubert static int atheros_reset_appfilter(struct atheros_driver_data *drv)
991206b73d0SCy Schubert {
992206b73d0SCy Schubert struct ieee80211req_set_filter filt;
993206b73d0SCy Schubert filt.app_filterype = 0;
994206b73d0SCy Schubert return set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
995206b73d0SCy Schubert sizeof(struct ieee80211req_set_filter));
996206b73d0SCy Schubert }
997206b73d0SCy Schubert
998206b73d0SCy Schubert #ifdef CONFIG_WPS
999206b73d0SCy Schubert static int
atheros_set_wps_ie(void * priv,const u8 * ie,size_t len,u32 frametype)1000206b73d0SCy Schubert atheros_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
1001206b73d0SCy Schubert {
1002206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1003206b73d0SCy Schubert u8 buf[512];
1004206b73d0SCy Schubert struct ieee80211req_getset_appiebuf *beac_ie;
1005206b73d0SCy Schubert
1006206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s buflen = %lu frametype=%u", __func__,
1007206b73d0SCy Schubert (unsigned long) len, frametype);
1008206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "atheros: IE", ie, len);
1009206b73d0SCy Schubert
1010206b73d0SCy Schubert beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
1011206b73d0SCy Schubert beac_ie->app_frmtype = frametype;
1012206b73d0SCy Schubert beac_ie->app_buflen = len;
1013206b73d0SCy Schubert if (ie)
1014206b73d0SCy Schubert os_memcpy(&(beac_ie->app_buf[0]), ie, len);
1015206b73d0SCy Schubert
1016206b73d0SCy Schubert /* append the WPA/RSN IE if it is set already */
1017206b73d0SCy Schubert if (((frametype == IEEE80211_APPIE_FRAME_BEACON) ||
1018206b73d0SCy Schubert (frametype == IEEE80211_APPIE_FRAME_PROBE_RESP)) &&
1019206b73d0SCy Schubert (drv->wpa_ie != NULL)) {
1020206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: Append WPA/RSN IE",
1021206b73d0SCy Schubert drv->wpa_ie);
1022206b73d0SCy Schubert os_memcpy(&(beac_ie->app_buf[len]), wpabuf_head(drv->wpa_ie),
1023206b73d0SCy Schubert wpabuf_len(drv->wpa_ie));
1024206b73d0SCy Schubert beac_ie->app_buflen += wpabuf_len(drv->wpa_ie);
1025206b73d0SCy Schubert }
1026206b73d0SCy Schubert
1027206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "atheros: SET_APPIEBUF",
1028206b73d0SCy Schubert beac_ie->app_buf, beac_ie->app_buflen);
1029206b73d0SCy Schubert return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
1030206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf) +
1031206b73d0SCy Schubert beac_ie->app_buflen);
1032206b73d0SCy Schubert }
1033206b73d0SCy Schubert
1034206b73d0SCy Schubert static int
atheros_set_ap_wps_ie(void * priv,const struct wpabuf * beacon,const struct wpabuf * proberesp,const struct wpabuf * assocresp)1035206b73d0SCy Schubert atheros_set_ap_wps_ie(void *priv, const struct wpabuf *beacon,
1036206b73d0SCy Schubert const struct wpabuf *proberesp,
1037206b73d0SCy Schubert const struct wpabuf *assocresp)
1038206b73d0SCy Schubert {
1039206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1040206b73d0SCy Schubert
1041206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - beacon", beacon);
1042206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - proberesp",
1043206b73d0SCy Schubert proberesp);
1044206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: set_ap_wps_ie - assocresp",
1045206b73d0SCy Schubert assocresp);
1046206b73d0SCy Schubert wpabuf_free(drv->wps_beacon_ie);
1047206b73d0SCy Schubert drv->wps_beacon_ie = beacon ? wpabuf_dup(beacon) : NULL;
1048206b73d0SCy Schubert wpabuf_free(drv->wps_probe_resp_ie);
1049206b73d0SCy Schubert drv->wps_probe_resp_ie = proberesp ? wpabuf_dup(proberesp) : NULL;
1050206b73d0SCy Schubert
1051206b73d0SCy Schubert atheros_set_wps_ie(priv, assocresp ? wpabuf_head(assocresp) : NULL,
1052206b73d0SCy Schubert assocresp ? wpabuf_len(assocresp) : 0,
1053206b73d0SCy Schubert IEEE80211_APPIE_FRAME_ASSOC_RESP);
1054206b73d0SCy Schubert if (atheros_set_wps_ie(priv, beacon ? wpabuf_head(beacon) : NULL,
1055206b73d0SCy Schubert beacon ? wpabuf_len(beacon) : 0,
1056206b73d0SCy Schubert IEEE80211_APPIE_FRAME_BEACON))
1057206b73d0SCy Schubert return -1;
1058206b73d0SCy Schubert return atheros_set_wps_ie(priv,
1059206b73d0SCy Schubert proberesp ? wpabuf_head(proberesp) : NULL,
1060206b73d0SCy Schubert proberesp ? wpabuf_len(proberesp): 0,
1061206b73d0SCy Schubert IEEE80211_APPIE_FRAME_PROBE_RESP);
1062206b73d0SCy Schubert }
1063206b73d0SCy Schubert #else /* CONFIG_WPS */
1064206b73d0SCy Schubert #define atheros_set_ap_wps_ie NULL
1065206b73d0SCy Schubert #endif /* CONFIG_WPS */
1066206b73d0SCy Schubert
1067206b73d0SCy Schubert static int
atheros_sta_auth(void * priv,struct wpa_driver_sta_auth_params * params)1068206b73d0SCy Schubert atheros_sta_auth(void *priv, struct wpa_driver_sta_auth_params *params)
1069206b73d0SCy Schubert {
1070206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1071206b73d0SCy Schubert struct ieee80211req_mlme mlme;
1072206b73d0SCy Schubert int ret;
1073206b73d0SCy Schubert
1074206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d",
1075206b73d0SCy Schubert __func__, ether_sprintf(params->addr), params->status);
1076206b73d0SCy Schubert
1077206b73d0SCy Schubert #ifdef CONFIG_FILS
1078206b73d0SCy Schubert /* Copy FILS AAD parameters if the driver supports FILS */
1079206b73d0SCy Schubert if (params->fils_auth && drv->fils_en) {
1080206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: im_op IEEE80211_MLME_AUTH_FILS",
1081206b73d0SCy Schubert __func__);
1082206b73d0SCy Schubert os_memcpy(mlme.fils_aad.ANonce, params->fils_anonce,
1083206b73d0SCy Schubert IEEE80211_FILS_NONCE_LEN);
1084206b73d0SCy Schubert os_memcpy(mlme.fils_aad.SNonce, params->fils_snonce,
1085206b73d0SCy Schubert IEEE80211_FILS_NONCE_LEN);
1086206b73d0SCy Schubert os_memcpy(mlme.fils_aad.kek, params->fils_kek,
1087206b73d0SCy Schubert IEEE80211_MAX_WPA_KEK_LEN);
1088206b73d0SCy Schubert mlme.fils_aad.kek_len = params->fils_kek_len;
1089206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_AUTH_FILS;
1090206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "FILS: ANonce",
1091206b73d0SCy Schubert mlme.fils_aad.ANonce, FILS_NONCE_LEN);
1092206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "FILS: SNonce",
1093206b73d0SCy Schubert mlme.fils_aad.SNonce, FILS_NONCE_LEN);
1094206b73d0SCy Schubert wpa_hexdump_key(MSG_DEBUG, "FILS: KEK",
1095206b73d0SCy Schubert mlme.fils_aad.kek, mlme.fils_aad.kek_len);
1096206b73d0SCy Schubert } else {
1097206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_AUTH;
1098206b73d0SCy Schubert }
1099206b73d0SCy Schubert #else /* CONFIG_FILS */
1100206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_AUTH;
1101206b73d0SCy Schubert #endif /* CONFIG_FILS */
1102206b73d0SCy Schubert
1103206b73d0SCy Schubert mlme.im_reason = params->status;
1104206b73d0SCy Schubert mlme.im_seq = params->seq;
1105206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, params->addr, IEEE80211_ADDR_LEN);
1106206b73d0SCy Schubert mlme.im_optie_len = params->len;
1107206b73d0SCy Schubert if (params->len) {
1108206b73d0SCy Schubert if (params->len < IEEE80211_MAX_OPT_IE) {
1109206b73d0SCy Schubert os_memcpy(mlme.im_optie, params->ie, params->len);
1110206b73d0SCy Schubert } else {
1111206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1112206b73d0SCy Schubert "opt_ie STA (addr " MACSTR " reason %d, "
1113206b73d0SCy Schubert "ie_len %d)",
1114206b73d0SCy Schubert __func__, MAC2STR(params->addr),
1115206b73d0SCy Schubert params->status, (int) params->len);
1116206b73d0SCy Schubert return -1;
1117206b73d0SCy Schubert }
1118206b73d0SCy Schubert }
1119206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1120206b73d0SCy Schubert if (ret < 0) {
1121206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to auth STA (addr " MACSTR
1122206b73d0SCy Schubert " reason %d)",
1123206b73d0SCy Schubert __func__, MAC2STR(params->addr), params->status);
1124206b73d0SCy Schubert }
1125206b73d0SCy Schubert return ret;
1126206b73d0SCy Schubert }
1127206b73d0SCy Schubert
1128206b73d0SCy Schubert 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)1129206b73d0SCy Schubert atheros_sta_assoc(void *priv, const u8 *own_addr, const u8 *addr,
1130206b73d0SCy Schubert int reassoc, u16 status_code, const u8 *ie, size_t len)
1131206b73d0SCy Schubert {
1132206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1133206b73d0SCy Schubert struct ieee80211req_mlme mlme;
1134206b73d0SCy Schubert int ret;
1135206b73d0SCy Schubert
1136206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: addr=%s status_code=%d reassoc %d",
1137206b73d0SCy Schubert __func__, ether_sprintf(addr), status_code, reassoc);
1138206b73d0SCy Schubert
1139206b73d0SCy Schubert if (reassoc)
1140206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_REASSOC;
1141206b73d0SCy Schubert else
1142206b73d0SCy Schubert mlme.im_op = IEEE80211_MLME_ASSOC;
1143206b73d0SCy Schubert mlme.im_reason = status_code;
1144206b73d0SCy Schubert os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
1145206b73d0SCy Schubert mlme.im_optie_len = len;
1146206b73d0SCy Schubert if (len) {
1147206b73d0SCy Schubert if (len < IEEE80211_MAX_OPT_IE) {
1148206b73d0SCy Schubert os_memcpy(mlme.im_optie, ie, len);
1149206b73d0SCy Schubert } else {
1150206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Not enough space to copy "
1151206b73d0SCy Schubert "opt_ie STA (addr " MACSTR " reason %d, "
1152206b73d0SCy Schubert "ie_len %d)",
1153206b73d0SCy Schubert __func__, MAC2STR(addr), status_code,
1154206b73d0SCy Schubert (int) len);
1155206b73d0SCy Schubert return -1;
1156206b73d0SCy Schubert }
1157206b73d0SCy Schubert }
1158206b73d0SCy Schubert ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
1159206b73d0SCy Schubert if (ret < 0) {
1160206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to assoc STA (addr " MACSTR
1161206b73d0SCy Schubert " reason %d)",
1162206b73d0SCy Schubert __func__, MAC2STR(addr), status_code);
1163206b73d0SCy Schubert }
1164206b73d0SCy Schubert return ret;
1165206b73d0SCy Schubert }
1166c1d255d3SCy Schubert
1167206b73d0SCy Schubert
1168206b73d0SCy Schubert static void
atheros_new_sta(struct atheros_driver_data * drv,u8 addr[IEEE80211_ADDR_LEN])1169206b73d0SCy Schubert atheros_new_sta(struct atheros_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
1170206b73d0SCy Schubert {
1171206b73d0SCy Schubert struct hostapd_data *hapd = drv->hapd;
1172206b73d0SCy Schubert struct ieee80211req_wpaie ie;
1173206b73d0SCy Schubert int ielen = 0;
1174206b73d0SCy Schubert u8 *iebuf = NULL;
1175206b73d0SCy Schubert
1176206b73d0SCy Schubert /*
1177206b73d0SCy Schubert * Fetch negotiated WPA/RSN parameters from the system.
1178206b73d0SCy Schubert */
1179206b73d0SCy Schubert os_memset(&ie, 0, sizeof(ie));
1180206b73d0SCy Schubert os_memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
1181206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
1182206b73d0SCy Schubert /*
1183206b73d0SCy Schubert * See ATH_WPS_IE comment in the beginning of the file for a
1184206b73d0SCy Schubert * possible cause for the failure..
1185206b73d0SCy Schubert */
1186206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE: %s",
1187206b73d0SCy Schubert __func__, strerror(errno));
1188206b73d0SCy Schubert goto no_ie;
1189206b73d0SCy Schubert }
1190206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "atheros req WPA IE",
1191206b73d0SCy Schubert ie.wpa_ie, IEEE80211_MAX_OPT_IE);
1192206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "atheros req RSN IE",
1193206b73d0SCy Schubert ie.rsn_ie, IEEE80211_MAX_OPT_IE);
1194206b73d0SCy Schubert #ifdef ATH_WPS_IE
1195206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "atheros req WPS IE",
1196206b73d0SCy Schubert ie.wps_ie, IEEE80211_MAX_OPT_IE);
1197206b73d0SCy Schubert #endif /* ATH_WPS_IE */
1198206b73d0SCy Schubert iebuf = ie.wpa_ie;
1199206b73d0SCy Schubert /* atheros seems to return some random data if WPA/RSN IE is not set.
1200206b73d0SCy Schubert * Assume the IE was not included if the IE type is unknown. */
1201206b73d0SCy Schubert if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
1202206b73d0SCy Schubert iebuf[1] = 0;
1203206b73d0SCy Schubert if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
1204206b73d0SCy Schubert /* atheros-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
1205206b73d0SCy Schubert * set. This is needed for WPA2. */
1206206b73d0SCy Schubert iebuf = ie.rsn_ie;
1207206b73d0SCy Schubert if (iebuf[0] != WLAN_EID_RSN)
1208206b73d0SCy Schubert iebuf[1] = 0;
1209206b73d0SCy Schubert }
1210206b73d0SCy Schubert
1211206b73d0SCy Schubert ielen = iebuf[1];
1212206b73d0SCy Schubert
1213206b73d0SCy Schubert #ifdef ATH_WPS_IE
1214206b73d0SCy Schubert /* if WPS IE is present, preference is given to WPS */
1215206b73d0SCy Schubert if (ie.wps_ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie.wps_ie[1] > 0) {
1216206b73d0SCy Schubert iebuf = ie.wps_ie;
1217206b73d0SCy Schubert ielen = ie.wps_ie[1];
1218206b73d0SCy Schubert }
1219206b73d0SCy Schubert #endif /* ATH_WPS_IE */
1220206b73d0SCy Schubert
1221206b73d0SCy Schubert if (ielen == 0)
1222206b73d0SCy Schubert iebuf = NULL;
1223206b73d0SCy Schubert else
1224206b73d0SCy Schubert ielen += 2;
1225206b73d0SCy Schubert
1226206b73d0SCy Schubert no_ie:
1227*a90b9d01SCy Schubert drv_event_assoc(hapd, addr, iebuf, ielen, NULL, 0, NULL, -1, 0);
1228206b73d0SCy Schubert
1229*a90b9d01SCy Schubert if (ether_addr_equal(addr, drv->acct_mac)) {
1230206b73d0SCy Schubert /* Cached accounting data is not valid anymore. */
1231206b73d0SCy Schubert os_memset(drv->acct_mac, 0, ETH_ALEN);
1232206b73d0SCy Schubert os_memset(&drv->acct_data, 0, sizeof(drv->acct_data));
1233206b73d0SCy Schubert }
1234206b73d0SCy Schubert }
1235206b73d0SCy Schubert
1236206b73d0SCy Schubert static void
atheros_wireless_event_wireless_custom(struct atheros_driver_data * drv,char * custom,char * end)1237206b73d0SCy Schubert atheros_wireless_event_wireless_custom(struct atheros_driver_data *drv,
1238206b73d0SCy Schubert char *custom, char *end)
1239206b73d0SCy Schubert {
1240206b73d0SCy Schubert #define MGMT_FRAM_TAG_SIZE 30 /* hardcoded in driver */
1241206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
1242206b73d0SCy Schubert
1243206b73d0SCy Schubert if (os_strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
1244206b73d0SCy Schubert char *pos;
1245206b73d0SCy Schubert u8 addr[ETH_ALEN];
1246206b73d0SCy Schubert pos = os_strstr(custom, "addr=");
1247206b73d0SCy Schubert if (pos == NULL) {
1248206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1249206b73d0SCy Schubert "MLME-MICHAELMICFAILURE.indication "
1250206b73d0SCy Schubert "without sender address ignored");
1251206b73d0SCy Schubert return;
1252206b73d0SCy Schubert }
1253206b73d0SCy Schubert pos += 5;
1254206b73d0SCy Schubert if (hwaddr_aton(pos, addr) == 0) {
1255206b73d0SCy Schubert union wpa_event_data data;
1256206b73d0SCy Schubert os_memset(&data, 0, sizeof(data));
1257206b73d0SCy Schubert data.michael_mic_failure.unicast = 1;
1258206b73d0SCy Schubert data.michael_mic_failure.src = addr;
1259206b73d0SCy Schubert wpa_supplicant_event(drv->hapd,
1260206b73d0SCy Schubert EVENT_MICHAEL_MIC_FAILURE, &data);
1261206b73d0SCy Schubert } else {
1262206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1263206b73d0SCy Schubert "MLME-MICHAELMICFAILURE.indication "
1264206b73d0SCy Schubert "with invalid MAC address");
1265206b73d0SCy Schubert }
1266206b73d0SCy Schubert } else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
1267206b73d0SCy Schubert char *key, *value;
1268206b73d0SCy Schubert u32 val;
1269206b73d0SCy Schubert key = custom;
1270206b73d0SCy Schubert while ((key = os_strchr(key, '\n')) != NULL) {
1271206b73d0SCy Schubert key++;
1272206b73d0SCy Schubert value = os_strchr(key, '=');
1273206b73d0SCy Schubert if (value == NULL)
1274206b73d0SCy Schubert continue;
1275206b73d0SCy Schubert *value++ = '\0';
1276206b73d0SCy Schubert val = strtoul(value, NULL, 10);
1277206b73d0SCy Schubert if (os_strcmp(key, "mac") == 0)
1278206b73d0SCy Schubert hwaddr_aton(value, drv->acct_mac);
1279206b73d0SCy Schubert else if (os_strcmp(key, "rx_packets") == 0)
1280206b73d0SCy Schubert drv->acct_data.rx_packets = val;
1281206b73d0SCy Schubert else if (os_strcmp(key, "tx_packets") == 0)
1282206b73d0SCy Schubert drv->acct_data.tx_packets = val;
1283206b73d0SCy Schubert else if (os_strcmp(key, "rx_bytes") == 0)
1284206b73d0SCy Schubert drv->acct_data.rx_bytes = val;
1285206b73d0SCy Schubert else if (os_strcmp(key, "tx_bytes") == 0)
1286206b73d0SCy Schubert drv->acct_data.tx_bytes = val;
1287206b73d0SCy Schubert key = value;
1288206b73d0SCy Schubert }
1289206b73d0SCy Schubert #ifdef CONFIG_WPS
1290206b73d0SCy Schubert } else if (os_strncmp(custom, "PUSH-BUTTON.indication", 22) == 0) {
1291206b73d0SCy Schubert /* Some atheros kernels send push button as a wireless event */
1292206b73d0SCy Schubert /* PROBLEM! this event is received for ALL BSSs ...
1293206b73d0SCy Schubert * so all are enabled for WPS... ugh.
1294206b73d0SCy Schubert */
1295206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_WPS_BUTTON_PUSHED, NULL);
1296206b73d0SCy Schubert } else if (os_strncmp(custom, "Manage.prob_req ", 16) == 0) {
1297206b73d0SCy Schubert /*
1298206b73d0SCy Schubert * Atheros driver uses a hack to pass Probe Request frames as a
1299206b73d0SCy Schubert * binary data in the custom wireless event. The old way (using
1300206b73d0SCy Schubert * packet sniffing) didn't work when bridging.
1301206b73d0SCy Schubert * Format: "Manage.prob_req <frame len>" | zero padding | frame
1302206b73d0SCy Schubert */
1303206b73d0SCy Schubert int len = atoi(custom + 16);
1304206b73d0SCy Schubert if (len < 0 || MGMT_FRAM_TAG_SIZE + len > end - custom) {
1305206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "Invalid Manage.prob_req event "
1306206b73d0SCy Schubert "length %d", len);
1307206b73d0SCy Schubert return;
1308206b73d0SCy Schubert }
1309206b73d0SCy Schubert atheros_raw_receive(drv, NULL,
1310206b73d0SCy Schubert (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1311206b73d0SCy Schubert #endif /* CONFIG_WPS */
1312206b73d0SCy Schubert } else if (os_strncmp(custom, "Manage.assoc_req ", 17) == 0) {
1313206b73d0SCy Schubert /* Format: "Manage.assoc_req <frame len>" | zero padding |
1314206b73d0SCy Schubert * frame */
1315206b73d0SCy Schubert int len = atoi(custom + 17);
1316206b73d0SCy Schubert if (len < 0 || MGMT_FRAM_TAG_SIZE + len > end - custom) {
1317206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1318206b73d0SCy Schubert "Invalid Manage.assoc_req event length %d",
1319206b73d0SCy Schubert len);
1320206b73d0SCy Schubert return;
1321206b73d0SCy Schubert }
1322206b73d0SCy Schubert atheros_raw_receive(drv, NULL,
1323206b73d0SCy Schubert (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1324206b73d0SCy Schubert } else if (os_strncmp(custom, "Manage.auth ", 12) == 0) {
1325206b73d0SCy Schubert /* Format: "Manage.auth <frame len>" | zero padding | frame */
1326206b73d0SCy Schubert int len = atoi(custom + 12);
1327206b73d0SCy Schubert if (len < 0 ||
1328206b73d0SCy Schubert MGMT_FRAM_TAG_SIZE + len > end - custom) {
1329206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1330206b73d0SCy Schubert "Invalid Manage.auth event length %d", len);
1331206b73d0SCy Schubert return;
1332206b73d0SCy Schubert }
1333206b73d0SCy Schubert atheros_raw_receive(drv, NULL,
1334206b73d0SCy Schubert (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1335206b73d0SCy Schubert } else if (os_strncmp(custom, "Manage.action ", 14) == 0) {
1336206b73d0SCy Schubert /* Format: "Manage.assoc_req <frame len>" | zero padding | frame
1337206b73d0SCy Schubert */
1338206b73d0SCy Schubert int len = atoi(custom + 14);
1339206b73d0SCy Schubert if (len < 0 || MGMT_FRAM_TAG_SIZE + len > end - custom) {
1340206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1341206b73d0SCy Schubert "Invalid Manage.action event length %d",
1342206b73d0SCy Schubert len);
1343206b73d0SCy Schubert return;
1344206b73d0SCy Schubert }
1345206b73d0SCy Schubert atheros_raw_receive(drv, NULL,
1346206b73d0SCy Schubert (u8 *) custom + MGMT_FRAM_TAG_SIZE, len);
1347206b73d0SCy Schubert }
1348206b73d0SCy Schubert }
1349206b73d0SCy Schubert
1350206b73d0SCy Schubert
send_action_cb_event(struct atheros_driver_data * drv,char * data,size_t data_len)1351206b73d0SCy Schubert static void send_action_cb_event(struct atheros_driver_data *drv,
1352206b73d0SCy Schubert char *data, size_t data_len)
1353206b73d0SCy Schubert {
1354206b73d0SCy Schubert union wpa_event_data event;
1355206b73d0SCy Schubert struct ieee80211_send_action_cb *sa;
1356206b73d0SCy Schubert const struct ieee80211_hdr *hdr;
1357206b73d0SCy Schubert u16 fc;
1358206b73d0SCy Schubert
1359206b73d0SCy Schubert if (data_len < sizeof(*sa) + 24) {
1360206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1361206b73d0SCy Schubert "athr: Too short event message (data_len=%d sizeof(*sa)=%d)",
1362206b73d0SCy Schubert (int) data_len, (int) sizeof(*sa));
1363206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "athr: Short event message",
1364206b73d0SCy Schubert data, data_len);
1365206b73d0SCy Schubert return;
1366206b73d0SCy Schubert }
1367206b73d0SCy Schubert
1368206b73d0SCy Schubert sa = (struct ieee80211_send_action_cb *) data;
1369206b73d0SCy Schubert
1370206b73d0SCy Schubert hdr = (const struct ieee80211_hdr *) (sa + 1);
1371206b73d0SCy Schubert fc = le_to_host16(hdr->frame_control);
1372206b73d0SCy Schubert
1373206b73d0SCy Schubert os_memset(&event, 0, sizeof(event));
1374206b73d0SCy Schubert event.tx_status.type = WLAN_FC_GET_TYPE(fc);
1375206b73d0SCy Schubert event.tx_status.stype = WLAN_FC_GET_STYPE(fc);
1376206b73d0SCy Schubert event.tx_status.dst = sa->dst_addr;
1377206b73d0SCy Schubert event.tx_status.data = (const u8 *) hdr;
1378206b73d0SCy Schubert event.tx_status.data_len = data_len - sizeof(*sa);
1379206b73d0SCy Schubert event.tx_status.ack = sa->ack;
1380206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_TX_STATUS, &event);
1381206b73d0SCy Schubert }
1382206b73d0SCy Schubert
1383206b73d0SCy Schubert
1384206b73d0SCy Schubert /*
1385206b73d0SCy Schubert * Handle size of data problem. WEXT only allows data of 256 bytes for custom
1386206b73d0SCy Schubert * events, and p2p data can be much bigger. So the athr driver sends a small
1387206b73d0SCy Schubert * event telling me to collect the big data with an ioctl.
1388206b73d0SCy Schubert * On the first event, send all pending events to supplicant.
1389206b73d0SCy Schubert */
fetch_pending_big_events(struct atheros_driver_data * drv)1390206b73d0SCy Schubert static void fetch_pending_big_events(struct atheros_driver_data *drv)
1391206b73d0SCy Schubert {
1392206b73d0SCy Schubert union wpa_event_data event;
1393206b73d0SCy Schubert const struct ieee80211_mgmt *mgmt;
1394206b73d0SCy Schubert u8 tbuf[IW_PRIV_SIZE_MASK]; /* max size is 2047 bytes */
1395206b73d0SCy Schubert u16 fc, stype;
1396206b73d0SCy Schubert struct iwreq iwr;
1397206b73d0SCy Schubert size_t data_len;
1398206b73d0SCy Schubert u32 freq, frame_type;
1399206b73d0SCy Schubert
1400206b73d0SCy Schubert while (1) {
1401206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
1402206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1403206b73d0SCy Schubert
1404206b73d0SCy Schubert iwr.u.data.pointer = (void *) tbuf;
1405206b73d0SCy Schubert iwr.u.data.length = sizeof(tbuf);
1406206b73d0SCy Schubert iwr.u.data.flags = IEEE80211_IOC_P2P_FETCH_FRAME;
1407206b73d0SCy Schubert
1408206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr)
1409206b73d0SCy Schubert < 0) {
1410206b73d0SCy Schubert if (errno == ENOSPC) {
1411206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s:%d exit",
1412206b73d0SCy Schubert __func__, __LINE__);
1413206b73d0SCy Schubert return;
1414206b73d0SCy Schubert }
1415206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "athr: %s: P2P_BIG_PARAM["
1416206b73d0SCy Schubert "P2P_FETCH_FRAME] failed: %s",
1417206b73d0SCy Schubert __func__, strerror(errno));
1418206b73d0SCy Schubert return;
1419206b73d0SCy Schubert }
1420206b73d0SCy Schubert data_len = iwr.u.data.length;
1421206b73d0SCy Schubert wpa_hexdump(MSG_DEBUG, "athr: P2P_FETCH_FRAME data",
1422206b73d0SCy Schubert (u8 *) tbuf, data_len);
1423206b73d0SCy Schubert if (data_len < sizeof(freq) + sizeof(frame_type) + 24) {
1424206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "athr: frame too short");
1425206b73d0SCy Schubert continue;
1426206b73d0SCy Schubert }
1427206b73d0SCy Schubert os_memcpy(&freq, tbuf, sizeof(freq));
1428206b73d0SCy Schubert os_memcpy(&frame_type, &tbuf[sizeof(freq)],
1429206b73d0SCy Schubert sizeof(frame_type));
1430206b73d0SCy Schubert mgmt = (void *) &tbuf[sizeof(freq) + sizeof(frame_type)];
1431206b73d0SCy Schubert data_len -= sizeof(freq) + sizeof(frame_type);
1432206b73d0SCy Schubert
1433206b73d0SCy Schubert if (frame_type == IEEE80211_EV_RX_MGMT) {
1434206b73d0SCy Schubert fc = le_to_host16(mgmt->frame_control);
1435206b73d0SCy Schubert stype = WLAN_FC_GET_STYPE(fc);
1436206b73d0SCy Schubert
1437206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "athr: EV_RX_MGMT stype=%u "
1438206b73d0SCy Schubert "freq=%u len=%u", stype, freq, (int) data_len);
1439206b73d0SCy Schubert
1440206b73d0SCy Schubert if (stype == WLAN_FC_STYPE_ACTION) {
1441206b73d0SCy Schubert os_memset(&event, 0, sizeof(event));
1442206b73d0SCy Schubert event.rx_mgmt.frame = (const u8 *) mgmt;
1443206b73d0SCy Schubert event.rx_mgmt.frame_len = data_len;
1444206b73d0SCy Schubert wpa_supplicant_event(drv->hapd, EVENT_RX_MGMT,
1445206b73d0SCy Schubert &event);
1446206b73d0SCy Schubert continue;
1447206b73d0SCy Schubert }
1448206b73d0SCy Schubert } else if (frame_type == IEEE80211_EV_P2P_SEND_ACTION_CB) {
1449206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1450206b73d0SCy Schubert "%s: ACTION_CB frame_type=%u len=%zu",
1451206b73d0SCy Schubert __func__, frame_type, data_len);
1452206b73d0SCy Schubert send_action_cb_event(drv, (void *) mgmt, data_len);
1453206b73d0SCy Schubert } else {
1454206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "athr: %s unknown type %d",
1455206b73d0SCy Schubert __func__, frame_type);
1456206b73d0SCy Schubert continue;
1457206b73d0SCy Schubert }
1458206b73d0SCy Schubert }
1459206b73d0SCy Schubert }
1460206b73d0SCy Schubert
1461206b73d0SCy Schubert static void
atheros_wireless_event_atheros_custom(struct atheros_driver_data * drv,int opcode,char * buf,int len)1462206b73d0SCy Schubert atheros_wireless_event_atheros_custom(struct atheros_driver_data *drv,
1463206b73d0SCy Schubert int opcode, char *buf, int len)
1464206b73d0SCy Schubert {
1465206b73d0SCy Schubert switch (opcode) {
1466206b73d0SCy Schubert case IEEE80211_EV_P2P_SEND_ACTION_CB:
1467206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "WEXT: EV_P2P_SEND_ACTION_CB");
1468206b73d0SCy Schubert fetch_pending_big_events(drv);
1469206b73d0SCy Schubert break;
1470206b73d0SCy Schubert case IEEE80211_EV_RX_MGMT:
1471206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "WEXT: EV_RX_MGMT");
1472206b73d0SCy Schubert fetch_pending_big_events(drv);
1473206b73d0SCy Schubert break;
1474206b73d0SCy Schubert default:
1475206b73d0SCy Schubert break;
1476206b73d0SCy Schubert }
1477206b73d0SCy Schubert }
1478206b73d0SCy Schubert
1479206b73d0SCy Schubert static void
atheros_wireless_event_wireless(struct atheros_driver_data * drv,char * data,unsigned int len)1480206b73d0SCy Schubert atheros_wireless_event_wireless(struct atheros_driver_data *drv,
1481206b73d0SCy Schubert char *data, unsigned int len)
1482206b73d0SCy Schubert {
1483206b73d0SCy Schubert struct iw_event iwe_buf, *iwe = &iwe_buf;
1484206b73d0SCy Schubert char *pos, *end, *custom, *buf;
1485206b73d0SCy Schubert
1486206b73d0SCy Schubert pos = data;
1487206b73d0SCy Schubert end = data + len;
1488206b73d0SCy Schubert
1489206b73d0SCy Schubert while ((size_t) (end - pos) >= IW_EV_LCP_LEN) {
1490206b73d0SCy Schubert /* Event data may be unaligned, so make a local, aligned copy
1491206b73d0SCy Schubert * before processing. */
1492206b73d0SCy Schubert os_memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
1493206b73d0SCy Schubert wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
1494206b73d0SCy Schubert iwe->cmd, iwe->len);
1495206b73d0SCy Schubert if (iwe->len <= IW_EV_LCP_LEN || iwe->len > end - pos)
1496206b73d0SCy Schubert return;
1497206b73d0SCy Schubert
1498206b73d0SCy Schubert custom = pos + IW_EV_POINT_LEN;
1499206b73d0SCy Schubert if (drv->we_version > 18 &&
1500206b73d0SCy Schubert (iwe->cmd == IWEVMICHAELMICFAILURE ||
1501206b73d0SCy Schubert iwe->cmd == IWEVASSOCREQIE ||
1502206b73d0SCy Schubert iwe->cmd == IWEVCUSTOM)) {
1503206b73d0SCy Schubert /* WE-19 removed the pointer from struct iw_point */
1504206b73d0SCy Schubert char *dpos = (char *) &iwe_buf.u.data.length;
1505206b73d0SCy Schubert int dlen = dpos - (char *) &iwe_buf;
1506206b73d0SCy Schubert os_memcpy(dpos, pos + IW_EV_LCP_LEN,
1507206b73d0SCy Schubert sizeof(struct iw_event) - dlen);
1508206b73d0SCy Schubert } else {
1509206b73d0SCy Schubert os_memcpy(&iwe_buf, pos, sizeof(struct iw_event));
1510206b73d0SCy Schubert custom += IW_EV_POINT_OFF;
1511206b73d0SCy Schubert }
1512206b73d0SCy Schubert
1513206b73d0SCy Schubert switch (iwe->cmd) {
1514206b73d0SCy Schubert case IWEVEXPIRED:
1515206b73d0SCy Schubert drv_event_disassoc(drv->hapd,
1516206b73d0SCy Schubert (u8 *) iwe->u.addr.sa_data);
1517206b73d0SCy Schubert break;
1518206b73d0SCy Schubert case IWEVREGISTERED:
1519206b73d0SCy Schubert atheros_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
1520206b73d0SCy Schubert break;
1521206b73d0SCy Schubert case IWEVASSOCREQIE:
1522206b73d0SCy Schubert /* Driver hack.. Use IWEVASSOCREQIE to bypass
1523206b73d0SCy Schubert * IWEVCUSTOM size limitations. Need to handle this
1524206b73d0SCy Schubert * just like IWEVCUSTOM.
1525206b73d0SCy Schubert */
1526206b73d0SCy Schubert case IWEVCUSTOM:
1527206b73d0SCy Schubert if (iwe->u.data.length > end - custom)
1528206b73d0SCy Schubert return;
1529206b73d0SCy Schubert buf = os_malloc(iwe->u.data.length + 1);
1530206b73d0SCy Schubert if (buf == NULL)
1531206b73d0SCy Schubert return; /* XXX */
1532206b73d0SCy Schubert os_memcpy(buf, custom, iwe->u.data.length);
1533206b73d0SCy Schubert buf[iwe->u.data.length] = '\0';
1534206b73d0SCy Schubert
1535206b73d0SCy Schubert if (iwe->u.data.flags != 0) {
1536206b73d0SCy Schubert atheros_wireless_event_atheros_custom(
1537206b73d0SCy Schubert drv, (int) iwe->u.data.flags,
1538206b73d0SCy Schubert buf, len);
1539206b73d0SCy Schubert } else {
1540206b73d0SCy Schubert atheros_wireless_event_wireless_custom(
1541206b73d0SCy Schubert drv, buf, buf + iwe->u.data.length);
1542206b73d0SCy Schubert }
1543206b73d0SCy Schubert os_free(buf);
1544206b73d0SCy Schubert break;
1545206b73d0SCy Schubert }
1546206b73d0SCy Schubert
1547206b73d0SCy Schubert pos += iwe->len;
1548206b73d0SCy Schubert }
1549206b73d0SCy Schubert }
1550206b73d0SCy Schubert
1551206b73d0SCy Schubert
1552206b73d0SCy Schubert static void
atheros_wireless_event_rtm_newlink(void * ctx,struct ifinfomsg * ifi,u8 * buf,size_t len)1553206b73d0SCy Schubert atheros_wireless_event_rtm_newlink(void *ctx,
1554206b73d0SCy Schubert struct ifinfomsg *ifi, u8 *buf, size_t len)
1555206b73d0SCy Schubert {
1556206b73d0SCy Schubert struct atheros_driver_data *drv = ctx;
1557206b73d0SCy Schubert int attrlen, rta_len;
1558206b73d0SCy Schubert struct rtattr *attr;
1559206b73d0SCy Schubert
1560206b73d0SCy Schubert if (ifi->ifi_index != drv->ifindex)
1561206b73d0SCy Schubert return;
1562206b73d0SCy Schubert
1563206b73d0SCy Schubert attrlen = len;
1564206b73d0SCy Schubert attr = (struct rtattr *) buf;
1565206b73d0SCy Schubert
1566206b73d0SCy Schubert rta_len = RTA_ALIGN(sizeof(struct rtattr));
1567206b73d0SCy Schubert while (RTA_OK(attr, attrlen)) {
1568206b73d0SCy Schubert if (attr->rta_type == IFLA_WIRELESS) {
1569206b73d0SCy Schubert atheros_wireless_event_wireless(
1570206b73d0SCy Schubert drv, ((char *) attr) + rta_len,
1571206b73d0SCy Schubert attr->rta_len - rta_len);
1572206b73d0SCy Schubert }
1573206b73d0SCy Schubert attr = RTA_NEXT(attr, attrlen);
1574206b73d0SCy Schubert }
1575206b73d0SCy Schubert }
1576206b73d0SCy Schubert
1577206b73d0SCy Schubert
1578206b73d0SCy Schubert static int
atheros_get_we_version(struct atheros_driver_data * drv)1579206b73d0SCy Schubert atheros_get_we_version(struct atheros_driver_data *drv)
1580206b73d0SCy Schubert {
1581206b73d0SCy Schubert struct iw_range *range;
1582206b73d0SCy Schubert struct iwreq iwr;
1583206b73d0SCy Schubert int minlen;
1584206b73d0SCy Schubert size_t buflen;
1585206b73d0SCy Schubert
1586206b73d0SCy Schubert drv->we_version = 0;
1587206b73d0SCy Schubert
1588206b73d0SCy Schubert /*
1589206b73d0SCy Schubert * Use larger buffer than struct iw_range in order to allow the
1590206b73d0SCy Schubert * structure to grow in the future.
1591206b73d0SCy Schubert */
1592206b73d0SCy Schubert buflen = sizeof(struct iw_range) + 500;
1593206b73d0SCy Schubert range = os_zalloc(buflen);
1594206b73d0SCy Schubert if (range == NULL)
1595206b73d0SCy Schubert return -1;
1596206b73d0SCy Schubert
1597206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
1598206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1599206b73d0SCy Schubert iwr.u.data.pointer = (caddr_t) range;
1600206b73d0SCy Schubert iwr.u.data.length = buflen;
1601206b73d0SCy Schubert
1602206b73d0SCy Schubert minlen = ((char *) &range->enc_capa) - (char *) range +
1603206b73d0SCy Schubert sizeof(range->enc_capa);
1604206b73d0SCy Schubert
1605206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
1606206b73d0SCy Schubert wpa_printf(MSG_ERROR, "ioctl[SIOCGIWRANGE]: %s",
1607206b73d0SCy Schubert strerror(errno));
1608206b73d0SCy Schubert os_free(range);
1609206b73d0SCy Schubert return -1;
1610206b73d0SCy Schubert } else if (iwr.u.data.length >= minlen &&
1611206b73d0SCy Schubert range->we_version_compiled >= 18) {
1612206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
1613206b73d0SCy Schubert "WE(source)=%d enc_capa=0x%x",
1614206b73d0SCy Schubert range->we_version_compiled,
1615206b73d0SCy Schubert range->we_version_source,
1616206b73d0SCy Schubert range->enc_capa);
1617206b73d0SCy Schubert drv->we_version = range->we_version_compiled;
1618206b73d0SCy Schubert }
1619206b73d0SCy Schubert
1620206b73d0SCy Schubert os_free(range);
1621206b73d0SCy Schubert return 0;
1622206b73d0SCy Schubert }
1623206b73d0SCy Schubert
1624206b73d0SCy Schubert
1625206b73d0SCy Schubert static int
atheros_wireless_event_init(struct atheros_driver_data * drv)1626206b73d0SCy Schubert atheros_wireless_event_init(struct atheros_driver_data *drv)
1627206b73d0SCy Schubert {
1628206b73d0SCy Schubert struct netlink_config *cfg;
1629206b73d0SCy Schubert
1630206b73d0SCy Schubert atheros_get_we_version(drv);
1631206b73d0SCy Schubert
1632206b73d0SCy Schubert cfg = os_zalloc(sizeof(*cfg));
1633206b73d0SCy Schubert if (cfg == NULL)
1634206b73d0SCy Schubert return -1;
1635206b73d0SCy Schubert cfg->ctx = drv;
1636206b73d0SCy Schubert cfg->newlink_cb = atheros_wireless_event_rtm_newlink;
1637206b73d0SCy Schubert drv->netlink = netlink_init(cfg);
1638206b73d0SCy Schubert if (drv->netlink == NULL) {
1639206b73d0SCy Schubert os_free(cfg);
1640206b73d0SCy Schubert return -1;
1641206b73d0SCy Schubert }
1642206b73d0SCy Schubert
1643206b73d0SCy Schubert return 0;
1644206b73d0SCy Schubert }
1645206b73d0SCy Schubert
1646206b73d0SCy Schubert
1647206b73d0SCy Schubert 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)1648206b73d0SCy Schubert atheros_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
1649*a90b9d01SCy Schubert int encrypt, const u8 *own_addr, u32 flags, int link_id)
1650206b73d0SCy Schubert {
1651206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1652206b73d0SCy Schubert unsigned char buf[3000];
1653206b73d0SCy Schubert unsigned char *bp = buf;
1654206b73d0SCy Schubert struct l2_ethhdr *eth;
1655206b73d0SCy Schubert size_t len;
1656206b73d0SCy Schubert int status;
1657206b73d0SCy Schubert
1658206b73d0SCy Schubert /*
1659206b73d0SCy Schubert * Prepend the Ethernet header. If the caller left us
1660206b73d0SCy Schubert * space at the front we could just insert it but since
1661206b73d0SCy Schubert * we don't know we copy to a local buffer. Given the frequency
1662206b73d0SCy Schubert * and size of frames this probably doesn't matter.
1663206b73d0SCy Schubert */
1664206b73d0SCy Schubert len = data_len + sizeof(struct l2_ethhdr);
1665206b73d0SCy Schubert if (len > sizeof(buf)) {
1666206b73d0SCy Schubert bp = os_malloc(len);
1667206b73d0SCy Schubert if (bp == NULL) {
1668206b73d0SCy Schubert wpa_printf(MSG_INFO,
1669206b73d0SCy Schubert "EAPOL frame discarded, cannot malloc temp buffer of size %lu!",
1670206b73d0SCy Schubert (unsigned long) len);
1671206b73d0SCy Schubert return -1;
1672206b73d0SCy Schubert }
1673206b73d0SCy Schubert }
1674206b73d0SCy Schubert eth = (struct l2_ethhdr *) bp;
1675206b73d0SCy Schubert os_memcpy(eth->h_dest, addr, ETH_ALEN);
1676206b73d0SCy Schubert os_memcpy(eth->h_source, own_addr, ETH_ALEN);
1677206b73d0SCy Schubert eth->h_proto = host_to_be16(ETH_P_EAPOL);
1678206b73d0SCy Schubert os_memcpy(eth + 1, data, data_len);
1679206b73d0SCy Schubert
1680206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
1681206b73d0SCy Schubert
1682206b73d0SCy Schubert status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
1683206b73d0SCy Schubert
1684206b73d0SCy Schubert if (bp != buf)
1685206b73d0SCy Schubert os_free(bp);
1686206b73d0SCy Schubert return status;
1687206b73d0SCy Schubert }
1688206b73d0SCy Schubert
1689206b73d0SCy Schubert static void
handle_read(void * ctx,const u8 * src_addr,const u8 * buf,size_t len)1690206b73d0SCy Schubert handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
1691206b73d0SCy Schubert {
1692206b73d0SCy Schubert struct atheros_driver_data *drv = ctx;
1693206b73d0SCy Schubert drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
1694206b73d0SCy Schubert len - sizeof(struct l2_ethhdr));
1695206b73d0SCy Schubert }
1696206b73d0SCy Schubert
1697206b73d0SCy Schubert
atheros_read_fils_cap(struct atheros_driver_data * drv)1698206b73d0SCy Schubert static void atheros_read_fils_cap(struct atheros_driver_data *drv)
1699206b73d0SCy Schubert {
1700206b73d0SCy Schubert int fils = 0;
1701206b73d0SCy Schubert
1702206b73d0SCy Schubert #ifdef CONFIG_FILS
1703206b73d0SCy Schubert /* TODO: Would be better to have #ifdef on the IEEE80211_PARAM_* value
1704206b73d0SCy Schubert * to automatically check this against the driver header files. */
1705206b73d0SCy Schubert if (get80211param(drv, IEEE80211_PARAM_ENABLE_FILS, &fils) < 0) {
1706206b73d0SCy Schubert wpa_printf(MSG_DEBUG,
1707206b73d0SCy Schubert "%s: Failed to get FILS capability from driver",
1708206b73d0SCy Schubert __func__);
1709206b73d0SCy Schubert /* Assume driver does not support FILS */
1710206b73d0SCy Schubert fils = 0;
1711206b73d0SCy Schubert }
1712206b73d0SCy Schubert #endif /* CONFIG_FILS */
1713206b73d0SCy Schubert drv->fils_en = fils;
1714206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: fils_en=%d", drv->fils_en);
1715206b73d0SCy Schubert }
1716206b73d0SCy Schubert
1717206b73d0SCy Schubert
1718206b73d0SCy Schubert static void *
atheros_init(struct hostapd_data * hapd,struct wpa_init_params * params)1719206b73d0SCy Schubert atheros_init(struct hostapd_data *hapd, struct wpa_init_params *params)
1720206b73d0SCy Schubert {
1721206b73d0SCy Schubert struct atheros_driver_data *drv;
1722206b73d0SCy Schubert struct ifreq ifr;
1723206b73d0SCy Schubert struct iwreq iwr;
1724206b73d0SCy Schubert char brname[IFNAMSIZ];
1725206b73d0SCy Schubert
1726206b73d0SCy Schubert drv = os_zalloc(sizeof(struct atheros_driver_data));
1727206b73d0SCy Schubert if (drv == NULL) {
1728206b73d0SCy Schubert wpa_printf(MSG_INFO,
1729206b73d0SCy Schubert "Could not allocate memory for atheros driver data");
1730206b73d0SCy Schubert return NULL;
1731206b73d0SCy Schubert }
1732206b73d0SCy Schubert
1733206b73d0SCy Schubert drv->hapd = hapd;
1734206b73d0SCy Schubert drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
1735206b73d0SCy Schubert if (drv->ioctl_sock < 0) {
1736206b73d0SCy Schubert wpa_printf(MSG_ERROR, "socket[PF_INET,SOCK_DGRAM]: %s",
1737206b73d0SCy Schubert strerror(errno));
1738206b73d0SCy Schubert goto bad;
1739206b73d0SCy Schubert }
1740206b73d0SCy Schubert os_memcpy(drv->iface, params->ifname, sizeof(drv->iface));
1741206b73d0SCy Schubert
1742206b73d0SCy Schubert os_memset(&ifr, 0, sizeof(ifr));
1743206b73d0SCy Schubert os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
1744206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
1745206b73d0SCy Schubert wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
1746206b73d0SCy Schubert strerror(errno));
1747206b73d0SCy Schubert goto bad;
1748206b73d0SCy Schubert }
1749206b73d0SCy Schubert drv->ifindex = ifr.ifr_ifindex;
1750206b73d0SCy Schubert
1751206b73d0SCy Schubert drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
1752206b73d0SCy Schubert handle_read, drv, 1);
1753206b73d0SCy Schubert if (drv->sock_xmit == NULL)
1754206b73d0SCy Schubert goto bad;
1755206b73d0SCy Schubert if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
1756206b73d0SCy Schubert goto bad;
1757206b73d0SCy Schubert os_memcpy(drv->own_addr, params->own_addr, ETH_ALEN);
1758206b73d0SCy Schubert if (params->bridge[0]) {
1759206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
1760206b73d0SCy Schubert params->bridge[0]);
1761206b73d0SCy Schubert drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
1762206b73d0SCy Schubert ETH_P_EAPOL, handle_read, drv,
1763206b73d0SCy Schubert 1);
1764206b73d0SCy Schubert if (drv->sock_recv == NULL)
1765206b73d0SCy Schubert goto bad;
1766206b73d0SCy Schubert } else if (linux_br_get(brname, drv->iface) == 0) {
1767206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
1768206b73d0SCy Schubert "EAPOL receive", brname);
1769206b73d0SCy Schubert drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
1770206b73d0SCy Schubert handle_read, drv, 1);
1771206b73d0SCy Schubert if (drv->sock_recv == NULL)
1772206b73d0SCy Schubert goto bad;
1773206b73d0SCy Schubert } else
1774206b73d0SCy Schubert drv->sock_recv = drv->sock_xmit;
1775206b73d0SCy Schubert
1776206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
1777206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1778206b73d0SCy Schubert
1779206b73d0SCy Schubert iwr.u.mode = IW_MODE_MASTER;
1780206b73d0SCy Schubert
1781206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
1782206b73d0SCy Schubert wpa_printf(MSG_ERROR,
1783206b73d0SCy Schubert "Could not set interface to master mode! ioctl[SIOCSIWMODE]: %s",
1784206b73d0SCy Schubert strerror(errno));
1785206b73d0SCy Schubert goto bad;
1786206b73d0SCy Schubert }
1787206b73d0SCy Schubert
1788206b73d0SCy Schubert /* mark down during setup */
1789206b73d0SCy Schubert linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1790206b73d0SCy Schubert atheros_set_privacy(drv, 0); /* default to no privacy */
1791206b73d0SCy Schubert
1792206b73d0SCy Schubert if (atheros_receive_pkt(drv))
1793206b73d0SCy Schubert goto bad;
1794206b73d0SCy Schubert
1795206b73d0SCy Schubert if (atheros_wireless_event_init(drv))
1796206b73d0SCy Schubert goto bad;
1797206b73d0SCy Schubert
1798206b73d0SCy Schubert /* Read FILS capability from the driver */
1799206b73d0SCy Schubert atheros_read_fils_cap(drv);
1800206b73d0SCy Schubert
1801206b73d0SCy Schubert return drv;
1802206b73d0SCy Schubert bad:
1803206b73d0SCy Schubert atheros_reset_appfilter(drv);
1804206b73d0SCy Schubert if (drv->sock_raw)
1805206b73d0SCy Schubert l2_packet_deinit(drv->sock_raw);
1806206b73d0SCy Schubert if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1807206b73d0SCy Schubert l2_packet_deinit(drv->sock_recv);
1808206b73d0SCy Schubert if (drv->sock_xmit != NULL)
1809206b73d0SCy Schubert l2_packet_deinit(drv->sock_xmit);
1810206b73d0SCy Schubert if (drv->ioctl_sock >= 0)
1811206b73d0SCy Schubert close(drv->ioctl_sock);
1812206b73d0SCy Schubert os_free(drv);
1813206b73d0SCy Schubert return NULL;
1814206b73d0SCy Schubert }
1815206b73d0SCy Schubert
1816206b73d0SCy Schubert
1817206b73d0SCy Schubert static void
atheros_deinit(void * priv)1818206b73d0SCy Schubert atheros_deinit(void *priv)
1819206b73d0SCy Schubert {
1820206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1821206b73d0SCy Schubert
1822206b73d0SCy Schubert atheros_reset_appfilter(drv);
1823206b73d0SCy Schubert
1824206b73d0SCy Schubert if (drv->wpa_ie || drv->wps_beacon_ie || drv->wps_probe_resp_ie) {
1825206b73d0SCy Schubert atheros_set_opt_ie(priv, NULL, 0);
1826206b73d0SCy Schubert wpabuf_free(drv->wpa_ie);
1827206b73d0SCy Schubert wpabuf_free(drv->wps_beacon_ie);
1828206b73d0SCy Schubert wpabuf_free(drv->wps_probe_resp_ie);
1829206b73d0SCy Schubert }
1830206b73d0SCy Schubert netlink_deinit(drv->netlink);
1831206b73d0SCy Schubert (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
1832206b73d0SCy Schubert if (drv->ioctl_sock >= 0)
1833206b73d0SCy Schubert close(drv->ioctl_sock);
1834206b73d0SCy Schubert if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
1835206b73d0SCy Schubert l2_packet_deinit(drv->sock_recv);
1836206b73d0SCy Schubert if (drv->sock_xmit != NULL)
1837206b73d0SCy Schubert l2_packet_deinit(drv->sock_xmit);
1838206b73d0SCy Schubert if (drv->sock_raw)
1839206b73d0SCy Schubert l2_packet_deinit(drv->sock_raw);
1840206b73d0SCy Schubert os_free(drv);
1841206b73d0SCy Schubert }
1842206b73d0SCy Schubert
1843206b73d0SCy Schubert static int
atheros_set_ssid(void * priv,const u8 * buf,int len)1844206b73d0SCy Schubert atheros_set_ssid(void *priv, const u8 *buf, int len)
1845206b73d0SCy Schubert {
1846206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1847206b73d0SCy Schubert struct iwreq iwr;
1848206b73d0SCy Schubert
1849206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
1850206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1851206b73d0SCy Schubert iwr.u.essid.flags = 1; /* SSID active */
1852206b73d0SCy Schubert iwr.u.essid.pointer = (caddr_t) buf;
1853206b73d0SCy Schubert iwr.u.essid.length = len;
1854206b73d0SCy Schubert
1855206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
1856206b73d0SCy Schubert wpa_printf(MSG_ERROR, "ioctl[SIOCSIWESSID,len=%d]: %s",
1857206b73d0SCy Schubert len, strerror(errno));
1858206b73d0SCy Schubert return -1;
1859206b73d0SCy Schubert }
1860206b73d0SCy Schubert return 0;
1861206b73d0SCy Schubert }
1862206b73d0SCy Schubert
1863206b73d0SCy Schubert static int
atheros_get_ssid(void * priv,u8 * buf,int len)1864206b73d0SCy Schubert atheros_get_ssid(void *priv, u8 *buf, int len)
1865206b73d0SCy Schubert {
1866206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1867206b73d0SCy Schubert struct iwreq iwr;
1868206b73d0SCy Schubert int ret = 0;
1869206b73d0SCy Schubert
1870206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
1871206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
1872206b73d0SCy Schubert iwr.u.essid.pointer = (caddr_t) buf;
1873206b73d0SCy Schubert iwr.u.essid.length = (len > IW_ESSID_MAX_SIZE) ?
1874206b73d0SCy Schubert IW_ESSID_MAX_SIZE : len;
1875206b73d0SCy Schubert
1876206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
1877206b73d0SCy Schubert wpa_printf(MSG_ERROR, "ioctl[SIOCGIWESSID]: %s",
1878206b73d0SCy Schubert strerror(errno));
1879206b73d0SCy Schubert ret = -1;
1880206b73d0SCy Schubert } else
1881206b73d0SCy Schubert ret = iwr.u.essid.length;
1882206b73d0SCy Schubert
1883206b73d0SCy Schubert return ret;
1884206b73d0SCy Schubert }
1885206b73d0SCy Schubert
1886206b73d0SCy Schubert static int
atheros_set_countermeasures(void * priv,int enabled)1887206b73d0SCy Schubert atheros_set_countermeasures(void *priv, int enabled)
1888206b73d0SCy Schubert {
1889206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1890206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
1891206b73d0SCy Schubert return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
1892206b73d0SCy Schubert }
1893206b73d0SCy Schubert
1894206b73d0SCy Schubert static int
atheros_commit(void * priv)1895206b73d0SCy Schubert atheros_commit(void *priv)
1896206b73d0SCy Schubert {
1897206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1898206b73d0SCy Schubert return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
1899206b73d0SCy Schubert }
1900206b73d0SCy Schubert
atheros_set_authmode(void * priv,int auth_algs)1901206b73d0SCy Schubert static int atheros_set_authmode(void *priv, int auth_algs)
1902206b73d0SCy Schubert {
1903206b73d0SCy Schubert int authmode;
1904206b73d0SCy Schubert
1905206b73d0SCy Schubert if ((auth_algs & WPA_AUTH_ALG_OPEN) &&
1906206b73d0SCy Schubert (auth_algs & WPA_AUTH_ALG_SHARED))
1907206b73d0SCy Schubert authmode = IEEE80211_AUTH_AUTO;
1908206b73d0SCy Schubert else if (auth_algs & WPA_AUTH_ALG_OPEN)
1909206b73d0SCy Schubert authmode = IEEE80211_AUTH_OPEN;
1910206b73d0SCy Schubert else if (auth_algs & WPA_AUTH_ALG_SHARED)
1911206b73d0SCy Schubert authmode = IEEE80211_AUTH_SHARED;
1912206b73d0SCy Schubert else
1913206b73d0SCy Schubert return -1;
1914206b73d0SCy Schubert
1915206b73d0SCy Schubert return set80211param(priv, IEEE80211_PARAM_AUTHMODE, authmode);
1916206b73d0SCy Schubert }
1917206b73d0SCy Schubert
atheros_set_ap(void * priv,struct wpa_driver_ap_params * params)1918206b73d0SCy Schubert static int atheros_set_ap(void *priv, struct wpa_driver_ap_params *params)
1919206b73d0SCy Schubert {
1920206b73d0SCy Schubert /*
1921206b73d0SCy Schubert * TODO: Use this to replace set_authmode, set_privacy, set_ieee8021x,
1922206b73d0SCy Schubert * set_generic_elem, and hapd_set_ssid.
1923206b73d0SCy Schubert */
1924206b73d0SCy Schubert
1925206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: set_ap - pairwise_ciphers=0x%x "
1926206b73d0SCy Schubert "group_cipher=0x%x key_mgmt_suites=0x%x auth_algs=0x%x "
1927206b73d0SCy Schubert "wpa_version=0x%x privacy=%d interworking=%d",
1928206b73d0SCy Schubert params->pairwise_ciphers, params->group_cipher,
1929206b73d0SCy Schubert params->key_mgmt_suites, params->auth_algs,
1930206b73d0SCy Schubert params->wpa_version, params->privacy, params->interworking);
1931206b73d0SCy Schubert wpa_hexdump_ascii(MSG_DEBUG, "atheros: SSID",
1932206b73d0SCy Schubert params->ssid, params->ssid_len);
1933206b73d0SCy Schubert if (params->hessid)
1934206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: HESSID " MACSTR,
1935206b73d0SCy Schubert MAC2STR(params->hessid));
1936206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: beacon_ies",
1937206b73d0SCy Schubert params->beacon_ies);
1938206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: proberesp_ies",
1939206b73d0SCy Schubert params->proberesp_ies);
1940206b73d0SCy Schubert wpa_hexdump_buf(MSG_DEBUG, "atheros: assocresp_ies",
1941206b73d0SCy Schubert params->assocresp_ies);
1942206b73d0SCy Schubert
1943206b73d0SCy Schubert #if defined(CONFIG_HS20) && (defined(IEEE80211_PARAM_OSEN) || defined(CONFIG_ATHEROS_OSEN))
1944206b73d0SCy Schubert if (params->osen) {
1945206b73d0SCy Schubert struct wpa_bss_params bss_params;
1946206b73d0SCy Schubert
1947206b73d0SCy Schubert os_memset(&bss_params, 0, sizeof(struct wpa_bss_params));
1948206b73d0SCy Schubert bss_params.enabled = 1;
1949206b73d0SCy Schubert bss_params.wpa = 2;
1950206b73d0SCy Schubert bss_params.wpa_pairwise = WPA_CIPHER_CCMP;
1951206b73d0SCy Schubert bss_params.wpa_group = WPA_CIPHER_CCMP;
1952206b73d0SCy Schubert bss_params.ieee802_1x = 1;
1953206b73d0SCy Schubert
1954206b73d0SCy Schubert if (atheros_set_privacy(priv, 1) ||
1955206b73d0SCy Schubert set80211param(priv, IEEE80211_PARAM_OSEN, 1))
1956206b73d0SCy Schubert return -1;
1957206b73d0SCy Schubert
1958206b73d0SCy Schubert return atheros_set_ieee8021x(priv, &bss_params);
1959206b73d0SCy Schubert }
1960206b73d0SCy Schubert #endif /* CONFIG_HS20 && IEEE80211_PARAM_OSEN */
1961206b73d0SCy Schubert
1962206b73d0SCy Schubert return 0;
1963206b73d0SCy Schubert }
1964206b73d0SCy Schubert
1965206b73d0SCy Schubert
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)1966206b73d0SCy Schubert static int atheros_send_mgmt(void *priv, const u8 *frm, size_t data_len,
1967206b73d0SCy Schubert int noack, unsigned int freq,
1968c1d255d3SCy Schubert const u16 *csa_offs, size_t csa_offs_len,
1969*a90b9d01SCy Schubert int no_encrypt, unsigned int wait, int link_id)
1970206b73d0SCy Schubert {
1971206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1972206b73d0SCy Schubert u8 buf[1510];
1973206b73d0SCy Schubert const struct ieee80211_mgmt *mgmt;
1974206b73d0SCy Schubert struct ieee80211req_mgmtbuf *mgmt_frm;
1975206b73d0SCy Schubert
1976206b73d0SCy Schubert mgmt = (const struct ieee80211_mgmt *) frm;
1977206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s frmlen = %lu " MACSTR, __func__,
1978206b73d0SCy Schubert (unsigned long) data_len, MAC2STR(mgmt->da));
1979206b73d0SCy Schubert mgmt_frm = (struct ieee80211req_mgmtbuf *) buf;
1980206b73d0SCy Schubert os_memcpy(mgmt_frm->macaddr, (u8 *)mgmt->da, IEEE80211_ADDR_LEN);
1981206b73d0SCy Schubert mgmt_frm->buflen = data_len;
1982206b73d0SCy Schubert if (&mgmt_frm->buf[0] + data_len > buf + sizeof(buf)) {
1983206b73d0SCy Schubert wpa_printf(MSG_INFO, "atheros: Too long frame for "
1984206b73d0SCy Schubert "atheros_send_mgmt (%u)", (unsigned int) data_len);
1985206b73d0SCy Schubert return -1;
1986206b73d0SCy Schubert }
1987206b73d0SCy Schubert os_memcpy(&mgmt_frm->buf[0], frm, data_len);
1988206b73d0SCy Schubert return set80211priv(drv, IEEE80211_IOCTL_SEND_MGMT, mgmt_frm,
1989206b73d0SCy Schubert sizeof(struct ieee80211req_mgmtbuf) + data_len);
1990206b73d0SCy Schubert }
1991206b73d0SCy Schubert
1992206b73d0SCy Schubert
1993206b73d0SCy Schubert #ifdef CONFIG_IEEE80211R
1994206b73d0SCy Schubert
atheros_add_tspec(void * priv,const u8 * addr,u8 * tspec_ie,size_t tspec_ielen)1995206b73d0SCy Schubert static int atheros_add_tspec(void *priv, const u8 *addr, u8 *tspec_ie,
1996206b73d0SCy Schubert size_t tspec_ielen)
1997206b73d0SCy Schubert {
1998206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
1999206b73d0SCy Schubert int retv;
2000206b73d0SCy Schubert struct ieee80211req_res req;
2001206b73d0SCy Schubert struct ieee80211req_res_addts *addts = &req.u.addts;
2002206b73d0SCy Schubert
2003206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s", __func__);
2004206b73d0SCy Schubert req.type = IEEE80211_RESREQ_ADDTS;
2005206b73d0SCy Schubert os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
2006206b73d0SCy Schubert os_memcpy(addts->tspecie, tspec_ie, tspec_ielen);
2007206b73d0SCy Schubert retv = set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
2008206b73d0SCy Schubert sizeof(struct ieee80211req_res));
2009206b73d0SCy Schubert if (retv < 0) {
2010206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s IEEE80211_IOCTL_RES_REQ FAILED "
2011206b73d0SCy Schubert "retv = %d", __func__, retv);
2012206b73d0SCy Schubert return -1;
2013206b73d0SCy Schubert }
2014206b73d0SCy Schubert os_memcpy(tspec_ie, addts->tspecie, tspec_ielen);
2015206b73d0SCy Schubert return addts->status;
2016206b73d0SCy Schubert }
2017206b73d0SCy Schubert
2018206b73d0SCy Schubert
atheros_add_sta_node(void * priv,const u8 * addr,u16 auth_alg)2019206b73d0SCy Schubert static int atheros_add_sta_node(void *priv, const u8 *addr, u16 auth_alg)
2020206b73d0SCy Schubert {
2021206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
2022206b73d0SCy Schubert struct ieee80211req_res req;
2023206b73d0SCy Schubert struct ieee80211req_res_addnode *addnode = &req.u.addnode;
2024206b73d0SCy Schubert
2025206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s", __func__);
2026206b73d0SCy Schubert req.type = IEEE80211_RESREQ_ADDNODE;
2027206b73d0SCy Schubert os_memcpy(&req.macaddr[0], addr, IEEE80211_ADDR_LEN);
2028206b73d0SCy Schubert addnode->auth_alg = auth_alg;
2029206b73d0SCy Schubert return set80211priv(drv, IEEE80211_IOCTL_RES_REQ, &req,
2030206b73d0SCy Schubert sizeof(struct ieee80211req_res));
2031206b73d0SCy Schubert }
2032206b73d0SCy Schubert
2033206b73d0SCy Schubert #endif /* CONFIG_IEEE80211R */
2034206b73d0SCy Schubert
2035206b73d0SCy Schubert
2036206b73d0SCy Schubert /* Use only to set a big param, get will not work. */
2037206b73d0SCy Schubert static int
set80211big(struct atheros_driver_data * drv,int op,const void * data,int len)2038206b73d0SCy Schubert set80211big(struct atheros_driver_data *drv, int op, const void *data, int len)
2039206b73d0SCy Schubert {
2040206b73d0SCy Schubert struct iwreq iwr;
2041206b73d0SCy Schubert
2042206b73d0SCy Schubert os_memset(&iwr, 0, sizeof(iwr));
2043206b73d0SCy Schubert os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
2044206b73d0SCy Schubert
2045206b73d0SCy Schubert iwr.u.data.pointer = (void *) data;
2046206b73d0SCy Schubert iwr.u.data.length = len;
2047206b73d0SCy Schubert iwr.u.data.flags = op;
2048206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: op=0x%x=%d (%s) len=0x%x",
2049206b73d0SCy Schubert __func__, op, op, athr_get_param_name(op), len);
2050206b73d0SCy Schubert
2051206b73d0SCy Schubert if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_P2P_BIG_PARAM, &iwr) < 0) {
2052206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: op=0x%x (%s) subop=0x%x=%d "
2053206b73d0SCy Schubert "value=0x%x,0x%x failed: %d (%s)",
2054206b73d0SCy Schubert __func__, op, athr_get_ioctl_name(op), iwr.u.mode,
2055206b73d0SCy Schubert iwr.u.mode, iwr.u.data.length,
2056206b73d0SCy Schubert iwr.u.data.flags, errno, strerror(errno));
2057206b73d0SCy Schubert return -1;
2058206b73d0SCy Schubert }
2059206b73d0SCy Schubert return 0;
2060206b73d0SCy Schubert }
2061206b73d0SCy Schubert
2062206b73d0SCy Schubert
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)2063206b73d0SCy Schubert static int atheros_send_action(void *priv, unsigned int freq,
2064206b73d0SCy Schubert unsigned int wait,
2065206b73d0SCy Schubert const u8 *dst, const u8 *src,
2066206b73d0SCy Schubert const u8 *bssid,
2067206b73d0SCy Schubert const u8 *data, size_t data_len, int no_cck)
2068206b73d0SCy Schubert {
2069206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
2070206b73d0SCy Schubert struct ieee80211_p2p_send_action *act;
2071206b73d0SCy Schubert int res;
2072206b73d0SCy Schubert
2073206b73d0SCy Schubert act = os_zalloc(sizeof(*act) + data_len);
2074206b73d0SCy Schubert if (act == NULL)
2075206b73d0SCy Schubert return -1;
2076206b73d0SCy Schubert act->freq = freq;
2077206b73d0SCy Schubert os_memcpy(act->dst_addr, dst, ETH_ALEN);
2078206b73d0SCy Schubert os_memcpy(act->src_addr, src, ETH_ALEN);
2079206b73d0SCy Schubert os_memcpy(act->bssid, bssid, ETH_ALEN);
2080206b73d0SCy Schubert os_memcpy(act + 1, data, data_len);
2081206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: freq=%d, wait=%u, dst=" MACSTR ", src="
2082206b73d0SCy Schubert MACSTR ", bssid=" MACSTR,
2083206b73d0SCy Schubert __func__, act->freq, wait, MAC2STR(act->dst_addr),
2084206b73d0SCy Schubert MAC2STR(act->src_addr), MAC2STR(act->bssid));
2085206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "athr: act", (u8 *) act, sizeof(*act));
2086206b73d0SCy Schubert wpa_hexdump(MSG_MSGDUMP, "athr: data", data, data_len);
2087206b73d0SCy Schubert
2088206b73d0SCy Schubert res = set80211big(drv, IEEE80211_IOC_P2P_SEND_ACTION,
2089206b73d0SCy Schubert act, sizeof(*act) + data_len);
2090206b73d0SCy Schubert os_free(act);
2091206b73d0SCy Schubert return res;
2092206b73d0SCy Schubert }
2093206b73d0SCy Schubert
2094206b73d0SCy Schubert
2095206b73d0SCy Schubert #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)2096206b73d0SCy Schubert static int athr_wnm_tfs(struct atheros_driver_data *drv, const u8* peer,
2097206b73d0SCy Schubert u8 *ie, u16 *len, enum wnm_oper oper)
2098206b73d0SCy Schubert {
2099206b73d0SCy Schubert #define IEEE80211_APPIE_MAX 1024 /* max appie buffer size */
2100206b73d0SCy Schubert u8 buf[IEEE80211_APPIE_MAX];
2101206b73d0SCy Schubert struct ieee80211req_getset_appiebuf *tfs_ie;
2102206b73d0SCy Schubert u16 val;
2103206b73d0SCy Schubert
2104206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: ifname=%s, WNM TFS IE oper=%d " MACSTR,
2105206b73d0SCy Schubert drv->iface, oper, MAC2STR(peer));
2106206b73d0SCy Schubert
2107206b73d0SCy Schubert switch (oper) {
2108206b73d0SCy Schubert case WNM_SLEEP_TFS_REQ_IE_SET:
2109206b73d0SCy Schubert if (*len > IEEE80211_APPIE_MAX -
2110206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf)) {
2111206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "TFS Req IE(s) too large");
2112206b73d0SCy Schubert return -1;
2113206b73d0SCy Schubert }
2114206b73d0SCy Schubert tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2115206b73d0SCy Schubert tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2116206b73d0SCy Schubert tfs_ie->app_buflen = ETH_ALEN + 2 + 2 + *len;
2117206b73d0SCy Schubert
2118206b73d0SCy Schubert /* Command header for driver */
2119206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2120206b73d0SCy Schubert val = oper;
2121206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2122206b73d0SCy Schubert val = *len;
2123206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2124206b73d0SCy Schubert
2125206b73d0SCy Schubert /* copy the ie */
2126206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2 + 2, ie, *len);
2127206b73d0SCy Schubert
2128206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2129206b73d0SCy Schubert IEEE80211_APPIE_MAX)) {
2130206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2131206b73d0SCy Schubert "%s", __func__, strerror(errno));
2132206b73d0SCy Schubert return -1;
2133206b73d0SCy Schubert }
2134206b73d0SCy Schubert break;
2135206b73d0SCy Schubert case WNM_SLEEP_TFS_RESP_IE_ADD:
2136206b73d0SCy Schubert tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2137206b73d0SCy Schubert tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2138206b73d0SCy Schubert tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2139206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf);
2140206b73d0SCy Schubert /* Command header for driver */
2141206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2142206b73d0SCy Schubert val = oper;
2143206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2144206b73d0SCy Schubert val = 0;
2145206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2146206b73d0SCy Schubert
2147206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_GET_APPIEBUF, tfs_ie,
2148206b73d0SCy Schubert IEEE80211_APPIE_MAX)) {
2149206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to get WNM TFS IE: "
2150206b73d0SCy Schubert "%s", __func__, strerror(errno));
2151206b73d0SCy Schubert return -1;
2152206b73d0SCy Schubert }
2153206b73d0SCy Schubert
2154206b73d0SCy Schubert *len = tfs_ie->app_buflen;
2155206b73d0SCy Schubert os_memcpy(ie, &(tfs_ie->app_buf[0]), *len);
2156206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: %c len=%d", tfs_ie->app_buf[0],
2157206b73d0SCy Schubert *len);
2158206b73d0SCy Schubert break;
2159206b73d0SCy Schubert case WNM_SLEEP_TFS_RESP_IE_NONE:
2160206b73d0SCy Schubert *len = 0;
2161206b73d0SCy Schubert break;
2162206b73d0SCy Schubert case WNM_SLEEP_TFS_IE_DEL:
2163206b73d0SCy Schubert tfs_ie = (struct ieee80211req_getset_appiebuf *) buf;
2164206b73d0SCy Schubert tfs_ie->app_frmtype = IEEE80211_APPIE_FRAME_WNM;
2165206b73d0SCy Schubert tfs_ie->app_buflen = IEEE80211_APPIE_MAX -
2166206b73d0SCy Schubert sizeof(struct ieee80211req_getset_appiebuf);
2167206b73d0SCy Schubert /* Command header for driver */
2168206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]), peer, ETH_ALEN);
2169206b73d0SCy Schubert val = oper;
2170206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN, &val, 2);
2171206b73d0SCy Schubert val = 0;
2172206b73d0SCy Schubert os_memcpy(&(tfs_ie->app_buf[0]) + ETH_ALEN + 2, &val, 2);
2173206b73d0SCy Schubert
2174206b73d0SCy Schubert if (set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, tfs_ie,
2175206b73d0SCy Schubert IEEE80211_APPIE_MAX)) {
2176206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "%s: Failed to set WNM TFS IE: "
2177206b73d0SCy Schubert "%s", __func__, strerror(errno));
2178206b73d0SCy Schubert return -1;
2179206b73d0SCy Schubert }
2180206b73d0SCy Schubert break;
2181206b73d0SCy Schubert default:
2182206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "Unsupported TFS oper %d", oper);
2183206b73d0SCy Schubert break;
2184206b73d0SCy Schubert }
2185206b73d0SCy Schubert
2186206b73d0SCy Schubert return 0;
2187206b73d0SCy Schubert }
2188206b73d0SCy Schubert
2189206b73d0SCy Schubert
atheros_wnm_sleep(struct atheros_driver_data * drv,const u8 * peer,enum wnm_oper oper)2190206b73d0SCy Schubert static int atheros_wnm_sleep(struct atheros_driver_data *drv,
2191206b73d0SCy Schubert const u8 *peer, enum wnm_oper oper)
2192206b73d0SCy Schubert {
2193206b73d0SCy Schubert u8 *data, *pos;
2194206b73d0SCy Schubert size_t dlen;
2195206b73d0SCy Schubert int ret;
2196206b73d0SCy Schubert u16 val;
2197206b73d0SCy Schubert
2198206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: WNM-Sleep Oper %d, " MACSTR,
2199206b73d0SCy Schubert oper, MAC2STR(peer));
2200206b73d0SCy Schubert
2201206b73d0SCy Schubert dlen = ETH_ALEN + 2 + 2;
2202206b73d0SCy Schubert data = os_malloc(dlen);
2203206b73d0SCy Schubert if (data == NULL)
2204206b73d0SCy Schubert return -1;
2205206b73d0SCy Schubert
2206206b73d0SCy Schubert /* Command header for driver */
2207206b73d0SCy Schubert pos = data;
2208206b73d0SCy Schubert os_memcpy(pos, peer, ETH_ALEN);
2209206b73d0SCy Schubert pos += ETH_ALEN;
2210206b73d0SCy Schubert
2211206b73d0SCy Schubert val = oper;
2212206b73d0SCy Schubert os_memcpy(pos, &val, 2);
2213206b73d0SCy Schubert pos += 2;
2214206b73d0SCy Schubert
2215206b73d0SCy Schubert val = 0;
2216206b73d0SCy Schubert os_memcpy(pos, &val, 2);
2217206b73d0SCy Schubert
2218206b73d0SCy Schubert ret = atheros_set_wps_ie(drv, data, dlen, IEEE80211_APPIE_FRAME_WNM);
2219206b73d0SCy Schubert
2220206b73d0SCy Schubert os_free(data);
2221206b73d0SCy Schubert
2222206b73d0SCy Schubert return ret;
2223206b73d0SCy Schubert }
2224206b73d0SCy Schubert
2225206b73d0SCy Schubert
atheros_wnm_oper(void * priv,enum wnm_oper oper,const u8 * peer,u8 * buf,u16 * buf_len)2226206b73d0SCy Schubert static int atheros_wnm_oper(void *priv, enum wnm_oper oper, const u8 *peer,
2227206b73d0SCy Schubert u8 *buf, u16 *buf_len)
2228206b73d0SCy Schubert {
2229206b73d0SCy Schubert struct atheros_driver_data *drv = priv;
2230206b73d0SCy Schubert
2231206b73d0SCy Schubert switch (oper) {
2232206b73d0SCy Schubert case WNM_SLEEP_ENTER_CONFIRM:
2233206b73d0SCy Schubert case WNM_SLEEP_ENTER_FAIL:
2234206b73d0SCy Schubert case WNM_SLEEP_EXIT_CONFIRM:
2235206b73d0SCy Schubert case WNM_SLEEP_EXIT_FAIL:
2236206b73d0SCy Schubert return atheros_wnm_sleep(drv, peer, oper);
2237206b73d0SCy Schubert case WNM_SLEEP_TFS_REQ_IE_SET:
2238206b73d0SCy Schubert case WNM_SLEEP_TFS_RESP_IE_ADD:
2239206b73d0SCy Schubert case WNM_SLEEP_TFS_RESP_IE_NONE:
2240206b73d0SCy Schubert case WNM_SLEEP_TFS_IE_DEL:
2241206b73d0SCy Schubert return athr_wnm_tfs(drv, peer, buf, buf_len, oper);
2242206b73d0SCy Schubert default:
2243206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "atheros: Unsupported WNM operation %d",
2244206b73d0SCy Schubert oper);
2245206b73d0SCy Schubert return -1;
2246206b73d0SCy Schubert }
2247206b73d0SCy Schubert }
2248206b73d0SCy Schubert #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2249206b73d0SCy Schubert
2250206b73d0SCy Schubert
2251206b73d0SCy Schubert const struct wpa_driver_ops wpa_driver_atheros_ops = {
2252206b73d0SCy Schubert .name = "atheros",
2253206b73d0SCy Schubert .hapd_init = atheros_init,
2254206b73d0SCy Schubert .hapd_deinit = atheros_deinit,
2255206b73d0SCy Schubert .set_ieee8021x = atheros_set_ieee8021x,
2256206b73d0SCy Schubert .set_privacy = atheros_set_privacy,
2257206b73d0SCy Schubert .set_key = atheros_set_key,
2258206b73d0SCy Schubert .get_seqnum = atheros_get_seqnum,
2259206b73d0SCy Schubert .flush = atheros_flush,
2260206b73d0SCy Schubert .set_generic_elem = atheros_set_opt_ie,
2261206b73d0SCy Schubert .sta_set_flags = atheros_sta_set_flags,
2262206b73d0SCy Schubert .read_sta_data = atheros_read_sta_driver_data,
2263206b73d0SCy Schubert .hapd_send_eapol = atheros_send_eapol,
2264206b73d0SCy Schubert .sta_disassoc = atheros_sta_disassoc,
2265206b73d0SCy Schubert .sta_deauth = atheros_sta_deauth,
2266206b73d0SCy Schubert .hapd_set_ssid = atheros_set_ssid,
2267206b73d0SCy Schubert .hapd_get_ssid = atheros_get_ssid,
2268206b73d0SCy Schubert .set_countermeasures = atheros_set_countermeasures,
2269206b73d0SCy Schubert .sta_clear_stats = atheros_sta_clear_stats,
2270206b73d0SCy Schubert .commit = atheros_commit,
2271206b73d0SCy Schubert .set_ap_wps_ie = atheros_set_ap_wps_ie,
2272206b73d0SCy Schubert .set_authmode = atheros_set_authmode,
2273206b73d0SCy Schubert .set_ap = atheros_set_ap,
2274206b73d0SCy Schubert .sta_assoc = atheros_sta_assoc,
2275206b73d0SCy Schubert .sta_auth = atheros_sta_auth,
2276206b73d0SCy Schubert .send_mlme = atheros_send_mgmt,
2277206b73d0SCy Schubert #ifdef CONFIG_IEEE80211R
2278206b73d0SCy Schubert .add_tspec = atheros_add_tspec,
2279206b73d0SCy Schubert .add_sta_node = atheros_add_sta_node,
2280206b73d0SCy Schubert #endif /* CONFIG_IEEE80211R */
2281206b73d0SCy Schubert .send_action = atheros_send_action,
2282206b73d0SCy Schubert #if defined(CONFIG_WNM) && defined(IEEE80211_APPIE_FRAME_WNM)
2283206b73d0SCy Schubert .wnm_oper = atheros_wnm_oper,
2284206b73d0SCy Schubert #endif /* CONFIG_WNM && IEEE80211_APPIE_FRAME_WNM */
2285206b73d0SCy Schubert .set_qos_map = atheros_set_qos_map,
2286206b73d0SCy Schubert };
2287