blob: 528529406e490deee900e1e3a2844f1709c69ff8 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajan1b2df402012-02-06 20:15:53 +05303 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valobdcd8172011-07-18 00:22:30 +03004 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
Paul Gortmaker6eb07ca2011-09-15 19:46:05 -040018#include <linux/moduleparam.h>
Raja Manic08631c2011-12-16 14:24:24 +053019#include <linux/inetdevice.h>
Kalle Valod6a434d2012-01-17 20:09:36 +020020#include <linux/export.h>
Paul Gortmaker6eb07ca2011-09-15 19:46:05 -040021
Kalle Valobdcd8172011-07-18 00:22:30 +030022#include "core.h"
23#include "cfg80211.h"
24#include "debug.h"
Kalle Valoabcb3442011-07-22 08:26:20 +030025#include "hif-ops.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030026#include "testmode.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030027
28#define RATETAB_ENT(_rate, _rateid, _flags) { \
29 .bitrate = (_rate), \
30 .flags = (_flags), \
31 .hw_value = (_rateid), \
32}
33
34#define CHAN2G(_channel, _freq, _flags) { \
35 .band = IEEE80211_BAND_2GHZ, \
36 .hw_value = (_channel), \
37 .center_freq = (_freq), \
38 .flags = (_flags), \
39 .max_antenna_gain = 0, \
40 .max_power = 30, \
41}
42
43#define CHAN5G(_channel, _flags) { \
44 .band = IEEE80211_BAND_5GHZ, \
45 .hw_value = (_channel), \
46 .center_freq = 5000 + (5 * (_channel)), \
47 .flags = (_flags), \
48 .max_antenna_gain = 0, \
49 .max_power = 30, \
50}
51
52static struct ieee80211_rate ath6kl_rates[] = {
53 RATETAB_ENT(10, 0x1, 0),
54 RATETAB_ENT(20, 0x2, 0),
55 RATETAB_ENT(55, 0x4, 0),
56 RATETAB_ENT(110, 0x8, 0),
57 RATETAB_ENT(60, 0x10, 0),
58 RATETAB_ENT(90, 0x20, 0),
59 RATETAB_ENT(120, 0x40, 0),
60 RATETAB_ENT(180, 0x80, 0),
61 RATETAB_ENT(240, 0x100, 0),
62 RATETAB_ENT(360, 0x200, 0),
63 RATETAB_ENT(480, 0x400, 0),
64 RATETAB_ENT(540, 0x800, 0),
65};
66
67#define ath6kl_a_rates (ath6kl_rates + 4)
68#define ath6kl_a_rates_size 8
69#define ath6kl_g_rates (ath6kl_rates + 0)
70#define ath6kl_g_rates_size 12
71
Vasanthakumar Thiagarajanfaaf1922012-02-27 11:44:19 +053072#define ath6kl_g_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
73 IEEE80211_HT_CAP_SGI_20 | \
74 IEEE80211_HT_CAP_SGI_40)
75
Kalle Valobdcd8172011-07-18 00:22:30 +030076static struct ieee80211_channel ath6kl_2ghz_channels[] = {
77 CHAN2G(1, 2412, 0),
78 CHAN2G(2, 2417, 0),
79 CHAN2G(3, 2422, 0),
80 CHAN2G(4, 2427, 0),
81 CHAN2G(5, 2432, 0),
82 CHAN2G(6, 2437, 0),
83 CHAN2G(7, 2442, 0),
84 CHAN2G(8, 2447, 0),
85 CHAN2G(9, 2452, 0),
86 CHAN2G(10, 2457, 0),
87 CHAN2G(11, 2462, 0),
88 CHAN2G(12, 2467, 0),
89 CHAN2G(13, 2472, 0),
90 CHAN2G(14, 2484, 0),
91};
92
93static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
94 CHAN5G(34, 0), CHAN5G(36, 0),
95 CHAN5G(38, 0), CHAN5G(40, 0),
96 CHAN5G(42, 0), CHAN5G(44, 0),
97 CHAN5G(46, 0), CHAN5G(48, 0),
98 CHAN5G(52, 0), CHAN5G(56, 0),
99 CHAN5G(60, 0), CHAN5G(64, 0),
100 CHAN5G(100, 0), CHAN5G(104, 0),
101 CHAN5G(108, 0), CHAN5G(112, 0),
102 CHAN5G(116, 0), CHAN5G(120, 0),
103 CHAN5G(124, 0), CHAN5G(128, 0),
104 CHAN5G(132, 0), CHAN5G(136, 0),
105 CHAN5G(140, 0), CHAN5G(149, 0),
106 CHAN5G(153, 0), CHAN5G(157, 0),
107 CHAN5G(161, 0), CHAN5G(165, 0),
108 CHAN5G(184, 0), CHAN5G(188, 0),
109 CHAN5G(192, 0), CHAN5G(196, 0),
110 CHAN5G(200, 0), CHAN5G(204, 0),
111 CHAN5G(208, 0), CHAN5G(212, 0),
112 CHAN5G(216, 0),
113};
114
115static struct ieee80211_supported_band ath6kl_band_2ghz = {
116 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
117 .channels = ath6kl_2ghz_channels,
118 .n_bitrates = ath6kl_g_rates_size,
119 .bitrates = ath6kl_g_rates,
Vasanthakumar Thiagarajanfaaf1922012-02-27 11:44:19 +0530120 .ht_cap.cap = ath6kl_g_htcap,
121 .ht_cap.ht_supported = true,
Kalle Valobdcd8172011-07-18 00:22:30 +0300122};
123
124static struct ieee80211_supported_band ath6kl_band_5ghz = {
125 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
126 .channels = ath6kl_5ghz_a_channels,
127 .n_bitrates = ath6kl_a_rates_size,
128 .bitrates = ath6kl_a_rates,
Vasanthakumar Thiagarajanfaaf1922012-02-27 11:44:19 +0530129 .ht_cap.cap = ath6kl_g_htcap,
130 .ht_cap.ht_supported = true,
Kalle Valobdcd8172011-07-18 00:22:30 +0300131};
132
Jouni Malinen837cb972011-10-11 17:31:57 +0300133#define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */
134
Kalle Valo10509f92011-12-13 14:52:07 +0200135/* returns true if scheduled scan was stopped */
136static bool __ath6kl_cfg80211_sscan_stop(struct ath6kl_vif *vif)
137{
138 struct ath6kl *ar = vif->ar;
139
140 if (ar->state != ATH6KL_STATE_SCHED_SCAN)
141 return false;
142
143 del_timer_sync(&vif->sched_scan_timer);
144
145 ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
146 ATH6KL_HOST_MODE_AWAKE);
147
148 ar->state = ATH6KL_STATE_ON;
149
150 return true;
151}
152
153static void ath6kl_cfg80211_sscan_disable(struct ath6kl_vif *vif)
154{
155 struct ath6kl *ar = vif->ar;
156 bool stopped;
157
158 stopped = __ath6kl_cfg80211_sscan_stop(vif);
159
160 if (!stopped)
161 return;
162
163 cfg80211_sched_scan_stopped(ar->wiphy);
164}
165
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530166static int ath6kl_set_wpa_version(struct ath6kl_vif *vif,
Kalle Valobdcd8172011-07-18 00:22:30 +0300167 enum nl80211_wpa_versions wpa_version)
168{
169 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
170
171 if (!wpa_version) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530172 vif->auth_mode = NONE_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300173 } else if (wpa_version & NL80211_WPA_VERSION_2) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530174 vif->auth_mode = WPA2_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300175 } else if (wpa_version & NL80211_WPA_VERSION_1) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530176 vif->auth_mode = WPA_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300177 } else {
178 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
179 return -ENOTSUPP;
180 }
181
182 return 0;
183}
184
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530185static int ath6kl_set_auth_type(struct ath6kl_vif *vif,
Kalle Valobdcd8172011-07-18 00:22:30 +0300186 enum nl80211_auth_type auth_type)
187{
Kalle Valobdcd8172011-07-18 00:22:30 +0300188 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
189
190 switch (auth_type) {
191 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530192 vif->dot11_auth_mode = OPEN_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300193 break;
194 case NL80211_AUTHTYPE_SHARED_KEY:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530195 vif->dot11_auth_mode = SHARED_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300196 break;
197 case NL80211_AUTHTYPE_NETWORK_EAP:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530198 vif->dot11_auth_mode = LEAP_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300199 break;
200
201 case NL80211_AUTHTYPE_AUTOMATIC:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530202 vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300203 break;
204
205 default:
Masanari Iida3c325fb2012-01-31 23:32:55 +0900206 ath6kl_err("%s: 0x%x not supported\n", __func__, auth_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300207 return -ENOTSUPP;
208 }
209
210 return 0;
211}
212
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530213static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast)
Kalle Valobdcd8172011-07-18 00:22:30 +0300214{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530215 u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto;
216 u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len :
217 &vif->grp_crypto_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300218
219 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
220 __func__, cipher, ucast);
221
222 switch (cipher) {
223 case 0:
224 /* our own hack to use value 0 as no crypto used */
225 *ar_cipher = NONE_CRYPT;
226 *ar_cipher_len = 0;
227 break;
228 case WLAN_CIPHER_SUITE_WEP40:
229 *ar_cipher = WEP_CRYPT;
230 *ar_cipher_len = 5;
231 break;
232 case WLAN_CIPHER_SUITE_WEP104:
233 *ar_cipher = WEP_CRYPT;
234 *ar_cipher_len = 13;
235 break;
236 case WLAN_CIPHER_SUITE_TKIP:
237 *ar_cipher = TKIP_CRYPT;
238 *ar_cipher_len = 0;
239 break;
240 case WLAN_CIPHER_SUITE_CCMP:
241 *ar_cipher = AES_CRYPT;
242 *ar_cipher_len = 0;
243 break;
Dai Shuibing5e070212011-11-03 11:39:37 +0200244 case WLAN_CIPHER_SUITE_SMS4:
245 *ar_cipher = WAPI_CRYPT;
246 *ar_cipher_len = 0;
247 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300248 default:
249 ath6kl_err("cipher 0x%x not supported\n", cipher);
250 return -ENOTSUPP;
251 }
252
253 return 0;
254}
255
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530256static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt)
Kalle Valobdcd8172011-07-18 00:22:30 +0300257{
258 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
259
260 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530261 if (vif->auth_mode == WPA_AUTH)
262 vif->auth_mode = WPA_PSK_AUTH;
263 else if (vif->auth_mode == WPA2_AUTH)
264 vif->auth_mode = WPA2_PSK_AUTH;
Jouni Malinen837cb972011-10-11 17:31:57 +0300265 } else if (key_mgmt == 0x00409600) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530266 if (vif->auth_mode == WPA_AUTH)
267 vif->auth_mode = WPA_AUTH_CCKM;
268 else if (vif->auth_mode == WPA2_AUTH)
269 vif->auth_mode = WPA2_AUTH_CCKM;
Kalle Valobdcd8172011-07-18 00:22:30 +0300270 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530271 vif->auth_mode = NONE_AUTH;
Kalle Valobdcd8172011-07-18 00:22:30 +0300272 }
273}
274
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530275static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300276{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530277 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530278
Kalle Valobdcd8172011-07-18 00:22:30 +0300279 if (!test_bit(WMI_READY, &ar->flag)) {
280 ath6kl_err("wmi is not ready\n");
281 return false;
282 }
283
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530284 if (!test_bit(WLAN_ENABLED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300285 ath6kl_err("wlan disabled\n");
286 return false;
287 }
288
289 return true;
290}
291
Kevin Fang6981ffd2011-10-07 08:51:19 +0800292static bool ath6kl_is_wpa_ie(const u8 *pos)
293{
294 return pos[0] == WLAN_EID_WPA && pos[1] >= 4 &&
295 pos[2] == 0x00 && pos[3] == 0x50 &&
296 pos[4] == 0xf2 && pos[5] == 0x01;
297}
298
299static bool ath6kl_is_rsn_ie(const u8 *pos)
300{
301 return pos[0] == WLAN_EID_RSN;
302}
303
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700304static bool ath6kl_is_wps_ie(const u8 *pos)
305{
306 return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
307 pos[1] >= 4 &&
308 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
309 pos[5] == 0x04);
310}
311
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530312static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies,
313 size_t ies_len)
Kevin Fang6981ffd2011-10-07 08:51:19 +0800314{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530315 struct ath6kl *ar = vif->ar;
Kevin Fang6981ffd2011-10-07 08:51:19 +0800316 const u8 *pos;
317 u8 *buf = NULL;
318 size_t len = 0;
319 int ret;
320
321 /*
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700322 * Clear previously set flag
323 */
324
325 ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
326
327 /*
Kevin Fang6981ffd2011-10-07 08:51:19 +0800328 * Filter out RSN/WPA IE(s)
329 */
330
331 if (ies && ies_len) {
332 buf = kmalloc(ies_len, GFP_KERNEL);
333 if (buf == NULL)
334 return -ENOMEM;
335 pos = ies;
336
337 while (pos + 1 < ies + ies_len) {
338 if (pos + 2 + pos[1] > ies + ies_len)
339 break;
340 if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) {
341 memcpy(buf + len, pos, 2 + pos[1]);
342 len += 2 + pos[1];
343 }
Aarthi Thiruvengadam63541212011-10-25 11:25:52 -0700344
345 if (ath6kl_is_wps_ie(pos))
346 ar->connect_ctrl_flags |= CONNECT_WPS_FLAG;
347
Kevin Fang6981ffd2011-10-07 08:51:19 +0800348 pos += 2 + pos[1];
349 }
350 }
351
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530352 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
353 WMI_FRAME_ASSOC_REQ, buf, len);
Kevin Fang6981ffd2011-10-07 08:51:19 +0800354 kfree(buf);
355 return ret;
356}
357
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530358static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type)
359{
360 switch (type) {
361 case NL80211_IFTYPE_STATION:
362 *nw_type = INFRA_NETWORK;
363 break;
364 case NL80211_IFTYPE_ADHOC:
365 *nw_type = ADHOC_NETWORK;
366 break;
367 case NL80211_IFTYPE_AP:
368 *nw_type = AP_NETWORK;
369 break;
370 case NL80211_IFTYPE_P2P_CLIENT:
371 *nw_type = INFRA_NETWORK;
372 break;
373 case NL80211_IFTYPE_P2P_GO:
374 *nw_type = AP_NETWORK;
375 break;
376 default:
377 ath6kl_err("invalid interface type %u\n", type);
378 return -ENOTSUPP;
379 }
380
381 return 0;
382}
383
384static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type,
385 u8 *if_idx, u8 *nw_type)
386{
387 int i;
388
389 if (ath6kl_nliftype_to_drv_iftype(type, nw_type))
390 return false;
391
392 if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) &&
393 ar->num_vif))
394 return false;
395
396 if (type == NL80211_IFTYPE_STATION ||
397 type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) {
Kalle Valo71f96ee2011-11-14 19:31:30 +0200398 for (i = 0; i < ar->vif_max; i++) {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530399 if ((ar->avail_idx_map >> i) & BIT(0)) {
400 *if_idx = i;
401 return true;
402 }
403 }
404 }
405
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530406 if (type == NL80211_IFTYPE_P2P_CLIENT ||
407 type == NL80211_IFTYPE_P2P_GO) {
Kalle Valo71f96ee2011-11-14 19:31:30 +0200408 for (i = ar->max_norm_iface; i < ar->vif_max; i++) {
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530409 if ((ar->avail_idx_map >> i) & BIT(0)) {
410 *if_idx = i;
411 return true;
412 }
413 }
414 }
415
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +0530416 return false;
417}
418
Kalle Valobdcd8172011-07-18 00:22:30 +0300419static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
420 struct cfg80211_connect_params *sme)
421{
422 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530423 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300424 int status;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800425 u8 nw_subtype = (ar->p2p) ? SUBTYPE_P2PDEV : SUBTYPE_NONE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300426
Kalle Valo10509f92011-12-13 14:52:07 +0200427 ath6kl_cfg80211_sscan_disable(vif);
428
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530429 vif->sme_state = SME_CONNECTING;
Kalle Valobdcd8172011-07-18 00:22:30 +0300430
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530431 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300432 return -EIO;
433
434 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
435 ath6kl_err("destroy in progress\n");
436 return -EBUSY;
437 }
438
439 if (test_bit(SKIP_SCAN, &ar->flag) &&
440 ((sme->channel && sme->channel->center_freq == 0) ||
441 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
442 ath6kl_err("SkipScan: channel or bssid invalid\n");
443 return -EINVAL;
444 }
445
446 if (down_interruptible(&ar->sem)) {
447 ath6kl_err("busy, couldn't get access\n");
448 return -ERESTARTSYS;
449 }
450
451 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
452 ath6kl_err("busy, destroy in progress\n");
453 up(&ar->sem);
454 return -EBUSY;
455 }
456
457 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
458 /*
459 * sleep until the command queue drains
460 */
461 wait_event_interruptible_timeout(ar->event_wq,
462 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
463 WMI_TIMEOUT);
464 if (signal_pending(current)) {
465 ath6kl_err("cmd queue drain timeout\n");
466 up(&ar->sem);
467 return -EINTR;
468 }
469 }
470
Jouni Malinen6e786cb2011-12-15 14:16:00 +0200471 status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len);
472 if (status) {
473 up(&ar->sem);
474 return status;
475 }
476
477 if (sme->ie == NULL || sme->ie_len == 0)
Raja Mani542c5192011-11-15 14:14:56 +0530478 ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
Kevin Fang6981ffd2011-10-07 08:51:19 +0800479
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530480 if (test_bit(CONNECTED, &vif->flags) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530481 vif->ssid_len == sme->ssid_len &&
482 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530483 vif->reconnect_flag = true;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530484 status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx,
485 vif->req_bssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530486 vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300487
488 up(&ar->sem);
489 if (status) {
490 ath6kl_err("wmi_reconnect_cmd failed\n");
491 return -EIO;
492 }
493 return 0;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530494 } else if (vif->ssid_len == sme->ssid_len &&
495 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530496 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300497 }
498
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530499 memset(vif->ssid, 0, sizeof(vif->ssid));
500 vif->ssid_len = sme->ssid_len;
501 memcpy(vif->ssid, sme->ssid, sme->ssid_len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300502
503 if (sme->channel)
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530504 vif->ch_hint = sme->channel->center_freq;
Kalle Valobdcd8172011-07-18 00:22:30 +0300505
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530506 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300507 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530508 memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300509
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530510 ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions);
Kalle Valobdcd8172011-07-18 00:22:30 +0300511
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530512 status = ath6kl_set_auth_type(vif, sme->auth_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300513 if (status) {
514 up(&ar->sem);
515 return status;
516 }
517
518 if (sme->crypto.n_ciphers_pairwise)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530519 ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true);
Kalle Valobdcd8172011-07-18 00:22:30 +0300520 else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530521 ath6kl_set_cipher(vif, 0, true);
Kalle Valobdcd8172011-07-18 00:22:30 +0300522
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530523 ath6kl_set_cipher(vif, sme->crypto.cipher_group, false);
Kalle Valobdcd8172011-07-18 00:22:30 +0300524
525 if (sme->crypto.n_akm_suites)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530526 ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +0300527
528 if ((sme->key_len) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530529 (vif->auth_mode == NONE_AUTH) &&
530 (vif->prwise_crypto == WEP_CRYPT)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300531 struct ath6kl_key *key = NULL;
532
Vivek Natarajan792ecb32011-12-29 16:18:39 +0530533 if (sme->key_idx > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300534 ath6kl_err("key index %d out of bounds\n",
535 sme->key_idx);
536 up(&ar->sem);
537 return -ENOENT;
538 }
539
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530540 key = &vif->keys[sme->key_idx];
Kalle Valobdcd8172011-07-18 00:22:30 +0300541 key->key_len = sme->key_len;
542 memcpy(key->key, sme->key, key->key_len);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530543 key->cipher = vif->prwise_crypto;
544 vif->def_txkey_index = sme->key_idx;
Kalle Valobdcd8172011-07-18 00:22:30 +0300545
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530546 ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530547 vif->prwise_crypto,
Kalle Valobdcd8172011-07-18 00:22:30 +0300548 GROUP_USAGE | TX_USAGE,
549 key->key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200550 NULL, 0,
Kalle Valobdcd8172011-07-18 00:22:30 +0300551 key->key, KEY_OP_INIT_VAL, NULL,
552 NO_SYNC_WMIFLAG);
553 }
554
555 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530556 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530557 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
558 ALL_BSS_FILTER, 0) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300559 ath6kl_err("couldn't set bss filtering\n");
560 up(&ar->sem);
561 return -EIO;
562 }
563 }
564
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530565 vif->nw_type = vif->next_mode;
Kalle Valobdcd8172011-07-18 00:22:30 +0300566
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800567 if (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
568 nw_subtype = SUBTYPE_P2PCLIENT;
569
Kalle Valobdcd8172011-07-18 00:22:30 +0300570 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
571 "%s: connect called with authmode %d dot11 auth %d"
572 " PW crypto %d PW crypto len %d GRP crypto %d"
573 " GRP crypto len %d channel hint %u\n",
574 __func__,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530575 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
576 vif->prwise_crypto_len, vif->grp_crypto,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530577 vif->grp_crypto_len, vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +0300578
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530579 vif->reconnect_flag = 0;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530580 status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530581 vif->dot11_auth_mode, vif->auth_mode,
582 vif->prwise_crypto,
583 vif->prwise_crypto_len,
584 vif->grp_crypto, vif->grp_crypto_len,
585 vif->ssid_len, vif->ssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530586 vif->req_bssid, vif->ch_hint,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800587 ar->connect_ctrl_flags, nw_subtype);
Kalle Valobdcd8172011-07-18 00:22:30 +0300588
589 up(&ar->sem);
590
591 if (status == -EINVAL) {
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530592 memset(vif->ssid, 0, sizeof(vif->ssid));
593 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300594 ath6kl_err("invalid request\n");
595 return -ENOENT;
596 } else if (status) {
597 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
598 return -EIO;
599 }
600
601 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530602 ((vif->auth_mode == WPA_PSK_AUTH)
603 || (vif->auth_mode == WPA2_PSK_AUTH))) {
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +0530604 mod_timer(&vif->disconnect_timer,
Kalle Valobdcd8172011-07-18 00:22:30 +0300605 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
606 }
607
608 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530609 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300610
611 return 0;
612}
613
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530614static struct cfg80211_bss *
615ath6kl_add_bss_if_needed(struct ath6kl_vif *vif,
616 enum network_type nw_type,
617 const u8 *bssid,
618 struct ieee80211_channel *chan,
619 const u8 *beacon_ie,
620 size_t beacon_ie_len)
Jouni Malinen01cac472011-09-19 19:14:59 +0300621{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530622 struct ath6kl *ar = vif->ar;
Jouni Malinen01cac472011-09-19 19:14:59 +0300623 struct cfg80211_bss *bss;
Raja Mani4eab6f42011-11-09 17:02:23 +0530624 u16 cap_mask, cap_val;
Jouni Malinen01cac472011-09-19 19:14:59 +0300625 u8 *ie;
626
Raja Mani4eab6f42011-11-09 17:02:23 +0530627 if (nw_type & ADHOC_NETWORK) {
628 cap_mask = WLAN_CAPABILITY_IBSS;
629 cap_val = WLAN_CAPABILITY_IBSS;
630 } else {
631 cap_mask = WLAN_CAPABILITY_ESS;
632 cap_val = WLAN_CAPABILITY_ESS;
633 }
634
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530635 bss = cfg80211_get_bss(ar->wiphy, chan, bssid,
Raja Mani4eab6f42011-11-09 17:02:23 +0530636 vif->ssid, vif->ssid_len,
637 cap_mask, cap_val);
Jouni Malinen01cac472011-09-19 19:14:59 +0300638 if (bss == NULL) {
639 /*
640 * Since cfg80211 may not yet know about the BSS,
641 * generate a partial entry until the first BSS info
642 * event becomes available.
643 *
644 * Prepend SSID element since it is not included in the Beacon
645 * IEs from the target.
646 */
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530647 ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL);
Jouni Malinen01cac472011-09-19 19:14:59 +0300648 if (ie == NULL)
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530649 return NULL;
Jouni Malinen01cac472011-09-19 19:14:59 +0300650 ie[0] = WLAN_EID_SSID;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530651 ie[1] = vif->ssid_len;
652 memcpy(ie + 2, vif->ssid, vif->ssid_len);
653 memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530654 bss = cfg80211_inform_bss(ar->wiphy, chan,
Raja Mani4eab6f42011-11-09 17:02:23 +0530655 bssid, 0, cap_val, 100,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530656 ie, 2 + vif->ssid_len + beacon_ie_len,
Jouni Malinen01cac472011-09-19 19:14:59 +0300657 0, GFP_KERNEL);
658 if (bss)
Raja Mani4eab6f42011-11-09 17:02:23 +0530659 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added bss %pM to "
660 "cfg80211\n", bssid);
Jouni Malinen01cac472011-09-19 19:14:59 +0300661 kfree(ie);
662 } else
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530663 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss\n");
Jouni Malinen01cac472011-09-19 19:14:59 +0300664
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530665 return bss;
Jouni Malinen01cac472011-09-19 19:14:59 +0300666}
667
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530668void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel,
Kalle Valobdcd8172011-07-18 00:22:30 +0300669 u8 *bssid, u16 listen_intvl,
670 u16 beacon_intvl,
671 enum network_type nw_type,
672 u8 beacon_ie_len, u8 assoc_req_len,
673 u8 assoc_resp_len, u8 *assoc_info)
674{
Jouni Malinen01cac472011-09-19 19:14:59 +0300675 struct ieee80211_channel *chan;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530676 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530677 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +0300678
679 /* capinfo + listen interval */
680 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
681
682 /* capinfo + status code + associd */
683 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
684
685 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
686 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
687 assoc_resp_ie_offset;
688
689 assoc_req_len -= assoc_req_ie_offset;
690 assoc_resp_len -= assoc_resp_ie_offset;
691
Jouni Malinen32c10872011-09-19 19:15:07 +0300692 /*
693 * Store Beacon interval here; DTIM period will be available only once
694 * a Beacon frame from the AP is seen.
695 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530696 vif->assoc_bss_beacon_int = beacon_intvl;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530697 clear_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +0300698
Kalle Valobdcd8172011-07-18 00:22:30 +0300699 if (nw_type & ADHOC_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530700 if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300701 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
702 "%s: ath6k not in ibss mode\n", __func__);
703 return;
704 }
705 }
706
707 if (nw_type & INFRA_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530708 if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
709 vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300710 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
711 "%s: ath6k not in station mode\n", __func__);
712 return;
713 }
714 }
715
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530716 chan = ieee80211_get_channel(ar->wiphy, (int) channel);
Kalle Valobdcd8172011-07-18 00:22:30 +0300717
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530718 bss = ath6kl_add_bss_if_needed(vif, nw_type, bssid, chan,
719 assoc_info, beacon_ie_len);
720 if (!bss) {
Raja Mani4eab6f42011-11-09 17:02:23 +0530721 ath6kl_err("could not add cfg80211 bss entry\n");
Kalle Valobdcd8172011-07-18 00:22:30 +0300722 return;
723 }
724
Raja Mani4eab6f42011-11-09 17:02:23 +0530725 if (nw_type & ADHOC_NETWORK) {
726 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
727 nw_type & ADHOC_CREATOR ? "creator" : "joiner");
728 cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530729 cfg80211_put_bss(bss);
Jouni Malinen01cac472011-09-19 19:14:59 +0300730 return;
731 }
732
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530733 if (vif->sme_state == SME_CONNECTING) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300734 /* inform connect result to cfg80211 */
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530735 vif->sme_state = SME_CONNECTED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530736 cfg80211_connect_result(vif->ndev, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300737 assoc_req_ie, assoc_req_len,
738 assoc_resp_ie, assoc_resp_len,
739 WLAN_STATUS_SUCCESS, GFP_KERNEL);
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530740 cfg80211_put_bss(bss);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530741 } else if (vif->sme_state == SME_CONNECTED) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300742 /* inform roam event to cfg80211 */
Vasanthakumar Thiagarajan5e13fd32011-12-13 17:19:57 +0530743 cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len,
744 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300745 }
746}
747
748static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
749 struct net_device *dev, u16 reason_code)
750{
Kalle Valod6d5c062011-11-25 13:17:37 +0200751 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530752 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300753
754 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
755 reason_code);
756
Kalle Valo10509f92011-12-13 14:52:07 +0200757 ath6kl_cfg80211_sscan_disable(vif);
758
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530759 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300760 return -EIO;
761
762 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
763 ath6kl_err("busy, destroy in progress\n");
764 return -EBUSY;
765 }
766
767 if (down_interruptible(&ar->sem)) {
768 ath6kl_err("busy, couldn't get access\n");
769 return -ERESTARTSYS;
770 }
771
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530772 vif->reconnect_flag = 0;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530773 ath6kl_disconnect(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530774 memset(vif->ssid, 0, sizeof(vif->ssid));
775 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300776
777 if (!test_bit(SKIP_SCAN, &ar->flag))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530778 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +0300779
780 up(&ar->sem);
781
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530782 vif->sme_state = SME_DISCONNECTED;
Vasanthakumar Thiagarajan170826d2011-09-10 15:26:35 +0530783
Kalle Valobdcd8172011-07-18 00:22:30 +0300784 return 0;
785}
786
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530787void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300788 u8 *bssid, u8 assoc_resp_len,
789 u8 *assoc_info, u16 proto_reason)
790{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530791 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530792
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530793 if (vif->scan_req) {
794 cfg80211_scan_done(vif->scan_req, true);
795 vif->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300796 }
797
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530798 if (vif->nw_type & ADHOC_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530799 if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300800 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
801 "%s: ath6k not in ibss mode\n", __func__);
802 return;
803 }
804 memset(bssid, 0, ETH_ALEN);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530805 cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300806 return;
807 }
808
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530809 if (vif->nw_type & INFRA_NETWORK) {
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +0530810 if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
811 vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300812 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
813 "%s: ath6k not in station mode\n", __func__);
814 return;
815 }
816 }
817
Vasanthakumar Thiagarajan1de547d2011-09-23 10:57:50 +0530818 /*
819 * Send a disconnect command to target when a disconnect event is
820 * received with reason code other than 3 (DISCONNECT_CMD - disconnect
821 * request from host) to make the firmware stop trying to connect even
822 * after giving disconnect event. There will be one more disconnect
823 * event for this disconnect command with reason code DISCONNECT_CMD
824 * which will be notified to cfg80211.
825 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300826
Vasanthakumar Thiagarajan1de547d2011-09-23 10:57:50 +0530827 if (reason != DISCONNECT_CMD) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530828 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300829 return;
830 }
831
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530832 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300833
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530834 if (vif->sme_state == SME_CONNECTING) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530835 cfg80211_connect_result(vif->ndev,
Vasanthakumar Thiagarajanac59a2b2011-09-10 15:26:34 +0530836 bssid, NULL, 0,
837 NULL, 0,
838 WLAN_STATUS_UNSPECIFIED_FAILURE,
839 GFP_KERNEL);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530840 } else if (vif->sme_state == SME_CONNECTED) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530841 cfg80211_disconnected(vif->ndev, reason,
Vasanthakumar Thiagarajanac59a2b2011-09-10 15:26:34 +0530842 NULL, 0, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300843 }
844
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530845 vif->sme_state = SME_DISCONNECTED;
Kalle Valobdcd8172011-07-18 00:22:30 +0300846}
847
Kalle Valobdcd8172011-07-18 00:22:30 +0300848static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
849 struct cfg80211_scan_request *request)
850{
Kalle Valod6d5c062011-11-25 13:17:37 +0200851 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530852 struct ath6kl_vif *vif = netdev_priv(ndev);
Edward Lu1276c9e2011-08-30 21:58:00 +0300853 s8 n_channels = 0;
854 u16 *channels = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300855 int ret = 0;
Vasanthakumar Thiagarajanf1f92172011-10-01 16:12:36 +0530856 u32 force_fg_scan = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300857
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530858 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300859 return -EIO;
860
Kalle Valo10509f92011-12-13 14:52:07 +0200861 ath6kl_cfg80211_sscan_disable(vif);
862
Kalle Valobdcd8172011-07-18 00:22:30 +0300863 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530864 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300865 ret = ath6kl_wmi_bssfilter_cmd(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530866 ar->wmi, vif->fw_vif_idx,
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530867 (test_bit(CONNECTED, &vif->flags) ?
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300868 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
869 if (ret) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300870 ath6kl_err("couldn't set bss filtering\n");
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300871 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300872 }
873 }
874
875 if (request->n_ssids && request->ssids[0].ssid_len) {
876 u8 i;
877
878 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
879 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
880
881 for (i = 0; i < request->n_ssids; i++)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530882 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
883 i + 1, SPECIFIC_SSID_FLAG,
Kalle Valobdcd8172011-07-18 00:22:30 +0300884 request->ssids[i].ssid_len,
885 request->ssids[i].ssid);
886 }
887
Aarthi Thiruvengadam080eec42012-02-28 09:17:04 -0800888 /* this also clears IE in fw if it's not set */
889 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
890 WMI_FRAME_PROBE_REQ,
891 request->ie, request->ie_len);
892 if (ret) {
893 ath6kl_err("failed to set Probe Request appie for "
894 "scan");
895 return ret;
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300896 }
897
Jouni Malinen11869be2011-09-02 20:07:06 +0300898 /*
899 * Scan only the requested channels if the request specifies a set of
900 * channels. If the list is longer than the target supports, do not
901 * configure the list and instead, scan all available channels.
902 */
903 if (request->n_channels > 0 &&
904 request->n_channels <= WMI_MAX_CHANNELS) {
Edward Lu1276c9e2011-08-30 21:58:00 +0300905 u8 i;
906
Jouni Malinen11869be2011-09-02 20:07:06 +0300907 n_channels = request->n_channels;
Edward Lu1276c9e2011-08-30 21:58:00 +0300908
909 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
910 if (channels == NULL) {
911 ath6kl_warn("failed to set scan channels, "
912 "scan all channels");
913 n_channels = 0;
914 }
915
916 for (i = 0; i < n_channels; i++)
917 channels[i] = request->channels[i]->center_freq;
918 }
919
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530920 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajanf1f92172011-10-01 16:12:36 +0530921 force_fg_scan = 1;
922
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800923 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
924 ar->fw_capabilities)) {
925 /*
926 * If capable of doing P2P mgmt operations using
927 * station interface, send additional information like
928 * supported rates to advertise and xmit rates for
929 * probe requests
930 */
931 ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx,
932 WMI_LONG_SCAN, force_fg_scan,
Vasanthakumar Thiagarajan13423c32012-02-21 15:30:42 +0530933 false, 0,
934 ATH6KL_FG_SCAN_INTERVAL,
935 n_channels, channels,
936 request->no_cck,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800937 request->rates);
938 } else {
939 ret = ath6kl_wmi_startscan_cmd(ar->wmi, vif->fw_vif_idx,
940 WMI_LONG_SCAN, force_fg_scan,
Vasanthakumar Thiagarajan13423c32012-02-21 15:30:42 +0530941 false, 0,
942 ATH6KL_FG_SCAN_INTERVAL,
943 n_channels, channels);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800944 }
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300945 if (ret)
Kalle Valobdcd8172011-07-18 00:22:30 +0300946 ath6kl_err("wmi_startscan_cmd failed\n");
Jouni Malinen11869be2011-09-02 20:07:06 +0300947 else
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530948 vif->scan_req = request;
Kalle Valobdcd8172011-07-18 00:22:30 +0300949
Edward Lu1276c9e2011-08-30 21:58:00 +0300950 kfree(channels);
951
Kalle Valobdcd8172011-07-18 00:22:30 +0300952 return ret;
953}
954
Kalle Valo1c17d312011-11-01 08:43:56 +0200955void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted)
Kalle Valobdcd8172011-07-18 00:22:30 +0300956{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530957 struct ath6kl *ar = vif->ar;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300958 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300959
Kalle Valo1c17d312011-11-01 08:43:56 +0200960 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__,
961 aborted ? " aborted" : "");
Kalle Valobdcd8172011-07-18 00:22:30 +0300962
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530963 if (!vif->scan_req)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300964 return;
Kalle Valobdcd8172011-07-18 00:22:30 +0300965
Kalle Valo1c17d312011-11-01 08:43:56 +0200966 if (aborted)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300967 goto out;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300968
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530969 if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) {
970 for (i = 0; i < vif->scan_req->n_ssids; i++) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530971 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
972 i + 1, DISABLE_SSID_FLAG,
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300973 0, NULL);
974 }
975 }
976
977out:
Kalle Valocb938212011-10-27 18:47:46 +0300978 cfg80211_scan_done(vif->scan_req, aborted);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530979 vif->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300980}
981
982static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
983 u8 key_index, bool pairwise,
984 const u8 *mac_addr,
985 struct key_params *params)
986{
Kalle Valod6d5c062011-11-25 13:17:37 +0200987 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530988 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300989 struct ath6kl_key *key = NULL;
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +0530990 int seq_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300991 u8 key_usage;
992 u8 key_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300993
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530994 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +0300995 return -EIO;
996
Jouni Malinen837cb972011-10-11 17:31:57 +0300997 if (params->cipher == CCKM_KRK_CIPHER_SUITE) {
998 if (params->key_len != WMI_KRK_LEN)
999 return -EINVAL;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301000 return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx,
1001 params->key);
Jouni Malinen837cb972011-10-11 17:31:57 +03001002 }
1003
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301004 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001005 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1006 "%s: key index %d out of bounds\n", __func__,
1007 key_index);
1008 return -ENOENT;
1009 }
1010
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301011 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001012 memset(key, 0, sizeof(struct ath6kl_key));
1013
1014 if (pairwise)
1015 key_usage = PAIRWISE_USAGE;
1016 else
1017 key_usage = GROUP_USAGE;
1018
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301019 seq_len = params->seq_len;
1020 if (params->cipher == WLAN_CIPHER_SUITE_SMS4 &&
1021 seq_len > ATH6KL_KEY_SEQ_LEN) {
1022 /* Only first half of the WPI PN is configured */
1023 seq_len = ATH6KL_KEY_SEQ_LEN;
Kalle Valobdcd8172011-07-18 00:22:30 +03001024 }
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301025 if (params->key_len > WLAN_MAX_KEY_LEN ||
1026 seq_len > sizeof(key->seq))
1027 return -EINVAL;
1028
1029 key->key_len = params->key_len;
1030 memcpy(key->key, params->key, key->key_len);
1031 key->seq_len = seq_len;
1032 memcpy(key->seq, params->seq, key->seq_len);
1033 key->cipher = params->cipher;
Kalle Valobdcd8172011-07-18 00:22:30 +03001034
1035 switch (key->cipher) {
1036 case WLAN_CIPHER_SUITE_WEP40:
1037 case WLAN_CIPHER_SUITE_WEP104:
1038 key_type = WEP_CRYPT;
1039 break;
1040
1041 case WLAN_CIPHER_SUITE_TKIP:
1042 key_type = TKIP_CRYPT;
1043 break;
1044
1045 case WLAN_CIPHER_SUITE_CCMP:
1046 key_type = AES_CRYPT;
1047 break;
Dai Shuibing5e070212011-11-03 11:39:37 +02001048 case WLAN_CIPHER_SUITE_SMS4:
1049 key_type = WAPI_CRYPT;
1050 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001051
1052 default:
1053 return -ENOTSUPP;
1054 }
1055
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301056 if (((vif->auth_mode == WPA_PSK_AUTH)
1057 || (vif->auth_mode == WPA2_PSK_AUTH))
Kalle Valobdcd8172011-07-18 00:22:30 +03001058 && (key_usage & GROUP_USAGE))
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301059 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001060
1061 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1062 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
1063 __func__, key_index, key->key_len, key_type,
1064 key_usage, key->seq_len);
1065
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301066 if (vif->nw_type == AP_NETWORK && !pairwise &&
Jouni Malinen47032902011-12-08 16:50:30 +02001067 (key_type == TKIP_CRYPT || key_type == AES_CRYPT ||
Vasanthakumar Thiagarajancc4d6232012-02-14 20:33:00 +05301068 key_type == WAPI_CRYPT)) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001069 ar->ap_mode_bkey.valid = true;
1070 ar->ap_mode_bkey.key_index = key_index;
1071 ar->ap_mode_bkey.key_type = key_type;
1072 ar->ap_mode_bkey.key_len = key->key_len;
1073 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301074 if (!test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001075 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
1076 "key configuration until AP mode has been "
1077 "started\n");
1078 /*
1079 * The key will be set in ath6kl_connect_ap_mode() once
1080 * the connected event is received from the target.
1081 */
1082 return 0;
1083 }
1084 }
1085
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301086 if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301087 !test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen151411e2011-09-15 15:10:16 +03001088 /*
1089 * Store the key locally so that it can be re-configured after
1090 * the AP mode has properly started
1091 * (ath6kl_install_statioc_wep_keys).
1092 */
1093 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration "
1094 "until AP mode has been started\n");
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301095 vif->wep_key_list[key_index].key_len = key->key_len;
1096 memcpy(vif->wep_key_list[key_index].key, key->key,
1097 key->key_len);
Jouni Malinen151411e2011-09-15 15:10:16 +03001098 return 0;
1099 }
1100
Vasanthakumar Thiagarajan7cefa442011-11-11 20:33:00 +05301101 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, key_index,
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001102 key_type, key_usage, key->key_len,
1103 key->seq, key->seq_len, key->key,
1104 KEY_OP_INIT_VAL,
1105 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001106}
1107
1108static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
1109 u8 key_index, bool pairwise,
1110 const u8 *mac_addr)
1111{
Kalle Valod6d5c062011-11-25 13:17:37 +02001112 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301113 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001114
1115 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1116
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301117 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001118 return -EIO;
1119
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301120 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001121 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1122 "%s: key index %d out of bounds\n", __func__,
1123 key_index);
1124 return -ENOENT;
1125 }
1126
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301127 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001128 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1129 "%s: index %d is empty\n", __func__, key_index);
1130 return 0;
1131 }
1132
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301133 vif->keys[key_index].key_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001134
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301135 return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001136}
1137
1138static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
1139 u8 key_index, bool pairwise,
1140 const u8 *mac_addr, void *cookie,
1141 void (*callback) (void *cookie,
1142 struct key_params *))
1143{
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301144 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001145 struct ath6kl_key *key = NULL;
1146 struct key_params params;
1147
1148 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1149
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301150 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001151 return -EIO;
1152
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301153 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001154 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1155 "%s: key index %d out of bounds\n", __func__,
1156 key_index);
1157 return -ENOENT;
1158 }
1159
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301160 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001161 memset(&params, 0, sizeof(params));
1162 params.cipher = key->cipher;
1163 params.key_len = key->key_len;
1164 params.seq_len = key->seq_len;
1165 params.seq = key->seq;
1166 params.key = key->key;
1167
1168 callback(cookie, &params);
1169
1170 return key->key_len ? 0 : -ENOENT;
1171}
1172
1173static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1174 struct net_device *ndev,
1175 u8 key_index, bool unicast,
1176 bool multicast)
1177{
Kalle Valod6d5c062011-11-25 13:17:37 +02001178 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301179 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001180 struct ath6kl_key *key = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001181 u8 key_usage;
Edward Lu229ed6b2011-08-30 21:58:07 +03001182 enum crypto_type key_type = NONE_CRYPT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001183
1184 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1185
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301186 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001187 return -EIO;
1188
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301189 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001190 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1191 "%s: key index %d out of bounds\n",
1192 __func__, key_index);
1193 return -ENOENT;
1194 }
1195
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301196 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001197 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1198 __func__, key_index);
1199 return -EINVAL;
1200 }
1201
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301202 vif->def_txkey_index = key_index;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301203 key = &vif->keys[vif->def_txkey_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001204 key_usage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301205 if (vif->prwise_crypto == WEP_CRYPT)
Kalle Valobdcd8172011-07-18 00:22:30 +03001206 key_usage |= TX_USAGE;
Edward Lu229ed6b2011-08-30 21:58:07 +03001207 if (unicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301208 key_type = vif->prwise_crypto;
Edward Lu229ed6b2011-08-30 21:58:07 +03001209 if (multicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301210 key_type = vif->grp_crypto;
Kalle Valobdcd8172011-07-18 00:22:30 +03001211
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301212 if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags))
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001213 return 0; /* Delay until AP mode has been started */
1214
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001215 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
1216 vif->def_txkey_index,
1217 key_type, key_usage,
1218 key->key_len, key->seq, key->seq_len,
1219 key->key,
1220 KEY_OP_INIT_VAL, NULL,
1221 SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001222}
1223
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301224void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001225 bool ismcast)
1226{
1227 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1228 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1229
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301230 cfg80211_michael_mic_failure(vif->ndev, vif->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001231 (ismcast ? NL80211_KEYTYPE_GROUP :
1232 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1233 GFP_KERNEL);
1234}
1235
1236static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1237{
1238 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301239 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001240 int ret;
1241
1242 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1243 changed);
1244
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301245 vif = ath6kl_vif_first(ar);
1246 if (!vif)
1247 return -EIO;
1248
1249 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001250 return -EIO;
1251
1252 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1253 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1254 if (ret != 0) {
1255 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1256 return -EIO;
1257 }
1258 }
1259
1260 return 0;
1261}
1262
1263/*
1264 * The type nl80211_tx_power_setting replaces the following
1265 * data type from 2.6.36 onwards
1266*/
1267static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1268 enum nl80211_tx_power_setting type,
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001269 int mbm)
Kalle Valobdcd8172011-07-18 00:22:30 +03001270{
1271 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301272 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001273 u8 ath6kl_dbm;
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001274 int dbm = MBM_TO_DBM(mbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001275
1276 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1277 type, dbm);
1278
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301279 vif = ath6kl_vif_first(ar);
1280 if (!vif)
1281 return -EIO;
1282
1283 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001284 return -EIO;
1285
1286 switch (type) {
1287 case NL80211_TX_POWER_AUTOMATIC:
1288 return 0;
1289 case NL80211_TX_POWER_LIMITED:
1290 ar->tx_pwr = ath6kl_dbm = dbm;
1291 break;
1292 default:
1293 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1294 __func__, type);
1295 return -EOPNOTSUPP;
1296 }
1297
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301298 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, ath6kl_dbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001299
1300 return 0;
1301}
1302
1303static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1304{
1305 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301306 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001307
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301308 vif = ath6kl_vif_first(ar);
1309 if (!vif)
1310 return -EIO;
1311
1312 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001313 return -EIO;
1314
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301315 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001316 ar->tx_pwr = 0;
1317
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301318 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001319 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1320 return -EIO;
1321 }
1322
1323 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1324 5 * HZ);
1325
1326 if (signal_pending(current)) {
1327 ath6kl_err("target did not respond\n");
1328 return -EINTR;
1329 }
1330 }
1331
1332 *dbm = ar->tx_pwr;
1333 return 0;
1334}
1335
1336static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1337 struct net_device *dev,
1338 bool pmgmt, int timeout)
1339{
1340 struct ath6kl *ar = ath6kl_priv(dev);
1341 struct wmi_power_mode_cmd mode;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301342 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001343
1344 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1345 __func__, pmgmt, timeout);
1346
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301347 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001348 return -EIO;
1349
1350 if (pmgmt) {
1351 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1352 mode.pwr_mode = REC_POWER;
1353 } else {
1354 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1355 mode.pwr_mode = MAX_PERF_POWER;
1356 }
1357
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301358 if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx,
1359 mode.pwr_mode) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001360 ath6kl_err("wmi_powermode_cmd failed\n");
1361 return -EIO;
1362 }
1363
1364 return 0;
1365}
1366
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301367static struct net_device *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
1368 char *name,
1369 enum nl80211_iftype type,
1370 u32 *flags,
1371 struct vif_params *params)
1372{
1373 struct ath6kl *ar = wiphy_priv(wiphy);
1374 struct net_device *ndev;
1375 u8 if_idx, nw_type;
1376
Kalle Valo71f96ee2011-11-14 19:31:30 +02001377 if (ar->num_vif == ar->vif_max) {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301378 ath6kl_err("Reached maximum number of supported vif\n");
1379 return ERR_PTR(-EINVAL);
1380 }
1381
1382 if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) {
1383 ath6kl_err("Not a supported interface type\n");
1384 return ERR_PTR(-EINVAL);
1385 }
1386
1387 ndev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
1388 if (!ndev)
1389 return ERR_PTR(-ENOMEM);
1390
1391 ar->num_vif++;
1392
1393 return ndev;
1394}
1395
1396static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy,
1397 struct net_device *ndev)
1398{
1399 struct ath6kl *ar = wiphy_priv(wiphy);
1400 struct ath6kl_vif *vif = netdev_priv(ndev);
1401
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301402 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301403 list_del(&vif->list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301404 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301405
1406 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1407
Kalle Valoc25889e2012-01-17 20:08:27 +02001408 ath6kl_cfg80211_vif_cleanup(vif);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301409
1410 return 0;
1411}
1412
Kalle Valobdcd8172011-07-18 00:22:30 +03001413static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1414 struct net_device *ndev,
1415 enum nl80211_iftype type, u32 *flags,
1416 struct vif_params *params)
1417{
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301418 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001419
1420 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1421
Kalle Valobdcd8172011-07-18 00:22:30 +03001422 switch (type) {
1423 case NL80211_IFTYPE_STATION:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301424 vif->next_mode = INFRA_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001425 break;
1426 case NL80211_IFTYPE_ADHOC:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301427 vif->next_mode = ADHOC_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001428 break;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001429 case NL80211_IFTYPE_AP:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301430 vif->next_mode = AP_NETWORK;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001431 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001432 case NL80211_IFTYPE_P2P_CLIENT:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301433 vif->next_mode = INFRA_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001434 break;
1435 case NL80211_IFTYPE_P2P_GO:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301436 vif->next_mode = AP_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001437 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001438 default:
1439 ath6kl_err("invalid interface type %u\n", type);
1440 return -EOPNOTSUPP;
1441 }
1442
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +05301443 vif->wdev.iftype = type;
Kalle Valobdcd8172011-07-18 00:22:30 +03001444
1445 return 0;
1446}
1447
1448static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1449 struct net_device *dev,
1450 struct cfg80211_ibss_params *ibss_param)
1451{
1452 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301453 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001454 int status;
1455
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301456 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001457 return -EIO;
1458
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301459 vif->ssid_len = ibss_param->ssid_len;
1460 memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001461
1462 if (ibss_param->channel)
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301463 vif->ch_hint = ibss_param->channel->center_freq;
Kalle Valobdcd8172011-07-18 00:22:30 +03001464
1465 if (ibss_param->channel_fixed) {
1466 /*
1467 * TODO: channel_fixed: The channel should be fixed, do not
1468 * search for IBSSs to join on other channels. Target
1469 * firmware does not support this feature, needs to be
1470 * updated.
1471 */
1472 return -EOPNOTSUPP;
1473 }
1474
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301475 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001476 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301477 memcpy(vif->req_bssid, ibss_param->bssid,
1478 sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001479
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301480 ath6kl_set_wpa_version(vif, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001481
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301482 status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
Kalle Valobdcd8172011-07-18 00:22:30 +03001483 if (status)
1484 return status;
1485
1486 if (ibss_param->privacy) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301487 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
1488 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001489 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301490 ath6kl_set_cipher(vif, 0, true);
1491 ath6kl_set_cipher(vif, 0, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001492 }
1493
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301494 vif->nw_type = vif->next_mode;
Kalle Valobdcd8172011-07-18 00:22:30 +03001495
1496 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1497 "%s: connect called with authmode %d dot11 auth %d"
1498 " PW crypto %d PW crypto len %d GRP crypto %d"
1499 " GRP crypto len %d channel hint %u\n",
1500 __func__,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301501 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
1502 vif->prwise_crypto_len, vif->grp_crypto,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301503 vif->grp_crypto_len, vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001504
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301505 status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301506 vif->dot11_auth_mode, vif->auth_mode,
1507 vif->prwise_crypto,
1508 vif->prwise_crypto_len,
1509 vif->grp_crypto, vif->grp_crypto_len,
1510 vif->ssid_len, vif->ssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301511 vif->req_bssid, vif->ch_hint,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001512 ar->connect_ctrl_flags, SUBTYPE_NONE);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301513 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001514
1515 return 0;
1516}
1517
1518static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1519 struct net_device *dev)
1520{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301521 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001522
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301523 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001524 return -EIO;
1525
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301526 ath6kl_disconnect(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301527 memset(vif->ssid, 0, sizeof(vif->ssid));
1528 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001529
1530 return 0;
1531}
1532
1533static const u32 cipher_suites[] = {
1534 WLAN_CIPHER_SUITE_WEP40,
1535 WLAN_CIPHER_SUITE_WEP104,
1536 WLAN_CIPHER_SUITE_TKIP,
1537 WLAN_CIPHER_SUITE_CCMP,
Jouni Malinen837cb972011-10-11 17:31:57 +03001538 CCKM_KRK_CIPHER_SUITE,
Dai Shuibing5e070212011-11-03 11:39:37 +02001539 WLAN_CIPHER_SUITE_SMS4,
Kalle Valobdcd8172011-07-18 00:22:30 +03001540};
1541
1542static bool is_rate_legacy(s32 rate)
1543{
1544 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1545 6000, 9000, 12000, 18000, 24000,
1546 36000, 48000, 54000
1547 };
1548 u8 i;
1549
1550 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1551 if (rate == legacy[i])
1552 return true;
1553
1554 return false;
1555}
1556
1557static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1558{
1559 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1560 52000, 58500, 65000, 72200
1561 };
1562 u8 i;
1563
1564 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1565 if (rate == ht20[i]) {
1566 if (i == ARRAY_SIZE(ht20) - 1)
1567 /* last rate uses sgi */
1568 *sgi = true;
1569 else
1570 *sgi = false;
1571
1572 *mcs = i;
1573 return true;
1574 }
1575 }
1576 return false;
1577}
1578
1579static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1580{
1581 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1582 81000, 108000, 121500, 135000,
1583 150000
1584 };
1585 u8 i;
1586
1587 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1588 if (rate == ht40[i]) {
1589 if (i == ARRAY_SIZE(ht40) - 1)
1590 /* last rate uses sgi */
1591 *sgi = true;
1592 else
1593 *sgi = false;
1594
1595 *mcs = i;
1596 return true;
1597 }
1598 }
1599
1600 return false;
1601}
1602
1603static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1604 u8 *mac, struct station_info *sinfo)
1605{
1606 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301607 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001608 long left;
1609 bool sgi;
1610 s32 rate;
1611 int ret;
1612 u8 mcs;
1613
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301614 if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
Kalle Valobdcd8172011-07-18 00:22:30 +03001615 return -ENOENT;
1616
1617 if (down_interruptible(&ar->sem))
1618 return -EBUSY;
1619
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301620 set_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001621
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301622 ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001623
1624 if (ret != 0) {
1625 up(&ar->sem);
1626 return -EIO;
1627 }
1628
1629 left = wait_event_interruptible_timeout(ar->event_wq,
1630 !test_bit(STATS_UPDATE_PEND,
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301631 &vif->flags),
Kalle Valobdcd8172011-07-18 00:22:30 +03001632 WMI_TIMEOUT);
1633
1634 up(&ar->sem);
1635
1636 if (left == 0)
1637 return -ETIMEDOUT;
1638 else if (left < 0)
1639 return left;
1640
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301641 if (vif->target_stats.rx_byte) {
1642 sinfo->rx_bytes = vif->target_stats.rx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001643 sinfo->filled |= STATION_INFO_RX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301644 sinfo->rx_packets = vif->target_stats.rx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001645 sinfo->filled |= STATION_INFO_RX_PACKETS;
1646 }
1647
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301648 if (vif->target_stats.tx_byte) {
1649 sinfo->tx_bytes = vif->target_stats.tx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001650 sinfo->filled |= STATION_INFO_TX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301651 sinfo->tx_packets = vif->target_stats.tx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001652 sinfo->filled |= STATION_INFO_TX_PACKETS;
1653 }
1654
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301655 sinfo->signal = vif->target_stats.cs_rssi;
Kalle Valobdcd8172011-07-18 00:22:30 +03001656 sinfo->filled |= STATION_INFO_SIGNAL;
1657
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301658 rate = vif->target_stats.tx_ucast_rate;
Kalle Valobdcd8172011-07-18 00:22:30 +03001659
1660 if (is_rate_legacy(rate)) {
1661 sinfo->txrate.legacy = rate / 100;
1662 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1663 if (sgi) {
1664 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1665 sinfo->txrate.mcs = mcs - 1;
1666 } else {
1667 sinfo->txrate.mcs = mcs;
1668 }
1669
1670 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1671 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1672 if (sgi) {
1673 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1674 sinfo->txrate.mcs = mcs - 1;
1675 } else {
1676 sinfo->txrate.mcs = mcs;
1677 }
1678
1679 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1680 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1681 } else {
Kalle Valo9a730832011-09-27 23:33:28 +03001682 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1683 "invalid rate from stats: %d\n", rate);
1684 ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
Kalle Valobdcd8172011-07-18 00:22:30 +03001685 return 0;
1686 }
1687
1688 sinfo->filled |= STATION_INFO_TX_BITRATE;
1689
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301690 if (test_bit(CONNECTED, &vif->flags) &&
1691 test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301692 vif->nw_type == INFRA_NETWORK) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001693 sinfo->filled |= STATION_INFO_BSS_PARAM;
1694 sinfo->bss_param.flags = 0;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301695 sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
1696 sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
Jouni Malinen32c10872011-09-19 19:15:07 +03001697 }
1698
Kalle Valobdcd8172011-07-18 00:22:30 +03001699 return 0;
1700}
1701
1702static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1703 struct cfg80211_pmksa *pmksa)
1704{
1705 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301706 struct ath6kl_vif *vif = netdev_priv(netdev);
1707
1708 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001709 pmksa->pmkid, true);
1710}
1711
1712static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1713 struct cfg80211_pmksa *pmksa)
1714{
1715 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301716 struct ath6kl_vif *vif = netdev_priv(netdev);
1717
1718 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001719 pmksa->pmkid, false);
1720}
1721
1722static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1723{
1724 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301725 struct ath6kl_vif *vif = netdev_priv(netdev);
1726
1727 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301728 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
1729 vif->bssid, NULL, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001730 return 0;
1731}
1732
Raja Manid91e8ee2012-01-30 17:13:10 +05301733static int ath6kl_wow_usr(struct ath6kl *ar, struct ath6kl_vif *vif,
1734 struct cfg80211_wowlan *wow, u32 *filter)
Raja Mani6cb3c712011-11-07 22:52:45 +02001735{
Raja Manid91e8ee2012-01-30 17:13:10 +05301736 int ret, pos;
1737 u8 mask[WOW_MASK_SIZE];
Raja Mani6cb3c712011-11-07 22:52:45 +02001738 u16 i;
Raja Mani6cb3c712011-11-07 22:52:45 +02001739
Raja Manid91e8ee2012-01-30 17:13:10 +05301740 /* Configure the patterns that we received from the user. */
Raja Mani6cb3c712011-11-07 22:52:45 +02001741 for (i = 0; i < wow->n_patterns; i++) {
1742
1743 /*
1744 * Convert given nl80211 specific mask value to equivalent
1745 * driver specific mask value and send it to the chip along
1746 * with patterns. For example, If the mask value defined in
1747 * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
1748 * then equivalent driver specific mask value is
1749 * "0xFF 0x00 0xFF 0x00".
1750 */
1751 memset(&mask, 0, sizeof(mask));
1752 for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
1753 if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
1754 mask[pos] = 0xFF;
1755 }
1756 /*
1757 * Note: Pattern's offset is not passed as part of wowlan
1758 * parameter from CFG layer. So it's always passed as ZERO
1759 * to the firmware. It means, given WOW patterns are always
1760 * matched from the first byte of received pkt in the firmware.
1761 */
1762 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
Raja Manid91e8ee2012-01-30 17:13:10 +05301763 vif->fw_vif_idx, WOW_LIST_ID,
1764 wow->patterns[i].pattern_len,
1765 0 /* pattern offset */,
1766 wow->patterns[i].pattern, mask);
Raja Mani6cb3c712011-11-07 22:52:45 +02001767 if (ret)
1768 return ret;
1769 }
1770
Raja Manid91e8ee2012-01-30 17:13:10 +05301771 if (wow->disconnect)
1772 *filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
1773
1774 if (wow->magic_pkt)
1775 *filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
1776
1777 if (wow->gtk_rekey_failure)
1778 *filter |= WOW_FILTER_OPTION_GTK_ERROR;
1779
1780 if (wow->eap_identity_req)
1781 *filter |= WOW_FILTER_OPTION_EAP_REQ;
1782
1783 if (wow->four_way_handshake)
1784 *filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
1785
1786 return 0;
1787}
1788
1789static int ath6kl_wow_ap(struct ath6kl *ar, struct ath6kl_vif *vif)
1790{
1791 static const u8 unicst_pattern[] = { 0x00, 0x00, 0x00,
1792 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1793 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1794 0x00, 0x08 };
1795 static const u8 unicst_mask[] = { 0x01, 0x00, 0x00,
1796 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1798 0x00, 0x7f };
1799 u8 unicst_offset = 0;
1800 static const u8 arp_pattern[] = { 0x08, 0x06 };
1801 static const u8 arp_mask[] = { 0xff, 0xff };
1802 u8 arp_offset = 20;
1803 static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
1804 static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
1805 u8 discvr_offset = 38;
1806 static const u8 dhcp_pattern[] = { 0xff, 0xff, 0xff, 0xff,
1807 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1809 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1810 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1811 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 /* port 67 */ };
1812 static const u8 dhcp_mask[] = { 0xff, 0xff, 0xff, 0xff,
1813 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
1815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1817 0x00, 0x00, 0x00, 0x00, 0xff, 0xff /* port 67 */ };
1818 u8 dhcp_offset = 0;
1819 int ret;
1820
1821 /* Setup unicast IP, EAPOL-like and ARP pkt pattern */
1822 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1823 vif->fw_vif_idx, WOW_LIST_ID,
1824 sizeof(unicst_pattern), unicst_offset,
1825 unicst_pattern, unicst_mask);
1826 if (ret) {
1827 ath6kl_err("failed to add WOW unicast IP pattern\n");
1828 return ret;
1829 }
1830
1831 /* Setup all ARP pkt pattern */
1832 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1833 vif->fw_vif_idx, WOW_LIST_ID,
1834 sizeof(arp_pattern), arp_offset,
1835 arp_pattern, arp_mask);
1836 if (ret) {
1837 ath6kl_err("failed to add WOW ARP pattern\n");
1838 return ret;
1839 }
1840
1841 /*
1842 * Setup multicast pattern for mDNS 224.0.0.251,
1843 * SSDP 239.255.255.250 and LLMNR 224.0.0.252
1844 */
1845 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1846 vif->fw_vif_idx, WOW_LIST_ID,
1847 sizeof(discvr_pattern), discvr_offset,
1848 discvr_pattern, discvr_mask);
1849 if (ret) {
1850 ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
1851 return ret;
1852 }
1853
1854 /* Setup all DHCP broadcast pkt pattern */
1855 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1856 vif->fw_vif_idx, WOW_LIST_ID,
1857 sizeof(dhcp_pattern), dhcp_offset,
1858 dhcp_pattern, dhcp_mask);
1859 if (ret) {
1860 ath6kl_err("failed to add WOW DHCP broadcast pattern\n");
1861 return ret;
1862 }
1863
1864 return 0;
1865}
1866
1867static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif)
1868{
1869 struct net_device *ndev = vif->ndev;
1870 static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
1871 static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
1872 u8 discvr_offset = 38;
1873 u8 mac_mask[ETH_ALEN];
1874 int ret;
1875
1876 /* Setup unicast pkt pattern */
1877 memset(mac_mask, 0xff, ETH_ALEN);
1878 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1879 vif->fw_vif_idx, WOW_LIST_ID,
1880 ETH_ALEN, 0, ndev->dev_addr,
1881 mac_mask);
1882 if (ret) {
1883 ath6kl_err("failed to add WOW unicast pattern\n");
1884 return ret;
1885 }
1886
1887 /*
1888 * Setup multicast pattern for mDNS 224.0.0.251,
1889 * SSDP 239.255.255.250 and LLMNR 224.0.0.252
1890 */
1891 if ((ndev->flags & IFF_ALLMULTI) ||
1892 (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev) > 0)) {
1893 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1894 vif->fw_vif_idx, WOW_LIST_ID,
1895 sizeof(discvr_pattern), discvr_offset,
1896 discvr_pattern, discvr_mask);
1897 if (ret) {
1898 ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR "
1899 "pattern\n");
1900 return ret;
1901 }
1902 }
1903
1904 return 0;
1905}
1906
1907static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
1908{
1909 struct in_device *in_dev;
1910 struct in_ifaddr *ifa;
1911 struct ath6kl_vif *vif;
1912 int ret, left;
1913 u32 filter = 0;
1914 u16 i;
1915 u8 index = 0;
1916 __be32 ips[MAX_IP_ADDRS];
1917
1918 vif = ath6kl_vif_first(ar);
1919 if (!vif)
1920 return -EIO;
1921
1922 if (!ath6kl_cfg80211_ready(vif))
1923 return -EIO;
1924
1925 if (!test_bit(CONNECTED, &vif->flags))
Raja Mani3c411a42012-01-30 17:13:12 +05301926 return -ENOTCONN;
Raja Manid91e8ee2012-01-30 17:13:10 +05301927
1928 if (wow && (wow->n_patterns > WOW_MAX_FILTERS_PER_LIST))
1929 return -EINVAL;
1930
1931 /* Clear existing WOW patterns */
1932 for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
1933 ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
1934 WOW_LIST_ID, i);
1935
1936 /*
1937 * Skip the default WOW pattern configuration
1938 * if the driver receives any WOW patterns from
1939 * the user.
1940 */
1941 if (wow)
1942 ret = ath6kl_wow_usr(ar, vif, wow, &filter);
1943 else if (vif->nw_type == AP_NETWORK)
1944 ret = ath6kl_wow_ap(ar, vif);
1945 else
1946 ret = ath6kl_wow_sta(ar, vif);
1947
1948 if (ret)
1949 return ret;
1950
Raja Manic08631c2011-12-16 14:24:24 +05301951 /* Setup own IP addr for ARP agent. */
1952 in_dev = __in_dev_get_rtnl(vif->ndev);
1953 if (!in_dev)
1954 goto skip_arp;
1955
1956 ifa = in_dev->ifa_list;
1957 memset(&ips, 0, sizeof(ips));
1958
1959 /* Configure IP addr only if IP address count < MAX_IP_ADDRS */
1960 while (index < MAX_IP_ADDRS && ifa) {
1961 ips[index] = ifa->ifa_local;
1962 ifa = ifa->ifa_next;
1963 index++;
1964 }
1965
1966 if (ifa) {
1967 ath6kl_err("total IP addr count is exceeding fw limit\n");
1968 return -EINVAL;
1969 }
1970
1971 ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]);
1972 if (ret) {
1973 ath6kl_err("fail to setup ip for arp agent\n");
1974 return ret;
1975 }
1976
1977skip_arp:
Raja Mani6cb3c712011-11-07 22:52:45 +02001978 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
1979 ATH6KL_WOW_MODE_ENABLE,
1980 filter,
1981 WOW_HOST_REQ_DELAY);
1982 if (ret)
1983 return ret;
1984
Raja Mani081c7a82012-01-30 17:13:11 +05301985 clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
1986
Raja Mani6cb3c712011-11-07 22:52:45 +02001987 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
1988 ATH6KL_HOST_MODE_ASLEEP);
1989 if (ret)
1990 return ret;
1991
Raja Mani081c7a82012-01-30 17:13:11 +05301992 left = wait_event_interruptible_timeout(ar->event_wq,
1993 test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags),
1994 WMI_TIMEOUT);
1995 if (left == 0) {
1996 ath6kl_warn("timeout, didn't get host sleep cmd "
1997 "processed event\n");
1998 ret = -ETIMEDOUT;
1999 } else if (left < 0) {
2000 ath6kl_warn("error while waiting for host sleep cmd "
2001 "processed event %d\n", left);
2002 ret = left;
2003 }
2004
Raja Mani6cb3c712011-11-07 22:52:45 +02002005 if (ar->tx_pending[ar->ctrl_ep]) {
2006 left = wait_event_interruptible_timeout(ar->event_wq,
2007 ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT);
2008 if (left == 0) {
2009 ath6kl_warn("clear wmi ctrl data timeout\n");
2010 ret = -ETIMEDOUT;
2011 } else if (left < 0) {
2012 ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
2013 ret = left;
2014 }
2015 }
2016
2017 return ret;
2018}
2019
2020static int ath6kl_wow_resume(struct ath6kl *ar)
2021{
2022 struct ath6kl_vif *vif;
2023 int ret;
2024
2025 vif = ath6kl_vif_first(ar);
2026 if (!vif)
2027 return -EIO;
2028
2029 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
2030 ATH6KL_HOST_MODE_AWAKE);
2031 return ret;
2032}
2033
Kalle Valo52d81a62011-11-01 08:44:21 +02002034int ath6kl_cfg80211_suspend(struct ath6kl *ar,
Raja Mani0f60e9f2011-11-07 22:52:45 +02002035 enum ath6kl_cfg_suspend_mode mode,
2036 struct cfg80211_wowlan *wow)
Kalle Valo52d81a62011-11-01 08:44:21 +02002037{
2038 int ret;
2039
Kalle Valo52d81a62011-11-01 08:44:21 +02002040 switch (mode) {
Raja Manid7c44e02011-11-07 22:52:46 +02002041 case ATH6KL_CFG_SUSPEND_WOW:
2042
2043 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
2044
2045 /* Flush all non control pkts in TX path */
2046 ath6kl_tx_data_cleanup(ar);
2047
2048 ret = ath6kl_wow_suspend(ar, wow);
Raja Mani1e9a9052012-03-06 15:03:59 +05302049 if (ret)
Raja Manid7c44e02011-11-07 22:52:46 +02002050 return ret;
Raja Mani1e9a9052012-03-06 15:03:59 +05302051
Raja Manid7c44e02011-11-07 22:52:46 +02002052 ar->state = ATH6KL_STATE_WOW;
2053 break;
2054
Kalle Valo52d81a62011-11-01 08:44:21 +02002055 case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
Raja Mani524441e2011-11-07 22:52:46 +02002056
Kalle Valo7125f012011-12-13 14:51:37 +02002057 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02002058
Kalle Valo52d81a62011-11-01 08:44:21 +02002059 /* save the current power mode before enabling power save */
2060 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
2061
2062 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
2063 if (ret) {
2064 ath6kl_warn("wmi powermode command failed during suspend: %d\n",
2065 ret);
2066 }
2067
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002068 ar->state = ATH6KL_STATE_DEEPSLEEP;
2069
Kalle Valo52d81a62011-11-01 08:44:21 +02002070 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002071
2072 case ATH6KL_CFG_SUSPEND_CUTPOWER:
Raja Mani524441e2011-11-07 22:52:46 +02002073
Kalle Valo7125f012011-12-13 14:51:37 +02002074 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02002075
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002076 if (ar->state == ATH6KL_STATE_OFF) {
2077 ath6kl_dbg(ATH6KL_DBG_SUSPEND,
2078 "suspend hw off, no action for cutpower\n");
2079 break;
2080 }
2081
2082 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
2083
2084 ret = ath6kl_init_hw_stop(ar);
2085 if (ret) {
2086 ath6kl_warn("failed to stop hw during suspend: %d\n",
2087 ret);
2088 }
2089
2090 ar->state = ATH6KL_STATE_CUTPOWER;
2091
2092 break;
2093
Kalle Valo10509f92011-12-13 14:52:07 +02002094 case ATH6KL_CFG_SUSPEND_SCHED_SCAN:
2095 /*
2096 * Nothing needed for schedule scan, firmware is already in
2097 * wow mode and sleeping most of the time.
2098 */
2099 break;
2100
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002101 default:
2102 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02002103 }
2104
2105 return 0;
2106}
Kalle Valod6a434d2012-01-17 20:09:36 +02002107EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
Kalle Valo52d81a62011-11-01 08:44:21 +02002108
2109int ath6kl_cfg80211_resume(struct ath6kl *ar)
2110{
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002111 int ret;
2112
2113 switch (ar->state) {
Raja Manid7c44e02011-11-07 22:52:46 +02002114 case ATH6KL_STATE_WOW:
2115 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
2116
2117 ret = ath6kl_wow_resume(ar);
2118 if (ret) {
2119 ath6kl_warn("wow mode resume failed: %d\n", ret);
2120 return ret;
2121 }
2122
2123 ar->state = ATH6KL_STATE_ON;
2124 break;
2125
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002126 case ATH6KL_STATE_DEEPSLEEP:
2127 if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
2128 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
2129 ar->wmi->saved_pwr_mode);
2130 if (ret) {
2131 ath6kl_warn("wmi powermode command failed during resume: %d\n",
2132 ret);
2133 }
2134 }
2135
2136 ar->state = ATH6KL_STATE_ON;
2137
2138 break;
2139
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002140 case ATH6KL_STATE_CUTPOWER:
2141 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
2142
2143 ret = ath6kl_init_hw_start(ar);
2144 if (ret) {
2145 ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
2146 return ret;
2147 }
Raja Manid7c44e02011-11-07 22:52:46 +02002148 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002149
Kalle Valo10509f92011-12-13 14:52:07 +02002150 case ATH6KL_STATE_SCHED_SCAN:
2151 break;
2152
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002153 default:
2154 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02002155 }
2156
2157 return 0;
2158}
Kalle Valod6a434d2012-01-17 20:09:36 +02002159EXPORT_SYMBOL(ath6kl_cfg80211_resume);
Kalle Valo52d81a62011-11-01 08:44:21 +02002160
Kalle Valoabcb3442011-07-22 08:26:20 +03002161#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02002162
2163/* hif layer decides what suspend mode to use */
2164static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
Kalle Valoabcb3442011-07-22 08:26:20 +03002165 struct cfg80211_wowlan *wow)
2166{
2167 struct ath6kl *ar = wiphy_priv(wiphy);
2168
Raja Mani0f60e9f2011-11-07 22:52:45 +02002169 return ath6kl_hif_suspend(ar, wow);
Kalle Valoabcb3442011-07-22 08:26:20 +03002170}
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002171
Kalle Valo52d81a62011-11-01 08:44:21 +02002172static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002173{
2174 struct ath6kl *ar = wiphy_priv(wiphy);
2175
2176 return ath6kl_hif_resume(ar);
2177}
Raja Mania918fb32011-11-07 22:52:46 +02002178
2179/*
2180 * FIXME: WOW suspend mode is selected if the host sdio controller supports
2181 * both sdio irq wake up and keep power. The target pulls sdio data line to
2182 * wake up the host when WOW pattern matches. This causes sdio irq handler
2183 * is being called in the host side which internally hits ath6kl's RX path.
2184 *
2185 * Since sdio interrupt is not disabled, RX path executes even before
2186 * the host executes the actual resume operation from PM module.
2187 *
2188 * In the current scenario, WOW resume should happen before start processing
2189 * any data from the target. So It's required to perform WOW resume in RX path.
2190 * Ideally we should perform WOW resume only in the actual platform
2191 * resume path. This area needs bit rework to avoid WOW resume in RX path.
2192 *
2193 * ath6kl_check_wow_status() is called from ath6kl_rx().
2194 */
2195void ath6kl_check_wow_status(struct ath6kl *ar)
2196{
2197 if (ar->state == ATH6KL_STATE_WOW)
2198 ath6kl_cfg80211_resume(ar);
2199}
2200
2201#else
2202
2203void ath6kl_check_wow_status(struct ath6kl *ar)
2204{
2205}
Kalle Valoabcb3442011-07-22 08:26:20 +03002206#endif
2207
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002208static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
2209 struct ieee80211_channel *chan,
2210 enum nl80211_channel_type channel_type)
2211{
Sujith Manoharane68f6752011-12-22 12:15:27 +05302212 struct ath6kl_vif *vif;
2213
2214 /*
2215 * 'dev' could be NULL if a channel change is required for the hardware
2216 * device itself, instead of a particular VIF.
2217 *
2218 * FIXME: To be handled properly when monitor mode is supported.
2219 */
2220 if (!dev)
2221 return -EBUSY;
2222
2223 vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002224
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302225 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002226 return -EIO;
2227
2228 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
2229 __func__, chan->center_freq, chan->hw_value);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302230 vif->next_chan = chan->center_freq;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002231
2232 return 0;
2233}
2234
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002235static bool ath6kl_is_p2p_ie(const u8 *pos)
2236{
2237 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
2238 pos[2] == 0x50 && pos[3] == 0x6f &&
2239 pos[4] == 0x9a && pos[5] == 0x09;
2240}
2241
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302242static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
2243 const u8 *ies, size_t ies_len)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002244{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302245 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002246 const u8 *pos;
2247 u8 *buf = NULL;
2248 size_t len = 0;
2249 int ret;
2250
2251 /*
2252 * Filter out P2P IE(s) since they will be included depending on
2253 * the Probe Request frame in ath6kl_send_go_probe_resp().
2254 */
2255
2256 if (ies && ies_len) {
2257 buf = kmalloc(ies_len, GFP_KERNEL);
2258 if (buf == NULL)
2259 return -ENOMEM;
2260 pos = ies;
2261 while (pos + 1 < ies + ies_len) {
2262 if (pos + 2 + pos[1] > ies + ies_len)
2263 break;
2264 if (!ath6kl_is_p2p_ie(pos)) {
2265 memcpy(buf + len, pos, 2 + pos[1]);
2266 len += 2 + pos[1];
2267 }
2268 pos += 2 + pos[1];
2269 }
2270 }
2271
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302272 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2273 WMI_FRAME_PROBE_RESP, buf, len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002274 kfree(buf);
2275 return ret;
2276}
2277
Johannes Berg88600202012-02-13 15:17:18 +01002278static int ath6kl_set_ies(struct ath6kl_vif *vif,
2279 struct cfg80211_beacon_data *info)
2280{
2281 struct ath6kl *ar = vif->ar;
2282 int res;
2283
2284 if (info->beacon_ies) {
2285 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2286 WMI_FRAME_BEACON,
2287 info->beacon_ies,
2288 info->beacon_ies_len);
2289 if (res)
2290 return res;
2291 }
2292
2293 if (info->proberesp_ies) {
2294 res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
2295 info->proberesp_ies_len);
2296 if (res)
2297 return res;
2298 }
2299
2300 if (info->assocresp_ies) {
2301 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2302 WMI_FRAME_ASSOC_RESP,
2303 info->assocresp_ies,
2304 info->assocresp_ies_len);
2305 if (res)
2306 return res;
2307 }
2308
2309 return 0;
2310}
2311
2312static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
2313 struct cfg80211_ap_settings *info)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002314{
2315 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302316 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002317 struct ieee80211_mgmt *mgmt;
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08002318 bool hidden = false;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002319 u8 *ies;
2320 int ies_len;
2321 struct wmi_connect_cmd p;
2322 int res;
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302323 int i, ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002324
Johannes Berg88600202012-02-13 15:17:18 +01002325 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s:\n", __func__);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002326
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302327 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002328 return -EIO;
2329
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302330 if (vif->next_mode != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002331 return -EOPNOTSUPP;
2332
Johannes Berg88600202012-02-13 15:17:18 +01002333 res = ath6kl_set_ies(vif, &info->beacon);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002334
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002335 ar->ap_mode_bkey.valid = false;
2336
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002337 /* TODO:
2338 * info->interval
2339 * info->dtim_period
2340 */
2341
Johannes Berg88600202012-02-13 15:17:18 +01002342 if (info->beacon.head == NULL)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002343 return -EINVAL;
Johannes Berg88600202012-02-13 15:17:18 +01002344 mgmt = (struct ieee80211_mgmt *) info->beacon.head;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002345 ies = mgmt->u.beacon.variable;
Johannes Berg88600202012-02-13 15:17:18 +01002346 if (ies > info->beacon.head + info->beacon.head_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002347 return -EINVAL;
Johannes Berg88600202012-02-13 15:17:18 +01002348 ies_len = info->beacon.head + info->beacon.head_len - ies;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002349
2350 if (info->ssid == NULL)
2351 return -EINVAL;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302352 memcpy(vif->ssid, info->ssid, info->ssid_len);
2353 vif->ssid_len = info->ssid_len;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002354 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08002355 hidden = true;
2356
2357 res = ath6kl_wmi_ap_hidden_ssid(ar->wmi, vif->fw_vif_idx, hidden);
2358 if (res)
2359 return res;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002360
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302361 ret = ath6kl_set_auth_type(vif, info->auth_type);
2362 if (ret)
2363 return ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002364
2365 memset(&p, 0, sizeof(p));
2366
2367 for (i = 0; i < info->crypto.n_akm_suites; i++) {
2368 switch (info->crypto.akm_suites[i]) {
2369 case WLAN_AKM_SUITE_8021X:
2370 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2371 p.auth_mode |= WPA_AUTH;
2372 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2373 p.auth_mode |= WPA2_AUTH;
2374 break;
2375 case WLAN_AKM_SUITE_PSK:
2376 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2377 p.auth_mode |= WPA_PSK_AUTH;
2378 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2379 p.auth_mode |= WPA2_PSK_AUTH;
2380 break;
2381 }
2382 }
2383 if (p.auth_mode == 0)
2384 p.auth_mode = NONE_AUTH;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302385 vif->auth_mode = p.auth_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002386
2387 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
2388 switch (info->crypto.ciphers_pairwise[i]) {
2389 case WLAN_CIPHER_SUITE_WEP40:
2390 case WLAN_CIPHER_SUITE_WEP104:
2391 p.prwise_crypto_type |= WEP_CRYPT;
2392 break;
2393 case WLAN_CIPHER_SUITE_TKIP:
2394 p.prwise_crypto_type |= TKIP_CRYPT;
2395 break;
2396 case WLAN_CIPHER_SUITE_CCMP:
2397 p.prwise_crypto_type |= AES_CRYPT;
2398 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002399 case WLAN_CIPHER_SUITE_SMS4:
2400 p.prwise_crypto_type |= WAPI_CRYPT;
2401 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002402 }
2403 }
Edward Lu229ed6b2011-08-30 21:58:07 +03002404 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002405 p.prwise_crypto_type = NONE_CRYPT;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302406 ath6kl_set_cipher(vif, 0, true);
Edward Lu229ed6b2011-08-30 21:58:07 +03002407 } else if (info->crypto.n_ciphers_pairwise == 1)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302408 ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002409
2410 switch (info->crypto.cipher_group) {
2411 case WLAN_CIPHER_SUITE_WEP40:
2412 case WLAN_CIPHER_SUITE_WEP104:
2413 p.grp_crypto_type = WEP_CRYPT;
2414 break;
2415 case WLAN_CIPHER_SUITE_TKIP:
2416 p.grp_crypto_type = TKIP_CRYPT;
2417 break;
2418 case WLAN_CIPHER_SUITE_CCMP:
2419 p.grp_crypto_type = AES_CRYPT;
2420 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002421 case WLAN_CIPHER_SUITE_SMS4:
2422 p.grp_crypto_type = WAPI_CRYPT;
2423 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002424 default:
2425 p.grp_crypto_type = NONE_CRYPT;
2426 break;
2427 }
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302428 ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002429
2430 p.nw_type = AP_NETWORK;
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302431 vif->nw_type = vif->next_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002432
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302433 p.ssid_len = vif->ssid_len;
2434 memcpy(p.ssid, vif->ssid, vif->ssid_len);
2435 p.dot11_auth_mode = vif->dot11_auth_mode;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302436 p.ch = cpu_to_le16(vif->next_chan);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002437
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05302438 /* Enable uAPSD support by default */
2439 res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
2440 if (res < 0)
2441 return res;
2442
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002443 if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
2444 p.nw_subtype = SUBTYPE_P2PGO;
2445 } else {
2446 /*
2447 * Due to firmware limitation, it is not possible to
2448 * do P2P mgmt operations in AP mode
2449 */
2450 p.nw_subtype = SUBTYPE_NONE;
2451 }
2452
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302453 res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002454 if (res < 0)
2455 return res;
2456
2457 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002458}
2459
Johannes Berg88600202012-02-13 15:17:18 +01002460static int ath6kl_change_beacon(struct wiphy *wiphy, struct net_device *dev,
2461 struct cfg80211_beacon_data *beacon)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002462{
Johannes Berg88600202012-02-13 15:17:18 +01002463 struct ath6kl_vif *vif = netdev_priv(dev);
2464
2465 if (!ath6kl_cfg80211_ready(vif))
2466 return -EIO;
2467
2468 if (vif->next_mode != AP_NETWORK)
2469 return -EOPNOTSUPP;
2470
2471 return ath6kl_set_ies(vif, beacon);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002472}
2473
Johannes Berg88600202012-02-13 15:17:18 +01002474static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002475{
2476 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302477 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002478
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302479 if (vif->nw_type != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002480 return -EOPNOTSUPP;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302481 if (!test_bit(CONNECTED, &vif->flags))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002482 return -ENOTCONN;
2483
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302484 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302485 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002486
2487 return 0;
2488}
2489
Jouni Malinen33e53082011-12-27 11:02:56 +02002490static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2491
2492static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
2493 u8 *mac)
2494{
2495 struct ath6kl *ar = ath6kl_priv(dev);
2496 struct ath6kl_vif *vif = netdev_priv(dev);
2497 const u8 *addr = mac ? mac : bcast_addr;
2498
2499 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
2500 addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
2501}
2502
Jouni Malinen23875132011-08-30 21:57:53 +03002503static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
2504 u8 *mac, struct station_parameters *params)
2505{
2506 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302507 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen23875132011-08-30 21:57:53 +03002508
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302509 if (vif->nw_type != AP_NETWORK)
Jouni Malinen23875132011-08-30 21:57:53 +03002510 return -EOPNOTSUPP;
2511
2512 /* Use this only for authorizing/unauthorizing a station */
2513 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
2514 return -EOPNOTSUPP;
2515
2516 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302517 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2518 WMI_AP_MLME_AUTHORIZE, mac, 0);
2519 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2520 WMI_AP_MLME_UNAUTHORIZE, mac, 0);
Jouni Malinen23875132011-08-30 21:57:53 +03002521}
2522
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002523static int ath6kl_remain_on_channel(struct wiphy *wiphy,
2524 struct net_device *dev,
2525 struct ieee80211_channel *chan,
2526 enum nl80211_channel_type channel_type,
2527 unsigned int duration,
2528 u64 *cookie)
2529{
2530 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302531 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen10522612011-10-27 16:00:13 +03002532 u32 id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002533
2534 /* TODO: if already pending or ongoing remain-on-channel,
2535 * return -EBUSY */
Jouni Malinen10522612011-10-27 16:00:13 +03002536 id = ++vif->last_roc_id;
2537 if (id == 0) {
2538 /* Do not use 0 as the cookie value */
2539 id = ++vif->last_roc_id;
2540 }
2541 *cookie = id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002542
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302543 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
2544 chan->center_freq, duration);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002545}
2546
2547static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
2548 struct net_device *dev,
2549 u64 cookie)
2550{
2551 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302552 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002553
Jouni Malinen10522612011-10-27 16:00:13 +03002554 if (cookie != vif->last_roc_id)
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002555 return -ENOENT;
Jouni Malinen10522612011-10-27 16:00:13 +03002556 vif->last_cancel_roc_id = cookie;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002557
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302558 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002559}
2560
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302561static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
2562 const u8 *buf, size_t len,
2563 unsigned int freq)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002564{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302565 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002566 const u8 *pos;
2567 u8 *p2p;
2568 int p2p_len;
2569 int ret;
2570 const struct ieee80211_mgmt *mgmt;
2571
2572 mgmt = (const struct ieee80211_mgmt *) buf;
2573
2574 /* Include P2P IE(s) from the frame generated in user space. */
2575
2576 p2p = kmalloc(len, GFP_KERNEL);
2577 if (p2p == NULL)
2578 return -ENOMEM;
2579 p2p_len = 0;
2580
2581 pos = mgmt->u.probe_resp.variable;
2582 while (pos + 1 < buf + len) {
2583 if (pos + 2 + pos[1] > buf + len)
2584 break;
2585 if (ath6kl_is_p2p_ie(pos)) {
2586 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
2587 p2p_len += 2 + pos[1];
2588 }
2589 pos += 2 + pos[1];
2590 }
2591
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302592 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
2593 mgmt->da, p2p, p2p_len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002594 kfree(p2p);
2595 return ret;
2596}
2597
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002598static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif,
2599 u32 id,
2600 u32 freq,
2601 u32 wait,
2602 const u8 *buf,
2603 size_t len,
2604 bool *more_data,
2605 bool no_cck)
2606{
2607 struct ieee80211_mgmt *mgmt;
2608 struct ath6kl_sta *conn;
2609 bool is_psq_empty = false;
2610 struct ath6kl_mgmt_buff *mgmt_buf;
2611 size_t mgmt_buf_size;
2612 struct ath6kl *ar = vif->ar;
2613
2614 mgmt = (struct ieee80211_mgmt *) buf;
2615 if (is_multicast_ether_addr(mgmt->da))
2616 return false;
2617
2618 conn = ath6kl_find_sta(vif, mgmt->da);
2619 if (!conn)
2620 return false;
2621
2622 if (conn->sta_flags & STA_PS_SLEEP) {
2623 if (!(conn->sta_flags & STA_PS_POLLED)) {
2624 /* Queue the frames if the STA is sleeping */
2625 mgmt_buf_size = len + sizeof(struct ath6kl_mgmt_buff);
2626 mgmt_buf = kmalloc(mgmt_buf_size, GFP_KERNEL);
2627 if (!mgmt_buf)
2628 return false;
2629
2630 INIT_LIST_HEAD(&mgmt_buf->list);
2631 mgmt_buf->id = id;
2632 mgmt_buf->freq = freq;
2633 mgmt_buf->wait = wait;
2634 mgmt_buf->len = len;
2635 mgmt_buf->no_cck = no_cck;
2636 memcpy(mgmt_buf->buf, buf, len);
2637 spin_lock_bh(&conn->psq_lock);
2638 is_psq_empty = skb_queue_empty(&conn->psq) &&
2639 (conn->mgmt_psq_len == 0);
2640 list_add_tail(&mgmt_buf->list, &conn->mgmt_psq);
2641 conn->mgmt_psq_len++;
2642 spin_unlock_bh(&conn->psq_lock);
2643
2644 /*
2645 * If this is the first pkt getting queued
2646 * for this STA, update the PVB for this
2647 * STA.
2648 */
2649 if (is_psq_empty)
2650 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
2651 conn->aid, 1);
2652 return true;
2653 }
2654
2655 /*
2656 * This tx is because of a PsPoll.
2657 * Determine if MoreData bit has to be set.
2658 */
2659 spin_lock_bh(&conn->psq_lock);
2660 if (!skb_queue_empty(&conn->psq) || (conn->mgmt_psq_len != 0))
2661 *more_data = true;
2662 spin_unlock_bh(&conn->psq_lock);
2663 }
2664
2665 return false;
2666}
2667
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002668static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2669 struct ieee80211_channel *chan, bool offchan,
2670 enum nl80211_channel_type channel_type,
2671 bool channel_type_valid, unsigned int wait,
Johannes Berge247bd902011-11-04 11:18:21 +01002672 const u8 *buf, size_t len, bool no_cck,
2673 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002674{
2675 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302676 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002677 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002678 const struct ieee80211_mgmt *mgmt;
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002679 bool more_data, queued;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002680
2681 mgmt = (const struct ieee80211_mgmt *) buf;
2682 if (buf + len >= mgmt->u.probe_resp.variable &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302683 vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002684 ieee80211_is_probe_resp(mgmt->frame_control)) {
2685 /*
2686 * Send Probe Response frame in AP mode using a separate WMI
2687 * command to allow the target to fill in the generic IEs.
2688 */
2689 *cookie = 0; /* TX status not supported */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302690 return ath6kl_send_go_probe_resp(vif, buf, len,
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002691 chan->center_freq);
2692 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002693
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302694 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002695 if (id == 0) {
2696 /*
2697 * 0 is a reserved value in the WMI command and shall not be
2698 * used for the command.
2699 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302700 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002701 }
2702
2703 *cookie = id;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002704
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002705 /* AP mode Power saving processing */
2706 if (vif->nw_type == AP_NETWORK) {
2707 queued = ath6kl_mgmt_powersave_ap(vif,
2708 id, chan->center_freq,
2709 wait, buf,
2710 len, &more_data, no_cck);
2711 if (queued)
2712 return 0;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002713 }
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002714
2715 return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id,
2716 chan->center_freq, wait,
2717 buf, len, no_cck);
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002718}
2719
Jouni Malinenae32c302011-08-30 21:58:01 +03002720static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
2721 struct net_device *dev,
2722 u16 frame_type, bool reg)
2723{
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302724 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinenae32c302011-08-30 21:58:01 +03002725
2726 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
2727 __func__, frame_type, reg);
2728 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
2729 /*
2730 * Note: This notification callback is not allowed to sleep, so
2731 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
2732 * hardcode target to report Probe Request frames all the time.
2733 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302734 vif->probe_req_report = reg;
Jouni Malinenae32c302011-08-30 21:58:01 +03002735 }
2736}
2737
Kalle Valo10509f92011-12-13 14:52:07 +02002738static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
2739 struct net_device *dev,
2740 struct cfg80211_sched_scan_request *request)
2741{
2742 struct ath6kl *ar = ath6kl_priv(dev);
2743 struct ath6kl_vif *vif = netdev_priv(dev);
2744 u16 interval;
2745 int ret;
2746 u8 i;
2747
2748 if (ar->state != ATH6KL_STATE_ON)
2749 return -EIO;
2750
2751 if (vif->sme_state != SME_DISCONNECTED)
2752 return -EBUSY;
2753
2754 for (i = 0; i < ar->wiphy->max_sched_scan_ssids; i++) {
2755 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2756 i, DISABLE_SSID_FLAG,
2757 0, NULL);
2758 }
2759
2760 /* fw uses seconds, also make sure that it's >0 */
2761 interval = max_t(u16, 1, request->interval / 1000);
2762
2763 ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
2764 interval, interval,
2765 10, 0, 0, 0, 3, 0, 0, 0);
2766
2767 if (request->n_ssids && request->ssids[0].ssid_len) {
2768 for (i = 0; i < request->n_ssids; i++) {
2769 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2770 i, SPECIFIC_SSID_FLAG,
2771 request->ssids[i].ssid_len,
2772 request->ssids[i].ssid);
2773 }
2774 }
2775
2776 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
2777 ATH6KL_WOW_MODE_ENABLE,
2778 WOW_FILTER_SSID,
2779 WOW_HOST_REQ_DELAY);
2780 if (ret) {
2781 ath6kl_warn("Failed to enable wow with ssid filter: %d\n", ret);
2782 return ret;
2783 }
2784
2785 /* this also clears IE in fw if it's not set */
2786 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2787 WMI_FRAME_PROBE_REQ,
2788 request->ie, request->ie_len);
2789 if (ret) {
2790 ath6kl_warn("Failed to set probe request IE for scheduled scan: %d",
2791 ret);
2792 return ret;
2793 }
2794
2795 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
2796 ATH6KL_HOST_MODE_ASLEEP);
2797 if (ret) {
2798 ath6kl_warn("Failed to enable host sleep mode for sched scan: %d\n",
2799 ret);
2800 return ret;
2801 }
2802
2803 ar->state = ATH6KL_STATE_SCHED_SCAN;
2804
2805 return ret;
2806}
2807
2808static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy,
2809 struct net_device *dev)
2810{
2811 struct ath6kl_vif *vif = netdev_priv(dev);
2812 bool stopped;
2813
2814 stopped = __ath6kl_cfg80211_sscan_stop(vif);
2815
2816 if (!stopped)
2817 return -EIO;
2818
2819 return 0;
2820}
2821
Jouni Malinenf80574a2011-08-30 21:58:04 +03002822static const struct ieee80211_txrx_stypes
2823ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
2824 [NL80211_IFTYPE_STATION] = {
2825 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2826 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2827 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2828 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2829 },
Jouni Malinenba1f6fe2011-12-27 11:03:53 +02002830 [NL80211_IFTYPE_AP] = {
2831 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2832 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2833 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2834 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2835 },
Jouni Malinenf80574a2011-08-30 21:58:04 +03002836 [NL80211_IFTYPE_P2P_CLIENT] = {
2837 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2838 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2839 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2840 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2841 },
2842 [NL80211_IFTYPE_P2P_GO] = {
2843 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2844 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2845 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2846 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2847 },
2848};
2849
Kalle Valobdcd8172011-07-18 00:22:30 +03002850static struct cfg80211_ops ath6kl_cfg80211_ops = {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302851 .add_virtual_intf = ath6kl_cfg80211_add_iface,
2852 .del_virtual_intf = ath6kl_cfg80211_del_iface,
Kalle Valobdcd8172011-07-18 00:22:30 +03002853 .change_virtual_intf = ath6kl_cfg80211_change_iface,
2854 .scan = ath6kl_cfg80211_scan,
2855 .connect = ath6kl_cfg80211_connect,
2856 .disconnect = ath6kl_cfg80211_disconnect,
2857 .add_key = ath6kl_cfg80211_add_key,
2858 .get_key = ath6kl_cfg80211_get_key,
2859 .del_key = ath6kl_cfg80211_del_key,
2860 .set_default_key = ath6kl_cfg80211_set_default_key,
2861 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
2862 .set_tx_power = ath6kl_cfg80211_set_txpower,
2863 .get_tx_power = ath6kl_cfg80211_get_txpower,
2864 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
2865 .join_ibss = ath6kl_cfg80211_join_ibss,
2866 .leave_ibss = ath6kl_cfg80211_leave_ibss,
2867 .get_station = ath6kl_get_station,
2868 .set_pmksa = ath6kl_set_pmksa,
2869 .del_pmksa = ath6kl_del_pmksa,
2870 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03002871 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03002872#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02002873 .suspend = __ath6kl_cfg80211_suspend,
2874 .resume = __ath6kl_cfg80211_resume,
Kalle Valoabcb3442011-07-22 08:26:20 +03002875#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002876 .set_channel = ath6kl_set_channel,
Johannes Berg88600202012-02-13 15:17:18 +01002877 .start_ap = ath6kl_start_ap,
2878 .change_beacon = ath6kl_change_beacon,
2879 .stop_ap = ath6kl_stop_ap,
Jouni Malinen33e53082011-12-27 11:02:56 +02002880 .del_station = ath6kl_del_station,
Jouni Malinen23875132011-08-30 21:57:53 +03002881 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002882 .remain_on_channel = ath6kl_remain_on_channel,
2883 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002884 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03002885 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valo10509f92011-12-13 14:52:07 +02002886 .sched_scan_start = ath6kl_cfg80211_sscan_start,
2887 .sched_scan_stop = ath6kl_cfg80211_sscan_stop,
Kalle Valobdcd8172011-07-18 00:22:30 +03002888};
2889
Kalle Valo7125f012011-12-13 14:51:37 +02002890void ath6kl_cfg80211_stop(struct ath6kl_vif *vif)
Kalle Valoec4b7f62011-11-01 08:44:04 +02002891{
Kalle Valo10509f92011-12-13 14:52:07 +02002892 ath6kl_cfg80211_sscan_disable(vif);
2893
Kalle Valoec4b7f62011-11-01 08:44:04 +02002894 switch (vif->sme_state) {
Kalle Valoc97a31b2011-12-13 14:51:10 +02002895 case SME_DISCONNECTED:
2896 break;
Kalle Valoec4b7f62011-11-01 08:44:04 +02002897 case SME_CONNECTING:
2898 cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
2899 NULL, 0,
2900 WLAN_STATUS_UNSPECIFIED_FAILURE,
2901 GFP_KERNEL);
2902 break;
2903 case SME_CONNECTED:
Kalle Valoec4b7f62011-11-01 08:44:04 +02002904 cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
2905 break;
2906 }
2907
2908 if (test_bit(CONNECTED, &vif->flags) ||
2909 test_bit(CONNECT_PEND, &vif->flags))
Kalle Valo7125f012011-12-13 14:51:37 +02002910 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002911
2912 vif->sme_state = SME_DISCONNECTED;
Kalle Valo1f40525512011-11-01 08:44:13 +02002913 clear_bit(CONNECTED, &vif->flags);
2914 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002915
2916 /* disable scanning */
Kalle Valo7125f012011-12-13 14:51:37 +02002917 if (ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF,
2918 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0)
2919 ath6kl_warn("failed to disable scan during stop\n");
Kalle Valoec4b7f62011-11-01 08:44:04 +02002920
2921 ath6kl_cfg80211_scan_complete_event(vif, true);
2922}
2923
Kalle Valo7125f012011-12-13 14:51:37 +02002924void ath6kl_cfg80211_stop_all(struct ath6kl *ar)
2925{
2926 struct ath6kl_vif *vif;
2927
2928 vif = ath6kl_vif_first(ar);
2929 if (!vif) {
2930 /* save the current power mode before enabling power save */
2931 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
2932
2933 if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
2934 ath6kl_warn("ath6kl_deep_sleep_enable: "
2935 "wmi_powermode_cmd failed\n");
2936 return;
2937 }
2938
2939 /*
2940 * FIXME: we should take ar->list_lock to protect changes in the
2941 * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop()
2942 * sleeps.
2943 */
2944 list_for_each_entry(vif, &ar->vif_list, list)
2945 ath6kl_cfg80211_stop(vif);
2946}
2947
Kalle Valoc25889e2012-01-17 20:08:27 +02002948static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03002949{
Vasanthakumar Thiagarajan7baef812012-01-21 15:22:50 +05302950 vif->aggr_cntxt = aggr_init(vif);
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302951 if (!vif->aggr_cntxt) {
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302952 ath6kl_err("failed to initialize aggr\n");
2953 return -ENOMEM;
2954 }
Kalle Valobdcd8172011-07-18 00:22:30 +03002955
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302956 setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302957 (unsigned long) vif->ndev);
Kalle Valo10509f92011-12-13 14:52:07 +02002958 setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer,
2959 (unsigned long) vif);
2960
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302961 set_bit(WMM_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05302962 spin_lock_init(&vif->if_lock);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302963
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302964 INIT_LIST_HEAD(&vif->mc_filter);
2965
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302966 return 0;
2967}
2968
Kalle Valoc25889e2012-01-17 20:08:27 +02002969void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302970{
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302971 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302972 struct ath6kl_mc_filter *mc_filter, *tmp;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302973
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302974 aggr_module_destroy(vif->aggr_cntxt);
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302975
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302976 ar->avail_idx_map |= BIT(vif->fw_vif_idx);
2977
2978 if (vif->nw_type == ADHOC_NETWORK)
2979 ar->ibss_if_active = false;
2980
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302981 list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
2982 list_del(&mc_filter->list);
2983 kfree(mc_filter);
2984 }
2985
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05302986 unregister_netdevice(vif->ndev);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302987
2988 ar->num_vif--;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302989}
2990
2991struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name,
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302992 enum nl80211_iftype type, u8 fw_vif_idx,
2993 u8 nw_type)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302994{
2995 struct net_device *ndev;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302996 struct ath6kl_vif *vif;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302997
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302998 ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302999 if (!ndev)
3000 return NULL;
3001
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05303002 vif = netdev_priv(ndev);
3003 ndev->ieee80211_ptr = &vif->wdev;
3004 vif->wdev.wiphy = ar->wiphy;
3005 vif->ar = ar;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05303006 vif->ndev = ndev;
3007 SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
3008 vif->wdev.netdev = ndev;
3009 vif->wdev.iftype = type;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303010 vif->fw_vif_idx = fw_vif_idx;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303011 vif->nw_type = vif->next_mode = nw_type;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303012
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303013 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
3014 if (fw_vif_idx != 0)
3015 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
3016 0x2;
3017
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303018 init_netdev(ndev);
3019
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +05303020 ath6kl_init_control_info(vif);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303021
Kalle Valoc25889e2012-01-17 20:08:27 +02003022 if (ath6kl_cfg80211_vif_init(vif))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303023 goto err;
3024
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05303025 if (register_netdevice(ndev))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303026 goto err;
3027
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303028 ar->avail_idx_map &= ~BIT(fw_vif_idx);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +05303029 vif->sme_state = SME_DISCONNECTED;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05303030 set_bit(WLAN_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303031 ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05303032 set_bit(NETDEV_REGISTERED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303033
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303034 if (type == NL80211_IFTYPE_ADHOC)
3035 ar->ibss_if_active = true;
3036
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05303037 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303038 list_add_tail(&vif->list, &ar->vif_list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05303039 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303040
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303041 return ndev;
3042
3043err:
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05303044 aggr_module_destroy(vif->aggr_cntxt);
3045 free_netdev(ndev);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303046 return NULL;
3047}
3048
Kalle Valo46d33a22012-01-17 20:08:40 +02003049int ath6kl_cfg80211_init(struct ath6kl *ar)
3050{
3051 struct wiphy *wiphy = ar->wiphy;
3052 int ret;
3053
3054 wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
3055
3056 wiphy->max_remain_on_channel_duration = 5000;
3057
3058 /* set device pointer for wiphy */
3059 set_wiphy_dev(wiphy, ar->dev);
3060
3061 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3062 BIT(NL80211_IFTYPE_ADHOC) |
3063 BIT(NL80211_IFTYPE_AP);
3064 if (ar->p2p) {
3065 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
3066 BIT(NL80211_IFTYPE_P2P_CLIENT);
3067 }
3068
3069 /* max num of ssids that can be probed during scanning */
3070 wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
3071 wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
3072 wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
3073 wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
3074 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3075
3076 wiphy->cipher_suites = cipher_suites;
3077 wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3078
3079 wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
3080 WIPHY_WOWLAN_DISCONNECT |
3081 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
3082 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
3083 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
3084 WIPHY_WOWLAN_4WAY_HANDSHAKE;
3085 wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST;
3086 wiphy->wowlan.pattern_min_len = 1;
3087 wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE;
3088
3089 wiphy->max_sched_scan_ssids = 10;
3090
Vasanthakumar Thiagarajanf2afdac2012-02-28 20:20:19 +05303091 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
3092 WIPHY_FLAG_HAVE_AP_SME |
3093 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
3094 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
3095
3096 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
3097 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
3098
3099 ar->wiphy->probe_resp_offload =
3100 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
3101 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
3102 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
3103 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
3104
Kalle Valo46d33a22012-01-17 20:08:40 +02003105 ret = wiphy_register(wiphy);
3106 if (ret < 0) {
3107 ath6kl_err("couldn't register wiphy device\n");
3108 return ret;
3109 }
3110
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +05303111 ar->wiphy_registered = true;
3112
Kalle Valo46d33a22012-01-17 20:08:40 +02003113 return 0;
3114}
3115
3116void ath6kl_cfg80211_cleanup(struct ath6kl *ar)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303117{
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05303118 wiphy_unregister(ar->wiphy);
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +05303119
3120 ar->wiphy_registered = false;
Kalle Valo45eaa782012-01-17 20:09:05 +02003121}
Kalle Valo46d33a22012-01-17 20:08:40 +02003122
Kalle Valo45eaa782012-01-17 20:09:05 +02003123struct ath6kl *ath6kl_cfg80211_create(void)
3124{
3125 struct ath6kl *ar;
3126 struct wiphy *wiphy;
3127
3128 /* create a new wiphy for use with cfg80211 */
3129 wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
3130
3131 if (!wiphy) {
3132 ath6kl_err("couldn't allocate wiphy device\n");
3133 return NULL;
3134 }
3135
3136 ar = wiphy_priv(wiphy);
3137 ar->wiphy = wiphy;
3138
3139 return ar;
3140}
3141
3142/* Note: ar variable must not be accessed after calling this! */
3143void ath6kl_cfg80211_destroy(struct ath6kl *ar)
3144{
Vasanthakumar Thiagarajan1d2a4452012-01-21 15:22:53 +05303145 int i;
3146
3147 for (i = 0; i < AP_MAX_NUM_STA; i++)
3148 kfree(ar->sta_list[i].aggr_conn);
3149
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05303150 wiphy_free(ar->wiphy);
Kalle Valobdcd8172011-07-18 00:22:30 +03003151}
Kalle Valo45eaa782012-01-17 20:09:05 +02003152