blob: 1195f9408857eef81b5fed13c35e9f69db77896d [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "core.h"
18#include "hif-ops.h"
19#include "cfg80211.h"
20#include "target.h"
21#include "debug.h"
22
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053023struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr)
Kalle Valobdcd8172011-07-18 00:22:30 +030024{
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053025 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +030026 struct ath6kl_sta *conn = NULL;
27 u8 i, max_conn;
28
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +053029 max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
Kalle Valobdcd8172011-07-18 00:22:30 +030030
31 for (i = 0; i < max_conn; i++) {
32 if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
33 conn = &ar->sta_list[i];
34 break;
35 }
36 }
37
38 return conn;
39}
40
41struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
42{
43 struct ath6kl_sta *conn = NULL;
44 u8 ctr;
45
46 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
47 if (ar->sta_list[ctr].aid == aid) {
48 conn = &ar->sta_list[ctr];
49 break;
50 }
51 }
52 return conn;
53}
54
55static void ath6kl_add_new_sta(struct ath6kl *ar, u8 *mac, u16 aid, u8 *wpaie,
56 u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
57{
58 struct ath6kl_sta *sta;
59 u8 free_slot;
60
61 free_slot = aid - 1;
62
63 sta = &ar->sta_list[free_slot];
64 memcpy(sta->mac, mac, ETH_ALEN);
Jouni Malinen3c774bb2011-08-30 21:57:51 +030065 if (ielen <= ATH6KL_MAX_IE)
66 memcpy(sta->wpa_ie, wpaie, ielen);
Kalle Valobdcd8172011-07-18 00:22:30 +030067 sta->aid = aid;
68 sta->keymgmt = keymgmt;
69 sta->ucipher = ucipher;
70 sta->auth = auth;
71
72 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
73 ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
74}
75
76static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
77{
78 struct ath6kl_sta *sta = &ar->sta_list[i];
79
80 /* empty the queued pkts in the PS queue if any */
81 spin_lock_bh(&sta->psq_lock);
82 skb_queue_purge(&sta->psq);
83 spin_unlock_bh(&sta->psq_lock);
84
85 memset(&ar->ap_stats.sta[sta->aid - 1], 0,
86 sizeof(struct wmi_per_sta_stat));
87 memset(sta->mac, 0, ETH_ALEN);
88 memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
89 sta->aid = 0;
90 sta->sta_flags = 0;
91
92 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
93
94}
95
96static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
97{
98 u8 i, removed = 0;
99
100 if (is_zero_ether_addr(mac))
101 return removed;
102
103 if (is_broadcast_ether_addr(mac)) {
104 ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
105
106 for (i = 0; i < AP_MAX_NUM_STA; i++) {
107 if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
108 ath6kl_sta_cleanup(ar, i);
109 removed = 1;
110 }
111 }
112 } else {
113 for (i = 0; i < AP_MAX_NUM_STA; i++) {
114 if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
115 ath6kl_dbg(ATH6KL_DBG_TRC,
116 "deleting station %pM aid=%d reason=%d\n",
117 mac, ar->sta_list[i].aid, reason);
118 ath6kl_sta_cleanup(ar, i);
119 removed = 1;
120 break;
121 }
122 }
123 }
124
125 return removed;
126}
127
128enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
129{
130 struct ath6kl *ar = devt;
131 return ar->ac2ep_map[ac];
132}
133
134struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
135{
136 struct ath6kl_cookie *cookie;
137
138 cookie = ar->cookie_list;
139 if (cookie != NULL) {
140 ar->cookie_list = cookie->arc_list_next;
141 ar->cookie_count--;
142 }
143
144 return cookie;
145}
146
147void ath6kl_cookie_init(struct ath6kl *ar)
148{
149 u32 i;
150
151 ar->cookie_list = NULL;
152 ar->cookie_count = 0;
153
154 memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
155
156 for (i = 0; i < MAX_COOKIE_NUM; i++)
157 ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
158}
159
160void ath6kl_cookie_cleanup(struct ath6kl *ar)
161{
162 ar->cookie_list = NULL;
163 ar->cookie_count = 0;
164}
165
166void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
167{
168 /* Insert first */
169
170 if (!ar || !cookie)
171 return;
172
173 cookie->arc_list_next = ar->cookie_list;
174 ar->cookie_list = cookie;
175 ar->cookie_count++;
176}
177
178/* set the window address register (using 4-byte register access ). */
179static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr)
180{
181 int status;
Kalle Valobdcd8172011-07-18 00:22:30 +0300182 s32 i;
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530183 __le32 addr_val;
Kalle Valobdcd8172011-07-18 00:22:30 +0300184
185 /*
186 * Write bytes 1,2,3 of the register to set the upper address bytes,
187 * the LSB is written last to initiate the access cycle
188 */
189
190 for (i = 1; i <= 3; i++) {
191 /*
192 * Fill the buffer with the address byte value we want to
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530193 * hit 4 times. No need to worry about endianness as the
194 * same byte is copied to all four bytes of addr_val at
195 * any time.
Kalle Valobdcd8172011-07-18 00:22:30 +0300196 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530197 memset((u8 *)&addr_val, ((u8 *)&addr)[i], 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300198
199 /*
200 * Hit each byte of the register address with a 4-byte
201 * write operation to the same address, this is a harmless
202 * operation.
203 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530204 status = hif_read_write_sync(ar, reg_addr + i, (u8 *)&addr_val,
Kalle Valobdcd8172011-07-18 00:22:30 +0300205 4, HIF_WR_SYNC_BYTE_FIX);
206 if (status)
207 break;
208 }
209
210 if (status) {
211 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
212 addr, reg_addr);
213 return status;
214 }
215
216 /*
217 * Write the address register again, this time write the whole
218 * 4-byte value. The effect here is that the LSB write causes the
219 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
220 * effect since we are writing the same values again
221 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530222 addr_val = cpu_to_le32(addr);
223 status = hif_read_write_sync(ar, reg_addr,
224 (u8 *)&(addr_val),
Kalle Valobdcd8172011-07-18 00:22:30 +0300225 4, HIF_WR_SYNC_BYTE_INC);
226
227 if (status) {
228 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
229 addr, reg_addr);
230 return status;
231 }
232
233 return 0;
234}
235
236/*
Kalle Valoaddb44b2011-09-02 10:32:05 +0300237 * Read from the hardware through its diagnostic window. No cooperation
238 * from the firmware is required for this.
Kalle Valobdcd8172011-07-18 00:22:30 +0300239 */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300240int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300241{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300242 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300243
244 /* set window register to start read cycle */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300245 ret = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, address);
246 if (ret)
247 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300248
249 /* read the data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300250 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) value,
251 sizeof(*value), HIF_RD_SYNC_BYTE_INC);
252 if (ret) {
253 ath6kl_warn("failed to read32 through diagnose window: %d\n",
254 ret);
255 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300256 }
257
Kalle Valoaddb44b2011-09-02 10:32:05 +0300258 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300259}
260
Kalle Valobdcd8172011-07-18 00:22:30 +0300261/*
262 * Write to the ATH6KL through its diagnostic window. No cooperation from
263 * the Target is required for this.
264 */
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300265int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300266{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300267 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300268
269 /* set write data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300270 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) &value,
271 sizeof(value), HIF_WR_SYNC_BYTE_INC);
272 if (ret) {
273 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
274 address, value);
275 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300276 }
277
278 /* set window register, which starts the write cycle */
279 return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS,
Kalle Valoaddb44b2011-09-02 10:32:05 +0300280 address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300281}
282
Kalle Valoaddb44b2011-09-02 10:32:05 +0300283int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
Kalle Valobdcd8172011-07-18 00:22:30 +0300284{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300285 u32 count, *buf = data;
286 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300287
Kalle Valoaddb44b2011-09-02 10:32:05 +0300288 if (WARN_ON(length % 4))
289 return -EINVAL;
290
291 for (count = 0; count < length / 4; count++, address += 4) {
292 ret = ath6kl_diag_read32(ar, address, &buf[count]);
293 if (ret)
294 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300295 }
296
Kalle Valoaddb44b2011-09-02 10:32:05 +0300297 return 0;
298}
299
300int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
301{
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300302 u32 count;
303 __le32 *buf = data;
Kalle Valoaddb44b2011-09-02 10:32:05 +0300304 int ret;
305
306 if (WARN_ON(length % 4))
307 return -EINVAL;
308
309 for (count = 0; count < length / 4; count++, address += 4) {
310 ret = ath6kl_diag_write32(ar, address, buf[count]);
311 if (ret)
312 return ret;
313 }
314
315 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300316}
317
Kalle Valobc07ddb2011-09-02 10:32:05 +0300318int ath6kl_read_fwlogs(struct ath6kl *ar)
319{
320 struct ath6kl_dbglog_hdr debug_hdr;
321 struct ath6kl_dbglog_buf debug_buf;
322 u32 address, length, dropped, firstbuf, debug_hdr_addr;
323 int ret = 0, loop;
324 u8 *buf;
325
326 buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
327 if (!buf)
328 return -ENOMEM;
329
330 address = TARG_VTOP(ar->target_type,
331 ath6kl_get_hi_item_addr(ar,
332 HI_ITEM(hi_dbglog_hdr)));
333
334 ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
335 if (ret)
336 goto out;
337
338 /* Get the contents of the ring buffer */
339 if (debug_hdr_addr == 0) {
340 ath6kl_warn("Invalid address for debug_hdr_addr\n");
341 ret = -EINVAL;
342 goto out;
343 }
344
345 address = TARG_VTOP(ar->target_type, debug_hdr_addr);
346 ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
347
348 address = TARG_VTOP(ar->target_type,
349 le32_to_cpu(debug_hdr.dbuf_addr));
350 firstbuf = address;
351 dropped = le32_to_cpu(debug_hdr.dropped);
352 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
353
354 loop = 100;
355
356 do {
357 address = TARG_VTOP(ar->target_type,
358 le32_to_cpu(debug_buf.buffer_addr));
359 length = le32_to_cpu(debug_buf.length);
360
361 if (length != 0 && (le32_to_cpu(debug_buf.length) <=
362 le32_to_cpu(debug_buf.bufsize))) {
363 length = ALIGN(length, 4);
364
365 ret = ath6kl_diag_read(ar, address,
366 buf, length);
367 if (ret)
368 goto out;
369
370 ath6kl_debug_fwlog_event(ar, buf, length);
371 }
372
373 address = TARG_VTOP(ar->target_type,
374 le32_to_cpu(debug_buf.next));
375 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
376 if (ret)
377 goto out;
378
379 loop--;
380
381 if (WARN_ON(loop == 0)) {
382 ret = -ETIMEDOUT;
383 goto out;
384 }
385 } while (address != firstbuf);
386
387out:
388 kfree(buf);
389
390 return ret;
391}
392
Kevin Fang31024d92011-07-11 17:14:13 +0800393/* FIXME: move to a better place, target.h? */
394#define AR6003_RESET_CONTROL_ADDRESS 0x00004000
395#define AR6004_RESET_CONTROL_ADDRESS 0x00004000
396
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530397void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
398 bool wait_fot_compltn, bool cold_reset)
Kalle Valobdcd8172011-07-18 00:22:30 +0300399{
400 int status = 0;
401 u32 address;
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300402 __le32 data;
Kalle Valobdcd8172011-07-18 00:22:30 +0300403
Kevin Fang31024d92011-07-11 17:14:13 +0800404 if (target_type != TARGET_TYPE_AR6003 &&
405 target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +0300406 return;
407
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300408 data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) :
409 cpu_to_le32(RESET_CONTROL_MBOX_RST);
Kalle Valobdcd8172011-07-18 00:22:30 +0300410
Kevin Fang31024d92011-07-11 17:14:13 +0800411 switch (target_type) {
412 case TARGET_TYPE_AR6003:
413 address = AR6003_RESET_CONTROL_ADDRESS;
414 break;
415 case TARGET_TYPE_AR6004:
416 address = AR6004_RESET_CONTROL_ADDRESS;
417 break;
418 default:
419 address = AR6003_RESET_CONTROL_ADDRESS;
420 break;
421 }
422
Kalle Valoaddb44b2011-09-02 10:32:05 +0300423 status = ath6kl_diag_write32(ar, address, data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300424
425 if (status)
426 ath6kl_err("failed to reset target\n");
427}
428
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530429static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300430{
431 u8 index;
432 u8 keyusage;
433
434 for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530435 if (vif->wep_key_list[index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300436 keyusage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530437 if (index == vif->def_txkey_index)
Kalle Valobdcd8172011-07-18 00:22:30 +0300438 keyusage |= TX_USAGE;
439
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530440 ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300441 index,
442 WEP_CRYPT,
443 keyusage,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530444 vif->wep_key_list[index].key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200445 NULL, 0,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530446 vif->wep_key_list[index].key,
Kalle Valobdcd8172011-07-18 00:22:30 +0300447 KEY_OP_INIT_VAL, NULL,
448 NO_SYNC_WMIFLAG);
449 }
450 }
451}
452
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530453void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +0300454{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530455 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300456 struct ath6kl_req_key *ik;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300457 int res;
458 u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
Kalle Valobdcd8172011-07-18 00:22:30 +0300459
Jouni Malinen572e27c2011-09-05 17:38:45 +0300460 ik = &ar->ap_mode_bkey;
Kalle Valobdcd8172011-07-18 00:22:30 +0300461
Jouni Malinen572e27c2011-09-05 17:38:45 +0300462 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300463
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530464 switch (vif->auth_mode) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300465 case NONE_AUTH:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530466 if (vif->prwise_crypto == WEP_CRYPT)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530467 ath6kl_install_static_wep_keys(vif);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300468 break;
469 case WPA_PSK_AUTH:
470 case WPA2_PSK_AUTH:
471 case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
472 if (!ik->valid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300473 break;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300474
Jouni Malinen572e27c2011-09-05 17:38:45 +0300475 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
476 "the initial group key for AP mode\n");
477 memset(key_rsc, 0, sizeof(key_rsc));
478 res = ath6kl_wmi_addkey_cmd(
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530479 ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +0200480 GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
481 ik->key,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300482 KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
483 if (res) {
484 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
485 "addkey failed: %d\n", res);
Kalle Valobdcd8172011-07-18 00:22:30 +0300486 }
Jouni Malinen572e27c2011-09-05 17:38:45 +0300487 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300488 }
489
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530490 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530491 set_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530492 netif_carrier_on(vif->ndev);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300493}
494
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530495void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300496 u8 keymgmt, u8 ucipher, u8 auth,
497 u8 assoc_req_len, u8 *assoc_info)
498{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530499 struct ath6kl *ar = vif->ar;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300500 u8 *ies = NULL, *wpa_ie = NULL, *pos;
501 size_t ies_len = 0;
502 struct station_info sinfo;
503
504 ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300505
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300506 if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
507 struct ieee80211_mgmt *mgmt =
508 (struct ieee80211_mgmt *) assoc_info;
509 if (ieee80211_is_assoc_req(mgmt->frame_control) &&
510 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
511 sizeof(mgmt->u.assoc_req)) {
512 ies = mgmt->u.assoc_req.variable;
513 ies_len = assoc_info + assoc_req_len - ies;
514 } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
515 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
516 + sizeof(mgmt->u.reassoc_req)) {
517 ies = mgmt->u.reassoc_req.variable;
518 ies_len = assoc_info + assoc_req_len - ies;
519 }
520 }
521
522 pos = ies;
523 while (pos && pos + 1 < ies + ies_len) {
524 if (pos + 2 + pos[1] > ies + ies_len)
525 break;
526 if (pos[0] == WLAN_EID_RSN)
527 wpa_ie = pos; /* RSN IE */
528 else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
529 pos[1] >= 4 &&
530 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
531 if (pos[5] == 0x01)
532 wpa_ie = pos; /* WPA IE */
533 else if (pos[5] == 0x04) {
534 wpa_ie = pos; /* WPS IE */
535 break; /* overrides WPA/RSN IE */
536 }
Dai Shuibing30677ae2011-11-03 11:39:39 +0200537 } else if (pos[0] == 0x44 && wpa_ie == NULL) {
538 /*
539 * Note: WAPI Parameter Set IE re-uses Element ID that
540 * was officially allocated for BSS AC Access Delay. As
541 * such, we need to be a bit more careful on when
542 * parsing the frame. However, BSS AC Access Delay
543 * element is not supposed to be included in
544 * (Re)Association Request frames, so this should not
545 * cause problems.
546 */
547 wpa_ie = pos; /* WAPI IE */
548 break;
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300549 }
550 pos += 2 + pos[1];
551 }
552
Jouni Malinen572e27c2011-09-05 17:38:45 +0300553 ath6kl_add_new_sta(ar, mac_addr, aid, wpa_ie,
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300554 wpa_ie ? 2 + wpa_ie[1] : 0,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300555 keymgmt, ucipher, auth);
Kalle Valobdcd8172011-07-18 00:22:30 +0300556
557 /* send event to application */
558 memset(&sinfo, 0, sizeof(sinfo));
559
560 /* TODO: sinfo.generation */
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300561
562 sinfo.assoc_req_ies = ies;
563 sinfo.assoc_req_ies_len = ies_len;
564 sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
565
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530566 cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300567
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530568 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300569}
570
Kalle Valobdcd8172011-07-18 00:22:30 +0300571void disconnect_timer_handler(unsigned long ptr)
572{
573 struct net_device *dev = (struct net_device *)ptr;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530574 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300575
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530576 ath6kl_init_profile_info(vif);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530577 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300578}
579
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530580void ath6kl_disconnect(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300581{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530582 if (test_bit(CONNECTED, &vif->flags) ||
583 test_bit(CONNECT_PEND, &vif->flags)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530584 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300585 /*
586 * Disconnect command is issued, clear the connect pending
587 * flag. The connected flag will be cleared in
588 * disconnect event notification.
589 */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530590 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300591 }
592}
593
594/* WMI Event handlers */
595
596static const char *get_hw_id_string(u32 id)
597{
598 switch (id) {
599 case AR6003_REV1_VERSION:
600 return "1.0";
601 case AR6003_REV2_VERSION:
602 return "2.0";
603 case AR6003_REV3_VERSION:
604 return "2.1.1";
605 default:
606 return "unknown";
607 }
608}
609
610void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
611{
612 struct ath6kl *ar = devt;
Kalle Valobdcd8172011-07-18 00:22:30 +0300613
Vasanthakumar Thiagarajand66ea4f2011-10-25 19:34:18 +0530614 memcpy(ar->mac_addr, datap, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +0300615 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
Vasanthakumar Thiagarajand66ea4f2011-10-25 19:34:18 +0530616 __func__, ar->mac_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +0300617
618 ar->version.wlan_ver = sw_ver;
619 ar->version.abi_ver = abi_ver;
620
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530621 snprintf(ar->wiphy->fw_version,
622 sizeof(ar->wiphy->fw_version),
Kalle Valobdcd8172011-07-18 00:22:30 +0300623 "%u.%u.%u.%u",
624 (ar->version.wlan_ver & 0xf0000000) >> 28,
625 (ar->version.wlan_ver & 0x0f000000) >> 24,
626 (ar->version.wlan_ver & 0x00ff0000) >> 16,
627 (ar->version.wlan_ver & 0x0000ffff));
628
629 /* indicate to the waiting thread that the ready event was received */
630 set_bit(WMI_READY, &ar->flag);
631 wake_up(&ar->event_wq);
632
Kalle Valo5fe4dff2011-10-30 21:16:15 +0200633 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
634 ath6kl_info("hw %s fw %s%s\n",
635 get_hw_id_string(ar->wiphy->hw_version),
636 ar->wiphy->fw_version,
637 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
638 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300639}
640
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530641void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
Kalle Valobdcd8172011-07-18 00:22:30 +0300642{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530643 struct ath6kl *ar = vif->ar;
Kalle Valo1c17d312011-11-01 08:43:56 +0200644 bool aborted = false;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530645
Kalle Valo1c17d312011-11-01 08:43:56 +0200646 if (status != WMI_SCAN_STATUS_SUCCESS)
647 aborted = true;
648
649 ath6kl_cfg80211_scan_complete_event(vif, aborted);
Kalle Valobdcd8172011-07-18 00:22:30 +0300650
Jouni Malinen551185c2011-09-19 19:15:06 +0300651 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530652 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530653 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
654 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +0300655 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300656
Kalle Valod23ace72011-10-24 12:17:51 +0300657 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
Kalle Valobdcd8172011-07-18 00:22:30 +0300658}
659
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530660void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300661 u16 listen_int, u16 beacon_int,
662 enum network_type net_type, u8 beacon_ie_len,
663 u8 assoc_req_len, u8 assoc_resp_len,
664 u8 *assoc_info)
665{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530666 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530667
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530668 ath6kl_cfg80211_connect_event(vif, channel, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300669 listen_int, beacon_int,
670 net_type, beacon_ie_len,
671 assoc_req_len, assoc_resp_len,
672 assoc_info);
673
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530674 memcpy(vif->bssid, bssid, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530675 vif->bss_ch = channel;
Kalle Valobdcd8172011-07-18 00:22:30 +0300676
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530677 if ((vif->nw_type == INFRA_NETWORK))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530678 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
679 ar->listen_intvl_t,
Kalle Valobdcd8172011-07-18 00:22:30 +0300680 ar->listen_intvl_b);
681
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530682 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300683
684 /* Update connect & link status atomically */
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530685 spin_lock_bh(&vif->if_lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530686 set_bit(CONNECTED, &vif->flags);
687 clear_bit(CONNECT_PEND, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530688 netif_carrier_on(vif->ndev);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +0530689 spin_unlock_bh(&vif->if_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +0300690
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +0530691 aggr_reset_state(vif->aggr_cntxt);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530692 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300693
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530694 if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300695 memset(ar->node_map, 0, sizeof(ar->node_map));
696 ar->node_num = 0;
697 ar->next_ep_id = ENDPOINT_2;
698 }
699
Jouni Malinen551185c2011-09-19 19:15:06 +0300700 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530701 set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530702 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
703 CURRENT_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +0300704 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300705}
706
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530707void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
Kalle Valobdcd8172011-07-18 00:22:30 +0300708{
709 struct ath6kl_sta *sta;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530710 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300711 u8 tsc[6];
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530712
Kalle Valobdcd8172011-07-18 00:22:30 +0300713 /*
714 * For AP case, keyid will have aid of STA which sent pkt with
715 * MIC error. Use this aid to get MAC & send it to hostapd.
716 */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530717 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300718 sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
719 if (!sta)
720 return;
721
722 ath6kl_dbg(ATH6KL_DBG_TRC,
723 "ap tkip mic error received from aid=%d\n", keyid);
724
725 memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530726 cfg80211_michael_mic_failure(vif->ndev, sta->mac,
Kalle Valobdcd8172011-07-18 00:22:30 +0300727 NL80211_KEYTYPE_PAIRWISE, keyid,
728 tsc, GFP_KERNEL);
729 } else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530730 ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
Kalle Valobdcd8172011-07-18 00:22:30 +0300731
732}
733
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530734static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +0300735{
736 struct wmi_target_stats *tgt_stats =
737 (struct wmi_target_stats *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530738 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530739 struct target_stats *stats = &vif->target_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +0300740 struct tkip_ccmp_stats *ccmp_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +0300741 u8 ac;
742
743 if (len < sizeof(*tgt_stats))
744 return;
745
Kalle Valobdcd8172011-07-18 00:22:30 +0300746 ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
747
748 stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
749 stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
750 stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
751 stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
752 stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
753 stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
754 stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
755 stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
756 stats->tx_rts_success_cnt +=
757 le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
758
759 for (ac = 0; ac < WMM_NUM_AC; ac++)
760 stats->tx_pkt_per_ac[ac] +=
761 le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
762
763 stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
764 stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
765 stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
766 stats->tx_mult_retry_cnt +=
767 le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
768 stats->tx_rts_fail_cnt +=
769 le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
770 stats->tx_ucast_rate =
771 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
772
773 stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
774 stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
775 stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
776 stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
777 stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
778 stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
779 stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
780 stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
781 stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
782 stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
783 stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
784 stats->rx_key_cache_miss +=
785 le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
786 stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
787 stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
788 stats->rx_ucast_rate =
789 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
790
791 ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
792
793 stats->tkip_local_mic_fail +=
794 le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
795 stats->tkip_cnter_measures_invoked +=
796 le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
797 stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
798
799 stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
800 stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
801
802 stats->pwr_save_fail_cnt +=
803 le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
804 stats->noise_floor_calib =
805 a_sle32_to_cpu(tgt_stats->noise_floor_calib);
806
807 stats->cs_bmiss_cnt +=
808 le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
809 stats->cs_low_rssi_cnt +=
810 le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
811 stats->cs_connect_cnt +=
812 le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
813 stats->cs_discon_cnt +=
814 le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
815
816 stats->cs_ave_beacon_rssi =
817 a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
818
819 stats->cs_last_roam_msec =
820 tgt_stats->cserv_stats.cs_last_roam_msec;
821 stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
822 stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
823
824 stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
825
826 stats->wow_pkt_dropped +=
827 le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
828 stats->wow_host_pkt_wakeups +=
829 tgt_stats->wow_stats.wow_host_pkt_wakeups;
830 stats->wow_host_evt_wakeups +=
831 tgt_stats->wow_stats.wow_host_evt_wakeups;
832 stats->wow_evt_discarded +=
833 le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
834
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +0530835 if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
836 clear_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300837 wake_up(&ar->event_wq);
838 }
839}
840
841static void ath6kl_add_le32(__le32 *var, __le32 val)
842{
843 *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
844}
845
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530846void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +0300847{
848 struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530849 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300850 struct wmi_ap_mode_stat *ap = &ar->ap_stats;
851 struct wmi_per_sta_stat *st_ap, *st_p;
852 u8 ac;
853
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530854 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300855 if (len < sizeof(*p))
856 return;
857
858 for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
859 st_ap = &ap->sta[ac];
860 st_p = &p->sta[ac];
861
862 ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
863 ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
864 ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
865 ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
866 ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
867 ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
868 ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
869 ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
870 }
871
872 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530873 ath6kl_update_target_stats(vif, ptr, len);
Kalle Valobdcd8172011-07-18 00:22:30 +0300874 }
875}
876
877void ath6kl_wakeup_event(void *dev)
878{
879 struct ath6kl *ar = (struct ath6kl *) dev;
880
881 wake_up(&ar->event_wq);
882}
883
884void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
885{
886 struct ath6kl *ar = (struct ath6kl *) devt;
887
888 ar->tx_pwr = tx_pwr;
889 wake_up(&ar->event_wq);
890}
891
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530892void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300893{
894 struct ath6kl_sta *conn;
895 struct sk_buff *skb;
896 bool psq_empty = false;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530897 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300898
899 conn = ath6kl_find_sta_by_aid(ar, aid);
900
901 if (!conn)
902 return;
903 /*
904 * Send out a packet queued on ps queue. When the ps queue
905 * becomes empty update the PVB for this station.
906 */
907 spin_lock_bh(&conn->psq_lock);
908 psq_empty = skb_queue_empty(&conn->psq);
909 spin_unlock_bh(&conn->psq_lock);
910
911 if (psq_empty)
912 /* TODO: Send out a NULL data frame */
913 return;
914
915 spin_lock_bh(&conn->psq_lock);
916 skb = skb_dequeue(&conn->psq);
917 spin_unlock_bh(&conn->psq_lock);
918
919 conn->sta_flags |= STA_PS_POLLED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530920 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300921 conn->sta_flags &= ~STA_PS_POLLED;
922
923 spin_lock_bh(&conn->psq_lock);
924 psq_empty = skb_queue_empty(&conn->psq);
925 spin_unlock_bh(&conn->psq_lock);
926
927 if (psq_empty)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530928 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300929}
930
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530931void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300932{
933 bool mcastq_empty = false;
934 struct sk_buff *skb;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530935 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300936
937 /*
938 * If there are no associated STAs, ignore the DTIM expiry event.
939 * There can be potential race conditions where the last associated
940 * STA may disconnect & before the host could clear the 'Indicate
941 * DTIM' request to the firmware, the firmware would have just
942 * indicated a DTIM expiry event. The race is between 'clear DTIM
943 * expiry cmd' going from the host to the firmware & the DTIM
944 * expiry event happening from the firmware to the host.
945 */
946 if (!ar->sta_list_index)
947 return;
948
949 spin_lock_bh(&ar->mcastpsq_lock);
950 mcastq_empty = skb_queue_empty(&ar->mcastpsq);
951 spin_unlock_bh(&ar->mcastpsq_lock);
952
953 if (mcastq_empty)
954 return;
955
956 /* set the STA flag to dtim_expired for the frame to go out */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530957 set_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300958
959 spin_lock_bh(&ar->mcastpsq_lock);
960 while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
961 spin_unlock_bh(&ar->mcastpsq_lock);
962
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530963 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300964
965 spin_lock_bh(&ar->mcastpsq_lock);
966 }
967 spin_unlock_bh(&ar->mcastpsq_lock);
968
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530969 clear_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300970
971 /* clear the LSB of the BitMapCtl field of the TIM IE */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530972 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300973}
974
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530975void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300976 u8 assoc_resp_len, u8 *assoc_info,
977 u16 prot_reason_status)
978{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530979 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530980
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530981 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300982 if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
983 return;
984
985 /* if no more associated STAs, empty the mcast PS q */
986 if (ar->sta_list_index == 0) {
987 spin_lock_bh(&ar->mcastpsq_lock);
988 skb_queue_purge(&ar->mcastpsq);
989 spin_unlock_bh(&ar->mcastpsq_lock);
990
991 /* clear the LSB of the TIM IE's BitMapCtl field */
992 if (test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530993 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
994 MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300995 }
996
997 if (!is_broadcast_ether_addr(bssid)) {
998 /* send event to application */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530999 cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +03001000 }
1001
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301002 if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301003 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301004 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen151411e2011-09-15 15:10:16 +03001005 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001006 return;
1007 }
1008
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301009 ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001010 assoc_resp_len, assoc_info,
1011 prot_reason_status);
1012
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301013 aggr_reset_state(vif->aggr_cntxt);
Kalle Valobdcd8172011-07-18 00:22:30 +03001014
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301015 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001016
Kalle Valod23ace72011-10-24 12:17:51 +03001017 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
Kalle Valobdcd8172011-07-18 00:22:30 +03001018
1019 /*
1020 * If the event is due to disconnect cmd from the host, only they
1021 * the target would stop trying to connect. Under any other
1022 * condition, target would keep trying to connect.
1023 */
1024 if (reason == DISCONNECT_CMD) {
1025 if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301026 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1027 NONE_BSS_FILTER, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001028 } else {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301029 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001030 if (((reason == ASSOC_FAILED) &&
1031 (prot_reason_status == 0x11)) ||
1032 ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301033 && (vif->reconnect_flag == 1))) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301034 set_bit(CONNECTED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001035 return;
1036 }
1037 }
1038
Kalle Valobdcd8172011-07-18 00:22:30 +03001039 /* update connect & link status atomically */
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05301040 spin_lock_bh(&vif->if_lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301041 clear_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301042 netif_carrier_off(vif->ndev);
Vasanthakumar Thiagarajan478ac022011-10-25 19:34:19 +05301043 spin_unlock_bh(&vif->if_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001044
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301045 if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
1046 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001047
1048 if (reason != CSERV_DISCONNECT)
1049 ar->user_key_ctrl = 0;
1050
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301051 netif_stop_queue(vif->ndev);
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301052 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301053 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001054
1055 ath6kl_tx_data_cleanup(ar);
1056}
1057
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301058struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
1059{
1060 struct ath6kl_vif *vif;
1061
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301062 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301063 if (list_empty(&ar->vif_list)) {
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301064 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301065 return NULL;
1066 }
1067
1068 vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
1069
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301070 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301071
1072 return vif;
1073}
1074
Kalle Valobdcd8172011-07-18 00:22:30 +03001075static int ath6kl_open(struct net_device *dev)
1076{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301077 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001078
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301079 set_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001080
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301081 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001082 netif_carrier_on(dev);
1083 netif_wake_queue(dev);
1084 } else
1085 netif_carrier_off(dev);
1086
Kalle Valobdcd8172011-07-18 00:22:30 +03001087 return 0;
1088}
1089
1090static int ath6kl_close(struct net_device *dev)
1091{
1092 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301093 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001094
1095 netif_stop_queue(dev);
1096
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301097 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03001098
1099 if (test_bit(WMI_READY, &ar->flag)) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301100 if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF,
1101 0, 0, 0, 0, 0, 0, 0, 0, 0))
Kalle Valobdcd8172011-07-18 00:22:30 +03001102 return -EIO;
1103
Kalle Valobdcd8172011-07-18 00:22:30 +03001104 }
1105
Kalle Valo1c17d312011-11-01 08:43:56 +02001106 ath6kl_cfg80211_scan_complete_event(vif, true);
Kalle Valobdcd8172011-07-18 00:22:30 +03001107
Kalle Valo68469342011-10-30 21:16:33 +02001108 clear_bit(WLAN_ENABLED, &vif->flags);
1109
Kalle Valobdcd8172011-07-18 00:22:30 +03001110 return 0;
1111}
1112
1113static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
1114{
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301115 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001116
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301117 return &vif->net_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001118}
1119
1120static struct net_device_ops ath6kl_netdev_ops = {
1121 .ndo_open = ath6kl_open,
1122 .ndo_stop = ath6kl_close,
1123 .ndo_start_xmit = ath6kl_data_tx,
1124 .ndo_get_stats = ath6kl_get_stats,
1125};
1126
1127void init_netdev(struct net_device *dev)
1128{
1129 dev->netdev_ops = &ath6kl_netdev_ops;
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301130 dev->destructor = free_netdev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001131 dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
1132
1133 dev->needed_headroom = ETH_HLEN;
1134 dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
1135 sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +05301136 + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +03001137
1138 return;
1139}