blob: 50b76d0a4c6a5b3823cb4494074be0dca53461c4 [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
Kalle Valo10509f92011-12-13 14:52:07 +0200888 /*
889 * FIXME: we should clear the IE in fw if it's not set so just
890 * remove the check altogether
891 */
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300892 if (request->ie) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530893 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
894 WMI_FRAME_PROBE_REQ,
Jouni Malinenb84da8c2011-08-30 21:57:59 +0300895 request->ie, request->ie_len);
896 if (ret) {
897 ath6kl_err("failed to set Probe Request appie for "
898 "scan");
899 return ret;
900 }
901 }
902
Jouni Malinen11869be2011-09-02 20:07:06 +0300903 /*
904 * Scan only the requested channels if the request specifies a set of
905 * channels. If the list is longer than the target supports, do not
906 * configure the list and instead, scan all available channels.
907 */
908 if (request->n_channels > 0 &&
909 request->n_channels <= WMI_MAX_CHANNELS) {
Edward Lu1276c9e2011-08-30 21:58:00 +0300910 u8 i;
911
Jouni Malinen11869be2011-09-02 20:07:06 +0300912 n_channels = request->n_channels;
Edward Lu1276c9e2011-08-30 21:58:00 +0300913
914 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
915 if (channels == NULL) {
916 ath6kl_warn("failed to set scan channels, "
917 "scan all channels");
918 n_channels = 0;
919 }
920
921 for (i = 0; i < n_channels; i++)
922 channels[i] = request->channels[i]->center_freq;
923 }
924
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530925 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajanf1f92172011-10-01 16:12:36 +0530926 force_fg_scan = 1;
927
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800928 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
929 ar->fw_capabilities)) {
930 /*
931 * If capable of doing P2P mgmt operations using
932 * station interface, send additional information like
933 * supported rates to advertise and xmit rates for
934 * probe requests
935 */
936 ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx,
937 WMI_LONG_SCAN, force_fg_scan,
Vasanthakumar Thiagarajan13423c32012-02-21 15:30:42 +0530938 false, 0,
939 ATH6KL_FG_SCAN_INTERVAL,
940 n_channels, channels,
941 request->no_cck,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800942 request->rates);
943 } else {
944 ret = ath6kl_wmi_startscan_cmd(ar->wmi, vif->fw_vif_idx,
945 WMI_LONG_SCAN, force_fg_scan,
Vasanthakumar Thiagarajan13423c32012-02-21 15:30:42 +0530946 false, 0,
947 ATH6KL_FG_SCAN_INTERVAL,
948 n_channels, channels);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -0800949 }
Jouni Malinen1b1e6ee2011-08-30 21:58:10 +0300950 if (ret)
Kalle Valobdcd8172011-07-18 00:22:30 +0300951 ath6kl_err("wmi_startscan_cmd failed\n");
Jouni Malinen11869be2011-09-02 20:07:06 +0300952 else
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530953 vif->scan_req = request;
Kalle Valobdcd8172011-07-18 00:22:30 +0300954
Edward Lu1276c9e2011-08-30 21:58:00 +0300955 kfree(channels);
956
Kalle Valobdcd8172011-07-18 00:22:30 +0300957 return ret;
958}
959
Kalle Valo1c17d312011-11-01 08:43:56 +0200960void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted)
Kalle Valobdcd8172011-07-18 00:22:30 +0300961{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530962 struct ath6kl *ar = vif->ar;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300963 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300964
Kalle Valo1c17d312011-11-01 08:43:56 +0200965 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__,
966 aborted ? " aborted" : "");
Kalle Valobdcd8172011-07-18 00:22:30 +0300967
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530968 if (!vif->scan_req)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300969 return;
Kalle Valobdcd8172011-07-18 00:22:30 +0300970
Kalle Valo1c17d312011-11-01 08:43:56 +0200971 if (aborted)
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300972 goto out;
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300973
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530974 if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) {
975 for (i = 0; i < vif->scan_req->n_ssids; i++) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530976 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
977 i + 1, DISABLE_SSID_FLAG,
Kalle Valo6fd1eac2011-07-21 10:22:50 +0300978 0, NULL);
979 }
980 }
981
982out:
Kalle Valocb938212011-10-27 18:47:46 +0300983 cfg80211_scan_done(vif->scan_req, aborted);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530984 vif->scan_req = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300985}
986
987static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
988 u8 key_index, bool pairwise,
989 const u8 *mac_addr,
990 struct key_params *params)
991{
Kalle Valod6d5c062011-11-25 13:17:37 +0200992 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530993 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300994 struct ath6kl_key *key = NULL;
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +0530995 int seq_len;
Kalle Valobdcd8172011-07-18 00:22:30 +0300996 u8 key_usage;
997 u8 key_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300998
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530999 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001000 return -EIO;
1001
Jouni Malinen837cb972011-10-11 17:31:57 +03001002 if (params->cipher == CCKM_KRK_CIPHER_SUITE) {
1003 if (params->key_len != WMI_KRK_LEN)
1004 return -EINVAL;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301005 return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx,
1006 params->key);
Jouni Malinen837cb972011-10-11 17:31:57 +03001007 }
1008
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301009 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001010 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1011 "%s: key index %d out of bounds\n", __func__,
1012 key_index);
1013 return -ENOENT;
1014 }
1015
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301016 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001017 memset(key, 0, sizeof(struct ath6kl_key));
1018
1019 if (pairwise)
1020 key_usage = PAIRWISE_USAGE;
1021 else
1022 key_usage = GROUP_USAGE;
1023
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301024 seq_len = params->seq_len;
1025 if (params->cipher == WLAN_CIPHER_SUITE_SMS4 &&
1026 seq_len > ATH6KL_KEY_SEQ_LEN) {
1027 /* Only first half of the WPI PN is configured */
1028 seq_len = ATH6KL_KEY_SEQ_LEN;
Kalle Valobdcd8172011-07-18 00:22:30 +03001029 }
Sujith Manoharan4a8ce2f2012-01-10 09:53:38 +05301030 if (params->key_len > WLAN_MAX_KEY_LEN ||
1031 seq_len > sizeof(key->seq))
1032 return -EINVAL;
1033
1034 key->key_len = params->key_len;
1035 memcpy(key->key, params->key, key->key_len);
1036 key->seq_len = seq_len;
1037 memcpy(key->seq, params->seq, key->seq_len);
1038 key->cipher = params->cipher;
Kalle Valobdcd8172011-07-18 00:22:30 +03001039
1040 switch (key->cipher) {
1041 case WLAN_CIPHER_SUITE_WEP40:
1042 case WLAN_CIPHER_SUITE_WEP104:
1043 key_type = WEP_CRYPT;
1044 break;
1045
1046 case WLAN_CIPHER_SUITE_TKIP:
1047 key_type = TKIP_CRYPT;
1048 break;
1049
1050 case WLAN_CIPHER_SUITE_CCMP:
1051 key_type = AES_CRYPT;
1052 break;
Dai Shuibing5e070212011-11-03 11:39:37 +02001053 case WLAN_CIPHER_SUITE_SMS4:
1054 key_type = WAPI_CRYPT;
1055 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001056
1057 default:
1058 return -ENOTSUPP;
1059 }
1060
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301061 if (((vif->auth_mode == WPA_PSK_AUTH)
1062 || (vif->auth_mode == WPA2_PSK_AUTH))
Kalle Valobdcd8172011-07-18 00:22:30 +03001063 && (key_usage & GROUP_USAGE))
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301064 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001065
1066 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1067 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
1068 __func__, key_index, key->key_len, key_type,
1069 key_usage, key->seq_len);
1070
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301071 if (vif->nw_type == AP_NETWORK && !pairwise &&
Jouni Malinen47032902011-12-08 16:50:30 +02001072 (key_type == TKIP_CRYPT || key_type == AES_CRYPT ||
Vasanthakumar Thiagarajancc4d6232012-02-14 20:33:00 +05301073 key_type == WAPI_CRYPT)) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001074 ar->ap_mode_bkey.valid = true;
1075 ar->ap_mode_bkey.key_index = key_index;
1076 ar->ap_mode_bkey.key_type = key_type;
1077 ar->ap_mode_bkey.key_len = key->key_len;
1078 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301079 if (!test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001080 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
1081 "key configuration until AP mode has been "
1082 "started\n");
1083 /*
1084 * The key will be set in ath6kl_connect_ap_mode() once
1085 * the connected event is received from the target.
1086 */
1087 return 0;
1088 }
1089 }
1090
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301091 if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301092 !test_bit(CONNECTED, &vif->flags)) {
Jouni Malinen151411e2011-09-15 15:10:16 +03001093 /*
1094 * Store the key locally so that it can be re-configured after
1095 * the AP mode has properly started
1096 * (ath6kl_install_statioc_wep_keys).
1097 */
1098 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration "
1099 "until AP mode has been started\n");
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301100 vif->wep_key_list[key_index].key_len = key->key_len;
1101 memcpy(vif->wep_key_list[key_index].key, key->key,
1102 key->key_len);
Jouni Malinen151411e2011-09-15 15:10:16 +03001103 return 0;
1104 }
1105
Vasanthakumar Thiagarajan7cefa442011-11-11 20:33:00 +05301106 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, key_index,
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001107 key_type, key_usage, key->key_len,
1108 key->seq, key->seq_len, key->key,
1109 KEY_OP_INIT_VAL,
1110 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001111}
1112
1113static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
1114 u8 key_index, bool pairwise,
1115 const u8 *mac_addr)
1116{
Kalle Valod6d5c062011-11-25 13:17:37 +02001117 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301118 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001119
1120 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1121
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301122 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001123 return -EIO;
1124
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301125 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001126 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1127 "%s: key index %d out of bounds\n", __func__,
1128 key_index);
1129 return -ENOENT;
1130 }
1131
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301132 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001133 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1134 "%s: index %d is empty\n", __func__, key_index);
1135 return 0;
1136 }
1137
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301138 vif->keys[key_index].key_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001139
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301140 return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001141}
1142
1143static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
1144 u8 key_index, bool pairwise,
1145 const u8 *mac_addr, void *cookie,
1146 void (*callback) (void *cookie,
1147 struct key_params *))
1148{
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301149 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001150 struct ath6kl_key *key = NULL;
1151 struct key_params params;
1152
1153 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1154
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301155 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001156 return -EIO;
1157
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301158 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001159 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1160 "%s: key index %d out of bounds\n", __func__,
1161 key_index);
1162 return -ENOENT;
1163 }
1164
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301165 key = &vif->keys[key_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001166 memset(&params, 0, sizeof(params));
1167 params.cipher = key->cipher;
1168 params.key_len = key->key_len;
1169 params.seq_len = key->seq_len;
1170 params.seq = key->seq;
1171 params.key = key->key;
1172
1173 callback(cookie, &params);
1174
1175 return key->key_len ? 0 : -ENOENT;
1176}
1177
1178static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1179 struct net_device *ndev,
1180 u8 key_index, bool unicast,
1181 bool multicast)
1182{
Kalle Valod6d5c062011-11-25 13:17:37 +02001183 struct ath6kl *ar = ath6kl_priv(ndev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301184 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001185 struct ath6kl_key *key = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001186 u8 key_usage;
Edward Lu229ed6b2011-08-30 21:58:07 +03001187 enum crypto_type key_type = NONE_CRYPT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001188
1189 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1190
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301191 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001192 return -EIO;
1193
Vivek Natarajan792ecb32011-12-29 16:18:39 +05301194 if (key_index > WMI_MAX_KEY_INDEX) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001195 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1196 "%s: key index %d out of bounds\n",
1197 __func__, key_index);
1198 return -ENOENT;
1199 }
1200
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301201 if (!vif->keys[key_index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001202 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1203 __func__, key_index);
1204 return -EINVAL;
1205 }
1206
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301207 vif->def_txkey_index = key_index;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301208 key = &vif->keys[vif->def_txkey_index];
Kalle Valobdcd8172011-07-18 00:22:30 +03001209 key_usage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301210 if (vif->prwise_crypto == WEP_CRYPT)
Kalle Valobdcd8172011-07-18 00:22:30 +03001211 key_usage |= TX_USAGE;
Edward Lu229ed6b2011-08-30 21:58:07 +03001212 if (unicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301213 key_type = vif->prwise_crypto;
Edward Lu229ed6b2011-08-30 21:58:07 +03001214 if (multicast)
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301215 key_type = vif->grp_crypto;
Kalle Valobdcd8172011-07-18 00:22:30 +03001216
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301217 if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags))
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001218 return 0; /* Delay until AP mode has been started */
1219
Jouni Malinenf3e61ec2011-11-02 23:46:47 +02001220 return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
1221 vif->def_txkey_index,
1222 key_type, key_usage,
1223 key->key_len, key->seq, key->seq_len,
1224 key->key,
1225 KEY_OP_INIT_VAL, NULL,
1226 SYNC_BOTH_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001227}
1228
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301229void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001230 bool ismcast)
1231{
1232 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1233 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1234
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301235 cfg80211_michael_mic_failure(vif->ndev, vif->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001236 (ismcast ? NL80211_KEYTYPE_GROUP :
1237 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1238 GFP_KERNEL);
1239}
1240
1241static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1242{
1243 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301244 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001245 int ret;
1246
1247 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1248 changed);
1249
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301250 vif = ath6kl_vif_first(ar);
1251 if (!vif)
1252 return -EIO;
1253
1254 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001255 return -EIO;
1256
1257 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1258 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1259 if (ret != 0) {
1260 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1261 return -EIO;
1262 }
1263 }
1264
1265 return 0;
1266}
1267
1268/*
1269 * The type nl80211_tx_power_setting replaces the following
1270 * data type from 2.6.36 onwards
1271*/
1272static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1273 enum nl80211_tx_power_setting type,
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001274 int mbm)
Kalle Valobdcd8172011-07-18 00:22:30 +03001275{
1276 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301277 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001278 u8 ath6kl_dbm;
Luis R. Rodriguezb992a282011-11-23 11:08:14 -05001279 int dbm = MBM_TO_DBM(mbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001280
1281 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1282 type, dbm);
1283
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301284 vif = ath6kl_vif_first(ar);
1285 if (!vif)
1286 return -EIO;
1287
1288 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001289 return -EIO;
1290
1291 switch (type) {
1292 case NL80211_TX_POWER_AUTOMATIC:
1293 return 0;
1294 case NL80211_TX_POWER_LIMITED:
1295 ar->tx_pwr = ath6kl_dbm = dbm;
1296 break;
1297 default:
1298 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1299 __func__, type);
1300 return -EOPNOTSUPP;
1301 }
1302
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301303 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, ath6kl_dbm);
Kalle Valobdcd8172011-07-18 00:22:30 +03001304
1305 return 0;
1306}
1307
1308static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1309{
1310 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301311 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001312
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301313 vif = ath6kl_vif_first(ar);
1314 if (!vif)
1315 return -EIO;
1316
1317 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001318 return -EIO;
1319
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301320 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001321 ar->tx_pwr = 0;
1322
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301323 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001324 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1325 return -EIO;
1326 }
1327
1328 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1329 5 * HZ);
1330
1331 if (signal_pending(current)) {
1332 ath6kl_err("target did not respond\n");
1333 return -EINTR;
1334 }
1335 }
1336
1337 *dbm = ar->tx_pwr;
1338 return 0;
1339}
1340
1341static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1342 struct net_device *dev,
1343 bool pmgmt, int timeout)
1344{
1345 struct ath6kl *ar = ath6kl_priv(dev);
1346 struct wmi_power_mode_cmd mode;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301347 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001348
1349 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1350 __func__, pmgmt, timeout);
1351
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301352 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001353 return -EIO;
1354
1355 if (pmgmt) {
1356 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1357 mode.pwr_mode = REC_POWER;
1358 } else {
1359 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1360 mode.pwr_mode = MAX_PERF_POWER;
1361 }
1362
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301363 if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx,
1364 mode.pwr_mode) != 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001365 ath6kl_err("wmi_powermode_cmd failed\n");
1366 return -EIO;
1367 }
1368
1369 return 0;
1370}
1371
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301372static struct net_device *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
1373 char *name,
1374 enum nl80211_iftype type,
1375 u32 *flags,
1376 struct vif_params *params)
1377{
1378 struct ath6kl *ar = wiphy_priv(wiphy);
1379 struct net_device *ndev;
1380 u8 if_idx, nw_type;
1381
Kalle Valo71f96ee2011-11-14 19:31:30 +02001382 if (ar->num_vif == ar->vif_max) {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301383 ath6kl_err("Reached maximum number of supported vif\n");
1384 return ERR_PTR(-EINVAL);
1385 }
1386
1387 if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) {
1388 ath6kl_err("Not a supported interface type\n");
1389 return ERR_PTR(-EINVAL);
1390 }
1391
1392 ndev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
1393 if (!ndev)
1394 return ERR_PTR(-ENOMEM);
1395
1396 ar->num_vif++;
1397
1398 return ndev;
1399}
1400
1401static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy,
1402 struct net_device *ndev)
1403{
1404 struct ath6kl *ar = wiphy_priv(wiphy);
1405 struct ath6kl_vif *vif = netdev_priv(ndev);
1406
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301407 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301408 list_del(&vif->list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301409 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301410
1411 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1412
Kalle Valoc25889e2012-01-17 20:08:27 +02001413 ath6kl_cfg80211_vif_cleanup(vif);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301414
1415 return 0;
1416}
1417
Kalle Valobdcd8172011-07-18 00:22:30 +03001418static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1419 struct net_device *ndev,
1420 enum nl80211_iftype type, u32 *flags,
1421 struct vif_params *params)
1422{
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301423 struct ath6kl_vif *vif = netdev_priv(ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001424
1425 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1426
Kalle Valobdcd8172011-07-18 00:22:30 +03001427 switch (type) {
1428 case NL80211_IFTYPE_STATION:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301429 vif->next_mode = INFRA_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001430 break;
1431 case NL80211_IFTYPE_ADHOC:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301432 vif->next_mode = ADHOC_NETWORK;
Kalle Valobdcd8172011-07-18 00:22:30 +03001433 break;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001434 case NL80211_IFTYPE_AP:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301435 vif->next_mode = AP_NETWORK;
Jouni Malinen6e4604c2011-09-05 17:38:46 +03001436 break;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001437 case NL80211_IFTYPE_P2P_CLIENT:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301438 vif->next_mode = INFRA_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001439 break;
1440 case NL80211_IFTYPE_P2P_GO:
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301441 vif->next_mode = AP_NETWORK;
Jouni Malinen6b5e5d22011-08-30 21:58:05 +03001442 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03001443 default:
1444 ath6kl_err("invalid interface type %u\n", type);
1445 return -EOPNOTSUPP;
1446 }
1447
Vasanthakumar Thiagarajan551959d2011-10-25 19:34:26 +05301448 vif->wdev.iftype = type;
Kalle Valobdcd8172011-07-18 00:22:30 +03001449
1450 return 0;
1451}
1452
1453static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1454 struct net_device *dev,
1455 struct cfg80211_ibss_params *ibss_param)
1456{
1457 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301458 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001459 int status;
1460
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301461 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001462 return -EIO;
1463
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301464 vif->ssid_len = ibss_param->ssid_len;
1465 memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001466
1467 if (ibss_param->channel)
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301468 vif->ch_hint = ibss_param->channel->center_freq;
Kalle Valobdcd8172011-07-18 00:22:30 +03001469
1470 if (ibss_param->channel_fixed) {
1471 /*
1472 * TODO: channel_fixed: The channel should be fixed, do not
1473 * search for IBSSs to join on other channels. Target
1474 * firmware does not support this feature, needs to be
1475 * updated.
1476 */
1477 return -EOPNOTSUPP;
1478 }
1479
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301480 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001481 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301482 memcpy(vif->req_bssid, ibss_param->bssid,
1483 sizeof(vif->req_bssid));
Kalle Valobdcd8172011-07-18 00:22:30 +03001484
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301485 ath6kl_set_wpa_version(vif, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001486
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301487 status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
Kalle Valobdcd8172011-07-18 00:22:30 +03001488 if (status)
1489 return status;
1490
1491 if (ibss_param->privacy) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301492 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
1493 ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001494 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301495 ath6kl_set_cipher(vif, 0, true);
1496 ath6kl_set_cipher(vif, 0, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001497 }
1498
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301499 vif->nw_type = vif->next_mode;
Kalle Valobdcd8172011-07-18 00:22:30 +03001500
1501 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1502 "%s: connect called with authmode %d dot11 auth %d"
1503 " PW crypto %d PW crypto len %d GRP crypto %d"
1504 " GRP crypto len %d channel hint %u\n",
1505 __func__,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301506 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
1507 vif->prwise_crypto_len, vif->grp_crypto,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301508 vif->grp_crypto_len, vif->ch_hint);
Kalle Valobdcd8172011-07-18 00:22:30 +03001509
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301510 status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301511 vif->dot11_auth_mode, vif->auth_mode,
1512 vif->prwise_crypto,
1513 vif->prwise_crypto_len,
1514 vif->grp_crypto, vif->grp_crypto_len,
1515 vif->ssid_len, vif->ssid,
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301516 vif->req_bssid, vif->ch_hint,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001517 ar->connect_ctrl_flags, SUBTYPE_NONE);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301518 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001519
1520 return 0;
1521}
1522
1523static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1524 struct net_device *dev)
1525{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301526 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001527
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301528 if (!ath6kl_cfg80211_ready(vif))
Kalle Valobdcd8172011-07-18 00:22:30 +03001529 return -EIO;
1530
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301531 ath6kl_disconnect(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05301532 memset(vif->ssid, 0, sizeof(vif->ssid));
1533 vif->ssid_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001534
1535 return 0;
1536}
1537
1538static const u32 cipher_suites[] = {
1539 WLAN_CIPHER_SUITE_WEP40,
1540 WLAN_CIPHER_SUITE_WEP104,
1541 WLAN_CIPHER_SUITE_TKIP,
1542 WLAN_CIPHER_SUITE_CCMP,
Jouni Malinen837cb972011-10-11 17:31:57 +03001543 CCKM_KRK_CIPHER_SUITE,
Dai Shuibing5e070212011-11-03 11:39:37 +02001544 WLAN_CIPHER_SUITE_SMS4,
Kalle Valobdcd8172011-07-18 00:22:30 +03001545};
1546
1547static bool is_rate_legacy(s32 rate)
1548{
1549 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1550 6000, 9000, 12000, 18000, 24000,
1551 36000, 48000, 54000
1552 };
1553 u8 i;
1554
1555 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1556 if (rate == legacy[i])
1557 return true;
1558
1559 return false;
1560}
1561
1562static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1563{
1564 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1565 52000, 58500, 65000, 72200
1566 };
1567 u8 i;
1568
1569 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1570 if (rate == ht20[i]) {
1571 if (i == ARRAY_SIZE(ht20) - 1)
1572 /* last rate uses sgi */
1573 *sgi = true;
1574 else
1575 *sgi = false;
1576
1577 *mcs = i;
1578 return true;
1579 }
1580 }
1581 return false;
1582}
1583
1584static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1585{
1586 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1587 81000, 108000, 121500, 135000,
1588 150000
1589 };
1590 u8 i;
1591
1592 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1593 if (rate == ht40[i]) {
1594 if (i == ARRAY_SIZE(ht40) - 1)
1595 /* last rate uses sgi */
1596 *sgi = true;
1597 else
1598 *sgi = false;
1599
1600 *mcs = i;
1601 return true;
1602 }
1603 }
1604
1605 return false;
1606}
1607
1608static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1609 u8 *mac, struct station_info *sinfo)
1610{
1611 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301612 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001613 long left;
1614 bool sgi;
1615 s32 rate;
1616 int ret;
1617 u8 mcs;
1618
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301619 if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
Kalle Valobdcd8172011-07-18 00:22:30 +03001620 return -ENOENT;
1621
1622 if (down_interruptible(&ar->sem))
1623 return -EBUSY;
1624
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301625 set_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001626
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301627 ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001628
1629 if (ret != 0) {
1630 up(&ar->sem);
1631 return -EIO;
1632 }
1633
1634 left = wait_event_interruptible_timeout(ar->event_wq,
1635 !test_bit(STATS_UPDATE_PEND,
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301636 &vif->flags),
Kalle Valobdcd8172011-07-18 00:22:30 +03001637 WMI_TIMEOUT);
1638
1639 up(&ar->sem);
1640
1641 if (left == 0)
1642 return -ETIMEDOUT;
1643 else if (left < 0)
1644 return left;
1645
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301646 if (vif->target_stats.rx_byte) {
1647 sinfo->rx_bytes = vif->target_stats.rx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001648 sinfo->filled |= STATION_INFO_RX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301649 sinfo->rx_packets = vif->target_stats.rx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001650 sinfo->filled |= STATION_INFO_RX_PACKETS;
1651 }
1652
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301653 if (vif->target_stats.tx_byte) {
1654 sinfo->tx_bytes = vif->target_stats.tx_byte;
Kalle Valobdcd8172011-07-18 00:22:30 +03001655 sinfo->filled |= STATION_INFO_TX_BYTES;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301656 sinfo->tx_packets = vif->target_stats.tx_pkt;
Kalle Valobdcd8172011-07-18 00:22:30 +03001657 sinfo->filled |= STATION_INFO_TX_PACKETS;
1658 }
1659
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301660 sinfo->signal = vif->target_stats.cs_rssi;
Kalle Valobdcd8172011-07-18 00:22:30 +03001661 sinfo->filled |= STATION_INFO_SIGNAL;
1662
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301663 rate = vif->target_stats.tx_ucast_rate;
Kalle Valobdcd8172011-07-18 00:22:30 +03001664
1665 if (is_rate_legacy(rate)) {
1666 sinfo->txrate.legacy = rate / 100;
1667 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1668 if (sgi) {
1669 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1670 sinfo->txrate.mcs = mcs - 1;
1671 } else {
1672 sinfo->txrate.mcs = mcs;
1673 }
1674
1675 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1676 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1677 if (sgi) {
1678 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1679 sinfo->txrate.mcs = mcs - 1;
1680 } else {
1681 sinfo->txrate.mcs = mcs;
1682 }
1683
1684 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1685 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1686 } else {
Kalle Valo9a730832011-09-27 23:33:28 +03001687 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1688 "invalid rate from stats: %d\n", rate);
1689 ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
Kalle Valobdcd8172011-07-18 00:22:30 +03001690 return 0;
1691 }
1692
1693 sinfo->filled |= STATION_INFO_TX_BITRATE;
1694
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301695 if (test_bit(CONNECTED, &vif->flags) &&
1696 test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301697 vif->nw_type == INFRA_NETWORK) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001698 sinfo->filled |= STATION_INFO_BSS_PARAM;
1699 sinfo->bss_param.flags = 0;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301700 sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
1701 sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
Jouni Malinen32c10872011-09-19 19:15:07 +03001702 }
1703
Kalle Valobdcd8172011-07-18 00:22:30 +03001704 return 0;
1705}
1706
1707static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1708 struct cfg80211_pmksa *pmksa)
1709{
1710 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301711 struct ath6kl_vif *vif = netdev_priv(netdev);
1712
1713 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001714 pmksa->pmkid, true);
1715}
1716
1717static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1718 struct cfg80211_pmksa *pmksa)
1719{
1720 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301721 struct ath6kl_vif *vif = netdev_priv(netdev);
1722
1723 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001724 pmksa->pmkid, false);
1725}
1726
1727static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1728{
1729 struct ath6kl *ar = ath6kl_priv(netdev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301730 struct ath6kl_vif *vif = netdev_priv(netdev);
1731
1732 if (test_bit(CONNECTED, &vif->flags))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301733 return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
1734 vif->bssid, NULL, false);
Kalle Valobdcd8172011-07-18 00:22:30 +03001735 return 0;
1736}
1737
Raja Manid91e8ee2012-01-30 17:13:10 +05301738static int ath6kl_wow_usr(struct ath6kl *ar, struct ath6kl_vif *vif,
1739 struct cfg80211_wowlan *wow, u32 *filter)
Raja Mani6cb3c712011-11-07 22:52:45 +02001740{
Raja Manid91e8ee2012-01-30 17:13:10 +05301741 int ret, pos;
1742 u8 mask[WOW_MASK_SIZE];
Raja Mani6cb3c712011-11-07 22:52:45 +02001743 u16 i;
Raja Mani6cb3c712011-11-07 22:52:45 +02001744
Raja Manid91e8ee2012-01-30 17:13:10 +05301745 /* Configure the patterns that we received from the user. */
Raja Mani6cb3c712011-11-07 22:52:45 +02001746 for (i = 0; i < wow->n_patterns; i++) {
1747
1748 /*
1749 * Convert given nl80211 specific mask value to equivalent
1750 * driver specific mask value and send it to the chip along
1751 * with patterns. For example, If the mask value defined in
1752 * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
1753 * then equivalent driver specific mask value is
1754 * "0xFF 0x00 0xFF 0x00".
1755 */
1756 memset(&mask, 0, sizeof(mask));
1757 for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
1758 if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
1759 mask[pos] = 0xFF;
1760 }
1761 /*
1762 * Note: Pattern's offset is not passed as part of wowlan
1763 * parameter from CFG layer. So it's always passed as ZERO
1764 * to the firmware. It means, given WOW patterns are always
1765 * matched from the first byte of received pkt in the firmware.
1766 */
1767 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
Raja Manid91e8ee2012-01-30 17:13:10 +05301768 vif->fw_vif_idx, WOW_LIST_ID,
1769 wow->patterns[i].pattern_len,
1770 0 /* pattern offset */,
1771 wow->patterns[i].pattern, mask);
Raja Mani6cb3c712011-11-07 22:52:45 +02001772 if (ret)
1773 return ret;
1774 }
1775
Raja Manid91e8ee2012-01-30 17:13:10 +05301776 if (wow->disconnect)
1777 *filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
1778
1779 if (wow->magic_pkt)
1780 *filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
1781
1782 if (wow->gtk_rekey_failure)
1783 *filter |= WOW_FILTER_OPTION_GTK_ERROR;
1784
1785 if (wow->eap_identity_req)
1786 *filter |= WOW_FILTER_OPTION_EAP_REQ;
1787
1788 if (wow->four_way_handshake)
1789 *filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
1790
1791 return 0;
1792}
1793
1794static int ath6kl_wow_ap(struct ath6kl *ar, struct ath6kl_vif *vif)
1795{
1796 static const u8 unicst_pattern[] = { 0x00, 0x00, 0x00,
1797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1798 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1799 0x00, 0x08 };
1800 static const u8 unicst_mask[] = { 0x01, 0x00, 0x00,
1801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1802 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1803 0x00, 0x7f };
1804 u8 unicst_offset = 0;
1805 static const u8 arp_pattern[] = { 0x08, 0x06 };
1806 static const u8 arp_mask[] = { 0xff, 0xff };
1807 u8 arp_offset = 20;
1808 static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
1809 static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
1810 u8 discvr_offset = 38;
1811 static const u8 dhcp_pattern[] = { 0xff, 0xff, 0xff, 0xff,
1812 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1813 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1816 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 /* port 67 */ };
1817 static const u8 dhcp_mask[] = { 0xff, 0xff, 0xff, 0xff,
1818 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1819 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
1820 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1822 0x00, 0x00, 0x00, 0x00, 0xff, 0xff /* port 67 */ };
1823 u8 dhcp_offset = 0;
1824 int ret;
1825
1826 /* Setup unicast IP, EAPOL-like and ARP pkt pattern */
1827 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1828 vif->fw_vif_idx, WOW_LIST_ID,
1829 sizeof(unicst_pattern), unicst_offset,
1830 unicst_pattern, unicst_mask);
1831 if (ret) {
1832 ath6kl_err("failed to add WOW unicast IP pattern\n");
1833 return ret;
1834 }
1835
1836 /* Setup all ARP pkt pattern */
1837 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1838 vif->fw_vif_idx, WOW_LIST_ID,
1839 sizeof(arp_pattern), arp_offset,
1840 arp_pattern, arp_mask);
1841 if (ret) {
1842 ath6kl_err("failed to add WOW ARP pattern\n");
1843 return ret;
1844 }
1845
1846 /*
1847 * Setup multicast pattern for mDNS 224.0.0.251,
1848 * SSDP 239.255.255.250 and LLMNR 224.0.0.252
1849 */
1850 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1851 vif->fw_vif_idx, WOW_LIST_ID,
1852 sizeof(discvr_pattern), discvr_offset,
1853 discvr_pattern, discvr_mask);
1854 if (ret) {
1855 ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
1856 return ret;
1857 }
1858
1859 /* Setup all DHCP broadcast pkt pattern */
1860 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1861 vif->fw_vif_idx, WOW_LIST_ID,
1862 sizeof(dhcp_pattern), dhcp_offset,
1863 dhcp_pattern, dhcp_mask);
1864 if (ret) {
1865 ath6kl_err("failed to add WOW DHCP broadcast pattern\n");
1866 return ret;
1867 }
1868
1869 return 0;
1870}
1871
1872static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif)
1873{
1874 struct net_device *ndev = vif->ndev;
1875 static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
1876 static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
1877 u8 discvr_offset = 38;
1878 u8 mac_mask[ETH_ALEN];
1879 int ret;
1880
1881 /* Setup unicast pkt pattern */
1882 memset(mac_mask, 0xff, ETH_ALEN);
1883 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1884 vif->fw_vif_idx, WOW_LIST_ID,
1885 ETH_ALEN, 0, ndev->dev_addr,
1886 mac_mask);
1887 if (ret) {
1888 ath6kl_err("failed to add WOW unicast pattern\n");
1889 return ret;
1890 }
1891
1892 /*
1893 * Setup multicast pattern for mDNS 224.0.0.251,
1894 * SSDP 239.255.255.250 and LLMNR 224.0.0.252
1895 */
1896 if ((ndev->flags & IFF_ALLMULTI) ||
1897 (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev) > 0)) {
1898 ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
1899 vif->fw_vif_idx, WOW_LIST_ID,
1900 sizeof(discvr_pattern), discvr_offset,
1901 discvr_pattern, discvr_mask);
1902 if (ret) {
1903 ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR "
1904 "pattern\n");
1905 return ret;
1906 }
1907 }
1908
1909 return 0;
1910}
1911
1912static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
1913{
1914 struct in_device *in_dev;
1915 struct in_ifaddr *ifa;
1916 struct ath6kl_vif *vif;
1917 int ret, left;
1918 u32 filter = 0;
1919 u16 i;
1920 u8 index = 0;
1921 __be32 ips[MAX_IP_ADDRS];
1922
1923 vif = ath6kl_vif_first(ar);
1924 if (!vif)
1925 return -EIO;
1926
1927 if (!ath6kl_cfg80211_ready(vif))
1928 return -EIO;
1929
1930 if (!test_bit(CONNECTED, &vif->flags))
Raja Mani3c411a42012-01-30 17:13:12 +05301931 return -ENOTCONN;
Raja Manid91e8ee2012-01-30 17:13:10 +05301932
1933 if (wow && (wow->n_patterns > WOW_MAX_FILTERS_PER_LIST))
1934 return -EINVAL;
1935
1936 /* Clear existing WOW patterns */
1937 for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
1938 ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
1939 WOW_LIST_ID, i);
1940
1941 /*
1942 * Skip the default WOW pattern configuration
1943 * if the driver receives any WOW patterns from
1944 * the user.
1945 */
1946 if (wow)
1947 ret = ath6kl_wow_usr(ar, vif, wow, &filter);
1948 else if (vif->nw_type == AP_NETWORK)
1949 ret = ath6kl_wow_ap(ar, vif);
1950 else
1951 ret = ath6kl_wow_sta(ar, vif);
1952
1953 if (ret)
1954 return ret;
1955
Raja Manic08631c2011-12-16 14:24:24 +05301956 /* Setup own IP addr for ARP agent. */
1957 in_dev = __in_dev_get_rtnl(vif->ndev);
1958 if (!in_dev)
1959 goto skip_arp;
1960
1961 ifa = in_dev->ifa_list;
1962 memset(&ips, 0, sizeof(ips));
1963
1964 /* Configure IP addr only if IP address count < MAX_IP_ADDRS */
1965 while (index < MAX_IP_ADDRS && ifa) {
1966 ips[index] = ifa->ifa_local;
1967 ifa = ifa->ifa_next;
1968 index++;
1969 }
1970
1971 if (ifa) {
1972 ath6kl_err("total IP addr count is exceeding fw limit\n");
1973 return -EINVAL;
1974 }
1975
1976 ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]);
1977 if (ret) {
1978 ath6kl_err("fail to setup ip for arp agent\n");
1979 return ret;
1980 }
1981
1982skip_arp:
Raja Mani6cb3c712011-11-07 22:52:45 +02001983 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
1984 ATH6KL_WOW_MODE_ENABLE,
1985 filter,
1986 WOW_HOST_REQ_DELAY);
1987 if (ret)
1988 return ret;
1989
Raja Mani081c7a82012-01-30 17:13:11 +05301990 clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
1991
Raja Mani6cb3c712011-11-07 22:52:45 +02001992 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
1993 ATH6KL_HOST_MODE_ASLEEP);
1994 if (ret)
1995 return ret;
1996
Raja Mani081c7a82012-01-30 17:13:11 +05301997 left = wait_event_interruptible_timeout(ar->event_wq,
1998 test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags),
1999 WMI_TIMEOUT);
2000 if (left == 0) {
2001 ath6kl_warn("timeout, didn't get host sleep cmd "
2002 "processed event\n");
2003 ret = -ETIMEDOUT;
2004 } else if (left < 0) {
2005 ath6kl_warn("error while waiting for host sleep cmd "
2006 "processed event %d\n", left);
2007 ret = left;
2008 }
2009
Raja Mani6cb3c712011-11-07 22:52:45 +02002010 if (ar->tx_pending[ar->ctrl_ep]) {
2011 left = wait_event_interruptible_timeout(ar->event_wq,
2012 ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT);
2013 if (left == 0) {
2014 ath6kl_warn("clear wmi ctrl data timeout\n");
2015 ret = -ETIMEDOUT;
2016 } else if (left < 0) {
2017 ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
2018 ret = left;
2019 }
2020 }
2021
2022 return ret;
2023}
2024
2025static int ath6kl_wow_resume(struct ath6kl *ar)
2026{
2027 struct ath6kl_vif *vif;
2028 int ret;
2029
2030 vif = ath6kl_vif_first(ar);
2031 if (!vif)
2032 return -EIO;
2033
2034 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
2035 ATH6KL_HOST_MODE_AWAKE);
2036 return ret;
2037}
2038
Kalle Valo52d81a62011-11-01 08:44:21 +02002039int ath6kl_cfg80211_suspend(struct ath6kl *ar,
Raja Mani0f60e9f2011-11-07 22:52:45 +02002040 enum ath6kl_cfg_suspend_mode mode,
2041 struct cfg80211_wowlan *wow)
Kalle Valo52d81a62011-11-01 08:44:21 +02002042{
2043 int ret;
2044
Kalle Valo52d81a62011-11-01 08:44:21 +02002045 switch (mode) {
Raja Manid7c44e02011-11-07 22:52:46 +02002046 case ATH6KL_CFG_SUSPEND_WOW:
2047
2048 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
2049
2050 /* Flush all non control pkts in TX path */
2051 ath6kl_tx_data_cleanup(ar);
2052
2053 ret = ath6kl_wow_suspend(ar, wow);
2054 if (ret) {
2055 ath6kl_err("wow suspend failed: %d\n", ret);
2056 return ret;
2057 }
2058 ar->state = ATH6KL_STATE_WOW;
2059 break;
2060
Kalle Valo52d81a62011-11-01 08:44:21 +02002061 case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
Raja Mani524441e2011-11-07 22:52:46 +02002062
Kalle Valo7125f012011-12-13 14:51:37 +02002063 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02002064
Kalle Valo52d81a62011-11-01 08:44:21 +02002065 /* save the current power mode before enabling power save */
2066 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
2067
2068 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
2069 if (ret) {
2070 ath6kl_warn("wmi powermode command failed during suspend: %d\n",
2071 ret);
2072 }
2073
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002074 ar->state = ATH6KL_STATE_DEEPSLEEP;
2075
Kalle Valo52d81a62011-11-01 08:44:21 +02002076 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002077
2078 case ATH6KL_CFG_SUSPEND_CUTPOWER:
Raja Mani524441e2011-11-07 22:52:46 +02002079
Kalle Valo7125f012011-12-13 14:51:37 +02002080 ath6kl_cfg80211_stop_all(ar);
Raja Mani524441e2011-11-07 22:52:46 +02002081
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002082 if (ar->state == ATH6KL_STATE_OFF) {
2083 ath6kl_dbg(ATH6KL_DBG_SUSPEND,
2084 "suspend hw off, no action for cutpower\n");
2085 break;
2086 }
2087
2088 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
2089
2090 ret = ath6kl_init_hw_stop(ar);
2091 if (ret) {
2092 ath6kl_warn("failed to stop hw during suspend: %d\n",
2093 ret);
2094 }
2095
2096 ar->state = ATH6KL_STATE_CUTPOWER;
2097
2098 break;
2099
Kalle Valo10509f92011-12-13 14:52:07 +02002100 case ATH6KL_CFG_SUSPEND_SCHED_SCAN:
2101 /*
2102 * Nothing needed for schedule scan, firmware is already in
2103 * wow mode and sleeping most of the time.
2104 */
2105 break;
2106
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002107 default:
2108 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02002109 }
2110
2111 return 0;
2112}
Kalle Valod6a434d2012-01-17 20:09:36 +02002113EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
Kalle Valo52d81a62011-11-01 08:44:21 +02002114
2115int ath6kl_cfg80211_resume(struct ath6kl *ar)
2116{
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002117 int ret;
2118
2119 switch (ar->state) {
Raja Manid7c44e02011-11-07 22:52:46 +02002120 case ATH6KL_STATE_WOW:
2121 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
2122
2123 ret = ath6kl_wow_resume(ar);
2124 if (ret) {
2125 ath6kl_warn("wow mode resume failed: %d\n", ret);
2126 return ret;
2127 }
2128
2129 ar->state = ATH6KL_STATE_ON;
2130 break;
2131
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002132 case ATH6KL_STATE_DEEPSLEEP:
2133 if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
2134 ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
2135 ar->wmi->saved_pwr_mode);
2136 if (ret) {
2137 ath6kl_warn("wmi powermode command failed during resume: %d\n",
2138 ret);
2139 }
2140 }
2141
2142 ar->state = ATH6KL_STATE_ON;
2143
2144 break;
2145
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002146 case ATH6KL_STATE_CUTPOWER:
2147 ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
2148
2149 ret = ath6kl_init_hw_start(ar);
2150 if (ret) {
2151 ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
2152 return ret;
2153 }
Raja Manid7c44e02011-11-07 22:52:46 +02002154 break;
Kalle Valob4b2a0b2011-11-01 08:44:44 +02002155
Kalle Valo10509f92011-12-13 14:52:07 +02002156 case ATH6KL_STATE_SCHED_SCAN:
2157 break;
2158
Kalle Valo76a9fbe2011-11-01 08:44:28 +02002159 default:
2160 break;
Kalle Valo52d81a62011-11-01 08:44:21 +02002161 }
2162
2163 return 0;
2164}
Kalle Valod6a434d2012-01-17 20:09:36 +02002165EXPORT_SYMBOL(ath6kl_cfg80211_resume);
Kalle Valo52d81a62011-11-01 08:44:21 +02002166
Kalle Valoabcb3442011-07-22 08:26:20 +03002167#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02002168
2169/* hif layer decides what suspend mode to use */
2170static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
Kalle Valoabcb3442011-07-22 08:26:20 +03002171 struct cfg80211_wowlan *wow)
2172{
2173 struct ath6kl *ar = wiphy_priv(wiphy);
2174
Raja Mani0f60e9f2011-11-07 22:52:45 +02002175 return ath6kl_hif_suspend(ar, wow);
Kalle Valoabcb3442011-07-22 08:26:20 +03002176}
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002177
Kalle Valo52d81a62011-11-01 08:44:21 +02002178static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
Chilam Ngaa6cffc2011-10-05 10:12:52 +03002179{
2180 struct ath6kl *ar = wiphy_priv(wiphy);
2181
2182 return ath6kl_hif_resume(ar);
2183}
Raja Mania918fb32011-11-07 22:52:46 +02002184
2185/*
2186 * FIXME: WOW suspend mode is selected if the host sdio controller supports
2187 * both sdio irq wake up and keep power. The target pulls sdio data line to
2188 * wake up the host when WOW pattern matches. This causes sdio irq handler
2189 * is being called in the host side which internally hits ath6kl's RX path.
2190 *
2191 * Since sdio interrupt is not disabled, RX path executes even before
2192 * the host executes the actual resume operation from PM module.
2193 *
2194 * In the current scenario, WOW resume should happen before start processing
2195 * any data from the target. So It's required to perform WOW resume in RX path.
2196 * Ideally we should perform WOW resume only in the actual platform
2197 * resume path. This area needs bit rework to avoid WOW resume in RX path.
2198 *
2199 * ath6kl_check_wow_status() is called from ath6kl_rx().
2200 */
2201void ath6kl_check_wow_status(struct ath6kl *ar)
2202{
2203 if (ar->state == ATH6KL_STATE_WOW)
2204 ath6kl_cfg80211_resume(ar);
2205}
2206
2207#else
2208
2209void ath6kl_check_wow_status(struct ath6kl *ar)
2210{
2211}
Kalle Valoabcb3442011-07-22 08:26:20 +03002212#endif
2213
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002214static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
2215 struct ieee80211_channel *chan,
2216 enum nl80211_channel_type channel_type)
2217{
Sujith Manoharane68f6752011-12-22 12:15:27 +05302218 struct ath6kl_vif *vif;
2219
2220 /*
2221 * 'dev' could be NULL if a channel change is required for the hardware
2222 * device itself, instead of a particular VIF.
2223 *
2224 * FIXME: To be handled properly when monitor mode is supported.
2225 */
2226 if (!dev)
2227 return -EBUSY;
2228
2229 vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002230
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302231 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002232 return -EIO;
2233
2234 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
2235 __func__, chan->center_freq, chan->hw_value);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302236 vif->next_chan = chan->center_freq;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002237
2238 return 0;
2239}
2240
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002241static bool ath6kl_is_p2p_ie(const u8 *pos)
2242{
2243 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
2244 pos[2] == 0x50 && pos[3] == 0x6f &&
2245 pos[4] == 0x9a && pos[5] == 0x09;
2246}
2247
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302248static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
2249 const u8 *ies, size_t ies_len)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002250{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302251 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002252 const u8 *pos;
2253 u8 *buf = NULL;
2254 size_t len = 0;
2255 int ret;
2256
2257 /*
2258 * Filter out P2P IE(s) since they will be included depending on
2259 * the Probe Request frame in ath6kl_send_go_probe_resp().
2260 */
2261
2262 if (ies && ies_len) {
2263 buf = kmalloc(ies_len, GFP_KERNEL);
2264 if (buf == NULL)
2265 return -ENOMEM;
2266 pos = ies;
2267 while (pos + 1 < ies + ies_len) {
2268 if (pos + 2 + pos[1] > ies + ies_len)
2269 break;
2270 if (!ath6kl_is_p2p_ie(pos)) {
2271 memcpy(buf + len, pos, 2 + pos[1]);
2272 len += 2 + pos[1];
2273 }
2274 pos += 2 + pos[1];
2275 }
2276 }
2277
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302278 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2279 WMI_FRAME_PROBE_RESP, buf, len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002280 kfree(buf);
2281 return ret;
2282}
2283
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002284static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
2285 struct beacon_parameters *info, bool add)
2286{
2287 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302288 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002289 struct ieee80211_mgmt *mgmt;
2290 u8 *ies;
2291 int ies_len;
2292 struct wmi_connect_cmd p;
2293 int res;
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302294 int i, ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002295
2296 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
2297
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302298 if (!ath6kl_cfg80211_ready(vif))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002299 return -EIO;
2300
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302301 if (vif->next_mode != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002302 return -EOPNOTSUPP;
2303
2304 if (info->beacon_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302305 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2306 WMI_FRAME_BEACON,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002307 info->beacon_ies,
2308 info->beacon_ies_len);
2309 if (res)
2310 return res;
2311 }
2312 if (info->proberesp_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302313 res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002314 info->proberesp_ies_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002315 if (res)
2316 return res;
2317 }
2318 if (info->assocresp_ies) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302319 res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2320 WMI_FRAME_ASSOC_RESP,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002321 info->assocresp_ies,
2322 info->assocresp_ies_len);
2323 if (res)
2324 return res;
2325 }
2326
2327 if (!add)
2328 return 0;
2329
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002330 ar->ap_mode_bkey.valid = false;
2331
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002332 /* TODO:
2333 * info->interval
2334 * info->dtim_period
2335 */
2336
2337 if (info->head == NULL)
2338 return -EINVAL;
2339 mgmt = (struct ieee80211_mgmt *) info->head;
2340 ies = mgmt->u.beacon.variable;
2341 if (ies > info->head + info->head_len)
2342 return -EINVAL;
2343 ies_len = info->head + info->head_len - ies;
2344
2345 if (info->ssid == NULL)
2346 return -EINVAL;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302347 memcpy(vif->ssid, info->ssid, info->ssid_len);
2348 vif->ssid_len = info->ssid_len;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002349 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
2350 return -EOPNOTSUPP; /* TODO */
2351
Vasanthakumar Thiagarajanbe5abaa2011-11-11 20:33:01 +05302352 ret = ath6kl_set_auth_type(vif, info->auth_type);
2353 if (ret)
2354 return ret;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002355
2356 memset(&p, 0, sizeof(p));
2357
2358 for (i = 0; i < info->crypto.n_akm_suites; i++) {
2359 switch (info->crypto.akm_suites[i]) {
2360 case WLAN_AKM_SUITE_8021X:
2361 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2362 p.auth_mode |= WPA_AUTH;
2363 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2364 p.auth_mode |= WPA2_AUTH;
2365 break;
2366 case WLAN_AKM_SUITE_PSK:
2367 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
2368 p.auth_mode |= WPA_PSK_AUTH;
2369 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
2370 p.auth_mode |= WPA2_PSK_AUTH;
2371 break;
2372 }
2373 }
2374 if (p.auth_mode == 0)
2375 p.auth_mode = NONE_AUTH;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302376 vif->auth_mode = p.auth_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002377
2378 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
2379 switch (info->crypto.ciphers_pairwise[i]) {
2380 case WLAN_CIPHER_SUITE_WEP40:
2381 case WLAN_CIPHER_SUITE_WEP104:
2382 p.prwise_crypto_type |= WEP_CRYPT;
2383 break;
2384 case WLAN_CIPHER_SUITE_TKIP:
2385 p.prwise_crypto_type |= TKIP_CRYPT;
2386 break;
2387 case WLAN_CIPHER_SUITE_CCMP:
2388 p.prwise_crypto_type |= AES_CRYPT;
2389 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002390 case WLAN_CIPHER_SUITE_SMS4:
2391 p.prwise_crypto_type |= WAPI_CRYPT;
2392 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002393 }
2394 }
Edward Lu229ed6b2011-08-30 21:58:07 +03002395 if (p.prwise_crypto_type == 0) {
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002396 p.prwise_crypto_type = NONE_CRYPT;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302397 ath6kl_set_cipher(vif, 0, true);
Edward Lu229ed6b2011-08-30 21:58:07 +03002398 } else if (info->crypto.n_ciphers_pairwise == 1)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302399 ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002400
2401 switch (info->crypto.cipher_group) {
2402 case WLAN_CIPHER_SUITE_WEP40:
2403 case WLAN_CIPHER_SUITE_WEP104:
2404 p.grp_crypto_type = WEP_CRYPT;
2405 break;
2406 case WLAN_CIPHER_SUITE_TKIP:
2407 p.grp_crypto_type = TKIP_CRYPT;
2408 break;
2409 case WLAN_CIPHER_SUITE_CCMP:
2410 p.grp_crypto_type = AES_CRYPT;
2411 break;
Dai Shuibingb8214df2011-11-03 11:39:38 +02002412 case WLAN_CIPHER_SUITE_SMS4:
2413 p.grp_crypto_type = WAPI_CRYPT;
2414 break;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002415 default:
2416 p.grp_crypto_type = NONE_CRYPT;
2417 break;
2418 }
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302419 ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002420
2421 p.nw_type = AP_NETWORK;
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302422 vif->nw_type = vif->next_mode;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002423
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +05302424 p.ssid_len = vif->ssid_len;
2425 memcpy(p.ssid, vif->ssid, vif->ssid_len);
2426 p.dot11_auth_mode = vif->dot11_auth_mode;
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302427 p.ch = cpu_to_le16(vif->next_chan);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002428
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05302429 /* Enable uAPSD support by default */
2430 res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
2431 if (res < 0)
2432 return res;
2433
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002434 if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
2435 p.nw_subtype = SUBTYPE_P2PGO;
2436 } else {
2437 /*
2438 * Due to firmware limitation, it is not possible to
2439 * do P2P mgmt operations in AP mode
2440 */
2441 p.nw_subtype = SUBTYPE_NONE;
2442 }
2443
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302444 res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002445 if (res < 0)
2446 return res;
2447
2448 return 0;
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002449}
2450
2451static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
2452 struct beacon_parameters *info)
2453{
2454 return ath6kl_ap_beacon(wiphy, dev, info, true);
2455}
2456
2457static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
2458 struct beacon_parameters *info)
2459{
2460 return ath6kl_ap_beacon(wiphy, dev, info, false);
2461}
2462
2463static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
2464{
2465 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302466 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002467
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302468 if (vif->nw_type != AP_NETWORK)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002469 return -EOPNOTSUPP;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302470 if (!test_bit(CONNECTED, &vif->flags))
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002471 return -ENOTCONN;
2472
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302473 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302474 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002475
2476 return 0;
2477}
2478
Jouni Malinen33e53082011-12-27 11:02:56 +02002479static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2480
2481static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
2482 u8 *mac)
2483{
2484 struct ath6kl *ar = ath6kl_priv(dev);
2485 struct ath6kl_vif *vif = netdev_priv(dev);
2486 const u8 *addr = mac ? mac : bcast_addr;
2487
2488 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
2489 addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
2490}
2491
Jouni Malinen23875132011-08-30 21:57:53 +03002492static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
2493 u8 *mac, struct station_parameters *params)
2494{
2495 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302496 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen23875132011-08-30 21:57:53 +03002497
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302498 if (vif->nw_type != AP_NETWORK)
Jouni Malinen23875132011-08-30 21:57:53 +03002499 return -EOPNOTSUPP;
2500
2501 /* Use this only for authorizing/unauthorizing a station */
2502 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
2503 return -EOPNOTSUPP;
2504
2505 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302506 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2507 WMI_AP_MLME_AUTHORIZE, mac, 0);
2508 return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
2509 WMI_AP_MLME_UNAUTHORIZE, mac, 0);
Jouni Malinen23875132011-08-30 21:57:53 +03002510}
2511
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002512static int ath6kl_remain_on_channel(struct wiphy *wiphy,
2513 struct net_device *dev,
2514 struct ieee80211_channel *chan,
2515 enum nl80211_channel_type channel_type,
2516 unsigned int duration,
2517 u64 *cookie)
2518{
2519 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302520 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen10522612011-10-27 16:00:13 +03002521 u32 id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002522
2523 /* TODO: if already pending or ongoing remain-on-channel,
2524 * return -EBUSY */
Jouni Malinen10522612011-10-27 16:00:13 +03002525 id = ++vif->last_roc_id;
2526 if (id == 0) {
2527 /* Do not use 0 as the cookie value */
2528 id = ++vif->last_roc_id;
2529 }
2530 *cookie = id;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002531
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302532 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
2533 chan->center_freq, duration);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002534}
2535
2536static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
2537 struct net_device *dev,
2538 u64 cookie)
2539{
2540 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302541 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002542
Jouni Malinen10522612011-10-27 16:00:13 +03002543 if (cookie != vif->last_roc_id)
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002544 return -ENOENT;
Jouni Malinen10522612011-10-27 16:00:13 +03002545 vif->last_cancel_roc_id = cookie;
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002546
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302547 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002548}
2549
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302550static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
2551 const u8 *buf, size_t len,
2552 unsigned int freq)
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002553{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302554 struct ath6kl *ar = vif->ar;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002555 const u8 *pos;
2556 u8 *p2p;
2557 int p2p_len;
2558 int ret;
2559 const struct ieee80211_mgmt *mgmt;
2560
2561 mgmt = (const struct ieee80211_mgmt *) buf;
2562
2563 /* Include P2P IE(s) from the frame generated in user space. */
2564
2565 p2p = kmalloc(len, GFP_KERNEL);
2566 if (p2p == NULL)
2567 return -ENOMEM;
2568 p2p_len = 0;
2569
2570 pos = mgmt->u.probe_resp.variable;
2571 while (pos + 1 < buf + len) {
2572 if (pos + 2 + pos[1] > buf + len)
2573 break;
2574 if (ath6kl_is_p2p_ie(pos)) {
2575 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
2576 p2p_len += 2 + pos[1];
2577 }
2578 pos += 2 + pos[1];
2579 }
2580
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302581 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
2582 mgmt->da, p2p, p2p_len);
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002583 kfree(p2p);
2584 return ret;
2585}
2586
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002587static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif,
2588 u32 id,
2589 u32 freq,
2590 u32 wait,
2591 const u8 *buf,
2592 size_t len,
2593 bool *more_data,
2594 bool no_cck)
2595{
2596 struct ieee80211_mgmt *mgmt;
2597 struct ath6kl_sta *conn;
2598 bool is_psq_empty = false;
2599 struct ath6kl_mgmt_buff *mgmt_buf;
2600 size_t mgmt_buf_size;
2601 struct ath6kl *ar = vif->ar;
2602
2603 mgmt = (struct ieee80211_mgmt *) buf;
2604 if (is_multicast_ether_addr(mgmt->da))
2605 return false;
2606
2607 conn = ath6kl_find_sta(vif, mgmt->da);
2608 if (!conn)
2609 return false;
2610
2611 if (conn->sta_flags & STA_PS_SLEEP) {
2612 if (!(conn->sta_flags & STA_PS_POLLED)) {
2613 /* Queue the frames if the STA is sleeping */
2614 mgmt_buf_size = len + sizeof(struct ath6kl_mgmt_buff);
2615 mgmt_buf = kmalloc(mgmt_buf_size, GFP_KERNEL);
2616 if (!mgmt_buf)
2617 return false;
2618
2619 INIT_LIST_HEAD(&mgmt_buf->list);
2620 mgmt_buf->id = id;
2621 mgmt_buf->freq = freq;
2622 mgmt_buf->wait = wait;
2623 mgmt_buf->len = len;
2624 mgmt_buf->no_cck = no_cck;
2625 memcpy(mgmt_buf->buf, buf, len);
2626 spin_lock_bh(&conn->psq_lock);
2627 is_psq_empty = skb_queue_empty(&conn->psq) &&
2628 (conn->mgmt_psq_len == 0);
2629 list_add_tail(&mgmt_buf->list, &conn->mgmt_psq);
2630 conn->mgmt_psq_len++;
2631 spin_unlock_bh(&conn->psq_lock);
2632
2633 /*
2634 * If this is the first pkt getting queued
2635 * for this STA, update the PVB for this
2636 * STA.
2637 */
2638 if (is_psq_empty)
2639 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
2640 conn->aid, 1);
2641 return true;
2642 }
2643
2644 /*
2645 * This tx is because of a PsPoll.
2646 * Determine if MoreData bit has to be set.
2647 */
2648 spin_lock_bh(&conn->psq_lock);
2649 if (!skb_queue_empty(&conn->psq) || (conn->mgmt_psq_len != 0))
2650 *more_data = true;
2651 spin_unlock_bh(&conn->psq_lock);
2652 }
2653
2654 return false;
2655}
2656
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002657static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2658 struct ieee80211_channel *chan, bool offchan,
2659 enum nl80211_channel_type channel_type,
2660 bool channel_type_valid, unsigned int wait,
Johannes Berge247bd902011-11-04 11:18:21 +01002661 const u8 *buf, size_t len, bool no_cck,
2662 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002663{
2664 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05302665 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002666 u32 id;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002667 const struct ieee80211_mgmt *mgmt;
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002668 bool more_data, queued;
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002669
2670 mgmt = (const struct ieee80211_mgmt *) buf;
2671 if (buf + len >= mgmt->u.probe_resp.variable &&
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05302672 vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002673 ieee80211_is_probe_resp(mgmt->frame_control)) {
2674 /*
2675 * Send Probe Response frame in AP mode using a separate WMI
2676 * command to allow the target to fill in the generic IEs.
2677 */
2678 *cookie = 0; /* TX status not supported */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302679 return ath6kl_send_go_probe_resp(vif, buf, len,
Jouni Malinen8bdfbf42011-08-30 21:58:09 +03002680 chan->center_freq);
2681 }
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002682
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302683 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002684 if (id == 0) {
2685 /*
2686 * 0 is a reserved value in the WMI command and shall not be
2687 * used for the command.
2688 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302689 id = vif->send_action_id++;
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002690 }
2691
2692 *cookie = id;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002693
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002694 /* AP mode Power saving processing */
2695 if (vif->nw_type == AP_NETWORK) {
2696 queued = ath6kl_mgmt_powersave_ap(vif,
2697 id, chan->center_freq,
2698 wait, buf,
2699 len, &more_data, no_cck);
2700 if (queued)
2701 return 0;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002702 }
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08002703
2704 return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id,
2705 chan->center_freq, wait,
2706 buf, len, no_cck);
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002707}
2708
Jouni Malinenae32c302011-08-30 21:58:01 +03002709static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
2710 struct net_device *dev,
2711 u16 frame_type, bool reg)
2712{
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302713 struct ath6kl_vif *vif = netdev_priv(dev);
Jouni Malinenae32c302011-08-30 21:58:01 +03002714
2715 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
2716 __func__, frame_type, reg);
2717 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
2718 /*
2719 * Note: This notification callback is not allowed to sleep, so
2720 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
2721 * hardcode target to report Probe Request frames all the time.
2722 */
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05302723 vif->probe_req_report = reg;
Jouni Malinenae32c302011-08-30 21:58:01 +03002724 }
2725}
2726
Kalle Valo10509f92011-12-13 14:52:07 +02002727static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
2728 struct net_device *dev,
2729 struct cfg80211_sched_scan_request *request)
2730{
2731 struct ath6kl *ar = ath6kl_priv(dev);
2732 struct ath6kl_vif *vif = netdev_priv(dev);
2733 u16 interval;
2734 int ret;
2735 u8 i;
2736
2737 if (ar->state != ATH6KL_STATE_ON)
2738 return -EIO;
2739
2740 if (vif->sme_state != SME_DISCONNECTED)
2741 return -EBUSY;
2742
2743 for (i = 0; i < ar->wiphy->max_sched_scan_ssids; i++) {
2744 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2745 i, DISABLE_SSID_FLAG,
2746 0, NULL);
2747 }
2748
2749 /* fw uses seconds, also make sure that it's >0 */
2750 interval = max_t(u16, 1, request->interval / 1000);
2751
2752 ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
2753 interval, interval,
2754 10, 0, 0, 0, 3, 0, 0, 0);
2755
2756 if (request->n_ssids && request->ssids[0].ssid_len) {
2757 for (i = 0; i < request->n_ssids; i++) {
2758 ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
2759 i, SPECIFIC_SSID_FLAG,
2760 request->ssids[i].ssid_len,
2761 request->ssids[i].ssid);
2762 }
2763 }
2764
2765 ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
2766 ATH6KL_WOW_MODE_ENABLE,
2767 WOW_FILTER_SSID,
2768 WOW_HOST_REQ_DELAY);
2769 if (ret) {
2770 ath6kl_warn("Failed to enable wow with ssid filter: %d\n", ret);
2771 return ret;
2772 }
2773
2774 /* this also clears IE in fw if it's not set */
2775 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
2776 WMI_FRAME_PROBE_REQ,
2777 request->ie, request->ie_len);
2778 if (ret) {
2779 ath6kl_warn("Failed to set probe request IE for scheduled scan: %d",
2780 ret);
2781 return ret;
2782 }
2783
2784 ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
2785 ATH6KL_HOST_MODE_ASLEEP);
2786 if (ret) {
2787 ath6kl_warn("Failed to enable host sleep mode for sched scan: %d\n",
2788 ret);
2789 return ret;
2790 }
2791
2792 ar->state = ATH6KL_STATE_SCHED_SCAN;
2793
2794 return ret;
2795}
2796
2797static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy,
2798 struct net_device *dev)
2799{
2800 struct ath6kl_vif *vif = netdev_priv(dev);
2801 bool stopped;
2802
2803 stopped = __ath6kl_cfg80211_sscan_stop(vif);
2804
2805 if (!stopped)
2806 return -EIO;
2807
2808 return 0;
2809}
2810
Jouni Malinenf80574a2011-08-30 21:58:04 +03002811static const struct ieee80211_txrx_stypes
2812ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
2813 [NL80211_IFTYPE_STATION] = {
2814 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2815 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2816 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2817 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2818 },
Jouni Malinenba1f6fe2011-12-27 11:03:53 +02002819 [NL80211_IFTYPE_AP] = {
2820 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2821 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2822 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2823 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2824 },
Jouni Malinenf80574a2011-08-30 21:58:04 +03002825 [NL80211_IFTYPE_P2P_CLIENT] = {
2826 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2827 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2828 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2829 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2830 },
2831 [NL80211_IFTYPE_P2P_GO] = {
2832 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2833 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
2834 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
2835 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
2836 },
2837};
2838
Kalle Valobdcd8172011-07-18 00:22:30 +03002839static struct cfg80211_ops ath6kl_cfg80211_ops = {
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302840 .add_virtual_intf = ath6kl_cfg80211_add_iface,
2841 .del_virtual_intf = ath6kl_cfg80211_del_iface,
Kalle Valobdcd8172011-07-18 00:22:30 +03002842 .change_virtual_intf = ath6kl_cfg80211_change_iface,
2843 .scan = ath6kl_cfg80211_scan,
2844 .connect = ath6kl_cfg80211_connect,
2845 .disconnect = ath6kl_cfg80211_disconnect,
2846 .add_key = ath6kl_cfg80211_add_key,
2847 .get_key = ath6kl_cfg80211_get_key,
2848 .del_key = ath6kl_cfg80211_del_key,
2849 .set_default_key = ath6kl_cfg80211_set_default_key,
2850 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
2851 .set_tx_power = ath6kl_cfg80211_set_txpower,
2852 .get_tx_power = ath6kl_cfg80211_get_txpower,
2853 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
2854 .join_ibss = ath6kl_cfg80211_join_ibss,
2855 .leave_ibss = ath6kl_cfg80211_leave_ibss,
2856 .get_station = ath6kl_get_station,
2857 .set_pmksa = ath6kl_set_pmksa,
2858 .del_pmksa = ath6kl_del_pmksa,
2859 .flush_pmksa = ath6kl_flush_pmksa,
Kalle Valo003353b0d2011-09-01 10:14:21 +03002860 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
Kalle Valoabcb3442011-07-22 08:26:20 +03002861#ifdef CONFIG_PM
Kalle Valo52d81a62011-11-01 08:44:21 +02002862 .suspend = __ath6kl_cfg80211_suspend,
2863 .resume = __ath6kl_cfg80211_resume,
Kalle Valoabcb3442011-07-22 08:26:20 +03002864#endif
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002865 .set_channel = ath6kl_set_channel,
2866 .add_beacon = ath6kl_add_beacon,
2867 .set_beacon = ath6kl_set_beacon,
2868 .del_beacon = ath6kl_del_beacon,
Jouni Malinen33e53082011-12-27 11:02:56 +02002869 .del_station = ath6kl_del_station,
Jouni Malinen23875132011-08-30 21:57:53 +03002870 .change_station = ath6kl_change_station,
Jouni Malinen63fa1e02011-08-30 21:57:55 +03002871 .remain_on_channel = ath6kl_remain_on_channel,
2872 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
Jouni Malinen8a6c80602011-08-30 21:57:56 +03002873 .mgmt_tx = ath6kl_mgmt_tx,
Jouni Malinenae32c302011-08-30 21:58:01 +03002874 .mgmt_frame_register = ath6kl_mgmt_frame_register,
Kalle Valo10509f92011-12-13 14:52:07 +02002875 .sched_scan_start = ath6kl_cfg80211_sscan_start,
2876 .sched_scan_stop = ath6kl_cfg80211_sscan_stop,
Kalle Valobdcd8172011-07-18 00:22:30 +03002877};
2878
Kalle Valo7125f012011-12-13 14:51:37 +02002879void ath6kl_cfg80211_stop(struct ath6kl_vif *vif)
Kalle Valoec4b7f62011-11-01 08:44:04 +02002880{
Kalle Valo10509f92011-12-13 14:52:07 +02002881 ath6kl_cfg80211_sscan_disable(vif);
2882
Kalle Valoec4b7f62011-11-01 08:44:04 +02002883 switch (vif->sme_state) {
Kalle Valoc97a31b2011-12-13 14:51:10 +02002884 case SME_DISCONNECTED:
2885 break;
Kalle Valoec4b7f62011-11-01 08:44:04 +02002886 case SME_CONNECTING:
2887 cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
2888 NULL, 0,
2889 WLAN_STATUS_UNSPECIFIED_FAILURE,
2890 GFP_KERNEL);
2891 break;
2892 case SME_CONNECTED:
Kalle Valoec4b7f62011-11-01 08:44:04 +02002893 cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
2894 break;
2895 }
2896
2897 if (test_bit(CONNECTED, &vif->flags) ||
2898 test_bit(CONNECT_PEND, &vif->flags))
Kalle Valo7125f012011-12-13 14:51:37 +02002899 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002900
2901 vif->sme_state = SME_DISCONNECTED;
Kalle Valo1f40525512011-11-01 08:44:13 +02002902 clear_bit(CONNECTED, &vif->flags);
2903 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valoec4b7f62011-11-01 08:44:04 +02002904
2905 /* disable scanning */
Kalle Valo7125f012011-12-13 14:51:37 +02002906 if (ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF,
2907 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0)
2908 ath6kl_warn("failed to disable scan during stop\n");
Kalle Valoec4b7f62011-11-01 08:44:04 +02002909
2910 ath6kl_cfg80211_scan_complete_event(vif, true);
2911}
2912
Kalle Valo7125f012011-12-13 14:51:37 +02002913void ath6kl_cfg80211_stop_all(struct ath6kl *ar)
2914{
2915 struct ath6kl_vif *vif;
2916
2917 vif = ath6kl_vif_first(ar);
2918 if (!vif) {
2919 /* save the current power mode before enabling power save */
2920 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
2921
2922 if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
2923 ath6kl_warn("ath6kl_deep_sleep_enable: "
2924 "wmi_powermode_cmd failed\n");
2925 return;
2926 }
2927
2928 /*
2929 * FIXME: we should take ar->list_lock to protect changes in the
2930 * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop()
2931 * sleeps.
2932 */
2933 list_for_each_entry(vif, &ar->vif_list, list)
2934 ath6kl_cfg80211_stop(vif);
2935}
2936
Kalle Valoc25889e2012-01-17 20:08:27 +02002937static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03002938{
Vasanthakumar Thiagarajan7baef812012-01-21 15:22:50 +05302939 vif->aggr_cntxt = aggr_init(vif);
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302940 if (!vif->aggr_cntxt) {
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302941 ath6kl_err("failed to initialize aggr\n");
2942 return -ENOMEM;
2943 }
Kalle Valobdcd8172011-07-18 00:22:30 +03002944
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302945 setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302946 (unsigned long) vif->ndev);
Kalle Valo10509f92011-12-13 14:52:07 +02002947 setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer,
2948 (unsigned long) vif);
2949
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05302950 set_bit(WMM_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05302951 spin_lock_init(&vif->if_lock);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302952
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302953 INIT_LIST_HEAD(&vif->mc_filter);
2954
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302955 return 0;
2956}
2957
Kalle Valoc25889e2012-01-17 20:08:27 +02002958void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302959{
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302960 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302961 struct ath6kl_mc_filter *mc_filter, *tmp;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302962
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05302963 aggr_module_destroy(vif->aggr_cntxt);
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302964
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302965 ar->avail_idx_map |= BIT(vif->fw_vif_idx);
2966
2967 if (vif->nw_type == ADHOC_NETWORK)
2968 ar->ibss_if_active = false;
2969
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05302970 list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
2971 list_del(&mc_filter->list);
2972 kfree(mc_filter);
2973 }
2974
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05302975 unregister_netdevice(vif->ndev);
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302976
2977 ar->num_vif--;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302978}
2979
2980struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name,
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302981 enum nl80211_iftype type, u8 fw_vif_idx,
2982 u8 nw_type)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302983{
2984 struct net_device *ndev;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302985 struct ath6kl_vif *vif;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302986
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05302987 ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05302988 if (!ndev)
2989 return NULL;
2990
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302991 vif = netdev_priv(ndev);
2992 ndev->ieee80211_ptr = &vif->wdev;
2993 vif->wdev.wiphy = ar->wiphy;
2994 vif->ar = ar;
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05302995 vif->ndev = ndev;
2996 SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
2997 vif->wdev.netdev = ndev;
2998 vif->wdev.iftype = type;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302999 vif->fw_vif_idx = fw_vif_idx;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303000 vif->nw_type = vif->next_mode = nw_type;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303001
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303002 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
3003 if (fw_vif_idx != 0)
3004 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
3005 0x2;
3006
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303007 init_netdev(ndev);
3008
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +05303009 ath6kl_init_control_info(vif);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303010
Kalle Valoc25889e2012-01-17 20:08:27 +02003011 if (ath6kl_cfg80211_vif_init(vif))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303012 goto err;
3013
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05303014 if (register_netdevice(ndev))
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303015 goto err;
3016
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303017 ar->avail_idx_map &= ~BIT(fw_vif_idx);
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +05303018 vif->sme_state = SME_DISCONNECTED;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05303019 set_bit(WLAN_ENABLED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303020 ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05303021 set_bit(NETDEV_REGISTERED, &vif->flags);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303022
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05303023 if (type == NL80211_IFTYPE_ADHOC)
3024 ar->ibss_if_active = true;
3025
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05303026 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303027 list_add_tail(&vif->list, &ar->vif_list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05303028 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303029
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303030 return ndev;
3031
3032err:
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05303033 aggr_module_destroy(vif->aggr_cntxt);
3034 free_netdev(ndev);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303035 return NULL;
3036}
3037
Kalle Valo46d33a22012-01-17 20:08:40 +02003038int ath6kl_cfg80211_init(struct ath6kl *ar)
3039{
3040 struct wiphy *wiphy = ar->wiphy;
3041 int ret;
3042
3043 wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
3044
3045 wiphy->max_remain_on_channel_duration = 5000;
3046
3047 /* set device pointer for wiphy */
3048 set_wiphy_dev(wiphy, ar->dev);
3049
3050 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3051 BIT(NL80211_IFTYPE_ADHOC) |
3052 BIT(NL80211_IFTYPE_AP);
3053 if (ar->p2p) {
3054 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
3055 BIT(NL80211_IFTYPE_P2P_CLIENT);
3056 }
3057
3058 /* max num of ssids that can be probed during scanning */
3059 wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
3060 wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
3061 wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
3062 wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
3063 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
3064
3065 wiphy->cipher_suites = cipher_suites;
3066 wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3067
3068 wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
3069 WIPHY_WOWLAN_DISCONNECT |
3070 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
3071 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
3072 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
3073 WIPHY_WOWLAN_4WAY_HANDSHAKE;
3074 wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST;
3075 wiphy->wowlan.pattern_min_len = 1;
3076 wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE;
3077
3078 wiphy->max_sched_scan_ssids = 10;
3079
Vasanthakumar Thiagarajanf2afdac2012-02-28 20:20:19 +05303080 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
3081 WIPHY_FLAG_HAVE_AP_SME |
3082 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
3083 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
3084
3085 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
3086 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
3087
3088 ar->wiphy->probe_resp_offload =
3089 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
3090 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
3091 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
3092 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
3093
Kalle Valo46d33a22012-01-17 20:08:40 +02003094 ret = wiphy_register(wiphy);
3095 if (ret < 0) {
3096 ath6kl_err("couldn't register wiphy device\n");
3097 return ret;
3098 }
3099
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +05303100 ar->wiphy_registered = true;
3101
Kalle Valo46d33a22012-01-17 20:08:40 +02003102 return 0;
3103}
3104
3105void ath6kl_cfg80211_cleanup(struct ath6kl *ar)
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05303106{
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05303107 wiphy_unregister(ar->wiphy);
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +05303108
3109 ar->wiphy_registered = false;
Kalle Valo45eaa782012-01-17 20:09:05 +02003110}
Kalle Valo46d33a22012-01-17 20:08:40 +02003111
Kalle Valo45eaa782012-01-17 20:09:05 +02003112struct ath6kl *ath6kl_cfg80211_create(void)
3113{
3114 struct ath6kl *ar;
3115 struct wiphy *wiphy;
3116
3117 /* create a new wiphy for use with cfg80211 */
3118 wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
3119
3120 if (!wiphy) {
3121 ath6kl_err("couldn't allocate wiphy device\n");
3122 return NULL;
3123 }
3124
3125 ar = wiphy_priv(wiphy);
3126 ar->wiphy = wiphy;
3127
3128 return ar;
3129}
3130
3131/* Note: ar variable must not be accessed after calling this! */
3132void ath6kl_cfg80211_destroy(struct ath6kl *ar)
3133{
Vasanthakumar Thiagarajan1d2a4452012-01-21 15:22:53 +05303134 int i;
3135
3136 for (i = 0; i < AP_MAX_NUM_STA; i++)
3137 kfree(ar->sta_list[i].aggr_conn);
3138
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05303139 wiphy_free(ar->wiphy);
Kalle Valobdcd8172011-07-18 00:22:30 +03003140}
Kalle Valo45eaa782012-01-17 20:09:05 +02003141