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