blob: 594d246da8e10564b6c4087abe70cb0b8ee8004f [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
Paul Gortmaker6eb07ca2011-09-15 19:46:05 -040017#include <linux/moduleparam.h>
Raja Manic08631c2011-12-16 14:24:24 +053018#include <linux/inetdevice.h>
Kalle Valod6a434d2012-01-17 20:09:36 +020019#include <linux/export.h>
Paul Gortmaker6eb07ca2011-09-15 19:46:05 -040020
Kalle Valobdcd8172011-07-18 00:22:30 +030021#include "core.h"
22#include "cfg80211.h"
23#include "debug.h"
Kalle Valoabcb3442011-07-22 08:26:20 +030024#include "hif-ops.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030025#include "testmode.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030026
27#define RATETAB_ENT(_rate, _rateid, _flags) { \
28 .bitrate = (_rate), \
29 .flags = (_flags), \
30 .hw_value = (_rateid), \
31}
32
33#define CHAN2G(_channel, _freq, _flags) { \
34 .band = IEEE80211_BAND_2GHZ, \
35 .hw_value = (_channel), \
36 .center_freq = (_freq), \
37 .flags = (_flags), \
38 .max_antenna_gain = 0, \
39 .max_power = 30, \
40}
41
42#define CHAN5G(_channel, _flags) { \
43 .band = IEEE80211_BAND_5GHZ, \
44 .hw_value = (_channel), \
45 .center_freq = 5000 + (5 * (_channel)), \
46 .flags = (_flags), \
47 .max_antenna_gain = 0, \
48 .max_power = 30, \
49}
50
51static struct ieee80211_rate ath6kl_rates[] = {
52 RATETAB_ENT(10, 0x1, 0),
53 RATETAB_ENT(20, 0x2, 0),
54 RATETAB_ENT(55, 0x4, 0),
55 RATETAB_ENT(110, 0x8, 0),
56 RATETAB_ENT(60, 0x10, 0),
57 RATETAB_ENT(90, 0x20, 0),
58 RATETAB_ENT(120, 0x40, 0),
59 RATETAB_ENT(180, 0x80, 0),
60 RATETAB_ENT(240, 0x100, 0),
61 RATETAB_ENT(360, 0x200, 0),
62 RATETAB_ENT(480, 0x400, 0),
63 RATETAB_ENT(540, 0x800, 0),
64};
65
66#define ath6kl_a_rates (ath6kl_rates + 4)
67#define ath6kl_a_rates_size 8
68#define ath6kl_g_rates (ath6kl_rates + 0)
69#define ath6kl_g_rates_size 12
70
71static struct ieee80211_channel ath6kl_2ghz_channels[] = {
72 CHAN2G(1, 2412, 0),
73 CHAN2G(2, 2417, 0),
74 CHAN2G(3, 2422, 0),
75 CHAN2G(4, 2427, 0),
76 CHAN2G(5, 2432, 0),
77 CHAN2G(6, 2437, 0),
78 CHAN2G(7, 2442, 0),
79 CHAN2G(8, 2447, 0),
80 CHAN2G(9, 2452, 0),
81 CHAN2G(10, 2457, 0),
82 CHAN2G(11, 2462, 0),
83 CHAN2G(12, 2467, 0),
84 CHAN2G(13, 2472, 0),
85 CHAN2G(14, 2484, 0),
86};
87
88static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
89 CHAN5G(34, 0), CHAN5G(36, 0),
90 CHAN5G(38, 0), CHAN5G(40, 0),
91 CHAN5G(42, 0), CHAN5G(44, 0),
92 CHAN5G(46, 0), CHAN5G(48, 0),
93 CHAN5G(52, 0), CHAN5G(56, 0),
94 CHAN5G(60, 0), CHAN5G(64, 0),
95 CHAN5G(100, 0), CHAN5G(104, 0),
96 CHAN5G(108, 0), CHAN5G(112, 0),
97 CHAN5G(116, 0), CHAN5G(120, 0),
98 CHAN5G(124, 0), CHAN5G(128, 0),
99 CHAN5G(132, 0), CHAN5G(136, 0),
100 CHAN5G(140, 0), CHAN5G(149, 0),
101 CHAN5G(153, 0), CHAN5G(157, 0),
102 CHAN5G(161, 0), CHAN5G(165, 0),
103 CHAN5G(184, 0), CHAN5G(188, 0),
104 CHAN5G(192, 0), CHAN5G(196, 0),
105 CHAN5G(200, 0), CHAN5G(204, 0),
106 CHAN5G(208, 0), CHAN5G(212, 0),
107 CHAN5G(216, 0),
108};
109
110static struct ieee80211_supported_band ath6kl_band_2ghz = {
111 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
112 .channels = ath6kl_2ghz_channels,
113 .n_bitrates = ath6kl_g_rates_size,
114 .bitrates = ath6kl_g_rates,
115};
116
117static struct ieee80211_supported_band ath6kl_band_5ghz = {
118 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
119 .channels = ath6kl_5ghz_a_channels,
120 .n_bitrates = ath6kl_a_rates_size,
121 .bitrates = ath6kl_a_rates,
122};
123
Jouni Malinen837cb972011-10-11 17:31:57 +0300124#define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */
125
Kalle Valo10509f92011-12-13 14:52:07 +0200126/* returns true if scheduled scan was stopped */
127static bool __ath6kl_cfg80211_sscan_stop(struct ath6kl_vif *vif)
128{
129 struct ath6kl *ar = vif->ar;
130
131 if (ar->state != ATH6KL_STATE_SCHED_SCAN)
132 return false;
133
134 del_timer_sync(&vif->sched_scan_timer);
135
136 ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
137 ATH6KL_HOST_MODE_AWAKE);
138
139 ar->state = ATH6KL_STATE_ON;
140
141 return true;
142}
143
144static void ath6kl_cfg80211_sscan_disable(struct ath6kl_vif *vif)
145{
146 struct ath6kl *ar = vif->ar;
147 bool stopped;
148
149 stopped = __ath6kl_cfg80211_sscan_stop(vif);
150
151 if (!stopped)
152 return;
153
154 cfg80211_sched_scan_stopped(ar->wiphy);
155}
156
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530157static int ath6kl_set_wpa_version(struct ath6kl_vif *vif,
Kalle Valobdcd8172011-07-18 00:22:30 +0300158 enum nl80211_wpa_versions wpa_version)
159{
160 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
161
162 if (!wpa_version) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530163 vif->auth_mode = NONE_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300164 } else if (wpa_version & NL80211_WPA_VERSION_2) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530165 vif->auth_mode = WPA2_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300166 } else if (wpa_version & NL80211_WPA_VERSION_1) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530167 vif->auth_mode = WPA_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300168 } else {
169 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
170 return -ENOTSUPP;
171 }
172
173 return 0;
174}
175
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530176static int ath6kl_set_auth_type(struct ath6kl_vif *vif,
Kalle Valobdcd8172011-07-18 00:22:30 +0300177 enum nl80211_auth_type auth_type)
178{
Kalle Valobdcd8172011-07-18 00:22:30 +0300179 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
180
181 switch (auth_type) {
182 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530183 vif->dot11_auth_mode = OPEN_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300184 break;
185 case NL80211_AUTHTYPE_SHARED_KEY:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530186 vif->dot11_auth_mode = SHARED_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300187 break;
188 case NL80211_AUTHTYPE_NETWORK_EAP:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530189 vif->dot11_auth_mode = LEAP_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300190 break;
191
192 case NL80211_AUTHTYPE_AUTOMATIC:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530193 vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300194 break;
195
196 default:
197 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
198 return -ENOTSUPP;
199 }
200
201 return 0;
202}
203
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530204static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast)
Kalle Valobdcd8172011-07-18 00:22:30 +0300205{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530206 u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto;
207 u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len :
208 &vif->grp_crypto_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300209
210 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
211 __func__, cipher, ucast);
212
213 switch (cipher) {
214 case 0:
215 /* our own hack to use value 0 as no crypto used */
216 *ar_cipher = NONE_CRYPT;
217 *ar_cipher_len = 0;
218 break;
219 case WLAN_CIPHER_SUITE_WEP40:
220 *ar_cipher = WEP_CRYPT;
221 *ar_cipher_len = 5;
222 break;
223 case WLAN_CIPHER_SUITE_WEP104:
224 *ar_cipher = WEP_CRYPT;
225 *ar_cipher_len = 13;
226 break;
227 case WLAN_CIPHER_SUITE_TKIP:
228 *ar_cipher = TKIP_CRYPT;
229 *ar_cipher_len = 0;
230 break;
231 case WLAN_CIPHER_SUITE_CCMP:
232 *ar_cipher = AES_CRYPT;
233 *ar_cipher_len = 0;
234 break;
Dai Shuibing5e070212011-11-03 11:39:37 +0200235 case WLAN_CIPHER_SUITE_SMS4:
236 *ar_cipher = WAPI_CRYPT;
237 *ar_cipher_len = 0;
238 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300239 default:
240 ath6kl_err("cipher 0x%x not supported\n", cipher);
241 return -ENOTSUPP;
242 }
243
244 return 0;
245}
246
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530247static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt)
Kalle Valobdcd8172011-07-18 00:22:30 +0300248{
249 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
250
251 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530252 if (vif->auth_mode == WPA_AUTH)
253 vif->auth_mode = WPA_PSK_AUTH;
254 else if (vif->auth_mode == WPA2_AUTH)
255 vif->auth_mode = WPA2_PSK_AUTH;
Jouni Malinen837cb972011-10-11 17:31:57 +0300256 } else if (key_mgmt == 0x00409600) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530257 if (vif->auth_mode == WPA_AUTH)
258 vif->auth_mode = WPA_AUTH_CCKM;
259 else if (vif->auth_mode == WPA2_AUTH)
260 vif->auth_mode = WPA2_AUTH_CCKM;
Kalle Valobdcd8172011-07-18 00:22:30 +0300261 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530262 vif->auth_mode = NONE_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300263 }
264}
265
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530266static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300267{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530268 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530269
Kalle Valobdcd8172011-07-18 00:22:30 +0300270 if (!test_bit(WMI_READY, &ar->flag)) {
271 ath6kl_err("wmi is not ready\n");
272 return false;
273 }
274
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530275 if (!test_bit(WLAN_ENABLED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300276 ath6kl_err("wlan disabled\n");
277 return false;
278 }
279
280 return true;
281}
282
Kevin Fang6981ffd2011-10-07 08:51:19 +0800283static bool ath6kl_is_wpa_ie(const u8 *pos)
284{
285 return pos[0] == WLAN_EID_WPA && pos[1] >= 4 &&
286 pos[2] == 0x00 && pos[3] == 0x50 &&
287 pos[4] == 0xf2 && pos[5] == 0x01;
288}
289
290static bool ath6kl_is_rsn_ie(const u8 *pos)
291{
292 return pos[0] == WLAN_EID_RSN;
293}
294
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700295static bool ath6kl_is_wps_ie(const u8 *pos)
296{
297 return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
298 pos[1] >= 4 &&
299 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
300 pos[5] == 0x04);
301}
302
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530303static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies,
304 size_t ies_len)
Kevin Fang6981ffd2011-10-07 08:51:19 +0800305{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530306 struct ath6kl *ar = vif->ar;
Kevin Fang6981ffd2011-10-07 08:51:19 +0800307 const u8 *pos;
308 u8 *buf = NULL;
309 size_t len = 0;
310 int ret;
311
312 /*
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700313 * Clear previously set flag
314 */
315
316 ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
317
318 /*
Kevin Fang6981ffd2011-10-07 08:51:19 +0800319 * Filter out RSN/WPA IE(s)
320 */
321
322 if (ies && ies_len) {
323 buf = kmalloc(ies_len, GFP_KERNEL);
324 if (buf == NULL)
325 return -ENOMEM;
326 pos = ies;
327
328 while (pos + 1 < ies + ies_len) {
329 if (pos + 2 + pos[1] > ies + ies_len)
330 break;
331 if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) {
332 memcpy(buf + len, pos, 2 + pos[1]);
333 len += 2 + pos[1];
334 }
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700335
336 if (ath6kl_is_wps_ie(pos))
337 ar->connect_ctrl_flags |= CONNECT_WPS_FLAG;
338
Kevin Fang6981ffd2011-10-07 08:51:19 +0800339 pos += 2 + pos[1];
340 }
341 }
342
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530343 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
344 WMI_FRAME_ASSOC_REQ, buf, len);
Kevin Fang6981ffd2011-10-07 08:51:19 +0800345 kfree(buf);
346 return ret;
347}
348
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530349static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type)
350{
351 switch (type) {
352 case NL80211_IFTYPE_STATION:
353 *nw_type = INFRA_NETWORK;
354 break;
355 case NL80211_IFTYPE_ADHOC:
356 *nw_type = ADHOC_NETWORK;
357 break;
358 case NL80211_IFTYPE_AP:
359 *nw_type = AP_NETWORK;
360 break;
361 case NL80211_IFTYPE_P2P_CLIENT:
362 *nw_type = INFRA_NETWORK;
363 break;
364 case NL80211_IFTYPE_P2P_GO:
365 *nw_type = AP_NETWORK;
366 break;
367 default:
368 ath6kl_err("invalid interface type %u\n", type);
369 return -ENOTSUPP;
370 }
371
372 return 0;
373}
374
375static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type,
376 u8 *if_idx, u8 *nw_type)
377{
378 int i;
379
380 if (ath6kl_nliftype_to_drv_iftype(type, nw_type))
381 return false;
382
383 if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) &&
384 ar->num_vif))
385 return false;
386
387 if (type == NL80211_IFTYPE_STATION ||
388 type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) {
Kalle Valo71f96ee2011-11-14 19:31:30 +0200389 for (i = 0; i < ar->vif_max; i++) {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530390 if ((ar->avail_idx_map >> i) & BIT(0)) {
391 *if_idx = i;
392 return true;
393 }
394 }
395 }
396
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530397 if (type == NL80211_IFTYPE_P2P_CLIENT ||
398 type == NL80211_IFTYPE_P2P_GO) {
Kalle Valo71f96ee2011-11-14 19:31:30 +0200399 for (i = ar->max_norm_iface; i < ar->vif_max; i++) {
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530400 if ((ar->avail_idx_map >> i) & BIT(0)) {
401 *if_idx = i;
402 return true;
403 }
404 }
405 }
406
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530407 return false;
408}
409
Kalle Valobdcd8172011-07-18 00:22:30 +0300410static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
411 struct cfg80211_connect_params *sme)
412{
413 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530414 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300415 int status;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800416 u8 nw_subtype = (ar->p2p) ? SUBTYPE_P2PDEV : SUBTYPE_NONE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300417
Kalle Valo10509f92011-12-13 14:52:07 +0200418 ath6kl_cfg80211_sscan_disable(vif);
419
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530420 vif->sme_state = SME_CONNECTING;
Kalle Valobdcd8172011-07-18 00:22:30 +0300421
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530422 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300423 return -EIO;
424
425 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
426 ath6kl_err("destroy in progress\n");
427 return -EBUSY;
428 }
429
430 if (test_bit(SKIP_SCAN, &ar->flag) &&
431 ((sme->channel && sme->channel->center_freq == 0) ||
432 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
433 ath6kl_err("SkipScan: channel or bssid invalid\n");
434 return -EINVAL;
435 }
436
437 if (down_interruptible(&ar->sem)) {
438 ath6kl_err("busy, couldn't get access\n");
439 return -ERESTARTSYS;
440 }
441
442 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
443 ath6kl_err("busy, destroy in progress\n");
444 up(&ar->sem);
445 return -EBUSY;
446 }
447
448 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
449 /*
450 * sleep until the command queue drains
451 */
452 wait_event_interruptible_timeout(ar->event_wq,
453 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
454 WMI_TIMEOUT);
455 if (signal_pending(current)) {
456 ath6kl_err("cmd queue drain timeout\n");
457 up(&ar->sem);
458 return -EINTR;
459 }
460 }
461
Jouni Malinen6e786cb2011-12-15 14:16:00 +0200462 status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len);
463 if (status) {
464 up(&ar->sem);
465 return status;
466 }
467
468 if (sme->ie == NULL || sme->ie_len == 0)
Raja Mani542c5192011-11-15 14:14:56 +0530469 ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
Kevin Fang6981ffd2011-10-07 08:51:19 +0800470
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530471 if (test_bit(CONNECTED, &vif->flags) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530472 vif->ssid_len == sme->ssid_len &&
473 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530474 vif->reconnect_flag = true;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530475 status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx,
476 vif->req_bssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530477 vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300478
479 up(&ar->sem);
480 if (status) {
481 ath6kl_err("wmi_reconnect_cmd failed\n");
482 return -EIO;
483 }
484 return 0;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530485 } else if (vif->ssid_len == sme->ssid_len &&
486 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530487 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300488 }
489
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530490 memset(vif->ssid, 0, sizeof(vif->ssid));
491 vif->ssid_len = sme->ssid_len;
492 memcpy(vif->ssid, sme->ssid, sme->ssid_len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300493
494 if (sme->channel)
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530495 vif->ch_hint = sme->channel->center_freq;
Kalle Valobdcd8172011-07-18 00:22:30 +0300496
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530497 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300498 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530499 memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300500
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530501 ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions);
Kalle Valobdcd8172011-07-18 00:22:30 +0300502
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530503 status = ath6kl_set_auth_type(vif, sme->auth_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300504 if (status) {
505 up(&ar->sem);
506 return status;
507 }
508
509 if (sme->crypto.n_ciphers_pairwise)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530510 ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true);
Kalle Valobdcd8172011-07-18 00:22:30 +0300511 else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530512 ath6kl_set_cipher(vif, 0, true);
Kalle Valobdcd8172011-07-18 00:22:30 +0300513
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530514 ath6kl_set_cipher(vif, sme->crypto.cipher_group, false);
Kalle Valobdcd8172011-07-18 00:22:30 +0300515
516 if (sme->crypto.n_akm_suites)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530517 ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +0300518
519 if ((sme->key_len) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530520 (vif->auth_mode == NONE_AUTH) &&
521 (vif->prwise_crypto == WEP_CRYPT)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300522 struct ath6kl_key *key = NULL;
523
Vivek Natarajan792ecb32011-12-29 16:18:39 +0530524 if (sme->key_idx > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300525 ath6kl_err("key index %d out of bounds\n",
526 sme->key_idx);
527 up(&ar->sem);
528 return -ENOENT;
529 }
530
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530531 key = &vif->keys[sme->key_idx];
Kalle Valobdcd8172011-07-18 00:22:30 +0300532 key->key_len = sme->key_len;
533 memcpy(key->key, sme->key, key->key_len);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530534 key->cipher = vif->prwise_crypto;
535 vif->def_txkey_index = sme->key_idx;
Kalle Valobdcd8172011-07-18 00:22:30 +0300536
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530537 ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530538 vif->prwise_crypto,
Kalle Valobdcd8172011-07-18 00:22:30 +0300539 GROUP_USAGE | TX_USAGE,
540 key->key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200541 NULL, 0,
Kalle Valobdcd8172011-07-18 00:22:30 +0300542 key->key, KEY_OP_INIT_VAL, NULL,
543 NO_SYNC_WMIFLAG);
544 }
545
546 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530547 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530548 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
549 ALL_BSS_FILTER, 0) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300550 ath6kl_err("couldn't set bss filtering\n");
551 up(&ar->sem);
552 return -EIO;
553 }
554 }
555
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530556 vif->nw_type = vif->next_mode;
Kalle Valobdcd8172011-07-18 00:22:30 +0300557
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800558 if (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
559 nw_subtype = SUBTYPE_P2PCLIENT;
560
Kalle Valobdcd8172011-07-18 00:22:30 +0300561 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
562 "%s: connect called with authmode %d dot11 auth %d"
563 " PW crypto %d PW crypto len %d GRP crypto %d"
564 " GRP crypto len %d channel hint %u\n",
565 __func__,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530566 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
567 vif->prwise_crypto_len, vif->grp_crypto,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530568 vif->grp_crypto_len, vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300569
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530570 vif->reconnect_flag = 0;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530571 status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530572 vif->dot11_auth_mode, vif->auth_mode,
573 vif->prwise_crypto,
574 vif->prwise_crypto_len,
575 vif->grp_crypto, vif->grp_crypto_len,
576 vif->ssid_len, vif->ssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530577 vif->req_bssid, vif->ch_hint,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800578 ar->connect_ctrl_flags, nw_subtype);
Kalle Valobdcd8172011-07-18 00:22:30 +0300579
580 up(&ar->sem);
581
582 if (status == -EINVAL) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530583 memset(vif->ssid, 0, sizeof(vif->ssid));
584 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300585 ath6kl_err("invalid request\n");
586 return -ENOENT;
587 } else if (status) {
588 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
589 return -EIO;
590 }
591
592 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530593 ((vif->auth_mode == WPA_PSK_AUTH)
594 || (vif->auth_mode == WPA2_PSK_AUTH))) {
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +0530595 mod_timer(&vif->disconnect_timer,
Kalle Valobdcd8172011-07-18 00:22:30 +0300596 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
597 }
598
599 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530600 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300601
602 return 0;
603}
604
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530605static struct cfg80211_bss *
606ath6kl_add_bss_if_needed(struct ath6kl_vif *vif,
607 enum network_type nw_type,
608 const u8 *bssid,
609 struct ieee80211_channel *chan,
610 const u8 *beacon_ie,
611 size_t beacon_ie_len)
Jouni Malinen01cac472011-09-19 19:14:59 +0300612{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530613 struct ath6kl *ar = vif->ar;
Jouni Malinen01cac472011-09-19 19:14:59 +0300614 struct cfg80211_bss *bss;
Raja Mani4eab6f42011-11-09 17:02:23 +0530615 u16 cap_mask, cap_val;
Jouni Malinen01cac472011-09-19 19:14:59 +0300616 u8 *ie;
617
Raja Mani4eab6f42011-11-09 17:02:23 +0530618 if (nw_type & ADHOC_NETWORK) {
619 cap_mask = WLAN_CAPABILITY_IBSS;
620 cap_val = WLAN_CAPABILITY_IBSS;
621 } else {
622 cap_mask = WLAN_CAPABILITY_ESS;
623 cap_val = WLAN_CAPABILITY_ESS;
624 }
625
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530626 bss = cfg80211_get_bss(ar->wiphy, chan, bssid,
Raja Mani4eab6f42011-11-09 17:02:23 +0530627 vif->ssid, vif->ssid_len,
628 cap_mask, cap_val);
Jouni Malinen01cac472011-09-19 19:14:59 +0300629 if (bss == NULL) {
630 /*
631 * Since cfg80211 may not yet know about the BSS,
632 * generate a partial entry until the first BSS info
633 * event becomes available.
634 *
635 * Prepend SSID element since it is not included in the Beacon
636 * IEs from the target.
637 */
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530638 ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL);
Jouni Malinen01cac472011-09-19 19:14:59 +0300639 if (ie == NULL)
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530640 return NULL;
Jouni Malinen01cac472011-09-19 19:14:59 +0300641 ie[0] = WLAN_EID_SSID;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530642 ie[1] = vif->ssid_len;
643 memcpy(ie + 2, vif->ssid, vif->ssid_len);
644 memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530645 bss = cfg80211_inform_bss(ar->wiphy, chan,
Raja Mani4eab6f42011-11-09 17:02:23 +0530646 bssid, 0, cap_val, 100,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530647 ie, 2 + vif->ssid_len + beacon_ie_len,
Jouni Malinen01cac472011-09-19 19:14:59 +0300648 0, GFP_KERNEL);
649 if (bss)
Raja Mani4eab6f42011-11-09 17:02:23 +0530650 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added bss %pM to "
651 "cfg80211\n", bssid);
Jouni Malinen01cac472011-09-19 19:14:59 +0300652 kfree(ie);
653 } else
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530654 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss\n");
Jouni Malinen01cac472011-09-19 19:14:59 +0300655
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530656 return bss;
Jouni Malinen01cac472011-09-19 19:14:59 +0300657}
658
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530659void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel,
Kalle Valobdcd8172011-07-18 00:22:30 +0300660 u8 *bssid, u16 listen_intvl,
661 u16 beacon_intvl,
662 enum network_type nw_type,
663 u8 beacon_ie_len, u8 assoc_req_len,
664 u8 assoc_resp_len, u8 *assoc_info)
665{
Jouni Malinen01cac472011-09-19 19:14:59 +0300666 struct ieee80211_channel *chan;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530667 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530668 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +0300669
670 /* capinfo + listen interval */
671 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
672
673 /* capinfo + status code + associd */
674 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
675
676 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
677 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
678 assoc_resp_ie_offset;
679
680 assoc_req_len -= assoc_req_ie_offset;
681 assoc_resp_len -= assoc_resp_ie_offset;
682
Jouni Malinen32c10872011-09-19 19:15:07 +0300683 /*
684 * Store Beacon interval here; DTIM period will be available only once
685 * a Beacon frame from the AP is seen.
686 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530687 vif->assoc_bss_beacon_int = beacon_intvl;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530688 clear_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +0300689
Kalle Valobdcd8172011-07-18 00:22:30 +0300690 if (nw_type & ADHOC_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530691 if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300692 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
693 "%s: ath6k not in ibss mode\n", __func__);
694 return;
695 }
696 }
697
698 if (nw_type & INFRA_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530699 if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
700 vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300701 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
702 "%s: ath6k not in station mode\n", __func__);
703 return;
704 }
705 }
706
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530707 chan = ieee80211_get_channel(ar->wiphy, (int) channel);
Kalle Valobdcd8172011-07-18 00:22:30 +0300708
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530709 bss = ath6kl_add_bss_if_needed(vif, nw_type, bssid, chan,
710 assoc_info, beacon_ie_len);
711 if (!bss) {
Raja Mani4eab6f42011-11-09 17:02:23 +0530712 ath6kl_err("could not add cfg80211 bss entry\n");
Kalle Valobdcd8172011-07-18 00:22:30 +0300713 return;
714 }
715
Raja Mani4eab6f42011-11-09 17:02:23 +0530716 if (nw_type & ADHOC_NETWORK) {
717 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
718 nw_type & ADHOC_CREATOR ? "creator" : "joiner");
719 cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530720 cfg80211_put_bss(bss);
Jouni Malinen01cac472011-09-19 19:14:59 +0300721 return;
722 }
723
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530724 if (vif->sme_state == SME_CONNECTING) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300725 /* inform connect result to cfg80211 */
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530726 vif->sme_state = SME_CONNECTED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530727 cfg80211_connect_result(vif->ndev, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300728 assoc_req_ie, assoc_req_len,
729 assoc_resp_ie, assoc_resp_len,
730 WLAN_STATUS_SUCCESS, GFP_KERNEL);
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530731 cfg80211_put_bss(bss);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530732 } else if (vif->sme_state == SME_CONNECTED) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300733 /* inform roam event to cfg80211 */
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530734 cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len,
735 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300736 }
737}
738
739static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
740 struct net_device *dev, u16 reason_code)
741{
Kalle Valod6d5c062011-11-25 13:17:37 +0200742 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530743 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300744
745 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
746 reason_code);
747
Kalle Valo10509f92011-12-13 14:52:07 +0200748 ath6kl_cfg80211_sscan_disable(vif);
749
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530750 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300751 return -EIO;
752
753 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
754 ath6kl_err("busy, destroy in progress\n");
755 return -EBUSY;
756 }
757
758 if (down_interruptible(&ar->sem)) {
759 ath6kl_err("busy, couldn't get access\n");
760 return -ERESTARTSYS;
761 }
762
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530763 vif->reconnect_flag = 0;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530764 ath6kl_disconnect(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530765 memset(vif->ssid, 0, sizeof(vif->ssid));
766 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300767
768 if (!test_bit(SKIP_SCAN, &ar->flag))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530769 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300770
771 up(&ar->sem);
772
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530773 vif->sme_state = SME_DISCONNECTED;
Vasanthakumar Thiagarajan170826d2011-09-10 15:26:35 +0530774
Kalle Valobdcd8172011-07-18 00:22:30 +0300775 return 0;
776}
777
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530778void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300779 u8 *bssid, u8 assoc_resp_len,
780 u8 *assoc_info, u16 proto_reason)
781{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530782 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530783
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530784 if (vif->scan_req) {
785 cfg80211_scan_done(vif->scan_req, true);
786 vif->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300787 }
788
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530789 if (vif->nw_type & ADHOC_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530790 if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300791 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
792 "%s: ath6k not in ibss mode\n", __func__);
793 return;
794 }
795 memset(bssid, 0, ETH_ALEN);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530796 cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300797 return;
798 }
799
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530800 if (vif->nw_type & INFRA_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530801 if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
802 vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300803 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
804 "%s: ath6k not in station mode\n", __func__);
805 return;
806 }
807 }
808
Vasanthakumar Thiagarajan1de547d2011-09-23 10:57:50 +0530809 /*
810 * Send a disconnect command to target when a disconnect event is
811 * received with reason code other than 3 (DISCONNECT_CMD - disconnect
812 * request from host) to make the firmware stop trying to connect even
813 * after giving disconnect event. There will be one more disconnect
814 * event for this disconnect command with reason code DISCONNECT_CMD
815 * which will be notified to cfg80211.
816 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300817
Vasanthakumar Thiagarajan1de547d2011-09-23 10:57:50 +0530818 if (reason != DISCONNECT_CMD) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530819 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300820 return;
821 }
822
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530823 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300824
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530825 if (vif->sme_state == SME_CONNECTING) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530826 cfg80211_connect_result(vif->ndev,
Vasanthakumar Thiagarajanac59a2b2011-09-10 15:26:34 +0530827 bssid, NULL, 0,
828 NULL, 0,
829 WLAN_STATUS_UNSPECIFIED_FAILURE,
830 GFP_KERNEL);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530831 } else if (vif->sme_state == SME_CONNECTED) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530832 cfg80211_disconnected(vif->ndev, reason,
Vasanthakumar Thiagarajanac59a2b2011-09-10 15:26:34 +0530833 NULL, 0, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300834 }
835
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530836 vif->sme_state = SME_DISCONNECTED;
Kalle Valobdcd8172011-07-18 00:22:30 +0300837}
838
Kalle Valobdcd8172011-07-18 00:22:30 +0300839static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
840 struct cfg80211_scan_request *request)
841{
Kalle Valod6d5c062011-11-25 13:17:37 +0200842 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530843 struct ath6kl_vif *vif = netdev_priv(ndev);
Edward Lu1276c9e2011-08-30 21:58:00 +0300844 s8 n_channels = 0;
845 u16 *channels = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300846 int ret = 0;
Vasanthakumar Thiagarajanf1f92172011-10-01 16:12:36 +0530847 u32 force_fg_scan = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300848
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530849 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300850 return -EIO;
851
Kalle Valo10509f92011-12-13 14:52:07 +0200852 ath6kl_cfg80211_sscan_disable(vif);
853
Kalle Valobdcd8172011-07-18 00:22:30 +0300854 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530855 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300856 ret = ath6kl_wmi_bssfilter_cmd(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530857 ar->wmi, vif->fw_vif_idx,
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530858 (test_bit(CONNECTED, &vif->flags) ?
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300859 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
860 if (ret) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300861 ath6kl_err("couldn't set bss filtering\n");
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300862 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300863 }
864 }
865
866 if (request->n_ssids && request->ssids[0].ssid_len) {
867 u8 i;
868
869 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
870 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
871
872 for (i = 0; i < request->n_ssids; i++)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530873 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
874 i + 1, SPECIFIC_SSID_FLAG,
Kalle Valobdcd8172011-07-18 00:22:30 +0300875 request->ssids[i].ssid_len,
876 request->ssids[i].ssid);
877 }
878
Kalle Valo10509f92011-12-13 14:52:07 +0200879 /*
880 * FIXME: we should clear the IE in fw if it's not set so just
881 * remove the check altogether
882 */
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300883 if (request->ie) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530884 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
885 WMI_FRAME_PROBE_REQ,
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300886 request->ie, request->ie_len);
887 if (ret) {
888 ath6kl_err("failed to set Probe Request appie for "
889 "scan");
890 return ret;
891 }
892 }
893
Jouni Malinen11869be2011-09-02 20:07:06 +0300894 /*
895 * Scan only the requested channels if the request specifies a set of
896 * channels. If the list is longer than the target supports, do not
897 * configure the list and instead, scan all available channels.
898 */
899 if (request->n_channels > 0 &&
900 request->n_channels <= WMI_MAX_CHANNELS) {
Edward Lu1276c9e2011-08-30 21:58:00 +0300901 u8 i;
902
Jouni Malinen11869be2011-09-02 20:07:06 +0300903 n_channels = request->n_channels;
Edward Lu1276c9e2011-08-30 21:58:00 +0300904
905 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
906 if (channels == NULL) {
907 ath6kl_warn("failed to set scan channels, "
908 "scan all channels");
909 n_channels = 0;
910 }
911
912 for (i = 0; i < n_channels; i++)
913 channels[i] = request->channels[i]->center_freq;
914 }
915
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530916 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajanf1f92172011-10-01 16:12:36 +0530917 force_fg_scan = 1;
918
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800919 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
920 ar->fw_capabilities)) {
921 /*
922 * If capable of doing P2P mgmt operations using
923 * station interface, send additional information like
924 * supported rates to advertise and xmit rates for
925 * probe requests
926 */
927 ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx,
928 WMI_LONG_SCAN, force_fg_scan,
929 false, 0, 0, n_channels,
930 channels, request->no_cck,
931 request->rates);
932 } else {
933 ret = ath6kl_wmi_startscan_cmd(ar->wmi, vif->fw_vif_idx,
934 WMI_LONG_SCAN, force_fg_scan,
935 false, 0, 0, n_channels,
936 channels);
937 }
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300938 if (ret)
Kalle Valobdcd8172011-07-18 00:22:30 +0300939 ath6kl_err("wmi_startscan_cmd failed\n");
Jouni Malinen11869be2011-09-02 20:07:06 +0300940 else
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530941 vif->scan_req = request;
Kalle Valobdcd8172011-07-18 00:22:30 +0300942
Edward Lu1276c9e2011-08-30 21:58:00 +0300943 kfree(channels);
944
Kalle Valobdcd8172011-07-18 00:22:30 +0300945 return ret;
946}
947
Kalle Valo1c17d312011-11-01 08:43:56 +0200948void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted)
Kalle Valobdcd8172011-07-18 00:22:30 +0300949{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530950 struct ath6kl *ar = vif->ar;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300951 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300952
Kalle Valo1c17d312011-11-01 08:43:56 +0200953 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__,
954 aborted ? " aborted" : "");
Kalle Valobdcd8172011-07-18 00:22:30 +0300955
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530956 if (!vif->scan_req)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300957 return;
Kalle Valobdcd8172011-07-18 00:22:30 +0300958
Kalle Valo1c17d312011-11-01 08:43:56 +0200959 if (aborted)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300960 goto out;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300961
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530962 if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) {
963 for (i = 0; i < vif->scan_req->n_ssids; i++) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530964 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
965 i + 1, DISABLE_SSID_FLAG,
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300966 0, NULL);
967 }
968 }
969
970out:
Kalle Valocb938212011-10-27 18:47:46 +0300971 cfg80211_scan_done(vif->scan_req, aborted);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530972 vif->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300973}
974
975static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
976 u8 key_index, bool pairwise,
977 const u8 *mac_addr,
978 struct key_params *params)
979{
Kalle Valod6d5c062011-11-25 13:17:37 +0200980 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530981 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300982 struct ath6kl_key *key = NULL;
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +0530983 int seq_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300984 u8 key_usage;
985 u8 key_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300986
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530987 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300988 return -EIO;
989
Jouni Malinen837cb972011-10-11 17:31:57 +0300990 if (params->cipher == CCKM_KRK_CIPHER_SUITE) {
991 if (params->key_len != WMI_KRK_LEN)
992 return -EINVAL;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530993 return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx,
994 params->key);
Jouni Malinen837cb972011-10-11 17:31:57 +0300995 }
996
Vivek Natarajan792ecb32011-12-29 16:18:39 +0530997 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300998 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
999 "%s: key index %d out of bounds\n", __func__,
1000 key_index);
1001 return -ENOENT;
1002 }
1003
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301004 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001005 memset(key, 0, sizeof(struct ath6kl_key));
1006
1007 if (pairwise)
1008 key_usage = PAIRWISE_USAGE;
1009 else
1010 key_usage = GROUP_USAGE;
1011
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301012 seq_len = params->seq_len;
1013 if (params->cipher == WLAN_CIPHER_SUITE_SMS4 &&
1014 seq_len > ATH6KL_KEY_SEQ_LEN) {
1015 /* Only first half of the WPI PN is configured */
1016 seq_len = ATH6KL_KEY_SEQ_LEN;
Kalle Valobdcd8172011-07-18 00:22:30 +03001017 }
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301018 if (params->key_len > WLAN_MAX_KEY_LEN ||
1019 seq_len > sizeof(key->seq))
1020 return -EINVAL;
1021
1022 key->key_len = params->key_len;
1023 memcpy(key->key, params->key, key->key_len);
1024 key->seq_len = seq_len;
1025 memcpy(key->seq, params->seq, key->seq_len);
1026 key->cipher = params->cipher;
Kalle Valobdcd8172011-07-18 00:22:30 +03001027
1028 switch (key->cipher) {
1029 case WLAN_CIPHER_SUITE_WEP40:
1030 case WLAN_CIPHER_SUITE_WEP104:
1031 key_type = WEP_CRYPT;
1032 break;
1033
1034 case WLAN_CIPHER_SUITE_TKIP:
1035 key_type = TKIP_CRYPT;
1036 break;
1037
1038 case WLAN_CIPHER_SUITE_CCMP:
1039 key_type = AES_CRYPT;
1040 break;
Dai Shuibing5e070212011-11-03 11:39:37 +02001041 case WLAN_CIPHER_SUITE_SMS4:
1042 key_type = WAPI_CRYPT;
1043 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001044
1045 default:
1046 return -ENOTSUPP;
1047 }
1048
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301049 if (((vif->auth_mode == WPA_PSK_AUTH)
1050 || (vif->auth_mode == WPA2_PSK_AUTH))
Kalle Valobdcd8172011-07-18 00:22:30 +03001051 && (key_usage & GROUP_USAGE))
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301052 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001053
1054 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1055 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
1056 __func__, key_index, key->key_len, key_type,
1057 key_usage, key->seq_len);
1058
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301059 if (vif->nw_type == AP_NETWORK && !pairwise &&
Jouni Malinen47032902011-12-08 16:50:30 +02001060 (key_type == TKIP_CRYPT || key_type == AES_CRYPT ||
1061 key_type == WAPI_CRYPT) && params) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001062 ar->ap_mode_bkey.valid = true;
1063 ar->ap_mode_bkey.key_index = key_index;
1064 ar->ap_mode_bkey.key_type = key_type;
1065 ar->ap_mode_bkey.key_len = key->key_len;
1066 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301067 if (!test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001068 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
1069 "key configuration until AP mode has been "
1070 "started\n");
1071 /*
1072 * The key will be set in ath6kl_connect_ap_mode() once
1073 * the connected event is received from the target.
1074 */
1075 return 0;
1076 }
1077 }
1078
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301079 if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301080 !test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen151411e2011-09-15 15:10:16 +03001081 /*
1082 * Store the key locally so that it can be re-configured after
1083 * the AP mode has properly started
1084 * (ath6kl_install_statioc_wep_keys).
1085 */
1086 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration "
1087 "until AP mode has been started\n");
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301088 vif->wep_key_list[key_index].key_len = key->key_len;
1089 memcpy(vif->wep_key_list[key_index].key, key->key,
1090 key->key_len);
Jouni Malinen151411e2011-09-15 15:10:16 +03001091 return 0;
1092 }
1093
Vasanthakumar Thiagarajan7cefa442011-11-11 20:33:00 +05301094 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, key_index,
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001095 key_type, key_usage, key->key_len,
1096 key->seq, key->seq_len, key->key,
1097 KEY_OP_INIT_VAL,
1098 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001099}
1100
1101static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
1102 u8 key_index, bool pairwise,
1103 const u8 *mac_addr)
1104{
Kalle Valod6d5c062011-11-25 13:17:37 +02001105 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301106 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001107
1108 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1109
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301110 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001111 return -EIO;
1112
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301113 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001114 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1115 "%s: key index %d out of bounds\n", __func__,
1116 key_index);
1117 return -ENOENT;
1118 }
1119
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301120 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001121 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1122 "%s: index %d is empty\n", __func__, key_index);
1123 return 0;
1124 }
1125
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301126 vif->keys[key_index].key_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001127
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301128 return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001129}
1130
1131static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
1132 u8 key_index, bool pairwise,
1133 const u8 *mac_addr, void *cookie,
1134 void (*callback) (void *cookie,
1135 struct key_params *))
1136{
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301137 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001138 struct ath6kl_key *key = NULL;
1139 struct key_params params;
1140
1141 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1142
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301143 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001144 return -EIO;
1145
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301146 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001147 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1148 "%s: key index %d out of bounds\n", __func__,
1149 key_index);
1150 return -ENOENT;
1151 }
1152
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301153 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001154 memset(&params, 0, sizeof(params));
1155 params.cipher = key->cipher;
1156 params.key_len = key->key_len;
1157 params.seq_len = key->seq_len;
1158 params.seq = key->seq;
1159 params.key = key->key;
1160
1161 callback(cookie, &params);
1162
1163 return key->key_len ? 0 : -ENOENT;
1164}
1165
1166static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1167 struct net_device *ndev,
1168 u8 key_index, bool unicast,
1169 bool multicast)
1170{
Kalle Valod6d5c062011-11-25 13:17:37 +02001171 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301172 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001173 struct ath6kl_key *key = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001174 u8 key_usage;
Edward Lu229ed6b2011-08-30 21:58:07 +03001175 enum crypto_type key_type = NONE_CRYPT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001176
1177 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1178
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301179 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001180 return -EIO;
1181
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301182 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001183 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1184 "%s: key index %d out of bounds\n",
1185 __func__, key_index);
1186 return -ENOENT;
1187 }
1188
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301189 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001190 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1191 __func__, key_index);
1192 return -EINVAL;
1193 }
1194
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301195 vif->def_txkey_index = key_index;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301196 key = &vif->keys[vif->def_txkey_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001197 key_usage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301198 if (vif->prwise_crypto == WEP_CRYPT)
Kalle Valobdcd8172011-07-18 00:22:30 +03001199 key_usage |= TX_USAGE;
Edward Lu229ed6b2011-08-30 21:58:07 +03001200 if (unicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301201 key_type = vif->prwise_crypto;
Edward Lu229ed6b2011-08-30 21:58:07 +03001202 if (multicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301203 key_type = vif->grp_crypto;
Kalle Valobdcd8172011-07-18 00:22:30 +03001204
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301205 if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags))
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001206 return 0; /* Delay until AP mode has been started */
1207
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001208 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
1209 vif->def_txkey_index,
1210 key_type, key_usage,
1211 key->key_len, key->seq, key->seq_len,
1212 key->key,
1213 KEY_OP_INIT_VAL, NULL,
1214 SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001215}
1216
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301217void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001218 bool ismcast)
1219{
1220 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1221 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1222
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301223 cfg80211_michael_mic_failure(vif->ndev, vif->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001224 (ismcast ? NL80211_KEYTYPE_GROUP :
1225 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1226 GFP_KERNEL);
1227}
1228
1229static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1230{
1231 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301232 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001233 int ret;
1234
1235 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1236 changed);
1237
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301238 vif = ath6kl_vif_first(ar);
1239 if (!vif)
1240 return -EIO;
1241
1242 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001243 return -EIO;
1244
1245 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1246 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1247 if (ret != 0) {
1248 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1249 return -EIO;
1250 }
1251 }
1252
1253 return 0;
1254}
1255
1256/*
1257 * The type nl80211_tx_power_setting replaces the following
1258 * data type from 2.6.36 onwards
1259*/
1260static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1261 enum nl80211_tx_power_setting type,
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001262 int mbm)
Kalle Valobdcd8172011-07-18 00:22:30 +03001263{
1264 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301265 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001266 u8 ath6kl_dbm;
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001267 int dbm = MBM_TO_DBM(mbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001268
1269 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1270 type, dbm);
1271
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301272 vif = ath6kl_vif_first(ar);
1273 if (!vif)
1274 return -EIO;
1275
1276 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001277 return -EIO;
1278
1279 switch (type) {
1280 case NL80211_TX_POWER_AUTOMATIC:
1281 return 0;
1282 case NL80211_TX_POWER_LIMITED:
1283 ar->tx_pwr = ath6kl_dbm = dbm;
1284 break;
1285 default:
1286 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1287 __func__, type);
1288 return -EOPNOTSUPP;
1289 }
1290
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301291 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, ath6kl_dbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001292
1293 return 0;
1294}
1295
1296static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1297{
1298 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301299 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001300
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301301 vif = ath6kl_vif_first(ar);
1302 if (!vif)
1303 return -EIO;
1304
1305 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001306 return -EIO;
1307
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301308 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001309 ar->tx_pwr = 0;
1310
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301311 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001312 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1313 return -EIO;
1314 }
1315
1316 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1317 5 * HZ);
1318
1319 if (signal_pending(current)) {
1320 ath6kl_err("target did not respond\n");
1321 return -EINTR;
1322 }
1323 }
1324
1325 *dbm = ar->tx_pwr;
1326 return 0;
1327}
1328
1329static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1330 struct net_device *dev,
1331 bool pmgmt, int timeout)
1332{
1333 struct ath6kl *ar = ath6kl_priv(dev);
1334 struct wmi_power_mode_cmd mode;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301335 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001336
1337 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1338 __func__, pmgmt, timeout);
1339
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301340 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001341 return -EIO;
1342
1343 if (pmgmt) {
1344 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1345 mode.pwr_mode = REC_POWER;
1346 } else {
1347 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1348 mode.pwr_mode = MAX_PERF_POWER;
1349 }
1350
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301351 if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx,
1352 mode.pwr_mode) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001353 ath6kl_err("wmi_powermode_cmd failed\n");
1354 return -EIO;
1355 }
1356
1357 return 0;
1358}
1359
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301360static struct net_device *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
1361 char *name,
1362 enum nl80211_iftype type,
1363 u32 *flags,
1364 struct vif_params *params)
1365{
1366 struct ath6kl *ar = wiphy_priv(wiphy);
1367 struct net_device *ndev;
1368 u8 if_idx, nw_type;
1369
Kalle Valo71f96ee2011-11-14 19:31:30 +02001370 if (ar->num_vif == ar->vif_max) {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301371 ath6kl_err("Reached maximum number of supported vif\n");
1372 return ERR_PTR(-EINVAL);
1373 }
1374
1375 if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) {
1376 ath6kl_err("Not a supported interface type\n");
1377 return ERR_PTR(-EINVAL);
1378 }
1379
1380 ndev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
1381 if (!ndev)
1382 return ERR_PTR(-ENOMEM);
1383
1384 ar->num_vif++;
1385
1386 return ndev;
1387}
1388
1389static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy,
1390 struct net_device *ndev)
1391{
1392 struct ath6kl *ar = wiphy_priv(wiphy);
1393 struct ath6kl_vif *vif = netdev_priv(ndev);
1394
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301395 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301396 list_del(&vif->list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301397 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301398
1399 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1400
Kalle Valoc25889e2012-01-17 20:08:27 +02001401 ath6kl_cfg80211_vif_cleanup(vif);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301402
1403 return 0;
1404}
1405
Kalle Valobdcd8172011-07-18 00:22:30 +03001406static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1407 struct net_device *ndev,
1408 enum nl80211_iftype type, u32 *flags,
1409 struct vif_params *params)
1410{
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301411 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001412
1413 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1414
Kalle Valobdcd8172011-07-18 00:22:30 +03001415 switch (type) {
1416 case NL80211_IFTYPE_STATION:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301417 vif->next_mode = INFRA_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001418 break;
1419 case NL80211_IFTYPE_ADHOC:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301420 vif->next_mode = ADHOC_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001421 break;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001422 case NL80211_IFTYPE_AP:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301423 vif->next_mode = AP_NETWORK;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001424 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001425 case NL80211_IFTYPE_P2P_CLIENT:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301426 vif->next_mode = INFRA_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001427 break;
1428 case NL80211_IFTYPE_P2P_GO:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301429 vif->next_mode = AP_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001430 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001431 default:
1432 ath6kl_err("invalid interface type %u\n", type);
1433 return -EOPNOTSUPP;
1434 }
1435
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +05301436 vif->wdev.iftype = type;
Kalle Valobdcd8172011-07-18 00:22:30 +03001437
1438 return 0;
1439}
1440
1441static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1442 struct net_device *dev,
1443 struct cfg80211_ibss_params *ibss_param)
1444{
1445 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301446 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001447 int status;
1448
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301449 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001450 return -EIO;
1451
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301452 vif->ssid_len = ibss_param->ssid_len;
1453 memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001454
1455 if (ibss_param->channel)
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301456 vif->ch_hint = ibss_param->channel->center_freq;
Kalle Valobdcd8172011-07-18 00:22:30 +03001457
1458 if (ibss_param->channel_fixed) {
1459 /*
1460 * TODO: channel_fixed: The channel should be fixed, do not
1461 * search for IBSSs to join on other channels. Target
1462 * firmware does not support this feature, needs to be
1463 * updated.
1464 */
1465 return -EOPNOTSUPP;
1466 }
1467
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301468 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001469 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301470 memcpy(vif->req_bssid, ibss_param->bssid,
1471 sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001472
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301473 ath6kl_set_wpa_version(vif, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001474
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301475 status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
Kalle Valobdcd8172011-07-18 00:22:30 +03001476 if (status)
1477 return status;
1478
1479 if (ibss_param->privacy) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301480 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
1481 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001482 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301483 ath6kl_set_cipher(vif, 0, true);
1484 ath6kl_set_cipher(vif, 0, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001485 }
1486
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301487 vif->nw_type = vif->next_mode;
Kalle Valobdcd8172011-07-18 00:22:30 +03001488
1489 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1490 "%s: connect called with authmode %d dot11 auth %d"
1491 " PW crypto %d PW crypto len %d GRP crypto %d"
1492 " GRP crypto len %d channel hint %u\n",
1493 __func__,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301494 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
1495 vif->prwise_crypto_len, vif->grp_crypto,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301496 vif->grp_crypto_len, vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001497
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301498 status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301499 vif->dot11_auth_mode, vif->auth_mode,
1500 vif->prwise_crypto,
1501 vif->prwise_crypto_len,
1502 vif->grp_crypto, vif->grp_crypto_len,
1503 vif->ssid_len, vif->ssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301504 vif->req_bssid, vif->ch_hint,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001505 ar->connect_ctrl_flags, SUBTYPE_NONE);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301506 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001507
1508 return 0;
1509}
1510
1511static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1512 struct net_device *dev)
1513{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301514 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001515
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301516 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001517 return -EIO;
1518
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301519 ath6kl_disconnect(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301520 memset(vif->ssid, 0, sizeof(vif->ssid));
1521 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001522
1523 return 0;
1524}
1525
1526static const u32 cipher_suites[] = {
1527 WLAN_CIPHER_SUITE_WEP40,
1528 WLAN_CIPHER_SUITE_WEP104,
1529 WLAN_CIPHER_SUITE_TKIP,
1530 WLAN_CIPHER_SUITE_CCMP,
Jouni Malinen837cb972011-10-11 17:31:57 +03001531 CCKM_KRK_CIPHER_SUITE,
Dai Shuibing5e070212011-11-03 11:39:37 +02001532 WLAN_CIPHER_SUITE_SMS4,
Kalle Valobdcd8172011-07-18 00:22:30 +03001533};
1534
1535static bool is_rate_legacy(s32 rate)
1536{
1537 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1538 6000, 9000, 12000, 18000, 24000,
1539 36000, 48000, 54000
1540 };
1541 u8 i;
1542
1543 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1544 if (rate == legacy[i])
1545 return true;
1546
1547 return false;
1548}
1549
1550static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1551{
1552 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1553 52000, 58500, 65000, 72200
1554 };
1555 u8 i;
1556
1557 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1558 if (rate == ht20[i]) {
1559 if (i == ARRAY_SIZE(ht20) - 1)
1560 /* last rate uses sgi */
1561 *sgi = true;
1562 else
1563 *sgi = false;
1564
1565 *mcs = i;
1566 return true;
1567 }
1568 }
1569 return false;
1570}
1571
1572static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1573{
1574 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1575 81000, 108000, 121500, 135000,
1576 150000
1577 };
1578 u8 i;
1579
1580 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1581 if (rate == ht40[i]) {
1582 if (i == ARRAY_SIZE(ht40) - 1)
1583 /* last rate uses sgi */
1584 *sgi = true;
1585 else
1586 *sgi = false;
1587
1588 *mcs = i;
1589 return true;
1590 }
1591 }
1592
1593 return false;
1594}
1595
1596static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1597 u8 *mac, struct station_info *sinfo)
1598{
1599 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301600 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001601 long left;
1602 bool sgi;
1603 s32 rate;
1604 int ret;
1605 u8 mcs;
1606
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301607 if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
Kalle Valobdcd8172011-07-18 00:22:30 +03001608 return -ENOENT;
1609
1610 if (down_interruptible(&ar->sem))
1611 return -EBUSY;
1612
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301613 set_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001614
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301615 ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001616
1617 if (ret != 0) {
1618 up(&ar->sem);
1619 return -EIO;
1620 }
1621
1622 left = wait_event_interruptible_timeout(ar->event_wq,
1623 !test_bit(STATS_UPDATE_PEND,
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301624 &vif->flags),
Kalle Valobdcd8172011-07-18 00:22:30 +03001625 WMI_TIMEOUT);
1626
1627 up(&ar->sem);
1628
1629 if (left == 0)
1630 return -ETIMEDOUT;
1631 else if (left < 0)
1632 return left;
1633
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301634 if (vif->target_stats.rx_byte) {
1635 sinfo->rx_bytes = vif->target_stats.rx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001636 sinfo->filled |= STATION_INFO_RX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301637 sinfo->rx_packets = vif->target_stats.rx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001638 sinfo->filled |= STATION_INFO_RX_PACKETS;
1639 }
1640
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301641 if (vif->target_stats.tx_byte) {
1642 sinfo->tx_bytes = vif->target_stats.tx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001643 sinfo->filled |= STATION_INFO_TX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301644 sinfo->tx_packets = vif->target_stats.tx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001645 sinfo->filled |= STATION_INFO_TX_PACKETS;
1646 }
1647
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301648 sinfo->signal = vif->target_stats.cs_rssi;
Kalle Valobdcd8172011-07-18 00:22:30 +03001649 sinfo->filled |= STATION_INFO_SIGNAL;
1650
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301651 rate = vif->target_stats.tx_ucast_rate;
Kalle Valobdcd8172011-07-18 00:22:30 +03001652
1653 if (is_rate_legacy(rate)) {
1654 sinfo->txrate.legacy = rate / 100;
1655 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1656 if (sgi) {
1657 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1658 sinfo->txrate.mcs = mcs - 1;
1659 } else {
1660 sinfo->txrate.mcs = mcs;
1661 }
1662
1663 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1664 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1665 if (sgi) {
1666 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1667 sinfo->txrate.mcs = mcs - 1;
1668 } else {
1669 sinfo->txrate.mcs = mcs;
1670 }
1671
1672 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1673 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1674 } else {
Kalle Valo9a730832011-09-27 23:33:28 +03001675 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1676 "invalid rate from stats: %d\n", rate);
1677 ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
Kalle Valobdcd8172011-07-18 00:22:30 +03001678 return 0;
1679 }
1680
1681 sinfo->filled |= STATION_INFO_TX_BITRATE;
1682
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301683 if (test_bit(CONNECTED, &vif->flags) &&
1684 test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301685 vif->nw_type == INFRA_NETWORK) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001686 sinfo->filled |= STATION_INFO_BSS_PARAM;
1687 sinfo->bss_param.flags = 0;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301688 sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
1689 sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
Jouni Malinen32c10872011-09-19 19:15:07 +03001690 }
1691
Kalle Valobdcd8172011-07-18 00:22:30 +03001692 return 0;
1693}
1694
1695static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1696 struct cfg80211_pmksa *pmksa)
1697{
1698 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301699 struct ath6kl_vif *vif = netdev_priv(netdev);
1700
1701 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001702 pmksa->pmkid, true);
1703}
1704
1705static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1706 struct cfg80211_pmksa *pmksa)
1707{
1708 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301709 struct ath6kl_vif *vif = netdev_priv(netdev);
1710
1711 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001712 pmksa->pmkid, false);
1713}
1714
1715static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1716{
1717 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301718 struct ath6kl_vif *vif = netdev_priv(netdev);
1719
1720 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301721 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
1722 vif->bssid, NULL, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001723 return 0;
1724}
1725
Raja Mani6cb3c712011-11-07 22:52:45 +02001726static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
1727{
Raja Manic08631c2011-12-16 14:24:24 +05301728 struct in_device *in_dev;
1729 struct in_ifaddr *ifa;
Raja Mani6cb3c712011-11-07 22:52:45 +02001730 struct ath6kl_vif *vif;
1731 int ret, pos, left;
1732 u32 filter = 0;
1733 u16 i;
Raja Manic08631c2011-12-16 14:24:24 +05301734 u8 mask[WOW_MASK_SIZE], index = 0;
1735 __be32 ips[MAX_IP_ADDRS];
Raja Mani6cb3c712011-11-07 22:52:45 +02001736
1737 vif = ath6kl_vif_first(ar);
1738 if (!vif)
1739 return -EIO;
1740
1741 if (!ath6kl_cfg80211_ready(vif))
1742 return -EIO;
1743
1744 if (!test_bit(CONNECTED, &vif->flags))
1745 return -EINVAL;
1746
1747 /* Clear existing WOW patterns */
1748 for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
1749 ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
1750 WOW_LIST_ID, i);
1751 /* Configure new WOW patterns */
1752 for (i = 0; i < wow->n_patterns; i++) {
1753
1754 /*
1755 * Convert given nl80211 specific mask value to equivalent
1756 * driver specific mask value and send it to the chip along
1757 * with patterns. For example, If the mask value defined in
1758 * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
1759 * then equivalent driver specific mask value is
1760 * "0xFF 0x00 0xFF 0x00".
1761 */
1762 memset(&mask, 0, sizeof(mask));
1763 for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
1764 if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
1765 mask[pos] = 0xFF;
1766 }
1767 /*
1768 * Note: Pattern's offset is not passed as part of wowlan
1769 * parameter from CFG layer. So it's always passed as ZERO
1770 * to the firmware. It means, given WOW patterns are always
1771 * matched from the first byte of received pkt in the firmware.
1772 */
1773 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1774 vif->fw_vif_idx, WOW_LIST_ID,
1775 wow->patterns[i].pattern_len,
1776 0 /* pattern offset */,
1777 wow->patterns[i].pattern, mask);
1778 if (ret)
1779 return ret;
1780 }
1781
Raja Manic08631c2011-12-16 14:24:24 +05301782 /* Setup own IP addr for ARP agent. */
1783 in_dev = __in_dev_get_rtnl(vif->ndev);
1784 if (!in_dev)
1785 goto skip_arp;
1786
1787 ifa = in_dev->ifa_list;
1788 memset(&ips, 0, sizeof(ips));
1789
1790 /* Configure IP addr only if IP address count < MAX_IP_ADDRS */
1791 while (index < MAX_IP_ADDRS && ifa) {
1792 ips[index] = ifa->ifa_local;
1793 ifa = ifa->ifa_next;
1794 index++;
1795 }
1796
1797 if (ifa) {
1798 ath6kl_err("total IP addr count is exceeding fw limit\n");
1799 return -EINVAL;
1800 }
1801
1802 ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]);
1803 if (ret) {
1804 ath6kl_err("fail to setup ip for arp agent\n");
1805 return ret;
1806 }
1807
1808skip_arp:
Raja Mani6cb3c712011-11-07 22:52:45 +02001809 if (wow->disconnect)
1810 filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
1811
1812 if (wow->magic_pkt)
1813 filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
1814
1815 if (wow->gtk_rekey_failure)
1816 filter |= WOW_FILTER_OPTION_GTK_ERROR;
1817
1818 if (wow->eap_identity_req)
1819 filter |= WOW_FILTER_OPTION_EAP_REQ;
1820
1821 if (wow->four_way_handshake)
1822 filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
1823
1824 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
1825 ATH6KL_WOW_MODE_ENABLE,
1826 filter,
1827 WOW_HOST_REQ_DELAY);
1828 if (ret)
1829 return ret;
1830
1831 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
1832 ATH6KL_HOST_MODE_ASLEEP);
1833 if (ret)
1834 return ret;
1835
1836 if (ar->tx_pending[ar->ctrl_ep]) {
1837 left = wait_event_interruptible_timeout(ar->event_wq,
1838 ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT);
1839 if (left == 0) {
1840 ath6kl_warn("clear wmi ctrl data timeout\n");
1841 ret = -ETIMEDOUT;
1842 } else if (left < 0) {
1843 ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
1844 ret = left;
1845 }
1846 }
1847
1848 return ret;
1849}
1850
1851static int ath6kl_wow_resume(struct ath6kl *ar)
1852{
1853 struct ath6kl_vif *vif;
1854 int ret;
1855
1856 vif = ath6kl_vif_first(ar);
1857 if (!vif)
1858 return -EIO;
1859
1860 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
1861 ATH6KL_HOST_MODE_AWAKE);
1862 return ret;
1863}
1864
Kalle Valo52d81a62011-11-01 08:44:21 +02001865int ath6kl_cfg80211_suspend(struct ath6kl *ar,
Raja Mani0f60e9f2011-11-07 22:52:45 +02001866 enum ath6kl_cfg_suspend_mode mode,
1867 struct cfg80211_wowlan *wow)
Kalle Valo52d81a62011-11-01 08:44:21 +02001868{
1869 int ret;
1870
Kalle Valo52d81a62011-11-01 08:44:21 +02001871 switch (mode) {
Raja Manid7c44e02011-11-07 22:52:46 +02001872 case ATH6KL_CFG_SUSPEND_WOW:
1873
1874 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
1875
1876 /* Flush all non control pkts in TX path */
1877 ath6kl_tx_data_cleanup(ar);
1878
1879 ret = ath6kl_wow_suspend(ar, wow);
1880 if (ret) {
1881 ath6kl_err("wow suspend failed: %d\n", ret);
1882 return ret;
1883 }
1884 ar->state = ATH6KL_STATE_WOW;
1885 break;
1886
Kalle Valo52d81a62011-11-01 08:44:21 +02001887 case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
Raja Mani524441e2011-11-07 22:52:46 +02001888
Kalle Valo7125f012011-12-13 14:51:37 +02001889 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02001890
Kalle Valo52d81a62011-11-01 08:44:21 +02001891 /* save the current power mode before enabling power save */
1892 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
1893
1894 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
1895 if (ret) {
1896 ath6kl_warn("wmi powermode command failed during suspend: %d\n",
1897 ret);
1898 }
1899
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001900 ar->state = ATH6KL_STATE_DEEPSLEEP;
1901
Kalle Valo52d81a62011-11-01 08:44:21 +02001902 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001903
1904 case ATH6KL_CFG_SUSPEND_CUTPOWER:
Raja Mani524441e2011-11-07 22:52:46 +02001905
Kalle Valo7125f012011-12-13 14:51:37 +02001906 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02001907
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001908 if (ar->state == ATH6KL_STATE_OFF) {
1909 ath6kl_dbg(ATH6KL_DBG_SUSPEND,
1910 "suspend hw off, no action for cutpower\n");
1911 break;
1912 }
1913
1914 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
1915
1916 ret = ath6kl_init_hw_stop(ar);
1917 if (ret) {
1918 ath6kl_warn("failed to stop hw during suspend: %d\n",
1919 ret);
1920 }
1921
1922 ar->state = ATH6KL_STATE_CUTPOWER;
1923
1924 break;
1925
Kalle Valo10509f92011-12-13 14:52:07 +02001926 case ATH6KL_CFG_SUSPEND_SCHED_SCAN:
1927 /*
1928 * Nothing needed for schedule scan, firmware is already in
1929 * wow mode and sleeping most of the time.
1930 */
1931 break;
1932
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001933 default:
1934 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02001935 }
1936
1937 return 0;
1938}
Kalle Valod6a434d2012-01-17 20:09:36 +02001939EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
Kalle Valo52d81a62011-11-01 08:44:21 +02001940
1941int ath6kl_cfg80211_resume(struct ath6kl *ar)
1942{
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001943 int ret;
1944
1945 switch (ar->state) {
Raja Manid7c44e02011-11-07 22:52:46 +02001946 case ATH6KL_STATE_WOW:
1947 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
1948
1949 ret = ath6kl_wow_resume(ar);
1950 if (ret) {
1951 ath6kl_warn("wow mode resume failed: %d\n", ret);
1952 return ret;
1953 }
1954
1955 ar->state = ATH6KL_STATE_ON;
1956 break;
1957
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001958 case ATH6KL_STATE_DEEPSLEEP:
1959 if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
1960 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
1961 ar->wmi->saved_pwr_mode);
1962 if (ret) {
1963 ath6kl_warn("wmi powermode command failed during resume: %d\n",
1964 ret);
1965 }
1966 }
1967
1968 ar->state = ATH6KL_STATE_ON;
1969
1970 break;
1971
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001972 case ATH6KL_STATE_CUTPOWER:
1973 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
1974
1975 ret = ath6kl_init_hw_start(ar);
1976 if (ret) {
1977 ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
1978 return ret;
1979 }
Raja Manid7c44e02011-11-07 22:52:46 +02001980 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02001981
Kalle Valo10509f92011-12-13 14:52:07 +02001982 case ATH6KL_STATE_SCHED_SCAN:
1983 break;
1984
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001985 default:
1986 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02001987 }
1988
1989 return 0;
1990}
Kalle Valod6a434d2012-01-17 20:09:36 +02001991EXPORT_SYMBOL(ath6kl_cfg80211_resume);
Kalle Valo52d81a62011-11-01 08:44:21 +02001992
Kalle Valoabcb3442011-07-22 08:26:20 +03001993#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02001994
1995/* hif layer decides what suspend mode to use */
1996static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
Kalle Valoabcb3442011-07-22 08:26:20 +03001997 struct cfg80211_wowlan *wow)
1998{
1999 struct ath6kl *ar = wiphy_priv(wiphy);
2000
Raja Mani0f60e9f2011-11-07 22:52:45 +02002001 return ath6kl_hif_suspend(ar, wow);
Kalle Valoabcb3442011-07-22 08:26:20 +03002002}
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002003
Kalle Valo52d81a62011-11-01 08:44:21 +02002004static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002005{
2006 struct ath6kl *ar = wiphy_priv(wiphy);
2007
2008 return ath6kl_hif_resume(ar);
2009}
Raja Mania918fb32011-11-07 22:52:46 +02002010
2011/*
2012 * FIXME: WOW suspend mode is selected if the host sdio controller supports
2013 * both sdio irq wake up and keep power. The target pulls sdio data line to
2014 * wake up the host when WOW pattern matches. This causes sdio irq handler
2015 * is being called in the host side which internally hits ath6kl's RX path.
2016 *
2017 * Since sdio interrupt is not disabled, RX path executes even before
2018 * the host executes the actual resume operation from PM module.
2019 *
2020 * In the current scenario, WOW resume should happen before start processing
2021 * any data from the target. So It's required to perform WOW resume in RX path.
2022 * Ideally we should perform WOW resume only in the actual platform
2023 * resume path. This area needs bit rework to avoid WOW resume in RX path.
2024 *
2025 * ath6kl_check_wow_status() is called from ath6kl_rx().
2026 */
2027void ath6kl_check_wow_status(struct ath6kl *ar)
2028{
2029 if (ar->state == ATH6KL_STATE_WOW)
2030 ath6kl_cfg80211_resume(ar);
2031}
2032
2033#else
2034
2035void ath6kl_check_wow_status(struct ath6kl *ar)
2036{
2037}
Kalle Valoabcb3442011-07-22 08:26:20 +03002038#endif
2039
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002040static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
2041 struct ieee80211_channel *chan,
2042 enum nl80211_channel_type channel_type)
2043{
Sujith Manoharane68f6752011-12-22 12:15:27 +05302044 struct ath6kl_vif *vif;
2045
2046 /*
2047 * 'dev' could be NULL if a channel change is required for the hardware
2048 * device itself, instead of a particular VIF.
2049 *
2050 * FIXME: To be handled properly when monitor mode is supported.
2051 */
2052 if (!dev)
2053 return -EBUSY;
2054
2055 vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002056
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302057 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002058 return -EIO;
2059
2060 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
2061 __func__, chan->center_freq, chan->hw_value);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302062 vif->next_chan = chan->center_freq;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002063
2064 return 0;
2065}
2066
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002067static bool ath6kl_is_p2p_ie(const u8 *pos)
2068{
2069 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
2070 pos[2] == 0x50 && pos[3] == 0x6f &&
2071 pos[4] == 0x9a && pos[5] == 0x09;
2072}
2073
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302074static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
2075 const u8 *ies, size_t ies_len)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002076{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302077 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002078 const u8 *pos;
2079 u8 *buf = NULL;
2080 size_t len = 0;
2081 int ret;
2082
2083 /*
2084 * Filter out P2P IE(s) since they will be included depending on
2085 * the Probe Request frame in ath6kl_send_go_probe_resp().
2086 */
2087
2088 if (ies && ies_len) {
2089 buf = kmalloc(ies_len, GFP_KERNEL);
2090 if (buf == NULL)
2091 return -ENOMEM;
2092 pos = ies;
2093 while (pos + 1 < ies + ies_len) {
2094 if (pos + 2 + pos[1] > ies + ies_len)
2095 break;
2096 if (!ath6kl_is_p2p_ie(pos)) {
2097 memcpy(buf + len, pos, 2 + pos[1]);
2098 len += 2 + pos[1];
2099 }
2100 pos += 2 + pos[1];
2101 }
2102 }
2103
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302104 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2105 WMI_FRAME_PROBE_RESP, buf, len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002106 kfree(buf);
2107 return ret;
2108}
2109
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002110static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
2111 struct beacon_parameters *info, bool add)
2112{
2113 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302114 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002115 struct ieee80211_mgmt *mgmt;
2116 u8 *ies;
2117 int ies_len;
2118 struct wmi_connect_cmd p;
2119 int res;
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302120 int i, ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002121
2122 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
2123
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302124 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002125 return -EIO;
2126
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302127 if (vif->next_mode != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002128 return -EOPNOTSUPP;
2129
2130 if (info->beacon_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302131 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2132 WMI_FRAME_BEACON,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002133 info->beacon_ies,
2134 info->beacon_ies_len);
2135 if (res)
2136 return res;
2137 }
2138 if (info->proberesp_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302139 res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002140 info->proberesp_ies_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002141 if (res)
2142 return res;
2143 }
2144 if (info->assocresp_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302145 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2146 WMI_FRAME_ASSOC_RESP,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002147 info->assocresp_ies,
2148 info->assocresp_ies_len);
2149 if (res)
2150 return res;
2151 }
2152
2153 if (!add)
2154 return 0;
2155
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002156 ar->ap_mode_bkey.valid = false;
2157
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002158 /* TODO:
2159 * info->interval
2160 * info->dtim_period
2161 */
2162
2163 if (info->head == NULL)
2164 return -EINVAL;
2165 mgmt = (struct ieee80211_mgmt *) info->head;
2166 ies = mgmt->u.beacon.variable;
2167 if (ies > info->head + info->head_len)
2168 return -EINVAL;
2169 ies_len = info->head + info->head_len - ies;
2170
2171 if (info->ssid == NULL)
2172 return -EINVAL;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302173 memcpy(vif->ssid, info->ssid, info->ssid_len);
2174 vif->ssid_len = info->ssid_len;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002175 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2176 return -EOPNOTSUPP; /* TODO */
2177
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302178 ret = ath6kl_set_auth_type(vif, info->auth_type);
2179 if (ret)
2180 return ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002181
2182 memset(&p, 0, sizeof(p));
2183
2184 for (i = 0; i < info->crypto.n_akm_suites; i++) {
2185 switch (info->crypto.akm_suites[i]) {
2186 case WLAN_AKM_SUITE_8021X:
2187 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2188 p.auth_mode |= WPA_AUTH;
2189 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2190 p.auth_mode |= WPA2_AUTH;
2191 break;
2192 case WLAN_AKM_SUITE_PSK:
2193 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2194 p.auth_mode |= WPA_PSK_AUTH;
2195 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2196 p.auth_mode |= WPA2_PSK_AUTH;
2197 break;
2198 }
2199 }
2200 if (p.auth_mode == 0)
2201 p.auth_mode = NONE_AUTH;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302202 vif->auth_mode = p.auth_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002203
2204 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
2205 switch (info->crypto.ciphers_pairwise[i]) {
2206 case WLAN_CIPHER_SUITE_WEP40:
2207 case WLAN_CIPHER_SUITE_WEP104:
2208 p.prwise_crypto_type |= WEP_CRYPT;
2209 break;
2210 case WLAN_CIPHER_SUITE_TKIP:
2211 p.prwise_crypto_type |= TKIP_CRYPT;
2212 break;
2213 case WLAN_CIPHER_SUITE_CCMP:
2214 p.prwise_crypto_type |= AES_CRYPT;
2215 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002216 case WLAN_CIPHER_SUITE_SMS4:
2217 p.prwise_crypto_type |= WAPI_CRYPT;
2218 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002219 }
2220 }
Edward Lu229ed6b2011-08-30 21:58:07 +03002221 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002222 p.prwise_crypto_type = NONE_CRYPT;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302223 ath6kl_set_cipher(vif, 0, true);
Edward Lu229ed6b2011-08-30 21:58:07 +03002224 } else if (info->crypto.n_ciphers_pairwise == 1)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302225 ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002226
2227 switch (info->crypto.cipher_group) {
2228 case WLAN_CIPHER_SUITE_WEP40:
2229 case WLAN_CIPHER_SUITE_WEP104:
2230 p.grp_crypto_type = WEP_CRYPT;
2231 break;
2232 case WLAN_CIPHER_SUITE_TKIP:
2233 p.grp_crypto_type = TKIP_CRYPT;
2234 break;
2235 case WLAN_CIPHER_SUITE_CCMP:
2236 p.grp_crypto_type = AES_CRYPT;
2237 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002238 case WLAN_CIPHER_SUITE_SMS4:
2239 p.grp_crypto_type = WAPI_CRYPT;
2240 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002241 default:
2242 p.grp_crypto_type = NONE_CRYPT;
2243 break;
2244 }
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302245 ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002246
2247 p.nw_type = AP_NETWORK;
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302248 vif->nw_type = vif->next_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002249
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302250 p.ssid_len = vif->ssid_len;
2251 memcpy(p.ssid, vif->ssid, vif->ssid_len);
2252 p.dot11_auth_mode = vif->dot11_auth_mode;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302253 p.ch = cpu_to_le16(vif->next_chan);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002254
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05302255 /* Enable uAPSD support by default */
2256 res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
2257 if (res < 0)
2258 return res;
2259
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002260 if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
2261 p.nw_subtype = SUBTYPE_P2PGO;
2262 } else {
2263 /*
2264 * Due to firmware limitation, it is not possible to
2265 * do P2P mgmt operations in AP mode
2266 */
2267 p.nw_subtype = SUBTYPE_NONE;
2268 }
2269
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302270 res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002271 if (res < 0)
2272 return res;
2273
2274 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002275}
2276
2277static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
2278 struct beacon_parameters *info)
2279{
2280 return ath6kl_ap_beacon(wiphy, dev, info, true);
2281}
2282
2283static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
2284 struct beacon_parameters *info)
2285{
2286 return ath6kl_ap_beacon(wiphy, dev, info, false);
2287}
2288
2289static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
2290{
2291 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302292 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002293
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302294 if (vif->nw_type != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002295 return -EOPNOTSUPP;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302296 if (!test_bit(CONNECTED, &vif->flags))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002297 return -ENOTCONN;
2298
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302299 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302300 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002301
2302 return 0;
2303}
2304
Jouni Malinen33e53082011-12-27 11:02:56 +02002305static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2306
2307static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
2308 u8 *mac)
2309{
2310 struct ath6kl *ar = ath6kl_priv(dev);
2311 struct ath6kl_vif *vif = netdev_priv(dev);
2312 const u8 *addr = mac ? mac : bcast_addr;
2313
2314 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
2315 addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
2316}
2317
Jouni Malinen23875132011-08-30 21:57:53 +03002318static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
2319 u8 *mac, struct station_parameters *params)
2320{
2321 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302322 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen23875132011-08-30 21:57:53 +03002323
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302324 if (vif->nw_type != AP_NETWORK)
Jouni Malinen23875132011-08-30 21:57:53 +03002325 return -EOPNOTSUPP;
2326
2327 /* Use this only for authorizing/unauthorizing a station */
2328 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
2329 return -EOPNOTSUPP;
2330
2331 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302332 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2333 WMI_AP_MLME_AUTHORIZE, mac, 0);
2334 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2335 WMI_AP_MLME_UNAUTHORIZE, mac, 0);
Jouni Malinen23875132011-08-30 21:57:53 +03002336}
2337
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002338static int ath6kl_remain_on_channel(struct wiphy *wiphy,
2339 struct net_device *dev,
2340 struct ieee80211_channel *chan,
2341 enum nl80211_channel_type channel_type,
2342 unsigned int duration,
2343 u64 *cookie)
2344{
2345 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302346 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen10522612011-10-27 16:00:13 +03002347 u32 id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002348
2349 /* TODO: if already pending or ongoing remain-on-channel,
2350 * return -EBUSY */
Jouni Malinen10522612011-10-27 16:00:13 +03002351 id = ++vif->last_roc_id;
2352 if (id == 0) {
2353 /* Do not use 0 as the cookie value */
2354 id = ++vif->last_roc_id;
2355 }
2356 *cookie = id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002357
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302358 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
2359 chan->center_freq, duration);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002360}
2361
2362static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
2363 struct net_device *dev,
2364 u64 cookie)
2365{
2366 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302367 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002368
Jouni Malinen10522612011-10-27 16:00:13 +03002369 if (cookie != vif->last_roc_id)
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002370 return -ENOENT;
Jouni Malinen10522612011-10-27 16:00:13 +03002371 vif->last_cancel_roc_id = cookie;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002372
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302373 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002374}
2375
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302376static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
2377 const u8 *buf, size_t len,
2378 unsigned int freq)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002379{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302380 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002381 const u8 *pos;
2382 u8 *p2p;
2383 int p2p_len;
2384 int ret;
2385 const struct ieee80211_mgmt *mgmt;
2386
2387 mgmt = (const struct ieee80211_mgmt *) buf;
2388
2389 /* Include P2P IE(s) from the frame generated in user space. */
2390
2391 p2p = kmalloc(len, GFP_KERNEL);
2392 if (p2p == NULL)
2393 return -ENOMEM;
2394 p2p_len = 0;
2395
2396 pos = mgmt->u.probe_resp.variable;
2397 while (pos + 1 < buf + len) {
2398 if (pos + 2 + pos[1] > buf + len)
2399 break;
2400 if (ath6kl_is_p2p_ie(pos)) {
2401 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
2402 p2p_len += 2 + pos[1];
2403 }
2404 pos += 2 + pos[1];
2405 }
2406
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302407 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
2408 mgmt->da, p2p, p2p_len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002409 kfree(p2p);
2410 return ret;
2411}
2412
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002413static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2414 struct ieee80211_channel *chan, bool offchan,
2415 enum nl80211_channel_type channel_type,
2416 bool channel_type_valid, unsigned int wait,
Johannes Berge247bd902011-11-04 11:18:21 +01002417 const u8 *buf, size_t len, bool no_cck,
2418 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002419{
2420 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302421 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002422 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002423 const struct ieee80211_mgmt *mgmt;
2424
2425 mgmt = (const struct ieee80211_mgmt *) buf;
2426 if (buf + len >= mgmt->u.probe_resp.variable &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302427 vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002428 ieee80211_is_probe_resp(mgmt->frame_control)) {
2429 /*
2430 * Send Probe Response frame in AP mode using a separate WMI
2431 * command to allow the target to fill in the generic IEs.
2432 */
2433 *cookie = 0; /* TX status not supported */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302434 return ath6kl_send_go_probe_resp(vif, buf, len,
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002435 chan->center_freq);
2436 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002437
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302438 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002439 if (id == 0) {
2440 /*
2441 * 0 is a reserved value in the WMI command and shall not be
2442 * used for the command.
2443 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302444 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002445 }
2446
2447 *cookie = id;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002448
2449 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
2450 ar->fw_capabilities)) {
2451 /*
2452 * If capable of doing P2P mgmt operations using
2453 * station interface, send additional information like
2454 * supported rates to advertise and xmit rates for
2455 * probe requests
2456 */
2457 return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id,
2458 chan->center_freq, wait,
2459 buf, len, no_cck);
2460 } else {
2461 return ath6kl_wmi_send_action_cmd(ar->wmi, vif->fw_vif_idx, id,
2462 chan->center_freq, wait,
2463 buf, len);
2464 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002465}
2466
Jouni Malinenae32c302011-08-30 21:58:01 +03002467static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
2468 struct net_device *dev,
2469 u16 frame_type, bool reg)
2470{
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302471 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinenae32c302011-08-30 21:58:01 +03002472
2473 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
2474 __func__, frame_type, reg);
2475 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
2476 /*
2477 * Note: This notification callback is not allowed to sleep, so
2478 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
2479 * hardcode target to report Probe Request frames all the time.
2480 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302481 vif->probe_req_report = reg;
Jouni Malinenae32c302011-08-30 21:58:01 +03002482 }
2483}
2484
Kalle Valo10509f92011-12-13 14:52:07 +02002485static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
2486 struct net_device *dev,
2487 struct cfg80211_sched_scan_request *request)
2488{
2489 struct ath6kl *ar = ath6kl_priv(dev);
2490 struct ath6kl_vif *vif = netdev_priv(dev);
2491 u16 interval;
2492 int ret;
2493 u8 i;
2494
2495 if (ar->state != ATH6KL_STATE_ON)
2496 return -EIO;
2497
2498 if (vif->sme_state != SME_DISCONNECTED)
2499 return -EBUSY;
2500
2501 for (i = 0; i < ar->wiphy->max_sched_scan_ssids; i++) {
2502 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2503 i, DISABLE_SSID_FLAG,
2504 0, NULL);
2505 }
2506
2507 /* fw uses seconds, also make sure that it's >0 */
2508 interval = max_t(u16, 1, request->interval / 1000);
2509
2510 ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
2511 interval, interval,
2512 10, 0, 0, 0, 3, 0, 0, 0);
2513
2514 if (request->n_ssids && request->ssids[0].ssid_len) {
2515 for (i = 0; i < request->n_ssids; i++) {
2516 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2517 i, SPECIFIC_SSID_FLAG,
2518 request->ssids[i].ssid_len,
2519 request->ssids[i].ssid);
2520 }
2521 }
2522
2523 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
2524 ATH6KL_WOW_MODE_ENABLE,
2525 WOW_FILTER_SSID,
2526 WOW_HOST_REQ_DELAY);
2527 if (ret) {
2528 ath6kl_warn("Failed to enable wow with ssid filter: %d\n", ret);
2529 return ret;
2530 }
2531
2532 /* this also clears IE in fw if it's not set */
2533 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2534 WMI_FRAME_PROBE_REQ,
2535 request->ie, request->ie_len);
2536 if (ret) {
2537 ath6kl_warn("Failed to set probe request IE for scheduled scan: %d",
2538 ret);
2539 return ret;
2540 }
2541
2542 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
2543 ATH6KL_HOST_MODE_ASLEEP);
2544 if (ret) {
2545 ath6kl_warn("Failed to enable host sleep mode for sched scan: %d\n",
2546 ret);
2547 return ret;
2548 }
2549
2550 ar->state = ATH6KL_STATE_SCHED_SCAN;
2551
2552 return ret;
2553}
2554
2555static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy,
2556 struct net_device *dev)
2557{
2558 struct ath6kl_vif *vif = netdev_priv(dev);
2559 bool stopped;
2560
2561 stopped = __ath6kl_cfg80211_sscan_stop(vif);
2562
2563 if (!stopped)
2564 return -EIO;
2565
2566 return 0;
2567}
2568
Jouni Malinenf80574a2011-08-30 21:58:04 +03002569static const struct ieee80211_txrx_stypes
2570ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
2571 [NL80211_IFTYPE_STATION] = {
2572 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2573 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2574 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2575 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2576 },
Jouni Malinenba1f6fe2011-12-27 11:03:53 +02002577 [NL80211_IFTYPE_AP] = {
2578 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2579 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2580 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2581 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2582 },
Jouni Malinenf80574a2011-08-30 21:58:04 +03002583 [NL80211_IFTYPE_P2P_CLIENT] = {
2584 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2585 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2586 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2587 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2588 },
2589 [NL80211_IFTYPE_P2P_GO] = {
2590 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2591 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2592 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2593 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2594 },
2595};
2596
Kalle Valobdcd8172011-07-18 00:22:30 +03002597static struct cfg80211_ops ath6kl_cfg80211_ops = {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302598 .add_virtual_intf = ath6kl_cfg80211_add_iface,
2599 .del_virtual_intf = ath6kl_cfg80211_del_iface,
Kalle Valobdcd8172011-07-18 00:22:30 +03002600 .change_virtual_intf = ath6kl_cfg80211_change_iface,
2601 .scan = ath6kl_cfg80211_scan,
2602 .connect = ath6kl_cfg80211_connect,
2603 .disconnect = ath6kl_cfg80211_disconnect,
2604 .add_key = ath6kl_cfg80211_add_key,
2605 .get_key = ath6kl_cfg80211_get_key,
2606 .del_key = ath6kl_cfg80211_del_key,
2607 .set_default_key = ath6kl_cfg80211_set_default_key,
2608 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
2609 .set_tx_power = ath6kl_cfg80211_set_txpower,
2610 .get_tx_power = ath6kl_cfg80211_get_txpower,
2611 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
2612 .join_ibss = ath6kl_cfg80211_join_ibss,
2613 .leave_ibss = ath6kl_cfg80211_leave_ibss,
2614 .get_station = ath6kl_get_station,
2615 .set_pmksa = ath6kl_set_pmksa,
2616 .del_pmksa = ath6kl_del_pmksa,
2617 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03002618 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03002619#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02002620 .suspend = __ath6kl_cfg80211_suspend,
2621 .resume = __ath6kl_cfg80211_resume,
Kalle Valoabcb3442011-07-22 08:26:20 +03002622#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002623 .set_channel = ath6kl_set_channel,
2624 .add_beacon = ath6kl_add_beacon,
2625 .set_beacon = ath6kl_set_beacon,
2626 .del_beacon = ath6kl_del_beacon,
Jouni Malinen33e53082011-12-27 11:02:56 +02002627 .del_station = ath6kl_del_station,
Jouni Malinen23875132011-08-30 21:57:53 +03002628 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002629 .remain_on_channel = ath6kl_remain_on_channel,
2630 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002631 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03002632 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valo10509f92011-12-13 14:52:07 +02002633 .sched_scan_start = ath6kl_cfg80211_sscan_start,
2634 .sched_scan_stop = ath6kl_cfg80211_sscan_stop,
Kalle Valobdcd8172011-07-18 00:22:30 +03002635};
2636
Kalle Valo7125f012011-12-13 14:51:37 +02002637void ath6kl_cfg80211_stop(struct ath6kl_vif *vif)
Kalle Valoec4b7f62011-11-01 08:44:04 +02002638{
Kalle Valo10509f92011-12-13 14:52:07 +02002639 ath6kl_cfg80211_sscan_disable(vif);
2640
Kalle Valoec4b7f62011-11-01 08:44:04 +02002641 switch (vif->sme_state) {
Kalle Valoc97a31b2011-12-13 14:51:10 +02002642 case SME_DISCONNECTED:
2643 break;
Kalle Valoec4b7f62011-11-01 08:44:04 +02002644 case SME_CONNECTING:
2645 cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
2646 NULL, 0,
2647 WLAN_STATUS_UNSPECIFIED_FAILURE,
2648 GFP_KERNEL);
2649 break;
2650 case SME_CONNECTED:
Kalle Valoec4b7f62011-11-01 08:44:04 +02002651 cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
2652 break;
2653 }
2654
2655 if (test_bit(CONNECTED, &vif->flags) ||
2656 test_bit(CONNECT_PEND, &vif->flags))
Kalle Valo7125f012011-12-13 14:51:37 +02002657 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002658
2659 vif->sme_state = SME_DISCONNECTED;
Kalle Valo1f40525512011-11-01 08:44:13 +02002660 clear_bit(CONNECTED, &vif->flags);
2661 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002662
2663 /* disable scanning */
Kalle Valo7125f012011-12-13 14:51:37 +02002664 if (ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF,
2665 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0)
2666 ath6kl_warn("failed to disable scan during stop\n");
Kalle Valoec4b7f62011-11-01 08:44:04 +02002667
2668 ath6kl_cfg80211_scan_complete_event(vif, true);
2669}
2670
Kalle Valo7125f012011-12-13 14:51:37 +02002671void ath6kl_cfg80211_stop_all(struct ath6kl *ar)
2672{
2673 struct ath6kl_vif *vif;
2674
2675 vif = ath6kl_vif_first(ar);
2676 if (!vif) {
2677 /* save the current power mode before enabling power save */
2678 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
2679
2680 if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
2681 ath6kl_warn("ath6kl_deep_sleep_enable: "
2682 "wmi_powermode_cmd failed\n");
2683 return;
2684 }
2685
2686 /*
2687 * FIXME: we should take ar->list_lock to protect changes in the
2688 * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop()
2689 * sleeps.
2690 */
2691 list_for_each_entry(vif, &ar->vif_list, list)
2692 ath6kl_cfg80211_stop(vif);
2693}
2694
Kalle Valoc25889e2012-01-17 20:08:27 +02002695static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03002696{
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302697 vif->aggr_cntxt = aggr_init(vif->ndev);
2698 if (!vif->aggr_cntxt) {
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302699 ath6kl_err("failed to initialize aggr\n");
2700 return -ENOMEM;
2701 }
Kalle Valobdcd8172011-07-18 00:22:30 +03002702
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302703 setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302704 (unsigned long) vif->ndev);
Kalle Valo10509f92011-12-13 14:52:07 +02002705 setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer,
2706 (unsigned long) vif);
2707
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302708 set_bit(WMM_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05302709 spin_lock_init(&vif->if_lock);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302710
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302711 INIT_LIST_HEAD(&vif->mc_filter);
2712
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302713 return 0;
2714}
2715
Kalle Valoc25889e2012-01-17 20:08:27 +02002716void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302717{
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302718 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302719 struct ath6kl_mc_filter *mc_filter, *tmp;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302720
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302721 aggr_module_destroy(vif->aggr_cntxt);
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302722
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302723 ar->avail_idx_map |= BIT(vif->fw_vif_idx);
2724
2725 if (vif->nw_type == ADHOC_NETWORK)
2726 ar->ibss_if_active = false;
2727
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302728 list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
2729 list_del(&mc_filter->list);
2730 kfree(mc_filter);
2731 }
2732
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05302733 unregister_netdevice(vif->ndev);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302734
2735 ar->num_vif--;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302736}
2737
2738struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name,
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302739 enum nl80211_iftype type, u8 fw_vif_idx,
2740 u8 nw_type)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302741{
2742 struct net_device *ndev;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302743 struct ath6kl_vif *vif;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302744
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302745 ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302746 if (!ndev)
2747 return NULL;
2748
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302749 vif = netdev_priv(ndev);
2750 ndev->ieee80211_ptr = &vif->wdev;
2751 vif->wdev.wiphy = ar->wiphy;
2752 vif->ar = ar;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302753 vif->ndev = ndev;
2754 SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
2755 vif->wdev.netdev = ndev;
2756 vif->wdev.iftype = type;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302757 vif->fw_vif_idx = fw_vif_idx;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302758 vif->nw_type = vif->next_mode = nw_type;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302759
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302760 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
2761 if (fw_vif_idx != 0)
2762 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
2763 0x2;
2764
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302765 init_netdev(ndev);
2766
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +05302767 ath6kl_init_control_info(vif);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302768
Kalle Valoc25889e2012-01-17 20:08:27 +02002769 if (ath6kl_cfg80211_vif_init(vif))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302770 goto err;
2771
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05302772 if (register_netdevice(ndev))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302773 goto err;
2774
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302775 ar->avail_idx_map &= ~BIT(fw_vif_idx);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +05302776 vif->sme_state = SME_DISCONNECTED;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302777 set_bit(WLAN_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302778 ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302779 set_bit(NETDEV_REGISTERED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302780
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302781 if (type == NL80211_IFTYPE_ADHOC)
2782 ar->ibss_if_active = true;
2783
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05302784 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302785 list_add_tail(&vif->list, &ar->vif_list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05302786 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302787
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302788 return ndev;
2789
2790err:
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05302791 aggr_module_destroy(vif->aggr_cntxt);
2792 free_netdev(ndev);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302793 return NULL;
2794}
2795
Kalle Valo46d33a22012-01-17 20:08:40 +02002796int ath6kl_cfg80211_init(struct ath6kl *ar)
2797{
2798 struct wiphy *wiphy = ar->wiphy;
2799 int ret;
2800
2801 wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
2802
2803 wiphy->max_remain_on_channel_duration = 5000;
2804
2805 /* set device pointer for wiphy */
2806 set_wiphy_dev(wiphy, ar->dev);
2807
2808 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2809 BIT(NL80211_IFTYPE_ADHOC) |
2810 BIT(NL80211_IFTYPE_AP);
2811 if (ar->p2p) {
2812 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
2813 BIT(NL80211_IFTYPE_P2P_CLIENT);
2814 }
2815
2816 /* max num of ssids that can be probed during scanning */
2817 wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
2818 wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
2819 wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
2820 wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
2821 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2822
2823 wiphy->cipher_suites = cipher_suites;
2824 wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2825
2826 wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
2827 WIPHY_WOWLAN_DISCONNECT |
2828 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
2829 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
2830 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
2831 WIPHY_WOWLAN_4WAY_HANDSHAKE;
2832 wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST;
2833 wiphy->wowlan.pattern_min_len = 1;
2834 wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE;
2835
2836 wiphy->max_sched_scan_ssids = 10;
2837
2838 ret = wiphy_register(wiphy);
2839 if (ret < 0) {
2840 ath6kl_err("couldn't register wiphy device\n");
2841 return ret;
2842 }
2843
2844 return 0;
2845}
2846
2847void ath6kl_cfg80211_cleanup(struct ath6kl *ar)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302848{
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05302849 wiphy_unregister(ar->wiphy);
Kalle Valo45eaa782012-01-17 20:09:05 +02002850}
Kalle Valo46d33a22012-01-17 20:08:40 +02002851
Kalle Valo45eaa782012-01-17 20:09:05 +02002852struct ath6kl *ath6kl_cfg80211_create(void)
2853{
2854 struct ath6kl *ar;
2855 struct wiphy *wiphy;
2856
2857 /* create a new wiphy for use with cfg80211 */
2858 wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
2859
2860 if (!wiphy) {
2861 ath6kl_err("couldn't allocate wiphy device\n");
2862 return NULL;
2863 }
2864
2865 ar = wiphy_priv(wiphy);
2866 ar->wiphy = wiphy;
2867
2868 return ar;
2869}
2870
2871/* Note: ar variable must not be accessed after calling this! */
2872void ath6kl_cfg80211_destroy(struct ath6kl *ar)
2873{
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05302874 wiphy_free(ar->wiphy);
Kalle Valobdcd8172011-07-18 00:22:30 +03002875}
Kalle Valo45eaa782012-01-17 20:09:05 +02002876