blob: 640569688219952bcb8688f3bc52538da3e783d1 [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 Malinen6e4604c2011-09-05 17:38:46 +03001224 case NL80211_IFTYPE_AP:
1225 ar->next_mode = AP_NETWORK;
1226 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001227 case NL80211_IFTYPE_P2P_CLIENT:
1228 ar->next_mode = INFRA_NETWORK;
1229 break;
1230 case NL80211_IFTYPE_P2P_GO:
1231 ar->next_mode = AP_NETWORK;
1232 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001233 default:
1234 ath6kl_err("invalid interface type %u\n", type);
1235 return -EOPNOTSUPP;
1236 }
1237
1238 wdev->iftype = type;
1239
1240 return 0;
1241}
1242
1243static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1244 struct net_device *dev,
1245 struct cfg80211_ibss_params *ibss_param)
1246{
1247 struct ath6kl *ar = ath6kl_priv(dev);
1248 int status;
1249
1250 if (!ath6kl_cfg80211_ready(ar))
1251 return -EIO;
1252
1253 ar->ssid_len = ibss_param->ssid_len;
1254 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1255
1256 if (ibss_param->channel)
1257 ar->ch_hint = ibss_param->channel->center_freq;
1258
1259 if (ibss_param->channel_fixed) {
1260 /*
1261 * TODO: channel_fixed: The channel should be fixed, do not
1262 * search for IBSSs to join on other channels. Target
1263 * firmware does not support this feature, needs to be
1264 * updated.
1265 */
1266 return -EOPNOTSUPP;
1267 }
1268
1269 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1270 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1271 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1272
1273 ath6kl_set_wpa_version(ar, 0);
1274
1275 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1276 if (status)
1277 return status;
1278
1279 if (ibss_param->privacy) {
1280 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1281 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1282 } else {
1283 ath6kl_set_cipher(ar, 0, true);
1284 ath6kl_set_cipher(ar, 0, false);
1285 }
1286
1287 ar->nw_type = ar->next_mode;
1288
1289 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1290 "%s: connect called with authmode %d dot11 auth %d"
1291 " PW crypto %d PW crypto len %d GRP crypto %d"
1292 " GRP crypto len %d channel hint %u\n",
1293 __func__,
1294 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1295 ar->prwise_crypto_len, ar->grp_crypto,
Edward Lu38acde32011-08-30 21:58:06 +03001296 ar->grp_crypto_len, ar->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001297
1298 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1299 ar->dot11_auth_mode, ar->auth_mode,
1300 ar->prwise_crypto,
1301 ar->prwise_crypto_len,
Edward Lu38acde32011-08-30 21:58:06 +03001302 ar->grp_crypto, ar->grp_crypto_len,
Kalle Valobdcd8172011-07-18 00:22:30 +03001303 ar->ssid_len, ar->ssid,
1304 ar->req_bssid, ar->ch_hint,
1305 ar->connect_ctrl_flags);
1306 set_bit(CONNECT_PEND, &ar->flag);
1307
1308 return 0;
1309}
1310
1311static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1312 struct net_device *dev)
1313{
1314 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1315
1316 if (!ath6kl_cfg80211_ready(ar))
1317 return -EIO;
1318
1319 ath6kl_disconnect(ar);
1320 memset(ar->ssid, 0, sizeof(ar->ssid));
1321 ar->ssid_len = 0;
1322
1323 return 0;
1324}
1325
1326static const u32 cipher_suites[] = {
1327 WLAN_CIPHER_SUITE_WEP40,
1328 WLAN_CIPHER_SUITE_WEP104,
1329 WLAN_CIPHER_SUITE_TKIP,
1330 WLAN_CIPHER_SUITE_CCMP,
1331};
1332
1333static bool is_rate_legacy(s32 rate)
1334{
1335 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1336 6000, 9000, 12000, 18000, 24000,
1337 36000, 48000, 54000
1338 };
1339 u8 i;
1340
1341 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1342 if (rate == legacy[i])
1343 return true;
1344
1345 return false;
1346}
1347
1348static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1349{
1350 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1351 52000, 58500, 65000, 72200
1352 };
1353 u8 i;
1354
1355 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1356 if (rate == ht20[i]) {
1357 if (i == ARRAY_SIZE(ht20) - 1)
1358 /* last rate uses sgi */
1359 *sgi = true;
1360 else
1361 *sgi = false;
1362
1363 *mcs = i;
1364 return true;
1365 }
1366 }
1367 return false;
1368}
1369
1370static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1371{
1372 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1373 81000, 108000, 121500, 135000,
1374 150000
1375 };
1376 u8 i;
1377
1378 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1379 if (rate == ht40[i]) {
1380 if (i == ARRAY_SIZE(ht40) - 1)
1381 /* last rate uses sgi */
1382 *sgi = true;
1383 else
1384 *sgi = false;
1385
1386 *mcs = i;
1387 return true;
1388 }
1389 }
1390
1391 return false;
1392}
1393
1394static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1395 u8 *mac, struct station_info *sinfo)
1396{
1397 struct ath6kl *ar = ath6kl_priv(dev);
1398 long left;
1399 bool sgi;
1400 s32 rate;
1401 int ret;
1402 u8 mcs;
1403
1404 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1405 return -ENOENT;
1406
1407 if (down_interruptible(&ar->sem))
1408 return -EBUSY;
1409
1410 set_bit(STATS_UPDATE_PEND, &ar->flag);
1411
1412 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1413
1414 if (ret != 0) {
1415 up(&ar->sem);
1416 return -EIO;
1417 }
1418
1419 left = wait_event_interruptible_timeout(ar->event_wq,
1420 !test_bit(STATS_UPDATE_PEND,
1421 &ar->flag),
1422 WMI_TIMEOUT);
1423
1424 up(&ar->sem);
1425
1426 if (left == 0)
1427 return -ETIMEDOUT;
1428 else if (left < 0)
1429 return left;
1430
1431 if (ar->target_stats.rx_byte) {
1432 sinfo->rx_bytes = ar->target_stats.rx_byte;
1433 sinfo->filled |= STATION_INFO_RX_BYTES;
1434 sinfo->rx_packets = ar->target_stats.rx_pkt;
1435 sinfo->filled |= STATION_INFO_RX_PACKETS;
1436 }
1437
1438 if (ar->target_stats.tx_byte) {
1439 sinfo->tx_bytes = ar->target_stats.tx_byte;
1440 sinfo->filled |= STATION_INFO_TX_BYTES;
1441 sinfo->tx_packets = ar->target_stats.tx_pkt;
1442 sinfo->filled |= STATION_INFO_TX_PACKETS;
1443 }
1444
1445 sinfo->signal = ar->target_stats.cs_rssi;
1446 sinfo->filled |= STATION_INFO_SIGNAL;
1447
1448 rate = ar->target_stats.tx_ucast_rate;
1449
1450 if (is_rate_legacy(rate)) {
1451 sinfo->txrate.legacy = rate / 100;
1452 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1453 if (sgi) {
1454 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1455 sinfo->txrate.mcs = mcs - 1;
1456 } else {
1457 sinfo->txrate.mcs = mcs;
1458 }
1459
1460 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1461 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1462 if (sgi) {
1463 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1464 sinfo->txrate.mcs = mcs - 1;
1465 } else {
1466 sinfo->txrate.mcs = mcs;
1467 }
1468
1469 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1470 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1471 } else {
1472 ath6kl_warn("invalid rate: %d\n", rate);
1473 return 0;
1474 }
1475
1476 sinfo->filled |= STATION_INFO_TX_BITRATE;
1477
1478 return 0;
1479}
1480
1481static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1482 struct cfg80211_pmksa *pmksa)
1483{
1484 struct ath6kl *ar = ath6kl_priv(netdev);
1485 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1486 pmksa->pmkid, true);
1487}
1488
1489static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1490 struct cfg80211_pmksa *pmksa)
1491{
1492 struct ath6kl *ar = ath6kl_priv(netdev);
1493 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1494 pmksa->pmkid, false);
1495}
1496
1497static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1498{
1499 struct ath6kl *ar = ath6kl_priv(netdev);
1500 if (test_bit(CONNECTED, &ar->flag))
1501 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1502 return 0;
1503}
1504
Kalle Valoabcb3442011-07-22 08:26:20 +03001505#ifdef CONFIG_PM
1506static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1507 struct cfg80211_wowlan *wow)
1508{
1509 struct ath6kl *ar = wiphy_priv(wiphy);
1510
1511 return ath6kl_hif_suspend(ar);
1512}
1513#endif
1514
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001515static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1516 struct ieee80211_channel *chan,
1517 enum nl80211_channel_type channel_type)
1518{
1519 struct ath6kl *ar = ath6kl_priv(dev);
1520
1521 if (!ath6kl_cfg80211_ready(ar))
1522 return -EIO;
1523
1524 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1525 __func__, chan->center_freq, chan->hw_value);
1526 ar->next_chan = chan->center_freq;
1527
1528 return 0;
1529}
1530
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001531static bool ath6kl_is_p2p_ie(const u8 *pos)
1532{
1533 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1534 pos[2] == 0x50 && pos[3] == 0x6f &&
1535 pos[4] == 0x9a && pos[5] == 0x09;
1536}
1537
1538static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1539 size_t ies_len)
1540{
1541 const u8 *pos;
1542 u8 *buf = NULL;
1543 size_t len = 0;
1544 int ret;
1545
1546 /*
1547 * Filter out P2P IE(s) since they will be included depending on
1548 * the Probe Request frame in ath6kl_send_go_probe_resp().
1549 */
1550
1551 if (ies && ies_len) {
1552 buf = kmalloc(ies_len, GFP_KERNEL);
1553 if (buf == NULL)
1554 return -ENOMEM;
1555 pos = ies;
1556 while (pos + 1 < ies + ies_len) {
1557 if (pos + 2 + pos[1] > ies + ies_len)
1558 break;
1559 if (!ath6kl_is_p2p_ie(pos)) {
1560 memcpy(buf + len, pos, 2 + pos[1]);
1561 len += 2 + pos[1];
1562 }
1563 pos += 2 + pos[1];
1564 }
1565 }
1566
1567 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1568 buf, len);
1569 kfree(buf);
1570 return ret;
1571}
1572
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001573static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1574 struct beacon_parameters *info, bool add)
1575{
1576 struct ath6kl *ar = ath6kl_priv(dev);
1577 struct ieee80211_mgmt *mgmt;
1578 u8 *ies;
1579 int ies_len;
1580 struct wmi_connect_cmd p;
1581 int res;
1582 int i;
1583
1584 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1585
1586 if (!ath6kl_cfg80211_ready(ar))
1587 return -EIO;
1588
1589 if (ar->next_mode != AP_NETWORK)
1590 return -EOPNOTSUPP;
1591
1592 if (info->beacon_ies) {
1593 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1594 info->beacon_ies,
1595 info->beacon_ies_len);
1596 if (res)
1597 return res;
1598 }
1599 if (info->proberesp_ies) {
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001600 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1601 info->proberesp_ies_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001602 if (res)
1603 return res;
1604 }
1605 if (info->assocresp_ies) {
1606 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1607 info->assocresp_ies,
1608 info->assocresp_ies_len);
1609 if (res)
1610 return res;
1611 }
1612
1613 if (!add)
1614 return 0;
1615
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001616 ar->ap_mode_bkey.valid = false;
1617
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001618 /* TODO:
1619 * info->interval
1620 * info->dtim_period
1621 */
1622
1623 if (info->head == NULL)
1624 return -EINVAL;
1625 mgmt = (struct ieee80211_mgmt *) info->head;
1626 ies = mgmt->u.beacon.variable;
1627 if (ies > info->head + info->head_len)
1628 return -EINVAL;
1629 ies_len = info->head + info->head_len - ies;
1630
1631 if (info->ssid == NULL)
1632 return -EINVAL;
1633 memcpy(ar->ssid, info->ssid, info->ssid_len);
1634 ar->ssid_len = info->ssid_len;
1635 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1636 return -EOPNOTSUPP; /* TODO */
1637
1638 ar->dot11_auth_mode = OPEN_AUTH;
1639
1640 memset(&p, 0, sizeof(p));
1641
1642 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1643 switch (info->crypto.akm_suites[i]) {
1644 case WLAN_AKM_SUITE_8021X:
1645 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1646 p.auth_mode |= WPA_AUTH;
1647 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1648 p.auth_mode |= WPA2_AUTH;
1649 break;
1650 case WLAN_AKM_SUITE_PSK:
1651 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1652 p.auth_mode |= WPA_PSK_AUTH;
1653 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1654 p.auth_mode |= WPA2_PSK_AUTH;
1655 break;
1656 }
1657 }
1658 if (p.auth_mode == 0)
1659 p.auth_mode = NONE_AUTH;
1660 ar->auth_mode = p.auth_mode;
1661
1662 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1663 switch (info->crypto.ciphers_pairwise[i]) {
1664 case WLAN_CIPHER_SUITE_WEP40:
1665 case WLAN_CIPHER_SUITE_WEP104:
1666 p.prwise_crypto_type |= WEP_CRYPT;
1667 break;
1668 case WLAN_CIPHER_SUITE_TKIP:
1669 p.prwise_crypto_type |= TKIP_CRYPT;
1670 break;
1671 case WLAN_CIPHER_SUITE_CCMP:
1672 p.prwise_crypto_type |= AES_CRYPT;
1673 break;
1674 }
1675 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001676 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001677 p.prwise_crypto_type = NONE_CRYPT;
Edward Lu229ed6b2011-08-30 21:58:07 +03001678 ath6kl_set_cipher(ar, 0, true);
1679 } else if (info->crypto.n_ciphers_pairwise == 1)
1680 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001681
1682 switch (info->crypto.cipher_group) {
1683 case WLAN_CIPHER_SUITE_WEP40:
1684 case WLAN_CIPHER_SUITE_WEP104:
1685 p.grp_crypto_type = WEP_CRYPT;
1686 break;
1687 case WLAN_CIPHER_SUITE_TKIP:
1688 p.grp_crypto_type = TKIP_CRYPT;
1689 break;
1690 case WLAN_CIPHER_SUITE_CCMP:
1691 p.grp_crypto_type = AES_CRYPT;
1692 break;
1693 default:
1694 p.grp_crypto_type = NONE_CRYPT;
1695 break;
1696 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001697 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001698
1699 p.nw_type = AP_NETWORK;
1700 ar->nw_type = ar->next_mode;
1701
1702 p.ssid_len = ar->ssid_len;
1703 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1704 p.dot11_auth_mode = ar->dot11_auth_mode;
1705 p.ch = cpu_to_le16(ar->next_chan);
1706
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001707 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1708 if (res < 0)
1709 return res;
1710
1711 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001712}
1713
1714static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1715 struct beacon_parameters *info)
1716{
1717 return ath6kl_ap_beacon(wiphy, dev, info, true);
1718}
1719
1720static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1721 struct beacon_parameters *info)
1722{
1723 return ath6kl_ap_beacon(wiphy, dev, info, false);
1724}
1725
1726static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1727{
1728 struct ath6kl *ar = ath6kl_priv(dev);
1729
1730 if (ar->nw_type != AP_NETWORK)
1731 return -EOPNOTSUPP;
1732 if (!test_bit(CONNECTED, &ar->flag))
1733 return -ENOTCONN;
1734
1735 ath6kl_wmi_disconnect_cmd(ar->wmi);
1736 clear_bit(CONNECTED, &ar->flag);
1737
1738 return 0;
1739}
1740
Jouni Malinen23875132011-08-30 21:57:53 +03001741static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1742 u8 *mac, struct station_parameters *params)
1743{
1744 struct ath6kl *ar = ath6kl_priv(dev);
1745
1746 if (ar->nw_type != AP_NETWORK)
1747 return -EOPNOTSUPP;
1748
1749 /* Use this only for authorizing/unauthorizing a station */
1750 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1751 return -EOPNOTSUPP;
1752
1753 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1754 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1755 mac, 0);
1756 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1757 0);
1758}
1759
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001760static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1761 struct net_device *dev,
1762 struct ieee80211_channel *chan,
1763 enum nl80211_channel_type channel_type,
1764 unsigned int duration,
1765 u64 *cookie)
1766{
1767 struct ath6kl *ar = ath6kl_priv(dev);
1768
1769 /* TODO: if already pending or ongoing remain-on-channel,
1770 * return -EBUSY */
1771 *cookie = 1; /* only a single pending request is supported */
1772
1773 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1774 duration);
1775}
1776
1777static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1778 struct net_device *dev,
1779 u64 cookie)
1780{
1781 struct ath6kl *ar = ath6kl_priv(dev);
1782
1783 if (cookie != 1)
1784 return -ENOENT;
1785
1786 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1787}
1788
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001789static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1790 size_t len, unsigned int freq)
1791{
1792 const u8 *pos;
1793 u8 *p2p;
1794 int p2p_len;
1795 int ret;
1796 const struct ieee80211_mgmt *mgmt;
1797
1798 mgmt = (const struct ieee80211_mgmt *) buf;
1799
1800 /* Include P2P IE(s) from the frame generated in user space. */
1801
1802 p2p = kmalloc(len, GFP_KERNEL);
1803 if (p2p == NULL)
1804 return -ENOMEM;
1805 p2p_len = 0;
1806
1807 pos = mgmt->u.probe_resp.variable;
1808 while (pos + 1 < buf + len) {
1809 if (pos + 2 + pos[1] > buf + len)
1810 break;
1811 if (ath6kl_is_p2p_ie(pos)) {
1812 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1813 p2p_len += 2 + pos[1];
1814 }
1815 pos += 2 + pos[1];
1816 }
1817
1818 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1819 p2p, p2p_len);
1820 kfree(p2p);
1821 return ret;
1822}
1823
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001824static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1825 struct ieee80211_channel *chan, bool offchan,
1826 enum nl80211_channel_type channel_type,
1827 bool channel_type_valid, unsigned int wait,
1828 const u8 *buf, size_t len, u64 *cookie)
1829{
1830 struct ath6kl *ar = ath6kl_priv(dev);
1831 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001832 const struct ieee80211_mgmt *mgmt;
1833
1834 mgmt = (const struct ieee80211_mgmt *) buf;
1835 if (buf + len >= mgmt->u.probe_resp.variable &&
1836 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1837 ieee80211_is_probe_resp(mgmt->frame_control)) {
1838 /*
1839 * Send Probe Response frame in AP mode using a separate WMI
1840 * command to allow the target to fill in the generic IEs.
1841 */
1842 *cookie = 0; /* TX status not supported */
1843 return ath6kl_send_go_probe_resp(ar, buf, len,
1844 chan->center_freq);
1845 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001846
1847 id = ar->send_action_id++;
1848 if (id == 0) {
1849 /*
1850 * 0 is a reserved value in the WMI command and shall not be
1851 * used for the command.
1852 */
1853 id = ar->send_action_id++;
1854 }
1855
1856 *cookie = id;
1857 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1858 buf, len);
1859}
1860
Jouni Malinenae32c302011-08-30 21:58:01 +03001861static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1862 struct net_device *dev,
1863 u16 frame_type, bool reg)
1864{
1865 struct ath6kl *ar = ath6kl_priv(dev);
1866
1867 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1868 __func__, frame_type, reg);
1869 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1870 /*
1871 * Note: This notification callback is not allowed to sleep, so
1872 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1873 * hardcode target to report Probe Request frames all the time.
1874 */
1875 ar->probe_req_report = reg;
1876 }
1877}
1878
Jouni Malinenf80574a2011-08-30 21:58:04 +03001879static const struct ieee80211_txrx_stypes
1880ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1881 [NL80211_IFTYPE_STATION] = {
1882 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1883 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1884 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1885 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1886 },
1887 [NL80211_IFTYPE_P2P_CLIENT] = {
1888 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1889 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1890 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1891 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1892 },
1893 [NL80211_IFTYPE_P2P_GO] = {
1894 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1895 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1896 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1897 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1898 },
1899};
1900
Kalle Valobdcd8172011-07-18 00:22:30 +03001901static struct cfg80211_ops ath6kl_cfg80211_ops = {
1902 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1903 .scan = ath6kl_cfg80211_scan,
1904 .connect = ath6kl_cfg80211_connect,
1905 .disconnect = ath6kl_cfg80211_disconnect,
1906 .add_key = ath6kl_cfg80211_add_key,
1907 .get_key = ath6kl_cfg80211_get_key,
1908 .del_key = ath6kl_cfg80211_del_key,
1909 .set_default_key = ath6kl_cfg80211_set_default_key,
1910 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1911 .set_tx_power = ath6kl_cfg80211_set_txpower,
1912 .get_tx_power = ath6kl_cfg80211_get_txpower,
1913 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1914 .join_ibss = ath6kl_cfg80211_join_ibss,
1915 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1916 .get_station = ath6kl_get_station,
1917 .set_pmksa = ath6kl_set_pmksa,
1918 .del_pmksa = ath6kl_del_pmksa,
1919 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03001920 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03001921#ifdef CONFIG_PM
1922 .suspend = ar6k_cfg80211_suspend,
1923#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001924 .set_channel = ath6kl_set_channel,
1925 .add_beacon = ath6kl_add_beacon,
1926 .set_beacon = ath6kl_set_beacon,
1927 .del_beacon = ath6kl_del_beacon,
Jouni Malinen23875132011-08-30 21:57:53 +03001928 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001929 .remain_on_channel = ath6kl_remain_on_channel,
1930 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001931 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03001932 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valobdcd8172011-07-18 00:22:30 +03001933};
1934
1935struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1936{
1937 int ret = 0;
1938 struct wireless_dev *wdev;
1939
1940 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1941 if (!wdev) {
1942 ath6kl_err("couldn't allocate wireless device\n");
1943 return NULL;
1944 }
1945
1946 /* create a new wiphy for use with cfg80211 */
1947 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1948 if (!wdev->wiphy) {
1949 ath6kl_err("couldn't allocate wiphy device\n");
1950 kfree(wdev);
1951 return NULL;
1952 }
1953
Jouni Malinenf80574a2011-08-30 21:58:04 +03001954 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1955
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001956 wdev->wiphy->max_remain_on_channel_duration = 5000;
1957
Kalle Valobdcd8172011-07-18 00:22:30 +03001958 /* set device pointer for wiphy */
1959 set_wiphy_dev(wdev->wiphy, dev);
1960
1961 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001962 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
Kalle Valobdcd8172011-07-18 00:22:30 +03001963 /* max num of ssids that can be probed during scanning */
1964 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
Jouni Malinenb84da8c2011-08-30 21:57:59 +03001965 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
Kalle Valobdcd8172011-07-18 00:22:30 +03001966 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1967 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1968 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1969
1970 wdev->wiphy->cipher_suites = cipher_suites;
1971 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1972
1973 ret = wiphy_register(wdev->wiphy);
1974 if (ret < 0) {
1975 ath6kl_err("couldn't register wiphy device\n");
1976 wiphy_free(wdev->wiphy);
1977 kfree(wdev);
1978 return NULL;
1979 }
1980
1981 return wdev;
1982}
1983
1984void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1985{
1986 struct wireless_dev *wdev = ar->wdev;
1987
1988 if (ar->scan_req) {
1989 cfg80211_scan_done(ar->scan_req, true);
1990 ar->scan_req = NULL;
1991 }
1992
1993 if (!wdev)
1994 return;
1995
1996 wiphy_unregister(wdev->wiphy);
1997 wiphy_free(wdev->wiphy);
1998 kfree(wdev);
1999}