blob: 1fe55f6f5d177513c1462d4d17651c8423f0e618 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "cfg80211.h"
19#include "debug.h"
Kalle Valoabcb3442011-07-22 08:26:20 +030020#include "hif-ops.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030021#include "testmode.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030022
23#define RATETAB_ENT(_rate, _rateid, _flags) { \
24 .bitrate = (_rate), \
25 .flags = (_flags), \
26 .hw_value = (_rateid), \
27}
28
29#define CHAN2G(_channel, _freq, _flags) { \
30 .band = IEEE80211_BAND_2GHZ, \
31 .hw_value = (_channel), \
32 .center_freq = (_freq), \
33 .flags = (_flags), \
34 .max_antenna_gain = 0, \
35 .max_power = 30, \
36}
37
38#define CHAN5G(_channel, _flags) { \
39 .band = IEEE80211_BAND_5GHZ, \
40 .hw_value = (_channel), \
41 .center_freq = 5000 + (5 * (_channel)), \
42 .flags = (_flags), \
43 .max_antenna_gain = 0, \
44 .max_power = 30, \
45}
46
47static struct ieee80211_rate ath6kl_rates[] = {
48 RATETAB_ENT(10, 0x1, 0),
49 RATETAB_ENT(20, 0x2, 0),
50 RATETAB_ENT(55, 0x4, 0),
51 RATETAB_ENT(110, 0x8, 0),
52 RATETAB_ENT(60, 0x10, 0),
53 RATETAB_ENT(90, 0x20, 0),
54 RATETAB_ENT(120, 0x40, 0),
55 RATETAB_ENT(180, 0x80, 0),
56 RATETAB_ENT(240, 0x100, 0),
57 RATETAB_ENT(360, 0x200, 0),
58 RATETAB_ENT(480, 0x400, 0),
59 RATETAB_ENT(540, 0x800, 0),
60};
61
62#define ath6kl_a_rates (ath6kl_rates + 4)
63#define ath6kl_a_rates_size 8
64#define ath6kl_g_rates (ath6kl_rates + 0)
65#define ath6kl_g_rates_size 12
66
67static struct ieee80211_channel ath6kl_2ghz_channels[] = {
68 CHAN2G(1, 2412, 0),
69 CHAN2G(2, 2417, 0),
70 CHAN2G(3, 2422, 0),
71 CHAN2G(4, 2427, 0),
72 CHAN2G(5, 2432, 0),
73 CHAN2G(6, 2437, 0),
74 CHAN2G(7, 2442, 0),
75 CHAN2G(8, 2447, 0),
76 CHAN2G(9, 2452, 0),
77 CHAN2G(10, 2457, 0),
78 CHAN2G(11, 2462, 0),
79 CHAN2G(12, 2467, 0),
80 CHAN2G(13, 2472, 0),
81 CHAN2G(14, 2484, 0),
82};
83
84static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
85 CHAN5G(34, 0), CHAN5G(36, 0),
86 CHAN5G(38, 0), CHAN5G(40, 0),
87 CHAN5G(42, 0), CHAN5G(44, 0),
88 CHAN5G(46, 0), CHAN5G(48, 0),
89 CHAN5G(52, 0), CHAN5G(56, 0),
90 CHAN5G(60, 0), CHAN5G(64, 0),
91 CHAN5G(100, 0), CHAN5G(104, 0),
92 CHAN5G(108, 0), CHAN5G(112, 0),
93 CHAN5G(116, 0), CHAN5G(120, 0),
94 CHAN5G(124, 0), CHAN5G(128, 0),
95 CHAN5G(132, 0), CHAN5G(136, 0),
96 CHAN5G(140, 0), CHAN5G(149, 0),
97 CHAN5G(153, 0), CHAN5G(157, 0),
98 CHAN5G(161, 0), CHAN5G(165, 0),
99 CHAN5G(184, 0), CHAN5G(188, 0),
100 CHAN5G(192, 0), CHAN5G(196, 0),
101 CHAN5G(200, 0), CHAN5G(204, 0),
102 CHAN5G(208, 0), CHAN5G(212, 0),
103 CHAN5G(216, 0),
104};
105
106static struct ieee80211_supported_band ath6kl_band_2ghz = {
107 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
108 .channels = ath6kl_2ghz_channels,
109 .n_bitrates = ath6kl_g_rates_size,
110 .bitrates = ath6kl_g_rates,
111};
112
113static struct ieee80211_supported_band ath6kl_band_5ghz = {
114 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
115 .channels = ath6kl_5ghz_a_channels,
116 .n_bitrates = ath6kl_a_rates_size,
117 .bitrates = ath6kl_a_rates,
118};
119
120static int ath6kl_set_wpa_version(struct ath6kl *ar,
121 enum nl80211_wpa_versions wpa_version)
122{
123 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
124
125 if (!wpa_version) {
126 ar->auth_mode = NONE_AUTH;
127 } else if (wpa_version & NL80211_WPA_VERSION_2) {
128 ar->auth_mode = WPA2_AUTH;
129 } else if (wpa_version & NL80211_WPA_VERSION_1) {
130 ar->auth_mode = WPA_AUTH;
131 } else {
132 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
133 return -ENOTSUPP;
134 }
135
136 return 0;
137}
138
139static int ath6kl_set_auth_type(struct ath6kl *ar,
140 enum nl80211_auth_type auth_type)
141{
142
143 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
144
145 switch (auth_type) {
146 case NL80211_AUTHTYPE_OPEN_SYSTEM:
147 ar->dot11_auth_mode = OPEN_AUTH;
148 break;
149 case NL80211_AUTHTYPE_SHARED_KEY:
150 ar->dot11_auth_mode = SHARED_AUTH;
151 break;
152 case NL80211_AUTHTYPE_NETWORK_EAP:
153 ar->dot11_auth_mode = LEAP_AUTH;
154 break;
155
156 case NL80211_AUTHTYPE_AUTOMATIC:
157 ar->dot11_auth_mode = OPEN_AUTH;
158 ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS;
159 break;
160
161 default:
162 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
163 return -ENOTSUPP;
164 }
165
166 return 0;
167}
168
169static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
170{
171 u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
Edward Lu38acde32011-08-30 21:58:06 +0300172 u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len :
173 &ar->grp_crypto_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300174
175 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
176 __func__, cipher, ucast);
177
178 switch (cipher) {
179 case 0:
180 /* our own hack to use value 0 as no crypto used */
181 *ar_cipher = NONE_CRYPT;
182 *ar_cipher_len = 0;
183 break;
184 case WLAN_CIPHER_SUITE_WEP40:
185 *ar_cipher = WEP_CRYPT;
186 *ar_cipher_len = 5;
187 break;
188 case WLAN_CIPHER_SUITE_WEP104:
189 *ar_cipher = WEP_CRYPT;
190 *ar_cipher_len = 13;
191 break;
192 case WLAN_CIPHER_SUITE_TKIP:
193 *ar_cipher = TKIP_CRYPT;
194 *ar_cipher_len = 0;
195 break;
196 case WLAN_CIPHER_SUITE_CCMP:
197 *ar_cipher = AES_CRYPT;
198 *ar_cipher_len = 0;
199 break;
200 default:
201 ath6kl_err("cipher 0x%x not supported\n", cipher);
202 return -ENOTSUPP;
203 }
204
205 return 0;
206}
207
208static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
209{
210 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
211
212 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
213 if (ar->auth_mode == WPA_AUTH)
214 ar->auth_mode = WPA_PSK_AUTH;
215 else if (ar->auth_mode == WPA2_AUTH)
216 ar->auth_mode = WPA2_PSK_AUTH;
217 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
218 ar->auth_mode = NONE_AUTH;
219 }
220}
221
222static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
223{
224 if (!test_bit(WMI_READY, &ar->flag)) {
225 ath6kl_err("wmi is not ready\n");
226 return false;
227 }
228
Raja Mani575b5f32011-07-19 19:27:33 +0530229 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300230 ath6kl_err("wlan disabled\n");
231 return false;
232 }
233
234 return true;
235}
236
237static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
238 struct cfg80211_connect_params *sme)
239{
240 struct ath6kl *ar = ath6kl_priv(dev);
241 int status;
242
243 ar->sme_state = SME_CONNECTING;
244
245 if (!ath6kl_cfg80211_ready(ar))
246 return -EIO;
247
248 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
249 ath6kl_err("destroy in progress\n");
250 return -EBUSY;
251 }
252
253 if (test_bit(SKIP_SCAN, &ar->flag) &&
254 ((sme->channel && sme->channel->center_freq == 0) ||
255 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
256 ath6kl_err("SkipScan: channel or bssid invalid\n");
257 return -EINVAL;
258 }
259
260 if (down_interruptible(&ar->sem)) {
261 ath6kl_err("busy, couldn't get access\n");
262 return -ERESTARTSYS;
263 }
264
265 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
266 ath6kl_err("busy, destroy in progress\n");
267 up(&ar->sem);
268 return -EBUSY;
269 }
270
271 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
272 /*
273 * sleep until the command queue drains
274 */
275 wait_event_interruptible_timeout(ar->event_wq,
276 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
277 WMI_TIMEOUT);
278 if (signal_pending(current)) {
279 ath6kl_err("cmd queue drain timeout\n");
280 up(&ar->sem);
281 return -EINTR;
282 }
283 }
284
285 if (test_bit(CONNECTED, &ar->flag) &&
286 ar->ssid_len == sme->ssid_len &&
287 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
288 ar->reconnect_flag = true;
289 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
290 ar->ch_hint);
291
292 up(&ar->sem);
293 if (status) {
294 ath6kl_err("wmi_reconnect_cmd failed\n");
295 return -EIO;
296 }
297 return 0;
298 } else if (ar->ssid_len == sme->ssid_len &&
299 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
300 ath6kl_disconnect(ar);
301 }
302
303 memset(ar->ssid, 0, sizeof(ar->ssid));
304 ar->ssid_len = sme->ssid_len;
305 memcpy(ar->ssid, sme->ssid, sme->ssid_len);
306
307 if (sme->channel)
308 ar->ch_hint = sme->channel->center_freq;
309
310 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
311 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
312 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
313
314 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
315
316 status = ath6kl_set_auth_type(ar, sme->auth_type);
317 if (status) {
318 up(&ar->sem);
319 return status;
320 }
321
322 if (sme->crypto.n_ciphers_pairwise)
323 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
324 else
325 ath6kl_set_cipher(ar, 0, true);
326
327 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
328
329 if (sme->crypto.n_akm_suites)
330 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
331
332 if ((sme->key_len) &&
333 (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
334 struct ath6kl_key *key = NULL;
335
336 if (sme->key_idx < WMI_MIN_KEY_INDEX ||
337 sme->key_idx > WMI_MAX_KEY_INDEX) {
338 ath6kl_err("key index %d out of bounds\n",
339 sme->key_idx);
340 up(&ar->sem);
341 return -ENOENT;
342 }
343
344 key = &ar->keys[sme->key_idx];
345 key->key_len = sme->key_len;
346 memcpy(key->key, sme->key, key->key_len);
347 key->cipher = ar->prwise_crypto;
348 ar->def_txkey_index = sme->key_idx;
349
350 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
351 ar->prwise_crypto,
352 GROUP_USAGE | TX_USAGE,
353 key->key_len,
354 NULL,
355 key->key, KEY_OP_INIT_VAL, NULL,
356 NO_SYNC_WMIFLAG);
357 }
358
359 if (!ar->usr_bss_filter) {
360 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
361 ath6kl_err("couldn't set bss filtering\n");
362 up(&ar->sem);
363 return -EIO;
364 }
365 }
366
367 ar->nw_type = ar->next_mode;
368
369 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
370 "%s: connect called with authmode %d dot11 auth %d"
371 " PW crypto %d PW crypto len %d GRP crypto %d"
372 " GRP crypto len %d channel hint %u\n",
373 __func__,
374 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
375 ar->prwise_crypto_len, ar->grp_crypto,
Edward Lu38acde32011-08-30 21:58:06 +0300376 ar->grp_crypto_len, ar->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300377
378 ar->reconnect_flag = 0;
379 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
380 ar->dot11_auth_mode, ar->auth_mode,
381 ar->prwise_crypto,
382 ar->prwise_crypto_len,
Edward Lu38acde32011-08-30 21:58:06 +0300383 ar->grp_crypto, ar->grp_crypto_len,
Kalle Valobdcd8172011-07-18 00:22:30 +0300384 ar->ssid_len, ar->ssid,
385 ar->req_bssid, ar->ch_hint,
386 ar->connect_ctrl_flags);
387
388 up(&ar->sem);
389
390 if (status == -EINVAL) {
391 memset(ar->ssid, 0, sizeof(ar->ssid));
392 ar->ssid_len = 0;
393 ath6kl_err("invalid request\n");
394 return -ENOENT;
395 } else if (status) {
396 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
397 return -EIO;
398 }
399
400 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
401 ((ar->auth_mode == WPA_PSK_AUTH)
402 || (ar->auth_mode == WPA2_PSK_AUTH))) {
403 mod_timer(&ar->disconnect_timer,
404 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
405 }
406
407 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
408 set_bit(CONNECT_PEND, &ar->flag);
409
410 return 0;
411}
412
413void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
414 u8 *bssid, u16 listen_intvl,
415 u16 beacon_intvl,
416 enum network_type nw_type,
417 u8 beacon_ie_len, u8 assoc_req_len,
418 u8 assoc_resp_len, u8 *assoc_info)
419{
420 u16 size = 0;
421 u16 capability = 0;
422 struct cfg80211_bss *bss = NULL;
423 struct ieee80211_mgmt *mgmt = NULL;
424 struct ieee80211_channel *ibss_ch = NULL;
425 s32 signal = 50 * 100;
426 u8 ie_buf_len = 0;
427 unsigned char ie_buf[256];
428 unsigned char *ptr_ie_buf = ie_buf;
429 unsigned char *ieeemgmtbuf = NULL;
430 u8 source_mac[ETH_ALEN];
Kalle Valobdcd8172011-07-18 00:22:30 +0300431
432 /* capinfo + listen interval */
433 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
434
435 /* capinfo + status code + associd */
436 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
437
438 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
439 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
440 assoc_resp_ie_offset;
441
442 assoc_req_len -= assoc_req_ie_offset;
443 assoc_resp_len -= assoc_resp_ie_offset;
444
445 ar->auto_auth_stage = AUTH_IDLE;
446
447 if (nw_type & ADHOC_NETWORK) {
448 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
449 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
450 "%s: ath6k not in ibss mode\n", __func__);
451 return;
452 }
453 }
454
455 if (nw_type & INFRA_NETWORK) {
Jouni Malinen6b5e5d22011-08-30 21:58:05 +0300456 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
457 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300458 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
459 "%s: ath6k not in station mode\n", __func__);
460 return;
461 }
462 }
463
Kalle Valobdcd8172011-07-18 00:22:30 +0300464 /*
465 * Earlier we were updating the cfg about bss by making a beacon frame
466 * only if the entry for bss is not there. This can have some issue if
467 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
468 * event is handled through a work queue and by the time it really gets
469 * handled, BSS would have been aged out. So it is better to update the
470 * cfg about BSS irrespective of its entry being present right now or
471 * not.
472 */
473
474 if (nw_type & ADHOC_NETWORK) {
475 /* construct 802.11 mgmt beacon */
476 if (ptr_ie_buf) {
477 *ptr_ie_buf++ = WLAN_EID_SSID;
478 *ptr_ie_buf++ = ar->ssid_len;
479 memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
480 ptr_ie_buf += ar->ssid_len;
481
482 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
483 *ptr_ie_buf++ = 2; /* length */
484 *ptr_ie_buf++ = 0; /* ATIM window */
485 *ptr_ie_buf++ = 0; /* ATIM window */
486
487 /* TODO: update ibss params and include supported rates,
488 * DS param set, extened support rates, wmm. */
489
490 ie_buf_len = ptr_ie_buf - ie_buf;
491 }
492
493 capability |= WLAN_CAPABILITY_IBSS;
494
495 if (ar->prwise_crypto == WEP_CRYPT)
496 capability |= WLAN_CAPABILITY_PRIVACY;
497
498 memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
499 ptr_ie_buf = ie_buf;
500 } else {
501 capability = *(u16 *) (&assoc_info[beacon_ie_len]);
502 memcpy(source_mac, bssid, ETH_ALEN);
503 ptr_ie_buf = assoc_req_ie;
504 ie_buf_len = assoc_req_len;
505 }
506
507 size = offsetof(struct ieee80211_mgmt, u)
508 + sizeof(mgmt->u.beacon)
509 + ie_buf_len;
510
511 ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
512 if (!ieeemgmtbuf) {
513 ath6kl_err("ieee mgmt buf alloc error\n");
Kalle Valobdcd8172011-07-18 00:22:30 +0300514 return;
515 }
516
517 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
518 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
519 IEEE80211_STYPE_BEACON);
520 memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
521 memcpy(mgmt->sa, source_mac, ETH_ALEN);
522 memcpy(mgmt->bssid, bssid, ETH_ALEN);
523 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
524 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
525 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
526
527 ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
528
529 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
530 "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
531 __func__, mgmt->bssid, ibss_ch->hw_value,
532 beacon_intvl, capability);
533
534 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
535 ibss_ch, mgmt,
536 size, signal, GFP_KERNEL);
537 kfree(ieeemgmtbuf);
538 cfg80211_put_bss(bss);
539
540 if (nw_type & ADHOC_NETWORK) {
541 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
542 return;
543 }
544
Raja Mani9aa60352011-08-04 19:26:29 +0530545 if (ar->sme_state == SME_CONNECTING) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300546 /* inform connect result to cfg80211 */
Raja Mani9aa60352011-08-04 19:26:29 +0530547 ar->sme_state = SME_CONNECTED;
Kalle Valobdcd8172011-07-18 00:22:30 +0300548 cfg80211_connect_result(ar->net_dev, bssid,
549 assoc_req_ie, assoc_req_len,
550 assoc_resp_ie, assoc_resp_len,
551 WLAN_STATUS_SUCCESS, GFP_KERNEL);
Raja Mani9aa60352011-08-04 19:26:29 +0530552 } else if (ar->sme_state == SME_CONNECTED) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300553 /* inform roam event to cfg80211 */
554 cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
555 assoc_req_ie, assoc_req_len,
556 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
557 }
558}
559
560static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
561 struct net_device *dev, u16 reason_code)
562{
563 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
564
565 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
566 reason_code);
567
568 if (!ath6kl_cfg80211_ready(ar))
569 return -EIO;
570
571 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
572 ath6kl_err("busy, destroy in progress\n");
573 return -EBUSY;
574 }
575
576 if (down_interruptible(&ar->sem)) {
577 ath6kl_err("busy, couldn't get access\n");
578 return -ERESTARTSYS;
579 }
580
581 ar->reconnect_flag = 0;
582 ath6kl_disconnect(ar);
583 memset(ar->ssid, 0, sizeof(ar->ssid));
584 ar->ssid_len = 0;
585
586 if (!test_bit(SKIP_SCAN, &ar->flag))
587 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
588
589 up(&ar->sem);
590
591 return 0;
592}
593
594void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
595 u8 *bssid, u8 assoc_resp_len,
596 u8 *assoc_info, u16 proto_reason)
597{
598 struct ath6kl_key *key = NULL;
599 u16 status;
600
601 if (ar->scan_req) {
602 cfg80211_scan_done(ar->scan_req, true);
603 ar->scan_req = NULL;
604 }
605
606 if (ar->nw_type & ADHOC_NETWORK) {
607 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
608 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
609 "%s: ath6k not in ibss mode\n", __func__);
610 return;
611 }
612 memset(bssid, 0, ETH_ALEN);
613 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
614 return;
615 }
616
617 if (ar->nw_type & INFRA_NETWORK) {
Jouni Malinen6b5e5d22011-08-30 21:58:05 +0300618 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
619 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300620 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
621 "%s: ath6k not in station mode\n", __func__);
622 return;
623 }
624 }
625
626 if (!test_bit(CONNECT_PEND, &ar->flag)) {
627 if (reason != DISCONNECT_CMD)
628 ath6kl_wmi_disconnect_cmd(ar->wmi);
629
630 return;
631 }
632
633 if (reason == NO_NETWORK_AVAIL) {
634 /* connect cmd failed */
635 ath6kl_wmi_disconnect_cmd(ar->wmi);
636 return;
637 }
638
639 if (reason != DISCONNECT_CMD)
640 return;
641
642 if (!ar->auto_auth_stage) {
643 clear_bit(CONNECT_PEND, &ar->flag);
644
645 if (ar->sme_state == SME_CONNECTING) {
646 cfg80211_connect_result(ar->net_dev,
647 bssid, NULL, 0,
648 NULL, 0,
649 WLAN_STATUS_UNSPECIFIED_FAILURE,
650 GFP_KERNEL);
Raja Mani0e5cc8e2011-08-12 17:52:24 +0530651 } else if (ar->sme_state == SME_CONNECTED) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300652 cfg80211_disconnected(ar->net_dev, reason,
653 NULL, 0, GFP_KERNEL);
654 }
655
656 ar->sme_state = SME_DISCONNECTED;
657 return;
658 }
659
660 if (ar->dot11_auth_mode != OPEN_AUTH)
661 return;
662
663 /*
664 * If the current auth algorithm is open, try shared and
665 * make autoAuthStage idle. We do not make it leap for now
666 * being.
667 */
668 key = &ar->keys[ar->def_txkey_index];
669 if (down_interruptible(&ar->sem)) {
670 ath6kl_err("busy, couldn't get access\n");
671 return;
672 }
673
674 ar->dot11_auth_mode = SHARED_AUTH;
675 ar->auto_auth_stage = AUTH_IDLE;
676
677 ath6kl_wmi_addkey_cmd(ar->wmi,
678 ar->def_txkey_index,
679 ar->prwise_crypto,
680 GROUP_USAGE | TX_USAGE,
681 key->key_len, NULL,
682 key->key,
683 KEY_OP_INIT_VAL, NULL,
684 NO_SYNC_WMIFLAG);
685
686 status = ath6kl_wmi_connect_cmd(ar->wmi,
687 ar->nw_type,
688 ar->dot11_auth_mode,
689 ar->auth_mode,
690 ar->prwise_crypto,
691 ar->prwise_crypto_len,
692 ar->grp_crypto,
Edward Lu38acde32011-08-30 21:58:06 +0300693 ar->grp_crypto_len,
Kalle Valobdcd8172011-07-18 00:22:30 +0300694 ar->ssid_len,
695 ar->ssid,
696 ar->req_bssid,
697 ar->ch_hint,
698 ar->connect_ctrl_flags);
699 up(&ar->sem);
700}
701
702static inline bool is_ch_11a(u16 ch)
703{
704 return (!((ch >= 2412) && (ch <= 2484)));
705}
706
Kalle Valocf104c22011-07-21 10:04:54 +0300707/* struct ath6kl_node_table::nt_nodelock is locked when calling this */
Vasanthakumar Thiagarajan91db35d2011-07-21 18:12:15 +0530708void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
Kalle Valobdcd8172011-07-18 00:22:30 +0300709{
Kalle Valobdcd8172011-07-18 00:22:30 +0300710 struct ieee80211_mgmt *mgmt;
711 struct ieee80211_channel *channel;
712 struct ieee80211_supported_band *band;
713 struct ath6kl_common_ie *cie;
714 s32 signal;
715 int freq;
716
717 cie = &ni->ni_cie;
718
719 if (is_ch_11a(cie->ie_chan))
720 band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
721 else if ((cie->ie_erp) || (cie->ie_xrates))
722 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
723 else
724 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
725
Kalle Valobdcd8172011-07-18 00:22:30 +0300726 freq = cie->ie_chan;
727 channel = ieee80211_get_channel(wiphy, freq);
728 signal = ni->ni_snr * 100;
729
730 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
731 "%s: bssid %pM ch %d freq %d size %d\n", __func__,
Jouni Malinen0ce77922011-08-11 00:32:49 +0300732 ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
733 /*
734 * Both Beacon and Probe Response frames have same payload structure,
735 * so it is fine to share the parser for both.
736 */
737 if (ni->ni_framelen < 8 + 2 + 2)
738 return;
739 mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
740 offsetof(struct ieee80211_mgmt, u));
741 cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
742 le64_to_cpu(mgmt->u.beacon.timestamp),
743 le16_to_cpu(mgmt->u.beacon.capab_info),
744 le16_to_cpu(mgmt->u.beacon.beacon_int),
745 mgmt->u.beacon.variable,
746 ni->ni_buf + ni->ni_framelen -
747 mgmt->u.beacon.variable,
748 signal, GFP_ATOMIC);
Kalle Valobdcd8172011-07-18 00:22:30 +0300749}
750
751static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
752 struct cfg80211_scan_request *request)
753{
754 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
Edward Lu1276c9e2011-08-30 21:58:00 +0300755 s8 n_channels = 0;
756 u16 *channels = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300757 int ret = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300758
759 if (!ath6kl_cfg80211_ready(ar))
760 return -EIO;
761
762 if (!ar->usr_bss_filter) {
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300763 ret = ath6kl_wmi_bssfilter_cmd(
764 ar->wmi,
765 (test_bit(CONNECTED, &ar->flag) ?
766 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
767 if (ret) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300768 ath6kl_err("couldn't set bss filtering\n");
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300769 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300770 }
771 }
772
773 if (request->n_ssids && request->ssids[0].ssid_len) {
774 u8 i;
775
776 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
777 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
778
779 for (i = 0; i < request->n_ssids; i++)
780 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
781 SPECIFIC_SSID_FLAG,
782 request->ssids[i].ssid_len,
783 request->ssids[i].ssid);
784 }
785
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300786 if (request->ie) {
787 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
788 request->ie, request->ie_len);
789 if (ret) {
790 ath6kl_err("failed to set Probe Request appie for "
791 "scan");
792 return ret;
793 }
794 }
795
Jouni Malinen11869be2011-09-02 20:07:06 +0300796 /*
797 * Scan only the requested channels if the request specifies a set of
798 * channels. If the list is longer than the target supports, do not
799 * configure the list and instead, scan all available channels.
800 */
801 if (request->n_channels > 0 &&
802 request->n_channels <= WMI_MAX_CHANNELS) {
Edward Lu1276c9e2011-08-30 21:58:00 +0300803 u8 i;
804
Jouni Malinen11869be2011-09-02 20:07:06 +0300805 n_channels = request->n_channels;
Edward Lu1276c9e2011-08-30 21:58:00 +0300806
807 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
808 if (channels == NULL) {
809 ath6kl_warn("failed to set scan channels, "
810 "scan all channels");
811 n_channels = 0;
812 }
813
814 for (i = 0; i < n_channels; i++)
815 channels[i] = request->channels[i]->center_freq;
816 }
817
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300818 ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
819 false, 0, 0, n_channels, channels);
820 if (ret)
Kalle Valobdcd8172011-07-18 00:22:30 +0300821 ath6kl_err("wmi_startscan_cmd failed\n");
Jouni Malinen11869be2011-09-02 20:07:06 +0300822 else
823 ar->scan_req = request;
Kalle Valobdcd8172011-07-18 00:22:30 +0300824
Edward Lu1276c9e2011-08-30 21:58:00 +0300825 kfree(channels);
826
Kalle Valobdcd8172011-07-18 00:22:30 +0300827 return ret;
828}
829
830void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
831{
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300832 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300833
834 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
835
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300836 if (!ar->scan_req)
837 return;
Kalle Valobdcd8172011-07-18 00:22:30 +0300838
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300839 if ((status == -ECANCELED) || (status == -EBUSY)) {
840 cfg80211_scan_done(ar->scan_req, true);
841 goto out;
Kalle Valobdcd8172011-07-18 00:22:30 +0300842 }
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300843
844 /* Translate data to cfg80211 mgmt format */
Vasanthakumar Thiagarajan8a8bc5a2011-07-21 14:42:52 +0530845 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300846
847 cfg80211_scan_done(ar->scan_req, false);
848
849 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
850 for (i = 0; i < ar->scan_req->n_ssids; i++) {
851 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
852 DISABLE_SSID_FLAG,
853 0, NULL);
854 }
855 }
856
857out:
858 ar->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300859}
860
861static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
862 u8 key_index, bool pairwise,
863 const u8 *mac_addr,
864 struct key_params *params)
865{
866 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
867 struct ath6kl_key *key = NULL;
868 u8 key_usage;
869 u8 key_type;
870 int status = 0;
871
872 if (!ath6kl_cfg80211_ready(ar))
873 return -EIO;
874
875 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
876 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
877 "%s: key index %d out of bounds\n", __func__,
878 key_index);
879 return -ENOENT;
880 }
881
882 key = &ar->keys[key_index];
883 memset(key, 0, sizeof(struct ath6kl_key));
884
885 if (pairwise)
886 key_usage = PAIRWISE_USAGE;
887 else
888 key_usage = GROUP_USAGE;
889
890 if (params) {
891 if (params->key_len > WLAN_MAX_KEY_LEN ||
892 params->seq_len > sizeof(key->seq))
893 return -EINVAL;
894
895 key->key_len = params->key_len;
896 memcpy(key->key, params->key, key->key_len);
897 key->seq_len = params->seq_len;
898 memcpy(key->seq, params->seq, key->seq_len);
899 key->cipher = params->cipher;
900 }
901
902 switch (key->cipher) {
903 case WLAN_CIPHER_SUITE_WEP40:
904 case WLAN_CIPHER_SUITE_WEP104:
905 key_type = WEP_CRYPT;
906 break;
907
908 case WLAN_CIPHER_SUITE_TKIP:
909 key_type = TKIP_CRYPT;
910 break;
911
912 case WLAN_CIPHER_SUITE_CCMP:
913 key_type = AES_CRYPT;
914 break;
915
916 default:
917 return -ENOTSUPP;
918 }
919
920 if (((ar->auth_mode == WPA_PSK_AUTH)
921 || (ar->auth_mode == WPA2_PSK_AUTH))
922 && (key_usage & GROUP_USAGE))
923 del_timer(&ar->disconnect_timer);
924
925 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
926 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
927 __func__, key_index, key->key_len, key_type,
928 key_usage, key->seq_len);
929
930 ar->def_txkey_index = key_index;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300931
932 if (ar->nw_type == AP_NETWORK && !pairwise &&
933 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
934 ar->ap_mode_bkey.valid = true;
935 ar->ap_mode_bkey.key_index = key_index;
936 ar->ap_mode_bkey.key_type = key_type;
937 ar->ap_mode_bkey.key_len = key->key_len;
938 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
939 if (!test_bit(CONNECTED, &ar->flag)) {
940 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
941 "key configuration until AP mode has been "
942 "started\n");
943 /*
944 * The key will be set in ath6kl_connect_ap_mode() once
945 * the connected event is received from the target.
946 */
947 return 0;
948 }
949 }
950
Kalle Valobdcd8172011-07-18 00:22:30 +0300951 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
952 key_type, key_usage, key->key_len,
953 key->seq, key->key, KEY_OP_INIT_VAL,
954 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
955
956 if (status)
957 return -EIO;
958
959 return 0;
960}
961
962static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
963 u8 key_index, bool pairwise,
964 const u8 *mac_addr)
965{
966 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
967
968 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
969
970 if (!ath6kl_cfg80211_ready(ar))
971 return -EIO;
972
973 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
974 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
975 "%s: key index %d out of bounds\n", __func__,
976 key_index);
977 return -ENOENT;
978 }
979
980 if (!ar->keys[key_index].key_len) {
981 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
982 "%s: index %d is empty\n", __func__, key_index);
983 return 0;
984 }
985
986 ar->keys[key_index].key_len = 0;
987
988 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
989}
990
991static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
992 u8 key_index, bool pairwise,
993 const u8 *mac_addr, void *cookie,
994 void (*callback) (void *cookie,
995 struct key_params *))
996{
997 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
998 struct ath6kl_key *key = NULL;
999 struct key_params params;
1000
1001 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1002
1003 if (!ath6kl_cfg80211_ready(ar))
1004 return -EIO;
1005
1006 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1007 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1008 "%s: key index %d out of bounds\n", __func__,
1009 key_index);
1010 return -ENOENT;
1011 }
1012
1013 key = &ar->keys[key_index];
1014 memset(&params, 0, sizeof(params));
1015 params.cipher = key->cipher;
1016 params.key_len = key->key_len;
1017 params.seq_len = key->seq_len;
1018 params.seq = key->seq;
1019 params.key = key->key;
1020
1021 callback(cookie, &params);
1022
1023 return key->key_len ? 0 : -ENOENT;
1024}
1025
1026static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1027 struct net_device *ndev,
1028 u8 key_index, bool unicast,
1029 bool multicast)
1030{
1031 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1032 struct ath6kl_key *key = NULL;
1033 int status = 0;
1034 u8 key_usage;
Edward Lu229ed6b2011-08-30 21:58:07 +03001035 enum crypto_type key_type = NONE_CRYPT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001036
1037 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1038
1039 if (!ath6kl_cfg80211_ready(ar))
1040 return -EIO;
1041
1042 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1043 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1044 "%s: key index %d out of bounds\n",
1045 __func__, key_index);
1046 return -ENOENT;
1047 }
1048
1049 if (!ar->keys[key_index].key_len) {
1050 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1051 __func__, key_index);
1052 return -EINVAL;
1053 }
1054
1055 ar->def_txkey_index = key_index;
1056 key = &ar->keys[ar->def_txkey_index];
1057 key_usage = GROUP_USAGE;
1058 if (ar->prwise_crypto == WEP_CRYPT)
1059 key_usage |= TX_USAGE;
Edward Lu229ed6b2011-08-30 21:58:07 +03001060 if (unicast)
1061 key_type = ar->prwise_crypto;
1062 if (multicast)
1063 key_type = ar->grp_crypto;
Kalle Valobdcd8172011-07-18 00:22:30 +03001064
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001065 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1066 return 0; /* Delay until AP mode has been started */
1067
Kalle Valobdcd8172011-07-18 00:22:30 +03001068 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
Edward Lu229ed6b2011-08-30 21:58:07 +03001069 key_type, key_usage,
Kalle Valobdcd8172011-07-18 00:22:30 +03001070 key->key_len, key->seq, key->key,
1071 KEY_OP_INIT_VAL, NULL,
1072 SYNC_BOTH_WMIFLAG);
1073 if (status)
1074 return -EIO;
1075
1076 return 0;
1077}
1078
1079void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1080 bool ismcast)
1081{
1082 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1083 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1084
1085 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1086 (ismcast ? NL80211_KEYTYPE_GROUP :
1087 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1088 GFP_KERNEL);
1089}
1090
1091static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1092{
1093 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1094 int ret;
1095
1096 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1097 changed);
1098
1099 if (!ath6kl_cfg80211_ready(ar))
1100 return -EIO;
1101
1102 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1103 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1104 if (ret != 0) {
1105 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1106 return -EIO;
1107 }
1108 }
1109
1110 return 0;
1111}
1112
1113/*
1114 * The type nl80211_tx_power_setting replaces the following
1115 * data type from 2.6.36 onwards
1116*/
1117static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1118 enum nl80211_tx_power_setting type,
1119 int dbm)
1120{
1121 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1122 u8 ath6kl_dbm;
1123
1124 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1125 type, dbm);
1126
1127 if (!ath6kl_cfg80211_ready(ar))
1128 return -EIO;
1129
1130 switch (type) {
1131 case NL80211_TX_POWER_AUTOMATIC:
1132 return 0;
1133 case NL80211_TX_POWER_LIMITED:
1134 ar->tx_pwr = ath6kl_dbm = dbm;
1135 break;
1136 default:
1137 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1138 __func__, type);
1139 return -EOPNOTSUPP;
1140 }
1141
1142 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1143
1144 return 0;
1145}
1146
1147static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1148{
1149 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1150
1151 if (!ath6kl_cfg80211_ready(ar))
1152 return -EIO;
1153
1154 if (test_bit(CONNECTED, &ar->flag)) {
1155 ar->tx_pwr = 0;
1156
1157 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1158 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1159 return -EIO;
1160 }
1161
1162 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1163 5 * HZ);
1164
1165 if (signal_pending(current)) {
1166 ath6kl_err("target did not respond\n");
1167 return -EINTR;
1168 }
1169 }
1170
1171 *dbm = ar->tx_pwr;
1172 return 0;
1173}
1174
1175static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1176 struct net_device *dev,
1177 bool pmgmt, int timeout)
1178{
1179 struct ath6kl *ar = ath6kl_priv(dev);
1180 struct wmi_power_mode_cmd mode;
1181
1182 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1183 __func__, pmgmt, timeout);
1184
1185 if (!ath6kl_cfg80211_ready(ar))
1186 return -EIO;
1187
1188 if (pmgmt) {
1189 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1190 mode.pwr_mode = REC_POWER;
1191 } else {
1192 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1193 mode.pwr_mode = MAX_PERF_POWER;
1194 }
1195
1196 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1197 ath6kl_err("wmi_powermode_cmd failed\n");
1198 return -EIO;
1199 }
1200
1201 return 0;
1202}
1203
1204static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1205 struct net_device *ndev,
1206 enum nl80211_iftype type, u32 *flags,
1207 struct vif_params *params)
1208{
1209 struct ath6kl *ar = ath6kl_priv(ndev);
1210 struct wireless_dev *wdev = ar->wdev;
1211
1212 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1213
1214 if (!ath6kl_cfg80211_ready(ar))
1215 return -EIO;
1216
1217 switch (type) {
1218 case NL80211_IFTYPE_STATION:
1219 ar->next_mode = INFRA_NETWORK;
1220 break;
1221 case NL80211_IFTYPE_ADHOC:
1222 ar->next_mode = ADHOC_NETWORK;
1223 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001224 case NL80211_IFTYPE_P2P_CLIENT:
1225 ar->next_mode = INFRA_NETWORK;
1226 break;
1227 case NL80211_IFTYPE_P2P_GO:
1228 ar->next_mode = AP_NETWORK;
1229 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001230 default:
1231 ath6kl_err("invalid interface type %u\n", type);
1232 return -EOPNOTSUPP;
1233 }
1234
1235 wdev->iftype = type;
1236
1237 return 0;
1238}
1239
1240static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1241 struct net_device *dev,
1242 struct cfg80211_ibss_params *ibss_param)
1243{
1244 struct ath6kl *ar = ath6kl_priv(dev);
1245 int status;
1246
1247 if (!ath6kl_cfg80211_ready(ar))
1248 return -EIO;
1249
1250 ar->ssid_len = ibss_param->ssid_len;
1251 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1252
1253 if (ibss_param->channel)
1254 ar->ch_hint = ibss_param->channel->center_freq;
1255
1256 if (ibss_param->channel_fixed) {
1257 /*
1258 * TODO: channel_fixed: The channel should be fixed, do not
1259 * search for IBSSs to join on other channels. Target
1260 * firmware does not support this feature, needs to be
1261 * updated.
1262 */
1263 return -EOPNOTSUPP;
1264 }
1265
1266 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1267 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1268 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1269
1270 ath6kl_set_wpa_version(ar, 0);
1271
1272 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1273 if (status)
1274 return status;
1275
1276 if (ibss_param->privacy) {
1277 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1278 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1279 } else {
1280 ath6kl_set_cipher(ar, 0, true);
1281 ath6kl_set_cipher(ar, 0, false);
1282 }
1283
1284 ar->nw_type = ar->next_mode;
1285
1286 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1287 "%s: connect called with authmode %d dot11 auth %d"
1288 " PW crypto %d PW crypto len %d GRP crypto %d"
1289 " GRP crypto len %d channel hint %u\n",
1290 __func__,
1291 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1292 ar->prwise_crypto_len, ar->grp_crypto,
Edward Lu38acde32011-08-30 21:58:06 +03001293 ar->grp_crypto_len, ar->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001294
1295 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1296 ar->dot11_auth_mode, ar->auth_mode,
1297 ar->prwise_crypto,
1298 ar->prwise_crypto_len,
Edward Lu38acde32011-08-30 21:58:06 +03001299 ar->grp_crypto, ar->grp_crypto_len,
Kalle Valobdcd8172011-07-18 00:22:30 +03001300 ar->ssid_len, ar->ssid,
1301 ar->req_bssid, ar->ch_hint,
1302 ar->connect_ctrl_flags);
1303 set_bit(CONNECT_PEND, &ar->flag);
1304
1305 return 0;
1306}
1307
1308static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1309 struct net_device *dev)
1310{
1311 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1312
1313 if (!ath6kl_cfg80211_ready(ar))
1314 return -EIO;
1315
1316 ath6kl_disconnect(ar);
1317 memset(ar->ssid, 0, sizeof(ar->ssid));
1318 ar->ssid_len = 0;
1319
1320 return 0;
1321}
1322
1323static const u32 cipher_suites[] = {
1324 WLAN_CIPHER_SUITE_WEP40,
1325 WLAN_CIPHER_SUITE_WEP104,
1326 WLAN_CIPHER_SUITE_TKIP,
1327 WLAN_CIPHER_SUITE_CCMP,
1328};
1329
1330static bool is_rate_legacy(s32 rate)
1331{
1332 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1333 6000, 9000, 12000, 18000, 24000,
1334 36000, 48000, 54000
1335 };
1336 u8 i;
1337
1338 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1339 if (rate == legacy[i])
1340 return true;
1341
1342 return false;
1343}
1344
1345static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1346{
1347 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1348 52000, 58500, 65000, 72200
1349 };
1350 u8 i;
1351
1352 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1353 if (rate == ht20[i]) {
1354 if (i == ARRAY_SIZE(ht20) - 1)
1355 /* last rate uses sgi */
1356 *sgi = true;
1357 else
1358 *sgi = false;
1359
1360 *mcs = i;
1361 return true;
1362 }
1363 }
1364 return false;
1365}
1366
1367static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1368{
1369 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1370 81000, 108000, 121500, 135000,
1371 150000
1372 };
1373 u8 i;
1374
1375 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1376 if (rate == ht40[i]) {
1377 if (i == ARRAY_SIZE(ht40) - 1)
1378 /* last rate uses sgi */
1379 *sgi = true;
1380 else
1381 *sgi = false;
1382
1383 *mcs = i;
1384 return true;
1385 }
1386 }
1387
1388 return false;
1389}
1390
1391static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1392 u8 *mac, struct station_info *sinfo)
1393{
1394 struct ath6kl *ar = ath6kl_priv(dev);
1395 long left;
1396 bool sgi;
1397 s32 rate;
1398 int ret;
1399 u8 mcs;
1400
1401 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1402 return -ENOENT;
1403
1404 if (down_interruptible(&ar->sem))
1405 return -EBUSY;
1406
1407 set_bit(STATS_UPDATE_PEND, &ar->flag);
1408
1409 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1410
1411 if (ret != 0) {
1412 up(&ar->sem);
1413 return -EIO;
1414 }
1415
1416 left = wait_event_interruptible_timeout(ar->event_wq,
1417 !test_bit(STATS_UPDATE_PEND,
1418 &ar->flag),
1419 WMI_TIMEOUT);
1420
1421 up(&ar->sem);
1422
1423 if (left == 0)
1424 return -ETIMEDOUT;
1425 else if (left < 0)
1426 return left;
1427
1428 if (ar->target_stats.rx_byte) {
1429 sinfo->rx_bytes = ar->target_stats.rx_byte;
1430 sinfo->filled |= STATION_INFO_RX_BYTES;
1431 sinfo->rx_packets = ar->target_stats.rx_pkt;
1432 sinfo->filled |= STATION_INFO_RX_PACKETS;
1433 }
1434
1435 if (ar->target_stats.tx_byte) {
1436 sinfo->tx_bytes = ar->target_stats.tx_byte;
1437 sinfo->filled |= STATION_INFO_TX_BYTES;
1438 sinfo->tx_packets = ar->target_stats.tx_pkt;
1439 sinfo->filled |= STATION_INFO_TX_PACKETS;
1440 }
1441
1442 sinfo->signal = ar->target_stats.cs_rssi;
1443 sinfo->filled |= STATION_INFO_SIGNAL;
1444
1445 rate = ar->target_stats.tx_ucast_rate;
1446
1447 if (is_rate_legacy(rate)) {
1448 sinfo->txrate.legacy = rate / 100;
1449 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1450 if (sgi) {
1451 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1452 sinfo->txrate.mcs = mcs - 1;
1453 } else {
1454 sinfo->txrate.mcs = mcs;
1455 }
1456
1457 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1458 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1459 if (sgi) {
1460 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1461 sinfo->txrate.mcs = mcs - 1;
1462 } else {
1463 sinfo->txrate.mcs = mcs;
1464 }
1465
1466 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1467 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1468 } else {
1469 ath6kl_warn("invalid rate: %d\n", rate);
1470 return 0;
1471 }
1472
1473 sinfo->filled |= STATION_INFO_TX_BITRATE;
1474
1475 return 0;
1476}
1477
1478static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1479 struct cfg80211_pmksa *pmksa)
1480{
1481 struct ath6kl *ar = ath6kl_priv(netdev);
1482 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1483 pmksa->pmkid, true);
1484}
1485
1486static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1487 struct cfg80211_pmksa *pmksa)
1488{
1489 struct ath6kl *ar = ath6kl_priv(netdev);
1490 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1491 pmksa->pmkid, false);
1492}
1493
1494static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1495{
1496 struct ath6kl *ar = ath6kl_priv(netdev);
1497 if (test_bit(CONNECTED, &ar->flag))
1498 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1499 return 0;
1500}
1501
Kalle Valoabcb3442011-07-22 08:26:20 +03001502#ifdef CONFIG_PM
1503static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1504 struct cfg80211_wowlan *wow)
1505{
1506 struct ath6kl *ar = wiphy_priv(wiphy);
1507
1508 return ath6kl_hif_suspend(ar);
1509}
1510#endif
1511
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001512static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1513 struct ieee80211_channel *chan,
1514 enum nl80211_channel_type channel_type)
1515{
1516 struct ath6kl *ar = ath6kl_priv(dev);
1517
1518 if (!ath6kl_cfg80211_ready(ar))
1519 return -EIO;
1520
1521 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1522 __func__, chan->center_freq, chan->hw_value);
1523 ar->next_chan = chan->center_freq;
1524
1525 return 0;
1526}
1527
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001528static bool ath6kl_is_p2p_ie(const u8 *pos)
1529{
1530 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1531 pos[2] == 0x50 && pos[3] == 0x6f &&
1532 pos[4] == 0x9a && pos[5] == 0x09;
1533}
1534
1535static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1536 size_t ies_len)
1537{
1538 const u8 *pos;
1539 u8 *buf = NULL;
1540 size_t len = 0;
1541 int ret;
1542
1543 /*
1544 * Filter out P2P IE(s) since they will be included depending on
1545 * the Probe Request frame in ath6kl_send_go_probe_resp().
1546 */
1547
1548 if (ies && ies_len) {
1549 buf = kmalloc(ies_len, GFP_KERNEL);
1550 if (buf == NULL)
1551 return -ENOMEM;
1552 pos = ies;
1553 while (pos + 1 < ies + ies_len) {
1554 if (pos + 2 + pos[1] > ies + ies_len)
1555 break;
1556 if (!ath6kl_is_p2p_ie(pos)) {
1557 memcpy(buf + len, pos, 2 + pos[1]);
1558 len += 2 + pos[1];
1559 }
1560 pos += 2 + pos[1];
1561 }
1562 }
1563
1564 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1565 buf, len);
1566 kfree(buf);
1567 return ret;
1568}
1569
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001570static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1571 struct beacon_parameters *info, bool add)
1572{
1573 struct ath6kl *ar = ath6kl_priv(dev);
1574 struct ieee80211_mgmt *mgmt;
1575 u8 *ies;
1576 int ies_len;
1577 struct wmi_connect_cmd p;
1578 int res;
1579 int i;
1580
1581 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1582
1583 if (!ath6kl_cfg80211_ready(ar))
1584 return -EIO;
1585
1586 if (ar->next_mode != AP_NETWORK)
1587 return -EOPNOTSUPP;
1588
1589 if (info->beacon_ies) {
1590 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1591 info->beacon_ies,
1592 info->beacon_ies_len);
1593 if (res)
1594 return res;
1595 }
1596 if (info->proberesp_ies) {
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001597 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1598 info->proberesp_ies_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001599 if (res)
1600 return res;
1601 }
1602 if (info->assocresp_ies) {
1603 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1604 info->assocresp_ies,
1605 info->assocresp_ies_len);
1606 if (res)
1607 return res;
1608 }
1609
1610 if (!add)
1611 return 0;
1612
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001613 ar->ap_mode_bkey.valid = false;
1614
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001615 /* TODO:
1616 * info->interval
1617 * info->dtim_period
1618 */
1619
1620 if (info->head == NULL)
1621 return -EINVAL;
1622 mgmt = (struct ieee80211_mgmt *) info->head;
1623 ies = mgmt->u.beacon.variable;
1624 if (ies > info->head + info->head_len)
1625 return -EINVAL;
1626 ies_len = info->head + info->head_len - ies;
1627
1628 if (info->ssid == NULL)
1629 return -EINVAL;
1630 memcpy(ar->ssid, info->ssid, info->ssid_len);
1631 ar->ssid_len = info->ssid_len;
1632 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1633 return -EOPNOTSUPP; /* TODO */
1634
1635 ar->dot11_auth_mode = OPEN_AUTH;
1636
1637 memset(&p, 0, sizeof(p));
1638
1639 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1640 switch (info->crypto.akm_suites[i]) {
1641 case WLAN_AKM_SUITE_8021X:
1642 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1643 p.auth_mode |= WPA_AUTH;
1644 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1645 p.auth_mode |= WPA2_AUTH;
1646 break;
1647 case WLAN_AKM_SUITE_PSK:
1648 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1649 p.auth_mode |= WPA_PSK_AUTH;
1650 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1651 p.auth_mode |= WPA2_PSK_AUTH;
1652 break;
1653 }
1654 }
1655 if (p.auth_mode == 0)
1656 p.auth_mode = NONE_AUTH;
1657 ar->auth_mode = p.auth_mode;
1658
1659 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1660 switch (info->crypto.ciphers_pairwise[i]) {
1661 case WLAN_CIPHER_SUITE_WEP40:
1662 case WLAN_CIPHER_SUITE_WEP104:
1663 p.prwise_crypto_type |= WEP_CRYPT;
1664 break;
1665 case WLAN_CIPHER_SUITE_TKIP:
1666 p.prwise_crypto_type |= TKIP_CRYPT;
1667 break;
1668 case WLAN_CIPHER_SUITE_CCMP:
1669 p.prwise_crypto_type |= AES_CRYPT;
1670 break;
1671 }
1672 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001673 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001674 p.prwise_crypto_type = NONE_CRYPT;
Edward Lu229ed6b2011-08-30 21:58:07 +03001675 ath6kl_set_cipher(ar, 0, true);
1676 } else if (info->crypto.n_ciphers_pairwise == 1)
1677 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001678
1679 switch (info->crypto.cipher_group) {
1680 case WLAN_CIPHER_SUITE_WEP40:
1681 case WLAN_CIPHER_SUITE_WEP104:
1682 p.grp_crypto_type = WEP_CRYPT;
1683 break;
1684 case WLAN_CIPHER_SUITE_TKIP:
1685 p.grp_crypto_type = TKIP_CRYPT;
1686 break;
1687 case WLAN_CIPHER_SUITE_CCMP:
1688 p.grp_crypto_type = AES_CRYPT;
1689 break;
1690 default:
1691 p.grp_crypto_type = NONE_CRYPT;
1692 break;
1693 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001694 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001695
1696 p.nw_type = AP_NETWORK;
1697 ar->nw_type = ar->next_mode;
1698
1699 p.ssid_len = ar->ssid_len;
1700 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1701 p.dot11_auth_mode = ar->dot11_auth_mode;
1702 p.ch = cpu_to_le16(ar->next_chan);
1703
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001704 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1705 if (res < 0)
1706 return res;
1707
1708 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001709}
1710
1711static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1712 struct beacon_parameters *info)
1713{
1714 return ath6kl_ap_beacon(wiphy, dev, info, true);
1715}
1716
1717static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1718 struct beacon_parameters *info)
1719{
1720 return ath6kl_ap_beacon(wiphy, dev, info, false);
1721}
1722
1723static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1724{
1725 struct ath6kl *ar = ath6kl_priv(dev);
1726
1727 if (ar->nw_type != AP_NETWORK)
1728 return -EOPNOTSUPP;
1729 if (!test_bit(CONNECTED, &ar->flag))
1730 return -ENOTCONN;
1731
1732 ath6kl_wmi_disconnect_cmd(ar->wmi);
1733 clear_bit(CONNECTED, &ar->flag);
1734
1735 return 0;
1736}
1737
Jouni Malinen23875132011-08-30 21:57:53 +03001738static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1739 u8 *mac, struct station_parameters *params)
1740{
1741 struct ath6kl *ar = ath6kl_priv(dev);
1742
1743 if (ar->nw_type != AP_NETWORK)
1744 return -EOPNOTSUPP;
1745
1746 /* Use this only for authorizing/unauthorizing a station */
1747 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1748 return -EOPNOTSUPP;
1749
1750 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1751 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1752 mac, 0);
1753 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1754 0);
1755}
1756
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001757static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1758 struct net_device *dev,
1759 struct ieee80211_channel *chan,
1760 enum nl80211_channel_type channel_type,
1761 unsigned int duration,
1762 u64 *cookie)
1763{
1764 struct ath6kl *ar = ath6kl_priv(dev);
1765
1766 /* TODO: if already pending or ongoing remain-on-channel,
1767 * return -EBUSY */
1768 *cookie = 1; /* only a single pending request is supported */
1769
1770 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1771 duration);
1772}
1773
1774static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1775 struct net_device *dev,
1776 u64 cookie)
1777{
1778 struct ath6kl *ar = ath6kl_priv(dev);
1779
1780 if (cookie != 1)
1781 return -ENOENT;
1782
1783 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1784}
1785
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001786static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1787 size_t len, unsigned int freq)
1788{
1789 const u8 *pos;
1790 u8 *p2p;
1791 int p2p_len;
1792 int ret;
1793 const struct ieee80211_mgmt *mgmt;
1794
1795 mgmt = (const struct ieee80211_mgmt *) buf;
1796
1797 /* Include P2P IE(s) from the frame generated in user space. */
1798
1799 p2p = kmalloc(len, GFP_KERNEL);
1800 if (p2p == NULL)
1801 return -ENOMEM;
1802 p2p_len = 0;
1803
1804 pos = mgmt->u.probe_resp.variable;
1805 while (pos + 1 < buf + len) {
1806 if (pos + 2 + pos[1] > buf + len)
1807 break;
1808 if (ath6kl_is_p2p_ie(pos)) {
1809 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1810 p2p_len += 2 + pos[1];
1811 }
1812 pos += 2 + pos[1];
1813 }
1814
1815 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1816 p2p, p2p_len);
1817 kfree(p2p);
1818 return ret;
1819}
1820
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001821static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1822 struct ieee80211_channel *chan, bool offchan,
1823 enum nl80211_channel_type channel_type,
1824 bool channel_type_valid, unsigned int wait,
1825 const u8 *buf, size_t len, u64 *cookie)
1826{
1827 struct ath6kl *ar = ath6kl_priv(dev);
1828 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001829 const struct ieee80211_mgmt *mgmt;
1830
1831 mgmt = (const struct ieee80211_mgmt *) buf;
1832 if (buf + len >= mgmt->u.probe_resp.variable &&
1833 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1834 ieee80211_is_probe_resp(mgmt->frame_control)) {
1835 /*
1836 * Send Probe Response frame in AP mode using a separate WMI
1837 * command to allow the target to fill in the generic IEs.
1838 */
1839 *cookie = 0; /* TX status not supported */
1840 return ath6kl_send_go_probe_resp(ar, buf, len,
1841 chan->center_freq);
1842 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001843
1844 id = ar->send_action_id++;
1845 if (id == 0) {
1846 /*
1847 * 0 is a reserved value in the WMI command and shall not be
1848 * used for the command.
1849 */
1850 id = ar->send_action_id++;
1851 }
1852
1853 *cookie = id;
1854 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1855 buf, len);
1856}
1857
Jouni Malinenae32c302011-08-30 21:58:01 +03001858static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1859 struct net_device *dev,
1860 u16 frame_type, bool reg)
1861{
1862 struct ath6kl *ar = ath6kl_priv(dev);
1863
1864 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1865 __func__, frame_type, reg);
1866 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1867 /*
1868 * Note: This notification callback is not allowed to sleep, so
1869 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1870 * hardcode target to report Probe Request frames all the time.
1871 */
1872 ar->probe_req_report = reg;
1873 }
1874}
1875
Jouni Malinenf80574a2011-08-30 21:58:04 +03001876static const struct ieee80211_txrx_stypes
1877ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1878 [NL80211_IFTYPE_STATION] = {
1879 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1880 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1881 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1882 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1883 },
1884 [NL80211_IFTYPE_P2P_CLIENT] = {
1885 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1886 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1887 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1888 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1889 },
1890 [NL80211_IFTYPE_P2P_GO] = {
1891 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1892 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1893 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1894 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1895 },
1896};
1897
Kalle Valobdcd8172011-07-18 00:22:30 +03001898static struct cfg80211_ops ath6kl_cfg80211_ops = {
1899 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1900 .scan = ath6kl_cfg80211_scan,
1901 .connect = ath6kl_cfg80211_connect,
1902 .disconnect = ath6kl_cfg80211_disconnect,
1903 .add_key = ath6kl_cfg80211_add_key,
1904 .get_key = ath6kl_cfg80211_get_key,
1905 .del_key = ath6kl_cfg80211_del_key,
1906 .set_default_key = ath6kl_cfg80211_set_default_key,
1907 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1908 .set_tx_power = ath6kl_cfg80211_set_txpower,
1909 .get_tx_power = ath6kl_cfg80211_get_txpower,
1910 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1911 .join_ibss = ath6kl_cfg80211_join_ibss,
1912 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1913 .get_station = ath6kl_get_station,
1914 .set_pmksa = ath6kl_set_pmksa,
1915 .del_pmksa = ath6kl_del_pmksa,
1916 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03001917 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03001918#ifdef CONFIG_PM
1919 .suspend = ar6k_cfg80211_suspend,
1920#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001921 .set_channel = ath6kl_set_channel,
1922 .add_beacon = ath6kl_add_beacon,
1923 .set_beacon = ath6kl_set_beacon,
1924 .del_beacon = ath6kl_del_beacon,
Jouni Malinen23875132011-08-30 21:57:53 +03001925 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001926 .remain_on_channel = ath6kl_remain_on_channel,
1927 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001928 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03001929 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valobdcd8172011-07-18 00:22:30 +03001930};
1931
1932struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1933{
1934 int ret = 0;
1935 struct wireless_dev *wdev;
1936
1937 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1938 if (!wdev) {
1939 ath6kl_err("couldn't allocate wireless device\n");
1940 return NULL;
1941 }
1942
1943 /* create a new wiphy for use with cfg80211 */
1944 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1945 if (!wdev->wiphy) {
1946 ath6kl_err("couldn't allocate wiphy device\n");
1947 kfree(wdev);
1948 return NULL;
1949 }
1950
Jouni Malinenf80574a2011-08-30 21:58:04 +03001951 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1952
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001953 wdev->wiphy->max_remain_on_channel_duration = 5000;
1954
Kalle Valobdcd8172011-07-18 00:22:30 +03001955 /* set device pointer for wiphy */
1956 set_wiphy_dev(wdev->wiphy, dev);
1957
1958 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1959 BIT(NL80211_IFTYPE_ADHOC);
1960 /* max num of ssids that can be probed during scanning */
1961 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
Jouni Malinenb84da8c2011-08-30 21:57:59 +03001962 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
Kalle Valobdcd8172011-07-18 00:22:30 +03001963 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1964 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1965 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1966
1967 wdev->wiphy->cipher_suites = cipher_suites;
1968 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1969
1970 ret = wiphy_register(wdev->wiphy);
1971 if (ret < 0) {
1972 ath6kl_err("couldn't register wiphy device\n");
1973 wiphy_free(wdev->wiphy);
1974 kfree(wdev);
1975 return NULL;
1976 }
1977
1978 return wdev;
1979}
1980
1981void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1982{
1983 struct wireless_dev *wdev = ar->wdev;
1984
1985 if (ar->scan_req) {
1986 cfg80211_scan_done(ar->scan_req, true);
1987 ar->scan_req = NULL;
1988 }
1989
1990 if (!wdev)
1991 return;
1992
1993 wiphy_unregister(wdev->wiphy);
1994 wiphy_free(wdev->wiphy);
1995 kfree(wdev);
1996}