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