ath6kl: Advertise supported mgmt_stypes
[linux-2.6-block.git] / drivers / net / wireless / ath / ath6kl / cfg80211.c
CommitLineData
bdcd8170
KV
1/*
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"
abcb344b 20#include "hif-ops.h"
bdcd8170
KV
21
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
575b5f34 227 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
bdcd8170
KV
228 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];
bdcd8170
KV
429
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) {
454 if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
455 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
456 "%s: ath6k not in station mode\n", __func__);
457 return;
458 }
459 }
460
bdcd8170
KV
461 /*
462 * Earlier we were updating the cfg about bss by making a beacon frame
463 * only if the entry for bss is not there. This can have some issue if
464 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
465 * event is handled through a work queue and by the time it really gets
466 * handled, BSS would have been aged out. So it is better to update the
467 * cfg about BSS irrespective of its entry being present right now or
468 * not.
469 */
470
471 if (nw_type & ADHOC_NETWORK) {
472 /* construct 802.11 mgmt beacon */
473 if (ptr_ie_buf) {
474 *ptr_ie_buf++ = WLAN_EID_SSID;
475 *ptr_ie_buf++ = ar->ssid_len;
476 memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
477 ptr_ie_buf += ar->ssid_len;
478
479 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
480 *ptr_ie_buf++ = 2; /* length */
481 *ptr_ie_buf++ = 0; /* ATIM window */
482 *ptr_ie_buf++ = 0; /* ATIM window */
483
484 /* TODO: update ibss params and include supported rates,
485 * DS param set, extened support rates, wmm. */
486
487 ie_buf_len = ptr_ie_buf - ie_buf;
488 }
489
490 capability |= WLAN_CAPABILITY_IBSS;
491
492 if (ar->prwise_crypto == WEP_CRYPT)
493 capability |= WLAN_CAPABILITY_PRIVACY;
494
495 memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
496 ptr_ie_buf = ie_buf;
497 } else {
498 capability = *(u16 *) (&assoc_info[beacon_ie_len]);
499 memcpy(source_mac, bssid, ETH_ALEN);
500 ptr_ie_buf = assoc_req_ie;
501 ie_buf_len = assoc_req_len;
502 }
503
504 size = offsetof(struct ieee80211_mgmt, u)
505 + sizeof(mgmt->u.beacon)
506 + ie_buf_len;
507
508 ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
509 if (!ieeemgmtbuf) {
510 ath6kl_err("ieee mgmt buf alloc error\n");
bdcd8170
KV
511 return;
512 }
513
514 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
515 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
516 IEEE80211_STYPE_BEACON);
517 memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
518 memcpy(mgmt->sa, source_mac, ETH_ALEN);
519 memcpy(mgmt->bssid, bssid, ETH_ALEN);
520 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
521 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
522 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
523
524 ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
525
526 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
527 "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
528 __func__, mgmt->bssid, ibss_ch->hw_value,
529 beacon_intvl, capability);
530
531 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
532 ibss_ch, mgmt,
533 size, signal, GFP_KERNEL);
534 kfree(ieeemgmtbuf);
535 cfg80211_put_bss(bss);
536
537 if (nw_type & ADHOC_NETWORK) {
538 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
539 return;
540 }
541
9aa60357 542 if (ar->sme_state == SME_CONNECTING) {
bdcd8170 543 /* inform connect result to cfg80211 */
9aa60357 544 ar->sme_state = SME_CONNECTED;
bdcd8170
KV
545 cfg80211_connect_result(ar->net_dev, bssid,
546 assoc_req_ie, assoc_req_len,
547 assoc_resp_ie, assoc_resp_len,
548 WLAN_STATUS_SUCCESS, GFP_KERNEL);
9aa60357 549 } else if (ar->sme_state == SME_CONNECTED) {
bdcd8170
KV
550 /* inform roam event to cfg80211 */
551 cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
552 assoc_req_ie, assoc_req_len,
553 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
554 }
555}
556
557static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
558 struct net_device *dev, u16 reason_code)
559{
560 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
561
562 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
563 reason_code);
564
565 if (!ath6kl_cfg80211_ready(ar))
566 return -EIO;
567
568 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
569 ath6kl_err("busy, destroy in progress\n");
570 return -EBUSY;
571 }
572
573 if (down_interruptible(&ar->sem)) {
574 ath6kl_err("busy, couldn't get access\n");
575 return -ERESTARTSYS;
576 }
577
578 ar->reconnect_flag = 0;
579 ath6kl_disconnect(ar);
580 memset(ar->ssid, 0, sizeof(ar->ssid));
581 ar->ssid_len = 0;
582
583 if (!test_bit(SKIP_SCAN, &ar->flag))
584 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
585
586 up(&ar->sem);
587
588 return 0;
589}
590
591void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
592 u8 *bssid, u8 assoc_resp_len,
593 u8 *assoc_info, u16 proto_reason)
594{
595 struct ath6kl_key *key = NULL;
596 u16 status;
597
598 if (ar->scan_req) {
599 cfg80211_scan_done(ar->scan_req, true);
600 ar->scan_req = NULL;
601 }
602
603 if (ar->nw_type & ADHOC_NETWORK) {
604 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
605 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
606 "%s: ath6k not in ibss mode\n", __func__);
607 return;
608 }
609 memset(bssid, 0, ETH_ALEN);
610 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
611 return;
612 }
613
614 if (ar->nw_type & INFRA_NETWORK) {
615 if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
616 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
617 "%s: ath6k not in station mode\n", __func__);
618 return;
619 }
620 }
621
622 if (!test_bit(CONNECT_PEND, &ar->flag)) {
623 if (reason != DISCONNECT_CMD)
624 ath6kl_wmi_disconnect_cmd(ar->wmi);
625
626 return;
627 }
628
629 if (reason == NO_NETWORK_AVAIL) {
630 /* connect cmd failed */
631 ath6kl_wmi_disconnect_cmd(ar->wmi);
632 return;
633 }
634
635 if (reason != DISCONNECT_CMD)
636 return;
637
638 if (!ar->auto_auth_stage) {
639 clear_bit(CONNECT_PEND, &ar->flag);
640
641 if (ar->sme_state == SME_CONNECTING) {
642 cfg80211_connect_result(ar->net_dev,
643 bssid, NULL, 0,
644 NULL, 0,
645 WLAN_STATUS_UNSPECIFIED_FAILURE,
646 GFP_KERNEL);
0e5cc8e6 647 } else if (ar->sme_state == SME_CONNECTED) {
bdcd8170
KV
648 cfg80211_disconnected(ar->net_dev, reason,
649 NULL, 0, GFP_KERNEL);
650 }
651
652 ar->sme_state = SME_DISCONNECTED;
653 return;
654 }
655
656 if (ar->dot11_auth_mode != OPEN_AUTH)
657 return;
658
659 /*
660 * If the current auth algorithm is open, try shared and
661 * make autoAuthStage idle. We do not make it leap for now
662 * being.
663 */
664 key = &ar->keys[ar->def_txkey_index];
665 if (down_interruptible(&ar->sem)) {
666 ath6kl_err("busy, couldn't get access\n");
667 return;
668 }
669
670 ar->dot11_auth_mode = SHARED_AUTH;
671 ar->auto_auth_stage = AUTH_IDLE;
672
673 ath6kl_wmi_addkey_cmd(ar->wmi,
674 ar->def_txkey_index,
675 ar->prwise_crypto,
676 GROUP_USAGE | TX_USAGE,
677 key->key_len, NULL,
678 key->key,
679 KEY_OP_INIT_VAL, NULL,
680 NO_SYNC_WMIFLAG);
681
682 status = ath6kl_wmi_connect_cmd(ar->wmi,
683 ar->nw_type,
684 ar->dot11_auth_mode,
685 ar->auth_mode,
686 ar->prwise_crypto,
687 ar->prwise_crypto_len,
688 ar->grp_crypto,
689 ar->grp_crpto_len,
690 ar->ssid_len,
691 ar->ssid,
692 ar->req_bssid,
693 ar->ch_hint,
694 ar->connect_ctrl_flags);
695 up(&ar->sem);
696}
697
698static inline bool is_ch_11a(u16 ch)
699{
700 return (!((ch >= 2412) && (ch <= 2484)));
701}
702
cf104c2a 703/* struct ath6kl_node_table::nt_nodelock is locked when calling this */
91db35da 704void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
bdcd8170 705{
bdcd8170
KV
706 struct ieee80211_mgmt *mgmt;
707 struct ieee80211_channel *channel;
708 struct ieee80211_supported_band *band;
709 struct ath6kl_common_ie *cie;
710 s32 signal;
711 int freq;
712
713 cie = &ni->ni_cie;
714
715 if (is_ch_11a(cie->ie_chan))
716 band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
717 else if ((cie->ie_erp) || (cie->ie_xrates))
718 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
719 else
720 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
721
bdcd8170
KV
722 freq = cie->ie_chan;
723 channel = ieee80211_get_channel(wiphy, freq);
724 signal = ni->ni_snr * 100;
725
726 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
727 "%s: bssid %pM ch %d freq %d size %d\n", __func__,
0ce77920
JM
728 ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
729 /*
730 * Both Beacon and Probe Response frames have same payload structure,
731 * so it is fine to share the parser for both.
732 */
733 if (ni->ni_framelen < 8 + 2 + 2)
734 return;
735 mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
736 offsetof(struct ieee80211_mgmt, u));
737 cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
738 le64_to_cpu(mgmt->u.beacon.timestamp),
739 le16_to_cpu(mgmt->u.beacon.capab_info),
740 le16_to_cpu(mgmt->u.beacon.beacon_int),
741 mgmt->u.beacon.variable,
742 ni->ni_buf + ni->ni_framelen -
743 mgmt->u.beacon.variable,
744 signal, GFP_ATOMIC);
bdcd8170
KV
745}
746
747static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
748 struct cfg80211_scan_request *request)
749{
750 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1276c9ef
EL
751 s8 n_channels = 0;
752 u16 *channels = NULL;
bdcd8170 753 int ret = 0;
bdcd8170
KV
754
755 if (!ath6kl_cfg80211_ready(ar))
756 return -EIO;
757
758 if (!ar->usr_bss_filter) {
759 if (ath6kl_wmi_bssfilter_cmd(ar->wmi,
760 (test_bit(CONNECTED, &ar->flag) ?
761 ALL_BUT_BSS_FILTER :
762 ALL_BSS_FILTER), 0) != 0) {
763 ath6kl_err("couldn't set bss filtering\n");
764 return -EIO;
765 }
766 }
767
768 if (request->n_ssids && request->ssids[0].ssid_len) {
769 u8 i;
770
771 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
772 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
773
774 for (i = 0; i < request->n_ssids; i++)
775 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
776 SPECIFIC_SSID_FLAG,
777 request->ssids[i].ssid_len,
778 request->ssids[i].ssid);
779 }
780
b84da8c7
JM
781 if (request->ie) {
782 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
783 request->ie, request->ie_len);
784 if (ret) {
785 ath6kl_err("failed to set Probe Request appie for "
786 "scan");
787 return ret;
788 }
789 }
790
1276c9ef
EL
791 if (request->n_channels > 0) {
792 u8 i;
793
794 n_channels = min(127U, request->n_channels);
795
796 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
797 if (channels == NULL) {
798 ath6kl_warn("failed to set scan channels, "
799 "scan all channels");
800 n_channels = 0;
801 }
802
803 for (i = 0; i < n_channels; i++)
804 channels[i] = request->channels[i]->center_freq;
805 }
806
b2c76bbe 807 if (ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
1276c9ef 808 false, 0, 0, n_channels, channels) != 0) {
bdcd8170
KV
809 ath6kl_err("wmi_startscan_cmd failed\n");
810 ret = -EIO;
811 }
812
813 ar->scan_req = request;
814
1276c9ef
EL
815 kfree(channels);
816
bdcd8170
KV
817 return ret;
818}
819
820void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
821{
6fd1eace 822 int i;
bdcd8170
KV
823
824 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
825
6fd1eace
KV
826 if (!ar->scan_req)
827 return;
828
829 if ((status == -ECANCELED) || (status == -EBUSY)) {
830 cfg80211_scan_done(ar->scan_req, true);
831 goto out;
832 }
833
834 /* Translate data to cfg80211 mgmt format */
8a8bc5a4 835 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
6fd1eace
KV
836
837 cfg80211_scan_done(ar->scan_req, false);
838
839 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
840 for (i = 0; i < ar->scan_req->n_ssids; i++) {
841 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
842 DISABLE_SSID_FLAG,
843 0, NULL);
bdcd8170 844 }
bdcd8170 845 }
6fd1eace
KV
846
847out:
848 ar->scan_req = NULL;
bdcd8170
KV
849}
850
851static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
852 u8 key_index, bool pairwise,
853 const u8 *mac_addr,
854 struct key_params *params)
855{
856 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
857 struct ath6kl_key *key = NULL;
858 u8 key_usage;
859 u8 key_type;
860 int status = 0;
861
862 if (!ath6kl_cfg80211_ready(ar))
863 return -EIO;
864
865 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
866 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
867 "%s: key index %d out of bounds\n", __func__,
868 key_index);
869 return -ENOENT;
870 }
871
872 key = &ar->keys[key_index];
873 memset(key, 0, sizeof(struct ath6kl_key));
874
875 if (pairwise)
876 key_usage = PAIRWISE_USAGE;
877 else
878 key_usage = GROUP_USAGE;
879
880 if (params) {
881 if (params->key_len > WLAN_MAX_KEY_LEN ||
882 params->seq_len > sizeof(key->seq))
883 return -EINVAL;
884
885 key->key_len = params->key_len;
886 memcpy(key->key, params->key, key->key_len);
887 key->seq_len = params->seq_len;
888 memcpy(key->seq, params->seq, key->seq_len);
889 key->cipher = params->cipher;
890 }
891
892 switch (key->cipher) {
893 case WLAN_CIPHER_SUITE_WEP40:
894 case WLAN_CIPHER_SUITE_WEP104:
895 key_type = WEP_CRYPT;
896 break;
897
898 case WLAN_CIPHER_SUITE_TKIP:
899 key_type = TKIP_CRYPT;
900 break;
901
902 case WLAN_CIPHER_SUITE_CCMP:
903 key_type = AES_CRYPT;
904 break;
905
906 default:
907 return -ENOTSUPP;
908 }
909
910 if (((ar->auth_mode == WPA_PSK_AUTH)
911 || (ar->auth_mode == WPA2_PSK_AUTH))
912 && (key_usage & GROUP_USAGE))
913 del_timer(&ar->disconnect_timer);
914
915 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
916 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
917 __func__, key_index, key->key_len, key_type,
918 key_usage, key->seq_len);
919
920 ar->def_txkey_index = key_index;
9a5b1318
JM
921
922 if (ar->nw_type == AP_NETWORK && !pairwise &&
923 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
924 ar->ap_mode_bkey.valid = true;
925 ar->ap_mode_bkey.key_index = key_index;
926 ar->ap_mode_bkey.key_type = key_type;
927 ar->ap_mode_bkey.key_len = key->key_len;
928 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
929 if (!test_bit(CONNECTED, &ar->flag)) {
930 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
931 "key configuration until AP mode has been "
932 "started\n");
933 /*
934 * The key will be set in ath6kl_connect_ap_mode() once
935 * the connected event is received from the target.
936 */
937 return 0;
938 }
939 }
940
bdcd8170
KV
941 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
942 key_type, key_usage, key->key_len,
943 key->seq, key->key, KEY_OP_INIT_VAL,
944 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
945
946 if (status)
947 return -EIO;
948
949 return 0;
950}
951
952static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
953 u8 key_index, bool pairwise,
954 const u8 *mac_addr)
955{
956 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
957
958 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
959
960 if (!ath6kl_cfg80211_ready(ar))
961 return -EIO;
962
963 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
964 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
965 "%s: key index %d out of bounds\n", __func__,
966 key_index);
967 return -ENOENT;
968 }
969
970 if (!ar->keys[key_index].key_len) {
971 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
972 "%s: index %d is empty\n", __func__, key_index);
973 return 0;
974 }
975
976 ar->keys[key_index].key_len = 0;
977
978 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
979}
980
981static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
982 u8 key_index, bool pairwise,
983 const u8 *mac_addr, void *cookie,
984 void (*callback) (void *cookie,
985 struct key_params *))
986{
987 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
988 struct ath6kl_key *key = NULL;
989 struct key_params params;
990
991 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
992
993 if (!ath6kl_cfg80211_ready(ar))
994 return -EIO;
995
996 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
997 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
998 "%s: key index %d out of bounds\n", __func__,
999 key_index);
1000 return -ENOENT;
1001 }
1002
1003 key = &ar->keys[key_index];
1004 memset(&params, 0, sizeof(params));
1005 params.cipher = key->cipher;
1006 params.key_len = key->key_len;
1007 params.seq_len = key->seq_len;
1008 params.seq = key->seq;
1009 params.key = key->key;
1010
1011 callback(cookie, &params);
1012
1013 return key->key_len ? 0 : -ENOENT;
1014}
1015
1016static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1017 struct net_device *ndev,
1018 u8 key_index, bool unicast,
1019 bool multicast)
1020{
1021 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1022 struct ath6kl_key *key = NULL;
1023 int status = 0;
1024 u8 key_usage;
1025
1026 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1027
1028 if (!ath6kl_cfg80211_ready(ar))
1029 return -EIO;
1030
1031 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1032 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1033 "%s: key index %d out of bounds\n",
1034 __func__, key_index);
1035 return -ENOENT;
1036 }
1037
1038 if (!ar->keys[key_index].key_len) {
1039 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1040 __func__, key_index);
1041 return -EINVAL;
1042 }
1043
1044 ar->def_txkey_index = key_index;
1045 key = &ar->keys[ar->def_txkey_index];
1046 key_usage = GROUP_USAGE;
1047 if (ar->prwise_crypto == WEP_CRYPT)
1048 key_usage |= TX_USAGE;
1049
9a5b1318
JM
1050 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1051 return 0; /* Delay until AP mode has been started */
1052
bdcd8170
KV
1053 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
1054 ar->prwise_crypto, key_usage,
1055 key->key_len, key->seq, key->key,
1056 KEY_OP_INIT_VAL, NULL,
1057 SYNC_BOTH_WMIFLAG);
1058 if (status)
1059 return -EIO;
1060
1061 return 0;
1062}
1063
1064void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1065 bool ismcast)
1066{
1067 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1068 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1069
1070 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1071 (ismcast ? NL80211_KEYTYPE_GROUP :
1072 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1073 GFP_KERNEL);
1074}
1075
1076static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1077{
1078 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1079 int ret;
1080
1081 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1082 changed);
1083
1084 if (!ath6kl_cfg80211_ready(ar))
1085 return -EIO;
1086
1087 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1088 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1089 if (ret != 0) {
1090 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1091 return -EIO;
1092 }
1093 }
1094
1095 return 0;
1096}
1097
1098/*
1099 * The type nl80211_tx_power_setting replaces the following
1100 * data type from 2.6.36 onwards
1101*/
1102static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1103 enum nl80211_tx_power_setting type,
1104 int dbm)
1105{
1106 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1107 u8 ath6kl_dbm;
1108
1109 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1110 type, dbm);
1111
1112 if (!ath6kl_cfg80211_ready(ar))
1113 return -EIO;
1114
1115 switch (type) {
1116 case NL80211_TX_POWER_AUTOMATIC:
1117 return 0;
1118 case NL80211_TX_POWER_LIMITED:
1119 ar->tx_pwr = ath6kl_dbm = dbm;
1120 break;
1121 default:
1122 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1123 __func__, type);
1124 return -EOPNOTSUPP;
1125 }
1126
1127 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1128
1129 return 0;
1130}
1131
1132static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1133{
1134 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1135
1136 if (!ath6kl_cfg80211_ready(ar))
1137 return -EIO;
1138
1139 if (test_bit(CONNECTED, &ar->flag)) {
1140 ar->tx_pwr = 0;
1141
1142 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1143 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1144 return -EIO;
1145 }
1146
1147 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1148 5 * HZ);
1149
1150 if (signal_pending(current)) {
1151 ath6kl_err("target did not respond\n");
1152 return -EINTR;
1153 }
1154 }
1155
1156 *dbm = ar->tx_pwr;
1157 return 0;
1158}
1159
1160static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1161 struct net_device *dev,
1162 bool pmgmt, int timeout)
1163{
1164 struct ath6kl *ar = ath6kl_priv(dev);
1165 struct wmi_power_mode_cmd mode;
1166
1167 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1168 __func__, pmgmt, timeout);
1169
1170 if (!ath6kl_cfg80211_ready(ar))
1171 return -EIO;
1172
1173 if (pmgmt) {
1174 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1175 mode.pwr_mode = REC_POWER;
1176 } else {
1177 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1178 mode.pwr_mode = MAX_PERF_POWER;
1179 }
1180
1181 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1182 ath6kl_err("wmi_powermode_cmd failed\n");
1183 return -EIO;
1184 }
1185
1186 return 0;
1187}
1188
1189static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1190 struct net_device *ndev,
1191 enum nl80211_iftype type, u32 *flags,
1192 struct vif_params *params)
1193{
1194 struct ath6kl *ar = ath6kl_priv(ndev);
1195 struct wireless_dev *wdev = ar->wdev;
1196
1197 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1198
1199 if (!ath6kl_cfg80211_ready(ar))
1200 return -EIO;
1201
1202 switch (type) {
1203 case NL80211_IFTYPE_STATION:
1204 ar->next_mode = INFRA_NETWORK;
1205 break;
1206 case NL80211_IFTYPE_ADHOC:
1207 ar->next_mode = ADHOC_NETWORK;
1208 break;
1209 default:
1210 ath6kl_err("invalid interface type %u\n", type);
1211 return -EOPNOTSUPP;
1212 }
1213
1214 wdev->iftype = type;
1215
1216 return 0;
1217}
1218
1219static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1220 struct net_device *dev,
1221 struct cfg80211_ibss_params *ibss_param)
1222{
1223 struct ath6kl *ar = ath6kl_priv(dev);
1224 int status;
1225
1226 if (!ath6kl_cfg80211_ready(ar))
1227 return -EIO;
1228
1229 ar->ssid_len = ibss_param->ssid_len;
1230 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1231
1232 if (ibss_param->channel)
1233 ar->ch_hint = ibss_param->channel->center_freq;
1234
1235 if (ibss_param->channel_fixed) {
1236 /*
1237 * TODO: channel_fixed: The channel should be fixed, do not
1238 * search for IBSSs to join on other channels. Target
1239 * firmware does not support this feature, needs to be
1240 * updated.
1241 */
1242 return -EOPNOTSUPP;
1243 }
1244
1245 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1246 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1247 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1248
1249 ath6kl_set_wpa_version(ar, 0);
1250
1251 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1252 if (status)
1253 return status;
1254
1255 if (ibss_param->privacy) {
1256 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1257 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1258 } else {
1259 ath6kl_set_cipher(ar, 0, true);
1260 ath6kl_set_cipher(ar, 0, false);
1261 }
1262
1263 ar->nw_type = ar->next_mode;
1264
1265 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1266 "%s: connect called with authmode %d dot11 auth %d"
1267 " PW crypto %d PW crypto len %d GRP crypto %d"
1268 " GRP crypto len %d channel hint %u\n",
1269 __func__,
1270 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1271 ar->prwise_crypto_len, ar->grp_crypto,
1272 ar->grp_crpto_len, ar->ch_hint);
1273
1274 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1275 ar->dot11_auth_mode, ar->auth_mode,
1276 ar->prwise_crypto,
1277 ar->prwise_crypto_len,
1278 ar->grp_crypto, ar->grp_crpto_len,
1279 ar->ssid_len, ar->ssid,
1280 ar->req_bssid, ar->ch_hint,
1281 ar->connect_ctrl_flags);
1282 set_bit(CONNECT_PEND, &ar->flag);
1283
1284 return 0;
1285}
1286
1287static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1288 struct net_device *dev)
1289{
1290 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1291
1292 if (!ath6kl_cfg80211_ready(ar))
1293 return -EIO;
1294
1295 ath6kl_disconnect(ar);
1296 memset(ar->ssid, 0, sizeof(ar->ssid));
1297 ar->ssid_len = 0;
1298
1299 return 0;
1300}
1301
1302static const u32 cipher_suites[] = {
1303 WLAN_CIPHER_SUITE_WEP40,
1304 WLAN_CIPHER_SUITE_WEP104,
1305 WLAN_CIPHER_SUITE_TKIP,
1306 WLAN_CIPHER_SUITE_CCMP,
1307};
1308
1309static bool is_rate_legacy(s32 rate)
1310{
1311 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1312 6000, 9000, 12000, 18000, 24000,
1313 36000, 48000, 54000
1314 };
1315 u8 i;
1316
1317 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1318 if (rate == legacy[i])
1319 return true;
1320
1321 return false;
1322}
1323
1324static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1325{
1326 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1327 52000, 58500, 65000, 72200
1328 };
1329 u8 i;
1330
1331 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1332 if (rate == ht20[i]) {
1333 if (i == ARRAY_SIZE(ht20) - 1)
1334 /* last rate uses sgi */
1335 *sgi = true;
1336 else
1337 *sgi = false;
1338
1339 *mcs = i;
1340 return true;
1341 }
1342 }
1343 return false;
1344}
1345
1346static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1347{
1348 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1349 81000, 108000, 121500, 135000,
1350 150000
1351 };
1352 u8 i;
1353
1354 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1355 if (rate == ht40[i]) {
1356 if (i == ARRAY_SIZE(ht40) - 1)
1357 /* last rate uses sgi */
1358 *sgi = true;
1359 else
1360 *sgi = false;
1361
1362 *mcs = i;
1363 return true;
1364 }
1365 }
1366
1367 return false;
1368}
1369
1370static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1371 u8 *mac, struct station_info *sinfo)
1372{
1373 struct ath6kl *ar = ath6kl_priv(dev);
1374 long left;
1375 bool sgi;
1376 s32 rate;
1377 int ret;
1378 u8 mcs;
1379
1380 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1381 return -ENOENT;
1382
1383 if (down_interruptible(&ar->sem))
1384 return -EBUSY;
1385
1386 set_bit(STATS_UPDATE_PEND, &ar->flag);
1387
1388 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1389
1390 if (ret != 0) {
1391 up(&ar->sem);
1392 return -EIO;
1393 }
1394
1395 left = wait_event_interruptible_timeout(ar->event_wq,
1396 !test_bit(STATS_UPDATE_PEND,
1397 &ar->flag),
1398 WMI_TIMEOUT);
1399
1400 up(&ar->sem);
1401
1402 if (left == 0)
1403 return -ETIMEDOUT;
1404 else if (left < 0)
1405 return left;
1406
1407 if (ar->target_stats.rx_byte) {
1408 sinfo->rx_bytes = ar->target_stats.rx_byte;
1409 sinfo->filled |= STATION_INFO_RX_BYTES;
1410 sinfo->rx_packets = ar->target_stats.rx_pkt;
1411 sinfo->filled |= STATION_INFO_RX_PACKETS;
1412 }
1413
1414 if (ar->target_stats.tx_byte) {
1415 sinfo->tx_bytes = ar->target_stats.tx_byte;
1416 sinfo->filled |= STATION_INFO_TX_BYTES;
1417 sinfo->tx_packets = ar->target_stats.tx_pkt;
1418 sinfo->filled |= STATION_INFO_TX_PACKETS;
1419 }
1420
1421 sinfo->signal = ar->target_stats.cs_rssi;
1422 sinfo->filled |= STATION_INFO_SIGNAL;
1423
1424 rate = ar->target_stats.tx_ucast_rate;
1425
1426 if (is_rate_legacy(rate)) {
1427 sinfo->txrate.legacy = rate / 100;
1428 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1429 if (sgi) {
1430 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1431 sinfo->txrate.mcs = mcs - 1;
1432 } else {
1433 sinfo->txrate.mcs = mcs;
1434 }
1435
1436 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1437 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1438 if (sgi) {
1439 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1440 sinfo->txrate.mcs = mcs - 1;
1441 } else {
1442 sinfo->txrate.mcs = mcs;
1443 }
1444
1445 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1446 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1447 } else {
1448 ath6kl_warn("invalid rate: %d\n", rate);
1449 return 0;
1450 }
1451
1452 sinfo->filled |= STATION_INFO_TX_BITRATE;
1453
1454 return 0;
1455}
1456
1457static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1458 struct cfg80211_pmksa *pmksa)
1459{
1460 struct ath6kl *ar = ath6kl_priv(netdev);
1461 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1462 pmksa->pmkid, true);
1463}
1464
1465static int ath6kl_del_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, false);
1471}
1472
1473static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1474{
1475 struct ath6kl *ar = ath6kl_priv(netdev);
1476 if (test_bit(CONNECTED, &ar->flag))
1477 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1478 return 0;
1479}
1480
abcb344b
KV
1481#ifdef CONFIG_PM
1482static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1483 struct cfg80211_wowlan *wow)
1484{
1485 struct ath6kl *ar = wiphy_priv(wiphy);
1486
1487 return ath6kl_hif_suspend(ar);
1488}
1489#endif
1490
6a7c9bad
JM
1491static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1492 struct ieee80211_channel *chan,
1493 enum nl80211_channel_type channel_type)
1494{
1495 struct ath6kl *ar = ath6kl_priv(dev);
1496
1497 if (!ath6kl_cfg80211_ready(ar))
1498 return -EIO;
1499
1500 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1501 __func__, chan->center_freq, chan->hw_value);
1502 ar->next_chan = chan->center_freq;
1503
1504 return 0;
1505}
1506
1507static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1508 struct beacon_parameters *info, bool add)
1509{
1510 struct ath6kl *ar = ath6kl_priv(dev);
1511 struct ieee80211_mgmt *mgmt;
1512 u8 *ies;
1513 int ies_len;
1514 struct wmi_connect_cmd p;
1515 int res;
1516 int i;
1517
1518 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1519
1520 if (!ath6kl_cfg80211_ready(ar))
1521 return -EIO;
1522
1523 if (ar->next_mode != AP_NETWORK)
1524 return -EOPNOTSUPP;
1525
1526 if (info->beacon_ies) {
1527 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1528 info->beacon_ies,
1529 info->beacon_ies_len);
1530 if (res)
1531 return res;
1532 }
1533 if (info->proberesp_ies) {
1534 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1535 info->proberesp_ies,
1536 info->proberesp_ies_len);
1537 if (res)
1538 return res;
1539 }
1540 if (info->assocresp_ies) {
1541 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1542 info->assocresp_ies,
1543 info->assocresp_ies_len);
1544 if (res)
1545 return res;
1546 }
1547
1548 if (!add)
1549 return 0;
1550
9a5b1318
JM
1551 ar->ap_mode_bkey.valid = false;
1552
6a7c9bad
JM
1553 /* TODO:
1554 * info->interval
1555 * info->dtim_period
1556 */
1557
1558 if (info->head == NULL)
1559 return -EINVAL;
1560 mgmt = (struct ieee80211_mgmt *) info->head;
1561 ies = mgmt->u.beacon.variable;
1562 if (ies > info->head + info->head_len)
1563 return -EINVAL;
1564 ies_len = info->head + info->head_len - ies;
1565
1566 if (info->ssid == NULL)
1567 return -EINVAL;
1568 memcpy(ar->ssid, info->ssid, info->ssid_len);
1569 ar->ssid_len = info->ssid_len;
1570 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1571 return -EOPNOTSUPP; /* TODO */
1572
1573 ar->dot11_auth_mode = OPEN_AUTH;
1574
1575 memset(&p, 0, sizeof(p));
1576
1577 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1578 switch (info->crypto.akm_suites[i]) {
1579 case WLAN_AKM_SUITE_8021X:
1580 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1581 p.auth_mode |= WPA_AUTH;
1582 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1583 p.auth_mode |= WPA2_AUTH;
1584 break;
1585 case WLAN_AKM_SUITE_PSK:
1586 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1587 p.auth_mode |= WPA_PSK_AUTH;
1588 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1589 p.auth_mode |= WPA2_PSK_AUTH;
1590 break;
1591 }
1592 }
1593 if (p.auth_mode == 0)
1594 p.auth_mode = NONE_AUTH;
1595 ar->auth_mode = p.auth_mode;
1596
1597 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1598 switch (info->crypto.ciphers_pairwise[i]) {
1599 case WLAN_CIPHER_SUITE_WEP40:
1600 case WLAN_CIPHER_SUITE_WEP104:
1601 p.prwise_crypto_type |= WEP_CRYPT;
1602 break;
1603 case WLAN_CIPHER_SUITE_TKIP:
1604 p.prwise_crypto_type |= TKIP_CRYPT;
1605 break;
1606 case WLAN_CIPHER_SUITE_CCMP:
1607 p.prwise_crypto_type |= AES_CRYPT;
1608 break;
1609 }
1610 }
1611 if (p.prwise_crypto_type == 0)
1612 p.prwise_crypto_type = NONE_CRYPT;
1613
1614 switch (info->crypto.cipher_group) {
1615 case WLAN_CIPHER_SUITE_WEP40:
1616 case WLAN_CIPHER_SUITE_WEP104:
1617 p.grp_crypto_type = WEP_CRYPT;
1618 break;
1619 case WLAN_CIPHER_SUITE_TKIP:
1620 p.grp_crypto_type = TKIP_CRYPT;
1621 break;
1622 case WLAN_CIPHER_SUITE_CCMP:
1623 p.grp_crypto_type = AES_CRYPT;
1624 break;
1625 default:
1626 p.grp_crypto_type = NONE_CRYPT;
1627 break;
1628 }
1629
1630 p.nw_type = AP_NETWORK;
1631 ar->nw_type = ar->next_mode;
1632
1633 p.ssid_len = ar->ssid_len;
1634 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1635 p.dot11_auth_mode = ar->dot11_auth_mode;
1636 p.ch = cpu_to_le16(ar->next_chan);
1637
9a5b1318
JM
1638 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1639 if (res < 0)
1640 return res;
1641
1642 return 0;
6a7c9bad
JM
1643}
1644
1645static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1646 struct beacon_parameters *info)
1647{
1648 return ath6kl_ap_beacon(wiphy, dev, info, true);
1649}
1650
1651static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1652 struct beacon_parameters *info)
1653{
1654 return ath6kl_ap_beacon(wiphy, dev, info, false);
1655}
1656
1657static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1658{
1659 struct ath6kl *ar = ath6kl_priv(dev);
1660
1661 if (ar->nw_type != AP_NETWORK)
1662 return -EOPNOTSUPP;
1663 if (!test_bit(CONNECTED, &ar->flag))
1664 return -ENOTCONN;
1665
1666 ath6kl_wmi_disconnect_cmd(ar->wmi);
1667 clear_bit(CONNECTED, &ar->flag);
1668
1669 return 0;
1670}
1671
23875136
JM
1672static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1673 u8 *mac, struct station_parameters *params)
1674{
1675 struct ath6kl *ar = ath6kl_priv(dev);
1676
1677 if (ar->nw_type != AP_NETWORK)
1678 return -EOPNOTSUPP;
1679
1680 /* Use this only for authorizing/unauthorizing a station */
1681 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1682 return -EOPNOTSUPP;
1683
1684 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1685 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1686 mac, 0);
1687 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1688 0);
1689}
1690
63fa1e0c
JM
1691static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1692 struct net_device *dev,
1693 struct ieee80211_channel *chan,
1694 enum nl80211_channel_type channel_type,
1695 unsigned int duration,
1696 u64 *cookie)
1697{
1698 struct ath6kl *ar = ath6kl_priv(dev);
1699
1700 /* TODO: if already pending or ongoing remain-on-channel,
1701 * return -EBUSY */
1702 *cookie = 1; /* only a single pending request is supported */
1703
1704 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1705 duration);
1706}
1707
1708static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1709 struct net_device *dev,
1710 u64 cookie)
1711{
1712 struct ath6kl *ar = ath6kl_priv(dev);
1713
1714 if (cookie != 1)
1715 return -ENOENT;
1716
1717 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1718}
1719
8a6c8060
JM
1720static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1721 struct ieee80211_channel *chan, bool offchan,
1722 enum nl80211_channel_type channel_type,
1723 bool channel_type_valid, unsigned int wait,
1724 const u8 *buf, size_t len, u64 *cookie)
1725{
1726 struct ath6kl *ar = ath6kl_priv(dev);
1727 u32 id;
1728
1729 id = ar->send_action_id++;
1730 if (id == 0) {
1731 /*
1732 * 0 is a reserved value in the WMI command and shall not be
1733 * used for the command.
1734 */
1735 id = ar->send_action_id++;
1736 }
1737
1738 *cookie = id;
1739 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1740 buf, len);
1741}
1742
ae32c30a
JM
1743static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1744 struct net_device *dev,
1745 u16 frame_type, bool reg)
1746{
1747 struct ath6kl *ar = ath6kl_priv(dev);
1748
1749 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1750 __func__, frame_type, reg);
1751 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1752 /*
1753 * Note: This notification callback is not allowed to sleep, so
1754 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1755 * hardcode target to report Probe Request frames all the time.
1756 */
1757 ar->probe_req_report = reg;
1758 }
1759}
1760
f80574ae
JM
1761static const struct ieee80211_txrx_stypes
1762ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1763 [NL80211_IFTYPE_STATION] = {
1764 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1765 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1766 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1767 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1768 },
1769 [NL80211_IFTYPE_P2P_CLIENT] = {
1770 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1771 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1772 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1773 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1774 },
1775 [NL80211_IFTYPE_P2P_GO] = {
1776 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1777 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1778 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1779 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1780 },
1781};
1782
bdcd8170
KV
1783static struct cfg80211_ops ath6kl_cfg80211_ops = {
1784 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1785 .scan = ath6kl_cfg80211_scan,
1786 .connect = ath6kl_cfg80211_connect,
1787 .disconnect = ath6kl_cfg80211_disconnect,
1788 .add_key = ath6kl_cfg80211_add_key,
1789 .get_key = ath6kl_cfg80211_get_key,
1790 .del_key = ath6kl_cfg80211_del_key,
1791 .set_default_key = ath6kl_cfg80211_set_default_key,
1792 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1793 .set_tx_power = ath6kl_cfg80211_set_txpower,
1794 .get_tx_power = ath6kl_cfg80211_get_txpower,
1795 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1796 .join_ibss = ath6kl_cfg80211_join_ibss,
1797 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1798 .get_station = ath6kl_get_station,
1799 .set_pmksa = ath6kl_set_pmksa,
1800 .del_pmksa = ath6kl_del_pmksa,
1801 .flush_pmksa = ath6kl_flush_pmksa,
abcb344b
KV
1802#ifdef CONFIG_PM
1803 .suspend = ar6k_cfg80211_suspend,
1804#endif
6a7c9bad
JM
1805 .set_channel = ath6kl_set_channel,
1806 .add_beacon = ath6kl_add_beacon,
1807 .set_beacon = ath6kl_set_beacon,
1808 .del_beacon = ath6kl_del_beacon,
23875136 1809 .change_station = ath6kl_change_station,
63fa1e0c
JM
1810 .remain_on_channel = ath6kl_remain_on_channel,
1811 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
8a6c8060 1812 .mgmt_tx = ath6kl_mgmt_tx,
ae32c30a 1813 .mgmt_frame_register = ath6kl_mgmt_frame_register,
bdcd8170
KV
1814};
1815
1816struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1817{
1818 int ret = 0;
1819 struct wireless_dev *wdev;
1820
1821 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1822 if (!wdev) {
1823 ath6kl_err("couldn't allocate wireless device\n");
1824 return NULL;
1825 }
1826
1827 /* create a new wiphy for use with cfg80211 */
1828 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1829 if (!wdev->wiphy) {
1830 ath6kl_err("couldn't allocate wiphy device\n");
1831 kfree(wdev);
1832 return NULL;
1833 }
1834
f80574ae
JM
1835 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1836
63fa1e0c
JM
1837 wdev->wiphy->max_remain_on_channel_duration = 5000;
1838
bdcd8170
KV
1839 /* set device pointer for wiphy */
1840 set_wiphy_dev(wdev->wiphy, dev);
1841
1842 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1843 BIT(NL80211_IFTYPE_ADHOC);
1844 /* max num of ssids that can be probed during scanning */
1845 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
b84da8c7 1846 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
bdcd8170
KV
1847 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1848 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1849 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1850
1851 wdev->wiphy->cipher_suites = cipher_suites;
1852 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1853
1854 ret = wiphy_register(wdev->wiphy);
1855 if (ret < 0) {
1856 ath6kl_err("couldn't register wiphy device\n");
1857 wiphy_free(wdev->wiphy);
1858 kfree(wdev);
1859 return NULL;
1860 }
1861
1862 return wdev;
1863}
1864
1865void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1866{
1867 struct wireless_dev *wdev = ar->wdev;
1868
1869 if (ar->scan_req) {
1870 cfg80211_scan_done(ar->scan_req, true);
1871 ar->scan_req = NULL;
1872 }
1873
1874 if (!wdev)
1875 return;
1876
1877 wiphy_unregister(wdev->wiphy);
1878 wiphy_free(wdev->wiphy);
1879 kfree(wdev);
1880}