blob: 7db66589ee0c8dc6e2d53223819f59ceaf088388 [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
Edward Lu1276c9e2011-08-30 21:58:00 +0300796 if (request->n_channels > 0) {
797 u8 i;
798
799 n_channels = min(127U, request->n_channels);
800
801 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
802 if (channels == NULL) {
803 ath6kl_warn("failed to set scan channels, "
804 "scan all channels");
805 n_channels = 0;
806 }
807
808 for (i = 0; i < n_channels; i++)
809 channels[i] = request->channels[i]->center_freq;
810 }
811
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300812 ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
813 false, 0, 0, n_channels, channels);
814 if (ret)
Kalle Valobdcd8172011-07-18 00:22:30 +0300815 ath6kl_err("wmi_startscan_cmd failed\n");
Kalle Valobdcd8172011-07-18 00:22:30 +0300816
817 ar->scan_req = request;
818
Edward Lu1276c9e2011-08-30 21:58:00 +0300819 kfree(channels);
820
Kalle Valobdcd8172011-07-18 00:22:30 +0300821 return ret;
822}
823
824void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
825{
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300826 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300827
828 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
829
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300830 if (!ar->scan_req)
831 return;
Kalle Valobdcd8172011-07-18 00:22:30 +0300832
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300833 if ((status == -ECANCELED) || (status == -EBUSY)) {
834 cfg80211_scan_done(ar->scan_req, true);
835 goto out;
Kalle Valobdcd8172011-07-18 00:22:30 +0300836 }
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300837
838 /* Translate data to cfg80211 mgmt format */
Vasanthakumar Thiagarajan8a8bc5a2011-07-21 14:42:52 +0530839 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300840
841 cfg80211_scan_done(ar->scan_req, false);
842
843 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
844 for (i = 0; i < ar->scan_req->n_ssids; i++) {
845 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
846 DISABLE_SSID_FLAG,
847 0, NULL);
848 }
849 }
850
851out:
852 ar->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300853}
854
855static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
856 u8 key_index, bool pairwise,
857 const u8 *mac_addr,
858 struct key_params *params)
859{
860 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
861 struct ath6kl_key *key = NULL;
862 u8 key_usage;
863 u8 key_type;
864 int status = 0;
865
866 if (!ath6kl_cfg80211_ready(ar))
867 return -EIO;
868
869 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
870 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
871 "%s: key index %d out of bounds\n", __func__,
872 key_index);
873 return -ENOENT;
874 }
875
876 key = &ar->keys[key_index];
877 memset(key, 0, sizeof(struct ath6kl_key));
878
879 if (pairwise)
880 key_usage = PAIRWISE_USAGE;
881 else
882 key_usage = GROUP_USAGE;
883
884 if (params) {
885 if (params->key_len > WLAN_MAX_KEY_LEN ||
886 params->seq_len > sizeof(key->seq))
887 return -EINVAL;
888
889 key->key_len = params->key_len;
890 memcpy(key->key, params->key, key->key_len);
891 key->seq_len = params->seq_len;
892 memcpy(key->seq, params->seq, key->seq_len);
893 key->cipher = params->cipher;
894 }
895
896 switch (key->cipher) {
897 case WLAN_CIPHER_SUITE_WEP40:
898 case WLAN_CIPHER_SUITE_WEP104:
899 key_type = WEP_CRYPT;
900 break;
901
902 case WLAN_CIPHER_SUITE_TKIP:
903 key_type = TKIP_CRYPT;
904 break;
905
906 case WLAN_CIPHER_SUITE_CCMP:
907 key_type = AES_CRYPT;
908 break;
909
910 default:
911 return -ENOTSUPP;
912 }
913
914 if (((ar->auth_mode == WPA_PSK_AUTH)
915 || (ar->auth_mode == WPA2_PSK_AUTH))
916 && (key_usage & GROUP_USAGE))
917 del_timer(&ar->disconnect_timer);
918
919 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
920 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
921 __func__, key_index, key->key_len, key_type,
922 key_usage, key->seq_len);
923
924 ar->def_txkey_index = key_index;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300925
926 if (ar->nw_type == AP_NETWORK && !pairwise &&
927 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
928 ar->ap_mode_bkey.valid = true;
929 ar->ap_mode_bkey.key_index = key_index;
930 ar->ap_mode_bkey.key_type = key_type;
931 ar->ap_mode_bkey.key_len = key->key_len;
932 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
933 if (!test_bit(CONNECTED, &ar->flag)) {
934 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
935 "key configuration until AP mode has been "
936 "started\n");
937 /*
938 * The key will be set in ath6kl_connect_ap_mode() once
939 * the connected event is received from the target.
940 */
941 return 0;
942 }
943 }
944
Kalle Valobdcd8172011-07-18 00:22:30 +0300945 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
946 key_type, key_usage, key->key_len,
947 key->seq, key->key, KEY_OP_INIT_VAL,
948 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
949
950 if (status)
951 return -EIO;
952
953 return 0;
954}
955
956static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
957 u8 key_index, bool pairwise,
958 const u8 *mac_addr)
959{
960 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
961
962 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
963
964 if (!ath6kl_cfg80211_ready(ar))
965 return -EIO;
966
967 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
968 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
969 "%s: key index %d out of bounds\n", __func__,
970 key_index);
971 return -ENOENT;
972 }
973
974 if (!ar->keys[key_index].key_len) {
975 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
976 "%s: index %d is empty\n", __func__, key_index);
977 return 0;
978 }
979
980 ar->keys[key_index].key_len = 0;
981
982 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
983}
984
985static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
986 u8 key_index, bool pairwise,
987 const u8 *mac_addr, void *cookie,
988 void (*callback) (void *cookie,
989 struct key_params *))
990{
991 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
992 struct ath6kl_key *key = NULL;
993 struct key_params params;
994
995 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
996
997 if (!ath6kl_cfg80211_ready(ar))
998 return -EIO;
999
1000 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1001 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1002 "%s: key index %d out of bounds\n", __func__,
1003 key_index);
1004 return -ENOENT;
1005 }
1006
1007 key = &ar->keys[key_index];
1008 memset(&params, 0, sizeof(params));
1009 params.cipher = key->cipher;
1010 params.key_len = key->key_len;
1011 params.seq_len = key->seq_len;
1012 params.seq = key->seq;
1013 params.key = key->key;
1014
1015 callback(cookie, &params);
1016
1017 return key->key_len ? 0 : -ENOENT;
1018}
1019
1020static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1021 struct net_device *ndev,
1022 u8 key_index, bool unicast,
1023 bool multicast)
1024{
1025 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1026 struct ath6kl_key *key = NULL;
1027 int status = 0;
1028 u8 key_usage;
Edward Lu229ed6b2011-08-30 21:58:07 +03001029 enum crypto_type key_type = NONE_CRYPT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001030
1031 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1032
1033 if (!ath6kl_cfg80211_ready(ar))
1034 return -EIO;
1035
1036 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1037 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1038 "%s: key index %d out of bounds\n",
1039 __func__, key_index);
1040 return -ENOENT;
1041 }
1042
1043 if (!ar->keys[key_index].key_len) {
1044 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1045 __func__, key_index);
1046 return -EINVAL;
1047 }
1048
1049 ar->def_txkey_index = key_index;
1050 key = &ar->keys[ar->def_txkey_index];
1051 key_usage = GROUP_USAGE;
1052 if (ar->prwise_crypto == WEP_CRYPT)
1053 key_usage |= TX_USAGE;
Edward Lu229ed6b2011-08-30 21:58:07 +03001054 if (unicast)
1055 key_type = ar->prwise_crypto;
1056 if (multicast)
1057 key_type = ar->grp_crypto;
Kalle Valobdcd8172011-07-18 00:22:30 +03001058
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001059 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1060 return 0; /* Delay until AP mode has been started */
1061
Kalle Valobdcd8172011-07-18 00:22:30 +03001062 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
Edward Lu229ed6b2011-08-30 21:58:07 +03001063 key_type, key_usage,
Kalle Valobdcd8172011-07-18 00:22:30 +03001064 key->key_len, key->seq, key->key,
1065 KEY_OP_INIT_VAL, NULL,
1066 SYNC_BOTH_WMIFLAG);
1067 if (status)
1068 return -EIO;
1069
1070 return 0;
1071}
1072
1073void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1074 bool ismcast)
1075{
1076 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1077 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1078
1079 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1080 (ismcast ? NL80211_KEYTYPE_GROUP :
1081 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1082 GFP_KERNEL);
1083}
1084
1085static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1086{
1087 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1088 int ret;
1089
1090 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1091 changed);
1092
1093 if (!ath6kl_cfg80211_ready(ar))
1094 return -EIO;
1095
1096 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1097 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1098 if (ret != 0) {
1099 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1100 return -EIO;
1101 }
1102 }
1103
1104 return 0;
1105}
1106
1107/*
1108 * The type nl80211_tx_power_setting replaces the following
1109 * data type from 2.6.36 onwards
1110*/
1111static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1112 enum nl80211_tx_power_setting type,
1113 int dbm)
1114{
1115 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1116 u8 ath6kl_dbm;
1117
1118 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1119 type, dbm);
1120
1121 if (!ath6kl_cfg80211_ready(ar))
1122 return -EIO;
1123
1124 switch (type) {
1125 case NL80211_TX_POWER_AUTOMATIC:
1126 return 0;
1127 case NL80211_TX_POWER_LIMITED:
1128 ar->tx_pwr = ath6kl_dbm = dbm;
1129 break;
1130 default:
1131 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1132 __func__, type);
1133 return -EOPNOTSUPP;
1134 }
1135
1136 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1137
1138 return 0;
1139}
1140
1141static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1142{
1143 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1144
1145 if (!ath6kl_cfg80211_ready(ar))
1146 return -EIO;
1147
1148 if (test_bit(CONNECTED, &ar->flag)) {
1149 ar->tx_pwr = 0;
1150
1151 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1152 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1153 return -EIO;
1154 }
1155
1156 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1157 5 * HZ);
1158
1159 if (signal_pending(current)) {
1160 ath6kl_err("target did not respond\n");
1161 return -EINTR;
1162 }
1163 }
1164
1165 *dbm = ar->tx_pwr;
1166 return 0;
1167}
1168
1169static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1170 struct net_device *dev,
1171 bool pmgmt, int timeout)
1172{
1173 struct ath6kl *ar = ath6kl_priv(dev);
1174 struct wmi_power_mode_cmd mode;
1175
1176 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1177 __func__, pmgmt, timeout);
1178
1179 if (!ath6kl_cfg80211_ready(ar))
1180 return -EIO;
1181
1182 if (pmgmt) {
1183 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1184 mode.pwr_mode = REC_POWER;
1185 } else {
1186 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1187 mode.pwr_mode = MAX_PERF_POWER;
1188 }
1189
1190 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1191 ath6kl_err("wmi_powermode_cmd failed\n");
1192 return -EIO;
1193 }
1194
1195 return 0;
1196}
1197
1198static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1199 struct net_device *ndev,
1200 enum nl80211_iftype type, u32 *flags,
1201 struct vif_params *params)
1202{
1203 struct ath6kl *ar = ath6kl_priv(ndev);
1204 struct wireless_dev *wdev = ar->wdev;
1205
1206 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1207
1208 if (!ath6kl_cfg80211_ready(ar))
1209 return -EIO;
1210
1211 switch (type) {
1212 case NL80211_IFTYPE_STATION:
1213 ar->next_mode = INFRA_NETWORK;
1214 break;
1215 case NL80211_IFTYPE_ADHOC:
1216 ar->next_mode = ADHOC_NETWORK;
1217 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001218 case NL80211_IFTYPE_P2P_CLIENT:
1219 ar->next_mode = INFRA_NETWORK;
1220 break;
1221 case NL80211_IFTYPE_P2P_GO:
1222 ar->next_mode = AP_NETWORK;
1223 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001224 default:
1225 ath6kl_err("invalid interface type %u\n", type);
1226 return -EOPNOTSUPP;
1227 }
1228
1229 wdev->iftype = type;
1230
1231 return 0;
1232}
1233
1234static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1235 struct net_device *dev,
1236 struct cfg80211_ibss_params *ibss_param)
1237{
1238 struct ath6kl *ar = ath6kl_priv(dev);
1239 int status;
1240
1241 if (!ath6kl_cfg80211_ready(ar))
1242 return -EIO;
1243
1244 ar->ssid_len = ibss_param->ssid_len;
1245 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1246
1247 if (ibss_param->channel)
1248 ar->ch_hint = ibss_param->channel->center_freq;
1249
1250 if (ibss_param->channel_fixed) {
1251 /*
1252 * TODO: channel_fixed: The channel should be fixed, do not
1253 * search for IBSSs to join on other channels. Target
1254 * firmware does not support this feature, needs to be
1255 * updated.
1256 */
1257 return -EOPNOTSUPP;
1258 }
1259
1260 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1261 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1262 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1263
1264 ath6kl_set_wpa_version(ar, 0);
1265
1266 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1267 if (status)
1268 return status;
1269
1270 if (ibss_param->privacy) {
1271 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1272 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1273 } else {
1274 ath6kl_set_cipher(ar, 0, true);
1275 ath6kl_set_cipher(ar, 0, false);
1276 }
1277
1278 ar->nw_type = ar->next_mode;
1279
1280 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1281 "%s: connect called with authmode %d dot11 auth %d"
1282 " PW crypto %d PW crypto len %d GRP crypto %d"
1283 " GRP crypto len %d channel hint %u\n",
1284 __func__,
1285 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1286 ar->prwise_crypto_len, ar->grp_crypto,
Edward Lu38acde32011-08-30 21:58:06 +03001287 ar->grp_crypto_len, ar->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001288
1289 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1290 ar->dot11_auth_mode, ar->auth_mode,
1291 ar->prwise_crypto,
1292 ar->prwise_crypto_len,
Edward Lu38acde32011-08-30 21:58:06 +03001293 ar->grp_crypto, ar->grp_crypto_len,
Kalle Valobdcd8172011-07-18 00:22:30 +03001294 ar->ssid_len, ar->ssid,
1295 ar->req_bssid, ar->ch_hint,
1296 ar->connect_ctrl_flags);
1297 set_bit(CONNECT_PEND, &ar->flag);
1298
1299 return 0;
1300}
1301
1302static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1303 struct net_device *dev)
1304{
1305 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1306
1307 if (!ath6kl_cfg80211_ready(ar))
1308 return -EIO;
1309
1310 ath6kl_disconnect(ar);
1311 memset(ar->ssid, 0, sizeof(ar->ssid));
1312 ar->ssid_len = 0;
1313
1314 return 0;
1315}
1316
1317static const u32 cipher_suites[] = {
1318 WLAN_CIPHER_SUITE_WEP40,
1319 WLAN_CIPHER_SUITE_WEP104,
1320 WLAN_CIPHER_SUITE_TKIP,
1321 WLAN_CIPHER_SUITE_CCMP,
1322};
1323
1324static bool is_rate_legacy(s32 rate)
1325{
1326 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1327 6000, 9000, 12000, 18000, 24000,
1328 36000, 48000, 54000
1329 };
1330 u8 i;
1331
1332 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1333 if (rate == legacy[i])
1334 return true;
1335
1336 return false;
1337}
1338
1339static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1340{
1341 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1342 52000, 58500, 65000, 72200
1343 };
1344 u8 i;
1345
1346 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1347 if (rate == ht20[i]) {
1348 if (i == ARRAY_SIZE(ht20) - 1)
1349 /* last rate uses sgi */
1350 *sgi = true;
1351 else
1352 *sgi = false;
1353
1354 *mcs = i;
1355 return true;
1356 }
1357 }
1358 return false;
1359}
1360
1361static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1362{
1363 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1364 81000, 108000, 121500, 135000,
1365 150000
1366 };
1367 u8 i;
1368
1369 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1370 if (rate == ht40[i]) {
1371 if (i == ARRAY_SIZE(ht40) - 1)
1372 /* last rate uses sgi */
1373 *sgi = true;
1374 else
1375 *sgi = false;
1376
1377 *mcs = i;
1378 return true;
1379 }
1380 }
1381
1382 return false;
1383}
1384
1385static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1386 u8 *mac, struct station_info *sinfo)
1387{
1388 struct ath6kl *ar = ath6kl_priv(dev);
1389 long left;
1390 bool sgi;
1391 s32 rate;
1392 int ret;
1393 u8 mcs;
1394
1395 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1396 return -ENOENT;
1397
1398 if (down_interruptible(&ar->sem))
1399 return -EBUSY;
1400
1401 set_bit(STATS_UPDATE_PEND, &ar->flag);
1402
1403 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1404
1405 if (ret != 0) {
1406 up(&ar->sem);
1407 return -EIO;
1408 }
1409
1410 left = wait_event_interruptible_timeout(ar->event_wq,
1411 !test_bit(STATS_UPDATE_PEND,
1412 &ar->flag),
1413 WMI_TIMEOUT);
1414
1415 up(&ar->sem);
1416
1417 if (left == 0)
1418 return -ETIMEDOUT;
1419 else if (left < 0)
1420 return left;
1421
1422 if (ar->target_stats.rx_byte) {
1423 sinfo->rx_bytes = ar->target_stats.rx_byte;
1424 sinfo->filled |= STATION_INFO_RX_BYTES;
1425 sinfo->rx_packets = ar->target_stats.rx_pkt;
1426 sinfo->filled |= STATION_INFO_RX_PACKETS;
1427 }
1428
1429 if (ar->target_stats.tx_byte) {
1430 sinfo->tx_bytes = ar->target_stats.tx_byte;
1431 sinfo->filled |= STATION_INFO_TX_BYTES;
1432 sinfo->tx_packets = ar->target_stats.tx_pkt;
1433 sinfo->filled |= STATION_INFO_TX_PACKETS;
1434 }
1435
1436 sinfo->signal = ar->target_stats.cs_rssi;
1437 sinfo->filled |= STATION_INFO_SIGNAL;
1438
1439 rate = ar->target_stats.tx_ucast_rate;
1440
1441 if (is_rate_legacy(rate)) {
1442 sinfo->txrate.legacy = rate / 100;
1443 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1444 if (sgi) {
1445 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1446 sinfo->txrate.mcs = mcs - 1;
1447 } else {
1448 sinfo->txrate.mcs = mcs;
1449 }
1450
1451 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1452 } else if (is_rate_ht40(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_40_MHZ_WIDTH;
1461 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1462 } else {
1463 ath6kl_warn("invalid rate: %d\n", rate);
1464 return 0;
1465 }
1466
1467 sinfo->filled |= STATION_INFO_TX_BITRATE;
1468
1469 return 0;
1470}
1471
1472static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1473 struct cfg80211_pmksa *pmksa)
1474{
1475 struct ath6kl *ar = ath6kl_priv(netdev);
1476 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1477 pmksa->pmkid, true);
1478}
1479
1480static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1481 struct cfg80211_pmksa *pmksa)
1482{
1483 struct ath6kl *ar = ath6kl_priv(netdev);
1484 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1485 pmksa->pmkid, false);
1486}
1487
1488static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1489{
1490 struct ath6kl *ar = ath6kl_priv(netdev);
1491 if (test_bit(CONNECTED, &ar->flag))
1492 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1493 return 0;
1494}
1495
Kalle Valoabcb3442011-07-22 08:26:20 +03001496#ifdef CONFIG_PM
1497static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1498 struct cfg80211_wowlan *wow)
1499{
1500 struct ath6kl *ar = wiphy_priv(wiphy);
1501
1502 return ath6kl_hif_suspend(ar);
1503}
1504#endif
1505
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001506static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1507 struct ieee80211_channel *chan,
1508 enum nl80211_channel_type channel_type)
1509{
1510 struct ath6kl *ar = ath6kl_priv(dev);
1511
1512 if (!ath6kl_cfg80211_ready(ar))
1513 return -EIO;
1514
1515 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1516 __func__, chan->center_freq, chan->hw_value);
1517 ar->next_chan = chan->center_freq;
1518
1519 return 0;
1520}
1521
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001522static bool ath6kl_is_p2p_ie(const u8 *pos)
1523{
1524 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1525 pos[2] == 0x50 && pos[3] == 0x6f &&
1526 pos[4] == 0x9a && pos[5] == 0x09;
1527}
1528
1529static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1530 size_t ies_len)
1531{
1532 const u8 *pos;
1533 u8 *buf = NULL;
1534 size_t len = 0;
1535 int ret;
1536
1537 /*
1538 * Filter out P2P IE(s) since they will be included depending on
1539 * the Probe Request frame in ath6kl_send_go_probe_resp().
1540 */
1541
1542 if (ies && ies_len) {
1543 buf = kmalloc(ies_len, GFP_KERNEL);
1544 if (buf == NULL)
1545 return -ENOMEM;
1546 pos = ies;
1547 while (pos + 1 < ies + ies_len) {
1548 if (pos + 2 + pos[1] > ies + ies_len)
1549 break;
1550 if (!ath6kl_is_p2p_ie(pos)) {
1551 memcpy(buf + len, pos, 2 + pos[1]);
1552 len += 2 + pos[1];
1553 }
1554 pos += 2 + pos[1];
1555 }
1556 }
1557
1558 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1559 buf, len);
1560 kfree(buf);
1561 return ret;
1562}
1563
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001564static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1565 struct beacon_parameters *info, bool add)
1566{
1567 struct ath6kl *ar = ath6kl_priv(dev);
1568 struct ieee80211_mgmt *mgmt;
1569 u8 *ies;
1570 int ies_len;
1571 struct wmi_connect_cmd p;
1572 int res;
1573 int i;
1574
1575 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1576
1577 if (!ath6kl_cfg80211_ready(ar))
1578 return -EIO;
1579
1580 if (ar->next_mode != AP_NETWORK)
1581 return -EOPNOTSUPP;
1582
1583 if (info->beacon_ies) {
1584 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1585 info->beacon_ies,
1586 info->beacon_ies_len);
1587 if (res)
1588 return res;
1589 }
1590 if (info->proberesp_ies) {
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001591 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1592 info->proberesp_ies_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001593 if (res)
1594 return res;
1595 }
1596 if (info->assocresp_ies) {
1597 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1598 info->assocresp_ies,
1599 info->assocresp_ies_len);
1600 if (res)
1601 return res;
1602 }
1603
1604 if (!add)
1605 return 0;
1606
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001607 ar->ap_mode_bkey.valid = false;
1608
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001609 /* TODO:
1610 * info->interval
1611 * info->dtim_period
1612 */
1613
1614 if (info->head == NULL)
1615 return -EINVAL;
1616 mgmt = (struct ieee80211_mgmt *) info->head;
1617 ies = mgmt->u.beacon.variable;
1618 if (ies > info->head + info->head_len)
1619 return -EINVAL;
1620 ies_len = info->head + info->head_len - ies;
1621
1622 if (info->ssid == NULL)
1623 return -EINVAL;
1624 memcpy(ar->ssid, info->ssid, info->ssid_len);
1625 ar->ssid_len = info->ssid_len;
1626 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1627 return -EOPNOTSUPP; /* TODO */
1628
1629 ar->dot11_auth_mode = OPEN_AUTH;
1630
1631 memset(&p, 0, sizeof(p));
1632
1633 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1634 switch (info->crypto.akm_suites[i]) {
1635 case WLAN_AKM_SUITE_8021X:
1636 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1637 p.auth_mode |= WPA_AUTH;
1638 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1639 p.auth_mode |= WPA2_AUTH;
1640 break;
1641 case WLAN_AKM_SUITE_PSK:
1642 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1643 p.auth_mode |= WPA_PSK_AUTH;
1644 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1645 p.auth_mode |= WPA2_PSK_AUTH;
1646 break;
1647 }
1648 }
1649 if (p.auth_mode == 0)
1650 p.auth_mode = NONE_AUTH;
1651 ar->auth_mode = p.auth_mode;
1652
1653 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1654 switch (info->crypto.ciphers_pairwise[i]) {
1655 case WLAN_CIPHER_SUITE_WEP40:
1656 case WLAN_CIPHER_SUITE_WEP104:
1657 p.prwise_crypto_type |= WEP_CRYPT;
1658 break;
1659 case WLAN_CIPHER_SUITE_TKIP:
1660 p.prwise_crypto_type |= TKIP_CRYPT;
1661 break;
1662 case WLAN_CIPHER_SUITE_CCMP:
1663 p.prwise_crypto_type |= AES_CRYPT;
1664 break;
1665 }
1666 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001667 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001668 p.prwise_crypto_type = NONE_CRYPT;
Edward Lu229ed6b2011-08-30 21:58:07 +03001669 ath6kl_set_cipher(ar, 0, true);
1670 } else if (info->crypto.n_ciphers_pairwise == 1)
1671 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001672
1673 switch (info->crypto.cipher_group) {
1674 case WLAN_CIPHER_SUITE_WEP40:
1675 case WLAN_CIPHER_SUITE_WEP104:
1676 p.grp_crypto_type = WEP_CRYPT;
1677 break;
1678 case WLAN_CIPHER_SUITE_TKIP:
1679 p.grp_crypto_type = TKIP_CRYPT;
1680 break;
1681 case WLAN_CIPHER_SUITE_CCMP:
1682 p.grp_crypto_type = AES_CRYPT;
1683 break;
1684 default:
1685 p.grp_crypto_type = NONE_CRYPT;
1686 break;
1687 }
Edward Lu229ed6b2011-08-30 21:58:07 +03001688 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001689
1690 p.nw_type = AP_NETWORK;
1691 ar->nw_type = ar->next_mode;
1692
1693 p.ssid_len = ar->ssid_len;
1694 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1695 p.dot11_auth_mode = ar->dot11_auth_mode;
1696 p.ch = cpu_to_le16(ar->next_chan);
1697
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001698 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1699 if (res < 0)
1700 return res;
1701
1702 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001703}
1704
1705static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1706 struct beacon_parameters *info)
1707{
1708 return ath6kl_ap_beacon(wiphy, dev, info, true);
1709}
1710
1711static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1712 struct beacon_parameters *info)
1713{
1714 return ath6kl_ap_beacon(wiphy, dev, info, false);
1715}
1716
1717static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1718{
1719 struct ath6kl *ar = ath6kl_priv(dev);
1720
1721 if (ar->nw_type != AP_NETWORK)
1722 return -EOPNOTSUPP;
1723 if (!test_bit(CONNECTED, &ar->flag))
1724 return -ENOTCONN;
1725
1726 ath6kl_wmi_disconnect_cmd(ar->wmi);
1727 clear_bit(CONNECTED, &ar->flag);
1728
1729 return 0;
1730}
1731
Jouni Malinen23875132011-08-30 21:57:53 +03001732static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1733 u8 *mac, struct station_parameters *params)
1734{
1735 struct ath6kl *ar = ath6kl_priv(dev);
1736
1737 if (ar->nw_type != AP_NETWORK)
1738 return -EOPNOTSUPP;
1739
1740 /* Use this only for authorizing/unauthorizing a station */
1741 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1742 return -EOPNOTSUPP;
1743
1744 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1745 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1746 mac, 0);
1747 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1748 0);
1749}
1750
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001751static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1752 struct net_device *dev,
1753 struct ieee80211_channel *chan,
1754 enum nl80211_channel_type channel_type,
1755 unsigned int duration,
1756 u64 *cookie)
1757{
1758 struct ath6kl *ar = ath6kl_priv(dev);
1759
1760 /* TODO: if already pending or ongoing remain-on-channel,
1761 * return -EBUSY */
1762 *cookie = 1; /* only a single pending request is supported */
1763
1764 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1765 duration);
1766}
1767
1768static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1769 struct net_device *dev,
1770 u64 cookie)
1771{
1772 struct ath6kl *ar = ath6kl_priv(dev);
1773
1774 if (cookie != 1)
1775 return -ENOENT;
1776
1777 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1778}
1779
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001780static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1781 size_t len, unsigned int freq)
1782{
1783 const u8 *pos;
1784 u8 *p2p;
1785 int p2p_len;
1786 int ret;
1787 const struct ieee80211_mgmt *mgmt;
1788
1789 mgmt = (const struct ieee80211_mgmt *) buf;
1790
1791 /* Include P2P IE(s) from the frame generated in user space. */
1792
1793 p2p = kmalloc(len, GFP_KERNEL);
1794 if (p2p == NULL)
1795 return -ENOMEM;
1796 p2p_len = 0;
1797
1798 pos = mgmt->u.probe_resp.variable;
1799 while (pos + 1 < buf + len) {
1800 if (pos + 2 + pos[1] > buf + len)
1801 break;
1802 if (ath6kl_is_p2p_ie(pos)) {
1803 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1804 p2p_len += 2 + pos[1];
1805 }
1806 pos += 2 + pos[1];
1807 }
1808
1809 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1810 p2p, p2p_len);
1811 kfree(p2p);
1812 return ret;
1813}
1814
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001815static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1816 struct ieee80211_channel *chan, bool offchan,
1817 enum nl80211_channel_type channel_type,
1818 bool channel_type_valid, unsigned int wait,
1819 const u8 *buf, size_t len, u64 *cookie)
1820{
1821 struct ath6kl *ar = ath6kl_priv(dev);
1822 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03001823 const struct ieee80211_mgmt *mgmt;
1824
1825 mgmt = (const struct ieee80211_mgmt *) buf;
1826 if (buf + len >= mgmt->u.probe_resp.variable &&
1827 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1828 ieee80211_is_probe_resp(mgmt->frame_control)) {
1829 /*
1830 * Send Probe Response frame in AP mode using a separate WMI
1831 * command to allow the target to fill in the generic IEs.
1832 */
1833 *cookie = 0; /* TX status not supported */
1834 return ath6kl_send_go_probe_resp(ar, buf, len,
1835 chan->center_freq);
1836 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001837
1838 id = ar->send_action_id++;
1839 if (id == 0) {
1840 /*
1841 * 0 is a reserved value in the WMI command and shall not be
1842 * used for the command.
1843 */
1844 id = ar->send_action_id++;
1845 }
1846
1847 *cookie = id;
1848 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1849 buf, len);
1850}
1851
Jouni Malinenae32c302011-08-30 21:58:01 +03001852static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1853 struct net_device *dev,
1854 u16 frame_type, bool reg)
1855{
1856 struct ath6kl *ar = ath6kl_priv(dev);
1857
1858 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1859 __func__, frame_type, reg);
1860 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1861 /*
1862 * Note: This notification callback is not allowed to sleep, so
1863 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1864 * hardcode target to report Probe Request frames all the time.
1865 */
1866 ar->probe_req_report = reg;
1867 }
1868}
1869
Jouni Malinenf80574a2011-08-30 21:58:04 +03001870static const struct ieee80211_txrx_stypes
1871ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1872 [NL80211_IFTYPE_STATION] = {
1873 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1874 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1875 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1876 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1877 },
1878 [NL80211_IFTYPE_P2P_CLIENT] = {
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_GO] = {
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};
1891
Kalle Valobdcd8172011-07-18 00:22:30 +03001892static struct cfg80211_ops ath6kl_cfg80211_ops = {
1893 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1894 .scan = ath6kl_cfg80211_scan,
1895 .connect = ath6kl_cfg80211_connect,
1896 .disconnect = ath6kl_cfg80211_disconnect,
1897 .add_key = ath6kl_cfg80211_add_key,
1898 .get_key = ath6kl_cfg80211_get_key,
1899 .del_key = ath6kl_cfg80211_del_key,
1900 .set_default_key = ath6kl_cfg80211_set_default_key,
1901 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1902 .set_tx_power = ath6kl_cfg80211_set_txpower,
1903 .get_tx_power = ath6kl_cfg80211_get_txpower,
1904 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1905 .join_ibss = ath6kl_cfg80211_join_ibss,
1906 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1907 .get_station = ath6kl_get_station,
1908 .set_pmksa = ath6kl_set_pmksa,
1909 .del_pmksa = ath6kl_del_pmksa,
1910 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03001911 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03001912#ifdef CONFIG_PM
1913 .suspend = ar6k_cfg80211_suspend,
1914#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001915 .set_channel = ath6kl_set_channel,
1916 .add_beacon = ath6kl_add_beacon,
1917 .set_beacon = ath6kl_set_beacon,
1918 .del_beacon = ath6kl_del_beacon,
Jouni Malinen23875132011-08-30 21:57:53 +03001919 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001920 .remain_on_channel = ath6kl_remain_on_channel,
1921 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03001922 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03001923 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valobdcd8172011-07-18 00:22:30 +03001924};
1925
1926struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1927{
1928 int ret = 0;
1929 struct wireless_dev *wdev;
1930
1931 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1932 if (!wdev) {
1933 ath6kl_err("couldn't allocate wireless device\n");
1934 return NULL;
1935 }
1936
1937 /* create a new wiphy for use with cfg80211 */
1938 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1939 if (!wdev->wiphy) {
1940 ath6kl_err("couldn't allocate wiphy device\n");
1941 kfree(wdev);
1942 return NULL;
1943 }
1944
Jouni Malinenf80574a2011-08-30 21:58:04 +03001945 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1946
Jouni Malinen63fa1e02011-08-30 21:57:55 +03001947 wdev->wiphy->max_remain_on_channel_duration = 5000;
1948
Kalle Valobdcd8172011-07-18 00:22:30 +03001949 /* set device pointer for wiphy */
1950 set_wiphy_dev(wdev->wiphy, dev);
1951
1952 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1953 BIT(NL80211_IFTYPE_ADHOC);
1954 /* max num of ssids that can be probed during scanning */
1955 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
Jouni Malinenb84da8c2011-08-30 21:57:59 +03001956 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
Kalle Valobdcd8172011-07-18 00:22:30 +03001957 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1958 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1959 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1960
1961 wdev->wiphy->cipher_suites = cipher_suites;
1962 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1963
1964 ret = wiphy_register(wdev->wiphy);
1965 if (ret < 0) {
1966 ath6kl_err("couldn't register wiphy device\n");
1967 wiphy_free(wdev->wiphy);
1968 kfree(wdev);
1969 return NULL;
1970 }
1971
1972 return wdev;
1973}
1974
1975void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1976{
1977 struct wireless_dev *wdev = ar->wdev;
1978
1979 if (ar->scan_req) {
1980 cfg80211_scan_done(ar->scan_req, true);
1981 ar->scan_req = NULL;
1982 }
1983
1984 if (!wdev)
1985 return;
1986
1987 wiphy_unregister(wdev->wiphy);
1988 wiphy_free(wdev->wiphy);
1989 kfree(wdev);
1990}