blob: 19b64ae08e12db04c13c8f71568d86b48b2ae98b [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
23struct ath6kl_sta *ath6kl_find_sta(struct ath6kl *ar, u8 *node_addr)
24{
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +053025 /* TODO: Findout vif */
26 struct ath6kl_vif *vif = ar->vif;
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
56static void ath6kl_add_new_sta(struct ath6kl *ar, u8 *mac, u16 aid, u8 *wpaie,
57 u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
58{
59 struct ath6kl_sta *sta;
60 u8 free_slot;
61
62 free_slot = aid - 1;
63
64 sta = &ar->sta_list[free_slot];
65 memcpy(sta->mac, mac, ETH_ALEN);
Jouni Malinen3c774bb2011-08-30 21:57:51 +030066 if (ielen <= ATH6KL_MAX_IE)
67 memcpy(sta->wpa_ie, wpaie, ielen);
Kalle Valobdcd8172011-07-18 00:22:30 +030068 sta->aid = aid;
69 sta->keymgmt = keymgmt;
70 sta->ucipher = ucipher;
71 sta->auth = auth;
72
73 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
74 ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
75}
76
77static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
78{
79 struct ath6kl_sta *sta = &ar->sta_list[i];
80
81 /* empty the queued pkts in the PS queue if any */
82 spin_lock_bh(&sta->psq_lock);
83 skb_queue_purge(&sta->psq);
84 spin_unlock_bh(&sta->psq_lock);
85
86 memset(&ar->ap_stats.sta[sta->aid - 1], 0,
87 sizeof(struct wmi_per_sta_stat));
88 memset(sta->mac, 0, ETH_ALEN);
89 memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
90 sta->aid = 0;
91 sta->sta_flags = 0;
92
93 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
94
95}
96
97static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
98{
99 u8 i, removed = 0;
100
101 if (is_zero_ether_addr(mac))
102 return removed;
103
104 if (is_broadcast_ether_addr(mac)) {
105 ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
106
107 for (i = 0; i < AP_MAX_NUM_STA; i++) {
108 if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
109 ath6kl_sta_cleanup(ar, i);
110 removed = 1;
111 }
112 }
113 } else {
114 for (i = 0; i < AP_MAX_NUM_STA; i++) {
115 if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
116 ath6kl_dbg(ATH6KL_DBG_TRC,
117 "deleting station %pM aid=%d reason=%d\n",
118 mac, ar->sta_list[i].aid, reason);
119 ath6kl_sta_cleanup(ar, i);
120 removed = 1;
121 break;
122 }
123 }
124 }
125
126 return removed;
127}
128
129enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
130{
131 struct ath6kl *ar = devt;
132 return ar->ac2ep_map[ac];
133}
134
135struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
136{
137 struct ath6kl_cookie *cookie;
138
139 cookie = ar->cookie_list;
140 if (cookie != NULL) {
141 ar->cookie_list = cookie->arc_list_next;
142 ar->cookie_count--;
143 }
144
145 return cookie;
146}
147
148void ath6kl_cookie_init(struct ath6kl *ar)
149{
150 u32 i;
151
152 ar->cookie_list = NULL;
153 ar->cookie_count = 0;
154
155 memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
156
157 for (i = 0; i < MAX_COOKIE_NUM; i++)
158 ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
159}
160
161void ath6kl_cookie_cleanup(struct ath6kl *ar)
162{
163 ar->cookie_list = NULL;
164 ar->cookie_count = 0;
165}
166
167void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
168{
169 /* Insert first */
170
171 if (!ar || !cookie)
172 return;
173
174 cookie->arc_list_next = ar->cookie_list;
175 ar->cookie_list = cookie;
176 ar->cookie_count++;
177}
178
179/* set the window address register (using 4-byte register access ). */
180static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr)
181{
182 int status;
Kalle Valobdcd8172011-07-18 00:22:30 +0300183 s32 i;
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530184 __le32 addr_val;
Kalle Valobdcd8172011-07-18 00:22:30 +0300185
186 /*
187 * Write bytes 1,2,3 of the register to set the upper address bytes,
188 * the LSB is written last to initiate the access cycle
189 */
190
191 for (i = 1; i <= 3; i++) {
192 /*
193 * Fill the buffer with the address byte value we want to
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530194 * hit 4 times. No need to worry about endianness as the
195 * same byte is copied to all four bytes of addr_val at
196 * any time.
Kalle Valobdcd8172011-07-18 00:22:30 +0300197 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530198 memset((u8 *)&addr_val, ((u8 *)&addr)[i], 4);
Kalle Valobdcd8172011-07-18 00:22:30 +0300199
200 /*
201 * Hit each byte of the register address with a 4-byte
202 * write operation to the same address, this is a harmless
203 * operation.
204 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530205 status = hif_read_write_sync(ar, reg_addr + i, (u8 *)&addr_val,
Kalle Valobdcd8172011-07-18 00:22:30 +0300206 4, HIF_WR_SYNC_BYTE_FIX);
207 if (status)
208 break;
209 }
210
211 if (status) {
212 ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n",
213 addr, reg_addr);
214 return status;
215 }
216
217 /*
218 * Write the address register again, this time write the whole
219 * 4-byte value. The effect here is that the LSB write causes the
220 * cycle to start, the extra 3 byte write to bytes 1,2,3 has no
221 * effect since we are writing the same values again
222 */
Vasanthakumar Thiagarajanb142b912011-08-31 15:48:15 +0530223 addr_val = cpu_to_le32(addr);
224 status = hif_read_write_sync(ar, reg_addr,
225 (u8 *)&(addr_val),
Kalle Valobdcd8172011-07-18 00:22:30 +0300226 4, HIF_WR_SYNC_BYTE_INC);
227
228 if (status) {
229 ath6kl_err("failed to write 0x%x to window reg: 0x%X\n",
230 addr, reg_addr);
231 return status;
232 }
233
234 return 0;
235}
236
237/*
Kalle Valoaddb44b2011-09-02 10:32:05 +0300238 * Read from the hardware through its diagnostic window. No cooperation
239 * from the firmware is required for this.
Kalle Valobdcd8172011-07-18 00:22:30 +0300240 */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300241int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300242{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300243 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300244
245 /* set window register to start read cycle */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300246 ret = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, address);
247 if (ret)
248 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300249
250 /* read the data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300251 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) value,
252 sizeof(*value), HIF_RD_SYNC_BYTE_INC);
253 if (ret) {
254 ath6kl_warn("failed to read32 through diagnose window: %d\n",
255 ret);
256 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300257 }
258
Kalle Valoaddb44b2011-09-02 10:32:05 +0300259 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300260}
261
Kalle Valobdcd8172011-07-18 00:22:30 +0300262/*
263 * Write to the ATH6KL through its diagnostic window. No cooperation from
264 * the Target is required for this.
265 */
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300266int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
Kalle Valobdcd8172011-07-18 00:22:30 +0300267{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300268 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300269
270 /* set write data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300271 ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) &value,
272 sizeof(value), HIF_WR_SYNC_BYTE_INC);
273 if (ret) {
274 ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
275 address, value);
276 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300277 }
278
279 /* set window register, which starts the write cycle */
280 return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS,
Kalle Valoaddb44b2011-09-02 10:32:05 +0300281 address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300282}
283
Kalle Valoaddb44b2011-09-02 10:32:05 +0300284int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
Kalle Valobdcd8172011-07-18 00:22:30 +0300285{
Kalle Valoaddb44b2011-09-02 10:32:05 +0300286 u32 count, *buf = data;
287 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300288
Kalle Valoaddb44b2011-09-02 10:32:05 +0300289 if (WARN_ON(length % 4))
290 return -EINVAL;
291
292 for (count = 0; count < length / 4; count++, address += 4) {
293 ret = ath6kl_diag_read32(ar, address, &buf[count]);
294 if (ret)
295 return ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300296 }
297
Kalle Valoaddb44b2011-09-02 10:32:05 +0300298 return 0;
299}
300
301int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
302{
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300303 u32 count;
304 __le32 *buf = data;
Kalle Valoaddb44b2011-09-02 10:32:05 +0300305 int ret;
306
307 if (WARN_ON(length % 4))
308 return -EINVAL;
309
310 for (count = 0; count < length / 4; count++, address += 4) {
311 ret = ath6kl_diag_write32(ar, address, buf[count]);
312 if (ret)
313 return ret;
314 }
315
316 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300317}
318
Kalle Valobc07ddb2011-09-02 10:32:05 +0300319int ath6kl_read_fwlogs(struct ath6kl *ar)
320{
321 struct ath6kl_dbglog_hdr debug_hdr;
322 struct ath6kl_dbglog_buf debug_buf;
323 u32 address, length, dropped, firstbuf, debug_hdr_addr;
324 int ret = 0, loop;
325 u8 *buf;
326
327 buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
328 if (!buf)
329 return -ENOMEM;
330
331 address = TARG_VTOP(ar->target_type,
332 ath6kl_get_hi_item_addr(ar,
333 HI_ITEM(hi_dbglog_hdr)));
334
335 ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
336 if (ret)
337 goto out;
338
339 /* Get the contents of the ring buffer */
340 if (debug_hdr_addr == 0) {
341 ath6kl_warn("Invalid address for debug_hdr_addr\n");
342 ret = -EINVAL;
343 goto out;
344 }
345
346 address = TARG_VTOP(ar->target_type, debug_hdr_addr);
347 ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
348
349 address = TARG_VTOP(ar->target_type,
350 le32_to_cpu(debug_hdr.dbuf_addr));
351 firstbuf = address;
352 dropped = le32_to_cpu(debug_hdr.dropped);
353 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
354
355 loop = 100;
356
357 do {
358 address = TARG_VTOP(ar->target_type,
359 le32_to_cpu(debug_buf.buffer_addr));
360 length = le32_to_cpu(debug_buf.length);
361
362 if (length != 0 && (le32_to_cpu(debug_buf.length) <=
363 le32_to_cpu(debug_buf.bufsize))) {
364 length = ALIGN(length, 4);
365
366 ret = ath6kl_diag_read(ar, address,
367 buf, length);
368 if (ret)
369 goto out;
370
371 ath6kl_debug_fwlog_event(ar, buf, length);
372 }
373
374 address = TARG_VTOP(ar->target_type,
375 le32_to_cpu(debug_buf.next));
376 ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
377 if (ret)
378 goto out;
379
380 loop--;
381
382 if (WARN_ON(loop == 0)) {
383 ret = -ETIMEDOUT;
384 goto out;
385 }
386 } while (address != firstbuf);
387
388out:
389 kfree(buf);
390
391 return ret;
392}
393
Kevin Fang31024d92011-07-11 17:14:13 +0800394/* FIXME: move to a better place, target.h? */
395#define AR6003_RESET_CONTROL_ADDRESS 0x00004000
396#define AR6004_RESET_CONTROL_ADDRESS 0x00004000
397
Kalle Valobdcd8172011-07-18 00:22:30 +0300398static void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
399 bool wait_fot_compltn, bool cold_reset)
400{
401 int status = 0;
402 u32 address;
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300403 __le32 data;
Kalle Valobdcd8172011-07-18 00:22:30 +0300404
Kevin Fang31024d92011-07-11 17:14:13 +0800405 if (target_type != TARGET_TYPE_AR6003 &&
406 target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +0300407 return;
408
Vasanthakumar Thiagarajanf9ea0752011-09-05 11:19:46 +0300409 data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) :
410 cpu_to_le32(RESET_CONTROL_MBOX_RST);
Kalle Valobdcd8172011-07-18 00:22:30 +0300411
Kevin Fang31024d92011-07-11 17:14:13 +0800412 switch (target_type) {
413 case TARGET_TYPE_AR6003:
414 address = AR6003_RESET_CONTROL_ADDRESS;
415 break;
416 case TARGET_TYPE_AR6004:
417 address = AR6004_RESET_CONTROL_ADDRESS;
418 break;
419 default:
420 address = AR6003_RESET_CONTROL_ADDRESS;
421 break;
422 }
423
Kalle Valoaddb44b2011-09-02 10:32:05 +0300424 status = ath6kl_diag_write32(ar, address, data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300425
426 if (status)
427 ath6kl_err("failed to reset target\n");
428}
429
430void ath6kl_stop_endpoint(struct net_device *dev, bool keep_profile,
431 bool get_dbglogs)
432{
433 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530434 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300435 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
436 bool discon_issued;
437
438 netif_stop_queue(dev);
439
440 /* disable the target and the interrupts associated with it */
441 if (test_bit(WMI_READY, &ar->flag)) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530442 discon_issued = (test_bit(CONNECTED, &vif->flags) ||
443 test_bit(CONNECT_PEND, &vif->flags));
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530444 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300445 if (!keep_profile)
446 ath6kl_init_profile_info(ar);
447
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +0530448 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +0300449
450 clear_bit(WMI_READY, &ar->flag);
451 ath6kl_wmi_shutdown(ar->wmi);
452 clear_bit(WMI_ENABLED, &ar->flag);
453 ar->wmi = NULL;
454
455 /*
456 * After wmi_shudown all WMI events will be dropped. We
457 * need to cleanup the buffers allocated in AP mode and
458 * give disconnect notification to stack, which usually
459 * happens in the disconnect_event. Simulate the disconnect
460 * event by calling the function directly. Sometimes
461 * disconnect_event will be received when the debug logs
462 * are collected.
463 */
464 if (discon_issued)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530465 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530466 (vif->nw_type & AP_NETWORK) ?
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530467 bcast_mac : vif->bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +0300468 0, NULL, 0);
469
470 ar->user_key_ctrl = 0;
471
472 } else {
473 ath6kl_dbg(ATH6KL_DBG_TRC,
474 "%s: wmi is not ready 0x%p 0x%p\n",
475 __func__, ar, ar->wmi);
476
477 /* Shut down WMI if we have started it */
478 if (test_bit(WMI_ENABLED, &ar->flag)) {
479 ath6kl_dbg(ATH6KL_DBG_TRC,
480 "%s: shut down wmi\n", __func__);
481 ath6kl_wmi_shutdown(ar->wmi);
482 clear_bit(WMI_ENABLED, &ar->flag);
483 ar->wmi = NULL;
484 }
485 }
486
487 if (ar->htc_target) {
488 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
Kalle Vaload226ec2011-08-10 09:49:12 +0300489 ath6kl_htc_stop(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +0300490 }
491
492 /*
493 * Try to reset the device if we can. The driver may have been
494 * configure NOT to reset the target during a debug session.
495 */
496 ath6kl_dbg(ATH6KL_DBG_TRC,
497 "attempting to reset target on instance destroy\n");
498 ath6kl_reset_device(ar, ar->target_type, true, true);
499}
500
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530501static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300502{
503 u8 index;
504 u8 keyusage;
505
506 for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530507 if (vif->wep_key_list[index].key_len) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300508 keyusage = GROUP_USAGE;
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530509 if (index == vif->def_txkey_index)
Kalle Valobdcd8172011-07-18 00:22:30 +0300510 keyusage |= TX_USAGE;
511
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530512 ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300513 index,
514 WEP_CRYPT,
515 keyusage,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530516 vif->wep_key_list[index].key_len,
Kalle Valobdcd8172011-07-18 00:22:30 +0300517 NULL,
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530518 vif->wep_key_list[index].key,
Kalle Valobdcd8172011-07-18 00:22:30 +0300519 KEY_OP_INIT_VAL, NULL,
520 NO_SYNC_WMIFLAG);
521 }
522 }
523}
524
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530525void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +0300526{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530527 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +0300528 struct ath6kl_req_key *ik;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300529 int res;
530 u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
Kalle Valobdcd8172011-07-18 00:22:30 +0300531
Jouni Malinen572e27c2011-09-05 17:38:45 +0300532 ik = &ar->ap_mode_bkey;
Kalle Valobdcd8172011-07-18 00:22:30 +0300533
Jouni Malinen572e27c2011-09-05 17:38:45 +0300534 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300535
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530536 switch (vif->auth_mode) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300537 case NONE_AUTH:
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530538 if (vif->prwise_crypto == WEP_CRYPT)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530539 ath6kl_install_static_wep_keys(vif);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300540 break;
541 case WPA_PSK_AUTH:
542 case WPA2_PSK_AUTH:
543 case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
544 if (!ik->valid)
Kalle Valobdcd8172011-07-18 00:22:30 +0300545 break;
Jouni Malinen9a5b1312011-08-30 21:57:52 +0300546
Jouni Malinen572e27c2011-09-05 17:38:45 +0300547 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
548 "the initial group key for AP mode\n");
549 memset(key_rsc, 0, sizeof(key_rsc));
550 res = ath6kl_wmi_addkey_cmd(
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530551 ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300552 GROUP_USAGE, ik->key_len, key_rsc, ik->key,
553 KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
554 if (res) {
555 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
556 "addkey failed: %d\n", res);
Kalle Valobdcd8172011-07-18 00:22:30 +0300557 }
Jouni Malinen572e27c2011-09-05 17:38:45 +0300558 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300559 }
560
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530561 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530562 set_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530563 netif_carrier_on(vif->ndev);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300564}
565
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530566void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300567 u8 keymgmt, u8 ucipher, u8 auth,
568 u8 assoc_req_len, u8 *assoc_info)
569{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530570 struct ath6kl *ar = vif->ar;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300571 u8 *ies = NULL, *wpa_ie = NULL, *pos;
572 size_t ies_len = 0;
573 struct station_info sinfo;
574
575 ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300576
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300577 if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
578 struct ieee80211_mgmt *mgmt =
579 (struct ieee80211_mgmt *) assoc_info;
580 if (ieee80211_is_assoc_req(mgmt->frame_control) &&
581 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
582 sizeof(mgmt->u.assoc_req)) {
583 ies = mgmt->u.assoc_req.variable;
584 ies_len = assoc_info + assoc_req_len - ies;
585 } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
586 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
587 + sizeof(mgmt->u.reassoc_req)) {
588 ies = mgmt->u.reassoc_req.variable;
589 ies_len = assoc_info + assoc_req_len - ies;
590 }
591 }
592
593 pos = ies;
594 while (pos && pos + 1 < ies + ies_len) {
595 if (pos + 2 + pos[1] > ies + ies_len)
596 break;
597 if (pos[0] == WLAN_EID_RSN)
598 wpa_ie = pos; /* RSN IE */
599 else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
600 pos[1] >= 4 &&
601 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
602 if (pos[5] == 0x01)
603 wpa_ie = pos; /* WPA IE */
604 else if (pos[5] == 0x04) {
605 wpa_ie = pos; /* WPS IE */
606 break; /* overrides WPA/RSN IE */
607 }
608 }
609 pos += 2 + pos[1];
610 }
611
Jouni Malinen572e27c2011-09-05 17:38:45 +0300612 ath6kl_add_new_sta(ar, mac_addr, aid, wpa_ie,
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300613 wpa_ie ? 2 + wpa_ie[1] : 0,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300614 keymgmt, ucipher, auth);
Kalle Valobdcd8172011-07-18 00:22:30 +0300615
616 /* send event to application */
617 memset(&sinfo, 0, sizeof(sinfo));
618
619 /* TODO: sinfo.generation */
Jouni Malinen3c774bb2011-08-30 21:57:51 +0300620
621 sinfo.assoc_req_ies = ies;
622 sinfo.assoc_req_ies_len = ies_len;
623 sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
624
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530625 cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +0300626
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530627 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300628}
629
630/* Functions for Tx credit handling */
631void ath6k_credit_init(struct htc_credit_state_info *cred_info,
632 struct list_head *ep_list,
633 int tot_credits)
634{
635 struct htc_endpoint_credit_dist *cur_ep_dist;
636 int count;
637
638 cred_info->cur_free_credits = tot_credits;
639 cred_info->total_avail_credits = tot_credits;
640
641 list_for_each_entry(cur_ep_dist, ep_list, list) {
642 if (cur_ep_dist->endpoint == ENDPOINT_0)
643 continue;
644
645 cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg;
646
647 if (tot_credits > 4)
648 if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) ||
649 (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) {
650 ath6kl_deposit_credit_to_ep(cred_info,
651 cur_ep_dist,
652 cur_ep_dist->cred_min);
653 cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
654 }
655
656 if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) {
657 ath6kl_deposit_credit_to_ep(cred_info, cur_ep_dist,
658 cur_ep_dist->cred_min);
659 /*
660 * Control service is always marked active, it
661 * never goes inactive EVER.
662 */
663 cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
664 } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC)
665 /* this is the lowest priority data endpoint */
666 cred_info->lowestpri_ep_dist = cur_ep_dist->list;
667
668 /*
669 * Streams have to be created (explicit | implicit) for all
670 * kinds of traffic. BE endpoints are also inactive in the
671 * beginning. When BE traffic starts it creates implicit
672 * streams that redistributes credits.
673 *
674 * Note: all other endpoints have minimums set but are
675 * initially given NO credits. credits will be distributed
676 * as traffic activity demands
677 */
678 }
679
680 WARN_ON(cred_info->cur_free_credits <= 0);
681
682 list_for_each_entry(cur_ep_dist, ep_list, list) {
683 if (cur_ep_dist->endpoint == ENDPOINT_0)
684 continue;
685
686 if (cur_ep_dist->svc_id == WMI_CONTROL_SVC)
687 cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg;
688 else {
689 /*
690 * For the remaining data endpoints, we assume that
691 * each cred_per_msg are the same. We use a simple
692 * calculation here, we take the remaining credits
693 * and determine how many max messages this can
694 * cover and then set each endpoint's normal value
695 * equal to 3/4 this amount.
696 */
697 count = (cred_info->cur_free_credits /
698 cur_ep_dist->cred_per_msg)
699 * cur_ep_dist->cred_per_msg;
700 count = (count * 3) >> 2;
701 count = max(count, cur_ep_dist->cred_per_msg);
702 cur_ep_dist->cred_norm = count;
703
704 }
705 }
706}
707
708/* initialize and setup credit distribution */
709int ath6k_setup_credit_dist(void *htc_handle,
710 struct htc_credit_state_info *cred_info)
711{
712 u16 servicepriority[5];
713
714 memset(cred_info, 0, sizeof(struct htc_credit_state_info));
715
716 servicepriority[0] = WMI_CONTROL_SVC; /* highest */
717 servicepriority[1] = WMI_DATA_VO_SVC;
718 servicepriority[2] = WMI_DATA_VI_SVC;
719 servicepriority[3] = WMI_DATA_BE_SVC;
720 servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */
721
722 /* set priority list */
Kalle Vaload226ec2011-08-10 09:49:12 +0300723 ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5);
Kalle Valobdcd8172011-07-18 00:22:30 +0300724
725 return 0;
726}
727
728/* reduce an ep's credits back to a set limit */
729static void ath6k_reduce_credits(struct htc_credit_state_info *cred_info,
730 struct htc_endpoint_credit_dist *ep_dist,
731 int limit)
732{
733 int credits;
734
735 ep_dist->cred_assngd = limit;
736
737 if (ep_dist->credits <= limit)
738 return;
739
740 credits = ep_dist->credits - limit;
741 ep_dist->credits -= credits;
742 cred_info->cur_free_credits += credits;
743}
744
745static void ath6k_credit_update(struct htc_credit_state_info *cred_info,
746 struct list_head *epdist_list)
747{
748 struct htc_endpoint_credit_dist *cur_dist_list;
749
750 list_for_each_entry(cur_dist_list, epdist_list, list) {
751 if (cur_dist_list->endpoint == ENDPOINT_0)
752 continue;
753
754 if (cur_dist_list->cred_to_dist > 0) {
755 cur_dist_list->credits +=
756 cur_dist_list->cred_to_dist;
757 cur_dist_list->cred_to_dist = 0;
758 if (cur_dist_list->credits >
759 cur_dist_list->cred_assngd)
760 ath6k_reduce_credits(cred_info,
761 cur_dist_list,
762 cur_dist_list->cred_assngd);
763
764 if (cur_dist_list->credits >
765 cur_dist_list->cred_norm)
766 ath6k_reduce_credits(cred_info, cur_dist_list,
767 cur_dist_list->cred_norm);
768
769 if (!(cur_dist_list->dist_flags & HTC_EP_ACTIVE)) {
770 if (cur_dist_list->txq_depth == 0)
771 ath6k_reduce_credits(cred_info,
772 cur_dist_list, 0);
773 }
774 }
775 }
776}
777
778/*
779 * HTC has an endpoint that needs credits, ep_dist is the endpoint in
780 * question.
781 */
782void ath6k_seek_credits(struct htc_credit_state_info *cred_info,
783 struct htc_endpoint_credit_dist *ep_dist)
784{
785 struct htc_endpoint_credit_dist *curdist_list;
786 int credits = 0;
787 int need;
788
789 if (ep_dist->svc_id == WMI_CONTROL_SVC)
790 goto out;
791
792 if ((ep_dist->svc_id == WMI_DATA_VI_SVC) ||
793 (ep_dist->svc_id == WMI_DATA_VO_SVC))
794 if ((ep_dist->cred_assngd >= ep_dist->cred_norm))
795 goto out;
796
797 /*
798 * For all other services, we follow a simple algorithm of:
799 *
800 * 1. checking the free pool for credits
801 * 2. checking lower priority endpoints for credits to take
802 */
803
804 credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
805
806 if (credits >= ep_dist->seek_cred)
807 goto out;
808
809 /*
810 * We don't have enough in the free pool, try taking away from
811 * lower priority services The rule for taking away credits:
812 *
813 * 1. Only take from lower priority endpoints
814 * 2. Only take what is allocated above the minimum (never
815 * starve an endpoint completely)
816 * 3. Only take what you need.
817 */
818
819 list_for_each_entry_reverse(curdist_list,
820 &cred_info->lowestpri_ep_dist,
821 list) {
822 if (curdist_list == ep_dist)
823 break;
824
825 need = ep_dist->seek_cred - cred_info->cur_free_credits;
826
827 if ((curdist_list->cred_assngd - need) >=
828 curdist_list->cred_min) {
829 /*
830 * The current one has been allocated more than
831 * it's minimum and it has enough credits assigned
832 * above it's minimum to fulfill our need try to
833 * take away just enough to fulfill our need.
834 */
835 ath6k_reduce_credits(cred_info, curdist_list,
836 curdist_list->cred_assngd - need);
837
838 if (cred_info->cur_free_credits >=
839 ep_dist->seek_cred)
840 break;
841 }
842
843 if (curdist_list->endpoint == ENDPOINT_0)
844 break;
845 }
846
847 credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
848
849out:
850 /* did we find some credits? */
851 if (credits)
852 ath6kl_deposit_credit_to_ep(cred_info, ep_dist, credits);
853
854 ep_dist->seek_cred = 0;
855}
856
857/* redistribute credits based on activity change */
858static void ath6k_redistribute_credits(struct htc_credit_state_info *info,
859 struct list_head *ep_dist_list)
860{
861 struct htc_endpoint_credit_dist *curdist_list;
862
863 list_for_each_entry(curdist_list, ep_dist_list, list) {
864 if (curdist_list->endpoint == ENDPOINT_0)
865 continue;
866
867 if ((curdist_list->svc_id == WMI_DATA_BK_SVC) ||
868 (curdist_list->svc_id == WMI_DATA_BE_SVC))
869 curdist_list->dist_flags |= HTC_EP_ACTIVE;
870
871 if ((curdist_list->svc_id != WMI_CONTROL_SVC) &&
872 !(curdist_list->dist_flags & HTC_EP_ACTIVE)) {
873 if (curdist_list->txq_depth == 0)
874 ath6k_reduce_credits(info,
875 curdist_list, 0);
876 else
877 ath6k_reduce_credits(info,
878 curdist_list,
879 curdist_list->cred_min);
880 }
881 }
882}
883
884/*
885 *
886 * This function is invoked whenever endpoints require credit
887 * distributions. A lock is held while this function is invoked, this
888 * function shall NOT block. The ep_dist_list is a list of distribution
889 * structures in prioritized order as defined by the call to the
890 * htc_set_credit_dist() api.
891 */
892void ath6k_credit_distribute(struct htc_credit_state_info *cred_info,
893 struct list_head *ep_dist_list,
894 enum htc_credit_dist_reason reason)
895{
896 switch (reason) {
897 case HTC_CREDIT_DIST_SEND_COMPLETE:
898 ath6k_credit_update(cred_info, ep_dist_list);
899 break;
900 case HTC_CREDIT_DIST_ACTIVITY_CHANGE:
901 ath6k_redistribute_credits(cred_info, ep_dist_list);
902 break;
903 default:
904 break;
905 }
906
907 WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits);
908 WARN_ON(cred_info->cur_free_credits < 0);
909}
910
911void disconnect_timer_handler(unsigned long ptr)
912{
913 struct net_device *dev = (struct net_device *)ptr;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530914 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +0300915
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530916 ath6kl_init_profile_info(vif->ar);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530917 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +0300918}
919
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530920void ath6kl_disconnect(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300921{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530922 if (test_bit(CONNECTED, &vif->flags) ||
923 test_bit(CONNECT_PEND, &vif->flags)) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530924 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +0300925 /*
926 * Disconnect command is issued, clear the connect pending
927 * flag. The connected flag will be cleared in
928 * disconnect event notification.
929 */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530930 clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +0300931 }
932}
933
Kalle Valoabcb3442011-07-22 08:26:20 +0300934void ath6kl_deep_sleep_enable(struct ath6kl *ar)
935{
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530936 /* TODO: Pass vif instead of taking it from ar */
937 struct ath6kl_vif *vif = ar->vif;
938
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530939 switch (vif->sme_state) {
Kalle Valoabcb3442011-07-22 08:26:20 +0300940 case SME_CONNECTING:
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530941 cfg80211_connect_result(ar->net_dev, vif->bssid, NULL, 0,
Kalle Valoabcb3442011-07-22 08:26:20 +0300942 NULL, 0,
943 WLAN_STATUS_UNSPECIFIED_FAILURE,
944 GFP_KERNEL);
945 break;
946 case SME_CONNECTED:
947 default:
948 /*
949 * FIXME: oddly enough smeState is in DISCONNECTED during
950 * suspend, why? Need to send disconnected event in that
951 * state.
952 */
953 cfg80211_disconnected(ar->net_dev, 0, NULL, 0, GFP_KERNEL);
954 break;
955 }
956
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530957 if (test_bit(CONNECTED, &vif->flags) ||
958 test_bit(CONNECT_PEND, &vif->flags))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530959 ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valoabcb3442011-07-22 08:26:20 +0300960
Vasanthakumar Thiagarajan14ee6f62011-10-25 19:34:09 +0530961 vif->sme_state = SME_DISCONNECTED;
Kalle Valoabcb3442011-07-22 08:26:20 +0300962
963 /* disable scanning */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530964 if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF, 0, 0,
965 0, 0, 0, 0, 0, 0, 0) != 0)
Kalle Valoabcb3442011-07-22 08:26:20 +0300966 printk(KERN_WARNING "ath6kl: failed to disable scan "
967 "during suspend\n");
968
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530969 ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300970
971 /* save the current power mode before enabling power save */
972 ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
973
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530974 if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
Chilam Ngaa6cffc2011-10-05 10:12:52 +0300975 ath6kl_warn("ath6kl_deep_sleep_enable: "
976 "wmi_powermode_cmd failed\n");
Kalle Valoabcb3442011-07-22 08:26:20 +0300977}
978
Kalle Valobdcd8172011-07-18 00:22:30 +0300979/* WMI Event handlers */
980
981static const char *get_hw_id_string(u32 id)
982{
983 switch (id) {
984 case AR6003_REV1_VERSION:
985 return "1.0";
986 case AR6003_REV2_VERSION:
987 return "2.0";
988 case AR6003_REV3_VERSION:
989 return "2.1.1";
990 default:
991 return "unknown";
992 }
993}
994
995void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
996{
997 struct ath6kl *ar = devt;
998 struct net_device *dev = ar->net_dev;
999
1000 memcpy(dev->dev_addr, datap, ETH_ALEN);
1001 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
1002 __func__, dev->dev_addr);
1003
1004 ar->version.wlan_ver = sw_ver;
1005 ar->version.abi_ver = abi_ver;
1006
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301007 snprintf(ar->wiphy->fw_version,
1008 sizeof(ar->wiphy->fw_version),
Kalle Valobdcd8172011-07-18 00:22:30 +03001009 "%u.%u.%u.%u",
1010 (ar->version.wlan_ver & 0xf0000000) >> 28,
1011 (ar->version.wlan_ver & 0x0f000000) >> 24,
1012 (ar->version.wlan_ver & 0x00ff0000) >> 16,
1013 (ar->version.wlan_ver & 0x0000ffff));
1014
1015 /* indicate to the waiting thread that the ready event was received */
1016 set_bit(WMI_READY, &ar->flag);
1017 wake_up(&ar->event_wq);
1018
Kalle Valo003353b0d2011-09-01 10:14:21 +03001019 ath6kl_info("hw %s fw %s%s\n",
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301020 get_hw_id_string(ar->wiphy->hw_version),
1021 ar->wiphy->fw_version,
Kalle Valo003353b0d2011-09-01 10:14:21 +03001022 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
Kalle Valobdcd8172011-07-18 00:22:30 +03001023}
1024
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301025void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
Kalle Valobdcd8172011-07-18 00:22:30 +03001026{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301027 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301028
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301029 ath6kl_cfg80211_scan_complete_event(vif, status);
Kalle Valobdcd8172011-07-18 00:22:30 +03001030
Jouni Malinen551185c2011-09-19 19:15:06 +03001031 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301032 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301033 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1034 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001035 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001036
1037 ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status);
1038}
1039
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301040void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001041 u16 listen_int, u16 beacon_int,
1042 enum network_type net_type, u8 beacon_ie_len,
1043 u8 assoc_req_len, u8 assoc_resp_len,
1044 u8 *assoc_info)
1045{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301046 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301047
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301048 ath6kl_cfg80211_connect_event(vif, channel, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001049 listen_int, beacon_int,
1050 net_type, beacon_ie_len,
1051 assoc_req_len, assoc_resp_len,
1052 assoc_info);
1053
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301054 memcpy(vif->bssid, bssid, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301055 vif->bss_ch = channel;
Kalle Valobdcd8172011-07-18 00:22:30 +03001056
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301057 if ((vif->nw_type == INFRA_NETWORK))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301058 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
1059 ar->listen_intvl_t,
Kalle Valobdcd8172011-07-18 00:22:30 +03001060 ar->listen_intvl_b);
1061
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301062 netif_wake_queue(vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001063
1064 /* Update connect & link status atomically */
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301065 spin_lock_bh(&ar->lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301066 set_bit(CONNECTED, &vif->flags);
1067 clear_bit(CONNECT_PEND, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301068 netif_carrier_on(vif->ndev);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301069 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001070
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301071 aggr_reset_state(vif->aggr_cntxt);
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301072 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001073
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301074 if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001075 memset(ar->node_map, 0, sizeof(ar->node_map));
1076 ar->node_num = 0;
1077 ar->next_ep_id = ENDPOINT_2;
1078 }
1079
Jouni Malinen551185c2011-09-19 19:15:06 +03001080 if (!ar->usr_bss_filter) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301081 set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301082 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1083 CURRENT_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001084 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001085}
1086
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301087void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
Kalle Valobdcd8172011-07-18 00:22:30 +03001088{
1089 struct ath6kl_sta *sta;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301090 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001091 u8 tsc[6];
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301092
Kalle Valobdcd8172011-07-18 00:22:30 +03001093 /*
1094 * For AP case, keyid will have aid of STA which sent pkt with
1095 * MIC error. Use this aid to get MAC & send it to hostapd.
1096 */
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301097 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001098 sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
1099 if (!sta)
1100 return;
1101
1102 ath6kl_dbg(ATH6KL_DBG_TRC,
1103 "ap tkip mic error received from aid=%d\n", keyid);
1104
1105 memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301106 cfg80211_michael_mic_failure(vif->ndev, sta->mac,
Kalle Valobdcd8172011-07-18 00:22:30 +03001107 NL80211_KEYTYPE_PAIRWISE, keyid,
1108 tsc, GFP_KERNEL);
1109 } else
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301110 ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001111
1112}
1113
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301114static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03001115{
1116 struct wmi_target_stats *tgt_stats =
1117 (struct wmi_target_stats *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301118 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301119 struct target_stats *stats = &vif->target_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001120 struct tkip_ccmp_stats *ccmp_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001121 u8 ac;
1122
1123 if (len < sizeof(*tgt_stats))
1124 return;
1125
Kalle Valobdcd8172011-07-18 00:22:30 +03001126 ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
1127
1128 stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
1129 stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
1130 stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
1131 stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
1132 stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
1133 stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
1134 stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
1135 stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
1136 stats->tx_rts_success_cnt +=
1137 le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
1138
1139 for (ac = 0; ac < WMM_NUM_AC; ac++)
1140 stats->tx_pkt_per_ac[ac] +=
1141 le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
1142
1143 stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
1144 stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
1145 stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
1146 stats->tx_mult_retry_cnt +=
1147 le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
1148 stats->tx_rts_fail_cnt +=
1149 le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
1150 stats->tx_ucast_rate =
1151 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
1152
1153 stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
1154 stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
1155 stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
1156 stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
1157 stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
1158 stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
1159 stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
1160 stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
1161 stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
1162 stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
1163 stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
1164 stats->rx_key_cache_miss +=
1165 le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
1166 stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
1167 stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
1168 stats->rx_ucast_rate =
1169 ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
1170
1171 ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
1172
1173 stats->tkip_local_mic_fail +=
1174 le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
1175 stats->tkip_cnter_measures_invoked +=
1176 le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
1177 stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
1178
1179 stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
1180 stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
1181
1182 stats->pwr_save_fail_cnt +=
1183 le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
1184 stats->noise_floor_calib =
1185 a_sle32_to_cpu(tgt_stats->noise_floor_calib);
1186
1187 stats->cs_bmiss_cnt +=
1188 le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
1189 stats->cs_low_rssi_cnt +=
1190 le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
1191 stats->cs_connect_cnt +=
1192 le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
1193 stats->cs_discon_cnt +=
1194 le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
1195
1196 stats->cs_ave_beacon_rssi =
1197 a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
1198
1199 stats->cs_last_roam_msec =
1200 tgt_stats->cserv_stats.cs_last_roam_msec;
1201 stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
1202 stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
1203
1204 stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
1205
1206 stats->wow_pkt_dropped +=
1207 le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
1208 stats->wow_host_pkt_wakeups +=
1209 tgt_stats->wow_stats.wow_host_pkt_wakeups;
1210 stats->wow_host_evt_wakeups +=
1211 tgt_stats->wow_stats.wow_host_evt_wakeups;
1212 stats->wow_evt_discarded +=
1213 le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
1214
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301215 if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
1216 clear_bit(STATS_UPDATE_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001217 wake_up(&ar->event_wq);
1218 }
1219}
1220
1221static void ath6kl_add_le32(__le32 *var, __le32 val)
1222{
1223 *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
1224}
1225
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301226void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03001227{
1228 struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301229 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001230 struct wmi_ap_mode_stat *ap = &ar->ap_stats;
1231 struct wmi_per_sta_stat *st_ap, *st_p;
1232 u8 ac;
1233
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301234 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001235 if (len < sizeof(*p))
1236 return;
1237
1238 for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
1239 st_ap = &ap->sta[ac];
1240 st_p = &p->sta[ac];
1241
1242 ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
1243 ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
1244 ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
1245 ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
1246 ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
1247 ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
1248 ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
1249 ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
1250 }
1251
1252 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301253 ath6kl_update_target_stats(vif, ptr, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001254 }
1255}
1256
1257void ath6kl_wakeup_event(void *dev)
1258{
1259 struct ath6kl *ar = (struct ath6kl *) dev;
1260
1261 wake_up(&ar->event_wq);
1262}
1263
1264void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
1265{
1266 struct ath6kl *ar = (struct ath6kl *) devt;
1267
1268 ar->tx_pwr = tx_pwr;
1269 wake_up(&ar->event_wq);
1270}
1271
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301272void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
Kalle Valobdcd8172011-07-18 00:22:30 +03001273{
1274 struct ath6kl_sta *conn;
1275 struct sk_buff *skb;
1276 bool psq_empty = false;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301277 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001278
1279 conn = ath6kl_find_sta_by_aid(ar, aid);
1280
1281 if (!conn)
1282 return;
1283 /*
1284 * Send out a packet queued on ps queue. When the ps queue
1285 * becomes empty update the PVB for this station.
1286 */
1287 spin_lock_bh(&conn->psq_lock);
1288 psq_empty = skb_queue_empty(&conn->psq);
1289 spin_unlock_bh(&conn->psq_lock);
1290
1291 if (psq_empty)
1292 /* TODO: Send out a NULL data frame */
1293 return;
1294
1295 spin_lock_bh(&conn->psq_lock);
1296 skb = skb_dequeue(&conn->psq);
1297 spin_unlock_bh(&conn->psq_lock);
1298
1299 conn->sta_flags |= STA_PS_POLLED;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301300 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001301 conn->sta_flags &= ~STA_PS_POLLED;
1302
1303 spin_lock_bh(&conn->psq_lock);
1304 psq_empty = skb_queue_empty(&conn->psq);
1305 spin_unlock_bh(&conn->psq_lock);
1306
1307 if (psq_empty)
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301308 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001309}
1310
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301311void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001312{
1313 bool mcastq_empty = false;
1314 struct sk_buff *skb;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301315 struct ath6kl *ar = vif->ar;
Kalle Valobdcd8172011-07-18 00:22:30 +03001316
1317 /*
1318 * If there are no associated STAs, ignore the DTIM expiry event.
1319 * There can be potential race conditions where the last associated
1320 * STA may disconnect & before the host could clear the 'Indicate
1321 * DTIM' request to the firmware, the firmware would have just
1322 * indicated a DTIM expiry event. The race is between 'clear DTIM
1323 * expiry cmd' going from the host to the firmware & the DTIM
1324 * expiry event happening from the firmware to the host.
1325 */
1326 if (!ar->sta_list_index)
1327 return;
1328
1329 spin_lock_bh(&ar->mcastpsq_lock);
1330 mcastq_empty = skb_queue_empty(&ar->mcastpsq);
1331 spin_unlock_bh(&ar->mcastpsq_lock);
1332
1333 if (mcastq_empty)
1334 return;
1335
1336 /* set the STA flag to dtim_expired for the frame to go out */
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301337 set_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001338
1339 spin_lock_bh(&ar->mcastpsq_lock);
1340 while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
1341 spin_unlock_bh(&ar->mcastpsq_lock);
1342
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301343 ath6kl_data_tx(skb, vif->ndev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001344
1345 spin_lock_bh(&ar->mcastpsq_lock);
1346 }
1347 spin_unlock_bh(&ar->mcastpsq_lock);
1348
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301349 clear_bit(DTIM_EXPIRED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001350
1351 /* clear the LSB of the BitMapCtl field of the TIM IE */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301352 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001353}
1354
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301355void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001356 u8 assoc_resp_len, u8 *assoc_info,
1357 u16 prot_reason_status)
1358{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301359 struct ath6kl *ar = vif->ar;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301360
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +05301361 if (vif->nw_type == AP_NETWORK) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001362 if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
1363 return;
1364
1365 /* if no more associated STAs, empty the mcast PS q */
1366 if (ar->sta_list_index == 0) {
1367 spin_lock_bh(&ar->mcastpsq_lock);
1368 skb_queue_purge(&ar->mcastpsq);
1369 spin_unlock_bh(&ar->mcastpsq_lock);
1370
1371 /* clear the LSB of the TIM IE's BitMapCtl field */
1372 if (test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301373 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
1374 MCAST_AID, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001375 }
1376
1377 if (!is_broadcast_ether_addr(bssid)) {
1378 /* send event to application */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301379 cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
Kalle Valobdcd8172011-07-18 00:22:30 +03001380 }
1381
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301382 if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +05301383 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301384 clear_bit(CONNECTED, &vif->flags);
Jouni Malinen151411e2011-09-15 15:10:16 +03001385 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001386 return;
1387 }
1388
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301389 ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03001390 assoc_resp_len, assoc_info,
1391 prot_reason_status);
1392
Vasanthakumar Thiagarajan2132c692011-10-25 19:34:07 +05301393 aggr_reset_state(vif->aggr_cntxt);
Kalle Valobdcd8172011-07-18 00:22:30 +03001394
Vasanthakumar Thiagarajande3ad712011-10-25 19:34:08 +05301395 del_timer(&vif->disconnect_timer);
Kalle Valobdcd8172011-07-18 00:22:30 +03001396
1397 ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT,
1398 "disconnect reason is %d\n", reason);
1399
1400 /*
1401 * If the event is due to disconnect cmd from the host, only they
1402 * the target would stop trying to connect. Under any other
1403 * condition, target would keep trying to connect.
1404 */
1405 if (reason == DISCONNECT_CMD) {
1406 if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301407 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1408 NONE_BSS_FILTER, 0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001409 } else {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301410 set_bit(CONNECT_PEND, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001411 if (((reason == ASSOC_FAILED) &&
1412 (prot_reason_status == 0x11)) ||
1413 ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301414 && (vif->reconnect_flag == 1))) {
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301415 set_bit(CONNECTED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001416 return;
1417 }
1418 }
1419
Kalle Valobdcd8172011-07-18 00:22:30 +03001420 /* update connect & link status atomically */
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301421 spin_lock_bh(&ar->lock);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301422 clear_bit(CONNECTED, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301423 netif_carrier_off(vif->ndev);
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301424 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001425
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301426 if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
1427 vif->reconnect_flag = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001428
1429 if (reason != CSERV_DISCONNECT)
1430 ar->user_key_ctrl = 0;
1431
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301432 netif_stop_queue(vif->ndev);
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +05301433 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +05301434 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001435
1436 ath6kl_tx_data_cleanup(ar);
1437}
1438
1439static int ath6kl_open(struct net_device *dev)
1440{
1441 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301442 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001443
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301444 spin_lock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001445
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301446 set_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001447
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301448 if (test_bit(CONNECTED, &vif->flags)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001449 netif_carrier_on(dev);
1450 netif_wake_queue(dev);
1451 } else
1452 netif_carrier_off(dev);
1453
Vasanthakumar Thiagarajan151bd302011-09-30 19:18:43 +05301454 spin_unlock_bh(&ar->lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001455
1456 return 0;
1457}
1458
1459static int ath6kl_close(struct net_device *dev)
1460{
1461 struct ath6kl *ar = ath6kl_priv(dev);
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301462 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001463
1464 netif_stop_queue(dev);
1465
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301466 ath6kl_disconnect(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03001467
1468 if (test_bit(WMI_READY, &ar->flag)) {
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301469 if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF,
1470 0, 0, 0, 0, 0, 0, 0, 0, 0))
Kalle Valobdcd8172011-07-18 00:22:30 +03001471 return -EIO;
1472
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301473 clear_bit(WLAN_ENABLED, &vif->flags);
Kalle Valobdcd8172011-07-18 00:22:30 +03001474 }
1475
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301476 ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
Kalle Valobdcd8172011-07-18 00:22:30 +03001477
1478 return 0;
1479}
1480
1481static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
1482{
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301483 struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001484
Vasanthakumar Thiagarajanb95907a2011-10-25 19:34:11 +05301485 return &vif->net_stats;
Kalle Valobdcd8172011-07-18 00:22:30 +03001486}
1487
1488static struct net_device_ops ath6kl_netdev_ops = {
1489 .ndo_open = ath6kl_open,
1490 .ndo_stop = ath6kl_close,
1491 .ndo_start_xmit = ath6kl_data_tx,
1492 .ndo_get_stats = ath6kl_get_stats,
1493};
1494
1495void init_netdev(struct net_device *dev)
1496{
1497 dev->netdev_ops = &ath6kl_netdev_ops;
1498 dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
1499
1500 dev->needed_headroom = ETH_HLEN;
1501 dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
1502 sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +05301503 + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +03001504
1505 return;
1506}