Commit | Line | Data |
---|---|---|
bdcd8170 KV |
1 | /* |
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 | ||
23 | struct ath6kl_sta *ath6kl_find_sta(struct ath6kl *ar, u8 *node_addr) | |
24 | { | |
f5938f24 VT |
25 | /* TODO: Findout vif */ |
26 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 KV |
27 | struct ath6kl_sta *conn = NULL; |
28 | u8 i, max_conn; | |
29 | ||
f5938f24 | 30 | max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0; |
bdcd8170 KV |
31 | |
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 | ||
42 | struct 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 | ||
56 | static 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); | |
3c774bba JM |
66 | if (ielen <= ATH6KL_MAX_IE) |
67 | memcpy(sta->wpa_ie, wpaie, ielen); | |
bdcd8170 KV |
68 | 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 | ||
77 | static 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 | ||
97 | static 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 | ||
129 | enum 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 | ||
135 | struct 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 | ||
148 | void 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 | ||
161 | void ath6kl_cookie_cleanup(struct ath6kl *ar) | |
162 | { | |
163 | ar->cookie_list = NULL; | |
164 | ar->cookie_count = 0; | |
165 | } | |
166 | ||
167 | void 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 ). */ | |
180 | static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr) | |
181 | { | |
182 | int status; | |
bdcd8170 | 183 | s32 i; |
b142b914 | 184 | __le32 addr_val; |
bdcd8170 KV |
185 | |
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 | |
b142b914 VT |
194 | * 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. | |
bdcd8170 | 197 | */ |
b142b914 | 198 | memset((u8 *)&addr_val, ((u8 *)&addr)[i], 4); |
bdcd8170 KV |
199 | |
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 | */ | |
b142b914 | 205 | status = hif_read_write_sync(ar, reg_addr + i, (u8 *)&addr_val, |
bdcd8170 KV |
206 | 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 | */ | |
b142b914 VT |
223 | addr_val = cpu_to_le32(addr); |
224 | status = hif_read_write_sync(ar, reg_addr, | |
225 | (u8 *)&(addr_val), | |
bdcd8170 KV |
226 | 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 | /* | |
addb44be KV |
238 | * Read from the hardware through its diagnostic window. No cooperation |
239 | * from the firmware is required for this. | |
bdcd8170 | 240 | */ |
addb44be | 241 | int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value) |
bdcd8170 | 242 | { |
addb44be | 243 | int ret; |
bdcd8170 KV |
244 | |
245 | /* set window register to start read cycle */ | |
addb44be KV |
246 | ret = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, address); |
247 | if (ret) | |
248 | return ret; | |
bdcd8170 KV |
249 | |
250 | /* read the data */ | |
addb44be KV |
251 | 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; | |
bdcd8170 KV |
257 | } |
258 | ||
addb44be | 259 | return 0; |
bdcd8170 KV |
260 | } |
261 | ||
bdcd8170 KV |
262 | /* |
263 | * Write to the ATH6KL through its diagnostic window. No cooperation from | |
264 | * the Target is required for this. | |
265 | */ | |
f9ea0753 | 266 | int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value) |
bdcd8170 | 267 | { |
addb44be | 268 | int ret; |
bdcd8170 KV |
269 | |
270 | /* set write data */ | |
addb44be KV |
271 | 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; | |
bdcd8170 KV |
277 | } |
278 | ||
279 | /* set window register, which starts the write cycle */ | |
280 | return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS, | |
addb44be | 281 | address); |
bdcd8170 KV |
282 | } |
283 | ||
addb44be | 284 | int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length) |
bdcd8170 | 285 | { |
addb44be KV |
286 | u32 count, *buf = data; |
287 | int ret; | |
bdcd8170 | 288 | |
addb44be KV |
289 | 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; | |
bdcd8170 KV |
296 | } |
297 | ||
addb44be KV |
298 | return 0; |
299 | } | |
300 | ||
301 | int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length) | |
302 | { | |
f9ea0753 VT |
303 | u32 count; |
304 | __le32 *buf = data; | |
addb44be KV |
305 | 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; | |
bdcd8170 KV |
317 | } |
318 | ||
bc07ddb2 KV |
319 | int 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 | ||
388 | out: | |
389 | kfree(buf); | |
390 | ||
391 | return ret; | |
392 | } | |
393 | ||
31024d99 KF |
394 | /* FIXME: move to a better place, target.h? */ |
395 | #define AR6003_RESET_CONTROL_ADDRESS 0x00004000 | |
396 | #define AR6004_RESET_CONTROL_ADDRESS 0x00004000 | |
397 | ||
bdcd8170 KV |
398 | static 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; | |
f9ea0753 | 403 | __le32 data; |
bdcd8170 | 404 | |
31024d99 KF |
405 | if (target_type != TARGET_TYPE_AR6003 && |
406 | target_type != TARGET_TYPE_AR6004) | |
bdcd8170 KV |
407 | return; |
408 | ||
f9ea0753 VT |
409 | data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) : |
410 | cpu_to_le32(RESET_CONTROL_MBOX_RST); | |
bdcd8170 | 411 | |
31024d99 KF |
412 | 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 | ||
addb44be | 424 | status = ath6kl_diag_write32(ar, address, data); |
bdcd8170 KV |
425 | |
426 | if (status) | |
427 | ath6kl_err("failed to reset target\n"); | |
428 | } | |
429 | ||
430 | void ath6kl_stop_endpoint(struct net_device *dev, bool keep_profile, | |
431 | bool get_dbglogs) | |
432 | { | |
433 | struct ath6kl *ar = ath6kl_priv(dev); | |
59c98449 | 434 | struct ath6kl_vif *vif = netdev_priv(dev); |
bdcd8170 KV |
435 | 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)) { | |
59c98449 VT |
442 | discon_issued = (test_bit(CONNECTED, &vif->flags) || |
443 | test_bit(CONNECT_PEND, &vif->flags)); | |
bdcd8170 KV |
444 | ath6kl_disconnect(ar); |
445 | if (!keep_profile) | |
446 | ath6kl_init_profile_info(ar); | |
447 | ||
de3ad713 | 448 | del_timer(&vif->disconnect_timer); |
bdcd8170 KV |
449 | |
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) | |
465 | ath6kl_disconnect_event(ar, DISCONNECT_CMD, | |
f5938f24 | 466 | (vif->nw_type & AP_NETWORK) ? |
8c8b65e3 | 467 | bcast_mac : vif->bssid, |
bdcd8170 KV |
468 | 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__); | |
ad226ec2 | 489 | ath6kl_htc_stop(ar->htc_target); |
bdcd8170 KV |
490 | } |
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 | ||
501 | static void ath6kl_install_static_wep_keys(struct ath6kl *ar) | |
502 | { | |
3450334f VT |
503 | /* TODO: Findout vif */ |
504 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 KV |
505 | u8 index; |
506 | u8 keyusage; | |
507 | ||
508 | for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { | |
6f2a73f9 | 509 | if (vif->wep_key_list[index].key_len) { |
bdcd8170 | 510 | keyusage = GROUP_USAGE; |
3450334f | 511 | if (index == vif->def_txkey_index) |
bdcd8170 KV |
512 | keyusage |= TX_USAGE; |
513 | ||
514 | ath6kl_wmi_addkey_cmd(ar->wmi, | |
515 | index, | |
516 | WEP_CRYPT, | |
517 | keyusage, | |
6f2a73f9 | 518 | vif->wep_key_list[index].key_len, |
bdcd8170 | 519 | NULL, |
6f2a73f9 | 520 | vif->wep_key_list[index].key, |
bdcd8170 KV |
521 | KEY_OP_INIT_VAL, NULL, |
522 | NO_SYNC_WMIFLAG); | |
523 | } | |
524 | } | |
525 | } | |
526 | ||
572e27c0 | 527 | void ath6kl_connect_ap_mode_bss(struct ath6kl *ar, u16 channel) |
bdcd8170 | 528 | { |
bdcd8170 | 529 | struct ath6kl_req_key *ik; |
9a5b1318 JM |
530 | int res; |
531 | u8 key_rsc[ATH6KL_KEY_SEQ_LEN]; | |
59c98449 VT |
532 | /* TODO: Pass vif instead of taking it from ar */ |
533 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 | 534 | |
572e27c0 | 535 | ik = &ar->ap_mode_bkey; |
bdcd8170 | 536 | |
572e27c0 | 537 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel); |
9a5b1318 | 538 | |
3450334f | 539 | switch (vif->auth_mode) { |
572e27c0 | 540 | case NONE_AUTH: |
3450334f | 541 | if (vif->prwise_crypto == WEP_CRYPT) |
572e27c0 JM |
542 | ath6kl_install_static_wep_keys(ar); |
543 | break; | |
544 | case WPA_PSK_AUTH: | |
545 | case WPA2_PSK_AUTH: | |
546 | case (WPA_PSK_AUTH | WPA2_PSK_AUTH): | |
547 | if (!ik->valid) | |
bdcd8170 | 548 | break; |
9a5b1318 | 549 | |
572e27c0 JM |
550 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for " |
551 | "the initial group key for AP mode\n"); | |
552 | memset(key_rsc, 0, sizeof(key_rsc)); | |
553 | res = ath6kl_wmi_addkey_cmd( | |
554 | ar->wmi, ik->key_index, ik->key_type, | |
555 | GROUP_USAGE, ik->key_len, key_rsc, ik->key, | |
556 | KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG); | |
557 | if (res) { | |
558 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed " | |
559 | "addkey failed: %d\n", res); | |
bdcd8170 | 560 | } |
572e27c0 | 561 | break; |
bdcd8170 KV |
562 | } |
563 | ||
572e27c0 | 564 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
59c98449 | 565 | set_bit(CONNECTED, &vif->flags); |
572e27c0 JM |
566 | netif_carrier_on(ar->net_dev); |
567 | } | |
568 | ||
569 | void ath6kl_connect_ap_mode_sta(struct ath6kl *ar, u16 aid, u8 *mac_addr, | |
570 | u8 keymgmt, u8 ucipher, u8 auth, | |
571 | u8 assoc_req_len, u8 *assoc_info) | |
572 | { | |
573 | u8 *ies = NULL, *wpa_ie = NULL, *pos; | |
574 | size_t ies_len = 0; | |
575 | struct station_info sinfo; | |
576 | ||
577 | ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid); | |
bdcd8170 | 578 | |
3c774bba JM |
579 | if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) { |
580 | struct ieee80211_mgmt *mgmt = | |
581 | (struct ieee80211_mgmt *) assoc_info; | |
582 | if (ieee80211_is_assoc_req(mgmt->frame_control) && | |
583 | assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) + | |
584 | sizeof(mgmt->u.assoc_req)) { | |
585 | ies = mgmt->u.assoc_req.variable; | |
586 | ies_len = assoc_info + assoc_req_len - ies; | |
587 | } else if (ieee80211_is_reassoc_req(mgmt->frame_control) && | |
588 | assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) | |
589 | + sizeof(mgmt->u.reassoc_req)) { | |
590 | ies = mgmt->u.reassoc_req.variable; | |
591 | ies_len = assoc_info + assoc_req_len - ies; | |
592 | } | |
593 | } | |
594 | ||
595 | pos = ies; | |
596 | while (pos && pos + 1 < ies + ies_len) { | |
597 | if (pos + 2 + pos[1] > ies + ies_len) | |
598 | break; | |
599 | if (pos[0] == WLAN_EID_RSN) | |
600 | wpa_ie = pos; /* RSN IE */ | |
601 | else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && | |
602 | pos[1] >= 4 && | |
603 | pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) { | |
604 | if (pos[5] == 0x01) | |
605 | wpa_ie = pos; /* WPA IE */ | |
606 | else if (pos[5] == 0x04) { | |
607 | wpa_ie = pos; /* WPS IE */ | |
608 | break; /* overrides WPA/RSN IE */ | |
609 | } | |
610 | } | |
611 | pos += 2 + pos[1]; | |
612 | } | |
613 | ||
572e27c0 | 614 | ath6kl_add_new_sta(ar, mac_addr, aid, wpa_ie, |
3c774bba | 615 | wpa_ie ? 2 + wpa_ie[1] : 0, |
572e27c0 | 616 | keymgmt, ucipher, auth); |
bdcd8170 KV |
617 | |
618 | /* send event to application */ | |
619 | memset(&sinfo, 0, sizeof(sinfo)); | |
620 | ||
621 | /* TODO: sinfo.generation */ | |
3c774bba JM |
622 | |
623 | sinfo.assoc_req_ies = ies; | |
624 | sinfo.assoc_req_ies_len = ies_len; | |
625 | sinfo.filled |= STATION_INFO_ASSOC_REQ_IES; | |
626 | ||
572e27c0 | 627 | cfg80211_new_sta(ar->net_dev, mac_addr, &sinfo, GFP_KERNEL); |
bdcd8170 KV |
628 | |
629 | netif_wake_queue(ar->net_dev); | |
bdcd8170 KV |
630 | } |
631 | ||
632 | /* Functions for Tx credit handling */ | |
633 | void ath6k_credit_init(struct htc_credit_state_info *cred_info, | |
634 | struct list_head *ep_list, | |
635 | int tot_credits) | |
636 | { | |
637 | struct htc_endpoint_credit_dist *cur_ep_dist; | |
638 | int count; | |
639 | ||
640 | cred_info->cur_free_credits = tot_credits; | |
641 | cred_info->total_avail_credits = tot_credits; | |
642 | ||
643 | list_for_each_entry(cur_ep_dist, ep_list, list) { | |
644 | if (cur_ep_dist->endpoint == ENDPOINT_0) | |
645 | continue; | |
646 | ||
647 | cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg; | |
648 | ||
649 | if (tot_credits > 4) | |
650 | if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) || | |
651 | (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) { | |
652 | ath6kl_deposit_credit_to_ep(cred_info, | |
653 | cur_ep_dist, | |
654 | cur_ep_dist->cred_min); | |
655 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; | |
656 | } | |
657 | ||
658 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) { | |
659 | ath6kl_deposit_credit_to_ep(cred_info, cur_ep_dist, | |
660 | cur_ep_dist->cred_min); | |
661 | /* | |
662 | * Control service is always marked active, it | |
663 | * never goes inactive EVER. | |
664 | */ | |
665 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; | |
666 | } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC) | |
667 | /* this is the lowest priority data endpoint */ | |
668 | cred_info->lowestpri_ep_dist = cur_ep_dist->list; | |
669 | ||
670 | /* | |
671 | * Streams have to be created (explicit | implicit) for all | |
672 | * kinds of traffic. BE endpoints are also inactive in the | |
673 | * beginning. When BE traffic starts it creates implicit | |
674 | * streams that redistributes credits. | |
675 | * | |
676 | * Note: all other endpoints have minimums set but are | |
677 | * initially given NO credits. credits will be distributed | |
678 | * as traffic activity demands | |
679 | */ | |
680 | } | |
681 | ||
682 | WARN_ON(cred_info->cur_free_credits <= 0); | |
683 | ||
684 | list_for_each_entry(cur_ep_dist, ep_list, list) { | |
685 | if (cur_ep_dist->endpoint == ENDPOINT_0) | |
686 | continue; | |
687 | ||
688 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) | |
689 | cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg; | |
690 | else { | |
691 | /* | |
692 | * For the remaining data endpoints, we assume that | |
693 | * each cred_per_msg are the same. We use a simple | |
694 | * calculation here, we take the remaining credits | |
695 | * and determine how many max messages this can | |
696 | * cover and then set each endpoint's normal value | |
697 | * equal to 3/4 this amount. | |
698 | */ | |
699 | count = (cred_info->cur_free_credits / | |
700 | cur_ep_dist->cred_per_msg) | |
701 | * cur_ep_dist->cred_per_msg; | |
702 | count = (count * 3) >> 2; | |
703 | count = max(count, cur_ep_dist->cred_per_msg); | |
704 | cur_ep_dist->cred_norm = count; | |
705 | ||
706 | } | |
707 | } | |
708 | } | |
709 | ||
710 | /* initialize and setup credit distribution */ | |
711 | int ath6k_setup_credit_dist(void *htc_handle, | |
712 | struct htc_credit_state_info *cred_info) | |
713 | { | |
714 | u16 servicepriority[5]; | |
715 | ||
716 | memset(cred_info, 0, sizeof(struct htc_credit_state_info)); | |
717 | ||
718 | servicepriority[0] = WMI_CONTROL_SVC; /* highest */ | |
719 | servicepriority[1] = WMI_DATA_VO_SVC; | |
720 | servicepriority[2] = WMI_DATA_VI_SVC; | |
721 | servicepriority[3] = WMI_DATA_BE_SVC; | |
722 | servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */ | |
723 | ||
724 | /* set priority list */ | |
ad226ec2 | 725 | ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5); |
bdcd8170 KV |
726 | |
727 | return 0; | |
728 | } | |
729 | ||
730 | /* reduce an ep's credits back to a set limit */ | |
731 | static void ath6k_reduce_credits(struct htc_credit_state_info *cred_info, | |
732 | struct htc_endpoint_credit_dist *ep_dist, | |
733 | int limit) | |
734 | { | |
735 | int credits; | |
736 | ||
737 | ep_dist->cred_assngd = limit; | |
738 | ||
739 | if (ep_dist->credits <= limit) | |
740 | return; | |
741 | ||
742 | credits = ep_dist->credits - limit; | |
743 | ep_dist->credits -= credits; | |
744 | cred_info->cur_free_credits += credits; | |
745 | } | |
746 | ||
747 | static void ath6k_credit_update(struct htc_credit_state_info *cred_info, | |
748 | struct list_head *epdist_list) | |
749 | { | |
750 | struct htc_endpoint_credit_dist *cur_dist_list; | |
751 | ||
752 | list_for_each_entry(cur_dist_list, epdist_list, list) { | |
753 | if (cur_dist_list->endpoint == ENDPOINT_0) | |
754 | continue; | |
755 | ||
756 | if (cur_dist_list->cred_to_dist > 0) { | |
757 | cur_dist_list->credits += | |
758 | cur_dist_list->cred_to_dist; | |
759 | cur_dist_list->cred_to_dist = 0; | |
760 | if (cur_dist_list->credits > | |
761 | cur_dist_list->cred_assngd) | |
762 | ath6k_reduce_credits(cred_info, | |
763 | cur_dist_list, | |
764 | cur_dist_list->cred_assngd); | |
765 | ||
766 | if (cur_dist_list->credits > | |
767 | cur_dist_list->cred_norm) | |
768 | ath6k_reduce_credits(cred_info, cur_dist_list, | |
769 | cur_dist_list->cred_norm); | |
770 | ||
771 | if (!(cur_dist_list->dist_flags & HTC_EP_ACTIVE)) { | |
772 | if (cur_dist_list->txq_depth == 0) | |
773 | ath6k_reduce_credits(cred_info, | |
774 | cur_dist_list, 0); | |
775 | } | |
776 | } | |
777 | } | |
778 | } | |
779 | ||
780 | /* | |
781 | * HTC has an endpoint that needs credits, ep_dist is the endpoint in | |
782 | * question. | |
783 | */ | |
784 | void ath6k_seek_credits(struct htc_credit_state_info *cred_info, | |
785 | struct htc_endpoint_credit_dist *ep_dist) | |
786 | { | |
787 | struct htc_endpoint_credit_dist *curdist_list; | |
788 | int credits = 0; | |
789 | int need; | |
790 | ||
791 | if (ep_dist->svc_id == WMI_CONTROL_SVC) | |
792 | goto out; | |
793 | ||
794 | if ((ep_dist->svc_id == WMI_DATA_VI_SVC) || | |
795 | (ep_dist->svc_id == WMI_DATA_VO_SVC)) | |
796 | if ((ep_dist->cred_assngd >= ep_dist->cred_norm)) | |
797 | goto out; | |
798 | ||
799 | /* | |
800 | * For all other services, we follow a simple algorithm of: | |
801 | * | |
802 | * 1. checking the free pool for credits | |
803 | * 2. checking lower priority endpoints for credits to take | |
804 | */ | |
805 | ||
806 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); | |
807 | ||
808 | if (credits >= ep_dist->seek_cred) | |
809 | goto out; | |
810 | ||
811 | /* | |
812 | * We don't have enough in the free pool, try taking away from | |
813 | * lower priority services The rule for taking away credits: | |
814 | * | |
815 | * 1. Only take from lower priority endpoints | |
816 | * 2. Only take what is allocated above the minimum (never | |
817 | * starve an endpoint completely) | |
818 | * 3. Only take what you need. | |
819 | */ | |
820 | ||
821 | list_for_each_entry_reverse(curdist_list, | |
822 | &cred_info->lowestpri_ep_dist, | |
823 | list) { | |
824 | if (curdist_list == ep_dist) | |
825 | break; | |
826 | ||
827 | need = ep_dist->seek_cred - cred_info->cur_free_credits; | |
828 | ||
829 | if ((curdist_list->cred_assngd - need) >= | |
830 | curdist_list->cred_min) { | |
831 | /* | |
832 | * The current one has been allocated more than | |
833 | * it's minimum and it has enough credits assigned | |
834 | * above it's minimum to fulfill our need try to | |
835 | * take away just enough to fulfill our need. | |
836 | */ | |
837 | ath6k_reduce_credits(cred_info, curdist_list, | |
838 | curdist_list->cred_assngd - need); | |
839 | ||
840 | if (cred_info->cur_free_credits >= | |
841 | ep_dist->seek_cred) | |
842 | break; | |
843 | } | |
844 | ||
845 | if (curdist_list->endpoint == ENDPOINT_0) | |
846 | break; | |
847 | } | |
848 | ||
849 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); | |
850 | ||
851 | out: | |
852 | /* did we find some credits? */ | |
853 | if (credits) | |
854 | ath6kl_deposit_credit_to_ep(cred_info, ep_dist, credits); | |
855 | ||
856 | ep_dist->seek_cred = 0; | |
857 | } | |
858 | ||
859 | /* redistribute credits based on activity change */ | |
860 | static void ath6k_redistribute_credits(struct htc_credit_state_info *info, | |
861 | struct list_head *ep_dist_list) | |
862 | { | |
863 | struct htc_endpoint_credit_dist *curdist_list; | |
864 | ||
865 | list_for_each_entry(curdist_list, ep_dist_list, list) { | |
866 | if (curdist_list->endpoint == ENDPOINT_0) | |
867 | continue; | |
868 | ||
869 | if ((curdist_list->svc_id == WMI_DATA_BK_SVC) || | |
870 | (curdist_list->svc_id == WMI_DATA_BE_SVC)) | |
871 | curdist_list->dist_flags |= HTC_EP_ACTIVE; | |
872 | ||
873 | if ((curdist_list->svc_id != WMI_CONTROL_SVC) && | |
874 | !(curdist_list->dist_flags & HTC_EP_ACTIVE)) { | |
875 | if (curdist_list->txq_depth == 0) | |
876 | ath6k_reduce_credits(info, | |
877 | curdist_list, 0); | |
878 | else | |
879 | ath6k_reduce_credits(info, | |
880 | curdist_list, | |
881 | curdist_list->cred_min); | |
882 | } | |
883 | } | |
884 | } | |
885 | ||
886 | /* | |
887 | * | |
888 | * This function is invoked whenever endpoints require credit | |
889 | * distributions. A lock is held while this function is invoked, this | |
890 | * function shall NOT block. The ep_dist_list is a list of distribution | |
891 | * structures in prioritized order as defined by the call to the | |
892 | * htc_set_credit_dist() api. | |
893 | */ | |
894 | void ath6k_credit_distribute(struct htc_credit_state_info *cred_info, | |
895 | struct list_head *ep_dist_list, | |
896 | enum htc_credit_dist_reason reason) | |
897 | { | |
898 | switch (reason) { | |
899 | case HTC_CREDIT_DIST_SEND_COMPLETE: | |
900 | ath6k_credit_update(cred_info, ep_dist_list); | |
901 | break; | |
902 | case HTC_CREDIT_DIST_ACTIVITY_CHANGE: | |
903 | ath6k_redistribute_credits(cred_info, ep_dist_list); | |
904 | break; | |
905 | default: | |
906 | break; | |
907 | } | |
908 | ||
909 | WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits); | |
910 | WARN_ON(cred_info->cur_free_credits < 0); | |
911 | } | |
912 | ||
913 | void disconnect_timer_handler(unsigned long ptr) | |
914 | { | |
915 | struct net_device *dev = (struct net_device *)ptr; | |
916 | struct ath6kl *ar = ath6kl_priv(dev); | |
917 | ||
918 | ath6kl_init_profile_info(ar); | |
919 | ath6kl_disconnect(ar); | |
920 | } | |
921 | ||
922 | void ath6kl_disconnect(struct ath6kl *ar) | |
923 | { | |
59c98449 VT |
924 | /* TODO: Pass vif instead of taking it from ar */ |
925 | struct ath6kl_vif *vif = ar->vif; | |
926 | ||
927 | if (test_bit(CONNECTED, &vif->flags) || | |
928 | test_bit(CONNECT_PEND, &vif->flags)) { | |
bdcd8170 KV |
929 | ath6kl_wmi_disconnect_cmd(ar->wmi); |
930 | /* | |
931 | * Disconnect command is issued, clear the connect pending | |
932 | * flag. The connected flag will be cleared in | |
933 | * disconnect event notification. | |
934 | */ | |
59c98449 | 935 | clear_bit(CONNECT_PEND, &vif->flags); |
bdcd8170 KV |
936 | } |
937 | } | |
938 | ||
abcb344b KV |
939 | void ath6kl_deep_sleep_enable(struct ath6kl *ar) |
940 | { | |
59c98449 VT |
941 | /* TODO: Pass vif instead of taking it from ar */ |
942 | struct ath6kl_vif *vif = ar->vif; | |
943 | ||
14ee6f6b | 944 | switch (vif->sme_state) { |
abcb344b | 945 | case SME_CONNECTING: |
8c8b65e3 | 946 | cfg80211_connect_result(ar->net_dev, vif->bssid, NULL, 0, |
abcb344b KV |
947 | NULL, 0, |
948 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
949 | GFP_KERNEL); | |
950 | break; | |
951 | case SME_CONNECTED: | |
952 | default: | |
953 | /* | |
954 | * FIXME: oddly enough smeState is in DISCONNECTED during | |
955 | * suspend, why? Need to send disconnected event in that | |
956 | * state. | |
957 | */ | |
958 | cfg80211_disconnected(ar->net_dev, 0, NULL, 0, GFP_KERNEL); | |
959 | break; | |
960 | } | |
961 | ||
59c98449 VT |
962 | if (test_bit(CONNECTED, &vif->flags) || |
963 | test_bit(CONNECT_PEND, &vif->flags)) | |
abcb344b KV |
964 | ath6kl_wmi_disconnect_cmd(ar->wmi); |
965 | ||
14ee6f6b | 966 | vif->sme_state = SME_DISCONNECTED; |
abcb344b KV |
967 | |
968 | /* disable scanning */ | |
969 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, 0, | |
970 | 0, 0) != 0) | |
971 | printk(KERN_WARNING "ath6kl: failed to disable scan " | |
972 | "during suspend\n"); | |
973 | ||
974 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); | |
aa6cffc1 CN |
975 | |
976 | /* save the current power mode before enabling power save */ | |
977 | ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode; | |
978 | ||
979 | if (ath6kl_wmi_powermode_cmd(ar->wmi, REC_POWER) != 0) | |
980 | ath6kl_warn("ath6kl_deep_sleep_enable: " | |
981 | "wmi_powermode_cmd failed\n"); | |
abcb344b KV |
982 | } |
983 | ||
bdcd8170 KV |
984 | /* WMI Event handlers */ |
985 | ||
986 | static const char *get_hw_id_string(u32 id) | |
987 | { | |
988 | switch (id) { | |
989 | case AR6003_REV1_VERSION: | |
990 | return "1.0"; | |
991 | case AR6003_REV2_VERSION: | |
992 | return "2.0"; | |
993 | case AR6003_REV3_VERSION: | |
994 | return "2.1.1"; | |
995 | default: | |
996 | return "unknown"; | |
997 | } | |
998 | } | |
999 | ||
1000 | void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver) | |
1001 | { | |
1002 | struct ath6kl *ar = devt; | |
1003 | struct net_device *dev = ar->net_dev; | |
1004 | ||
1005 | memcpy(dev->dev_addr, datap, ETH_ALEN); | |
1006 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n", | |
1007 | __func__, dev->dev_addr); | |
1008 | ||
1009 | ar->version.wlan_ver = sw_ver; | |
1010 | ar->version.abi_ver = abi_ver; | |
1011 | ||
be98e3a4 VT |
1012 | snprintf(ar->wiphy->fw_version, |
1013 | sizeof(ar->wiphy->fw_version), | |
bdcd8170 KV |
1014 | "%u.%u.%u.%u", |
1015 | (ar->version.wlan_ver & 0xf0000000) >> 28, | |
1016 | (ar->version.wlan_ver & 0x0f000000) >> 24, | |
1017 | (ar->version.wlan_ver & 0x00ff0000) >> 16, | |
1018 | (ar->version.wlan_ver & 0x0000ffff)); | |
1019 | ||
1020 | /* indicate to the waiting thread that the ready event was received */ | |
1021 | set_bit(WMI_READY, &ar->flag); | |
1022 | wake_up(&ar->event_wq); | |
1023 | ||
003353b0 | 1024 | ath6kl_info("hw %s fw %s%s\n", |
be98e3a4 VT |
1025 | get_hw_id_string(ar->wiphy->hw_version), |
1026 | ar->wiphy->fw_version, | |
003353b0 | 1027 | test_bit(TESTMODE, &ar->flag) ? " testmode" : ""); |
bdcd8170 KV |
1028 | } |
1029 | ||
1030 | void ath6kl_scan_complete_evt(struct ath6kl *ar, int status) | |
1031 | { | |
59c98449 VT |
1032 | /* TODO: Pass vif instead of taking it from ar */ |
1033 | struct ath6kl_vif *vif = ar->vif; | |
1034 | ||
bdcd8170 KV |
1035 | ath6kl_cfg80211_scan_complete_event(ar, status); |
1036 | ||
551185ca | 1037 | if (!ar->usr_bss_filter) { |
59c98449 | 1038 | clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); |
bdcd8170 | 1039 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
551185ca | 1040 | } |
bdcd8170 KV |
1041 | |
1042 | ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status); | |
1043 | } | |
1044 | ||
1045 | void ath6kl_connect_event(struct ath6kl *ar, u16 channel, u8 *bssid, | |
1046 | u16 listen_int, u16 beacon_int, | |
1047 | enum network_type net_type, u8 beacon_ie_len, | |
1048 | u8 assoc_req_len, u8 assoc_resp_len, | |
1049 | u8 *assoc_info) | |
1050 | { | |
59c98449 VT |
1051 | /* TODO: findout vif instead of taking it from ar */ |
1052 | struct ath6kl_vif *vif = ar->vif; | |
1053 | ||
bdcd8170 KV |
1054 | ath6kl_cfg80211_connect_event(ar, channel, bssid, |
1055 | listen_int, beacon_int, | |
1056 | net_type, beacon_ie_len, | |
1057 | assoc_req_len, assoc_resp_len, | |
1058 | assoc_info); | |
1059 | ||
8c8b65e3 | 1060 | memcpy(vif->bssid, bssid, sizeof(vif->bssid)); |
f74bac54 | 1061 | vif->bss_ch = channel; |
bdcd8170 | 1062 | |
f5938f24 | 1063 | if ((vif->nw_type == INFRA_NETWORK)) |
bdcd8170 KV |
1064 | ath6kl_wmi_listeninterval_cmd(ar->wmi, ar->listen_intvl_t, |
1065 | ar->listen_intvl_b); | |
1066 | ||
1067 | netif_wake_queue(ar->net_dev); | |
1068 | ||
1069 | /* Update connect & link status atomically */ | |
151bd30b | 1070 | spin_lock_bh(&ar->lock); |
59c98449 VT |
1071 | set_bit(CONNECTED, &vif->flags); |
1072 | clear_bit(CONNECT_PEND, &vif->flags); | |
bdcd8170 | 1073 | netif_carrier_on(ar->net_dev); |
151bd30b | 1074 | spin_unlock_bh(&ar->lock); |
bdcd8170 | 1075 | |
2132c69c | 1076 | aggr_reset_state(vif->aggr_cntxt); |
bdcd8170 KV |
1077 | ar->reconnect_flag = 0; |
1078 | ||
f5938f24 | 1079 | if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) { |
bdcd8170 KV |
1080 | memset(ar->node_map, 0, sizeof(ar->node_map)); |
1081 | ar->node_num = 0; | |
1082 | ar->next_ep_id = ENDPOINT_2; | |
1083 | } | |
1084 | ||
551185ca | 1085 | if (!ar->usr_bss_filter) { |
59c98449 | 1086 | set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); |
551185ca JM |
1087 | ath6kl_wmi_bssfilter_cmd(ar->wmi, CURRENT_BSS_FILTER, 0); |
1088 | } | |
bdcd8170 KV |
1089 | } |
1090 | ||
1091 | void ath6kl_tkip_micerr_event(struct ath6kl *ar, u8 keyid, bool ismcast) | |
1092 | { | |
1093 | struct ath6kl_sta *sta; | |
f5938f24 VT |
1094 | /* TODO: Findout vif */ |
1095 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 KV |
1096 | u8 tsc[6]; |
1097 | /* | |
1098 | * For AP case, keyid will have aid of STA which sent pkt with | |
1099 | * MIC error. Use this aid to get MAC & send it to hostapd. | |
1100 | */ | |
f5938f24 | 1101 | if (vif->nw_type == AP_NETWORK) { |
bdcd8170 KV |
1102 | sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2)); |
1103 | if (!sta) | |
1104 | return; | |
1105 | ||
1106 | ath6kl_dbg(ATH6KL_DBG_TRC, | |
1107 | "ap tkip mic error received from aid=%d\n", keyid); | |
1108 | ||
1109 | memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */ | |
1110 | cfg80211_michael_mic_failure(ar->net_dev, sta->mac, | |
1111 | NL80211_KEYTYPE_PAIRWISE, keyid, | |
1112 | tsc, GFP_KERNEL); | |
1113 | } else | |
1114 | ath6kl_cfg80211_tkip_micerr_event(ar, keyid, ismcast); | |
1115 | ||
1116 | } | |
1117 | ||
1118 | static void ath6kl_update_target_stats(struct ath6kl *ar, u8 *ptr, u32 len) | |
1119 | { | |
1120 | struct wmi_target_stats *tgt_stats = | |
1121 | (struct wmi_target_stats *) ptr; | |
1122 | struct target_stats *stats = &ar->target_stats; | |
1123 | struct tkip_ccmp_stats *ccmp_stats; | |
bdcd8170 KV |
1124 | u8 ac; |
1125 | ||
1126 | if (len < sizeof(*tgt_stats)) | |
1127 | return; | |
1128 | ||
bdcd8170 KV |
1129 | ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n"); |
1130 | ||
1131 | stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt); | |
1132 | stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte); | |
1133 | stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt); | |
1134 | stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte); | |
1135 | stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt); | |
1136 | stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte); | |
1137 | stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt); | |
1138 | stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte); | |
1139 | stats->tx_rts_success_cnt += | |
1140 | le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt); | |
1141 | ||
1142 | for (ac = 0; ac < WMM_NUM_AC; ac++) | |
1143 | stats->tx_pkt_per_ac[ac] += | |
1144 | le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]); | |
1145 | ||
1146 | stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err); | |
1147 | stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt); | |
1148 | stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt); | |
1149 | stats->tx_mult_retry_cnt += | |
1150 | le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt); | |
1151 | stats->tx_rts_fail_cnt += | |
1152 | le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt); | |
1153 | stats->tx_ucast_rate = | |
1154 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate)); | |
1155 | ||
1156 | stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt); | |
1157 | stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte); | |
1158 | stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt); | |
1159 | stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte); | |
1160 | stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt); | |
1161 | stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte); | |
1162 | stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt); | |
1163 | stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte); | |
1164 | stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt); | |
1165 | stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err); | |
1166 | stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err); | |
1167 | stats->rx_key_cache_miss += | |
1168 | le32_to_cpu(tgt_stats->stats.rx.key_cache_miss); | |
1169 | stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err); | |
1170 | stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame); | |
1171 | stats->rx_ucast_rate = | |
1172 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate)); | |
1173 | ||
1174 | ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats; | |
1175 | ||
1176 | stats->tkip_local_mic_fail += | |
1177 | le32_to_cpu(ccmp_stats->tkip_local_mic_fail); | |
1178 | stats->tkip_cnter_measures_invoked += | |
1179 | le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked); | |
1180 | stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err); | |
1181 | ||
1182 | stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err); | |
1183 | stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays); | |
1184 | ||
1185 | stats->pwr_save_fail_cnt += | |
1186 | le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt); | |
1187 | stats->noise_floor_calib = | |
1188 | a_sle32_to_cpu(tgt_stats->noise_floor_calib); | |
1189 | ||
1190 | stats->cs_bmiss_cnt += | |
1191 | le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt); | |
1192 | stats->cs_low_rssi_cnt += | |
1193 | le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt); | |
1194 | stats->cs_connect_cnt += | |
1195 | le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt); | |
1196 | stats->cs_discon_cnt += | |
1197 | le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt); | |
1198 | ||
1199 | stats->cs_ave_beacon_rssi = | |
1200 | a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi); | |
1201 | ||
1202 | stats->cs_last_roam_msec = | |
1203 | tgt_stats->cserv_stats.cs_last_roam_msec; | |
1204 | stats->cs_snr = tgt_stats->cserv_stats.cs_snr; | |
1205 | stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi); | |
1206 | ||
1207 | stats->lq_val = le32_to_cpu(tgt_stats->lq_val); | |
1208 | ||
1209 | stats->wow_pkt_dropped += | |
1210 | le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped); | |
1211 | stats->wow_host_pkt_wakeups += | |
1212 | tgt_stats->wow_stats.wow_host_pkt_wakeups; | |
1213 | stats->wow_host_evt_wakeups += | |
1214 | tgt_stats->wow_stats.wow_host_evt_wakeups; | |
1215 | stats->wow_evt_discarded += | |
1216 | le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded); | |
1217 | ||
1218 | if (test_bit(STATS_UPDATE_PEND, &ar->flag)) { | |
1219 | clear_bit(STATS_UPDATE_PEND, &ar->flag); | |
1220 | wake_up(&ar->event_wq); | |
1221 | } | |
1222 | } | |
1223 | ||
1224 | static void ath6kl_add_le32(__le32 *var, __le32 val) | |
1225 | { | |
1226 | *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val)); | |
1227 | } | |
1228 | ||
1229 | void ath6kl_tgt_stats_event(struct ath6kl *ar, u8 *ptr, u32 len) | |
1230 | { | |
1231 | struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr; | |
1232 | struct wmi_ap_mode_stat *ap = &ar->ap_stats; | |
1233 | struct wmi_per_sta_stat *st_ap, *st_p; | |
f5938f24 VT |
1234 | /* TODO: Findout vif */ |
1235 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 KV |
1236 | u8 ac; |
1237 | ||
f5938f24 | 1238 | if (vif->nw_type == AP_NETWORK) { |
bdcd8170 KV |
1239 | if (len < sizeof(*p)) |
1240 | return; | |
1241 | ||
1242 | for (ac = 0; ac < AP_MAX_NUM_STA; ac++) { | |
1243 | st_ap = &ap->sta[ac]; | |
1244 | st_p = &p->sta[ac]; | |
1245 | ||
1246 | ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes); | |
1247 | ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts); | |
1248 | ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error); | |
1249 | ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard); | |
1250 | ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes); | |
1251 | ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts); | |
1252 | ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error); | |
1253 | ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard); | |
1254 | } | |
1255 | ||
1256 | } else { | |
1257 | ath6kl_update_target_stats(ar, ptr, len); | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | void ath6kl_wakeup_event(void *dev) | |
1262 | { | |
1263 | struct ath6kl *ar = (struct ath6kl *) dev; | |
1264 | ||
1265 | wake_up(&ar->event_wq); | |
1266 | } | |
1267 | ||
1268 | void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr) | |
1269 | { | |
1270 | struct ath6kl *ar = (struct ath6kl *) devt; | |
1271 | ||
1272 | ar->tx_pwr = tx_pwr; | |
1273 | wake_up(&ar->event_wq); | |
1274 | } | |
1275 | ||
1276 | void ath6kl_pspoll_event(struct ath6kl *ar, u8 aid) | |
1277 | { | |
1278 | struct ath6kl_sta *conn; | |
1279 | struct sk_buff *skb; | |
1280 | bool psq_empty = false; | |
1281 | ||
1282 | conn = ath6kl_find_sta_by_aid(ar, aid); | |
1283 | ||
1284 | if (!conn) | |
1285 | return; | |
1286 | /* | |
1287 | * Send out a packet queued on ps queue. When the ps queue | |
1288 | * becomes empty update the PVB for this station. | |
1289 | */ | |
1290 | spin_lock_bh(&conn->psq_lock); | |
1291 | psq_empty = skb_queue_empty(&conn->psq); | |
1292 | spin_unlock_bh(&conn->psq_lock); | |
1293 | ||
1294 | if (psq_empty) | |
1295 | /* TODO: Send out a NULL data frame */ | |
1296 | return; | |
1297 | ||
1298 | spin_lock_bh(&conn->psq_lock); | |
1299 | skb = skb_dequeue(&conn->psq); | |
1300 | spin_unlock_bh(&conn->psq_lock); | |
1301 | ||
1302 | conn->sta_flags |= STA_PS_POLLED; | |
1303 | ath6kl_data_tx(skb, ar->net_dev); | |
1304 | conn->sta_flags &= ~STA_PS_POLLED; | |
1305 | ||
1306 | spin_lock_bh(&conn->psq_lock); | |
1307 | psq_empty = skb_queue_empty(&conn->psq); | |
1308 | spin_unlock_bh(&conn->psq_lock); | |
1309 | ||
1310 | if (psq_empty) | |
1311 | ath6kl_wmi_set_pvb_cmd(ar->wmi, conn->aid, 0); | |
1312 | } | |
1313 | ||
1314 | void ath6kl_dtimexpiry_event(struct ath6kl *ar) | |
1315 | { | |
1316 | bool mcastq_empty = false; | |
1317 | struct sk_buff *skb; | |
59c98449 VT |
1318 | /* TODO: Pass vif instead of taking it from ar */ |
1319 | struct ath6kl_vif *vif = ar->vif; | |
bdcd8170 KV |
1320 | |
1321 | /* | |
1322 | * If there are no associated STAs, ignore the DTIM expiry event. | |
1323 | * There can be potential race conditions where the last associated | |
1324 | * STA may disconnect & before the host could clear the 'Indicate | |
1325 | * DTIM' request to the firmware, the firmware would have just | |
1326 | * indicated a DTIM expiry event. The race is between 'clear DTIM | |
1327 | * expiry cmd' going from the host to the firmware & the DTIM | |
1328 | * expiry event happening from the firmware to the host. | |
1329 | */ | |
1330 | if (!ar->sta_list_index) | |
1331 | return; | |
1332 | ||
1333 | spin_lock_bh(&ar->mcastpsq_lock); | |
1334 | mcastq_empty = skb_queue_empty(&ar->mcastpsq); | |
1335 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1336 | ||
1337 | if (mcastq_empty) | |
1338 | return; | |
1339 | ||
1340 | /* set the STA flag to dtim_expired for the frame to go out */ | |
59c98449 | 1341 | set_bit(DTIM_EXPIRED, &vif->flags); |
bdcd8170 KV |
1342 | |
1343 | spin_lock_bh(&ar->mcastpsq_lock); | |
1344 | while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) { | |
1345 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1346 | ||
1347 | ath6kl_data_tx(skb, ar->net_dev); | |
1348 | ||
1349 | spin_lock_bh(&ar->mcastpsq_lock); | |
1350 | } | |
1351 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1352 | ||
59c98449 | 1353 | clear_bit(DTIM_EXPIRED, &vif->flags); |
bdcd8170 KV |
1354 | |
1355 | /* clear the LSB of the BitMapCtl field of the TIM IE */ | |
1356 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); | |
1357 | } | |
1358 | ||
1359 | void ath6kl_disconnect_event(struct ath6kl *ar, u8 reason, u8 *bssid, | |
1360 | u8 assoc_resp_len, u8 *assoc_info, | |
1361 | u16 prot_reason_status) | |
1362 | { | |
59c98449 VT |
1363 | /* TODO: Findout vif instead of taking it from ar */ |
1364 | struct ath6kl_vif *vif = ar->vif; | |
1365 | ||
f5938f24 | 1366 | if (vif->nw_type == AP_NETWORK) { |
bdcd8170 KV |
1367 | if (!ath6kl_remove_sta(ar, bssid, prot_reason_status)) |
1368 | return; | |
1369 | ||
1370 | /* if no more associated STAs, empty the mcast PS q */ | |
1371 | if (ar->sta_list_index == 0) { | |
1372 | spin_lock_bh(&ar->mcastpsq_lock); | |
1373 | skb_queue_purge(&ar->mcastpsq); | |
1374 | spin_unlock_bh(&ar->mcastpsq_lock); | |
1375 | ||
1376 | /* clear the LSB of the TIM IE's BitMapCtl field */ | |
1377 | if (test_bit(WMI_READY, &ar->flag)) | |
1378 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); | |
1379 | } | |
1380 | ||
1381 | if (!is_broadcast_ether_addr(bssid)) { | |
1382 | /* send event to application */ | |
1383 | cfg80211_del_sta(ar->net_dev, bssid, GFP_KERNEL); | |
1384 | } | |
1385 | ||
151411e8 | 1386 | if (memcmp(ar->net_dev->dev_addr, bssid, ETH_ALEN) == 0) { |
6f2a73f9 | 1387 | memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list)); |
59c98449 | 1388 | clear_bit(CONNECTED, &vif->flags); |
151411e8 | 1389 | } |
bdcd8170 KV |
1390 | return; |
1391 | } | |
1392 | ||
1393 | ath6kl_cfg80211_disconnect_event(ar, reason, bssid, | |
1394 | assoc_resp_len, assoc_info, | |
1395 | prot_reason_status); | |
1396 | ||
2132c69c | 1397 | aggr_reset_state(vif->aggr_cntxt); |
bdcd8170 | 1398 | |
de3ad713 | 1399 | del_timer(&vif->disconnect_timer); |
bdcd8170 KV |
1400 | |
1401 | ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT, | |
1402 | "disconnect reason is %d\n", reason); | |
1403 | ||
1404 | /* | |
1405 | * If the event is due to disconnect cmd from the host, only they | |
1406 | * the target would stop trying to connect. Under any other | |
1407 | * condition, target would keep trying to connect. | |
1408 | */ | |
1409 | if (reason == DISCONNECT_CMD) { | |
1410 | if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag)) | |
1411 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); | |
1412 | } else { | |
59c98449 | 1413 | set_bit(CONNECT_PEND, &vif->flags); |
bdcd8170 KV |
1414 | if (((reason == ASSOC_FAILED) && |
1415 | (prot_reason_status == 0x11)) || | |
1416 | ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) | |
1417 | && (ar->reconnect_flag == 1))) { | |
59c98449 | 1418 | set_bit(CONNECTED, &vif->flags); |
bdcd8170 KV |
1419 | return; |
1420 | } | |
1421 | } | |
1422 | ||
bdcd8170 | 1423 | /* update connect & link status atomically */ |
151bd30b | 1424 | spin_lock_bh(&ar->lock); |
59c98449 | 1425 | clear_bit(CONNECTED, &vif->flags); |
bdcd8170 | 1426 | netif_carrier_off(ar->net_dev); |
151bd30b | 1427 | spin_unlock_bh(&ar->lock); |
bdcd8170 KV |
1428 | |
1429 | if ((reason != CSERV_DISCONNECT) || (ar->reconnect_flag != 1)) | |
1430 | ar->reconnect_flag = 0; | |
1431 | ||
1432 | if (reason != CSERV_DISCONNECT) | |
1433 | ar->user_key_ctrl = 0; | |
1434 | ||
1435 | netif_stop_queue(ar->net_dev); | |
8c8b65e3 | 1436 | memset(vif->bssid, 0, sizeof(vif->bssid)); |
f74bac54 | 1437 | vif->bss_ch = 0; |
bdcd8170 KV |
1438 | |
1439 | ath6kl_tx_data_cleanup(ar); | |
1440 | } | |
1441 | ||
1442 | static int ath6kl_open(struct net_device *dev) | |
1443 | { | |
1444 | struct ath6kl *ar = ath6kl_priv(dev); | |
59c98449 | 1445 | struct ath6kl_vif *vif = netdev_priv(dev); |
bdcd8170 | 1446 | |
151bd30b | 1447 | spin_lock_bh(&ar->lock); |
bdcd8170 | 1448 | |
59c98449 | 1449 | set_bit(WLAN_ENABLED, &vif->flags); |
bdcd8170 | 1450 | |
59c98449 | 1451 | if (test_bit(CONNECTED, &vif->flags)) { |
bdcd8170 KV |
1452 | netif_carrier_on(dev); |
1453 | netif_wake_queue(dev); | |
1454 | } else | |
1455 | netif_carrier_off(dev); | |
1456 | ||
151bd30b | 1457 | spin_unlock_bh(&ar->lock); |
bdcd8170 KV |
1458 | |
1459 | return 0; | |
1460 | } | |
1461 | ||
1462 | static int ath6kl_close(struct net_device *dev) | |
1463 | { | |
1464 | struct ath6kl *ar = ath6kl_priv(dev); | |
59c98449 | 1465 | struct ath6kl_vif *vif = netdev_priv(dev); |
bdcd8170 KV |
1466 | |
1467 | netif_stop_queue(dev); | |
1468 | ||
1469 | ath6kl_disconnect(ar); | |
1470 | ||
1471 | if (test_bit(WMI_READY, &ar->flag)) { | |
1472 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, | |
1473 | 0, 0, 0)) | |
1474 | return -EIO; | |
1475 | ||
59c98449 | 1476 | clear_bit(WLAN_ENABLED, &vif->flags); |
bdcd8170 KV |
1477 | } |
1478 | ||
1479 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); | |
1480 | ||
1481 | return 0; | |
1482 | } | |
1483 | ||
1484 | static struct net_device_stats *ath6kl_get_stats(struct net_device *dev) | |
1485 | { | |
1486 | struct ath6kl *ar = ath6kl_priv(dev); | |
1487 | ||
1488 | return &ar->net_stats; | |
1489 | } | |
1490 | ||
1491 | static struct net_device_ops ath6kl_netdev_ops = { | |
1492 | .ndo_open = ath6kl_open, | |
1493 | .ndo_stop = ath6kl_close, | |
1494 | .ndo_start_xmit = ath6kl_data_tx, | |
1495 | .ndo_get_stats = ath6kl_get_stats, | |
1496 | }; | |
1497 | ||
1498 | void init_netdev(struct net_device *dev) | |
1499 | { | |
1500 | dev->netdev_ops = &ath6kl_netdev_ops; | |
1501 | dev->watchdog_timeo = ATH6KL_TX_TIMEOUT; | |
1502 | ||
1503 | dev->needed_headroom = ETH_HLEN; | |
1504 | dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) + | |
1505 | sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH | |
1df94a85 | 1506 | + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES; |
bdcd8170 KV |
1507 | |
1508 | return; | |
1509 | } |