blob: d463a18332dc0ff5de9e5d2624af3a7ae259f715 [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
18#include "core.h"
19#include "hif-ops.h"
20#include "cfg80211.h"
21#include "target.h"
22#include "debug.h"
23
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053024struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr)
Kalle Valobdcd8172011-07-18 00:22:30 +030025{
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053026 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +030027 struct ath6kl_sta *conn = NULL;
28 u8 i, max_conn;
29
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +053030 max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
Kalle Valobdcd8172011-07-18 00:22:30 +030031
32 for (i = 0; i < max_conn; i++) {
33 if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
34 conn = &ar->sta_list[i];
35 break;
36 }
37 }
38
39 return conn;
40}
41
42struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
43{
44 struct ath6kl_sta *conn = NULL;
45 u8 ctr;
46
47 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
48 if (ar->sta_list[ctr].aid == aid) {
49 conn = &ar->sta_list[ctr];
50 break;
51 }
52 }
53 return conn;
54}
55
Vasanthakumar Thiagarajan17741c82012-01-21 15:22:51 +053056static void ath6kl_add_new_sta(struct ath6kl_vif *vif, u8 *mac, u16 aid,
57 u8 *wpaie, size_t ielen, u8 keymgmt,
58 u8 ucipher, u8 auth, u8 apsd_info)
Kalle Valobdcd8172011-07-18 00:22:30 +030059{
Vasanthakumar Thiagarajan17741c82012-01-21 15:22:51 +053060 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +030061 struct ath6kl_sta *sta;
62 u8 free_slot;
63
64 free_slot = aid - 1;
65
66 sta = &ar->sta_list[free_slot];
67 memcpy(sta->mac, mac, ETH_ALEN);
Jouni Malinen3c774bb2011-08-30 21:57:51 +030068 if (ielen <= ATH6KL_MAX_IE)
69 memcpy(sta->wpa_ie, wpaie, ielen);
Kalle Valobdcd8172011-07-18 00:22:30 +030070 sta->aid = aid;
71 sta->keymgmt = keymgmt;
72 sta->ucipher = ucipher;
73 sta->auth = auth;
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +053074 sta->apsd_info = apsd_info;
Kalle Valobdcd8172011-07-18 00:22:30 +030075
76 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
77 ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
Vasanthakumar Thiagarajanc8651542012-01-26 13:17:18 +053078 aggr_conn_init(vif, vif->aggr_cntxt, sta->aggr_conn);
Kalle Valobdcd8172011-07-18 00:22:30 +030079}
80
81static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
82{
83 struct ath6kl_sta *sta = &ar->sta_list[i];
84
85 /* empty the queued pkts in the PS queue if any */
86 spin_lock_bh(&sta->psq_lock);
87 skb_queue_purge(&sta->psq);
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +053088 skb_queue_purge(&sta->apsdq);
Kalle Valobdcd8172011-07-18 00:22:30 +030089 spin_unlock_bh(&sta->psq_lock);
90
91 memset(&ar->ap_stats.sta[sta->aid - 1], 0,
92 sizeof(struct wmi_per_sta_stat));
93 memset(sta->mac, 0, ETH_ALEN);
94 memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
95 sta->aid = 0;
96 sta->sta_flags = 0;
97
98 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
Vasanthakumar Thiagarajan1d2a4452012-01-21 15:22:53 +053099 aggr_reset_state(sta->aggr_conn);
Kalle Valobdcd8172011-07-18 00:22:30 +0300100}
101
102static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
103{
104 u8 i, removed = 0;
105
106 if (is_zero_ether_addr(mac))
107 return removed;
108
109 if (is_broadcast_ether_addr(mac)) {
110 ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
111
112 for (i = 0; i < AP_MAX_NUM_STA; i++) {
113 if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
114 ath6kl_sta_cleanup(ar, i);
115 removed = 1;
116 }
117 }
118 } else {
119 for (i = 0; i < AP_MAX_NUM_STA; i++) {
120 if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
121 ath6kl_dbg(ATH6KL_DBG_TRC,
122 "deleting station %pM aid=%d reason=%d\n",
123 mac, ar->sta_list[i].aid, reason);
124 ath6kl_sta_cleanup(ar, i);
125 removed = 1;
126 break;
127 }
128 }
129 }
130
131 return removed;
132}
133
134enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
135{
136 struct ath6kl *ar = devt;
137 return ar->ac2ep_map[ac];
138}
139
140struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
141{
142 struct ath6kl_cookie *cookie;
143
144 cookie = ar->cookie_list;
145 if (cookie != NULL) {
146 ar->cookie_list = cookie->arc_list_next;
147 ar->cookie_count--;
148 }
149
150 return cookie;
151}
152
153void ath6kl_cookie_init(struct ath6kl *ar)
154{
155 u32 i;
156
157 ar->cookie_list = NULL;
158 ar->cookie_count = 0;
159
160 memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
161
162 for (i = 0; i < MAX_COOKIE_NUM; i++)
163 ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
164}
165
166void ath6kl_cookie_cleanup(struct ath6kl *ar)
167{
168 ar->cookie_list = NULL;
169 ar->cookie_count = 0;
170}
171
172void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
173{
174 /* Insert first */
175
176 if (!ar || !cookie)
177 return;
178
179 cookie->arc_list_next = ar->cookie_list;
180 ar->cookie_list = cookie;
181 ar->cookie_count++;
182}
183
Kalle Valobdcd8172011-07-18 00:22:30 +0300184/*
Kalle Valoaddb44b2011-09-02 10:32:05 +0300185 * Read from the hardware through its diagnostic window. No cooperation
186 * from the firmware is required for this.
Kalle Valobdcd8172011-07-18 00:22:30 +0300187 */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300188int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300189{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300190 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300191
Kalle Valoc7111492011-11-11 12:17:51 +0200192 ret = ath6kl_hif_diag_read32(ar, address, value);
Kalle Valoaddb44b2011-09-02 10:32:05 +0300193 if (ret) {
194 ath6kl_warn("failed to read32 through diagnose window: %d\n",
195 ret);
196 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300197 }
198
Kalle Valoaddb44b2011-09-02 10:32:05 +0300199 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300200}
201
Kalle Valobdcd8172011-07-18 00:22:30 +0300202/*
203 * Write to the ATH6KL through its diagnostic window. No cooperation from
204 * the Target is required for this.
205 */
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300206int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300207{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300208 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300209
Kalle Valoc7111492011-11-11 12:17:51 +0200210 ret = ath6kl_hif_diag_write32(ar, address, value);
211
Kalle Valoaddb44b2011-09-02 10:32:05 +0300212 if (ret) {
213 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
214 address, value);
215 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300216 }
217
Kalle Valoc7111492011-11-11 12:17:51 +0200218 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300219}
220
Kalle Valoaddb44b2011-09-02 10:32:05 +0300221int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
Kalle Valobdcd8172011-07-18 00:22:30 +0300222{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300223 u32 count, *buf = data;
224 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300225
Kalle Valoaddb44b2011-09-02 10:32:05 +0300226 if (WARN_ON(length % 4))
227 return -EINVAL;
228
229 for (count = 0; count < length / 4; count++, address += 4) {
230 ret = ath6kl_diag_read32(ar, address, &buf[count]);
231 if (ret)
232 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300233 }
234
Kalle Valoaddb44b2011-09-02 10:32:05 +0300235 return 0;
236}
237
238int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
239{
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300240 u32 count;
241 __le32 *buf = data;
Kalle Valoaddb44b2011-09-02 10:32:05 +0300242 int ret;
243
244 if (WARN_ON(length % 4))
245 return -EINVAL;
246
247 for (count = 0; count < length / 4; count++, address += 4) {
248 ret = ath6kl_diag_write32(ar, address, buf[count]);
249 if (ret)
250 return ret;
251 }
252
253 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300254}
255
Kalle Valobc07ddb2011-09-02 10:32:05 +0300256int ath6kl_read_fwlogs(struct ath6kl *ar)
257{
258 struct ath6kl_dbglog_hdr debug_hdr;
259 struct ath6kl_dbglog_buf debug_buf;
260 u32 address, length, dropped, firstbuf, debug_hdr_addr;
Raja Manie80ec842012-01-12 15:01:48 +0530261 int ret, loop;
Kalle Valobc07ddb2011-09-02 10:32:05 +0300262 u8 *buf;
263
264 buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
265 if (!buf)
266 return -ENOMEM;
267
268 address = TARG_VTOP(ar->target_type,
269 ath6kl_get_hi_item_addr(ar,
270 HI_ITEM(hi_dbglog_hdr)));
271
272 ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
273 if (ret)
274 goto out;
275
276 /* Get the contents of the ring buffer */
277 if (debug_hdr_addr == 0) {
278 ath6kl_warn("Invalid address for debug_hdr_addr\n");
279 ret = -EINVAL;
280 goto out;
281 }
282
283 address = TARG_VTOP(ar->target_type, debug_hdr_addr);
284 ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
285
286 address = TARG_VTOP(ar->target_type,
287 le32_to_cpu(debug_hdr.dbuf_addr));
288 firstbuf = address;
289 dropped = le32_to_cpu(debug_hdr.dropped);
290 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
291
292 loop = 100;
293
294 do {
295 address = TARG_VTOP(ar->target_type,
296 le32_to_cpu(debug_buf.buffer_addr));
297 length = le32_to_cpu(debug_buf.length);
298
299 if (length != 0 && (le32_to_cpu(debug_buf.length) <=
300 le32_to_cpu(debug_buf.bufsize))) {
301 length = ALIGN(length, 4);
302
303 ret = ath6kl_diag_read(ar, address,
304 buf, length);
305 if (ret)
306 goto out;
307
308 ath6kl_debug_fwlog_event(ar, buf, length);
309 }
310
311 address = TARG_VTOP(ar->target_type,
312 le32_to_cpu(debug_buf.next));
313 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
314 if (ret)
315 goto out;
316
317 loop--;
318
319 if (WARN_ON(loop == 0)) {
320 ret = -ETIMEDOUT;
321 goto out;
322 }
323 } while (address != firstbuf);
324
325out:
326 kfree(buf);
327
328 return ret;
329}
330
Kevin Fang31024d92011-07-11 17:14:13 +0800331/* FIXME: move to a better place, target.h? */
332#define AR6003_RESET_CONTROL_ADDRESS 0x00004000
333#define AR6004_RESET_CONTROL_ADDRESS 0x00004000
334
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530335void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
336 bool wait_fot_compltn, bool cold_reset)
Kalle Valobdcd8172011-07-18 00:22:30 +0300337{
338 int status = 0;
339 u32 address;
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300340 __le32 data;
Kalle Valobdcd8172011-07-18 00:22:30 +0300341
Kevin Fang31024d92011-07-11 17:14:13 +0800342 if (target_type != TARGET_TYPE_AR6003 &&
343 target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +0300344 return;
345
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300346 data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) :
347 cpu_to_le32(RESET_CONTROL_MBOX_RST);
Kalle Valobdcd8172011-07-18 00:22:30 +0300348
Kevin Fang31024d92011-07-11 17:14:13 +0800349 switch (target_type) {
350 case TARGET_TYPE_AR6003:
351 address = AR6003_RESET_CONTROL_ADDRESS;
352 break;
353 case TARGET_TYPE_AR6004:
354 address = AR6004_RESET_CONTROL_ADDRESS;
355 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800356 }
357
Kalle Valoaddb44b2011-09-02 10:32:05 +0300358 status = ath6kl_diag_write32(ar, address, data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300359
360 if (status)
361 ath6kl_err("failed to reset target\n");
362}
363
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530364static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300365{
366 u8 index;
367 u8 keyusage;
368
Vivek Natarajan792ecb32011-12-29 16:18:39 +0530369 for (index = 0; index <= WMI_MAX_KEY_INDEX; index++) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530370 if (vif->wep_key_list[index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300371 keyusage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530372 if (index == vif->def_txkey_index)
Kalle Valobdcd8172011-07-18 00:22:30 +0300373 keyusage |= TX_USAGE;
374
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530375 ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300376 index,
377 WEP_CRYPT,
378 keyusage,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530379 vif->wep_key_list[index].key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200380 NULL, 0,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530381 vif->wep_key_list[index].key,
Kalle Valobdcd8172011-07-18 00:22:30 +0300382 KEY_OP_INIT_VAL, NULL,
383 NO_SYNC_WMIFLAG);
384 }
385 }
386}
387
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530388void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +0300389{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530390 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300391 struct ath6kl_req_key *ik;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300392 int res;
393 u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
Kalle Valobdcd8172011-07-18 00:22:30 +0300394
Jouni Malinen572e27c2011-09-05 17:38:45 +0300395 ik = &ar->ap_mode_bkey;
Kalle Valobdcd8172011-07-18 00:22:30 +0300396
Jouni Malinen572e27c2011-09-05 17:38:45 +0300397 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300398
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530399 switch (vif->auth_mode) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300400 case NONE_AUTH:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530401 if (vif->prwise_crypto == WEP_CRYPT)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530402 ath6kl_install_static_wep_keys(vif);
Jouni Malinen47032902011-12-08 16:50:30 +0200403 if (!ik->valid || ik->key_type != WAPI_CRYPT)
404 break;
405 /* for WAPI, we need to set the delayed group key, continue: */
Jouni Malinen572e27c2011-09-05 17:38:45 +0300406 case WPA_PSK_AUTH:
407 case WPA2_PSK_AUTH:
408 case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
409 if (!ik->valid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300410 break;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300411
Jouni Malinen572e27c2011-09-05 17:38:45 +0300412 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
413 "the initial group key for AP mode\n");
414 memset(key_rsc, 0, sizeof(key_rsc));
415 res = ath6kl_wmi_addkey_cmd(
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530416 ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200417 GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
418 ik->key,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300419 KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
420 if (res) {
421 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
422 "addkey failed: %d\n", res);
Kalle Valobdcd8172011-07-18 00:22:30 +0300423 }
Jouni Malinen572e27c2011-09-05 17:38:45 +0300424 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300425 }
426
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530427 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530428 set_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530429 netif_carrier_on(vif->ndev);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300430}
431
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530432void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300433 u8 keymgmt, u8 ucipher, u8 auth,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530434 u8 assoc_req_len, u8 *assoc_info, u8 apsd_info)
Jouni Malinen572e27c2011-09-05 17:38:45 +0300435{
436 u8 *ies = NULL, *wpa_ie = NULL, *pos;
437 size_t ies_len = 0;
438 struct station_info sinfo;
439
440 ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300441
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300442 if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
443 struct ieee80211_mgmt *mgmt =
444 (struct ieee80211_mgmt *) assoc_info;
445 if (ieee80211_is_assoc_req(mgmt->frame_control) &&
446 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
447 sizeof(mgmt->u.assoc_req)) {
448 ies = mgmt->u.assoc_req.variable;
449 ies_len = assoc_info + assoc_req_len - ies;
450 } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
451 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
452 + sizeof(mgmt->u.reassoc_req)) {
453 ies = mgmt->u.reassoc_req.variable;
454 ies_len = assoc_info + assoc_req_len - ies;
455 }
456 }
457
458 pos = ies;
459 while (pos && pos + 1 < ies + ies_len) {
460 if (pos + 2 + pos[1] > ies + ies_len)
461 break;
462 if (pos[0] == WLAN_EID_RSN)
463 wpa_ie = pos; /* RSN IE */
464 else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
465 pos[1] >= 4 &&
466 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
467 if (pos[5] == 0x01)
468 wpa_ie = pos; /* WPA IE */
469 else if (pos[5] == 0x04) {
470 wpa_ie = pos; /* WPS IE */
471 break; /* overrides WPA/RSN IE */
472 }
Dai Shuibing30677ae2011-11-03 11:39:39 +0200473 } else if (pos[0] == 0x44 && wpa_ie == NULL) {
474 /*
475 * Note: WAPI Parameter Set IE re-uses Element ID that
476 * was officially allocated for BSS AC Access Delay. As
477 * such, we need to be a bit more careful on when
478 * parsing the frame. However, BSS AC Access Delay
479 * element is not supposed to be included in
480 * (Re)Association Request frames, so this should not
481 * cause problems.
482 */
483 wpa_ie = pos; /* WAPI IE */
484 break;
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300485 }
486 pos += 2 + pos[1];
487 }
488
Vasanthakumar Thiagarajan17741c82012-01-21 15:22:51 +0530489 ath6kl_add_new_sta(vif, mac_addr, aid, wpa_ie,
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300490 wpa_ie ? 2 + wpa_ie[1] : 0,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530491 keymgmt, ucipher, auth, apsd_info);
Kalle Valobdcd8172011-07-18 00:22:30 +0300492
493 /* send event to application */
494 memset(&sinfo, 0, sizeof(sinfo));
495
496 /* TODO: sinfo.generation */
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300497
498 sinfo.assoc_req_ies = ies;
499 sinfo.assoc_req_ies_len = ies_len;
500 sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
501
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530502 cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300503
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530504 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300505}
506
Kalle Valobdcd8172011-07-18 00:22:30 +0300507void disconnect_timer_handler(unsigned long ptr)
508{
509 struct net_device *dev = (struct net_device *)ptr;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530510 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300511
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530512 ath6kl_init_profile_info(vif);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530513 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300514}
515
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530516void ath6kl_disconnect(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300517{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530518 if (test_bit(CONNECTED, &vif->flags) ||
519 test_bit(CONNECT_PEND, &vif->flags)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530520 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300521 /*
522 * Disconnect command is issued, clear the connect pending
523 * flag. The connected flag will be cleared in
524 * disconnect event notification.
525 */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530526 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300527 }
528}
529
530/* WMI Event handlers */
531
Kalle Valobdcd8172011-07-18 00:22:30 +0300532void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
533{
534 struct ath6kl *ar = devt;
Kalle Valobdcd8172011-07-18 00:22:30 +0300535
Vasanthakumar Thiagarajand66ea4f2011-10-25 19:34:18 +0530536 memcpy(ar->mac_addr, datap, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +0300537 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
Vasanthakumar Thiagarajand66ea4f2011-10-25 19:34:18 +0530538 __func__, ar->mac_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +0300539
540 ar->version.wlan_ver = sw_ver;
541 ar->version.abi_ver = abi_ver;
542
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530543 snprintf(ar->wiphy->fw_version,
544 sizeof(ar->wiphy->fw_version),
Kalle Valobdcd8172011-07-18 00:22:30 +0300545 "%u.%u.%u.%u",
546 (ar->version.wlan_ver & 0xf0000000) >> 28,
547 (ar->version.wlan_ver & 0x0f000000) >> 24,
548 (ar->version.wlan_ver & 0x00ff0000) >> 16,
549 (ar->version.wlan_ver & 0x0000ffff));
550
551 /* indicate to the waiting thread that the ready event was received */
552 set_bit(WMI_READY, &ar->flag);
553 wake_up(&ar->event_wq);
Kalle Valobdcd8172011-07-18 00:22:30 +0300554}
555
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530556void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
Kalle Valobdcd8172011-07-18 00:22:30 +0300557{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530558 struct ath6kl *ar = vif->ar;
Kalle Valo1c17d312011-11-01 08:43:56 +0200559 bool aborted = false;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530560
Kalle Valo1c17d312011-11-01 08:43:56 +0200561 if (status != WMI_SCAN_STATUS_SUCCESS)
562 aborted = true;
563
564 ath6kl_cfg80211_scan_complete_event(vif, aborted);
Kalle Valobdcd8172011-07-18 00:22:30 +0300565
Jouni Malinen551185c2011-09-19 19:15:06 +0300566 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530567 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530568 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
569 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +0300570 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300571
Kalle Valod23ace72011-10-24 12:17:51 +0300572 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
Kalle Valobdcd8172011-07-18 00:22:30 +0300573}
574
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530575void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300576 u16 listen_int, u16 beacon_int,
577 enum network_type net_type, u8 beacon_ie_len,
578 u8 assoc_req_len, u8 assoc_resp_len,
579 u8 *assoc_info)
580{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530581 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530582
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530583 ath6kl_cfg80211_connect_event(vif, channel, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300584 listen_int, beacon_int,
585 net_type, beacon_ie_len,
586 assoc_req_len, assoc_resp_len,
587 assoc_info);
588
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530589 memcpy(vif->bssid, bssid, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530590 vif->bss_ch = channel;
Kalle Valobdcd8172011-07-18 00:22:30 +0300591
Sujith Manoharan82327362012-01-10 09:54:10 +0530592 if ((vif->nw_type == INFRA_NETWORK)) {
593 ar->listen_intvl_b = listen_int;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530594 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
Sujith Manoharan82327362012-01-10 09:54:10 +0530595 0, ar->listen_intvl_b);
596 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300597
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530598 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300599
600 /* Update connect & link status atomically */
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530601 spin_lock_bh(&vif->if_lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530602 set_bit(CONNECTED, &vif->flags);
603 clear_bit(CONNECT_PEND, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530604 netif_carrier_on(vif->ndev);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530605 spin_unlock_bh(&vif->if_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300606
Vasanthakumar Thiagarajan1d2a4452012-01-21 15:22:53 +0530607 aggr_reset_state(vif->aggr_cntxt->aggr_conn);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530608 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300609
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530610 if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300611 memset(ar->node_map, 0, sizeof(ar->node_map));
612 ar->node_num = 0;
613 ar->next_ep_id = ENDPOINT_2;
614 }
615
Jouni Malinen551185c2011-09-19 19:15:06 +0300616 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530617 set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530618 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
619 CURRENT_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +0300620 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300621}
622
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530623void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
Kalle Valobdcd8172011-07-18 00:22:30 +0300624{
625 struct ath6kl_sta *sta;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530626 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300627 u8 tsc[6];
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530628
Kalle Valobdcd8172011-07-18 00:22:30 +0300629 /*
630 * For AP case, keyid will have aid of STA which sent pkt with
631 * MIC error. Use this aid to get MAC & send it to hostapd.
632 */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530633 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300634 sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
635 if (!sta)
636 return;
637
638 ath6kl_dbg(ATH6KL_DBG_TRC,
639 "ap tkip mic error received from aid=%d\n", keyid);
640
641 memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530642 cfg80211_michael_mic_failure(vif->ndev, sta->mac,
Kalle Valobdcd8172011-07-18 00:22:30 +0300643 NL80211_KEYTYPE_PAIRWISE, keyid,
644 tsc, GFP_KERNEL);
645 } else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530646 ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
Kalle Valobdcd8172011-07-18 00:22:30 +0300647
648}
649
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530650static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +0300651{
652 struct wmi_target_stats *tgt_stats =
653 (struct wmi_target_stats *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530654 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530655 struct target_stats *stats = &vif->target_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +0300656 struct tkip_ccmp_stats *ccmp_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +0300657 u8 ac;
658
659 if (len < sizeof(*tgt_stats))
660 return;
661
Kalle Valobdcd8172011-07-18 00:22:30 +0300662 ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
663
664 stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
665 stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
666 stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
667 stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
668 stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
669 stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
670 stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
671 stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
672 stats->tx_rts_success_cnt +=
673 le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
674
675 for (ac = 0; ac < WMM_NUM_AC; ac++)
676 stats->tx_pkt_per_ac[ac] +=
677 le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
678
679 stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
680 stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
681 stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
682 stats->tx_mult_retry_cnt +=
683 le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
684 stats->tx_rts_fail_cnt +=
685 le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
686 stats->tx_ucast_rate =
687 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
688
689 stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
690 stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
691 stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
692 stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
693 stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
694 stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
695 stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
696 stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
697 stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
698 stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
699 stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
700 stats->rx_key_cache_miss +=
701 le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
702 stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
703 stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
704 stats->rx_ucast_rate =
705 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
706
707 ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
708
709 stats->tkip_local_mic_fail +=
710 le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
711 stats->tkip_cnter_measures_invoked +=
712 le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
713 stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
714
715 stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
716 stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
717
718 stats->pwr_save_fail_cnt +=
719 le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
720 stats->noise_floor_calib =
721 a_sle32_to_cpu(tgt_stats->noise_floor_calib);
722
723 stats->cs_bmiss_cnt +=
724 le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
725 stats->cs_low_rssi_cnt +=
726 le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
727 stats->cs_connect_cnt +=
728 le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
729 stats->cs_discon_cnt +=
730 le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
731
732 stats->cs_ave_beacon_rssi =
733 a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
734
735 stats->cs_last_roam_msec =
736 tgt_stats->cserv_stats.cs_last_roam_msec;
737 stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
738 stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
739
740 stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
741
742 stats->wow_pkt_dropped +=
743 le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
744 stats->wow_host_pkt_wakeups +=
745 tgt_stats->wow_stats.wow_host_pkt_wakeups;
746 stats->wow_host_evt_wakeups +=
747 tgt_stats->wow_stats.wow_host_evt_wakeups;
748 stats->wow_evt_discarded +=
749 le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
750
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530751 if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
752 clear_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300753 wake_up(&ar->event_wq);
754 }
755}
756
757static void ath6kl_add_le32(__le32 *var, __le32 val)
758{
759 *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
760}
761
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530762void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +0300763{
764 struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530765 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300766 struct wmi_ap_mode_stat *ap = &ar->ap_stats;
767 struct wmi_per_sta_stat *st_ap, *st_p;
768 u8 ac;
769
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530770 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300771 if (len < sizeof(*p))
772 return;
773
774 for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
775 st_ap = &ap->sta[ac];
776 st_p = &p->sta[ac];
777
778 ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
779 ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
780 ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
781 ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
782 ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
783 ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
784 ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
785 ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
786 }
787
788 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530789 ath6kl_update_target_stats(vif, ptr, len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300790 }
791}
792
793void ath6kl_wakeup_event(void *dev)
794{
795 struct ath6kl *ar = (struct ath6kl *) dev;
796
797 wake_up(&ar->event_wq);
798}
799
800void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
801{
802 struct ath6kl *ar = (struct ath6kl *) devt;
803
804 ar->tx_pwr = tx_pwr;
805 wake_up(&ar->event_wq);
806}
807
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530808void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300809{
810 struct ath6kl_sta *conn;
811 struct sk_buff *skb;
812 bool psq_empty = false;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530813 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300814
815 conn = ath6kl_find_sta_by_aid(ar, aid);
816
817 if (!conn)
818 return;
819 /*
820 * Send out a packet queued on ps queue. When the ps queue
821 * becomes empty update the PVB for this station.
822 */
823 spin_lock_bh(&conn->psq_lock);
824 psq_empty = skb_queue_empty(&conn->psq);
825 spin_unlock_bh(&conn->psq_lock);
826
827 if (psq_empty)
828 /* TODO: Send out a NULL data frame */
829 return;
830
831 spin_lock_bh(&conn->psq_lock);
832 skb = skb_dequeue(&conn->psq);
833 spin_unlock_bh(&conn->psq_lock);
834
835 conn->sta_flags |= STA_PS_POLLED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530836 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300837 conn->sta_flags &= ~STA_PS_POLLED;
838
839 spin_lock_bh(&conn->psq_lock);
840 psq_empty = skb_queue_empty(&conn->psq);
841 spin_unlock_bh(&conn->psq_lock);
842
843 if (psq_empty)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530844 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300845}
846
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530847void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300848{
849 bool mcastq_empty = false;
850 struct sk_buff *skb;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530851 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300852
853 /*
854 * If there are no associated STAs, ignore the DTIM expiry event.
855 * There can be potential race conditions where the last associated
856 * STA may disconnect & before the host could clear the 'Indicate
857 * DTIM' request to the firmware, the firmware would have just
858 * indicated a DTIM expiry event. The race is between 'clear DTIM
859 * expiry cmd' going from the host to the firmware & the DTIM
860 * expiry event happening from the firmware to the host.
861 */
862 if (!ar->sta_list_index)
863 return;
864
865 spin_lock_bh(&ar->mcastpsq_lock);
866 mcastq_empty = skb_queue_empty(&ar->mcastpsq);
867 spin_unlock_bh(&ar->mcastpsq_lock);
868
869 if (mcastq_empty)
870 return;
871
872 /* set the STA flag to dtim_expired for the frame to go out */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530873 set_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300874
875 spin_lock_bh(&ar->mcastpsq_lock);
876 while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
877 spin_unlock_bh(&ar->mcastpsq_lock);
878
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530879 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300880
881 spin_lock_bh(&ar->mcastpsq_lock);
882 }
883 spin_unlock_bh(&ar->mcastpsq_lock);
884
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530885 clear_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300886
887 /* clear the LSB of the BitMapCtl field of the TIM IE */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530888 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300889}
890
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530891void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300892 u8 assoc_resp_len, u8 *assoc_info,
893 u16 prot_reason_status)
894{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530895 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530896
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530897 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300898 if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
899 return;
900
901 /* if no more associated STAs, empty the mcast PS q */
902 if (ar->sta_list_index == 0) {
903 spin_lock_bh(&ar->mcastpsq_lock);
904 skb_queue_purge(&ar->mcastpsq);
905 spin_unlock_bh(&ar->mcastpsq_lock);
906
907 /* clear the LSB of the TIM IE's BitMapCtl field */
908 if (test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530909 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
910 MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300911 }
912
913 if (!is_broadcast_ether_addr(bssid)) {
914 /* send event to application */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530915 cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300916 }
917
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530918 if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530919 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530920 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen151411e2011-09-15 15:10:16 +0300921 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300922 return;
923 }
924
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530925 ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300926 assoc_resp_len, assoc_info,
927 prot_reason_status);
928
Vasanthakumar Thiagarajan1d2a4452012-01-21 15:22:53 +0530929 aggr_reset_state(vif->aggr_cntxt->aggr_conn);
Kalle Valobdcd8172011-07-18 00:22:30 +0300930
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +0530931 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +0300932
Kalle Valod23ace72011-10-24 12:17:51 +0300933 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
Kalle Valobdcd8172011-07-18 00:22:30 +0300934
935 /*
936 * If the event is due to disconnect cmd from the host, only they
937 * the target would stop trying to connect. Under any other
938 * condition, target would keep trying to connect.
939 */
940 if (reason == DISCONNECT_CMD) {
941 if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530942 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
943 NONE_BSS_FILTER, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300944 } else {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530945 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300946 if (((reason == ASSOC_FAILED) &&
947 (prot_reason_status == 0x11)) ||
948 ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530949 && (vif->reconnect_flag == 1))) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530950 set_bit(CONNECTED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300951 return;
952 }
953 }
954
Kalle Valobdcd8172011-07-18 00:22:30 +0300955 /* update connect & link status atomically */
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530956 spin_lock_bh(&vif->if_lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530957 clear_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530958 netif_carrier_off(vif->ndev);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530959 spin_unlock_bh(&vif->if_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300960
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530961 if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
962 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300963
964 if (reason != CSERV_DISCONNECT)
965 ar->user_key_ctrl = 0;
966
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530967 netif_stop_queue(vif->ndev);
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530968 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530969 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300970
971 ath6kl_tx_data_cleanup(ar);
972}
973
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530974struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
975{
976 struct ath6kl_vif *vif;
977
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530978 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530979 if (list_empty(&ar->vif_list)) {
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530980 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530981 return NULL;
982 }
983
984 vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
985
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530986 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530987
988 return vif;
989}
990
Kalle Valobdcd8172011-07-18 00:22:30 +0300991static int ath6kl_open(struct net_device *dev)
992{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530993 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300994
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530995 set_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300996
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530997 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300998 netif_carrier_on(dev);
999 netif_wake_queue(dev);
1000 } else
1001 netif_carrier_off(dev);
1002
Kalle Valobdcd8172011-07-18 00:22:30 +03001003 return 0;
1004}
1005
1006static int ath6kl_close(struct net_device *dev)
1007{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301008 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001009
1010 netif_stop_queue(dev);
1011
Kalle Valo7125f012011-12-13 14:51:37 +02001012 ath6kl_cfg80211_stop(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03001013
Kalle Valo68469342011-10-30 21:16:33 +02001014 clear_bit(WLAN_ENABLED, &vif->flags);
1015
Kalle Valobdcd8172011-07-18 00:22:30 +03001016 return 0;
1017}
1018
1019static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
1020{
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301021 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001022
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301023 return &vif->net_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001024}
1025
Kalle Valod6f80262012-01-17 15:05:19 +02001026static int ath6kl_set_features(struct net_device *dev,
1027 netdev_features_t features)
Rishi Panjwanibc48ad32011-12-27 14:28:00 -08001028{
1029 struct ath6kl_vif *vif = netdev_priv(dev);
1030 struct ath6kl *ar = vif->ar;
1031 int err = 0;
1032
1033 if ((features & NETIF_F_RXCSUM) &&
1034 (ar->rx_meta_ver != WMI_META_VERSION_2)) {
1035 ar->rx_meta_ver = WMI_META_VERSION_2;
1036 err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
1037 vif->fw_vif_idx,
1038 ar->rx_meta_ver, 0, 0);
1039 if (err) {
1040 dev->features = features & ~NETIF_F_RXCSUM;
1041 return err;
1042 }
1043 } else if (!(features & NETIF_F_RXCSUM) &&
1044 (ar->rx_meta_ver == WMI_META_VERSION_2)) {
1045 ar->rx_meta_ver = 0;
1046 err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
1047 vif->fw_vif_idx,
1048 ar->rx_meta_ver, 0, 0);
1049 if (err) {
1050 dev->features = features | NETIF_F_RXCSUM;
1051 return err;
1052 }
1053
1054 }
1055
1056 return err;
1057}
1058
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05301059static void ath6kl_set_multicast_list(struct net_device *ndev)
1060{
1061 struct ath6kl_vif *vif = netdev_priv(ndev);
1062 bool mc_all_on = false, mc_all_off = false;
1063 int mc_count = netdev_mc_count(ndev);
1064 struct netdev_hw_addr *ha;
1065 bool found;
1066 struct ath6kl_mc_filter *mc_filter, *tmp;
1067 struct list_head mc_filter_new;
1068 int ret;
1069
1070 if (!test_bit(WMI_READY, &vif->ar->flag) ||
1071 !test_bit(WLAN_ENABLED, &vif->flags))
1072 return;
1073
1074 mc_all_on = !!(ndev->flags & IFF_PROMISC) ||
1075 !!(ndev->flags & IFF_ALLMULTI) ||
1076 !!(mc_count > ATH6K_MAX_MC_FILTERS_PER_LIST);
1077
1078 mc_all_off = !(ndev->flags & IFF_MULTICAST) || mc_count == 0;
1079
1080 if (mc_all_on || mc_all_off) {
1081 /* Enable/disable all multicast */
1082 ath6kl_dbg(ATH6KL_DBG_TRC, "%s multicast filter\n",
1083 mc_all_on ? "enabling" : "disabling");
1084 ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi, vif->fw_vif_idx,
1085 mc_all_on);
1086 if (ret)
1087 ath6kl_warn("Failed to %s multicast receive\n",
1088 mc_all_on ? "enable" : "disable");
1089 return;
1090 }
1091
1092 list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
1093 found = false;
1094 netdev_for_each_mc_addr(ha, ndev) {
1095 if (memcmp(ha->addr, mc_filter->hw_addr,
1096 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
1097 found = true;
1098 break;
1099 }
1100 }
1101
1102 if (!found) {
1103 /*
1104 * Delete the filter which was previously set
1105 * but not in the new request.
1106 */
1107 ath6kl_dbg(ATH6KL_DBG_TRC,
1108 "Removing %pM from multicast filter\n",
1109 mc_filter->hw_addr);
1110 ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
1111 vif->fw_vif_idx, mc_filter->hw_addr,
1112 false);
1113 if (ret) {
1114 ath6kl_warn("Failed to remove multicast filter:%pM\n",
1115 mc_filter->hw_addr);
1116 return;
1117 }
1118
1119 list_del(&mc_filter->list);
1120 kfree(mc_filter);
1121 }
1122 }
1123
1124 INIT_LIST_HEAD(&mc_filter_new);
1125
1126 netdev_for_each_mc_addr(ha, ndev) {
1127 found = false;
1128 list_for_each_entry(mc_filter, &vif->mc_filter, list) {
1129 if (memcmp(ha->addr, mc_filter->hw_addr,
1130 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
1131 found = true;
1132 break;
1133 }
1134 }
1135
1136 if (!found) {
1137 mc_filter = kzalloc(sizeof(struct ath6kl_mc_filter),
1138 GFP_ATOMIC);
1139 if (!mc_filter) {
1140 WARN_ON(1);
1141 goto out;
1142 }
1143
1144 memcpy(mc_filter->hw_addr, ha->addr,
1145 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
1146 /* Set the multicast filter */
1147 ath6kl_dbg(ATH6KL_DBG_TRC,
1148 "Adding %pM to multicast filter list\n",
1149 mc_filter->hw_addr);
1150 ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
1151 vif->fw_vif_idx, mc_filter->hw_addr,
1152 true);
1153 if (ret) {
1154 ath6kl_warn("Failed to add multicast filter :%pM\n",
1155 mc_filter->hw_addr);
1156 kfree(mc_filter);
1157 goto out;
1158 }
1159
1160 list_add_tail(&mc_filter->list, &mc_filter_new);
1161 }
1162 }
1163
1164out:
1165 list_splice_tail(&mc_filter_new, &vif->mc_filter);
1166}
1167
Stephen Hemminger4269a932012-01-05 10:39:48 -08001168static const struct net_device_ops ath6kl_netdev_ops = {
Kalle Valobdcd8172011-07-18 00:22:30 +03001169 .ndo_open = ath6kl_open,
1170 .ndo_stop = ath6kl_close,
1171 .ndo_start_xmit = ath6kl_data_tx,
1172 .ndo_get_stats = ath6kl_get_stats,
Rishi Panjwanibc48ad32011-12-27 14:28:00 -08001173 .ndo_set_features = ath6kl_set_features,
Vasanthakumar Thiagarajan80abaf92012-01-03 14:42:01 +05301174 .ndo_set_rx_mode = ath6kl_set_multicast_list,
Kalle Valobdcd8172011-07-18 00:22:30 +03001175};
1176
1177void init_netdev(struct net_device *dev)
1178{
1179 dev->netdev_ops = &ath6kl_netdev_ops;
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301180 dev->destructor = free_netdev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001181 dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
1182
1183 dev->needed_headroom = ETH_HLEN;
1184 dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
1185 sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +05301186 + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +03001187
1188 return;
1189}