]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/suse-2.6.27.25/patches.drivers/staging-add-rt3070-wireless-driver.patch
Updated xen patches taken from suse.
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.drivers / staging-add-rt3070-wireless-driver.patch
1 From 74165ca9acb4060a4cd2de0095f4ff3f0885da3f Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@suse.de>
3 Date: Wed, 25 Feb 2009 16:14:55 -0800
4 Subject: Staging: add rt3070 wireless driver
5
6 From: Greg Kroah-Hartman <gregkh@suse.de>
7
8 This is the Ralink RT3070 driver from the company that does horrible
9 things like reading a config file from /etc. However, the driver that
10 is currently under development from the wireless development community
11 is not working at all yet, so distros and users are using this version
12 instead (quite common hardware on a lot of netbook machines).
13
14 So here is this driver, for now, until the wireless developers get a
15 "clean" version into the main tree, or until this version is cleaned up
16 sufficiently to move out of the staging tree.
17
18 Ported to the Linux build system, fixed lots of build issues, forward
19 ported to the current kernel version, and other minor cleanups were all
20 done by me.
21
22 Cc: Linux wireless <linux-wireless@vger.kernel.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
24
25 ---
26 drivers/staging/Kconfig | 2
27 drivers/staging/Makefile | 1
28 drivers/staging/rt3070/2870_main_dev.c | 1627 ++++
29 drivers/staging/rt3070/Kconfig | 6
30 drivers/staging/rt3070/Makefile | 47
31 drivers/staging/rt3070/action.h | 68
32 drivers/staging/rt3070/aironet.h | 210
33 drivers/staging/rt3070/ap.h | 557 +
34 drivers/staging/rt3070/chlist.h | 1253 +++
35 drivers/staging/rt3070/common/2870_rtmp_init.c | 1762 ++++
36 drivers/staging/rt3070/common/action.c | 1038 ++
37 drivers/staging/rt3070/common/ba_action.c | 1810 ++++
38 drivers/staging/rt3070/common/cmm_data.c | 2827 +++++++
39 drivers/staging/rt3070/common/cmm_data_2870.c | 980 ++
40 drivers/staging/rt3070/common/cmm_info.c | 3395 +++++++++
41 drivers/staging/rt3070/common/cmm_sanity.c | 1669 ++++
42 drivers/staging/rt3070/common/cmm_sync.c | 711 +
43 drivers/staging/rt3070/common/cmm_wpa.c | 1606 ++++
44 drivers/staging/rt3070/common/dfs.c | 441 +
45 drivers/staging/rt3070/common/eeprom.c | 1498 ++++
46 drivers/staging/rt3070/common/md5.c | 1427 +++
47 drivers/staging/rt3070/common/mlme.c | 9136 +++++++++++++++++++++++++
48 drivers/staging/rt3070/common/netif_block.c | 136
49 drivers/staging/rt3070/common/rtmp_init.c | 4197 +++++++++++
50 drivers/staging/rt3070/common/rtmp_tkip.c | 1613 ++++
51 drivers/staging/rt3070/common/rtmp_wep.c | 508 +
52 drivers/staging/rt3070/common/rtusb_bulk.c | 1382 +++
53 drivers/staging/rt3070/common/rtusb_data.c | 218
54 drivers/staging/rt3070/common/rtusb_io.c | 1908 +++++
55 drivers/staging/rt3070/common/spectrum.c | 1876 +++++
56 drivers/staging/rt3070/dfs.h | 100
57 drivers/staging/rt3070/firmware.h | 558 +
58 drivers/staging/rt3070/leap.h | 215
59 drivers/staging/rt3070/link_list.h | 134
60 drivers/staging/rt3070/md4.h | 42
61 drivers/staging/rt3070/md5.h | 107
62 drivers/staging/rt3070/mlme.h | 1468 ++++
63 drivers/staging/rt3070/netif_block.h | 58
64 drivers/staging/rt3070/oid.h | 1142 +++
65 drivers/staging/rt3070/rt2870.h | 756 ++
66 drivers/staging/rt3070/rt28xx.h | 2725 +++++++
67 drivers/staging/rt3070/rt_ate.c | 6506 +++++++++++++++++
68 drivers/staging/rt3070/rt_ate.h | 294
69 drivers/staging/rt3070/rt_config.h | 121
70 drivers/staging/rt3070/rt_linux.c | 1063 ++
71 drivers/staging/rt3070/rt_linux.h | 887 ++
72 drivers/staging/rt3070/rt_main_dev.c | 1800 ++++
73 drivers/staging/rt3070/rt_profile.c | 2041 +++++
74 drivers/staging/rt3070/rtmp.h | 7728 +++++++++++++++++++++
75 drivers/staging/rt3070/rtmp_ckipmic.h | 113
76 drivers/staging/rt3070/rtmp_def.h | 1559 ++++
77 drivers/staging/rt3070/rtmp_type.h | 95
78 drivers/staging/rt3070/spectrum.h | 322
79 drivers/staging/rt3070/spectrum_def.h | 95
80 drivers/staging/rt3070/sta/aironet.c | 1312 +++
81 drivers/staging/rt3070/sta/assoc.c | 2060 +++++
82 drivers/staging/rt3070/sta/auth.c | 475 +
83 drivers/staging/rt3070/sta/auth_rsp.c | 167
84 drivers/staging/rt3070/sta/connect.c | 2857 +++++++
85 drivers/staging/rt3070/sta/dls.c | 2170 +++++
86 drivers/staging/rt3070/sta/rtmp_data.c | 2637 +++++++
87 drivers/staging/rt3070/sta/sanity.c | 420 +
88 drivers/staging/rt3070/sta/sync.c | 1755 ++++
89 drivers/staging/rt3070/sta/wpa.c | 2099 +++++
90 drivers/staging/rt3070/sta_ioctl.c | 7203 +++++++++++++++++++
91 drivers/staging/rt3070/wpa.h | 356
92 66 files changed, 97349 insertions(+)
93
94 --- a/drivers/staging/Kconfig
95 +++ b/drivers/staging/Kconfig
96 @@ -51,6 +51,8 @@ source "drivers/staging/rt2860/Kconfig"
97
98 source "drivers/staging/rt2870/Kconfig"
99
100 +source "drivers/staging/rt3070/Kconfig"
101 +
102 source "drivers/staging/benet/Kconfig"
103
104 source "drivers/staging/rtl8187se/Kconfig"
105 --- a/drivers/staging/Makefile
106 +++ b/drivers/staging/Makefile
107 @@ -17,5 +17,6 @@ obj-$(CONFIG_AGNX) += agnx/
108 obj-$(CONFIG_OTUS) += otus/
109 obj-$(CONFIG_RT2860) += rt2860/
110 obj-$(CONFIG_RT2870) += rt2870/
111 +obj-$(CONFIG_RT3070) += rt3070/
112 obj-$(CONFIG_BENET) += benet/
113 obj-$(CONFIG_RTL8187SE) += rtl8187se/
114 --- /dev/null
115 +++ b/drivers/staging/rt3070/2870_main_dev.c
116 @@ -0,0 +1,1627 @@
117 +/*
118 + *************************************************************************
119 + * Ralink Tech Inc.
120 + * 5F., No.36, Taiyuan St., Jhubei City,
121 + * Hsinchu County 302,
122 + * Taiwan, R.O.C.
123 + *
124 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
125 + *
126 + * This program is free software; you can redistribute it and/or modify *
127 + * it under the terms of the GNU General Public License as published by *
128 + * the Free Software Foundation; either version 2 of the License, or *
129 + * (at your option) any later version. *
130 + * *
131 + * This program is distributed in the hope that it will be useful, *
132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
134 + * GNU General Public License for more details. *
135 + * *
136 + * You should have received a copy of the GNU General Public License *
137 + * along with this program; if not, write to the *
138 + * Free Software Foundation, Inc., *
139 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
140 + * *
141 + *************************************************************************
142 +
143 + Module Name:
144 + rtmp_main.c
145 +
146 + Abstract:
147 + main initialization routines
148 +
149 + Revision History:
150 + Who When What
151 + -------- ---------- ----------------------------------------------
152 + Name Date Modification logs
153 + Jan Lee 01-10-2005 modified
154 + Sample Jun/01/07 Merge RT2870 and RT2860 drivers.
155 +*/
156 +
157 +#include "rt_config.h"
158 +
159 +
160 +// Following information will be show when you run 'modinfo'
161 +// *** If you have a solution for the bug in current version of driver, please mail to me.
162 +// Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. ***
163 +MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
164 +MODULE_DESCRIPTION("RT2870 Wireless Lan Linux Driver");
165 +#ifdef CONFIG_STA_SUPPORT
166 +MODULE_LICENSE("GPL");
167 +#ifdef MODULE_VERSION
168 +MODULE_VERSION(STA_DRIVER_VERSION);
169 +#endif
170 +#endif // CONFIG_STA_SUPPORT //
171 +
172 +#ifdef MULTIPLE_CARD_SUPPORT
173 +// record whether the card in the card list is used in the card file
174 +extern UINT8 MC_CardUsed[];
175 +#endif // MULTIPLE_CARD_SUPPORT //
176 +
177 +/* Kernel thread and vars, which handles packets that are completed. Only
178 + * packets that have a "complete" function are sent here. This way, the
179 + * completion is run out of kernel context, and doesn't block the rest of
180 + * the stack. */
181 +//static int mlme_kill = 0; // Mlme kernel thread
182 +//static int RTUSBCmd_kill = 0; // Command kernel thread
183 +//static int TimerFunc_kill = 0; // TimerQ kernel thread
184 +
185 +//static wait_queue_head_t timerWaitQ;
186 +//static wait_queue_t waitQ;
187 +
188 +extern INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
189 + IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
190 +
191 +
192 +/* module table */
193 +struct usb_device_id rtusb_usb_id[] = RT2870_USB_DEVICES;
194 +INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
195 +MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
196 +
197 +#ifndef PF_NOFREEZE
198 +#define PF_NOFREEZE 0
199 +#endif
200 +
201 +
202 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
203 +
204 +/**************************************************************************/
205 +/**************************************************************************/
206 +//tested for kernel 2.4 series
207 +/**************************************************************************/
208 +/**************************************************************************/
209 +static void *rtusb_probe(struct usb_device *dev, UINT interface,
210 + const struct usb_device_id *id_table);
211 +static void rtusb_disconnect(struct usb_device *dev, void *ptr);
212 +
213 +struct usb_driver rtusb_driver = {
214 + name:"rt2870",
215 + probe:rtusb_probe,
216 + disconnect:rtusb_disconnect,
217 + id_table:rtusb_usb_id,
218 + };
219 +
220 +#else
221 +
222 +#ifdef CONFIG_PM
223 +static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
224 +static int rt2870_resume(struct usb_interface *intf);
225 +#endif // CONFIG_PM //
226 +
227 +/**************************************************************************/
228 +/**************************************************************************/
229 +//tested for kernel 2.6series
230 +/**************************************************************************/
231 +/**************************************************************************/
232 +static int rtusb_probe (struct usb_interface *intf,
233 + const struct usb_device_id *id);
234 +static void rtusb_disconnect(struct usb_interface *intf);
235 +
236 +struct usb_driver rtusb_driver = {
237 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
238 + .owner = THIS_MODULE,
239 +#endif
240 + .name="rt2870",
241 + .probe=rtusb_probe,
242 + .disconnect=rtusb_disconnect,
243 + .id_table=rtusb_usb_id,
244 +
245 +#ifdef CONFIG_PM
246 + suspend: rt2870_suspend,
247 + resume: rt2870_resume,
248 +#endif
249 + };
250 +
251 +#ifdef CONFIG_PM
252 +
253 +VOID RT2860RejectPendingPackets(
254 + IN PRTMP_ADAPTER pAd)
255 +{
256 + // clear PS packets
257 + // clear TxSw packets
258 +}
259 +
260 +static int rt2870_suspend(
261 + struct usb_interface *intf,
262 + pm_message_t state)
263 +{
264 + struct net_device *net_dev;
265 + PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
266 +
267 +
268 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
269 + net_dev = pAd->net_dev;
270 + netif_device_detach(net_dev);
271 +
272 + pAd->PM_FlgSuspend = 1;
273 + if (netif_running(net_dev)) {
274 + RTUSBCancelPendingBulkInIRP(pAd);
275 + RTUSBCancelPendingBulkOutIRP(pAd);
276 + }
277 + DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
278 + return 0;
279 +}
280 +
281 +static int rt2870_resume(
282 + struct usb_interface *intf)
283 +{
284 + struct net_device *net_dev;
285 + PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
286 +
287 +
288 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
289 +
290 + pAd->PM_FlgSuspend = 0;
291 + net_dev = pAd->net_dev;
292 + netif_device_attach(net_dev);
293 + netif_start_queue(net_dev);
294 + netif_carrier_on(net_dev);
295 + netif_wake_queue(net_dev);
296 +
297 + DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
298 + return 0;
299 +}
300 +#endif // CONFIG_PM //
301 +#endif // LINUX_VERSION_CODE //
302 +
303 +
304 +// Init driver module
305 +INT __init rtusb_init(void)
306 +{
307 + printk("rtusb init --->\n");
308 + return usb_register(&rtusb_driver);
309 +}
310 +
311 +// Deinit driver module
312 +VOID __exit rtusb_exit(void)
313 +{
314 + usb_deregister(&rtusb_driver);
315 + printk("<--- rtusb exit\n");
316 +}
317 +
318 +module_init(rtusb_init);
319 +module_exit(rtusb_exit);
320 +
321 +
322 +
323 +
324 +/*--------------------------------------------------------------------- */
325 +/* function declarations */
326 +/*--------------------------------------------------------------------- */
327 +
328 +/*
329 +========================================================================
330 +Routine Description:
331 + MLME kernel thread.
332 +
333 +Arguments:
334 + *Context the pAd, driver control block pointer
335 +
336 +Return Value:
337 + 0 close the thread
338 +
339 +Note:
340 +========================================================================
341 +*/
342 +INT MlmeThread(
343 + IN void *Context)
344 +{
345 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
346 + POS_COOKIE pObj;
347 + int status;
348 +
349 + pObj = (POS_COOKIE)pAd->OS_Cookie;
350 +
351 + rtmp_os_thread_init("rt2870MlmeThread", (PVOID)&(pAd->mlmeComplete));
352 +
353 + while (pAd->mlme_kill == 0)
354 + {
355 + /* lock the device pointers */
356 + //down(&(pAd->mlme_semaphore));
357 + status = down_interruptible(&(pAd->mlme_semaphore));
358 +
359 + /* lock the device pointers , need to check if required*/
360 + //down(&(pAd->usbdev_semaphore));
361 +
362 + if (!pAd->PM_FlgSuspend)
363 + MlmeHandler(pAd);
364 +
365 + /* unlock the device pointers */
366 + //up(&(pAd->usbdev_semaphore));
367 + if (status != 0)
368 + {
369 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
370 + break;
371 + }
372 + }
373 +
374 + /* notify the exit routine that we're actually exiting now
375 + *
376 + * complete()/wait_for_completion() is similar to up()/down(),
377 + * except that complete() is safe in the case where the structure
378 + * is getting deleted in a parallel mode of execution (i.e. just
379 + * after the down() -- that's necessary for the thread-shutdown
380 + * case.
381 + *
382 + * complete_and_exit() goes even further than this -- it is safe in
383 + * the case that the thread of the caller is going away (not just
384 + * the structure) -- this is necessary for the module-remove case.
385 + * This is important in preemption kernels, which transfer the flow
386 + * of execution immediately upon a complete().
387 + */
388 + DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__FUNCTION__));
389 +
390 + pObj->MLMEThr_pid = NULL;
391 +
392 + complete_and_exit (&pAd->mlmeComplete, 0);
393 + return 0;
394 +
395 +}
396 +
397 +
398 +/*
399 +========================================================================
400 +Routine Description:
401 + USB command kernel thread.
402 +
403 +Arguments:
404 + *Context the pAd, driver control block pointer
405 +
406 +Return Value:
407 + 0 close the thread
408 +
409 +Note:
410 +========================================================================
411 +*/
412 +INT RTUSBCmdThread(
413 + IN void * Context)
414 +{
415 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
416 + POS_COOKIE pObj;
417 + int status;
418 +
419 + pObj = (POS_COOKIE)pAd->OS_Cookie;
420 +
421 + rtmp_os_thread_init("rt2870CmdThread", (PVOID)&(pAd->CmdQComplete));
422 +
423 + NdisAcquireSpinLock(&pAd->CmdQLock);
424 + pAd->CmdQ.CmdQState = RT2870_THREAD_RUNNING;
425 + NdisReleaseSpinLock(&pAd->CmdQLock);
426 +
427 + while (pAd->CmdQ.CmdQState == RT2870_THREAD_RUNNING)
428 + {
429 + /* lock the device pointers */
430 + //down(&(pAd->RTUSBCmd_semaphore));
431 + status = down_interruptible(&(pAd->RTUSBCmd_semaphore));
432 +
433 + if (pAd->CmdQ.CmdQState == RT2870_THREAD_STOPED)
434 + break;
435 +
436 + if (status != 0)
437 + {
438 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
439 + break;
440 + }
441 + /* lock the device pointers , need to check if required*/
442 + //down(&(pAd->usbdev_semaphore));
443 +
444 + if (!pAd->PM_FlgSuspend)
445 + CMDHandler(pAd);
446 +
447 + /* unlock the device pointers */
448 + //up(&(pAd->usbdev_semaphore));
449 + }
450 +
451 + if (!pAd->PM_FlgSuspend)
452 + { // Clear the CmdQElements.
453 + CmdQElmt *pCmdQElmt = NULL;
454 +
455 + NdisAcquireSpinLock(&pAd->CmdQLock);
456 + pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
457 + while(pAd->CmdQ.size)
458 + {
459 + RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
460 + if (pCmdQElmt)
461 + {
462 + if (pCmdQElmt->CmdFromNdis == TRUE)
463 + {
464 + if (pCmdQElmt->buffer != NULL)
465 + NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
466 +
467 + NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
468 + }
469 + else
470 + {
471 + if ((pCmdQElmt->buffer != NULL) && (pCmdQElmt->bufferlength != 0))
472 + NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
473 + {
474 + NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
475 + }
476 + }
477 + }
478 + }
479 +
480 + NdisReleaseSpinLock(&pAd->CmdQLock);
481 + }
482 + /* notify the exit routine that we're actually exiting now
483 + *
484 + * complete()/wait_for_completion() is similar to up()/down(),
485 + * except that complete() is safe in the case where the structure
486 + * is getting deleted in a parallel mode of execution (i.e. just
487 + * after the down() -- that's necessary for the thread-shutdown
488 + * case.
489 + *
490 + * complete_and_exit() goes even further than this -- it is safe in
491 + * the case that the thread of the caller is going away (not just
492 + * the structure) -- this is necessary for the module-remove case.
493 + * This is important in preemption kernels, which transfer the flow
494 + * of execution immediately upon a complete().
495 + */
496 + DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
497 +
498 + pObj->RTUSBCmdThr_pid = NULL;
499 +
500 + complete_and_exit (&pAd->CmdQComplete, 0);
501 + return 0;
502 +
503 +}
504 +
505 +
506 +static void RT2870_TimerQ_Handle(RTMP_ADAPTER *pAd)
507 +{
508 + int status;
509 + RALINK_TIMER_STRUCT *pTimer;
510 + RT2870_TIMER_ENTRY *pEntry;
511 + unsigned long irqFlag;
512 +
513 + while(!pAd->TimerFunc_kill)
514 + {
515 +// printk("waiting for event!\n");
516 + pTimer = NULL;
517 +
518 + status = down_interruptible(&(pAd->RTUSBTimer_semaphore));
519 +
520 + if (pAd->TimerQ.status == RT2870_THREAD_STOPED)
521 + break;
522 +
523 + // event happened.
524 + while(pAd->TimerQ.pQHead)
525 + {
526 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlag);
527 + pEntry = pAd->TimerQ.pQHead;
528 + if (pEntry)
529 + {
530 + pTimer = pEntry->pRaTimer;
531 +
532 + // update pQHead
533 + pAd->TimerQ.pQHead = pEntry->pNext;
534 + if (pEntry == pAd->TimerQ.pQTail)
535 + pAd->TimerQ.pQTail = NULL;
536 +
537 + // return this queue entry to timerQFreeList.
538 + pEntry->pNext = pAd->TimerQ.pQPollFreeList;
539 + pAd->TimerQ.pQPollFreeList = pEntry;
540 + }
541 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlag);
542 +
543 + if (pTimer)
544 + {
545 + if (pTimer->handle != NULL)
546 + if (!pAd->PM_FlgSuspend)
547 + pTimer->handle(NULL, (PVOID) pTimer->cookie, NULL, pTimer);
548 + if ((pTimer->Repeat) && (pTimer->State == FALSE))
549 + RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue);
550 + }
551 + }
552 +
553 + if (status != 0)
554 + {
555 + pAd->TimerQ.status = RT2870_THREAD_STOPED;
556 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
557 + break;
558 + }
559 + }
560 +}
561 +
562 +
563 +INT TimerQThread(
564 + IN OUT PVOID Context)
565 +{
566 + PRTMP_ADAPTER pAd;
567 + POS_COOKIE pObj;
568 +
569 + pAd = (PRTMP_ADAPTER)Context;
570 + pObj = (POS_COOKIE) pAd->OS_Cookie;
571 +
572 + rtmp_os_thread_init("rt2870TimerQHandle", (PVOID)&(pAd->TimerQComplete));
573 +
574 + RT2870_TimerQ_Handle(pAd);
575 +
576 + /* notify the exit routine that we're actually exiting now
577 + *
578 + * complete()/wait_for_completion() is similar to up()/down(),
579 + * except that complete() is safe in the case where the structure
580 + * is getting deleted in a parallel mode of execution (i.e. just
581 + * after the down() -- that's necessary for the thread-shutdown
582 + * case.
583 + *
584 + * complete_and_exit() goes even further than this -- it is safe in
585 + * the case that the thread of the caller is going away (not just
586 + * the structure) -- this is necessary for the module-remove case.
587 + * This is important in preemption kernels, which transfer the flow
588 + * of execution immediately upon a complete().
589 + */
590 + DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__FUNCTION__));
591 +
592 + pObj->TimerQThr_pid = NULL;
593 +
594 + complete_and_exit(&pAd->TimerQComplete, 0);
595 + return 0;
596 +
597 +}
598 +
599 +
600 +RT2870_TIMER_ENTRY *RT2870_TimerQ_Insert(
601 + IN RTMP_ADAPTER *pAd,
602 + IN RALINK_TIMER_STRUCT *pTimer)
603 +{
604 + RT2870_TIMER_ENTRY *pQNode = NULL, *pQTail;
605 + unsigned long irqFlags;
606 +
607 +
608 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
609 + if (pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)
610 + {
611 + if(pAd->TimerQ.pQPollFreeList)
612 + {
613 + pQNode = pAd->TimerQ.pQPollFreeList;
614 + pAd->TimerQ.pQPollFreeList = pQNode->pNext;
615 +
616 + pQNode->pRaTimer = pTimer;
617 + pQNode->pNext = NULL;
618 +
619 + pQTail = pAd->TimerQ.pQTail;
620 + if (pAd->TimerQ.pQTail != NULL)
621 + pQTail->pNext = pQNode;
622 + pAd->TimerQ.pQTail = pQNode;
623 + if (pAd->TimerQ.pQHead == NULL)
624 + pAd->TimerQ.pQHead = pQNode;
625 + }
626 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
627 +
628 + if (pQNode)
629 + up(&pAd->RTUSBTimer_semaphore);
630 + //wake_up(&timerWaitQ);
631 + }
632 + else
633 + {
634 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
635 + }
636 + return pQNode;
637 +}
638 +
639 +
640 +BOOLEAN RT2870_TimerQ_Remove(
641 + IN RTMP_ADAPTER *pAd,
642 + IN RALINK_TIMER_STRUCT *pTimer)
643 +{
644 + RT2870_TIMER_ENTRY *pNode, *pPrev = NULL;
645 + unsigned long irqFlags;
646 +
647 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
648 + if (pAd->TimerQ.status >= RT2870_THREAD_INITED)
649 + {
650 + pNode = pAd->TimerQ.pQHead;
651 + while (pNode)
652 + {
653 + if (pNode->pRaTimer == pTimer)
654 + break;
655 + pPrev = pNode;
656 + pNode = pNode->pNext;
657 + }
658 +
659 + // Now move it to freeList queue.
660 + if (pNode)
661 + {
662 + if (pNode == pAd->TimerQ.pQHead)
663 + pAd->TimerQ.pQHead = pNode->pNext;
664 + if (pNode == pAd->TimerQ.pQTail)
665 + pAd->TimerQ.pQTail = pPrev;
666 + if (pPrev != NULL)
667 + pPrev->pNext = pNode->pNext;
668 +
669 + // return this queue entry to timerQFreeList.
670 + pNode->pNext = pAd->TimerQ.pQPollFreeList;
671 + pAd->TimerQ.pQPollFreeList = pNode;
672 + }
673 + }
674 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
675 +
676 + return TRUE;
677 +}
678 +
679 +
680 +void RT2870_TimerQ_Exit(RTMP_ADAPTER *pAd)
681 +{
682 + RT2870_TIMER_ENTRY *pTimerQ;
683 + unsigned long irqFlags;
684 +
685 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
686 + while (pAd->TimerQ.pQHead)
687 + {
688 + pTimerQ = pAd->TimerQ.pQHead;
689 + pAd->TimerQ.pQHead = pTimerQ->pNext;
690 + // remove the timeQ
691 + }
692 + pAd->TimerQ.pQPollFreeList = NULL;
693 + os_free_mem(pAd, pAd->TimerQ.pTimerQPoll);
694 + pAd->TimerQ.pQTail = NULL;
695 + pAd->TimerQ.pQHead = NULL;
696 + pAd->TimerQ.status = RT2870_THREAD_STOPED;
697 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
698 +
699 +}
700 +
701 +
702 +void RT2870_TimerQ_Init(RTMP_ADAPTER *pAd)
703 +{
704 + int i;
705 + RT2870_TIMER_ENTRY *pQNode, *pEntry;
706 + unsigned long irqFlags;
707 +
708 + NdisAllocateSpinLock(&pAd->TimerQLock);
709 +
710 + RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
711 + NdisZeroMemory(&pAd->TimerQ, sizeof(pAd->TimerQ));
712 + //InterlockedExchange(&pAd->TimerQ.count, 0);
713 +
714 + /* Initialise the wait q head */
715 + //init_waitqueue_head(&timerWaitQ);
716 +
717 + os_alloc_mem(pAd, &pAd->TimerQ.pTimerQPoll, sizeof(RT2870_TIMER_ENTRY) * TIMER_QUEUE_SIZE_MAX);
718 + if (pAd->TimerQ.pTimerQPoll)
719 + {
720 + pEntry = NULL;
721 + pQNode = (RT2870_TIMER_ENTRY *)pAd->TimerQ.pTimerQPoll;
722 + for (i = 0 ;i <TIMER_QUEUE_SIZE_MAX; i++)
723 + {
724 + pQNode->pNext = pEntry;
725 + pEntry = pQNode;
726 + pQNode++;
727 + }
728 + pAd->TimerQ.pQPollFreeList = pEntry;
729 + pAd->TimerQ.pQHead = NULL;
730 + pAd->TimerQ.pQTail = NULL;
731 + pAd->TimerQ.status = RT2870_THREAD_INITED;
732 + }
733 + RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
734 +}
735 +
736 +
737 +VOID RT2870_WatchDog(IN RTMP_ADAPTER *pAd)
738 +{
739 + PHT_TX_CONTEXT pHTTXContext;
740 + int idx;
741 + ULONG irqFlags;
742 + PURB pUrb;
743 + BOOLEAN needDumpSeq = FALSE;
744 + UINT32 MACValue;
745 +
746 +
747 + idx = 0;
748 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
749 + if ((MACValue & 0xff) !=0 )
750 + {
751 + DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 0 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
752 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
753 + while((MACValue &0xff) != 0 && (idx++ < 10))
754 + {
755 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
756 + NdisMSleep(1);
757 + }
758 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
759 + }
760 +
761 +//PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
762 +#ifdef CONFIG_STA_SUPPORT
763 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
764 + {
765 + idx = 0;
766 + if ((MACValue & 0xff00) !=0 )
767 + {
768 + DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 1 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
769 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf4000a);
770 + while((MACValue &0xff00) != 0 && (idx++ < 10))
771 + {
772 + RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
773 + NdisMSleep(1);
774 + }
775 + RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
776 + }
777 + }
778 +#endif // CONFIG_STA_SUPPORT //
779 +
780 + if (pAd->watchDogRxOverFlowCnt >= 2)
781 + {
782 + DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
783 + if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
784 + fRTMP_ADAPTER_BULKIN_RESET |
785 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
786 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
787 + {
788 + DBGPRINT(RT_DEBUG_TRACE, ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
789 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
790 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
791 + needDumpSeq = TRUE;
792 + }
793 + pAd->watchDogRxOverFlowCnt = 0;
794 + }
795 +
796 +
797 + for (idx = 0; idx < NUM_OF_TX_RING; idx++)
798 + {
799 + pUrb = NULL;
800 +
801 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
802 + if ((pAd->BulkOutPending[idx] == TRUE) && pAd->watchDogTxPendingCnt)
803 + {
804 + pAd->watchDogTxPendingCnt[idx]++;
805 +
806 + if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
807 + (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_BULKOUT_RESET)))
808 + )
809 + {
810 + // FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it!
811 + pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[idx]);
812 + if (pHTTXContext->IRPPending)
813 + { // Check TxContext.
814 + pUrb = pHTTXContext->pUrb;
815 + }
816 + else if (idx == MGMTPIPEIDX)
817 + {
818 + PTX_CONTEXT pMLMEContext, pNULLContext, pPsPollContext;
819 +
820 + //Check MgmtContext.
821 + pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
822 + pPsPollContext = (PTX_CONTEXT)(&pAd->PsPollContext);
823 + pNULLContext = (PTX_CONTEXT)(&pAd->NullContext);
824 +
825 + if (pMLMEContext->IRPPending)
826 + {
827 + ASSERT(pMLMEContext->IRPPending);
828 + pUrb = pMLMEContext->pUrb;
829 + }
830 + else if (pNULLContext->IRPPending)
831 + {
832 + ASSERT(pNULLContext->IRPPending);
833 + pUrb = pNULLContext->pUrb;
834 + }
835 + else if (pPsPollContext->IRPPending)
836 + {
837 + ASSERT(pPsPollContext->IRPPending);
838 + pUrb = pPsPollContext->pUrb;
839 + }
840 + }
841 +
842 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
843 +
844 + DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n", idx));
845 + if (pUrb)
846 + {
847 + DBGPRINT(RT_DEBUG_TRACE, ("Unlink the pending URB!\n"));
848 + // unlink it now
849 + RTUSB_UNLINK_URB(pUrb);
850 + // Sleep 200 microseconds to give cancellation time to work
851 + RTMPusecDelay(200);
852 + needDumpSeq = TRUE;
853 + }
854 + else
855 + {
856 + DBGPRINT(RT_DEBUG_ERROR, ("Unkonw bulkOut URB maybe hanged!!!!!!!!!!!!\n"));
857 + }
858 + }
859 + else
860 + {
861 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
862 + }
863 + }
864 + else
865 + {
866 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
867 + }
868 + }
869 +
870 +#ifdef DOT11_N_SUPPORT
871 + // For Sigma debug, dump the ba_reordering sequence.
872 + if((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0))
873 + {
874 + USHORT Idx;
875 + PBA_REC_ENTRY pBAEntry = NULL;
876 + UCHAR count = 0;
877 + struct reordering_mpdu *mpdu_blk;
878 +
879 + Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
880 +
881 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
882 + if((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL))
883 + {
884 + DBGPRINT(RT_DEBUG_TRACE, ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
885 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
886 + mpdu_blk = pBAEntry->list.next;
887 + while (mpdu_blk)
888 + {
889 + DBGPRINT(RT_DEBUG_TRACE, ("\t%d:Seq-%d, bAMSDU-%d!\n", count, mpdu_blk->Sequence, mpdu_blk->bAMSDU));
890 + mpdu_blk = mpdu_blk->next;
891 + count++;
892 + }
893 +
894 + DBGPRINT(RT_DEBUG_TRACE, ("\npBAEntry->LastIndSeq=%d!\n", pBAEntry->LastIndSeq));
895 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
896 + }
897 + }
898 +#endif // DOT11_N_SUPPORT //
899 +}
900 +
901 +/*
902 +========================================================================
903 +Routine Description:
904 + Release allocated resources.
905 +
906 +Arguments:
907 + *dev Point to the PCI or USB device
908 + pAd driver control block pointer
909 +
910 +Return Value:
911 + None
912 +
913 +Note:
914 +========================================================================
915 +*/
916 +static void _rtusb_disconnect(struct usb_device *dev, PRTMP_ADAPTER pAd)
917 +{
918 + struct net_device *net_dev = NULL;
919 +
920 +
921 + DBGPRINT(RT_DEBUG_ERROR, ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
922 + dev->bus->bus_name, dev->devpath));
923 + if (!pAd)
924 + {
925 +#ifdef MULTIPLE_CARD_SUPPORT
926 + if ((pAd->MC_RowID >= 0) && (pAd->MC_RowID <= MAX_NUM_OF_MULTIPLE_CARD))
927 + MC_CardUsed[pAd->MC_RowID] = 0; // not clear MAC address
928 +#endif // MULTIPLE_CARD_SUPPORT //
929 +
930 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
931 + while(MOD_IN_USE > 0)
932 + {
933 + MOD_DEC_USE_COUNT;
934 + }
935 +#else
936 + usb_put_dev(dev);
937 +#endif // LINUX_VERSION_CODE //
938 +
939 + printk("rtusb_disconnect: pAd == NULL!\n");
940 + return;
941 + }
942 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
943 +
944 +
945 +
946 + // for debug, wait to show some messages to /proc system
947 + udelay(1);
948 +
949 +
950 +
951 +
952 + net_dev = pAd->net_dev;
953 + if (pAd->net_dev != NULL)
954 + {
955 + printk("rtusb_disconnect: unregister_netdev(), dev->name=%s!\n", net_dev->name);
956 + unregister_netdev (pAd->net_dev);
957 + }
958 + udelay(1);
959 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
960 +#else
961 + flush_scheduled_work();
962 +#endif // LINUX_VERSION_CODE //
963 + udelay(1);
964 +
965 + // free net_device memory
966 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
967 + kfree(net_dev);
968 +#else
969 + free_netdev(net_dev);
970 +#endif // LINUX_VERSION_CODE //
971 +
972 + // free adapter memory
973 + RTMPFreeAdapter(pAd);
974 +
975 + // release a use of the usb device structure
976 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
977 + while(MOD_IN_USE > 0)
978 + {
979 + MOD_DEC_USE_COUNT;
980 + }
981 +#else
982 + usb_put_dev(dev);
983 +#endif // LINUX_VERSION_CODE //
984 + udelay(1);
985 +
986 + DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
987 +}
988 +
989 +
990 +/*
991 +========================================================================
992 +Routine Description:
993 + Probe RT28XX chipset.
994 +
995 +Arguments:
996 + *dev Point to the PCI or USB device
997 + interface
998 + *id_table Point to the PCI or USB device ID
999 +
1000 +Return Value:
1001 + None
1002 +
1003 +Note:
1004 +========================================================================
1005 +*/
1006 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1007 +static void *rtusb_probe(struct usb_device *dev, UINT interface,
1008 + const struct usb_device_id *id)
1009 +{
1010 + PRTMP_ADAPTER pAd;
1011 + rt28xx_probe((void *)dev, (void *)id, interface, &pAd);
1012 + return (void *)pAd;
1013 +}
1014 +
1015 +//Disconnect function is called within exit routine
1016 +static void rtusb_disconnect(struct usb_device *dev, void *ptr)
1017 +{
1018 + _rtusb_disconnect(dev, ((PRTMP_ADAPTER)ptr));
1019 +}
1020 +
1021 +#else /* kernel 2.6 series */
1022 +static int rtusb_probe (struct usb_interface *intf,
1023 + const struct usb_device_id *id)
1024 +{
1025 + PRTMP_ADAPTER pAd;
1026 + return (int)rt28xx_probe((void *)intf, (void *)id, 0, &pAd);
1027 +}
1028 +
1029 +
1030 +static void rtusb_disconnect(struct usb_interface *intf)
1031 +{
1032 + struct usb_device *dev = interface_to_usbdev(intf);
1033 + PRTMP_ADAPTER pAd;
1034 +
1035 +
1036 + pAd = usb_get_intfdata(intf);
1037 + usb_set_intfdata(intf, NULL);
1038 +
1039 + _rtusb_disconnect(dev, pAd);
1040 +}
1041 +#endif // LINUX_VERSION_CODE //
1042 +
1043 +
1044 +/*
1045 +========================================================================
1046 +Routine Description:
1047 + Close kernel threads.
1048 +
1049 +Arguments:
1050 + *pAd the raxx interface data pointer
1051 +
1052 +Return Value:
1053 + NONE
1054 +
1055 +Note:
1056 +========================================================================
1057 +*/
1058 +VOID RT28xxThreadTerminate(
1059 + IN RTMP_ADAPTER *pAd)
1060 +{
1061 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
1062 + INT ret;
1063 +
1064 +
1065 + // Sleep 50 milliseconds so pending io might finish normally
1066 + RTMPusecDelay(50000);
1067 +
1068 + // We want to wait until all pending receives and sends to the
1069 + // device object. We cancel any
1070 + // irps. Wait until sends and receives have stopped.
1071 + RTUSBCancelPendingIRPs(pAd);
1072 +
1073 + // Terminate Threads
1074 + if (pObj->MLMEThr_pid)
1075 + {
1076 + printk("Terminate the MLMEThr_pid=%d!\n", pid_nr(pObj->MLMEThr_pid));
1077 + mb();
1078 + pAd->mlme_kill = 1;
1079 + //RT28XX_MLME_HANDLER(pAd);
1080 + mb();
1081 + ret = kill_pid(pObj->MLMEThr_pid, SIGTERM, 1);
1082 + if (ret)
1083 + {
1084 + printk (KERN_WARNING "%s: unable to Mlme thread, pid=%d, ret=%d!\n",
1085 + pAd->net_dev->name, pid_nr(pObj->MLMEThr_pid), ret);
1086 + }
1087 + else
1088 + {
1089 + //wait_for_completion (&pAd->notify);
1090 + wait_for_completion (&pAd->mlmeComplete);
1091 + pObj->MLMEThr_pid = NULL;
1092 + }
1093 + }
1094 +
1095 + if (pObj->RTUSBCmdThr_pid >= 0)
1096 + {
1097 + printk("Terminate the RTUSBCmdThr_pid=%d!\n", pid_nr(pObj->RTUSBCmdThr_pid));
1098 + mb();
1099 + NdisAcquireSpinLock(&pAd->CmdQLock);
1100 + pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
1101 + NdisReleaseSpinLock(&pAd->CmdQLock);
1102 + mb();
1103 + //RTUSBCMDUp(pAd);
1104 + ret = kill_pid(pObj->RTUSBCmdThr_pid, SIGTERM, 1);
1105 + if (ret)
1106 + {
1107 + printk(KERN_WARNING "%s: unable to RTUSBCmd thread, pid=%d, ret=%d!\n",
1108 + pAd->net_dev->name, pid_nr(pObj->RTUSBCmdThr_pid), ret);
1109 + }
1110 + else
1111 + {
1112 + //wait_for_completion (&pAd->notify);
1113 + wait_for_completion (&pAd->CmdQComplete);
1114 + pObj->RTUSBCmdThr_pid = NULL;
1115 + }
1116 + }
1117 + if (pObj->TimerQThr_pid >= 0)
1118 + {
1119 + POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;
1120 +
1121 + printk("Terminate the TimerQThr_pid=%d!\n", pid_nr(pObj->TimerQThr_pid));
1122 + mb();
1123 + pAd->TimerFunc_kill = 1;
1124 + mb();
1125 + ret = kill_pid(pObj->TimerQThr_pid, SIGTERM, 1);
1126 + if (ret)
1127 + {
1128 + printk(KERN_WARNING "%s: unable to stop TimerQThread, pid=%d, ret=%d!\n",
1129 + pAd->net_dev->name, pid_nr(pObj->TimerQThr_pid), ret);
1130 + }
1131 + else
1132 + {
1133 + printk("wait_for_completion TimerQThr\n");
1134 + wait_for_completion(&pAd->TimerQComplete);
1135 + pObj->TimerQThr_pid = NULL;
1136 + }
1137 + }
1138 + // Kill tasklets
1139 + pAd->mlme_kill = 0;
1140 + pAd->CmdQ.CmdQState = RT2870_THREAD_UNKNOWN;
1141 + pAd->TimerFunc_kill = 0;
1142 +}
1143 +
1144 +
1145 +void kill_thread_task(IN PRTMP_ADAPTER pAd)
1146 +{
1147 + POS_COOKIE pObj;
1148 +
1149 + pObj = (POS_COOKIE) pAd->OS_Cookie;
1150 +
1151 + tasklet_kill(&pObj->rx_done_task);
1152 + tasklet_kill(&pObj->mgmt_dma_done_task);
1153 + tasklet_kill(&pObj->ac0_dma_done_task);
1154 + tasklet_kill(&pObj->ac1_dma_done_task);
1155 + tasklet_kill(&pObj->ac2_dma_done_task);
1156 + tasklet_kill(&pObj->ac3_dma_done_task);
1157 + tasklet_kill(&pObj->hcca_dma_done_task);
1158 + tasklet_kill(&pObj->tbtt_task);
1159 +
1160 +}
1161 +
1162 +
1163 +/*
1164 +========================================================================
1165 +Routine Description:
1166 + Check the chipset vendor/product ID.
1167 +
1168 +Arguments:
1169 + _dev_p Point to the PCI or USB device
1170 +
1171 +Return Value:
1172 + TRUE Check ok
1173 + FALSE Check fail
1174 +
1175 +Note:
1176 +========================================================================
1177 +*/
1178 +BOOLEAN RT28XXChipsetCheck(
1179 + IN void *_dev_p)
1180 +{
1181 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1182 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1183 +#else
1184 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1185 + struct usb_device *dev_p = interface_to_usbdev(intf);
1186 +#endif // LINUX_VERSION_CODE //
1187 + UINT32 i;
1188 +
1189 +
1190 + for(i=0; i<rtusb_usb_id_len; i++)
1191 + {
1192 + if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
1193 + dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
1194 + {
1195 + printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
1196 + dev_p->descriptor.idVendor, dev_p->descriptor.idProduct);
1197 + break;
1198 + }
1199 + }
1200 +
1201 + if (i == rtusb_usb_id_len)
1202 + {
1203 + printk("rt2870: Error! Device Descriptor not matching!\n");
1204 + return FALSE;
1205 + }
1206 +
1207 + return TRUE;
1208 +}
1209 +
1210 +
1211 +/*
1212 +========================================================================
1213 +Routine Description:
1214 + Init net device structure.
1215 +
1216 +Arguments:
1217 + _dev_p Point to the PCI or USB device
1218 + *net_dev Point to the net device
1219 + *pAd the raxx interface data pointer
1220 +
1221 +Return Value:
1222 + TRUE Init ok
1223 + FALSE Init fail
1224 +
1225 +Note:
1226 +========================================================================
1227 +*/
1228 +BOOLEAN RT28XXNetDevInit(
1229 + IN void *_dev_p,
1230 + IN struct net_device *net_dev,
1231 + IN RTMP_ADAPTER *pAd)
1232 +{
1233 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1234 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1235 +#else
1236 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1237 + struct usb_device *dev_p = interface_to_usbdev(intf);
1238 +#endif // LINUX_VERSION_CODE //
1239 +
1240 +
1241 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1242 + pAd->config = dev_p->config;
1243 +#else
1244 + pAd->config = &dev_p->config->desc;
1245 +#endif // LINUX_VERSION_CODE //
1246 + return TRUE;
1247 +}
1248 +
1249 +
1250 +/*
1251 +========================================================================
1252 +Routine Description:
1253 + Init net device structure.
1254 +
1255 +Arguments:
1256 + _dev_p Point to the PCI or USB device
1257 + *pAd the raxx interface data pointer
1258 +
1259 +Return Value:
1260 + TRUE Config ok
1261 + FALSE Config fail
1262 +
1263 +Note:
1264 +========================================================================
1265 +*/
1266 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1267 +BOOLEAN RT28XXProbePostConfig(
1268 + IN void *_dev_p,
1269 + IN RTMP_ADAPTER *pAd,
1270 + IN INT32 interface)
1271 +{
1272 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
1273 + struct usb_interface *intf;
1274 + struct usb_interface_descriptor *iface_desc;
1275 + struct usb_endpoint_descriptor *endpoint;
1276 + ULONG BulkOutIdx;
1277 + UINT32 i;
1278 +
1279 +
1280 + /* get the active interface descriptor */
1281 + intf = &dev_p->actconfig->interface[interface];
1282 + iface_desc = &intf->altsetting[0];
1283 +
1284 + /* get # of enpoints */
1285 + pAd->NumberOfPipes = iface_desc->bNumEndpoints;
1286 + DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->bNumEndpoints));
1287 +
1288 + /* Configure Pipes */
1289 + endpoint = &iface_desc->endpoint[0];
1290 + BulkOutIdx = 0;
1291 +
1292 + for(i=0; i<pAd->NumberOfPipes; i++)
1293 + {
1294 + if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) &&
1295 + ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
1296 + {
1297 + pAd->BulkInEpAddr = endpoint[i].bEndpointAddress;
1298 + pAd->BulkInMaxPacketSize = endpoint[i].wMaxPacketSize;
1299 +
1300 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1301 + ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));
1302 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1303 + ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress));
1304 + }
1305 + else if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) &&
1306 + ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
1307 + {
1308 + // There are 6 bulk out EP. EP6 highest priority.
1309 + // EP1-4 is EDCA. EP5 is HCCA.
1310 + pAd->BulkOutEpAddr[BulkOutIdx++] = endpoint[i].bEndpointAddress;
1311 + pAd->BulkOutMaxPacketSize = endpoint[i].wMaxPacketSize;
1312 +
1313 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1314 + ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
1315 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1316 + ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress));
1317 + }
1318 + }
1319 +
1320 + if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
1321 + {
1322 + printk("Could not find both bulk-in and bulk-out endpoints\n");
1323 + return FALSE;
1324 + }
1325 +
1326 + return TRUE;
1327 +}
1328 +
1329 +#else
1330 +BOOLEAN RT28XXProbePostConfig(
1331 + IN void *_dev_p,
1332 + IN RTMP_ADAPTER *pAd,
1333 + IN INT32 interface)
1334 +{
1335 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
1336 + struct usb_host_interface *iface_desc;
1337 + ULONG BulkOutIdx;
1338 + UINT32 i;
1339 +
1340 +
1341 + /* get the active interface descriptor */
1342 + iface_desc = intf->cur_altsetting;
1343 +
1344 + /* get # of enpoints */
1345 + pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
1346 + DBGPRINT(RT_DEBUG_TRACE,
1347 + ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
1348 +
1349 + /* Configure Pipes */
1350 + BulkOutIdx = 0;
1351 +
1352 + for(i=0; i<pAd->NumberOfPipes; i++)
1353 + {
1354 + if ((iface_desc->endpoint[i].desc.bmAttributes ==
1355 + USB_ENDPOINT_XFER_BULK) &&
1356 + ((iface_desc->endpoint[i].desc.bEndpointAddress &
1357 + USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
1358 + {
1359 + pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress;
1360 + pAd->BulkInMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1361 +
1362 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1363 + ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));
1364 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1365 + ("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress));
1366 + }
1367 + else if ((iface_desc->endpoint[i].desc.bmAttributes ==
1368 + USB_ENDPOINT_XFER_BULK) &&
1369 + ((iface_desc->endpoint[i].desc.bEndpointAddress &
1370 + USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
1371 + {
1372 + // there are 6 bulk out EP. EP6 highest priority.
1373 + // EP1-4 is EDCA. EP5 is HCCA.
1374 + pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress;
1375 + pAd->BulkOutMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1376 +
1377 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1378 + ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
1379 + DBGPRINT_RAW(RT_DEBUG_TRACE,
1380 + ("EP address = 0x%2x \n", iface_desc->endpoint[i].desc.bEndpointAddress));
1381 + }
1382 + }
1383 +
1384 + if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
1385 + {
1386 + printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __FUNCTION__);
1387 + return FALSE;
1388 + }
1389 +
1390 + return TRUE;
1391 +}
1392 +#endif // LINUX_VERSION_CODE //
1393 +
1394 +
1395 +/*
1396 +========================================================================
1397 +Routine Description:
1398 + Disable DMA.
1399 +
1400 +Arguments:
1401 + *pAd the raxx interface data pointer
1402 +
1403 +Return Value:
1404 + None
1405 +
1406 +Note:
1407 +========================================================================
1408 +*/
1409 +VOID RT28XXDMADisable(
1410 + IN RTMP_ADAPTER *pAd)
1411 +{
1412 + // no use
1413 +}
1414 +
1415 +
1416 +
1417 +/*
1418 +========================================================================
1419 +Routine Description:
1420 + Enable DMA.
1421 +
1422 +Arguments:
1423 + *pAd the raxx interface data pointer
1424 +
1425 +Return Value:
1426 + None
1427 +
1428 +Note:
1429 +========================================================================
1430 +*/
1431 +VOID RT28XXDMAEnable(
1432 + IN RTMP_ADAPTER *pAd)
1433 +{
1434 + WPDMA_GLO_CFG_STRUC GloCfg;
1435 + USB_DMA_CFG_STRUC UsbCfg;
1436 + int i = 0;
1437 +
1438 +
1439 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1440 + do
1441 + {
1442 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1443 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
1444 + break;
1445 +
1446 + DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
1447 + RTMPusecDelay(1000);
1448 + i++;
1449 + }while ( i <200);
1450 +
1451 +
1452 + RTMPusecDelay(50);
1453 + GloCfg.field.EnTXWriteBackDDONE = 1;
1454 + GloCfg.field.EnableRxDMA = 1;
1455 + GloCfg.field.EnableTxDMA = 1;
1456 + DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1457 + RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1458 +
1459 + UsbCfg.word = 0;
1460 + UsbCfg.field.phyclear = 0;
1461 + /* usb version is 1.1,do not use bulk in aggregation */
1462 + if (pAd->BulkInMaxPacketSize == 512)
1463 + UsbCfg.field.RxBulkAggEn = 1;
1464 + /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */
1465 + UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3;
1466 + UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */
1467 + UsbCfg.field.RxBulkEn = 1;
1468 + UsbCfg.field.TxBulkEn = 1;
1469 +
1470 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);
1471 +
1472 +}
1473 +
1474 +/*
1475 +========================================================================
1476 +Routine Description:
1477 + Write Beacon buffer to Asic.
1478 +
1479 +Arguments:
1480 + *pAd the raxx interface data pointer
1481 +
1482 +Return Value:
1483 + None
1484 +
1485 +Note:
1486 +========================================================================
1487 +*/
1488 +VOID RT28xx_UpdateBeaconToAsic(
1489 + IN RTMP_ADAPTER *pAd,
1490 + IN INT apidx,
1491 + IN ULONG FrameLen,
1492 + IN ULONG UpdatePos)
1493 +{
1494 + PUCHAR pBeaconFrame = NULL;
1495 + UCHAR *ptr;
1496 + UINT i, padding;
1497 + BEACON_SYNC_STRUCT *pBeaconSync = pAd->CommonCfg.pBeaconSync;
1498 + UINT32 longValue;
1499 +// USHORT shortValue;
1500 + BOOLEAN bBcnReq = FALSE;
1501 + UCHAR bcn_idx = 0;
1502 +
1503 +
1504 + if (pBeaconFrame == NULL)
1505 + {
1506 + DBGPRINT(RT_DEBUG_ERROR,("pBeaconFrame is NULL!\n"));
1507 + return;
1508 + }
1509 +
1510 + if (pBeaconSync == NULL)
1511 + {
1512 + DBGPRINT(RT_DEBUG_ERROR,("pBeaconSync is NULL!\n"));
1513 + return;
1514 + }
1515 +
1516 + //if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) ||
1517 + // ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP))
1518 + // )
1519 + if (bBcnReq == FALSE)
1520 + {
1521 + /* when the ra interface is down, do not send its beacon frame */
1522 + /* clear all zero */
1523 + for(i=0; i<TXWI_SIZE; i+=4) {
1524 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1525 + }
1526 + pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1527 + NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE);
1528 + }
1529 + else
1530 + {
1531 + ptr = (PUCHAR)&pAd->BeaconTxWI;
1532 +#ifdef RT_BIG_ENDIAN
1533 + RTMPWIEndianChange(ptr, TYPE_TXWI);
1534 +#endif
1535 + if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE)
1536 + { // If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames.
1537 + pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1538 + NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE);
1539 + }
1540 +
1541 + if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) != (1 << bcn_idx))
1542 + {
1543 + for (i=0; i<TXWI_SIZE; i+=4) // 16-byte TXWI field
1544 + {
1545 + longValue = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1546 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longValue);
1547 + ptr += 4;
1548 + }
1549 + }
1550 +
1551 + ptr = pBeaconSync->BeaconBuf[bcn_idx];
1552 + padding = (FrameLen & 0x01);
1553 + NdisZeroMemory((PUCHAR)(pBeaconFrame + FrameLen), padding);
1554 + FrameLen += padding;
1555 + for (i = 0 ; i < FrameLen /*HW_BEACON_OFFSET*/; i += 2)
1556 + {
1557 + if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE)
1558 + {
1559 + NdisMoveMemory(ptr, pBeaconFrame, 2);
1560 + //shortValue = *ptr + (*(ptr+1)<<8);
1561 + //RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue);
1562 + RTUSBMultiWrite(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, ptr, 2);
1563 + }
1564 + ptr +=2;
1565 + pBeaconFrame += 2;
1566 + }
1567 +
1568 + pBeaconSync->BeaconBitMap |= (1 << bcn_idx);
1569 +
1570 + // For AP interface, set the DtimBitOn so that we can send Bcast/Mcast frame out after this beacon frame.
1571 + }
1572 +
1573 +}
1574 +
1575 +
1576 +VOID RT2870_BssBeaconStop(
1577 + IN RTMP_ADAPTER *pAd)
1578 +{
1579 + BEACON_SYNC_STRUCT *pBeaconSync;
1580 + int i, offset;
1581 + BOOLEAN Cancelled = TRUE;
1582 +
1583 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1584 + if (pBeaconSync && pBeaconSync->EnableBeacon)
1585 + {
1586 + INT NumOfBcn;
1587 +
1588 +
1589 +#ifdef CONFIG_STA_SUPPORT
1590 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1591 + {
1592 + NumOfBcn = MAX_MESH_NUM;
1593 + }
1594 +#endif // CONFIG_STA_SUPPORT //
1595 +
1596 + RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1597 +
1598 + for(i=0; i<NumOfBcn; i++)
1599 + {
1600 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1601 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1602 +
1603 + for (offset=0; offset<HW_BEACON_OFFSET; offset+=4)
1604 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[i] + offset, 0x00);
1605 +
1606 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1607 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1608 + }
1609 + pBeaconSync->BeaconBitMap = 0;
1610 + pBeaconSync->DtimBitOn = 0;
1611 + }
1612 +}
1613 +
1614 +
1615 +VOID RT2870_BssBeaconStart(
1616 + IN RTMP_ADAPTER *pAd)
1617 +{
1618 + int apidx;
1619 + BEACON_SYNC_STRUCT *pBeaconSync;
1620 +// LARGE_INTEGER tsfTime, deltaTime;
1621 +
1622 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1623 + if (pBeaconSync && pBeaconSync->EnableBeacon)
1624 + {
1625 + INT NumOfBcn;
1626 +
1627 +
1628 +#ifdef CONFIG_STA_SUPPORT
1629 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1630 + {
1631 + NumOfBcn = MAX_MESH_NUM;
1632 + }
1633 +#endif // CONFIG_STA_SUPPORT //
1634 +
1635 + for(apidx=0; apidx<NumOfBcn; apidx++)
1636 + {
1637 + UCHAR CapabilityInfoLocationInBeacon = 0;
1638 + UCHAR TimIELocationInBeacon = 0;
1639 +
1640 +#ifdef CONFIG_STA_SUPPORT
1641 +#endif // CONFIG_STA_SUPPORT //
1642 +
1643 + NdisZeroMemory(pBeaconSync->BeaconBuf[apidx], HW_BEACON_OFFSET);
1644 + pBeaconSync->CapabilityInfoLocationInBeacon[apidx] = CapabilityInfoLocationInBeacon;
1645 + pBeaconSync->TimIELocationInBeacon[apidx] = TimIELocationInBeacon;
1646 + NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx], TXWI_SIZE);
1647 + }
1648 + pBeaconSync->BeaconBitMap = 0;
1649 + pBeaconSync->DtimBitOn = 0;
1650 + pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE;
1651 +
1652 + pAd->CommonCfg.BeaconAdjust = 0;
1653 + pAd->CommonCfg.BeaconFactor = 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10);
1654 + pAd->CommonCfg.BeaconRemain = (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1;
1655 + printk("RT2870_BssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n", pAd->CommonCfg.BeaconFactor, pAd->CommonCfg.BeaconRemain);
1656 + RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer, pAd->CommonCfg.BeaconPeriod);
1657 +
1658 + }
1659 +}
1660 +
1661 +
1662 +VOID RT2870_BssBeaconInit(
1663 + IN RTMP_ADAPTER *pAd)
1664 +{
1665 + BEACON_SYNC_STRUCT *pBeaconSync;
1666 + int i;
1667 +
1668 + NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(BEACON_SYNC_STRUCT), MEM_ALLOC_FLAG);
1669 + if (pAd->CommonCfg.pBeaconSync)
1670 + {
1671 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1672 + NdisZeroMemory(pBeaconSync, sizeof(BEACON_SYNC_STRUCT));
1673 + for(i=0; i < HW_BEACON_MAX_COUNT; i++)
1674 + {
1675 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1676 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1677 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1678 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1679 + }
1680 + pBeaconSync->BeaconBitMap = 0;
1681 +
1682 + //RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE);
1683 + pBeaconSync->EnableBeacon = TRUE;
1684 + }
1685 +}
1686 +
1687 +
1688 +VOID RT2870_BssBeaconExit(
1689 + IN RTMP_ADAPTER *pAd)
1690 +{
1691 + BEACON_SYNC_STRUCT *pBeaconSync;
1692 + BOOLEAN Cancelled = TRUE;
1693 + int i;
1694 +
1695 + if (pAd->CommonCfg.pBeaconSync)
1696 + {
1697 + pBeaconSync = pAd->CommonCfg.pBeaconSync;
1698 + pBeaconSync->EnableBeacon = FALSE;
1699 + RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1700 + pBeaconSync->BeaconBitMap = 0;
1701 +
1702 + for(i=0; i<HW_BEACON_MAX_COUNT; i++)
1703 + {
1704 + NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1705 + pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1706 + pBeaconSync->TimIELocationInBeacon[i] = 0;
1707 + NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1708 + }
1709 +
1710 + NdisFreeMemory(pAd->CommonCfg.pBeaconSync, HW_BEACON_OFFSET * HW_BEACON_MAX_COUNT, 0);
1711 + pAd->CommonCfg.pBeaconSync = NULL;
1712 + }
1713 +}
1714 +
1715 +VOID BeaconUpdateExec(
1716 + IN PVOID SystemSpecific1,
1717 + IN PVOID FunctionContext,
1718 + IN PVOID SystemSpecific2,
1719 + IN PVOID SystemSpecific3)
1720 +{
1721 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext;
1722 + LARGE_INTEGER tsfTime_a;//, tsfTime_b, deltaTime_exp, deltaTime_ab;
1723 + UINT32 delta, remain, remain_low, remain_high;
1724 +// BOOLEAN positive;
1725 +
1726 + ReSyncBeaconTime(pAd);
1727 +
1728 +
1729 +
1730 + RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart);
1731 + RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart);
1732 +
1733 +
1734 + //positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp);
1735 + remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart;
1736 + remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10);
1737 + remain = (remain_high + remain_low)%(pAd->CommonCfg.BeaconPeriod << 10);
1738 + delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain;
1739 +
1740 + pAd->CommonCfg.BeaconUpdateTimer.TimerValue = (delta >> 10) + 10;
1741 +
1742 +}
1743 +
1744 --- /dev/null
1745 +++ b/drivers/staging/rt3070/action.h
1746 @@ -0,0 +1,68 @@
1747 +/*
1748 + *************************************************************************
1749 + * Ralink Tech Inc.
1750 + * 5F., No.36, Taiyuan St., Jhubei City,
1751 + * Hsinchu County 302,
1752 + * Taiwan, R.O.C.
1753 + *
1754 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
1755 + *
1756 + * This program is free software; you can redistribute it and/or modify *
1757 + * it under the terms of the GNU General Public License as published by *
1758 + * the Free Software Foundation; either version 2 of the License, or *
1759 + * (at your option) any later version. *
1760 + * *
1761 + * This program is distributed in the hope that it will be useful, *
1762 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
1763 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
1764 + * GNU General Public License for more details. *
1765 + * *
1766 + * You should have received a copy of the GNU General Public License *
1767 + * along with this program; if not, write to the *
1768 + * Free Software Foundation, Inc., *
1769 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1770 + * *
1771 + *************************************************************************
1772 +
1773 + Module Name:
1774 + aironet.h
1775 +
1776 + Abstract:
1777 +
1778 + Revision History:
1779 + Who When What
1780 + -------- ---------- ----------------------------------------------
1781 + Name Date Modification logs
1782 + Paul Lin 04-06-15 Initial
1783 +*/
1784 +
1785 +#ifndef __ACTION_H__
1786 +#define __ACTION_H__
1787 +
1788 +typedef struct PACKED __HT_INFO_OCTET
1789 +{
1790 +#ifdef RT_BIG_ENDIAN
1791 + UCHAR Reserved:5;
1792 + UCHAR STA_Channel_Width:1;
1793 + UCHAR Forty_MHz_Intolerant:1;
1794 + UCHAR Request:1;
1795 +#else
1796 + UCHAR Request:1;
1797 + UCHAR Forty_MHz_Intolerant:1;
1798 + UCHAR STA_Channel_Width:1;
1799 + UCHAR Reserved:5;
1800 +#endif
1801 +} HT_INFORMATION_OCTET;
1802 +
1803 +
1804 +typedef struct PACKED __FRAME_HT_INFO
1805 +{
1806 + HEADER_802_11 Hdr;
1807 + UCHAR Category;
1808 + UCHAR Action;
1809 + HT_INFORMATION_OCTET HT_Info;
1810 +} FRAME_HT_INFO, *PFRAME_HT_INFO;
1811 +
1812 +#endif /* __ACTION_H__ */
1813 +
1814 +
1815 --- /dev/null
1816 +++ b/drivers/staging/rt3070/aironet.h
1817 @@ -0,0 +1,210 @@
1818 +/*
1819 + *************************************************************************
1820 + * Ralink Tech Inc.
1821 + * 5F., No.36, Taiyuan St., Jhubei City,
1822 + * Hsinchu County 302,
1823 + * Taiwan, R.O.C.
1824 + *
1825 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
1826 + *
1827 + * This program is free software; you can redistribute it and/or modify *
1828 + * it under the terms of the GNU General Public License as published by *
1829 + * the Free Software Foundation; either version 2 of the License, or *
1830 + * (at your option) any later version. *
1831 + * *
1832 + * This program is distributed in the hope that it will be useful, *
1833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
1834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
1835 + * GNU General Public License for more details. *
1836 + * *
1837 + * You should have received a copy of the GNU General Public License *
1838 + * along with this program; if not, write to the *
1839 + * Free Software Foundation, Inc., *
1840 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1841 + * *
1842 + *************************************************************************
1843 +
1844 + Module Name:
1845 + aironet.h
1846 +
1847 + Abstract:
1848 +
1849 + Revision History:
1850 + Who When What
1851 + -------- ---------- ----------------------------------------------
1852 + Name Date Modification logs
1853 + Paul Lin 04-06-15 Initial
1854 +*/
1855 +
1856 +#ifndef __AIRONET_H__
1857 +#define __AIRONET_H__
1858 +
1859 +// Measurement Type definition
1860 +#define MSRN_TYPE_UNUSED 0
1861 +#define MSRN_TYPE_CHANNEL_LOAD_REQ 1
1862 +#define MSRN_TYPE_NOISE_HIST_REQ 2
1863 +#define MSRN_TYPE_BEACON_REQ 3
1864 +#define MSRN_TYPE_FRAME_REQ 4
1865 +
1866 +// Scan Mode in Beacon Request
1867 +#define MSRN_SCAN_MODE_PASSIVE 0
1868 +#define MSRN_SCAN_MODE_ACTIVE 1
1869 +#define MSRN_SCAN_MODE_BEACON_TABLE 2
1870 +
1871 +// PHY type definition for Aironet beacon report, CCX 2 table 36-9
1872 +#define PHY_FH 1
1873 +#define PHY_DSS 2
1874 +#define PHY_UNUSED 3
1875 +#define PHY_OFDM 4
1876 +#define PHY_HR_DSS 5
1877 +#define PHY_ERP 6
1878 +
1879 +// RPI table in dBm
1880 +#define RPI_0 0 // Power <= -87
1881 +#define RPI_1 1 // -87 < Power <= -82
1882 +#define RPI_2 2 // -82 < Power <= -77
1883 +#define RPI_3 3 // -77 < Power <= -72
1884 +#define RPI_4 4 // -72 < Power <= -67
1885 +#define RPI_5 5 // -67 < Power <= -62
1886 +#define RPI_6 6 // -62 < Power <= -57
1887 +#define RPI_7 7 // -57 < Power
1888 +
1889 +// Cisco Aironet IAPP definetions
1890 +#define AIRONET_IAPP_TYPE 0x32
1891 +#define AIRONET_IAPP_SUBTYPE_REQUEST 0x01
1892 +#define AIRONET_IAPP_SUBTYPE_REPORT 0x81
1893 +
1894 +// Measurement Request detail format
1895 +typedef struct _MEASUREMENT_REQUEST {
1896 + UCHAR Channel;
1897 + UCHAR ScanMode; // Use only in beacon request, other requests did not use this field
1898 + USHORT Duration;
1899 +} MEASUREMENT_REQUEST, *PMEASUREMENT_REQUEST;
1900 +
1901 +// Beacon Measurement Report
1902 +// All these field might change to UCHAR, because we didn't do anything to these report.
1903 +// We copy all these beacons and report to CCX 2 AP.
1904 +typedef struct _BEACON_REPORT {
1905 + UCHAR Channel;
1906 + UCHAR Spare;
1907 + USHORT Duration;
1908 + UCHAR PhyType; // Definiation is listed above table 36-9
1909 + UCHAR RxPower;
1910 + UCHAR BSSID[6];
1911 + UCHAR ParentTSF[4];
1912 + UCHAR TargetTSF[8];
1913 + USHORT BeaconInterval;
1914 + USHORT CapabilityInfo;
1915 +} BEACON_REPORT, *PBEACON_REPORT;
1916 +
1917 +// Frame Measurement Report (Optional)
1918 +typedef struct _FRAME_REPORT {
1919 + UCHAR Channel;
1920 + UCHAR Spare;
1921 + USHORT Duration;
1922 + UCHAR TA;
1923 + UCHAR BSSID[6];
1924 + UCHAR RSSI;
1925 + UCHAR Count;
1926 +} FRAME_REPORT, *PFRAME_REPORT;
1927 +
1928 +#pragma pack(1)
1929 +// Channel Load Report
1930 +typedef struct _CHANNEL_LOAD_REPORT {
1931 + UCHAR Channel;
1932 + UCHAR Spare;
1933 + USHORT Duration;
1934 + UCHAR CCABusy;
1935 +} CHANNEL_LOAD_REPORT, *PCHANNEL_LOAD_REPORT;
1936 +#pragma pack()
1937 +
1938 +// Nosie Histogram Report
1939 +typedef struct _NOISE_HIST_REPORT {
1940 + UCHAR Channel;
1941 + UCHAR Spare;
1942 + USHORT Duration;
1943 + UCHAR Density[8];
1944 +} NOISE_HIST_REPORT, *PNOISE_HIST_REPORT;
1945 +
1946 +// Radio Management Capability element
1947 +typedef struct _RADIO_MANAGEMENT_CAPABILITY {
1948 + UCHAR Eid; // TODO: Why the Eid is 1 byte, not normal 2 bytes???
1949 + UCHAR Length;
1950 + UCHAR AironetOui[3]; // AIronet OUI (00 40 96)
1951 + UCHAR Type; // Type / Version
1952 + USHORT Status; // swap16 required
1953 +} RADIO_MANAGEMENT_CAPABILITY, *PRADIO_MANAGEMENT_CAPABILITY;
1954 +
1955 +// Measurement Mode Bit definition
1956 +typedef struct _MEASUREMENT_MODE {
1957 + UCHAR Rsvd:4;
1958 + UCHAR Report:1;
1959 + UCHAR NotUsed:1;
1960 + UCHAR Enable:1;
1961 + UCHAR Parallel:1;
1962 +} MEASUREMENT_MODE, *PMEASUREMENT_MODE;
1963 +
1964 +// Measurement Request element, This is little endian mode
1965 +typedef struct _MEASUREMENT_REQUEST_ELEMENT {
1966 + USHORT Eid;
1967 + USHORT Length; // swap16 required
1968 + USHORT Token; // non-zero unique token
1969 + UCHAR Mode; // Measurement Mode
1970 + UCHAR Type; // Measurement type
1971 +} MEASUREMENT_REQUEST_ELEMENT, *PMEASUREMENT_REQUEST_ELEMENT;
1972 +
1973 +// Measurement Report element, This is little endian mode
1974 +typedef struct _MEASUREMENT_REPORT_ELEMENT {
1975 + USHORT Eid;
1976 + USHORT Length; // swap16 required
1977 + USHORT Token; // non-zero unique token
1978 + UCHAR Mode; // Measurement Mode
1979 + UCHAR Type; // Measurement type
1980 +} MEASUREMENT_REPORT_ELEMENT, *PMEASUREMENT_REPORT_ELEMENT;
1981 +
1982 +// Cisco Aironet IAPP Frame Header, Network byte order used
1983 +typedef struct _AIRONET_IAPP_HEADER {
1984 + UCHAR CiscoSnapHeader[8]; // 8 bytes Cisco snap header
1985 + USHORT Length; // IAPP ID & length, remember to swap16 in LE system
1986 + UCHAR Type; // IAPP type
1987 + UCHAR SubType; // IAPP subtype
1988 + UCHAR DA[6]; // Destination MAC address
1989 + UCHAR SA[6]; // Source MAC address
1990 + USHORT Token; // Dialog token, no need to swap16 since it is for yoken usage only
1991 +} AIRONET_IAPP_HEADER, *PAIRONET_IAPP_HEADER;
1992 +
1993 +// Radio Measurement Request frame
1994 +typedef struct _AIRONET_RM_REQUEST_FRAME {
1995 + AIRONET_IAPP_HEADER IAPP; // Common header
1996 + UCHAR Delay; // Activation Delay
1997 + UCHAR Offset; // Measurement offset
1998 +} AIRONET_RM_REQUEST_FRAME, *PAIRONET_RM_REQUEST_FRAME;
1999 +
2000 +// Radio Measurement Report frame
2001 +typedef struct _AIRONET_RM_REPORT_FRAME {
2002 + AIRONET_IAPP_HEADER IAPP; // Common header
2003 +} AIRONET_RM_REPORT_FRAME, *PAIRONET_RM_REPORT_FRAME;
2004 +
2005 +// Saved element request actions which will saved in StaCfg.
2006 +typedef struct _RM_REQUEST_ACTION {
2007 + MEASUREMENT_REQUEST_ELEMENT ReqElem; // Saved request element
2008 + MEASUREMENT_REQUEST Measurement; // Saved measurement within the request element
2009 +} RM_REQUEST_ACTION, *PRM_REQUEST_ACTION;
2010 +
2011 +// CCX administration control
2012 +typedef union _CCX_CONTROL {
2013 + struct {
2014 + UINT32 Enable:1; // Enable CCX2
2015 + UINT32 LeapEnable:1; // Enable LEAP at CCX2
2016 + UINT32 RMEnable:1; // Radio Measurement Enable
2017 + UINT32 DCRMEnable:1; // Non serving channel Radio Measurement enable
2018 + UINT32 QOSEnable:1; // Enable QOS for CCX 2.0 support
2019 + UINT32 FastRoamEnable:1; // Enable fast roaming
2020 + UINT32 Rsvd:2; // Not used
2021 + UINT32 dBmToRoam:8; // the condition to roam when receiving Rssi less than this value. It's negative value.
2022 + UINT32 TuLimit:16; // Limit for different channel scan
2023 + } field;
2024 + UINT32 word;
2025 +} CCX_CONTROL, *PCCX_CONTROL;
2026 +
2027 +#endif // __AIRONET_H__
2028 --- /dev/null
2029 +++ b/drivers/staging/rt3070/ap.h
2030 @@ -0,0 +1,557 @@
2031 +/*
2032 + *************************************************************************
2033 + * Ralink Tech Inc.
2034 + * 5F., No.36, Taiyuan St., Jhubei City,
2035 + * Hsinchu County 302,
2036 + * Taiwan, R.O.C.
2037 + *
2038 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
2039 + *
2040 + * This program is free software; you can redistribute it and/or modify *
2041 + * it under the terms of the GNU General Public License as published by *
2042 + * the Free Software Foundation; either version 2 of the License, or *
2043 + * (at your option) any later version. *
2044 + * *
2045 + * This program is distributed in the hope that it will be useful, *
2046 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
2047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
2048 + * GNU General Public License for more details. *
2049 + * *
2050 + * You should have received a copy of the GNU General Public License *
2051 + * along with this program; if not, write to the *
2052 + * Free Software Foundation, Inc., *
2053 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
2054 + * *
2055 + *************************************************************************
2056 +
2057 + Module Name:
2058 + ap.h
2059 +
2060 + Abstract:
2061 + Miniport generic portion header file
2062 +
2063 + Revision History:
2064 + Who When What
2065 + -------- ---------- ----------------------------------------------
2066 + Paul Lin 08-01-2002 created
2067 + James Tan 09-06-2002 modified (Revise NTCRegTable)
2068 + John Chang 12-22-2004 modified for RT2561/2661. merge with STA driver
2069 +*/
2070 +#ifndef __AP_H__
2071 +#define __AP_H__
2072 +
2073 +
2074 +
2075 +// ========================= AP RTMP.h ================================
2076 +
2077 +
2078 +
2079 +// =============================================================
2080 +// Function Prototypes
2081 +// =============================================================
2082 +
2083 +// ap_data.c
2084 +
2085 +BOOLEAN APBridgeToWirelessSta(
2086 + IN PRTMP_ADAPTER pAd,
2087 + IN PUCHAR pHeader,
2088 + IN UINT HdrLen,
2089 + IN PUCHAR pData,
2090 + IN UINT DataLen,
2091 + IN ULONG fromwdsidx);
2092 +
2093 +BOOLEAN APHandleRxDoneInterrupt(
2094 + IN PRTMP_ADAPTER pAd);
2095 +
2096 +VOID APSendPackets(
2097 + IN NDIS_HANDLE MiniportAdapterContext,
2098 + IN PPNDIS_PACKET ppPacketArray,
2099 + IN UINT NumberOfPackets);
2100 +
2101 +NDIS_STATUS APSendPacket(
2102 + IN PRTMP_ADAPTER pAd,
2103 + IN PNDIS_PACKET pPacket);
2104 +
2105 +
2106 +NDIS_STATUS APHardTransmit(
2107 + IN PRTMP_ADAPTER pAd,
2108 + IN TX_BLK *pTxBlk,
2109 + IN UCHAR QueIdx);
2110 +
2111 +VOID APRxEAPOLFrameIndicate(
2112 + IN PRTMP_ADAPTER pAd,
2113 + IN MAC_TABLE_ENTRY *pEntry,
2114 + IN RX_BLK *pRxBlk,
2115 + IN UCHAR FromWhichBSSID);
2116 +
2117 +NDIS_STATUS APCheckRxError(
2118 + IN PRTMP_ADAPTER pAd,
2119 + IN PRT28XX_RXD_STRUC pRxD,
2120 + IN UCHAR Wcid);
2121 +
2122 +BOOLEAN APCheckClass2Class3Error(
2123 + IN PRTMP_ADAPTER pAd,
2124 + IN ULONG Wcid,
2125 + IN PHEADER_802_11 pHeader);
2126 +
2127 +VOID APHandleRxPsPoll(
2128 + IN PRTMP_ADAPTER pAd,
2129 + IN PUCHAR pAddr,
2130 + IN USHORT Aid,
2131 + IN BOOLEAN isActive);
2132 +
2133 +VOID RTMPDescriptorEndianChange(
2134 + IN PUCHAR pData,
2135 + IN ULONG DescriptorType);
2136 +
2137 +VOID RTMPFrameEndianChange(
2138 + IN PRTMP_ADAPTER pAd,
2139 + IN PUCHAR pData,
2140 + IN ULONG Dir,
2141 + IN BOOLEAN FromRxDoneInt);
2142 +
2143 +// ap_assoc.c
2144 +
2145 +VOID APAssocStateMachineInit(
2146 + IN PRTMP_ADAPTER pAd,
2147 + IN STATE_MACHINE *S,
2148 + OUT STATE_MACHINE_FUNC Trans[]);
2149 +
2150 +VOID APPeerAssocReqAction(
2151 + IN PRTMP_ADAPTER pAd,
2152 + IN MLME_QUEUE_ELEM *Elem);
2153 +
2154 +VOID APPeerReassocReqAction(
2155 + IN PRTMP_ADAPTER pAd,
2156 + IN MLME_QUEUE_ELEM *Elem);
2157 +
2158 +VOID APPeerDisassocReqAction(
2159 + IN PRTMP_ADAPTER pAd,
2160 + IN MLME_QUEUE_ELEM *Elem);
2161 +
2162 +VOID MbssKickOutStas(
2163 + IN PRTMP_ADAPTER pAd,
2164 + IN INT apidx,
2165 + IN USHORT Reason);
2166 +
2167 +VOID APMlmeKickOutSta(
2168 + IN PRTMP_ADAPTER pAd,
2169 + IN PUCHAR pStaAddr,
2170 + IN UCHAR Wcid,
2171 + IN USHORT Reason);
2172 +
2173 +VOID APMlmeDisassocReqAction(
2174 + IN PRTMP_ADAPTER pAd,
2175 + IN MLME_QUEUE_ELEM *Elem);
2176 +
2177 +VOID APCls3errAction(
2178 + IN PRTMP_ADAPTER pAd,
2179 + IN ULONG Wcid,
2180 + IN PHEADER_802_11 pHeader);
2181 +
2182 +
2183 +USHORT APBuildAssociation(
2184 + IN PRTMP_ADAPTER pAd,
2185 + IN MAC_TABLE_ENTRY *pEntry,
2186 + IN USHORT CapabilityInfo,
2187 + IN UCHAR MaxSupportedRateIn500Kbps,
2188 + IN UCHAR *RSN,
2189 + IN UCHAR *pRSNLen,
2190 + IN BOOLEAN bWmmCapable,
2191 + IN ULONG RalinkIe,
2192 +#ifdef DOT11N_DRAFT3
2193 + IN EXT_CAP_INFO_ELEMENT ExtCapInfo,
2194 +#endif // DOT11N_DRAFT3 //
2195 + IN HT_CAPABILITY_IE *pHtCapability,
2196 + IN UCHAR HtCapabilityLen,
2197 + OUT USHORT *pAid);
2198 +
2199 +/*
2200 +VOID RTMPAddClientSec(
2201 + IN PRTMP_ADAPTER pAd,
2202 + IN UCHAR BssIdx,
2203 + IN UCHAR KeyIdx,
2204 + IN UCHAR CipherAlg,
2205 + IN PUCHAR pKey,
2206 + IN PUCHAR pTxMic,
2207 + IN PUCHAR pRxMic,
2208 + IN MAC_TABLE_ENTRY *pEntry);
2209 +*/
2210 +
2211 +// ap_auth.c
2212 +
2213 +void APAuthStateMachineInit(
2214 + IN PRTMP_ADAPTER pAd,
2215 + IN STATE_MACHINE *Sm,
2216 + OUT STATE_MACHINE_FUNC Trans[]);
2217 +
2218 +VOID APMlmeDeauthReqAction(
2219 + IN PRTMP_ADAPTER pAd,
2220 + IN MLME_QUEUE_ELEM *Elem);
2221 +
2222 +VOID APCls2errAction(
2223 + IN PRTMP_ADAPTER pAd,
2224 + IN ULONG Wcid,
2225 + IN PHEADER_802_11 pHeader);
2226 +
2227 +// ap_authrsp.c
2228 +
2229 +VOID APAuthRspStateMachineInit(
2230 + IN PRTMP_ADAPTER pAd,
2231 + IN PSTATE_MACHINE Sm,
2232 + IN STATE_MACHINE_FUNC Trans[]);
2233 +
2234 +VOID APPeerAuthAtAuthRspIdleAction(
2235 + IN PRTMP_ADAPTER pAd,
2236 + IN MLME_QUEUE_ELEM *Elem);
2237 +
2238 +VOID APPeerDeauthReqAction(
2239 + IN PRTMP_ADAPTER pAd,
2240 + IN MLME_QUEUE_ELEM *Elem);
2241 +
2242 +VOID APPeerAuthSimpleRspGenAndSend(
2243 + IN PRTMP_ADAPTER pAd,
2244 + IN PHEADER_802_11 pHdr80211,
2245 + IN USHORT Alg,
2246 + IN USHORT Seq,
2247 + IN USHORT StatusCode);
2248 +
2249 +// ap_connect.c
2250 +
2251 +BOOLEAN BeaconTransmitRequired(
2252 + IN PRTMP_ADAPTER pAd,
2253 + IN INT apidx);
2254 +
2255 +VOID APMakeBssBeacon(
2256 + IN PRTMP_ADAPTER pAd,
2257 + IN INT apidx);
2258 +
2259 +VOID APUpdateBeaconFrame(
2260 + IN PRTMP_ADAPTER pAd,
2261 + IN INT apidx);
2262 +
2263 +VOID APMakeAllBssBeacon(
2264 + IN PRTMP_ADAPTER pAd);
2265 +
2266 +VOID APUpdateAllBeaconFrame(
2267 + IN PRTMP_ADAPTER pAd);
2268 +
2269 +
2270 +// ap_sync.c
2271 +
2272 +VOID APSyncStateMachineInit(
2273 + IN PRTMP_ADAPTER pAd,
2274 + IN STATE_MACHINE *Sm,
2275 + OUT STATE_MACHINE_FUNC Trans[]);
2276 +
2277 +VOID APScanTimeout(
2278 + IN PVOID SystemSpecific1,
2279 + IN PVOID FunctionContext,
2280 + IN PVOID SystemSpecific2,
2281 + IN PVOID SystemSpecific3);
2282 +
2283 +VOID APInvalidStateWhenScan(
2284 + IN PRTMP_ADAPTER pAd,
2285 + IN MLME_QUEUE_ELEM *Elem);
2286 +
2287 +VOID APScanTimeoutAction(
2288 + IN PRTMP_ADAPTER pAd,
2289 + IN MLME_QUEUE_ELEM *Elem);
2290 +
2291 +VOID APPeerProbeReqAction(
2292 + IN PRTMP_ADAPTER pAd,
2293 + IN MLME_QUEUE_ELEM *Elem);
2294 +
2295 +VOID APPeerBeaconAction(
2296 + IN PRTMP_ADAPTER pAd,
2297 + IN MLME_QUEUE_ELEM *Elem);
2298 +
2299 +VOID APMlmeScanReqAction(
2300 + IN PRTMP_ADAPTER pAd,
2301 + IN MLME_QUEUE_ELEM *Elem);
2302 +
2303 +VOID APPeerBeaconAtScanAction(
2304 + IN PRTMP_ADAPTER pAd,
2305 + IN MLME_QUEUE_ELEM *Elem);
2306 +
2307 +VOID APScanCnclAction(
2308 + IN PRTMP_ADAPTER pAd,
2309 + IN MLME_QUEUE_ELEM *Elem);
2310 +
2311 +VOID ApSiteSurvey(
2312 + IN PRTMP_ADAPTER pAd);
2313 +
2314 +VOID SupportRate(
2315 + IN PUCHAR SupRate,
2316 + IN UCHAR SupRateLen,
2317 + IN PUCHAR ExtRate,
2318 + IN UCHAR ExtRateLen,
2319 + OUT PUCHAR *Rates,
2320 + OUT PUCHAR RatesLen,
2321 + OUT PUCHAR pMaxSupportRate);
2322 +
2323 +
2324 +BOOLEAN ApScanRunning(
2325 + IN PRTMP_ADAPTER pAd);
2326 +
2327 +#ifdef DOT11N_DRAFT3
2328 +VOID APOverlappingBSSScan(
2329 + IN RTMP_ADAPTER *pAd);
2330 +#endif // DOT11N_DRAFT3 //
2331 +
2332 +// ap_wpa.c
2333 +
2334 +VOID APWpaStateMachineInit(
2335 + IN PRTMP_ADAPTER pAd,
2336 + IN STATE_MACHINE *Sm,
2337 + OUT STATE_MACHINE_FUNC Trans[]);
2338 +
2339 +// ap_mlme.c
2340 +
2341 +VOID APMlmePeriodicExec(
2342 + IN PRTMP_ADAPTER pAd);
2343 +
2344 +VOID APMlmeSelectTxRateTable(
2345 + IN PRTMP_ADAPTER pAd,
2346 + IN PMAC_TABLE_ENTRY pEntry,
2347 + IN PUCHAR *ppTable,
2348 + IN PUCHAR pTableSize,
2349 + IN PUCHAR pInitTxRateIdx);
2350 +
2351 +VOID APMlmeSetTxRate(
2352 + IN PRTMP_ADAPTER pAd,
2353 + IN PMAC_TABLE_ENTRY pEntry,
2354 + IN PRTMP_TX_RATE_SWITCH pTxRate);
2355 +
2356 +VOID APMlmeDynamicTxRateSwitching(
2357 + IN PRTMP_ADAPTER pAd);
2358 +
2359 +VOID APQuickResponeForRateUpExec(
2360 + IN PVOID SystemSpecific1,
2361 + IN PVOID FunctionContext,
2362 + IN PVOID SystemSpecific2,
2363 + IN PVOID SystemSpecific3);
2364 +
2365 +BOOLEAN APMsgTypeSubst(
2366 + IN PRTMP_ADAPTER pAd,
2367 + IN PFRAME_802_11 pFrame,
2368 + OUT INT *Machine,
2369 + OUT INT *MsgType);
2370 +
2371 +VOID APQuickResponeForRateUpExec(
2372 + IN PVOID SystemSpecific1,
2373 + IN PVOID FunctionContext,
2374 + IN PVOID SystemSpecific2,
2375 + IN PVOID SystemSpecific3);
2376 +
2377 +#ifdef RT2870
2378 +VOID BeaconUpdateExec(
2379 + IN PVOID SystemSpecific1,
2380 + IN PVOID FunctionContext,
2381 + IN PVOID SystemSpecific2,
2382 + IN PVOID SystemSpecific3);
2383 +#endif // RT2870 //
2384 +
2385 +VOID RTMPSetPiggyBack(
2386 + IN PRTMP_ADAPTER pAd,
2387 + IN BOOLEAN bPiggyBack);
2388 +
2389 +VOID APAsicEvaluateRxAnt(
2390 + IN PRTMP_ADAPTER pAd);
2391 +
2392 +VOID APAsicRxAntEvalTimeout(
2393 + IN PRTMP_ADAPTER pAd);
2394 +
2395 +// ap.c
2396 +
2397 +VOID APSwitchChannel(
2398 + IN PRTMP_ADAPTER pAd,
2399 + IN INT Channel);
2400 +
2401 +NDIS_STATUS APInitialize(
2402 + IN PRTMP_ADAPTER pAd);
2403 +
2404 +VOID APShutdown(
2405 + IN PRTMP_ADAPTER pAd);
2406 +
2407 +VOID APStartUp(
2408 + IN PRTMP_ADAPTER pAd);
2409 +
2410 +VOID APStop(
2411 + IN PRTMP_ADAPTER pAd);
2412 +
2413 +VOID APCleanupPsQueue(
2414 + IN PRTMP_ADAPTER pAd,
2415 + IN PQUEUE_HEADER pQueue);
2416 +
2417 +VOID MacTableReset(
2418 + IN PRTMP_ADAPTER pAd);
2419 +
2420 +MAC_TABLE_ENTRY *MacTableInsertEntry(
2421 + IN PRTMP_ADAPTER pAd,
2422 + IN PUCHAR pAddr,
2423 + IN UCHAR apidx,
2424 + IN BOOLEAN CleanAll);
2425 +
2426 +BOOLEAN MacTableDeleteEntry(
2427 + IN PRTMP_ADAPTER pAd,
2428 + IN USHORT wcid,
2429 + IN PUCHAR pAddr);
2430 +
2431 +MAC_TABLE_ENTRY *MacTableLookup(
2432 + IN PRTMP_ADAPTER pAd,
2433 + IN PUCHAR pAddr);
2434 +
2435 +VOID MacTableMaintenance(
2436 + IN PRTMP_ADAPTER pAd);
2437 +
2438 +UINT32 MacTableAssocStaNumGet(
2439 + IN PRTMP_ADAPTER pAd);
2440 +
2441 +MAC_TABLE_ENTRY *APSsPsInquiry(
2442 + IN PRTMP_ADAPTER pAd,
2443 + IN PUCHAR pAddr,
2444 + OUT SST *Sst,
2445 + OUT USHORT *Aid,
2446 + OUT UCHAR *PsMode,
2447 + OUT UCHAR *Rate);
2448 +
2449 +BOOLEAN APPsIndicate(
2450 + IN PRTMP_ADAPTER pAd,
2451 + IN PUCHAR pAddr,
2452 + IN ULONG Wcid,
2453 + IN UCHAR Psm);
2454 +
2455 +VOID ApLogEvent(
2456 + IN PRTMP_ADAPTER pAd,
2457 + IN PUCHAR pAddr,
2458 + IN USHORT Event);
2459 +
2460 +#ifdef DOT11_N_SUPPORT
2461 +VOID APUpdateOperationMode(
2462 + IN PRTMP_ADAPTER pAd);
2463 +#endif // DOT11_N_SUPPORT //
2464 +
2465 +VOID APUpdateCapabilityAndErpIe(
2466 + IN PRTMP_ADAPTER pAd);
2467 +
2468 +BOOLEAN ApCheckAccessControlList(
2469 + IN PRTMP_ADAPTER pAd,
2470 + IN PUCHAR pAddr,
2471 + IN UCHAR Apidx);
2472 +
2473 +VOID ApUpdateAccessControlList(
2474 + IN PRTMP_ADAPTER pAd,
2475 + IN UCHAR Apidx);
2476 +
2477 +VOID ApEnqueueNullFrame(
2478 + IN PRTMP_ADAPTER pAd,
2479 + IN PUCHAR pAddr,
2480 + IN UCHAR TxRate,
2481 + IN UCHAR PID,
2482 + IN UCHAR apidx,
2483 + IN BOOLEAN bQosNull,
2484 + IN BOOLEAN bEOSP,
2485 + IN UCHAR OldUP);
2486 +
2487 +VOID ApSendFrame(
2488 + IN PRTMP_ADAPTER pAd,
2489 + IN PVOID pBuffer,
2490 + IN ULONG Length,
2491 + IN UCHAR TxRate,
2492 + IN UCHAR PID);
2493 +
2494 +VOID ApEnqueueAckFrame(
2495 + IN PRTMP_ADAPTER pAd,
2496 + IN PUCHAR pAddr,
2497 + IN UCHAR TxRate,
2498 + IN UCHAR apidx);
2499 +
2500 +UCHAR APAutoSelectChannel(
2501 + IN PRTMP_ADAPTER pAd,
2502 + IN BOOLEAN Optimal);
2503 +
2504 +// ap_sanity.c
2505 +
2506 +
2507 +BOOLEAN PeerAssocReqCmmSanity(
2508 + IN PRTMP_ADAPTER pAd,
2509 + IN BOOLEAN isRessoc,
2510 + IN VOID *Msg,
2511 + IN ULONG MsgLen,
2512 + OUT PUCHAR pAddr2,
2513 + OUT USHORT *pCapabilityInfo,
2514 + OUT USHORT *pListenInterval,
2515 + OUT PUCHAR pApAddr,
2516 + OUT UCHAR *pSsidLen,
2517 + OUT char *Ssid,
2518 + OUT UCHAR *pRatesLen,
2519 + OUT UCHAR Rates[],
2520 + OUT UCHAR *RSN,
2521 + OUT UCHAR *pRSNLen,
2522 + OUT BOOLEAN *pbWmmCapable,
2523 + OUT ULONG *pRalinkIe,
2524 +#ifdef DOT11N_DRAFT3
2525 + OUT EXT_CAP_INFO_ELEMENT *pExtCapInfo,
2526 +#endif // DOT11N_DRAFT3 //
2527 + OUT UCHAR *pHtCapabilityLen,
2528 + OUT HT_CAPABILITY_IE *pHtCapability);
2529 +
2530 +
2531 +BOOLEAN PeerDisassocReqSanity(
2532 + IN PRTMP_ADAPTER pAd,
2533 + IN VOID *Msg,
2534 + IN ULONG MsgLen,
2535 + OUT PUCHAR pAddr2,
2536 + OUT USHORT *Reason);
2537 +
2538 +BOOLEAN PeerDeauthReqSanity(
2539 + IN PRTMP_ADAPTER pAd,
2540 + IN VOID *Msg,
2541 + IN ULONG MsgLen,
2542 + OUT PUCHAR pAddr2,
2543 + OUT USHORT *Reason);
2544 +
2545 +BOOLEAN APPeerAuthSanity(
2546 + IN PRTMP_ADAPTER pAd,
2547 + IN VOID *Msg,
2548 + IN ULONG MsgLen,
2549 + OUT PUCHAR pAddr1,
2550 + OUT PUCHAR pAddr2,
2551 + OUT USHORT *Alg,
2552 + OUT USHORT *Seq,
2553 + OUT USHORT *Status,
2554 + CHAR *ChlgText);
2555 +
2556 +BOOLEAN APPeerProbeReqSanity(
2557 + IN PRTMP_ADAPTER pAd,
2558 + IN VOID *Msg,
2559 + IN ULONG MsgLen,
2560 + OUT PUCHAR pAddr2,
2561 + OUT CHAR Ssid[],
2562 + OUT UCHAR *SsidLen);
2563 +
2564 +BOOLEAN APPeerBeaconAndProbeRspSanity(
2565 + IN PRTMP_ADAPTER pAd,
2566 + IN VOID *Msg,
2567 + IN ULONG MsgLen,
2568 + OUT PUCHAR pAddr2,
2569 + OUT PUCHAR pBssid,
2570 + OUT CHAR Ssid[],
2571 + OUT UCHAR *SsidLen,
2572 + OUT UCHAR *BssType,
2573 + OUT USHORT *BeaconPeriod,
2574 + OUT UCHAR *Channel,
2575 + OUT LARGE_INTEGER *Timestamp,
2576 + OUT USHORT *CapabilityInfo,
2577 + OUT UCHAR Rate[],
2578 + OUT UCHAR *RateLen,
2579 + OUT BOOLEAN *ExtendedRateIeExist,
2580 + OUT UCHAR *Erp);
2581 +
2582 +
2583 +// ================== end of AP RTMP.h ========================
2584 +
2585 +
2586 +#endif // __AP_H__
2587 +
2588 --- /dev/null
2589 +++ b/drivers/staging/rt3070/chlist.h
2590 @@ -0,0 +1,1253 @@
2591 +/*
2592 + *************************************************************************
2593 + * Ralink Tech Inc.
2594 + * 5F., No.36, Taiyuan St., Jhubei City,
2595 + * Hsinchu County 302,
2596 + * Taiwan, R.O.C.
2597 + *
2598 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
2599 + *
2600 + * This program is free software; you can redistribute it and/or modify *
2601 + * it under the terms of the GNU General Public License as published by *
2602 + * the Free Software Foundation; either version 2 of the License, or *
2603 + * (at your option) any later version. *
2604 + * *
2605 + * This program is distributed in the hope that it will be useful, *
2606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
2607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
2608 + * GNU General Public License for more details. *
2609 + * *
2610 + * You should have received a copy of the GNU General Public License *
2611 + * along with this program; if not, write to the *
2612 + * Free Software Foundation, Inc., *
2613 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
2614 + * *
2615 + *************************************************************************
2616 +
2617 + Module Name:
2618 + chlist.c
2619 +
2620 + Abstract:
2621 +
2622 + Revision History:
2623 + Who When What
2624 + -------- ---------- ----------------------------------------------
2625 + Fonchi Wu 2007-12-19 created
2626 +*/
2627 +
2628 +#ifndef __CHLIST_H__
2629 +#define __CHLIST_H__
2630 +
2631 +#include "rtmp_type.h"
2632 +#include "rtmp_def.h"
2633 +
2634 +
2635 +#define ODOR 0
2636 +#define IDOR 1
2637 +#define BOTH 2
2638 +
2639 +#define BAND_5G 0
2640 +#define BAND_24G 1
2641 +#define BAND_BOTH 2
2642 +
2643 +typedef struct _CH_DESP {
2644 + UCHAR FirstChannel;
2645 + UCHAR NumOfCh;
2646 + CHAR MaxTxPwr; // dBm
2647 + UCHAR Geography; // 0:out door, 1:in door, 2:both
2648 + BOOLEAN DfsReq; // Dfs require, 0: No, 1: yes.
2649 +} CH_DESP, *PCH_DESP;
2650 +
2651 +typedef struct _CH_REGION {
2652 + UCHAR CountReg[3];
2653 + UCHAR DfsType; // 0: CE, 1: FCC, 2: JAP, 3:JAP_W53, JAP_W56
2654 + CH_DESP ChDesp[10];
2655 +} CH_REGION, *PCH_REGION;
2656 +
2657 +static CH_REGION ChRegion[] =
2658 +{
2659 + { // Antigua and Berbuda
2660 + "AG",
2661 + CE,
2662 + {
2663 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2664 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2665 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2666 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2667 + { 0}, // end
2668 + }
2669 + },
2670 +
2671 + { // Argentina
2672 + "AR",
2673 + CE,
2674 + {
2675 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2676 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2677 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2678 + { 0}, // end
2679 + }
2680 + },
2681 +
2682 + { // Aruba
2683 + "AW",
2684 + CE,
2685 + {
2686 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2687 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2688 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2689 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2690 + { 0}, // end
2691 + }
2692 + },
2693 +
2694 + { // Australia
2695 + "AU",
2696 + CE,
2697 + {
2698 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2699 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2700 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2701 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2702 + { 0}, // end
2703 + }
2704 + },
2705 +
2706 + { // Austria
2707 + "AT",
2708 + CE,
2709 + {
2710 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2711 + { 36, 4, 23, IDOR, TRUE}, // 5G, ch 36~48
2712 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2713 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2714 + { 0}, // end
2715 + }
2716 + },
2717 +
2718 + { // Bahamas
2719 + "BS",
2720 + CE,
2721 + {
2722 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2723 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2724 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2725 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2726 + { 0}, // end
2727 + }
2728 + },
2729 +
2730 + { // Barbados
2731 + "BB",
2732 + CE,
2733 + {
2734 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2735 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2736 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2737 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2738 + { 0}, // end
2739 + }
2740 + },
2741 +
2742 + { // Bermuda
2743 + "BM",
2744 + CE,
2745 + {
2746 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2747 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2748 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2749 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2750 + { 0}, // end
2751 + }
2752 + },
2753 +
2754 + { // Brazil
2755 + "BR",
2756 + CE,
2757 + {
2758 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2759 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2760 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2761 + { 100, 11, 24, BOTH, FALSE}, // 5G, ch 100~140
2762 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 100~140
2763 + { 0}, // end
2764 + }
2765 + },
2766 +
2767 + { // Belgium
2768 + "BE",
2769 + CE,
2770 + {
2771 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2772 + { 36, 4, 18, IDOR, FALSE}, // 5G, ch 36~48
2773 + { 52, 4, 18, IDOR, FALSE}, // 5G, ch 52~64
2774 + { 0}, // end
2775 + }
2776 + },
2777 +
2778 + { // Bulgaria
2779 + "BG",
2780 + CE,
2781 + {
2782 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2783 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2784 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2785 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
2786 + { 0}, // end
2787 + }
2788 + },
2789 +
2790 + { // Canada
2791 + "CA",
2792 + CE,
2793 + {
2794 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2795 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2796 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
2797 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2798 + { 0}, // end
2799 + }
2800 + },
2801 +
2802 + { // Cayman IsLands
2803 + "KY",
2804 + CE,
2805 + {
2806 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2807 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
2808 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2809 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2810 + { 0}, // end
2811 + }
2812 + },
2813 +
2814 + { // Chile
2815 + "CL",
2816 + CE,
2817 + {
2818 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2819 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 36~48
2820 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
2821 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
2822 + { 0}, // end
2823 + }
2824 + },
2825 +
2826 + { // China
2827 + "CN",
2828 + CE,
2829 + {
2830 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2831 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
2832 + { 0}, // end
2833 + }
2834 + },
2835 +
2836 + { // Colombia
2837 + "CO",
2838 + CE,
2839 + {
2840 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2841 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2842 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2843 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2844 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2845 + { 0}, // end
2846 + }
2847 + },
2848 +
2849 + { // Costa Rica
2850 + "CR",
2851 + CE,
2852 + {
2853 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2854 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2855 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2856 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2857 + { 0}, // end
2858 + }
2859 + },
2860 +
2861 + { // Cyprus
2862 + "CY",
2863 + CE,
2864 + {
2865 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2866 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2867 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
2868 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2869 + { 0}, // end
2870 + }
2871 + },
2872 +
2873 + { // Czech_Republic
2874 + "CZ",
2875 + CE,
2876 + {
2877 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2878 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2879 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2880 + { 0}, // end
2881 + }
2882 + },
2883 +
2884 + { // Denmark
2885 + "DK",
2886 + CE,
2887 + {
2888 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2889 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2890 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2891 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2892 + { 0}, // end
2893 + }
2894 + },
2895 +
2896 + { // Dominican Republic
2897 + "DO",
2898 + CE,
2899 + {
2900 + { 1, 0, 20, BOTH, FALSE}, // 2.4 G, ch 0
2901 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
2902 + { 0}, // end
2903 + }
2904 + },
2905 +
2906 + { // Equador
2907 + "EC",
2908 + CE,
2909 + {
2910 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2911 + { 100, 11, 27, BOTH, FALSE}, // 5G, ch 100~140
2912 + { 0}, // end
2913 + }
2914 + },
2915 +
2916 + { // El Salvador
2917 + "SV",
2918 + CE,
2919 + {
2920 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2921 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2922 + { 52, 4, 30, BOTH, TRUE}, // 5G, ch 52~64
2923 + { 149, 4, 36, BOTH, TRUE}, // 5G, ch 149~165
2924 + { 0}, // end
2925 + }
2926 + },
2927 +
2928 + { // Finland
2929 + "FI",
2930 + CE,
2931 + {
2932 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2933 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2934 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2935 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2936 + { 0}, // end
2937 + }
2938 + },
2939 +
2940 + { // France
2941 + "FR",
2942 + CE,
2943 + {
2944 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2945 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2946 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2947 + { 0}, // end
2948 + }
2949 + },
2950 +
2951 + { // Germany
2952 + "DE",
2953 + CE,
2954 + {
2955 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2956 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2957 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2958 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
2959 + { 0}, // end
2960 + }
2961 + },
2962 +
2963 + { // Greece
2964 + "GR",
2965 + CE,
2966 + {
2967 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2968 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
2969 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
2970 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
2971 + { 0}, // end
2972 + }
2973 + },
2974 +
2975 + { // Guam
2976 + "GU",
2977 + CE,
2978 + {
2979 + { 1, 11, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
2980 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2981 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2982 + { 100, 11, 30, BOTH, FALSE}, // 5G, ch 100~140
2983 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
2984 + { 0}, // end
2985 + }
2986 + },
2987 +
2988 + { // Guatemala
2989 + "GT",
2990 + CE,
2991 + {
2992 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
2993 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
2994 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
2995 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
2996 + { 0}, // end
2997 + }
2998 + },
2999 +
3000 + { // Haiti
3001 + "HT",
3002 + CE,
3003 + {
3004 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3005 + { 36, 4, 17, BOTH, FALSE}, // 5G, ch 36~48
3006 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
3007 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3008 + { 0}, // end
3009 + }
3010 + },
3011 +
3012 + { // Honduras
3013 + "HN",
3014 + CE,
3015 + {
3016 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3017 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3018 + { 0}, // end
3019 + }
3020 + },
3021 +
3022 + { // Hong Kong
3023 + "HK",
3024 + CE,
3025 + {
3026 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3027 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3028 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3029 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3030 + { 0}, // end
3031 + }
3032 + },
3033 +
3034 + { // Hungary
3035 + "HU",
3036 + CE,
3037 + {
3038 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3039 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3040 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3041 + { 0}, // end
3042 + }
3043 + },
3044 +
3045 + { // Iceland
3046 + "IS",
3047 + CE,
3048 + {
3049 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3050 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3051 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3052 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3053 + { 0}, // end
3054 + }
3055 + },
3056 +
3057 + { // India
3058 + "IN",
3059 + CE,
3060 + {
3061 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3062 + { 149, 4, 24, IDOR, FALSE}, // 5G, ch 149~161
3063 + { 0}, // end
3064 + }
3065 + },
3066 +
3067 + { // Indonesia
3068 + "ID",
3069 + CE,
3070 + {
3071 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3072 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3073 + { 0}, // end
3074 + }
3075 + },
3076 +
3077 + { // Ireland
3078 + "IE",
3079 + CE,
3080 + {
3081 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3082 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3083 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3084 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
3085 + { 0}, // end
3086 + }
3087 + },
3088 +
3089 + { // Israel
3090 + "IL",
3091 + CE,
3092 + {
3093 + { 1, 3, 20, IDOR, FALSE}, // 2.4 G, ch 1~3
3094 + { 4, 6, 20, BOTH, FALSE}, // 2.4 G, ch 4~9
3095 + { 10, 4, 20, IDOR, FALSE}, // 2.4 G, ch 10~13
3096 + { 0}, // end
3097 + }
3098 + },
3099 +
3100 + { // Italy
3101 + "IT",
3102 + CE,
3103 + {
3104 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3105 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3106 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3107 + { 100, 11, 30, ODOR, TRUE}, // 5G, ch 100~140
3108 + { 0}, // end
3109 + }
3110 + },
3111 +
3112 + { // Japan
3113 + "JP",
3114 + JAP,
3115 + {
3116 + { 1, 14, 20, BOTH, FALSE}, // 2.4 G, ch 1~14
3117 + { 34, 4, 23, IDOR, FALSE}, // 5G, ch 34~46
3118 + { 0}, // end
3119 + }
3120 + },
3121 +
3122 + { // Jordan
3123 + "JO",
3124 + CE,
3125 + {
3126 + { 1, 13, 20, IDOR, FALSE}, // 2.4 G, ch 1~13
3127 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3128 + { 149, 4, 23, IDOR, FALSE}, // 5G, ch 149~161
3129 + { 0}, // end
3130 + }
3131 + },
3132 +
3133 + { // Latvia
3134 + "LV",
3135 + CE,
3136 + {
3137 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3138 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3139 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3140 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3141 + { 0}, // end
3142 + }
3143 + },
3144 +
3145 + { // Liechtenstein
3146 + "LI",
3147 + CE,
3148 + {
3149 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3150 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3151 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3152 + { 0}, // end
3153 + }
3154 + },
3155 +
3156 + { // Lithuania
3157 + "LT",
3158 + CE,
3159 + {
3160 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3161 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3162 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3163 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3164 + { 0}, // end
3165 + }
3166 + },
3167 +
3168 + { // Luxemburg
3169 + "LU",
3170 + CE,
3171 + {
3172 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3173 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3174 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3175 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3176 + { 0}, // end
3177 + }
3178 + },
3179 +
3180 + { // Malaysia
3181 + "MY",
3182 + CE,
3183 + {
3184 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3185 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3186 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
3187 + { 0}, // end
3188 + }
3189 + },
3190 +
3191 + { // Malta
3192 + "MT",
3193 + CE,
3194 + {
3195 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3196 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3197 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3198 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3199 + { 0}, // end
3200 + }
3201 + },
3202 +
3203 + { // Marocco
3204 + "MA",
3205 + CE,
3206 + {
3207 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3208 + { 36, 4, 24, IDOR, FALSE}, // 5G, ch 36~48
3209 + { 0}, // end
3210 + }
3211 + },
3212 +
3213 + { // Mexico
3214 + "MX",
3215 + CE,
3216 + {
3217 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3218 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3219 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
3220 + { 149, 5, 30, IDOR, FALSE}, // 5G, ch 149~165
3221 + { 0}, // end
3222 + }
3223 + },
3224 +
3225 + { // Netherlands
3226 + "NL",
3227 + CE,
3228 + {
3229 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3230 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3231 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
3232 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3233 + { 0}, // end
3234 + }
3235 + },
3236 +
3237 + { // New Zealand
3238 + "NZ",
3239 + CE,
3240 + {
3241 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3242 + { 36, 4, 24, BOTH, FALSE}, // 5G, ch 36~48
3243 + { 52, 4, 24, BOTH, FALSE}, // 5G, ch 52~64
3244 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3245 + { 0}, // end
3246 + }
3247 + },
3248 +
3249 + { // Norway
3250 + "NO",
3251 + CE,
3252 + {
3253 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3254 + { 36, 4, 24, IDOR, FALSE}, // 5G, ch 36~48
3255 + { 52, 4, 24, IDOR, TRUE}, // 5G, ch 52~64
3256 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 149~161
3257 + { 0}, // end
3258 + }
3259 + },
3260 +
3261 + { // Peru
3262 + "PE",
3263 + CE,
3264 + {
3265 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3266 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3267 + { 0}, // end
3268 + }
3269 + },
3270 +
3271 + { // Portugal
3272 + "PT",
3273 + CE,
3274 + {
3275 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3276 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3277 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3278 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3279 + { 0}, // end
3280 + }
3281 + },
3282 +
3283 + { // Poland
3284 + "PL",
3285 + CE,
3286 + {
3287 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3288 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3289 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3290 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3291 + { 0}, // end
3292 + }
3293 + },
3294 +
3295 + { // Romania
3296 + "RO",
3297 + CE,
3298 + {
3299 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3300 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3301 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3302 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3303 + { 0}, // end
3304 + }
3305 + },
3306 +
3307 + { // Russia
3308 + "RU",
3309 + CE,
3310 + {
3311 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3312 + { 149, 4, 20, IDOR, FALSE}, // 5G, ch 149~161
3313 + { 0}, // end
3314 + }
3315 + },
3316 +
3317 + { // Saudi Arabia
3318 + "SA",
3319 + CE,
3320 + {
3321 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3322 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3323 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3324 + { 149, 4, 23, BOTH, FALSE}, // 5G, ch 149~161
3325 + { 0}, // end
3326 + }
3327 + },
3328 +
3329 + { // Serbia_and_Montenegro
3330 + "CS",
3331 + CE,
3332 + {
3333 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3334 + { 0}, // end
3335 + }
3336 + },
3337 +
3338 + { // Singapore
3339 + "SG",
3340 + CE,
3341 + {
3342 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3343 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3344 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3345 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
3346 + { 0}, // end
3347 + }
3348 + },
3349 +
3350 + { // Slovakia
3351 + "SK",
3352 + CE,
3353 + {
3354 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3355 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3356 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3357 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3358 + { 0}, // end
3359 + }
3360 + },
3361 +
3362 + { // Slovenia
3363 + "SI",
3364 + CE,
3365 + {
3366 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3367 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3368 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3369 + { 0}, // end
3370 + }
3371 + },
3372 +
3373 + { // South Africa
3374 + "ZA",
3375 + CE,
3376 + {
3377 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3378 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3379 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3380 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3381 + { 149, 4, 30, BOTH, FALSE}, // 5G, ch 149~161
3382 + { 0}, // end
3383 + }
3384 + },
3385 +
3386 + { // South Korea
3387 + "KR",
3388 + CE,
3389 + {
3390 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3391 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 36~48
3392 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3393 + { 100, 8, 20, BOTH, FALSE}, // 5G, ch 100~128
3394 + { 149, 4, 20, BOTH, FALSE}, // 5G, ch 149~161
3395 + { 0}, // end
3396 + }
3397 + },
3398 +
3399 + { // Spain
3400 + "ES",
3401 + CE,
3402 + {
3403 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3404 + { 36, 4, 17, IDOR, FALSE}, // 5G, ch 36~48
3405 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3406 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3407 + { 0}, // end
3408 + }
3409 + },
3410 +
3411 + { // Sweden
3412 + "SE",
3413 + CE,
3414 + {
3415 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3416 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 36~48
3417 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3418 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3419 + { 0}, // end
3420 + }
3421 + },
3422 +
3423 + { // Switzerland
3424 + "CH",
3425 + CE,
3426 + {
3427 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~13
3428 + { 36, 4, 23, IDOR, TRUE}, // 5G, ch 36~48
3429 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3430 + { 0}, // end
3431 + }
3432 + },
3433 +
3434 + { // Taiwan
3435 + "TW",
3436 + CE,
3437 + {
3438 + { 1, 11, 30, BOTH, FALSE}, // 2.4 G, ch 1~11
3439 + { 52, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3440 + { 0}, // end
3441 + }
3442 + },
3443 +
3444 + { // Turkey
3445 + "TR",
3446 + CE,
3447 + {
3448 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3449 + { 36, 4, 23, BOTH, FALSE}, // 5G, ch 36~48
3450 + { 52, 4, 23, BOTH, FALSE}, // 5G, ch 52~64
3451 + { 0}, // end
3452 + }
3453 + },
3454 +
3455 + { // UK
3456 + "GB",
3457 + CE,
3458 + {
3459 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3460 + { 36, 4, 23, IDOR, FALSE}, // 5G, ch 52~64
3461 + { 52, 4, 23, IDOR, TRUE}, // 5G, ch 52~64
3462 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3463 + { 0}, // end
3464 + }
3465 + },
3466 +
3467 + { // Ukraine
3468 + "UA",
3469 + CE,
3470 + {
3471 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3472 + { 0}, // end
3473 + }
3474 + },
3475 +
3476 + { // United_Arab_Emirates
3477 + "AE",
3478 + CE,
3479 + {
3480 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3481 + { 0}, // end
3482 + }
3483 + },
3484 +
3485 + { // United_States
3486 + "US",
3487 + CE,
3488 + {
3489 + { 1, 11, 30, BOTH, FALSE}, // 2.4 G, ch 1~11
3490 + { 36, 4, 17, IDOR, FALSE}, // 5G, ch 52~64
3491 + { 52, 4, 24, BOTH, TRUE}, // 5G, ch 52~64
3492 + { 100, 11, 30, BOTH, TRUE}, // 5G, ch 100~140
3493 + { 149, 5, 30, BOTH, FALSE}, // 5G, ch 149~165
3494 + { 0}, // end
3495 + }
3496 + },
3497 +
3498 + { // Venezuela
3499 + "VE",
3500 + CE,
3501 + {
3502 + { 1, 13, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3503 + { 149, 4, 27, BOTH, FALSE}, // 5G, ch 149~161
3504 + { 0}, // end
3505 + }
3506 + },
3507 +
3508 + { // Default
3509 + "",
3510 + CE,
3511 + {
3512 + { 1, 11, 20, BOTH, FALSE}, // 2.4 G, ch 1~11
3513 + { 36, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3514 + { 52, 4, 20, BOTH, FALSE}, // 5G, ch 52~64
3515 + { 100, 11, 20, BOTH, FALSE}, // 5G, ch 100~140
3516 + { 149, 5, 20, BOTH, FALSE}, // 5G, ch 149~165
3517 + { 0}, // end
3518 + }
3519 + },
3520 +};
3521 +
3522 +static inline PCH_REGION GetChRegion(
3523 + IN PUCHAR CntryCode)
3524 +{
3525 + INT loop = 0;
3526 + PCH_REGION pChRegion = NULL;
3527 +
3528 + while (strcmp(ChRegion[loop].CountReg, "") != 0)
3529 + {
3530 + if (strncmp(ChRegion[loop].CountReg, CntryCode, 2) == 0)
3531 + {
3532 + pChRegion = &ChRegion[loop];
3533 + break;
3534 + }
3535 + loop++;
3536 + }
3537 +
3538 + if (pChRegion == NULL)
3539 + pChRegion = &ChRegion[loop];
3540 + return pChRegion;
3541 +}
3542 +
3543 +static inline VOID ChBandCheck(
3544 + IN UCHAR PhyMode,
3545 + OUT PUCHAR pChType)
3546 +{
3547 + switch(PhyMode)
3548 + {
3549 + case PHY_11A:
3550 +#ifdef DOT11_N_SUPPORT
3551 + case PHY_11AN_MIXED:
3552 +#endif // DOT11_N_SUPPORT //
3553 + *pChType = BAND_5G;
3554 + break;
3555 + case PHY_11ABG_MIXED:
3556 +#ifdef DOT11_N_SUPPORT
3557 + case PHY_11AGN_MIXED:
3558 + case PHY_11ABGN_MIXED:
3559 +#endif // DOT11_N_SUPPORT //
3560 + *pChType = BAND_BOTH;
3561 + break;
3562 +
3563 + default:
3564 + *pChType = BAND_24G;
3565 + break;
3566 + }
3567 +}
3568 +
3569 +static inline UCHAR FillChList(
3570 + IN PRTMP_ADAPTER pAd,
3571 + IN PCH_DESP pChDesp,
3572 + IN UCHAR Offset,
3573 + IN UCHAR increment)
3574 +{
3575 + INT i, j, l;
3576 + UCHAR channel;
3577 +
3578 + j = Offset;
3579 + for (i = 0; i < pChDesp->NumOfCh; i++)
3580 + {
3581 + channel = pChDesp->FirstChannel + i * increment;
3582 + for (l=0; l<MAX_NUM_OF_CHANNELS; l++)
3583 + {
3584 + if (channel == pAd->TxPower[l].Channel)
3585 + {
3586 + pAd->ChannelList[j].Power = pAd->TxPower[l].Power;
3587 + pAd->ChannelList[j].Power2 = pAd->TxPower[l].Power2;
3588 + break;
3589 + }
3590 + }
3591 + if (l == MAX_NUM_OF_CHANNELS)
3592 + continue;
3593 +
3594 + pAd->ChannelList[j].Channel = pChDesp->FirstChannel + i * increment;
3595 + pAd->ChannelList[j].MaxTxPwr = pChDesp->MaxTxPwr;
3596 + pAd->ChannelList[j].DfsReq = pChDesp->DfsReq;
3597 + j++;
3598 + }
3599 + pAd->ChannelListNum = j;
3600 +
3601 + return j;
3602 +}
3603 +
3604 +static inline VOID CreateChList(
3605 + IN PRTMP_ADAPTER pAd,
3606 + IN PCH_REGION pChRegion,
3607 + IN UCHAR Geography)
3608 +{
3609 + INT i;
3610 + UCHAR offset = 0;
3611 + PCH_DESP pChDesp;
3612 + UCHAR ChType;
3613 + UCHAR increment;
3614 +
3615 + if (pChRegion == NULL)
3616 + return;
3617 +
3618 + ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
3619 +
3620 + for (i=0; i<10; i++)
3621 + {
3622 + pChDesp = &pChRegion->ChDesp[i];
3623 + if (pChDesp->FirstChannel == 0)
3624 + break;
3625 +
3626 + if (ChType == BAND_5G)
3627 + {
3628 + if (pChDesp->FirstChannel <= 14)
3629 + continue;
3630 + }
3631 + else if (ChType == BAND_24G)
3632 + {
3633 + if (pChDesp->FirstChannel > 14)
3634 + continue;
3635 + }
3636 +
3637 + if ((pChDesp->Geography == BOTH)
3638 + || (pChDesp->Geography == Geography))
3639 + {
3640 + if (pChDesp->FirstChannel > 14)
3641 + increment = 4;
3642 + else
3643 + increment = 1;
3644 + offset = FillChList(pAd, pChDesp, offset, increment);
3645 + }
3646 + }
3647 +}
3648 +
3649 +static inline VOID BuildChannelListEx(
3650 + IN PRTMP_ADAPTER pAd)
3651 +{
3652 + PCH_REGION pChReg;
3653 +
3654 + pChReg = GetChRegion(pAd->CommonCfg.CountryCode);
3655 + CreateChList(pAd, pChReg, pAd->CommonCfg.Geography);
3656 +}
3657 +
3658 +static inline VOID BuildBeaconChList(
3659 + IN PRTMP_ADAPTER pAd,
3660 + OUT PUCHAR pBuf,
3661 + OUT PULONG pBufLen)
3662 +{
3663 + INT i;
3664 + ULONG TmpLen;
3665 + PCH_REGION pChRegion;
3666 + PCH_DESP pChDesp;
3667 + UCHAR ChType;
3668 +
3669 + pChRegion = GetChRegion(pAd->CommonCfg.CountryCode);
3670 +
3671 + if (pChRegion == NULL)
3672 + return;
3673 +
3674 + ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
3675 + *pBufLen = 0;
3676 +
3677 + for (i=0; i<10; i++)
3678 + {
3679 + pChDesp = &pChRegion->ChDesp[i];
3680 + if (pChDesp->FirstChannel == 0)
3681 + break;
3682 +
3683 + if (ChType == BAND_5G)
3684 + {
3685 + if (pChDesp->FirstChannel <= 14)
3686 + continue;
3687 + }
3688 + else if (ChType == BAND_24G)
3689 + {
3690 + if (pChDesp->FirstChannel > 14)
3691 + continue;
3692 + }
3693 +
3694 + if ((pChDesp->Geography == BOTH)
3695 + || (pChDesp->Geography == pAd->CommonCfg.Geography))
3696 + {
3697 + MakeOutgoingFrame(pBuf + *pBufLen, &TmpLen,
3698 + 1, &pChDesp->FirstChannel,
3699 + 1, &pChDesp->NumOfCh,
3700 + 1, &pChDesp->MaxTxPwr,
3701 + END_OF_ARGS);
3702 + *pBufLen += TmpLen;
3703 + }
3704 + }
3705 +}
3706 +
3707 +
3708 +#ifdef DOT11_N_SUPPORT
3709 +static inline BOOLEAN IsValidChannel(
3710 + IN PRTMP_ADAPTER pAd,
3711 + IN UCHAR channel)
3712 +
3713 +{
3714 + INT i;
3715 +
3716 + for (i = 0; i < pAd->ChannelListNum; i++)
3717 + {
3718 + if (pAd->ChannelList[i].Channel == channel)
3719 + break;
3720 + }
3721 +
3722 + if (i == pAd->ChannelListNum)
3723 + return FALSE;
3724 + else
3725 + return TRUE;
3726 +}
3727 +
3728 +
3729 +static inline UCHAR GetExtCh(
3730 + IN UCHAR Channel,
3731 + IN UCHAR Direction)
3732 +{
3733 + CHAR ExtCh;
3734 +
3735 + if (Direction == EXTCHA_ABOVE)
3736 + ExtCh = Channel + 4;
3737 + else
3738 + ExtCh = (Channel - 4) > 0 ? (Channel - 4) : 0;
3739 +
3740 + return ExtCh;
3741 +}
3742 +
3743 +
3744 +static inline VOID N_ChannelCheck(
3745 + IN PRTMP_ADAPTER pAd)
3746 +{
3747 + //UCHAR ChannelNum = pAd->ChannelListNum;
3748 + UCHAR Channel = pAd->CommonCfg.Channel;
3749 +
3750 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
3751 + {
3752 + if (Channel > 14)
3753 + {
3754 + if ((Channel == 36) || (Channel == 44) || (Channel == 52) || (Channel == 60) || (Channel == 100) || (Channel == 108) ||
3755 + (Channel == 116) || (Channel == 124) || (Channel == 132) || (Channel == 149) || (Channel == 157))
3756 + {
3757 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
3758 + }
3759 + else if ((Channel == 40) || (Channel == 48) || (Channel == 56) || (Channel == 64) || (Channel == 104) || (Channel == 112) ||
3760 + (Channel == 120) || (Channel == 128) || (Channel == 136) || (Channel == 153) || (Channel == 161))
3761 + {
3762 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
3763 + }
3764 + else
3765 + {
3766 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3767 + }
3768 + }
3769 + else
3770 + {
3771 + do
3772 + {
3773 + UCHAR ExtCh;
3774 + UCHAR Dir = pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
3775 + ExtCh = GetExtCh(Channel, Dir);
3776 + if (IsValidChannel(pAd, ExtCh))
3777 + break;
3778 +
3779 + Dir = (Dir == EXTCHA_ABOVE) ? EXTCHA_BELOW : EXTCHA_ABOVE;
3780 + ExtCh = GetExtCh(Channel, Dir);
3781 + if (IsValidChannel(pAd, ExtCh))
3782 + {
3783 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = Dir;
3784 + break;
3785 + }
3786 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3787 + } while(FALSE);
3788 +
3789 + if (Channel == 14)
3790 + {
3791 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
3792 + //pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_NONE; // We didn't set the ExtCh as NONE due to it'll set in RTMPSetHT()
3793 + }
3794 + }
3795 + }
3796 +
3797 +
3798 +}
3799 +
3800 +
3801 +static inline VOID N_SetCenCh(
3802 + IN PRTMP_ADAPTER pAd)
3803 +{
3804 + if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
3805 + {
3806 + if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
3807 + {
3808 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
3809 + }
3810 + else
3811 + {
3812 + if (pAd->CommonCfg.Channel == 14)
3813 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 1;
3814 + else
3815 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
3816 + }
3817 + }
3818 + else
3819 + {
3820 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
3821 + }
3822 +}
3823 +#endif // DOT11_N_SUPPORT //
3824 +
3825 +
3826 +static inline UINT8 GetCuntryMaxTxPwr(
3827 + IN PRTMP_ADAPTER pAd,
3828 + IN UINT8 channel)
3829 +{
3830 + int i;
3831 + for (i = 0; i < pAd->ChannelListNum; i++)
3832 + {
3833 + if (pAd->ChannelList[i].Channel == channel)
3834 + break;
3835 + }
3836 +
3837 + if (i == pAd->ChannelListNum)
3838 + return 0xff;
3839 + else
3840 + return pAd->ChannelList[i].MaxTxPwr;
3841 +}
3842 +#endif // __CHLIST_H__
3843 +
3844 --- /dev/null
3845 +++ b/drivers/staging/rt3070/common/2870_rtmp_init.c
3846 @@ -0,0 +1,1762 @@
3847 +/*
3848 + *************************************************************************
3849 + * Ralink Tech Inc.
3850 + * 5F., No.36, Taiyuan St., Jhubei City,
3851 + * Hsinchu County 302,
3852 + * Taiwan, R.O.C.
3853 + *
3854 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
3855 + *
3856 + * This program is free software; you can redistribute it and/or modify *
3857 + * it under the terms of the GNU General Public License as published by *
3858 + * the Free Software Foundation; either version 2 of the License, or *
3859 + * (at your option) any later version. *
3860 + * *
3861 + * This program is distributed in the hope that it will be useful, *
3862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
3863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
3864 + * GNU General Public License for more details. *
3865 + * *
3866 + * You should have received a copy of the GNU General Public License *
3867 + * along with this program; if not, write to the *
3868 + * Free Software Foundation, Inc., *
3869 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
3870 + * *
3871 + *************************************************************************
3872 +
3873 + Module Name:
3874 + 2870_rtmp_init.c
3875 +
3876 + Abstract:
3877 + Miniport generic portion header file
3878 +
3879 + Revision History:
3880 + Who When What
3881 + -------- ---------- ----------------------------------------------
3882 + Paul Lin 2002-08-01 created
3883 + John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme
3884 + Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT.
3885 + Sample Lin 2007-05-31 Merge RT2860 and RT2870 drivers.
3886 +*/
3887 +
3888 +#include "../rt_config.h"
3889 +
3890 +
3891 +static void rx_done_tasklet(unsigned long data);
3892 +static void rt2870_hcca_dma_done_tasklet(unsigned long data);
3893 +static void rt2870_ac3_dma_done_tasklet(unsigned long data);
3894 +static void rt2870_ac2_dma_done_tasklet(unsigned long data);
3895 +static void rt2870_ac1_dma_done_tasklet(unsigned long data);
3896 +static void rt2870_ac0_dma_done_tasklet(unsigned long data);
3897 +static void rt2870_mgmt_dma_done_tasklet(unsigned long data);
3898 +static void rt2870_null_frame_complete_tasklet(unsigned long data);
3899 +static void rt2870_rts_frame_complete_tasklet(unsigned long data);
3900 +static void rt2870_pspoll_frame_complete_tasklet(unsigned long data);
3901 +static void rt2870_dataout_complete_tasklet(unsigned long data);
3902 +
3903 +
3904 +/*
3905 +========================================================================
3906 +Routine Description:
3907 + Initialize receive data structures.
3908 +
3909 +Arguments:
3910 + pAd Pointer to our adapter
3911 +
3912 +Return Value:
3913 + NDIS_STATUS_SUCCESS
3914 + NDIS_STATUS_RESOURCES
3915 +
3916 +Note:
3917 + Initialize all receive releated private buffer, include those define
3918 + in RTMP_ADAPTER structure and all private data structures. The mahor
3919 + work is to allocate buffer for each packet and chain buffer to
3920 + NDIS packet descriptor.
3921 +========================================================================
3922 +*/
3923 +NDIS_STATUS NICInitRecv(
3924 + IN PRTMP_ADAPTER pAd)
3925 +{
3926 + UCHAR i;
3927 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
3928 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
3929 +
3930 +
3931 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitRecv\n"));
3932 + pObj = pObj;
3933 +
3934 + //InterlockedExchange(&pAd->PendingRx, 0);
3935 + pAd->PendingRx = 0;
3936 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
3937 + pAd->NextRxBulkInIndex = 0 ; //RX_RING_SIZE -1; // Rx Bulk pointer
3938 + pAd->NextRxBulkInPosition = 0;
3939 +
3940 + for (i = 0; i < (RX_RING_SIZE); i++)
3941 + {
3942 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
3943 +
3944 + //Allocate URB
3945 + pRxContext->pUrb = RTUSB_ALLOC_URB(0);
3946 + if (pRxContext->pUrb == NULL)
3947 + {
3948 + Status = NDIS_STATUS_RESOURCES;
3949 + goto out1;
3950 + }
3951 +
3952 + // Allocate transfer buffer
3953 + pRxContext->TransferBuffer = RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE, &pRxContext->data_dma);
3954 + if (pRxContext->TransferBuffer == NULL)
3955 + {
3956 + Status = NDIS_STATUS_RESOURCES;
3957 + goto out1;
3958 + }
3959 +
3960 + NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
3961 +
3962 + pRxContext->pAd = pAd;
3963 + pRxContext->pIrp = NULL;
3964 + pRxContext->InUse = FALSE;
3965 + pRxContext->IRPPending = FALSE;
3966 + pRxContext->Readable = FALSE;
3967 + //pRxContext->ReorderInUse = FALSE;
3968 + pRxContext->bRxHandling = FALSE;
3969 + pRxContext->BulkInOffset = 0;
3970 + }
3971 +
3972 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitRecv\n"));
3973 + return Status;
3974 +
3975 +out1:
3976 + for (i = 0; i < (RX_RING_SIZE); i++)
3977 + {
3978 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
3979 +
3980 + if (NULL != pRxContext->TransferBuffer)
3981 + {
3982 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE,
3983 + pRxContext->TransferBuffer, pRxContext->data_dma);
3984 + pRxContext->TransferBuffer = NULL;
3985 + }
3986 +
3987 + if (NULL != pRxContext->pUrb)
3988 + {
3989 + RTUSB_UNLINK_URB(pRxContext->pUrb);
3990 + RTUSB_FREE_URB(pRxContext->pUrb);
3991 + pRxContext->pUrb = NULL;
3992 + }
3993 + }
3994 +
3995 + return Status;
3996 +}
3997 +
3998 +
3999 +/*
4000 +========================================================================
4001 +Routine Description:
4002 + Initialize transmit data structures.
4003 +
4004 +Arguments:
4005 + pAd Pointer to our adapter
4006 +
4007 +Return Value:
4008 + NDIS_STATUS_SUCCESS
4009 + NDIS_STATUS_RESOURCES
4010 +
4011 +Note:
4012 +========================================================================
4013 +*/
4014 +NDIS_STATUS NICInitTransmit(
4015 + IN PRTMP_ADAPTER pAd)
4016 +{
4017 +#define LM_USB_ALLOC(pObj, Context, TB_Type, BufferSize, Status, msg1, err1, msg2, err2) \
4018 + Context->pUrb = RTUSB_ALLOC_URB(0); \
4019 + if (Context->pUrb == NULL) { \
4020 + DBGPRINT(RT_DEBUG_ERROR, msg1); \
4021 + Status = NDIS_STATUS_RESOURCES; \
4022 + goto err1; } \
4023 + \
4024 + Context->TransferBuffer = \
4025 + (TB_Type)RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, BufferSize, &Context->data_dma); \
4026 + if (Context->TransferBuffer == NULL) { \
4027 + DBGPRINT(RT_DEBUG_ERROR, msg2); \
4028 + Status = NDIS_STATUS_RESOURCES; \
4029 + goto err2; }
4030 +
4031 +#define LM_URB_FREE(pObj, Context, BufferSize) \
4032 + if (NULL != Context->pUrb) { \
4033 + RTUSB_UNLINK_URB(Context->pUrb); \
4034 + RTUSB_FREE_URB(Context->pUrb); \
4035 + Context->pUrb = NULL; } \
4036 + if (NULL != Context->TransferBuffer) { \
4037 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
4038 + Context->TransferBuffer, \
4039 + Context->data_dma); \
4040 + Context->TransferBuffer = NULL; }
4041 +
4042 + UCHAR i, acidx;
4043 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
4044 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
4045 + PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext);
4046 + PTX_CONTEXT pRTSContext = &(pAd->RTSContext);
4047 + PTX_CONTEXT pMLMEContext = NULL;
4048 +// PHT_TX_CONTEXT pHTTXContext = NULL;
4049 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4050 + PVOID RingBaseVa;
4051 +// RTMP_TX_RING *pTxRing;
4052 + RTMP_MGMT_RING *pMgmtRing;
4053 +
4054 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitTransmit\n"));
4055 + pObj = pObj;
4056 +
4057 + // Init 4 set of Tx parameters
4058 + for(acidx = 0; acidx < NUM_OF_TX_RING; acidx++)
4059 + {
4060 + // Initialize all Transmit releated queues
4061 + InitializeQueueHeader(&pAd->TxSwQueue[acidx]);
4062 +
4063 + // Next Local tx ring pointer waiting for buck out
4064 + pAd->NextBulkOutIndex[acidx] = acidx;
4065 + pAd->BulkOutPending[acidx] = FALSE; // Buck Out control flag
4066 + //pAd->DataBulkDoneIdx[acidx] = 0;
4067 + }
4068 +
4069 + //pAd->NextMLMEIndex = 0;
4070 + //pAd->PushMgmtIndex = 0;
4071 + //pAd->PopMgmtIndex = 0;
4072 + //InterlockedExchange(&pAd->MgmtQueueSize, 0);
4073 + //InterlockedExchange(&pAd->TxCount, 0);
4074 +
4075 + //pAd->PrioRingFirstIndex = 0;
4076 + //pAd->PrioRingTxCnt = 0;
4077 +
4078 + do
4079 + {
4080 + //
4081 + // TX_RING_SIZE, 4 ACs
4082 + //
4083 +#ifdef CONFIG_STA_SUPPORT
4084 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
4085 + for(acidx=0; acidx<4; acidx++)
4086 +#endif // CONFIG_STA_SUPPORT //
4087 + {
4088 +#if 1 //def DOT11_N_SUPPORT
4089 + PHT_TX_CONTEXT pHTTXContext = &(pAd->TxContext[acidx]);
4090 +
4091 + NdisZeroMemory(pHTTXContext, sizeof(HT_TX_CONTEXT));
4092 + //Allocate URB
4093 + LM_USB_ALLOC(pObj, pHTTXContext, PHTTX_BUFFER, sizeof(HTTX_BUFFER), Status,
4094 + ("<-- ERROR in Alloc TX TxContext[%d] urb!! \n", acidx),
4095 + done,
4096 + ("<-- ERROR in Alloc TX TxContext[%d] HTTX_BUFFER !! \n", acidx),
4097 + out1);
4098 +
4099 + NdisZeroMemory(pHTTXContext->TransferBuffer->Aggregation, 4);
4100 + pHTTXContext->pAd = pAd;
4101 + pHTTXContext->pIrp = NULL;
4102 + pHTTXContext->IRPPending = FALSE;
4103 + pHTTXContext->NextBulkOutPosition = 0;
4104 + pHTTXContext->ENextBulkOutPosition = 0;
4105 + pHTTXContext->CurWritePosition = 0;
4106 + pHTTXContext->CurWriteRealPos = 0;
4107 + pHTTXContext->BulkOutSize = 0;
4108 + pHTTXContext->BulkOutPipeId = acidx;
4109 + pHTTXContext->bRingEmpty = TRUE;
4110 + pHTTXContext->bCopySavePad = FALSE;
4111 +#endif // DOT11_N_SUPPORT //
4112 + pAd->BulkOutPending[acidx] = FALSE;
4113 + }
4114 +
4115 +
4116 + //
4117 + // MGMT_RING_SIZE
4118 + //
4119 + // Allocate MGMT ring descriptor's memory
4120 + pAd->MgmtDescRing.AllocSize = MGMT_RING_SIZE * sizeof(TX_CONTEXT);
4121 + RTMPAllocateMemory(&pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize);
4122 + if (pAd->MgmtDescRing.AllocVa == NULL)
4123 + {
4124 + DBGPRINT_ERR(("Failed to allocate a big buffer for MgmtDescRing!\n"));
4125 + Status = NDIS_STATUS_RESOURCES;
4126 + goto out1;
4127 + }
4128 + NdisZeroMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize);
4129 + RingBaseVa = pAd->MgmtDescRing.AllocVa;
4130 +
4131 + // Initialize MGMT Ring and associated buffer memory
4132 + pMgmtRing = &pAd->MgmtRing;
4133 + for (i = 0; i < MGMT_RING_SIZE; i++)
4134 + {
4135 + // link the pre-allocated Mgmt buffer to MgmtRing.Cell
4136 + pMgmtRing->Cell[i].AllocSize = sizeof(TX_CONTEXT);
4137 + pMgmtRing->Cell[i].AllocVa = RingBaseVa;
4138 + pMgmtRing->Cell[i].pNdisPacket = NULL;
4139 + pMgmtRing->Cell[i].pNextNdisPacket = NULL;
4140 +
4141 + //Allocate URB for MLMEContext
4142 + pMLMEContext = (PTX_CONTEXT) pAd->MgmtRing.Cell[i].AllocVa;
4143 + pMLMEContext->pUrb = RTUSB_ALLOC_URB(0);
4144 + if (pMLMEContext->pUrb == NULL)
4145 + {
4146 + DBGPRINT(RT_DEBUG_ERROR, ("<-- ERROR in Alloc TX MLMEContext[%d] urb!! \n", i));
4147 + Status = NDIS_STATUS_RESOURCES;
4148 + goto out2;
4149 + }
4150 + pMLMEContext->pAd = pAd;
4151 + pMLMEContext->pIrp = NULL;
4152 + pMLMEContext->TransferBuffer = NULL;
4153 + pMLMEContext->InUse = FALSE;
4154 + pMLMEContext->IRPPending = FALSE;
4155 + pMLMEContext->bWaitingBulkOut = FALSE;
4156 + pMLMEContext->BulkOutSize = 0;
4157 + pMLMEContext->SelfIdx = i;
4158 +
4159 + // Offset to next ring descriptor address
4160 + RingBaseVa = (PUCHAR) RingBaseVa + sizeof(TX_CONTEXT);
4161 + }
4162 + DBGPRINT(RT_DEBUG_TRACE, ("MGMT Ring: total %d entry allocated\n", i));
4163 +
4164 + //pAd->MgmtRing.TxSwFreeIdx = (MGMT_RING_SIZE - 1);
4165 + pAd->MgmtRing.TxSwFreeIdx = MGMT_RING_SIZE;
4166 + pAd->MgmtRing.TxCpuIdx = 0;
4167 + pAd->MgmtRing.TxDmaIdx = 0;
4168 +
4169 + //
4170 + // BEACON_RING_SIZE
4171 + //
4172 + for(i=0; i<BEACON_RING_SIZE; i++) // 2
4173 + {
4174 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4175 +
4176 +
4177 + NdisZeroMemory(pBeaconContext, sizeof(TX_CONTEXT));
4178 +
4179 + //Allocate URB
4180 + LM_USB_ALLOC(pObj, pBeaconContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4181 + ("<-- ERROR in Alloc TX BeaconContext[%d] urb!! \n", i),
4182 + out2,
4183 + ("<-- ERROR in Alloc TX BeaconContext[%d] TX_BUFFER !! \n", i),
4184 + out3);
4185 +
4186 + pBeaconContext->pAd = pAd;
4187 + pBeaconContext->pIrp = NULL;
4188 + pBeaconContext->InUse = FALSE;
4189 + pBeaconContext->IRPPending = FALSE;
4190 + }
4191 +
4192 + //
4193 + // NullContext
4194 + //
4195 + NdisZeroMemory(pNullContext, sizeof(TX_CONTEXT));
4196 +
4197 + //Allocate URB
4198 + LM_USB_ALLOC(pObj, pNullContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4199 + ("<-- ERROR in Alloc TX NullContext urb!! \n"),
4200 + out3,
4201 + ("<-- ERROR in Alloc TX NullContext TX_BUFFER !! \n"),
4202 + out4);
4203 +
4204 + pNullContext->pAd = pAd;
4205 + pNullContext->pIrp = NULL;
4206 + pNullContext->InUse = FALSE;
4207 + pNullContext->IRPPending = FALSE;
4208 +
4209 + //
4210 + // RTSContext
4211 + //
4212 + NdisZeroMemory(pRTSContext, sizeof(TX_CONTEXT));
4213 +
4214 + //Allocate URB
4215 + LM_USB_ALLOC(pObj, pRTSContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4216 + ("<-- ERROR in Alloc TX RTSContext urb!! \n"),
4217 + out4,
4218 + ("<-- ERROR in Alloc TX RTSContext TX_BUFFER !! \n"),
4219 + out5);
4220 +
4221 + pRTSContext->pAd = pAd;
4222 + pRTSContext->pIrp = NULL;
4223 + pRTSContext->InUse = FALSE;
4224 + pRTSContext->IRPPending = FALSE;
4225 +
4226 + //
4227 + // PsPollContext
4228 + //
4229 + //NdisZeroMemory(pPsPollContext, sizeof(TX_CONTEXT));
4230 + //Allocate URB
4231 + LM_USB_ALLOC(pObj, pPsPollContext, PTX_BUFFER, sizeof(TX_BUFFER), Status,
4232 + ("<-- ERROR in Alloc TX PsPollContext urb!! \n"),
4233 + out5,
4234 + ("<-- ERROR in Alloc TX PsPollContext TX_BUFFER !! \n"),
4235 + out6);
4236 +
4237 + pPsPollContext->pAd = pAd;
4238 + pPsPollContext->pIrp = NULL;
4239 + pPsPollContext->InUse = FALSE;
4240 + pPsPollContext->IRPPending = FALSE;
4241 + pPsPollContext->bAggregatible = FALSE;
4242 + pPsPollContext->LastOne = TRUE;
4243 +
4244 + } while (FALSE);
4245 +
4246 +
4247 +done:
4248 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitTransmit\n"));
4249 +
4250 + return Status;
4251 +
4252 + /* --------------------------- ERROR HANDLE --------------------------- */
4253 +out6:
4254 + LM_URB_FREE(pObj, pPsPollContext, sizeof(TX_BUFFER));
4255 +
4256 +out5:
4257 + LM_URB_FREE(pObj, pRTSContext, sizeof(TX_BUFFER));
4258 +
4259 +out4:
4260 + LM_URB_FREE(pObj, pNullContext, sizeof(TX_BUFFER));
4261 +
4262 +out3:
4263 + for(i=0; i<BEACON_RING_SIZE; i++)
4264 + {
4265 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4266 + if (pBeaconContext)
4267 + LM_URB_FREE(pObj, pBeaconContext, sizeof(TX_BUFFER));
4268 + }
4269 +
4270 +out2:
4271 + if (pAd->MgmtDescRing.AllocVa)
4272 + {
4273 + pMgmtRing = &pAd->MgmtRing;
4274 + for(i=0; i<MGMT_RING_SIZE; i++)
4275 + {
4276 + pMLMEContext = (PTX_CONTEXT) pAd->MgmtRing.Cell[i].AllocVa;
4277 + if (pMLMEContext)
4278 + LM_URB_FREE(pObj, pMLMEContext, sizeof(TX_BUFFER));
4279 + }
4280 + NdisFreeMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize, 0);
4281 + pAd->MgmtDescRing.AllocVa = NULL;
4282 + }
4283 +
4284 +out1:
4285 +#ifdef CONFIG_STA_SUPPORT
4286 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
4287 + for(acidx=0; acidx<4; acidx++)
4288 +#endif // CONFIG_STA_SUPPORT //
4289 + {
4290 + PHT_TX_CONTEXT pTxContext = &(pAd->TxContext[acidx]);
4291 + if (pTxContext)
4292 + LM_URB_FREE(pObj, pTxContext, sizeof(HTTX_BUFFER));
4293 + }
4294 +
4295 + // Here we didn't have any pre-allocated memory need to free.
4296 +
4297 + return Status;
4298 +}
4299 +
4300 +
4301 +/*
4302 +========================================================================
4303 +Routine Description:
4304 + Allocate DMA memory blocks for send, receive.
4305 +
4306 +Arguments:
4307 + pAd Pointer to our adapter
4308 +
4309 +Return Value:
4310 + NDIS_STATUS_SUCCESS
4311 + NDIS_STATUS_FAILURE
4312 + NDIS_STATUS_RESOURCES
4313 +
4314 +Note:
4315 +========================================================================
4316 +*/
4317 +NDIS_STATUS RTMPAllocTxRxRingMemory(
4318 + IN PRTMP_ADAPTER pAd)
4319 +{
4320 +// COUNTER_802_11 pCounter = &pAd->WlanCounters;
4321 + NDIS_STATUS Status;
4322 + INT num;
4323 +
4324 +
4325 + DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n"));
4326 +
4327 +
4328 + do
4329 + {
4330 + // Init the CmdQ and CmdQLock
4331 + NdisAllocateSpinLock(&pAd->CmdQLock);
4332 + NdisAcquireSpinLock(&pAd->CmdQLock);
4333 + RTUSBInitializeCmdQ(&pAd->CmdQ);
4334 + NdisReleaseSpinLock(&pAd->CmdQLock);
4335 +
4336 +
4337 + NdisAllocateSpinLock(&pAd->MLMEBulkOutLock);
4338 + //NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock);
4339 + NdisAllocateSpinLock(&pAd->BulkOutLock[0]);
4340 + NdisAllocateSpinLock(&pAd->BulkOutLock[1]);
4341 + NdisAllocateSpinLock(&pAd->BulkOutLock[2]);
4342 + NdisAllocateSpinLock(&pAd->BulkOutLock[3]);
4343 + NdisAllocateSpinLock(&pAd->BulkOutLock[4]);
4344 + NdisAllocateSpinLock(&pAd->BulkOutLock[5]);
4345 + NdisAllocateSpinLock(&pAd->BulkInLock);
4346 +
4347 + for (num = 0; num < NUM_OF_TX_RING; num++)
4348 + {
4349 + NdisAllocateSpinLock(&pAd->TxContextQueueLock[num]);
4350 + }
4351 +
4352 +#ifdef RALINK_ATE
4353 + NdisAllocateSpinLock(&pAd->GenericLock);
4354 +#endif // RALINK_ATE //
4355 +
4356 +// NdisAllocateSpinLock(&pAd->MemLock); // Not used in RT28XX
4357 +
4358 +// NdisAllocateSpinLock(&pAd->MacTabLock); // init it in UserCfgInit()
4359 +// NdisAllocateSpinLock(&pAd->BATabLock); // init it in BATableInit()
4360 +
4361 +// for(num=0; num<MAX_LEN_OF_BA_REC_TABLE; num++)
4362 +// {
4363 +// NdisAllocateSpinLock(&pAd->BATable.BARecEntry[num].RxReRingLock);
4364 +// }
4365 +
4366 + //
4367 + // Init Mac Table
4368 + //
4369 +// MacTableInitialize(pAd);
4370 +
4371 + //
4372 + // Init send data structures and related parameters
4373 + //
4374 + Status = NICInitTransmit(pAd);
4375 + if (Status != NDIS_STATUS_SUCCESS)
4376 + break;
4377 +
4378 + //
4379 + // Init receive data structures and related parameters
4380 + //
4381 + Status = NICInitRecv(pAd);
4382 + if (Status != NDIS_STATUS_SUCCESS)
4383 + break;
4384 +
4385 + pAd->PendingIoCount = 1;
4386 +
4387 + } while (FALSE);
4388 +
4389 + NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME));
4390 + pAd->FragFrame.pFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
4391 +
4392 + if (pAd->FragFrame.pFragPacket == NULL)
4393 + {
4394 + Status = NDIS_STATUS_RESOURCES;
4395 + }
4396 +
4397 + DBGPRINT_S(Status, ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status));
4398 + return Status;
4399 +}
4400 +
4401 +
4402 +/*
4403 +========================================================================
4404 +Routine Description:
4405 + Calls USB_InterfaceStop and frees memory allocated for the URBs
4406 + calls NdisMDeregisterDevice and frees the memory
4407 + allocated in VNetInitialize for the Adapter Object
4408 +
4409 +Arguments:
4410 + *pAd the raxx interface data pointer
4411 +
4412 +Return Value:
4413 + None
4414 +
4415 +Note:
4416 +========================================================================
4417 +*/
4418 +VOID RTMPFreeTxRxRingMemory(
4419 + IN PRTMP_ADAPTER pAd)
4420 +{
4421 +#define LM_URB_FREE(pObj, Context, BufferSize) \
4422 + if (NULL != Context->pUrb) { \
4423 + RTUSB_UNLINK_URB(Context->pUrb); \
4424 + RTUSB_FREE_URB(Context->pUrb); \
4425 + Context->pUrb = NULL; } \
4426 + if (NULL != Context->TransferBuffer) { \
4427 + RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
4428 + Context->TransferBuffer, \
4429 + Context->data_dma); \
4430 + Context->TransferBuffer = NULL; }
4431 +
4432 +
4433 + UINT i, acidx;
4434 + PTX_CONTEXT pNullContext = &pAd->NullContext;
4435 + PTX_CONTEXT pPsPollContext = &pAd->PsPollContext;
4436 + PTX_CONTEXT pRTSContext = &pAd->RTSContext;
4437 +// PHT_TX_CONTEXT pHTTXContext;
4438 + //PRTMP_REORDERBUF pReorderBuf;
4439 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4440 +// RTMP_TX_RING *pTxRing;
4441 +
4442 + DBGPRINT(RT_DEBUG_ERROR, ("---> RTMPFreeTxRxRingMemory\n"));
4443 + pObj = pObj;
4444 +
4445 + // Free all resources for the RECEIVE buffer queue.
4446 + for(i=0; i<(RX_RING_SIZE); i++)
4447 + {
4448 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
4449 + if (pRxContext)
4450 + LM_URB_FREE(pObj, pRxContext, MAX_RXBULK_SIZE);
4451 + }
4452 +
4453 + // Free PsPoll frame resource
4454 + LM_URB_FREE(pObj, pPsPollContext, sizeof(TX_BUFFER));
4455 +
4456 + // Free NULL frame resource
4457 + LM_URB_FREE(pObj, pNullContext, sizeof(TX_BUFFER));
4458 +
4459 + // Free RTS frame resource
4460 + LM_URB_FREE(pObj, pRTSContext, sizeof(TX_BUFFER));
4461 +
4462 +
4463 + // Free beacon frame resource
4464 + for(i=0; i<BEACON_RING_SIZE; i++)
4465 + {
4466 + PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
4467 + if (pBeaconContext)
4468 + LM_URB_FREE(pObj, pBeaconContext, sizeof(TX_BUFFER));
4469 + }
4470 +
4471 +
4472 + // Free mgmt frame resource
4473 + for(i = 0; i < MGMT_RING_SIZE; i++)
4474 + {
4475 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[i].AllocVa;
4476 + //LM_URB_FREE(pObj, pMLMEContext, sizeof(TX_BUFFER));
4477 + if (NULL != pAd->MgmtRing.Cell[i].pNdisPacket)
4478 + {
4479 + RTMPFreeNdisPacket(pAd, pAd->MgmtRing.Cell[i].pNdisPacket);
4480 + pAd->MgmtRing.Cell[i].pNdisPacket = NULL;
4481 + pMLMEContext->TransferBuffer = NULL;
4482 + }
4483 +
4484 + if (pMLMEContext)
4485 + {
4486 + if (NULL != pMLMEContext->pUrb)
4487 + {
4488 + RTUSB_UNLINK_URB(pMLMEContext->pUrb);
4489 + RTUSB_FREE_URB(pMLMEContext->pUrb);
4490 + pMLMEContext->pUrb = NULL;
4491 + }
4492 + }
4493 + }
4494 + if (pAd->MgmtDescRing.AllocVa)
4495 + NdisFreeMemory(pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize, 0);
4496 +
4497 +
4498 + // Free Tx frame resource
4499 +#ifdef CONFIG_STA_SUPPORT
4500 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
4501 + for(acidx=0; acidx<4; acidx++)
4502 +#endif // CONFIG_STA_SUPPORT //
4503 + {
4504 + PHT_TX_CONTEXT pHTTXContext = &(pAd->TxContext[acidx]);
4505 + if (pHTTXContext)
4506 + LM_URB_FREE(pObj, pHTTXContext, sizeof(HTTX_BUFFER));
4507 + }
4508 +
4509 + if (pAd->FragFrame.pFragPacket)
4510 + RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, NDIS_STATUS_SUCCESS);
4511 +
4512 + for(i=0; i<6; i++)
4513 + {
4514 + NdisFreeSpinLock(&pAd->BulkOutLock[i]);
4515 + }
4516 +
4517 + NdisFreeSpinLock(&pAd->BulkInLock);
4518 + NdisFreeSpinLock(&pAd->MLMEBulkOutLock);
4519 +
4520 + NdisFreeSpinLock(&pAd->CmdQLock);
4521 +#ifdef RALINK_ATE
4522 + NdisFreeSpinLock(&pAd->GenericLock);
4523 +#endif // RALINK_ATE //
4524 + // Clear all pending bulk-out request flags.
4525 + RTUSB_CLEAR_BULK_FLAG(pAd, 0xffffffff);
4526 +
4527 +// NdisFreeSpinLock(&pAd->MacTabLock);
4528 +
4529 +// for(i=0; i<MAX_LEN_OF_BA_REC_TABLE; i++)
4530 +// {
4531 +// NdisFreeSpinLock(&pAd->BATable.BARecEntry[i].RxReRingLock);
4532 +// }
4533 +
4534 + DBGPRINT(RT_DEBUG_ERROR, ("<--- ReleaseAdapter\n"));
4535 +}
4536 +
4537 +
4538 +/*
4539 +========================================================================
4540 +Routine Description:
4541 + Allocate memory for adapter control block.
4542 +
4543 +Arguments:
4544 + pAd Pointer to our adapter
4545 +
4546 +Return Value:
4547 + NDIS_STATUS_SUCCESS
4548 + NDIS_STATUS_FAILURE
4549 + NDIS_STATUS_RESOURCES
4550 +
4551 +Note:
4552 +========================================================================
4553 +*/
4554 +NDIS_STATUS AdapterBlockAllocateMemory(
4555 + IN PVOID handle,
4556 + OUT PVOID *ppAd)
4557 +{
4558 + PUSB_DEV usb_dev;
4559 + POS_COOKIE pObj = (POS_COOKIE) handle;
4560 +
4561 +
4562 + usb_dev = pObj->pUsb_Dev;
4563 +
4564 + pObj->MLMEThr_pid = NULL;
4565 + pObj->RTUSBCmdThr_pid = NULL;
4566 +
4567 + *ppAd = (PVOID)vmalloc(sizeof(RTMP_ADAPTER));
4568 +
4569 + if (*ppAd)
4570 + {
4571 + NdisZeroMemory(*ppAd, sizeof(RTMP_ADAPTER));
4572 + ((PRTMP_ADAPTER)*ppAd)->OS_Cookie = handle;
4573 + return (NDIS_STATUS_SUCCESS);
4574 + }
4575 + else
4576 + {
4577 + return (NDIS_STATUS_FAILURE);
4578 + }
4579 +}
4580 +
4581 +
4582 +/*
4583 +========================================================================
4584 +Routine Description:
4585 + Create kernel threads & tasklets.
4586 +
4587 +Arguments:
4588 + *net_dev Pointer to wireless net device interface
4589 +
4590 +Return Value:
4591 + NDIS_STATUS_SUCCESS
4592 + NDIS_STATUS_FAILURE
4593 +
4594 +Note:
4595 +========================================================================
4596 +*/
4597 +NDIS_STATUS CreateThreads(
4598 + IN struct net_device *net_dev)
4599 +{
4600 + PRTMP_ADAPTER pAd = net_dev->ml_priv;
4601 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
4602 + pid_t pid_number;
4603 +
4604 + //init_MUTEX(&(pAd->usbdev_semaphore));
4605 +
4606 + init_MUTEX_LOCKED(&(pAd->mlme_semaphore));
4607 + init_completion (&pAd->mlmeComplete);
4608 +
4609 + init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore));
4610 + init_completion (&pAd->CmdQComplete);
4611 +
4612 + init_MUTEX_LOCKED(&(pAd->RTUSBTimer_semaphore));
4613 + init_completion (&pAd->TimerQComplete);
4614 +
4615 + // Creat MLME Thread
4616 + pObj->MLMEThr_pid = NULL;
4617 + pid_number = kernel_thread(MlmeThread, pAd, CLONE_VM);
4618 + if (pid_number < 0)
4619 + {
4620 + printk (KERN_WARNING "%s: unable to start Mlme thread\n",pAd->net_dev->name);
4621 + return NDIS_STATUS_FAILURE;
4622 + }
4623 + pObj->MLMEThr_pid = find_get_pid(pid_number);
4624 + // Wait for the thread to start
4625 + wait_for_completion(&(pAd->mlmeComplete));
4626 +
4627 + // Creat Command Thread
4628 + pObj->RTUSBCmdThr_pid = NULL;
4629 + pid_number = kernel_thread(RTUSBCmdThread, pAd, CLONE_VM);
4630 + if (pid_number < 0)
4631 + {
4632 + printk (KERN_WARNING "%s: unable to start RTUSBCmd thread\n",pAd->net_dev->name);
4633 + return NDIS_STATUS_FAILURE;
4634 + }
4635 + pObj->RTUSBCmdThr_pid = find_get_pid(pid_number);
4636 + wait_for_completion(&(pAd->CmdQComplete));
4637 +
4638 + pObj->TimerQThr_pid = NULL;
4639 + pid_number = kernel_thread(TimerQThread, pAd, CLONE_VM);
4640 + if (pid_number < 0)
4641 + {
4642 + printk (KERN_WARNING "%s: unable to start TimerQThread\n",pAd->net_dev->name);
4643 + return NDIS_STATUS_FAILURE;
4644 + }
4645 + pObj->TimerQThr_pid = find_get_pid(pid_number);
4646 + // Wait for the thread to start
4647 + wait_for_completion(&(pAd->TimerQComplete));
4648 +
4649 + // Create receive tasklet
4650 + tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (ULONG)pAd);
4651 + tasklet_init(&pObj->mgmt_dma_done_task, rt2870_mgmt_dma_done_tasklet, (unsigned long)pAd);
4652 + tasklet_init(&pObj->ac0_dma_done_task, rt2870_ac0_dma_done_tasklet, (unsigned long)pAd);
4653 + tasklet_init(&pObj->ac1_dma_done_task, rt2870_ac1_dma_done_tasklet, (unsigned long)pAd);
4654 + tasklet_init(&pObj->ac2_dma_done_task, rt2870_ac2_dma_done_tasklet, (unsigned long)pAd);
4655 + tasklet_init(&pObj->ac3_dma_done_task, rt2870_ac3_dma_done_tasklet, (unsigned long)pAd);
4656 + tasklet_init(&pObj->hcca_dma_done_task, rt2870_hcca_dma_done_tasklet, (unsigned long)pAd);
4657 + tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
4658 + tasklet_init(&pObj->null_frame_complete_task, rt2870_null_frame_complete_tasklet, (unsigned long)pAd);
4659 + tasklet_init(&pObj->rts_frame_complete_task, rt2870_rts_frame_complete_tasklet, (unsigned long)pAd);
4660 + tasklet_init(&pObj->pspoll_frame_complete_task, rt2870_pspoll_frame_complete_tasklet, (unsigned long)pAd);
4661 +
4662 + return NDIS_STATUS_SUCCESS;
4663 +}
4664 +
4665 +
4666 +#ifdef CONFIG_STA_SUPPORT
4667 +/*
4668 +========================================================================
4669 +Routine Description:
4670 + As STA's BSSID is a WC too, it uses shared key table.
4671 + This function write correct unicast TX key to ASIC WCID.
4672 + And we still make a copy in our MacTab.Content[BSSID_WCID].PairwiseKey.
4673 + Caller guarantee TKIP/AES always has keyidx = 0. (pairwise key)
4674 + Caller guarantee WEP calls this function when set Txkey, default key index=0~3.
4675 +
4676 +Arguments:
4677 + pAd Pointer to our adapter
4678 + pKey Pointer to the where the key stored
4679 +
4680 +Return Value:
4681 + NDIS_SUCCESS Add key successfully
4682 +
4683 +Note:
4684 +========================================================================
4685 +*/
4686 +VOID RTMPAddBSSIDCipher(
4687 + IN PRTMP_ADAPTER pAd,
4688 + IN UCHAR Aid,
4689 + IN PNDIS_802_11_KEY pKey,
4690 + IN UCHAR CipherAlg)
4691 +{
4692 + PUCHAR pTxMic, pRxMic;
4693 + BOOLEAN bKeyRSC, bAuthenticator; // indicate the receive SC set by KeyRSC value
4694 +// UCHAR CipherAlg;
4695 + UCHAR i;
4696 + ULONG WCIDAttri;
4697 + USHORT offset;
4698 + UCHAR KeyIdx, IVEIV[8];
4699 + UINT32 Value;
4700 +
4701 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddBSSIDCipher==> Aid = %d\n",Aid));
4702 +
4703 + // Bit 29 of Add-key KeyRSC
4704 + bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
4705 +
4706 + // Bit 28 of Add-key Authenticator
4707 + bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
4708 + KeyIdx = (UCHAR)pKey->KeyIndex&0xff;
4709 +
4710 + if (KeyIdx > 4)
4711 + return;
4712 +
4713 +
4714 + if (pAd->MacTab.Content[Aid].PairwiseKey.CipherAlg == CIPHER_TKIP)
4715 + { if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
4716 + {
4717 + // for WPA-None Tx, Rx MIC is the same
4718 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4719 + pRxMic = pTxMic;
4720 + }
4721 + else if (bAuthenticator == TRUE)
4722 + {
4723 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4724 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
4725 + }
4726 + else
4727 + {
4728 + pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
4729 + pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
4730 + }
4731 +
4732 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE) + 0x10;
4733 + for (i=0; i<8; )
4734 + {
4735 + Value = *(pTxMic+i);
4736 + Value += (*(pTxMic+i+1)<<8);
4737 + Value += (*(pTxMic+i+2)<<16);
4738 + Value += (*(pTxMic+i+3)<<24);
4739 + RTUSBWriteMACRegister(pAd, offset+i, Value);
4740 + i+=4;
4741 + }
4742 +
4743 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE) + 0x18;
4744 + for (i=0; i<8; )
4745 + {
4746 + Value = *(pRxMic+i);
4747 + Value += (*(pRxMic+i+1)<<8);
4748 + Value += (*(pRxMic+i+2)<<16);
4749 + Value += (*(pRxMic+i+3)<<24);
4750 + RTUSBWriteMACRegister(pAd, offset+i, Value);
4751 + i+=4;
4752 + }
4753 +
4754 + // Only Key lenth equal to TKIP key have these
4755 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxMic, pRxMic, 8);
4756 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.TxMic, pTxMic, 8);
4757 +
4758 + DBGPRINT(RT_DEBUG_TRACE,
4759 + (" TxMIC = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n",
4760 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],
4761 + pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
4762 + DBGPRINT(RT_DEBUG_TRACE,
4763 + (" RxMIC = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n",
4764 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],
4765 + pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
4766 + }
4767 +
4768 + // 2. Record Security Key.
4769 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen= (UCHAR)pKey->KeyLength;
4770 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
4771 +
4772 + // 3. Check RxTsc. And used to init to ASIC IV.
4773 + if (bKeyRSC == TRUE)
4774 + NdisMoveMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxTsc, &pKey->KeyRSC, 6);
4775 + else
4776 + NdisZeroMemory(pAd->MacTab.Content[Aid].PairwiseKey.RxTsc, 6);
4777 +
4778 + // 4. Init TxTsc to one based on WiFi WPA specs
4779 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[0] = 1;
4780 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[1] = 0;
4781 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[2] = 0;
4782 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[3] = 0;
4783 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[4] = 0;
4784 + pAd->MacTab.Content[Aid].PairwiseKey.TxTsc[5] = 0;
4785 +
4786 + CipherAlg = pAd->MacTab.Content[Aid].PairwiseKey.CipherAlg;
4787 +
4788 + offset = PAIRWISE_KEY_TABLE_BASE + (Aid * HW_KEY_ENTRY_SIZE);
4789 + RTUSBMultiWrite(pAd, (USHORT) offset, pKey->KeyMaterial,
4790 + ((pKey->KeyLength == LEN_TKIP_KEY) ? 16 : (USHORT)pKey->KeyLength));
4791 +
4792 + offset = SHARED_KEY_TABLE_BASE + (KeyIdx * HW_KEY_ENTRY_SIZE);
4793 + RTUSBMultiWrite(pAd, (USHORT) offset, pKey->KeyMaterial, (USHORT)pKey->KeyLength);
4794 +
4795 + offset = PAIRWISE_IVEIV_TABLE_BASE + (Aid * HW_IVEIV_ENTRY_SIZE);
4796 + NdisZeroMemory(IVEIV, 8);
4797 +
4798 + // IV/EIV
4799 + if ((CipherAlg == CIPHER_TKIP) ||
4800 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
4801 + (CipherAlg == CIPHER_AES))
4802 + {
4803 + IVEIV[3] = 0x20; // Eiv bit on. keyid always 0 for pairwise key
4804 + }
4805 + // default key idx needs to set.
4806 + // in TKIP/AES KeyIdx = 0 , WEP KeyIdx is default tx key.
4807 + else
4808 + {
4809 + IVEIV[3] |= (KeyIdx<< 6);
4810 + }
4811 + RTUSBMultiWrite(pAd, (USHORT) offset, IVEIV, 8);
4812 +
4813 + // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0
4814 + if ((CipherAlg == CIPHER_TKIP) ||
4815 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
4816 + (CipherAlg == CIPHER_AES))
4817 + {
4818 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
4819 + }
4820 + else
4821 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
4822 +
4823 + offset = MAC_WCID_ATTRIBUTE_BASE + (Aid* HW_WCID_ATTRI_SIZE);
4824 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
4825 + RTUSBReadMACRegister(pAd, offset, &Value);
4826 +
4827 + DBGPRINT(RT_DEBUG_TRACE, ("BSSID_WCID : offset = %x, WCIDAttri = %lx\n",
4828 + offset, WCIDAttri));
4829 +
4830 + // pAddr
4831 + // Add Bssid mac address at linkup. not here. check!
4832 + /*offset = MAC_WCID_BASE + (BSSID_WCID * HW_WCID_ENTRY_SIZE);
4833 + *for (i=0; i<MAC_ADDR_LEN; i++)
4834 + {
4835 + RTMP_IO_WRITE8(pAd, offset+i, pKey->BSSID[i]);
4836 + }
4837 + */
4838 +
4839 + DBGPRINT(RT_DEBUG_ERROR, ("AddBSSIDasWCIDEntry: Alg=%s, KeyLength = %d\n",
4840 + CipherName[CipherAlg], pKey->KeyLength));
4841 + DBGPRINT(RT_DEBUG_TRACE, ("Key [idx=%x] [KeyLen = %d]\n",
4842 + pKey->KeyIndex, pKey->KeyLength));
4843 + for(i=0; i<pKey->KeyLength; i++)
4844 + DBGPRINT_RAW(RT_DEBUG_TRACE,(" %x:", pKey->KeyMaterial[i]));
4845 + DBGPRINT(RT_DEBUG_TRACE,(" \n"));
4846 +}
4847 +#endif // CONFIG_STA_SUPPORT //
4848 +
4849 +/*
4850 +========================================================================
4851 +Routine Description:
4852 + Get a received packet.
4853 +
4854 +Arguments:
4855 + pAd device control block
4856 + pSaveRxD receive descriptor information
4857 + *pbReschedule need reschedule flag
4858 + *pRxPending pending received packet flag
4859 +
4860 +Return Value:
4861 + the recieved packet
4862 +
4863 +Note:
4864 +========================================================================
4865 +*/
4866 +#define RT2870_RXDMALEN_FIELD_SIZE 4
4867 +PNDIS_PACKET GetPacketFromRxRing(
4868 + IN PRTMP_ADAPTER pAd,
4869 + OUT PRT28XX_RXD_STRUC pSaveRxD,
4870 + OUT BOOLEAN *pbReschedule,
4871 + IN OUT UINT32 *pRxPending)
4872 +{
4873 + PRX_CONTEXT pRxContext;
4874 + PNDIS_PACKET pSkb;
4875 + PUCHAR pData;
4876 + ULONG ThisFrameLen;
4877 + ULONG RxBufferLength;
4878 + PRXWI_STRUC pRxWI;
4879 +
4880 + pRxContext = &pAd->RxContext[pAd->NextRxBulkInReadIndex];
4881 + if ((pRxContext->Readable == FALSE) || (pRxContext->InUse == TRUE))
4882 + return NULL;
4883 +
4884 + RxBufferLength = pRxContext->BulkInOffset - pAd->ReadPosition;
4885 + if (RxBufferLength < (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXWI_STRUC) + sizeof(RXINFO_STRUC)))
4886 + {
4887 + goto label_null;
4888 + }
4889 +
4890 + pData = &pRxContext->TransferBuffer[pAd->ReadPosition]; /* 4KB */
4891 + // The RXDMA field is 4 bytes, now just use the first 2 bytes. The Length including the (RXWI + MSDU + Padding)
4892 + ThisFrameLen = *pData + (*(pData+1)<<8);
4893 + if (ThisFrameLen == 0)
4894 + {
4895 + DBGPRINT(RT_DEBUG_TRACE, ("BIRIdx(%d): RXDMALen is zero.[%ld], BulkInBufLen = %ld)\n",
4896 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset));
4897 + goto label_null;
4898 + }
4899 + if ((ThisFrameLen&0x3) != 0)
4900 + {
4901 + DBGPRINT(RT_DEBUG_ERROR, ("BIRIdx(%d): RXDMALen not multiple of 4.[%ld], BulkInBufLen = %ld)\n",
4902 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset));
4903 + goto label_null;
4904 + }
4905 +
4906 + if ((ThisFrameLen + 8)> RxBufferLength) // 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXINFO_STRUC))
4907 + {
4908 + DBGPRINT(RT_DEBUG_TRACE,("BIRIdx(%d):FrameLen(0x%lx) outranges. BulkInLen=0x%lx, remaining RxBufLen=0x%lx, ReadPos=0x%lx\n",
4909 + pAd->NextRxBulkInReadIndex, ThisFrameLen, pRxContext->BulkInOffset, RxBufferLength, pAd->ReadPosition));
4910 +
4911 + // error frame. finish this loop
4912 + goto label_null;
4913 + }
4914 +
4915 + // skip USB frame length field
4916 + pData += RT2870_RXDMALEN_FIELD_SIZE;
4917 + pRxWI = (PRXWI_STRUC)pData;
4918 +#ifdef RT_BIG_ENDIAN
4919 + RTMPWIEndianChange(pData, TYPE_RXWI);
4920 +#endif // RT_BIG_ENDIAN //
4921 + if (pRxWI->MPDUtotalByteCount > ThisFrameLen)
4922 + {
4923 + DBGPRINT(RT_DEBUG_ERROR, ("%s():pRxWIMPDUtotalByteCount(%d) large than RxDMALen(%ld)\n",
4924 + __FUNCTION__, pRxWI->MPDUtotalByteCount, ThisFrameLen));
4925 + goto label_null;
4926 + }
4927 +#ifdef RT_BIG_ENDIAN
4928 + RTMPWIEndianChange(pData, TYPE_RXWI);
4929 +#endif // RT_BIG_ENDIAN //
4930 +
4931 + // allocate a rx packet
4932 + pSkb = dev_alloc_skb(ThisFrameLen);
4933 + if (pSkb == NULL)
4934 + {
4935 + DBGPRINT(RT_DEBUG_ERROR,("%s():Cannot Allocate sk buffer for this Bulk-In buffer!\n", __FUNCTION__));
4936 + goto label_null;
4937 + }
4938 +
4939 + // copy the rx packet
4940 + memcpy(skb_put(pSkb, ThisFrameLen), pData, ThisFrameLen);
4941 + RTPKT_TO_OSPKT(pSkb)->dev = get_netdev_from_bssid(pAd, BSS0);
4942 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pSkb), PKTSRC_NDIS);
4943 +
4944 + // copy RxD
4945 + *pSaveRxD = *(PRXINFO_STRUC)(pData + ThisFrameLen);
4946 +#ifdef RT_BIG_ENDIAN
4947 + RTMPDescriptorEndianChange((PUCHAR)pSaveRxD, TYPE_RXINFO);
4948 +#endif // RT_BIG_ENDIAN //
4949 +
4950 + // update next packet read position.
4951 + pAd->ReadPosition += (ThisFrameLen + RT2870_RXDMALEN_FIELD_SIZE + RXINFO_SIZE); // 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(RXINFO_STRUC))
4952 +
4953 + return pSkb;
4954 +
4955 +label_null:
4956 +
4957 + return NULL;
4958 +}
4959 +
4960 +
4961 +/*
4962 +========================================================================
4963 +Routine Description:
4964 + Handle received packets.
4965 +
4966 +Arguments:
4967 + data - URB information pointer
4968 +
4969 +Return Value:
4970 + None
4971 +
4972 +Note:
4973 +========================================================================
4974 +*/
4975 +static void rx_done_tasklet(unsigned long data)
4976 +{
4977 + purbb_t pUrb;
4978 + PRX_CONTEXT pRxContext;
4979 + PRTMP_ADAPTER pAd;
4980 + NTSTATUS Status;
4981 + unsigned int IrqFlags;
4982 +
4983 + pUrb = (purbb_t)data;
4984 + pRxContext = (PRX_CONTEXT)pUrb->context;
4985 + pAd = pRxContext->pAd;
4986 + Status = pUrb->status;
4987 +
4988 +
4989 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
4990 + pRxContext->InUse = FALSE;
4991 + pRxContext->IRPPending = FALSE;
4992 + pRxContext->BulkInOffset += pUrb->actual_length;
4993 + //NdisInterlockedDecrement(&pAd->PendingRx);
4994 + pAd->PendingRx--;
4995 +
4996 + if (Status == USB_ST_NOERROR)
4997 + {
4998 + pAd->BulkInComplete++;
4999 + pAd->NextRxBulkInPosition = 0;
5000 + if (pRxContext->BulkInOffset) // As jan's comment, it may bulk-in success but size is zero.
5001 + {
5002 + pRxContext->Readable = TRUE;
5003 + INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE);
5004 + }
5005 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
5006 + }
5007 + else // STATUS_OTHER
5008 + {
5009 + pAd->BulkInCompleteFail++;
5010 + // Still read this packet although it may comtain wrong bytes.
5011 + pRxContext->Readable = FALSE;
5012 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
5013 +
5014 + // Parsing all packets. because after reset, the index will reset to all zero.
5015 + if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5016 + fRTMP_ADAPTER_BULKIN_RESET |
5017 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5018 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5019 + {
5020 +
5021 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk In Failed. Status=%d, BIIdx=0x%x, BIRIdx=0x%x, actual_length= 0x%x\n",
5022 + Status, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pRxContext->pUrb->actual_length));
5023 +
5024 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
5025 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
5026 + }
5027 + }
5028 +
5029 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
5030 +
5031 +#ifdef RALINK_ATE
5032 + if (ATE_ON(pAd))
5033 + {
5034 + // If the driver is in ATE mode and Rx frame is set into here.
5035 + if (pAd->ContinBulkIn == TRUE)
5036 + {
5037 + RTUSBBulkReceive(pAd);
5038 + }
5039 + }
5040 + else
5041 +#endif // RALINK_ATE //
5042 + RTUSBBulkReceive(pAd);
5043 +
5044 + return;
5045 +
5046 +}
5047 +
5048 +
5049 +static void rt2870_mgmt_dma_done_tasklet(unsigned long data)
5050 +{
5051 + PRTMP_ADAPTER pAd;
5052 + PTX_CONTEXT pMLMEContext;
5053 + int index;
5054 + PNDIS_PACKET pPacket;
5055 + purbb_t pUrb;
5056 + NTSTATUS Status;
5057 + unsigned long IrqFlags;
5058 +
5059 +
5060 + pUrb = (purbb_t)data;
5061 + pMLMEContext = (PTX_CONTEXT)pUrb->context;
5062 + pAd = pMLMEContext->pAd;
5063 + Status = pUrb->status;
5064 + index = pMLMEContext->SelfIdx;
5065 +
5066 + ASSERT((pAd->MgmtRing.TxDmaIdx == index));
5067 +
5068 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
5069 +
5070 +
5071 + if (Status != USB_ST_NOERROR)
5072 + {
5073 + //Bulk-Out fail status handle
5074 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5075 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5076 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5077 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5078 + {
5079 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out MLME Failed, Status=%d!\n", Status));
5080 + // TODO: How to handle about the MLMEBulkOut failed issue. Need to resend the mgmt pkt?
5081 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5082 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5083 + }
5084 + }
5085 +
5086 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
5087 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
5088 +
5089 + RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
5090 + // Reset MLME context flags
5091 + pMLMEContext->IRPPending = FALSE;
5092 + pMLMEContext->InUse = FALSE;
5093 + pMLMEContext->bWaitingBulkOut = FALSE;
5094 + pMLMEContext->BulkOutSize = 0;
5095 +
5096 + pPacket = pAd->MgmtRing.Cell[index].pNdisPacket;
5097 + pAd->MgmtRing.Cell[index].pNdisPacket = NULL;
5098 +
5099 + // Increase MgmtRing Index
5100 + INC_RING_INDEX(pAd->MgmtRing.TxDmaIdx, MGMT_RING_SIZE);
5101 + pAd->MgmtRing.TxSwFreeIdx++;
5102 + RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
5103 +
5104 + // No-matter success or fail, we free the mgmt packet.
5105 + if (pPacket)
5106 + RTMPFreeNdisPacket(pAd, pPacket);
5107 +
5108 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5109 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5110 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5111 + {
5112 + // do nothing and return directly.
5113 + }
5114 + else
5115 + {
5116 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET) &&
5117 + ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG))
5118 + { // For Mgmt Bulk-Out failed, ignore it now.
5119 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5120 + }
5121 + else
5122 + {
5123 +
5124 + // Always call Bulk routine, even reset bulk.
5125 + // The protectioon of rest bulk should be in BulkOut routine
5126 + if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */)
5127 + {
5128 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
5129 + }
5130 + RTUSBKickBulkOut(pAd);
5131 + }
5132 + }
5133 +
5134 +}
5135 +
5136 +
5137 +static void rt2870_hcca_dma_done_tasklet(unsigned long data)
5138 +{
5139 + PRTMP_ADAPTER pAd;
5140 + PHT_TX_CONTEXT pHTTXContext;
5141 + UCHAR BulkOutPipeId = 4;
5142 + purbb_t pUrb;
5143 +
5144 +
5145 + pUrb = (purbb_t)data;
5146 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5147 + pAd = pHTTXContext->pAd;
5148 +
5149 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5150 +
5151 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5152 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5153 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5154 + {
5155 + // do nothing and return directly.
5156 + }
5157 + else
5158 + {
5159 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5160 + {
5161 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5162 + }
5163 + else
5164 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5165 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5166 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5167 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5168 + (pHTTXContext->bCurWriting == FALSE))
5169 + {
5170 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5171 + }
5172 +
5173 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<4);
5174 + RTUSBKickBulkOut(pAd);
5175 + }
5176 + }
5177 +
5178 +
5179 + return;
5180 +}
5181 +
5182 +
5183 +static void rt2870_ac3_dma_done_tasklet(unsigned long data)
5184 +{
5185 + PRTMP_ADAPTER pAd;
5186 + PHT_TX_CONTEXT pHTTXContext;
5187 + UCHAR BulkOutPipeId = 3;
5188 + purbb_t pUrb;
5189 +
5190 +
5191 + pUrb = (purbb_t)data;
5192 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5193 + pAd = pHTTXContext->pAd;
5194 +
5195 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5196 +
5197 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5198 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5199 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5200 + {
5201 + // do nothing and return directly.
5202 + }
5203 + else
5204 + {
5205 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5206 + {
5207 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5208 + }
5209 + else
5210 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5211 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5212 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5213 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5214 + (pHTTXContext->bCurWriting == FALSE))
5215 + {
5216 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5217 + }
5218 +
5219 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<3);
5220 + RTUSBKickBulkOut(pAd);
5221 + }
5222 + }
5223 +
5224 +
5225 + return;
5226 +}
5227 +
5228 +
5229 +static void rt2870_ac2_dma_done_tasklet(unsigned long data)
5230 +{
5231 + PRTMP_ADAPTER pAd;
5232 + PHT_TX_CONTEXT pHTTXContext;
5233 + UCHAR BulkOutPipeId = 2;
5234 + purbb_t pUrb;
5235 +
5236 +
5237 + pUrb = (purbb_t)data;
5238 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5239 + pAd = pHTTXContext->pAd;
5240 +
5241 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5242 +
5243 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5244 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5245 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5246 + {
5247 + // do nothing and return directly.
5248 + }
5249 + else
5250 + {
5251 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5252 + {
5253 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5254 + }
5255 + else
5256 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5257 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5258 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5259 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5260 + (pHTTXContext->bCurWriting == FALSE))
5261 + {
5262 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5263 + }
5264 +
5265 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<2);
5266 + RTUSBKickBulkOut(pAd);
5267 + }
5268 + }
5269 +
5270 + return;
5271 +}
5272 +
5273 +
5274 +static void rt2870_ac1_dma_done_tasklet(unsigned long data)
5275 +{
5276 + PRTMP_ADAPTER pAd;
5277 + PHT_TX_CONTEXT pHTTXContext;
5278 + UCHAR BulkOutPipeId = 1;
5279 + purbb_t pUrb;
5280 +
5281 +
5282 + pUrb = (purbb_t)data;
5283 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5284 + pAd = pHTTXContext->pAd;
5285 +
5286 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5287 +
5288 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5289 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5290 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5291 + {
5292 + // do nothing and return directly.
5293 + }
5294 + else
5295 + {
5296 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5297 + {
5298 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5299 + }
5300 + else
5301 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5302 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5303 + /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5304 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5305 + (pHTTXContext->bCurWriting == FALSE))
5306 + {
5307 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5308 + }
5309 +
5310 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<1);
5311 + RTUSBKickBulkOut(pAd);
5312 + }
5313 + }
5314 +
5315 +
5316 + return;
5317 +}
5318 +
5319 +
5320 +static void rt2870_ac0_dma_done_tasklet(unsigned long data)
5321 +{
5322 + PRTMP_ADAPTER pAd;
5323 + PHT_TX_CONTEXT pHTTXContext;
5324 + UCHAR BulkOutPipeId = 0;
5325 + purbb_t pUrb;
5326 +
5327 +
5328 + pUrb = (purbb_t)data;
5329 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5330 + pAd = pHTTXContext->pAd;
5331 +
5332 + rt2870_dataout_complete_tasklet((unsigned long)pUrb);
5333 +
5334 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5335 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5336 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
5337 + {
5338 + // do nothing and return directly.
5339 + }
5340 + else
5341 + {
5342 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))
5343 + {
5344 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5345 + }
5346 + else
5347 + { pHTTXContext = &pAd->TxContext[BulkOutPipeId];
5348 + if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
5349 + /* ((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
5350 + (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
5351 + (pHTTXContext->bCurWriting == FALSE))
5352 + {
5353 + RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS);
5354 + }
5355 +
5356 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL);
5357 + RTUSBKickBulkOut(pAd);
5358 + }
5359 + }
5360 +
5361 +
5362 + return;
5363 +
5364 +}
5365 +
5366 +
5367 +static void rt2870_null_frame_complete_tasklet(unsigned long data)
5368 +{
5369 + PRTMP_ADAPTER pAd;
5370 + PTX_CONTEXT pNullContext;
5371 + purbb_t pUrb;
5372 + NTSTATUS Status;
5373 + unsigned long irqFlag;
5374 +
5375 +
5376 + pUrb = (purbb_t)data;
5377 + pNullContext = (PTX_CONTEXT)pUrb->context;
5378 + pAd = pNullContext->pAd;
5379 + Status = pUrb->status;
5380 +
5381 + // Reset Null frame context flags
5382 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
5383 + pNullContext->IRPPending = FALSE;
5384 + pNullContext->InUse = FALSE;
5385 + pAd->BulkOutPending[0] = FALSE;
5386 + pAd->watchDogTxPendingCnt[0] = 0;
5387 +
5388 + if (Status == USB_ST_NOERROR)
5389 + {
5390 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5391 +
5392 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5393 + }
5394 + else // STATUS_OTHER
5395 + {
5396 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5397 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5398 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5399 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5400 + {
5401 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out Null Frame Failed, ReasonCode=%d!\n", Status));
5402 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5403 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5404 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5405 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5406 + }
5407 + else
5408 + {
5409 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5410 + }
5411 + }
5412 +
5413 + // Always call Bulk routine, even reset bulk.
5414 + // The protectioon of rest bulk should be in BulkOut routine
5415 + RTUSBKickBulkOut(pAd);
5416 +
5417 +}
5418 +
5419 +
5420 +static void rt2870_rts_frame_complete_tasklet(unsigned long data)
5421 +{
5422 + PRTMP_ADAPTER pAd;
5423 + PTX_CONTEXT pRTSContext;
5424 + purbb_t pUrb;
5425 + NTSTATUS Status;
5426 + unsigned long irqFlag;
5427 +
5428 +
5429 + pUrb = (purbb_t)data;
5430 + pRTSContext = (PTX_CONTEXT)pUrb->context;
5431 + pAd = pRTSContext->pAd;
5432 + Status = pUrb->status;
5433 +
5434 + // Reset RTS frame context flags
5435 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
5436 + pRTSContext->IRPPending = FALSE;
5437 + pRTSContext->InUse = FALSE;
5438 +
5439 + if (Status == USB_ST_NOERROR)
5440 + {
5441 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5442 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5443 + }
5444 + else // STATUS_OTHER
5445 + {
5446 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5447 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5448 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5449 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5450 + {
5451 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out RTS Frame Failed\n"));
5452 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5453 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5454 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5455 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5456 + }
5457 + else
5458 + {
5459 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
5460 + }
5461 + }
5462 +
5463 + RTMP_SEM_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
5464 + pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE;
5465 + RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
5466 +
5467 + // Always call Bulk routine, even reset bulk.
5468 + // The protectioon of rest bulk should be in BulkOut routine
5469 + RTUSBKickBulkOut(pAd);
5470 +
5471 +}
5472 +
5473 +
5474 +static void rt2870_pspoll_frame_complete_tasklet(unsigned long data)
5475 +{
5476 + PRTMP_ADAPTER pAd;
5477 + PTX_CONTEXT pPsPollContext;
5478 + purbb_t pUrb;
5479 + NTSTATUS Status;
5480 +
5481 +
5482 + pUrb = (purbb_t)data;
5483 + pPsPollContext = (PTX_CONTEXT)pUrb->context;
5484 + pAd = pPsPollContext->pAd;
5485 + Status = pUrb->status;
5486 +
5487 + // Reset PsPoll context flags
5488 + pPsPollContext->IRPPending = FALSE;
5489 + pPsPollContext->InUse = FALSE;
5490 + pAd->watchDogTxPendingCnt[0] = 0;
5491 +
5492 + if (Status == USB_ST_NOERROR)
5493 + {
5494 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
5495 + }
5496 + else // STATUS_OTHER
5497 + {
5498 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
5499 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
5500 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
5501 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
5502 + {
5503 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out PSPoll Failed\n"));
5504 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5505 + pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
5506 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
5507 + }
5508 + }
5509 +
5510 + RTMP_SEM_LOCK(&pAd->BulkOutLock[0]);
5511 + pAd->BulkOutPending[0] = FALSE;
5512 + RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]);
5513 +
5514 + // Always call Bulk routine, even reset bulk.
5515 + // The protectioon of rest bulk should be in BulkOut routine
5516 + RTUSBKickBulkOut(pAd);
5517 +
5518 +}
5519 +
5520 +
5521 +static void rt2870_dataout_complete_tasklet(unsigned long data)
5522 +{
5523 + PRTMP_ADAPTER pAd;
5524 + purbb_t pUrb;
5525 + POS_COOKIE pObj;
5526 + PHT_TX_CONTEXT pHTTXContext;
5527 + UCHAR BulkOutPipeId;
5528 + NTSTATUS Status;
5529 + unsigned long IrqFlags;
5530 +
5531 +
5532 + pUrb = (purbb_t)data;
5533 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
5534 + pAd = pHTTXContext->pAd;
5535 + pObj = (POS_COOKIE) pAd->OS_Cookie;
5536 + Status = pUrb->status;
5537 +
5538 + // Store BulkOut PipeId
5539 + BulkOutPipeId = pHTTXContext->BulkOutPipeId;
5540 + pAd->BulkOutDataOneSecCount++;
5541 +
5542 + //DBGPRINT(RT_DEBUG_LOUD, ("Done-B(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", BulkOutPipeId, in_interrupt(), pHTTXContext->CurWritePosition,
5543 + // pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
5544 +
5545 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5546 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
5547 + pHTTXContext->IRPPending = FALSE;
5548 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
5549 +
5550 + if (Status == USB_ST_NOERROR)
5551 + {
5552 + pAd->BulkOutComplete++;
5553 +
5554 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5555 +
5556 + pAd->Counters8023.GoodTransmits++;
5557 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5558 + FREE_HTTX_RING(pAd, BulkOutPipeId, pHTTXContext);
5559 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5560 +
5561 +
5562 + }
5563 + else // STATUS_OTHER
5564 + {
5565 + PUCHAR pBuf;
5566 +
5567 + pAd->BulkOutCompleteOther++;
5568 +
5569 + pBuf = &pHTTXContext->TransferBuffer->field.WirelessPacket[pHTTXContext->NextBulkOutPosition];
5570 +
5571 + if (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
5572 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
5573 + fRTMP_ADAPTER_NIC_NOT_EXIST |
5574 + fRTMP_ADAPTER_BULKOUT_RESET)))
5575 + {
5576 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
5577 + pAd->bulkResetPipeid = BulkOutPipeId;
5578 + pAd->bulkResetReq[BulkOutPipeId] = pAd->BulkOutReq;
5579 + }
5580 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
5581 +
5582 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkOutDataPacket failed: ReasonCode=%d!\n", Status));
5583 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("\t>>BulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther));
5584 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("\t>>BulkOut Header:%x %x %x %x %x %x %x %x\n", pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7]));
5585 + //DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOutCompleteCancel=0x%x, BulkOutCompleteOther=0x%x\n", pAd->BulkOutCompleteCancel, pAd->BulkOutCompleteOther));
5586 +
5587 + }
5588 +
5589 + //
5590 + // bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut
5591 + // bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out.
5592 + //
5593 + //RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5594 + if ((pHTTXContext->ENextBulkOutPosition != pHTTXContext->CurWritePosition) &&
5595 + (pHTTXContext->ENextBulkOutPosition != (pHTTXContext->CurWritePosition+8)) &&
5596 + !RTUSB_TEST_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId)))
5597 + {
5598 + // Indicate There is data avaliable
5599 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
5600 + }
5601 + //RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
5602 +
5603 + // Always call Bulk routine, even reset bulk.
5604 + // The protection of rest bulk should be in BulkOut routine
5605 + RTUSBKickBulkOut(pAd);
5606 +}
5607 +
5608 +/* End of 2870_rtmp_init.c */
5609 --- /dev/null
5610 +++ b/drivers/staging/rt3070/common/action.c
5611 @@ -0,0 +1,1038 @@
5612 +/*
5613 + *************************************************************************
5614 + * Ralink Tech Inc.
5615 + * 5F., No.36, Taiyuan St., Jhubei City,
5616 + * Hsinchu County 302,
5617 + * Taiwan, R.O.C.
5618 + *
5619 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
5620 + *
5621 + * This program is free software; you can redistribute it and/or modify *
5622 + * it under the terms of the GNU General Public License as published by *
5623 + * the Free Software Foundation; either version 2 of the License, or *
5624 + * (at your option) any later version. *
5625 + * *
5626 + * This program is distributed in the hope that it will be useful, *
5627 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
5628 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
5629 + * GNU General Public License for more details. *
5630 + * *
5631 + * You should have received a copy of the GNU General Public License *
5632 + * along with this program; if not, write to the *
5633 + * Free Software Foundation, Inc., *
5634 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
5635 + * *
5636 + *************************************************************************
5637 +
5638 + Module Name:
5639 + action.c
5640 +
5641 + Abstract:
5642 + Handle association related requests either from WSTA or from local MLME
5643 +
5644 + Revision History:
5645 + Who When What
5646 + -------- ---------- ----------------------------------------------
5647 + Jan Lee 2006 created for rt2860
5648 + */
5649 +
5650 +#include "../rt_config.h"
5651 +#include "../action.h"
5652 +
5653 +
5654 +static VOID ReservedAction(
5655 + IN PRTMP_ADAPTER pAd,
5656 + IN MLME_QUEUE_ELEM *Elem);
5657 +
5658 +/*
5659 + ==========================================================================
5660 + Description:
5661 + association state machine init, including state transition and timer init
5662 + Parameters:
5663 + S - pointer to the association state machine
5664 + Note:
5665 + The state machine looks like the following
5666 +
5667 + ASSOC_IDLE
5668 + MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action
5669 + MT2_PEER_DISASSOC_REQ peer_disassoc_action
5670 + MT2_PEER_ASSOC_REQ drop
5671 + MT2_PEER_REASSOC_REQ drop
5672 + MT2_CLS3ERR cls3err_action
5673 + ==========================================================================
5674 + */
5675 +VOID ActionStateMachineInit(
5676 + IN PRTMP_ADAPTER pAd,
5677 + IN STATE_MACHINE *S,
5678 + OUT STATE_MACHINE_FUNC Trans[])
5679 +{
5680 + StateMachineInit(S, (STATE_MACHINE_FUNC *)Trans, MAX_ACT_STATE, MAX_ACT_MSG, (STATE_MACHINE_FUNC)Drop, ACT_IDLE, ACT_MACHINE_BASE);
5681 +
5682 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_SPECTRUM_CATE, (STATE_MACHINE_FUNC)PeerSpectrumAction);
5683 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_QOS_CATE, (STATE_MACHINE_FUNC)PeerQOSAction);
5684 +
5685 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, (STATE_MACHINE_FUNC)ReservedAction);
5686 +#ifdef QOS_DLS_SUPPORT
5687 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, (STATE_MACHINE_FUNC)PeerDLSAction);
5688 +#endif // QOS_DLS_SUPPORT //
5689 +
5690 +#ifdef DOT11_N_SUPPORT
5691 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_BA_CATE, (STATE_MACHINE_FUNC)PeerBAAction);
5692 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_HT_CATE, (STATE_MACHINE_FUNC)PeerHTAction);
5693 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ADD_BA_CATE, (STATE_MACHINE_FUNC)MlmeADDBAAction);
5694 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ORI_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction);
5695 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_REC_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction);
5696 +#endif // DOT11_N_SUPPORT //
5697 +
5698 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_PUBLIC_CATE, (STATE_MACHINE_FUNC)PeerPublicAction);
5699 + StateMachineSetAction(S, ACT_IDLE, MT2_PEER_RM_CATE, (STATE_MACHINE_FUNC)PeerRMAction);
5700 +
5701 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_QOS_CATE, (STATE_MACHINE_FUNC)MlmeQOSAction);
5702 + StateMachineSetAction(S, ACT_IDLE, MT2_MLME_DLS_CATE, (STATE_MACHINE_FUNC)MlmeDLSAction);
5703 + StateMachineSetAction(S, ACT_IDLE, MT2_ACT_INVALID, (STATE_MACHINE_FUNC)MlmeInvalidAction);
5704 +}
5705 +
5706 +#ifdef DOT11_N_SUPPORT
5707 +VOID MlmeADDBAAction(
5708 + IN PRTMP_ADAPTER pAd,
5709 + IN MLME_QUEUE_ELEM *Elem)
5710 +
5711 +{
5712 + MLME_ADDBA_REQ_STRUCT *pInfo;
5713 + UCHAR Addr[6];
5714 + PUCHAR pOutBuffer = NULL;
5715 + NDIS_STATUS NStatus;
5716 + ULONG Idx;
5717 + FRAME_ADDBA_REQ Frame;
5718 + ULONG FrameLen;
5719 + BA_ORI_ENTRY *pBAEntry = NULL;
5720 +
5721 + pInfo = (MLME_ADDBA_REQ_STRUCT *)Elem->Msg;
5722 + NdisZeroMemory(&Frame, sizeof(FRAME_ADDBA_REQ));
5723 +
5724 + if(MlmeAddBAReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr))
5725 + {
5726 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
5727 + if(NStatus != NDIS_STATUS_SUCCESS)
5728 + {
5729 + DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeADDBAAction() allocate memory failed \n"));
5730 + return;
5731 + }
5732 + // 1. find entry
5733 + Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
5734 + if (Idx == 0)
5735 + {
5736 + MlmeFreeMemory(pAd, pOutBuffer);
5737 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() can't find BAOriEntry \n"));
5738 + return;
5739 + }
5740 + else
5741 + {
5742 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
5743 + }
5744 +
5745 +#ifdef CONFIG_STA_SUPPORT
5746 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5747 + {
5748 + if (ADHOC_ON(pAd))
5749 + ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5750 + else
5751 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pInfo->pAddr);
5752 +
5753 + }
5754 +#endif // CONFIG_STA_SUPPORT //
5755 +
5756 + Frame.Category = CATEGORY_BA;
5757 + Frame.Action = ADDBA_REQ;
5758 + Frame.BaParm.AMSDUSupported = 0;
5759 + Frame.BaParm.BAPolicy = IMMED_BA;
5760 + Frame.BaParm.TID = pInfo->TID;
5761 + Frame.BaParm.BufSize = pInfo->BaBufSize;
5762 + Frame.Token = pInfo->Token;
5763 + Frame.TimeOutValue = pInfo->TimeOutValue;
5764 + Frame.BaStartSeq.field.FragNum = 0;
5765 + Frame.BaStartSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID];
5766 +
5767 + *(USHORT *)(&Frame.BaParm) = cpu2le16(*(USHORT *)(&Frame.BaParm));
5768 + Frame.TimeOutValue = cpu2le16(Frame.TimeOutValue);
5769 + Frame.BaStartSeq.word = cpu2le16(Frame.BaStartSeq.word);
5770 +
5771 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
5772 + sizeof(FRAME_ADDBA_REQ), &Frame,
5773 + END_OF_ARGS);
5774 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
5775 + //MiniportDataMMRequest(pAd, MapUserPriorityToAccessCategory[pInfo->TID], pOutBuffer, FrameLen);
5776 + MlmeFreeMemory(pAd, pOutBuffer);
5777 +
5778 + DBGPRINT(RT_DEBUG_TRACE, ("BA - Send ADDBA request. StartSeq = %x, FrameLen = %ld. BufSize = %d\n", Frame.BaStartSeq.field.StartSeq, FrameLen, Frame.BaParm.BufSize));
5779 + }
5780 +}
5781 +
5782 +/*
5783 + ==========================================================================
5784 + Description:
5785 + send DELBA and delete BaEntry if any
5786 + Parametrs:
5787 + Elem - MLME message MLME_DELBA_REQ_STRUCT
5788 +
5789 + IRQL = DISPATCH_LEVEL
5790 +
5791 + ==========================================================================
5792 + */
5793 +VOID MlmeDELBAAction(
5794 + IN PRTMP_ADAPTER pAd,
5795 + IN MLME_QUEUE_ELEM *Elem)
5796 +{
5797 + MLME_DELBA_REQ_STRUCT *pInfo;
5798 + PUCHAR pOutBuffer = NULL;
5799 + PUCHAR pOutBuffer2 = NULL;
5800 + NDIS_STATUS NStatus;
5801 + ULONG Idx;
5802 + FRAME_DELBA_REQ Frame;
5803 + ULONG FrameLen;
5804 + FRAME_BAR FrameBar;
5805 +
5806 + pInfo = (MLME_DELBA_REQ_STRUCT *)Elem->Msg;
5807 + // must send back DELBA
5808 + NdisZeroMemory(&Frame, sizeof(FRAME_DELBA_REQ));
5809 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeDELBAAction(), Initiator(%d) \n", pInfo->Initiator));
5810 +
5811 + if(MlmeDelBAReqSanity(pAd, Elem->Msg, Elem->MsgLen))
5812 + {
5813 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
5814 + if(NStatus != NDIS_STATUS_SUCCESS)
5815 + {
5816 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeDELBAAction() allocate memory failed 1. \n"));
5817 + return;
5818 + }
5819 +
5820 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory
5821 + if(NStatus != NDIS_STATUS_SUCCESS)
5822 + {
5823 + MlmeFreeMemory(pAd, pOutBuffer);
5824 + DBGPRINT(RT_DEBUG_ERROR, ("BA - MlmeDELBAAction() allocate memory failed 2. \n"));
5825 + return;
5826 + }
5827 +
5828 + // SEND BAR (Send BAR to refresh peer reordering buffer.)
5829 + Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
5830 +
5831 +#ifdef CONFIG_STA_SUPPORT
5832 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5833 + BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress);
5834 +#endif // CONFIG_STA_SUPPORT //
5835 +
5836 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL funciton.
5837 + FrameBar.StartingSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; // make sure sequence not clear in DEL funciton.
5838 + FrameBar.BarControl.TID = pInfo->TID; // make sure sequence not clear in DEL funciton.
5839 + FrameBar.BarControl.ACKPolicy = IMMED_BA; // make sure sequence not clear in DEL funciton.
5840 + FrameBar.BarControl.Compressed = 1; // make sure sequence not clear in DEL funciton.
5841 + FrameBar.BarControl.MTID = 0; // make sure sequence not clear in DEL funciton.
5842 +
5843 + MakeOutgoingFrame(pOutBuffer2, &FrameLen,
5844 + sizeof(FRAME_BAR), &FrameBar,
5845 + END_OF_ARGS);
5846 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
5847 + MlmeFreeMemory(pAd, pOutBuffer2);
5848 + DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeDELBAAction() . Send BAR to refresh peer reordering buffer \n"));
5849 +
5850 + // SEND DELBA FRAME
5851 + FrameLen = 0;
5852 +#ifdef CONFIG_STA_SUPPORT
5853 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5854 + {
5855 + if (ADHOC_ON(pAd))
5856 + ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
5857 + else
5858 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[pInfo->Wcid].Addr);
5859 + }
5860 +#endif // CONFIG_STA_SUPPORT //
5861 + Frame.Category = CATEGORY_BA;
5862 + Frame.Action = DELBA;
5863 + Frame.DelbaParm.Initiator = pInfo->Initiator;
5864 + Frame.DelbaParm.TID = pInfo->TID;
5865 + Frame.ReasonCode = 39; // Time Out
5866 + *(USHORT *)(&Frame.DelbaParm) = cpu2le16(*(USHORT *)(&Frame.DelbaParm));
5867 + Frame.ReasonCode = cpu2le16(Frame.ReasonCode);
5868 +
5869 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
5870 + sizeof(FRAME_DELBA_REQ), &Frame,
5871 + END_OF_ARGS);
5872 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
5873 + MlmeFreeMemory(pAd, pOutBuffer);
5874 + DBGPRINT(RT_DEBUG_TRACE, ("BA - MlmeDELBAAction() . 3 DELBA sent. Initiator(%d)\n", pInfo->Initiator));
5875 + }
5876 +}
5877 +#endif // DOT11_N_SUPPORT //
5878 +
5879 +VOID MlmeQOSAction(
5880 + IN PRTMP_ADAPTER pAd,
5881 + IN MLME_QUEUE_ELEM *Elem)
5882 +{
5883 +}
5884 +
5885 +VOID MlmeDLSAction(
5886 + IN PRTMP_ADAPTER pAd,
5887 + IN MLME_QUEUE_ELEM *Elem)
5888 +{
5889 +}
5890 +
5891 +VOID MlmeInvalidAction(
5892 + IN PRTMP_ADAPTER pAd,
5893 + IN MLME_QUEUE_ELEM *Elem)
5894 +{
5895 + //PUCHAR pOutBuffer = NULL;
5896 + //Return the receiving frame except the MSB of category filed set to 1. 7.3.1.11
5897 +}
5898 +
5899 +VOID PeerQOSAction(
5900 + IN PRTMP_ADAPTER pAd,
5901 + IN MLME_QUEUE_ELEM *Elem)
5902 +{
5903 +}
5904 +
5905 +#ifdef QOS_DLS_SUPPORT
5906 +VOID PeerDLSAction(
5907 + IN PRTMP_ADAPTER pAd,
5908 + IN MLME_QUEUE_ELEM *Elem)
5909 +{
5910 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
5911 +
5912 + switch(Action)
5913 + {
5914 + case ACTION_DLS_REQUEST:
5915 +#ifdef CONFIG_STA_SUPPORT
5916 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5917 + PeerDlsReqAction(pAd, Elem);
5918 +#endif // CONFIG_STA_SUPPORT //
5919 + break;
5920 +
5921 + case ACTION_DLS_RESPONSE:
5922 +#ifdef CONFIG_STA_SUPPORT
5923 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5924 + PeerDlsRspAction(pAd, Elem);
5925 +#endif // CONFIG_STA_SUPPORT //
5926 + break;
5927 +
5928 + case ACTION_DLS_TEARDOWN:
5929 +#ifdef CONFIG_STA_SUPPORT
5930 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
5931 + PeerDlsTearDownAction(pAd, Elem);
5932 +#endif // CONFIG_STA_SUPPORT //
5933 + break;
5934 + }
5935 +}
5936 +#endif // QOS_DLS_SUPPORT //
5937 +
5938 +#ifdef DOT11_N_SUPPORT
5939 +VOID PeerBAAction(
5940 + IN PRTMP_ADAPTER pAd,
5941 + IN MLME_QUEUE_ELEM *Elem)
5942 +{
5943 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
5944 +
5945 + switch(Action)
5946 + {
5947 + case ADDBA_REQ:
5948 + PeerAddBAReqAction(pAd,Elem);
5949 + break;
5950 + case ADDBA_RESP:
5951 + PeerAddBARspAction(pAd,Elem);
5952 + break;
5953 + case DELBA:
5954 + PeerDelBAAction(pAd,Elem);
5955 + break;
5956 + }
5957 +}
5958 +
5959 +
5960 +#ifdef DOT11N_DRAFT3
5961 +
5962 +#ifdef CONFIG_STA_SUPPORT
5963 +VOID StaPublicAction(
5964 + IN PRTMP_ADAPTER pAd,
5965 + IN UCHAR Bss2040Coexist)
5966 +{
5967 + BSS_2040_COEXIST_IE BssCoexist;
5968 + MLME_SCAN_REQ_STRUCT ScanReq;
5969 +
5970 + BssCoexist.word = Bss2040Coexist;
5971 + // AP asks Station to return a 20/40 BSS Coexistence mgmt frame. So we first starts a scan, then send back 20/40 BSS Coexistence mgmt frame
5972 + if ((BssCoexist.field.InfoReq == 1) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SCAN_2040)))
5973 + {
5974 + // Clear record first. After scan , will update those bit and send back to transmiter.
5975 + pAd->CommonCfg.BSSCoexist2040.field.InfoReq = 1;
5976 + pAd->CommonCfg.BSSCoexist2040.field.Intolerant40 = 0;
5977 + pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq = 0;
5978 + // Fill out stuff for scan request
5979 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_2040_BSS_COEXIST);
5980 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
5981 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
5982 + }
5983 +}
5984 +
5985 +
5986 +/*
5987 +Description : Build Intolerant Channel Rerpot from Trigger event table.
5988 +return : how many bytes copied.
5989 +*/
5990 +ULONG BuildIntolerantChannelRep(
5991 + IN PRTMP_ADAPTER pAd,
5992 + IN PUCHAR pDest)
5993 +{
5994 + ULONG FrameLen = 0;
5995 + ULONG ReadOffset = 0;
5996 + UCHAR i;
5997 + UCHAR LastRegClass = 0xff;
5998 + PUCHAR pLen;
5999 +
6000 + for ( i = 0;i < MAX_TRIGGER_EVENT;i++)
6001 + {
6002 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].bValid == TRUE)
6003 + {
6004 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].RegClass == LastRegClass)
6005 + {
6006 + *(pDest + ReadOffset) = (UCHAR)pAd->CommonCfg.TriggerEventTab.EventA[i].Channel;
6007 + *pLen++;
6008 + ReadOffset++;
6009 + FrameLen++;
6010 + }
6011 + else
6012 + {
6013 + *(pDest + ReadOffset) = IE_2040_BSS_INTOLERANT_REPORT; // IE
6014 + *(pDest + ReadOffset + 1) = 2; // Len = RegClass byte + channel byte.
6015 + pLen = pDest + ReadOffset + 1;
6016 + LastRegClass = pAd->CommonCfg.TriggerEventTab.EventA[i].RegClass;
6017 + *(pDest + ReadOffset + 2) = LastRegClass; // Len = RegClass byte + channel byte.
6018 + *(pDest + ReadOffset + 3) = (UCHAR)pAd->CommonCfg.TriggerEventTab.EventA[i].Channel;
6019 + FrameLen += 4;
6020 + ReadOffset += 4;
6021 + }
6022 +
6023 + }
6024 + }
6025 + return FrameLen;
6026 +}
6027 +
6028 +
6029 +/*
6030 +Description : Send 20/40 BSS Coexistence Action frame If one trigger event is triggered.
6031 +*/
6032 +VOID Send2040CoexistAction(
6033 + IN PRTMP_ADAPTER pAd,
6034 + IN UCHAR Wcid,
6035 + IN BOOLEAN bAddIntolerantCha)
6036 +{
6037 + PUCHAR pOutBuffer = NULL;
6038 + NDIS_STATUS NStatus;
6039 + FRAME_ACTION_HDR Frame;
6040 + ULONG FrameLen;
6041 + ULONG IntolerantChaRepLen;
6042 +
6043 + IntolerantChaRepLen = 0;
6044 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6045 + if(NStatus != NDIS_STATUS_SUCCESS)
6046 + {
6047 + DBGPRINT(RT_DEBUG_ERROR,("ACT - Send2040CoexistAction() allocate memory failed \n"));
6048 + return;
6049 + }
6050 + ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[Wcid].Addr, pAd->CommonCfg.Bssid);
6051 + Frame.Category = CATEGORY_PUBLIC;
6052 + Frame.Action = ACTION_BSS_2040_COEXIST;
6053 +
6054 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6055 + sizeof(FRAME_ACTION_HDR), &Frame,
6056 + END_OF_ARGS);
6057 +
6058 + *(pOutBuffer + FrameLen) = pAd->CommonCfg.BSSCoexist2040.word;
6059 + FrameLen++;
6060 +
6061 + if (bAddIntolerantCha == TRUE)
6062 + IntolerantChaRepLen = BuildIntolerantChannelRep(pAd, pOutBuffer + FrameLen);
6063 +
6064 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen + IntolerantChaRepLen);
6065 + DBGPRINT(RT_DEBUG_ERROR,("ACT - Send2040CoexistAction( BSSCoexist2040 = 0x%x ) \n", pAd->CommonCfg.BSSCoexist2040.word));
6066 +
6067 +}
6068 +
6069 +
6070 +/*
6071 + ==========================================================================
6072 + Description:
6073 + After scan, Update 20/40 BSS Coexistence IE and send out.
6074 + According to 802.11n D3.03 11.14.10
6075 +
6076 + Parameters:
6077 + ==========================================================================
6078 + */
6079 +VOID Update2040CoexistFrameAndNotify(
6080 + IN PRTMP_ADAPTER pAd,
6081 + IN UCHAR Wcid,
6082 + IN BOOLEAN bAddIntolerantCha)
6083 +{
6084 + BSS_2040_COEXIST_IE OldValue;
6085 +
6086 + OldValue.word = pAd->CommonCfg.BSSCoexist2040.word;
6087 + if ((pAd->CommonCfg.TriggerEventTab.EventANo > 0) || (pAd->CommonCfg.TriggerEventTab.EventBCountDown > 0))
6088 + pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq = 1;
6089 +
6090 + // Need to check !!!!
6091 + // How STA will set Intolerant40 if implementation dependent. Now we don't set this bit first.!!!!!
6092 + // So Only check BSS20WidthReq change.
6093 + if (OldValue.field.BSS20WidthReq != pAd->CommonCfg.BSSCoexist2040.field.BSS20WidthReq)
6094 + {
6095 + Send2040CoexistAction(pAd, Wcid, bAddIntolerantCha);
6096 + }
6097 +}
6098 +#endif // CONFIG_STA_SUPPORT //
6099 +
6100 +
6101 +BOOLEAN ChannelSwitchSanityCheck(
6102 + IN PRTMP_ADAPTER pAd,
6103 + IN UCHAR Wcid,
6104 + IN UCHAR NewChannel,
6105 + IN UCHAR Secondary)
6106 +{
6107 + UCHAR i;
6108 +
6109 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
6110 + return FALSE;
6111 +
6112 + if ((NewChannel > 7) && (Secondary == 1))
6113 + return FALSE;
6114 +
6115 + if ((NewChannel < 5) && (Secondary == 3))
6116 + return FALSE;
6117 +
6118 + // 0. Check if new channel is in the channellist.
6119 + for (i = 0;i < pAd->ChannelListNum;i++)
6120 + {
6121 + if (pAd->ChannelList[i].Channel == NewChannel)
6122 + {
6123 + break;
6124 + }
6125 + }
6126 +
6127 + if (i == pAd->ChannelListNum)
6128 + return FALSE;
6129 +
6130 + return TRUE;
6131 +}
6132 +
6133 +
6134 +VOID ChannelSwitchAction(
6135 + IN PRTMP_ADAPTER pAd,
6136 + IN UCHAR Wcid,
6137 + IN UCHAR NewChannel,
6138 + IN UCHAR Secondary)
6139 +{
6140 + UCHAR BBPValue = 0;
6141 + ULONG MACValue;
6142 +
6143 + DBGPRINT(RT_DEBUG_TRACE,("SPECTRUM - ChannelSwitchAction(NewChannel = %d , Secondary = %d) \n", NewChannel, Secondary));
6144 +
6145 + if (ChannelSwitchSanityCheck(pAd, Wcid, NewChannel, Secondary) == FALSE)
6146 + return;
6147 +
6148 + // 1. Switches to BW = 20.
6149 + if (Secondary == 0)
6150 + {
6151 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6152 + BBPValue&= (~0x18);
6153 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6154 + if (pAd->MACVersion == 0x28600100)
6155 + {
6156 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
6157 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
6158 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
6159 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
6160 + }
6161 + pAd->CommonCfg.BBPCurrentBW = BW_20;
6162 + pAd->CommonCfg.Channel = NewChannel;
6163 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
6164 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel,FALSE);
6165 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
6166 + pAd->MacTab.Content[Wcid].HTPhyMode.field.BW = 0;
6167 + DBGPRINT(RT_DEBUG_TRACE, ("!!!20MHz !!! \n" ));
6168 + }
6169 + // 1. Switches to BW = 40 And Station supports BW = 40.
6170 + else if (((Secondary == 1) || (Secondary == 3)) && (pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == 1))
6171 + {
6172 + pAd->CommonCfg.Channel = NewChannel;
6173 +
6174 + if (Secondary == 1)
6175 + {
6176 + // Secondary above.
6177 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
6178 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &MACValue);
6179 + MACValue &= 0xfe;
6180 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, MACValue);
6181 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6182 + BBPValue&= (~0x18);
6183 + BBPValue|= (0x10);
6184 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6185 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPValue);
6186 + BBPValue&= (~0x20);
6187 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPValue);
6188 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
6189 + }
6190 + else
6191 + {
6192 + // Secondary below.
6193 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
6194 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &MACValue);
6195 + MACValue &= 0xfe;
6196 + MACValue |= 0x1;
6197 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, MACValue);
6198 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
6199 + BBPValue&= (~0x18);
6200 + BBPValue|= (0x10);
6201 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
6202 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPValue);
6203 + BBPValue&= (~0x20);
6204 + BBPValue|= (0x20);
6205 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPValue);
6206 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
6207 + }
6208 + pAd->CommonCfg.BBPCurrentBW = BW_40;
6209 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
6210 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
6211 + pAd->MacTab.Content[Wcid].HTPhyMode.field.BW = 1;
6212 + }
6213 +}
6214 +#endif // DOT11N_DRAFT3 //
6215 +#endif // DOT11_N_SUPPORT //
6216 +
6217 +VOID PeerPublicAction(
6218 + IN PRTMP_ADAPTER pAd,
6219 + IN MLME_QUEUE_ELEM *Elem)
6220 +{
6221 +#ifdef DOT11N_DRAFT3
6222 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
6223 +#endif // DOT11N_DRAFT3 //
6224 +
6225 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
6226 + return;
6227 +
6228 +#ifdef DOT11N_DRAFT3
6229 + switch(Action)
6230 + {
6231 + case ACTION_BSS_2040_COEXIST: // Format defined in IEEE 7.4.7a.1 in 11n Draf3.03
6232 + {
6233 + //UCHAR BssCoexist;
6234 + BSS_2040_COEXIST_ELEMENT *pCoexistInfo;
6235 + BSS_2040_COEXIST_IE *pBssCoexistIe;
6236 + BSS_2040_INTOLERANT_CH_REPORT *pIntolerantReport = NULL;
6237 +
6238 + if (Elem->MsgLen <= (LENGTH_802_11 + sizeof(BSS_2040_COEXIST_ELEMENT)) )
6239 + {
6240 + DBGPRINT(RT_DEBUG_ERROR, ("ACTION - 20/40 BSS Coexistence Management Frame length too short! len = %ld!\n", Elem->MsgLen));
6241 + break;
6242 + }
6243 + DBGPRINT(RT_DEBUG_TRACE, ("ACTION - 20/40 BSS Coexistence Management action----> \n"));
6244 + hex_dump("CoexistenceMgmtFrame", Elem->Msg, Elem->MsgLen);
6245 +
6246 +
6247 + pCoexistInfo = (BSS_2040_COEXIST_ELEMENT *) &Elem->Msg[LENGTH_802_11+2];
6248 + //hex_dump("CoexistInfo", (PUCHAR)pCoexistInfo, sizeof(BSS_2040_COEXIST_ELEMENT));
6249 + if (Elem->MsgLen >= (LENGTH_802_11 + sizeof(BSS_2040_COEXIST_ELEMENT) + sizeof(BSS_2040_INTOLERANT_CH_REPORT)))
6250 + {
6251 + pIntolerantReport = (BSS_2040_INTOLERANT_CH_REPORT *)((PUCHAR)pCoexistInfo + sizeof(BSS_2040_COEXIST_ELEMENT));
6252 + }
6253 + //hex_dump("IntolerantReport ", (PUCHAR)pIntolerantReport, sizeof(BSS_2040_INTOLERANT_CH_REPORT));
6254 +
6255 + pBssCoexistIe = (BSS_2040_COEXIST_IE *)(&pCoexistInfo->BssCoexistIe);
6256 +
6257 +#ifdef CONFIG_STA_SUPPORT
6258 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6259 + {
6260 + if (INFRA_ON(pAd))
6261 + {
6262 + StaPublicAction(pAd, pCoexistInfo);
6263 + }
6264 + }
6265 +#endif // CONFIG_STA_SUPPORT //
6266 +
6267 + }
6268 + break;
6269 + }
6270 +
6271 +#endif // DOT11N_DRAFT3 //
6272 +
6273 +}
6274 +
6275 +
6276 +static VOID ReservedAction(
6277 + IN PRTMP_ADAPTER pAd,
6278 + IN MLME_QUEUE_ELEM *Elem)
6279 +{
6280 + UCHAR Category;
6281 +
6282 + if (Elem->MsgLen <= LENGTH_802_11)
6283 + {
6284 + return;
6285 + }
6286 +
6287 + Category = Elem->Msg[LENGTH_802_11];
6288 + DBGPRINT(RT_DEBUG_TRACE,("Rcv reserved category(%d) Action Frame\n", Category));
6289 + hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen);
6290 +}
6291 +
6292 +VOID PeerRMAction(
6293 + IN PRTMP_ADAPTER pAd,
6294 + IN MLME_QUEUE_ELEM *Elem)
6295 +
6296 +{
6297 + return;
6298 +}
6299 +
6300 +#ifdef DOT11_N_SUPPORT
6301 +static VOID respond_ht_information_exchange_action(
6302 + IN PRTMP_ADAPTER pAd,
6303 + IN MLME_QUEUE_ELEM *Elem)
6304 +{
6305 + PUCHAR pOutBuffer = NULL;
6306 + NDIS_STATUS NStatus;
6307 + ULONG FrameLen;
6308 + FRAME_HT_INFO HTINFOframe, *pFrame;
6309 + UCHAR *pAddr;
6310 +
6311 +
6312 + // 2. Always send back ADDBA Response
6313 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6314 +
6315 + if (NStatus != NDIS_STATUS_SUCCESS)
6316 + {
6317 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - respond_ht_information_exchange_action() allocate memory failed \n"));
6318 + return;
6319 + }
6320 +
6321 + // get RA
6322 + pFrame = (FRAME_HT_INFO *) &Elem->Msg[0];
6323 + pAddr = pFrame->Hdr.Addr2;
6324 +
6325 + NdisZeroMemory(&HTINFOframe, sizeof(FRAME_HT_INFO));
6326 + // 2-1. Prepare ADDBA Response frame.
6327 +#ifdef CONFIG_STA_SUPPORT
6328 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6329 + {
6330 + if (ADHOC_ON(pAd))
6331 + ActHeaderInit(pAd, &HTINFOframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
6332 + else
6333 + ActHeaderInit(pAd, &HTINFOframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr);
6334 + }
6335 +#endif // CONFIG_STA_SUPPORT //
6336 +
6337 + HTINFOframe.Category = CATEGORY_HT;
6338 + HTINFOframe.Action = HT_INFO_EXCHANGE;
6339 + HTINFOframe.HT_Info.Request = 0;
6340 + HTINFOframe.HT_Info.Forty_MHz_Intolerant = pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant;
6341 + HTINFOframe.HT_Info.STA_Channel_Width = pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth;
6342 +
6343 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6344 + sizeof(FRAME_HT_INFO), &HTINFOframe,
6345 + END_OF_ARGS);
6346 +
6347 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
6348 + MlmeFreeMemory(pAd, pOutBuffer);
6349 +}
6350 +
6351 +
6352 +#ifdef DOT11N_DRAFT3
6353 +VOID SendNotifyBWActionFrame(
6354 + IN PRTMP_ADAPTER pAd,
6355 + IN UCHAR Wcid,
6356 + IN UCHAR apidx)
6357 +{
6358 + PUCHAR pOutBuffer = NULL;
6359 + NDIS_STATUS NStatus;
6360 + FRAME_ACTION_HDR Frame;
6361 + ULONG FrameLen;
6362 + PUCHAR pAddr1;
6363 +
6364 +
6365 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6366 + if(NStatus != NDIS_STATUS_SUCCESS)
6367 + {
6368 + DBGPRINT(RT_DEBUG_ERROR,("ACT - SendNotifyBWAction() allocate memory failed \n"));
6369 + return;
6370 + }
6371 +
6372 + if (Wcid == MCAST_WCID)
6373 + pAddr1 = &BROADCAST_ADDR[0];
6374 + else
6375 + pAddr1 = pAd->MacTab.Content[Wcid].Addr;
6376 + ActHeaderInit(pAd, &Frame.Hdr, pAddr1, pAd->ApCfg.MBSSID[apidx].Bssid, pAd->ApCfg.MBSSID[apidx].Bssid);
6377 +
6378 + Frame.Category = CATEGORY_HT;
6379 + Frame.Action = NOTIFY_BW_ACTION;
6380 +
6381 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6382 + sizeof(FRAME_ACTION_HDR), &Frame,
6383 + END_OF_ARGS);
6384 +
6385 + *(pOutBuffer + FrameLen) = pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth;
6386 + FrameLen++;
6387 +
6388 +
6389 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
6390 + DBGPRINT(RT_DEBUG_TRACE,("ACT - SendNotifyBWAction(NotifyBW= %d)!\n", pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth));
6391 +
6392 +}
6393 +#endif // DOT11N_DRAFT3 //
6394 +
6395 +
6396 +VOID PeerHTAction(
6397 + IN PRTMP_ADAPTER pAd,
6398 + IN MLME_QUEUE_ELEM *Elem)
6399 +{
6400 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
6401 +
6402 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
6403 + return;
6404 +
6405 + switch(Action)
6406 + {
6407 + case NOTIFY_BW_ACTION:
6408 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Notify Channel bandwidth action----> \n"));
6409 +#ifdef CONFIG_STA_SUPPORT
6410 + if(pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
6411 + {
6412 + // Note, this is to patch DIR-1353 AP. When the AP set to Wep, it will use legacy mode. But AP still keeps
6413 + // sending BW_Notify Action frame, and cause us to linkup and linkdown.
6414 + // In legacy mode, don't need to parse HT action frame.
6415 + DBGPRINT(RT_DEBUG_TRACE,("ACTION -Ignore HT Notify Channel BW when link as legacy mode. BW = %d---> \n",
6416 + Elem->Msg[LENGTH_802_11+2] ));
6417 + break;
6418 + }
6419 +#endif // CONFIG_STA_SUPPORT //
6420 +
6421 + if (Elem->Msg[LENGTH_802_11+2] == 0) // 7.4.8.2. if value is 1, keep the same as supported channel bandwidth.
6422 + pAd->MacTab.Content[Elem->Wcid].HTPhyMode.field.BW = 0;
6423 +
6424 + break;
6425 +
6426 + case SMPS_ACTION:
6427 + // 7.3.1.25
6428 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - SMPS action----> \n"));
6429 + if (((Elem->Msg[LENGTH_802_11+2]&0x1) == 0))
6430 + {
6431 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_ENABLE;
6432 + }
6433 + else if (((Elem->Msg[LENGTH_802_11+2]&0x2) == 0))
6434 + {
6435 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_STATIC;
6436 + }
6437 + else
6438 + {
6439 + pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_DYNAMIC;
6440 + }
6441 +
6442 + DBGPRINT(RT_DEBUG_TRACE,("Aid(%d) MIMO PS = %d\n", Elem->Wcid, pAd->MacTab.Content[Elem->Wcid].MmpsMode));
6443 + // rt2860c : add something for smps change.
6444 + break;
6445 +
6446 + case SETPCO_ACTION:
6447 + break;
6448 +
6449 + case MIMO_CHA_MEASURE_ACTION:
6450 + break;
6451 +
6452 + case HT_INFO_EXCHANGE:
6453 + {
6454 + HT_INFORMATION_OCTET *pHT_info;
6455 +
6456 + pHT_info = (HT_INFORMATION_OCTET *) &Elem->Msg[LENGTH_802_11+2];
6457 + // 7.4.8.10
6458 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Information Exchange action----> \n"));
6459 + if (pHT_info->Request)
6460 + {
6461 + respond_ht_information_exchange_action(pAd, Elem);
6462 + }
6463 + }
6464 + break;
6465 + }
6466 +}
6467 +
6468 +
6469 +/*
6470 + ==========================================================================
6471 + Description:
6472 + Retry sending ADDBA Reqest.
6473 +
6474 + IRQL = DISPATCH_LEVEL
6475 +
6476 + Parametrs:
6477 + p8023Header: if this is already 802.3 format, p8023Header is NULL
6478 +
6479 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
6480 + FALSE , then continue indicaterx at this moment.
6481 + ==========================================================================
6482 + */
6483 +VOID ORIBATimerTimeout(
6484 + IN PRTMP_ADAPTER pAd)
6485 +{
6486 + MAC_TABLE_ENTRY *pEntry;
6487 + INT i, total;
6488 +// FRAME_BAR FrameBar;
6489 +// ULONG FrameLen;
6490 +// NDIS_STATUS NStatus;
6491 +// PUCHAR pOutBuffer = NULL;
6492 +// USHORT Sequence;
6493 + UCHAR TID;
6494 +
6495 +#ifdef RALINK_ATE
6496 + if (ATE_ON(pAd))
6497 + return;
6498 +#endif // RALINK_ATE //
6499 +
6500 + total = pAd->MacTab.Size * NUM_OF_TID;
6501 +
6502 + for (i = 1; ((i <MAX_LEN_OF_BA_ORI_TABLE) && (total > 0)) ; i++)
6503 + {
6504 + if (pAd->BATable.BAOriEntry[i].ORI_BA_Status == Originator_Done)
6505 + {
6506 + pEntry = &pAd->MacTab.Content[pAd->BATable.BAOriEntry[i].Wcid];
6507 + TID = pAd->BATable.BAOriEntry[i].TID;
6508 +
6509 + ASSERT(pAd->BATable.BAOriEntry[i].Wcid < MAX_LEN_OF_MAC_TABLE);
6510 + }
6511 + total --;
6512 + }
6513 +}
6514 +
6515 +
6516 +VOID SendRefreshBAR(
6517 + IN PRTMP_ADAPTER pAd,
6518 + IN MAC_TABLE_ENTRY *pEntry)
6519 +{
6520 + FRAME_BAR FrameBar;
6521 + ULONG FrameLen;
6522 + NDIS_STATUS NStatus;
6523 + PUCHAR pOutBuffer = NULL;
6524 + USHORT Sequence;
6525 + UCHAR i, TID;
6526 + USHORT idx;
6527 + BA_ORI_ENTRY *pBAEntry;
6528 +
6529 + for (i = 0; i <NUM_OF_TID; i++)
6530 + {
6531 + idx = pEntry->BAOriWcidArray[i];
6532 + if (idx == 0)
6533 + {
6534 + continue;
6535 + }
6536 + pBAEntry = &pAd->BATable.BAOriEntry[idx];
6537 +
6538 + if (pBAEntry->ORI_BA_Status == Originator_Done)
6539 + {
6540 + TID = pBAEntry->TID;
6541 +
6542 + ASSERT(pBAEntry->Wcid < MAX_LEN_OF_MAC_TABLE);
6543 +
6544 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
6545 + if(NStatus != NDIS_STATUS_SUCCESS)
6546 + {
6547 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n"));
6548 + return;
6549 + }
6550 +
6551 + Sequence = pEntry->TxSeq[TID];
6552 +
6553 +
6554 +#ifdef CONFIG_STA_SUPPORT
6555 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6556 + BarHeaderInit(pAd, &FrameBar, pEntry->Addr, pAd->CurrentAddress);
6557 +#endif // CONFIG_STA_SUPPORT //
6558 +
6559 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function.
6560 + FrameBar.StartingSeq.field.StartSeq = Sequence; // make sure sequence not clear in DEL funciton.
6561 + FrameBar.BarControl.TID = TID; // make sure sequence not clear in DEL funciton.
6562 +
6563 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
6564 + sizeof(FRAME_BAR), &FrameBar,
6565 + END_OF_ARGS);
6566 + //if (!(CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_RALINK_CHIPSET)))
6567 + if (1) // Now we always send BAR.
6568 + {
6569 + //MiniportMMRequestUnlock(pAd, 0, pOutBuffer, FrameLen);
6570 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
6571 + //MiniportDataMMRequest(pAd, MapUserPriorityToAccessCategory[TID], pOutBuffer, FrameLen);
6572 + }
6573 + MlmeFreeMemory(pAd, pOutBuffer);
6574 + }
6575 + }
6576 +}
6577 +#endif // DOT11_N_SUPPORT //
6578 +
6579 +VOID ActHeaderInit(
6580 + IN PRTMP_ADAPTER pAd,
6581 + IN OUT PHEADER_802_11 pHdr80211,
6582 + IN PUCHAR Addr1,
6583 + IN PUCHAR Addr2,
6584 + IN PUCHAR Addr3)
6585 +{
6586 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
6587 + pHdr80211->FC.Type = BTYPE_MGMT;
6588 + pHdr80211->FC.SubType = SUBTYPE_ACTION;
6589 +
6590 + COPY_MAC_ADDR(pHdr80211->Addr1, Addr1);
6591 + COPY_MAC_ADDR(pHdr80211->Addr2, Addr2);
6592 + COPY_MAC_ADDR(pHdr80211->Addr3, Addr3);
6593 +}
6594 +
6595 +VOID BarHeaderInit(
6596 + IN PRTMP_ADAPTER pAd,
6597 + IN OUT PFRAME_BAR pCntlBar,
6598 + IN PUCHAR pDA,
6599 + IN PUCHAR pSA)
6600 +{
6601 +// USHORT Duration;
6602 +
6603 + NdisZeroMemory(pCntlBar, sizeof(FRAME_BAR));
6604 + pCntlBar->FC.Type = BTYPE_CNTL;
6605 + pCntlBar->FC.SubType = SUBTYPE_BLOCK_ACK_REQ;
6606 + pCntlBar->BarControl.MTID = 0;
6607 + pCntlBar->BarControl.Compressed = 1;
6608 + pCntlBar->BarControl.ACKPolicy = 0;
6609 +
6610 +
6611 + pCntlBar->Duration = 16 + RTMPCalcDuration(pAd, RATE_1, sizeof(FRAME_BA));
6612 +
6613 + COPY_MAC_ADDR(pCntlBar->Addr1, pDA);
6614 + COPY_MAC_ADDR(pCntlBar->Addr2, pSA);
6615 +}
6616 +
6617 +
6618 +/*
6619 + ==========================================================================
6620 + Description:
6621 + Insert Category and action code into the action frame.
6622 +
6623 + Parametrs:
6624 + 1. frame buffer pointer.
6625 + 2. frame length.
6626 + 3. category code of the frame.
6627 + 4. action code of the frame.
6628 +
6629 + Return : None.
6630 + ==========================================================================
6631 + */
6632 +VOID InsertActField(
6633 + IN PRTMP_ADAPTER pAd,
6634 + OUT PUCHAR pFrameBuf,
6635 + OUT PULONG pFrameLen,
6636 + IN UINT8 Category,
6637 + IN UINT8 ActCode)
6638 +{
6639 + ULONG TempLen;
6640 +
6641 + MakeOutgoingFrame( pFrameBuf, &TempLen,
6642 + 1, &Category,
6643 + 1, &ActCode,
6644 + END_OF_ARGS);
6645 +
6646 + *pFrameLen = *pFrameLen + TempLen;
6647 +
6648 + return;
6649 +}
6650 --- /dev/null
6651 +++ b/drivers/staging/rt3070/common/ba_action.c
6652 @@ -0,0 +1,1810 @@
6653 +/*
6654 + *************************************************************************
6655 + * Ralink Tech Inc.
6656 + * 5F., No.36, Taiyuan St., Jhubei City,
6657 + * Hsinchu County 302,
6658 + * Taiwan, R.O.C.
6659 + *
6660 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
6661 + *
6662 + * This program is free software; you can redistribute it and/or modify *
6663 + * it under the terms of the GNU General Public License as published by *
6664 + * the Free Software Foundation; either version 2 of the License, or *
6665 + * (at your option) any later version. *
6666 + * *
6667 + * This program is distributed in the hope that it will be useful, *
6668 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
6669 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
6670 + * GNU General Public License for more details. *
6671 + * *
6672 + * You should have received a copy of the GNU General Public License *
6673 + * along with this program; if not, write to the *
6674 + * Free Software Foundation, Inc., *
6675 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
6676 + * *
6677 + *************************************************************************
6678 + */
6679 +
6680 +
6681 +#ifdef DOT11_N_SUPPORT
6682 +
6683 +#include "../rt_config.h"
6684 +
6685 +
6686 +
6687 +#define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) //1 // inital sequence number of BA session
6688 +
6689 +#define ORI_SESSION_MAX_RETRY 8
6690 +#define ORI_BA_SESSION_TIMEOUT (2000) // ms
6691 +#define REC_BA_SESSION_IDLE_TIMEOUT (1000) // ms
6692 +
6693 +#define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms
6694 +#define MAX_REORDERING_PACKET_TIMEOUT ((3000 * HZ)/1000) // system ticks -- 100 ms
6695 +
6696 +#define RESET_RCV_SEQ (0xFFFF)
6697 +
6698 +static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk);
6699 +
6700 +
6701 +BA_ORI_ENTRY *BATableAllocOriEntry(
6702 + IN PRTMP_ADAPTER pAd,
6703 + OUT USHORT *Idx);
6704 +
6705 +BA_REC_ENTRY *BATableAllocRecEntry(
6706 + IN PRTMP_ADAPTER pAd,
6707 + OUT USHORT *Idx);
6708 +
6709 +VOID BAOriSessionSetupTimeout(
6710 + IN PVOID SystemSpecific1,
6711 + IN PVOID FunctionContext,
6712 + IN PVOID SystemSpecific2,
6713 + IN PVOID SystemSpecific3);
6714 +
6715 +VOID BARecSessionIdleTimeout(
6716 + IN PVOID SystemSpecific1,
6717 + IN PVOID FunctionContext,
6718 + IN PVOID SystemSpecific2,
6719 + IN PVOID SystemSpecific3);
6720 +
6721 +
6722 +BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout);
6723 +BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout);
6724 +
6725 +#define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \
6726 + Announce_Reordering_Packet(_pAd, _mpdu_blk);
6727 +
6728 +VOID BA_MaxWinSizeReasign(
6729 + IN PRTMP_ADAPTER pAd,
6730 + IN MAC_TABLE_ENTRY *pEntryPeer,
6731 + OUT UCHAR *pWinSize)
6732 +{
6733 + UCHAR MaxSize;
6734 +
6735 +
6736 + if (pAd->MACVersion >= RALINK_2883_VERSION) // 3*3
6737 + {
6738 + if (pAd->MACVersion >= RALINK_3070_VERSION)
6739 + {
6740 + if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled)
6741 + MaxSize = 7; // for non-open mode
6742 + else
6743 + MaxSize = 13;
6744 + }
6745 + else
6746 + MaxSize = 31;
6747 + }
6748 + else if (pAd->MACVersion >= RALINK_2880E_VERSION) // 2880 e
6749 + {
6750 + if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled)
6751 + MaxSize = 7; // for non-open mode
6752 + else
6753 + MaxSize = 13;
6754 + }
6755 + else
6756 + MaxSize = 7;
6757 +
6758 + DBGPRINT(RT_DEBUG_TRACE, ("ba> Win Size = %d, Max Size = %d\n",
6759 + *pWinSize, MaxSize));
6760 +
6761 + if ((*pWinSize) > MaxSize)
6762 + {
6763 + DBGPRINT(RT_DEBUG_TRACE, ("ba> reassign max win size from %d to %d\n",
6764 + *pWinSize, MaxSize));
6765 +
6766 + *pWinSize = MaxSize;
6767 + }
6768 +}
6769 +
6770 +void Announce_Reordering_Packet(IN PRTMP_ADAPTER pAd,
6771 + IN struct reordering_mpdu *mpdu)
6772 +{
6773 + PNDIS_PACKET pPacket;
6774 +
6775 + pPacket = mpdu->pPacket;
6776 +
6777 + if (mpdu->bAMSDU)
6778 + {
6779 + ASSERT(0);
6780 + BA_Reorder_AMSDU_Annnounce(pAd, pPacket);
6781 + }
6782 + else
6783 + {
6784 + //
6785 + // pass this 802.3 packet to upper layer or forward this packet to WM directly
6786 + //
6787 +
6788 +#ifdef CONFIG_STA_SUPPORT
6789 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
6790 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket, RTMP_GET_PACKET_IF(pPacket));
6791 +#endif // CONFIG_STA_SUPPORT //
6792 + }
6793 +}
6794 +
6795 +/*
6796 + * Insert a reordering mpdu into sorted linked list by sequence no.
6797 + */
6798 +BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list, struct reordering_mpdu *mpdu)
6799 +{
6800 +
6801 + struct reordering_mpdu **ppScan = &list->next;
6802 +
6803 + while (*ppScan != NULL)
6804 + {
6805 + if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ))
6806 + {
6807 + ppScan = &(*ppScan)->next;
6808 + }
6809 + else if ((*ppScan)->Sequence == mpdu->Sequence)
6810 + {
6811 + /* give up this duplicated frame */
6812 + return(FALSE);
6813 + }
6814 + else
6815 + {
6816 + /* find position */
6817 + break;
6818 + }
6819 + }
6820 +
6821 + mpdu->next = *ppScan;
6822 + *ppScan = mpdu;
6823 + list->qlen++;
6824 + return TRUE;
6825 +}
6826 +
6827 +
6828 +/*
6829 + * caller lock critical section if necessary
6830 + */
6831 +static inline void ba_enqueue(struct reordering_list *list, struct reordering_mpdu *mpdu_blk)
6832 +{
6833 + list->qlen++;
6834 + mpdu_blk->next = list->next;
6835 + list->next = mpdu_blk;
6836 +}
6837 +
6838 +/*
6839 + * caller lock critical section if necessary
6840 + */
6841 +static inline struct reordering_mpdu * ba_dequeue(struct reordering_list *list)
6842 +{
6843 + struct reordering_mpdu *mpdu_blk = NULL;
6844 +
6845 + ASSERT(list);
6846 +
6847 + if (list->qlen)
6848 + {
6849 + list->qlen--;
6850 + mpdu_blk = list->next;
6851 + if (mpdu_blk)
6852 + {
6853 + list->next = mpdu_blk->next;
6854 + mpdu_blk->next = NULL;
6855 + }
6856 + }
6857 + return mpdu_blk;
6858 +}
6859 +
6860 +
6861 +static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct reordering_list *list)
6862 +{
6863 + return(ba_dequeue(list));
6864 +}
6865 +
6866 +
6867 +static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct reordering_list *list)
6868 + {
6869 + ASSERT(list);
6870 +
6871 + return(list->next);
6872 + }
6873 +
6874 +
6875 +/*
6876 + * free all resource for reordering mechanism
6877 + */
6878 +void ba_reordering_resource_release(PRTMP_ADAPTER pAd)
6879 +{
6880 + BA_TABLE *Tab;
6881 + PBA_REC_ENTRY pBAEntry;
6882 + struct reordering_mpdu *mpdu_blk;
6883 + int i;
6884 +
6885 + Tab = &pAd->BATable;
6886 +
6887 + /* I. release all pending reordering packet */
6888 + NdisAcquireSpinLock(&pAd->BATabLock);
6889 + for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++)
6890 + {
6891 + pBAEntry = &Tab->BARecEntry[i];
6892 + if (pBAEntry->REC_BA_Status != Recipient_NONE)
6893 + {
6894 + while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list)))
6895 + {
6896 + ASSERT(mpdu_blk->pPacket);
6897 + RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket, NDIS_STATUS_FAILURE);
6898 + ba_mpdu_blk_free(pAd, mpdu_blk);
6899 + }
6900 + }
6901 + }
6902 + NdisReleaseSpinLock(&pAd->BATabLock);
6903 +
6904 + ASSERT(pBAEntry->list.qlen == 0);
6905 + /* II. free memory of reordering mpdu table */
6906 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
6907 + os_free_mem(pAd, pAd->mpdu_blk_pool.mem);
6908 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
6909 +}
6910 +
6911 +
6912 +
6913 +/*
6914 + * Allocate all resource for reordering mechanism
6915 + */
6916 +BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num)
6917 +{
6918 + int i;
6919 + PUCHAR mem;
6920 + struct reordering_mpdu *mpdu_blk;
6921 + struct reordering_list *freelist;
6922 +
6923 + /* allocate spinlock */
6924 + NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock);
6925 +
6926 + /* initialize freelist */
6927 + freelist = &pAd->mpdu_blk_pool.freelist;
6928 + freelist->next = NULL;
6929 + freelist->qlen = 0;
6930 +
6931 + DBGPRINT(RT_DEBUG_TRACE, ("Allocate %d memory for BA reordering\n", (UINT32)(num*sizeof(struct reordering_mpdu))));
6932 +
6933 + /* allocate number of mpdu_blk memory */
6934 + os_alloc_mem(pAd, (PUCHAR *)&mem, (num*sizeof(struct reordering_mpdu)));
6935 +
6936 + pAd->mpdu_blk_pool.mem = mem;
6937 +
6938 + if (mem == NULL)
6939 + {
6940 + DBGPRINT(RT_DEBUG_ERROR, ("Can't Allocate Memory for BA Reordering\n"));
6941 + return(FALSE);
6942 + }
6943 +
6944 + /* build mpdu_blk free list */
6945 + for (i=0; i<num; i++)
6946 + {
6947 + /* get mpdu_blk */
6948 + mpdu_blk = (struct reordering_mpdu *) mem;
6949 + /* initial mpdu_blk */
6950 + NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
6951 + /* next mpdu_blk */
6952 + mem += sizeof(struct reordering_mpdu);
6953 + /* insert mpdu_blk into freelist */
6954 + ba_enqueue(freelist, mpdu_blk);
6955 + }
6956 +
6957 + return(TRUE);
6958 +}
6959 +
6960 +//static int blk_count=0; // sample take off, no use
6961 +
6962 +static struct reordering_mpdu *ba_mpdu_blk_alloc(PRTMP_ADAPTER pAd)
6963 +{
6964 + struct reordering_mpdu *mpdu_blk;
6965 +
6966 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
6967 + mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist);
6968 + if (mpdu_blk)
6969 + {
6970 +// blk_count++;
6971 + /* reset mpdu_blk */
6972 + NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
6973 + }
6974 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
6975 + return mpdu_blk;
6976 +}
6977 +
6978 +static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk)
6979 +{
6980 + ASSERT(mpdu_blk);
6981 +
6982 + NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
6983 +// blk_count--;
6984 + ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk);
6985 + NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
6986 +}
6987 +
6988 +
6989 +static USHORT ba_indicate_reordering_mpdus_in_order(
6990 + IN PRTMP_ADAPTER pAd,
6991 + IN PBA_REC_ENTRY pBAEntry,
6992 + IN USHORT StartSeq)
6993 +{
6994 + struct reordering_mpdu *mpdu_blk;
6995 + USHORT LastIndSeq = RESET_RCV_SEQ;
6996 +
6997 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
6998 +
6999 + while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list)))
7000 + {
7001 + /* find in-order frame */
7002 + if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ))
7003 + {
7004 + break;
7005 + }
7006 + /* dequeue in-order frame from reodering list */
7007 + mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
7008 + /* pass this frame up */
7009 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7010 + /* move to next sequence */
7011 + StartSeq = mpdu_blk->Sequence;
7012 + LastIndSeq = StartSeq;
7013 + /* free mpdu_blk */
7014 + ba_mpdu_blk_free(pAd, mpdu_blk);
7015 + }
7016 +
7017 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7018 +
7019 + /* update last indicated sequence */
7020 + return LastIndSeq;
7021 +}
7022 +
7023 +static void ba_indicate_reordering_mpdus_le_seq(
7024 + IN PRTMP_ADAPTER pAd,
7025 + IN PBA_REC_ENTRY pBAEntry,
7026 + IN USHORT Sequence)
7027 +{
7028 + struct reordering_mpdu *mpdu_blk;
7029 +
7030 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
7031 + while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list)))
7032 + {
7033 + /* find in-order frame */
7034 + if ((mpdu_blk->Sequence == Sequence) || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ))
7035 + {
7036 + /* dequeue in-order frame from reodering list */
7037 + mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
7038 + /* pass this frame up */
7039 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7040 + /* free mpdu_blk */
7041 + ba_mpdu_blk_free(pAd, mpdu_blk);
7042 + }
7043 + else
7044 + {
7045 + break;
7046 + }
7047 + }
7048 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7049 +}
7050 +
7051 +
7052 +static void ba_refresh_reordering_mpdus(
7053 + IN PRTMP_ADAPTER pAd,
7054 + PBA_REC_ENTRY pBAEntry)
7055 +{
7056 + struct reordering_mpdu *mpdu_blk;
7057 +
7058 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
7059 +
7060 + /* dequeue in-order frame from reodering list */
7061 + while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list)))
7062 + {
7063 + /* pass this frame up */
7064 + ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
7065 +
7066 + pBAEntry->LastIndSeq = mpdu_blk->Sequence;
7067 + ba_mpdu_blk_free(pAd, mpdu_blk);
7068 +
7069 + /* update last indicated sequence */
7070 + }
7071 + ASSERT(pBAEntry->list.qlen == 0);
7072 + pBAEntry->LastIndSeq = RESET_RCV_SEQ;
7073 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
7074 +}
7075 +
7076 +
7077 +//static
7078 +void ba_flush_reordering_timeout_mpdus(
7079 + IN PRTMP_ADAPTER pAd,
7080 + IN PBA_REC_ENTRY pBAEntry,
7081 + IN ULONG Now32)
7082 +
7083 +{
7084 + USHORT Sequence;
7085 +
7086 +// if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) &&
7087 +// (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //||
7088 +// (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) &&
7089 +// (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8)))
7090 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(MAX_REORDERING_PACKET_TIMEOUT/6)))
7091 + &&(pBAEntry->list.qlen > 1)
7092 + )
7093 + {
7094 + DBGPRINT(RT_DEBUG_TRACE,("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer),
7095 + (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), MAX_REORDERING_PACKET_TIMEOUT,
7096 + pBAEntry->LastIndSeq));
7097 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7098 + pBAEntry->LastIndSeqAtTimer = Now32;
7099 + }
7100 + else
7101 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT)))
7102 + && (pBAEntry->list.qlen > 0)
7103 + )
7104 + {
7105 +// printk("timeout[%d] (%lx-%lx = %d > %d): %x, ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer),
7106 +// (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), REORDERING_PACKET_TIMEOUT,
7107 +// pBAEntry->LastIndSeq);
7108 + //
7109 + // force LastIndSeq to shift to LastIndSeq+1
7110 + //
7111 + Sequence = (pBAEntry->LastIndSeq+1) & MAXSEQ;
7112 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
7113 + pBAEntry->LastIndSeqAtTimer = Now32;
7114 + pBAEntry->LastIndSeq = Sequence;
7115 + //
7116 + // indicate in-order mpdus
7117 + //
7118 + Sequence = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, Sequence);
7119 + if (Sequence != RESET_RCV_SEQ)
7120 + {
7121 + pBAEntry->LastIndSeq = Sequence;
7122 + }
7123 +
7124 + //printk("%x, flush one!\n", pBAEntry->LastIndSeq);
7125 +
7126 + }
7127 +}
7128 +
7129 +
7130 +/*
7131 + * generate ADDBA request to
7132 + * set up BA agreement
7133 + */
7134 +VOID BAOriSessionSetUp(
7135 + IN PRTMP_ADAPTER pAd,
7136 + IN MAC_TABLE_ENTRY *pEntry,
7137 + IN UCHAR TID,
7138 + IN USHORT TimeOut,
7139 + IN ULONG DelayTime,
7140 + IN BOOLEAN isForced)
7141 +
7142 +{
7143 + //MLME_ADDBA_REQ_STRUCT AddbaReq;
7144 + BA_ORI_ENTRY *pBAEntry = NULL;
7145 + USHORT Idx;
7146 + BOOLEAN Cancelled;
7147 +
7148 + if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE) && (isForced == FALSE))
7149 + return;
7150 +
7151 + // if this entry is limited to use legacy tx mode, it doesn't generate BA.
7152 + if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT)
7153 + return;
7154 +
7155 + if ((pEntry->BADeclineBitmap & (1<<TID)) && (isForced == FALSE))
7156 + {
7157 + // try again after 3 secs
7158 + DelayTime = 3000;
7159 +// printk("DeCline BA from Peer\n");
7160 +// return;
7161 + }
7162 +
7163 +
7164 + Idx = pEntry->BAOriWcidArray[TID];
7165 + if (Idx == 0)
7166 + {
7167 + // allocate a BA session
7168 + pBAEntry = BATableAllocOriEntry(pAd, &Idx);
7169 + if (pBAEntry == NULL)
7170 + {
7171 + DBGPRINT(RT_DEBUG_TRACE,("ADDBA - MlmeADDBAAction() allocate BA session failed \n"));
7172 + return;
7173 + }
7174 + }
7175 + else
7176 + {
7177 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7178 + }
7179 +
7180 + if (pBAEntry->ORI_BA_Status >= Originator_WaitRes)
7181 + {
7182 + return;
7183 + }
7184 +
7185 + pEntry->BAOriWcidArray[TID] = Idx;
7186 +
7187 + // Initialize BA session
7188 + pBAEntry->ORI_BA_Status = Originator_WaitRes;
7189 + pBAEntry->Wcid = pEntry->Aid;
7190 + pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit;
7191 + pBAEntry->Sequence = BA_ORI_INIT_SEQ;
7192 + pBAEntry->Token = 1; // (2008-01-21) Jan Lee recommends it - this token can't be 0
7193 + pBAEntry->TID = TID;
7194 + pBAEntry->TimeOutValue = TimeOut;
7195 + pBAEntry->pAdapter = pAd;
7196 +
7197 + DBGPRINT(RT_DEBUG_TRACE,("Send AddBA to %02x:%02x:%02x:%02x:%02x:%02x Tid:%d isForced:%d Wcid:%d\n"
7198 + ,pEntry->Addr[0],pEntry->Addr[1],pEntry->Addr[2]
7199 + ,pEntry->Addr[3],pEntry->Addr[4],pEntry->Addr[5]
7200 + ,TID,isForced,pEntry->Aid));
7201 +
7202 + if (!(pEntry->TXBAbitmap & (1<<TID)))
7203 + {
7204 + RTMPInitTimer(pAd, &pBAEntry->ORIBATimer, GET_TIMER_FUNCTION(BAOriSessionSetupTimeout), pBAEntry, FALSE);
7205 + }
7206 + else
7207 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7208 +
7209 + // set timer to send ADDBA request
7210 + RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime);
7211 +}
7212 +
7213 +VOID BAOriSessionAdd(
7214 + IN PRTMP_ADAPTER pAd,
7215 + IN MAC_TABLE_ENTRY *pEntry,
7216 + IN PFRAME_ADDBA_RSP pFrame)
7217 +{
7218 + BA_ORI_ENTRY *pBAEntry = NULL;
7219 + BOOLEAN Cancelled;
7220 + UCHAR TID;
7221 + USHORT Idx;
7222 + PUCHAR pOutBuffer2 = NULL;
7223 + NDIS_STATUS NStatus;
7224 + ULONG FrameLen;
7225 + FRAME_BAR FrameBar;
7226 +
7227 + TID = pFrame->BaParm.TID;
7228 + Idx = pEntry->BAOriWcidArray[TID];
7229 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7230 +
7231 + // Start fill in parameters.
7232 + if ((Idx !=0) && (pBAEntry->TID == TID) && (pBAEntry->ORI_BA_Status == Originator_WaitRes))
7233 + {
7234 + pBAEntry->BAWinSize = min(pBAEntry->BAWinSize, ((UCHAR)pFrame->BaParm.BufSize));
7235 + BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize);
7236 +
7237 + pBAEntry->TimeOutValue = pFrame->TimeOutValue;
7238 + pBAEntry->ORI_BA_Status = Originator_Done;
7239 + // reset sequence number
7240 + pBAEntry->Sequence = BA_ORI_INIT_SEQ;
7241 + // Set Bitmap flag.
7242 + pEntry->TXBAbitmap |= (1<<TID);
7243 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7244 +
7245 + pBAEntry->ORIBATimer.TimerValue = 0; //pFrame->TimeOutValue;
7246 +
7247 + DBGPRINT(RT_DEBUG_TRACE,("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n", __FUNCTION__, pEntry->TXBAbitmap,
7248 + pBAEntry->BAWinSize, pBAEntry->ORIBATimer.TimerValue));
7249 +
7250 + // SEND BAR ;
7251 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory
7252 + if (NStatus != NDIS_STATUS_SUCCESS)
7253 + {
7254 + DBGPRINT(RT_DEBUG_TRACE,("BA - BAOriSessionAdd() allocate memory failed \n"));
7255 + return;
7256 + }
7257 +
7258 +
7259 +#ifdef CONFIG_STA_SUPPORT
7260 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
7261 + BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pBAEntry->Wcid].Addr, pAd->CurrentAddress);
7262 +#endif // CONFIG_STA_SUPPORT //
7263 +
7264 + FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function.
7265 + FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; // make sure sequence not clear in DEL funciton.
7266 + FrameBar.BarControl.TID = pBAEntry->TID; // make sure sequence not clear in DEL funciton.
7267 + MakeOutgoingFrame(pOutBuffer2, &FrameLen,
7268 + sizeof(FRAME_BAR), &FrameBar,
7269 + END_OF_ARGS);
7270 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
7271 + MlmeFreeMemory(pAd, pOutBuffer2);
7272 +
7273 +
7274 + if (pBAEntry->ORIBATimer.TimerValue)
7275 + RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); // in mSec
7276 + }
7277 +}
7278 +
7279 +BOOLEAN BARecSessionAdd(
7280 + IN PRTMP_ADAPTER pAd,
7281 + IN MAC_TABLE_ENTRY *pEntry,
7282 + IN PFRAME_ADDBA_REQ pFrame)
7283 +{
7284 + BA_REC_ENTRY *pBAEntry = NULL;
7285 + BOOLEAN Status = TRUE;
7286 + BOOLEAN Cancelled;
7287 + USHORT Idx;
7288 + UCHAR TID;
7289 + UCHAR BAWinSize;
7290 + //UINT32 Value;
7291 + //UINT offset;
7292 +
7293 +
7294 + ASSERT(pEntry);
7295 +
7296 + // find TID
7297 + TID = pFrame->BaParm.TID;
7298 +
7299 + BAWinSize = min(((UCHAR)pFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
7300 +
7301 + // Intel patch
7302 + if (BAWinSize == 0)
7303 + {
7304 + BAWinSize = 64;
7305 + }
7306 +
7307 + Idx = pEntry->BARecWcidArray[TID];
7308 +
7309 +
7310 + if (Idx == 0)
7311 + {
7312 + pBAEntry = BATableAllocRecEntry(pAd, &Idx);
7313 + }
7314 + else
7315 + {
7316 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
7317 + // flush all pending reordering mpdus
7318 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7319 + }
7320 +
7321 + DBGPRINT(RT_DEBUG_TRACE,("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __FUNCTION__, pAd->BATable.numAsRecipient, Idx,
7322 + pFrame->BaParm.BufSize, BAWinSize));
7323 +
7324 + // Start fill in parameters.
7325 + if (pBAEntry != NULL)
7326 + {
7327 + ASSERT(pBAEntry->list.qlen == 0);
7328 +
7329 + pBAEntry->REC_BA_Status = Recipient_HandleRes;
7330 + pBAEntry->BAWinSize = BAWinSize;
7331 + pBAEntry->Wcid = pEntry->Aid;
7332 + pBAEntry->TID = TID;
7333 + pBAEntry->TimeOutValue = pFrame->TimeOutValue;
7334 + pBAEntry->REC_BA_Status = Recipient_Accept;
7335 + // initial sequence number
7336 + pBAEntry->LastIndSeq = RESET_RCV_SEQ; //pFrame->BaStartSeq.field.StartSeq;
7337 +
7338 + printk("Start Seq = %08x\n", pFrame->BaStartSeq.field.StartSeq);
7339 +
7340 + if (pEntry->RXBAbitmap & (1<<TID))
7341 + {
7342 + RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
7343 + }
7344 + else
7345 + {
7346 + RTMPInitTimer(pAd, &pBAEntry->RECBATimer, GET_TIMER_FUNCTION(BARecSessionIdleTimeout), pBAEntry, TRUE);
7347 + }
7348 +
7349 + // Set Bitmap flag.
7350 + pEntry->RXBAbitmap |= (1<<TID);
7351 + pEntry->BARecWcidArray[TID] = Idx;
7352 +
7353 + pEntry->BADeclineBitmap &= ~(1<<TID);
7354 +
7355 + // Set BA session mask in WCID table.
7356 + RT28XX_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID);
7357 +
7358 + DBGPRINT(RT_DEBUG_TRACE,("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n",
7359 + pEntry->Aid, pEntry->RXBAbitmap, pEntry->BARecWcidArray[TID]));
7360 + }
7361 + else
7362 + {
7363 + Status = FALSE;
7364 + DBGPRINT(RT_DEBUG_TRACE,("Can't Accept ADDBA for %02x:%02x:%02x:%02x:%02x:%02x TID = %d\n",
7365 + PRINT_MAC(pEntry->Addr), TID));
7366 + }
7367 + return(Status);
7368 +}
7369 +
7370 +
7371 +BA_REC_ENTRY *BATableAllocRecEntry(
7372 + IN PRTMP_ADAPTER pAd,
7373 + OUT USHORT *Idx)
7374 +{
7375 + int i;
7376 + BA_REC_ENTRY *pBAEntry = NULL;
7377 +
7378 +
7379 + NdisAcquireSpinLock(&pAd->BATabLock);
7380 +
7381 + if (pAd->BATable.numAsRecipient >= MAX_BARECI_SESSION)
7382 + {
7383 + printk("BA Recipeint Session (%ld) > %d\n", pAd->BATable.numAsRecipient,
7384 + MAX_BARECI_SESSION);
7385 + goto done;
7386 + }
7387 +
7388 + // reserve idx 0 to identify BAWcidArray[TID] as empty
7389 + for (i=1; i < MAX_LEN_OF_BA_REC_TABLE; i++)
7390 + {
7391 + pBAEntry =&pAd->BATable.BARecEntry[i];
7392 + if ((pBAEntry->REC_BA_Status == Recipient_NONE))
7393 + {
7394 + // get one
7395 + pAd->BATable.numAsRecipient++;
7396 + pBAEntry->REC_BA_Status = Recipient_USED;
7397 + *Idx = i;
7398 + break;
7399 + }
7400 + }
7401 +
7402 +done:
7403 + NdisReleaseSpinLock(&pAd->BATabLock);
7404 + return pBAEntry;
7405 +}
7406 +
7407 +BA_ORI_ENTRY *BATableAllocOriEntry(
7408 + IN PRTMP_ADAPTER pAd,
7409 + OUT USHORT *Idx)
7410 +{
7411 + int i;
7412 + BA_ORI_ENTRY *pBAEntry = NULL;
7413 +
7414 + NdisAcquireSpinLock(&pAd->BATabLock);
7415 +
7416 + if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE))
7417 + {
7418 + goto done;
7419 + }
7420 +
7421 + // reserve idx 0 to identify BAWcidArray[TID] as empty
7422 + for (i=1; i<MAX_LEN_OF_BA_ORI_TABLE; i++)
7423 + {
7424 + pBAEntry =&pAd->BATable.BAOriEntry[i];
7425 + if ((pBAEntry->ORI_BA_Status == Originator_NONE))
7426 + {
7427 + // get one
7428 + pAd->BATable.numAsOriginator++;
7429 + pBAEntry->ORI_BA_Status = Originator_USED;
7430 + pBAEntry->pAdapter = pAd;
7431 + *Idx = i;
7432 + break;
7433 + }
7434 + }
7435 +
7436 +done:
7437 + NdisReleaseSpinLock(&pAd->BATabLock);
7438 + return pBAEntry;
7439 +}
7440 +
7441 +
7442 +VOID BATableFreeOriEntry(
7443 + IN PRTMP_ADAPTER pAd,
7444 + IN ULONG Idx)
7445 +{
7446 + BA_ORI_ENTRY *pBAEntry = NULL;
7447 + MAC_TABLE_ENTRY *pEntry;
7448 +
7449 +
7450 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE))
7451 + return;
7452 +
7453 + pBAEntry =&pAd->BATable.BAOriEntry[Idx];
7454 +
7455 + if (pBAEntry->ORI_BA_Status != Originator_NONE)
7456 + {
7457 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7458 + pEntry->BAOriWcidArray[pBAEntry->TID] = 0;
7459 +
7460 +
7461 + NdisAcquireSpinLock(&pAd->BATabLock);
7462 + if (pBAEntry->ORI_BA_Status == Originator_Done)
7463 + {
7464 + pEntry->TXBAbitmap &= (~(1<<(pBAEntry->TID) ));
7465 + DBGPRINT(RT_DEBUG_TRACE, ("BATableFreeOriEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient));
7466 + // Erase Bitmap flag.
7467 + }
7468 +
7469 + ASSERT(pAd->BATable.numAsOriginator != 0);
7470 +
7471 + pAd->BATable.numAsOriginator -= 1;
7472 +
7473 + pBAEntry->ORI_BA_Status = Originator_NONE;
7474 + pBAEntry->Token = 0;
7475 + NdisReleaseSpinLock(&pAd->BATabLock);
7476 + }
7477 +}
7478 +
7479 +
7480 +VOID BATableFreeRecEntry(
7481 + IN PRTMP_ADAPTER pAd,
7482 + IN ULONG Idx)
7483 +{
7484 + BA_REC_ENTRY *pBAEntry = NULL;
7485 + MAC_TABLE_ENTRY *pEntry;
7486 +
7487 +
7488 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE))
7489 + return;
7490 +
7491 + pBAEntry =&pAd->BATable.BARecEntry[Idx];
7492 +
7493 + if (pBAEntry->REC_BA_Status != Recipient_NONE)
7494 + {
7495 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7496 + pEntry->BARecWcidArray[pBAEntry->TID] = 0;
7497 +
7498 + NdisAcquireSpinLock(&pAd->BATabLock);
7499 +
7500 + ASSERT(pAd->BATable.numAsRecipient != 0);
7501 +
7502 + pAd->BATable.numAsRecipient -= 1;
7503 +
7504 + pBAEntry->REC_BA_Status = Recipient_NONE;
7505 + NdisReleaseSpinLock(&pAd->BATabLock);
7506 + }
7507 +}
7508 +
7509 +
7510 +VOID BAOriSessionTearDown(
7511 + IN OUT PRTMP_ADAPTER pAd,
7512 + IN UCHAR Wcid,
7513 + IN UCHAR TID,
7514 + IN BOOLEAN bPassive,
7515 + IN BOOLEAN bForceSend)
7516 +{
7517 + ULONG Idx = 0;
7518 + BA_ORI_ENTRY *pBAEntry;
7519 + BOOLEAN Cancelled;
7520 +
7521 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
7522 + {
7523 + return;
7524 + }
7525 +
7526 + //
7527 + // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID).
7528 + //
7529 + Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID];
7530 + if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE))
7531 + {
7532 + if (bForceSend == TRUE)
7533 + {
7534 + // force send specified TID DelBA
7535 + MLME_DELBA_REQ_STRUCT DelbaReq;
7536 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7537 +
7538 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7539 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7540 +
7541 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7542 + DelbaReq.Wcid = Wcid;
7543 + DelbaReq.TID = TID;
7544 + DelbaReq.Initiator = ORIGINATOR;
7545 +#if 1
7546 + Elem->MsgLen = sizeof(DelbaReq);
7547 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7548 + MlmeDELBAAction(pAd, Elem);
7549 + kfree(Elem);
7550 +#else
7551 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7552 + RT28XX_MLME_HANDLER(pAd);
7553 +#endif
7554 + }
7555 +
7556 + return;
7557 + }
7558 +
7559 + DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID));
7560 +
7561 + pBAEntry = &pAd->BATable.BAOriEntry[Idx];
7562 + DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->ORI_BA_Status));
7563 + //
7564 + // Prepare DelBA action frame and send to the peer.
7565 + //
7566 + if ((bPassive == FALSE) && (TID == pBAEntry->TID) && (pBAEntry->ORI_BA_Status == Originator_Done))
7567 + {
7568 + MLME_DELBA_REQ_STRUCT DelbaReq;
7569 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7570 +
7571 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7572 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7573 +
7574 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7575 + DelbaReq.Wcid = Wcid;
7576 + DelbaReq.TID = pBAEntry->TID;
7577 + DelbaReq.Initiator = ORIGINATOR;
7578 +#if 1
7579 + Elem->MsgLen = sizeof(DelbaReq);
7580 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7581 + MlmeDELBAAction(pAd, Elem);
7582 + kfree(Elem);
7583 +#else
7584 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7585 + RT28XX_MLME_HANDLER(pAd);
7586 +#endif
7587 + }
7588 + RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
7589 + BATableFreeOriEntry(pAd, Idx);
7590 +
7591 + if (bPassive)
7592 + {
7593 + //BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE);
7594 + }
7595 +}
7596 +
7597 +VOID BARecSessionTearDown(
7598 + IN OUT PRTMP_ADAPTER pAd,
7599 + IN UCHAR Wcid,
7600 + IN UCHAR TID,
7601 + IN BOOLEAN bPassive)
7602 +{
7603 + ULONG Idx = 0;
7604 + BA_REC_ENTRY *pBAEntry;
7605 +
7606 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
7607 + {
7608 + return;
7609 + }
7610 +
7611 + //
7612 + // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID).
7613 + //
7614 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
7615 + if (Idx == 0)
7616 + return;
7617 +
7618 + DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID));
7619 +
7620 +
7621 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
7622 + DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->REC_BA_Status));
7623 + //
7624 + // Prepare DelBA action frame and send to the peer.
7625 + //
7626 + if ((TID == pBAEntry->TID) && (pBAEntry->REC_BA_Status == Recipient_Accept))
7627 + {
7628 + MLME_DELBA_REQ_STRUCT DelbaReq;
7629 + BOOLEAN Cancelled;
7630 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
7631 + //ULONG offset;
7632 + //UINT32 VALUE;
7633 +
7634 + RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
7635 +
7636 + //
7637 + // 1. Send DELBA Action Frame
7638 + //
7639 + if (bPassive == FALSE)
7640 + {
7641 + NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
7642 + NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM));
7643 +
7644 + COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr);
7645 + DelbaReq.Wcid = Wcid;
7646 + DelbaReq.TID = TID;
7647 + DelbaReq.Initiator = RECIPIENT;
7648 +#if 1
7649 + Elem->MsgLen = sizeof(DelbaReq);
7650 + NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
7651 + MlmeDELBAAction(pAd, Elem);
7652 + kfree(Elem);
7653 +#else
7654 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq);
7655 + RT28XX_MLME_HANDLER(pAd);
7656 +#endif
7657 + }
7658 +
7659 +
7660 + //
7661 + // 2. Free resource of BA session
7662 + //
7663 + // flush all pending reordering mpdus
7664 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7665 +
7666 + NdisAcquireSpinLock(&pAd->BATabLock);
7667 +
7668 + // Erase Bitmap flag.
7669 + pBAEntry->LastIndSeq = RESET_RCV_SEQ;
7670 + pBAEntry->BAWinSize = 0;
7671 + // Erase Bitmap flag at software mactable
7672 + pAd->MacTab.Content[Wcid].RXBAbitmap &= (~(1<<(pBAEntry->TID)));
7673 + pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0;
7674 +
7675 + RT28XX_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID);
7676 +
7677 + NdisReleaseSpinLock(&pAd->BATabLock);
7678 +
7679 + }
7680 +
7681 + BATableFreeRecEntry(pAd, Idx);
7682 +}
7683 +
7684 +VOID BASessionTearDownALL(
7685 + IN OUT PRTMP_ADAPTER pAd,
7686 + IN UCHAR Wcid)
7687 +{
7688 + int i;
7689 +
7690 + for (i=0; i<NUM_OF_TID; i++)
7691 + {
7692 + BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE);
7693 + BARecSessionTearDown(pAd, Wcid, i, FALSE);
7694 + }
7695 +}
7696 +
7697 +
7698 +/*
7699 + ==========================================================================
7700 + Description:
7701 + Retry sending ADDBA Reqest.
7702 +
7703 + IRQL = DISPATCH_LEVEL
7704 +
7705 + Parametrs:
7706 + p8023Header: if this is already 802.3 format, p8023Header is NULL
7707 +
7708 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
7709 + FALSE , then continue indicaterx at this moment.
7710 + ==========================================================================
7711 + */
7712 +VOID BAOriSessionSetupTimeout(
7713 + IN PVOID SystemSpecific1,
7714 + IN PVOID FunctionContext,
7715 + IN PVOID SystemSpecific2,
7716 + IN PVOID SystemSpecific3)
7717 +{
7718 + BA_ORI_ENTRY *pBAEntry = (BA_ORI_ENTRY *)FunctionContext;
7719 + MAC_TABLE_ENTRY *pEntry;
7720 + PRTMP_ADAPTER pAd;
7721 +
7722 + if (pBAEntry == NULL)
7723 + return;
7724 +
7725 + pAd = pBAEntry->pAdapter;
7726 +
7727 +#ifdef CONFIG_STA_SUPPORT
7728 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
7729 + {
7730 + // Do nothing if monitor mode is on
7731 + if (MONITOR_ON(pAd))
7732 + return;
7733 + }
7734 +#endif // CONFIG_STA_SUPPORT //
7735 +
7736 +#ifdef RALINK_ATE
7737 + // Nothing to do in ATE mode.
7738 + if (ATE_ON(pAd))
7739 + return;
7740 +#endif // RALINK_ATE //
7741 +
7742 + pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
7743 +
7744 + if ((pBAEntry->ORI_BA_Status == Originator_WaitRes) && (pBAEntry->Token < ORI_SESSION_MAX_RETRY))
7745 + {
7746 + MLME_ADDBA_REQ_STRUCT AddbaReq;
7747 +
7748 + NdisZeroMemory(&AddbaReq, sizeof(AddbaReq));
7749 + COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr);
7750 + AddbaReq.Wcid = (UCHAR)(pEntry->Aid);
7751 + AddbaReq.TID = pBAEntry->TID;
7752 + AddbaReq.BaBufSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit;
7753 + AddbaReq.TimeOutValue = 0;
7754 + AddbaReq.Token = pBAEntry->Token;
7755 + MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE, sizeof(MLME_ADDBA_REQ_STRUCT), (PVOID)&AddbaReq);
7756 + RT28XX_MLME_HANDLER(pAd);
7757 + //DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) : Send ADD BA again\n", pBAEntry->Token));
7758 +
7759 + DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) to %02x:%02x:%02x:%02x:%02x:%02x Tid:%d Wcid:%d\n"
7760 + ,pBAEntry->Token
7761 + ,pEntry->Addr[0],pEntry->Addr[1],pEntry->Addr[2]
7762 + ,pEntry->Addr[3],pEntry->Addr[4],pEntry->Addr[5]
7763 + ,pBAEntry->TID,pEntry->Aid));
7764 +
7765 + pBAEntry->Token++;
7766 + RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT);
7767 + }
7768 + else
7769 + {
7770 + BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]);
7771 + }
7772 +}
7773 +
7774 +/*
7775 + ==========================================================================
7776 + Description:
7777 + Retry sending ADDBA Reqest.
7778 +
7779 + IRQL = DISPATCH_LEVEL
7780 +
7781 + Parametrs:
7782 + p8023Header: if this is already 802.3 format, p8023Header is NULL
7783 +
7784 + Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
7785 + FALSE , then continue indicaterx at this moment.
7786 + ==========================================================================
7787 + */
7788 +VOID BARecSessionIdleTimeout(
7789 + IN PVOID SystemSpecific1,
7790 + IN PVOID FunctionContext,
7791 + IN PVOID SystemSpecific2,
7792 + IN PVOID SystemSpecific3)
7793 +{
7794 +
7795 + BA_REC_ENTRY *pBAEntry = (BA_REC_ENTRY *)FunctionContext;
7796 + PRTMP_ADAPTER pAd;
7797 + ULONG Now32;
7798 +
7799 + if (pBAEntry == NULL)
7800 + return;
7801 +
7802 + if ((pBAEntry->REC_BA_Status == Recipient_Accept))
7803 + {
7804 + NdisGetSystemUpTime(&Now32);
7805 +
7806 + if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer + REC_BA_SESSION_IDLE_TIMEOUT)))
7807 + {
7808 + pAd = pBAEntry->pAdapter;
7809 + // flush all pending reordering mpdus
7810 + ba_refresh_reordering_mpdus(pAd, pBAEntry);
7811 + printk("%ld: REC BA session Timeout\n", Now32);
7812 + }
7813 + }
7814 +}
7815 +
7816 +
7817 +VOID PeerAddBAReqAction(
7818 + IN PRTMP_ADAPTER pAd,
7819 + IN MLME_QUEUE_ELEM *Elem)
7820 +
7821 +{
7822 + // 7.4.4.1
7823 + //ULONG Idx;
7824 + UCHAR Status = 1;
7825 + UCHAR pAddr[6];
7826 + FRAME_ADDBA_RSP ADDframe;
7827 + PUCHAR pOutBuffer = NULL;
7828 + NDIS_STATUS NStatus;
7829 + PFRAME_ADDBA_REQ pAddreqFrame = NULL;
7830 + //UCHAR BufSize;
7831 + ULONG FrameLen;
7832 + PULONG ptemp;
7833 + PMAC_TABLE_ENTRY pMacEntry;
7834 +
7835 + DBGPRINT(RT_DEBUG_TRACE, ("%s ==> (Wcid = %d)\n", __FUNCTION__, Elem->Wcid));
7836 +
7837 + //hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen);
7838 +
7839 + //ADDBA Request from unknown peer, ignore this.
7840 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
7841 + return;
7842 +
7843 + pMacEntry = &pAd->MacTab.Content[Elem->Wcid];
7844 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerAddBAReqAction----> \n"));
7845 + ptemp = (PULONG)Elem->Msg;
7846 + //DBGPRINT_RAW(RT_DEBUG_EMU, ("%08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x\n", *(ptemp), *(ptemp+1), *(ptemp+2), *(ptemp+3), *(ptemp+4), *(ptemp+5), *(ptemp+6), *(ptemp+7), *(ptemp+8)));
7847 +
7848 + if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr))
7849 + {
7850 +
7851 + if ((pAd->CommonCfg.bBADecline == FALSE) && IS_HT_STA(pMacEntry))
7852 + {
7853 + pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]);
7854 + printk("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid);
7855 + if (BARecSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pAddreqFrame))
7856 + Status = 0;
7857 + else
7858 + Status = 38; // more parameters have invalid values
7859 + }
7860 + else
7861 + {
7862 + Status = 37; // the request has been declined.
7863 + }
7864 + }
7865 +
7866 + if (pAd->MacTab.Content[Elem->Wcid].ValidAsCLI)
7867 + ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC);
7868 +
7869 + pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]);
7870 + // 2. Always send back ADDBA Response
7871 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
7872 + if (NStatus != NDIS_STATUS_SUCCESS)
7873 + {
7874 + DBGPRINT(RT_DEBUG_TRACE,("ACTION - PeerBAAction() allocate memory failed \n"));
7875 + return;
7876 + }
7877 +
7878 + NdisZeroMemory(&ADDframe, sizeof(FRAME_ADDBA_RSP));
7879 + // 2-1. Prepare ADDBA Response frame.
7880 +#ifdef CONFIG_STA_SUPPORT
7881 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
7882 + {
7883 + if (ADHOC_ON(pAd))
7884 + ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
7885 + else
7886 + ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr);
7887 + }
7888 +#endif // CONFIG_STA_SUPPORT //
7889 + ADDframe.Category = CATEGORY_BA;
7890 + ADDframe.Action = ADDBA_RESP;
7891 + ADDframe.Token = pAddreqFrame->Token;
7892 + // What is the Status code?? need to check.
7893 + ADDframe.StatusCode = Status;
7894 + ADDframe.BaParm.BAPolicy = IMMED_BA;
7895 + ADDframe.BaParm.AMSDUSupported = 0;
7896 + ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID;
7897 + ADDframe.BaParm.BufSize = min(((UCHAR)pAddreqFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
7898 + if (ADDframe.BaParm.BufSize == 0)
7899 + {
7900 + ADDframe.BaParm.BufSize = 64;
7901 + }
7902 + ADDframe.TimeOutValue = 0; //pAddreqFrame->TimeOutValue;
7903 +
7904 + *(USHORT *)(&ADDframe.BaParm) = cpu2le16(*(USHORT *)(&ADDframe.BaParm));
7905 + ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode);
7906 + ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue);
7907 +
7908 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
7909 + sizeof(FRAME_ADDBA_RSP), &ADDframe,
7910 + END_OF_ARGS);
7911 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
7912 + MlmeFreeMemory(pAd, pOutBuffer);
7913 +
7914 + DBGPRINT(RT_DEBUG_TRACE, ("%s(%d): TID(%d), BufSize(%d) <== \n", __FUNCTION__, Elem->Wcid, ADDframe.BaParm.TID,
7915 + ADDframe.BaParm.BufSize));
7916 +}
7917 +
7918 +
7919 +VOID PeerAddBARspAction(
7920 + IN PRTMP_ADAPTER pAd,
7921 + IN MLME_QUEUE_ELEM *Elem)
7922 +
7923 +{
7924 + //UCHAR Idx, i;
7925 + //PUCHAR pOutBuffer = NULL;
7926 + PFRAME_ADDBA_RSP pFrame = NULL;
7927 + //PBA_ORI_ENTRY pBAEntry;
7928 +
7929 + //ADDBA Response from unknown peer, ignore this.
7930 + if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
7931 + return;
7932 +
7933 + DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __FUNCTION__, Elem->Wcid));
7934 +
7935 + //hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen);
7936 +
7937 + if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen))
7938 + {
7939 + pFrame = (PFRAME_ADDBA_RSP)(&Elem->Msg[0]);
7940 +
7941 + DBGPRINT(RT_DEBUG_TRACE, ("\t\t StatusCode = %d\n", pFrame->StatusCode));
7942 + switch (pFrame->StatusCode)
7943 + {
7944 + case 0:
7945 + // I want a BAsession with this peer as an originator.
7946 + BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pFrame);
7947 + break;
7948 + default:
7949 + // check status == USED ???
7950 + BAOriSessionTearDown(pAd, Elem->Wcid, pFrame->BaParm.TID, TRUE, FALSE);
7951 + break;
7952 + }
7953 + // Rcv Decline StatusCode
7954 + if ((pFrame->StatusCode == 37)
7955 +#ifdef CONFIG_STA_SUPPORT
7956 + || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd) && (pFrame->StatusCode != 0))
7957 +#endif // CONFIG_STA_SUPPORT //
7958 + )
7959 + {
7960 + pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |= 1<<pFrame->BaParm.TID;
7961 + }
7962 + }
7963 +}
7964 +
7965 +VOID PeerDelBAAction(
7966 + IN PRTMP_ADAPTER pAd,
7967 + IN MLME_QUEUE_ELEM *Elem)
7968 +
7969 +{
7970 + //UCHAR Idx;
7971 + //PUCHAR pOutBuffer = NULL;
7972 + PFRAME_DELBA_REQ pDelFrame = NULL;
7973 +
7974 + DBGPRINT(RT_DEBUG_TRACE,("%s ==>\n", __FUNCTION__));
7975 + //DELBA Request from unknown peer, ignore this.
7976 + if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen))
7977 + {
7978 + pDelFrame = (PFRAME_DELBA_REQ)(&Elem->Msg[0]);
7979 + if (pDelFrame->DelbaParm.Initiator == ORIGINATOR)
7980 + {
7981 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> ORIGINATOR\n"));
7982 + BARecSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE);
7983 + }
7984 + else
7985 + {
7986 + DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n", pDelFrame->ReasonCode));
7987 + //hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen);
7988 + BAOriSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE, FALSE);
7989 + }
7990 + }
7991 +}
7992 +
7993 +
7994 +BOOLEAN CntlEnqueueForRecv(
7995 + IN PRTMP_ADAPTER pAd,
7996 + IN ULONG Wcid,
7997 + IN ULONG MsgLen,
7998 + IN PFRAME_BA_REQ pMsg)
7999 +{
8000 + PFRAME_BA_REQ pFrame = pMsg;
8001 + //PRTMP_REORDERBUF pBuffer;
8002 + //PRTMP_REORDERBUF pDmaBuf;
8003 + PBA_REC_ENTRY pBAEntry;
8004 + //BOOLEAN Result;
8005 + ULONG Idx;
8006 + //UCHAR NumRxPkt;
8007 + UCHAR TID;//, i;
8008 +
8009 + TID = (UCHAR)pFrame->BARControl.TID;
8010 +
8011 + DBGPRINT(RT_DEBUG_TRACE, ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __FUNCTION__, Wcid, TID));
8012 + //hex_dump("BAR", (PCHAR) pFrame, MsgLen);
8013 + // Do nothing if the driver is starting halt state.
8014 + // This might happen when timer already been fired before cancel timer with mlmehalt
8015 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
8016 + return FALSE;
8017 +
8018 + // First check the size, it MUST not exceed the mlme queue size
8019 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
8020 + {
8021 + DBGPRINT_ERR(("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen));
8022 + return FALSE;
8023 + }
8024 + else if (MsgLen != sizeof(FRAME_BA_REQ))
8025 + {
8026 + DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen));
8027 + return FALSE;
8028 + }
8029 + else if (MsgLen != sizeof(FRAME_BA_REQ))
8030 + {
8031 + DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen));
8032 + return FALSE;
8033 + }
8034 +
8035 + if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8))
8036 + {
8037 + // if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search.
8038 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
8039 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
8040 + }
8041 + else
8042 + {
8043 + return FALSE;
8044 + }
8045 +
8046 + DBGPRINT(RT_DEBUG_TRACE, ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID, pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq ));
8047 +
8048 + if (SEQ_SMALLER(pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq, MAXSEQ))
8049 + {
8050 + //printk("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq);
8051 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, pFrame->BAStartingSeq.field.StartSeq);
8052 + pBAEntry->LastIndSeq = (pFrame->BAStartingSeq.field.StartSeq == 0) ? MAXSEQ :(pFrame->BAStartingSeq.field.StartSeq -1);
8053 + }
8054 + //ba_refresh_reordering_mpdus(pAd, pBAEntry);
8055 + return TRUE;
8056 +}
8057 +
8058 +/*
8059 +Description : Send PSMP Action frame If PSMP mode switches.
8060 +*/
8061 +VOID SendPSMPAction(
8062 + IN PRTMP_ADAPTER pAd,
8063 + IN UCHAR Wcid,
8064 + IN UCHAR Psmp)
8065 +{
8066 + PUCHAR pOutBuffer = NULL;
8067 + NDIS_STATUS NStatus;
8068 + //ULONG Idx;
8069 + FRAME_PSMP_ACTION Frame;
8070 + ULONG FrameLen;
8071 +#ifdef RT30xx
8072 + UCHAR bbpdata=0;
8073 + UINT32 macdata;
8074 +#endif // RT30xx //
8075 +
8076 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
8077 + if (NStatus != NDIS_STATUS_SUCCESS)
8078 + {
8079 + DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n"));
8080 + return;
8081 + }
8082 +#ifdef CONFIG_STA_SUPPORT
8083 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8084 + ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr);
8085 +#endif // CONFIG_STA_SUPPORT //
8086 +
8087 + Frame.Category = CATEGORY_HT;
8088 + Frame.Action = SMPS_ACTION;
8089 + switch (Psmp)
8090 + {
8091 + case MMPS_ENABLE:
8092 +#ifdef RT30xx
8093 + if (IS_RT3090(pAd))
8094 + {
8095 + // disable MMPS BBP control register
8096 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata);
8097 + bbpdata &= ~(0x04); //bit 2
8098 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata);
8099 +
8100 + // disable MMPS MAC control register
8101 + RTMP_IO_READ32(pAd, 0x1210, &macdata);
8102 + macdata &= ~(0x09); //bit 0, 3
8103 + RTMP_IO_WRITE32(pAd, 0x1210, macdata);
8104 + }
8105 +#endif // RT30xx //
8106 + Frame.Psmp = 0;
8107 + break;
8108 + case MMPS_DYNAMIC:
8109 +#ifdef RT30xx
8110 + if (IS_RT3090(pAd))
8111 + {
8112 + // enable MMPS BBP control register
8113 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata);
8114 + bbpdata |= 0x04; //bit 2
8115 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata);
8116 +
8117 + // enable MMPS MAC control register
8118 + RTMP_IO_READ32(pAd, 0x1210, &macdata);
8119 + macdata |= 0x09; //bit 0, 3
8120 + RTMP_IO_WRITE32(pAd, 0x1210, macdata);
8121 + }
8122 +#endif // RT30xx //
8123 + Frame.Psmp = 3;
8124 + break;
8125 + case MMPS_STATIC:
8126 +#ifdef RT30xx
8127 + if (IS_RT3090(pAd))
8128 + {
8129 + // enable MMPS BBP control register
8130 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata);
8131 + bbpdata |= 0x04; //bit 2
8132 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata);
8133 +
8134 + // enable MMPS MAC control register
8135 + RTMP_IO_READ32(pAd, 0x1210, &macdata);
8136 + macdata |= 0x09; //bit 0, 3
8137 + RTMP_IO_WRITE32(pAd, 0x1210, macdata);
8138 + }
8139 +#endif // RT30xx //
8140 + Frame.Psmp = 1;
8141 + break;
8142 + }
8143 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
8144 + sizeof(FRAME_PSMP_ACTION), &Frame,
8145 + END_OF_ARGS);
8146 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
8147 + MlmeFreeMemory(pAd, pOutBuffer);
8148 + DBGPRINT(RT_DEBUG_ERROR,("HT - SendPSMPAction( %d ) \n", Frame.Psmp));
8149 +}
8150 +
8151 +
8152 +#define RADIO_MEASUREMENT_REQUEST_ACTION 0
8153 +
8154 +typedef struct PACKED
8155 +{
8156 + UCHAR RegulatoryClass;
8157 + UCHAR ChannelNumber;
8158 + USHORT RandomInterval;
8159 + USHORT MeasurementDuration;
8160 + UCHAR MeasurementMode;
8161 + UCHAR BSSID[MAC_ADDR_LEN];
8162 + UCHAR ReportingCondition;
8163 + UCHAR Threshold;
8164 + UCHAR SSIDIE[2]; // 2 byte
8165 +} BEACON_REQUEST;
8166 +
8167 +typedef struct PACKED
8168 +{
8169 + UCHAR ID;
8170 + UCHAR Length;
8171 + UCHAR Token;
8172 + UCHAR RequestMode;
8173 + UCHAR Type;
8174 +} MEASUREMENT_REQ;
8175 +
8176 +
8177 +
8178 +
8179 +void convert_reordering_packet_to_preAMSDU_or_802_3_packet(
8180 + IN PRTMP_ADAPTER pAd,
8181 + IN RX_BLK *pRxBlk,
8182 + IN UCHAR FromWhichBSSID)
8183 +{
8184 + PNDIS_PACKET pRxPkt;
8185 + UCHAR Header802_3[LENGTH_802_3];
8186 +
8187 + // 1. get 802.3 Header
8188 + // 2. remove LLC
8189 + // a. pointer pRxBlk->pData to payload
8190 + // b. modify pRxBlk->DataSize
8191 +
8192 +#ifdef CONFIG_STA_SUPPORT
8193 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8194 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
8195 +#endif // CONFIG_STA_SUPPORT //
8196 +
8197 + ASSERT(pRxBlk->pRxPacket);
8198 + pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
8199 +
8200 + RTPKT_TO_OSPKT(pRxPkt)->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
8201 + RTPKT_TO_OSPKT(pRxPkt)->data = pRxBlk->pData;
8202 + RTPKT_TO_OSPKT(pRxPkt)->len = pRxBlk->DataSize;
8203 + RTPKT_TO_OSPKT(pRxPkt)->tail = RTPKT_TO_OSPKT(pRxPkt)->data + RTPKT_TO_OSPKT(pRxPkt)->len;
8204 +
8205 + //
8206 + // copy 802.3 header, if necessary
8207 + //
8208 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU))
8209 + {
8210 +
8211 +#ifdef CONFIG_STA_SUPPORT
8212 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8213 + {
8214 +#ifdef LINUX
8215 + NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3);
8216 +#endif
8217 +#ifdef UCOS
8218 + NdisMoveMemory(net_pkt_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3);
8219 +#endif
8220 + }
8221 +#endif // CONFIG_STA_SUPPORT //
8222 + }
8223 +}
8224 +
8225 +
8226 +#define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \
8227 + do \
8228 + { \
8229 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \
8230 + { \
8231 + Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8232 + } \
8233 + else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \
8234 + { \
8235 + Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8236 + } \
8237 + else \
8238 + { \
8239 + Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
8240 + } \
8241 + } while (0);
8242 +
8243 +
8244 +
8245 +static VOID ba_enqueue_reordering_packet(
8246 + IN PRTMP_ADAPTER pAd,
8247 + IN PBA_REC_ENTRY pBAEntry,
8248 + IN RX_BLK *pRxBlk,
8249 + IN UCHAR FromWhichBSSID)
8250 +{
8251 + struct reordering_mpdu *mpdu_blk;
8252 + UINT16 Sequence = (UINT16) pRxBlk->pHeader->Sequence;
8253 +
8254 + mpdu_blk = ba_mpdu_blk_alloc(pAd);
8255 + if (mpdu_blk != NULL)
8256 + {
8257 + // Write RxD buffer address & allocated buffer length
8258 + NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
8259 +
8260 + mpdu_blk->Sequence = Sequence;
8261 +
8262 + mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU);
8263 +
8264 + convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd, pRxBlk, FromWhichBSSID);
8265 +
8266 + STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
8267 +
8268 + //
8269 + // it is necessary for reordering packet to record
8270 + // which BSS it come from
8271 + //
8272 + RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
8273 +
8274 + mpdu_blk->pPacket = pRxBlk->pRxPacket;
8275 +
8276 + if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk) == FALSE)
8277 + {
8278 + // had been already within reordering list
8279 + // don't indicate
8280 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_SUCCESS);
8281 + ba_mpdu_blk_free(pAd, mpdu_blk);
8282 + }
8283 +
8284 + ASSERT((0<= pBAEntry->list.qlen) && (pBAEntry->list.qlen <= pBAEntry->BAWinSize));
8285 + NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
8286 + }
8287 + else
8288 + {
8289 + DBGPRINT(RT_DEBUG_ERROR, ("!!! (%d) Can't allocate reordering mpdu blk\n",
8290 + pBAEntry->list.qlen));
8291 + /*
8292 + * flush all pending reordering mpdus
8293 + * and receving mpdu to upper layer
8294 + * make tcp/ip to take care reordering mechanism
8295 + */
8296 + //ba_refresh_reordering_mpdus(pAd, pBAEntry);
8297 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
8298 +
8299 + pBAEntry->LastIndSeq = Sequence;
8300 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8301 + }
8302 +}
8303 +
8304 +
8305 +/*
8306 + ==========================================================================
8307 + Description:
8308 + Indicate this packet to upper layer or put it into reordering buffer
8309 +
8310 + Parametrs:
8311 + pRxBlk : carry necessary packet info 802.11 format
8312 + FromWhichBSSID : the packet received from which BSS
8313 +
8314 + Return :
8315 + none
8316 +
8317 + Note :
8318 + the packet queued into reordering buffer need to cover to 802.3 format
8319 + or pre_AMSDU format
8320 + ==========================================================================
8321 + */
8322 +
8323 +VOID Indicate_AMPDU_Packet(
8324 + IN PRTMP_ADAPTER pAd,
8325 + IN RX_BLK *pRxBlk,
8326 + IN UCHAR FromWhichBSSID)
8327 +{
8328 + USHORT Idx;
8329 + PBA_REC_ENTRY pBAEntry = NULL;
8330 + UINT16 Sequence = pRxBlk->pHeader->Sequence;
8331 + ULONG Now32;
8332 + UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID;
8333 + UCHAR TID = pRxBlk->pRxWI->TID;
8334 +
8335 +
8336 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU) && (pRxBlk->DataSize > MAX_RX_PKT_LEN))
8337 + {
8338 + // release packet
8339 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8340 + return;
8341 + }
8342 +
8343 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
8344 + {
8345 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
8346 + if (Idx == 0)
8347 + {
8348 + /* Rec BA Session had been torn down */
8349 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8350 + return;
8351 + }
8352 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
8353 + }
8354 + else
8355 + {
8356 + // impossible !!!
8357 + ASSERT(0);
8358 + // release packet
8359 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8360 + return;
8361 + }
8362 +
8363 + ASSERT(pBAEntry);
8364 +
8365 + // update last rx time
8366 + NdisGetSystemUpTime(&Now32);
8367 +
8368 + pBAEntry->rcvSeq = Sequence;
8369 +
8370 +
8371 + ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32);
8372 + pBAEntry->LastIndSeqAtTimer = Now32;
8373 +
8374 + //
8375 + // Reset Last Indicate Sequence
8376 + //
8377 + if (pBAEntry->LastIndSeq == RESET_RCV_SEQ)
8378 + {
8379 + ASSERT((pBAEntry->list.qlen == 0) && (pBAEntry->list.next == NULL));
8380 +
8381 + // reset rcv sequence of BA session
8382 + pBAEntry->LastIndSeq = Sequence;
8383 + pBAEntry->LastIndSeqAtTimer = Now32;
8384 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8385 + return;
8386 + }
8387 +
8388 +
8389 + //
8390 + // I. Check if in order.
8391 + //
8392 + if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ))
8393 + {
8394 + USHORT LastIndSeq;
8395 +
8396 + pBAEntry->LastIndSeq = Sequence;
8397 + INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
8398 + LastIndSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq);
8399 + if (LastIndSeq != RESET_RCV_SEQ)
8400 + {
8401 + pBAEntry->LastIndSeq = LastIndSeq;
8402 + }
8403 + pBAEntry->LastIndSeqAtTimer = Now32;
8404 + }
8405 + //
8406 + // II. Drop Duplicated Packet
8407 + //
8408 + else if (Sequence == pBAEntry->LastIndSeq)
8409 + {
8410 +
8411 + // drop and release packet
8412 + pBAEntry->nDropPacket++;
8413 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8414 + }
8415 + //
8416 + // III. Drop Old Received Packet
8417 + //
8418 + else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ))
8419 + {
8420 +
8421 + // drop and release packet
8422 + pBAEntry->nDropPacket++;
8423 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
8424 + }
8425 + //
8426 + // IV. Receive Sequence within Window Size
8427 + //
8428 + else if (SEQ_SMALLER(Sequence, (((pBAEntry->LastIndSeq+pBAEntry->BAWinSize+1)) & MAXSEQ), MAXSEQ))
8429 + {
8430 + ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID);
8431 + }
8432 + //
8433 + // V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer
8434 + //
8435 + else
8436 + {
8437 + LONG WinStartSeq, TmpSeq;
8438 +
8439 +
8440 + TmpSeq = Sequence - (pBAEntry->BAWinSize) -1;
8441 + if (TmpSeq < 0)
8442 + {
8443 + TmpSeq = (MAXSEQ+1) + TmpSeq;
8444 + }
8445 + WinStartSeq = (TmpSeq+1) & MAXSEQ;
8446 + ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq);
8447 + pBAEntry->LastIndSeq = WinStartSeq; //TmpSeq;
8448 +
8449 + pBAEntry->LastIndSeqAtTimer = Now32;
8450 +
8451 + ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID);
8452 +
8453 + TmpSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq);
8454 + if (TmpSeq != RESET_RCV_SEQ)
8455 + {
8456 + pBAEntry->LastIndSeq = TmpSeq;
8457 + }
8458 + }
8459 +}
8460 +
8461 +#endif // DOT11_N_SUPPORT //
8462 +
8463 --- /dev/null
8464 +++ b/drivers/staging/rt3070/common/cmm_data_2870.c
8465 @@ -0,0 +1,980 @@
8466 +/*
8467 + *************************************************************************
8468 + * Ralink Tech Inc.
8469 + * 5F., No.36, Taiyuan St., Jhubei City,
8470 + * Hsinchu County 302,
8471 + * Taiwan, R.O.C.
8472 + *
8473 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
8474 + *
8475 + * This program is free software; you can redistribute it and/or modify *
8476 + * it under the terms of the GNU General Public License as published by *
8477 + * the Free Software Foundation; either version 2 of the License, or *
8478 + * (at your option) any later version. *
8479 + * *
8480 + * This program is distributed in the hope that it will be useful, *
8481 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
8482 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
8483 + * GNU General Public License for more details. *
8484 + * *
8485 + * You should have received a copy of the GNU General Public License *
8486 + * along with this program; if not, write to the *
8487 + * Free Software Foundation, Inc., *
8488 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
8489 + * *
8490 + *************************************************************************
8491 +*/
8492 +/*
8493 + All functions in this file must be USB-depended, or you should out your function
8494 + in other files.
8495 +
8496 +*/
8497 +#include "../rt_config.h"
8498 +
8499 +
8500 +/*
8501 + We can do copy the frame into pTxContext when match following conditions.
8502 + =>
8503 + =>
8504 + =>
8505 +*/
8506 +static inline NDIS_STATUS RtmpUSBCanDoWrite(
8507 + IN RTMP_ADAPTER *pAd,
8508 + IN UCHAR QueIdx,
8509 + IN HT_TX_CONTEXT *pHTTXContext)
8510 +{
8511 + NDIS_STATUS canWrite = NDIS_STATUS_RESOURCES;
8512 +
8513 + if (((pHTTXContext->CurWritePosition) < pHTTXContext->NextBulkOutPosition) && (pHTTXContext->CurWritePosition + LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition)
8514 + {
8515 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c1!\n"));
8516 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
8517 + }
8518 + else if ((pHTTXContext->CurWritePosition == 8) && (pHTTXContext->NextBulkOutPosition < LOCAL_TXBUF_SIZE))
8519 + {
8520 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c2!\n"));
8521 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
8522 + }
8523 + else if (pHTTXContext->bCurWriting == TRUE)
8524 + {
8525 + DBGPRINT(RT_DEBUG_ERROR,("RtmpUSBCanDoWrite c3!\n"));
8526 + }
8527 + else
8528 + {
8529 + canWrite = NDIS_STATUS_SUCCESS;
8530 + }
8531 +
8532 +
8533 + return canWrite;
8534 +}
8535 +
8536 +
8537 +USHORT RtmpUSB_WriteSubTxResource(
8538 + IN PRTMP_ADAPTER pAd,
8539 + IN TX_BLK *pTxBlk,
8540 + IN BOOLEAN bIsLast,
8541 + OUT USHORT *FreeNumber)
8542 +{
8543 +
8544 + // Dummy function. Should be removed in the future.
8545 + return 0;
8546 +
8547 +}
8548 +
8549 +USHORT RtmpUSB_WriteFragTxResource(
8550 + IN PRTMP_ADAPTER pAd,
8551 + IN TX_BLK *pTxBlk,
8552 + IN UCHAR fragNum,
8553 + OUT USHORT *FreeNumber)
8554 +{
8555 + HT_TX_CONTEXT *pHTTXContext;
8556 + USHORT hwHdrLen; // The hwHdrLen consist of 802.11 header length plus the header padding length.
8557 + UINT32 fillOffset;
8558 + TXINFO_STRUC *pTxInfo;
8559 + TXWI_STRUC *pTxWI;
8560 + PUCHAR pWirelessPacket = NULL;
8561 + UCHAR QueIdx;
8562 + NDIS_STATUS Status;
8563 + unsigned long IrqFlags;
8564 + UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8565 + BOOLEAN TxQLastRound = FALSE;
8566 +
8567 + //
8568 + // get Tx Ring Resource & Dma Buffer address
8569 + //
8570 + QueIdx = pTxBlk->QueIdx;
8571 + pHTTXContext = &pAd->TxContext[QueIdx];
8572 +
8573 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8574 +
8575 + pHTTXContext = &pAd->TxContext[QueIdx];
8576 + fillOffset = pHTTXContext->CurWritePosition;
8577 +
8578 + if(fragNum == 0)
8579 + {
8580 + // Check if we have enough space for this bulk-out batch.
8581 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8582 + if (Status == NDIS_STATUS_SUCCESS)
8583 + {
8584 + pHTTXContext->bCurWriting = TRUE;
8585 +
8586 + // Reserve space for 8 bytes padding.
8587 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8588 + {
8589 + pHTTXContext->ENextBulkOutPosition += 8;
8590 + pHTTXContext->CurWritePosition += 8;
8591 + fillOffset += 8;
8592 + }
8593 + pTxBlk->Priv = 0;
8594 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8595 + }
8596 + else
8597 + {
8598 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8599 +
8600 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
8601 + return(Status);
8602 + }
8603 + }
8604 + else
8605 + {
8606 + // For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer.
8607 + Status = ((pHTTXContext->bCurWriting == TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
8608 + if (Status == NDIS_STATUS_SUCCESS)
8609 + {
8610 + fillOffset += pTxBlk->Priv;
8611 + }
8612 + else
8613 + {
8614 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8615 +
8616 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
8617 + return(Status);
8618 + }
8619 + }
8620 +
8621 + NdisZeroMemory((PUCHAR)(&pTxBlk->HeaderBuf[0]), TXINFO_SIZE);
8622 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8623 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8624 +
8625 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8626 +
8627 + // copy TXWI + WLAN Header + LLC into DMA Header Buffer
8628 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8629 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8630 +
8631 + // Build our URB for USBD
8632 + DMAHdrLen = TXWI_SIZE + hwHdrLen;
8633 + USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
8634 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
8635 + USBDMApktLen += padding;
8636 +
8637 + pTxBlk->Priv += (TXINFO_SIZE + USBDMApktLen);
8638 +
8639 + // For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload
8640 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(USBDMApktLen), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8641 +
8642 + if (fragNum == pTxBlk->TotalFragNum)
8643 + {
8644 + pTxInfo->USBDMATxburst = 0;
8645 + if ((pHTTXContext->CurWritePosition + pTxBlk->Priv + 3906)> MAX_TXBULK_LIMIT)
8646 + {
8647 + pTxInfo->SwUseLastRound = 1;
8648 + TxQLastRound = TRUE;
8649 + }
8650 + }
8651 + else
8652 + {
8653 + pTxInfo->USBDMATxburst = 1;
8654 + }
8655 +
8656 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8657 +#ifdef RT_BIG_ENDIAN
8658 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket + TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
8659 +#endif // RT_BIG_ENDIAN //
8660 + pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8661 + pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8662 +
8663 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8664 +
8665 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
8666 +
8667 + // Zero the last padding.
8668 + pWirelessPacket += pTxBlk->SrcBufLen;
8669 + NdisZeroMemory(pWirelessPacket, padding + 8);
8670 +
8671 + if (fragNum == pTxBlk->TotalFragNum)
8672 + {
8673 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8674 +
8675 + // Update the pHTTXContext->CurWritePosition. 3906 used to prevent the NextBulkOut is a A-RALINK/A-MSDU Frame.
8676 + pHTTXContext->CurWritePosition += pTxBlk->Priv;
8677 + if (TxQLastRound == TRUE)
8678 + pHTTXContext->CurWritePosition = 8;
8679 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8680 +
8681 +
8682 + // Finally, set bCurWriting as FALSE
8683 + pHTTXContext->bCurWriting = FALSE;
8684 +
8685 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8686 +
8687 + // succeed and release the skb buffer
8688 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
8689 + }
8690 +
8691 +
8692 + return(Status);
8693 +
8694 +}
8695 +
8696 +
8697 +USHORT RtmpUSB_WriteSingleTxResource(
8698 + IN PRTMP_ADAPTER pAd,
8699 + IN TX_BLK *pTxBlk,
8700 + IN BOOLEAN bIsLast,
8701 + OUT USHORT *FreeNumber)
8702 +{
8703 + HT_TX_CONTEXT *pHTTXContext;
8704 + USHORT hwHdrLen;
8705 + UINT32 fillOffset;
8706 + TXINFO_STRUC *pTxInfo;
8707 + TXWI_STRUC *pTxWI;
8708 + PUCHAR pWirelessPacket;
8709 + UCHAR QueIdx;
8710 + unsigned long IrqFlags;
8711 + NDIS_STATUS Status;
8712 + UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8713 + BOOLEAN bTxQLastRound = FALSE;
8714 +
8715 + // For USB, didn't need PCI_MAP_SINGLE()
8716 + //SrcBufPA = PCI_MAP_SINGLE(pAd, (char *) pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, PCI_DMA_TODEVICE);
8717 +
8718 +
8719 + //
8720 + // get Tx Ring Resource & Dma Buffer address
8721 + //
8722 + QueIdx = pTxBlk->QueIdx;
8723 +
8724 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8725 + pHTTXContext = &pAd->TxContext[QueIdx];
8726 + fillOffset = pHTTXContext->CurWritePosition;
8727 +
8728 +
8729 +
8730 + // Check ring full.
8731 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8732 + if(Status == NDIS_STATUS_SUCCESS)
8733 + {
8734 + pHTTXContext->bCurWriting = TRUE;
8735 +
8736 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8737 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8738 +
8739 + // Reserve space for 8 bytes padding.
8740 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8741 + {
8742 + pHTTXContext->ENextBulkOutPosition += 8;
8743 + pHTTXContext->CurWritePosition += 8;
8744 + fillOffset += 8;
8745 + }
8746 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8747 +
8748 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8749 +
8750 + // copy TXWI + WLAN Header + LLC into DMA Header Buffer
8751 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8752 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8753 +
8754 + // Build our URB for USBD
8755 + DMAHdrLen = TXWI_SIZE + hwHdrLen;
8756 + USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
8757 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
8758 + USBDMApktLen += padding;
8759 +
8760 + pTxBlk->Priv = (TXINFO_SIZE + USBDMApktLen);
8761 +
8762 + // For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload
8763 + //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
8764 +#ifdef CONFIG_STA_SUPPORT
8765 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
8766 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(USBDMApktLen), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8767 +#endif // CONFIG_STA_SUPPORT //
8768 +
8769 + if ((pHTTXContext->CurWritePosition + 3906 + pTxBlk->Priv) > MAX_TXBULK_LIMIT)
8770 + {
8771 + pTxInfo->SwUseLastRound = 1;
8772 + bTxQLastRound = TRUE;
8773 + }
8774 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8775 +#ifdef RT_BIG_ENDIAN
8776 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket + TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
8777 +#endif // RT_BIG_ENDIAN //
8778 + pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8779 +
8780 + // We unlock it here to prevent the first 8 bytes maybe over-writed issue.
8781 + // 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxcontext.
8782 + // 2. An interrupt break our routine and handle bulk-out complete.
8783 + // 3. In the bulk-out compllete, it need to do another bulk-out,
8784 + // if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition,
8785 + // but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE.
8786 + // 4. Interrupt complete.
8787 + // 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext.
8788 + // 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition.
8789 + // and the packet will wrong.
8790 + pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
8791 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8792 +
8793 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
8794 + pWirelessPacket += pTxBlk->SrcBufLen;
8795 + NdisZeroMemory(pWirelessPacket, padding + 8);
8796 +
8797 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8798 +
8799 + pHTTXContext->CurWritePosition += pTxBlk->Priv;
8800 + if (bTxQLastRound)
8801 + pHTTXContext->CurWritePosition = 8;
8802 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8803 +
8804 + pHTTXContext->bCurWriting = FALSE;
8805 + }
8806 +
8807 +
8808 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8809 +
8810 +
8811 + // succeed and release the skb buffer
8812 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
8813 +
8814 + return(Status);
8815 +
8816 +}
8817 +
8818 +
8819 +USHORT RtmpUSB_WriteMultiTxResource(
8820 + IN PRTMP_ADAPTER pAd,
8821 + IN TX_BLK *pTxBlk,
8822 + IN UCHAR frameNum,
8823 + OUT USHORT *FreeNumber)
8824 +{
8825 + HT_TX_CONTEXT *pHTTXContext;
8826 + USHORT hwHdrLen; // The hwHdrLen consist of 802.11 header length plus the header padding length.
8827 + UINT32 fillOffset;
8828 + TXINFO_STRUC *pTxInfo;
8829 + TXWI_STRUC *pTxWI;
8830 + PUCHAR pWirelessPacket = NULL;
8831 + UCHAR QueIdx;
8832 + NDIS_STATUS Status;
8833 + unsigned long IrqFlags;
8834 + //UINT32 USBDMApktLen = 0, DMAHdrLen, padding;
8835 +
8836 + //
8837 + // get Tx Ring Resource & Dma Buffer address
8838 + //
8839 + QueIdx = pTxBlk->QueIdx;
8840 + pHTTXContext = &pAd->TxContext[QueIdx];
8841 +
8842 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8843 +
8844 + if(frameNum == 0)
8845 + {
8846 + // Check if we have enough space for this bulk-out batch.
8847 + Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
8848 + if (Status == NDIS_STATUS_SUCCESS)
8849 + {
8850 + pHTTXContext->bCurWriting = TRUE;
8851 +
8852 + pTxInfo = (PTXINFO_STRUC)(&pTxBlk->HeaderBuf[0]);
8853 + pTxWI= (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]);
8854 +
8855 +
8856 + // Reserve space for 8 bytes padding.
8857 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition))
8858 + {
8859 +
8860 + pHTTXContext->CurWritePosition += 8;
8861 + pHTTXContext->ENextBulkOutPosition += 8;
8862 + }
8863 + fillOffset = pHTTXContext->CurWritePosition;
8864 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
8865 +
8866 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8867 +
8868 + //
8869 + // Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer
8870 + //
8871 + if (pTxBlk->TxFrameType == TX_AMSDU_FRAME)
8872 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD;
8873 + hwHdrLen = pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD + pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD;
8874 + else if (pTxBlk->TxFrameType == TX_RALINK_FRAME)
8875 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD;
8876 + hwHdrLen = pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD + pTxBlk->HdrPadLen + LENGTH_ARALINK_HEADER_FIELD;
8877 + else
8878 + //hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4);
8879 + hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
8880 +
8881 + // Update the pTxBlk->Priv.
8882 + pTxBlk->Priv = TXINFO_SIZE + TXWI_SIZE + hwHdrLen;
8883 +
8884 + // pTxInfo->USBDMApktLen now just a temp value and will to correct latter.
8885 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(pTxBlk->Priv), FALSE, FIFO_EDCA, FALSE /*NextValid*/, FALSE);
8886 +
8887 + // Copy it.
8888 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, pTxBlk->Priv);
8889 +#ifdef RT_BIG_ENDIAN
8890 + RTMPFrameEndianChange(pAd, (PUCHAR)(pWirelessPacket+ TXINFO_SIZE + TXWI_SIZE), DIR_WRITE, FALSE);
8891 +#endif // RT_BIG_ENDIAN //
8892 + pHTTXContext->CurWriteRealPos += pTxBlk->Priv;
8893 + pWirelessPacket += pTxBlk->Priv;
8894 + }
8895 + }
8896 + else
8897 + { // For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer.
8898 +
8899 + Status = ((pHTTXContext->bCurWriting == TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
8900 + if (Status == NDIS_STATUS_SUCCESS)
8901 + {
8902 + fillOffset = (pHTTXContext->CurWritePosition + pTxBlk->Priv);
8903 + pWirelessPacket = &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
8904 +
8905 + //hwHdrLen = pTxBlk->MpduHeaderLen;
8906 + NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, pTxBlk->MpduHeaderLen);
8907 + pWirelessPacket += (pTxBlk->MpduHeaderLen);
8908 + pTxBlk->Priv += pTxBlk->MpduHeaderLen;
8909 + }
8910 + else
8911 + { // It should not happened now unless we are going to shutdown.
8912 + DBGPRINT(RT_DEBUG_ERROR, ("WriteMultiTxResource():bCurWriting is FALSE when handle sub-sequent frames.\n"));
8913 + Status = NDIS_STATUS_FAILURE;
8914 + }
8915 + }
8916 +
8917 +
8918 + // We unlock it here to prevent the first 8 bytes maybe over-write issue.
8919 + // 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxContext.
8920 + // 2. An interrupt break our routine and handle bulk-out complete.
8921 + // 3. In the bulk-out compllete, it need to do another bulk-out,
8922 + // if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition,
8923 + // but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE.
8924 + // 4. Interrupt complete.
8925 + // 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext.
8926 + // 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition.
8927 + // and the packet will wrong.
8928 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8929 +
8930 + if (Status != NDIS_STATUS_SUCCESS)
8931 + {
8932 + DBGPRINT(RT_DEBUG_ERROR,("WriteMultiTxResource: CWPos = %ld, NBOutPos = %ld.\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition));
8933 + goto done;
8934 + }
8935 +
8936 + // Copy the frame content into DMA buffer and update the pTxBlk->Priv
8937 + NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
8938 + pWirelessPacket += pTxBlk->SrcBufLen;
8939 + pTxBlk->Priv += pTxBlk->SrcBufLen;
8940 +
8941 +done:
8942 + // Release the skb buffer here
8943 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
8944 +
8945 + return(Status);
8946 +
8947 +}
8948 +
8949 +
8950 +VOID RtmpUSB_FinalWriteTxResource(
8951 + IN PRTMP_ADAPTER pAd,
8952 + IN TX_BLK *pTxBlk,
8953 + IN USHORT totalMPDUSize,
8954 + IN USHORT TxIdx)
8955 +{
8956 + UCHAR QueIdx;
8957 + HT_TX_CONTEXT *pHTTXContext;
8958 + UINT32 fillOffset;
8959 + TXINFO_STRUC *pTxInfo;
8960 + TXWI_STRUC *pTxWI;
8961 + UINT32 USBDMApktLen, padding;
8962 + unsigned long IrqFlags;
8963 + PUCHAR pWirelessPacket;
8964 +
8965 + QueIdx = pTxBlk->QueIdx;
8966 + pHTTXContext = &pAd->TxContext[QueIdx];
8967 +
8968 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
8969 +
8970 + if (pHTTXContext->bCurWriting == TRUE)
8971 + {
8972 + fillOffset = pHTTXContext->CurWritePosition;
8973 + if (((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition) || ((pHTTXContext->ENextBulkOutPosition-8) == pHTTXContext->CurWritePosition))
8974 + && (pHTTXContext->bCopySavePad == TRUE))
8975 + pWirelessPacket = (PUCHAR)(&pHTTXContext->SavedPad[0]);
8976 + else
8977 + pWirelessPacket = (PUCHAR)(&pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset]);
8978 +
8979 + //
8980 + // Update TxInfo->USBDMApktLen ,
8981 + // the length = TXWI_SIZE + 802.11_hdr + 802.11_hdr_pad + payload_of_all_batch_frames + Bulk-Out-padding
8982 + //
8983 + pTxInfo = (PTXINFO_STRUC)(pWirelessPacket);
8984 +
8985 + // Calculate the bulk-out padding
8986 + USBDMApktLen = pTxBlk->Priv - TXINFO_SIZE;
8987 + padding = (4 - (USBDMApktLen % 4)) & 0x03; // round up to 4 byte alignment
8988 + USBDMApktLen += padding;
8989 +
8990 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
8991 +
8992 + //
8993 + // Update TXWI->MPDUtotalByteCount ,
8994 + // the length = 802.11 header + payload_of_all_batch_frames
8995 + pTxWI= (PTXWI_STRUC)(pWirelessPacket + TXINFO_SIZE);
8996 + pTxWI->MPDUtotalByteCount = totalMPDUSize;
8997 +
8998 + //
8999 + // Update the pHTTXContext->CurWritePosition
9000 + //
9001 + pHTTXContext->CurWritePosition += (TXINFO_SIZE + USBDMApktLen);
9002 + if ((pHTTXContext->CurWritePosition + 3906)> MAX_TXBULK_LIMIT)
9003 + { // Add 3906 for prevent the NextBulkOut packet size is a A-RALINK/A-MSDU Frame.
9004 + pHTTXContext->CurWritePosition = 8;
9005 + pTxInfo->SwUseLastRound = 1;
9006 + }
9007 + pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
9008 +
9009 +
9010 + //
9011 + // Zero the last padding.
9012 + //
9013 + pWirelessPacket = (&pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset + pTxBlk->Priv]);
9014 + NdisZeroMemory(pWirelessPacket, padding + 8);
9015 +
9016 + // Finally, set bCurWriting as FALSE
9017 + pHTTXContext->bCurWriting = FALSE;
9018 +
9019 + }
9020 + else
9021 + { // It should not happened now unless we are going to shutdown.
9022 + DBGPRINT(RT_DEBUG_ERROR, ("FinalWriteTxResource():bCurWriting is FALSE when handle last frames.\n"));
9023 + }
9024 +
9025 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
9026 +
9027 +}
9028 +
9029 +
9030 +VOID RtmpUSBDataLastTxIdx(
9031 + IN PRTMP_ADAPTER pAd,
9032 + IN UCHAR QueIdx,
9033 + IN USHORT TxIdx)
9034 +{
9035 + // DO nothing for USB.
9036 +}
9037 +
9038 +
9039 +/*
9040 + When can do bulk-out:
9041 + 1. TxSwFreeIdx < TX_RING_SIZE;
9042 + It means has at least one Ring entity is ready for bulk-out, kick it out.
9043 + 2. If TxSwFreeIdx == TX_RING_SIZE
9044 + Check if the CurWriting flag is FALSE, if it's FALSE, we can do kick out.
9045 +
9046 +*/
9047 +VOID RtmpUSBDataKickOut(
9048 + IN PRTMP_ADAPTER pAd,
9049 + IN TX_BLK *pTxBlk,
9050 + IN UCHAR QueIdx)
9051 +{
9052 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
9053 + RTUSBKickBulkOut(pAd);
9054 +
9055 +}
9056 +
9057 +
9058 +/*
9059 + Must be run in Interrupt context
9060 + This function handle RT2870 specific TxDesc and cpu index update and kick the packet out.
9061 + */
9062 +int RtmpUSBMgmtKickOut(
9063 + IN RTMP_ADAPTER *pAd,
9064 + IN UCHAR QueIdx,
9065 + IN PNDIS_PACKET pPacket,
9066 + IN PUCHAR pSrcBufVA,
9067 + IN UINT SrcBufLen)
9068 +{
9069 + PTXINFO_STRUC pTxInfo;
9070 + ULONG BulkOutSize;
9071 + UCHAR padLen;
9072 + PUCHAR pDest;
9073 + ULONG SwIdx = pAd->MgmtRing.TxCpuIdx;
9074 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[SwIdx].AllocVa;
9075 + unsigned long IrqFlags;
9076 +
9077 +
9078 + pTxInfo = (PTXINFO_STRUC)(pSrcBufVA);
9079 +
9080 + // Build our URB for USBD
9081 + BulkOutSize = SrcBufLen;
9082 + BulkOutSize = (BulkOutSize + 3) & (~3);
9083 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(BulkOutSize - TXINFO_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
9084 +
9085 + BulkOutSize += 4; // Always add 4 extra bytes at every packet.
9086 +
9087 + // If BulkOutSize is multiple of BulkOutMaxPacketSize, add extra 4 bytes again.
9088 + if ((BulkOutSize % pAd->BulkOutMaxPacketSize) == 0)
9089 + BulkOutSize += 4;
9090 +
9091 + padLen = BulkOutSize - SrcBufLen;
9092 + ASSERT((padLen <= RTMP_PKT_TAIL_PADDING));
9093 +
9094 + // Now memzero all extra padding bytes.
9095 + pDest = (PUCHAR)(pSrcBufVA + SrcBufLen);
9096 + skb_put(GET_OS_PKT_TYPE(pPacket), padLen);
9097 + NdisZeroMemory(pDest, padLen);
9098 +
9099 + RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
9100 +
9101 + pAd->MgmtRing.Cell[pAd->MgmtRing.TxCpuIdx].pNdisPacket = pPacket;
9102 + pMLMEContext->TransferBuffer = (PTX_BUFFER)(GET_OS_PKT_DATAPTR(pPacket));
9103 +
9104 + // Length in TxInfo should be 8 less than bulkout size.
9105 + pMLMEContext->BulkOutSize = BulkOutSize;
9106 + pMLMEContext->InUse = TRUE;
9107 + pMLMEContext->bWaitingBulkOut = TRUE;
9108 +
9109 +
9110 + //for debug
9111 + //hex_dump("RtmpUSBMgmtKickOut", &pMLMEContext->TransferBuffer->field.WirelessPacket[0], (pMLMEContext->BulkOutSize > 16 ? 16 : pMLMEContext->BulkOutSize));
9112 +
9113 + //pAd->RalinkCounters.KickTxCount++;
9114 + //pAd->RalinkCounters.OneSecTxDoneCount++;
9115 +
9116 + //if (pAd->MgmtRing.TxSwFreeIdx == MGMT_RING_SIZE)
9117 + // needKickOut = TRUE;
9118 +
9119 + // Decrease the TxSwFreeIdx and Increase the TX_CTX_IDX
9120 + pAd->MgmtRing.TxSwFreeIdx--;
9121 + INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE);
9122 +
9123 + RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
9124 +
9125 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
9126 + //if (needKickOut)
9127 + RTUSBKickBulkOut(pAd);
9128 +
9129 + return 0;
9130 +}
9131 +
9132 +
9133 +VOID RtmpUSBNullFrameKickOut(
9134 + IN RTMP_ADAPTER *pAd,
9135 + IN UCHAR QueIdx,
9136 + IN UCHAR *pNullFrame,
9137 + IN UINT32 frameLen)
9138 +{
9139 + if (pAd->NullContext.InUse == FALSE)
9140 + {
9141 + PTX_CONTEXT pNullContext;
9142 + PTXINFO_STRUC pTxInfo;
9143 + PTXWI_STRUC pTxWI;
9144 + PUCHAR pWirelessPkt;
9145 +
9146 + pNullContext = &(pAd->NullContext);
9147 +
9148 + // Set the in use bit
9149 + pNullContext->InUse = TRUE;
9150 + pWirelessPkt = (PUCHAR)&pNullContext->TransferBuffer->field.WirelessPacket[0];
9151 +
9152 + RTMPZeroMemory(&pWirelessPkt[0], 100);
9153 + pTxInfo = (PTXINFO_STRUC)&pWirelessPkt[0];
9154 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
9155 + pTxInfo->QSEL = FIFO_EDCA;
9156 + pTxWI = (PTXWI_STRUC)&pWirelessPkt[TXINFO_SIZE];
9157 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
9158 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
9159 +#ifdef RT_BIG_ENDIAN
9160 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
9161 +#endif // RT_BIG_ENDIAN //
9162 +
9163 + RTMPMoveMemory(&pWirelessPkt[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
9164 +#ifdef RT_BIG_ENDIAN
9165 + RTMPFrameEndianChange(pAd, (PUCHAR)&pWirelessPkt[TXINFO_SIZE + TXWI_SIZE], DIR_WRITE, FALSE);
9166 +#endif // RT_BIG_ENDIAN //
9167 + pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
9168 +
9169 + // Fill out frame length information for global Bulk out arbitor
9170 + //pNullContext->BulkOutSize = TransferBufferLength;
9171 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - send NULL Frame @%d Mbps...\n", RateIdToMbps[pAd->CommonCfg.TxRate]));
9172 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
9173 +
9174 + // Kick bulk out
9175 + RTUSBKickBulkOut(pAd);
9176 + }
9177 +
9178 +}
9179 +
9180 +#ifdef CONFIG_STA_SUPPORT
9181 +/*
9182 + ========================================================================
9183 +
9184 + Routine Description:
9185 + Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound
9186 +
9187 + Arguments:
9188 + pRxD Pointer to the Rx descriptor
9189 +
9190 + Return Value:
9191 + NDIS_STATUS_SUCCESS No err
9192 + NDIS_STATUS_FAILURE Error
9193 +
9194 + Note:
9195 +
9196 + ========================================================================
9197 +*/
9198 +NDIS_STATUS RTMPCheckRxError(
9199 + IN PRTMP_ADAPTER pAd,
9200 + IN PHEADER_802_11 pHeader,
9201 + IN PRXWI_STRUC pRxWI,
9202 + IN PRT28XX_RXD_STRUC pRxINFO)
9203 +{
9204 + PCIPHER_KEY pWpaKey;
9205 + INT dBm;
9206 +
9207 + if (pAd->bPromiscuous == TRUE)
9208 + return(NDIS_STATUS_SUCCESS);
9209 + if(pRxINFO == NULL)
9210 + return(NDIS_STATUS_FAILURE);
9211 +
9212 + // Phy errors & CRC errors
9213 + if (pRxINFO->Crc)
9214 + {
9215 + // Check RSSI for Noise Hist statistic collection.
9216 + dBm = (INT) (pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta;
9217 + if (dBm <= -87)
9218 + pAd->StaCfg.RPIDensity[0] += 1;
9219 + else if (dBm <= -82)
9220 + pAd->StaCfg.RPIDensity[1] += 1;
9221 + else if (dBm <= -77)
9222 + pAd->StaCfg.RPIDensity[2] += 1;
9223 + else if (dBm <= -72)
9224 + pAd->StaCfg.RPIDensity[3] += 1;
9225 + else if (dBm <= -67)
9226 + pAd->StaCfg.RPIDensity[4] += 1;
9227 + else if (dBm <= -62)
9228 + pAd->StaCfg.RPIDensity[5] += 1;
9229 + else if (dBm <= -57)
9230 + pAd->StaCfg.RPIDensity[6] += 1;
9231 + else if (dBm > -57)
9232 + pAd->StaCfg.RPIDensity[7] += 1;
9233 +
9234 + return(NDIS_STATUS_FAILURE);
9235 + }
9236 +
9237 + // Add Rx size to channel load counter, we should ignore error counts
9238 + pAd->StaCfg.CLBusyBytes += (pRxWI->MPDUtotalByteCount+ 14);
9239 +
9240 + // Drop ToDs promiscous frame, it is opened due to CCX 2 channel load statistics
9241 + if (pHeader->FC.ToDs)
9242 + {
9243 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Err;FC.ToDs\n"));
9244 + return NDIS_STATUS_FAILURE;
9245 + }
9246 +
9247 + // Paul 04-03 for OFDM Rx length issue
9248 + if (pRxWI->MPDUtotalByteCount > MAX_AGGREGATION_SIZE)
9249 + {
9250 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("received packet too long\n"));
9251 + return NDIS_STATUS_FAILURE;
9252 + }
9253 +
9254 + // Drop not U2M frames, cant's drop here because we will drop beacon in this case
9255 + // I am kind of doubting the U2M bit operation
9256 + // if (pRxD->U2M == 0)
9257 + // return(NDIS_STATUS_FAILURE);
9258 +
9259 + // drop decyption fail frame
9260 + if (pRxINFO->Decrypted && pRxINFO->CipherErr)
9261 + {
9262 +
9263 + //
9264 + // MIC Error
9265 + //
9266 + if ((pRxINFO->CipherErr == 2) && pRxINFO->MyBss)
9267 + {
9268 + pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex];
9269 + RTMPReportMicError(pAd, pWpaKey);
9270 + DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error\n"));
9271 + }
9272 +
9273 + if (pRxINFO->Decrypted &&
9274 + (pAd->SharedKey[BSS0][pRxWI->KeyIndex].CipherAlg == CIPHER_AES) &&
9275 + (pHeader->Sequence == pAd->FragFrame.Sequence))
9276 + {
9277 + //
9278 + // Acceptable since the First FragFrame no CipherErr problem.
9279 + //
9280 + return(NDIS_STATUS_SUCCESS);
9281 + }
9282 +
9283 + return(NDIS_STATUS_FAILURE);
9284 + }
9285 +
9286 + return(NDIS_STATUS_SUCCESS);
9287 +}
9288 +
9289 +VOID RT28xxUsbStaAsicForceWakeup(
9290 + IN PRTMP_ADAPTER pAd,
9291 + IN BOOLEAN bFromTx)
9292 +{
9293 + AUTO_WAKEUP_STRUC AutoWakeupCfg;
9294 +
9295 + AutoWakeupCfg.word = 0;
9296 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9297 +
9298 + AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
9299 +
9300 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
9301 +}
9302 +
9303 +VOID RT28xxUsbStaAsicSleepThenAutoWakeup(
9304 + IN PRTMP_ADAPTER pAd,
9305 + IN USHORT TbttNumToNextWakeUp)
9306 +{
9307 + AUTO_WAKEUP_STRUC AutoWakeupCfg;
9308 +
9309 + // we have decided to SLEEP, so at least do it for a BEACON period.
9310 + if (TbttNumToNextWakeUp == 0)
9311 + TbttNumToNextWakeUp = 1;
9312 +
9313 + AutoWakeupCfg.word = 0;
9314 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9315 +
9316 + AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1;
9317 + AutoWakeupCfg.field.EnableAutoWakeup = 1;
9318 + AutoWakeupCfg.field.AutoLeadTime = 5;
9319 + RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
9320 +
9321 + AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); // send POWER-SAVE command to MCU. Timeout 40us.
9322 +
9323 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE);
9324 +
9325 +}
9326 +#endif // CONFIG_STA_SUPPORT //
9327 +
9328 +VOID RT28xxUsbMlmeRadioOn(
9329 + IN PRTMP_ADAPTER pAd)
9330 +{
9331 + DBGPRINT(RT_DEBUG_TRACE,("RT28xxUsbMlmeRadioOn()\n"));
9332 +
9333 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
9334 + return;
9335 +
9336 +#ifdef CONFIG_STA_SUPPORT
9337 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9338 + {
9339 + AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
9340 + RTMPusecDelay(10000);
9341 + }
9342 +#endif // CONFIG_STA_SUPPORT //
9343 + NICResetFromError(pAd);
9344 +
9345 + // Enable Tx/Rx
9346 + RTMPEnableRxTx(pAd);
9347 +
9348 +#ifdef RT3070
9349 + if (IS_RT3071(pAd))
9350 + {
9351 + RT30xxReverseRFSleepModeSetup(pAd);
9352 + }
9353 +#endif // RT3070 //
9354 +
9355 + // Clear Radio off flag
9356 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
9357 +
9358 +#ifdef CONFIG_STA_SUPPORT
9359 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9360 + RTUSBBulkReceive(pAd);
9361 +#endif // CONFIG_STA_SUPPORT //
9362 +
9363 + // Set LED
9364 + RTMPSetLED(pAd, LED_RADIO_ON);
9365 +}
9366 +
9367 +VOID RT28xxUsbMlmeRadioOFF(
9368 + IN PRTMP_ADAPTER pAd)
9369 +{
9370 + WPDMA_GLO_CFG_STRUC GloCfg;
9371 + UINT32 Value, i;
9372 +
9373 + DBGPRINT(RT_DEBUG_TRACE,("RT28xxUsbMlmeRadioOFF()\n"));
9374 +
9375 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
9376 + return;
9377 +
9378 + // Set LED
9379 + RTMPSetLED(pAd, LED_RADIO_OFF);
9380 + // Set Radio off flag
9381 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
9382 +
9383 +#ifdef CONFIG_STA_SUPPORT
9384 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9385 + {
9386 + // Link down first if any association exists
9387 + if (INFRA_ON(pAd) || ADHOC_ON(pAd))
9388 + LinkDown(pAd, FALSE);
9389 + RTMPusecDelay(10000);
9390 +
9391 + //==========================================
9392 + // Clean up old bss table
9393 + BssTableInit(&pAd->ScanTab);
9394 + }
9395 +#endif // CONFIG_STA_SUPPORT //
9396 +
9397 +
9398 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
9399 + {
9400 + // Must using 40MHz.
9401 + AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel);
9402 + }
9403 + else
9404 + {
9405 + // Must using 20MHz.
9406 + AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel);
9407 + }
9408 +
9409 + // Disable Tx/Rx DMA
9410 + RTUSBReadMACRegister(pAd, WPDMA_GLO_CFG, &GloCfg.word); // disable DMA
9411 + GloCfg.field.EnableTxDMA = 0;
9412 + GloCfg.field.EnableRxDMA = 0;
9413 + RTUSBWriteMACRegister(pAd, WPDMA_GLO_CFG, GloCfg.word); // abort all TX rings
9414 +
9415 + // Waiting for DMA idle
9416 + i = 0;
9417 + do
9418 + {
9419 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
9420 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
9421 + break;
9422 +
9423 + RTMPusecDelay(1000);
9424 + }while (i++ < 100);
9425 +
9426 + // Disable MAC Tx/Rx
9427 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
9428 + Value &= (0xfffffff3);
9429 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
9430 +
9431 + // MAC_SYS_CTRL => value = 0x0 => 40mA
9432 + //RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0);
9433 +
9434 + // PWR_PIN_CFG => value = 0x0 => 40mA
9435 + //RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0);
9436 +
9437 + // TX_PIN_CFG => value = 0x0 => 20mA
9438 + //RTMP_IO_WRITE32(pAd, TX_PIN_CFG, 0);
9439 +
9440 +#ifdef CONFIG_STA_SUPPORT
9441 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9442 + AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02);
9443 +#endif // CONFIG_STA_SUPPORT //
9444 +}
9445 +
9446 --- /dev/null
9447 +++ b/drivers/staging/rt3070/common/cmm_data.c
9448 @@ -0,0 +1,2827 @@
9449 +/*
9450 + *************************************************************************
9451 + * Ralink Tech Inc.
9452 + * 5F., No.36, Taiyuan St., Jhubei City,
9453 + * Hsinchu County 302,
9454 + * Taiwan, R.O.C.
9455 + *
9456 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
9457 + *
9458 + * This program is free software; you can redistribute it and/or modify *
9459 + * it under the terms of the GNU General Public License as published by *
9460 + * the Free Software Foundation; either version 2 of the License, or *
9461 + * (at your option) any later version. *
9462 + * *
9463 + * This program is distributed in the hope that it will be useful, *
9464 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9465 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
9466 + * GNU General Public License for more details. *
9467 + * *
9468 + * You should have received a copy of the GNU General Public License *
9469 + * along with this program; if not, write to the *
9470 + * Free Software Foundation, Inc., *
9471 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
9472 + * *
9473 + *************************************************************************
9474 +*/
9475 +
9476 +#include "../rt_config.h"
9477 +
9478 +#define MAX_TX_IN_TBTT (16)
9479 +
9480 +
9481 +UCHAR SNAP_802_1H[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
9482 +UCHAR SNAP_BRIDGE_TUNNEL[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
9483 +// Add Cisco Aironet SNAP heade for CCX2 support
9484 +UCHAR SNAP_AIRONET[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00};
9485 +UCHAR CKIP_LLC_SNAP[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02};
9486 +UCHAR EAPOL_LLC_SNAP[]= {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e};
9487 +UCHAR EAPOL[] = {0x88, 0x8e};
9488 +UCHAR TPID[] = {0x81, 0x00}; /* VLAN related */
9489 +
9490 +UCHAR IPX[] = {0x81, 0x37};
9491 +UCHAR APPLE_TALK[] = {0x80, 0xf3};
9492 +UCHAR RateIdToPlcpSignal[12] = {
9493 + 0, /* RATE_1 */ 1, /* RATE_2 */ 2, /* RATE_5_5 */ 3, /* RATE_11 */ // see BBP spec
9494 + 11, /* RATE_6 */ 15, /* RATE_9 */ 10, /* RATE_12 */ 14, /* RATE_18 */ // see IEEE802.11a-1999 p.14
9495 + 9, /* RATE_24 */ 13, /* RATE_36 */ 8, /* RATE_48 */ 12 /* RATE_54 */ }; // see IEEE802.11a-1999 p.14
9496 +
9497 +UCHAR OfdmSignalToRateId[16] = {
9498 + RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 0, 1, 2, 3 respectively
9499 + RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 4, 5, 6, 7 respectively
9500 + RATE_48, RATE_24, RATE_12, RATE_6, // OFDM PLCP Signal = 8, 9, 10, 11 respectively
9501 + RATE_54, RATE_36, RATE_18, RATE_9, // OFDM PLCP Signal = 12, 13, 14, 15 respectively
9502 +};
9503 +
9504 +UCHAR OfdmRateToRxwiMCS[12] = {
9505 + 0, 0, 0, 0,
9506 + 0, 1, 2, 3, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3
9507 + 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7
9508 +};
9509 +UCHAR RxwiMCSToOfdmRate[12] = {
9510 + RATE_6, RATE_9, RATE_12, RATE_18,
9511 + RATE_24, RATE_36, RATE_48, RATE_54, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3
9512 + 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7
9513 +};
9514 +
9515 +char* MCSToMbps[] = {"1Mbps","2Mbps","5.5Mbps","11Mbps","06Mbps","09Mbps","12Mbps","18Mbps","24Mbps","36Mbps","48Mbps","54Mbps","MM-0","MM-1","MM-2","MM-3","MM-4","MM-5","MM-6","MM-7","MM-8","MM-9","MM-10","MM-11","MM-12","MM-13","MM-14","MM-15","MM-32","ee1","ee2","ee3"};
9516 +
9517 +UCHAR default_cwmin[]={CW_MIN_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1, CW_MIN_IN_BITS-2};
9518 +//UCHAR default_cwmax[]={CW_MAX_IN_BITS, CW_MAX_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1};
9519 +UCHAR default_sta_aifsn[]={3,7,2,2};
9520 +
9521 +UCHAR MapUserPriorityToAccessCategory[8] = {QID_AC_BE, QID_AC_BK, QID_AC_BK, QID_AC_BE, QID_AC_VI, QID_AC_VI, QID_AC_VO, QID_AC_VO};
9522 +
9523 +
9524 +/*
9525 + ========================================================================
9526 +
9527 + Routine Description:
9528 + API for MLME to transmit management frame to AP (BSS Mode)
9529 + or station (IBSS Mode)
9530 +
9531 + Arguments:
9532 + pAd Pointer to our adapter
9533 + pData Pointer to the outgoing 802.11 frame
9534 + Length Size of outgoing management frame
9535 +
9536 + Return Value:
9537 + NDIS_STATUS_FAILURE
9538 + NDIS_STATUS_PENDING
9539 + NDIS_STATUS_SUCCESS
9540 +
9541 + IRQL = PASSIVE_LEVEL
9542 + IRQL = DISPATCH_LEVEL
9543 +
9544 + Note:
9545 +
9546 + ========================================================================
9547 +*/
9548 +NDIS_STATUS MiniportMMRequest(
9549 + IN PRTMP_ADAPTER pAd,
9550 + IN UCHAR QueIdx,
9551 + IN PUCHAR pData,
9552 + IN UINT Length)
9553 +{
9554 + PNDIS_PACKET pPacket;
9555 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
9556 + ULONG FreeNum;
9557 + UCHAR IrqState;
9558 + UCHAR rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; //RTMP_HW_HDR_LEN];
9559 +
9560 + ASSERT(Length <= MGMT_DMA_BUFFER_SIZE);
9561 +
9562 + QueIdx=3;
9563 +
9564 + // 2860C use Tx Ring
9565 +
9566 + IrqState = pAd->irq_disabled;
9567 +
9568 + do
9569 + {
9570 + // Reset is in progress, stop immediately
9571 + if ( RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
9572 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)||
9573 + !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
9574 + {
9575 + Status = NDIS_STATUS_FAILURE;
9576 + break;
9577 + }
9578 +
9579 + // Check Free priority queue
9580 + // Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing.
9581 +
9582 + // 2860C use Tx Ring
9583 + if (pAd->MACVersion == 0x28600100)
9584 + {
9585 + FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
9586 + }
9587 + else
9588 + {
9589 + FreeNum = GET_MGMTRING_FREENO(pAd);
9590 + }
9591 +
9592 + if ((FreeNum > 0))
9593 + {
9594 + // We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870
9595 + NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE));
9596 + Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE), pData, Length);
9597 + if (Status != NDIS_STATUS_SUCCESS)
9598 + {
9599 + DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n"));
9600 + break;
9601 + }
9602 +
9603 + //pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
9604 + //pAd->CommonCfg.MlmeRate = RATE_2;
9605 +
9606 +
9607 + Status = MlmeHardTransmit(pAd, QueIdx, pPacket);
9608 + if (Status != NDIS_STATUS_SUCCESS)
9609 + RTMPFreeNdisPacket(pAd, pPacket);
9610 + }
9611 + else
9612 + {
9613 + pAd->RalinkCounters.MgmtRingFullCount++;
9614 + DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n",
9615 + QueIdx, pAd->RalinkCounters.MgmtRingFullCount));
9616 + }
9617 +
9618 + } while (FALSE);
9619 +
9620 +
9621 + return Status;
9622 +}
9623 +
9624 +
9625 +
9626 +NDIS_STATUS MlmeDataHardTransmit(
9627 + IN PRTMP_ADAPTER pAd,
9628 + IN UCHAR QueIdx,
9629 + IN PNDIS_PACKET pPacket);
9630 +
9631 +#define MAX_DATAMM_RETRY 3
9632 +/*
9633 + ========================================================================
9634 +
9635 + Routine Description:
9636 + API for MLME to transmit management frame to AP (BSS Mode)
9637 + or station (IBSS Mode)
9638 +
9639 + Arguments:
9640 + pAd Pointer to our adapter
9641 + pData Pointer to the outgoing 802.11 frame
9642 + Length Size of outgoing management frame
9643 +
9644 + Return Value:
9645 + NDIS_STATUS_FAILURE
9646 + NDIS_STATUS_PENDING
9647 + NDIS_STATUS_SUCCESS
9648 +
9649 + IRQL = PASSIVE_LEVEL
9650 + IRQL = DISPATCH_LEVEL
9651 +
9652 + Note:
9653 +
9654 + ========================================================================
9655 +*/
9656 +NDIS_STATUS MiniportDataMMRequest(
9657 + IN PRTMP_ADAPTER pAd,
9658 + IN UCHAR QueIdx,
9659 + IN PUCHAR pData,
9660 + IN UINT Length)
9661 +{
9662 + PNDIS_PACKET pPacket;
9663 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
9664 + ULONG FreeNum;
9665 + int retry = 0;
9666 + UCHAR IrqState;
9667 + UCHAR rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; //RTMP_HW_HDR_LEN];
9668 +
9669 + ASSERT(Length <= MGMT_DMA_BUFFER_SIZE);
9670 +
9671 + // 2860C use Tx Ring
9672 + IrqState = pAd->irq_disabled;
9673 +
9674 + do
9675 + {
9676 + // Reset is in progress, stop immediately
9677 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
9678 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)||
9679 + !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
9680 + {
9681 + Status = NDIS_STATUS_FAILURE;
9682 + break;
9683 + }
9684 +
9685 + // Check Free priority queue
9686 + // Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing.
9687 +
9688 + // 2860C use Tx Ring
9689 +
9690 + // free Tx(QueIdx) resources
9691 + FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
9692 +
9693 + if ((FreeNum > 0))
9694 + {
9695 + // We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870
9696 + NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE));
9697 + Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE), pData, Length);
9698 + if (Status != NDIS_STATUS_SUCCESS)
9699 + {
9700 + DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n"));
9701 + break;
9702 + }
9703 +
9704 + //pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
9705 + //pAd->CommonCfg.MlmeRate = RATE_2;
9706 +
9707 +
9708 + Status = MlmeDataHardTransmit(pAd, QueIdx, pPacket);
9709 + if (Status != NDIS_STATUS_SUCCESS)
9710 + RTMPFreeNdisPacket(pAd, pPacket);
9711 + retry = MAX_DATAMM_RETRY;
9712 + }
9713 + else
9714 + {
9715 + retry ++;
9716 +
9717 + printk("retry %d\n", retry);
9718 + pAd->RalinkCounters.MgmtRingFullCount++;
9719 +
9720 + if (retry >= MAX_DATAMM_RETRY)
9721 + {
9722 + DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in DataRing, MgmtRingFullCount=%ld!\n",
9723 + QueIdx, pAd->RalinkCounters.MgmtRingFullCount));
9724 + }
9725 + }
9726 +
9727 + } while (retry < MAX_DATAMM_RETRY);
9728 +
9729 +
9730 + return Status;
9731 +}
9732 +
9733 +
9734 +
9735 +
9736 +
9737 +
9738 +/*
9739 + ========================================================================
9740 +
9741 + Routine Description:
9742 + Copy frame from waiting queue into relative ring buffer and set
9743 + appropriate ASIC register to kick hardware transmit function
9744 +
9745 + Arguments:
9746 + pAd Pointer to our adapter
9747 + pBuffer Pointer to memory of outgoing frame
9748 + Length Size of outgoing management frame
9749 +
9750 + Return Value:
9751 + NDIS_STATUS_FAILURE
9752 + NDIS_STATUS_PENDING
9753 + NDIS_STATUS_SUCCESS
9754 +
9755 + IRQL = PASSIVE_LEVEL
9756 + IRQL = DISPATCH_LEVEL
9757 +
9758 + Note:
9759 +
9760 + ========================================================================
9761 +*/
9762 +NDIS_STATUS MlmeHardTransmit(
9763 + IN PRTMP_ADAPTER pAd,
9764 + IN UCHAR QueIdx,
9765 + IN PNDIS_PACKET pPacket)
9766 +{
9767 + if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
9768 +#ifdef CARRIER_DETECTION_SUPPORT
9769 +#endif // CARRIER_DETECTION_SUPPORT //
9770 + )
9771 + {
9772 + return NDIS_STATUS_FAILURE;
9773 + }
9774 +
9775 + return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket);
9776 +
9777 +}
9778 +
9779 +NDIS_STATUS MlmeDataHardTransmit(
9780 + IN PRTMP_ADAPTER pAd,
9781 + IN UCHAR QueIdx,
9782 + IN PNDIS_PACKET pPacket)
9783 +{
9784 + if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
9785 +#ifdef CARRIER_DETECTION_SUPPORT
9786 +#endif // CARRIER_DETECTION_SUPPORT //
9787 + )
9788 + {
9789 + return NDIS_STATUS_FAILURE;
9790 + }
9791 +
9792 +#ifdef RT2870
9793 + return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket);
9794 +#endif // RT2870 //
9795 +}
9796 +
9797 +
9798 +
9799 +
9800 +
9801 +NDIS_STATUS MlmeHardTransmitMgmtRing(
9802 + IN PRTMP_ADAPTER pAd,
9803 + IN UCHAR QueIdx,
9804 + IN PNDIS_PACKET pPacket)
9805 +{
9806 + PACKET_INFO PacketInfo;
9807 + PUCHAR pSrcBufVA;
9808 + UINT SrcBufLen;
9809 + PHEADER_802_11 pHeader_802_11;
9810 + BOOLEAN bAckRequired, bInsertTimestamp;
9811 + UCHAR MlmeRate;
9812 + PTXWI_STRUC pFirstTxWI;
9813 + MAC_TABLE_ENTRY *pMacEntry = NULL;
9814 +
9815 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
9816 +
9817 + // Make sure MGMT ring resource won't be used by other threads
9818 +// sample, for IRQ LOCK -> SEM LOCK
9819 +// IrqState = pAd->irq_disabled;
9820 +// if (!IrqState)
9821 + RTMP_SEM_LOCK(&pAd->MgmtRingLock);
9822 +
9823 +
9824 + if (pSrcBufVA == NULL)
9825 + {
9826 + // The buffer shouldn't be NULL
9827 +// if (!IrqState)
9828 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9829 + return NDIS_STATUS_FAILURE;
9830 + }
9831 +
9832 +#ifdef CONFIG_STA_SUPPORT
9833 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9834 + {
9835 + // outgoing frame always wakeup PHY to prevent frame lost
9836 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
9837 + AsicForceWakeup(pAd, TRUE);
9838 + }
9839 +#endif // CONFIG_STA_SUPPORT //
9840 +
9841 + pFirstTxWI = (PTXWI_STRUC)(pSrcBufVA + TXINFO_SIZE);
9842 + pHeader_802_11 = (PHEADER_802_11) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); //TXWI_SIZE);
9843 +
9844 + if (pHeader_802_11->Addr1[0] & 0x01)
9845 + {
9846 + MlmeRate = pAd->CommonCfg.BasicMlmeRate;
9847 + }
9848 + else
9849 + {
9850 + MlmeRate = pAd->CommonCfg.MlmeRate;
9851 + }
9852 +
9853 + // Verify Mlme rate for a / g bands.
9854 + if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) // 11A band
9855 + MlmeRate = RATE_6;
9856 +
9857 + if ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
9858 + (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL))
9859 + {
9860 + pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1);
9861 + }
9862 +
9863 +#ifdef CONFIG_STA_SUPPORT
9864 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
9865 + {
9866 + // Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode.
9867 + if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED
9868 +#ifdef DOT11_N_SUPPORT
9869 + || pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED
9870 +#endif // DOT11_N_SUPPORT //
9871 + )
9872 + {
9873 + if (pAd->LatchRfRegs.Channel > 14)
9874 + pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
9875 + else
9876 + pAd->CommonCfg.MlmeTransmit.field.MODE = 0;
9877 + }
9878 + }
9879 +#endif // CONFIG_STA_SUPPORT //
9880 +
9881 + //
9882 + // Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE)
9883 + // Snice it's been set to 0 while on MgtMacHeaderInit
9884 + // By the way this will cause frame to be send on PWR_SAVE failed.
9885 + //
9886 + // pHeader_802_11->FC.PwrMgmt = 0; // (pAd->StaCfg.Psm == PWR_SAVE);
9887 + //
9888 + // In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame
9889 +#ifdef CONFIG_STA_SUPPORT
9890 + // Data-Null packets alse pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD
9891 + if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL))
9892 + {
9893 + if ((pAd->StaCfg.Psm == PWR_SAVE) &&
9894 + (pHeader_802_11->FC.SubType == SUBTYPE_ACTION))
9895 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
9896 + else
9897 + pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE;
9898 + }
9899 +#endif // CONFIG_STA_SUPPORT //
9900 +
9901 + bInsertTimestamp = FALSE;
9902 + if (pHeader_802_11->FC.Type == BTYPE_CNTL) // must be PS-POLL
9903 + {
9904 +#ifdef CONFIG_STA_SUPPORT
9905 + //Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue.
9906 + if ((pAd->OpMode == OPMODE_STA) && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL))
9907 + {
9908 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
9909 + }
9910 +#endif // CONFIG_STA_SUPPORT //
9911 + bAckRequired = FALSE;
9912 + }
9913 + else // BTYPE_MGMT or BTYPE_DATA(must be NULL frame)
9914 + {
9915 + //pAd->Sequence++;
9916 + //pHeader_802_11->Sequence = pAd->Sequence;
9917 +
9918 + if (pHeader_802_11->Addr1[0] & 0x01) // MULTICAST, BROADCAST
9919 + {
9920 + bAckRequired = FALSE;
9921 + pHeader_802_11->Duration = 0;
9922 + }
9923 + else
9924 + {
9925 + bAckRequired = TRUE;
9926 + pHeader_802_11->Duration = RTMPCalcDuration(pAd, MlmeRate, 14);
9927 + if (pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP)
9928 + {
9929 + bInsertTimestamp = TRUE;
9930 + }
9931 + }
9932 + }
9933 +
9934 + pHeader_802_11->Sequence = pAd->Sequence++;
9935 + if (pAd->Sequence >0xfff)
9936 + pAd->Sequence = 0;
9937 +
9938 + // Before radar detection done, mgmt frame can not be sent but probe req
9939 + // Because we need to use probe req to trigger driver to send probe req in passive scan
9940 + if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ)
9941 + && (pAd->CommonCfg.bIEEE80211H == 1)
9942 + && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE))
9943 + {
9944 + DBGPRINT(RT_DEBUG_ERROR,("MlmeHardTransmit --> radar detect not in normal mode !!!\n"));
9945 +// if (!IrqState)
9946 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9947 + return (NDIS_STATUS_FAILURE);
9948 + }
9949 +
9950 +#ifdef RT_BIG_ENDIAN
9951 + RTMPFrameEndianChange(pAd, (PUCHAR)pHeader_802_11, DIR_WRITE, FALSE);
9952 +#endif
9953 +
9954 + //
9955 + // fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET
9956 + // should always has only one ohysical buffer, and the whole frame size equals
9957 + // to the first scatter buffer size
9958 + //
9959 +
9960 + // Initialize TX Descriptor
9961 + // For inter-frame gap, the number is for this frame and next frame
9962 + // For MLME rate, we will fix as 2Mb to match other vendor's implement
9963 +// pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
9964 +
9965 +// management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not.
9966 + if (pMacEntry == NULL)
9967 + {
9968 + RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, FALSE, bAckRequired, FALSE,
9969 + 0, RESERVED_WCID, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), PID_MGMT, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
9970 + }
9971 + else
9972 + {
9973 + RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE,
9974 + bInsertTimestamp, FALSE, bAckRequired, FALSE,
9975 + 0, pMacEntry->Aid, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE),
9976 + pMacEntry->MaxHTPhyMode.field.MCS, 0,
9977 + (UCHAR)pMacEntry->MaxHTPhyMode.field.MCS,
9978 + IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode);
9979 + }
9980 +
9981 +#ifdef RT_BIG_ENDIAN
9982 + RTMPWIEndianChange((PUCHAR)pFirstTxWI, TYPE_TXWI);
9983 +#endif
9984 +
9985 + // Now do hardware-depened kick out.
9986 + HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen);
9987 +
9988 + // Make sure to release MGMT ring resource
9989 +// if (!IrqState)
9990 + RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
9991 + return NDIS_STATUS_SUCCESS;
9992 +}
9993 +
9994 +
9995 +/********************************************************************************
9996 +
9997 + New DeQueue Procedures.
9998 +
9999 + ********************************************************************************/
10000 +
10001 +#define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \
10002 + do{ \
10003 + if (bIntContext == FALSE) \
10004 + RTMP_IRQ_LOCK((lock), IrqFlags); \
10005 + }while(0)
10006 +
10007 +#define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \
10008 + do{ \
10009 + if (bIntContext == FALSE) \
10010 + RTMP_IRQ_UNLOCK((lock), IrqFlags); \
10011 + }while(0)
10012 +
10013 +
10014 +/*
10015 + ========================================================================
10016 + Tx Path design algorithm:
10017 + Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal),
10018 + Specific Packet Type. Following show the classification rule and policy for each kinds of packets.
10019 + Classification Rule=>
10020 + Multicast: (*addr1 & 0x01) == 0x01
10021 + Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc.
10022 + 11N Rate : If peer support HT
10023 + (1).AMPDU -- If TXBA is negotiated.
10024 + (2).AMSDU -- If AMSDU is capable for both peer and ourself.
10025 + *). AMSDU can embedded in a AMPDU, but now we didn't support it.
10026 + (3).Normal -- Other packets which send as 11n rate.
10027 +
10028 + B/G Rate : If peer is b/g only.
10029 + (1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6
10030 + (2).Normal -- Other packets which send as b/g rate.
10031 + Fragment:
10032 + The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment.
10033 +
10034 + Classified Packet Handle Rule=>
10035 + Multicast:
10036 + No ACK, //pTxBlk->bAckRequired = FALSE;
10037 + No WMM, //pTxBlk->bWMM = FALSE;
10038 + No piggyback, //pTxBlk->bPiggyBack = FALSE;
10039 + Force LowRate, //pTxBlk->bForceLowRate = TRUE;
10040 + Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use
10041 + the same policy to handle it.
10042 + Force LowRate, //pTxBlk->bForceLowRate = TRUE;
10043 +
10044 + 11N Rate :
10045 + No piggyback, //pTxBlk->bPiggyBack = FALSE;
10046 +
10047 + (1).AMSDU
10048 + pTxBlk->bWMM = TRUE;
10049 + (2).AMPDU
10050 + pTxBlk->bWMM = TRUE;
10051 + (3).Normal
10052 +
10053 + B/G Rate :
10054 + (1).ARALINK
10055 +
10056 + (2).Normal
10057 + ========================================================================
10058 +*/
10059 +static UCHAR TxPktClassification(
10060 + IN RTMP_ADAPTER *pAd,
10061 + IN PNDIS_PACKET pPacket)
10062 +{
10063 + UCHAR TxFrameType = TX_UNKOWN_FRAME;
10064 + UCHAR Wcid;
10065 + MAC_TABLE_ENTRY *pMacEntry = NULL;
10066 +#ifdef DOT11_N_SUPPORT
10067 + BOOLEAN bHTRate = FALSE;
10068 +#endif // DOT11_N_SUPPORT //
10069 +
10070 + Wcid = RTMP_GET_PACKET_WCID(pPacket);
10071 + if (Wcid == MCAST_WCID)
10072 + { // Handle for RA is Broadcast/Multicast Address.
10073 + return TX_MCAST_FRAME;
10074 + }
10075 +
10076 + // Handle for unicast packets
10077 + pMacEntry = &pAd->MacTab.Content[Wcid];
10078 + if (RTMP_GET_PACKET_LOWRATE(pPacket))
10079 + { // It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame
10080 + TxFrameType = TX_LEGACY_FRAME;
10081 + }
10082 +#ifdef DOT11_N_SUPPORT
10083 + else if (IS_HT_RATE(pMacEntry))
10084 + { // it's a 11n capable packet
10085 +
10086 + // Depends on HTPhyMode to check if the peer support the HTRate transmission.
10087 + // Currently didn't support A-MSDU embedded in A-MPDU
10088 + bHTRate = TRUE;
10089 + if (RTMP_GET_PACKET_MOREDATA(pPacket) || (pMacEntry->PsMode == PWR_SAVE))
10090 + TxFrameType = TX_LEGACY_FRAME;
10091 +#ifdef UAPSD_AP_SUPPORT
10092 + else if (RTMP_GET_PACKET_EOSP(pPacket))
10093 + TxFrameType = TX_LEGACY_FRAME;
10094 +#endif // UAPSD_AP_SUPPORT //
10095 + else if((pMacEntry->TXBAbitmap & (1<<(RTMP_GET_PACKET_UP(pPacket)))) != 0)
10096 + return TX_AMPDU_FRAME;
10097 + else if(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AMSDU_INUSED))
10098 + return TX_AMSDU_FRAME;
10099 + else
10100 + TxFrameType = TX_LEGACY_FRAME;
10101 + }
10102 +#endif // DOT11_N_SUPPORT //
10103 + else
10104 + { // it's a legacy b/g packet.
10105 + if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) &&
10106 + (RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) &&
10107 + (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))))
10108 + { // if peer support Ralink Aggregation, we use it.
10109 + TxFrameType = TX_RALINK_FRAME;
10110 + }
10111 + else
10112 + {
10113 + TxFrameType = TX_LEGACY_FRAME;
10114 + }
10115 + }
10116 +
10117 + // Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU.
10118 + if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1) && (TxFrameType == TX_LEGACY_FRAME))
10119 + TxFrameType = TX_FRAG_FRAME;
10120 +
10121 + return TxFrameType;
10122 +}
10123 +
10124 +
10125 +BOOLEAN RTMP_FillTxBlkInfo(
10126 + IN RTMP_ADAPTER *pAd,
10127 + IN TX_BLK *pTxBlk)
10128 +{
10129 + PACKET_INFO PacketInfo;
10130 + PNDIS_PACKET pPacket;
10131 + PMAC_TABLE_ENTRY pMacEntry = NULL;
10132 +
10133 + pPacket = pTxBlk->pPacket;
10134 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
10135 +
10136 + pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket);
10137 + pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket);
10138 + pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket);
10139 + pTxBlk->FrameGap = IFS_HTTXOP; // ASIC determine Frame Gap
10140 +
10141 + if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket))
10142 + TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame);
10143 + else
10144 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame);
10145 +
10146 + // Default to clear this flag
10147 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS);
10148 +
10149 +
10150 + if (pTxBlk->Wcid == MCAST_WCID)
10151 + {
10152 + pTxBlk->pMacEntry = NULL;
10153 + {
10154 +#ifdef MCAST_RATE_SPECIFIC
10155 + PUCHAR pDA = GET_OS_PKT_DATAPTR(pPacket);
10156 + if (((*pDA & 0x01) == 0x01) && (*pDA != 0xff))
10157 + pTxBlk->pTransmit = &pAd->CommonCfg.MCastPhyMode;
10158 + else
10159 +#endif // MCAST_RATE_SPECIFIC //
10160 + pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
10161 + }
10162 +
10163 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); // AckRequired = FALSE, when broadcast packet in Adhoc mode.
10164 + //TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate);
10165 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag);
10166 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
10167 + if (RTMP_GET_PACKET_MOREDATA(pPacket))
10168 + {
10169 + TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
10170 + }
10171 +
10172 + }
10173 + else
10174 + {
10175 + pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid];
10176 + pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode;
10177 +
10178 + pMacEntry = pTxBlk->pMacEntry;
10179 +
10180 +
10181 + // For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK.
10182 + if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK)
10183 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
10184 + else
10185 + TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired);
10186 +
10187 + {
10188 +
10189 +#ifdef CONFIG_STA_SUPPORT
10190 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
10191 + {
10192 +
10193 + // If support WMM, enable it.
10194 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
10195 + CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))
10196 + TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM);
10197 +
10198 +// if (pAd->StaCfg.bAutoTxRateSwitch)
10199 +// TX_BLK_SET_FLAG(pTxBlk, fTX_AutoRateSwitch);
10200 + }
10201 +#endif // CONFIG_STA_SUPPORT //
10202 + }
10203 +
10204 + if (pTxBlk->TxFrameType == TX_LEGACY_FRAME)
10205 + {
10206 + if ( (RTMP_GET_PACKET_LOWRATE(pPacket)) ||
10207 + ((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1)))
10208 + { // Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate.
10209 + pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
10210 +#ifdef DOT11_N_SUPPORT
10211 + // Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it???
10212 + if (IS_HT_STA(pTxBlk->pMacEntry) &&
10213 + (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET)) &&
10214 + ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RDG_CAPABLE)))
10215 + {
10216 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
10217 + TX_BLK_SET_FLAG(pTxBlk, fTX_bForceNonQoS);
10218 + }
10219 +#endif // DOT11_N_SUPPORT //
10220 + }
10221 +
10222 +#ifdef DOT11_N_SUPPORT
10223 + if ( (IS_HT_RATE(pMacEntry) == FALSE) &&
10224 + (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE)))
10225 + { // Currently piggy-back only support when peer is operate in b/g mode.
10226 + TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack);
10227 + }
10228 +#endif // DOT11_N_SUPPORT //
10229 +
10230 + if (RTMP_GET_PACKET_MOREDATA(pPacket))
10231 + {
10232 + TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
10233 + }
10234 +#ifdef UAPSD_AP_SUPPORT
10235 + if (RTMP_GET_PACKET_EOSP(pPacket))
10236 + {
10237 + TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM_UAPSD_EOSP);
10238 + }
10239 +#endif // UAPSD_AP_SUPPORT //
10240 + }
10241 + else if (pTxBlk->TxFrameType == TX_FRAG_FRAME)
10242 + {
10243 + TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag);
10244 + }
10245 +
10246 + pMacEntry->DebugTxCount++;
10247 + }
10248 +
10249 + return TRUE;
10250 +
10251 +FillTxBlkErr:
10252 + return FALSE;
10253 +}
10254 +
10255 +
10256 +BOOLEAN CanDoAggregateTransmit(
10257 + IN RTMP_ADAPTER *pAd,
10258 + IN NDIS_PACKET *pPacket,
10259 + IN TX_BLK *pTxBlk)
10260 +{
10261 +
10262 + //printk("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType);
10263 +
10264 + if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID)
10265 + return FALSE;
10266 +
10267 + if (RTMP_GET_PACKET_DHCP(pPacket) ||
10268 + RTMP_GET_PACKET_EAPOL(pPacket) ||
10269 + RTMP_GET_PACKET_WAI(pPacket))
10270 + return FALSE;
10271 +
10272 + if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) &&
10273 + ((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))> (RX_BUFFER_AGGRESIZE - 100)))
10274 + { // For AMSDU, allow the packets with total length < max-amsdu size
10275 + return FALSE;
10276 + }
10277 +
10278 + if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) &&
10279 + (pTxBlk->TxPacketList.Number == 2))
10280 + { // For RALINK-Aggregation, allow two frames in one batch.
10281 + return FALSE;
10282 + }
10283 +
10284 +#ifdef CONFIG_STA_SUPPORT
10285 + if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) // must be unicast to AP
10286 + return TRUE;
10287 + else
10288 +#endif // CONFIG_STA_SUPPORT //
10289 + return FALSE;
10290 +
10291 +}
10292 +
10293 +
10294 +/*
10295 + ========================================================================
10296 +
10297 + Routine Description:
10298 + To do the enqueue operation and extract the first item of waiting
10299 + list. If a number of available shared memory segments could meet
10300 + the request of extracted item, the extracted item will be fragmented
10301 + into shared memory segments.
10302 +
10303 + Arguments:
10304 + pAd Pointer to our adapter
10305 + pQueue Pointer to Waiting Queue
10306 +
10307 + Return Value:
10308 + None
10309 +
10310 + IRQL = DISPATCH_LEVEL
10311 +
10312 + Note:
10313 +
10314 + ========================================================================
10315 +*/
10316 +VOID RTMPDeQueuePacket(
10317 + IN PRTMP_ADAPTER pAd,
10318 + IN BOOLEAN bIntContext,
10319 + IN UCHAR QIdx, /* BulkOutPipeId */
10320 + IN UCHAR Max_Tx_Packets)
10321 +{
10322 + PQUEUE_ENTRY pEntry = NULL;
10323 + PNDIS_PACKET pPacket;
10324 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
10325 + UCHAR Count=0;
10326 + PQUEUE_HEADER pQueue;
10327 + ULONG FreeNumber[NUM_OF_TX_RING];
10328 + UCHAR QueIdx, sQIdx, eQIdx;
10329 + unsigned long IrqFlags = 0;
10330 + BOOLEAN hasTxDesc = FALSE;
10331 + TX_BLK TxBlk;
10332 + TX_BLK *pTxBlk;
10333 +
10334 +#ifdef DBG_DIAGNOSE
10335 + BOOLEAN firstRound;
10336 + RtmpDiagStruct *pDiagStruct = &pAd->DiagStruct;
10337 +#endif
10338 +
10339 +
10340 + if (QIdx == NUM_OF_TX_RING)
10341 + {
10342 + sQIdx = 0;
10343 +//PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
10344 +#ifdef CONFIG_STA_SUPPORT
10345 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
10346 + eQIdx = 3; // 4 ACs, start from 0.
10347 +#endif // CONFIG_STA_SUPPORT //
10348 + }
10349 + else
10350 + {
10351 + sQIdx = eQIdx = QIdx;
10352 + }
10353 +
10354 + for (QueIdx=sQIdx; QueIdx <= eQIdx; QueIdx++)
10355 + {
10356 + Count=0;
10357 +
10358 + RT28XX_START_DEQUEUE(pAd, QueIdx, IrqFlags);
10359 +
10360 +#ifdef DBG_DIAGNOSE
10361 + firstRound = ((QueIdx == 0) ? TRUE : FALSE);
10362 +#endif // DBG_DIAGNOSE //
10363 +
10364 + while (1)
10365 + {
10366 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS |
10367 + fRTMP_ADAPTER_RADIO_OFF |
10368 + fRTMP_ADAPTER_RESET_IN_PROGRESS |
10369 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
10370 + fRTMP_ADAPTER_NIC_NOT_EXIST))))
10371 + {
10372 + RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
10373 + return;
10374 + }
10375 +
10376 + if (Count >= Max_Tx_Packets)
10377 + break;
10378 +
10379 + DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10380 + if (&pAd->TxSwQueue[QueIdx] == NULL)
10381 + {
10382 +#ifdef DBG_DIAGNOSE
10383 + if (firstRound == TRUE)
10384 + pDiagStruct->TxSWQueCnt[pDiagStruct->ArrayCurIdx][0]++;
10385 +#endif // DBG_DIAGNOSE //
10386 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10387 + break;
10388 + }
10389 +
10390 +
10391 + // probe the Queue Head
10392 + pQueue = &pAd->TxSwQueue[QueIdx];
10393 + if ((pEntry = pQueue->Head) == NULL)
10394 + {
10395 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10396 + break;
10397 + }
10398 +
10399 + pTxBlk = &TxBlk;
10400 + NdisZeroMemory((PUCHAR)pTxBlk, sizeof(TX_BLK));
10401 + //InitializeQueueHeader(&pTxBlk->TxPacketList); // Didn't need it because we already memzero it.
10402 + pTxBlk->QueIdx = QueIdx;
10403 +
10404 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10405 +
10406 + // Early check to make sure we have enoguh Tx Resource.
10407 + hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket);
10408 + if (!hasTxDesc)
10409 + {
10410 + pAd->PrivateInfo.TxRingFullCnt++;
10411 +
10412 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10413 +
10414 + break;
10415 + }
10416 +
10417 + pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket);
10418 + pEntry = RemoveHeadQueue(pQueue);
10419 + pTxBlk->TotalFrameNum++;
10420 + pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary
10421 + pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
10422 + pTxBlk->pPacket = pPacket;
10423 + InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
10424 +
10425 + if (pTxBlk->TxFrameType == TX_RALINK_FRAME || pTxBlk->TxFrameType == TX_AMSDU_FRAME)
10426 + {
10427 + // Enhance SW Aggregation Mechanism
10428 + if (NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, FreeNumber[QueIdx], pTxBlk->TxFrameType))
10429 + {
10430 + InsertHeadQueue(pQueue, PACKET_TO_QUEUE_ENTRY(pPacket));
10431 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10432 + break;
10433 + }
10434 +
10435 + do{
10436 + if((pEntry = pQueue->Head) == NULL)
10437 + break;
10438 +
10439 + // For TX_AMSDU_FRAME/TX_RALINK_FRAME, Need to check if next pakcet can do aggregation.
10440 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10441 + FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx);
10442 + hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket);
10443 + if ((hasTxDesc == FALSE) || (CanDoAggregateTransmit(pAd, pPacket, pTxBlk) == FALSE))
10444 + break;
10445 +
10446 + //Remove the packet from the TxSwQueue and insert into pTxBlk
10447 + pEntry = RemoveHeadQueue(pQueue);
10448 + ASSERT(pEntry);
10449 + pPacket = QUEUE_ENTRY_TO_PKT(pEntry);
10450 + pTxBlk->TotalFrameNum++;
10451 + pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary
10452 + pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
10453 + InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket));
10454 + }while(1);
10455 +
10456 + if (pTxBlk->TxPacketList.Number == 1)
10457 + pTxBlk->TxFrameType = TX_LEGACY_FRAME;
10458 + }
10459 +
10460 +#ifdef RT2870
10461 + DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
10462 +#endif // RT2870 //
10463 +
10464 + Count += pTxBlk->TxPacketList.Number;
10465 +
10466 + // Do HardTransmit now.
10467 +#ifdef CONFIG_STA_SUPPORT
10468 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
10469 + Status = STAHardTransmit(pAd, pTxBlk, QueIdx);
10470 +#endif // CONFIG_STA_SUPPORT //
10471 + }
10472 +
10473 + RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
10474 +
10475 +#ifdef RT2870
10476 + if (!hasTxDesc)
10477 + RTUSBKickBulkOut(pAd);
10478 +#endif // RT2870 //
10479 +
10480 +#ifdef BLOCK_NET_IF
10481 + if ((pAd->blockQueueTab[QueIdx].SwTxQueueBlockFlag == TRUE)
10482 + && (pAd->TxSwQueue[QueIdx].Number < 1))
10483 + {
10484 + releaseNetIf(&pAd->blockQueueTab[QueIdx]);
10485 + }
10486 +#endif // BLOCK_NET_IF //
10487 +
10488 + }
10489 +
10490 +}
10491 +
10492 +
10493 +/*
10494 + ========================================================================
10495 +
10496 + Routine Description:
10497 + Calculates the duration which is required to transmit out frames
10498 + with given size and specified rate.
10499 +
10500 + Arguments:
10501 + pAd Pointer to our adapter
10502 + Rate Transmit rate
10503 + Size Frame size in units of byte
10504 +
10505 + Return Value:
10506 + Duration number in units of usec
10507 +
10508 + IRQL = PASSIVE_LEVEL
10509 + IRQL = DISPATCH_LEVEL
10510 +
10511 + Note:
10512 +
10513 + ========================================================================
10514 +*/
10515 +USHORT RTMPCalcDuration(
10516 + IN PRTMP_ADAPTER pAd,
10517 + IN UCHAR Rate,
10518 + IN ULONG Size)
10519 +{
10520 + ULONG Duration = 0;
10521 +
10522 + if (Rate < RATE_FIRST_OFDM_RATE) // CCK
10523 + {
10524 + if ((Rate > RATE_1) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED))
10525 + Duration = 96; // 72+24 preamble+plcp
10526 + else
10527 + Duration = 192; // 144+48 preamble+plcp
10528 +
10529 + Duration += (USHORT)((Size << 4) / RateIdTo500Kbps[Rate]);
10530 + if ((Size << 4) % RateIdTo500Kbps[Rate])
10531 + Duration ++;
10532 + }
10533 + else if (Rate <= RATE_LAST_OFDM_RATE)// OFDM rates
10534 + {
10535 + Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension
10536 + Duration += 4 * (USHORT)((11 + Size * 4) / RateIdTo500Kbps[Rate]);
10537 + if ((11 + Size * 4) % RateIdTo500Kbps[Rate])
10538 + Duration += 4;
10539 + }
10540 + else //mimo rate
10541 + {
10542 + Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension
10543 + }
10544 +
10545 + return (USHORT)Duration;
10546 +}
10547 +
10548 +
10549 +/*
10550 + ========================================================================
10551 +
10552 + Routine Description:
10553 + Calculates the duration which is required to transmit out frames
10554 + with given size and specified rate.
10555 +
10556 + Arguments:
10557 + pTxWI Pointer to head of each MPDU to HW.
10558 + Ack Setting for Ack requirement bit
10559 + Fragment Setting for Fragment bit
10560 + RetryMode Setting for retry mode
10561 + Ifs Setting for IFS gap
10562 + Rate Setting for transmit rate
10563 + Service Setting for service
10564 + Length Frame length
10565 + TxPreamble Short or Long preamble when using CCK rates
10566 + QueIdx - 0-3, according to 802.11e/d4.4 June/2003
10567 +
10568 + Return Value:
10569 + None
10570 +
10571 + IRQL = PASSIVE_LEVEL
10572 + IRQL = DISPATCH_LEVEL
10573 +
10574 + See also : BASmartHardTransmit() !!!
10575 +
10576 + ========================================================================
10577 +*/
10578 +VOID RTMPWriteTxWI(
10579 + IN PRTMP_ADAPTER pAd,
10580 + IN PTXWI_STRUC pOutTxWI,
10581 + IN BOOLEAN FRAG,
10582 + IN BOOLEAN CFACK,
10583 + IN BOOLEAN InsTimestamp,
10584 + IN BOOLEAN AMPDU,
10585 + IN BOOLEAN Ack,
10586 + IN BOOLEAN NSeq, // HW new a sequence.
10587 + IN UCHAR BASize,
10588 + IN UCHAR WCID,
10589 + IN ULONG Length,
10590 + IN UCHAR PID,
10591 + IN UCHAR TID,
10592 + IN UCHAR TxRate,
10593 + IN UCHAR Txopmode,
10594 + IN BOOLEAN CfAck,
10595 + IN HTTRANSMIT_SETTING *pTransmit)
10596 +{
10597 + PMAC_TABLE_ENTRY pMac = NULL;
10598 + TXWI_STRUC TxWI;
10599 + PTXWI_STRUC pTxWI;
10600 +
10601 + if (WCID < MAX_LEN_OF_MAC_TABLE)
10602 + pMac = &pAd->MacTab.Content[WCID];
10603 +
10604 + //
10605 + // Always use Long preamble before verifiation short preamble functionality works well.
10606 + // Todo: remove the following line if short preamble functionality works
10607 + //
10608 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10609 + NdisZeroMemory(&TxWI, TXWI_SIZE);
10610 + pTxWI = &TxWI;
10611 +
10612 + pTxWI->FRAG= FRAG;
10613 +
10614 + pTxWI->CFACK = CFACK;
10615 + pTxWI->TS= InsTimestamp;
10616 + pTxWI->AMPDU = AMPDU;
10617 + pTxWI->ACK = Ack;
10618 + pTxWI->txop= Txopmode;
10619 +
10620 + pTxWI->NSEQ = NSeq;
10621 + // John tune the performace with Intel Client in 20 MHz performance
10622 +#ifdef DOT11_N_SUPPORT
10623 + BASize = pAd->CommonCfg.TxBASize;
10624 +
10625 + if( BASize >7 )
10626 + BASize =7;
10627 + pTxWI->BAWinSize = BASize;
10628 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10629 + pTxWI->STBC = pTransmit->field.STBC;
10630 +#endif // DOT11_N_SUPPORT //
10631 +
10632 + pTxWI->WirelessCliID = WCID;
10633 + pTxWI->MPDUtotalByteCount = Length;
10634 + pTxWI->PacketId = PID;
10635 +
10636 + // If CCK or OFDM, BW must be 20
10637 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10638 +#ifdef DOT11N_DRAFT3
10639 + if (pTxWI->BW)
10640 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10641 +#endif // DOT11N_DRAFT3 //
10642 +
10643 + pTxWI->MCS = pTransmit->field.MCS;
10644 + pTxWI->PHYMODE = pTransmit->field.MODE;
10645 + pTxWI->CFACK = CfAck;
10646 +
10647 +#ifdef DOT11_N_SUPPORT
10648 + if (pMac)
10649 + {
10650 + if (pAd->CommonCfg.bMIMOPSEnable)
10651 + {
10652 + if ((pMac->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10653 + {
10654 + // Dynamic MIMO Power Save Mode
10655 + pTxWI->MIMOps = 1;
10656 + }
10657 + else if (pMac->MmpsMode == MMPS_STATIC)
10658 + {
10659 + // Static MIMO Power Save Mode
10660 + if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7)
10661 + {
10662 + pTxWI->MCS = 7;
10663 + pTxWI->MIMOps = 0;
10664 + }
10665 + }
10666 + }
10667 + //pTxWI->MIMOps = (pMac->PsMode == PWR_MMPS)? 1:0;
10668 + if (pMac->bIAmBadAtheros && (pMac->WepStatus != Ndis802_11WEPDisabled))
10669 + {
10670 + pTxWI->MpduDensity = 7;
10671 + }
10672 + else
10673 + {
10674 + pTxWI->MpduDensity = pMac->MpduDensity;
10675 + }
10676 + }
10677 +#endif // DOT11_N_SUPPORT //
10678 +
10679 + pTxWI->PacketId = pTxWI->MCS;
10680 + NdisMoveMemory(pOutTxWI, &TxWI, sizeof(TXWI_STRUC));
10681 +}
10682 +
10683 +
10684 +VOID RTMPWriteTxWI_Data(
10685 + IN PRTMP_ADAPTER pAd,
10686 + IN OUT PTXWI_STRUC pTxWI,
10687 + IN TX_BLK *pTxBlk)
10688 +{
10689 + HTTRANSMIT_SETTING *pTransmit;
10690 + PMAC_TABLE_ENTRY pMacEntry;
10691 +#ifdef DOT11_N_SUPPORT
10692 + UCHAR BASize;
10693 +#endif // DOT11_N_SUPPORT //
10694 +
10695 +
10696 + ASSERT(pTxWI);
10697 +
10698 + pTransmit = pTxBlk->pTransmit;
10699 + pMacEntry = pTxBlk->pMacEntry;
10700 +
10701 +
10702 + //
10703 + // Always use Long preamble before verifiation short preamble functionality works well.
10704 + // Todo: remove the following line if short preamble functionality works
10705 + //
10706 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10707 + NdisZeroMemory(pTxWI, TXWI_SIZE);
10708 +
10709 + pTxWI->FRAG = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag);
10710 + pTxWI->ACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAckRequired);
10711 + pTxWI->txop = pTxBlk->FrameGap;
10712 +
10713 +#ifdef CONFIG_STA_SUPPORT
10714 +#ifdef QOS_DLS_SUPPORT
10715 + if (pMacEntry &&
10716 + (pAd->StaCfg.BssType == BSS_INFRA) &&
10717 + (pMacEntry->ValidAsDls == TRUE))
10718 + pTxWI->WirelessCliID = BSSID_WCID;
10719 + else
10720 +#endif // QOS_DLS_SUPPORT //
10721 +#endif // CONFIG_STA_SUPPORT //
10722 + pTxWI->WirelessCliID = pTxBlk->Wcid;
10723 +
10724 + pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
10725 + pTxWI->CFACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bPiggyBack);
10726 +
10727 + // If CCK or OFDM, BW must be 20
10728 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10729 +#ifdef DOT11_N_SUPPORT
10730 +#ifdef DOT11N_DRAFT3
10731 + if (pTxWI->BW)
10732 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10733 +#endif // DOT11N_DRAFT3 //
10734 + pTxWI->AMPDU = ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) ? TRUE : FALSE);
10735 +
10736 + // John tune the performace with Intel Client in 20 MHz performance
10737 + BASize = pAd->CommonCfg.TxBASize;
10738 + if((pTxBlk->TxFrameType == TX_AMPDU_FRAME) && (pMacEntry))
10739 + {
10740 + UCHAR RABAOriIdx = 0; //The RA's BA Originator table index.
10741 +
10742 + RABAOriIdx = pTxBlk->pMacEntry->BAOriWcidArray[pTxBlk->UserPriority];
10743 + BASize = pAd->BATable.BAOriEntry[RABAOriIdx].BAWinSize;
10744 + }
10745 +
10746 + pTxWI->TxBF = pTransmit->field.TxBF;
10747 + pTxWI->BAWinSize = BASize;
10748 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10749 + pTxWI->STBC = pTransmit->field.STBC;
10750 +#endif // DOT11_N_SUPPORT //
10751 +
10752 + pTxWI->MCS = pTransmit->field.MCS;
10753 + pTxWI->PHYMODE = pTransmit->field.MODE;
10754 +
10755 +#ifdef DOT11_N_SUPPORT
10756 + if (pMacEntry)
10757 + {
10758 + if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10759 + {
10760 + // Dynamic MIMO Power Save Mode
10761 + pTxWI->MIMOps = 1;
10762 + }
10763 + else if (pMacEntry->MmpsMode == MMPS_STATIC)
10764 + {
10765 + // Static MIMO Power Save Mode
10766 + if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7)
10767 + {
10768 + pTxWI->MCS = 7;
10769 + pTxWI->MIMOps = 0;
10770 + }
10771 + }
10772 +
10773 + if (pMacEntry->bIAmBadAtheros && (pMacEntry->WepStatus != Ndis802_11WEPDisabled))
10774 + {
10775 + pTxWI->MpduDensity = 7;
10776 + }
10777 + else
10778 + {
10779 + pTxWI->MpduDensity = pMacEntry->MpduDensity;
10780 + }
10781 + }
10782 +#endif // DOT11_N_SUPPORT //
10783 +
10784 +#ifdef DBG_DIAGNOSE
10785 + if (pTxBlk->QueIdx== 0)
10786 + {
10787 + pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++;
10788 + pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++;
10789 + }
10790 +#endif // DBG_DIAGNOSE //
10791 +
10792 + // for rate adapation
10793 + pTxWI->PacketId = pTxWI->MCS;
10794 +#ifdef INF_AMAZON_SE
10795 +/*Iverson patch for WMM A5-T07 ,WirelessStaToWirelessSta do not bulk out aggregate */
10796 + if( RTMP_GET_PACKET_NOBULKOUT(pTxBlk->pPacket))
10797 + {
10798 + if(pTxWI->PHYMODE == MODE_CCK)
10799 + {
10800 + pTxWI->PacketId = 6;
10801 + }
10802 + }
10803 +#endif // INF_AMAZON_SE //
10804 +}
10805 +
10806 +
10807 +VOID RTMPWriteTxWI_Cache(
10808 + IN PRTMP_ADAPTER pAd,
10809 + IN OUT PTXWI_STRUC pTxWI,
10810 + IN TX_BLK *pTxBlk)
10811 +{
10812 + PHTTRANSMIT_SETTING /*pTxHTPhyMode,*/ pTransmit;
10813 + PMAC_TABLE_ENTRY pMacEntry;
10814 +
10815 + //
10816 + // update TXWI
10817 + //
10818 + pMacEntry = pTxBlk->pMacEntry;
10819 + pTransmit = pTxBlk->pTransmit;
10820 +
10821 + //if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED))
10822 + //if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pMacEntry))
10823 + //if (TX_BLK_TEST_FLAG(pTxBlk, fTX_AutoRateSwitch))
10824 + if (pMacEntry->bAutoTxRateSwitch)
10825 + {
10826 + pTxWI->txop = IFS_HTTXOP;
10827 +
10828 + // If CCK or OFDM, BW must be 20
10829 + pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
10830 + pTxWI->ShortGI = pTransmit->field.ShortGI;
10831 + pTxWI->STBC = pTransmit->field.STBC;
10832 +
10833 + pTxWI->MCS = pTransmit->field.MCS;
10834 + pTxWI->PHYMODE = pTransmit->field.MODE;
10835 +
10836 + // set PID for TxRateSwitching
10837 + pTxWI->PacketId = pTransmit->field.MCS;
10838 + }
10839 +
10840 +#ifdef DOT11_N_SUPPORT
10841 + pTxWI->AMPDU = ((pMacEntry->NoBADataCountDown == 0) ? TRUE: FALSE);
10842 + pTxWI->MIMOps = 0;
10843 +
10844 +#ifdef DOT11N_DRAFT3
10845 + if (pTxWI->BW)
10846 + pTxWI->BW = (pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth == 0) ? (BW_20) : (pTransmit->field.BW);
10847 +#endif // DOT11N_DRAFT3 //
10848 +
10849 + if (pAd->CommonCfg.bMIMOPSEnable)
10850 + {
10851 + // MIMO Power Save Mode
10852 + if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7))
10853 + {
10854 + // Dynamic MIMO Power Save Mode
10855 + pTxWI->MIMOps = 1;
10856 + }
10857 + else if (pMacEntry->MmpsMode == MMPS_STATIC)
10858 + {
10859 + // Static MIMO Power Save Mode
10860 + if ((pTransmit->field.MODE >= MODE_HTMIX) && (pTransmit->field.MCS > 7))
10861 + {
10862 + pTxWI->MCS = 7;
10863 + pTxWI->MIMOps = 0;
10864 + }
10865 + }
10866 + }
10867 +#endif // DOT11_N_SUPPORT //
10868 +
10869 +#ifdef DBG_DIAGNOSE
10870 + if (pTxBlk->QueIdx== 0)
10871 + {
10872 + pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++;
10873 + pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++;
10874 + }
10875 +#endif // DBG_DIAGNOSE //
10876 +
10877 + pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
10878 +
10879 +}
10880 +
10881 +
10882 +/*
10883 + ========================================================================
10884 +
10885 + Routine Description:
10886 + Calculates the duration which is required to transmit out frames
10887 + with given size and specified rate.
10888 +
10889 + Arguments:
10890 + pTxD Pointer to transmit descriptor
10891 + Ack Setting for Ack requirement bit
10892 + Fragment Setting for Fragment bit
10893 + RetryMode Setting for retry mode
10894 + Ifs Setting for IFS gap
10895 + Rate Setting for transmit rate
10896 + Service Setting for service
10897 + Length Frame length
10898 + TxPreamble Short or Long preamble when using CCK rates
10899 + QueIdx - 0-3, according to 802.11e/d4.4 June/2003
10900 +
10901 + Return Value:
10902 + None
10903 +
10904 + IRQL = PASSIVE_LEVEL
10905 + IRQL = DISPATCH_LEVEL
10906 +
10907 + ========================================================================
10908 +*/
10909 +VOID RTMPWriteTxDescriptor(
10910 + IN PRTMP_ADAPTER pAd,
10911 + IN PTXD_STRUC pTxD,
10912 + IN BOOLEAN bWIV,
10913 + IN UCHAR QueueSEL)
10914 +{
10915 + //
10916 + // Always use Long preamble before verifiation short preamble functionality works well.
10917 + // Todo: remove the following line if short preamble functionality works
10918 + //
10919 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
10920 +
10921 + pTxD->WIV = (bWIV) ? 1: 0;
10922 + pTxD->QSEL= (QueueSEL);
10923 + if (pAd->bGenOneHCCA == TRUE)
10924 + pTxD->QSEL= FIFO_HCCA;
10925 + pTxD->DMADONE = 0;
10926 +}
10927 +
10928 +
10929 +// should be called only when -
10930 +// 1. MEADIA_CONNECTED
10931 +// 2. AGGREGATION_IN_USED
10932 +// 3. Fragmentation not in used
10933 +// 4. either no previous frame (pPrevAddr1=NULL) .OR. previoud frame is aggregatible
10934 +BOOLEAN TxFrameIsAggregatible(
10935 + IN PRTMP_ADAPTER pAd,
10936 + IN PUCHAR pPrevAddr1,
10937 + IN PUCHAR p8023hdr)
10938 +{
10939 +
10940 + // can't aggregate EAPOL (802.1x) frame
10941 + if ((p8023hdr[12] == 0x88) && (p8023hdr[13] == 0x8e))
10942 + return FALSE;
10943 +
10944 + // can't aggregate multicast/broadcast frame
10945 + if (p8023hdr[0] & 0x01)
10946 + return FALSE;
10947 +
10948 + if (INFRA_ON(pAd)) // must be unicast to AP
10949 + return TRUE;
10950 + else if ((pPrevAddr1 == NULL) || MAC_ADDR_EQUAL(pPrevAddr1, p8023hdr)) // unicast to same STA
10951 + return TRUE;
10952 + else
10953 + return FALSE;
10954 +}
10955 +
10956 +
10957 +/*
10958 + ========================================================================
10959 +
10960 + Routine Description:
10961 + Check the MSDU Aggregation policy
10962 + 1.HT aggregation is A-MSDU
10963 + 2.legaacy rate aggregation is software aggregation by Ralink.
10964 +
10965 + Arguments:
10966 +
10967 + Return Value:
10968 +
10969 + Note:
10970 +
10971 + ========================================================================
10972 +*/
10973 +BOOLEAN PeerIsAggreOn(
10974 + IN PRTMP_ADAPTER pAd,
10975 + IN ULONG TxRate,
10976 + IN PMAC_TABLE_ENTRY pMacEntry)
10977 +{
10978 + ULONG AFlags = (fCLIENT_STATUS_AMSDU_INUSED | fCLIENT_STATUS_AGGREGATION_CAPABLE);
10979 +
10980 + if (pMacEntry != NULL && CLIENT_STATUS_TEST_FLAG(pMacEntry, AFlags))
10981 + {
10982 +#ifdef DOT11_N_SUPPORT
10983 + if (pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
10984 + {
10985 + return TRUE;
10986 + }
10987 +#endif // DOT11_N_SUPPORT //
10988 +
10989 +#ifdef AGGREGATION_SUPPORT
10990 + if (TxRate >= RATE_6 && pAd->CommonCfg.bAggregationCapable && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE))))
10991 + { // legacy Ralink Aggregation support
10992 + return TRUE;
10993 + }
10994 +#endif // AGGREGATION_SUPPORT //
10995 + }
10996 +
10997 + return FALSE;
10998 +
10999 +}
11000 +
11001 +
11002 +/*
11003 + ========================================================================
11004 +
11005 + Routine Description:
11006 + Check and fine the packet waiting in SW queue with highest priority
11007 +
11008 + Arguments:
11009 + pAd Pointer to our adapter
11010 +
11011 + Return Value:
11012 + pQueue Pointer to Waiting Queue
11013 +
11014 + IRQL = DISPATCH_LEVEL
11015 +
11016 + Note:
11017 +
11018 + ========================================================================
11019 +*/
11020 +PQUEUE_HEADER RTMPCheckTxSwQueue(
11021 + IN PRTMP_ADAPTER pAd,
11022 + OUT PUCHAR pQueIdx)
11023 +{
11024 +
11025 + ULONG Number;
11026 + // 2004-11-15 to be removed. test aggregation only
11027 +// if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) && (*pNumber < 2))
11028 +// return NULL;
11029 +
11030 + Number = pAd->TxSwQueue[QID_AC_BK].Number
11031 + + pAd->TxSwQueue[QID_AC_BE].Number
11032 + + pAd->TxSwQueue[QID_AC_VI].Number
11033 + + pAd->TxSwQueue[QID_AC_VO].Number
11034 + + pAd->TxSwQueue[QID_HCCA].Number;
11035 +
11036 + if (pAd->TxSwQueue[QID_AC_VO].Head != NULL)
11037 + {
11038 + *pQueIdx = QID_AC_VO;
11039 + return (&pAd->TxSwQueue[QID_AC_VO]);
11040 + }
11041 + else if (pAd->TxSwQueue[QID_AC_VI].Head != NULL)
11042 + {
11043 + *pQueIdx = QID_AC_VI;
11044 + return (&pAd->TxSwQueue[QID_AC_VI]);
11045 + }
11046 + else if (pAd->TxSwQueue[QID_AC_BE].Head != NULL)
11047 + {
11048 + *pQueIdx = QID_AC_BE;
11049 + return (&pAd->TxSwQueue[QID_AC_BE]);
11050 + }
11051 + else if (pAd->TxSwQueue[QID_AC_BK].Head != NULL)
11052 + {
11053 + *pQueIdx = QID_AC_BK;
11054 + return (&pAd->TxSwQueue[QID_AC_BK]);
11055 + }
11056 + else if (pAd->TxSwQueue[QID_HCCA].Head != NULL)
11057 + {
11058 + *pQueIdx = QID_HCCA;
11059 + return (&pAd->TxSwQueue[QID_HCCA]);
11060 + }
11061 +
11062 + // No packet pending in Tx Sw queue
11063 + *pQueIdx = QID_AC_BK;
11064 +
11065 + return (NULL);
11066 +}
11067 +
11068 +
11069 +
11070 +/*
11071 + ========================================================================
11072 +
11073 + Routine Description:
11074 + Suspend MSDU transmission
11075 +
11076 + Arguments:
11077 + pAd Pointer to our adapter
11078 +
11079 + Return Value:
11080 + None
11081 +
11082 + Note:
11083 +
11084 + ========================================================================
11085 +*/
11086 +VOID RTMPSuspendMsduTransmission(
11087 + IN PRTMP_ADAPTER pAd)
11088 +{
11089 + DBGPRINT(RT_DEBUG_TRACE,("SCANNING, suspend MSDU transmission ...\n"));
11090 +
11091 +
11092 + //
11093 + // Before BSS_SCAN_IN_PROGRESS, we need to keep Current R66 value and
11094 + // use Lowbound as R66 value on ScanNextChannel(...)
11095 + //
11096 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
11097 +
11098 + // set BBP_R66 to 0x30/0x40 when scanning (AsicSwitchChannel will set R66 according to channel when scanning)
11099 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x26 + GET_LNA_GAIN(pAd)));
11100 + RTMPSetAGCInitValue(pAd, BW_20);
11101 +
11102 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
11103 + //RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x000f0000); // abort all TX rings
11104 +}
11105 +
11106 +
11107 +/*
11108 + ========================================================================
11109 +
11110 + Routine Description:
11111 + Resume MSDU transmission
11112 +
11113 + Arguments:
11114 + pAd Pointer to our adapter
11115 +
11116 + Return Value:
11117 + None
11118 +
11119 + IRQL = DISPATCH_LEVEL
11120 +
11121 + Note:
11122 +
11123 + ========================================================================
11124 +*/
11125 +VOID RTMPResumeMsduTransmission(
11126 + IN PRTMP_ADAPTER pAd)
11127 +{
11128 +// UCHAR IrqState;
11129 +
11130 + DBGPRINT(RT_DEBUG_TRACE,("SCAN done, resume MSDU transmission ...\n"));
11131 +
11132 +
11133 + // After finish BSS_SCAN_IN_PROGRESS, we need to restore Current R66 value
11134 + // R66 should not be 0
11135 + if (pAd->BbpTuning.R66CurrentValue == 0)
11136 + {
11137 + pAd->BbpTuning.R66CurrentValue = 0x38;
11138 + DBGPRINT_ERR(("RTMPResumeMsduTransmission, R66CurrentValue=0...\n"));
11139 + }
11140 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, pAd->BbpTuning.R66CurrentValue);
11141 +
11142 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
11143 +// sample, for IRQ LOCK to SEM LOCK
11144 +// IrqState = pAd->irq_disabled;
11145 +// if (IrqState)
11146 +// RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS);
11147 +// else
11148 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
11149 +}
11150 +
11151 +
11152 +UINT deaggregate_AMSDU_announce(
11153 + IN PRTMP_ADAPTER pAd,
11154 + PNDIS_PACKET pPacket,
11155 + IN PUCHAR pData,
11156 + IN ULONG DataSize)
11157 +{
11158 + USHORT PayloadSize;
11159 + USHORT SubFrameSize;
11160 + PHEADER_802_3 pAMSDUsubheader;
11161 + UINT nMSDU;
11162 + UCHAR Header802_3[14];
11163 +
11164 + PUCHAR pPayload, pDA, pSA, pRemovedLLCSNAP;
11165 + PNDIS_PACKET pClonePacket;
11166 +
11167 +
11168 +
11169 + nMSDU = 0;
11170 +
11171 + while (DataSize > LENGTH_802_3)
11172 + {
11173 +
11174 + nMSDU++;
11175 +
11176 + //hex_dump("subheader", pData, 64);
11177 + pAMSDUsubheader = (PHEADER_802_3)pData;
11178 + //pData += LENGTH_802_3;
11179 + PayloadSize = pAMSDUsubheader->Octet[1] + (pAMSDUsubheader->Octet[0]<<8);
11180 + SubFrameSize = PayloadSize + LENGTH_802_3;
11181 +
11182 +
11183 + if ((DataSize < SubFrameSize) || (PayloadSize > 1518 ))
11184 + {
11185 + break;
11186 + }
11187 +
11188 + //printk("%d subframe: Size = %d\n", nMSDU, PayloadSize);
11189 +
11190 + pPayload = pData + LENGTH_802_3;
11191 + pDA = pData;
11192 + pSA = pData + MAC_ADDR_LEN;
11193 +
11194 + // convert to 802.3 header
11195 + CONVERT_TO_802_3(Header802_3, pDA, pSA, pPayload, PayloadSize, pRemovedLLCSNAP);
11196 +
11197 +#ifdef CONFIG_STA_SUPPORT
11198 + if ((Header802_3[12] == 0x88) && (Header802_3[13] == 0x8E) )
11199 + {
11200 + // avoid local heap overflow, use dyanamic allocation
11201 + MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
11202 + memmove(Elem->Msg+(LENGTH_802_11 + LENGTH_802_1_H), pPayload, PayloadSize);
11203 + Elem->MsgLen = LENGTH_802_11 + LENGTH_802_1_H + PayloadSize;
11204 + WpaEAPOLKeyAction(pAd, Elem);
11205 + kfree(Elem);
11206 + }
11207 +#endif // CONFIG_STA_SUPPORT //
11208 +
11209 +#ifdef CONFIG_STA_SUPPORT
11210 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11211 + {
11212 + if (pRemovedLLCSNAP)
11213 + {
11214 + pPayload -= LENGTH_802_3;
11215 + PayloadSize += LENGTH_802_3;
11216 + NdisMoveMemory(pPayload, &Header802_3[0], LENGTH_802_3);
11217 + }
11218 + }
11219 +#endif // CONFIG_STA_SUPPORT //
11220 +
11221 + pClonePacket = ClonePacket(pAd, pPacket, pPayload, PayloadSize);
11222 + if (pClonePacket)
11223 + {
11224 +#ifdef CONFIG_STA_SUPPORT
11225 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11226 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pClonePacket, RTMP_GET_PACKET_IF(pPacket));
11227 +#endif // CONFIG_STA_SUPPORT //
11228 + }
11229 +
11230 +
11231 + // A-MSDU has padding to multiple of 4 including subframe header.
11232 + // align SubFrameSize up to multiple of 4
11233 + SubFrameSize = (SubFrameSize+3)&(~0x3);
11234 +
11235 +
11236 + if (SubFrameSize > 1528 || SubFrameSize < 32)
11237 + {
11238 + break;
11239 + }
11240 +
11241 + if (DataSize > SubFrameSize)
11242 + {
11243 + pData += SubFrameSize;
11244 + DataSize -= SubFrameSize;
11245 + }
11246 + else
11247 + {
11248 + // end of A-MSDU
11249 + DataSize = 0;
11250 + }
11251 + }
11252 +
11253 + // finally release original rx packet
11254 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
11255 +
11256 + return nMSDU;
11257 +}
11258 +
11259 +
11260 +UINT BA_Reorder_AMSDU_Annnounce(
11261 + IN PRTMP_ADAPTER pAd,
11262 + IN PNDIS_PACKET pPacket)
11263 +{
11264 + PUCHAR pData;
11265 + USHORT DataSize;
11266 + UINT nMSDU = 0;
11267 +
11268 + pData = (PUCHAR) GET_OS_PKT_DATAPTR(pPacket);
11269 + DataSize = (USHORT) GET_OS_PKT_LEN(pPacket);
11270 +
11271 + nMSDU = deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
11272 +
11273 + return nMSDU;
11274 +}
11275 +
11276 +
11277 +/*
11278 + ==========================================================================
11279 + Description:
11280 + Look up the MAC address in the MAC table. Return NULL if not found.
11281 + Return:
11282 + pEntry - pointer to the MAC entry; NULL is not found
11283 + ==========================================================================
11284 +*/
11285 +MAC_TABLE_ENTRY *MacTableLookup(
11286 + IN PRTMP_ADAPTER pAd,
11287 + PUCHAR pAddr)
11288 +{
11289 + ULONG HashIdx;
11290 + MAC_TABLE_ENTRY *pEntry = NULL;
11291 +
11292 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11293 + pEntry = pAd->MacTab.Hash[HashIdx];
11294 +
11295 + while (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsWDS || pEntry->ValidAsApCli || pEntry->ValidAsMesh))
11296 + {
11297 + if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
11298 + {
11299 + break;
11300 + }
11301 + else
11302 + pEntry = pEntry->pNext;
11303 + }
11304 +
11305 + return pEntry;
11306 +}
11307 +
11308 +MAC_TABLE_ENTRY *MacTableInsertEntry(
11309 + IN PRTMP_ADAPTER pAd,
11310 + IN PUCHAR pAddr,
11311 + IN UCHAR apidx,
11312 + IN BOOLEAN CleanAll)
11313 +{
11314 + UCHAR HashIdx;
11315 + int i, FirstWcid;
11316 + MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
11317 +// USHORT offset;
11318 +// ULONG addr;
11319 +
11320 + // if FULL, return
11321 + if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE)
11322 + return NULL;
11323 +
11324 + FirstWcid = 1;
11325 +#ifdef CONFIG_STA_SUPPORT
11326 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11327 + if (pAd->StaCfg.BssType == BSS_INFRA)
11328 + FirstWcid = 2;
11329 +#endif // CONFIG_STA_SUPPORT //
11330 +
11331 + // allocate one MAC entry
11332 + NdisAcquireSpinLock(&pAd->MacTabLock);
11333 + for (i = FirstWcid; i< MAX_LEN_OF_MAC_TABLE; i++) // skip entry#0 so that "entry index == AID" for fast lookup
11334 + {
11335 + // pick up the first available vacancy
11336 + if ((pAd->MacTab.Content[i].ValidAsCLI == FALSE) &&
11337 + (pAd->MacTab.Content[i].ValidAsWDS == FALSE) &&
11338 + (pAd->MacTab.Content[i].ValidAsApCli== FALSE) &&
11339 + (pAd->MacTab.Content[i].ValidAsMesh == FALSE)
11340 +#ifdef CONFIG_STA_SUPPORT
11341 +#ifdef QOS_DLS_SUPPORT
11342 + && (pAd->MacTab.Content[i].ValidAsDls == FALSE)
11343 +#endif // QOS_DLS_SUPPORT //
11344 +#endif // CONFIG_STA_SUPPORT //
11345 + )
11346 + {
11347 + pEntry = &pAd->MacTab.Content[i];
11348 + if (CleanAll == TRUE)
11349 + {
11350 + pEntry->MaxSupportedRate = RATE_11;
11351 + pEntry->CurrTxRate = RATE_11;
11352 + NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY));
11353 + pEntry->PairwiseKey.KeyLen = 0;
11354 + pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
11355 + }
11356 +#ifdef CONFIG_STA_SUPPORT
11357 +#ifdef QOS_DLS_SUPPORT
11358 + if (apidx >= MIN_NET_DEVICE_FOR_DLS)
11359 + {
11360 + pEntry->ValidAsCLI = FALSE;
11361 + pEntry->ValidAsWDS = FALSE;
11362 + pEntry->ValidAsApCli = FALSE;
11363 + pEntry->ValidAsMesh = FALSE;
11364 + pEntry->ValidAsDls = TRUE;
11365 + pEntry->isCached = FALSE;
11366 + }
11367 + else
11368 +#endif // QOS_DLS_SUPPORT //
11369 +#endif // CONFIG_STA_SUPPORT //
11370 + {
11371 +
11372 +#ifdef CONFIG_STA_SUPPORT
11373 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11374 + {
11375 + pEntry->ValidAsCLI = TRUE;
11376 + pEntry->ValidAsWDS = FALSE;
11377 + pEntry->ValidAsApCli = FALSE;
11378 + pEntry->ValidAsMesh = FALSE;
11379 + pEntry->ValidAsDls = FALSE;
11380 + }
11381 +#endif // CONFIG_STA_SUPPORT //
11382 + }
11383 +
11384 + pEntry->bIAmBadAtheros = FALSE;
11385 + pEntry->pAd = pAd;
11386 + pEntry->CMTimerRunning = FALSE;
11387 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
11388 + pEntry->RSNIE_Len = 0;
11389 + NdisZeroMemory(pEntry->R_Counter, sizeof(pEntry->R_Counter));
11390 + pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR;
11391 +
11392 + if (pEntry->ValidAsMesh)
11393 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_MESH);
11394 + else if (pEntry->ValidAsApCli)
11395 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_APCLI);
11396 + else if (pEntry->ValidAsWDS)
11397 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_WDS);
11398 +#ifdef CONFIG_STA_SUPPORT
11399 +#ifdef QOS_DLS_SUPPORT
11400 + else if (pEntry->ValidAsDls)
11401 + pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_DLS);
11402 +#endif // QOS_DLS_SUPPORT //
11403 +#endif // CONFIG_STA_SUPPORT //
11404 + else
11405 + pEntry->apidx = apidx;
11406 +
11407 + {
11408 +
11409 +#ifdef CONFIG_STA_SUPPORT
11410 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11411 + {
11412 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
11413 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
11414 + pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
11415 + }
11416 +#endif // CONFIG_STA_SUPPORT //
11417 + }
11418 +
11419 + pEntry->GTKState = REKEY_NEGOTIATING;
11420 + pEntry->PairwiseKey.KeyLen = 0;
11421 + pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
11422 +#ifdef CONFIG_STA_SUPPORT
11423 +#ifdef QOS_DLS_SUPPORT
11424 + if (pEntry->ValidAsDls == TRUE)
11425 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
11426 + else
11427 +#endif //QOS_DLS_SUPPORT
11428 +#endif // CONFIG_STA_SUPPORT //
11429 + pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED;
11430 + pEntry->PMKID_CacheIdx = ENTRY_NOT_FOUND;
11431 + COPY_MAC_ADDR(pEntry->Addr, pAddr);
11432 + pEntry->Sst = SST_NOT_AUTH;
11433 + pEntry->AuthState = AS_NOT_AUTH;
11434 + pEntry->Aid = (USHORT)i; //0;
11435 + pEntry->CapabilityInfo = 0;
11436 + pEntry->PsMode = PWR_ACTIVE;
11437 + pEntry->PsQIdleCount = 0;
11438 + pEntry->NoDataIdleCount = 0;
11439 + pEntry->ContinueTxFailCnt = 0;
11440 + InitializeQueueHeader(&pEntry->PsQueue);
11441 +
11442 +
11443 + pAd->MacTab.Size ++;
11444 +
11445 + // Add this entry into ASIC RX WCID search table
11446 + RT28XX_STA_ENTRY_ADD(pAd, pEntry);
11447 +
11448 +
11449 +
11450 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableInsertEntry - allocate entry #%d, Total= %d\n",i, pAd->MacTab.Size));
11451 + break;
11452 + }
11453 + }
11454 +
11455 + // add this MAC entry into HASH table
11456 + if (pEntry)
11457 + {
11458 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11459 + if (pAd->MacTab.Hash[HashIdx] == NULL)
11460 + {
11461 + pAd->MacTab.Hash[HashIdx] = pEntry;
11462 + }
11463 + else
11464 + {
11465 + pCurrEntry = pAd->MacTab.Hash[HashIdx];
11466 + while (pCurrEntry->pNext != NULL)
11467 + pCurrEntry = pCurrEntry->pNext;
11468 + pCurrEntry->pNext = pEntry;
11469 + }
11470 + }
11471 +
11472 + NdisReleaseSpinLock(&pAd->MacTabLock);
11473 + return pEntry;
11474 +}
11475 +
11476 +/*
11477 + ==========================================================================
11478 + Description:
11479 + Delete a specified client from MAC table
11480 + ==========================================================================
11481 + */
11482 +BOOLEAN MacTableDeleteEntry(
11483 + IN PRTMP_ADAPTER pAd,
11484 + IN USHORT wcid,
11485 + IN PUCHAR pAddr)
11486 +{
11487 + USHORT HashIdx;
11488 + MAC_TABLE_ENTRY *pEntry, *pPrevEntry, *pProbeEntry;
11489 + BOOLEAN Cancelled;
11490 + //USHORT offset; // unused variable
11491 + //UCHAR j; // unused variable
11492 +
11493 + if (wcid >= MAX_LEN_OF_MAC_TABLE)
11494 + return FALSE;
11495 +
11496 + NdisAcquireSpinLock(&pAd->MacTabLock);
11497 +
11498 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
11499 + //pEntry = pAd->MacTab.Hash[HashIdx];
11500 + pEntry = &pAd->MacTab.Content[wcid];
11501 +
11502 + if (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsApCli || pEntry->ValidAsWDS || pEntry->ValidAsMesh
11503 +#ifdef CONFIG_STA_SUPPORT
11504 +#ifdef QOS_DLS_SUPPORT
11505 + || pEntry->ValidAsDls
11506 +#endif // QOS_DLS_SUPPORT //
11507 +#endif // CONFIG_STA_SUPPORT //
11508 + ))
11509 + {
11510 + if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
11511 + {
11512 +
11513 + // Delete this entry from ASIC on-chip WCID Table
11514 + RT28XX_STA_ENTRY_MAC_RESET(pAd, wcid);
11515 +
11516 +#ifdef DOT11_N_SUPPORT
11517 + // free resources of BA
11518 + BASessionTearDownALL(pAd, pEntry->Aid);
11519 +#endif // DOT11_N_SUPPORT //
11520 +
11521 +
11522 + pPrevEntry = NULL;
11523 + pProbeEntry = pAd->MacTab.Hash[HashIdx];
11524 + ASSERT(pProbeEntry);
11525 +
11526 + // update Hash list
11527 + do
11528 + {
11529 + if (pProbeEntry == pEntry)
11530 + {
11531 + if (pPrevEntry == NULL)
11532 + {
11533 + pAd->MacTab.Hash[HashIdx] = pEntry->pNext;
11534 + }
11535 + else
11536 + {
11537 + pPrevEntry->pNext = pEntry->pNext;
11538 + }
11539 + break;
11540 + }
11541 +
11542 + pPrevEntry = pProbeEntry;
11543 + pProbeEntry = pProbeEntry->pNext;
11544 + } while (pProbeEntry);
11545 +
11546 + // not found !!!
11547 + ASSERT(pProbeEntry != NULL);
11548 +
11549 + RT28XX_STA_ENTRY_KEY_DEL(pAd, BSS0, wcid);
11550 +
11551 +
11552 + if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
11553 + {
11554 + RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
11555 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
11556 + }
11557 +
11558 +
11559 + NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY));
11560 + pAd->MacTab.Size --;
11561 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableDeleteEntry1 - Total= %d\n", pAd->MacTab.Size));
11562 + }
11563 + else
11564 + {
11565 + printk("\n%s: Impossible Wcid = %d !!!!!\n", __FUNCTION__, wcid);
11566 + }
11567 + }
11568 +
11569 + NdisReleaseSpinLock(&pAd->MacTabLock);
11570 +
11571 + //Reset operating mode when no Sta.
11572 + if (pAd->MacTab.Size == 0)
11573 + {
11574 +#ifdef DOT11_N_SUPPORT
11575 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode = 0;
11576 +#endif // DOT11_N_SUPPORT //
11577 + //AsicUpdateProtect(pAd, 0 /*pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode*/, (ALLN_SETPROTECT), TRUE, 0 /*pAd->MacTab.fAnyStationNonGF*/);
11578 + RT28XX_UPDATE_PROTECT(pAd); // edit by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
11579 + }
11580 +
11581 + return TRUE;
11582 +}
11583 +
11584 +
11585 +/*
11586 + ==========================================================================
11587 + Description:
11588 + This routine reset the entire MAC table. All packets pending in
11589 + the power-saving queues are freed here.
11590 + ==========================================================================
11591 + */
11592 +VOID MacTableReset(
11593 + IN PRTMP_ADAPTER pAd)
11594 +{
11595 + int i;
11596 +
11597 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableReset\n"));
11598 + //NdisAcquireSpinLock(&pAd->MacTabLock);
11599 +
11600 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
11601 + {
11602 + if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
11603 + {
11604 +
11605 +#ifdef DOT11_N_SUPPORT
11606 + // free resources of BA
11607 + BASessionTearDownALL(pAd, i);
11608 +#endif // DOT11_N_SUPPORT //
11609 +
11610 + pAd->MacTab.Content[i].ValidAsCLI = FALSE;
11611 +
11612 +
11613 +
11614 +#ifdef RT2870
11615 + NdisZeroMemory(pAd->MacTab.Content[i].Addr, 6);
11616 + RT28XX_STA_ENTRY_MAC_RESET(pAd, i);
11617 +#endif // RT2870 //
11618 +
11619 + //AsicDelWcidTab(pAd, i);
11620 + }
11621 + }
11622 +
11623 + return;
11624 +}
11625 +
11626 +/*
11627 + ==========================================================================
11628 + Description:
11629 +
11630 + IRQL = DISPATCH_LEVEL
11631 +
11632 + ==========================================================================
11633 +*/
11634 +VOID AssocParmFill(
11635 + IN PRTMP_ADAPTER pAd,
11636 + IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
11637 + IN PUCHAR pAddr,
11638 + IN USHORT CapabilityInfo,
11639 + IN ULONG Timeout,
11640 + IN USHORT ListenIntv)
11641 +{
11642 + COPY_MAC_ADDR(AssocReq->Addr, pAddr);
11643 + // Add mask to support 802.11b mode only
11644 + AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; // not cf-pollable, not cf-poll-request
11645 + AssocReq->Timeout = Timeout;
11646 + AssocReq->ListenIntv = ListenIntv;
11647 +}
11648 +
11649 +
11650 +/*
11651 + ==========================================================================
11652 + Description:
11653 +
11654 + IRQL = DISPATCH_LEVEL
11655 +
11656 + ==========================================================================
11657 +*/
11658 +VOID DisassocParmFill(
11659 + IN PRTMP_ADAPTER pAd,
11660 + IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
11661 + IN PUCHAR pAddr,
11662 + IN USHORT Reason)
11663 +{
11664 + COPY_MAC_ADDR(DisassocReq->Addr, pAddr);
11665 + DisassocReq->Reason = Reason;
11666 +}
11667 +
11668 +
11669 +/*
11670 + ========================================================================
11671 +
11672 + Routine Description:
11673 + Check the out going frame, if this is an DHCP or ARP datagram
11674 + will be duplicate another frame at low data rate transmit.
11675 +
11676 + Arguments:
11677 + pAd Pointer to our adapter
11678 + pPacket Pointer to outgoing Ndis frame
11679 +
11680 + Return Value:
11681 + TRUE To be duplicate at Low data rate transmit. (1mb)
11682 + FALSE Do nothing.
11683 +
11684 + IRQL = DISPATCH_LEVEL
11685 +
11686 + Note:
11687 +
11688 + MAC header + IP Header + UDP Header
11689 + 14 Bytes 20 Bytes
11690 +
11691 + UDP Header
11692 + 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|
11693 + Source Port
11694 + 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|
11695 + Destination Port
11696 +
11697 + port 0x43 means Bootstrap Protocol, server.
11698 + Port 0x44 means Bootstrap Protocol, client.
11699 +
11700 + ========================================================================
11701 +*/
11702 +
11703 +BOOLEAN RTMPCheckDHCPFrame(
11704 + IN PRTMP_ADAPTER pAd,
11705 + IN PNDIS_PACKET pPacket)
11706 +{
11707 + PACKET_INFO PacketInfo;
11708 + ULONG NumberOfBytesRead = 0;
11709 + ULONG CurrentOffset = 0;
11710 + PVOID pVirtualAddress = NULL;
11711 + UINT NdisBufferLength;
11712 + PUCHAR pSrc;
11713 + USHORT Protocol;
11714 + UCHAR ByteOffset36 = 0;
11715 + UCHAR ByteOffset38 = 0;
11716 + BOOLEAN ReadFirstParm = TRUE;
11717 +
11718 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, (PUCHAR *)&pVirtualAddress, &NdisBufferLength);
11719 +
11720 + NumberOfBytesRead += NdisBufferLength;
11721 + pSrc = (PUCHAR) pVirtualAddress;
11722 + Protocol = *(pSrc + 12) * 256 + *(pSrc + 13);
11723 +
11724 + //
11725 + // Check DHCP & BOOTP protocol
11726 + //
11727 + while (NumberOfBytesRead <= PacketInfo.TotalPacketLength)
11728 + {
11729 + if ((NumberOfBytesRead >= 35) && (ReadFirstParm == TRUE))
11730 + {
11731 + CurrentOffset = 35 - (NumberOfBytesRead - NdisBufferLength);
11732 + ByteOffset36 = *(pSrc + CurrentOffset);
11733 + ReadFirstParm = FALSE;
11734 + }
11735 +
11736 + if (NumberOfBytesRead >= 37)
11737 + {
11738 + CurrentOffset = 37 - (NumberOfBytesRead - NdisBufferLength);
11739 + ByteOffset38 = *(pSrc + CurrentOffset);
11740 + //End of Read
11741 + break;
11742 + }
11743 + return FALSE;
11744 + }
11745 +
11746 + // Check for DHCP & BOOTP protocol
11747 + if ((ByteOffset36 != 0x44) || (ByteOffset38 != 0x43))
11748 + {
11749 + //
11750 + // 2054 (hex 0806) for ARP datagrams
11751 + // if this packet is not ARP datagrams, then do nothing
11752 + // ARP datagrams will also be duplicate at 1mb broadcast frames
11753 + //
11754 + if (Protocol != 0x0806 )
11755 + return FALSE;
11756 + }
11757 +
11758 + return TRUE;
11759 +}
11760 +
11761 +
11762 +BOOLEAN RTMPCheckEtherType(
11763 + IN PRTMP_ADAPTER pAd,
11764 + IN PNDIS_PACKET pPacket)
11765 +{
11766 + USHORT TypeLen;
11767 + UCHAR Byte0, Byte1;
11768 + PUCHAR pSrcBuf;
11769 + UINT32 pktLen;
11770 + UINT16 srcPort, dstPort;
11771 + BOOLEAN status = TRUE;
11772 +
11773 +
11774 + pSrcBuf = GET_OS_PKT_DATAPTR(pPacket);
11775 + pktLen = GET_OS_PKT_LEN(pPacket);
11776 +
11777 + ASSERT(pSrcBuf);
11778 +
11779 + RTMP_SET_PACKET_SPECIFIC(pPacket, 0);
11780 +
11781 + // get Ethernet protocol field
11782 + TypeLen = (pSrcBuf[12] << 8) + pSrcBuf[13];
11783 +
11784 + pSrcBuf += LENGTH_802_3; // Skip the Ethernet Header.
11785 +
11786 + if (TypeLen <= 1500)
11787 + { // 802.3, 802.3 LLC
11788 + /*
11789 + DestMAC(6) + SrcMAC(6) + Lenght(2) +
11790 + DSAP(1) + SSAP(1) + Control(1) +
11791 + if the DSAP = 0xAA, SSAP=0xAA, Contorl = 0x03, it has a 5-bytes SNAP header.
11792 + => + SNAP (5, OriginationID(3) + etherType(2))
11793 + */
11794 + if (pSrcBuf[0] == 0xAA && pSrcBuf[1] == 0xAA && pSrcBuf[2] == 0x03)
11795 + {
11796 + Sniff2BytesFromNdisBuffer(pSrcBuf, 6, &Byte0, &Byte1);
11797 + RTMP_SET_PACKET_LLCSNAP(pPacket, 1);
11798 + TypeLen = (USHORT)((Byte0 << 8) + Byte1);
11799 + pSrcBuf += 8; // Skip this LLC/SNAP header
11800 + }
11801 + else
11802 + {
11803 + //It just has 3-byte LLC header, maybe a legacy ether type frame. we didn't handle it.
11804 + }
11805 + }
11806 +
11807 + // If it's a VLAN packet, get the real Type/Length field.
11808 + if (TypeLen == 0x8100)
11809 + {
11810 + /* 0x8100 means VLAN packets */
11811 +
11812 + /* Dest. MAC Address (6-bytes) +
11813 + Source MAC Address (6-bytes) +
11814 + Length/Type = 802.1Q Tag Type (2-byte) +
11815 + Tag Control Information (2-bytes) +
11816 + Length / Type (2-bytes) +
11817 + data payload (0-n bytes) +
11818 + Pad (0-p bytes) +
11819 + Frame Check Sequence (4-bytes) */
11820 +
11821 + RTMP_SET_PACKET_VLAN(pPacket, 1);
11822 + Sniff2BytesFromNdisBuffer(pSrcBuf, 2, &Byte0, &Byte1);
11823 + TypeLen = (USHORT)((Byte0 << 8) + Byte1);
11824 +
11825 + pSrcBuf += 4; // Skip the VLAN Header.
11826 + }
11827 +
11828 + switch (TypeLen)
11829 + {
11830 + case 0x0800:
11831 + {
11832 + ASSERT((pktLen > 34));
11833 + if (*(pSrcBuf + 9) == 0x11)
11834 + { // udp packet
11835 + ASSERT((pktLen > 34)); // 14 for ethernet header, 20 for IP header
11836 +
11837 + pSrcBuf += 20; // Skip the IP header
11838 + srcPort = OS_NTOHS(*((UINT16 *)pSrcBuf));
11839 + dstPort = OS_NTOHS(*((UINT16 *)(pSrcBuf +2)));
11840 +
11841 + if ((srcPort==0x44 && dstPort==0x43) || (srcPort==0x43 && dstPort==0x44))
11842 + { //It's a BOOTP/DHCP packet
11843 + RTMP_SET_PACKET_DHCP(pPacket, 1);
11844 + }
11845 + }
11846 + }
11847 + break;
11848 + case 0x0806:
11849 + {
11850 + //ARP Packet.
11851 + RTMP_SET_PACKET_DHCP(pPacket, 1);
11852 + }
11853 + break;
11854 + case 0x888e:
11855 + {
11856 + // EAPOL Packet.
11857 + RTMP_SET_PACKET_EAPOL(pPacket, 1);
11858 + }
11859 + break;
11860 + default:
11861 + status = FALSE;
11862 + break;
11863 + }
11864 +
11865 + return status;
11866 +
11867 +}
11868 +
11869 +
11870 +
11871 +VOID Update_Rssi_Sample(
11872 + IN PRTMP_ADAPTER pAd,
11873 + IN RSSI_SAMPLE *pRssi,
11874 + IN PRXWI_STRUC pRxWI)
11875 + {
11876 + CHAR rssi0 = pRxWI->RSSI0;
11877 + CHAR rssi1 = pRxWI->RSSI1;
11878 + CHAR rssi2 = pRxWI->RSSI2;
11879 +
11880 + if (rssi0 != 0)
11881 + {
11882 + pRssi->LastRssi0 = ConvertToRssi(pAd, (CHAR)rssi0, RSSI_0);
11883 + pRssi->AvgRssi0X8 = (pRssi->AvgRssi0X8 - pRssi->AvgRssi0) + pRssi->LastRssi0;
11884 + pRssi->AvgRssi0 = pRssi->AvgRssi0X8 >> 3;
11885 + }
11886 +
11887 + if (rssi1 != 0)
11888 + {
11889 + pRssi->LastRssi1 = ConvertToRssi(pAd, (CHAR)rssi1, RSSI_1);
11890 + pRssi->AvgRssi1X8 = (pRssi->AvgRssi1X8 - pRssi->AvgRssi1) + pRssi->LastRssi1;
11891 + pRssi->AvgRssi1 = pRssi->AvgRssi1X8 >> 3;
11892 + }
11893 +
11894 + if (rssi2 != 0)
11895 + {
11896 + pRssi->LastRssi2 = ConvertToRssi(pAd, (CHAR)rssi2, RSSI_2);
11897 + pRssi->AvgRssi2X8 = (pRssi->AvgRssi2X8 - pRssi->AvgRssi2) + pRssi->LastRssi2;
11898 + pRssi->AvgRssi2 = pRssi->AvgRssi2X8 >> 3;
11899 + }
11900 +}
11901 +
11902 +
11903 +
11904 +// Normal legacy Rx packet indication
11905 +VOID Indicate_Legacy_Packet(
11906 + IN PRTMP_ADAPTER pAd,
11907 + IN RX_BLK *pRxBlk,
11908 + IN UCHAR FromWhichBSSID)
11909 +{
11910 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
11911 + UCHAR Header802_3[LENGTH_802_3];
11912 +
11913 + // 1. get 802.3 Header
11914 + // 2. remove LLC
11915 + // a. pointer pRxBlk->pData to payload
11916 + // b. modify pRxBlk->DataSize
11917 +#ifdef CONFIG_STA_SUPPORT
11918 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11919 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
11920 +#endif // CONFIG_STA_SUPPORT //
11921 +
11922 + if (pRxBlk->DataSize > MAX_RX_PKT_LEN)
11923 + {
11924 + // release packet
11925 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
11926 + return;
11927 + }
11928 +
11929 +
11930 + STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
11931 +
11932 +#ifdef RT2870
11933 +#ifdef DOT11_N_SUPPORT
11934 + if (pAd->CommonCfg.bDisableReordering == 0)
11935 + {
11936 + PBA_REC_ENTRY pBAEntry;
11937 + ULONG Now32;
11938 + UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID;
11939 + UCHAR TID = pRxBlk->pRxWI->TID;
11940 + USHORT Idx;
11941 +
11942 +#define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms
11943 +
11944 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
11945 + {
11946 + Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
11947 + if (Idx != 0)
11948 + {
11949 + pBAEntry = &pAd->BATable.BARecEntry[Idx];
11950 + // update last rx time
11951 + NdisGetSystemUpTime(&Now32);
11952 + if ((pBAEntry->list.qlen > 0) &&
11953 + RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT)))
11954 + )
11955 + {
11956 + printk("Indicate_Legacy_Packet():flush reordering_timeout_mpdus! RxWI->Flags=%d, pRxWI.TID=%d, RxD->AMPDU=%d!\n", pRxBlk->Flags, pRxBlk->pRxWI->TID, pRxBlk->RxD.AMPDU);
11957 + hex_dump("Dump the legacy Packet:", GET_OS_PKT_DATAPTR(pRxBlk->pRxPacket), 64);
11958 + ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32);
11959 + }
11960 + }
11961 + }
11962 + }
11963 +#endif // DOT11_N_SUPPORT //
11964 +#endif // RT2870 //
11965 +
11966 + wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
11967 +
11968 + //
11969 + // pass this 802.3 packet to upper layer or forward this packet to WM directly
11970 + //
11971 +#ifdef CONFIG_STA_SUPPORT
11972 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
11973 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxPacket, FromWhichBSSID);
11974 +#endif // CONFIG_STA_SUPPORT //
11975 +
11976 +}
11977 +
11978 +
11979 +// Normal, AMPDU or AMSDU
11980 +VOID CmmRxnonRalinkFrameIndicate(
11981 + IN PRTMP_ADAPTER pAd,
11982 + IN RX_BLK *pRxBlk,
11983 + IN UCHAR FromWhichBSSID)
11984 +{
11985 +#ifdef DOT11_N_SUPPORT
11986 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))
11987 + {
11988 + Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
11989 + }
11990 + else
11991 +#endif // DOT11_N_SUPPORT //
11992 + {
11993 +#ifdef DOT11_N_SUPPORT
11994 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU))
11995 + {
11996 + // handle A-MSDU
11997 + Indicate_AMSDU_Packet(pAd, pRxBlk, FromWhichBSSID);
11998 + }
11999 + else
12000 +#endif // DOT11_N_SUPPORT //
12001 + {
12002 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
12003 + }
12004 + }
12005 +}
12006 +
12007 +
12008 +VOID CmmRxRalinkFrameIndicate(
12009 + IN PRTMP_ADAPTER pAd,
12010 + IN MAC_TABLE_ENTRY *pEntry,
12011 + IN RX_BLK *pRxBlk,
12012 + IN UCHAR FromWhichBSSID)
12013 +{
12014 + UCHAR Header802_3[LENGTH_802_3];
12015 + UINT16 Msdu2Size;
12016 + UINT16 Payload1Size, Payload2Size;
12017 + PUCHAR pData2;
12018 + PNDIS_PACKET pPacket2 = NULL;
12019 +
12020 +
12021 +
12022 + Msdu2Size = *(pRxBlk->pData) + (*(pRxBlk->pData+1) << 8);
12023 +
12024 + if ((Msdu2Size <= 1536) && (Msdu2Size < pRxBlk->DataSize))
12025 + {
12026 + /* skip two byte MSDU2 len */
12027 + pRxBlk->pData += 2;
12028 + pRxBlk->DataSize -= 2;
12029 + }
12030 + else
12031 + {
12032 + // release packet
12033 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12034 + return;
12035 + }
12036 +
12037 + // get 802.3 Header and remove LLC
12038 +#ifdef CONFIG_STA_SUPPORT
12039 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12040 + RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
12041 +#endif // CONFIG_STA_SUPPORT //
12042 +
12043 +
12044 + ASSERT(pRxBlk->pRxPacket);
12045 +
12046 + // Ralink Aggregation frame
12047 + pAd->RalinkCounters.OneSecRxAggregationCount ++;
12048 + Payload1Size = pRxBlk->DataSize - Msdu2Size;
12049 + Payload2Size = Msdu2Size - LENGTH_802_3;
12050 +
12051 + pData2 = pRxBlk->pData + Payload1Size + LENGTH_802_3;
12052 +#ifdef CONFIG_STA_SUPPORT
12053 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12054 + pPacket2 = duplicate_pkt(pAd, (pData2-LENGTH_802_3), LENGTH_802_3, pData2, Payload2Size, FromWhichBSSID);
12055 +#endif // CONFIG_STA_SUPPORT //
12056 +
12057 + if (!pPacket2)
12058 + {
12059 + // release packet
12060 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12061 + return;
12062 + }
12063 +
12064 + // update payload size of 1st packet
12065 + pRxBlk->DataSize = Payload1Size;
12066 + wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
12067 +
12068 +#ifdef CONFIG_STA_SUPPORT
12069 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12070 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxBlk->pRxPacket, FromWhichBSSID);
12071 +#endif // CONFIG_STA_SUPPORT //
12072 +
12073 + if (pPacket2)
12074 + {
12075 +#ifdef CONFIG_STA_SUPPORT
12076 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12077 + ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket2, FromWhichBSSID);
12078 +#endif // CONFIG_STA_SUPPORT //
12079 + }
12080 +}
12081 +
12082 +
12083 +#define RESET_FRAGFRAME(_fragFrame) \
12084 + { \
12085 + _fragFrame.RxSize = 0; \
12086 + _fragFrame.Sequence = 0; \
12087 + _fragFrame.LastFrag = 0; \
12088 + _fragFrame.Flags = 0; \
12089 + }
12090 +
12091 +
12092 +PNDIS_PACKET RTMPDeFragmentDataFrame(
12093 + IN PRTMP_ADAPTER pAd,
12094 + IN RX_BLK *pRxBlk)
12095 +{
12096 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
12097 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
12098 + UCHAR *pData = pRxBlk->pData;
12099 + USHORT DataSize = pRxBlk->DataSize;
12100 + PNDIS_PACKET pRetPacket = NULL;
12101 + UCHAR *pFragBuffer = NULL;
12102 + BOOLEAN bReassDone = FALSE;
12103 + UCHAR HeaderRoom = 0;
12104 +
12105 +
12106 + ASSERT(pHeader);
12107 +
12108 + HeaderRoom = pData - (UCHAR *)pHeader;
12109 +
12110 + // Re-assemble the fragmented packets
12111 + if (pHeader->Frag == 0) // Frag. Number is 0 : First frag or only one pkt
12112 + {
12113 + // the first pkt of fragment, record it.
12114 + if (pHeader->FC.MoreFrag)
12115 + {
12116 + ASSERT(pAd->FragFrame.pFragPacket);
12117 + pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
12118 + pAd->FragFrame.RxSize = DataSize + HeaderRoom;
12119 + NdisMoveMemory(pFragBuffer, pHeader, pAd->FragFrame.RxSize);
12120 + pAd->FragFrame.Sequence = pHeader->Sequence;
12121 + pAd->FragFrame.LastFrag = pHeader->Frag; // Should be 0
12122 + ASSERT(pAd->FragFrame.LastFrag == 0);
12123 + goto done; // end of processing this frame
12124 + }
12125 + }
12126 + else //Middle & End of fragment
12127 + {
12128 + if ((pHeader->Sequence != pAd->FragFrame.Sequence) ||
12129 + (pHeader->Frag != (pAd->FragFrame.LastFrag + 1)))
12130 + {
12131 + // Fragment is not the same sequence or out of fragment number order
12132 + // Reset Fragment control blk
12133 + RESET_FRAGFRAME(pAd->FragFrame);
12134 + DBGPRINT(RT_DEBUG_ERROR, ("Fragment is not the same sequence or out of fragment number order.\n"));
12135 + goto done; // give up this frame
12136 + }
12137 + else if ((pAd->FragFrame.RxSize + DataSize) > MAX_FRAME_SIZE)
12138 + {
12139 + // Fragment frame is too large, it exeeds the maximum frame size.
12140 + // Reset Fragment control blk
12141 + RESET_FRAGFRAME(pAd->FragFrame);
12142 + DBGPRINT(RT_DEBUG_ERROR, ("Fragment frame is too large, it exeeds the maximum frame size.\n"));
12143 + goto done; // give up this frame
12144 + }
12145 +
12146 + //
12147 + // Broadcom AP(BCM94704AGR) will send out LLC in fragment's packet, LLC only can accpet at first fragment.
12148 + // In this case, we will dropt it.
12149 + //
12150 + if (NdisEqualMemory(pData, SNAP_802_1H, sizeof(SNAP_802_1H)))
12151 + {
12152 + DBGPRINT(RT_DEBUG_ERROR, ("Find another LLC at Middle or End fragment(SN=%d, Frag=%d)\n", pHeader->Sequence, pHeader->Frag));
12153 + goto done; // give up this frame
12154 + }
12155 +
12156 + pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
12157 +
12158 + // concatenate this fragment into the re-assembly buffer
12159 + NdisMoveMemory((pFragBuffer + pAd->FragFrame.RxSize), pData, DataSize);
12160 + pAd->FragFrame.RxSize += DataSize;
12161 + pAd->FragFrame.LastFrag = pHeader->Frag; // Update fragment number
12162 +
12163 + // Last fragment
12164 + if (pHeader->FC.MoreFrag == FALSE)
12165 + {
12166 + bReassDone = TRUE;
12167 + }
12168 + }
12169 +
12170 +done:
12171 + // always release rx fragmented packet
12172 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
12173 +
12174 + // return defragmented packet if packet is reassembled completely
12175 + // otherwise return NULL
12176 + if (bReassDone)
12177 + {
12178 + PNDIS_PACKET pNewFragPacket;
12179 +
12180 + // allocate a new packet buffer for fragment
12181 + pNewFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
12182 + if (pNewFragPacket)
12183 + {
12184 + // update RxBlk
12185 + pRetPacket = pAd->FragFrame.pFragPacket;
12186 + pAd->FragFrame.pFragPacket = pNewFragPacket;
12187 + pRxBlk->pHeader = (PHEADER_802_11) GET_OS_PKT_DATAPTR(pRetPacket);
12188 + pRxBlk->pData = (UCHAR *)pRxBlk->pHeader + HeaderRoom;
12189 + pRxBlk->DataSize = pAd->FragFrame.RxSize - HeaderRoom;
12190 + pRxBlk->pRxPacket = pRetPacket;
12191 + }
12192 + else
12193 + {
12194 + RESET_FRAGFRAME(pAd->FragFrame);
12195 + }
12196 + }
12197 +
12198 + return pRetPacket;
12199 +}
12200 +
12201 +
12202 +VOID Indicate_AMSDU_Packet(
12203 + IN PRTMP_ADAPTER pAd,
12204 + IN RX_BLK *pRxBlk,
12205 + IN UCHAR FromWhichBSSID)
12206 +{
12207 + UINT nMSDU;
12208 +
12209 + update_os_packet_info(pAd, pRxBlk, FromWhichBSSID);
12210 + RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
12211 + nMSDU = deaggregate_AMSDU_announce(pAd, pRxBlk->pRxPacket, pRxBlk->pData, pRxBlk->DataSize);
12212 +}
12213 +
12214 +VOID Indicate_EAPOL_Packet(
12215 + IN PRTMP_ADAPTER pAd,
12216 + IN RX_BLK *pRxBlk,
12217 + IN UCHAR FromWhichBSSID)
12218 +{
12219 + MAC_TABLE_ENTRY *pEntry = NULL;
12220 +
12221 +
12222 +#ifdef CONFIG_STA_SUPPORT
12223 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12224 + {
12225 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
12226 + STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
12227 + return;
12228 + }
12229 +#endif // CONFIG_STA_SUPPORT //
12230 +
12231 + if (pEntry == NULL)
12232 + {
12233 + DBGPRINT(RT_DEBUG_WARN, ("Indicate_EAPOL_Packet: drop and release the invalid packet.\n"));
12234 + // release packet
12235 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
12236 + return;
12237 + }
12238 +}
12239 +
12240 +#define BCN_TBTT_OFFSET 64 //defer 64 us
12241 +VOID ReSyncBeaconTime(
12242 + IN PRTMP_ADAPTER pAd)
12243 +{
12244 +
12245 + UINT32 Offset;
12246 +
12247 +
12248 + Offset = (pAd->TbttTickCount) % (BCN_TBTT_OFFSET);
12249 +
12250 + pAd->TbttTickCount++;
12251 +
12252 + //
12253 + // The updated BeaconInterval Value will affect Beacon Interval after two TBTT
12254 + // beacasue the original BeaconInterval had been loaded into next TBTT_TIMER
12255 + //
12256 + if (Offset == (BCN_TBTT_OFFSET-2))
12257 + {
12258 + BCN_TIME_CFG_STRUC csr;
12259 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
12260 + csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod << 4) - 1 ; // ASIC register in units of 1/16 TU = 64us
12261 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
12262 + }
12263 + else
12264 + {
12265 + if (Offset == (BCN_TBTT_OFFSET-1))
12266 + {
12267 + BCN_TIME_CFG_STRUC csr;
12268 +
12269 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
12270 + csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod) << 4; // ASIC register in units of 1/16 TU
12271 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
12272 + }
12273 + }
12274 +}
12275 +
12276 --- /dev/null
12277 +++ b/drivers/staging/rt3070/common/cmm_info.c
12278 @@ -0,0 +1,3395 @@
12279 +/*
12280 + *************************************************************************
12281 + * Ralink Tech Inc.
12282 + * 5F., No.36, Taiyuan St., Jhubei City,
12283 + * Hsinchu County 302,
12284 + * Taiwan, R.O.C.
12285 + *
12286 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
12287 + *
12288 + * This program is free software; you can redistribute it and/or modify *
12289 + * it under the terms of the GNU General Public License as published by *
12290 + * the Free Software Foundation; either version 2 of the License, or *
12291 + * (at your option) any later version. *
12292 + * *
12293 + * This program is distributed in the hope that it will be useful, *
12294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12296 + * GNU General Public License for more details. *
12297 + * *
12298 + * You should have received a copy of the GNU General Public License *
12299 + * along with this program; if not, write to the *
12300 + * Free Software Foundation, Inc., *
12301 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
12302 + * *
12303 + *************************************************************************
12304 +*/
12305 +
12306 +#include "../rt_config.h"
12307 +
12308 +INT Show_SSID_Proc(
12309 + IN PRTMP_ADAPTER pAd,
12310 + OUT PUCHAR pBuf);
12311 +
12312 +INT Show_WirelessMode_Proc(
12313 + IN PRTMP_ADAPTER pAd,
12314 + OUT PUCHAR pBuf);
12315 +
12316 +INT Show_TxBurst_Proc(
12317 + IN PRTMP_ADAPTER pAd,
12318 + OUT PUCHAR pBuf);
12319 +
12320 +INT Show_TxPreamble_Proc(
12321 + IN PRTMP_ADAPTER pAd,
12322 + OUT PUCHAR pBuf);
12323 +
12324 +INT Show_TxPower_Proc(
12325 + IN PRTMP_ADAPTER pAd,
12326 + OUT PUCHAR pBuf);
12327 +
12328 +INT Show_Channel_Proc(
12329 + IN PRTMP_ADAPTER pAd,
12330 + OUT PUCHAR pBuf);
12331 +
12332 +INT Show_BGProtection_Proc(
12333 + IN PRTMP_ADAPTER pAd,
12334 + OUT PUCHAR pBuf);
12335 +
12336 +INT Show_RTSThreshold_Proc(
12337 + IN PRTMP_ADAPTER pAd,
12338 + OUT PUCHAR pBuf);
12339 +
12340 +INT Show_FragThreshold_Proc(
12341 + IN PRTMP_ADAPTER pAd,
12342 + OUT PUCHAR pBuf);
12343 +
12344 +#ifdef DOT11_N_SUPPORT
12345 +INT Show_HtBw_Proc(
12346 + IN PRTMP_ADAPTER pAd,
12347 + OUT PUCHAR pBuf);
12348 +
12349 +INT Show_HtMcs_Proc(
12350 + IN PRTMP_ADAPTER pAd,
12351 + OUT PUCHAR pBuf);
12352 +
12353 +INT Show_HtGi_Proc(
12354 + IN PRTMP_ADAPTER pAd,
12355 + OUT PUCHAR pBuf);
12356 +
12357 +INT Show_HtOpMode_Proc(
12358 + IN PRTMP_ADAPTER pAd,
12359 + OUT PUCHAR pBuf);
12360 +
12361 +INT Show_HtExtcha_Proc(
12362 + IN PRTMP_ADAPTER pAd,
12363 + OUT PUCHAR pBuf);
12364 +
12365 +INT Show_HtMpduDensity_Proc(
12366 + IN PRTMP_ADAPTER pAd,
12367 + OUT PUCHAR pBuf);
12368 +
12369 +INT Show_HtBaWinSize_Proc(
12370 + IN PRTMP_ADAPTER pAd,
12371 + OUT PUCHAR pBuf);
12372 +
12373 +INT Show_HtRdg_Proc(
12374 + IN PRTMP_ADAPTER pAd,
12375 + OUT PUCHAR pBuf);
12376 +
12377 +INT Show_HtAmsdu_Proc(
12378 + IN PRTMP_ADAPTER pAd,
12379 + OUT PUCHAR pBuf);
12380 +
12381 +INT Show_HtAutoBa_Proc(
12382 + IN PRTMP_ADAPTER pAd,
12383 + OUT PUCHAR pBuf);
12384 +#endif // DOT11_N_SUPPORT //
12385 +
12386 +INT Show_CountryRegion_Proc(
12387 + IN PRTMP_ADAPTER pAd,
12388 + OUT PUCHAR pBuf);
12389 +
12390 +INT Show_CountryRegionABand_Proc(
12391 + IN PRTMP_ADAPTER pAd,
12392 + OUT PUCHAR pBuf);
12393 +
12394 +INT Show_CountryCode_Proc(
12395 + IN PRTMP_ADAPTER pAd,
12396 + OUT PUCHAR pBuf);
12397 +
12398 +#ifdef AGGREGATION_SUPPORT
12399 +INT Show_PktAggregate_Proc(
12400 + IN PRTMP_ADAPTER pAd,
12401 + OUT PUCHAR pBuf);
12402 +#endif // AGGREGATION_SUPPORT //
12403 +
12404 +#ifdef WMM_SUPPORT
12405 +INT Show_WmmCapable_Proc(
12406 + IN PRTMP_ADAPTER pAd,
12407 + OUT PUCHAR pBuf);
12408 +#endif // WMM_SUPPORT //
12409 +
12410 +INT Show_IEEE80211H_Proc(
12411 + IN PRTMP_ADAPTER pAd,
12412 + OUT PUCHAR pBuf);
12413 +
12414 +#ifdef CONFIG_STA_SUPPORT
12415 +INT Show_NetworkType_Proc(
12416 + IN PRTMP_ADAPTER pAd,
12417 + OUT PUCHAR pBuf);
12418 +#endif // CONFIG_STA_SUPPORT //
12419 +
12420 +INT Show_AuthMode_Proc(
12421 + IN PRTMP_ADAPTER pAd,
12422 + OUT PUCHAR pBuf);
12423 +
12424 +INT Show_EncrypType_Proc(
12425 + IN PRTMP_ADAPTER pAd,
12426 + OUT PUCHAR pBuf);
12427 +
12428 +INT Show_DefaultKeyID_Proc(
12429 + IN PRTMP_ADAPTER pAd,
12430 + OUT PUCHAR pBuf);
12431 +
12432 +INT Show_Key1_Proc(
12433 + IN PRTMP_ADAPTER pAd,
12434 + OUT PUCHAR pBuf);
12435 +
12436 +INT Show_Key2_Proc(
12437 + IN PRTMP_ADAPTER pAd,
12438 + OUT PUCHAR pBuf);
12439 +
12440 +INT Show_Key3_Proc(
12441 + IN PRTMP_ADAPTER pAd,
12442 + OUT PUCHAR pBuf);
12443 +
12444 +INT Show_Key4_Proc(
12445 + IN PRTMP_ADAPTER pAd,
12446 + OUT PUCHAR pBuf);
12447 +
12448 +INT Show_WPAPSK_Proc(
12449 + IN PRTMP_ADAPTER pAd,
12450 + OUT PUCHAR pBuf);
12451 +
12452 +static struct {
12453 + CHAR *name;
12454 + INT (*show_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
12455 +} *PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC, RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC[] = {
12456 + {"SSID", Show_SSID_Proc},
12457 + {"WirelessMode", Show_WirelessMode_Proc},
12458 + {"TxBurst", Show_TxBurst_Proc},
12459 + {"TxPreamble", Show_TxPreamble_Proc},
12460 + {"TxPower", Show_TxPower_Proc},
12461 + {"Channel", Show_Channel_Proc},
12462 + {"BGProtection", Show_BGProtection_Proc},
12463 + {"RTSThreshold", Show_RTSThreshold_Proc},
12464 + {"FragThreshold", Show_FragThreshold_Proc},
12465 +#ifdef DOT11_N_SUPPORT
12466 + {"HtBw", Show_HtBw_Proc},
12467 + {"HtMcs", Show_HtMcs_Proc},
12468 + {"HtGi", Show_HtGi_Proc},
12469 + {"HtOpMode", Show_HtOpMode_Proc},
12470 + {"HtExtcha", Show_HtExtcha_Proc},
12471 + {"HtMpduDensity", Show_HtMpduDensity_Proc},
12472 + {"HtBaWinSize", Show_HtBaWinSize_Proc},
12473 + {"HtRdg", Show_HtRdg_Proc},
12474 + {"HtAmsdu", Show_HtAmsdu_Proc},
12475 + {"HtAutoBa", Show_HtAutoBa_Proc},
12476 +#endif // DOT11_N_SUPPORT //
12477 + {"CountryRegion", Show_CountryRegion_Proc},
12478 + {"CountryRegionABand", Show_CountryRegionABand_Proc},
12479 + {"CountryCode", Show_CountryCode_Proc},
12480 +#ifdef AGGREGATION_SUPPORT
12481 + {"PktAggregate", Show_PktAggregate_Proc},
12482 +#endif
12483 +
12484 +#ifdef WMM_SUPPORT
12485 + {"WmmCapable", Show_WmmCapable_Proc},
12486 +#endif
12487 + {"IEEE80211H", Show_IEEE80211H_Proc},
12488 +#ifdef CONFIG_STA_SUPPORT
12489 + {"NetworkType", Show_NetworkType_Proc},
12490 +#endif // CONFIG_STA_SUPPORT //
12491 + {"AuthMode", Show_AuthMode_Proc},
12492 + {"EncrypType", Show_EncrypType_Proc},
12493 + {"DefaultKeyID", Show_DefaultKeyID_Proc},
12494 + {"Key1", Show_Key1_Proc},
12495 + {"Key2", Show_Key2_Proc},
12496 + {"Key3", Show_Key3_Proc},
12497 + {"Key4", Show_Key4_Proc},
12498 + {"WPAPSK", Show_WPAPSK_Proc},
12499 + {NULL, NULL}
12500 +};
12501 +
12502 +/*
12503 + ==========================================================================
12504 + Description:
12505 + Get Driver version.
12506 +
12507 + Return:
12508 + ==========================================================================
12509 +*/
12510 +INT Set_DriverVersion_Proc(
12511 + IN PRTMP_ADAPTER pAd,
12512 + IN PUCHAR arg)
12513 +{
12514 +
12515 +#ifdef CONFIG_STA_SUPPORT
12516 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12517 + DBGPRINT(RT_DEBUG_TRACE, ("Driver version-%s\n", STA_DRIVER_VERSION));
12518 +#endif // CONFIG_STA_SUPPORT //
12519 +
12520 + return TRUE;
12521 +}
12522 +
12523 +/*
12524 + ==========================================================================
12525 + Description:
12526 + Set Country Region.
12527 + This command will not work, if the field of CountryRegion in eeprom is programmed.
12528 + Return:
12529 + TRUE if all parameters are OK, FALSE otherwise
12530 + ==========================================================================
12531 +*/
12532 +INT Set_CountryRegion_Proc(
12533 + IN PRTMP_ADAPTER pAd,
12534 + IN PUCHAR arg)
12535 +{
12536 + ULONG region;
12537 +
12538 + region = simple_strtol(arg, 0, 10);
12539 +
12540 +#ifdef EXT_BUILD_CHANNEL_LIST
12541 + return -EOPNOTSUPP;
12542 +#endif // EXT_BUILD_CHANNEL_LIST //
12543 +
12544 + // Country can be set only when EEPROM not programmed
12545 + if (pAd->CommonCfg.CountryRegion & 0x80)
12546 + {
12547 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n"));
12548 + return FALSE;
12549 + }
12550 +
12551 + if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND))
12552 + {
12553 + pAd->CommonCfg.CountryRegion = (UCHAR) region;
12554 + }
12555 + else if (region == REGION_31_BG_BAND)
12556 + {
12557 + pAd->CommonCfg.CountryRegion = (UCHAR) region;
12558 + }
12559 + else
12560 + {
12561 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n"));
12562 + return FALSE;
12563 + }
12564 +
12565 + // if set country region, driver needs to be reset
12566 + BuildChannelList(pAd);
12567 +
12568 + DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegion));
12569 +
12570 + return TRUE;
12571 +}
12572 +
12573 +/*
12574 + ==========================================================================
12575 + Description:
12576 + Set Country Region for A band.
12577 + This command will not work, if the field of CountryRegion in eeprom is programmed.
12578 + Return:
12579 + TRUE if all parameters are OK, FALSE otherwise
12580 + ==========================================================================
12581 +*/
12582 +INT Set_CountryRegionABand_Proc(
12583 + IN PRTMP_ADAPTER pAd,
12584 + IN PUCHAR arg)
12585 +{
12586 + ULONG region;
12587 +
12588 + region = simple_strtol(arg, 0, 10);
12589 +
12590 +#ifdef EXT_BUILD_CHANNEL_LIST
12591 + return -EOPNOTSUPP;
12592 +#endif // EXT_BUILD_CHANNEL_LIST //
12593 +
12594 + // Country can be set only when EEPROM not programmed
12595 + if (pAd->CommonCfg.CountryRegionForABand & 0x80)
12596 + {
12597 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n"));
12598 + return FALSE;
12599 + }
12600 +
12601 + if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND))
12602 + {
12603 + pAd->CommonCfg.CountryRegionForABand = (UCHAR) region;
12604 + }
12605 + else
12606 + {
12607 + DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n"));
12608 + return FALSE;
12609 + }
12610 +
12611 + // if set country region, driver needs to be reset
12612 + BuildChannelList(pAd);
12613 +
12614 + DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegionABand_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegionForABand));
12615 +
12616 + return TRUE;
12617 +}
12618 +
12619 +/*
12620 + ==========================================================================
12621 + Description:
12622 + Set Wireless Mode
12623 + Return:
12624 + TRUE if all parameters are OK, FALSE otherwise
12625 + ==========================================================================
12626 +*/
12627 +INT Set_WirelessMode_Proc(
12628 + IN PRTMP_ADAPTER pAd,
12629 + IN PUCHAR arg)
12630 +{
12631 + ULONG WirelessMode;
12632 + INT success = TRUE;
12633 +
12634 + WirelessMode = simple_strtol(arg, 0, 10);
12635 +
12636 +
12637 +#ifdef CONFIG_STA_SUPPORT
12638 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12639 + {
12640 + INT MaxPhyMode = PHY_11G;
12641 +
12642 +#ifdef DOT11_N_SUPPORT
12643 + MaxPhyMode = PHY_11N_5G;
12644 +#endif // DOT11_N_SUPPORT //
12645 +
12646 + if (WirelessMode <= MaxPhyMode)
12647 + {
12648 + RTMPSetPhyMode(pAd, WirelessMode);
12649 +#ifdef DOT11_N_SUPPORT
12650 + if (WirelessMode >= PHY_11ABGN_MIXED)
12651 + {
12652 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
12653 + pAd->CommonCfg.REGBACapability.field.AutoBA = TRUE;
12654 + }
12655 + else
12656 + {
12657 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
12658 + pAd->CommonCfg.REGBACapability.field.AutoBA = FALSE;
12659 + }
12660 +#endif // DOT11_N_SUPPORT //
12661 + // Set AdhocMode rates
12662 + if (pAd->StaCfg.BssType == BSS_ADHOC)
12663 + {
12664 + MlmeUpdateTxRates(pAd, FALSE, 0);
12665 + MakeIbssBeacon(pAd); // re-build BEACON frame
12666 + AsicEnableIbssSync(pAd); // copy to on-chip memory
12667 + }
12668 + }
12669 + else
12670 + {
12671 + success = FALSE;
12672 + }
12673 + }
12674 +#endif // CONFIG_STA_SUPPORT //
12675 +
12676 + // it is needed to set SSID to take effect
12677 + if (success == TRUE)
12678 + {
12679 +#ifdef DOT11_N_SUPPORT
12680 + SetCommonHT(pAd);
12681 +#endif // DOT11_N_SUPPORT //
12682 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WirelessMode_Proc::(=%ld)\n", WirelessMode));
12683 + }
12684 + else
12685 + {
12686 + DBGPRINT(RT_DEBUG_ERROR, ("Set_WirelessMode_Proc::parameters out of range\n"));
12687 + }
12688 +
12689 + return success;
12690 +}
12691 +
12692 +/*
12693 + ==========================================================================
12694 + Description:
12695 + Set Channel
12696 + Return:
12697 + TRUE if all parameters are OK, FALSE otherwise
12698 + ==========================================================================
12699 +*/
12700 +INT Set_Channel_Proc(
12701 + IN PRTMP_ADAPTER pAd,
12702 + IN PUCHAR arg)
12703 +{
12704 + INT success = TRUE;
12705 + UCHAR Channel;
12706 +
12707 + Channel = (UCHAR) simple_strtol(arg, 0, 10);
12708 +
12709 + // check if this channel is valid
12710 + if (ChannelSanity(pAd, Channel) == TRUE)
12711 + {
12712 +#ifdef CONFIG_STA_SUPPORT
12713 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12714 + {
12715 + pAd->CommonCfg.Channel = Channel;
12716 +
12717 + if (MONITOR_ON(pAd))
12718 + {
12719 +#ifdef DOT11_N_SUPPORT
12720 + N_ChannelCheck(pAd);
12721 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
12722 + pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
12723 + {
12724 + N_SetCenCh(pAd);
12725 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
12726 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
12727 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40, control_channel(%d), CentralChannel(%d) \n",
12728 + pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
12729 + }
12730 + else
12731 +#endif // DOT11_N_SUPPORT //
12732 + {
12733 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
12734 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
12735 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAd->CommonCfg.Channel));
12736 + }
12737 + }
12738 + }
12739 +#endif // CONFIG_STA_SUPPORT //
12740 + success = TRUE;
12741 + }
12742 + else
12743 + {
12744 +
12745 +#ifdef CONFIG_STA_SUPPORT
12746 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12747 + success = FALSE;
12748 +#endif // CONFIG_STA_SUPPORT //
12749 + }
12750 +
12751 +
12752 + if (success == TRUE)
12753 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Channel_Proc::(Channel=%d)\n", pAd->CommonCfg.Channel));
12754 +
12755 + return success;
12756 +}
12757 +
12758 +/*
12759 + ==========================================================================
12760 + Description:
12761 + Set Short Slot Time Enable or Disable
12762 + Return:
12763 + TRUE if all parameters are OK, FALSE otherwise
12764 + ==========================================================================
12765 +*/
12766 +INT Set_ShortSlot_Proc(
12767 + IN PRTMP_ADAPTER pAd,
12768 + IN PUCHAR arg)
12769 +{
12770 + ULONG ShortSlot;
12771 +
12772 + ShortSlot = simple_strtol(arg, 0, 10);
12773 +
12774 + if (ShortSlot == 1)
12775 + pAd->CommonCfg.bUseShortSlotTime = TRUE;
12776 + else if (ShortSlot == 0)
12777 + pAd->CommonCfg.bUseShortSlotTime = FALSE;
12778 + else
12779 + return FALSE; //Invalid argument
12780 +
12781 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAd->CommonCfg.bUseShortSlotTime));
12782 +
12783 + return TRUE;
12784 +}
12785 +
12786 +/*
12787 + ==========================================================================
12788 + Description:
12789 + Set Tx power
12790 + Return:
12791 + TRUE if all parameters are OK, FALSE otherwise
12792 + ==========================================================================
12793 +*/
12794 +INT Set_TxPower_Proc(
12795 + IN PRTMP_ADAPTER pAd,
12796 + IN PUCHAR arg)
12797 +{
12798 + ULONG TxPower;
12799 + INT success = FALSE;
12800 +
12801 + TxPower = (ULONG) simple_strtol(arg, 0, 10);
12802 + if (TxPower <= 100)
12803 + {
12804 +
12805 +#ifdef CONFIG_STA_SUPPORT
12806 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12807 + {
12808 + pAd->CommonCfg.TxPowerDefault = TxPower;
12809 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
12810 + }
12811 +#endif // CONFIG_STA_SUPPORT //
12812 + success = TRUE;
12813 + }
12814 + else
12815 + success = FALSE;
12816 +
12817 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPower_Proc::(TxPowerPercentage=%ld)\n", pAd->CommonCfg.TxPowerPercentage));
12818 +
12819 + return success;
12820 +}
12821 +
12822 +/*
12823 + ==========================================================================
12824 + Description:
12825 + Set 11B/11G Protection
12826 + Return:
12827 + TRUE if all parameters are OK, FALSE otherwise
12828 + ==========================================================================
12829 +*/
12830 +INT Set_BGProtection_Proc(
12831 + IN PRTMP_ADAPTER pAd,
12832 + IN PUCHAR arg)
12833 +{
12834 + switch (simple_strtol(arg, 0, 10))
12835 + {
12836 + case 0: //AUTO
12837 + pAd->CommonCfg.UseBGProtection = 0;
12838 + break;
12839 + case 1: //Always On
12840 + pAd->CommonCfg.UseBGProtection = 1;
12841 + break;
12842 + case 2: //Always OFF
12843 + pAd->CommonCfg.UseBGProtection = 2;
12844 + break;
12845 + default: //Invalid argument
12846 + return FALSE;
12847 + }
12848 +
12849 +
12850 + DBGPRINT(RT_DEBUG_TRACE, ("Set_BGProtection_Proc::(BGProtection=%ld)\n", pAd->CommonCfg.UseBGProtection));
12851 +
12852 + return TRUE;
12853 +}
12854 +
12855 +/*
12856 + ==========================================================================
12857 + Description:
12858 + Set TxPreamble
12859 + Return:
12860 + TRUE if all parameters are OK, FALSE otherwise
12861 + ==========================================================================
12862 +*/
12863 +INT Set_TxPreamble_Proc(
12864 + IN PRTMP_ADAPTER pAd,
12865 + IN PUCHAR arg)
12866 +{
12867 + RT_802_11_PREAMBLE Preamble;
12868 +
12869 + Preamble = simple_strtol(arg, 0, 10);
12870 +
12871 +
12872 + switch (Preamble)
12873 + {
12874 + case Rt802_11PreambleShort:
12875 + pAd->CommonCfg.TxPreamble = Preamble;
12876 +#ifdef CONFIG_STA_SUPPORT
12877 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12878 + MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
12879 +#endif // CONFIG_STA_SUPPORT //
12880 + break;
12881 + case Rt802_11PreambleLong:
12882 +#ifdef CONFIG_STA_SUPPORT
12883 + case Rt802_11PreambleAuto:
12884 + // if user wants AUTO, initialize to LONG here, then change according to AP's
12885 + // capability upon association.
12886 +#endif // CONFIG_STA_SUPPORT //
12887 + pAd->CommonCfg.TxPreamble = Preamble;
12888 +#ifdef CONFIG_STA_SUPPORT
12889 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12890 + MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
12891 +#endif // CONFIG_STA_SUPPORT //
12892 + break;
12893 + default: //Invalid argument
12894 + return FALSE;
12895 + }
12896 +
12897 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPreamble_Proc::(TxPreamble=%ld)\n", pAd->CommonCfg.TxPreamble));
12898 +
12899 + return TRUE;
12900 +}
12901 +
12902 +/*
12903 + ==========================================================================
12904 + Description:
12905 + Set RTS Threshold
12906 + Return:
12907 + TRUE if all parameters are OK, FALSE otherwise
12908 + ==========================================================================
12909 +*/
12910 +INT Set_RTSThreshold_Proc(
12911 + IN PRTMP_ADAPTER pAd,
12912 + IN PUCHAR arg)
12913 +{
12914 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
12915 +
12916 + RtsThresh = simple_strtol(arg, 0, 10);
12917 +
12918 + if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
12919 + pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
12920 +#ifdef CONFIG_STA_SUPPORT
12921 + else if (RtsThresh == 0)
12922 + pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
12923 +#endif // CONFIG_STA_SUPPORT //
12924 + else
12925 + return FALSE; //Invalid argument
12926 +
12927 + DBGPRINT(RT_DEBUG_TRACE, ("Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAd->CommonCfg.RtsThreshold));
12928 +
12929 + return TRUE;
12930 +}
12931 +
12932 +/*
12933 + ==========================================================================
12934 + Description:
12935 + Set Fragment Threshold
12936 + Return:
12937 + TRUE if all parameters are OK, FALSE otherwise
12938 + ==========================================================================
12939 +*/
12940 +INT Set_FragThreshold_Proc(
12941 + IN PRTMP_ADAPTER pAd,
12942 + IN PUCHAR arg)
12943 +{
12944 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
12945 +
12946 + FragThresh = simple_strtol(arg, 0, 10);
12947 +
12948 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
12949 + {
12950 + //Illegal FragThresh so we set it to default
12951 + pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
12952 + }
12953 + else if (FragThresh % 2 == 1)
12954 + {
12955 + // The length of each fragment shall always be an even number of octets, except for the last fragment
12956 + // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
12957 + pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
12958 + }
12959 + else
12960 + {
12961 + pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
12962 + }
12963 +
12964 +#ifdef CONFIG_STA_SUPPORT
12965 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
12966 + {
12967 + if (pAd->CommonCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
12968 + pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
12969 + else
12970 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
12971 + }
12972 +#endif // CONFIG_STA_SUPPORT //
12973 +
12974 + DBGPRINT(RT_DEBUG_TRACE, ("Set_FragThreshold_Proc::(FragThreshold=%d)\n", pAd->CommonCfg.FragmentThreshold));
12975 +
12976 + return TRUE;
12977 +}
12978 +
12979 +/*
12980 + ==========================================================================
12981 + Description:
12982 + Set TxBurst
12983 + Return:
12984 + TRUE if all parameters are OK, FALSE otherwise
12985 + ==========================================================================
12986 +*/
12987 +INT Set_TxBurst_Proc(
12988 + IN PRTMP_ADAPTER pAd,
12989 + IN PUCHAR arg)
12990 +{
12991 + ULONG TxBurst;
12992 +
12993 + TxBurst = simple_strtol(arg, 0, 10);
12994 + if (TxBurst == 1)
12995 + pAd->CommonCfg.bEnableTxBurst = TRUE;
12996 + else if (TxBurst == 0)
12997 + pAd->CommonCfg.bEnableTxBurst = FALSE;
12998 + else
12999 + return FALSE; //Invalid argument
13000 +
13001 + DBGPRINT(RT_DEBUG_TRACE, ("Set_TxBurst_Proc::(TxBurst=%d)\n", pAd->CommonCfg.bEnableTxBurst));
13002 +
13003 + return TRUE;
13004 +}
13005 +
13006 +#ifdef AGGREGATION_SUPPORT
13007 +/*
13008 + ==========================================================================
13009 + Description:
13010 + Set TxBurst
13011 + Return:
13012 + TRUE if all parameters are OK, FALSE otherwise
13013 + ==========================================================================
13014 +*/
13015 +INT Set_PktAggregate_Proc(
13016 + IN PRTMP_ADAPTER pAd,
13017 + IN PUCHAR arg)
13018 +{
13019 + ULONG aggre;
13020 +
13021 + aggre = simple_strtol(arg, 0, 10);
13022 +
13023 + if (aggre == 1)
13024 + pAd->CommonCfg.bAggregationCapable = TRUE;
13025 + else if (aggre == 0)
13026 + pAd->CommonCfg.bAggregationCapable = FALSE;
13027 + else
13028 + return FALSE; //Invalid argument
13029 +
13030 +
13031 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PktAggregate_Proc::(AGGRE=%d)\n", pAd->CommonCfg.bAggregationCapable));
13032 +
13033 + return TRUE;
13034 +}
13035 +#endif
13036 +
13037 +/*
13038 + ==========================================================================
13039 + Description:
13040 + Set IEEE80211H.
13041 + This parameter is 1 when needs radar detection, otherwise 0
13042 + Return:
13043 + TRUE if all parameters are OK, FALSE otherwise
13044 + ==========================================================================
13045 +*/
13046 +INT Set_IEEE80211H_Proc(
13047 + IN PRTMP_ADAPTER pAd,
13048 + IN PUCHAR arg)
13049 +{
13050 + ULONG ieee80211h;
13051 +
13052 + ieee80211h = simple_strtol(arg, 0, 10);
13053 +
13054 + if (ieee80211h == 1)
13055 + pAd->CommonCfg.bIEEE80211H = TRUE;
13056 + else if (ieee80211h == 0)
13057 + pAd->CommonCfg.bIEEE80211H = FALSE;
13058 + else
13059 + return FALSE; //Invalid argument
13060 +
13061 + DBGPRINT(RT_DEBUG_TRACE, ("Set_IEEE80211H_Proc::(IEEE80211H=%d)\n", pAd->CommonCfg.bIEEE80211H));
13062 +
13063 + return TRUE;
13064 +}
13065 +
13066 +
13067 +#ifdef DBG
13068 +/*
13069 + ==========================================================================
13070 + Description:
13071 + For Debug information
13072 + Return:
13073 + TRUE if all parameters are OK, FALSE otherwise
13074 + ==========================================================================
13075 +*/
13076 +INT Set_Debug_Proc(
13077 + IN PRTMP_ADAPTER pAd,
13078 + IN PUCHAR arg)
13079 +{
13080 + DBGPRINT(RT_DEBUG_TRACE, ("==> Set_Debug_Proc *******************\n"));
13081 +
13082 + if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
13083 + RTDebugLevel = simple_strtol(arg, 0, 10);
13084 +
13085 + DBGPRINT(RT_DEBUG_TRACE, ("<== Set_Debug_Proc(RTDebugLevel = %ld)\n", RTDebugLevel));
13086 +
13087 + return TRUE;
13088 +}
13089 +#endif
13090 +
13091 +INT Show_DescInfo_Proc(
13092 + IN PRTMP_ADAPTER pAd,
13093 + IN PUCHAR arg)
13094 +{
13095 +
13096 + return TRUE;
13097 +}
13098 +
13099 +/*
13100 + ==========================================================================
13101 + Description:
13102 + Reset statistics counter
13103 +
13104 + Arguments:
13105 + pAdapter Pointer to our adapter
13106 + arg
13107 +
13108 + Return:
13109 + TRUE if all parameters are OK, FALSE otherwise
13110 + ==========================================================================
13111 +*/
13112 +INT Set_ResetStatCounter_Proc(
13113 + IN PRTMP_ADAPTER pAd,
13114 + IN PUCHAR arg)
13115 +{
13116 + //UCHAR i;
13117 + //MAC_TABLE_ENTRY *pEntry;
13118 +
13119 + DBGPRINT(RT_DEBUG_TRACE, ("==>Set_ResetStatCounter_Proc\n"));
13120 +
13121 + // add the most up-to-date h/w raw counters into software counters
13122 + NICUpdateRawCounters(pAd);
13123 +
13124 + NdisZeroMemory(&pAd->WlanCounters, sizeof(COUNTER_802_11));
13125 + NdisZeroMemory(&pAd->Counters8023, sizeof(COUNTER_802_3));
13126 + NdisZeroMemory(&pAd->RalinkCounters, sizeof(COUNTER_RALINK));
13127 +
13128 + return TRUE;
13129 +}
13130 +
13131 +BOOLEAN RTMPCheckStrPrintAble(
13132 + IN CHAR *pInPutStr,
13133 + IN UCHAR strLen)
13134 +{
13135 + UCHAR i=0;
13136 +
13137 + for (i=0; i<strLen; i++)
13138 + {
13139 + if ((pInPutStr[i] < 0x21) ||
13140 + (pInPutStr[i] > 0x7E))
13141 + return FALSE;
13142 + }
13143 +
13144 + return TRUE;
13145 +}
13146 +
13147 +/*
13148 + ========================================================================
13149 +
13150 + Routine Description:
13151 + Remove WPA Key process
13152 +
13153 + Arguments:
13154 + pAd Pointer to our adapter
13155 + pBuf Pointer to the where the key stored
13156 +
13157 + Return Value:
13158 + NDIS_SUCCESS Add key successfully
13159 +
13160 + IRQL = DISPATCH_LEVEL
13161 +
13162 + Note:
13163 +
13164 + ========================================================================
13165 +*/
13166 +#ifdef CONFIG_STA_SUPPORT
13167 +VOID RTMPSetDesiredRates(
13168 + IN PRTMP_ADAPTER pAdapter,
13169 + IN LONG Rates)
13170 +{
13171 + NDIS_802_11_RATES aryRates;
13172 +
13173 + memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
13174 + switch (pAdapter->CommonCfg.PhyMode)
13175 + {
13176 + case PHY_11A: // A only
13177 + switch (Rates)
13178 + {
13179 + case 6000000: //6M
13180 + aryRates[0] = 0x0c; // 6M
13181 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13182 + break;
13183 + case 9000000: //9M
13184 + aryRates[0] = 0x12; // 9M
13185 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13186 + break;
13187 + case 12000000: //12M
13188 + aryRates[0] = 0x18; // 12M
13189 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13190 + break;
13191 + case 18000000: //18M
13192 + aryRates[0] = 0x24; // 18M
13193 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13194 + break;
13195 + case 24000000: //24M
13196 + aryRates[0] = 0x30; // 24M
13197 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
13198 + break;
13199 + case 36000000: //36M
13200 + aryRates[0] = 0x48; // 36M
13201 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
13202 + break;
13203 + case 48000000: //48M
13204 + aryRates[0] = 0x60; // 48M
13205 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
13206 + break;
13207 + case 54000000: //54M
13208 + aryRates[0] = 0x6c; // 54M
13209 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
13210 + break;
13211 + case -1: //Auto
13212 + default:
13213 + aryRates[0] = 0x6c; // 54Mbps
13214 + aryRates[1] = 0x60; // 48Mbps
13215 + aryRates[2] = 0x48; // 36Mbps
13216 + aryRates[3] = 0x30; // 24Mbps
13217 + aryRates[4] = 0x24; // 18M
13218 + aryRates[5] = 0x18; // 12M
13219 + aryRates[6] = 0x12; // 9M
13220 + aryRates[7] = 0x0c; // 6M
13221 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
13222 + break;
13223 + }
13224 + break;
13225 + case PHY_11BG_MIXED: // B/G Mixed
13226 + case PHY_11B: // B only
13227 + case PHY_11ABG_MIXED: // A/B/G Mixed
13228 + default:
13229 + switch (Rates)
13230 + {
13231 + case 1000000: //1M
13232 + aryRates[0] = 0x02;
13233 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13234 + break;
13235 + case 2000000: //2M
13236 + aryRates[0] = 0x04;
13237 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13238 + break;
13239 + case 5000000: //5.5M
13240 + aryRates[0] = 0x0b; // 5.5M
13241 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13242 + break;
13243 + case 11000000: //11M
13244 + aryRates[0] = 0x16; // 11M
13245 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13246 + break;
13247 + case 6000000: //6M
13248 + aryRates[0] = 0x0c; // 6M
13249 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
13250 + break;
13251 + case 9000000: //9M
13252 + aryRates[0] = 0x12; // 9M
13253 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
13254 + break;
13255 + case 12000000: //12M
13256 + aryRates[0] = 0x18; // 12M
13257 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
13258 + break;
13259 + case 18000000: //18M
13260 + aryRates[0] = 0x24; // 18M
13261 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
13262 + break;
13263 + case 24000000: //24M
13264 + aryRates[0] = 0x30; // 24M
13265 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
13266 + break;
13267 + case 36000000: //36M
13268 + aryRates[0] = 0x48; // 36M
13269 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
13270 + break;
13271 + case 48000000: //48M
13272 + aryRates[0] = 0x60; // 48M
13273 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
13274 + break;
13275 + case 54000000: //54M
13276 + aryRates[0] = 0x6c; // 54M
13277 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
13278 + break;
13279 + case -1: //Auto
13280 + default:
13281 + if (pAdapter->CommonCfg.PhyMode == PHY_11B)
13282 + { //B Only
13283 + aryRates[0] = 0x16; // 11Mbps
13284 + aryRates[1] = 0x0b; // 5.5Mbps
13285 + aryRates[2] = 0x04; // 2Mbps
13286 + aryRates[3] = 0x02; // 1Mbps
13287 + }
13288 + else
13289 + { //(B/G) Mixed or (A/B/G) Mixed
13290 + aryRates[0] = 0x6c; // 54Mbps
13291 + aryRates[1] = 0x60; // 48Mbps
13292 + aryRates[2] = 0x48; // 36Mbps
13293 + aryRates[3] = 0x30; // 24Mbps
13294 + aryRates[4] = 0x16; // 11Mbps
13295 + aryRates[5] = 0x0b; // 5.5Mbps
13296 + aryRates[6] = 0x04; // 2Mbps
13297 + aryRates[7] = 0x02; // 1Mbps
13298 + }
13299 + pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
13300 + break;
13301 + }
13302 + break;
13303 + }
13304 +
13305 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
13306 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
13307 + DBGPRINT(RT_DEBUG_TRACE, (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
13308 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
13309 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
13310 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
13311 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
13312 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
13313 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
13314 +}
13315 +
13316 +NDIS_STATUS RTMPWPARemoveKeyProc(
13317 + IN PRTMP_ADAPTER pAd,
13318 + IN PVOID pBuf)
13319 +{
13320 + PNDIS_802_11_REMOVE_KEY pKey;
13321 + ULONG KeyIdx;
13322 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
13323 + BOOLEAN bTxKey; // Set the key as transmit key
13324 + BOOLEAN bPairwise; // Indicate the key is pairwise key
13325 + BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
13326 + // Otherwise, it will set by the NIC.
13327 + BOOLEAN bAuthenticator; // indicate key is set by authenticator.
13328 + INT i;
13329 +
13330 + DBGPRINT(RT_DEBUG_TRACE,("---> RTMPWPARemoveKeyProc\n"));
13331 +
13332 + pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
13333 + KeyIdx = pKey->KeyIndex & 0xff;
13334 + // Bit 31 of Add-key, Tx Key
13335 + bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
13336 + // Bit 30 of Add-key PairwiseKey
13337 + bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
13338 + // Bit 29 of Add-key KeyRSC
13339 + bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
13340 + // Bit 28 of Add-key Authenticator
13341 + bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
13342 +
13343 + // 1. If bTx is TRUE, return failure information
13344 + if (bTxKey == TRUE)
13345 + return(NDIS_STATUS_INVALID_DATA);
13346 +
13347 + // 2. Check Pairwise Key
13348 + if (bPairwise)
13349 + {
13350 + // a. If BSSID is broadcast, remove all pairwise keys.
13351 + // b. If not broadcast, remove the pairwise specified by BSSID
13352 + for (i = 0; i < SHARE_KEY_NUM; i++)
13353 + {
13354 + if (MAC_ADDR_EQUAL(pAd->SharedKey[BSS0][i].BssId, pKey->BSSID))
13355 + {
13356 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%d)\n", i));
13357 + pAd->SharedKey[BSS0][i].KeyLen = 0;
13358 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
13359 + AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)i);
13360 + Status = NDIS_STATUS_SUCCESS;
13361 + break;
13362 + }
13363 + }
13364 + }
13365 + // 3. Group Key
13366 + else
13367 + {
13368 + // a. If BSSID is broadcast, remove all group keys indexed
13369 + // b. If BSSID matched, delete the group key indexed.
13370 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%ld)\n", KeyIdx));
13371 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = 0;
13372 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
13373 + AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx);
13374 + Status = NDIS_STATUS_SUCCESS;
13375 + }
13376 +
13377 + return (Status);
13378 +}
13379 +#endif // CONFIG_STA_SUPPORT //
13380 +
13381 +
13382 +#ifdef CONFIG_STA_SUPPORT
13383 +/*
13384 + ========================================================================
13385 +
13386 + Routine Description:
13387 + Remove All WPA Keys
13388 +
13389 + Arguments:
13390 + pAd Pointer to our adapter
13391 +
13392 + Return Value:
13393 + None
13394 +
13395 + IRQL = DISPATCH_LEVEL
13396 +
13397 + Note:
13398 +
13399 + ========================================================================
13400 +*/
13401 +VOID RTMPWPARemoveAllKeys(
13402 + IN PRTMP_ADAPTER pAd)
13403 +{
13404 +
13405 + UCHAR i;
13406 +
13407 + DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
13408 +
13409 + // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after
13410 + // Link up. And it will be replaced if user changed it.
13411 + if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
13412 + return;
13413 +
13414 + // For WPA-None, there is no need to remove it, since WinXP won't set it again after
13415 + // Link up. And it will be replaced if user changed it.
13416 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
13417 + return;
13418 +
13419 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
13420 + AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
13421 +
13422 + // set all shared key mode as no-security.
13423 + for (i = 0; i < SHARE_KEY_NUM; i++)
13424 + {
13425 + DBGPRINT(RT_DEBUG_TRACE,("remove %s key #%d\n", CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
13426 + NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY));
13427 +
13428 + AsicRemoveSharedKeyEntry(pAd, BSS0, i);
13429 + }
13430 +
13431 +}
13432 +#endif // CONFIG_STA_SUPPORT //
13433 +
13434 +/*
13435 + ========================================================================
13436 + Routine Description:
13437 + Change NIC PHY mode. Re-association may be necessary. possible settings
13438 + include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
13439 +
13440 + Arguments:
13441 + pAd - Pointer to our adapter
13442 + phymode -
13443 +
13444 + IRQL = PASSIVE_LEVEL
13445 + IRQL = DISPATCH_LEVEL
13446 +
13447 + ========================================================================
13448 +*/
13449 +VOID RTMPSetPhyMode(
13450 + IN PRTMP_ADAPTER pAd,
13451 + IN ULONG phymode)
13452 +{
13453 + INT i;
13454 + // the selected phymode must be supported by the RF IC encoded in E2PROM
13455 +
13456 + pAd->CommonCfg.PhyMode = (UCHAR)phymode;
13457 +
13458 + DBGPRINT(RT_DEBUG_TRACE,("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
13459 +#ifdef EXT_BUILD_CHANNEL_LIST
13460 + BuildChannelListEx(pAd);
13461 +#else
13462 + BuildChannelList(pAd);
13463 +#endif // EXT_BUILD_CHANNEL_LIST //
13464 +
13465 + // sanity check user setting
13466 + for (i = 0; i < pAd->ChannelListNum; i++)
13467 + {
13468 + if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
13469 + break;
13470 + }
13471 +
13472 + if (i == pAd->ChannelListNum)
13473 + {
13474 +#ifdef CONFIG_STA_SUPPORT
13475 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
13476 + pAd->CommonCfg.Channel = FirstChannel(pAd);
13477 +#endif // CONFIG_STA_SUPPORT //
13478 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", pAd->CommonCfg.Channel));
13479 + }
13480 +
13481 + NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
13482 + NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
13483 + NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
13484 + switch (phymode) {
13485 + case PHY_11B:
13486 + pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
13487 + pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
13488 + pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
13489 + pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
13490 + pAd->CommonCfg.SupRateLen = 4;
13491 + pAd->CommonCfg.ExtRateLen = 0;
13492 + pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
13493 + pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
13494 + pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
13495 + pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
13496 + //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use
13497 + break;
13498 +
13499 + case PHY_11G:
13500 + case PHY_11BG_MIXED:
13501 + case PHY_11ABG_MIXED:
13502 +#ifdef DOT11_N_SUPPORT
13503 + case PHY_11N_2_4G:
13504 + case PHY_11ABGN_MIXED:
13505 + case PHY_11BGN_MIXED:
13506 + case PHY_11GN_MIXED:
13507 +#endif // DOT11_N_SUPPORT //
13508 + pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
13509 + pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
13510 + pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
13511 + pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
13512 + pAd->CommonCfg.SupRate[4] = 0x12; // 9 mbps, in units of 0.5 Mbps
13513 + pAd->CommonCfg.SupRate[5] = 0x24; // 18 mbps, in units of 0.5 Mbps
13514 + pAd->CommonCfg.SupRate[6] = 0x48; // 36 mbps, in units of 0.5 Mbps
13515 + pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
13516 + pAd->CommonCfg.SupRateLen = 8;
13517 + pAd->CommonCfg.ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps
13518 + pAd->CommonCfg.ExtRate[1] = 0x18; // 12 mbps, in units of 0.5 Mbps
13519 + pAd->CommonCfg.ExtRate[2] = 0x30; // 24 mbps, in units of 0.5 Mbps
13520 + pAd->CommonCfg.ExtRate[3] = 0x60; // 48 mbps, in units of 0.5 Mbps
13521 + pAd->CommonCfg.ExtRateLen = 4;
13522 + pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps
13523 + pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps
13524 + pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
13525 + pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps
13526 + pAd->CommonCfg.DesireRate[4] = 12; // 6 mbps, in units of 0.5 Mbps
13527 + pAd->CommonCfg.DesireRate[5] = 18; // 9 mbps, in units of 0.5 Mbps
13528 + pAd->CommonCfg.DesireRate[6] = 24; // 12 mbps, in units of 0.5 Mbps
13529 + pAd->CommonCfg.DesireRate[7] = 36; // 18 mbps, in units of 0.5 Mbps
13530 + pAd->CommonCfg.DesireRate[8] = 48; // 24 mbps, in units of 0.5 Mbps
13531 + pAd->CommonCfg.DesireRate[9] = 72; // 36 mbps, in units of 0.5 Mbps
13532 + pAd->CommonCfg.DesireRate[10] = 96; // 48 mbps, in units of 0.5 Mbps
13533 + pAd->CommonCfg.DesireRate[11] = 108; // 54 mbps, in units of 0.5 Mbps
13534 + break;
13535 +
13536 + case PHY_11A:
13537 +#ifdef DOT11_N_SUPPORT
13538 + case PHY_11AN_MIXED:
13539 + case PHY_11AGN_MIXED:
13540 + case PHY_11N_5G:
13541 +#endif // DOT11_N_SUPPORT //
13542 + pAd->CommonCfg.SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
13543 + pAd->CommonCfg.SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
13544 + pAd->CommonCfg.SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
13545 + pAd->CommonCfg.SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
13546 + pAd->CommonCfg.SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
13547 + pAd->CommonCfg.SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
13548 + pAd->CommonCfg.SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
13549 + pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
13550 + pAd->CommonCfg.SupRateLen = 8;
13551 + pAd->CommonCfg.ExtRateLen = 0;
13552 + pAd->CommonCfg.DesireRate[0] = 12; // 6 mbps, in units of 0.5 Mbps
13553 + pAd->CommonCfg.DesireRate[1] = 18; // 9 mbps, in units of 0.5 Mbps
13554 + pAd->CommonCfg.DesireRate[2] = 24; // 12 mbps, in units of 0.5 Mbps
13555 + pAd->CommonCfg.DesireRate[3] = 36; // 18 mbps, in units of 0.5 Mbps
13556 + pAd->CommonCfg.DesireRate[4] = 48; // 24 mbps, in units of 0.5 Mbps
13557 + pAd->CommonCfg.DesireRate[5] = 72; // 36 mbps, in units of 0.5 Mbps
13558 + pAd->CommonCfg.DesireRate[6] = 96; // 48 mbps, in units of 0.5 Mbps
13559 + pAd->CommonCfg.DesireRate[7] = 108; // 54 mbps, in units of 0.5 Mbps
13560 + //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use
13561 + break;
13562 +
13563 + default:
13564 + break;
13565 + }
13566 +
13567 +
13568 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
13569 +}
13570 +
13571 +
13572 +#ifdef DOT11_N_SUPPORT
13573 +/*
13574 + ========================================================================
13575 + Routine Description:
13576 + Caller ensures we has 802.11n support.
13577 + Calls at setting HT from AP/STASetinformation
13578 +
13579 + Arguments:
13580 + pAd - Pointer to our adapter
13581 + phymode -
13582 +
13583 + ========================================================================
13584 +*/
13585 +VOID RTMPSetHT(
13586 + IN PRTMP_ADAPTER pAd,
13587 + IN OID_SET_HT_PHYMODE *pHTPhyMode)
13588 +{
13589 + //ULONG *pmcs;
13590 + UINT32 Value = 0;
13591 + UCHAR BBPValue = 0;
13592 + UCHAR BBP3Value = 0;
13593 + UCHAR RxStream = pAd->CommonCfg.RxStream;
13594 +
13595 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
13596 + pHTPhyMode->HtMode, pHTPhyMode->ExtOffset,
13597 + pHTPhyMode->MCS, pHTPhyMode->BW,
13598 + pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
13599 +
13600 + // Don't zero supportedHyPhy structure.
13601 + RTMPZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
13602 + RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
13603 + RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, sizeof(pAd->CommonCfg.NewExtChanOffset));
13604 + RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, sizeof(pAd->CommonCfg.DesiredHtPhy));
13605 +
13606 + if (pAd->CommonCfg.bRdg)
13607 + {
13608 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
13609 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
13610 + }
13611 + else
13612 + {
13613 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
13614 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
13615 + }
13616 +
13617 + pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
13618 + pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
13619 +
13620 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : RxBAWinLimit = %d\n", pAd->CommonCfg.BACapability.field.RxBAWinLimit));
13621 +
13622 + // Mimo power save, A-MSDU size,
13623 + pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
13624 + pAd->CommonCfg.DesiredHtPhy.AmsduSize = (UCHAR)pAd->CommonCfg.BACapability.field.AmsduSize;
13625 + pAd->CommonCfg.DesiredHtPhy.MimoPs = (UCHAR)pAd->CommonCfg.BACapability.field.MMPSmode;
13626 + pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
13627 +
13628 + pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
13629 + pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
13630 + pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
13631 +
13632 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
13633 + pAd->CommonCfg.DesiredHtPhy.AmsduSize,
13634 + pAd->CommonCfg.DesiredHtPhy.MimoPs,
13635 + pAd->CommonCfg.DesiredHtPhy.MpduDensity,
13636 + pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
13637 +
13638 + if(pHTPhyMode->HtMode == HTMODE_GF)
13639 + {
13640 + pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
13641 + pAd->CommonCfg.DesiredHtPhy.GF = 1;
13642 + }
13643 + else
13644 + pAd->CommonCfg.DesiredHtPhy.GF = 0;
13645 +
13646 + // Decide Rx MCSSet
13647 + switch (RxStream)
13648 + {
13649 + case 1:
13650 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13651 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00;
13652 + break;
13653 +
13654 + case 2:
13655 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13656 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
13657 + break;
13658 +
13659 + case 3: // 3*3
13660 + pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
13661 + pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
13662 + pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff;
13663 + break;
13664 + }
13665 +
13666 + if (pAd->CommonCfg.bForty_Mhz_Intolerant && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40) )
13667 + {
13668 + pHTPhyMode->BW = BW_20;
13669 + pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
13670 + }
13671 +
13672 + if(pHTPhyMode->BW == BW_40)
13673 + {
13674 + pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32
13675 + pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
13676 + if (pAd->CommonCfg.Channel <= 14)
13677 + pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
13678 +
13679 + pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
13680 + pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
13681 + pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = (pHTPhyMode->ExtOffset == EXTCHA_BELOW)? (EXTCHA_BELOW): EXTCHA_ABOVE;
13682 + // Set Regsiter for extension channel position.
13683 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
13684 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
13685 + if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW))
13686 + {
13687 + Value |= 0x1;
13688 + BBP3Value |= (0x20);
13689 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
13690 + }
13691 + else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE))
13692 + {
13693 + Value &= 0xfe;
13694 + BBP3Value &= (~0x20);
13695 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
13696 + }
13697 +
13698 + // Turn on BBP 40MHz mode now only as AP .
13699 + // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection.
13700 + if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
13701 + )
13702 + {
13703 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
13704 + BBPValue &= (~0x18);
13705 + BBPValue |= 0x10;
13706 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
13707 +
13708 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
13709 + pAd->CommonCfg.BBPCurrentBW = BW_40;
13710 + }
13711 + }
13712 + else
13713 + {
13714 + pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
13715 + pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
13716 + pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
13717 + pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
13718 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
13719 + // Turn on BBP 20MHz mode by request here.
13720 + {
13721 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
13722 + BBPValue &= (~0x18);
13723 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
13724 + pAd->CommonCfg.BBPCurrentBW = BW_20;
13725 + }
13726 + }
13727 +
13728 + if(pHTPhyMode->STBC == STBC_USE)
13729 + {
13730 + pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
13731 + pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
13732 + pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
13733 + pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
13734 + }
13735 + else
13736 + {
13737 + pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
13738 + pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
13739 + }
13740 +
13741 + if(pHTPhyMode->SHORTGI == GI_400)
13742 + {
13743 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
13744 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
13745 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
13746 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
13747 + }
13748 + else
13749 + {
13750 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
13751 + pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
13752 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
13753 + pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
13754 + }
13755 +
13756 + // We support link adaptation for unsolicit MCS feedback, set to 2.
13757 + pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT;
13758 + pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
13759 + // 1, the extension channel above the control channel.
13760 +
13761 + // EDCA parameters used for AP's own transmission
13762 + if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
13763 + {
13764 + pAd->CommonCfg.APEdcaParm.bValid = TRUE;
13765 + pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
13766 + pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
13767 + pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
13768 + pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
13769 +
13770 + pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
13771 + pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
13772 + pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
13773 + pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
13774 +
13775 + pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
13776 + pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
13777 + pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
13778 + pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
13779 +
13780 + pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
13781 + pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
13782 + pAd->CommonCfg.APEdcaParm.Txop[2] = 94;
13783 + pAd->CommonCfg.APEdcaParm.Txop[3] = 47;
13784 + }
13785 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
13786 +
13787 +
13788 +#ifdef CONFIG_STA_SUPPORT
13789 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
13790 + {
13791 + RTMPSetIndividualHT(pAd, 0);
13792 + }
13793 +#endif // CONFIG_STA_SUPPORT //
13794 +
13795 +}
13796 +
13797 +/*
13798 + ========================================================================
13799 + Routine Description:
13800 + Caller ensures we has 802.11n support.
13801 + Calls at setting HT from AP/STASetinformation
13802 +
13803 + Arguments:
13804 + pAd - Pointer to our adapter
13805 + phymode -
13806 +
13807 + ========================================================================
13808 +*/
13809 +VOID RTMPSetIndividualHT(
13810 + IN PRTMP_ADAPTER pAd,
13811 + IN UCHAR apidx)
13812 +{
13813 + PRT_HT_PHY_INFO pDesired_ht_phy = NULL;
13814 + UCHAR TxStream = pAd->CommonCfg.TxStream;
13815 + UCHAR DesiredMcs = MCS_AUTO;
13816 +
13817 + do
13818 + {
13819 +
13820 +#ifdef CONFIG_STA_SUPPORT
13821 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
13822 + {
13823 + pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
13824 + DesiredMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
13825 + //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE;
13826 + break;
13827 + }
13828 +#endif // CONFIG_STA_SUPPORT //
13829 + } while (FALSE);
13830 +
13831 + if (pDesired_ht_phy == NULL)
13832 + {
13833 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
13834 + return;
13835 + }
13836 + RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO));
13837 +
13838 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
13839 + // Check the validity of MCS
13840 + if ((TxStream == 1) && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15)))
13841 + {
13842 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", DesiredMcs));
13843 + DesiredMcs = MCS_7;
13844 + }
13845 +
13846 + if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) && (DesiredMcs == MCS_32))
13847 + {
13848 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
13849 + DesiredMcs = MCS_0;
13850 + }
13851 +
13852 + pDesired_ht_phy->bHtEnable = TRUE;
13853 +
13854 + // Decide desired Tx MCS
13855 + switch (TxStream)
13856 + {
13857 + case 1:
13858 + if (DesiredMcs == MCS_AUTO)
13859 + {
13860 + pDesired_ht_phy->MCSSet[0]= 0xff;
13861 + pDesired_ht_phy->MCSSet[1]= 0x00;
13862 + }
13863 + else if (DesiredMcs <= MCS_7)
13864 + {
13865 + pDesired_ht_phy->MCSSet[0]= 1<<DesiredMcs;
13866 + pDesired_ht_phy->MCSSet[1]= 0x00;
13867 + }
13868 + break;
13869 +
13870 + case 2:
13871 + if (DesiredMcs == MCS_AUTO)
13872 + {
13873 + pDesired_ht_phy->MCSSet[0]= 0xff;
13874 + pDesired_ht_phy->MCSSet[1]= 0xff;
13875 + }
13876 + else if (DesiredMcs <= MCS_15)
13877 + {
13878 + ULONG mode;
13879 +
13880 + mode = DesiredMcs / 8;
13881 + if (mode < 2)
13882 + pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
13883 + }
13884 + break;
13885 +
13886 + case 3: // 3*3
13887 + if (DesiredMcs == MCS_AUTO)
13888 + {
13889 + /* MCS0 ~ MCS23, 3 bytes */
13890 + pDesired_ht_phy->MCSSet[0]= 0xff;
13891 + pDesired_ht_phy->MCSSet[1]= 0xff;
13892 + pDesired_ht_phy->MCSSet[2]= 0xff;
13893 + }
13894 + else if (DesiredMcs <= MCS_23)
13895 + {
13896 + ULONG mode;
13897 +
13898 + mode = DesiredMcs / 8;
13899 + if (mode < 3)
13900 + pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
13901 + }
13902 + break;
13903 + }
13904 +
13905 + if(pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40)
13906 + {
13907 + if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
13908 + pDesired_ht_phy->MCSSet[4] = 0x1;
13909 + }
13910 +
13911 + // update HT Rate setting
13912 + if (pAd->OpMode == OPMODE_STA)
13913 + MlmeUpdateHtTxRates(pAd, BSS0);
13914 + else
13915 + MlmeUpdateHtTxRates(pAd, apidx);
13916 +}
13917 +
13918 +
13919 +/*
13920 + ========================================================================
13921 + Routine Description:
13922 + Update HT IE from our capability.
13923 +
13924 + Arguments:
13925 + Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
13926 +
13927 +
13928 + ========================================================================
13929 +*/
13930 +VOID RTMPUpdateHTIE(
13931 + IN RT_HT_CAPABILITY *pRtHt,
13932 + IN UCHAR *pMcsSet,
13933 + OUT HT_CAPABILITY_IE *pHtCapability,
13934 + OUT ADD_HT_INFO_IE *pAddHtInfo)
13935 +{
13936 + RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE));
13937 + RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE));
13938 +
13939 + pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
13940 + pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
13941 + pHtCapability->HtCapInfo.GF = pRtHt->GF;
13942 + pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
13943 + pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
13944 + pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
13945 + pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
13946 + pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
13947 + pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
13948 + pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
13949 +
13950 + pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset ;
13951 + pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
13952 + pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
13953 + pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
13954 + RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet*/pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar.
13955 +
13956 + DBGPRINT(RT_DEBUG_TRACE,("RTMPUpdateHTIE <== \n"));
13957 +}
13958 +#endif // DOT11_N_SUPPORT //
13959 +
13960 +/*
13961 + ========================================================================
13962 + Description:
13963 + Add Client security information into ASIC WCID table and IVEIV table.
13964 + Return:
13965 + ========================================================================
13966 +*/
13967 +VOID RTMPAddWcidAttributeEntry(
13968 + IN PRTMP_ADAPTER pAd,
13969 + IN UCHAR BssIdx,
13970 + IN UCHAR KeyIdx,
13971 + IN UCHAR CipherAlg,
13972 + IN MAC_TABLE_ENTRY *pEntry)
13973 +{
13974 + UINT32 WCIDAttri = 0;
13975 + USHORT offset;
13976 + UCHAR IVEIV = 0;
13977 + USHORT Wcid = 0;
13978 +
13979 + {
13980 +#ifdef CONFIG_STA_SUPPORT
13981 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
13982 + {
13983 + if (BssIdx > BSS0)
13984 + {
13985 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", BssIdx));
13986 + return;
13987 + }
13988 +
13989 + // 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists.
13990 + // 2. In Infra mode, the AID:1 MUST be wcid of infra STA.
13991 + // the AID:2~ assign to mesh link entry.
13992 + if (pEntry && ADHOC_ON(pAd))
13993 + Wcid = pEntry->Aid;
13994 + else if (pEntry && INFRA_ON(pAd))
13995 + {
13996 +#ifdef QOS_DLS_SUPPORT
13997 + if (pEntry->ValidAsDls == TRUE)
13998 + Wcid = pEntry->Aid;
13999 + else
14000 +#endif // QOS_DLS_SUPPORT //
14001 + Wcid = BSSID_WCID;
14002 + }
14003 + else
14004 + Wcid = MCAST_WCID;
14005 + }
14006 +#endif // CONFIG_STA_SUPPORT //
14007 + }
14008 +
14009 + // Update WCID attribute table
14010 + offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
14011 +
14012 +#ifdef CONFIG_STA_SUPPORT
14013 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14014 + {
14015 + if (pEntry && pEntry->ValidAsMesh)
14016 + WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
14017 +#ifdef QOS_DLS_SUPPORT
14018 + else if ((pEntry) && (pEntry->ValidAsDls) &&
14019 + ((CipherAlg == CIPHER_TKIP) ||
14020 + (CipherAlg == CIPHER_TKIP_NO_MIC) ||
14021 + (CipherAlg == CIPHER_AES) ||
14022 + (CipherAlg == CIPHER_NONE)))
14023 + WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
14024 +#endif // QOS_DLS_SUPPORT //
14025 + else
14026 + WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE;
14027 + }
14028 +#endif // CONFIG_STA_SUPPORT //
14029 +
14030 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
14031 +
14032 +
14033 + // Update IV/EIV table
14034 + offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
14035 +
14036 + // WPA mode
14037 + if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES))
14038 + {
14039 + // Eiv bit on. keyid always is 0 for pairwise key
14040 + IVEIV = (KeyIdx <<6) | 0x20;
14041 + }
14042 + else
14043 + {
14044 + // WEP KeyIdx is default tx key.
14045 + IVEIV = (KeyIdx << 6);
14046 + }
14047 +
14048 + // For key index and ext IV bit, so only need to update the position(offset+3).
14049 +#ifdef RT2870
14050 + RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV);
14051 +#endif // RT2870 //
14052 +
14053 + DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg]));
14054 + DBGPRINT(RT_DEBUG_TRACE,(" WCIDAttri = 0x%x \n", WCIDAttri));
14055 +
14056 +}
14057 +
14058 +/*
14059 + ==========================================================================
14060 + Description:
14061 + Parse encryption type
14062 +Arguments:
14063 + pAdapter Pointer to our adapter
14064 + wrq Pointer to the ioctl argument
14065 +
14066 + Return Value:
14067 + None
14068 +
14069 + Note:
14070 + ==========================================================================
14071 +*/
14072 +CHAR *GetEncryptType(CHAR enc)
14073 +{
14074 + if(enc == Ndis802_11WEPDisabled)
14075 + return "NONE";
14076 + if(enc == Ndis802_11WEPEnabled)
14077 + return "WEP";
14078 + if(enc == Ndis802_11Encryption2Enabled)
14079 + return "TKIP";
14080 + if(enc == Ndis802_11Encryption3Enabled)
14081 + return "AES";
14082 + if(enc == Ndis802_11Encryption4Enabled)
14083 + return "TKIPAES";
14084 + else
14085 + return "UNKNOW";
14086 +}
14087 +
14088 +CHAR *GetAuthMode(CHAR auth)
14089 +{
14090 + if(auth == Ndis802_11AuthModeOpen)
14091 + return "OPEN";
14092 + if(auth == Ndis802_11AuthModeShared)
14093 + return "SHARED";
14094 + if(auth == Ndis802_11AuthModeAutoSwitch)
14095 + return "AUTOWEP";
14096 + if(auth == Ndis802_11AuthModeWPA)
14097 + return "WPA";
14098 + if(auth == Ndis802_11AuthModeWPAPSK)
14099 + return "WPAPSK";
14100 + if(auth == Ndis802_11AuthModeWPANone)
14101 + return "WPANONE";
14102 + if(auth == Ndis802_11AuthModeWPA2)
14103 + return "WPA2";
14104 + if(auth == Ndis802_11AuthModeWPA2PSK)
14105 + return "WPA2PSK";
14106 + if(auth == Ndis802_11AuthModeWPA1WPA2)
14107 + return "WPA1WPA2";
14108 + if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
14109 + return "WPA1PSKWPA2PSK";
14110 +
14111 + return "UNKNOW";
14112 +}
14113 +
14114 +#if 1 //#ifndef UCOS
14115 +/*
14116 + ==========================================================================
14117 + Description:
14118 + Get site survey results
14119 + Arguments:
14120 + pAdapter Pointer to our adapter
14121 + wrq Pointer to the ioctl argument
14122 +
14123 + Return Value:
14124 + None
14125 +
14126 + Note:
14127 + Usage:
14128 + 1.) UI needs to wait 4 seconds after issue a site survey command
14129 + 2.) iwpriv ra0 get_site_survey
14130 + 3.) UI needs to prepare at least 4096bytes to get the results
14131 + ==========================================================================
14132 +*/
14133 +#define LINE_LEN (4+33+20+8+10+9+7+3) // Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType
14134 +#ifdef CONFIG_STA_SUPPORT
14135 +#endif // CONFIG_STA_SUPPORT //
14136 +VOID RTMPIoctlGetSiteSurvey(
14137 + IN PRTMP_ADAPTER pAdapter,
14138 + IN struct iwreq *wrq)
14139 +{
14140 + CHAR *msg;
14141 + INT i=0;
14142 + INT WaitCnt;
14143 + INT Status=0;
14144 + CHAR Ssid[MAX_LEN_OF_SSID +1];
14145 + INT Rssi = 0, max_len = LINE_LEN;
14146 + UINT Rssi_Quality = 0;
14147 + NDIS_802_11_NETWORK_TYPE wireless_mode;
14148 +
14149 + os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len));
14150 +
14151 + if (msg == NULL)
14152 + {
14153 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n"));
14154 + return;
14155 + }
14156 +
14157 + memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len );
14158 + memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1));
14159 + sprintf(msg,"%s","\n");
14160 + sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n",
14161 + "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT");
14162 +
14163 +#ifdef CONFIG_STA_SUPPORT
14164 +#endif // CONFIG_STA_SUPPORT //
14165 +
14166 + WaitCnt = 0;
14167 +#ifdef CONFIG_STA_SUPPORT
14168 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
14169 + while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200))
14170 + OS_WAIT(500);
14171 +#endif // CONFIG_STA_SUPPORT //
14172 +
14173 + for(i=0; i<pAdapter->ScanTab.BssNr ;i++)
14174 + {
14175 + if( pAdapter->ScanTab.BssEntry[i].Channel==0)
14176 + break;
14177 +
14178 + if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA)
14179 + break;
14180 +
14181 + //Channel
14182 + sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel);
14183 + //SSID
14184 + memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
14185 + Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0';
14186 + sprintf(msg+strlen(msg),"%-33s", Ssid);
14187 + //BSSID
14188 + sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x ",
14189 + pAdapter->ScanTab.BssEntry[i].Bssid[0],
14190 + pAdapter->ScanTab.BssEntry[i].Bssid[1],
14191 + pAdapter->ScanTab.BssEntry[i].Bssid[2],
14192 + pAdapter->ScanTab.BssEntry[i].Bssid[3],
14193 + pAdapter->ScanTab.BssEntry[i].Bssid[4],
14194 + pAdapter->ScanTab.BssEntry[i].Bssid[5]);
14195 + //Encryption Type
14196 + sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus));
14197 + //Authentication Mode
14198 + if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled)
14199 + sprintf(msg+strlen(msg),"%-10s", "UNKNOW");
14200 + else
14201 + sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode));
14202 + // Rssi
14203 + Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi;
14204 + if (Rssi >= -50)
14205 + Rssi_Quality = 100;
14206 + else if (Rssi >= -80) // between -50 ~ -80dbm
14207 + Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10);
14208 + else if (Rssi >= -90) // between -80 ~ -90dbm
14209 + Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10);
14210 + else // < -84 dbm
14211 + Rssi_Quality = 0;
14212 + sprintf(msg+strlen(msg),"%-9d", Rssi_Quality);
14213 + // Wireless Mode
14214 + wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
14215 + if (wireless_mode == Ndis802_11FH ||
14216 + wireless_mode == Ndis802_11DS)
14217 + sprintf(msg+strlen(msg),"%-7s", "11b");
14218 + else if (wireless_mode == Ndis802_11OFDM5)
14219 + sprintf(msg+strlen(msg),"%-7s", "11a");
14220 + else if (wireless_mode == Ndis802_11OFDM5_N)
14221 + sprintf(msg+strlen(msg),"%-7s", "11a/n");
14222 + else if (wireless_mode == Ndis802_11OFDM24)
14223 + sprintf(msg+strlen(msg),"%-7s", "11b/g");
14224 + else if (wireless_mode == Ndis802_11OFDM24_N)
14225 + sprintf(msg+strlen(msg),"%-7s", "11b/g/n");
14226 + else
14227 + sprintf(msg+strlen(msg),"%-7s", "unknow");
14228 + //Network Type
14229 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC)
14230 + sprintf(msg+strlen(msg),"%-3s", " Ad");
14231 + else
14232 + sprintf(msg+strlen(msg),"%-3s", " In");
14233 +
14234 + sprintf(msg+strlen(msg),"\n");
14235 +#ifdef CONFIG_STA_SUPPORT
14236 +#endif // CONFIG_STA_SUPPORT //
14237 + }
14238 +
14239 +#ifdef CONFIG_STA_SUPPORT
14240 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
14241 +#endif // CONFIG_STA_SUPPORT //
14242 + wrq->u.data.length = strlen(msg);
14243 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
14244 +
14245 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length));
14246 + os_free_mem(NULL, (PUCHAR)msg);
14247 +}
14248 +
14249 +
14250 +#define MAC_LINE_LEN (14+4+4+10+10+10+6+6) // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate
14251 +VOID RTMPIoctlGetMacTable(
14252 + IN PRTMP_ADAPTER pAd,
14253 + IN struct iwreq *wrq)
14254 +{
14255 + INT i;
14256 + RT_802_11_MAC_TABLE MacTab;
14257 + char *msg;
14258 +
14259 + MacTab.Num = 0;
14260 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
14261 + {
14262 + if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))
14263 + {
14264 + COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);
14265 + MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;
14266 + MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;
14267 +#ifdef DOT11_N_SUPPORT
14268 + MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;
14269 +#endif // DOT11_N_SUPPORT //
14270 +
14271 + // Fill in RSSI per entry
14272 + MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;
14273 + MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;
14274 + MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;
14275 +
14276 + // the connected time per entry
14277 + MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;
14278 + MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;
14279 + MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;
14280 + MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;
14281 + MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;
14282 + MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;
14283 + MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;
14284 + MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;
14285 +
14286 + MacTab.Num += 1;
14287 + }
14288 + }
14289 + wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);
14290 + if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))
14291 + {
14292 + DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __FUNCTION__));
14293 + }
14294 +
14295 + msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);
14296 + memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );
14297 + sprintf(msg,"%s","\n");
14298 + sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",
14299 + "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");
14300 +
14301 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
14302 + {
14303 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
14304 + if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))
14305 + {
14306 + if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )
14307 + break;
14308 + sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x ",
14309 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
14310 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
14311 + sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);
14312 + sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);
14313 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo
14314 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo
14315 + sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo
14316 + sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);
14317 + sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo
14318 + }
14319 + }
14320 + // for compatible with old API just do the printk to console
14321 + //wrq->u.data.length = strlen(msg);
14322 + //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
14323 + {
14324 + DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));
14325 + }
14326 +
14327 + kfree(msg);
14328 +}
14329 +#endif // UCOS //
14330 +
14331 +#ifdef DOT11_N_SUPPORT
14332 +INT Set_BASetup_Proc(
14333 + IN PRTMP_ADAPTER pAd,
14334 + IN PUCHAR arg)
14335 +{
14336 + UCHAR mac[6], tid;
14337 + char *token, sepValue[] = ":", DASH = '-';
14338 + INT i;
14339 + MAC_TABLE_ENTRY *pEntry;
14340 +
14341 +/*
14342 + The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d,
14343 + =>The six 2 digit hex-decimal number previous are the Mac address,
14344 + =>The seventh decimal number is the tid value.
14345 +*/
14346 + //printk("\n%s\n", arg);
14347 +
14348 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14349 + return FALSE;
14350 +
14351 + token = strchr(arg, DASH);
14352 + if ((token != NULL) && (strlen(token)>1))
14353 + {
14354 + tid = simple_strtol((token+1), 0, 10);
14355 + if (tid > 15)
14356 + return FALSE;
14357 +
14358 + *token = '\0';
14359 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14360 + {
14361 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14362 + return FALSE;
14363 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14364 + }
14365 + if(i != 6)
14366 + return FALSE;
14367 +
14368 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1],
14369 + mac[2], mac[3], mac[4], mac[5], tid);
14370 +
14371 + pEntry = MacTableLookup(pAd, mac);
14372 +
14373 + if (pEntry) {
14374 + printk("\nSetup BA Session: Tid = %d\n", tid);
14375 + BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);
14376 + }
14377 +
14378 + return TRUE;
14379 + }
14380 +
14381 + return FALSE;
14382 +
14383 +}
14384 +
14385 +INT Set_BADecline_Proc(
14386 + IN PRTMP_ADAPTER pAd,
14387 + IN PUCHAR arg)
14388 +{
14389 + ULONG bBADecline;
14390 +
14391 + bBADecline = simple_strtol(arg, 0, 10);
14392 +
14393 + if (bBADecline == 0)
14394 + {
14395 + pAd->CommonCfg.bBADecline = FALSE;
14396 + }
14397 + else if (bBADecline == 1)
14398 + {
14399 + pAd->CommonCfg.bBADecline = TRUE;
14400 + }
14401 + else
14402 + {
14403 + return FALSE; //Invalid argument
14404 + }
14405 +
14406 + DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));
14407 +
14408 + return TRUE;
14409 +}
14410 +
14411 +INT Set_BAOriTearDown_Proc(
14412 + IN PRTMP_ADAPTER pAd,
14413 + IN PUCHAR arg)
14414 +{
14415 + UCHAR mac[6], tid;
14416 + char *token, sepValue[] = ":", DASH = '-';
14417 + INT i;
14418 + MAC_TABLE_ENTRY *pEntry;
14419 +
14420 + //printk("\n%s\n", arg);
14421 +/*
14422 + The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
14423 + =>The six 2 digit hex-decimal number previous are the Mac address,
14424 + =>The seventh decimal number is the tid value.
14425 +*/
14426 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14427 + return FALSE;
14428 +
14429 + token = strchr(arg, DASH);
14430 + if ((token != NULL) && (strlen(token)>1))
14431 + {
14432 + tid = simple_strtol((token+1), 0, 10);
14433 + if (tid > NUM_OF_TID)
14434 + return FALSE;
14435 +
14436 + *token = '\0';
14437 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14438 + {
14439 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14440 + return FALSE;
14441 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14442 + }
14443 + if(i != 6)
14444 + return FALSE;
14445 +
14446 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
14447 + mac[2], mac[3], mac[4], mac[5], tid);
14448 +
14449 + pEntry = MacTableLookup(pAd, mac);
14450 +
14451 + if (pEntry) {
14452 + printk("\nTear down Ori BA Session: Tid = %d\n", tid);
14453 + BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE);
14454 + }
14455 +
14456 + return TRUE;
14457 + }
14458 +
14459 + return FALSE;
14460 +
14461 +}
14462 +
14463 +INT Set_BARecTearDown_Proc(
14464 + IN PRTMP_ADAPTER pAd,
14465 + IN PUCHAR arg)
14466 +{
14467 + UCHAR mac[6], tid;
14468 + char *token, sepValue[] = ":", DASH = '-';
14469 + INT i;
14470 + MAC_TABLE_ENTRY *pEntry;
14471 +
14472 + //printk("\n%s\n", arg);
14473 +/*
14474 + The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
14475 + =>The six 2 digit hex-decimal number previous are the Mac address,
14476 + =>The seventh decimal number is the tid value.
14477 +*/
14478 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
14479 + return FALSE;
14480 +
14481 + token = strchr(arg, DASH);
14482 + if ((token != NULL) && (strlen(token)>1))
14483 + {
14484 + tid = simple_strtol((token+1), 0, 10);
14485 + if (tid > NUM_OF_TID)
14486 + return FALSE;
14487 +
14488 + *token = '\0';
14489 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14490 + {
14491 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14492 + return FALSE;
14493 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14494 + }
14495 + if(i != 6)
14496 + return FALSE;
14497 +
14498 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
14499 + mac[2], mac[3], mac[4], mac[5], tid);
14500 +
14501 + pEntry = MacTableLookup(pAd, mac);
14502 +
14503 + if (pEntry) {
14504 + printk("\nTear down Rec BA Session: Tid = %d\n", tid);
14505 + BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE);
14506 + }
14507 +
14508 + return TRUE;
14509 + }
14510 +
14511 + return FALSE;
14512 +
14513 +}
14514 +
14515 +INT Set_HtBw_Proc(
14516 + IN PRTMP_ADAPTER pAd,
14517 + IN PUCHAR arg)
14518 +{
14519 + ULONG HtBw;
14520 +
14521 + HtBw = simple_strtol(arg, 0, 10);
14522 + if (HtBw == BW_40)
14523 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
14524 + else if (HtBw == BW_20)
14525 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
14526 + else
14527 + return FALSE; //Invalid argument
14528 +
14529 + SetCommonHT(pAd);
14530 +
14531 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW));
14532 +
14533 + return TRUE;
14534 +}
14535 +
14536 +INT Set_HtMcs_Proc(
14537 + IN PRTMP_ADAPTER pAd,
14538 + IN PUCHAR arg)
14539 +{
14540 + ULONG HtMcs, Mcs_tmp;
14541 +#ifdef CONFIG_STA_SUPPORT
14542 + BOOLEAN bAutoRate = FALSE;
14543 +#endif // CONFIG_STA_SUPPORT //
14544 +
14545 + Mcs_tmp = simple_strtol(arg, 0, 10);
14546 +
14547 + if (Mcs_tmp <= 15 || Mcs_tmp == 32)
14548 + HtMcs = Mcs_tmp;
14549 + else
14550 + HtMcs = MCS_AUTO;
14551 +
14552 +#ifdef CONFIG_STA_SUPPORT
14553 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
14554 + {
14555 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs;
14556 + pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE;
14557 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n",
14558 + pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch));
14559 +
14560 + if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) ||
14561 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
14562 + {
14563 + if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
14564 + (HtMcs >= 0 && HtMcs <= 3) &&
14565 + (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
14566 + {
14567 + RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
14568 + }
14569 + else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
14570 + (HtMcs >= 0 && HtMcs <= 7) &&
14571 + (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
14572 + {
14573 + RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
14574 + }
14575 + else
14576 + bAutoRate = TRUE;
14577 +
14578 + if (bAutoRate)
14579 + {
14580 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
14581 + RTMPSetDesiredRates(pAd, -1);
14582 + }
14583 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode));
14584 + }
14585 + if (ADHOC_ON(pAd))
14586 + return TRUE;
14587 + }
14588 +#endif // CONFIG_STA_SUPPORT //
14589 +
14590 + SetCommonHT(pAd);
14591 +
14592 + return TRUE;
14593 +}
14594 +
14595 +INT Set_HtGi_Proc(
14596 + IN PRTMP_ADAPTER pAd,
14597 + IN PUCHAR arg)
14598 +{
14599 + ULONG HtGi;
14600 +
14601 + HtGi = simple_strtol(arg, 0, 10);
14602 +
14603 + if ( HtGi == GI_400)
14604 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
14605 + else if ( HtGi == GI_800 )
14606 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
14607 + else
14608 + return FALSE; //Invalid argument
14609 +
14610 + SetCommonHT(pAd);
14611 +
14612 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI));
14613 +
14614 + return TRUE;
14615 +}
14616 +
14617 +
14618 +INT Set_HtTxBASize_Proc(
14619 + IN PRTMP_ADAPTER pAd,
14620 + IN PUCHAR arg)
14621 +{
14622 + UCHAR Size;
14623 +
14624 + Size = simple_strtol(arg, 0, 10);
14625 +
14626 + if (Size <=0 || Size >=64)
14627 + {
14628 + Size = 8;
14629 + }
14630 + pAd->CommonCfg.TxBASize = Size-1;
14631 + DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
14632 +
14633 + return TRUE;
14634 +}
14635 +
14636 +
14637 +INT Set_HtOpMode_Proc(
14638 + IN PRTMP_ADAPTER pAd,
14639 + IN PUCHAR arg)
14640 +{
14641 +
14642 + ULONG Value;
14643 +
14644 + Value = simple_strtol(arg, 0, 10);
14645 +
14646 + if (Value == HTMODE_GF)
14647 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
14648 + else if ( Value == HTMODE_MM )
14649 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
14650 + else
14651 + return FALSE; //Invalid argument
14652 +
14653 + SetCommonHT(pAd);
14654 +
14655 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE));
14656 +
14657 + return TRUE;
14658 +
14659 +}
14660 +
14661 +INT Set_HtStbc_Proc(
14662 + IN PRTMP_ADAPTER pAd,
14663 + IN PUCHAR arg)
14664 +{
14665 +
14666 + ULONG Value;
14667 +
14668 + Value = simple_strtol(arg, 0, 10);
14669 +
14670 + if (Value == STBC_USE)
14671 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
14672 + else if ( Value == STBC_NONE )
14673 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
14674 + else
14675 + return FALSE; //Invalid argument
14676 +
14677 + SetCommonHT(pAd);
14678 +
14679 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC));
14680 +
14681 + return TRUE;
14682 +}
14683 +
14684 +INT Set_HtHtc_Proc(
14685 + IN PRTMP_ADAPTER pAd,
14686 + IN PUCHAR arg)
14687 +{
14688 +
14689 + ULONG Value;
14690 +
14691 + Value = simple_strtol(arg, 0, 10);
14692 + if (Value == 0)
14693 + pAd->HTCEnable = FALSE;
14694 + else if ( Value ==1 )
14695 + pAd->HTCEnable = TRUE;
14696 + else
14697 + return FALSE; //Invalid argument
14698 +
14699 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable));
14700 +
14701 + return TRUE;
14702 +}
14703 +
14704 +INT Set_HtExtcha_Proc(
14705 + IN PRTMP_ADAPTER pAd,
14706 + IN PUCHAR arg)
14707 +{
14708 +
14709 + ULONG Value;
14710 +
14711 + Value = simple_strtol(arg, 0, 10);
14712 +
14713 + if (Value == 0)
14714 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
14715 + else if ( Value ==1 )
14716 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
14717 + else
14718 + return FALSE; //Invalid argument
14719 +
14720 + SetCommonHT(pAd);
14721 +
14722 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA));
14723 +
14724 + return TRUE;
14725 +}
14726 +
14727 +INT Set_HtMpduDensity_Proc(
14728 + IN PRTMP_ADAPTER pAd,
14729 + IN PUCHAR arg)
14730 +{
14731 + ULONG Value;
14732 +
14733 + Value = simple_strtol(arg, 0, 10);
14734 +
14735 + if (Value <=7 && Value >= 0)
14736 + pAd->CommonCfg.BACapability.field.MpduDensity = Value;
14737 + else
14738 + pAd->CommonCfg.BACapability.field.MpduDensity = 4;
14739 +
14740 + SetCommonHT(pAd);
14741 +
14742 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity));
14743 +
14744 + return TRUE;
14745 +}
14746 +
14747 +INT Set_HtBaWinSize_Proc(
14748 + IN PRTMP_ADAPTER pAd,
14749 + IN PUCHAR arg)
14750 +{
14751 + ULONG Value;
14752 +
14753 + Value = simple_strtol(arg, 0, 10);
14754 +
14755 +
14756 + if (Value >=1 && Value <= 64)
14757 + {
14758 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
14759 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
14760 + }
14761 + else
14762 + {
14763 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
14764 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
14765 + }
14766 +
14767 + SetCommonHT(pAd);
14768 +
14769 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit));
14770 +
14771 + return TRUE;
14772 +}
14773 +
14774 +INT Set_HtRdg_Proc(
14775 + IN PRTMP_ADAPTER pAd,
14776 + IN PUCHAR arg)
14777 +{
14778 + ULONG Value;
14779 +
14780 + Value = simple_strtol(arg, 0, 10);
14781 +
14782 + if (Value == 0)
14783 + pAd->CommonCfg.bRdg = FALSE;
14784 + else if ( Value ==1 )
14785 + {
14786 + pAd->HTCEnable = TRUE;
14787 + pAd->CommonCfg.bRdg = TRUE;
14788 + }
14789 + else
14790 + return FALSE; //Invalid argument
14791 +
14792 + SetCommonHT(pAd);
14793 +
14794 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg));
14795 +
14796 + return TRUE;
14797 +}
14798 +
14799 +INT Set_HtLinkAdapt_Proc(
14800 + IN PRTMP_ADAPTER pAd,
14801 + IN PUCHAR arg)
14802 +{
14803 + ULONG Value;
14804 +
14805 + Value = simple_strtol(arg, 0, 10);
14806 + if (Value == 0)
14807 + pAd->bLinkAdapt = FALSE;
14808 + else if ( Value ==1 )
14809 + {
14810 + pAd->HTCEnable = TRUE;
14811 + pAd->bLinkAdapt = TRUE;
14812 + }
14813 + else
14814 + return FALSE; //Invalid argument
14815 +
14816 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt));
14817 +
14818 + return TRUE;
14819 +}
14820 +
14821 +INT Set_HtAmsdu_Proc(
14822 + IN PRTMP_ADAPTER pAd,
14823 + IN PUCHAR arg)
14824 +{
14825 + ULONG Value;
14826 +
14827 + Value = simple_strtol(arg, 0, 10);
14828 + if (Value == 0)
14829 + pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
14830 + else if ( Value == 1 )
14831 + pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
14832 + else
14833 + return FALSE; //Invalid argument
14834 +
14835 + SetCommonHT(pAd);
14836 +
14837 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable));
14838 +
14839 + return TRUE;
14840 +}
14841 +
14842 +INT Set_HtAutoBa_Proc(
14843 + IN PRTMP_ADAPTER pAd,
14844 + IN PUCHAR arg)
14845 +{
14846 + ULONG Value;
14847 +
14848 + Value = simple_strtol(arg, 0, 10);
14849 + if (Value == 0)
14850 + {
14851 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
14852 + pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
14853 + }
14854 + else if (Value == 1)
14855 + {
14856 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
14857 + pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
14858 + }
14859 + else
14860 + return FALSE; //Invalid argument
14861 +
14862 + pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
14863 + pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy;
14864 + SetCommonHT(pAd);
14865 +
14866 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA));
14867 +
14868 + return TRUE;
14869 +
14870 +}
14871 +
14872 +INT Set_HtProtect_Proc(
14873 + IN PRTMP_ADAPTER pAd,
14874 + IN PUCHAR arg)
14875 +{
14876 + ULONG Value;
14877 +
14878 + Value = simple_strtol(arg, 0, 10);
14879 + if (Value == 0)
14880 + pAd->CommonCfg.bHTProtect = FALSE;
14881 + else if (Value == 1)
14882 + pAd->CommonCfg.bHTProtect = TRUE;
14883 + else
14884 + return FALSE; //Invalid argument
14885 +
14886 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect));
14887 +
14888 + return TRUE;
14889 +}
14890 +
14891 +INT Set_SendPSMPAction_Proc(
14892 + IN PRTMP_ADAPTER pAd,
14893 + IN PUCHAR arg)
14894 +{
14895 + UCHAR mac[6], mode;
14896 + char *token, sepValue[] = ":", DASH = '-';
14897 + INT i;
14898 + MAC_TABLE_ENTRY *pEntry;
14899 +
14900 + //printk("\n%s\n", arg);
14901 +/*
14902 + The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
14903 + =>The six 2 digit hex-decimal number previous are the Mac address,
14904 + =>The seventh decimal number is the mode value.
14905 +*/
14906 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format.
14907 + return FALSE;
14908 +
14909 + token = strchr(arg, DASH);
14910 + if ((token != NULL) && (strlen(token)>1))
14911 + {
14912 + mode = simple_strtol((token+1), 0, 10);
14913 + if (mode > MMPS_ENABLE)
14914 + return FALSE;
14915 +
14916 + *token = '\0';
14917 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
14918 + {
14919 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
14920 + return FALSE;
14921 + AtoH(token, (PUCHAR)(&mac[i]), 1);
14922 + }
14923 + if(i != 6)
14924 + return FALSE;
14925 +
14926 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
14927 + mac[2], mac[3], mac[4], mac[5], mode);
14928 +
14929 + pEntry = MacTableLookup(pAd, mac);
14930 +
14931 + if (pEntry) {
14932 + printk("\nSendPSMPAction MIPS mode = %d\n", mode);
14933 + SendPSMPAction(pAd, pEntry->Aid, mode);
14934 + }
14935 +
14936 + return TRUE;
14937 + }
14938 +
14939 + return FALSE;
14940 +
14941 +
14942 +}
14943 +
14944 +INT Set_HtMIMOPSmode_Proc(
14945 + IN PRTMP_ADAPTER pAd,
14946 + IN PUCHAR arg)
14947 +{
14948 + ULONG Value;
14949 +
14950 + Value = simple_strtol(arg, 0, 10);
14951 +
14952 + if (Value <=3 && Value >= 0)
14953 + pAd->CommonCfg.BACapability.field.MMPSmode = Value;
14954 + else
14955 + pAd->CommonCfg.BACapability.field.MMPSmode = 3;
14956 +
14957 + SetCommonHT(pAd);
14958 +
14959 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode));
14960 +
14961 + return TRUE;
14962 +}
14963 +
14964 +
14965 +INT Set_ForceShortGI_Proc(
14966 + IN PRTMP_ADAPTER pAd,
14967 + IN PUCHAR arg)
14968 +{
14969 + ULONG Value;
14970 +
14971 + Value = simple_strtol(arg, 0, 10);
14972 + if (Value == 0)
14973 + pAd->WIFItestbed.bShortGI = FALSE;
14974 + else if (Value == 1)
14975 + pAd->WIFItestbed.bShortGI = TRUE;
14976 + else
14977 + return FALSE; //Invalid argument
14978 +
14979 + SetCommonHT(pAd);
14980 +
14981 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI));
14982 +
14983 + return TRUE;
14984 +}
14985 +
14986 +
14987 +
14988 +INT Set_ForceGF_Proc(
14989 + IN PRTMP_ADAPTER pAd,
14990 + IN PUCHAR arg)
14991 +{
14992 + ULONG Value;
14993 +
14994 + Value = simple_strtol(arg, 0, 10);
14995 + if (Value == 0)
14996 + pAd->WIFItestbed.bGreenField = FALSE;
14997 + else if (Value == 1)
14998 + pAd->WIFItestbed.bGreenField = TRUE;
14999 + else
15000 + return FALSE; //Invalid argument
15001 +
15002 + SetCommonHT(pAd);
15003 +
15004 + DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField));
15005 +
15006 + return TRUE;
15007 +}
15008 +
15009 +INT Set_HtMimoPs_Proc(
15010 + IN PRTMP_ADAPTER pAd,
15011 + IN PUCHAR arg)
15012 +{
15013 + ULONG Value;
15014 +
15015 + Value = simple_strtol(arg, 0, 10);
15016 + if (Value == 0)
15017 + pAd->CommonCfg.bMIMOPSEnable = FALSE;
15018 + else if (Value == 1)
15019 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
15020 + else
15021 + return FALSE; //Invalid argument
15022 +
15023 + DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable));
15024 +
15025 + return TRUE;
15026 +}
15027 +#endif // DOT11_N_SUPPORT //
15028 +
15029 +
15030 +#ifdef DOT11_N_SUPPORT
15031 +INT SetCommonHT(
15032 + IN PRTMP_ADAPTER pAd)
15033 +{
15034 + OID_SET_HT_PHYMODE SetHT;
15035 +
15036 + if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
15037 + return FALSE;
15038 +
15039 + SetHT.PhyMode = pAd->CommonCfg.PhyMode;
15040 + SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath);
15041 + SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
15042 + SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
15043 + SetHT.MCS = MCS_AUTO;
15044 + SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW;
15045 + SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC;
15046 + SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
15047 +
15048 + RTMPSetHT(pAd, &SetHT);
15049 +
15050 + return TRUE;
15051 +}
15052 +#endif // DOT11_N_SUPPORT //
15053 +
15054 +INT Set_FixedTxMode_Proc(
15055 + IN PRTMP_ADAPTER pAd,
15056 + IN PUCHAR arg)
15057 +{
15058 + UCHAR fix_tx_mode = FIXED_TXMODE_HT;
15059 +
15060 + if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0)
15061 + {
15062 + fix_tx_mode = FIXED_TXMODE_OFDM;
15063 + }
15064 + else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0)
15065 + {
15066 + fix_tx_mode = FIXED_TXMODE_CCK;
15067 + }
15068 +
15069 +#ifdef CONFIG_STA_SUPPORT
15070 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15071 + pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
15072 +#endif // CONFIG_STA_SUPPORT //
15073 +
15074 + DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode));
15075 +
15076 + return TRUE;
15077 +}
15078 +
15079 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
15080 +INT Set_OpMode_Proc(
15081 + IN PRTMP_ADAPTER pAd,
15082 + IN PUCHAR arg)
15083 +{
15084 + ULONG Value;
15085 +
15086 + Value = simple_strtol(arg, 0, 10);
15087 +
15088 +#ifdef RT2870
15089 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
15090 +#endif // RT2870 //
15091 + {
15092 + DBGPRINT(RT_DEBUG_ERROR, ("Can not switch operate mode on interface up !! \n"));
15093 + return FALSE;
15094 + }
15095 +
15096 + if (Value == 0)
15097 + pAd->OpMode = OPMODE_STA;
15098 + else if (Value == 1)
15099 + pAd->OpMode = OPMODE_AP;
15100 + else
15101 + return FALSE; //Invalid argument
15102 +
15103 + DBGPRINT(RT_DEBUG_TRACE, ("Set_OpMode_Proc::(OpMode=%s)\n", pAd->OpMode == 1 ? "AP Mode" : "STA Mode"));
15104 +
15105 + return TRUE;
15106 +}
15107 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
15108 +
15109 +
15110 +/////////////////////////////////////////////////////////////////////////
15111 +PCHAR RTMPGetRalinkAuthModeStr(
15112 + IN NDIS_802_11_AUTHENTICATION_MODE authMode)
15113 +{
15114 + switch(authMode)
15115 + {
15116 + case Ndis802_11AuthModeOpen:
15117 + return "OPEN";
15118 + default:
15119 + case Ndis802_11AuthModeWPAPSK:
15120 + return "WPAPSK";
15121 + case Ndis802_11AuthModeShared:
15122 + return "SHARED";
15123 + case Ndis802_11AuthModeWPA:
15124 + return "WPA";
15125 + case Ndis802_11AuthModeWPA2:
15126 + return "WPA2";
15127 + case Ndis802_11AuthModeWPA2PSK:
15128 + return "WPA2PSK";
15129 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
15130 + return "WPAPSKWPA2PSK";
15131 + case Ndis802_11AuthModeWPA1WPA2:
15132 + return "WPA1WPA2";
15133 + }
15134 +}
15135 +
15136 +PCHAR RTMPGetRalinkEncryModeStr(
15137 + IN USHORT encryMode)
15138 +{
15139 + switch(encryMode)
15140 + {
15141 + default:
15142 + case Ndis802_11WEPDisabled:
15143 + return "NONE";
15144 + case Ndis802_11WEPEnabled:
15145 + return "WEP";
15146 + case Ndis802_11Encryption2Enabled:
15147 + return "TKIP";
15148 + case Ndis802_11Encryption3Enabled:
15149 + return "AES";
15150 + case Ndis802_11Encryption4Enabled:
15151 + return "TKIPAES";
15152 + }
15153 +}
15154 +
15155 +INT RTMPShowCfgValue(
15156 + IN PRTMP_ADAPTER pAd,
15157 + IN PUCHAR pName,
15158 + IN PUCHAR pBuf)
15159 +{
15160 + INT Status = 0;
15161 +
15162 + for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
15163 + {
15164 + if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name))
15165 + {
15166 + if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf))
15167 + Status = -EINVAL;
15168 + break; //Exit for loop.
15169 + }
15170 + }
15171 +
15172 + if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL)
15173 + {
15174 + sprintf(pBuf, "\n");
15175 + for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
15176 + sprintf(pBuf, "%s%s\n", pBuf, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
15177 + }
15178 +
15179 + return Status;
15180 +}
15181 +
15182 +INT Show_SSID_Proc(
15183 + IN PRTMP_ADAPTER pAd,
15184 + OUT PUCHAR pBuf)
15185 +{
15186 +
15187 +#ifdef CONFIG_STA_SUPPORT
15188 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15189 + sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid);
15190 +#endif // CONFIG_STA_SUPPORT //
15191 + return 0;
15192 +}
15193 +
15194 +INT Show_WirelessMode_Proc(
15195 + IN PRTMP_ADAPTER pAd,
15196 + OUT PUCHAR pBuf)
15197 +{
15198 + switch(pAd->CommonCfg.PhyMode)
15199 + {
15200 + case PHY_11BG_MIXED:
15201 + sprintf(pBuf, "\t11B/G");
15202 + break;
15203 + case PHY_11B:
15204 + sprintf(pBuf, "\t11B");
15205 + break;
15206 + case PHY_11A:
15207 + sprintf(pBuf, "\t11A");
15208 + break;
15209 + case PHY_11ABG_MIXED:
15210 + sprintf(pBuf, "\t11A/B/G");
15211 + break;
15212 + case PHY_11G:
15213 + sprintf(pBuf, "\t11G");
15214 + break;
15215 +#ifdef DOT11_N_SUPPORT
15216 + case PHY_11ABGN_MIXED:
15217 + sprintf(pBuf, "\t11A/B/G/N");
15218 + break;
15219 + case PHY_11N_2_4G:
15220 + sprintf(pBuf, "\t11N only with 2.4G");
15221 + break;
15222 + case PHY_11GN_MIXED:
15223 + sprintf(pBuf, "\t11G/N");
15224 + break;
15225 + case PHY_11AN_MIXED:
15226 + sprintf(pBuf, "\t11A/N");
15227 + break;
15228 + case PHY_11BGN_MIXED:
15229 + sprintf(pBuf, "\t11B/G/N");
15230 + break;
15231 + case PHY_11AGN_MIXED:
15232 + sprintf(pBuf, "\t11A/G/N");
15233 + break;
15234 + case PHY_11N_5G:
15235 + sprintf(pBuf, "\t11N only with 5G");
15236 + break;
15237 +#endif // DOT11_N_SUPPORT //
15238 + default:
15239 + sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode);
15240 + break;
15241 + }
15242 + return 0;
15243 +}
15244 +
15245 +
15246 +INT Show_TxBurst_Proc(
15247 + IN PRTMP_ADAPTER pAd,
15248 + OUT PUCHAR pBuf)
15249 +{
15250 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE");
15251 + return 0;
15252 +}
15253 +
15254 +INT Show_TxPreamble_Proc(
15255 + IN PRTMP_ADAPTER pAd,
15256 + OUT PUCHAR pBuf)
15257 +{
15258 + switch(pAd->CommonCfg.TxPreamble)
15259 + {
15260 + case Rt802_11PreambleShort:
15261 + sprintf(pBuf, "\tShort");
15262 + break;
15263 + case Rt802_11PreambleLong:
15264 + sprintf(pBuf, "\tLong");
15265 + break;
15266 + case Rt802_11PreambleAuto:
15267 + sprintf(pBuf, "\tAuto");
15268 + break;
15269 + default:
15270 + sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble);
15271 + break;
15272 + }
15273 +
15274 + return 0;
15275 +}
15276 +
15277 +INT Show_TxPower_Proc(
15278 + IN PRTMP_ADAPTER pAd,
15279 + OUT PUCHAR pBuf)
15280 +{
15281 + sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage);
15282 + return 0;
15283 +}
15284 +
15285 +INT Show_Channel_Proc(
15286 + IN PRTMP_ADAPTER pAd,
15287 + OUT PUCHAR pBuf)
15288 +{
15289 + sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel);
15290 + return 0;
15291 +}
15292 +
15293 +INT Show_BGProtection_Proc(
15294 + IN PRTMP_ADAPTER pAd,
15295 + OUT PUCHAR pBuf)
15296 +{
15297 + switch(pAd->CommonCfg.UseBGProtection)
15298 + {
15299 + case 1: //Always On
15300 + sprintf(pBuf, "\tON");
15301 + break;
15302 + case 2: //Always OFF
15303 + sprintf(pBuf, "\tOFF");
15304 + break;
15305 + case 0: //AUTO
15306 + sprintf(pBuf, "\tAuto");
15307 + break;
15308 + default:
15309 + sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection);
15310 + break;
15311 + }
15312 + return 0;
15313 +}
15314 +
15315 +INT Show_RTSThreshold_Proc(
15316 + IN PRTMP_ADAPTER pAd,
15317 + OUT PUCHAR pBuf)
15318 +{
15319 + sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold);
15320 + return 0;
15321 +}
15322 +
15323 +INT Show_FragThreshold_Proc(
15324 + IN PRTMP_ADAPTER pAd,
15325 + OUT PUCHAR pBuf)
15326 +{
15327 + sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold);
15328 + return 0;
15329 +}
15330 +
15331 +#ifdef DOT11_N_SUPPORT
15332 +INT Show_HtBw_Proc(
15333 + IN PRTMP_ADAPTER pAd,
15334 + OUT PUCHAR pBuf)
15335 +{
15336 + if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
15337 + {
15338 + sprintf(pBuf, "\t40 MHz");
15339 + }
15340 + else
15341 + {
15342 + sprintf(pBuf, "\t20 MHz");
15343 + }
15344 + return 0;
15345 +}
15346 +
15347 +INT Show_HtMcs_Proc(
15348 + IN PRTMP_ADAPTER pAd,
15349 + OUT PUCHAR pBuf)
15350 +{
15351 +
15352 +#ifdef CONFIG_STA_SUPPORT
15353 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15354 + sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS);
15355 +#endif // CONFIG_STA_SUPPORT //
15356 + return 0;
15357 +}
15358 +
15359 +INT Show_HtGi_Proc(
15360 + IN PRTMP_ADAPTER pAd,
15361 + OUT PUCHAR pBuf)
15362 +{
15363 + switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI)
15364 + {
15365 + case GI_400:
15366 + sprintf(pBuf, "\tGI_400");
15367 + break;
15368 + case GI_800:
15369 + sprintf(pBuf, "\tGI_800");
15370 + break;
15371 + default:
15372 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI);
15373 + break;
15374 + }
15375 + return 0;
15376 +}
15377 +
15378 +INT Show_HtOpMode_Proc(
15379 + IN PRTMP_ADAPTER pAd,
15380 + OUT PUCHAR pBuf)
15381 +{
15382 + switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE)
15383 + {
15384 + case HTMODE_GF:
15385 + sprintf(pBuf, "\tGF");
15386 + break;
15387 + case HTMODE_MM:
15388 + sprintf(pBuf, "\tMM");
15389 + break;
15390 + default:
15391 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE);
15392 + break;
15393 + }
15394 + return 0;
15395 +}
15396 +
15397 +INT Show_HtExtcha_Proc(
15398 + IN PRTMP_ADAPTER pAd,
15399 + OUT PUCHAR pBuf)
15400 +{
15401 + switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)
15402 + {
15403 + case EXTCHA_BELOW:
15404 + sprintf(pBuf, "\tBelow");
15405 + break;
15406 + case EXTCHA_ABOVE:
15407 + sprintf(pBuf, "\tAbove");
15408 + break;
15409 + default:
15410 + sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA);
15411 + break;
15412 + }
15413 + return 0;
15414 +}
15415 +
15416 +
15417 +INT Show_HtMpduDensity_Proc(
15418 + IN PRTMP_ADAPTER pAd,
15419 + OUT PUCHAR pBuf)
15420 +{
15421 + sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity);
15422 + return 0;
15423 +}
15424 +
15425 +INT Show_HtBaWinSize_Proc(
15426 + IN PRTMP_ADAPTER pAd,
15427 + OUT PUCHAR pBuf)
15428 +{
15429 + sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit);
15430 + return 0;
15431 +}
15432 +
15433 +INT Show_HtRdg_Proc(
15434 + IN PRTMP_ADAPTER pAd,
15435 + OUT PUCHAR pBuf)
15436 +{
15437 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE");
15438 + return 0;
15439 +}
15440 +
15441 +INT Show_HtAmsdu_Proc(
15442 + IN PRTMP_ADAPTER pAd,
15443 + OUT PUCHAR pBuf)
15444 +{
15445 + sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE");
15446 + return 0;
15447 +}
15448 +
15449 +INT Show_HtAutoBa_Proc(
15450 + IN PRTMP_ADAPTER pAd,
15451 + OUT PUCHAR pBuf)
15452 +{
15453 + sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE");
15454 + return 0;
15455 +}
15456 +#endif // DOT11_N_SUPPORT //
15457 +
15458 +INT Show_CountryRegion_Proc(
15459 + IN PRTMP_ADAPTER pAd,
15460 + OUT PUCHAR pBuf)
15461 +{
15462 + sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion);
15463 + return 0;
15464 +}
15465 +
15466 +INT Show_CountryRegionABand_Proc(
15467 + IN PRTMP_ADAPTER pAd,
15468 + OUT PUCHAR pBuf)
15469 +{
15470 + sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand);
15471 + return 0;
15472 +}
15473 +
15474 +INT Show_CountryCode_Proc(
15475 + IN PRTMP_ADAPTER pAd,
15476 + OUT PUCHAR pBuf)
15477 +{
15478 + sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode);
15479 + return 0;
15480 +}
15481 +
15482 +#ifdef AGGREGATION_SUPPORT
15483 +INT Show_PktAggregate_Proc(
15484 + IN PRTMP_ADAPTER pAd,
15485 + OUT PUCHAR pBuf)
15486 +{
15487 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE");
15488 + return 0;
15489 +}
15490 +#endif // AGGREGATION_SUPPORT //
15491 +
15492 +#ifdef WMM_SUPPORT
15493 +INT Show_WmmCapable_Proc(
15494 + IN PRTMP_ADAPTER pAd,
15495 + OUT PUCHAR pBuf)
15496 +{
15497 +
15498 +#ifdef CONFIG_STA_SUPPORT
15499 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15500 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE");
15501 +#endif // CONFIG_STA_SUPPORT //
15502 +
15503 + return 0;
15504 +}
15505 +#endif // WMM_SUPPORT //
15506 +
15507 +INT Show_IEEE80211H_Proc(
15508 + IN PRTMP_ADAPTER pAd,
15509 + OUT PUCHAR pBuf)
15510 +{
15511 + sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE");
15512 + return 0;
15513 +}
15514 +
15515 +#ifdef CONFIG_STA_SUPPORT
15516 +INT Show_NetworkType_Proc(
15517 + IN PRTMP_ADAPTER pAd,
15518 + OUT PUCHAR pBuf)
15519 +{
15520 + switch(pAd->StaCfg.BssType)
15521 + {
15522 + case BSS_ADHOC:
15523 + sprintf(pBuf, "\tAdhoc");
15524 + break;
15525 + case BSS_INFRA:
15526 + sprintf(pBuf, "\tInfra");
15527 + break;
15528 + case BSS_ANY:
15529 + sprintf(pBuf, "\tAny");
15530 + break;
15531 + case BSS_MONITOR:
15532 + sprintf(pBuf, "\tMonitor");
15533 + break;
15534 + default:
15535 + sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType);
15536 + break;
15537 + }
15538 + return 0;
15539 +}
15540 +#endif // CONFIG_STA_SUPPORT //
15541 +
15542 +INT Show_AuthMode_Proc(
15543 + IN PRTMP_ADAPTER pAd,
15544 + OUT PUCHAR pBuf)
15545 +{
15546 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen;
15547 +
15548 +#ifdef CONFIG_STA_SUPPORT
15549 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15550 + AuthMode = pAd->StaCfg.AuthMode;
15551 +#endif // CONFIG_STA_SUPPORT //
15552 +
15553 + if ((AuthMode >= Ndis802_11AuthModeOpen) &&
15554 + (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
15555 + sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode));
15556 + else
15557 + sprintf(pBuf, "\tUnknow Value(%d)", AuthMode);
15558 +
15559 + return 0;
15560 +}
15561 +
15562 +INT Show_EncrypType_Proc(
15563 + IN PRTMP_ADAPTER pAd,
15564 + OUT PUCHAR pBuf)
15565 +{
15566 + NDIS_802_11_WEP_STATUS WepStatus = Ndis802_11WEPDisabled;
15567 +
15568 +#ifdef CONFIG_STA_SUPPORT
15569 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15570 + WepStatus = pAd->StaCfg.WepStatus;
15571 +#endif // CONFIG_STA_SUPPORT //
15572 +
15573 + if ((WepStatus >= Ndis802_11WEPEnabled) &&
15574 + (WepStatus <= Ndis802_11Encryption4KeyAbsent))
15575 + sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus));
15576 + else
15577 + sprintf(pBuf, "\tUnknow Value(%d)", WepStatus);
15578 +
15579 + return 0;
15580 +}
15581 +
15582 +INT Show_DefaultKeyID_Proc(
15583 + IN PRTMP_ADAPTER pAd,
15584 + OUT PUCHAR pBuf)
15585 +{
15586 + UCHAR DefaultKeyId = 0;
15587 +
15588 +#ifdef CONFIG_STA_SUPPORT
15589 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15590 + DefaultKeyId = pAd->StaCfg.DefaultKeyId;
15591 +#endif // CONFIG_STA_SUPPORT //
15592 +
15593 + sprintf(pBuf, "\t%d", DefaultKeyId);
15594 +
15595 + return 0;
15596 +}
15597 +
15598 +INT Show_WepKey_Proc(
15599 + IN PRTMP_ADAPTER pAd,
15600 + IN INT KeyIdx,
15601 + OUT PUCHAR pBuf)
15602 +{
15603 + UCHAR Key[16] = {0}, KeyLength = 0;
15604 + INT index = BSS0;
15605 +
15606 + KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen;
15607 + NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength);
15608 +
15609 + //check key string is ASCII or not
15610 + if (RTMPCheckStrPrintAble(Key, KeyLength))
15611 + sprintf(pBuf, "\t%s", Key);
15612 + else
15613 + {
15614 + int idx;
15615 + sprintf(pBuf, "\t");
15616 + for (idx = 0; idx < KeyLength; idx++)
15617 + sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]);
15618 + }
15619 + return 0;
15620 +}
15621 +
15622 +INT Show_Key1_Proc(
15623 + IN PRTMP_ADAPTER pAd,
15624 + OUT PUCHAR pBuf)
15625 +{
15626 + Show_WepKey_Proc(pAd, 0, pBuf);
15627 + return 0;
15628 +}
15629 +
15630 +INT Show_Key2_Proc(
15631 + IN PRTMP_ADAPTER pAd,
15632 + OUT PUCHAR pBuf)
15633 +{
15634 + Show_WepKey_Proc(pAd, 1, pBuf);
15635 + return 0;
15636 +}
15637 +
15638 +INT Show_Key3_Proc(
15639 + IN PRTMP_ADAPTER pAd,
15640 + OUT PUCHAR pBuf)
15641 +{
15642 + Show_WepKey_Proc(pAd, 2, pBuf);
15643 + return 0;
15644 +}
15645 +
15646 +INT Show_Key4_Proc(
15647 + IN PRTMP_ADAPTER pAd,
15648 + OUT PUCHAR pBuf)
15649 +{
15650 + Show_WepKey_Proc(pAd, 3, pBuf);
15651 + return 0;
15652 +}
15653 +
15654 +INT Show_WPAPSK_Proc(
15655 + IN PRTMP_ADAPTER pAd,
15656 + OUT PUCHAR pBuf)
15657 +{
15658 + INT idx;
15659 + UCHAR PMK[32] = {0};
15660 +
15661 +
15662 +#ifdef CONFIG_STA_SUPPORT
15663 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
15664 + NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32);
15665 +#endif // CONFIG_STA_SUPPORT //
15666 +
15667 + sprintf(pBuf, "\tPMK = ");
15668 + for (idx = 0; idx < 32; idx++)
15669 + sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]);
15670 +
15671 + return 0;
15672 +}
15673 +
15674 --- /dev/null
15675 +++ b/drivers/staging/rt3070/common/cmm_sanity.c
15676 @@ -0,0 +1,1669 @@
15677 +/*
15678 + *************************************************************************
15679 + * Ralink Tech Inc.
15680 + * 5F., No.36, Taiyuan St., Jhubei City,
15681 + * Hsinchu County 302,
15682 + * Taiwan, R.O.C.
15683 + *
15684 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
15685 + *
15686 + * This program is free software; you can redistribute it and/or modify *
15687 + * it under the terms of the GNU General Public License as published by *
15688 + * the Free Software Foundation; either version 2 of the License, or *
15689 + * (at your option) any later version. *
15690 + * *
15691 + * This program is distributed in the hope that it will be useful, *
15692 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15693 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15694 + * GNU General Public License for more details. *
15695 + * *
15696 + * You should have received a copy of the GNU General Public License *
15697 + * along with this program; if not, write to the *
15698 + * Free Software Foundation, Inc., *
15699 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
15700 + * *
15701 + *************************************************************************
15702 +
15703 + Module Name:
15704 + sanity.c
15705 +
15706 + Abstract:
15707 +
15708 + Revision History:
15709 + Who When What
15710 + -------- ---------- ----------------------------------------------
15711 + John Chang 2004-09-01 add WMM support
15712 +*/
15713 +#include "../rt_config.h"
15714 +
15715 +
15716 +extern UCHAR CISCO_OUI[];
15717 +
15718 +extern UCHAR WPA_OUI[];
15719 +extern UCHAR RSN_OUI[];
15720 +extern UCHAR WME_INFO_ELEM[];
15721 +extern UCHAR WME_PARM_ELEM[];
15722 +extern UCHAR Ccx2QosInfo[];
15723 +extern UCHAR RALINK_OUI[];
15724 +extern UCHAR BROADCOM_OUI[];
15725 +extern UCHAR WPS_OUI[];
15726 +
15727 +/*
15728 + ==========================================================================
15729 + Description:
15730 + MLME message sanity check
15731 + Return:
15732 + TRUE if all parameters are OK, FALSE otherwise
15733 +
15734 + IRQL = DISPATCH_LEVEL
15735 +
15736 + ==========================================================================
15737 + */
15738 +BOOLEAN MlmeAddBAReqSanity(
15739 + IN PRTMP_ADAPTER pAd,
15740 + IN VOID *Msg,
15741 + IN ULONG MsgLen,
15742 + OUT PUCHAR pAddr2)
15743 +{
15744 + PMLME_ADDBA_REQ_STRUCT pInfo;
15745 +
15746 + pInfo = (MLME_ADDBA_REQ_STRUCT *)Msg;
15747 +
15748 + if ((MsgLen != sizeof(MLME_ADDBA_REQ_STRUCT)))
15749 + {
15750 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - message lenght not correct.\n"));
15751 + return FALSE;
15752 + }
15753 +
15754 + if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))
15755 + {
15756 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n"));
15757 + return FALSE;
15758 + }
15759 +
15760 + /*
15761 + if ((pInfo->BaBufSize > MAX_RX_REORDERBUF) || (pInfo->BaBufSize < 2))
15762 + {
15763 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - Rx Reordering buffer too big or too small\n"));
15764 + return FALSE;
15765 + }
15766 + */
15767 +
15768 + if ((pInfo->pAddr[0]&0x01) == 0x01)
15769 + {
15770 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - broadcast address not support BA\n"));
15771 + return FALSE;
15772 + }
15773 +
15774 + return TRUE;
15775 +}
15776 +
15777 +/*
15778 + ==========================================================================
15779 + Description:
15780 + MLME message sanity check
15781 + Return:
15782 + TRUE if all parameters are OK, FALSE otherwise
15783 +
15784 + IRQL = DISPATCH_LEVEL
15785 +
15786 + ==========================================================================
15787 + */
15788 +BOOLEAN MlmeDelBAReqSanity(
15789 + IN PRTMP_ADAPTER pAd,
15790 + IN VOID *Msg,
15791 + IN ULONG MsgLen)
15792 +{
15793 + MLME_DELBA_REQ_STRUCT *pInfo;
15794 + pInfo = (MLME_DELBA_REQ_STRUCT *)Msg;
15795 +
15796 + if ((MsgLen != sizeof(MLME_DELBA_REQ_STRUCT)))
15797 + {
15798 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - message lenght not correct.\n"));
15799 + return FALSE;
15800 + }
15801 +
15802 + if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))
15803 + {
15804 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n"));
15805 + return FALSE;
15806 + }
15807 +
15808 + if ((pInfo->TID & 0xf0))
15809 + {
15810 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n"));
15811 + return FALSE;
15812 + }
15813 +
15814 + if (NdisEqualMemory(pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr, MAC_ADDR_LEN) == 0)
15815 + {
15816 + DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n"));
15817 + return FALSE;
15818 + }
15819 +
15820 + return TRUE;
15821 +}
15822 +
15823 +BOOLEAN PeerAddBAReqActionSanity(
15824 + IN PRTMP_ADAPTER pAd,
15825 + IN VOID *pMsg,
15826 + IN ULONG MsgLen,
15827 + OUT PUCHAR pAddr2)
15828 +{
15829 + PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
15830 + PFRAME_ADDBA_REQ pAddFrame;
15831 + pAddFrame = (PFRAME_ADDBA_REQ)(pMsg);
15832 + if (MsgLen < (sizeof(FRAME_ADDBA_REQ)))
15833 + {
15834 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", MsgLen));
15835 + return FALSE;
15836 + }
15837 + // we support immediate BA.
15838 + *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm));
15839 + pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
15840 + pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word);
15841 +
15842 + if (pAddFrame->BaParm.BAPolicy != IMMED_BA)
15843 + {
15844 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));
15845 + DBGPRINT(RT_DEBUG_ERROR,("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, pAddFrame->BaParm.AMSDUSupported));
15846 + return FALSE;
15847 + }
15848 +
15849 + // we support immediate BA.
15850 + if (pAddFrame->BaParm.TID &0xfff0)
15851 + {
15852 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", pAddFrame->BaParm.TID));
15853 + return FALSE;
15854 + }
15855 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
15856 + return TRUE;
15857 +}
15858 +
15859 +BOOLEAN PeerAddBARspActionSanity(
15860 + IN PRTMP_ADAPTER pAd,
15861 + IN VOID *pMsg,
15862 + IN ULONG MsgLen)
15863 +{
15864 + //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
15865 + PFRAME_ADDBA_RSP pAddFrame;
15866 +
15867 + pAddFrame = (PFRAME_ADDBA_RSP)(pMsg);
15868 + if (MsgLen < (sizeof(FRAME_ADDBA_RSP)))
15869 + {
15870 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", MsgLen));
15871 + return FALSE;
15872 + }
15873 + // we support immediate BA.
15874 + *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm));
15875 + pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode);
15876 + pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
15877 +
15878 + if (pAddFrame->BaParm.BAPolicy != IMMED_BA)
15879 + {
15880 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));
15881 + return FALSE;
15882 + }
15883 +
15884 + // we support immediate BA.
15885 + if (pAddFrame->BaParm.TID &0xfff0)
15886 + {
15887 + DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", pAddFrame->BaParm.TID));
15888 + return FALSE;
15889 + }
15890 + return TRUE;
15891 +
15892 +}
15893 +
15894 +BOOLEAN PeerDelBAActionSanity(
15895 + IN PRTMP_ADAPTER pAd,
15896 + IN UCHAR Wcid,
15897 + IN VOID *pMsg,
15898 + IN ULONG MsgLen )
15899 +{
15900 + //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
15901 + PFRAME_DELBA_REQ pDelFrame;
15902 + if (MsgLen != (sizeof(FRAME_DELBA_REQ)))
15903 + return FALSE;
15904 +
15905 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
15906 + return FALSE;
15907 +
15908 + pDelFrame = (PFRAME_DELBA_REQ)(pMsg);
15909 +
15910 + *(USHORT *)(&pDelFrame->DelbaParm) = cpu2le16(*(USHORT *)(&pDelFrame->DelbaParm));
15911 + pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode);
15912 +
15913 + if (pDelFrame->DelbaParm.TID &0xfff0)
15914 + return FALSE;
15915 +
15916 + return TRUE;
15917 +}
15918 +
15919 +/*
15920 + ==========================================================================
15921 + Description:
15922 + MLME message sanity check
15923 + Return:
15924 + TRUE if all parameters are OK, FALSE otherwise
15925 +
15926 + IRQL = DISPATCH_LEVEL
15927 +
15928 + ==========================================================================
15929 + */
15930 +BOOLEAN PeerBeaconAndProbeRspSanity(
15931 + IN PRTMP_ADAPTER pAd,
15932 + IN VOID *Msg,
15933 + IN ULONG MsgLen,
15934 + IN UCHAR MsgChannel,
15935 + OUT PUCHAR pAddr2,
15936 + OUT PUCHAR pBssid,
15937 + OUT CHAR Ssid[],
15938 + OUT UCHAR *pSsidLen,
15939 + OUT UCHAR *pBssType,
15940 + OUT USHORT *pBeaconPeriod,
15941 + OUT UCHAR *pChannel,
15942 + OUT UCHAR *pNewChannel,
15943 + OUT LARGE_INTEGER *pTimestamp,
15944 + OUT CF_PARM *pCfParm,
15945 + OUT USHORT *pAtimWin,
15946 + OUT USHORT *pCapabilityInfo,
15947 + OUT UCHAR *pErp,
15948 + OUT UCHAR *pDtimCount,
15949 + OUT UCHAR *pDtimPeriod,
15950 + OUT UCHAR *pBcastFlag,
15951 + OUT UCHAR *pMessageToMe,
15952 + OUT UCHAR SupRate[],
15953 + OUT UCHAR *pSupRateLen,
15954 + OUT UCHAR ExtRate[],
15955 + OUT UCHAR *pExtRateLen,
15956 + OUT UCHAR *pCkipFlag,
15957 + OUT UCHAR *pAironetCellPowerLimit,
15958 + OUT PEDCA_PARM pEdcaParm,
15959 + OUT PQBSS_LOAD_PARM pQbssLoad,
15960 + OUT PQOS_CAPABILITY_PARM pQosCapability,
15961 + OUT ULONG *pRalinkIe,
15962 + OUT UCHAR *pHtCapabilityLen,
15963 +#ifdef CONFIG_STA_SUPPORT
15964 + OUT UCHAR *pPreNHtCapabilityLen,
15965 +#endif // CONFIG_STA_SUPPORT //
15966 + OUT HT_CAPABILITY_IE *pHtCapability,
15967 + OUT UCHAR *AddHtInfoLen,
15968 + OUT ADD_HT_INFO_IE *AddHtInfo,
15969 + OUT UCHAR *NewExtChannelOffset, // Ht extension channel offset(above or below)
15970 + OUT USHORT *LengthVIE,
15971 + OUT PNDIS_802_11_VARIABLE_IEs pVIE)
15972 +{
15973 + CHAR *Ptr;
15974 +#ifdef CONFIG_STA_SUPPORT
15975 + CHAR TimLen;
15976 +#endif // CONFIG_STA_SUPPORT //
15977 + PFRAME_802_11 pFrame;
15978 + PEID_STRUCT pEid;
15979 + UCHAR SubType;
15980 + UCHAR Sanity;
15981 + //UCHAR ECWMin, ECWMax;
15982 + //MAC_CSR9_STRUC Csr9;
15983 + ULONG Length = 0;
15984 +
15985 + // For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel
15986 + // 1. If the AP is 11n enabled, then check the control channel.
15987 + // 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!!)
15988 + UCHAR CtrlChannel = 0;
15989 +
15990 + // Add for 3 necessary EID field check
15991 + Sanity = 0;
15992 +
15993 + *pAtimWin = 0;
15994 + *pErp = 0;
15995 + *pDtimCount = 0;
15996 + *pDtimPeriod = 0;
15997 + *pBcastFlag = 0;
15998 + *pMessageToMe = 0;
15999 + *pExtRateLen = 0;
16000 + *pCkipFlag = 0; // Default of CkipFlag is 0
16001 + *pAironetCellPowerLimit = 0xFF; // Default of AironetCellPowerLimit is 0xFF
16002 + *LengthVIE = 0; // Set the length of VIE to init value 0
16003 + *pHtCapabilityLen = 0; // Set the length of VIE to init value 0
16004 +#ifdef CONFIG_STA_SUPPORT
16005 + if (pAd->OpMode == OPMODE_STA)
16006 + *pPreNHtCapabilityLen = 0; // Set the length of VIE to init value 0
16007 +#endif // CONFIG_STA_SUPPORT //
16008 + *AddHtInfoLen = 0; // Set the length of VIE to init value 0
16009 + *pRalinkIe = 0;
16010 + *pNewChannel = 0;
16011 + *NewExtChannelOffset = 0xff; //Default 0xff means no such IE
16012 + pCfParm->bValid = FALSE; // default: no IE_CF found
16013 + pQbssLoad->bValid = FALSE; // default: no IE_QBSS_LOAD found
16014 + pEdcaParm->bValid = FALSE; // default: no IE_EDCA_PARAMETER found
16015 + pQosCapability->bValid = FALSE; // default: no IE_QOS_CAPABILITY found
16016 +
16017 + pFrame = (PFRAME_802_11)Msg;
16018 +
16019 + // get subtype from header
16020 + SubType = (UCHAR)pFrame->Hdr.FC.SubType;
16021 +
16022 + // get Addr2 and BSSID from header
16023 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16024 + COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3);
16025 +
16026 +// hex_dump("Beacon", Msg, MsgLen);
16027 +
16028 + Ptr = pFrame->Octet;
16029 + Length += LENGTH_802_11;
16030 +
16031 + // get timestamp from payload and advance the pointer
16032 + NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN);
16033 +
16034 + pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart);
16035 + pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart);
16036 +
16037 + Ptr += TIMESTAMP_LEN;
16038 + Length += TIMESTAMP_LEN;
16039 +
16040 + // get beacon interval from payload and advance the pointer
16041 + NdisMoveMemory(pBeaconPeriod, Ptr, 2);
16042 + Ptr += 2;
16043 + Length += 2;
16044 +
16045 + // get capability info from payload and advance the pointer
16046 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
16047 + Ptr += 2;
16048 + Length += 2;
16049 +
16050 + if (CAP_IS_ESS_ON(*pCapabilityInfo))
16051 + *pBssType = BSS_INFRA;
16052 + else
16053 + *pBssType = BSS_ADHOC;
16054 +
16055 + pEid = (PEID_STRUCT) Ptr;
16056 +
16057 + // get variable fields from payload and advance the pointer
16058 + while ((Length + 2 + pEid->Len) <= MsgLen)
16059 + {
16060 + //
16061 + // Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow.
16062 + //
16063 + if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN)
16064 + {
16065 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n",
16066 + (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN));
16067 + break;
16068 + }
16069 +
16070 + switch(pEid->Eid)
16071 + {
16072 + case IE_SSID:
16073 + // Already has one SSID EID in this beacon, ignore the second one
16074 + if (Sanity & 0x1)
16075 + break;
16076 + if(pEid->Len <= MAX_LEN_OF_SSID)
16077 + {
16078 + NdisMoveMemory(Ssid, pEid->Octet, pEid->Len);
16079 + *pSsidLen = pEid->Len;
16080 + Sanity |= 0x1;
16081 + }
16082 + else
16083 + {
16084 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len));
16085 + return FALSE;
16086 + }
16087 + break;
16088 +
16089 + case IE_SUPP_RATES:
16090 + if(pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
16091 + {
16092 + Sanity |= 0x2;
16093 + NdisMoveMemory(SupRate, pEid->Octet, pEid->Len);
16094 + *pSupRateLen = pEid->Len;
16095 +
16096 + // TODO: 2004-09-14 not a good design here, cause it exclude extra rates
16097 + // from ScanTab. We should report as is. And filter out unsupported
16098 + // rates in MlmeAux.
16099 + // Check against the supported rates
16100 + // RTMPCheckRates(pAd, SupRate, pSupRateLen);
16101 + }
16102 + else
16103 + {
16104 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",pEid->Len));
16105 + return FALSE;
16106 + }
16107 + break;
16108 +
16109 + case IE_HT_CAP:
16110 + if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!
16111 + {
16112 + NdisMoveMemory(pHtCapability, pEid->Octet, sizeof(HT_CAPABILITY_IE));
16113 + *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes.
16114 +
16115 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
16116 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
16117 +
16118 +#ifdef CONFIG_STA_SUPPORT
16119 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16120 + {
16121 + *pPreNHtCapabilityLen = 0; // Nnow we only support 26 bytes.
16122 +
16123 + Ptr = (PUCHAR) pVIE;
16124 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16125 + *LengthVIE += (pEid->Len + 2);
16126 + }
16127 +#endif // CONFIG_STA_SUPPORT //
16128 + }
16129 + else
16130 + {
16131 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n", pEid->Len));
16132 + }
16133 +
16134 + break;
16135 + case IE_ADD_HT:
16136 + if (pEid->Len >= sizeof(ADD_HT_INFO_IE))
16137 + {
16138 + // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only
16139 + // copy first sizeof(ADD_HT_INFO_IE)
16140 + NdisMoveMemory(AddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));
16141 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
16142 +
16143 + CtrlChannel = AddHtInfo->ControlChan;
16144 +
16145 + *(USHORT *)(&AddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo2));
16146 + *(USHORT *)(&AddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo3));
16147 +
16148 +#ifdef CONFIG_STA_SUPPORT
16149 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16150 + {
16151 + Ptr = (PUCHAR) pVIE;
16152 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16153 + *LengthVIE += (pEid->Len + 2);
16154 + }
16155 +#endif // CONFIG_STA_SUPPORT //
16156 + }
16157 + else
16158 + {
16159 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n"));
16160 + }
16161 +
16162 + break;
16163 + case IE_SECONDARY_CH_OFFSET:
16164 + if (pEid->Len == 1)
16165 + {
16166 + *NewExtChannelOffset = pEid->Octet[0];
16167 + }
16168 + else
16169 + {
16170 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
16171 + }
16172 +
16173 + break;
16174 + case IE_FH_PARM:
16175 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n"));
16176 + break;
16177 +
16178 + case IE_DS_PARM:
16179 + if(pEid->Len == 1)
16180 + {
16181 + *pChannel = *pEid->Octet;
16182 +#ifdef CONFIG_STA_SUPPORT
16183 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16184 + {
16185 + if (ChannelSanity(pAd, *pChannel) == 0)
16186 + {
16187 +
16188 + return FALSE;
16189 + }
16190 + }
16191 +#endif // CONFIG_STA_SUPPORT //
16192 + Sanity |= 0x4;
16193 + }
16194 + else
16195 + {
16196 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n",pEid->Len));
16197 + return FALSE;
16198 + }
16199 + break;
16200 +
16201 + case IE_CF_PARM:
16202 + if(pEid->Len == 6)
16203 + {
16204 + pCfParm->bValid = TRUE;
16205 + pCfParm->CfpCount = pEid->Octet[0];
16206 + pCfParm->CfpPeriod = pEid->Octet[1];
16207 + pCfParm->CfpMaxDuration = pEid->Octet[2] + 256 * pEid->Octet[3];
16208 + pCfParm->CfpDurRemaining = pEid->Octet[4] + 256 * pEid->Octet[5];
16209 + }
16210 + else
16211 + {
16212 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n"));
16213 + return FALSE;
16214 + }
16215 + break;
16216 +
16217 + case IE_IBSS_PARM:
16218 + if(pEid->Len == 2)
16219 + {
16220 + NdisMoveMemory(pAtimWin, pEid->Octet, pEid->Len);
16221 + }
16222 + else
16223 + {
16224 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n"));
16225 + return FALSE;
16226 + }
16227 + break;
16228 +
16229 +#ifdef CONFIG_STA_SUPPORT
16230 + case IE_TIM:
16231 + if(INFRA_ON(pAd) && SubType == SUBTYPE_BEACON)
16232 + {
16233 + GetTimBit((PUCHAR)pEid, pAd->StaActive.Aid, &TimLen, pBcastFlag, pDtimCount, pDtimPeriod, pMessageToMe);
16234 + }
16235 + break;
16236 +#endif // CONFIG_STA_SUPPORT //
16237 + case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
16238 + if(pEid->Len == 3)
16239 + {
16240 + *pNewChannel = pEid->Octet[1]; //extract new channel number
16241 + }
16242 + break;
16243 +
16244 + // New for WPA
16245 + // CCX v2 has the same IE, we need to parse that too
16246 + // Wifi WMM use the same IE vale, need to parse that too
16247 + // case IE_WPA:
16248 + case IE_VENDOR_SPECIFIC:
16249 + // Check Broadcom/Atheros 802.11n OUI version, for HT Capability IE.
16250 + // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan.
16251 + /*if (NdisEqualMemory(pEid->Octet, BROADCOM_OUI, 3) && (pEid->Len >= 4))
16252 + {
16253 + if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 30))
16254 + {
16255 + {
16256 + NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE));
16257 + *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes.
16258 + }
16259 + }
16260 + if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 26))
16261 + {
16262 + {
16263 + NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE));
16264 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; // Nnow we only support 26 bytes.
16265 + }
16266 + }
16267 + }
16268 + */
16269 + // Check the OUI version, filter out non-standard usage
16270 + if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3) && (pEid->Len == 7))
16271 + {
16272 + //*pRalinkIe = pEid->Octet[3];
16273 + if (pEid->Octet[3] != 0)
16274 + *pRalinkIe = pEid->Octet[3];
16275 + else
16276 + *pRalinkIe = 0xf0000000; // Set to non-zero value (can't set bit0-2) to represent this is Ralink Chip. So at linkup, we will set ralinkchip flag.
16277 + }
16278 +#ifdef CONFIG_STA_SUPPORT
16279 +#ifdef DOT11_N_SUPPORT
16280 + // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan.
16281 +
16282 + // Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP,
16283 + // Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE
16284 + else if ((*pHtCapabilityLen == 0) && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI, 3) && (pEid->Len >= 4) && (pAd->OpMode == OPMODE_STA))
16285 + {
16286 + if ((pEid->Octet[3] == OUI_PREN_HT_CAP) && (pEid->Len >= 30) && (*pHtCapabilityLen == 0))
16287 + {
16288 + NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE));
16289 + *pPreNHtCapabilityLen = SIZE_HT_CAP_IE;
16290 + }
16291 +
16292 + if ((pEid->Octet[3] == OUI_PREN_ADD_HT) && (pEid->Len >= 26))
16293 + {
16294 + NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE));
16295 + *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
16296 + }
16297 + }
16298 +#endif // DOT11_N_SUPPORT //
16299 +#endif // CONFIG_STA_SUPPORT //
16300 + else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
16301 + {
16302 + // Copy to pVIE which will report to microsoft bssid list.
16303 + Ptr = (PUCHAR) pVIE;
16304 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16305 + *LengthVIE += (pEid->Len + 2);
16306 + }
16307 + else if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))
16308 + {
16309 + PUCHAR ptr;
16310 + int i;
16311 +
16312 + // parsing EDCA parameters
16313 + pEdcaParm->bValid = TRUE;
16314 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
16315 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
16316 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
16317 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
16318 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
16319 + ptr = &pEid->Octet[8];
16320 + for (i=0; i<4; i++)
16321 + {
16322 + UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX
16323 + pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM
16324 + pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN
16325 + pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin
16326 + pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax
16327 + pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us
16328 + ptr += 4; // point to next AC
16329 + }
16330 + }
16331 + else if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6) && (pEid->Len == 7))
16332 + {
16333 + // parsing EDCA parameters
16334 + pEdcaParm->bValid = TRUE;
16335 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
16336 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
16337 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
16338 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
16339 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
16340 +
16341 + // use default EDCA parameter
16342 + pEdcaParm->bACM[QID_AC_BE] = 0;
16343 + pEdcaParm->Aifsn[QID_AC_BE] = 3;
16344 + pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS;
16345 + pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS;
16346 + pEdcaParm->Txop[QID_AC_BE] = 0;
16347 +
16348 + pEdcaParm->bACM[QID_AC_BK] = 0;
16349 + pEdcaParm->Aifsn[QID_AC_BK] = 7;
16350 + pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS;
16351 + pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS;
16352 + pEdcaParm->Txop[QID_AC_BK] = 0;
16353 +
16354 + pEdcaParm->bACM[QID_AC_VI] = 0;
16355 + pEdcaParm->Aifsn[QID_AC_VI] = 2;
16356 + pEdcaParm->Cwmin[QID_AC_VI] = CW_MIN_IN_BITS-1;
16357 + pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS;
16358 + pEdcaParm->Txop[QID_AC_VI] = 96; // AC_VI: 96*32us ~= 3ms
16359 +
16360 + pEdcaParm->bACM[QID_AC_VO] = 0;
16361 + pEdcaParm->Aifsn[QID_AC_VO] = 2;
16362 + pEdcaParm->Cwmin[QID_AC_VO] = CW_MIN_IN_BITS-2;
16363 + pEdcaParm->Cwmax[QID_AC_VO] = CW_MAX_IN_BITS-1;
16364 + pEdcaParm->Txop[QID_AC_VO] = 48; // AC_VO: 48*32us ~= 1.5ms
16365 + }
16366 +#ifdef CONFIG_STA_SUPPORT
16367 +#endif // CONFIG_STA_SUPPORT //
16368 + else
16369 + {
16370 + }
16371 +
16372 + break;
16373 +
16374 + case IE_EXT_SUPP_RATES:
16375 + if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
16376 + {
16377 + NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
16378 + *pExtRateLen = pEid->Len;
16379 +
16380 + // TODO: 2004-09-14 not a good design here, cause it exclude extra rates
16381 + // from ScanTab. We should report as is. And filter out unsupported
16382 + // rates in MlmeAux.
16383 + // Check against the supported rates
16384 + // RTMPCheckRates(pAd, ExtRate, pExtRateLen);
16385 + }
16386 + break;
16387 +
16388 + case IE_ERP:
16389 + if (pEid->Len == 1)
16390 + {
16391 + *pErp = (UCHAR)pEid->Octet[0];
16392 + }
16393 + break;
16394 +
16395 + case IE_AIRONET_CKIP:
16396 + // 0. Check Aironet IE length, it must be larger or equal to 28
16397 + // Cisco AP350 used length as 28
16398 + // Cisco AP12XX used length as 30
16399 + if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
16400 + break;
16401 +
16402 + // 1. Copy CKIP flag byte to buffer for process
16403 + *pCkipFlag = *(pEid->Octet + 8);
16404 + break;
16405 +
16406 + case IE_AP_TX_POWER:
16407 + // AP Control of Client Transmit Power
16408 + //0. Check Aironet IE length, it must be 6
16409 + if (pEid->Len != 0x06)
16410 + break;
16411 +
16412 + // Get cell power limit in dBm
16413 + if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
16414 + *pAironetCellPowerLimit = *(pEid->Octet + 4);
16415 + break;
16416 +
16417 + // WPA2 & 802.11i RSN
16418 + case IE_RSN:
16419 + // There is no OUI for version anymore, check the group cipher OUI before copying
16420 + if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
16421 + {
16422 + // Copy to pVIE which will report to microsoft bssid list.
16423 + Ptr = (PUCHAR) pVIE;
16424 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16425 + *LengthVIE += (pEid->Len + 2);
16426 + }
16427 + break;
16428 +#ifdef CONFIG_STA_SUPPORT
16429 +#ifdef EXT_BUILD_CHANNEL_LIST
16430 + case IE_COUNTRY:
16431 + Ptr = (PUCHAR) pVIE;
16432 + NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2);
16433 + *LengthVIE += (pEid->Len + 2);
16434 + break;
16435 +#endif // EXT_BUILD_CHANNEL_LIST //
16436 +#endif // CONFIG_STA_SUPPORT //
16437 + default:
16438 + break;
16439 + }
16440 +
16441 + Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len]
16442 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
16443 + }
16444 +
16445 + // For some 11a AP. it did not have the channel EID, patch here
16446 +#ifdef CONFIG_STA_SUPPORT
16447 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
16448 + {
16449 + UCHAR LatchRfChannel = MsgChannel;
16450 + if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0))
16451 + {
16452 + if (CtrlChannel != 0)
16453 + *pChannel = CtrlChannel;
16454 + else
16455 + *pChannel = LatchRfChannel;
16456 + Sanity |= 0x4;
16457 + }
16458 + }
16459 +#endif // CONFIG_STA_SUPPORT //
16460 +
16461 + if (Sanity != 0x7)
16462 + {
16463 + DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n", Sanity));
16464 + return FALSE;
16465 + }
16466 + else
16467 + {
16468 + return TRUE;
16469 + }
16470 +
16471 +}
16472 +
16473 +#ifdef DOT11N_DRAFT3
16474 +/*
16475 + ==========================================================================
16476 + Description:
16477 + MLME message sanity check for some IE addressed in 802.11n d3.03.
16478 + Return:
16479 + TRUE if all parameters are OK, FALSE otherwise
16480 +
16481 + IRQL = DISPATCH_LEVEL
16482 +
16483 + ==========================================================================
16484 + */
16485 +BOOLEAN PeerBeaconAndProbeRspSanity2(
16486 + IN PRTMP_ADAPTER pAd,
16487 + IN VOID *Msg,
16488 + IN ULONG MsgLen,
16489 + OUT UCHAR *RegClass)
16490 +{
16491 + CHAR *Ptr;
16492 + PFRAME_802_11 pFrame;
16493 + PEID_STRUCT pEid;
16494 + ULONG Length = 0;
16495 +
16496 + pFrame = (PFRAME_802_11)Msg;
16497 +
16498 + *RegClass = 0;
16499 + Ptr = pFrame->Octet;
16500 + Length += LENGTH_802_11;
16501 +
16502 + // get timestamp from payload and advance the pointer
16503 + Ptr += TIMESTAMP_LEN;
16504 + Length += TIMESTAMP_LEN;
16505 +
16506 + // get beacon interval from payload and advance the pointer
16507 + Ptr += 2;
16508 + Length += 2;
16509 +
16510 + // get capability info from payload and advance the pointer
16511 + Ptr += 2;
16512 + Length += 2;
16513 +
16514 + pEid = (PEID_STRUCT) Ptr;
16515 +
16516 + // get variable fields from payload and advance the pointer
16517 + while ((Length + 2 + pEid->Len) <= MsgLen)
16518 + {
16519 + switch(pEid->Eid)
16520 + {
16521 + case IE_SUPP_REG_CLASS:
16522 + if(pEid->Len > 0)
16523 + {
16524 + *RegClass = *pEid->Octet;
16525 + }
16526 + else
16527 + {
16528 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len));
16529 + return FALSE;
16530 + }
16531 + break;
16532 + }
16533 +
16534 + Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len]
16535 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
16536 + }
16537 +
16538 + return TRUE;
16539 +
16540 +}
16541 +#endif // DOT11N_DRAFT3 //
16542 +
16543 +/*
16544 + ==========================================================================
16545 + Description:
16546 + MLME message sanity check
16547 + Return:
16548 + TRUE if all parameters are OK, FALSE otherwise
16549 + ==========================================================================
16550 + */
16551 +BOOLEAN MlmeScanReqSanity(
16552 + IN PRTMP_ADAPTER pAd,
16553 + IN VOID *Msg,
16554 + IN ULONG MsgLen,
16555 + OUT UCHAR *pBssType,
16556 + OUT CHAR Ssid[],
16557 + OUT UCHAR *pSsidLen,
16558 + OUT UCHAR *pScanType)
16559 +{
16560 + MLME_SCAN_REQ_STRUCT *Info;
16561 +
16562 + Info = (MLME_SCAN_REQ_STRUCT *)(Msg);
16563 + *pBssType = Info->BssType;
16564 + *pSsidLen = Info->SsidLen;
16565 + NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
16566 + *pScanType = Info->ScanType;
16567 +
16568 + if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC || *pBssType == BSS_ANY)
16569 + && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE
16570 +#ifdef CONFIG_STA_SUPPORT
16571 + || *pScanType == SCAN_CISCO_PASSIVE || *pScanType == SCAN_CISCO_ACTIVE
16572 + || *pScanType == SCAN_CISCO_CHANNEL_LOAD || *pScanType == SCAN_CISCO_NOISE
16573 +#endif // CONFIG_STA_SUPPORT //
16574 + ))
16575 + {
16576 + return TRUE;
16577 + }
16578 + else
16579 + {
16580 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqSanity fail - wrong BssType or ScanType\n"));
16581 + return FALSE;
16582 + }
16583 +}
16584 +
16585 +// IRQL = DISPATCH_LEVEL
16586 +UCHAR ChannelSanity(
16587 + IN PRTMP_ADAPTER pAd,
16588 + IN UCHAR channel)
16589 +{
16590 + int i;
16591 +
16592 + for (i = 0; i < pAd->ChannelListNum; i ++)
16593 + {
16594 + if (channel == pAd->ChannelList[i].Channel)
16595 + return 1;
16596 + }
16597 + return 0;
16598 +}
16599 +
16600 +/*
16601 + ==========================================================================
16602 + Description:
16603 + MLME message sanity check
16604 + Return:
16605 + TRUE if all parameters are OK, FALSE otherwise
16606 +
16607 + IRQL = DISPATCH_LEVEL
16608 +
16609 + ==========================================================================
16610 + */
16611 +BOOLEAN PeerDeauthSanity(
16612 + IN PRTMP_ADAPTER pAd,
16613 + IN VOID *Msg,
16614 + IN ULONG MsgLen,
16615 + OUT PUCHAR pAddr2,
16616 + OUT USHORT *pReason)
16617 +{
16618 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
16619 +
16620 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16621 + NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
16622 +
16623 + return TRUE;
16624 +}
16625 +
16626 +/*
16627 + ==========================================================================
16628 + Description:
16629 + MLME message sanity check
16630 + Return:
16631 + TRUE if all parameters are OK, FALSE otherwise
16632 +
16633 + IRQL = DISPATCH_LEVEL
16634 +
16635 + ==========================================================================
16636 + */
16637 +BOOLEAN PeerAuthSanity(
16638 + IN PRTMP_ADAPTER pAd,
16639 + IN VOID *Msg,
16640 + IN ULONG MsgLen,
16641 + OUT PUCHAR pAddr,
16642 + OUT USHORT *pAlg,
16643 + OUT USHORT *pSeq,
16644 + OUT USHORT *pStatus,
16645 + CHAR *pChlgText)
16646 +{
16647 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
16648 +
16649 + COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2);
16650 + NdisMoveMemory(pAlg, &pFrame->Octet[0], 2);
16651 + NdisMoveMemory(pSeq, &pFrame->Octet[2], 2);
16652 + NdisMoveMemory(pStatus, &pFrame->Octet[4], 2);
16653 +
16654 + if ((*pAlg == Ndis802_11AuthModeOpen)
16655 +#ifdef LEAP_SUPPORT
16656 + || (*pAlg == CISCO_AuthModeLEAP)
16657 +#endif // LEAP_SUPPORT //
16658 + )
16659 + {
16660 + if (*pSeq == 1 || *pSeq == 2)
16661 + {
16662 + return TRUE;
16663 + }
16664 + else
16665 + {
16666 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n"));
16667 + return FALSE;
16668 + }
16669 + }
16670 + else if (*pAlg == Ndis802_11AuthModeShared)
16671 + {
16672 + if (*pSeq == 1 || *pSeq == 4)
16673 + {
16674 + return TRUE;
16675 + }
16676 + else if (*pSeq == 2 || *pSeq == 3)
16677 + {
16678 + NdisMoveMemory(pChlgText, &pFrame->Octet[8], CIPHER_TEXT_LEN);
16679 + return TRUE;
16680 + }
16681 + else
16682 + {
16683 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n"));
16684 + return FALSE;
16685 + }
16686 + }
16687 + else
16688 + {
16689 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong algorithm\n"));
16690 + return FALSE;
16691 + }
16692 +}
16693 +
16694 +/*
16695 + ==========================================================================
16696 + Description:
16697 + MLME message sanity check
16698 + Return:
16699 + TRUE if all parameters are OK, FALSE otherwise
16700 + ==========================================================================
16701 + */
16702 +BOOLEAN MlmeAuthReqSanity(
16703 + IN PRTMP_ADAPTER pAd,
16704 + IN VOID *Msg,
16705 + IN ULONG MsgLen,
16706 + OUT PUCHAR pAddr,
16707 + OUT ULONG *pTimeout,
16708 + OUT USHORT *pAlg)
16709 +{
16710 + MLME_AUTH_REQ_STRUCT *pInfo;
16711 +
16712 + pInfo = (MLME_AUTH_REQ_STRUCT *)Msg;
16713 + COPY_MAC_ADDR(pAddr, pInfo->Addr);
16714 + *pTimeout = pInfo->Timeout;
16715 + *pAlg = pInfo->Alg;
16716 +
16717 + if (((*pAlg == Ndis802_11AuthModeShared) ||(*pAlg == Ndis802_11AuthModeOpen)
16718 +#ifdef LEAP_SUPPORT
16719 + || (*pAlg == CISCO_AuthModeLEAP)
16720 +#endif // LEAP_SUPPORT //
16721 + ) &&
16722 + ((*pAddr & 0x01) == 0))
16723 + {
16724 + return TRUE;
16725 + }
16726 + else
16727 + {
16728 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeAuthReqSanity fail - wrong algorithm\n"));
16729 + return FALSE;
16730 + }
16731 +}
16732 +
16733 +/*
16734 + ==========================================================================
16735 + Description:
16736 + MLME message sanity check
16737 + Return:
16738 + TRUE if all parameters are OK, FALSE otherwise
16739 +
16740 + IRQL = DISPATCH_LEVEL
16741 +
16742 + ==========================================================================
16743 + */
16744 +BOOLEAN MlmeAssocReqSanity(
16745 + IN PRTMP_ADAPTER pAd,
16746 + IN VOID *Msg,
16747 + IN ULONG MsgLen,
16748 + OUT PUCHAR pApAddr,
16749 + OUT USHORT *pCapabilityInfo,
16750 + OUT ULONG *pTimeout,
16751 + OUT USHORT *pListenIntv)
16752 +{
16753 + MLME_ASSOC_REQ_STRUCT *pInfo;
16754 +
16755 + pInfo = (MLME_ASSOC_REQ_STRUCT *)Msg;
16756 + *pTimeout = pInfo->Timeout; // timeout
16757 + COPY_MAC_ADDR(pApAddr, pInfo->Addr); // AP address
16758 + *pCapabilityInfo = pInfo->CapabilityInfo; // capability info
16759 + *pListenIntv = pInfo->ListenIntv;
16760 +
16761 + return TRUE;
16762 +}
16763 +
16764 +/*
16765 + ==========================================================================
16766 + Description:
16767 + MLME message sanity check
16768 + Return:
16769 + TRUE if all parameters are OK, FALSE otherwise
16770 +
16771 + IRQL = DISPATCH_LEVEL
16772 +
16773 + ==========================================================================
16774 + */
16775 +BOOLEAN PeerDisassocSanity(
16776 + IN PRTMP_ADAPTER pAd,
16777 + IN VOID *Msg,
16778 + IN ULONG MsgLen,
16779 + OUT PUCHAR pAddr2,
16780 + OUT USHORT *pReason)
16781 +{
16782 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
16783 +
16784 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
16785 + NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
16786 +
16787 + return TRUE;
16788 +}
16789 +
16790 +/*
16791 + ========================================================================
16792 + Routine Description:
16793 + Sanity check NetworkType (11b, 11g or 11a)
16794 +
16795 + Arguments:
16796 + pBss - Pointer to BSS table.
16797 +
16798 + Return Value:
16799 + Ndis802_11DS .......(11b)
16800 + Ndis802_11OFDM24....(11g)
16801 + Ndis802_11OFDM5.....(11a)
16802 +
16803 + IRQL = DISPATCH_LEVEL
16804 +
16805 + ========================================================================
16806 +*/
16807 +NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(
16808 + IN PBSS_ENTRY pBss)
16809 +{
16810 + NDIS_802_11_NETWORK_TYPE NetWorkType;
16811 + UCHAR rate, i;
16812 +
16813 + NetWorkType = Ndis802_11DS;
16814 +
16815 + if (pBss->Channel <= 14)
16816 + {
16817 + //
16818 + // First check support Rate.
16819 + //
16820 + for (i = 0; i < pBss->SupRateLen; i++)
16821 + {
16822 + rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit
16823 + if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22))
16824 + {
16825 + continue;
16826 + }
16827 + else
16828 + {
16829 + //
16830 + // Otherwise (even rate > 108) means Ndis802_11OFDM24
16831 + //
16832 + NetWorkType = Ndis802_11OFDM24;
16833 + break;
16834 + }
16835 + }
16836 +
16837 + //
16838 + // Second check Extend Rate.
16839 + //
16840 + if (NetWorkType != Ndis802_11OFDM24)
16841 + {
16842 + for (i = 0; i < pBss->ExtRateLen; i++)
16843 + {
16844 + rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit
16845 + if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22))
16846 + {
16847 + continue;
16848 + }
16849 + else
16850 + {
16851 + //
16852 + // Otherwise (even rate > 108) means Ndis802_11OFDM24
16853 + //
16854 + NetWorkType = Ndis802_11OFDM24;
16855 + break;
16856 + }
16857 + }
16858 + }
16859 + }
16860 + else
16861 + {
16862 + NetWorkType = Ndis802_11OFDM5;
16863 + }
16864 +
16865 + if (pBss->HtCapabilityLen != 0)
16866 + {
16867 + if (NetWorkType == Ndis802_11OFDM5)
16868 + NetWorkType = Ndis802_11OFDM5_N;
16869 + else
16870 + NetWorkType = Ndis802_11OFDM24_N;
16871 + }
16872 +
16873 + return NetWorkType;
16874 +}
16875 +
16876 +/*
16877 + ==========================================================================
16878 + Description:
16879 + WPA message sanity check
16880 + Return:
16881 + TRUE if all parameters are OK, FALSE otherwise
16882 + ==========================================================================
16883 + */
16884 +BOOLEAN PeerWpaMessageSanity(
16885 + IN PRTMP_ADAPTER pAd,
16886 + IN PEAPOL_PACKET pMsg,
16887 + IN ULONG MsgLen,
16888 + IN UCHAR MsgType,
16889 + IN MAC_TABLE_ENTRY *pEntry)
16890 +{
16891 + UCHAR mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE];
16892 + BOOLEAN bReplayDiff = FALSE;
16893 + BOOLEAN bWPA2 = FALSE;
16894 + KEY_INFO EapolKeyInfo;
16895 + UCHAR GroupKeyIndex = 0;
16896 +
16897 +
16898 + NdisZeroMemory(mic, sizeof(mic));
16899 + NdisZeroMemory(digest, sizeof(digest));
16900 + NdisZeroMemory(KEYDATA, sizeof(KEYDATA));
16901 + NdisZeroMemory((PUCHAR)&EapolKeyInfo, sizeof(EapolKeyInfo));
16902 +
16903 + NdisMoveMemory((PUCHAR)&EapolKeyInfo, (PUCHAR)&pMsg->KeyDesc.KeyInfo, sizeof(KEY_INFO));
16904 +
16905 + *((USHORT *)&EapolKeyInfo) = cpu2le16(*((USHORT *)&EapolKeyInfo));
16906 +
16907 + // Choose WPA2 or not
16908 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK))
16909 + bWPA2 = TRUE;
16910 +
16911 + // 0. Check MsgType
16912 + if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1))
16913 + {
16914 + DBGPRINT(RT_DEBUG_ERROR, ("The message type is invalid(%d)! \n", MsgType));
16915 + return FALSE;
16916 + }
16917 +
16918 + // 1. Replay counter check
16919 + if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) // For supplicant
16920 + {
16921 + // First validate replay counter, only accept message with larger replay counter.
16922 + // Let equal pass, some AP start with all zero replay counter
16923 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
16924 +
16925 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
16926 + if ((RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY) != 1) &&
16927 + (RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
16928 + {
16929 + bReplayDiff = TRUE;
16930 + }
16931 + }
16932 + else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) // For authenticator
16933 + {
16934 + // check Replay Counter coresponds to MSG from authenticator, otherwise discard
16935 + if (!NdisEqualMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY))
16936 + {
16937 + bReplayDiff = TRUE;
16938 + }
16939 + }
16940 +
16941 + // Replay Counter different condition
16942 + if (bReplayDiff)
16943 + {
16944 + // send wireless event - for replay counter different
16945 + if (pAd->CommonCfg.bWirelessEvent)
16946 + RTMPSendWirelessEvent(pAd, IW_REPLAY_COUNTER_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
16947 +
16948 + if (MsgType < EAPOL_GROUP_MSG_1)
16949 + {
16950 + DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n", MsgType));
16951 + }
16952 + else
16953 + {
16954 + DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4)));
16955 + }
16956 +
16957 + hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
16958 + hex_dump("Current replay counter ", pEntry->R_Counter, LEN_KEY_DESC_REPLAY);
16959 + return FALSE;
16960 + }
16961 +
16962 + // 2. Verify MIC except Pairwise Msg1
16963 + if (MsgType != EAPOL_PAIR_MSG_1)
16964 + {
16965 + UCHAR rcvd_mic[LEN_KEY_DESC_MIC];
16966 +
16967 + // Record the received MIC for check later
16968 + NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
16969 + NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
16970 +
16971 + if (pEntry->WepStatus == Ndis802_11Encryption2Enabled) // TKIP
16972 + {
16973 + hmac_md5(pEntry->PTK, LEN_EAP_MICK, (PUCHAR)pMsg, MsgLen, mic);
16974 + }
16975 + else if (pEntry->WepStatus == Ndis802_11Encryption3Enabled) // AES
16976 + {
16977 + HMAC_SHA1((PUCHAR)pMsg, MsgLen, pEntry->PTK, LEN_EAP_MICK, digest);
16978 + NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
16979 + }
16980 +
16981 + if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC))
16982 + {
16983 + // send wireless event - for MIC different
16984 + if (pAd->CommonCfg.bWirelessEvent)
16985 + RTMPSendWirelessEvent(pAd, IW_MIC_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
16986 +
16987 + if (MsgType < EAPOL_GROUP_MSG_1)
16988 + {
16989 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in pairwise msg %d of 4-way handshake!\n", MsgType));
16990 + }
16991 + else
16992 + {
16993 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4)));
16994 + }
16995 +
16996 + hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC);
16997 + hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC);
16998 +
16999 + return FALSE;
17000 + }
17001 + }
17002 +
17003 + // Extract the context of the Key Data field if it exist
17004 + // The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is un-encrypted.
17005 + // The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted.
17006 + if (pMsg->KeyDesc.KeyDataLen[1] > 0)
17007 + {
17008 + // Decrypt this field
17009 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
17010 + {
17011 + if(pEntry->WepStatus == Ndis802_11Encryption3Enabled)
17012 + {
17013 + // AES
17014 + AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA, pMsg->KeyDesc.KeyDataLen[1],pMsg->KeyDesc.KeyData);
17015 + }
17016 + else
17017 + {
17018 + INT i;
17019 + UCHAR Key[32];
17020 + // Decrypt TKIP GTK
17021 + // Construct 32 bytes RC4 Key
17022 + NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16);
17023 + NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16);
17024 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
17025 + //discard first 256 bytes
17026 + for(i = 0; i < 256; i++)
17027 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
17028 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
17029 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]);
17030 + }
17031 +
17032 + if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
17033 + GroupKeyIndex = EapolKeyInfo.KeyIndex;
17034 +
17035 + }
17036 + else if ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2))
17037 + {
17038 + NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]);
17039 + }
17040 + else
17041 + {
17042 +
17043 + return TRUE;
17044 + }
17045 +
17046 + // Parse Key Data field to
17047 + // 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2)
17048 + // 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2
17049 + // 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2)
17050 + if (!RTMPParseEapolKeyData(pAd, KEYDATA, pMsg->KeyDesc.KeyDataLen[1], GroupKeyIndex, MsgType, bWPA2, pEntry))
17051 + {
17052 + return FALSE;
17053 + }
17054 + }
17055 +
17056 + return TRUE;
17057 +
17058 +}
17059 +
17060 +#ifdef CONFIG_STA_SUPPORT
17061 +#ifdef QOS_DLS_SUPPORT
17062 +BOOLEAN MlmeDlsReqSanity(
17063 + IN PRTMP_ADAPTER pAd,
17064 + IN VOID *Msg,
17065 + IN ULONG MsgLen,
17066 + OUT PRT_802_11_DLS *pDLS,
17067 + OUT PUSHORT pReason)
17068 +{
17069 + MLME_DLS_REQ_STRUCT *pInfo;
17070 +
17071 + pInfo = (MLME_DLS_REQ_STRUCT *)Msg;
17072 +
17073 + *pDLS = pInfo->pDLS;
17074 + *pReason = pInfo->Reason;
17075 +
17076 + return TRUE;
17077 +}
17078 +#endif // QOS_DLS_SUPPORT //
17079 +#endif // CONFIG_STA_SUPPORT //
17080 +
17081 +#ifdef QOS_DLS_SUPPORT
17082 +BOOLEAN PeerDlsReqSanity(
17083 + IN PRTMP_ADAPTER pAd,
17084 + IN VOID *Msg,
17085 + IN ULONG MsgLen,
17086 + OUT PUCHAR pDA,
17087 + OUT PUCHAR pSA,
17088 + OUT USHORT *pCapabilityInfo,
17089 + OUT USHORT *pDlsTimeout,
17090 + OUT UCHAR *pRatesLen,
17091 + OUT UCHAR Rates[],
17092 + OUT UCHAR *pHtCapabilityLen,
17093 + OUT HT_CAPABILITY_IE *pHtCapability)
17094 +{
17095 + CHAR *Ptr;
17096 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17097 + PEID_STRUCT eid_ptr;
17098 +
17099 + // to prevent caller from using garbage output value
17100 + *pCapabilityInfo = 0;
17101 + *pDlsTimeout = 0;
17102 + *pHtCapabilityLen = 0;
17103 +
17104 + Ptr = Fr->Octet;
17105 +
17106 + // offset to destination MAC address (Category and Action field)
17107 + Ptr += 2;
17108 +
17109 + // get DA from payload and advance the pointer
17110 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17111 + Ptr += MAC_ADDR_LEN;
17112 +
17113 + // get SA from payload and advance the pointer
17114 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17115 + Ptr += MAC_ADDR_LEN;
17116 +
17117 + // get capability info from payload and advance the pointer
17118 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
17119 + Ptr += 2;
17120 +
17121 + // get capability info from payload and advance the pointer
17122 + NdisMoveMemory(pDlsTimeout, Ptr, 2);
17123 + Ptr += 2;
17124 +
17125 + // Category and Action field + DA + SA + capability + Timeout
17126 + eid_ptr = (PEID_STRUCT) &Fr->Octet[18];
17127 +
17128 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((UCHAR*)Fr + MsgLen))
17129 + {
17130 + switch(eid_ptr->Eid)
17131 + {
17132 + case IE_SUPP_RATES:
17133 + if ((eid_ptr->Len <= MAX_LEN_OF_SUPPORTED_RATES) && (eid_ptr->Len > 0))
17134 + {
17135 + NdisMoveMemory(Rates, eid_ptr->Octet, eid_ptr->Len);
17136 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - IE_SUPP_RATES., Len=%d. Rates[0]=%x\n",eid_ptr->Len, Rates[0]));
17137 + DBGPRINT(RT_DEBUG_TRACE, ("Rates[1]=%x %x %x %x %x %x %x\n", Rates[1], Rates[2], Rates[3], Rates[4], Rates[5], Rates[6], Rates[7]));
17138 + *pRatesLen = eid_ptr->Len;
17139 + }
17140 + else
17141 + {
17142 + *pRatesLen = 8;
17143 + Rates[0] = 0x82;
17144 + Rates[1] = 0x84;
17145 + Rates[2] = 0x8b;
17146 + Rates[3] = 0x96;
17147 + Rates[4] = 0x12;
17148 + Rates[5] = 0x24;
17149 + Rates[6] = 0x48;
17150 + Rates[7] = 0x6c;
17151 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - wrong IE_SUPP_RATES., Len=%d\n",eid_ptr->Len));
17152 + }
17153 + break;
17154 +
17155 + case IE_EXT_SUPP_RATES:
17156 + if (eid_ptr->Len + *pRatesLen <= MAX_LEN_OF_SUPPORTED_RATES)
17157 + {
17158 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, eid_ptr->Len);
17159 + *pRatesLen = (*pRatesLen) + eid_ptr->Len;
17160 + }
17161 + else
17162 + {
17163 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, MAX_LEN_OF_SUPPORTED_RATES - (*pRatesLen));
17164 + *pRatesLen = MAX_LEN_OF_SUPPORTED_RATES;
17165 + }
17166 + break;
17167 +
17168 + case IE_HT_CAP:
17169 + if (eid_ptr->Len >= sizeof(HT_CAPABILITY_IE))
17170 + {
17171 + NdisMoveMemory(pHtCapability, eid_ptr->Octet, sizeof(HT_CAPABILITY_IE));
17172 +
17173 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
17174 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
17175 + *pHtCapabilityLen = sizeof(HT_CAPABILITY_IE);
17176 +
17177 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - IE_HT_CAP\n"));
17178 + }
17179 + else
17180 + {
17181 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsReqSanity - wrong IE_HT_CAP.eid_ptr->Len = %d\n", eid_ptr->Len));
17182 + }
17183 + break;
17184 +
17185 + default:
17186 + break;
17187 + }
17188 +
17189 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
17190 + }
17191 +
17192 + return TRUE;
17193 +}
17194 +
17195 +BOOLEAN PeerDlsRspSanity(
17196 + IN PRTMP_ADAPTER pAd,
17197 + IN VOID *Msg,
17198 + IN ULONG MsgLen,
17199 + OUT PUCHAR pDA,
17200 + OUT PUCHAR pSA,
17201 + OUT USHORT *pCapabilityInfo,
17202 + OUT USHORT *pStatus,
17203 + OUT UCHAR *pRatesLen,
17204 + OUT UCHAR Rates[],
17205 + OUT UCHAR *pHtCapabilityLen,
17206 + OUT HT_CAPABILITY_IE *pHtCapability)
17207 +{
17208 + CHAR *Ptr;
17209 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17210 + PEID_STRUCT eid_ptr;
17211 +
17212 + // to prevent caller from using garbage output value
17213 + *pStatus = 0;
17214 + *pCapabilityInfo = 0;
17215 + *pHtCapabilityLen = 0;
17216 +
17217 + Ptr = Fr->Octet;
17218 +
17219 + // offset to destination MAC address (Category and Action field)
17220 + Ptr += 2;
17221 +
17222 + // get status code from payload and advance the pointer
17223 + NdisMoveMemory(pStatus, Ptr, 2);
17224 + Ptr += 2;
17225 +
17226 + // get DA from payload and advance the pointer
17227 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17228 + Ptr += MAC_ADDR_LEN;
17229 +
17230 + // get SA from payload and advance the pointer
17231 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17232 + Ptr += MAC_ADDR_LEN;
17233 +
17234 + if (pStatus == 0)
17235 + {
17236 + // get capability info from payload and advance the pointer
17237 + NdisMoveMemory(pCapabilityInfo, Ptr, 2);
17238 + Ptr += 2;
17239 + }
17240 +
17241 + // Category and Action field + status code + DA + SA + capability
17242 + eid_ptr = (PEID_STRUCT) &Fr->Octet[18];
17243 +
17244 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((UCHAR*)Fr + MsgLen))
17245 + {
17246 + switch(eid_ptr->Eid)
17247 + {
17248 + case IE_SUPP_RATES:
17249 + if ((eid_ptr->Len <= MAX_LEN_OF_SUPPORTED_RATES) && (eid_ptr->Len > 0))
17250 + {
17251 + NdisMoveMemory(Rates, eid_ptr->Octet, eid_ptr->Len);
17252 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - IE_SUPP_RATES., Len=%d. Rates[0]=%x\n",eid_ptr->Len, Rates[0]));
17253 + DBGPRINT(RT_DEBUG_TRACE, ("Rates[1]=%x %x %x %x %x %x %x\n", Rates[1], Rates[2], Rates[3], Rates[4], Rates[5], Rates[6], Rates[7]));
17254 + *pRatesLen = eid_ptr->Len;
17255 + }
17256 + else
17257 + {
17258 + *pRatesLen = 8;
17259 + Rates[0] = 0x82;
17260 + Rates[1] = 0x84;
17261 + Rates[2] = 0x8b;
17262 + Rates[3] = 0x96;
17263 + Rates[4] = 0x12;
17264 + Rates[5] = 0x24;
17265 + Rates[6] = 0x48;
17266 + Rates[7] = 0x6c;
17267 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - wrong IE_SUPP_RATES., Len=%d\n",eid_ptr->Len));
17268 + }
17269 + break;
17270 +
17271 + case IE_EXT_SUPP_RATES:
17272 + if (eid_ptr->Len + *pRatesLen <= MAX_LEN_OF_SUPPORTED_RATES)
17273 + {
17274 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, eid_ptr->Len);
17275 + *pRatesLen = (*pRatesLen) + eid_ptr->Len;
17276 + }
17277 + else
17278 + {
17279 + NdisMoveMemory(&Rates[*pRatesLen], eid_ptr->Octet, MAX_LEN_OF_SUPPORTED_RATES - (*pRatesLen));
17280 + *pRatesLen = MAX_LEN_OF_SUPPORTED_RATES;
17281 + }
17282 + break;
17283 +
17284 + case IE_HT_CAP:
17285 + if (eid_ptr->Len >= sizeof(HT_CAPABILITY_IE))
17286 + {
17287 + NdisMoveMemory(pHtCapability, eid_ptr->Octet, sizeof(HT_CAPABILITY_IE));
17288 +
17289 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
17290 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
17291 + *pHtCapabilityLen = sizeof(HT_CAPABILITY_IE);
17292 +
17293 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - IE_HT_CAP\n"));
17294 + }
17295 + else
17296 + {
17297 + DBGPRINT(RT_DEBUG_TRACE, ("PeerDlsRspSanity - wrong IE_HT_CAP.eid_ptr->Len = %d\n", eid_ptr->Len));
17298 + }
17299 + break;
17300 +
17301 + default:
17302 + break;
17303 + }
17304 +
17305 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
17306 + }
17307 +
17308 + return TRUE;
17309 +}
17310 +
17311 +BOOLEAN PeerDlsTearDownSanity(
17312 + IN PRTMP_ADAPTER pAd,
17313 + IN VOID *Msg,
17314 + IN ULONG MsgLen,
17315 + OUT PUCHAR pDA,
17316 + OUT PUCHAR pSA,
17317 + OUT USHORT *pReason)
17318 +{
17319 + CHAR *Ptr;
17320 + PFRAME_802_11 Fr = (PFRAME_802_11)Msg;
17321 +
17322 + // to prevent caller from using garbage output value
17323 + *pReason = 0;
17324 +
17325 + Ptr = Fr->Octet;
17326 +
17327 + // offset to destination MAC address (Category and Action field)
17328 + Ptr += 2;
17329 +
17330 + // get DA from payload and advance the pointer
17331 + NdisMoveMemory(pDA, Ptr, MAC_ADDR_LEN);
17332 + Ptr += MAC_ADDR_LEN;
17333 +
17334 + // get SA from payload and advance the pointer
17335 + NdisMoveMemory(pSA, Ptr, MAC_ADDR_LEN);
17336 + Ptr += MAC_ADDR_LEN;
17337 +
17338 + // get reason code from payload and advance the pointer
17339 + NdisMoveMemory(pReason, Ptr, 2);
17340 + Ptr += 2;
17341 +
17342 + return TRUE;
17343 +}
17344 +#endif // QOS_DLS_SUPPORT //
17345 +
17346 --- /dev/null
17347 +++ b/drivers/staging/rt3070/common/cmm_sync.c
17348 @@ -0,0 +1,711 @@
17349 +/*
17350 + *************************************************************************
17351 + * Ralink Tech Inc.
17352 + * 5F., No.36, Taiyuan St., Jhubei City,
17353 + * Hsinchu County 302,
17354 + * Taiwan, R.O.C.
17355 + *
17356 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
17357 + *
17358 + * This program is free software; you can redistribute it and/or modify *
17359 + * it under the terms of the GNU General Public License as published by *
17360 + * the Free Software Foundation; either version 2 of the License, or *
17361 + * (at your option) any later version. *
17362 + * *
17363 + * This program is distributed in the hope that it will be useful, *
17364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17366 + * GNU General Public License for more details. *
17367 + * *
17368 + * You should have received a copy of the GNU General Public License *
17369 + * along with this program; if not, write to the *
17370 + * Free Software Foundation, Inc., *
17371 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17372 + * *
17373 + *************************************************************************
17374 +
17375 + Module Name:
17376 + sync.c
17377 +
17378 + Abstract:
17379 +
17380 + Revision History:
17381 + Who When What
17382 + -------- ---------- ----------------------------------------------
17383 + John Chang 2004-09-01 modified for rt2561/2661
17384 +*/
17385 +#include "../rt_config.h"
17386 +
17387 +// 2.4 Ghz channel plan index in the TxPower arrays.
17388 +#define BG_BAND_REGION_0_START 0 // 1,2,3,4,5,6,7,8,9,10,11
17389 +#define BG_BAND_REGION_0_SIZE 11
17390 +#define BG_BAND_REGION_1_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13
17391 +#define BG_BAND_REGION_1_SIZE 13
17392 +#define BG_BAND_REGION_2_START 9 // 10,11
17393 +#define BG_BAND_REGION_2_SIZE 2
17394 +#define BG_BAND_REGION_3_START 9 // 10,11,12,13
17395 +#define BG_BAND_REGION_3_SIZE 4
17396 +#define BG_BAND_REGION_4_START 13 // 14
17397 +#define BG_BAND_REGION_4_SIZE 1
17398 +#define BG_BAND_REGION_5_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14
17399 +#define BG_BAND_REGION_5_SIZE 14
17400 +#define BG_BAND_REGION_6_START 2 // 3,4,5,6,7,8,9
17401 +#define BG_BAND_REGION_6_SIZE 7
17402 +#define BG_BAND_REGION_7_START 4 // 5,6,7,8,9,10,11,12,13
17403 +#define BG_BAND_REGION_7_SIZE 9
17404 +#define BG_BAND_REGION_31_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14
17405 +#define BG_BAND_REGION_31_SIZE 14
17406 +
17407 +// 5 Ghz channel plan index in the TxPower arrays.
17408 +UCHAR A_BAND_REGION_0_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165};
17409 +UCHAR A_BAND_REGION_1_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
17410 +UCHAR A_BAND_REGION_2_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64};
17411 +UCHAR A_BAND_REGION_3_CHANNEL_LIST[]={52, 56, 60, 64, 149, 153, 157, 161};
17412 +UCHAR A_BAND_REGION_4_CHANNEL_LIST[]={149, 153, 157, 161, 165};
17413 +UCHAR A_BAND_REGION_5_CHANNEL_LIST[]={149, 153, 157, 161};
17414 +UCHAR A_BAND_REGION_6_CHANNEL_LIST[]={36, 40, 44, 48};
17415 +UCHAR A_BAND_REGION_7_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165};
17416 +UCHAR A_BAND_REGION_8_CHANNEL_LIST[]={52, 56, 60, 64};
17417 +UCHAR A_BAND_REGION_9_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165};
17418 +UCHAR A_BAND_REGION_10_CHANNEL_LIST[]={36, 40, 44, 48, 149, 153, 157, 161, 165};
17419 +UCHAR A_BAND_REGION_11_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161};
17420 +
17421 +//BaSizeArray follows the 802.11n definition as MaxRxFactor. 2^(13+factor) bytes. When factor =0, it's about Ba buffer size =8.
17422 +UCHAR BaSizeArray[4] = {8,16,32,64};
17423 +
17424 +/*
17425 + ==========================================================================
17426 + Description:
17427 + Update StaCfg->ChannelList[] according to 1) Country Region 2) RF IC type,
17428 + and 3) PHY-mode user selected.
17429 + The outcome is used by driver when doing site survey.
17430 +
17431 + IRQL = PASSIVE_LEVEL
17432 + IRQL = DISPATCH_LEVEL
17433 +
17434 + ==========================================================================
17435 + */
17436 +VOID BuildChannelList(
17437 + IN PRTMP_ADAPTER pAd)
17438 +{
17439 + UCHAR i, j, index=0, num=0;
17440 + PUCHAR pChannelList = NULL;
17441 +
17442 + NdisZeroMemory(pAd->ChannelList, MAX_NUM_OF_CHANNELS * sizeof(CHANNEL_TX_POWER));
17443 +
17444 + // if not 11a-only mode, channel list starts from 2.4Ghz band
17445 + if ((pAd->CommonCfg.PhyMode != PHY_11A)
17446 +#ifdef DOT11_N_SUPPORT
17447 + && (pAd->CommonCfg.PhyMode != PHY_11AN_MIXED) && (pAd->CommonCfg.PhyMode != PHY_11N_5G)
17448 +#endif // DOT11_N_SUPPORT //
17449 + )
17450 + {
17451 + switch (pAd->CommonCfg.CountryRegion & 0x7f)
17452 + {
17453 + case REGION_0_BG_BAND: // 1 -11
17454 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_0_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_0_SIZE);
17455 + index += BG_BAND_REGION_0_SIZE;
17456 + break;
17457 + case REGION_1_BG_BAND: // 1 - 13
17458 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_1_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_1_SIZE);
17459 + index += BG_BAND_REGION_1_SIZE;
17460 + break;
17461 + case REGION_2_BG_BAND: // 10 - 11
17462 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_2_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_2_SIZE);
17463 + index += BG_BAND_REGION_2_SIZE;
17464 + break;
17465 + case REGION_3_BG_BAND: // 10 - 13
17466 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_3_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_3_SIZE);
17467 + index += BG_BAND_REGION_3_SIZE;
17468 + break;
17469 + case REGION_4_BG_BAND: // 14
17470 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_4_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_4_SIZE);
17471 + index += BG_BAND_REGION_4_SIZE;
17472 + break;
17473 + case REGION_5_BG_BAND: // 1 - 14
17474 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_5_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_5_SIZE);
17475 + index += BG_BAND_REGION_5_SIZE;
17476 + break;
17477 + case REGION_6_BG_BAND: // 3 - 9
17478 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_6_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_6_SIZE);
17479 + index += BG_BAND_REGION_6_SIZE;
17480 + break;
17481 + case REGION_7_BG_BAND: // 5 - 13
17482 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_7_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_7_SIZE);
17483 + index += BG_BAND_REGION_7_SIZE;
17484 + break;
17485 + case REGION_31_BG_BAND: // 1 - 14
17486 + NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_31_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_31_SIZE);
17487 + index += BG_BAND_REGION_31_SIZE;
17488 + break;
17489 + default: // Error. should never happen
17490 + break;
17491 + }
17492 + for (i=0; i<index; i++)
17493 + pAd->ChannelList[i].MaxTxPwr = 20;
17494 + }
17495 +
17496 + if ((pAd->CommonCfg.PhyMode == PHY_11A) || (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
17497 +#ifdef DOT11_N_SUPPORT
17498 + || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED)
17499 + || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)
17500 +#endif // DOT11_N_SUPPORT //
17501 + )
17502 + {
17503 + switch (pAd->CommonCfg.CountryRegionForABand & 0x7f)
17504 + {
17505 + case REGION_0_A_BAND:
17506 + num = sizeof(A_BAND_REGION_0_CHANNEL_LIST)/sizeof(UCHAR);
17507 + pChannelList = A_BAND_REGION_0_CHANNEL_LIST;
17508 + break;
17509 + case REGION_1_A_BAND:
17510 + num = sizeof(A_BAND_REGION_1_CHANNEL_LIST)/sizeof(UCHAR);
17511 + pChannelList = A_BAND_REGION_1_CHANNEL_LIST;
17512 + break;
17513 + case REGION_2_A_BAND:
17514 + num = sizeof(A_BAND_REGION_2_CHANNEL_LIST)/sizeof(UCHAR);
17515 + pChannelList = A_BAND_REGION_2_CHANNEL_LIST;
17516 + break;
17517 + case REGION_3_A_BAND:
17518 + num = sizeof(A_BAND_REGION_3_CHANNEL_LIST)/sizeof(UCHAR);
17519 + pChannelList = A_BAND_REGION_3_CHANNEL_LIST;
17520 + break;
17521 + case REGION_4_A_BAND:
17522 + num = sizeof(A_BAND_REGION_4_CHANNEL_LIST)/sizeof(UCHAR);
17523 + pChannelList = A_BAND_REGION_4_CHANNEL_LIST;
17524 + break;
17525 + case REGION_5_A_BAND:
17526 + num = sizeof(A_BAND_REGION_5_CHANNEL_LIST)/sizeof(UCHAR);
17527 + pChannelList = A_BAND_REGION_5_CHANNEL_LIST;
17528 + break;
17529 + case REGION_6_A_BAND:
17530 + num = sizeof(A_BAND_REGION_6_CHANNEL_LIST)/sizeof(UCHAR);
17531 + pChannelList = A_BAND_REGION_6_CHANNEL_LIST;
17532 + break;
17533 + case REGION_7_A_BAND:
17534 + num = sizeof(A_BAND_REGION_7_CHANNEL_LIST)/sizeof(UCHAR);
17535 + pChannelList = A_BAND_REGION_7_CHANNEL_LIST;
17536 + break;
17537 + case REGION_8_A_BAND:
17538 + num = sizeof(A_BAND_REGION_8_CHANNEL_LIST)/sizeof(UCHAR);
17539 + pChannelList = A_BAND_REGION_8_CHANNEL_LIST;
17540 + break;
17541 + case REGION_9_A_BAND:
17542 + num = sizeof(A_BAND_REGION_9_CHANNEL_LIST)/sizeof(UCHAR);
17543 + pChannelList = A_BAND_REGION_9_CHANNEL_LIST;
17544 + break;
17545 +
17546 + case REGION_10_A_BAND:
17547 + num = sizeof(A_BAND_REGION_10_CHANNEL_LIST)/sizeof(UCHAR);
17548 + pChannelList = A_BAND_REGION_10_CHANNEL_LIST;
17549 + break;
17550 +
17551 + case REGION_11_A_BAND:
17552 + num = sizeof(A_BAND_REGION_11_CHANNEL_LIST)/sizeof(UCHAR);
17553 + pChannelList = A_BAND_REGION_11_CHANNEL_LIST;
17554 + break;
17555 +
17556 + default: // Error. should never happen
17557 + DBGPRINT(RT_DEBUG_WARN,("countryregion=%d not support", pAd->CommonCfg.CountryRegionForABand));
17558 + break;
17559 + }
17560 +
17561 + if (num != 0)
17562 + {
17563 + UCHAR RadarCh[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
17564 + for (i=0; i<num; i++)
17565 + {
17566 + for (j=0; j<MAX_NUM_OF_CHANNELS; j++)
17567 + {
17568 + if (pChannelList[i] == pAd->TxPower[j].Channel)
17569 + NdisMoveMemory(&pAd->ChannelList[index+i], &pAd->TxPower[j], sizeof(CHANNEL_TX_POWER));
17570 + }
17571 + for (j=0; j<15; j++)
17572 + {
17573 + if (pChannelList[i] == RadarCh[j])
17574 + pAd->ChannelList[index+i].DfsReq = TRUE;
17575 + }
17576 + pAd->ChannelList[index+i].MaxTxPwr = 20;
17577 + }
17578 + index += num;
17579 + }
17580 + }
17581 +
17582 + pAd->ChannelListNum = index;
17583 + DBGPRINT(RT_DEBUG_TRACE,("country code=%d/%d, RFIC=%d, PHY mode=%d, support %d channels\n",
17584 + pAd->CommonCfg.CountryRegion, pAd->CommonCfg.CountryRegionForABand, pAd->RfIcType, pAd->CommonCfg.PhyMode, pAd->ChannelListNum));
17585 +#ifdef DBG
17586 + for (i=0;i<pAd->ChannelListNum;i++)
17587 + {
17588 + DBGPRINT_RAW(RT_DEBUG_TRACE,("BuildChannel # %d :: Pwr0 = %d, Pwr1 =%d, \n ", pAd->ChannelList[i].Channel, pAd->ChannelList[i].Power, pAd->ChannelList[i].Power2));
17589 + }
17590 +#endif
17591 +}
17592 +
17593 +/*
17594 + ==========================================================================
17595 + Description:
17596 + This routine return the first channel number according to the country
17597 + code selection and RF IC selection (signal band or dual band). It is called
17598 + whenever driver need to start a site survey of all supported channels.
17599 + Return:
17600 + ch - the first channel number of current country code setting
17601 +
17602 + IRQL = PASSIVE_LEVEL
17603 +
17604 + ==========================================================================
17605 + */
17606 +UCHAR FirstChannel(
17607 + IN PRTMP_ADAPTER pAd)
17608 +{
17609 + return pAd->ChannelList[0].Channel;
17610 +}
17611 +
17612 +/*
17613 + ==========================================================================
17614 + Description:
17615 + This routine returns the next channel number. This routine is called
17616 + during driver need to start a site survey of all supported channels.
17617 + Return:
17618 + next_channel - the next channel number valid in current country code setting.
17619 + Note:
17620 + return 0 if no more next channel
17621 + ==========================================================================
17622 + */
17623 +UCHAR NextChannel(
17624 + IN PRTMP_ADAPTER pAd,
17625 + IN UCHAR channel)
17626 +{
17627 + int i;
17628 + UCHAR next_channel = 0;
17629 +
17630 + for (i = 0; i < (pAd->ChannelListNum - 1); i++)
17631 + if (channel == pAd->ChannelList[i].Channel)
17632 + {
17633 + next_channel = pAd->ChannelList[i+1].Channel;
17634 + break;
17635 + }
17636 + return next_channel;
17637 +}
17638 +
17639 +/*
17640 + ==========================================================================
17641 + Description:
17642 + This routine is for Cisco Compatible Extensions 2.X
17643 + Spec31. AP Control of Client Transmit Power
17644 + Return:
17645 + None
17646 + Note:
17647 + Required by Aironet dBm(mW)
17648 + 0dBm(1mW), 1dBm(5mW), 13dBm(20mW), 15dBm(30mW),
17649 + 17dBm(50mw), 20dBm(100mW)
17650 +
17651 + We supported
17652 + 3dBm(Lowest), 6dBm(10%), 9dBm(25%), 12dBm(50%),
17653 + 14dBm(75%), 15dBm(100%)
17654 +
17655 + The client station's actual transmit power shall be within +/- 5dB of
17656 + the minimum value or next lower value.
17657 + ==========================================================================
17658 + */
17659 +VOID ChangeToCellPowerLimit(
17660 + IN PRTMP_ADAPTER pAd,
17661 + IN UCHAR AironetCellPowerLimit)
17662 +{
17663 + //valud 0xFF means that hasn't found power limit information
17664 + //from the AP's Beacon/Probe response.
17665 + if (AironetCellPowerLimit == 0xFF)
17666 + return;
17667 +
17668 + if (AironetCellPowerLimit < 6) //Used Lowest Power Percentage.
17669 + pAd->CommonCfg.TxPowerPercentage = 6;
17670 + else if (AironetCellPowerLimit < 9)
17671 + pAd->CommonCfg.TxPowerPercentage = 10;
17672 + else if (AironetCellPowerLimit < 12)
17673 + pAd->CommonCfg.TxPowerPercentage = 25;
17674 + else if (AironetCellPowerLimit < 14)
17675 + pAd->CommonCfg.TxPowerPercentage = 50;
17676 + else if (AironetCellPowerLimit < 15)
17677 + pAd->CommonCfg.TxPowerPercentage = 75;
17678 + else
17679 + pAd->CommonCfg.TxPowerPercentage = 100; //else used maximum
17680 +
17681 + if (pAd->CommonCfg.TxPowerPercentage > pAd->CommonCfg.TxPowerDefault)
17682 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
17683 +
17684 +}
17685 +
17686 +CHAR ConvertToRssi(
17687 + IN PRTMP_ADAPTER pAd,
17688 + IN CHAR Rssi,
17689 + IN UCHAR RssiNumber)
17690 +{
17691 + UCHAR RssiOffset, LNAGain;
17692 +
17693 + // Rssi equals to zero should be an invalid value
17694 + if (Rssi == 0)
17695 + return -99;
17696 +
17697 + LNAGain = GET_LNA_GAIN(pAd);
17698 + if (pAd->LatchRfRegs.Channel > 14)
17699 + {
17700 + if (RssiNumber == 0)
17701 + RssiOffset = pAd->ARssiOffset0;
17702 + else if (RssiNumber == 1)
17703 + RssiOffset = pAd->ARssiOffset1;
17704 + else
17705 + RssiOffset = pAd->ARssiOffset2;
17706 + }
17707 + else
17708 + {
17709 + if (RssiNumber == 0)
17710 + RssiOffset = pAd->BGRssiOffset0;
17711 + else if (RssiNumber == 1)
17712 + RssiOffset = pAd->BGRssiOffset1;
17713 + else
17714 + RssiOffset = pAd->BGRssiOffset2;
17715 + }
17716 +
17717 + return (-12 - RssiOffset - LNAGain - Rssi);
17718 +}
17719 +
17720 +/*
17721 + ==========================================================================
17722 + Description:
17723 + Scan next channel
17724 + ==========================================================================
17725 + */
17726 +VOID ScanNextChannel(
17727 + IN PRTMP_ADAPTER pAd)
17728 +{
17729 + HEADER_802_11 Hdr80211;
17730 + PUCHAR pOutBuffer = NULL;
17731 + NDIS_STATUS NStatus;
17732 + ULONG FrameLen = 0;
17733 + UCHAR SsidLen = 0, ScanType = pAd->MlmeAux.ScanType, BBPValue = 0;
17734 +#ifdef CONFIG_STA_SUPPORT
17735 + USHORT Status;
17736 + PHEADER_802_11 pHdr80211;
17737 +#endif // CONFIG_STA_SUPPORT //
17738 + UINT ScanTimeIn5gChannel = SHORT_CHANNEL_TIME;
17739 +
17740 +#ifdef CONFIG_STA_SUPPORT
17741 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
17742 + {
17743 + if (MONITOR_ON(pAd))
17744 + return;
17745 + }
17746 +#endif // CONFIG_STA_SUPPORT //
17747 +
17748 +#ifdef RALINK_ATE
17749 + // Nothing to do in ATE mode.
17750 + if (ATE_ON(pAd))
17751 + return;
17752 +#endif // RALINK_ATE //
17753 +
17754 + if (pAd->MlmeAux.Channel == 0)
17755 + {
17756 + if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
17757 +#ifdef CONFIG_STA_SUPPORT
17758 + && (INFRA_ON(pAd)
17759 + || (pAd->OpMode == OPMODE_AP))
17760 +#endif // CONFIG_STA_SUPPORT //
17761 + )
17762 + {
17763 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
17764 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
17765 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
17766 + BBPValue &= (~0x18);
17767 + BBPValue |= 0x10;
17768 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
17769 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
17770 + }
17771 + else
17772 + {
17773 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
17774 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
17775 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to channel %d, Total BSS[%02d]\n",pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
17776 + }
17777 +
17778 +#ifdef CONFIG_STA_SUPPORT
17779 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
17780 + {
17781 + //
17782 + // To prevent data lost.
17783 + // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.
17784 + // Now, we need to send an NULL data with turned PSM bit off to AP, when scan progress done
17785 + //
17786 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))
17787 + {
17788 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);
17789 + if (NStatus == NDIS_STATUS_SUCCESS)
17790 + {
17791 + pHdr80211 = (PHEADER_802_11) pOutBuffer;
17792 + MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
17793 + pHdr80211->Duration = 0;
17794 + pHdr80211->FC.Type = BTYPE_DATA;
17795 + pHdr80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
17796 +
17797 + // Send using priority queue
17798 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
17799 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame\n"));
17800 + MlmeFreeMemory(pAd, pOutBuffer);
17801 + RTMPusecDelay(5000);
17802 + }
17803 + }
17804 +
17805 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
17806 + Status = MLME_SUCCESS;
17807 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
17808 + }
17809 +#endif // CONFIG_STA_SUPPORT //
17810 +
17811 +
17812 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
17813 + }
17814 +#ifdef RT2870
17815 +#ifdef CONFIG_STA_SUPPORT
17816 + else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) && (pAd->OpMode == OPMODE_STA))
17817 + {
17818 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
17819 + MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE);
17820 + }
17821 +#endif // CONFIG_STA_SUPPORT //
17822 +#endif // RT2870 //
17823 + else
17824 + {
17825 +#ifdef CONFIG_STA_SUPPORT
17826 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
17827 + {
17828 + // BBP and RF are not accessible in PS mode, we has to wake them up first
17829 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
17830 + AsicForceWakeup(pAd, TRUE);
17831 +
17832 + // leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON
17833 + if (pAd->StaCfg.Psm == PWR_SAVE)
17834 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
17835 + }
17836 +#endif // CONFIG_STA_SUPPORT //
17837 +
17838 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, TRUE);
17839 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
17840 +
17841 +#ifdef CONFIG_STA_SUPPORT
17842 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
17843 + {
17844 + if (pAd->MlmeAux.Channel > 14)
17845 + {
17846 + if ((pAd->CommonCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
17847 + {
17848 + ScanType = SCAN_PASSIVE;
17849 + ScanTimeIn5gChannel = MIN_CHANNEL_TIME;
17850 + }
17851 + }
17852 +
17853 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
17854 + // carrier detection
17855 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
17856 + {
17857 + ScanType = SCAN_PASSIVE;
17858 + ScanTimeIn5gChannel = MIN_CHANNEL_TIME;
17859 + }
17860 +#endif // CARRIER_DETECTION_SUPPORT //
17861 + }
17862 +
17863 +#endif // CONFIG_STA_SUPPORT //
17864 +
17865 + //Global country domain(ch1-11:active scan, ch12-14 passive scan)
17866 + if ((pAd->MlmeAux.Channel <= 14) && (pAd->MlmeAux.Channel >= 12) && ((pAd->CommonCfg.CountryRegion & 0x7f) == REGION_31_BG_BAND))
17867 + {
17868 + ScanType = SCAN_PASSIVE;
17869 + }
17870 +
17871 + // We need to shorten active scan time in order for WZC connect issue
17872 + // Chnage the channel scan time for CISCO stuff based on its IAPP announcement
17873 + if (ScanType == FAST_SCAN_ACTIVE)
17874 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, FAST_ACTIVE_SCAN_TIME);
17875 +#ifdef CONFIG_STA_SUPPORT
17876 + else if (((ScanType == SCAN_CISCO_ACTIVE) ||
17877 + (ScanType == SCAN_CISCO_PASSIVE) ||
17878 + (ScanType == SCAN_CISCO_CHANNEL_LOAD) ||
17879 + (ScanType == SCAN_CISCO_NOISE)) && (pAd->OpMode == OPMODE_STA))
17880 + {
17881 + if (pAd->StaCfg.CCXScanTime < 25)
17882 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime * 2);
17883 + else
17884 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime);
17885 + }
17886 +#endif // CONFIG_STA_SUPPORT //
17887 + else // must be SCAN_PASSIVE or SCAN_ACTIVE
17888 + {
17889 + if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
17890 +#ifdef DOT11_N_SUPPORT
17891 + || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED)
17892 +#endif // DOT11_N_SUPPORT //
17893 + )
17894 + {
17895 + if (pAd->MlmeAux.Channel > 14)
17896 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, ScanTimeIn5gChannel);
17897 + else
17898 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MIN_CHANNEL_TIME);
17899 + }
17900 + else
17901 + RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MAX_CHANNEL_TIME);
17902 + }
17903 +
17904 + if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE) ||
17905 + (ScanType == SCAN_CISCO_ACTIVE))
17906 + {
17907 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
17908 + if (NStatus != NDIS_STATUS_SUCCESS)
17909 + {
17910 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - ScanNextChannel() allocate memory fail\n"));
17911 +#ifdef CONFIG_STA_SUPPORT
17912 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
17913 + {
17914 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
17915 + Status = MLME_FAIL_NO_RESOURCE;
17916 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
17917 + }
17918 +#endif // CONFIG_STA_SUPPORT //
17919 +
17920 + return;
17921 + }
17922 +
17923 + // There is no need to send broadcast probe request if active scan is in effect.
17924 + if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE)
17925 + )
17926 + SsidLen = pAd->MlmeAux.SsidLen;
17927 + else
17928 + SsidLen = 0;
17929 +
17930 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
17931 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
17932 + sizeof(HEADER_802_11), &Hdr80211,
17933 + 1, &SsidIe,
17934 + 1, &SsidLen,
17935 + SsidLen, pAd->MlmeAux.Ssid,
17936 + 1, &SupRateIe,
17937 + 1, &pAd->CommonCfg.SupRateLen,
17938 + pAd->CommonCfg.SupRateLen, pAd->CommonCfg.SupRate,
17939 + END_OF_ARGS);
17940 +
17941 + if (pAd->CommonCfg.ExtRateLen)
17942 + {
17943 + ULONG Tmp;
17944 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
17945 + 1, &ExtRateIe,
17946 + 1, &pAd->CommonCfg.ExtRateLen,
17947 + pAd->CommonCfg.ExtRateLen, pAd->CommonCfg.ExtRate,
17948 + END_OF_ARGS);
17949 + FrameLen += Tmp;
17950 + }
17951 +
17952 +#ifdef DOT11_N_SUPPORT
17953 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
17954 + {
17955 + ULONG Tmp;
17956 + UCHAR HtLen;
17957 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
17958 +#ifdef RT_BIG_ENDIAN
17959 + HT_CAPABILITY_IE HtCapabilityTmp;
17960 +#endif
17961 + if (pAd->bBroadComHT == TRUE)
17962 + {
17963 + HtLen = pAd->MlmeAux.HtCapabilityLen + 4;
17964 +#ifdef RT_BIG_ENDIAN
17965 + NdisMoveMemory(&HtCapabilityTmp, &pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
17966 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
17967 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
17968 +
17969 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
17970 + 1, &WpaIe,
17971 + 1, &HtLen,
17972 + 4, &BROADCOM[0],
17973 + pAd->MlmeAux.HtCapabilityLen, &HtCapabilityTmp,
17974 + END_OF_ARGS);
17975 +#else
17976 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
17977 + 1, &WpaIe,
17978 + 1, &HtLen,
17979 + 4, &BROADCOM[0],
17980 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
17981 + END_OF_ARGS);
17982 +#endif // RT_BIG_ENDIAN //
17983 + }
17984 + else
17985 + {
17986 + HtLen = pAd->MlmeAux.HtCapabilityLen;
17987 +#ifdef RT_BIG_ENDIAN
17988 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, SIZE_HT_CAP_IE);
17989 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
17990 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
17991 +
17992 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
17993 + 1, &HtCapIe,
17994 + 1, &HtLen,
17995 + HtLen, &HtCapabilityTmp,
17996 + END_OF_ARGS);
17997 +#else
17998 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
17999 + 1, &HtCapIe,
18000 + 1, &HtLen,
18001 + HtLen, &pAd->CommonCfg.HtCapability,
18002 + END_OF_ARGS);
18003 +#endif // RT_BIG_ENDIAN //
18004 + }
18005 + FrameLen += Tmp;
18006 +
18007 +#ifdef DOT11N_DRAFT3
18008 + if (pAd->CommonCfg.BACapability.field.b2040CoexistScanSup == 1)
18009 + {
18010 + ULONG Tmp;
18011 + HtLen = 1;
18012 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
18013 + 1, &ExtHtCapIe,
18014 + 1, &HtLen,
18015 + 1, &pAd->CommonCfg.BSSCoexist2040.word,
18016 + END_OF_ARGS);
18017 +
18018 + FrameLen += Tmp;
18019 + }
18020 +#endif // DOT11N_DRAFT3 //
18021 + }
18022 +#endif // DOT11_N_SUPPORT //
18023 +
18024 +
18025 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
18026 + MlmeFreeMemory(pAd, pOutBuffer);
18027 + }
18028 +
18029 + // For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe reponse
18030 +
18031 +#ifdef CONFIG_STA_SUPPORT
18032 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18033 + pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN;
18034 +#endif // CONFIG_STA_SUPPORT //
18035 +
18036 + }
18037 +}
18038 +
18039 +VOID MgtProbReqMacHeaderInit(
18040 + IN PRTMP_ADAPTER pAd,
18041 + IN OUT PHEADER_802_11 pHdr80211,
18042 + IN UCHAR SubType,
18043 + IN UCHAR ToDs,
18044 + IN PUCHAR pDA,
18045 + IN PUCHAR pBssid)
18046 +{
18047 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
18048 +
18049 + pHdr80211->FC.Type = BTYPE_MGMT;
18050 + pHdr80211->FC.SubType = SubType;
18051 + if (SubType == SUBTYPE_ACK)
18052 + pHdr80211->FC.Type = BTYPE_CNTL;
18053 + pHdr80211->FC.ToDs = ToDs;
18054 + COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
18055 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
18056 + COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
18057 +}
18058 +
18059 +
18060 --- /dev/null
18061 +++ b/drivers/staging/rt3070/common/cmm_wpa.c
18062 @@ -0,0 +1,1606 @@
18063 +/*
18064 + *************************************************************************
18065 + * Ralink Tech Inc.
18066 + * 5F., No.36, Taiyuan St., Jhubei City,
18067 + * Hsinchu County 302,
18068 + * Taiwan, R.O.C.
18069 + *
18070 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
18071 + *
18072 + * This program is free software; you can redistribute it and/or modify *
18073 + * it under the terms of the GNU General Public License as published by *
18074 + * the Free Software Foundation; either version 2 of the License, or *
18075 + * (at your option) any later version. *
18076 + * *
18077 + * This program is distributed in the hope that it will be useful, *
18078 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18079 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18080 + * GNU General Public License for more details. *
18081 + * *
18082 + * You should have received a copy of the GNU General Public License *
18083 + * along with this program; if not, write to the *
18084 + * Free Software Foundation, Inc., *
18085 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18086 + * *
18087 + *************************************************************************
18088 +
18089 + Module Name:
18090 + wpa.c
18091 +
18092 + Abstract:
18093 +
18094 + Revision History:
18095 + Who When What
18096 + -------- ---------- ----------------------------------------------
18097 + Jan Lee 03-07-22 Initial
18098 + Paul Lin 03-11-28 Modify for supplicant
18099 +*/
18100 +#include "../rt_config.h"
18101 +// WPA OUI
18102 +UCHAR OUI_WPA_NONE_AKM[4] = {0x00, 0x50, 0xF2, 0x00};
18103 +UCHAR OUI_WPA_VERSION[4] = {0x00, 0x50, 0xF2, 0x01};
18104 +UCHAR OUI_WPA_TKIP[4] = {0x00, 0x50, 0xF2, 0x02};
18105 +UCHAR OUI_WPA_CCMP[4] = {0x00, 0x50, 0xF2, 0x04};
18106 +UCHAR OUI_WPA_8021X_AKM[4] = {0x00, 0x50, 0xF2, 0x01};
18107 +UCHAR OUI_WPA_PSK_AKM[4] = {0x00, 0x50, 0xF2, 0x02};
18108 +// WPA2 OUI
18109 +UCHAR OUI_WPA2_WEP40[4] = {0x00, 0x0F, 0xAC, 0x01};
18110 +UCHAR OUI_WPA2_TKIP[4] = {0x00, 0x0F, 0xAC, 0x02};
18111 +UCHAR OUI_WPA2_CCMP[4] = {0x00, 0x0F, 0xAC, 0x04};
18112 +UCHAR OUI_WPA2_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x01};
18113 +UCHAR OUI_WPA2_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x02};
18114 +// MSA OUI
18115 +UCHAR OUI_MSA_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x05}; // Not yet final - IEEE 802.11s-D1.06
18116 +UCHAR OUI_MSA_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x06}; // Not yet final - IEEE 802.11s-D1.06
18117 +
18118 +/*
18119 + ========================================================================
18120 +
18121 + Routine Description:
18122 + The pseudo-random function(PRF) that hashes various inputs to
18123 + derive a pseudo-random value. To add liveness to the pseudo-random
18124 + value, a nonce should be one of the inputs.
18125 +
18126 + It is used to generate PTK, GTK or some specific random value.
18127 +
18128 + Arguments:
18129 + UCHAR *key, - the key material for HMAC_SHA1 use
18130 + INT key_len - the length of key
18131 + UCHAR *prefix - a prefix label
18132 + INT prefix_len - the length of the label
18133 + UCHAR *data - a specific data with variable length
18134 + INT data_len - the length of a specific data
18135 + INT len - the output lenght
18136 +
18137 + Return Value:
18138 + UCHAR *output - the calculated result
18139 +
18140 + Note:
18141 + 802.11i-2004 Annex H.3
18142 +
18143 + ========================================================================
18144 +*/
18145 +VOID PRF(
18146 + IN UCHAR *key,
18147 + IN INT key_len,
18148 + IN UCHAR *prefix,
18149 + IN INT prefix_len,
18150 + IN UCHAR *data,
18151 + IN INT data_len,
18152 + OUT UCHAR *output,
18153 + IN INT len)
18154 +{
18155 + INT i;
18156 + UCHAR *input;
18157 + INT currentindex = 0;
18158 + INT total_len;
18159 +
18160 + // Allocate memory for input
18161 + os_alloc_mem(NULL, (PUCHAR *)&input, 1024);
18162 +
18163 + if (input == NULL)
18164 + {
18165 + DBGPRINT(RT_DEBUG_ERROR, ("!!!PRF: no memory!!!\n"));
18166 + return;
18167 + }
18168 +
18169 + // Generate concatenation input
18170 + NdisMoveMemory(input, prefix, prefix_len);
18171 +
18172 + // Concatenate a single octet containing 0
18173 + input[prefix_len] = 0;
18174 +
18175 + // Concatenate specific data
18176 + NdisMoveMemory(&input[prefix_len + 1], data, data_len);
18177 + total_len = prefix_len + 1 + data_len;
18178 +
18179 + // Concatenate a single octet containing 0
18180 + // This octet shall be update later
18181 + input[total_len] = 0;
18182 + total_len++;
18183 +
18184 + // Iterate to calculate the result by hmac-sha-1
18185 + // Then concatenate to last result
18186 + for (i = 0; i < (len + 19) / 20; i++)
18187 + {
18188 + HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
18189 + currentindex += 20;
18190 +
18191 + // update the last octet
18192 + input[total_len - 1]++;
18193 + }
18194 + os_free_mem(NULL, input);
18195 +}
18196 +
18197 +/*
18198 + ========================================================================
18199 +
18200 + Routine Description:
18201 + It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK.
18202 + It shall be called by 4-way handshake processing.
18203 +
18204 + Arguments:
18205 + pAd - pointer to our pAdapter context
18206 + PMK - pointer to PMK
18207 + ANonce - pointer to ANonce
18208 + AA - pointer to Authenticator Address
18209 + SNonce - pointer to SNonce
18210 + SA - pointer to Supplicant Address
18211 + len - indicate the length of PTK (octet)
18212 +
18213 + Return Value:
18214 + Output pointer to the PTK
18215 +
18216 + Note:
18217 + Refer to IEEE 802.11i-2004 8.5.1.2
18218 +
18219 + ========================================================================
18220 +*/
18221 +VOID WpaCountPTK(
18222 + IN PRTMP_ADAPTER pAd,
18223 + IN UCHAR *PMK,
18224 + IN UCHAR *ANonce,
18225 + IN UCHAR *AA,
18226 + IN UCHAR *SNonce,
18227 + IN UCHAR *SA,
18228 + OUT UCHAR *output,
18229 + IN UINT len)
18230 +{
18231 + UCHAR concatenation[76];
18232 + UINT CurrPos = 0;
18233 + UCHAR temp[32];
18234 + UCHAR Prefix[] = {'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ',
18235 + 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'};
18236 +
18237 + // initiate the concatenation input
18238 + NdisZeroMemory(temp, sizeof(temp));
18239 + NdisZeroMemory(concatenation, 76);
18240 +
18241 + // Get smaller address
18242 + if (RTMPCompareMemory(SA, AA, 6) == 1)
18243 + NdisMoveMemory(concatenation, AA, 6);
18244 + else
18245 + NdisMoveMemory(concatenation, SA, 6);
18246 + CurrPos += 6;
18247 +
18248 + // Get larger address
18249 + if (RTMPCompareMemory(SA, AA, 6) == 1)
18250 + NdisMoveMemory(&concatenation[CurrPos], SA, 6);
18251 + else
18252 + NdisMoveMemory(&concatenation[CurrPos], AA, 6);
18253 +
18254 + // store the larger mac address for backward compatible of
18255 + // ralink proprietary STA-key issue
18256 + NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN);
18257 + CurrPos += 6;
18258 +
18259 + // Get smaller Nonce
18260 + if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
18261 + NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
18262 + else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
18263 + NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
18264 + else
18265 + NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
18266 + CurrPos += 32;
18267 +
18268 + // Get larger Nonce
18269 + if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
18270 + NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
18271 + else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
18272 + NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
18273 + else
18274 + NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
18275 + CurrPos += 32;
18276 +
18277 + hex_dump("concatenation=", concatenation, 76);
18278 +
18279 + // Use PRF to generate PTK
18280 + PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len);
18281 +
18282 +}
18283 +
18284 +/*
18285 + ========================================================================
18286 +
18287 + Routine Description:
18288 + Generate random number by software.
18289 +
18290 + Arguments:
18291 + pAd - pointer to our pAdapter context
18292 + macAddr - pointer to local MAC address
18293 +
18294 + Return Value:
18295 +
18296 + Note:
18297 + 802.1ii-2004 Annex H.5
18298 +
18299 + ========================================================================
18300 +*/
18301 +VOID GenRandom(
18302 + IN PRTMP_ADAPTER pAd,
18303 + IN UCHAR *macAddr,
18304 + OUT UCHAR *random)
18305 +{
18306 + INT i, curr;
18307 + UCHAR local[80], KeyCounter[32];
18308 + UCHAR result[80];
18309 + ULONG CurrentTime;
18310 + UCHAR prefix[] = {'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r'};
18311 +
18312 + // Zero the related information
18313 + NdisZeroMemory(result, 80);
18314 + NdisZeroMemory(local, 80);
18315 + NdisZeroMemory(KeyCounter, 32);
18316 +
18317 + for (i = 0; i < 32; i++)
18318 + {
18319 + // copy the local MAC address
18320 + COPY_MAC_ADDR(local, macAddr);
18321 + curr = MAC_ADDR_LEN;
18322 +
18323 + // concatenate the current time
18324 + NdisGetSystemUpTime(&CurrentTime);
18325 + NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime));
18326 + curr += sizeof(CurrentTime);
18327 +
18328 + // concatenate the last result
18329 + NdisMoveMemory(&local[curr], result, 32);
18330 + curr += 32;
18331 +
18332 + // concatenate a variable
18333 + NdisMoveMemory(&local[curr], &i, 2);
18334 + curr += 2;
18335 +
18336 + // calculate the result
18337 + PRF(KeyCounter, 32, prefix,12, local, curr, result, 32);
18338 + }
18339 +
18340 + NdisMoveMemory(random, result, 32);
18341 +}
18342 +
18343 +/*
18344 + ========================================================================
18345 +
18346 + Routine Description:
18347 + Build cipher suite in RSN-IE.
18348 + It only shall be called by RTMPMakeRSNIE.
18349 +
18350 + Arguments:
18351 + pAd - pointer to our pAdapter context
18352 + ElementID - indicate the WPA1 or WPA2
18353 + WepStatus - indicate the encryption type
18354 + bMixCipher - a boolean to indicate the pairwise cipher and group
18355 + cipher are the same or not
18356 +
18357 + Return Value:
18358 +
18359 + Note:
18360 +
18361 + ========================================================================
18362 +*/
18363 +static VOID RTMPInsertRsnIeCipher(
18364 + IN PRTMP_ADAPTER pAd,
18365 + IN UCHAR ElementID,
18366 + IN UINT WepStatus,
18367 + IN BOOLEAN bMixCipher,
18368 + IN UCHAR FlexibleCipher,
18369 + OUT PUCHAR pRsnIe,
18370 + OUT UCHAR *rsn_len)
18371 +{
18372 + UCHAR PairwiseCnt;
18373 +
18374 + *rsn_len = 0;
18375 +
18376 + // decide WPA2 or WPA1
18377 + if (ElementID == Wpa2Ie)
18378 + {
18379 + RSNIE2 *pRsnie_cipher = (RSNIE2*)pRsnIe;
18380 +
18381 + // Assign the verson as 1
18382 + pRsnie_cipher->version = 1;
18383 +
18384 + switch (WepStatus)
18385 + {
18386 + // TKIP mode
18387 + case Ndis802_11Encryption2Enabled:
18388 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18389 + pRsnie_cipher->ucount = 1;
18390 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
18391 + *rsn_len = sizeof(RSNIE2);
18392 + break;
18393 +
18394 + // AES mode
18395 + case Ndis802_11Encryption3Enabled:
18396 + if (bMixCipher)
18397 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18398 + else
18399 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_CCMP, 4);
18400 + pRsnie_cipher->ucount = 1;
18401 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
18402 + *rsn_len = sizeof(RSNIE2);
18403 + break;
18404 +
18405 + // TKIP-AES mix mode
18406 + case Ndis802_11Encryption4Enabled:
18407 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
18408 +
18409 + PairwiseCnt = 1;
18410 + // Insert WPA2 TKIP as the first pairwise cipher
18411 + if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher))
18412 + {
18413 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
18414 + // Insert WPA2 AES as the secondary pairwise cipher
18415 + if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher))
18416 + {
18417 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA2_CCMP, 4);
18418 + PairwiseCnt = 2;
18419 + }
18420 + }
18421 + else
18422 + {
18423 + // Insert WPA2 AES as the first pairwise cipher
18424 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
18425 + }
18426 +
18427 + pRsnie_cipher->ucount = PairwiseCnt;
18428 + *rsn_len = sizeof(RSNIE2) + (4 * (PairwiseCnt - 1));
18429 + break;
18430 + }
18431 +
18432 + // swap for big-endian platform
18433 + pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
18434 + pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
18435 + }
18436 + else
18437 + {
18438 + RSNIE *pRsnie_cipher = (RSNIE*)pRsnIe;
18439 +
18440 + // Assign OUI and version
18441 + NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4);
18442 + pRsnie_cipher->version = 1;
18443 +
18444 + switch (WepStatus)
18445 + {
18446 + // TKIP mode
18447 + case Ndis802_11Encryption2Enabled:
18448 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18449 + pRsnie_cipher->ucount = 1;
18450 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
18451 + *rsn_len = sizeof(RSNIE);
18452 + break;
18453 +
18454 + // AES mode
18455 + case Ndis802_11Encryption3Enabled:
18456 + if (bMixCipher)
18457 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18458 + else
18459 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_CCMP, 4);
18460 + pRsnie_cipher->ucount = 1;
18461 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
18462 + *rsn_len = sizeof(RSNIE);
18463 + break;
18464 +
18465 + // TKIP-AES mix mode
18466 + case Ndis802_11Encryption4Enabled:
18467 + NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
18468 +
18469 + PairwiseCnt = 1;
18470 + // Insert WPA TKIP as the first pairwise cipher
18471 + if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher))
18472 + {
18473 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
18474 + // Insert WPA AES as the secondary pairwise cipher
18475 + if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher))
18476 + {
18477 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA_CCMP, 4);
18478 + PairwiseCnt = 2;
18479 + }
18480 + }
18481 + else
18482 + {
18483 + // Insert WPA AES as the first pairwise cipher
18484 + NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
18485 + }
18486 +
18487 + pRsnie_cipher->ucount = PairwiseCnt;
18488 + *rsn_len = sizeof(RSNIE) + (4 * (PairwiseCnt - 1));
18489 + break;
18490 + }
18491 +
18492 + // swap for big-endian platform
18493 + pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
18494 + pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
18495 + }
18496 +
18497 +}
18498 +
18499 +/*
18500 + ========================================================================
18501 +
18502 + Routine Description:
18503 + Build AKM suite in RSN-IE.
18504 + It only shall be called by RTMPMakeRSNIE.
18505 +
18506 + Arguments:
18507 + pAd - pointer to our pAdapter context
18508 + ElementID - indicate the WPA1 or WPA2
18509 + AuthMode - indicate the authentication mode
18510 + apidx - indicate the interface index
18511 +
18512 + Return Value:
18513 +
18514 + Note:
18515 +
18516 + ========================================================================
18517 +*/
18518 +static VOID RTMPInsertRsnIeAKM(
18519 + IN PRTMP_ADAPTER pAd,
18520 + IN UCHAR ElementID,
18521 + IN UINT AuthMode,
18522 + IN UCHAR apidx,
18523 + OUT PUCHAR pRsnIe,
18524 + OUT UCHAR *rsn_len)
18525 +{
18526 + RSNIE_AUTH *pRsnie_auth;
18527 +
18528 + pRsnie_auth = (RSNIE_AUTH*)(pRsnIe + (*rsn_len));
18529 +
18530 + // decide WPA2 or WPA1
18531 + if (ElementID == Wpa2Ie)
18532 + {
18533 + switch (AuthMode)
18534 + {
18535 + case Ndis802_11AuthModeWPA2:
18536 + case Ndis802_11AuthModeWPA1WPA2:
18537 + pRsnie_auth->acount = 1;
18538 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_8021X_AKM, 4);
18539 + break;
18540 +
18541 + case Ndis802_11AuthModeWPA2PSK:
18542 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
18543 + pRsnie_auth->acount = 1;
18544 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_PSK_AKM, 4);
18545 + break;
18546 + }
18547 + }
18548 + else
18549 + {
18550 + switch (AuthMode)
18551 + {
18552 + case Ndis802_11AuthModeWPA:
18553 + case Ndis802_11AuthModeWPA1WPA2:
18554 + pRsnie_auth->acount = 1;
18555 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_8021X_AKM, 4);
18556 + break;
18557 +
18558 + case Ndis802_11AuthModeWPAPSK:
18559 + case Ndis802_11AuthModeWPA1PSKWPA2PSK:
18560 + pRsnie_auth->acount = 1;
18561 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_PSK_AKM, 4);
18562 + break;
18563 +
18564 + case Ndis802_11AuthModeWPANone:
18565 + pRsnie_auth->acount = 1;
18566 + NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_NONE_AKM, 4);
18567 + break;
18568 + }
18569 + }
18570 +
18571 + pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount);
18572 +
18573 + (*rsn_len) += sizeof(RSNIE_AUTH); // update current RSNIE length
18574 +
18575 +}
18576 +
18577 +/*
18578 + ========================================================================
18579 +
18580 + Routine Description:
18581 + Build capability in RSN-IE.
18582 + It only shall be called by RTMPMakeRSNIE.
18583 +
18584 + Arguments:
18585 + pAd - pointer to our pAdapter context
18586 + ElementID - indicate the WPA1 or WPA2
18587 + apidx - indicate the interface index
18588 +
18589 + Return Value:
18590 +
18591 + Note:
18592 +
18593 + ========================================================================
18594 +*/
18595 +static VOID RTMPInsertRsnIeCap(
18596 + IN PRTMP_ADAPTER pAd,
18597 + IN UCHAR ElementID,
18598 + IN UCHAR apidx,
18599 + OUT PUCHAR pRsnIe,
18600 + OUT UCHAR *rsn_len)
18601 +{
18602 + RSN_CAPABILITIES *pRSN_Cap;
18603 +
18604 + // it could be ignored in WPA1 mode
18605 + if (ElementID == WpaIe)
18606 + return;
18607 +
18608 + pRSN_Cap = (RSN_CAPABILITIES*)(pRsnIe + (*rsn_len));
18609 +
18610 +
18611 + pRSN_Cap->word = cpu2le16(pRSN_Cap->word);
18612 +
18613 + (*rsn_len) += sizeof(RSN_CAPABILITIES); // update current RSNIE length
18614 +
18615 +}
18616 +
18617 +
18618 +/*
18619 + ========================================================================
18620 +
18621 + Routine Description:
18622 + Build RSN IE context. It is not included element-ID and length.
18623 +
18624 + Arguments:
18625 + pAd - pointer to our pAdapter context
18626 + AuthMode - indicate the authentication mode
18627 + WepStatus - indicate the encryption type
18628 + apidx - indicate the interface index
18629 +
18630 + Return Value:
18631 +
18632 + Note:
18633 +
18634 + ========================================================================
18635 +*/
18636 +VOID RTMPMakeRSNIE(
18637 + IN PRTMP_ADAPTER pAd,
18638 + IN UINT AuthMode,
18639 + IN UINT WepStatus,
18640 + IN UCHAR apidx)
18641 +{
18642 + PUCHAR pRsnIe = NULL; // primary RSNIE
18643 + UCHAR *rsnielen_cur_p = 0; // the length of the primary RSNIE
18644 + UCHAR *rsnielen_ex_cur_p = 0; // the length of the secondary RSNIE
18645 + UCHAR PrimaryRsnie;
18646 + BOOLEAN bMixCipher = FALSE; // indicate the pairwise and group cipher are different
18647 + UCHAR p_offset;
18648 + WPA_MIX_PAIR_CIPHER FlexibleCipher = MIX_CIPHER_NOTUSE; // it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode
18649 +
18650 + rsnielen_cur_p = NULL;
18651 + rsnielen_ex_cur_p = NULL;
18652 +
18653 + {
18654 +#ifdef CONFIG_STA_SUPPORT
18655 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
18656 + {
18657 +#ifdef WPA_SUPPLICANT_SUPPORT
18658 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
18659 + {
18660 + if (AuthMode < Ndis802_11AuthModeWPA)
18661 + return;
18662 + }
18663 + else
18664 +#endif // WPA_SUPPLICANT_SUPPORT //
18665 + {
18666 + // Support WPAPSK or WPA2PSK in STA-Infra mode
18667 + // Support WPANone in STA-Adhoc mode
18668 + if ((AuthMode != Ndis802_11AuthModeWPAPSK) &&
18669 + (AuthMode != Ndis802_11AuthModeWPA2PSK) &&
18670 + (AuthMode != Ndis802_11AuthModeWPANone)
18671 + )
18672 + return;
18673 + }
18674 +
18675 + DBGPRINT(RT_DEBUG_TRACE,("==> RTMPMakeRSNIE(STA)\n"));
18676 +
18677 + // Zero RSNIE context
18678 + pAd->StaCfg.RSNIE_Len = 0;
18679 + NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE);
18680 +
18681 + // Pointer to RSNIE
18682 + rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len;
18683 + pRsnIe = pAd->StaCfg.RSN_IE;
18684 +
18685 + bMixCipher = pAd->StaCfg.bMixCipher;
18686 + }
18687 +#endif // CONFIG_STA_SUPPORT //
18688 + }
18689 +
18690 + // indicate primary RSNIE as WPA or WPA2
18691 + if ((AuthMode == Ndis802_11AuthModeWPA) ||
18692 + (AuthMode == Ndis802_11AuthModeWPAPSK) ||
18693 + (AuthMode == Ndis802_11AuthModeWPANone) ||
18694 + (AuthMode == Ndis802_11AuthModeWPA1WPA2) ||
18695 + (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK))
18696 + PrimaryRsnie = WpaIe;
18697 + else
18698 + PrimaryRsnie = Wpa2Ie;
18699 +
18700 + {
18701 + // Build the primary RSNIE
18702 + // 1. insert cipher suite
18703 + RTMPInsertRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, FlexibleCipher, pRsnIe, &p_offset);
18704 +
18705 + // 2. insert AKM
18706 + RTMPInsertRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, &p_offset);
18707 +
18708 + // 3. insert capability
18709 + RTMPInsertRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset);
18710 + }
18711 +
18712 + // 4. update the RSNIE length
18713 + *rsnielen_cur_p = p_offset;
18714 +
18715 + hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p));
18716 +
18717 +
18718 +}
18719 +
18720 +/*
18721 + ==========================================================================
18722 + Description:
18723 + Check whether the received frame is EAP frame.
18724 +
18725 + Arguments:
18726 + pAd - pointer to our pAdapter context
18727 + pEntry - pointer to active entry
18728 + pData - the received frame
18729 + DataByteCount - the received frame's length
18730 + FromWhichBSSID - indicate the interface index
18731 +
18732 + Return:
18733 + TRUE - This frame is EAP frame
18734 + FALSE - otherwise
18735 + ==========================================================================
18736 +*/
18737 +BOOLEAN RTMPCheckWPAframe(
18738 + IN PRTMP_ADAPTER pAd,
18739 + IN PMAC_TABLE_ENTRY pEntry,
18740 + IN PUCHAR pData,
18741 + IN ULONG DataByteCount,
18742 + IN UCHAR FromWhichBSSID)
18743 +{
18744 + ULONG Body_len;
18745 + BOOLEAN Cancelled;
18746 +
18747 +
18748 + if(DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H))
18749 + return FALSE;
18750 +
18751 +
18752 + // Skip LLC header
18753 + if (NdisEqualMemory(SNAP_802_1H, pData, 6) ||
18754 + // Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL
18755 + NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6))
18756 + {
18757 + pData += 6;
18758 + }
18759 + // Skip 2-bytes EAPoL type
18760 + if (NdisEqualMemory(EAPOL, pData, 2))
18761 + {
18762 + pData += 2;
18763 + }
18764 + else
18765 + return FALSE;
18766 +
18767 + switch (*(pData+1))
18768 + {
18769 + case EAPPacket:
18770 + Body_len = (*(pData+2)<<8) | (*(pData+3));
18771 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", Body_len));
18772 + break;
18773 + case EAPOLStart:
18774 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Start frame, TYPE = 1 \n"));
18775 + if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
18776 + {
18777 + DBGPRINT(RT_DEBUG_TRACE, ("Cancel the EnqueueEapolStartTimerRunning \n"));
18778 + RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
18779 + pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
18780 + }
18781 + break;
18782 + case EAPOLLogoff:
18783 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLLogoff frame, TYPE = 2 \n"));
18784 + break;
18785 + case EAPOLKey:
18786 + Body_len = (*(pData+2)<<8) | (*(pData+3));
18787 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", Body_len));
18788 + break;
18789 + case EAPOLASFAlert:
18790 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLASFAlert frame, TYPE = 4 \n"));
18791 + break;
18792 + default:
18793 + return FALSE;
18794 +
18795 + }
18796 + return TRUE;
18797 +}
18798 +
18799 +
18800 +/*
18801 + ==========================================================================
18802 + Description:
18803 + ENCRYPT AES GTK before sending in EAPOL frame.
18804 + AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function.
18805 + This function references to RFC 3394 for aes key wrap algorithm.
18806 + Return:
18807 + ==========================================================================
18808 +*/
18809 +VOID AES_GTK_KEY_WRAP(
18810 + IN UCHAR *key,
18811 + IN UCHAR *plaintext,
18812 + IN UCHAR p_len,
18813 + OUT UCHAR *ciphertext)
18814 +{
18815 + UCHAR A[8], BIN[16], BOUT[16];
18816 + UCHAR R[512];
18817 + INT num_blocks = p_len/8; // unit:64bits
18818 + INT i, j;
18819 + aes_context aesctx;
18820 + UCHAR xor;
18821 +
18822 + rtmp_aes_set_key(&aesctx, key, 128);
18823 +
18824 + // Init IA
18825 + for (i = 0; i < 8; i++)
18826 + A[i] = 0xa6;
18827 +
18828 + //Input plaintext
18829 + for (i = 0; i < num_blocks; i++)
18830 + {
18831 + for (j = 0 ; j < 8; j++)
18832 + R[8 * (i + 1) + j] = plaintext[8 * i + j];
18833 + }
18834 +
18835 + // Key Mix
18836 + for (j = 0; j < 6; j++)
18837 + {
18838 + for(i = 1; i <= num_blocks; i++)
18839 + {
18840 + //phase 1
18841 + NdisMoveMemory(BIN, A, 8);
18842 + NdisMoveMemory(&BIN[8], &R[8 * i], 8);
18843 + rtmp_aes_encrypt(&aesctx, BIN, BOUT);
18844 +
18845 + NdisMoveMemory(A, &BOUT[0], 8);
18846 + xor = num_blocks * j + i;
18847 + A[7] = BOUT[7] ^ xor;
18848 + NdisMoveMemory(&R[8 * i], &BOUT[8], 8);
18849 + }
18850 + }
18851 +
18852 + // Output ciphertext
18853 + NdisMoveMemory(ciphertext, A, 8);
18854 +
18855 + for (i = 1; i <= num_blocks; i++)
18856 + {
18857 + for (j = 0 ; j < 8; j++)
18858 + ciphertext[8 * i + j] = R[8 * i + j];
18859 + }
18860 +}
18861 +
18862 +
18863 +/*
18864 + ========================================================================
18865 +
18866 + Routine Description:
18867 + Misc function to decrypt AES body
18868 +
18869 + Arguments:
18870 +
18871 + Return Value:
18872 +
18873 + Note:
18874 + This function references to RFC 3394 for aes key unwrap algorithm.
18875 +
18876 + ========================================================================
18877 +*/
18878 +VOID AES_GTK_KEY_UNWRAP(
18879 + IN UCHAR *key,
18880 + OUT UCHAR *plaintext,
18881 + IN UCHAR c_len,
18882 + IN UCHAR *ciphertext)
18883 +
18884 +{
18885 + UCHAR A[8], BIN[16], BOUT[16];
18886 + UCHAR xor;
18887 + INT i, j;
18888 + aes_context aesctx;
18889 + UCHAR *R;
18890 + INT num_blocks = c_len/8; // unit:64bits
18891 +
18892 +
18893 + os_alloc_mem(NULL, (PUCHAR *)&R, 512);
18894 +
18895 + if (R == NULL)
18896 + {
18897 + DBGPRINT(RT_DEBUG_ERROR, ("!!!AES_GTK_KEY_UNWRAP: no memory!!!\n"));
18898 + return;
18899 + } /* End of if */
18900 +
18901 + // Initialize
18902 + NdisMoveMemory(A, ciphertext, 8);
18903 + //Input plaintext
18904 + for(i = 0; i < (c_len-8); i++)
18905 + {
18906 + R[ i] = ciphertext[i + 8];
18907 + }
18908 +
18909 + rtmp_aes_set_key(&aesctx, key, 128);
18910 +
18911 + for(j = 5; j >= 0; j--)
18912 + {
18913 + for(i = (num_blocks-1); i > 0; i--)
18914 + {
18915 + xor = (num_blocks -1 )* j + i;
18916 + NdisMoveMemory(BIN, A, 8);
18917 + BIN[7] = A[7] ^ xor;
18918 + NdisMoveMemory(&BIN[8], &R[(i-1)*8], 8);
18919 + rtmp_aes_decrypt(&aesctx, BIN, BOUT);
18920 + NdisMoveMemory(A, &BOUT[0], 8);
18921 + NdisMoveMemory(&R[(i-1)*8], &BOUT[8], 8);
18922 + }
18923 + }
18924 +
18925 + // OUTPUT
18926 + for(i = 0; i < c_len; i++)
18927 + {
18928 + plaintext[i] = R[i];
18929 + }
18930 +
18931 +
18932 + os_free_mem(NULL, R);
18933 +}
18934 +
18935 +/*
18936 + ==========================================================================
18937 + Description:
18938 + Report the EAP message type
18939 +
18940 + Arguments:
18941 + msg - EAPOL_PAIR_MSG_1
18942 + EAPOL_PAIR_MSG_2
18943 + EAPOL_PAIR_MSG_3
18944 + EAPOL_PAIR_MSG_4
18945 + EAPOL_GROUP_MSG_1
18946 + EAPOL_GROUP_MSG_2
18947 +
18948 + Return:
18949 + message type string
18950 +
18951 + ==========================================================================
18952 +*/
18953 +CHAR *GetEapolMsgType(CHAR msg)
18954 +{
18955 + if(msg == EAPOL_PAIR_MSG_1)
18956 + return "Pairwise Message 1";
18957 + else if(msg == EAPOL_PAIR_MSG_2)
18958 + return "Pairwise Message 2";
18959 + else if(msg == EAPOL_PAIR_MSG_3)
18960 + return "Pairwise Message 3";
18961 + else if(msg == EAPOL_PAIR_MSG_4)
18962 + return "Pairwise Message 4";
18963 + else if(msg == EAPOL_GROUP_MSG_1)
18964 + return "Group Message 1";
18965 + else if(msg == EAPOL_GROUP_MSG_2)
18966 + return "Group Message 2";
18967 + else
18968 + return "Invalid Message";
18969 +}
18970 +
18971 +
18972 +/*
18973 + ========================================================================
18974 +
18975 + Routine Description:
18976 + Check Sanity RSN IE of EAPoL message
18977 +
18978 + Arguments:
18979 +
18980 + Return Value:
18981 +
18982 +
18983 + ========================================================================
18984 +*/
18985 +BOOLEAN RTMPCheckRSNIE(
18986 + IN PRTMP_ADAPTER pAd,
18987 + IN PUCHAR pData,
18988 + IN UCHAR DataLen,
18989 + IN MAC_TABLE_ENTRY *pEntry,
18990 + OUT UCHAR *Offset)
18991 +{
18992 + PUCHAR pVIE;
18993 + UCHAR len;
18994 + PEID_STRUCT pEid;
18995 + BOOLEAN result = FALSE;
18996 +
18997 + pVIE = pData;
18998 + len = DataLen;
18999 + *Offset = 0;
19000 +
19001 + while (len > sizeof(RSNIE2))
19002 + {
19003 + pEid = (PEID_STRUCT) pVIE;
19004 + // WPA RSN IE
19005 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
19006 + {
19007 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) &&
19008 + (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
19009 + (pEntry->RSNIE_Len == (pEid->Len + 2)))
19010 + {
19011 + result = TRUE;
19012 + }
19013 +
19014 + *Offset += (pEid->Len + 2);
19015 + }
19016 + // WPA2 RSN IE
19017 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
19018 + {
19019 + if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) &&
19020 + (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
19021 + (pEntry->RSNIE_Len == (pEid->Len + 2))/* ToDo-AlbertY for mesh*/)
19022 + {
19023 + result = TRUE;
19024 + }
19025 +
19026 + *Offset += (pEid->Len + 2);
19027 + }
19028 + else
19029 + {
19030 + break;
19031 + }
19032 +
19033 + pVIE += (pEid->Len + 2);
19034 + len -= (pEid->Len + 2);
19035 + }
19036 +
19037 +
19038 + return result;
19039 +
19040 +}
19041 +
19042 +
19043 +/*
19044 + ========================================================================
19045 +
19046 + Routine Description:
19047 + Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
19048 + GTK is encaptulated in KDE format at p.83 802.11i D10
19049 +
19050 + Arguments:
19051 +
19052 + Return Value:
19053 +
19054 + Note:
19055 + 802.11i D10
19056 +
19057 + ========================================================================
19058 +*/
19059 +BOOLEAN RTMPParseEapolKeyData(
19060 + IN PRTMP_ADAPTER pAd,
19061 + IN PUCHAR pKeyData,
19062 + IN UCHAR KeyDataLen,
19063 + IN UCHAR GroupKeyIndex,
19064 + IN UCHAR MsgType,
19065 + IN BOOLEAN bWPA2,
19066 + IN MAC_TABLE_ENTRY *pEntry)
19067 +{
19068 + PKDE_ENCAP pKDE = NULL;
19069 + PUCHAR pMyKeyData = pKeyData;
19070 + UCHAR KeyDataLength = KeyDataLen;
19071 + UCHAR GTKLEN = 0;
19072 + UCHAR DefaultIdx = 0;
19073 + UCHAR skip_offset;
19074 +
19075 + // Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it
19076 + if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3)
19077 + {
19078 + // Check RSN IE whether it is WPA2/WPA2PSK
19079 + if (!RTMPCheckRSNIE(pAd, pKeyData, KeyDataLen, pEntry, &skip_offset))
19080 + {
19081 + // send wireless event - for RSN IE different
19082 + if (pAd->CommonCfg.bWirelessEvent)
19083 + RTMPSendWirelessEvent(pAd, IW_RSNIE_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
19084 +
19085 + DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in msg %d of 4-way handshake!\n", MsgType));
19086 + hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen);
19087 + hex_dump("Desired RSN_IE ", pEntry->RSN_IE, pEntry->RSNIE_Len);
19088 +
19089 + return FALSE;
19090 + }
19091 + else
19092 + {
19093 + if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3)
19094 + {
19095 + // skip RSN IE
19096 + pMyKeyData += skip_offset;
19097 + KeyDataLength -= skip_offset;
19098 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
19099 + }
19100 + else
19101 + return TRUE;
19102 + }
19103 + }
19104 +
19105 + DBGPRINT(RT_DEBUG_TRACE,("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
19106 +
19107 + // Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2
19108 + if (bWPA2 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1))
19109 + {
19110 + if (KeyDataLength >= 8) // KDE format exclude GTK length
19111 + {
19112 + pKDE = (PKDE_ENCAP) pMyKeyData;
19113 +
19114 +
19115 + DefaultIdx = pKDE->GTKEncap.Kid;
19116 +
19117 + // Sanity check - KED length
19118 + if (KeyDataLength < (pKDE->Len + 2))
19119 + {
19120 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
19121 + return FALSE;
19122 + }
19123 +
19124 + // Get GTK length - refer to IEEE 802.11i-2004 p.82
19125 + GTKLEN = pKDE->Len -6;
19126 + if (GTKLEN < LEN_AES_KEY)
19127 + {
19128 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
19129 + return FALSE;
19130 + }
19131 +
19132 + }
19133 + else
19134 + {
19135 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KDE format length is too short \n"));
19136 + return FALSE;
19137 + }
19138 +
19139 + DBGPRINT(RT_DEBUG_TRACE, ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", DefaultIdx, GTKLEN));
19140 + // skip it
19141 + pMyKeyData += 8;
19142 + KeyDataLength -= 8;
19143 +
19144 + }
19145 + else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1)
19146 + {
19147 + DefaultIdx = GroupKeyIndex;
19148 + DBGPRINT(RT_DEBUG_TRACE, ("GTK DefaultKeyID=%d \n", DefaultIdx));
19149 + }
19150 +
19151 + // Sanity check - shared key index must be 1 ~ 3
19152 + if (DefaultIdx < 1 || DefaultIdx > 3)
19153 + {
19154 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index(%d) is invalid in %s %s \n", DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
19155 + return FALSE;
19156 + }
19157 +
19158 +
19159 +#ifdef CONFIG_STA_SUPPORT
19160 + // Todo
19161 +#endif // CONFIG_STA_SUPPORT //
19162 +
19163 + return TRUE;
19164 +
19165 +}
19166 +
19167 +
19168 +/*
19169 + ========================================================================
19170 +
19171 + Routine Description:
19172 + Construct EAPoL message for WPA handshaking
19173 + Its format is below,
19174 +
19175 + +--------------------+
19176 + | Protocol Version | 1 octet
19177 + +--------------------+
19178 + | Protocol Type | 1 octet
19179 + +--------------------+
19180 + | Body Length | 2 octets
19181 + +--------------------+
19182 + | Descriptor Type | 1 octet
19183 + +--------------------+
19184 + | Key Information | 2 octets
19185 + +--------------------+
19186 + | Key Length | 1 octet
19187 + +--------------------+
19188 + | Key Repaly Counter | 8 octets
19189 + +--------------------+
19190 + | Key Nonce | 32 octets
19191 + +--------------------+
19192 + | Key IV | 16 octets
19193 + +--------------------+
19194 + | Key RSC | 8 octets
19195 + +--------------------+
19196 + | Key ID or Reserved | 8 octets
19197 + +--------------------+
19198 + | Key MIC | 16 octets
19199 + +--------------------+
19200 + | Key Data Length | 2 octets
19201 + +--------------------+
19202 + | Key Data | n octets
19203 + +--------------------+
19204 +
19205 +
19206 + Arguments:
19207 + pAd Pointer to our adapter
19208 +
19209 + Return Value:
19210 + None
19211 +
19212 + Note:
19213 +
19214 + ========================================================================
19215 +*/
19216 +VOID ConstructEapolMsg(
19217 + IN PRTMP_ADAPTER pAd,
19218 + IN UCHAR AuthMode,
19219 + IN UCHAR WepStatus,
19220 + IN UCHAR GroupKeyWepStatus,
19221 + IN UCHAR MsgType,
19222 + IN UCHAR DefaultKeyIdx,
19223 + IN UCHAR *ReplayCounter,
19224 + IN UCHAR *KeyNonce,
19225 + IN UCHAR *TxRSC,
19226 + IN UCHAR *PTK,
19227 + IN UCHAR *GTK,
19228 + IN UCHAR *RSNIE,
19229 + IN UCHAR RSNIE_Len,
19230 + OUT PEAPOL_PACKET pMsg)
19231 +{
19232 + BOOLEAN bWPA2 = FALSE;
19233 +
19234 + // Choose WPA2 or not
19235 + if ((AuthMode == Ndis802_11AuthModeWPA2) || (AuthMode == Ndis802_11AuthModeWPA2PSK))
19236 + bWPA2 = TRUE;
19237 +
19238 + // Init Packet and Fill header
19239 + pMsg->ProVer = EAPOL_VER;
19240 + pMsg->ProType = EAPOLKey;
19241 +
19242 + // Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field
19243 + pMsg->Body_Len[1] = LEN_EAPOL_KEY_MSG;
19244 +
19245 + // Fill in EAPoL descriptor
19246 + if (bWPA2)
19247 + pMsg->KeyDesc.Type = WPA2_KEY_DESC;
19248 + else
19249 + pMsg->KeyDesc.Type = WPA1_KEY_DESC;
19250 +
19251 + // Fill in Key information, refer to IEEE Std 802.11i-2004 page 78
19252 + // When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used.
19253 + pMsg->KeyDesc.KeyInfo.KeyDescVer =
19254 + (((WepStatus == Ndis802_11Encryption3Enabled) || (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
19255 +
19256 + // Specify Key Type as Group(0) or Pairwise(1)
19257 + if (MsgType >= EAPOL_GROUP_MSG_1)
19258 + pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY;
19259 + else
19260 + pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
19261 +
19262 + // Specify Key Index, only group_msg1_WPA1
19263 + if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))
19264 + pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx;
19265 +
19266 + if (MsgType == EAPOL_PAIR_MSG_3)
19267 + pMsg->KeyDesc.KeyInfo.Install = 1;
19268 +
19269 + if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))
19270 + pMsg->KeyDesc.KeyInfo.KeyAck = 1;
19271 +
19272 + if (MsgType != EAPOL_PAIR_MSG_1)
19273 + pMsg->KeyDesc.KeyInfo.KeyMic = 1;
19274 +
19275 + if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)))
19276 + {
19277 + pMsg->KeyDesc.KeyInfo.Secure = 1;
19278 + }
19279 +
19280 + if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
19281 + {
19282 + pMsg->KeyDesc.KeyInfo.EKD_DL = 1;
19283 + }
19284 +
19285 + // key Information element has done.
19286 + *(USHORT *)(&pMsg->KeyDesc.KeyInfo) = cpu2le16(*(USHORT *)(&pMsg->KeyDesc.KeyInfo));
19287 +
19288 + // Fill in Key Length
19289 + {
19290 + if (MsgType >= EAPOL_GROUP_MSG_1)
19291 + {
19292 + // the length of group key cipher
19293 + pMsg->KeyDesc.KeyLength[1] = ((GroupKeyWepStatus == Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : LEN_AES_KEY);
19294 + }
19295 + else
19296 + {
19297 + // the length of pairwise key cipher
19298 + pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
19299 + }
19300 + }
19301 +
19302 + // Fill in replay counter
19303 + NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, ReplayCounter, LEN_KEY_DESC_REPLAY);
19304 +
19305 + // Fill Key Nonce field
19306 + // ANonce : pairwise_msg1 & pairwise_msg3
19307 + // SNonce : pairwise_msg2
19308 + // GNonce : group_msg1_wpa1
19309 + if ((MsgType <= EAPOL_PAIR_MSG_3) || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))))
19310 + NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, LEN_KEY_DESC_NONCE);
19311 +
19312 + // Fill key IV - WPA2 as 0, WPA1 as random
19313 + if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
19314 + {
19315 + // Suggest IV be random number plus some number,
19316 + NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], LEN_KEY_DESC_IV);
19317 + pMsg->KeyDesc.KeyIv[15] += 2;
19318 + }
19319 +
19320 + // Fill Key RSC field
19321 + // It contains the RSC for the GTK being installed.
19322 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
19323 + {
19324 + NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6);
19325 + }
19326 +
19327 + // Clear Key MIC field for MIC calculation later
19328 + NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
19329 +
19330 + ConstructEapolKeyData(pAd,
19331 + AuthMode,
19332 + WepStatus,
19333 + GroupKeyWepStatus,
19334 + MsgType,
19335 + DefaultKeyIdx,
19336 + bWPA2,
19337 + PTK,
19338 + GTK,
19339 + RSNIE,
19340 + RSNIE_Len,
19341 + pMsg);
19342 +
19343 + // Calculate MIC and fill in KeyMic Field except Pairwise Msg 1.
19344 + if (MsgType != EAPOL_PAIR_MSG_1)
19345 + {
19346 + CalculateMIC(pAd, WepStatus, PTK, pMsg);
19347 + }
19348 +
19349 + DBGPRINT(RT_DEBUG_TRACE, ("===> ConstructEapolMsg for %s %s\n", ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
19350 + DBGPRINT(RT_DEBUG_TRACE, (" Body length = %d \n", pMsg->Body_Len[1]));
19351 + DBGPRINT(RT_DEBUG_TRACE, (" Key length = %d \n", pMsg->KeyDesc.KeyLength[1]));
19352 +
19353 +
19354 +}
19355 +
19356 +/*
19357 + ========================================================================
19358 +
19359 + Routine Description:
19360 + Construct the Key Data field of EAPoL message
19361 +
19362 + Arguments:
19363 + pAd Pointer to our adapter
19364 + Elem Message body
19365 +
19366 + Return Value:
19367 + None
19368 +
19369 + Note:
19370 +
19371 + ========================================================================
19372 +*/
19373 +VOID ConstructEapolKeyData(
19374 + IN PRTMP_ADAPTER pAd,
19375 + IN UCHAR AuthMode,
19376 + IN UCHAR WepStatus,
19377 + IN UCHAR GroupKeyWepStatus,
19378 + IN UCHAR MsgType,
19379 + IN UCHAR DefaultKeyIdx,
19380 + IN BOOLEAN bWPA2Capable,
19381 + IN UCHAR *PTK,
19382 + IN UCHAR *GTK,
19383 + IN UCHAR *RSNIE,
19384 + IN UCHAR RSNIE_LEN,
19385 + OUT PEAPOL_PACKET pMsg)
19386 +{
19387 + UCHAR *mpool, *Key_Data, *Rc4GTK;
19388 + UCHAR ekey[(LEN_KEY_DESC_IV+LEN_EAP_EK)];
19389 + UCHAR data_offset;
19390 +
19391 +
19392 + if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2)
19393 + return;
19394 +
19395 + // allocate memory pool
19396 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1500);
19397 +
19398 + if (mpool == NULL)
19399 + return;
19400 +
19401 + /* Rc4GTK Len = 512 */
19402 + Rc4GTK = (UCHAR *) ROUND_UP(mpool, 4);
19403 + /* Key_Data Len = 512 */
19404 + Key_Data = (UCHAR *) ROUND_UP(Rc4GTK + 512, 4);
19405 +
19406 + NdisZeroMemory(Key_Data, 512);
19407 + pMsg->KeyDesc.KeyDataLen[1] = 0;
19408 + data_offset = 0;
19409 +
19410 + // Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3
19411 + if (RSNIE_LEN && ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3)))
19412 + {
19413 + if (bWPA2Capable)
19414 + Key_Data[data_offset + 0] = IE_WPA2;
19415 + else
19416 + Key_Data[data_offset + 0] = IE_WPA;
19417 +
19418 + Key_Data[data_offset + 1] = RSNIE_LEN;
19419 + NdisMoveMemory(&Key_Data[data_offset + 2], RSNIE, RSNIE_LEN);
19420 + data_offset += (2 + RSNIE_LEN);
19421 + }
19422 +
19423 + // Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2
19424 + if (bWPA2Capable && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
19425 + {
19426 + // Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h
19427 + Key_Data[data_offset + 0] = 0xDD;
19428 +
19429 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19430 + {
19431 + Key_Data[data_offset + 1] = 0x16;// 4+2+16(OUI+DataType+DataField)
19432 + }
19433 + else
19434 + {
19435 + Key_Data[data_offset + 1] = 0x26;// 4+2+32(OUI+DataType+DataField)
19436 + }
19437 +
19438 + Key_Data[data_offset + 2] = 0x00;
19439 + Key_Data[data_offset + 3] = 0x0F;
19440 + Key_Data[data_offset + 4] = 0xAC;
19441 + Key_Data[data_offset + 5] = 0x01;
19442 +
19443 + // GTK KDE format - 802.11i-2004 Figure-43x
19444 + Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03);
19445 + Key_Data[data_offset + 7] = 0x00; // Reserved Byte
19446 +
19447 + data_offset += 8;
19448 + }
19449 +
19450 +
19451 + // Encapsulate GTK and encrypt the key-data field with KEK.
19452 + // Only for pairwise_msg3_WPA2 and group_msg1
19453 + if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) || (MsgType == EAPOL_GROUP_MSG_1))
19454 + {
19455 + // Fill in GTK
19456 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19457 + {
19458 + NdisMoveMemory(&Key_Data[data_offset], GTK, LEN_AES_KEY);
19459 + data_offset += LEN_AES_KEY;
19460 + }
19461 + else
19462 + {
19463 + NdisMoveMemory(&Key_Data[data_offset], GTK, TKIP_GTK_LENGTH);
19464 + data_offset += TKIP_GTK_LENGTH;
19465 + }
19466 +
19467 + // Still dont know why, but if not append will occur "GTK not include in MSG3"
19468 + // Patch for compatibility between zero config and funk
19469 + if (MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable)
19470 + {
19471 + if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
19472 + {
19473 + Key_Data[data_offset + 0] = 0xDD;
19474 + Key_Data[data_offset + 1] = 0;
19475 + data_offset += 2;
19476 + }
19477 + else
19478 + {
19479 + Key_Data[data_offset + 0] = 0xDD;
19480 + Key_Data[data_offset + 1] = 0;
19481 + Key_Data[data_offset + 2] = 0;
19482 + Key_Data[data_offset + 3] = 0;
19483 + Key_Data[data_offset + 4] = 0;
19484 + Key_Data[data_offset + 5] = 0;
19485 + data_offset += 6;
19486 + }
19487 + }
19488 +
19489 + // Encrypt the data material in key data field
19490 + if (WepStatus == Ndis802_11Encryption3Enabled)
19491 + {
19492 + AES_GTK_KEY_WRAP(&PTK[16], Key_Data, data_offset, Rc4GTK);
19493 + // AES wrap function will grow 8 bytes in length
19494 + data_offset += 8;
19495 + }
19496 + else
19497 + {
19498 + // PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV)
19499 + // put TxTsc in Key RSC field
19500 + pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32.
19501 +
19502 + // ekey is the contanetion of IV-field, and PTK[16]->PTK[31]
19503 + NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, LEN_KEY_DESC_IV);
19504 + NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &PTK[16], LEN_EAP_EK);
19505 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); //INIT SBOX, KEYLEN+3(IV)
19506 + pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, data_offset);
19507 + WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, Key_Data, data_offset);
19508 + }
19509 +
19510 + NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset);
19511 + }
19512 + else
19513 + {
19514 + NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset);
19515 + }
19516 +
19517 + // set key data length field and total length
19518 + pMsg->KeyDesc.KeyDataLen[1] = data_offset;
19519 + pMsg->Body_Len[1] += data_offset;
19520 +
19521 + os_free_mem(pAd, mpool);
19522 +
19523 +}
19524 +
19525 +/*
19526 + ========================================================================
19527 +
19528 + Routine Description:
19529 + Calcaulate MIC. It is used during 4-ways handsharking.
19530 +
19531 + Arguments:
19532 + pAd - pointer to our pAdapter context
19533 + PeerWepStatus - indicate the encryption type
19534 +
19535 + Return Value:
19536 +
19537 + Note:
19538 +
19539 + ========================================================================
19540 +*/
19541 +VOID CalculateMIC(
19542 + IN PRTMP_ADAPTER pAd,
19543 + IN UCHAR PeerWepStatus,
19544 + IN UCHAR *PTK,
19545 + OUT PEAPOL_PACKET pMsg)
19546 +{
19547 + UCHAR *OutBuffer;
19548 + ULONG FrameLen = 0;
19549 + UCHAR mic[LEN_KEY_DESC_MIC];
19550 + UCHAR digest[80];
19551 +
19552 + // allocate memory for MIC calculation
19553 + os_alloc_mem(pAd, (PUCHAR *)&OutBuffer, 512);
19554 +
19555 + if (OutBuffer == NULL)
19556 + {
19557 + DBGPRINT(RT_DEBUG_ERROR, ("!!!CalculateMIC: no memory!!!\n"));
19558 + return;
19559 + }
19560 +
19561 + // make a frame for calculating MIC.
19562 + MakeOutgoingFrame(OutBuffer, &FrameLen,
19563 + pMsg->Body_Len[1] + 4, pMsg,
19564 + END_OF_ARGS);
19565 +
19566 + NdisZeroMemory(mic, sizeof(mic));
19567 +
19568 + // Calculate MIC
19569 + if (PeerWepStatus == Ndis802_11Encryption3Enabled)
19570 + {
19571 + HMAC_SHA1(OutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
19572 + NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
19573 + }
19574 + else
19575 + {
19576 + hmac_md5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic);
19577 + }
19578 +
19579 + // store the calculated MIC
19580 + NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC);
19581 +
19582 + os_free_mem(pAd, OutBuffer);
19583 +}
19584 +
19585 +/*
19586 + ========================================================================
19587 +
19588 + Routine Description:
19589 + Some received frames can't decrypt by Asic, so decrypt them by software.
19590 +
19591 + Arguments:
19592 + pAd - pointer to our pAdapter context
19593 + PeerWepStatus - indicate the encryption type
19594 +
19595 + Return Value:
19596 + NDIS_STATUS_SUCCESS - decryption successful
19597 + NDIS_STATUS_FAILURE - decryption failure
19598 +
19599 + ========================================================================
19600 +*/
19601 +NDIS_STATUS RTMPSoftDecryptBroadCastData(
19602 + IN PRTMP_ADAPTER pAd,
19603 + IN RX_BLK *pRxBlk,
19604 + IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
19605 + IN PCIPHER_KEY pShard_key)
19606 +{
19607 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
19608 +
19609 +
19610 +
19611 + // handle WEP decryption
19612 + if (GroupCipher == Ndis802_11Encryption1Enabled)
19613 + {
19614 + if (RTMPSoftDecryptWEP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, pShard_key))
19615 + {
19616 +
19617 + //Minus IV[4] & ICV[4]
19618 + pRxWI->MPDUtotalByteCount -= 8;
19619 + }
19620 + else
19621 + {
19622 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : Software decrypt WEP data fails.\n"));
19623 + // give up this frame
19624 + return NDIS_STATUS_FAILURE;
19625 + }
19626 + }
19627 + // handle TKIP decryption
19628 + else if (GroupCipher == Ndis802_11Encryption2Enabled)
19629 + {
19630 + if (RTMPSoftDecryptTKIP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, pShard_key))
19631 + {
19632 +
19633 + //Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV
19634 + pRxWI->MPDUtotalByteCount -= 20;
19635 + }
19636 + else
19637 + {
19638 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptTKIP Failed\n"));
19639 + // give up this frame
19640 + return NDIS_STATUS_FAILURE;
19641 + }
19642 + }
19643 + // handle AES decryption
19644 + else if (GroupCipher == Ndis802_11Encryption3Enabled)
19645 + {
19646 + if (RTMPSoftDecryptAES(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount , pShard_key))
19647 + {
19648 +
19649 + //8 bytes MIC, 8 bytes IV/EIV (CCMP Header)
19650 + pRxWI->MPDUtotalByteCount -= 16;
19651 + }
19652 + else
19653 + {
19654 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptAES Failed\n"));
19655 + // give up this frame
19656 + return NDIS_STATUS_FAILURE;
19657 + }
19658 + }
19659 + else
19660 + {
19661 + // give up this frame
19662 + return NDIS_STATUS_FAILURE;
19663 + }
19664 +
19665 + return NDIS_STATUS_SUCCESS;
19666 +
19667 +}
19668 +
19669 --- /dev/null
19670 +++ b/drivers/staging/rt3070/common/dfs.c
19671 @@ -0,0 +1,441 @@
19672 +/*
19673 + *************************************************************************
19674 + * Ralink Tech Inc.
19675 + * 5F., No.36, Taiyuan St., Jhubei City,
19676 + * Hsinchu County 302,
19677 + * Taiwan, R.O.C.
19678 + *
19679 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
19680 + *
19681 + * This program is free software; you can redistribute it and/or modify *
19682 + * it under the terms of the GNU General Public License as published by *
19683 + * the Free Software Foundation; either version 2 of the License, or *
19684 + * (at your option) any later version. *
19685 + * *
19686 + * This program is distributed in the hope that it will be useful, *
19687 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19688 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19689 + * GNU General Public License for more details. *
19690 + * *
19691 + * You should have received a copy of the GNU General Public License *
19692 + * along with this program; if not, write to the *
19693 + * Free Software Foundation, Inc., *
19694 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19695 + * *
19696 + *************************************************************************
19697 +
19698 + Module Name:
19699 + ap_dfs.c
19700 +
19701 + Abstract:
19702 + Support DFS function.
19703 +
19704 + Revision History:
19705 + Who When What
19706 + -------- ---------- ----------------------------------------------
19707 + Fonchi 03-12-2007 created
19708 +*/
19709 +
19710 +#include "../rt_config.h"
19711 +
19712 +typedef struct _RADAR_DURATION_TABLE
19713 +{
19714 + ULONG RDDurRegion;
19715 + ULONG RadarSignalDuration;
19716 + ULONG Tolerance;
19717 +} RADAR_DURATION_TABLE, *PRADAR_DURATION_TABLE;
19718 +
19719 +
19720 +static UCHAR RdIdleTimeTable[MAX_RD_REGION][4] =
19721 +{
19722 + {9, 250, 250, 250}, // CE
19723 + {4, 250, 250, 250}, // FCC
19724 + {4, 250, 250, 250}, // JAP
19725 + {15, 250, 250, 250}, // JAP_W53
19726 + {4, 250, 250, 250} // JAP_W56
19727 +};
19728 +
19729 +/*
19730 + ========================================================================
19731 +
19732 + Routine Description:
19733 + Bbp Radar detection routine
19734 +
19735 + Arguments:
19736 + pAd Pointer to our adapter
19737 +
19738 + Return Value:
19739 +
19740 + ========================================================================
19741 +*/
19742 +VOID BbpRadarDetectionStart(
19743 + IN PRTMP_ADAPTER pAd)
19744 +{
19745 + UINT8 RadarPeriod;
19746 +
19747 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 114, 0x02);
19748 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 121, 0x20);
19749 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 122, 0x00);
19750 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 123, 0x08/*0x80*/);
19751 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 124, 0x28);
19752 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 125, 0xff);
19753 +
19754 + RadarPeriod = ((UINT)RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + (UINT)pAd->CommonCfg.RadarDetect.DfsSessionTime) < 250 ?
19755 + (RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + pAd->CommonCfg.RadarDetect.DfsSessionTime) : 250;
19756 +
19757 + RTMP_IO_WRITE8(pAd, 0x7020, 0x1d);
19758 + RTMP_IO_WRITE8(pAd, 0x7021, 0x40);
19759 +
19760 + RadarDetectionStart(pAd, 0, RadarPeriod);
19761 + return;
19762 +}
19763 +
19764 +/*
19765 + ========================================================================
19766 +
19767 + Routine Description:
19768 + Bbp Radar detection routine
19769 +
19770 + Arguments:
19771 + pAd Pointer to our adapter
19772 +
19773 + Return Value:
19774 +
19775 + ========================================================================
19776 +*/
19777 +VOID BbpRadarDetectionStop(
19778 + IN PRTMP_ADAPTER pAd)
19779 +{
19780 + RTMP_IO_WRITE8(pAd, 0x7020, 0x1d);
19781 + RTMP_IO_WRITE8(pAd, 0x7021, 0x60);
19782 +
19783 + RadarDetectionStop(pAd);
19784 + return;
19785 +}
19786 +
19787 +/*
19788 + ========================================================================
19789 +
19790 + Routine Description:
19791 + Radar detection routine
19792 +
19793 + Arguments:
19794 + pAd Pointer to our adapter
19795 +
19796 + Return Value:
19797 +
19798 + ========================================================================
19799 +*/
19800 +VOID RadarDetectionStart(
19801 + IN PRTMP_ADAPTER pAd,
19802 + IN BOOLEAN CTSProtect,
19803 + IN UINT8 CTSPeriod)
19804 +{
19805 + UINT8 DfsActiveTime = (pAd->CommonCfg.RadarDetect.DfsSessionTime & 0x1f);
19806 + UINT8 CtsProtect = (CTSProtect == 1) ? 0x02 : 0x01; // CTS protect.
19807 +
19808 + if (CTSProtect != 0)
19809 + {
19810 + switch(pAd->CommonCfg.RadarDetect.RDDurRegion)
19811 + {
19812 + case FCC:
19813 + case JAP_W56:
19814 + CtsProtect = 0x03;
19815 + break;
19816 +
19817 + case CE:
19818 + case JAP_W53:
19819 + default:
19820 + CtsProtect = 0x02;
19821 + break;
19822 + }
19823 + }
19824 + else
19825 + CtsProtect = 0x01;
19826 +
19827 +
19828 + // send start-RD with CTS protection command to MCU
19829 + // highbyte [7] reserve
19830 + // highbyte [6:5] 0x: stop Carrier/Radar detection
19831 + // highbyte [10]: Start Carrier/Radar detection without CTS protection, 11: Start Carrier/Radar detection with CTS protection
19832 + // highbyte [4:0] Radar/carrier detection duration. In 1ms.
19833 +
19834 + // lowbyte [7:0] Radar/carrier detection period, in 1ms.
19835 + AsicSendCommandToMcu(pAd, 0x60, 0xff, CTSPeriod, DfsActiveTime | (CtsProtect << 5));
19836 + //AsicSendCommandToMcu(pAd, 0x63, 0xff, 10, 0);
19837 +
19838 + return;
19839 +}
19840 +
19841 +/*
19842 + ========================================================================
19843 +
19844 + Routine Description:
19845 + Radar detection routine
19846 +
19847 + Arguments:
19848 + pAd Pointer to our adapter
19849 +
19850 + Return Value:
19851 + TRUE Found radar signal
19852 + FALSE Not found radar signal
19853 +
19854 + ========================================================================
19855 +*/
19856 +VOID RadarDetectionStop(
19857 + IN PRTMP_ADAPTER pAd)
19858 +{
19859 + DBGPRINT(RT_DEBUG_TRACE,("RadarDetectionStop.\n"));
19860 + AsicSendCommandToMcu(pAd, 0x60, 0xff, 0x00, 0x00); // send start-RD with CTS protection command to MCU
19861 +
19862 + return;
19863 +}
19864 +
19865 +/*
19866 + ========================================================================
19867 +
19868 + Routine Description:
19869 + Radar channel check routine
19870 +
19871 + Arguments:
19872 + pAd Pointer to our adapter
19873 +
19874 + Return Value:
19875 + TRUE need to do radar detect
19876 + FALSE need not to do radar detect
19877 +
19878 + ========================================================================
19879 +*/
19880 +BOOLEAN RadarChannelCheck(
19881 + IN PRTMP_ADAPTER pAd,
19882 + IN UCHAR Ch)
19883 +{
19884 +#if 1
19885 + INT i;
19886 + BOOLEAN result = FALSE;
19887 +
19888 + for (i=0; i<pAd->ChannelListNum; i++)
19889 + {
19890 + if (Ch == pAd->ChannelList[i].Channel)
19891 + {
19892 + result = pAd->ChannelList[i].DfsReq;
19893 + break;
19894 + }
19895 + }
19896 +
19897 + return result;
19898 +#else
19899 + INT i;
19900 + UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
19901 +
19902 + for (i=0; i<15; i++)
19903 + {
19904 + if (Ch == Channel[i])
19905 + {
19906 + break;
19907 + }
19908 + }
19909 +
19910 + if (i != 15)
19911 + return TRUE;
19912 + else
19913 + return FALSE;
19914 +#endif
19915 +}
19916 +
19917 +ULONG JapRadarType(
19918 + IN PRTMP_ADAPTER pAd)
19919 +{
19920 + ULONG i;
19921 + const UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
19922 +
19923 + if (pAd->CommonCfg.RadarDetect.RDDurRegion != JAP)
19924 + {
19925 + return pAd->CommonCfg.RadarDetect.RDDurRegion;
19926 + }
19927 +
19928 + for (i=0; i<15; i++)
19929 + {
19930 + if (pAd->CommonCfg.Channel == Channel[i])
19931 + {
19932 + break;
19933 + }
19934 + }
19935 +
19936 + if (i < 4)
19937 + return JAP_W53;
19938 + else if (i < 15)
19939 + return JAP_W56;
19940 + else
19941 + return JAP; // W52
19942 +
19943 +}
19944 +
19945 +ULONG RTMPBbpReadRadarDuration(
19946 + IN PRTMP_ADAPTER pAd)
19947 +{
19948 + UINT8 byteValue = 0;
19949 + ULONG result;
19950 +
19951 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R115, &byteValue);
19952 +
19953 + result = 0;
19954 + switch (byteValue)
19955 + {
19956 + case 1: // radar signal detected by pulse mode.
19957 + case 2: // radar signal detected by width mode.
19958 + result = RTMPReadRadarDuration(pAd);
19959 + break;
19960 +
19961 + case 0: // No radar signal.
19962 + default:
19963 +
19964 + result = 0;
19965 + break;
19966 + }
19967 +
19968 + return result;
19969 +}
19970 +
19971 +ULONG RTMPReadRadarDuration(
19972 + IN PRTMP_ADAPTER pAd)
19973 +{
19974 + ULONG result = 0;
19975 +
19976 +#ifdef DFS_SUPPORT
19977 + UINT8 duration1 = 0, duration2 = 0, duration3 = 0;
19978 +
19979 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R116, &duration1);
19980 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R117, &duration2);
19981 + BBP_IO_READ8_BY_REG_ID(pAd, BBP_R118, &duration3);
19982 + result = (duration1 << 16) + (duration2 << 8) + duration3;
19983 +#endif // DFS_SUPPORT //
19984 +
19985 + return result;
19986 +
19987 +}
19988 +
19989 +VOID RTMPCleanRadarDuration(
19990 + IN PRTMP_ADAPTER pAd)
19991 +{
19992 + return;
19993 +}
19994 +
19995 +/*
19996 + ========================================================================
19997 + Routine Description:
19998 + Radar wave detection. The API should be invoke each second.
19999 +
20000 + Arguments:
20001 + pAd - Adapter pointer
20002 +
20003 + Return Value:
20004 + None
20005 +
20006 + ========================================================================
20007 +*/
20008 +VOID ApRadarDetectPeriodic(
20009 + IN PRTMP_ADAPTER pAd)
20010 +{
20011 + INT i;
20012 +
20013 + pAd->CommonCfg.RadarDetect.InServiceMonitorCount++;
20014 +
20015 + for (i=0; i<pAd->ChannelListNum; i++)
20016 + {
20017 + if (pAd->ChannelList[i].RemainingTimeForUse > 0)
20018 + {
20019 + pAd->ChannelList[i].RemainingTimeForUse --;
20020 + if ((pAd->Mlme.PeriodicRound%5) == 0)
20021 + {
20022 + DBGPRINT(RT_DEBUG_TRACE, ("RadarDetectPeriodic - ch=%d, RemainingTimeForUse=%d\n", pAd->ChannelList[i].Channel, pAd->ChannelList[i].RemainingTimeForUse));
20023 + }
20024 + }
20025 + }
20026 +
20027 + //radar detect
20028 + if ((pAd->CommonCfg.Channel > 14)
20029 + && (pAd->CommonCfg.bIEEE80211H == 1)
20030 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
20031 + {
20032 + RadarDetectPeriodic(pAd);
20033 + }
20034 +
20035 + return;
20036 +}
20037 +
20038 +// Periodic Radar detection, switch channel will occur in RTMPHandleTBTTInterrupt()
20039 +// Before switch channel, driver needs doing channel switch announcement.
20040 +VOID RadarDetectPeriodic(
20041 + IN PRTMP_ADAPTER pAd)
20042 +{
20043 + // need to check channel availability, after switch channel
20044 + if (pAd->CommonCfg.RadarDetect.RDMode != RD_SILENCE_MODE)
20045 + return;
20046 +
20047 + // channel availability check time is 60sec, use 65 for assurance
20048 + if (pAd->CommonCfg.RadarDetect.RDCount++ > pAd->CommonCfg.RadarDetect.ChMovingTime)
20049 + {
20050 + DBGPRINT(RT_DEBUG_TRACE, ("Not found radar signal, start send beacon and radar detection in service monitor\n\n"));
20051 + BbpRadarDetectionStop(pAd);
20052 + AsicEnableBssSync(pAd);
20053 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
20054 +
20055 +
20056 + return;
20057 + }
20058 +
20059 + return;
20060 +}
20061 +
20062 +
20063 +/*
20064 + ==========================================================================
20065 + Description:
20066 + change channel moving time for DFS testing.
20067 +
20068 + Arguments:
20069 + pAdapter Pointer to our adapter
20070 + wrq Pointer to the ioctl argument
20071 +
20072 + Return Value:
20073 + None
20074 +
20075 + Note:
20076 + Usage:
20077 + 1.) iwpriv ra0 set ChMovTime=[value]
20078 + ==========================================================================
20079 +*/
20080 +INT Set_ChMovingTime_Proc(
20081 + IN PRTMP_ADAPTER pAd,
20082 + IN PUCHAR arg)
20083 +{
20084 + UINT8 Value;
20085 +
20086 + Value = simple_strtol(arg, 0, 10);
20087 +
20088 + pAd->CommonCfg.RadarDetect.ChMovingTime = Value;
20089 +
20090 + DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __FUNCTION__,
20091 + pAd->CommonCfg.RadarDetect.ChMovingTime));
20092 +
20093 + return TRUE;
20094 +}
20095 +
20096 +INT Set_LongPulseRadarTh_Proc(
20097 + IN PRTMP_ADAPTER pAd,
20098 + IN PUCHAR arg)
20099 +{
20100 + UINT8 Value;
20101 +
20102 + Value = simple_strtol(arg, 0, 10) > 10 ? 10 : simple_strtol(arg, 0, 10);
20103 +
20104 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh = Value;
20105 +
20106 + DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __FUNCTION__,
20107 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh));
20108 +
20109 + return TRUE;
20110 +}
20111 +
20112 +
20113 --- /dev/null
20114 +++ b/drivers/staging/rt3070/common/eeprom.c
20115 @@ -0,0 +1,1498 @@
20116 +/*
20117 + *************************************************************************
20118 + * Ralink Tech Inc.
20119 + * 5F., No.36, Taiyuan St., Jhubei City,
20120 + * Hsinchu County 302,
20121 + * Taiwan, R.O.C.
20122 + *
20123 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
20124 + *
20125 + * This program is free software; you can redistribute it and/or modify *
20126 + * it under the terms of the GNU General Public License as published by *
20127 + * the Free Software Foundation; either version 2 of the License, or *
20128 + * (at your option) any later version. *
20129 + * *
20130 + * This program is distributed in the hope that it will be useful, *
20131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20133 + * GNU General Public License for more details. *
20134 + * *
20135 + * You should have received a copy of the GNU General Public License *
20136 + * along with this program; if not, write to the *
20137 + * Free Software Foundation, Inc., *
20138 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20139 + * *
20140 + *************************************************************************
20141 +
20142 + Module Name:
20143 + eeprom.c
20144 +
20145 + Abstract:
20146 +
20147 + Revision History:
20148 + Who When What
20149 + -------- ---------- ----------------------------------------------
20150 + Name Date Modification logs
20151 +*/
20152 +#include "../rt_config.h"
20153 +
20154 +// IRQL = PASSIVE_LEVEL
20155 +VOID RaiseClock(
20156 + IN PRTMP_ADAPTER pAd,
20157 + IN UINT32 *x)
20158 +{
20159 + *x = *x | EESK;
20160 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
20161 + RTMPusecDelay(1); // Max frequency = 1MHz in Spec. definition
20162 +}
20163 +
20164 +// IRQL = PASSIVE_LEVEL
20165 +VOID LowerClock(
20166 + IN PRTMP_ADAPTER pAd,
20167 + IN UINT32 *x)
20168 +{
20169 + *x = *x & ~EESK;
20170 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
20171 + RTMPusecDelay(1);
20172 +}
20173 +
20174 +// IRQL = PASSIVE_LEVEL
20175 +USHORT ShiftInBits(
20176 + IN PRTMP_ADAPTER pAd)
20177 +{
20178 + UINT32 x,i;
20179 + USHORT data=0;
20180 +
20181 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20182 +
20183 + x &= ~( EEDO | EEDI);
20184 +
20185 + for(i=0; i<16; i++)
20186 + {
20187 + data = data << 1;
20188 + RaiseClock(pAd, &x);
20189 +
20190 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20191 + LowerClock(pAd, &x); //prevent read failed
20192 +
20193 + x &= ~(EEDI);
20194 + if(x & EEDO)
20195 + data |= 1;
20196 + }
20197 +
20198 + return data;
20199 +}
20200 +
20201 +// IRQL = PASSIVE_LEVEL
20202 +VOID ShiftOutBits(
20203 + IN PRTMP_ADAPTER pAd,
20204 + IN USHORT data,
20205 + IN USHORT count)
20206 +{
20207 + UINT32 x,mask;
20208 +
20209 + mask = 0x01 << (count - 1);
20210 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20211 +
20212 + x &= ~(EEDO | EEDI);
20213 +
20214 + do
20215 + {
20216 + x &= ~EEDI;
20217 + if(data & mask) x |= EEDI;
20218 +
20219 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20220 +
20221 + RaiseClock(pAd, &x);
20222 + LowerClock(pAd, &x);
20223 +
20224 + mask = mask >> 1;
20225 + } while(mask);
20226 +
20227 + x &= ~EEDI;
20228 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20229 +}
20230 +
20231 +// IRQL = PASSIVE_LEVEL
20232 +VOID EEpromCleanup(
20233 + IN PRTMP_ADAPTER pAd)
20234 +{
20235 + UINT32 x;
20236 +
20237 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20238 +
20239 + x &= ~(EECS | EEDI);
20240 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20241 +
20242 + RaiseClock(pAd, &x);
20243 + LowerClock(pAd, &x);
20244 +}
20245 +
20246 +VOID EWEN(
20247 + IN PRTMP_ADAPTER pAd)
20248 +{
20249 + UINT32 x;
20250 +
20251 + // reset bits and set EECS
20252 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20253 + x &= ~(EEDI | EEDO | EESK);
20254 + x |= EECS;
20255 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20256 +
20257 + // kick a pulse
20258 + RaiseClock(pAd, &x);
20259 + LowerClock(pAd, &x);
20260 +
20261 + // output the read_opcode and six pulse in that order
20262 + ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
20263 + ShiftOutBits(pAd, 0, 6);
20264 +
20265 + EEpromCleanup(pAd);
20266 +}
20267 +
20268 +VOID EWDS(
20269 + IN PRTMP_ADAPTER pAd)
20270 +{
20271 + UINT32 x;
20272 +
20273 + // reset bits and set EECS
20274 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20275 + x &= ~(EEDI | EEDO | EESK);
20276 + x |= EECS;
20277 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20278 +
20279 + // kick a pulse
20280 + RaiseClock(pAd, &x);
20281 + LowerClock(pAd, &x);
20282 +
20283 + // output the read_opcode and six pulse in that order
20284 + ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
20285 + ShiftOutBits(pAd, 0, 6);
20286 +
20287 + EEpromCleanup(pAd);
20288 +}
20289 +
20290 +// IRQL = PASSIVE_LEVEL
20291 +USHORT RTMP_EEPROM_READ16(
20292 + IN PRTMP_ADAPTER pAd,
20293 + IN USHORT Offset)
20294 +{
20295 + UINT32 x;
20296 + USHORT data;
20297 +
20298 + if (pAd->NicConfig2.field.AntDiversity)
20299 + {
20300 + pAd->EepromAccess = TRUE;
20301 + }
20302 +//2008/09/11:KH add to support efuse<--
20303 +//2008/09/11:KH add to support efuse-->
20304 +{
20305 + Offset /= 2;
20306 + // reset bits and set EECS
20307 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20308 + x &= ~(EEDI | EEDO | EESK);
20309 + x |= EECS;
20310 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20311 +
20312 + // patch can not access e-Fuse issue
20313 + if (!IS_RT3090(pAd))
20314 + {
20315 + // kick a pulse
20316 + RaiseClock(pAd, &x);
20317 + LowerClock(pAd, &x);
20318 + }
20319 +
20320 + // output the read_opcode and register number in that order
20321 + ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
20322 + ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
20323 +
20324 + // Now read the data (16 bits) in from the selected EEPROM word
20325 + data = ShiftInBits(pAd);
20326 +
20327 + EEpromCleanup(pAd);
20328 +
20329 + // Antenna and EEPROM access are both using EESK pin,
20330 + // Therefor we should avoid accessing EESK at the same time
20331 + // Then restore antenna after EEPROM access
20332 + if ((pAd->NicConfig2.field.AntDiversity) || (pAd->RfIcType == RFIC_3020))
20333 + {
20334 + pAd->EepromAccess = FALSE;
20335 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
20336 + }
20337 +}
20338 + return data;
20339 +} //ReadEEprom
20340 +
20341 +VOID RTMP_EEPROM_WRITE16(
20342 + IN PRTMP_ADAPTER pAd,
20343 + IN USHORT Offset,
20344 + IN USHORT Data)
20345 +{
20346 + UINT32 x;
20347 +
20348 + if (pAd->NicConfig2.field.AntDiversity)
20349 + {
20350 + pAd->EepromAccess = TRUE;
20351 + }
20352 + //2008/09/11:KH add to support efuse<--
20353 +//2008/09/11:KH add to support efuse-->
20354 + {
20355 + Offset /= 2;
20356 +
20357 + EWEN(pAd);
20358 +
20359 + // reset bits and set EECS
20360 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20361 + x &= ~(EEDI | EEDO | EESK);
20362 + x |= EECS;
20363 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
20364 +
20365 + // patch can not access e-Fuse issue
20366 + if (!IS_RT3090(pAd))
20367 + {
20368 + // kick a pulse
20369 + RaiseClock(pAd, &x);
20370 + LowerClock(pAd, &x);
20371 + }
20372 +
20373 + // output the read_opcode ,register number and data in that order
20374 + ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3);
20375 + ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
20376 + ShiftOutBits(pAd, Data, 16); // 16-bit access
20377 +
20378 + // read DO status
20379 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
20380 +
20381 + EEpromCleanup(pAd);
20382 +
20383 + RTMPusecDelay(10000); //delay for twp(MAX)=10ms
20384 +
20385 + EWDS(pAd);
20386 +
20387 + EEpromCleanup(pAd);
20388 +
20389 + // Antenna and EEPROM access are both using EESK pin,
20390 + // Therefor we should avoid accessing EESK at the same time
20391 + // Then restore antenna after EEPROM access
20392 + if ((pAd->NicConfig2.field.AntDiversity) || (pAd->RfIcType == RFIC_3020))
20393 + {
20394 + pAd->EepromAccess = FALSE;
20395 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
20396 + }
20397 +}
20398 +}
20399 +
20400 +//2008/09/11:KH add to support efuse<--
20401 +#ifdef RT30xx
20402 +/*
20403 + ========================================================================
20404 +
20405 + Routine Description:
20406 +
20407 + Arguments:
20408 +
20409 + Return Value:
20410 +
20411 + IRQL =
20412 +
20413 + Note:
20414 +
20415 + ========================================================================
20416 +*/
20417 +UCHAR eFuseReadRegisters(
20418 + IN PRTMP_ADAPTER pAd,
20419 + IN USHORT Offset,
20420 + IN USHORT Length,
20421 + OUT USHORT* pData)
20422 +{
20423 + EFUSE_CTRL_STRUC eFuseCtrlStruc;
20424 + int i;
20425 + USHORT efuseDataOffset;
20426 + UINT32 data;
20427 +
20428 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20429 +
20430 + //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
20431 + //Use the eeprom logical address and covert to address to block number
20432 + eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
20433 +
20434 + //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 0.
20435 + eFuseCtrlStruc.field.EFSROM_MODE = 0;
20436 +
20437 + //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
20438 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
20439 +
20440 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
20441 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
20442 +
20443 + //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
20444 + i = 0;
20445 + while(i < 100)
20446 + {
20447 + //rtmp.HwMemoryReadDword(EFUSE_CTRL, (DWORD *) &eFuseCtrlStruc, 4);
20448 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20449 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
20450 + {
20451 + break;
20452 + }
20453 + RTMPusecDelay(2);
20454 + i++;
20455 + }
20456 +
20457 + //if EFSROM_AOUT is not found in physical address, write 0xffff
20458 + if (eFuseCtrlStruc.field.EFSROM_AOUT == 0x3f)
20459 + {
20460 + for(i=0; i<Length/2; i++)
20461 + *(pData+2*i) = 0xffff;
20462 + }
20463 + else
20464 + {
20465 + //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x590-0x59C)
20466 + efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC) ;
20467 + //data hold 4 bytes data.
20468 + //In RTMP_IO_READ32 will automatically execute 32-bytes swapping
20469 + RTMP_IO_READ32(pAd, efuseDataOffset, &data);
20470 + //Decide the upper 2 bytes or the bottom 2 bytes.
20471 + // Little-endian S | S Big-endian
20472 + // addr 3 2 1 0 | 0 1 2 3
20473 + // Ori-V D C B A | A B C D
20474 + //After swapping
20475 + // D C B A | D C B A
20476 + //Return 2-bytes
20477 + //The return byte statrs from S. Therefore, the little-endian will return BA, the Big-endian will return DC.
20478 + //For returning the bottom 2 bytes, the Big-endian should shift right 2-bytes.
20479 +#ifdef RT_BIG_ENDIAN
20480 + data = data << (8*((Offset & 0x3)^0x2));
20481 +#else
20482 + data = data >> (8*(Offset & 0x3));
20483 +#endif
20484 +
20485 + NdisMoveMemory(pData, &data, Length);
20486 + }
20487 +
20488 + return (UCHAR) eFuseCtrlStruc.field.EFSROM_AOUT;
20489 +
20490 +}
20491 +
20492 +/*
20493 + ========================================================================
20494 +
20495 + Routine Description:
20496 +
20497 + Arguments:
20498 +
20499 + Return Value:
20500 +
20501 + IRQL =
20502 +
20503 + Note:
20504 +
20505 + ========================================================================
20506 +*/
20507 +VOID eFusePhysicalReadRegisters(
20508 + IN PRTMP_ADAPTER pAd,
20509 + IN USHORT Offset,
20510 + IN USHORT Length,
20511 + OUT USHORT* pData)
20512 +{
20513 + EFUSE_CTRL_STRUC eFuseCtrlStruc;
20514 + int i;
20515 + USHORT efuseDataOffset;
20516 + UINT32 data;
20517 +
20518 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20519 +
20520 + //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
20521 + eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
20522 +
20523 + //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1.
20524 + //Read in physical view
20525 + eFuseCtrlStruc.field.EFSROM_MODE = 1;
20526 +
20527 + //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
20528 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
20529 +
20530 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
20531 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
20532 +
20533 + //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
20534 + i = 0;
20535 + while(i < 100)
20536 + {
20537 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20538 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
20539 + break;
20540 + RTMPusecDelay(2);
20541 + i++;
20542 + }
20543 +
20544 + //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590)
20545 + //Because the size of each EFUSE_DATA is 4 Bytes, the size of address of each is 2 bits.
20546 + //The previous 2 bits is the EFUSE_DATA number, the last 2 bits is used to decide which bytes
20547 + //Decide which EFUSE_DATA to read
20548 + //590:F E D C
20549 + //594:B A 9 8
20550 + //598:7 6 5 4
20551 + //59C:3 2 1 0
20552 + efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC) ;
20553 +
20554 + RTMP_IO_READ32(pAd, efuseDataOffset, &data);
20555 +
20556 +#ifdef RT_BIG_ENDIAN
20557 + data = data << (8*((Offset & 0x3)^0x2));
20558 +#else
20559 + data = data >> (8*(Offset & 0x3));
20560 +#endif
20561 +
20562 + NdisMoveMemory(pData, &data, Length);
20563 +
20564 +}
20565 +
20566 +/*
20567 + ========================================================================
20568 +
20569 + Routine Description:
20570 +
20571 + Arguments:
20572 +
20573 + Return Value:
20574 +
20575 + IRQL =
20576 +
20577 + Note:
20578 +
20579 + ========================================================================
20580 +*/
20581 +VOID eFuseReadPhysical(
20582 + IN PRTMP_ADAPTER pAd,
20583 + IN PUSHORT lpInBuffer,
20584 + IN ULONG nInBufferSize,
20585 + OUT PUSHORT lpOutBuffer,
20586 + IN ULONG nOutBufferSize
20587 +)
20588 +{
20589 + USHORT* pInBuf = (USHORT*)lpInBuffer;
20590 + USHORT* pOutBuf = (USHORT*)lpOutBuffer;
20591 +
20592 + USHORT Offset = pInBuf[0]; //addr
20593 + USHORT Length = pInBuf[1]; //length
20594 + int i;
20595 +
20596 + for(i=0; i<Length; i+=2)
20597 + {
20598 + eFusePhysicalReadRegisters(pAd,Offset+i, 2, &pOutBuf[i/2]);
20599 + }
20600 +}
20601 +
20602 +/*
20603 + ========================================================================
20604 +
20605 + Routine Description:
20606 +
20607 + Arguments:
20608 +
20609 + Return Value:
20610 +
20611 + IRQL =
20612 +
20613 + Note:
20614 +
20615 + ========================================================================
20616 +*/
20617 +NTSTATUS eFuseRead(
20618 + IN PRTMP_ADAPTER pAd,
20619 + IN USHORT Offset,
20620 + OUT PUCHAR pData,
20621 + IN USHORT Length)
20622 +{
20623 + USHORT* pOutBuf = (USHORT*)pData;
20624 + NTSTATUS Status = STATUS_SUCCESS;
20625 + UCHAR EFSROM_AOUT;
20626 + int i;
20627 +
20628 + for(i=0; i<Length; i+=2)
20629 + {
20630 + EFSROM_AOUT = eFuseReadRegisters(pAd, Offset+i, 2, &pOutBuf[i/2]);
20631 + }
20632 + return Status;
20633 +}
20634 +
20635 +/*
20636 + ========================================================================
20637 +
20638 + Routine Description:
20639 +
20640 + Arguments:
20641 +
20642 + Return Value:
20643 +
20644 + IRQL =
20645 +
20646 + Note:
20647 +
20648 + ========================================================================
20649 +*/
20650 +VOID eFusePhysicalWriteRegisters(
20651 + IN PRTMP_ADAPTER pAd,
20652 + IN USHORT Offset,
20653 + IN USHORT Length,
20654 + OUT USHORT* pData)
20655 +{
20656 + EFUSE_CTRL_STRUC eFuseCtrlStruc;
20657 + int i;
20658 + USHORT efuseDataOffset;
20659 + UINT32 data, eFuseDataBuffer[4];
20660 +
20661 + //Step0. Write 16-byte of data to EFUSE_DATA0-3 (0x590-0x59C), where EFUSE_DATA0 is the LSB DW, EFUSE_DATA3 is the MSB DW.
20662 +
20663 + /////////////////////////////////////////////////////////////////
20664 + //read current values of 16-byte block
20665 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20666 +
20667 + //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
20668 + eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
20669 +
20670 + //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1.
20671 + eFuseCtrlStruc.field.EFSROM_MODE = 1;
20672 +
20673 + //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
20674 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
20675 +
20676 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
20677 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
20678 +
20679 + //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
20680 + i = 0;
20681 + while(i < 100)
20682 + {
20683 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20684 +
20685 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
20686 + break;
20687 + RTMPusecDelay(2);
20688 + i++;
20689 + }
20690 +
20691 + //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590)
20692 + efuseDataOffset = EFUSE_DATA3;
20693 + for(i=0; i< 4; i++)
20694 + {
20695 + RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &eFuseDataBuffer[i]);
20696 + efuseDataOffset -= 4;
20697 + }
20698 +
20699 + //Update the value, the offset is multiple of 2, length is 2
20700 + efuseDataOffset = (Offset & 0xc) >> 2;
20701 + data = pData[0] & 0xffff;
20702 + //The offset should be 0x***10 or 0x***00
20703 + if((Offset % 4) != 0)
20704 + {
20705 + eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff) | (data << 16);
20706 + }
20707 + else
20708 + {
20709 + eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff0000) | data;
20710 + }
20711 +
20712 + efuseDataOffset = EFUSE_DATA3;
20713 + for(i=0; i< 4; i++)
20714 + {
20715 + RTMP_IO_WRITE32(pAd, efuseDataOffset, eFuseDataBuffer[i]);
20716 + efuseDataOffset -= 4;
20717 + }
20718 + /////////////////////////////////////////////////////////////////
20719 +
20720 + //Step1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
20721 + eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
20722 +
20723 + //Step2. Write EFSROM_MODE (0x580, bit7:bit6) to 3.
20724 + eFuseCtrlStruc.field.EFSROM_MODE = 3;
20725 +
20726 + //Step3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure.
20727 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
20728 +
20729 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
20730 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
20731 +
20732 + //Step4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It¡¦s done.
20733 + i = 0;
20734 + while(i < 100)
20735 + {
20736 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
20737 +
20738 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
20739 + break;
20740 +
20741 + RTMPusecDelay(2);
20742 + i++;
20743 + }
20744 +}
20745 +
20746 +/*
20747 + ========================================================================
20748 +
20749 + Routine Description:
20750 +
20751 + Arguments:
20752 +
20753 + Return Value:
20754 +
20755 + IRQL =
20756 +
20757 + Note:
20758 +
20759 + ========================================================================
20760 +*/
20761 +NTSTATUS eFuseWriteRegisters(
20762 + IN PRTMP_ADAPTER pAd,
20763 + IN USHORT Offset,
20764 + IN USHORT Length,
20765 + IN USHORT* pData)
20766 +{
20767 + USHORT i;
20768 + USHORT eFuseData;
20769 + USHORT LogicalAddress, BlkNum = 0xffff;
20770 + UCHAR EFSROM_AOUT;
20771 +
20772 + USHORT addr,tmpaddr, InBuf[3], tmpOffset;
20773 + USHORT buffer[8];
20774 + BOOLEAN bWriteSuccess = TRUE;
20775 +
20776 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters Offset=%x, pData=%x\n", Offset, *pData));
20777 +
20778 + //Step 0. find the entry in the mapping table
20779 + //The address of EEPROM is 2-bytes alignment.
20780 + //The last bit is used for alignment, so it must be 0.
20781 + tmpOffset = Offset & 0xfffe;
20782 + EFSROM_AOUT = eFuseReadRegisters(pAd, tmpOffset, 2, &eFuseData);
20783 +
20784 + if( EFSROM_AOUT == 0x3f)
20785 + { //find available logical address pointer
20786 + //the logical address does not exist, find an empty one
20787 + //from the first address of block 45=16*45=0x2d0 to the last address of block 47
20788 + //==>48*16-3(reserved)=2FC
20789 + for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
20790 + {
20791 + //Retrive the logical block nubmer form each logical address pointer
20792 + //It will access two logical address pointer each time.
20793 + eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
20794 + if( (LogicalAddress & 0xff) == 0)
20795 + {//Not used logical address pointer
20796 + BlkNum = i-EFUSE_USAGE_MAP_START;
20797 + break;
20798 + }
20799 + else if(( (LogicalAddress >> 8) & 0xff) == 0)
20800 + {//Not used logical address pointer
20801 + if (i != EFUSE_USAGE_MAP_END)
20802 + {
20803 + BlkNum = i-EFUSE_USAGE_MAP_START+1;
20804 + }
20805 + break;
20806 + }
20807 + }
20808 + }
20809 + else
20810 + {
20811 + BlkNum = EFSROM_AOUT;
20812 + }
20813 +
20814 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters BlkNum = %d \n", BlkNum));
20815 +
20816 + if(BlkNum == 0xffff)
20817 + {
20818 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n"));
20819 + return FALSE;
20820 + }
20821 +
20822 + //Step 1. Save data of this block which is pointed by the avaible logical address pointer
20823 + // read and save the original block data
20824 + for(i =0; i<8; i++)
20825 + {
20826 + addr = BlkNum * 0x10 ;
20827 +
20828 + InBuf[0] = addr+2*i;
20829 + InBuf[1] = 2;
20830 + InBuf[2] = 0x0;
20831 +
20832 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
20833 +
20834 + buffer[i] = InBuf[2];
20835 + }
20836 +
20837 + //Step 2. Update the data in buffer, and write the data to Efuse
20838 + buffer[ (Offset >> 1) % 8] = pData[0];
20839 +
20840 + do
20841 + {
20842 + //Step 3. Write the data to Efuse
20843 + if(!bWriteSuccess)
20844 + {
20845 + for(i =0; i<8; i++)
20846 + {
20847 + addr = BlkNum * 0x10 ;
20848 +
20849 + InBuf[0] = addr+2*i;
20850 + InBuf[1] = 2;
20851 + InBuf[2] = buffer[i];
20852 +
20853 + eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2);
20854 + }
20855 + }
20856 + else
20857 + {
20858 + addr = BlkNum * 0x10 ;
20859 +
20860 + InBuf[0] = addr+(Offset % 16);
20861 + InBuf[1] = 2;
20862 + InBuf[2] = pData[0];
20863 +
20864 + eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2);
20865 + }
20866 +
20867 + //Step 4. Write mapping table
20868 + addr = EFUSE_USAGE_MAP_START+BlkNum;
20869 +
20870 + tmpaddr = addr;
20871 +
20872 + if(addr % 2 != 0)
20873 + addr = addr -1;
20874 + InBuf[0] = addr;
20875 + InBuf[1] = 2;
20876 +
20877 + //convert the address from 10 to 8 bit ( bit7, 6 = parity and bit5 ~ 0 = bit9~4), and write to logical map entry
20878 + tmpOffset = Offset;
20879 + tmpOffset >>= 4;
20880 + tmpOffset |= ((~((tmpOffset & 0x01) ^ ( tmpOffset >> 1 & 0x01) ^ (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01))) << 6) & 0x40;
20881 + tmpOffset |= ((~( (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01) ^ (tmpOffset >> 4 & 0x01) ^ ( tmpOffset >> 5 & 0x01))) << 7) & 0x80;
20882 +
20883 + // write the logical address
20884 + if(tmpaddr%2 != 0)
20885 + InBuf[2] = tmpOffset<<8;
20886 + else
20887 + InBuf[2] = tmpOffset;
20888 +
20889 + eFuseWritePhysical(pAd,&InBuf[0], 6, NULL, 0);
20890 +
20891 + //Step 5. Compare data if not the same, invalidate the mapping entry, then re-write the data until E-fuse is exhausted
20892 + bWriteSuccess = TRUE;
20893 + for(i =0; i<8; i++)
20894 + {
20895 + addr = BlkNum * 0x10 ;
20896 +
20897 + InBuf[0] = addr+2*i;
20898 + InBuf[1] = 2;
20899 + InBuf[2] = 0x0;
20900 +
20901 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
20902 +
20903 + if(buffer[i] != InBuf[2])
20904 + {
20905 + bWriteSuccess = FALSE;
20906 + break;
20907 + }
20908 + }
20909 +
20910 + //Step 6. invlidate mapping entry and find a free mapping entry if not succeed
20911 + if (!bWriteSuccess)
20912 + {
20913 + DBGPRINT(RT_DEBUG_TRACE, ("Not bWriteSuccess BlkNum = %d\n", BlkNum));
20914 +
20915 + // the offset of current mapping entry
20916 + addr = EFUSE_USAGE_MAP_START+BlkNum;
20917 +
20918 + //find a new mapping entry
20919 + BlkNum = 0xffff;
20920 + for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
20921 + {
20922 + eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
20923 + if( (LogicalAddress & 0xff) == 0)
20924 + {
20925 + BlkNum = i-EFUSE_USAGE_MAP_START;
20926 + break;
20927 + }
20928 + else if(( (LogicalAddress >> 8) & 0xff) == 0)
20929 + {
20930 + if (i != EFUSE_USAGE_MAP_END)
20931 + {
20932 + BlkNum = i+1-EFUSE_USAGE_MAP_START;
20933 + }
20934 + break;
20935 + }
20936 + }
20937 + DBGPRINT(RT_DEBUG_TRACE, ("Not bWriteSuccess new BlkNum = %d\n", BlkNum));
20938 + if(BlkNum == 0xffff)
20939 + {
20940 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n"));
20941 + return FALSE;
20942 + }
20943 +
20944 + //invalidate the original mapping entry if new entry is not found
20945 + tmpaddr = addr;
20946 +
20947 + if(addr % 2 != 0)
20948 + addr = addr -1;
20949 + InBuf[0] = addr;
20950 + InBuf[1] = 2;
20951 +
20952 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
20953 +
20954 + // write the logical address
20955 + if(tmpaddr%2 != 0)
20956 + {
20957 + // Invalidate the high byte
20958 + for (i=8; i<15; i++)
20959 + {
20960 + if( ( (InBuf[2] >> i) & 0x01) == 0)
20961 + {
20962 + InBuf[2] |= (0x1 <<i);
20963 + break;
20964 + }
20965 + }
20966 + }
20967 + else
20968 + {
20969 + // invalidate the low byte
20970 + for (i=0; i<8; i++)
20971 + {
20972 + if( ( (InBuf[2] >> i) & 0x01) == 0)
20973 + {
20974 + InBuf[2] |= (0x1 <<i);
20975 + break;
20976 + }
20977 + }
20978 + }
20979 + eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 0);
20980 + }
20981 + }
20982 + while(!bWriteSuccess);
20983 +
20984 + return TRUE;
20985 +}
20986 +
20987 +/*
20988 + ========================================================================
20989 +
20990 + Routine Description:
20991 +
20992 + Arguments:
20993 +
20994 + Return Value:
20995 +
20996 + IRQL =
20997 +
20998 + Note:
20999 +
21000 + ========================================================================
21001 +*/
21002 +VOID eFuseWritePhysical(
21003 + IN PRTMP_ADAPTER pAd,
21004 + PUSHORT lpInBuffer,
21005 + ULONG nInBufferSize,
21006 + PUCHAR lpOutBuffer,
21007 + ULONG nOutBufferSize
21008 +)
21009 +{
21010 + USHORT* pInBuf = (USHORT*)lpInBuffer;
21011 + int i;
21012 + //USHORT* pOutBuf = (USHORT*)ioBuffer;
21013 +
21014 + USHORT Offset = pInBuf[0]; //addr
21015 + USHORT Length = pInBuf[1]; //length
21016 + USHORT* pValueX = &pInBuf[2]; //value ...
21017 + // Little-endian S | S Big-endian
21018 + // addr 3 2 1 0 | 0 1 2 3
21019 + // Ori-V D C B A | A B C D
21020 + //After swapping
21021 + // D C B A | D C B A
21022 + //Both the little and big-endian use the same sequence to write data.
21023 + //Therefore, we only need swap data when read the data.
21024 + for(i=0; i<Length; i+=2)
21025 + {
21026 + eFusePhysicalWriteRegisters(pAd, Offset+i, 2, &pValueX[i/2]);
21027 + }
21028 +}
21029 +
21030 +
21031 +/*
21032 + ========================================================================
21033 +
21034 + Routine Description:
21035 +
21036 + Arguments:
21037 +
21038 + Return Value:
21039 +
21040 + IRQL =
21041 +
21042 + Note:
21043 +
21044 + ========================================================================
21045 +*/
21046 +NTSTATUS eFuseWrite(
21047 + IN PRTMP_ADAPTER pAd,
21048 + IN USHORT Offset,
21049 + IN PUCHAR pData,
21050 + IN USHORT length)
21051 +{
21052 + int i;
21053 +
21054 + USHORT* pValueX = (PUSHORT) pData; //value ...
21055 + //The input value=3070 will be stored as following
21056 + // Little-endian S | S Big-endian
21057 + // addr 1 0 | 0 1
21058 + // Ori-V 30 70 | 30 70
21059 + //After swapping
21060 + // 30 70 | 70 30
21061 + //Casting
21062 + // 3070 | 7030 (x)
21063 + //The swapping should be removed for big-endian
21064 + for(i=0; i<length; i+=2)
21065 + {
21066 + eFuseWriteRegisters(pAd, Offset+i, 2, &pValueX[i/2]);
21067 + }
21068 +
21069 + return TRUE;
21070 +}
21071 +
21072 +/*
21073 + ========================================================================
21074 +
21075 + Routine Description:
21076 +
21077 + Arguments:
21078 +
21079 + Return Value:
21080 +
21081 + IRQL =
21082 +
21083 + Note:
21084 +
21085 + ========================================================================
21086 +*/
21087 +INT set_eFuseGetFreeBlockCount_Proc(
21088 + IN PRTMP_ADAPTER pAd,
21089 + IN PUCHAR arg)
21090 +{
21091 + USHORT i;
21092 + USHORT LogicalAddress;
21093 + USHORT efusefreenum=0;
21094 + if(!pAd->bUseEfuse)
21095 + return FALSE;
21096 + for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i+=2)
21097 + {
21098 + eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
21099 + if( (LogicalAddress & 0xff) == 0)
21100 + {
21101 + efusefreenum= (UCHAR) (EFUSE_USAGE_MAP_END-i+1);
21102 + break;
21103 + }
21104 + else if(( (LogicalAddress >> 8) & 0xff) == 0)
21105 + {
21106 + efusefreenum = (UCHAR) (EFUSE_USAGE_MAP_END-i);
21107 + break;
21108 + }
21109 +
21110 + if(i == EFUSE_USAGE_MAP_END)
21111 + efusefreenum = 0;
21112 + }
21113 + printk("efuseFreeNumber is %d\n",efusefreenum);
21114 + return TRUE;
21115 +}
21116 +INT set_eFusedump_Proc(
21117 + IN PRTMP_ADAPTER pAd,
21118 + IN PUCHAR arg)
21119 +{
21120 +USHORT InBuf[3];
21121 + INT i=0;
21122 + if(!pAd->bUseEfuse)
21123 + return FALSE;
21124 + for(i =0; i<EFUSE_USAGE_MAP_END/2; i++)
21125 + {
21126 + InBuf[0] = 2*i;
21127 + InBuf[1] = 2;
21128 + InBuf[2] = 0x0;
21129 +
21130 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
21131 + if(i%4==0)
21132 + printk("\nBlock %x:",i/8);
21133 + printk("%04x ",InBuf[2]);
21134 + }
21135 + return TRUE;
21136 +}
21137 +INT set_eFuseLoadFromBin_Proc(
21138 + IN PRTMP_ADAPTER pAd,
21139 + IN PUCHAR arg)
21140 +{
21141 + CHAR *src;
21142 + struct file *srcf;
21143 + INT retval, orgfsuid, orgfsgid;
21144 + mm_segment_t orgfs;
21145 + UCHAR *buffer;
21146 + UCHAR BinFileSize=0;
21147 + INT i = 0,j=0,k=1;
21148 + USHORT *PDATA;
21149 + USHORT DATA;
21150 + BinFileSize=strlen("RT30xxEEPROM.bin");
21151 + src = kmalloc(128, MEM_ALLOC_FLAG);
21152 + NdisZeroMemory(src, 128);
21153 +
21154 + if(strlen(arg)>0)
21155 + {
21156 +
21157 + NdisMoveMemory(src, arg, strlen(arg));
21158 + }
21159 +
21160 + else
21161 + {
21162 +
21163 + NdisMoveMemory(src, "RT30xxEEPROM.bin", BinFileSize);
21164 + }
21165 +
21166 + DBGPRINT(RT_DEBUG_TRACE, ("FileName=%s\n",src));
21167 + buffer = kmalloc(MAX_EEPROM_BIN_FILE_SIZE, MEM_ALLOC_FLAG);
21168 +
21169 + if(buffer == NULL)
21170 + {
21171 + kfree(src);
21172 + return FALSE;
21173 +}
21174 + PDATA=kmalloc(sizeof(USHORT)*8,MEM_ALLOC_FLAG);
21175 +
21176 + if(PDATA==NULL)
21177 + {
21178 + kfree(src);
21179 +
21180 + kfree(buffer);
21181 + return FALSE;
21182 + }
21183 + /* Don't change to uid 0, let the file be opened as the "normal" user */
21184 +#if 0
21185 + orgfsuid = current->fsuid;
21186 + orgfsgid = current->fsgid;
21187 + current->fsuid=current->fsgid = 0;
21188 +#endif
21189 + orgfs = get_fs();
21190 + set_fs(KERNEL_DS);
21191 +
21192 + if (src && *src)
21193 + {
21194 + srcf = filp_open(src, O_RDONLY, 0);
21195 + if (IS_ERR(srcf))
21196 + {
21197 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
21198 + return FALSE;
21199 + }
21200 + else
21201 + {
21202 + // The object must have a read method
21203 + if (srcf->f_op && srcf->f_op->read)
21204 + {
21205 + memset(buffer, 0x00, MAX_EEPROM_BIN_FILE_SIZE);
21206 + while(srcf->f_op->read(srcf, &buffer[i], 1, &srcf->f_pos)==1)
21207 + {
21208 + DBGPRINT(RT_DEBUG_TRACE, ("%02X ",buffer[i]));
21209 + if((i+1)%8==0)
21210 + DBGPRINT(RT_DEBUG_TRACE, ("\n"));
21211 + i++;
21212 + if(i>=MAX_EEPROM_BIN_FILE_SIZE)
21213 + {
21214 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld reading %s, The file is too large[1024]\n", -PTR_ERR(srcf),src));
21215 + kfree(PDATA);
21216 + kfree(buffer);
21217 + kfree(src);
21218 + return FALSE;
21219 + }
21220 + }
21221 + }
21222 + else
21223 + {
21224 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error!! System doest not support read function\n"));
21225 + kfree(PDATA);
21226 + kfree(buffer);
21227 + kfree(src);
21228 + return FALSE;
21229 + }
21230 + }
21231 +
21232 +
21233 + }
21234 + else
21235 + {
21236 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error src or srcf is null\n"));
21237 + kfree(PDATA);
21238 + kfree(buffer);
21239 + return FALSE;
21240 +
21241 + }
21242 +
21243 +
21244 + retval=filp_close(srcf,NULL);
21245 +
21246 + if (retval)
21247 + {
21248 + DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
21249 + }
21250 + set_fs(orgfs);
21251 +#if 0
21252 + current->fsuid = orgfsuid;
21253 + current->fsgid = orgfsgid;
21254 +#endif
21255 + for(j=0;j<i;j++)
21256 + {
21257 + DBGPRINT(RT_DEBUG_TRACE, ("%02X ",buffer[j]));
21258 + if((j+1)%2==0)
21259 + PDATA[j/2%8]=((buffer[j]<<8)&0xff00)|(buffer[j-1]&0xff);
21260 + if(j%16==0)
21261 + {
21262 + k=buffer[j];
21263 + }
21264 + else
21265 + {
21266 + k&=buffer[j];
21267 + if((j+1)%16==0)
21268 + {
21269 +
21270 + DBGPRINT(RT_DEBUG_TRACE, (" result=%02X,blk=%02x\n",k,j/16));
21271 +
21272 + if(k!=0xff)
21273 + eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA);
21274 + else
21275 + {
21276 + if(eFuseReadRegisters(pAd,j, 2,(PUSHORT)&DATA)!=0x3f)
21277 + eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA);
21278 + }
21279 + /*
21280 + for(l=0;l<8;l++)
21281 + printk("%04x ",PDATA[l]);
21282 + printk("\n");
21283 + */
21284 + NdisZeroMemory(PDATA,16);
21285 +
21286 +
21287 + }
21288 + }
21289 +
21290 +
21291 + }
21292 +
21293 +
21294 + kfree(PDATA);
21295 + kfree(buffer);
21296 + kfree(src);
21297 + return TRUE;
21298 +}
21299 +NTSTATUS eFuseWriteRegistersFromBin(
21300 + IN PRTMP_ADAPTER pAd,
21301 + IN USHORT Offset,
21302 + IN USHORT Length,
21303 + IN USHORT* pData)
21304 +{
21305 + USHORT i;
21306 + USHORT eFuseData;
21307 + USHORT LogicalAddress, BlkNum = 0xffff;
21308 + UCHAR EFSROM_AOUT,Loop=0;
21309 + EFUSE_CTRL_STRUC eFuseCtrlStruc;
21310 + USHORT efuseDataOffset;
21311 + UINT32 data,tempbuffer;
21312 + USHORT addr,tmpaddr, InBuf[3], tmpOffset;
21313 + UINT32 buffer[4];
21314 + BOOLEAN bWriteSuccess = TRUE;
21315 + BOOLEAN bNotWrite=TRUE;
21316 + BOOLEAN bAllocateNewBlk=TRUE;
21317 +
21318 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin Offset=%x, pData=%04x:%04x:%04x:%04x\n", Offset, *pData,*(pData+1),*(pData+2),*(pData+3)));
21319 +
21320 + do
21321 + {
21322 + //Step 0. find the entry in the mapping table
21323 + //The address of EEPROM is 2-bytes alignment.
21324 + //The last bit is used for alignment, so it must be 0.
21325 + Loop++;
21326 + tmpOffset = Offset & 0xfffe;
21327 + EFSROM_AOUT = eFuseReadRegisters(pAd, tmpOffset, 2, &eFuseData);
21328 +
21329 + if( EFSROM_AOUT == 0x3f)
21330 + { //find available logical address pointer
21331 + //the logical address does not exist, find an empty one
21332 + //from the first address of block 45=16*45=0x2d0 to the last address of block 47
21333 + //==>48*16-3(reserved)=2FC
21334 + bAllocateNewBlk=TRUE;
21335 + for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
21336 + {
21337 + //Retrive the logical block nubmer form each logical address pointer
21338 + //It will access two logical address pointer each time.
21339 + eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
21340 + if( (LogicalAddress & 0xff) == 0)
21341 + {//Not used logical address pointer
21342 + BlkNum = i-EFUSE_USAGE_MAP_START;
21343 + break;
21344 + }
21345 + else if(( (LogicalAddress >> 8) & 0xff) == 0)
21346 + {//Not used logical address pointer
21347 + if (i != EFUSE_USAGE_MAP_END)
21348 + {
21349 + BlkNum = i-EFUSE_USAGE_MAP_START+1;
21350 + }
21351 + break;
21352 + }
21353 + }
21354 + }
21355 + else
21356 + {
21357 + bAllocateNewBlk=FALSE;
21358 + BlkNum = EFSROM_AOUT;
21359 + }
21360 +
21361 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters BlkNum = %d \n", BlkNum));
21362 +
21363 + if(BlkNum == 0xffff)
21364 + {
21365 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n"));
21366 + return FALSE;
21367 + }
21368 + //Step 1.1.0
21369 + //If the block is not existing in mapping table, create one
21370 + //and write down the 16-bytes data to the new block
21371 + if(bAllocateNewBlk)
21372 + {
21373 + DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk\n"));
21374 + efuseDataOffset = EFUSE_DATA3;
21375 + for(i=0; i< 4; i++)
21376 + {
21377 + DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk, Data%d=%04x%04x\n",3-i,pData[2*i+1],pData[2*i]));
21378 + tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i];
21379 +
21380 +
21381 + RTMP_IO_WRITE32(pAd, efuseDataOffset,tempbuffer);
21382 + efuseDataOffset -= 4;
21383 +
21384 + }
21385 + /////////////////////////////////////////////////////////////////
21386 +
21387 + //Step1.1.1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
21388 + eFuseCtrlStruc.field.EFSROM_AIN = BlkNum* 0x10 ;
21389 +
21390 + //Step1.1.2. Write EFSROM_MODE (0x580, bit7:bit6) to 3.
21391 + eFuseCtrlStruc.field.EFSROM_MODE = 3;
21392 +
21393 + //Step1.1.3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure.
21394 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
21395 +
21396 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
21397 +
21398 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
21399 +
21400 + //Step1.1.4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It¡¦s done.
21401 + i = 0;
21402 + while(i < 100)
21403 + {
21404 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
21405 +
21406 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
21407 + break;
21408 +
21409 + RTMPusecDelay(2);
21410 + i++;
21411 + }
21412 +
21413 + }
21414 + else
21415 + { //Step1.2.
21416 + //If the same logical number is existing, check if the writting data and the data
21417 + //saving in this block are the same.
21418 + /////////////////////////////////////////////////////////////////
21419 + //read current values of 16-byte block
21420 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
21421 +
21422 + //Step1.2.0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment.
21423 + eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
21424 +
21425 + //Step1.2.1. Write EFSROM_MODE (0x580, bit7:bit6) to 1.
21426 + eFuseCtrlStruc.field.EFSROM_MODE = 0;
21427 +
21428 + //Step1.2.2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure.
21429 + eFuseCtrlStruc.field.EFSROM_KICK = 1;
21430 +
21431 + NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
21432 + RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
21433 +
21434 + //Step1.2.3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again.
21435 + i = 0;
21436 + while(i < 100)
21437 + {
21438 + RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc);
21439 +
21440 + if(eFuseCtrlStruc.field.EFSROM_KICK == 0)
21441 + break;
21442 + RTMPusecDelay(2);
21443 + i++;
21444 + }
21445 +
21446 + //Step1.2.4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590)
21447 + efuseDataOffset = EFUSE_DATA3;
21448 + for(i=0; i< 4; i++)
21449 + {
21450 + RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &buffer[i]);
21451 + efuseDataOffset -= 4;
21452 + }
21453 + //Step1.2.5. Check if the data of efuse and the writing data are the same.
21454 + for(i =0; i<4; i++)
21455 + {
21456 + tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i];
21457 + DBGPRINT(RT_DEBUG_TRACE, ("buffer[%d]=%x,pData[%d]=%x,pData[%d]=%x,tempbuffer=%x\n",i,buffer[i],2*i,pData[2*i],2*i+1,pData[2*i+1],tempbuffer));
21458 +
21459 + if(((buffer[i]&0xffff0000)==(pData[2*i+1]<<16))&&((buffer[i]&0xffff)==pData[2*i]))
21460 + bNotWrite&=TRUE;
21461 + else
21462 + {
21463 + bNotWrite&=FALSE;
21464 + break;
21465 + }
21466 + }
21467 + if(!bNotWrite)
21468 + {
21469 + printk("The data is not the same\n");
21470 +
21471 + for(i =0; i<8; i++)
21472 + {
21473 + addr = BlkNum * 0x10 ;
21474 +
21475 + InBuf[0] = addr+2*i;
21476 + InBuf[1] = 2;
21477 + InBuf[2] = pData[i];
21478 +
21479 + eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2);
21480 + }
21481 +
21482 + }
21483 + else
21484 + return TRUE;
21485 + }
21486 +
21487 +
21488 +
21489 + //Step 2. Write mapping table
21490 + addr = EFUSE_USAGE_MAP_START+BlkNum;
21491 +
21492 + tmpaddr = addr;
21493 +
21494 + if(addr % 2 != 0)
21495 + addr = addr -1;
21496 + InBuf[0] = addr;
21497 + InBuf[1] = 2;
21498 +
21499 + //convert the address from 10 to 8 bit ( bit7, 6 = parity and bit5 ~ 0 = bit9~4), and write to logical map entry
21500 + tmpOffset = Offset;
21501 + tmpOffset >>= 4;
21502 + tmpOffset |= ((~((tmpOffset & 0x01) ^ ( tmpOffset >> 1 & 0x01) ^ (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01))) << 6) & 0x40;
21503 + tmpOffset |= ((~( (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01) ^ (tmpOffset >> 4 & 0x01) ^ ( tmpOffset >> 5 & 0x01))) << 7) & 0x80;
21504 +
21505 + // write the logical address
21506 + if(tmpaddr%2 != 0)
21507 + InBuf[2] = tmpOffset<<8;
21508 + else
21509 + InBuf[2] = tmpOffset;
21510 +
21511 + eFuseWritePhysical(pAd,&InBuf[0], 6, NULL, 0);
21512 +
21513 + //Step 3. Compare data if not the same, invalidate the mapping entry, then re-write the data until E-fuse is exhausted
21514 + bWriteSuccess = TRUE;
21515 + for(i =0; i<8; i++)
21516 + {
21517 + addr = BlkNum * 0x10 ;
21518 +
21519 + InBuf[0] = addr+2*i;
21520 + InBuf[1] = 2;
21521 + InBuf[2] = 0x0;
21522 +
21523 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
21524 + DBGPRINT(RT_DEBUG_TRACE, ("addr=%x, buffer[i]=%x,InBuf[2]=%x\n",InBuf[0],pData[i],InBuf[2]));
21525 + if(pData[i] != InBuf[2])
21526 + {
21527 + bWriteSuccess = FALSE;
21528 + break;
21529 + }
21530 + }
21531 +
21532 + //Step 4. invlidate mapping entry and find a free mapping entry if not succeed
21533 +
21534 + if (!bWriteSuccess&&Loop<2)
21535 + {
21536 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess BlkNum = %d\n", BlkNum));
21537 +
21538 + // the offset of current mapping entry
21539 + addr = EFUSE_USAGE_MAP_START+BlkNum;
21540 +
21541 + //find a new mapping entry
21542 + BlkNum = 0xffff;
21543 + for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2)
21544 + {
21545 + eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
21546 + if( (LogicalAddress & 0xff) == 0)
21547 + {
21548 + BlkNum = i-EFUSE_USAGE_MAP_START;
21549 + break;
21550 + }
21551 + else if(( (LogicalAddress >> 8) & 0xff) == 0)
21552 + {
21553 + if (i != EFUSE_USAGE_MAP_END)
21554 + {
21555 + BlkNum = i+1-EFUSE_USAGE_MAP_START;
21556 + }
21557 + break;
21558 + }
21559 + }
21560 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess new BlkNum = %d\n", BlkNum));
21561 + if(BlkNum == 0xffff)
21562 + {
21563 + DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin: out of free E-fuse space!!!\n"));
21564 + return FALSE;
21565 + }
21566 +
21567 + //invalidate the original mapping entry if new entry is not found
21568 + tmpaddr = addr;
21569 +
21570 + if(addr % 2 != 0)
21571 + addr = addr -1;
21572 + InBuf[0] = addr;
21573 + InBuf[1] = 2;
21574 +
21575 + eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
21576 +
21577 + // write the logical address
21578 + if(tmpaddr%2 != 0)
21579 + {
21580 + // Invalidate the high byte
21581 + for (i=8; i<15; i++)
21582 + {
21583 + if( ( (InBuf[2] >> i) & 0x01) == 0)
21584 + {
21585 + InBuf[2] |= (0x1 <<i);
21586 + break;
21587 + }
21588 + }
21589 + }
21590 + else
21591 + {
21592 + // invalidate the low byte
21593 + for (i=0; i<8; i++)
21594 + {
21595 + if( ( (InBuf[2] >> i) & 0x01) == 0)
21596 + {
21597 + InBuf[2] |= (0x1 <<i);
21598 + break;
21599 + }
21600 + }
21601 + }
21602 + eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 0);
21603 + }
21604 +
21605 + }
21606 + while(!bWriteSuccess&&Loop<2);
21607 +
21608 + return TRUE;
21609 +}
21610 +
21611 +#endif // RT30xx //
21612 +//2008/09/11:KH add to support efuse-->
21613 +
21614 --- /dev/null
21615 +++ b/drivers/staging/rt3070/common/md5.c
21616 @@ -0,0 +1,1427 @@
21617 +/*
21618 + *************************************************************************
21619 + * Ralink Tech Inc.
21620 + * 5F., No.36, Taiyuan St., Jhubei City,
21621 + * Hsinchu County 302,
21622 + * Taiwan, R.O.C.
21623 + *
21624 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
21625 + *
21626 + * This program is free software; you can redistribute it and/or modify *
21627 + * it under the terms of the GNU General Public License as published by *
21628 + * the Free Software Foundation; either version 2 of the License, or *
21629 + * (at your option) any later version. *
21630 + * *
21631 + * This program is distributed in the hope that it will be useful, *
21632 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21633 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21634 + * GNU General Public License for more details. *
21635 + * *
21636 + * You should have received a copy of the GNU General Public License *
21637 + * along with this program; if not, write to the *
21638 + * Free Software Foundation, Inc., *
21639 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21640 + * *
21641 + *************************************************************************
21642 +
21643 + Module Name:
21644 + md5.c
21645 +
21646 + Abstract:
21647 +
21648 + Revision History:
21649 + Who When What
21650 + -------- ---------- ----------------------------------------------
21651 + Name Date Modification logs
21652 + jan 10-28-03 Initial
21653 + Rita 11-23-04 Modify MD5 and SHA-1
21654 + Rita 10-14-05 Modify SHA-1 in big-endian platform
21655 + */
21656 +#include "../rt_config.h"
21657 +
21658 +/**
21659 + * md5_mac:
21660 + * @key: pointer to the key used for MAC generation
21661 + * @key_len: length of the key in bytes
21662 + * @data: pointer to the data area for which the MAC is generated
21663 + * @data_len: length of the data in bytes
21664 + * @mac: pointer to the buffer holding space for the MAC; the buffer should
21665 + * have space for 128-bit (16 bytes) MD5 hash value
21666 + *
21667 + * md5_mac() determines the message authentication code by using secure hash
21668 + * MD5(key | data | key).
21669 + */
21670 +void md5_mac(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac)
21671 +{
21672 + MD5_CTX context;
21673 +
21674 + MD5Init(&context);
21675 + MD5Update(&context, key, key_len);
21676 + MD5Update(&context, data, data_len);
21677 + MD5Update(&context, key, key_len);
21678 + MD5Final(mac, &context);
21679 +}
21680 +
21681 +/**
21682 + * hmac_md5:
21683 + * @key: pointer to the key used for MAC generation
21684 + * @key_len: length of the key in bytes
21685 + * @data: pointer to the data area for which the MAC is generated
21686 + * @data_len: length of the data in bytes
21687 + * @mac: pointer to the buffer holding space for the MAC; the buffer should
21688 + * have space for 128-bit (16 bytes) MD5 hash value
21689 + *
21690 + * hmac_md5() determines the message authentication code using HMAC-MD5.
21691 + * This implementation is based on the sample code presented in RFC 2104.
21692 + */
21693 +void hmac_md5(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac)
21694 +{
21695 + MD5_CTX context;
21696 + u8 k_ipad[65]; /* inner padding - key XORd with ipad */
21697 + u8 k_opad[65]; /* outer padding - key XORd with opad */
21698 + u8 tk[16];
21699 + int i;
21700 +
21701 + //assert(key != NULL && data != NULL && mac != NULL);
21702 +
21703 + /* if key is longer than 64 bytes reset it to key = MD5(key) */
21704 + if (key_len > 64) {
21705 + MD5_CTX ttcontext;
21706 +
21707 + MD5Init(&ttcontext);
21708 + MD5Update(&ttcontext, key, key_len);
21709 + MD5Final(tk, &ttcontext);
21710 + //key=(PUCHAR)ttcontext.buf;
21711 + key = tk;
21712 + key_len = 16;
21713 + }
21714 +
21715 + /* the HMAC_MD5 transform looks like:
21716 + *
21717 + * MD5(K XOR opad, MD5(K XOR ipad, text))
21718 + *
21719 + * where K is an n byte key
21720 + * ipad is the byte 0x36 repeated 64 times
21721 + * opad is the byte 0x5c repeated 64 times
21722 + * and text is the data being protected */
21723 +
21724 + /* start out by storing key in pads */
21725 + NdisZeroMemory(k_ipad, sizeof(k_ipad));
21726 + NdisZeroMemory(k_opad, sizeof(k_opad));
21727 + //assert(key_len < sizeof(k_ipad));
21728 + NdisMoveMemory(k_ipad, key, key_len);
21729 + NdisMoveMemory(k_opad, key, key_len);
21730 +
21731 + /* XOR key with ipad and opad values */
21732 + for (i = 0; i < 64; i++) {
21733 + k_ipad[i] ^= 0x36;
21734 + k_opad[i] ^= 0x5c;
21735 + }
21736 +
21737 + /* perform inner MD5 */
21738 + MD5Init(&context); /* init context for 1st pass */
21739 + MD5Update(&context, k_ipad, 64); /* start with inner pad */
21740 + MD5Update(&context, data, data_len); /* then text of datagram */
21741 + MD5Final(mac, &context); /* finish up 1st pass */
21742 +
21743 + /* perform outer MD5 */
21744 + MD5Init(&context); /* init context for 2nd pass */
21745 + MD5Update(&context, k_opad, 64); /* start with outer pad */
21746 + MD5Update(&context, mac, 16); /* then results of 1st hash */
21747 + MD5Final(mac, &context); /* finish up 2nd pass */
21748 +}
21749 +
21750 +#ifndef RT_BIG_ENDIAN
21751 +#define byteReverse(buf, len) /* Nothing */
21752 +#else
21753 +void byteReverse(unsigned char *buf, unsigned longs);
21754 +void byteReverse(unsigned char *buf, unsigned longs)
21755 +{
21756 + do {
21757 + *(UINT32 *)buf = SWAP32(*(UINT32 *)buf);
21758 + buf += 4;
21759 + } while (--longs);
21760 +}
21761 +#endif
21762 +
21763 +
21764 +/* ========================== MD5 implementation =========================== */
21765 +// four base functions for MD5
21766 +#define MD5_F1(x, y, z) (((x) & (y)) | ((~x) & (z)))
21767 +#define MD5_F2(x, y, z) (((x) & (z)) | ((y) & (~z)))
21768 +#define MD5_F3(x, y, z) ((x) ^ (y) ^ (z))
21769 +#define MD5_F4(x, y, z) ((y) ^ ((x) | (~z)))
21770 +#define CYCLIC_LEFT_SHIFT(w, s) (((w) << (s)) | ((w) >> (32-(s))))
21771 +
21772 +#define MD5Step(f, w, x, y, z, data, t, s) \
21773 + ( w += f(x, y, z) + data + t, w = (CYCLIC_LEFT_SHIFT(w, s)) & 0xffffffff, w += x )
21774 +
21775 +
21776 +/*
21777 + * Function Description:
21778 + * Initiate MD5 Context satisfied in RFC 1321
21779 + *
21780 + * Arguments:
21781 + * pCtx Pointer to MD5 context
21782 + *
21783 + * Return Value:
21784 + * None
21785 + */
21786 +VOID MD5Init(MD5_CTX *pCtx)
21787 +{
21788 + pCtx->Buf[0]=0x67452301;
21789 + pCtx->Buf[1]=0xefcdab89;
21790 + pCtx->Buf[2]=0x98badcfe;
21791 + pCtx->Buf[3]=0x10325476;
21792 +
21793 + pCtx->LenInBitCount[0]=0;
21794 + pCtx->LenInBitCount[1]=0;
21795 +}
21796 +
21797 +
21798 +/*
21799 + * Function Description:
21800 + * Update MD5 Context, allow of an arrary of octets as the next portion
21801 + * of the message
21802 + *
21803 + * Arguments:
21804 + * pCtx Pointer to MD5 context
21805 + * pData Pointer to input data
21806 + * LenInBytes The length of input data (unit: byte)
21807 + *
21808 + * Return Value:
21809 + * None
21810 + *
21811 + * Note:
21812 + * Called after MD5Init or MD5Update(itself)
21813 + */
21814 +VOID MD5Update(MD5_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes)
21815 +{
21816 +
21817 + UINT32 TfTimes;
21818 + UINT32 temp;
21819 + unsigned int i;
21820 +
21821 + temp = pCtx->LenInBitCount[0];
21822 +
21823 + pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3));
21824 +
21825 + if (pCtx->LenInBitCount[0] < temp)
21826 + pCtx->LenInBitCount[1]++; //carry in
21827 +
21828 + pCtx->LenInBitCount[1] += LenInBytes >> 29;
21829 +
21830 + // mod 64 bytes
21831 + temp = (temp >> 3) & 0x3f;
21832 +
21833 + // process lacks of 64-byte data
21834 + if (temp)
21835 + {
21836 + UCHAR *pAds = (UCHAR *) pCtx->Input + temp;
21837 +
21838 + if ((temp+LenInBytes) < 64)
21839 + {
21840 + NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes);
21841 + return;
21842 + }
21843 +
21844 + NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp);
21845 + byteReverse(pCtx->Input, 16);
21846 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21847 +
21848 + pData += 64-temp;
21849 + LenInBytes -= 64-temp;
21850 + } // end of if (temp)
21851 +
21852 +
21853 + TfTimes = (LenInBytes >> 6);
21854 +
21855 + for (i=TfTimes; i>0; i--)
21856 + {
21857 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64);
21858 + byteReverse(pCtx->Input, 16);
21859 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21860 + pData += 64;
21861 + LenInBytes -= 64;
21862 + } // end of for
21863 +
21864 + // buffering lacks of 64-byte data
21865 + if(LenInBytes)
21866 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes);
21867 +
21868 +}
21869 +
21870 +
21871 +/*
21872 + * Function Description:
21873 + * Append padding bits and length of original message in the tail
21874 + * The message digest has to be completed in the end
21875 + *
21876 + * Arguments:
21877 + * Digest Output of Digest-Message for MD5
21878 + * pCtx Pointer to MD5 context
21879 + *
21880 + * Return Value:
21881 + * None
21882 + *
21883 + * Note:
21884 + * Called after MD5Update
21885 + */
21886 +VOID MD5Final(UCHAR Digest[16], MD5_CTX *pCtx)
21887 +{
21888 + UCHAR Remainder;
21889 + UCHAR PadLenInBytes;
21890 + UCHAR *pAppend=0;
21891 + unsigned int i;
21892 +
21893 + Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f);
21894 +
21895 + PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder);
21896 +
21897 + pAppend = (UCHAR *)pCtx->Input + Remainder;
21898 +
21899 + // padding bits without crossing block(64-byte based) boundary
21900 + if (Remainder < 56)
21901 + {
21902 + *pAppend = 0x80;
21903 + PadLenInBytes --;
21904 +
21905 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes);
21906 +
21907 + // add data-length field, from low to high
21908 + for (i=0; i<4; i++)
21909 + {
21910 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff);
21911 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff);
21912 + }
21913 +
21914 + byteReverse(pCtx->Input, 16);
21915 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21916 + } // end of if
21917 +
21918 + // padding bits with crossing block(64-byte based) boundary
21919 + else
21920 + {
21921 + // the first block ===
21922 + *pAppend = 0x80;
21923 + PadLenInBytes --;
21924 +
21925 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1));
21926 + PadLenInBytes -= (64 - Remainder - 1);
21927 +
21928 + byteReverse(pCtx->Input, 16);
21929 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21930 +
21931 +
21932 + // the second block ===
21933 + NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes);
21934 +
21935 + // add data-length field
21936 + for (i=0; i<4; i++)
21937 + {
21938 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff);
21939 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff);
21940 + }
21941 +
21942 + byteReverse(pCtx->Input, 16);
21943 + MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input);
21944 + } // end of else
21945 +
21946 +
21947 + NdisMoveMemory((UCHAR *)Digest, (UINT32 *)pCtx->Buf, 16); // output
21948 + byteReverse((UCHAR *)Digest, 4);
21949 + NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free
21950 +}
21951 +
21952 +
21953 +/*
21954 + * Function Description:
21955 + * The central algorithm of MD5, consists of four rounds and sixteen
21956 + * steps per round
21957 + *
21958 + * Arguments:
21959 + * Buf Buffers of four states (output: 16 bytes)
21960 + * Mes Input data (input: 64 bytes)
21961 + *
21962 + * Return Value:
21963 + * None
21964 + *
21965 + * Note:
21966 + * Called by MD5Update or MD5Final
21967 + */
21968 +VOID MD5Transform(UINT32 Buf[4], UINT32 Mes[16])
21969 +{
21970 + UINT32 Reg[4], Temp;
21971 + unsigned int i;
21972 +
21973 + static UCHAR LShiftVal[16] =
21974 + {
21975 + 7, 12, 17, 22,
21976 + 5, 9 , 14, 20,
21977 + 4, 11, 16, 23,
21978 + 6, 10, 15, 21,
21979 + };
21980 +
21981 +
21982 + // [equal to 4294967296*abs(sin(index))]
21983 + static UINT32 MD5Table[64] =
21984 + {
21985 + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
21986 + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
21987 + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
21988 + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
21989 +
21990 + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
21991 + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
21992 + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
21993 + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
21994 +
21995 + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
21996 + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
21997 + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
21998 + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
21999 +
22000 + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
22001 + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
22002 + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
22003 + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
22004 + };
22005 +
22006 +
22007 + for (i=0; i<4; i++)
22008 + Reg[i]=Buf[i];
22009 +
22010 +
22011 + // 64 steps in MD5 algorithm
22012 + for (i=0; i<16; i++)
22013 + {
22014 + MD5Step(MD5_F1, Reg[0], Reg[1], Reg[2], Reg[3], Mes[i],
22015 + MD5Table[i], LShiftVal[i & 0x3]);
22016 +
22017 + // one-word right shift
22018 + Temp = Reg[3];
22019 + Reg[3] = Reg[2];
22020 + Reg[2] = Reg[1];
22021 + Reg[1] = Reg[0];
22022 + Reg[0] = Temp;
22023 + }
22024 + for (i=16; i<32; i++)
22025 + {
22026 + MD5Step(MD5_F2, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(5*(i & 0xf)+1) & 0xf],
22027 + MD5Table[i], LShiftVal[(0x1 << 2)+(i & 0x3)]);
22028 +
22029 + // one-word right shift
22030 + Temp = Reg[3];
22031 + Reg[3] = Reg[2];
22032 + Reg[2] = Reg[1];
22033 + Reg[1] = Reg[0];
22034 + Reg[0] = Temp;
22035 + }
22036 + for (i=32; i<48; i++)
22037 + {
22038 + MD5Step(MD5_F3, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(3*(i & 0xf)+5) & 0xf],
22039 + MD5Table[i], LShiftVal[(0x1 << 3)+(i & 0x3)]);
22040 +
22041 + // one-word right shift
22042 + Temp = Reg[3];
22043 + Reg[3] = Reg[2];
22044 + Reg[2] = Reg[1];
22045 + Reg[1] = Reg[0];
22046 + Reg[0] = Temp;
22047 + }
22048 + for (i=48; i<64; i++)
22049 + {
22050 + MD5Step(MD5_F4, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(7*(i & 0xf)) & 0xf],
22051 + MD5Table[i], LShiftVal[(0x3 << 2)+(i & 0x3)]);
22052 +
22053 + // one-word right shift
22054 + Temp = Reg[3];
22055 + Reg[3] = Reg[2];
22056 + Reg[2] = Reg[1];
22057 + Reg[1] = Reg[0];
22058 + Reg[0] = Temp;
22059 + }
22060 +
22061 +
22062 + // (temporary)output
22063 + for (i=0; i<4; i++)
22064 + Buf[i] += Reg[i];
22065 +
22066 +}
22067 +
22068 +
22069 +
22070 +/* ========================= SHA-1 implementation ========================== */
22071 +// four base functions for SHA-1
22072 +#define SHA1_F1(b, c, d) (((b) & (c)) | ((~b) & (d)))
22073 +#define SHA1_F2(b, c, d) ((b) ^ (c) ^ (d))
22074 +#define SHA1_F3(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
22075 +
22076 +
22077 +#define SHA1Step(f, a, b, c, d, e, w, k) \
22078 + ( e += ( f(b, c, d) + w + k + CYCLIC_LEFT_SHIFT(a, 5)) & 0xffffffff, \
22079 + b = CYCLIC_LEFT_SHIFT(b, 30) )
22080 +
22081 +//Initiate SHA-1 Context satisfied in RFC 3174
22082 +VOID SHAInit(SHA_CTX *pCtx)
22083 +{
22084 + pCtx->Buf[0]=0x67452301;
22085 + pCtx->Buf[1]=0xefcdab89;
22086 + pCtx->Buf[2]=0x98badcfe;
22087 + pCtx->Buf[3]=0x10325476;
22088 + pCtx->Buf[4]=0xc3d2e1f0;
22089 +
22090 + pCtx->LenInBitCount[0]=0;
22091 + pCtx->LenInBitCount[1]=0;
22092 +}
22093 +
22094 +/*
22095 + * Function Description:
22096 + * Update SHA-1 Context, allow of an arrary of octets as the next
22097 + * portion of the message
22098 + *
22099 + * Arguments:
22100 + * pCtx Pointer to SHA-1 context
22101 + * pData Pointer to input data
22102 + * LenInBytes The length of input data (unit: byte)
22103 + *
22104 + * Return Value:
22105 + * error indicate more than pow(2,64) bits of data
22106 + *
22107 + * Note:
22108 + * Called after SHAInit or SHAUpdate(itself)
22109 + */
22110 +UCHAR SHAUpdate(SHA_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes)
22111 +{
22112 + UINT32 TfTimes;
22113 + UINT32 temp1,temp2;
22114 + unsigned int i;
22115 + UCHAR err=1;
22116 +
22117 + temp1 = pCtx->LenInBitCount[0];
22118 + temp2 = pCtx->LenInBitCount[1];
22119 +
22120 + pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3));
22121 + if (pCtx->LenInBitCount[0] < temp1)
22122 + pCtx->LenInBitCount[1]++; //carry in
22123 +
22124 +
22125 + pCtx->LenInBitCount[1] = (UINT32) (pCtx->LenInBitCount[1] +(LenInBytes >> 29));
22126 + if (pCtx->LenInBitCount[1] < temp2)
22127 + return (err); //check total length of original data
22128 +
22129 +
22130 + // mod 64 bytes
22131 + temp1 = (temp1 >> 3) & 0x3f;
22132 +
22133 + // process lacks of 64-byte data
22134 + if (temp1)
22135 + {
22136 + UCHAR *pAds = (UCHAR *) pCtx->Input + temp1;
22137 +
22138 + if ((temp1+LenInBytes) < 64)
22139 + {
22140 + NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes);
22141 + return (0);
22142 + }
22143 +
22144 + NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp1);
22145 + byteReverse((UCHAR *)pCtx->Input, 16);
22146 +
22147 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
22148 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
22149 +
22150 + pData += 64-temp1;
22151 + LenInBytes -= 64-temp1;
22152 + } // end of if (temp1)
22153 +
22154 +
22155 + TfTimes = (LenInBytes >> 6);
22156 +
22157 + for (i=TfTimes; i>0; i--)
22158 + {
22159 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64);
22160 + byteReverse((UCHAR *)pCtx->Input, 16);
22161 +
22162 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
22163 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
22164 + pData += 64;
22165 + LenInBytes -= 64;
22166 + } // end of for
22167 +
22168 + // buffering lacks of 64-byte data
22169 + if(LenInBytes)
22170 + NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes);
22171 +
22172 + return (0);
22173 +
22174 +}
22175 +
22176 +// Append padding bits and length of original message in the tail
22177 +// The message digest has to be completed in the end
22178 +VOID SHAFinal(SHA_CTX *pCtx, UCHAR Digest[20])
22179 +{
22180 + UCHAR Remainder;
22181 + UCHAR PadLenInBytes;
22182 + UCHAR *pAppend=0;
22183 + unsigned int i;
22184 +
22185 + Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f);
22186 +
22187 + pAppend = (UCHAR *)pCtx->Input + Remainder;
22188 +
22189 + PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder);
22190 +
22191 + // padding bits without crossing block(64-byte based) boundary
22192 + if (Remainder < 56)
22193 + {
22194 + *pAppend = 0x80;
22195 + PadLenInBytes --;
22196 +
22197 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes);
22198 +
22199 + // add data-length field, from high to low
22200 + for (i=0; i<4; i++)
22201 + {
22202 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff);
22203 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff);
22204 + }
22205 +
22206 + byteReverse((UCHAR *)pCtx->Input, 16);
22207 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 14);
22208 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
22209 + } // end of if
22210 +
22211 + // padding bits with crossing block(64-byte based) boundary
22212 + else
22213 + {
22214 + // the first block ===
22215 + *pAppend = 0x80;
22216 + PadLenInBytes --;
22217 +
22218 + NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1));
22219 + PadLenInBytes -= (64 - Remainder - 1);
22220 +
22221 + byteReverse((UCHAR *)pCtx->Input, 16);
22222 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
22223 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
22224 +
22225 +
22226 + // the second block ===
22227 + NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes);
22228 +
22229 + // add data-length field
22230 + for (i=0; i<4; i++)
22231 + {
22232 + pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff);
22233 + pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff);
22234 + }
22235 +
22236 + byteReverse((UCHAR *)pCtx->Input, 16);
22237 + NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16);
22238 + SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input);
22239 + } // end of else
22240 +
22241 +
22242 + //Output, bytereverse
22243 + for (i=0; i<20; i++)
22244 + {
22245 + Digest [i] = (UCHAR)(pCtx->Buf[i>>2] >> 8*(3-(i & 0x3)));
22246 + }
22247 +
22248 + NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free
22249 +}
22250 +
22251 +
22252 +// The central algorithm of SHA-1, consists of four rounds and
22253 +// twenty steps per round
22254 +VOID SHATransform(UINT32 Buf[5], UINT32 Mes[20])
22255 +{
22256 + UINT32 Reg[5],Temp;
22257 + unsigned int i;
22258 + UINT32 W[80];
22259 +
22260 + static UINT32 SHA1Table[4] = { 0x5a827999, 0x6ed9eba1,
22261 + 0x8f1bbcdc, 0xca62c1d6 };
22262 +
22263 + Reg[0]=Buf[0];
22264 + Reg[1]=Buf[1];
22265 + Reg[2]=Buf[2];
22266 + Reg[3]=Buf[3];
22267 + Reg[4]=Buf[4];
22268 +
22269 + //the first octet of a word is stored in the 0th element, bytereverse
22270 + for(i = 0; i < 16; i++)
22271 + {
22272 + W[i] = (Mes[i] >> 24) & 0xff;
22273 + W[i] |= (Mes[i] >> 8 ) & 0xff00;
22274 + W[i] |= (Mes[i] << 8 ) & 0xff0000;
22275 + W[i] |= (Mes[i] << 24) & 0xff000000;
22276 + }
22277 +
22278 +
22279 + for (i = 0; i < 64; i++)
22280 + W[16+i] = CYCLIC_LEFT_SHIFT(W[i] ^ W[2+i] ^ W[8+i] ^ W[13+i], 1);
22281 +
22282 +
22283 + // 80 steps in SHA-1 algorithm
22284 + for (i=0; i<80; i++)
22285 + {
22286 + if (i<20)
22287 + SHA1Step(SHA1_F1, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
22288 + W[i], SHA1Table[0]);
22289 +
22290 + else if (i>=20 && i<40)
22291 + SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
22292 + W[i], SHA1Table[1]);
22293 +
22294 + else if (i>=40 && i<60)
22295 + SHA1Step(SHA1_F3, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
22296 + W[i], SHA1Table[2]);
22297 +
22298 + else
22299 + SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4],
22300 + W[i], SHA1Table[3]);
22301 +
22302 +
22303 + // one-word right shift
22304 + Temp = Reg[4];
22305 + Reg[4] = Reg[3];
22306 + Reg[3] = Reg[2];
22307 + Reg[2] = Reg[1];
22308 + Reg[1] = Reg[0];
22309 + Reg[0] = Temp;
22310 +
22311 + } // end of for-loop
22312 +
22313 +
22314 + // (temporary)output
22315 + for (i=0; i<5; i++)
22316 + Buf[i] += Reg[i];
22317 +
22318 +}
22319 +
22320 +
22321 +/* ========================= AES En/Decryption ========================== */
22322 +
22323 +/* forward S-box */
22324 +static uint32 FSb[256] =
22325 +{
22326 + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
22327 + 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
22328 + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
22329 + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
22330 + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
22331 + 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
22332 + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
22333 + 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
22334 + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
22335 + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
22336 + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
22337 + 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
22338 + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
22339 + 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
22340 + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
22341 + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
22342 + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
22343 + 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
22344 + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
22345 + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
22346 + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
22347 + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
22348 + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
22349 + 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
22350 + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
22351 + 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
22352 + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
22353 + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
22354 + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
22355 + 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
22356 + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
22357 + 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
22358 +};
22359 +
22360 +/* forward table */
22361 +#define FT \
22362 +\
22363 + V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \
22364 + V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \
22365 + V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \
22366 + V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \
22367 + V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \
22368 + V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \
22369 + V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \
22370 + V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \
22371 + V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \
22372 + V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \
22373 + V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \
22374 + V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \
22375 + V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \
22376 + V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \
22377 + V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \
22378 + V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \
22379 + V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \
22380 + V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \
22381 + V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \
22382 + V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \
22383 + V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \
22384 + V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \
22385 + V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \
22386 + V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \
22387 + V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \
22388 + V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \
22389 + V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \
22390 + V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \
22391 + V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \
22392 + V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \
22393 + V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \
22394 + V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \
22395 + V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \
22396 + V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \
22397 + V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \
22398 + V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \
22399 + V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \
22400 + V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \
22401 + V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \
22402 + V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \
22403 + V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \
22404 + V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \
22405 + V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \
22406 + V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \
22407 + V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \
22408 + V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \
22409 + V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \
22410 + V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \
22411 + V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \
22412 + V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \
22413 + V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \
22414 + V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \
22415 + V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \
22416 + V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \
22417 + V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \
22418 + V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \
22419 + V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \
22420 + V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \
22421 + V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \
22422 + V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \
22423 + V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \
22424 + V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \
22425 + V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \
22426 + V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A)
22427 +
22428 +#define V(a,b,c,d) 0x##a##b##c##d
22429 +static uint32 FT0[256] = { FT };
22430 +#undef V
22431 +
22432 +#define V(a,b,c,d) 0x##d##a##b##c
22433 +static uint32 FT1[256] = { FT };
22434 +#undef V
22435 +
22436 +#define V(a,b,c,d) 0x##c##d##a##b
22437 +static uint32 FT2[256] = { FT };
22438 +#undef V
22439 +
22440 +#define V(a,b,c,d) 0x##b##c##d##a
22441 +static uint32 FT3[256] = { FT };
22442 +#undef V
22443 +
22444 +#undef FT
22445 +
22446 +/* reverse S-box */
22447 +
22448 +static uint32 RSb[256] =
22449 +{
22450 + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
22451 + 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
22452 + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
22453 + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
22454 + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
22455 + 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
22456 + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
22457 + 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
22458 + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
22459 + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
22460 + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
22461 + 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
22462 + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
22463 + 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
22464 + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
22465 + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
22466 + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
22467 + 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
22468 + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
22469 + 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
22470 + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
22471 + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
22472 + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
22473 + 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
22474 + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
22475 + 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
22476 + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
22477 + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
22478 + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
22479 + 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
22480 + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
22481 + 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
22482 +};
22483 +
22484 +/* reverse table */
22485 +
22486 +#define RT \
22487 +\
22488 + V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \
22489 + V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \
22490 + V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \
22491 + V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \
22492 + V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \
22493 + V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \
22494 + V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \
22495 + V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \
22496 + V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \
22497 + V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \
22498 + V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \
22499 + V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \
22500 + V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \
22501 + V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \
22502 + V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \
22503 + V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \
22504 + V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \
22505 + V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \
22506 + V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \
22507 + V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \
22508 + V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \
22509 + V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \
22510 + V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \
22511 + V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \
22512 + V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \
22513 + V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \
22514 + V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \
22515 + V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \
22516 + V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \
22517 + V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \
22518 + V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \
22519 + V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \
22520 + V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \
22521 + V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \
22522 + V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \
22523 + V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \
22524 + V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \
22525 + V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \
22526 + V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \
22527 + V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \
22528 + V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \
22529 + V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \
22530 + V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \
22531 + V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \
22532 + V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \
22533 + V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \
22534 + V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \
22535 + V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \
22536 + V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \
22537 + V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \
22538 + V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \
22539 + V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \
22540 + V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \
22541 + V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \
22542 + V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \
22543 + V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \
22544 + V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \
22545 + V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \
22546 + V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \
22547 + V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \
22548 + V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \
22549 + V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \
22550 + V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \
22551 + V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42)
22552 +
22553 +#define V(a,b,c,d) 0x##a##b##c##d
22554 +static uint32 RT0[256] = { RT };
22555 +#undef V
22556 +
22557 +#define V(a,b,c,d) 0x##d##a##b##c
22558 +static uint32 RT1[256] = { RT };
22559 +#undef V
22560 +
22561 +#define V(a,b,c,d) 0x##c##d##a##b
22562 +static uint32 RT2[256] = { RT };
22563 +#undef V
22564 +
22565 +#define V(a,b,c,d) 0x##b##c##d##a
22566 +static uint32 RT3[256] = { RT };
22567 +#undef V
22568 +
22569 +#undef RT
22570 +
22571 +/* round constants */
22572 +
22573 +static uint32 RCON[10] =
22574 +{
22575 + 0x01000000, 0x02000000, 0x04000000, 0x08000000,
22576 + 0x10000000, 0x20000000, 0x40000000, 0x80000000,
22577 + 0x1B000000, 0x36000000
22578 +};
22579 +
22580 +/* key schedule tables */
22581 +
22582 +static int KT_init = 1;
22583 +
22584 +static uint32 KT0[256];
22585 +static uint32 KT1[256];
22586 +static uint32 KT2[256];
22587 +static uint32 KT3[256];
22588 +
22589 +/* platform-independant 32-bit integer manipulation macros */
22590 +
22591 +#define GET_UINT32(n,b,i) \
22592 +{ \
22593 + (n) = ( (uint32) (b)[(i) ] << 24 ) \
22594 + | ( (uint32) (b)[(i) + 1] << 16 ) \
22595 + | ( (uint32) (b)[(i) + 2] << 8 ) \
22596 + | ( (uint32) (b)[(i) + 3] ); \
22597 +}
22598 +
22599 +#define PUT_UINT32(n,b,i) \
22600 +{ \
22601 + (b)[(i) ] = (uint8) ( (n) >> 24 ); \
22602 + (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
22603 + (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
22604 + (b)[(i) + 3] = (uint8) ( (n) ); \
22605 +}
22606 +
22607 +/* AES key scheduling routine */
22608 +
22609 +int rtmp_aes_set_key( aes_context *ctx, uint8 *key, int nbits )
22610 +{
22611 + int i;
22612 + uint32 *RK, *SK;
22613 +
22614 + switch( nbits )
22615 + {
22616 + case 128: ctx->nr = 10; break;
22617 + case 192: ctx->nr = 12; break;
22618 + case 256: ctx->nr = 14; break;
22619 + default : return( 1 );
22620 + }
22621 +
22622 + RK = ctx->erk;
22623 +
22624 + for( i = 0; i < (nbits >> 5); i++ )
22625 + {
22626 + GET_UINT32( RK[i], key, i * 4 );
22627 + }
22628 +
22629 + /* setup encryption round keys */
22630 +
22631 + switch( nbits )
22632 + {
22633 + case 128:
22634 +
22635 + for( i = 0; i < 10; i++, RK += 4 )
22636 + {
22637 + RK[4] = RK[0] ^ RCON[i] ^
22638 + ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^
22639 + ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^
22640 + ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^
22641 + ( FSb[ (uint8) ( RK[3] >> 24 ) ] );
22642 +
22643 + RK[5] = RK[1] ^ RK[4];
22644 + RK[6] = RK[2] ^ RK[5];
22645 + RK[7] = RK[3] ^ RK[6];
22646 + }
22647 + break;
22648 +
22649 + case 192:
22650 +
22651 + for( i = 0; i < 8; i++, RK += 6 )
22652 + {
22653 + RK[6] = RK[0] ^ RCON[i] ^
22654 + ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^
22655 + ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^
22656 + ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^
22657 + ( FSb[ (uint8) ( RK[5] >> 24 ) ] );
22658 +
22659 + RK[7] = RK[1] ^ RK[6];
22660 + RK[8] = RK[2] ^ RK[7];
22661 + RK[9] = RK[3] ^ RK[8];
22662 + RK[10] = RK[4] ^ RK[9];
22663 + RK[11] = RK[5] ^ RK[10];
22664 + }
22665 + break;
22666 +
22667 + case 256:
22668 +
22669 + for( i = 0; i < 7; i++, RK += 8 )
22670 + {
22671 + RK[8] = RK[0] ^ RCON[i] ^
22672 + ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^
22673 + ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^
22674 + ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^
22675 + ( FSb[ (uint8) ( RK[7] >> 24 ) ] );
22676 +
22677 + RK[9] = RK[1] ^ RK[8];
22678 + RK[10] = RK[2] ^ RK[9];
22679 + RK[11] = RK[3] ^ RK[10];
22680 +
22681 + RK[12] = RK[4] ^
22682 + ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^
22683 + ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^
22684 + ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^
22685 + ( FSb[ (uint8) ( RK[11] ) ] );
22686 +
22687 + RK[13] = RK[5] ^ RK[12];
22688 + RK[14] = RK[6] ^ RK[13];
22689 + RK[15] = RK[7] ^ RK[14];
22690 + }
22691 + break;
22692 + }
22693 +
22694 + /* setup decryption round keys */
22695 +
22696 + if( KT_init )
22697 + {
22698 + for( i = 0; i < 256; i++ )
22699 + {
22700 + KT0[i] = RT0[ FSb[i] ];
22701 + KT1[i] = RT1[ FSb[i] ];
22702 + KT2[i] = RT2[ FSb[i] ];
22703 + KT3[i] = RT3[ FSb[i] ];
22704 + }
22705 +
22706 + KT_init = 0;
22707 + }
22708 +
22709 + SK = ctx->drk;
22710 +
22711 + *SK++ = *RK++;
22712 + *SK++ = *RK++;
22713 + *SK++ = *RK++;
22714 + *SK++ = *RK++;
22715 +
22716 + for( i = 1; i < ctx->nr; i++ )
22717 + {
22718 + RK -= 8;
22719 +
22720 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22721 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22722 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22723 + KT3[ (uint8) ( *RK ) ]; RK++;
22724 +
22725 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22726 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22727 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22728 + KT3[ (uint8) ( *RK ) ]; RK++;
22729 +
22730 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22731 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22732 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22733 + KT3[ (uint8) ( *RK ) ]; RK++;
22734 +
22735 + *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
22736 + KT1[ (uint8) ( *RK >> 16 ) ] ^
22737 + KT2[ (uint8) ( *RK >> 8 ) ] ^
22738 + KT3[ (uint8) ( *RK ) ]; RK++;
22739 + }
22740 +
22741 + RK -= 8;
22742 +
22743 + *SK++ = *RK++;
22744 + *SK++ = *RK++;
22745 + *SK++ = *RK++;
22746 + *SK++ = *RK++;
22747 +
22748 + return( 0 );
22749 +}
22750 +
22751 +/* AES 128-bit block encryption routine */
22752 +
22753 +void rtmp_aes_encrypt(aes_context *ctx, uint8 input[16], uint8 output[16] )
22754 +{
22755 + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
22756 +
22757 + RK = ctx->erk;
22758 + GET_UINT32( X0, input, 0 ); X0 ^= RK[0];
22759 + GET_UINT32( X1, input, 4 ); X1 ^= RK[1];
22760 + GET_UINT32( X2, input, 8 ); X2 ^= RK[2];
22761 + GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
22762 +
22763 +#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
22764 +{ \
22765 + RK += 4; \
22766 + \
22767 + X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \
22768 + FT1[ (uint8) ( Y1 >> 16 ) ] ^ \
22769 + FT2[ (uint8) ( Y2 >> 8 ) ] ^ \
22770 + FT3[ (uint8) ( Y3 ) ]; \
22771 + \
22772 + X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \
22773 + FT1[ (uint8) ( Y2 >> 16 ) ] ^ \
22774 + FT2[ (uint8) ( Y3 >> 8 ) ] ^ \
22775 + FT3[ (uint8) ( Y0 ) ]; \
22776 + \
22777 + X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \
22778 + FT1[ (uint8) ( Y3 >> 16 ) ] ^ \
22779 + FT2[ (uint8) ( Y0 >> 8 ) ] ^ \
22780 + FT3[ (uint8) ( Y1 ) ]; \
22781 + \
22782 + X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \
22783 + FT1[ (uint8) ( Y0 >> 16 ) ] ^ \
22784 + FT2[ (uint8) ( Y1 >> 8 ) ] ^ \
22785 + FT3[ (uint8) ( Y2 ) ]; \
22786 +}
22787 +
22788 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */
22789 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */
22790 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */
22791 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */
22792 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */
22793 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */
22794 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */
22795 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */
22796 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */
22797 +
22798 + if( ctx->nr > 10 )
22799 + {
22800 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */
22801 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */
22802 + }
22803 +
22804 + if( ctx->nr > 12 )
22805 + {
22806 + AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */
22807 + AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */
22808 + }
22809 +
22810 + /* last round */
22811 +
22812 + RK += 4;
22813 +
22814 + X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
22815 + ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
22816 + ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
22817 + ( FSb[ (uint8) ( Y3 ) ] );
22818 +
22819 + X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
22820 + ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
22821 + ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
22822 + ( FSb[ (uint8) ( Y0 ) ] );
22823 +
22824 + X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
22825 + ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
22826 + ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
22827 + ( FSb[ (uint8) ( Y1 ) ] );
22828 +
22829 + X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
22830 + ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
22831 + ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
22832 + ( FSb[ (uint8) ( Y2 ) ] );
22833 +
22834 + PUT_UINT32( X0, output, 0 );
22835 + PUT_UINT32( X1, output, 4 );
22836 + PUT_UINT32( X2, output, 8 );
22837 + PUT_UINT32( X3, output, 12 );
22838 +}
22839 +
22840 +/* AES 128-bit block decryption routine */
22841 +
22842 +void rtmp_aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] )
22843 +{
22844 + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
22845 +
22846 + RK = ctx->drk;
22847 +
22848 + GET_UINT32( X0, input, 0 ); X0 ^= RK[0];
22849 + GET_UINT32( X1, input, 4 ); X1 ^= RK[1];
22850 + GET_UINT32( X2, input, 8 ); X2 ^= RK[2];
22851 + GET_UINT32( X3, input, 12 ); X3 ^= RK[3];
22852 +
22853 +#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
22854 +{ \
22855 + RK += 4; \
22856 + \
22857 + X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \
22858 + RT1[ (uint8) ( Y3 >> 16 ) ] ^ \
22859 + RT2[ (uint8) ( Y2 >> 8 ) ] ^ \
22860 + RT3[ (uint8) ( Y1 ) ]; \
22861 + \
22862 + X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \
22863 + RT1[ (uint8) ( Y0 >> 16 ) ] ^ \
22864 + RT2[ (uint8) ( Y3 >> 8 ) ] ^ \
22865 + RT3[ (uint8) ( Y2 ) ]; \
22866 + \
22867 + X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \
22868 + RT1[ (uint8) ( Y1 >> 16 ) ] ^ \
22869 + RT2[ (uint8) ( Y0 >> 8 ) ] ^ \
22870 + RT3[ (uint8) ( Y3 ) ]; \
22871 + \
22872 + X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \
22873 + RT1[ (uint8) ( Y2 >> 16 ) ] ^ \
22874 + RT2[ (uint8) ( Y1 >> 8 ) ] ^ \
22875 + RT3[ (uint8) ( Y0 ) ]; \
22876 +}
22877 +
22878 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */
22879 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */
22880 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */
22881 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */
22882 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */
22883 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */
22884 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */
22885 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */
22886 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */
22887 +
22888 + if( ctx->nr > 10 )
22889 + {
22890 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */
22891 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */
22892 + }
22893 +
22894 + if( ctx->nr > 12 )
22895 + {
22896 + AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */
22897 + AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */
22898 + }
22899 +
22900 + /* last round */
22901 +
22902 + RK += 4;
22903 +
22904 + X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
22905 + ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
22906 + ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
22907 + ( RSb[ (uint8) ( Y1 ) ] );
22908 +
22909 + X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
22910 + ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
22911 + ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
22912 + ( RSb[ (uint8) ( Y2 ) ] );
22913 +
22914 + X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
22915 + ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
22916 + ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
22917 + ( RSb[ (uint8) ( Y3 ) ] );
22918 +
22919 + X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
22920 + ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
22921 + ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
22922 + ( RSb[ (uint8) ( Y0 ) ] );
22923 +
22924 + PUT_UINT32( X0, output, 0 );
22925 + PUT_UINT32( X1, output, 4 );
22926 + PUT_UINT32( X2, output, 8 );
22927 + PUT_UINT32( X3, output, 12 );
22928 +}
22929 +
22930 +/*
22931 + ========================================================================
22932 +
22933 + Routine Description:
22934 + SHA1 function
22935 +
22936 + Arguments:
22937 +
22938 + Return Value:
22939 +
22940 + Note:
22941 +
22942 + ========================================================================
22943 +*/
22944 +VOID HMAC_SHA1(
22945 + IN UCHAR *text,
22946 + IN UINT text_len,
22947 + IN UCHAR *key,
22948 + IN UINT key_len,
22949 + IN UCHAR *digest)
22950 +{
22951 + SHA_CTX context;
22952 + UCHAR k_ipad[65]; /* inner padding - key XORd with ipad */
22953 + UCHAR k_opad[65]; /* outer padding - key XORd with opad */
22954 + INT i;
22955 +
22956 + // if key is longer than 64 bytes reset it to key=SHA1(key)
22957 + if (key_len > 64)
22958 + {
22959 + SHA_CTX tctx;
22960 + SHAInit(&tctx);
22961 + SHAUpdate(&tctx, key, key_len);
22962 + SHAFinal(&tctx, key);
22963 + key_len = 20;
22964 + }
22965 + NdisZeroMemory(k_ipad, sizeof(k_ipad));
22966 + NdisZeroMemory(k_opad, sizeof(k_opad));
22967 + NdisMoveMemory(k_ipad, key, key_len);
22968 + NdisMoveMemory(k_opad, key, key_len);
22969 +
22970 + // XOR key with ipad and opad values
22971 + for (i = 0; i < 64; i++)
22972 + {
22973 + k_ipad[i] ^= 0x36;
22974 + k_opad[i] ^= 0x5c;
22975 + }
22976 +
22977 + // perform inner SHA1
22978 + SHAInit(&context); /* init context for 1st pass */
22979 + SHAUpdate(&context, k_ipad, 64); /* start with inner pad */
22980 + SHAUpdate(&context, text, text_len); /* then text of datagram */
22981 + SHAFinal(&context, digest); /* finish up 1st pass */
22982 +
22983 + //perform outer SHA1
22984 + SHAInit(&context); /* init context for 2nd pass */
22985 + SHAUpdate(&context, k_opad, 64); /* start with outer pad */
22986 + SHAUpdate(&context, digest, 20); /* then results of 1st hash */
22987 + SHAFinal(&context, digest); /* finish up 2nd pass */
22988 +
22989 +}
22990 +
22991 +/*
22992 +* F(P, S, c, i) = U1 xor U2 xor ... Uc
22993 +* U1 = PRF(P, S || Int(i))
22994 +* U2 = PRF(P, U1)
22995 +* Uc = PRF(P, Uc-1)
22996 +*/
22997 +
22998 +void F(char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output)
22999 +{
23000 + unsigned char digest[36], digest1[SHA_DIGEST_LEN];
23001 + int i, j;
23002 +
23003 + /* U1 = PRF(P, S || int(i)) */
23004 + memcpy(digest, ssid, ssidlength);
23005 + digest[ssidlength] = (unsigned char)((count>>24) & 0xff);
23006 + digest[ssidlength+1] = (unsigned char)((count>>16) & 0xff);
23007 + digest[ssidlength+2] = (unsigned char)((count>>8) & 0xff);
23008 + digest[ssidlength+3] = (unsigned char)(count & 0xff);
23009 + HMAC_SHA1(digest, ssidlength+4, (unsigned char*) password, (int) strlen(password), digest1); // for WPA update
23010 +
23011 + /* output = U1 */
23012 + memcpy(output, digest1, SHA_DIGEST_LEN);
23013 +
23014 + for (i = 1; i < iterations; i++)
23015 + {
23016 + /* Un = PRF(P, Un-1) */
23017 + HMAC_SHA1(digest1, SHA_DIGEST_LEN, (unsigned char*) password, (int) strlen(password), digest); // for WPA update
23018 + memcpy(digest1, digest, SHA_DIGEST_LEN);
23019 +
23020 + /* output = output xor Un */
23021 + for (j = 0; j < SHA_DIGEST_LEN; j++)
23022 + {
23023 + output[j] ^= digest[j];
23024 + }
23025 + }
23026 +}
23027 +/*
23028 +* password - ascii string up to 63 characters in length
23029 +* ssid - octet string up to 32 octets
23030 +* ssidlength - length of ssid in octets
23031 +* output must be 40 octets in length and outputs 256 bits of key
23032 +*/
23033 +int PasswordHash(char *password, unsigned char *ssid, int ssidlength, unsigned char *output)
23034 +{
23035 + if ((strlen(password) > 63) || (ssidlength > 32))
23036 + return 0;
23037 +
23038 + F(password, ssid, ssidlength, 4096, 1, output);
23039 + F(password, ssid, ssidlength, 4096, 2, &output[SHA_DIGEST_LEN]);
23040 + return 1;
23041 +}
23042 +
23043 +
23044 --- /dev/null
23045 +++ b/drivers/staging/rt3070/common/mlme.c
23046 @@ -0,0 +1,9136 @@
23047 +/*
23048 + *************************************************************************
23049 + * Ralink Tech Inc.
23050 + * 5F., No.36, Taiyuan St., Jhubei City,
23051 + * Hsinchu County 302,
23052 + * Taiwan, R.O.C.
23053 + *
23054 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
23055 + *
23056 + * This program is free software; you can redistribute it and/or modify *
23057 + * it under the terms of the GNU General Public License as published by *
23058 + * the Free Software Foundation; either version 2 of the License, or *
23059 + * (at your option) any later version. *
23060 + * *
23061 + * This program is distributed in the hope that it will be useful, *
23062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23064 + * GNU General Public License for more details. *
23065 + * *
23066 + * You should have received a copy of the GNU General Public License *
23067 + * along with this program; if not, write to the *
23068 + * Free Software Foundation, Inc., *
23069 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23070 + * *
23071 + *************************************************************************
23072 +
23073 + Module Name:
23074 + mlme.c
23075 +
23076 + Abstract:
23077 +
23078 + Revision History:
23079 + Who When What
23080 + -------- ---------- ----------------------------------------------
23081 + John Chang 2004-08-25 Modify from RT2500 code base
23082 + John Chang 2004-09-06 modified for RT2600
23083 +*/
23084 +
23085 +#include "../rt_config.h"
23086 +#include <stdarg.h>
23087 +
23088 +UCHAR CISCO_OUI[] = {0x00, 0x40, 0x96};
23089 +
23090 +UCHAR WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
23091 +UCHAR RSN_OUI[] = {0x00, 0x0f, 0xac};
23092 +UCHAR WAPI_OUI[] = {0x00, 0x14, 0x72};
23093 +UCHAR WME_INFO_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
23094 +UCHAR WME_PARM_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
23095 +UCHAR Ccx2QosInfo[] = {0x00, 0x40, 0x96, 0x04};
23096 +UCHAR RALINK_OUI[] = {0x00, 0x0c, 0x43};
23097 +UCHAR BROADCOM_OUI[] = {0x00, 0x90, 0x4c};
23098 +UCHAR WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
23099 +#ifdef CONFIG_STA_SUPPORT
23100 +#ifdef DOT11_N_SUPPORT
23101 +UCHAR PRE_N_HT_OUI[] = {0x00, 0x90, 0x4c};
23102 +#endif // DOT11_N_SUPPORT //
23103 +#endif // CONFIG_STA_SUPPORT //
23104 +
23105 +UCHAR RateSwitchTable[] = {
23106 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23107 + 0x11, 0x00, 0, 0, 0, // Initial used item after association
23108 + 0x00, 0x00, 0, 40, 101,
23109 + 0x01, 0x00, 1, 40, 50,
23110 + 0x02, 0x00, 2, 35, 45,
23111 + 0x03, 0x00, 3, 20, 45,
23112 + 0x04, 0x21, 0, 30, 50,
23113 + 0x05, 0x21, 1, 20, 50,
23114 + 0x06, 0x21, 2, 20, 50,
23115 + 0x07, 0x21, 3, 15, 50,
23116 + 0x08, 0x21, 4, 15, 30,
23117 + 0x09, 0x21, 5, 10, 25,
23118 + 0x0a, 0x21, 6, 8, 25,
23119 + 0x0b, 0x21, 7, 8, 25,
23120 + 0x0c, 0x20, 12, 15, 30,
23121 + 0x0d, 0x20, 13, 8, 20,
23122 + 0x0e, 0x20, 14, 8, 20,
23123 + 0x0f, 0x20, 15, 8, 25,
23124 + 0x10, 0x22, 15, 8, 25,
23125 + 0x11, 0x00, 0, 0, 0,
23126 + 0x12, 0x00, 0, 0, 0,
23127 + 0x13, 0x00, 0, 0, 0,
23128 + 0x14, 0x00, 0, 0, 0,
23129 + 0x15, 0x00, 0, 0, 0,
23130 + 0x16, 0x00, 0, 0, 0,
23131 + 0x17, 0x00, 0, 0, 0,
23132 + 0x18, 0x00, 0, 0, 0,
23133 + 0x19, 0x00, 0, 0, 0,
23134 + 0x1a, 0x00, 0, 0, 0,
23135 + 0x1b, 0x00, 0, 0, 0,
23136 + 0x1c, 0x00, 0, 0, 0,
23137 + 0x1d, 0x00, 0, 0, 0,
23138 + 0x1e, 0x00, 0, 0, 0,
23139 + 0x1f, 0x00, 0, 0, 0,
23140 +};
23141 +
23142 +UCHAR RateSwitchTable11B[] = {
23143 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23144 + 0x04, 0x03, 0, 0, 0, // Initial used item after association
23145 + 0x00, 0x00, 0, 40, 101,
23146 + 0x01, 0x00, 1, 40, 50,
23147 + 0x02, 0x00, 2, 35, 45,
23148 + 0x03, 0x00, 3, 20, 45,
23149 +};
23150 +
23151 +UCHAR RateSwitchTable11BG[] = {
23152 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23153 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
23154 + 0x00, 0x00, 0, 40, 101,
23155 + 0x01, 0x00, 1, 40, 50,
23156 + 0x02, 0x00, 2, 35, 45,
23157 + 0x03, 0x00, 3, 20, 45,
23158 + 0x04, 0x10, 2, 20, 35,
23159 + 0x05, 0x10, 3, 16, 35,
23160 + 0x06, 0x10, 4, 10, 25,
23161 + 0x07, 0x10, 5, 16, 25,
23162 + 0x08, 0x10, 6, 10, 25,
23163 + 0x09, 0x10, 7, 10, 13,
23164 +};
23165 +
23166 +UCHAR RateSwitchTable11G[] = {
23167 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23168 + 0x08, 0x00, 0, 0, 0, // Initial used item after association
23169 + 0x00, 0x10, 0, 20, 101,
23170 + 0x01, 0x10, 1, 20, 35,
23171 + 0x02, 0x10, 2, 20, 35,
23172 + 0x03, 0x10, 3, 16, 35,
23173 + 0x04, 0x10, 4, 10, 25,
23174 + 0x05, 0x10, 5, 16, 25,
23175 + 0x06, 0x10, 6, 10, 25,
23176 + 0x07, 0x10, 7, 10, 13,
23177 +};
23178 +
23179 +#ifdef DOT11_N_SUPPORT
23180 +UCHAR RateSwitchTable11N1S[] = {
23181 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23182 + 0x09, 0x00, 0, 0, 0, // Initial used item after association
23183 + 0x00, 0x21, 0, 30, 101,
23184 + 0x01, 0x21, 1, 20, 50,
23185 + 0x02, 0x21, 2, 20, 50,
23186 + 0x03, 0x21, 3, 15, 50,
23187 + 0x04, 0x21, 4, 15, 30,
23188 + 0x05, 0x21, 5, 10, 25,
23189 + 0x06, 0x21, 6, 8, 14,
23190 + 0x07, 0x21, 7, 8, 14,
23191 + 0x08, 0x23, 7, 8, 14,
23192 +};
23193 +
23194 +UCHAR RateSwitchTable11N2S[] = {
23195 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23196 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
23197 + 0x00, 0x21, 0, 30, 101,
23198 + 0x01, 0x21, 1, 20, 50,
23199 + 0x02, 0x21, 2, 20, 50,
23200 + 0x03, 0x21, 3, 15, 50,
23201 + 0x04, 0x21, 4, 15, 30,
23202 + 0x05, 0x20, 12, 15, 30,
23203 + 0x06, 0x20, 13, 8, 20,
23204 + 0x07, 0x20, 14, 8, 20,
23205 + 0x08, 0x20, 15, 8, 25,
23206 + 0x09, 0x22, 15, 8, 25,
23207 +};
23208 +
23209 +UCHAR RateSwitchTable11N3S[] = {
23210 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23211 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
23212 + 0x00, 0x21, 0, 30, 101,
23213 + 0x01, 0x21, 1, 20, 50,
23214 + 0x02, 0x21, 2, 20, 50,
23215 + 0x03, 0x21, 3, 15, 50,
23216 + 0x04, 0x21, 4, 15, 30,
23217 + 0x05, 0x20, 12, 15, 30,
23218 + 0x06, 0x20, 13, 8, 20,
23219 + 0x07, 0x20, 14, 8, 20,
23220 + 0x08, 0x20, 15, 8, 25,
23221 + 0x09, 0x22, 15, 8, 25,
23222 +};
23223 +
23224 +UCHAR RateSwitchTable11N2SForABand[] = {
23225 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23226 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
23227 + 0x00, 0x21, 0, 30, 101,
23228 + 0x01, 0x21, 1, 20, 50,
23229 + 0x02, 0x21, 2, 20, 50,
23230 + 0x03, 0x21, 3, 15, 50,
23231 + 0x04, 0x21, 4, 15, 30,
23232 + 0x05, 0x21, 5, 15, 30,
23233 + 0x06, 0x20, 12, 15, 30,
23234 + 0x07, 0x20, 13, 8, 20,
23235 + 0x08, 0x20, 14, 8, 20,
23236 + 0x09, 0x20, 15, 8, 25,
23237 + 0x0a, 0x22, 15, 8, 25,
23238 +};
23239 +
23240 +UCHAR RateSwitchTable11N3SForABand[] = { // 3*3
23241 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23242 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
23243 + 0x00, 0x21, 0, 30, 101,
23244 + 0x01, 0x21, 1, 20, 50,
23245 + 0x02, 0x21, 2, 20, 50,
23246 + 0x03, 0x21, 3, 15, 50,
23247 + 0x04, 0x21, 4, 15, 30,
23248 + 0x05, 0x21, 5, 15, 30,
23249 + 0x06, 0x20, 12, 15, 30,
23250 + 0x07, 0x20, 13, 8, 20,
23251 + 0x08, 0x20, 14, 8, 20,
23252 + 0x09, 0x20, 15, 8, 25,
23253 + 0x0a, 0x22, 15, 8, 25,
23254 +};
23255 +
23256 +UCHAR RateSwitchTable11BGN1S[] = {
23257 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23258 + 0x0d, 0x00, 0, 0, 0, // Initial used item after association
23259 + 0x00, 0x00, 0, 40, 101,
23260 + 0x01, 0x00, 1, 40, 50,
23261 + 0x02, 0x00, 2, 35, 45,
23262 + 0x03, 0x00, 3, 20, 45,
23263 + 0x04, 0x21, 0, 30,101, //50
23264 + 0x05, 0x21, 1, 20, 50,
23265 + 0x06, 0x21, 2, 20, 50,
23266 + 0x07, 0x21, 3, 15, 50,
23267 + 0x08, 0x21, 4, 15, 30,
23268 + 0x09, 0x21, 5, 10, 25,
23269 + 0x0a, 0x21, 6, 8, 14,
23270 + 0x0b, 0x21, 7, 8, 14,
23271 + 0x0c, 0x23, 7, 8, 14,
23272 +};
23273 +
23274 +UCHAR RateSwitchTable11BGN2S[] = {
23275 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23276 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
23277 + 0x00, 0x21, 0, 30,101, //50
23278 + 0x01, 0x21, 1, 20, 50,
23279 + 0x02, 0x21, 2, 20, 50,
23280 + 0x03, 0x21, 3, 15, 50,
23281 + 0x04, 0x21, 4, 15, 30,
23282 + 0x05, 0x20, 12, 15, 30,
23283 + 0x06, 0x20, 13, 8, 20,
23284 + 0x07, 0x20, 14, 8, 20,
23285 + 0x08, 0x20, 15, 8, 25,
23286 + 0x09, 0x22, 15, 8, 25,
23287 +};
23288 +
23289 +UCHAR RateSwitchTable11BGN3S[] = { // 3*3
23290 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23291 + 0x0a, 0x00, 0, 0, 0, // Initial used item after association
23292 + 0x00, 0x21, 0, 30,101, //50
23293 + 0x01, 0x21, 1, 20, 50,
23294 + 0x02, 0x21, 2, 20, 50,
23295 + 0x03, 0x21, 3, 20, 50,
23296 + 0x04, 0x21, 4, 15, 50,
23297 +#if 1
23298 + 0x05, 0x20, 20, 15, 30,
23299 + 0x06, 0x20, 21, 8, 20,
23300 + 0x07, 0x20, 22, 8, 20,
23301 + 0x08, 0x20, 23, 8, 25,
23302 + 0x09, 0x22, 23, 8, 25,
23303 +#else // for RT2860 2*3 test
23304 + 0x05, 0x20, 12, 15, 30,
23305 + 0x06, 0x20, 13, 8, 20,
23306 + 0x07, 0x20, 14, 8, 20,
23307 + 0x08, 0x20, 15, 8, 25,
23308 + 0x09, 0x22, 15, 8, 25,
23309 +#endif
23310 +};
23311 +
23312 +UCHAR RateSwitchTable11BGN2SForABand[] = {
23313 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23314 + 0x0b, 0x09, 0, 0, 0, // Initial used item after association
23315 + 0x00, 0x21, 0, 30,101, //50
23316 + 0x01, 0x21, 1, 20, 50,
23317 + 0x02, 0x21, 2, 20, 50,
23318 + 0x03, 0x21, 3, 15, 50,
23319 + 0x04, 0x21, 4, 15, 30,
23320 + 0x05, 0x21, 5, 15, 30,
23321 + 0x06, 0x20, 12, 15, 30,
23322 + 0x07, 0x20, 13, 8, 20,
23323 + 0x08, 0x20, 14, 8, 20,
23324 + 0x09, 0x20, 15, 8, 25,
23325 + 0x0a, 0x22, 15, 8, 25,
23326 +};
23327 +
23328 +UCHAR RateSwitchTable11BGN3SForABand[] = { // 3*3
23329 +// Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)
23330 + 0x0c, 0x09, 0, 0, 0, // Initial used item after association
23331 + 0x00, 0x21, 0, 30,101, //50
23332 + 0x01, 0x21, 1, 20, 50,
23333 + 0x02, 0x21, 2, 20, 50,
23334 + 0x03, 0x21, 3, 15, 50,
23335 + 0x04, 0x21, 4, 15, 30,
23336 + 0x05, 0x21, 5, 15, 30,
23337 + 0x06, 0x21, 12, 15, 30,
23338 + 0x07, 0x20, 20, 15, 30,
23339 + 0x08, 0x20, 21, 8, 20,
23340 + 0x09, 0x20, 22, 8, 20,
23341 + 0x0a, 0x20, 23, 8, 25,
23342 + 0x0b, 0x22, 23, 8, 25,
23343 +};
23344 +#endif // DOT11_N_SUPPORT //
23345 +
23346 +PUCHAR ReasonString[] = {
23347 + /* 0 */ "Reserved",
23348 + /* 1 */ "Unspecified Reason",
23349 + /* 2 */ "Previous Auth no longer valid",
23350 + /* 3 */ "STA is leaving / has left",
23351 + /* 4 */ "DIS-ASSOC due to inactivity",
23352 + /* 5 */ "AP unable to hanle all associations",
23353 + /* 6 */ "class 2 error",
23354 + /* 7 */ "class 3 error",
23355 + /* 8 */ "STA is leaving / has left",
23356 + /* 9 */ "require auth before assoc/re-assoc",
23357 + /* 10 */ "Reserved",
23358 + /* 11 */ "Reserved",
23359 + /* 12 */ "Reserved",
23360 + /* 13 */ "invalid IE",
23361 + /* 14 */ "MIC error",
23362 + /* 15 */ "4-way handshake timeout",
23363 + /* 16 */ "2-way (group key) handshake timeout",
23364 + /* 17 */ "4-way handshake IE diff among AssosReq/Rsp/Beacon",
23365 + /* 18 */
23366 +};
23367 +
23368 +extern UCHAR OfdmRateToRxwiMCS[];
23369 +// since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate.
23370 +// otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rate
23371 +ULONG BasicRateMask[12] = {0xfffff001 /* 1-Mbps */, 0xfffff003 /* 2 Mbps */, 0xfffff007 /* 5.5 */, 0xfffff00f /* 11 */,
23372 + 0xfffff01f /* 6 */ , 0xfffff03f /* 9 */ , 0xfffff07f /* 12 */ , 0xfffff0ff /* 18 */,
23373 + 0xfffff1ff /* 24 */ , 0xfffff3ff /* 36 */ , 0xfffff7ff /* 48 */ , 0xffffffff /* 54 */};
23374 +
23375 +UCHAR MULTICAST_ADDR[MAC_ADDR_LEN] = {0x1, 0x00, 0x00, 0x00, 0x00, 0x00};
23376 +UCHAR BROADCAST_ADDR[MAC_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
23377 +UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
23378 +
23379 +// e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than
23380 +// this value, then it's quaranteed capable of operating in 36 mbps TX rate in
23381 +// clean environment.
23382 +// TxRate: 1 2 5.5 11 6 9 12 18 24 36 48 54 72 100
23383 +CHAR RssiSafeLevelForTxRate[] ={ -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 };
23384 +
23385 +UCHAR RateIdToMbps[] = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100};
23386 +USHORT RateIdTo500Kbps[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200};
23387 +
23388 +UCHAR SsidIe = IE_SSID;
23389 +UCHAR SupRateIe = IE_SUPP_RATES;
23390 +UCHAR ExtRateIe = IE_EXT_SUPP_RATES;
23391 +#ifdef DOT11_N_SUPPORT
23392 +UCHAR HtCapIe = IE_HT_CAP;
23393 +UCHAR AddHtInfoIe = IE_ADD_HT;
23394 +UCHAR NewExtChanIe = IE_SECONDARY_CH_OFFSET;
23395 +#ifdef DOT11N_DRAFT3
23396 +UCHAR ExtHtCapIe = IE_EXT_CAPABILITY;
23397 +#endif // DOT11N_DRAFT3 //
23398 +#endif // DOT11_N_SUPPORT //
23399 +UCHAR ErpIe = IE_ERP;
23400 +UCHAR DsIe = IE_DS_PARM;
23401 +UCHAR TimIe = IE_TIM;
23402 +UCHAR WpaIe = IE_WPA;
23403 +UCHAR Wpa2Ie = IE_WPA2;
23404 +UCHAR IbssIe = IE_IBSS_PARM;
23405 +UCHAR Ccx2Ie = IE_CCX_V2;
23406 +UCHAR WapiIe = IE_WAPI;
23407 +
23408 +extern UCHAR WPA_OUI[];
23409 +
23410 +UCHAR SES_OUI[] = {0x00, 0x90, 0x4c};
23411 +
23412 +UCHAR ZeroSsid[32] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
23413 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
23414 +
23415 +// Reset the RFIC setting to new series
23416 +RTMP_RF_REGS RF2850RegTable[] = {
23417 +// ch R1 R2 R3(TX0~4=0) R4
23418 + {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b},
23419 + {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f},
23420 + {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b},
23421 + {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f},
23422 + {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b},
23423 + {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f},
23424 + {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b},
23425 + {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f},
23426 + {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b},
23427 + {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f},
23428 + {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b},
23429 + {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f},
23430 + {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b},
23431 + {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193},
23432 +
23433 + // 802.11 UNI / HyperLan 2
23434 + {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3},
23435 + {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193},
23436 + {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183},
23437 + {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3},
23438 + {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b},
23439 + {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b},
23440 + {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193},
23441 + {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3},
23442 + {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b},
23443 + {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183},
23444 + {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193},
23445 + {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}, // Plugfest#4, Day4, change RFR3 left4th 9->5.
23446 +
23447 + // 802.11 HyperLan 2
23448 + {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783},
23449 +
23450 + // 2008.04.30 modified
23451 + // The system team has AN to improve the EVM value
23452 + // for channel 102 to 108 for the RT2850/RT2750 dual band solution.
23453 + {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793},
23454 + {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3},
23455 + {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193},
23456 +
23457 + {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183},
23458 + {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b},
23459 + {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3},
23460 + {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193},
23461 + {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183},
23462 + {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193},
23463 + {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}, // 0x980ed1bb->0x980ed15b required by Rory 20070927
23464 + {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3},
23465 + {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b},
23466 + {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193},
23467 + {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b},
23468 + {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183},
23469 +
23470 + // 802.11 UNII
23471 + {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7},
23472 + {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187},
23473 + {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f},
23474 + {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f},
23475 + {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7},
23476 + {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187},
23477 + {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197},
23478 +
23479 + // Japan
23480 + {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b},
23481 + {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13},
23482 + {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b},
23483 + {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23},
23484 + {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13},
23485 + {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b},
23486 + {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23},
23487 +
23488 + // still lack of MMAC(Japan) ch 34,38,42,46
23489 +};
23490 +UCHAR NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(RTMP_RF_REGS));
23491 +
23492 +FREQUENCY_ITEM FreqItems3020[] =
23493 +{
23494 + /**************************************************/
23495 + // ISM : 2.4 to 2.483 GHz //
23496 + /**************************************************/
23497 + // 11g
23498 + /**************************************************/
23499 + //-CH---N-------R---K-----------
23500 + {1, 241, 2, 2},
23501 + {2, 241, 2, 7},
23502 + {3, 242, 2, 2},
23503 + {4, 242, 2, 7},
23504 + {5, 243, 2, 2},
23505 + {6, 243, 2, 7},
23506 + {7, 244, 2, 2},
23507 + {8, 244, 2, 7},
23508 + {9, 245, 2, 2},
23509 + {10, 245, 2, 7},
23510 + {11, 246, 2, 2},
23511 + {12, 246, 2, 7},
23512 + {13, 247, 2, 2},
23513 + {14, 248, 2, 4},
23514 +};
23515 +//2008/07/10:KH Modified to share this variable
23516 +UCHAR NUM_OF_3020_CHNL=(sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM));
23517 +
23518 +/*
23519 + ==========================================================================
23520 + Description:
23521 + initialize the MLME task and its data structure (queue, spinlock,
23522 + timer, state machines).
23523 +
23524 + IRQL = PASSIVE_LEVEL
23525 +
23526 + Return:
23527 + always return NDIS_STATUS_SUCCESS
23528 +
23529 + ==========================================================================
23530 +*/
23531 +NDIS_STATUS MlmeInit(
23532 + IN PRTMP_ADAPTER pAd)
23533 +{
23534 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
23535 +
23536 + DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n"));
23537 +
23538 + do
23539 + {
23540 + Status = MlmeQueueInit(&pAd->Mlme.Queue);
23541 + if(Status != NDIS_STATUS_SUCCESS)
23542 + break;
23543 +
23544 + pAd->Mlme.bRunning = FALSE;
23545 + NdisAllocateSpinLock(&pAd->Mlme.TaskLock);
23546 +
23547 +#ifdef CONFIG_STA_SUPPORT
23548 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23549 + {
23550 + BssTableInit(&pAd->ScanTab);
23551 +
23552 + // init STA state machines
23553 + AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine, pAd->Mlme.AssocFunc);
23554 + AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine, pAd->Mlme.AuthFunc);
23555 + AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine, pAd->Mlme.AuthRspFunc);
23556 + SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine, pAd->Mlme.SyncFunc);
23557 + WpaPskStateMachineInit(pAd, &pAd->Mlme.WpaPskMachine, pAd->Mlme.WpaPskFunc);
23558 + AironetStateMachineInit(pAd, &pAd->Mlme.AironetMachine, pAd->Mlme.AironetFunc);
23559 +
23560 +#ifdef QOS_DLS_SUPPORT
23561 + DlsStateMachineInit(pAd, &pAd->Mlme.DlsMachine, pAd->Mlme.DlsFunc);
23562 +#endif // QOS_DLS_SUPPORT //
23563 +
23564 +
23565 + // Since we are using switch/case to implement it, the init is different from the above
23566 + // state machine init
23567 + MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL);
23568 + }
23569 +#endif // CONFIG_STA_SUPPORT //
23570 +
23571 +
23572 +
23573 + ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine, pAd->Mlme.ActFunc);
23574 +
23575 + // Init mlme periodic timer
23576 + RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer, GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE);
23577 +
23578 + // Set mlme periodic timer
23579 + RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
23580 +
23581 + // software-based RX Antenna diversity
23582 + RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE);
23583 +
23584 +
23585 +#ifdef CONFIG_STA_SUPPORT
23586 +#endif // CONFIG_STA_SUPPORT //
23587 +
23588 + } while (FALSE);
23589 +
23590 + DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n"));
23591 +
23592 + return Status;
23593 +}
23594 +
23595 +/*
23596 + ==========================================================================
23597 + Description:
23598 + main loop of the MLME
23599 + Pre:
23600 + Mlme has to be initialized, and there are something inside the queue
23601 + Note:
23602 + This function is invoked from MPSetInformation and MPReceive;
23603 + This task guarantee only one MlmeHandler will run.
23604 +
23605 + IRQL = DISPATCH_LEVEL
23606 +
23607 + ==========================================================================
23608 + */
23609 +VOID MlmeHandler(
23610 + IN PRTMP_ADAPTER pAd)
23611 +{
23612 + MLME_QUEUE_ELEM *Elem = NULL;
23613 +
23614 + // Only accept MLME and Frame from peer side, no other (control/data) frame should
23615 + // get into this state machine
23616 +
23617 + NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
23618 + if(pAd->Mlme.bRunning)
23619 + {
23620 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23621 + return;
23622 + }
23623 + else
23624 + {
23625 + pAd->Mlme.bRunning = TRUE;
23626 + }
23627 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23628 +
23629 + while (!MlmeQueueEmpty(&pAd->Mlme.Queue))
23630 + {
23631 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) ||
23632 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
23633 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23634 + {
23635 + DBGPRINT(RT_DEBUG_TRACE, ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n", pAd->Mlme.Queue.Num));
23636 + break;
23637 + }
23638 +
23639 +#ifdef RALINK_ATE
23640 + if(ATE_ON(pAd))
23641 + {
23642 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now in MlmeHandler\n"));
23643 + break;
23644 + }
23645 +#endif // RALINK_ATE //
23646 +
23647 + //From message type, determine which state machine I should drive
23648 + if (MlmeDequeue(&pAd->Mlme.Queue, &Elem))
23649 + {
23650 +#ifdef RT2870
23651 + if (Elem->MsgType == MT2_RESET_CONF)
23652 + {
23653 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! reset MLME state machine !!!\n"));
23654 + MlmeRestartStateMachine(pAd);
23655 + Elem->Occupied = FALSE;
23656 + Elem->MsgLen = 0;
23657 + continue;
23658 + }
23659 +#endif // RT2870 //
23660 +
23661 + // if dequeue success
23662 + switch (Elem->Machine)
23663 + {
23664 + // STA state machines
23665 +#ifdef CONFIG_STA_SUPPORT
23666 + case ASSOC_STATE_MACHINE:
23667 + StateMachinePerformAction(pAd, &pAd->Mlme.AssocMachine, Elem);
23668 + break;
23669 + case AUTH_STATE_MACHINE:
23670 + StateMachinePerformAction(pAd, &pAd->Mlme.AuthMachine, Elem);
23671 + break;
23672 + case AUTH_RSP_STATE_MACHINE:
23673 + StateMachinePerformAction(pAd, &pAd->Mlme.AuthRspMachine, Elem);
23674 + break;
23675 + case SYNC_STATE_MACHINE:
23676 + StateMachinePerformAction(pAd, &pAd->Mlme.SyncMachine, Elem);
23677 + break;
23678 + case MLME_CNTL_STATE_MACHINE:
23679 + MlmeCntlMachinePerformAction(pAd, &pAd->Mlme.CntlMachine, Elem);
23680 + break;
23681 + case WPA_PSK_STATE_MACHINE:
23682 + StateMachinePerformAction(pAd, &pAd->Mlme.WpaPskMachine, Elem);
23683 + break;
23684 +#ifdef LEAP_SUPPORT
23685 + case LEAP_STATE_MACHINE:
23686 + LeapMachinePerformAction(pAd, &pAd->Mlme.LeapMachine, Elem);
23687 + break;
23688 +#endif
23689 + case AIRONET_STATE_MACHINE:
23690 + StateMachinePerformAction(pAd, &pAd->Mlme.AironetMachine, Elem);
23691 + break;
23692 +
23693 +#ifdef QOS_DLS_SUPPORT
23694 + case DLS_STATE_MACHINE:
23695 + StateMachinePerformAction(pAd, &pAd->Mlme.DlsMachine, Elem);
23696 + break;
23697 +#endif // QOS_DLS_SUPPORT //
23698 +#endif // CONFIG_STA_SUPPORT //
23699 +
23700 + case ACTION_STATE_MACHINE:
23701 + StateMachinePerformAction(pAd, &pAd->Mlme.ActMachine, Elem);
23702 + break;
23703 +
23704 +
23705 +
23706 +
23707 + default:
23708 + DBGPRINT(RT_DEBUG_TRACE, ("ERROR: Illegal machine %ld in MlmeHandler()\n", Elem->Machine));
23709 + break;
23710 + } // end of switch
23711 +
23712 + // free MLME element
23713 + Elem->Occupied = FALSE;
23714 + Elem->MsgLen = 0;
23715 +
23716 + }
23717 + else {
23718 + DBGPRINT_ERR(("MlmeHandler: MlmeQueue empty\n"));
23719 + }
23720 + }
23721 +
23722 + NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
23723 + pAd->Mlme.bRunning = FALSE;
23724 + NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
23725 +}
23726 +
23727 +/*
23728 + ==========================================================================
23729 + Description:
23730 + Destructor of MLME (Destroy queue, state machine, spin lock and timer)
23731 + Parameters:
23732 + Adapter - NIC Adapter pointer
23733 + Post:
23734 + The MLME task will no longer work properly
23735 +
23736 + IRQL = PASSIVE_LEVEL
23737 +
23738 + ==========================================================================
23739 + */
23740 +VOID MlmeHalt(
23741 + IN PRTMP_ADAPTER pAd)
23742 +{
23743 + BOOLEAN Cancelled;
23744 +#ifdef RT3070
23745 + UINT32 TxPinCfg = 0x00050F0F;
23746 +#endif // RT3070 //
23747 +
23748 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n"));
23749 +
23750 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23751 + {
23752 + // disable BEACON generation and other BEACON related hardware timers
23753 + AsicDisableSync(pAd);
23754 + }
23755 +
23756 +#ifdef CONFIG_STA_SUPPORT
23757 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23758 + {
23759 +#ifdef QOS_DLS_SUPPORT
23760 + UCHAR i;
23761 +#endif // QOS_DLS_SUPPORT //
23762 + // Cancel pending timers
23763 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
23764 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
23765 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
23766 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
23767 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
23768 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
23769 +
23770 +#ifdef QOS_DLS_SUPPORT
23771 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
23772 + {
23773 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled);
23774 + }
23775 +#endif // QOS_DLS_SUPPORT //
23776 + }
23777 +#endif // CONFIG_STA_SUPPORT //
23778 +
23779 + RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
23780 + RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled);
23781 +
23782 +
23783 +
23784 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
23785 + {
23786 + // Set LED
23787 + RTMPSetLED(pAd, LED_HALT);
23788 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
23789 +#ifdef RT2870
23790 + {
23791 + LED_CFG_STRUC LedCfg;
23792 + RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word);
23793 + LedCfg.field.LedPolar = 0;
23794 + LedCfg.field.RLedMode = 0;
23795 + LedCfg.field.GLedMode = 0;
23796 + LedCfg.field.YLedMode = 0;
23797 + RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word);
23798 + }
23799 +#endif // RT2870 //
23800 +#ifdef RT3070
23801 + //
23802 + // Turn off LNA_PE
23803 + //
23804 + if (IS_RT3070(pAd) || IS_RT3071(pAd))
23805 + {
23806 + TxPinCfg &= 0xFFFFF0F0;
23807 + RTUSBWriteMACRegister(pAd, TX_PIN_CFG, TxPinCfg);
23808 + }
23809 +#endif // RT3070 //
23810 + }
23811 +
23812 + RTMPusecDelay(5000); // 5 msec to gurantee Ant Diversity timer canceled
23813 +
23814 + MlmeQueueDestroy(&pAd->Mlme.Queue);
23815 + NdisFreeSpinLock(&pAd->Mlme.TaskLock);
23816 +
23817 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n"));
23818 +}
23819 +
23820 +VOID MlmeResetRalinkCounters(
23821 + IN PRTMP_ADAPTER pAd)
23822 +{
23823 + pAd->RalinkCounters.LastOneSecRxOkDataCnt = pAd->RalinkCounters.OneSecRxOkDataCnt;
23824 + // clear all OneSecxxx counters.
23825 + pAd->RalinkCounters.OneSecBeaconSentCnt = 0;
23826 + pAd->RalinkCounters.OneSecFalseCCACnt = 0;
23827 + pAd->RalinkCounters.OneSecRxFcsErrCnt = 0;
23828 + pAd->RalinkCounters.OneSecRxOkCnt = 0;
23829 + pAd->RalinkCounters.OneSecTxFailCount = 0;
23830 + pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0;
23831 + pAd->RalinkCounters.OneSecTxRetryOkCount = 0;
23832 + pAd->RalinkCounters.OneSecRxOkDataCnt = 0;
23833 +
23834 + // TODO: for debug only. to be removed
23835 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0;
23836 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0;
23837 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0;
23838 + pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0;
23839 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0;
23840 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0;
23841 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0;
23842 + pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0;
23843 + pAd->RalinkCounters.OneSecTxDoneCount = 0;
23844 + pAd->RalinkCounters.OneSecRxCount = 0;
23845 + pAd->RalinkCounters.OneSecTxAggregationCount = 0;
23846 + pAd->RalinkCounters.OneSecRxAggregationCount = 0;
23847 +
23848 + return;
23849 +}
23850 +
23851 +unsigned long rx_AMSDU;
23852 +unsigned long rx_Total;
23853 +
23854 +/*
23855 + ==========================================================================
23856 + Description:
23857 + This routine is executed periodically to -
23858 + 1. Decide if it's a right time to turn on PwrMgmt bit of all
23859 + outgoiing frames
23860 + 2. Calculate ChannelQuality based on statistics of the last
23861 + period, so that TX rate won't toggling very frequently between a
23862 + successful TX and a failed TX.
23863 + 3. If the calculated ChannelQuality indicated current connection not
23864 + healthy, then a ROAMing attempt is tried here.
23865 +
23866 + IRQL = DISPATCH_LEVEL
23867 +
23868 + ==========================================================================
23869 + */
23870 +#define ADHOC_BEACON_LOST_TIME (8*OS_HZ) // 8 sec
23871 +VOID MlmePeriodicExec(
23872 + IN PVOID SystemSpecific1,
23873 + IN PVOID FunctionContext,
23874 + IN PVOID SystemSpecific2,
23875 + IN PVOID SystemSpecific3)
23876 +{
23877 + ULONG TxTotalCnt;
23878 + PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext;
23879 +
23880 +#ifdef CONFIG_STA_SUPPORT
23881 +#endif // CONFIG_STA_SUPPORT //
23882 +
23883 + // Do nothing if the driver is starting halt state.
23884 + // This might happen when timer already been fired before cancel timer with mlmehalt
23885 + if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_HALT_IN_PROGRESS |
23886 + fRTMP_ADAPTER_RADIO_OFF |
23887 + fRTMP_ADAPTER_RADIO_MEASUREMENT |
23888 + fRTMP_ADAPTER_RESET_IN_PROGRESS))))
23889 + return;
23890 +
23891 + RT28XX_MLME_PRE_SANITY_CHECK(pAd);
23892 +
23893 +#ifdef RALINK_ATE
23894 + /* Do not show RSSI until "Normal 1 second Mlme PeriodicExec". */
23895 + if (ATE_ON(pAd))
23896 + {
23897 + if (pAd->Mlme.PeriodicRound % MLME_TASK_EXEC_MULTIPLE != (MLME_TASK_EXEC_MULTIPLE - 1))
23898 + {
23899 + pAd->Mlme.PeriodicRound ++;
23900 + return;
23901 + }
23902 + }
23903 +#endif // RALINK_ATE //
23904 +
23905 +#ifdef CONFIG_STA_SUPPORT
23906 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23907 + {
23908 + // Do nothing if monitor mode is on
23909 + if (MONITOR_ON(pAd))
23910 + return;
23911 +
23912 + if (pAd->Mlme.PeriodicRound & 0x1)
23913 + {
23914 + // This is the fix for wifi 11n extension channel overlapping test case. for 2860D
23915 + if (((pAd->MACVersion & 0xffff) == 0x0101) &&
23916 + (STA_TGN_WIFI_ON(pAd)) &&
23917 + (pAd->CommonCfg.IOTestParm.bToggle == FALSE))
23918 +
23919 + {
23920 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf);
23921 + pAd->CommonCfg.IOTestParm.bToggle = TRUE;
23922 + }
23923 + else if ((STA_TGN_WIFI_ON(pAd)) &&
23924 + ((pAd->MACVersion & 0xffff) == 0x0101))
23925 + {
23926 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f);
23927 + pAd->CommonCfg.IOTestParm.bToggle = FALSE;
23928 + }
23929 + }
23930 + }
23931 +#endif // CONFIG_STA_SUPPORT //
23932 +
23933 + pAd->bUpdateBcnCntDone = FALSE;
23934 +
23935 +// RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3);
23936 + pAd->Mlme.PeriodicRound ++;
23937 +
23938 +#ifdef RT2870
23939 + // execute every 100ms, update the Tx FIFO Cnt for update Tx Rate.
23940 + NICUpdateFifoStaCounters(pAd);
23941 +#endif // RT2870 //
23942 + // execute every 500ms
23943 + if ((pAd->Mlme.PeriodicRound % 5 == 0) && RTMPAutoRateSwitchCheck(pAd)/*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED))*/)
23944 + {
23945 +#ifdef CONFIG_STA_SUPPORT
23946 + // perform dynamic tx rate switching based on past TX history
23947 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
23948 + {
23949 + if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
23950 + )
23951 + && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)))
23952 + MlmeDynamicTxRateSwitching(pAd);
23953 + }
23954 +#endif // CONFIG_STA_SUPPORT //
23955 + }
23956 +
23957 + // Normal 1 second Mlme PeriodicExec.
23958 + if (pAd->Mlme.PeriodicRound %MLME_TASK_EXEC_MULTIPLE == 0)
23959 + {
23960 + pAd->Mlme.OneSecPeriodicRound ++;
23961 +
23962 +#ifdef RALINK_ATE
23963 + if (ATE_ON(pAd))
23964 + {
23965 + /* request from Baron : move this routine from later to here */
23966 + /* for showing Rx error count in ATE RXFRAME */
23967 + NICUpdateRawCounters(pAd);
23968 + if (pAd->ate.bRxFer == 1)
23969 + {
23970 + pAd->ate.RxTotalCnt += pAd->ate.RxCntPerSec;
23971 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx packet cnt = %d/%d\n", pAd->ate.RxCntPerSec, pAd->ate.RxTotalCnt);
23972 + pAd->ate.RxCntPerSec = 0;
23973 +
23974 + if (pAd->ate.RxAntennaSel == 0)
23975 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi0=%d, AvgRssi1=%d, AvgRssi2=%d\n\n",
23976 + pAd->ate.AvgRssi0, pAd->ate.AvgRssi1, pAd->ate.AvgRssi2);
23977 + else
23978 + ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi=%d\n\n", pAd->ate.AvgRssi0);
23979 + }
23980 + MlmeResetRalinkCounters(pAd);
23981 + return;
23982 + }
23983 +#endif // RALINK_ATE //
23984 +
23985 +
23986 + if (rx_Total)
23987 + {
23988 +
23989 + // reset counters
23990 + rx_AMSDU = 0;
23991 + rx_Total = 0;
23992 + }
23993 +
23994 + //ORIBATimerTimeout(pAd);
23995 +
23996 + // Media status changed, report to NDIS
23997 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE))
23998 + {
23999 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
24000 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
24001 + {
24002 + pAd->IndicateMediaState = NdisMediaStateConnected;
24003 + RTMP_IndicateMediaState(pAd);
24004 +
24005 + }
24006 + else
24007 + {
24008 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
24009 + RTMP_IndicateMediaState(pAd);
24010 + }
24011 + }
24012 +
24013 + NdisGetSystemUpTime(&pAd->Mlme.Now32);
24014 +
24015 + // add the most up-to-date h/w raw counters into software variable, so that
24016 + // the dynamic tuning mechanism below are based on most up-to-date information
24017 + NICUpdateRawCounters(pAd);
24018 +
24019 +#ifdef RT2870
24020 + RT2870_WatchDog(pAd);
24021 +#endif // RT2870 //
24022 +
24023 +#ifdef DOT11_N_SUPPORT
24024 + // Need statistics after read counter. So put after NICUpdateRawCounters
24025 + ORIBATimerTimeout(pAd);
24026 +#endif // DOT11_N_SUPPORT //
24027 +
24028 + // The time period for checking antenna is according to traffic
24029 + {
24030 + if (pAd->Mlme.bEnableAutoAntennaCheck)
24031 + {
24032 + TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
24033 + pAd->RalinkCounters.OneSecTxRetryOkCount +
24034 + pAd->RalinkCounters.OneSecTxFailCount;
24035 +
24036 + // dynamic adjust antenna evaluation period according to the traffic
24037 + if (TxTotalCnt > 50)
24038 + {
24039 + if (pAd->Mlme.OneSecPeriodicRound % 10 == 0)
24040 + {
24041 + AsicEvaluateRxAnt(pAd);
24042 + }
24043 + }
24044 + else
24045 + {
24046 + if (pAd->Mlme.OneSecPeriodicRound % 3 == 0)
24047 + {
24048 + AsicEvaluateRxAnt(pAd);
24049 + }
24050 + }
24051 + }
24052 + }
24053 +
24054 +#ifdef CONFIG_STA_SUPPORT
24055 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
24056 + STAMlmePeriodicExec(pAd);
24057 +#endif // CONFIG_STA_SUPPORT //
24058 +
24059 + MlmeResetRalinkCounters(pAd);
24060 +
24061 +#ifdef CONFIG_STA_SUPPORT
24062 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
24063 + {
24064 + {
24065 + // When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock
24066 + // and sending CTS-to-self over and over.
24067 + // Software Patch Solution:
24068 + // 1. Polling debug state register 0x10F4 every one second.
24069 + // 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred.
24070 + // 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again.
24071 +
24072 + UINT32 MacReg = 0;
24073 +
24074 + RTMP_IO_READ32(pAd, 0x10F4, &MacReg);
24075 + if (((MacReg & 0x20000000) && (MacReg & 0x80)) || ((MacReg & 0x20000000) && (MacReg & 0x20)))
24076 + {
24077 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
24078 + RTMPusecDelay(1);
24079 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC);
24080 +
24081 + DBGPRINT(RT_DEBUG_WARN,("Warning, MAC specific condition occurs \n"));
24082 + }
24083 + }
24084 + }
24085 +#endif // CONFIG_STA_SUPPORT //
24086 +
24087 + RT28XX_MLME_HANDLER(pAd);
24088 + }
24089 +
24090 +
24091 + pAd->bUpdateBcnCntDone = FALSE;
24092 +}
24093 +
24094 +#ifdef CONFIG_STA_SUPPORT
24095 +VOID STAMlmePeriodicExec(
24096 + PRTMP_ADAPTER pAd)
24097 +{
24098 + ULONG TxTotalCnt;
24099 + int i;
24100 +
24101 +//
24102 +// We return here in ATE mode, because the statistics
24103 +// that ATE needs are not collected via this routine.
24104 +//
24105 +#ifdef RALINK_ATE
24106 + // It is supposed that we will never reach here in ATE mode.
24107 + ASSERT(!(ATE_ON(pAd)));
24108 + if (ATE_ON(pAd))
24109 + return;
24110 +#endif // RALINK_ATE //
24111 +
24112 +#ifdef WPA_SUPPLICANT_SUPPORT
24113 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)
24114 +#endif // WPA_SUPPLICANT_SUPPORT //
24115 + {
24116 + // WPA MIC error should block association attempt for 60 seconds
24117 + if (pAd->StaCfg.bBlockAssoc && (pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ) < pAd->Mlme.Now32))
24118 + pAd->StaCfg.bBlockAssoc = FALSE;
24119 + }
24120 +
24121 + if ((pAd->PreMediaState != pAd->IndicateMediaState) && (pAd->CommonCfg.bWirelessEvent))
24122 + {
24123 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
24124 + {
24125 + RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
24126 + }
24127 + pAd->PreMediaState = pAd->IndicateMediaState;
24128 + }
24129 +
24130 +
24131 +
24132 +
24133 + AsicStaBbpTuning(pAd);
24134 +
24135 + TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
24136 + pAd->RalinkCounters.OneSecTxRetryOkCount +
24137 + pAd->RalinkCounters.OneSecTxFailCount;
24138 +
24139 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
24140 + {
24141 + // update channel quality for Roaming and UI LinkQuality display
24142 + MlmeCalculateChannelQuality(pAd, pAd->Mlme.Now32);
24143 + }
24144 +
24145 + // must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if
24146 + // Radio is currently in noisy environment
24147 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
24148 + AsicAdjustTxPower(pAd);
24149 +
24150 + if (INFRA_ON(pAd))
24151 + {
24152 +#ifdef QOS_DLS_SUPPORT
24153 + // Check DLS time out, then tear down those session
24154 + RTMPCheckDLSTimeOut(pAd);
24155 +#endif // QOS_DLS_SUPPORT //
24156 +
24157 + // Is PSM bit consistent with user power management policy?
24158 + // This is the only place that will set PSM bit ON.
24159 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
24160 + MlmeCheckPsmChange(pAd, pAd->Mlme.Now32);
24161 +
24162 + pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt;
24163 +
24164 + if ((pAd->StaCfg.LastBeaconRxTime + 1*OS_HZ < pAd->Mlme.Now32) &&
24165 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
24166 + ((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt < 600)))
24167 + {
24168 + RTMPSetAGCInitValue(pAd, BW_20);
24169 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n", (0x2E + GET_LNA_GAIN(pAd))));
24170 + }
24171 +
24172 + //if ((pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) &&
24173 + // (pAd->RalinkCounters.OneSecTxRetryOkCount == 0))
24174 + {
24175 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable)
24176 + {
24177 + // When APSD is enabled, the period changes as 20 sec
24178 + if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8)
24179 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
24180 + }
24181 + else
24182 + {
24183 + // Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out)
24184 + if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8)
24185 + {
24186 + if (pAd->CommonCfg.bWmmCapable)
24187 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
24188 + else
24189 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE);
24190 + }
24191 + }
24192 + }
24193 +
24194 + if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality))
24195 + {
24196 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount));
24197 + pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE;
24198 + pAd->StaCfg.CCXAdjacentAPLinkDownTime = pAd->StaCfg.LastBeaconRxTime;
24199 +
24200 + // Lost AP, send disconnect & link down event
24201 + LinkDown(pAd, FALSE);
24202 +
24203 +#ifdef WPA_SUPPLICANT_SUPPORT
24204 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
24205 + if (pAd->StaCfg.WpaSupplicantUP)
24206 + {
24207 + union iwreq_data wrqu;
24208 + //send disassociate event to wpa_supplicant
24209 + memset(&wrqu, 0, sizeof(wrqu));
24210 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
24211 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
24212 + }
24213 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
24214 +#endif // WPA_SUPPLICANT_SUPPORT //
24215 +
24216 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
24217 + {
24218 + union iwreq_data wrqu;
24219 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
24220 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
24221 + }
24222 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
24223 +
24224 + // RTMPPatchMacBbpBug(pAd);
24225 + MlmeAutoReconnectLastSSID(pAd);
24226 + }
24227 + else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality))
24228 + {
24229 + pAd->RalinkCounters.BadCQIAutoRecoveryCount ++;
24230 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount));
24231 + MlmeAutoReconnectLastSSID(pAd);
24232 + }
24233 +
24234 + // Add auto seamless roaming
24235 + if (pAd->StaCfg.bFastRoaming)
24236 + {
24237 + SHORT dBmToRoam = (SHORT)pAd->StaCfg.dBmToRoam;
24238 +
24239 + DBGPRINT(RT_DEBUG_TRACE, ("Rssi=%d, dBmToRoam=%d\n", RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2), (CHAR)dBmToRoam));
24240 +
24241 + if (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) <= (CHAR)dBmToRoam)
24242 + {
24243 + MlmeCheckForFastRoaming(pAd, pAd->Mlme.Now32);
24244 + }
24245 + }
24246 + }
24247 + else if (ADHOC_ON(pAd))
24248 + {
24249 + //radar detect
24250 + if ((pAd->CommonCfg.Channel > 14)
24251 + && (pAd->CommonCfg.bIEEE80211H == 1)
24252 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
24253 + {
24254 + RadarDetectPeriodic(pAd);
24255 + }
24256 +
24257 + // If all peers leave, and this STA becomes the last one in this IBSS, then change MediaState
24258 + // to DISCONNECTED. But still holding this IBSS (i.e. sending BEACON) so that other STAs can
24259 + // join later.
24260 + if ((pAd->StaCfg.LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32) &&
24261 + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
24262 + {
24263 + MLME_START_REQ_STRUCT StartReq;
24264 +
24265 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - excessive BEACON lost, last STA in this IBSS, MediaState=Disconnected\n"));
24266 + LinkDown(pAd, FALSE);
24267 +
24268 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
24269 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
24270 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
24271 + }
24272 +
24273 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
24274 + {
24275 + MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[i];
24276 +
24277 + if (pEntry->ValidAsCLI == FALSE)
24278 + continue;
24279 +
24280 + if (pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32)
24281 + MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr);
24282 + }
24283 + }
24284 + else // no INFRA nor ADHOC connection
24285 + {
24286 +
24287 + if (pAd->StaCfg.bScanReqIsFromWebUI &&
24288 + ((pAd->StaCfg.LastScanTime + 30 * OS_HZ) > pAd->Mlme.Now32))
24289 + goto SKIP_AUTO_SCAN_CONN;
24290 + else
24291 + pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
24292 +
24293 + if ((pAd->StaCfg.bAutoReconnect == TRUE)
24294 + && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)
24295 + && (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE))
24296 + {
24297 + if ((pAd->ScanTab.BssNr==0) && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE))
24298 + {
24299 + MLME_SCAN_REQ_STRUCT ScanReq;
24300 +
24301 + if ((pAd->StaCfg.LastScanTime + 10 * OS_HZ) < pAd->Mlme.Now32)
24302 + {
24303 + DBGPRINT(RT_DEBUG_TRACE, ("STAMlmePeriodicExec():CNTL - ScanTab.BssNr==0, start a new ACTIVE scan SSID[%s]\n", pAd->MlmeAux.AutoReconnectSsid));
24304 + ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen, BSS_ANY, SCAN_ACTIVE);
24305 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
24306 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
24307 + // Reset Missed scan number
24308 + pAd->StaCfg.LastScanTime = pAd->Mlme.Now32;
24309 + }
24310 + else if (pAd->StaCfg.BssType == BSS_ADHOC) // Quit the forever scan when in a very clean room
24311 + MlmeAutoReconnectLastSSID(pAd);
24312 + }
24313 + else if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24314 + {
24315 + if ((pAd->Mlme.OneSecPeriodicRound % 7) == 0)
24316 + {
24317 + MlmeAutoScan(pAd);
24318 + pAd->StaCfg.LastScanTime = pAd->Mlme.Now32;
24319 + }
24320 + else
24321 + {
24322 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
24323 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
24324 + {
24325 + if ((pAd->Mlme.OneSecPeriodicRound % 5) == 1)
24326 + MlmeAutoReconnectLastSSID(pAd);
24327 + }
24328 + else
24329 +#endif // CARRIER_DETECTION_SUPPORT //
24330 + MlmeAutoReconnectLastSSID(pAd);
24331 + }
24332 + }
24333 + }
24334 + }
24335 +
24336 +SKIP_AUTO_SCAN_CONN:
24337 +
24338 +#ifdef DOT11_N_SUPPORT
24339 + if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap !=0) && (pAd->MacTab.fAnyBASession == FALSE))
24340 + {
24341 + pAd->MacTab.fAnyBASession = TRUE;
24342 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, FALSE, FALSE);
24343 + }
24344 + else if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap ==0) && (pAd->MacTab.fAnyBASession == TRUE))
24345 + {
24346 + pAd->MacTab.fAnyBASession = FALSE;
24347 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
24348 + }
24349 +#endif // DOT11_N_SUPPORT //
24350 +
24351 +
24352 +#ifdef DOT11_N_SUPPORT
24353 +#ifdef DOT11N_DRAFT3
24354 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SCAN_2040))
24355 + TriEventCounterMaintenance(pAd);
24356 +#endif // DOT11N_DRAFT3 //
24357 +#endif // DOT11_N_SUPPORT //
24358 +
24359 + return;
24360 +}
24361 +
24362 +// Link down report
24363 +VOID LinkDownExec(
24364 + IN PVOID SystemSpecific1,
24365 + IN PVOID FunctionContext,
24366 + IN PVOID SystemSpecific2,
24367 + IN PVOID SystemSpecific3)
24368 +{
24369 +
24370 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
24371 +
24372 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
24373 + RTMP_IndicateMediaState(pAd);
24374 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
24375 +}
24376 +
24377 +// IRQL = DISPATCH_LEVEL
24378 +VOID MlmeAutoScan(
24379 + IN PRTMP_ADAPTER pAd)
24380 +{
24381 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24382 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24383 + {
24384 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Driver auto scan\n"));
24385 + MlmeEnqueue(pAd,
24386 + MLME_CNTL_STATE_MACHINE,
24387 + OID_802_11_BSSID_LIST_SCAN,
24388 + 0,
24389 + NULL);
24390 + RT28XX_MLME_HANDLER(pAd);
24391 + }
24392 +}
24393 +
24394 +// IRQL = DISPATCH_LEVEL
24395 +VOID MlmeAutoReconnectLastSSID(
24396 + IN PRTMP_ADAPTER pAd)
24397 +{
24398 +
24399 +
24400 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24401 + if ((pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) &&
24402 + (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE))
24403 + {
24404 + NDIS_802_11_SSID OidSsid;
24405 + OidSsid.SsidLength = pAd->MlmeAux.AutoReconnectSsidLen;
24406 + NdisMoveMemory(OidSsid.Ssid, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
24407 +
24408 + DBGPRINT(RT_DEBUG_TRACE, ("Driver auto reconnect to last OID_802_11_SSID setting - %s, len - %d\n", pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen));
24409 + MlmeEnqueue(pAd,
24410 + MLME_CNTL_STATE_MACHINE,
24411 + OID_802_11_SSID,
24412 + sizeof(NDIS_802_11_SSID),
24413 + &OidSsid);
24414 + RT28XX_MLME_HANDLER(pAd);
24415 + }
24416 +}
24417 +#endif // CONFIG_STA_SUPPORT //
24418 +
24419 +/*
24420 + ==========================================================================
24421 + Validate SSID for connection try and rescan purpose
24422 + Valid SSID will have visible chars only.
24423 + The valid length is from 0 to 32.
24424 + IRQL = DISPATCH_LEVEL
24425 + ==========================================================================
24426 + */
24427 +BOOLEAN MlmeValidateSSID(
24428 + IN PUCHAR pSsid,
24429 + IN UCHAR SsidLen)
24430 +{
24431 + int index;
24432 +
24433 + if (SsidLen > MAX_LEN_OF_SSID)
24434 + return (FALSE);
24435 +
24436 + // Check each character value
24437 + for (index = 0; index < SsidLen; index++)
24438 + {
24439 + if (pSsid[index] < 0x20)
24440 + return (FALSE);
24441 + }
24442 +
24443 + // All checked
24444 + return (TRUE);
24445 +}
24446 +
24447 +VOID MlmeSelectTxRateTable(
24448 + IN PRTMP_ADAPTER pAd,
24449 + IN PMAC_TABLE_ENTRY pEntry,
24450 + IN PUCHAR *ppTable,
24451 + IN PUCHAR pTableSize,
24452 + IN PUCHAR pInitTxRateIdx)
24453 +{
24454 + do
24455 + {
24456 + // decide the rate table for tuning
24457 + if (pAd->CommonCfg.TxRateTableSize > 0)
24458 + {
24459 + *ppTable = RateSwitchTable;
24460 + *pTableSize = RateSwitchTable[0];
24461 + *pInitTxRateIdx = RateSwitchTable[1];
24462 +
24463 + break;
24464 + }
24465 +
24466 +#ifdef CONFIG_STA_SUPPORT
24467 + if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd))
24468 + {
24469 +#ifdef DOT11_N_SUPPORT
24470 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) &&
24471 + (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24472 + ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24473 + {// 11N 1S Adhoc
24474 + *ppTable = RateSwitchTable11N1S;
24475 + *pTableSize = RateSwitchTable11N1S[0];
24476 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24477 +
24478 + }
24479 + else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) &&
24480 + (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24481 + (pEntry->HTCapability.MCSSet[1] == 0xff) &&
24482 + (pAd->Antenna.field.TxPath == 2))
24483 + {// 11N 2S Adhoc
24484 + if (pAd->LatchRfRegs.Channel <= 14)
24485 + {
24486 + *ppTable = RateSwitchTable11N2S;
24487 + *pTableSize = RateSwitchTable11N2S[0];
24488 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24489 + }
24490 + else
24491 + {
24492 + *ppTable = RateSwitchTable11N2SForABand;
24493 + *pTableSize = RateSwitchTable11N2SForABand[0];
24494 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24495 + }
24496 +
24497 + }
24498 + else
24499 +#endif // DOT11_N_SUPPORT //
24500 + if ((pEntry->RateLen == 4)
24501 +#ifdef DOT11_N_SUPPORT
24502 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24503 +#endif // DOT11_N_SUPPORT //
24504 + )
24505 + {
24506 + *ppTable = RateSwitchTable11B;
24507 + *pTableSize = RateSwitchTable11B[0];
24508 + *pInitTxRateIdx = RateSwitchTable11B[1];
24509 +
24510 + }
24511 + else if (pAd->LatchRfRegs.Channel <= 14)
24512 + {
24513 + *ppTable = RateSwitchTable11BG;
24514 + *pTableSize = RateSwitchTable11BG[0];
24515 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24516 +
24517 + }
24518 + else
24519 + {
24520 + *ppTable = RateSwitchTable11G;
24521 + *pTableSize = RateSwitchTable11G[0];
24522 + *pInitTxRateIdx = RateSwitchTable11G[1];
24523 +
24524 + }
24525 + break;
24526 + }
24527 +#endif // CONFIG_STA_SUPPORT //
24528 +
24529 +#ifdef DOT11_N_SUPPORT
24530 + //if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) &&
24531 + // ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24532 + if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24533 + ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1)))
24534 + {// 11BGN 1S AP
24535 + *ppTable = RateSwitchTable11BGN1S;
24536 + *pTableSize = RateSwitchTable11BGN1S[0];
24537 + *pInitTxRateIdx = RateSwitchTable11BGN1S[1];
24538 +
24539 + break;
24540 + }
24541 +
24542 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) &&
24543 + // (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2))
24544 + if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) &&
24545 + (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2))
24546 + {// 11BGN 2S AP
24547 + if (pAd->LatchRfRegs.Channel <= 14)
24548 + {
24549 + *ppTable = RateSwitchTable11BGN2S;
24550 + *pTableSize = RateSwitchTable11BGN2S[0];
24551 + *pInitTxRateIdx = RateSwitchTable11BGN2S[1];
24552 +
24553 + }
24554 + else
24555 + {
24556 + *ppTable = RateSwitchTable11BGN2SForABand;
24557 + *pTableSize = RateSwitchTable11BGN2SForABand[0];
24558 + *pInitTxRateIdx = RateSwitchTable11BGN2SForABand[1];
24559 +
24560 + }
24561 + break;
24562 + }
24563 +
24564 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1)))
24565 + if ((pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1)))
24566 + {// 11N 1S AP
24567 + *ppTable = RateSwitchTable11N1S;
24568 + *pTableSize = RateSwitchTable11N1S[0];
24569 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24570 +
24571 + break;
24572 + }
24573 +
24574 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2))
24575 + if ((pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2))
24576 + {// 11N 2S AP
24577 + if (pAd->LatchRfRegs.Channel <= 14)
24578 + {
24579 + *ppTable = RateSwitchTable11N2S;
24580 + *pTableSize = RateSwitchTable11N2S[0];
24581 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24582 + }
24583 + else
24584 + {
24585 + *ppTable = RateSwitchTable11N2SForABand;
24586 + *pTableSize = RateSwitchTable11N2SForABand[0];
24587 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24588 + }
24589 +
24590 + break;
24591 + }
24592 +#endif // DOT11_N_SUPPORT //
24593 + //else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24594 + if ((pEntry->RateLen == 4)
24595 +#ifdef DOT11_N_SUPPORT
24596 +//Iverson mark for Adhoc b mode,sta will use rate 54 Mbps when connect with sta b/g/n mode
24597 +// && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24598 +#endif // DOT11_N_SUPPORT //
24599 + )
24600 + {// B only AP
24601 + *ppTable = RateSwitchTable11B;
24602 + *pTableSize = RateSwitchTable11B[0];
24603 + *pInitTxRateIdx = RateSwitchTable11B[1];
24604 +
24605 + break;
24606 + }
24607 +
24608 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24609 + if ((pEntry->RateLen > 8)
24610 +#ifdef DOT11_N_SUPPORT
24611 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24612 +#endif // DOT11_N_SUPPORT //
24613 + )
24614 + {// B/G mixed AP
24615 + *ppTable = RateSwitchTable11BG;
24616 + *pTableSize = RateSwitchTable11BG[0];
24617 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24618 +
24619 + break;
24620 + }
24621 +
24622 + //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24623 + if ((pEntry->RateLen == 8)
24624 +#ifdef DOT11_N_SUPPORT
24625 + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)
24626 +#endif // DOT11_N_SUPPORT //
24627 + )
24628 + {// G only AP
24629 + *ppTable = RateSwitchTable11G;
24630 + *pTableSize = RateSwitchTable11G[0];
24631 + *pInitTxRateIdx = RateSwitchTable11G[1];
24632 +
24633 + break;
24634 + }
24635 +#ifdef DOT11_N_SUPPORT
24636 +#endif // DOT11_N_SUPPORT //
24637 +
24638 +#ifdef CONFIG_STA_SUPPORT
24639 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
24640 + {
24641 +#ifdef DOT11_N_SUPPORT
24642 + //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0))
24643 + if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0))
24644 +#endif // DOT11_N_SUPPORT //
24645 + { // Legacy mode
24646 + if (pAd->CommonCfg.MaxTxRate <= RATE_11)
24647 + {
24648 + *ppTable = RateSwitchTable11B;
24649 + *pTableSize = RateSwitchTable11B[0];
24650 + *pInitTxRateIdx = RateSwitchTable11B[1];
24651 + }
24652 + else if ((pAd->CommonCfg.MaxTxRate > RATE_11) && (pAd->CommonCfg.MinTxRate > RATE_11))
24653 + {
24654 + *ppTable = RateSwitchTable11G;
24655 + *pTableSize = RateSwitchTable11G[0];
24656 + *pInitTxRateIdx = RateSwitchTable11G[1];
24657 +
24658 + }
24659 + else
24660 + {
24661 + *ppTable = RateSwitchTable11BG;
24662 + *pTableSize = RateSwitchTable11BG[0];
24663 + *pInitTxRateIdx = RateSwitchTable11BG[1];
24664 + }
24665 + break;
24666 + }
24667 +#ifdef DOT11_N_SUPPORT
24668 + if (pAd->LatchRfRegs.Channel <= 14)
24669 + {
24670 + if (pAd->CommonCfg.TxStream == 1)
24671 + {
24672 + *ppTable = RateSwitchTable11N1S;
24673 + *pTableSize = RateSwitchTable11N1S[0];
24674 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24675 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n"));
24676 + }
24677 + else
24678 + {
24679 + *ppTable = RateSwitchTable11N2S;
24680 + *pTableSize = RateSwitchTable11N2S[0];
24681 + *pInitTxRateIdx = RateSwitchTable11N2S[1];
24682 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n"));
24683 + }
24684 + }
24685 + else
24686 + {
24687 + if (pAd->CommonCfg.TxStream == 1)
24688 + {
24689 + *ppTable = RateSwitchTable11N1S;
24690 + *pTableSize = RateSwitchTable11N1S[0];
24691 + *pInitTxRateIdx = RateSwitchTable11N1S[1];
24692 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n"));
24693 + }
24694 + else
24695 + {
24696 + *ppTable = RateSwitchTable11N2SForABand;
24697 + *pTableSize = RateSwitchTable11N2SForABand[0];
24698 + *pInitTxRateIdx = RateSwitchTable11N2SForABand[1];
24699 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n"));
24700 + }
24701 + }
24702 +#endif // DOT11_N_SUPPORT //
24703 + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n",
24704 + pAd->StaActive.SupRateLen, pAd->StaActive.ExtRateLen, pAd->StaActive.SupportedPhyInfo.MCSSet[0], pAd->StaActive.SupportedPhyInfo.MCSSet[1]));
24705 + }
24706 +#endif // CONFIG_STA_SUPPORT //
24707 + } while(FALSE);
24708 +}
24709 +
24710 +#ifdef CONFIG_STA_SUPPORT
24711 +/*
24712 + ==========================================================================
24713 + Description:
24714 + This routine checks if there're other APs out there capable for
24715 + roaming. Caller should call this routine only when Link up in INFRA mode
24716 + and channel quality is below CQI_GOOD_THRESHOLD.
24717 +
24718 + IRQL = DISPATCH_LEVEL
24719 +
24720 + Output:
24721 + ==========================================================================
24722 + */
24723 +VOID MlmeCheckForRoaming(
24724 + IN PRTMP_ADAPTER pAd,
24725 + IN ULONG Now32)
24726 +{
24727 + USHORT i;
24728 + BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab;
24729 + BSS_ENTRY *pBss;
24730 +
24731 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForRoaming\n"));
24732 + // put all roaming candidates into RoamTab, and sort in RSSI order
24733 + BssTableInit(pRoamTab);
24734 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
24735 + {
24736 + pBss = &pAd->ScanTab.BssEntry[i];
24737 +
24738 + if ((pBss->LastBeaconRxTime + BEACON_LOST_TIME) < Now32)
24739 + continue; // AP disappear
24740 + if (pBss->Rssi <= RSSI_THRESHOLD_FOR_ROAMING)
24741 + continue; // RSSI too weak. forget it.
24742 + if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
24743 + continue; // skip current AP
24744 + if (pBss->Rssi < (pAd->StaCfg.RssiSample.LastRssi0 + RSSI_DELTA))
24745 + continue; // only AP with stronger RSSI is eligible for roaming
24746 +
24747 + // AP passing all above rules is put into roaming candidate table
24748 + NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY));
24749 + pRoamTab->BssNr += 1;
24750 + }
24751 +
24752 + if (pRoamTab->BssNr > 0)
24753 + {
24754 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24755 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24756 + {
24757 + pAd->RalinkCounters.PoorCQIRoamingCount ++;
24758 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount));
24759 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL);
24760 + RT28XX_MLME_HANDLER(pAd);
24761 + }
24762 + }
24763 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForRoaming(# of candidate= %d)\n",pRoamTab->BssNr));
24764 +}
24765 +
24766 +/*
24767 + ==========================================================================
24768 + Description:
24769 + This routine checks if there're other APs out there capable for
24770 + roaming. Caller should call this routine only when link up in INFRA mode
24771 + and channel quality is below CQI_GOOD_THRESHOLD.
24772 +
24773 + IRQL = DISPATCH_LEVEL
24774 +
24775 + Output:
24776 + ==========================================================================
24777 + */
24778 +VOID MlmeCheckForFastRoaming(
24779 + IN PRTMP_ADAPTER pAd,
24780 + IN ULONG Now)
24781 +{
24782 + USHORT i;
24783 + BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab;
24784 + BSS_ENTRY *pBss;
24785 +
24786 + DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForFastRoaming\n"));
24787 + // put all roaming candidates into RoamTab, and sort in RSSI order
24788 + BssTableInit(pRoamTab);
24789 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
24790 + {
24791 + pBss = &pAd->ScanTab.BssEntry[i];
24792 +
24793 + if ((pBss->Rssi <= -50) && (pBss->Channel == pAd->CommonCfg.Channel))
24794 + continue; // RSSI too weak. forget it.
24795 + if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
24796 + continue; // skip current AP
24797 + if (!SSID_EQUAL(pBss->Ssid, pBss->SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))
24798 + continue; // skip different SSID
24799 + if (pBss->Rssi < (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) + RSSI_DELTA))
24800 + continue; // skip AP without better RSSI
24801 +
24802 + DBGPRINT(RT_DEBUG_TRACE, ("LastRssi0 = %d, pBss->Rssi = %d\n", RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2), pBss->Rssi));
24803 + // AP passing all above rules is put into roaming candidate table
24804 + NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY));
24805 + pRoamTab->BssNr += 1;
24806 + }
24807 +
24808 + if (pRoamTab->BssNr > 0)
24809 + {
24810 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24811 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
24812 + {
24813 + pAd->RalinkCounters.PoorCQIRoamingCount ++;
24814 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount));
24815 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL);
24816 + RT28XX_MLME_HANDLER(pAd);
24817 + }
24818 + }
24819 + // Maybe site survey required
24820 + else
24821 + {
24822 + if ((pAd->StaCfg.LastScanTime + 10 * 1000) < Now)
24823 + {
24824 + // check CntlMachine.CurrState to avoid collision with NDIS SetOID request
24825 + DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming, No eligable entry, try new scan!\n"));
24826 + pAd->StaCfg.ScanCnt = 2;
24827 + pAd->StaCfg.LastScanTime = Now;
24828 + MlmeAutoScan(pAd);
24829 + }
24830 + }
24831 +
24832 + DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForFastRoaming (BssNr=%d)\n", pRoamTab->BssNr));
24833 +}
24834 +
24835 +/*
24836 + ==========================================================================
24837 + Description:
24838 + This routine calculates TxPER, RxPER of the past N-sec period. And
24839 + according to the calculation result, ChannelQuality is calculated here
24840 + to decide if current AP is still doing the job.
24841 +
24842 + If ChannelQuality is not good, a ROAMing attempt may be tried later.
24843 + Output:
24844 + StaCfg.ChannelQuality - 0..100
24845 +
24846 + IRQL = DISPATCH_LEVEL
24847 +
24848 + NOTE: This routine decide channle quality based on RX CRC error ratio.
24849 + Caller should make sure a function call to NICUpdateRawCounters(pAd)
24850 + is performed right before this routine, so that this routine can decide
24851 + channel quality based on the most up-to-date information
24852 + ==========================================================================
24853 + */
24854 +VOID MlmeCalculateChannelQuality(
24855 + IN PRTMP_ADAPTER pAd,
24856 + IN ULONG Now32)
24857 +{
24858 + ULONG TxOkCnt, TxCnt, TxPER, TxPRR;
24859 + ULONG RxCnt, RxPER;
24860 + UCHAR NorRssi;
24861 + CHAR MaxRssi;
24862 + ULONG BeaconLostTime = BEACON_LOST_TIME;
24863 +
24864 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
24865 + // longer beacon lost time when carrier detection enabled
24866 + if (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
24867 + {
24868 + BeaconLostTime = BEACON_LOST_TIME + BEACON_LOST_TIME/2;
24869 + }
24870 +#endif // CARRIER_DETECTION_SUPPORT //
24871 +
24872 + MaxRssi = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
24873 +
24874 + //
24875 + // calculate TX packet error ratio and TX retry ratio - if too few TX samples, skip TX related statistics
24876 + //
24877 + TxOkCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + pAd->RalinkCounters.OneSecTxRetryOkCount;
24878 + TxCnt = TxOkCnt + pAd->RalinkCounters.OneSecTxFailCount;
24879 + if (TxCnt < 5)
24880 + {
24881 + TxPER = 0;
24882 + TxPRR = 0;
24883 + }
24884 + else
24885 + {
24886 + TxPER = (pAd->RalinkCounters.OneSecTxFailCount * 100) / TxCnt;
24887 + TxPRR = ((TxCnt - pAd->RalinkCounters.OneSecTxNoRetryOkCount) * 100) / TxCnt;
24888 + }
24889 +
24890 + //
24891 + // calculate RX PER - don't take RxPER into consideration if too few sample
24892 + //
24893 + RxCnt = pAd->RalinkCounters.OneSecRxOkCnt + pAd->RalinkCounters.OneSecRxFcsErrCnt;
24894 + if (RxCnt < 5)
24895 + RxPER = 0;
24896 + else
24897 + RxPER = (pAd->RalinkCounters.OneSecRxFcsErrCnt * 100) / RxCnt;
24898 +
24899 + //
24900 + // decide ChannelQuality based on: 1)last BEACON received time, 2)last RSSI, 3)TxPER, and 4)RxPER
24901 + //
24902 + if (INFRA_ON(pAd) &&
24903 + (pAd->RalinkCounters.OneSecTxNoRetryOkCount < 2) && // no heavy traffic
24904 + (pAd->StaCfg.LastBeaconRxTime + BeaconLostTime < Now32))
24905 + {
24906 + DBGPRINT(RT_DEBUG_TRACE, ("BEACON lost > %ld msec with TxOkCnt=%ld -> CQI=0\n", BeaconLostTime, TxOkCnt));
24907 + pAd->Mlme.ChannelQuality = 0;
24908 + }
24909 + else
24910 + {
24911 + // Normalize Rssi
24912 + if (MaxRssi > -40)
24913 + NorRssi = 100;
24914 + else if (MaxRssi < -90)
24915 + NorRssi = 0;
24916 + else
24917 + NorRssi = (MaxRssi + 90) * 2;
24918 +
24919 + // ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER (RSSI 0..100), (TxPER 100..0), (RxPER 100..0)
24920 + pAd->Mlme.ChannelQuality = (RSSI_WEIGHTING * NorRssi +
24921 + TX_WEIGHTING * (100 - TxPRR) +
24922 + RX_WEIGHTING* (100 - RxPER)) / 100;
24923 + if (pAd->Mlme.ChannelQuality >= 100)
24924 + pAd->Mlme.ChannelQuality = 100;
24925 + }
24926 +
24927 +}
24928 +
24929 +VOID MlmeSetTxRate(
24930 + IN PRTMP_ADAPTER pAd,
24931 + IN PMAC_TABLE_ENTRY pEntry,
24932 + IN PRTMP_TX_RATE_SWITCH pTxRate)
24933 +{
24934 + UCHAR MaxMode = MODE_OFDM;
24935 +
24936 +#ifdef DOT11_N_SUPPORT
24937 + MaxMode = MODE_HTGREENFIELD;
24938 +
24939 + if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC) && (pAd->Antenna.field.TxPath == 2))
24940 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE;
24941 + else
24942 +#endif // DOT11_N_SUPPORT //
24943 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
24944 +
24945 + if (pTxRate->CurrMCS < MCS_AUTO)
24946 + pAd->StaCfg.HTPhyMode.field.MCS = pTxRate->CurrMCS;
24947 +
24948 + if (pAd->StaCfg.HTPhyMode.field.MCS > 7)
24949 + pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
24950 +
24951 + if (ADHOC_ON(pAd))
24952 + {
24953 + // If peer adhoc is b-only mode, we can't send 11g rate.
24954 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24955 + pEntry->HTPhyMode.field.STBC = STBC_NONE;
24956 +
24957 + //
24958 + // For Adhoc MODE_CCK, driver will use AdhocBOnlyJoined flag to roll back to B only if necessary
24959 + //
24960 + pEntry->HTPhyMode.field.MODE = pTxRate->Mode;
24961 + pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI;
24962 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24963 +
24964 + // Patch speed error in status page
24965 + pAd->StaCfg.HTPhyMode.field.MODE = pEntry->HTPhyMode.field.MODE;
24966 + }
24967 + else
24968 + {
24969 + if (pTxRate->Mode <= MaxMode)
24970 + pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode;
24971 +
24972 +#ifdef DOT11_N_SUPPORT
24973 + if (pTxRate->ShortGI && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI))
24974 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400;
24975 + else
24976 +#endif // DOT11_N_SUPPORT //
24977 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24978 +
24979 +#ifdef DOT11_N_SUPPORT
24980 + // Reexam each bandwidth's SGI support.
24981 + if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400)
24982 + {
24983 + if ((pEntry->HTPhyMode.field.BW == BW_20) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE)))
24984 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24985 + if ((pEntry->HTPhyMode.field.BW == BW_40) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE)))
24986 + pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
24987 + }
24988 +
24989 + // Turn RTS/CTS rate to 6Mbps.
24990 + if ((pEntry->HTPhyMode.field.MCS == 0) && (pAd->StaCfg.HTPhyMode.field.MCS != 0))
24991 + {
24992 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
24993 + if (pAd->MacTab.fAnyBASession)
24994 + {
24995 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
24996 + }
24997 + else
24998 + {
24999 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
25000 + }
25001 + }
25002 + else if ((pEntry->HTPhyMode.field.MCS == 8) && (pAd->StaCfg.HTPhyMode.field.MCS != 8))
25003 + {
25004 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
25005 + if (pAd->MacTab.fAnyBASession)
25006 + {
25007 + AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
25008 + }
25009 + else
25010 + {
25011 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
25012 + }
25013 + }
25014 + else if ((pEntry->HTPhyMode.field.MCS != 0) && (pAd->StaCfg.HTPhyMode.field.MCS == 0))
25015 + {
25016 + AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
25017 +
25018 + }
25019 + else if ((pEntry->HTPhyMode.field.MCS != 8) && (pAd->StaCfg.HTPhyMode.field.MCS == 8))
25020 + {
25021 + AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent);
25022 + }
25023 +#endif // DOT11_N_SUPPORT //
25024 +
25025 + pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC;
25026 + pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI;
25027 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
25028 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
25029 +#ifdef DOT11_N_SUPPORT
25030 + if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD) &&
25031 + pAd->WIFItestbed.bGreenField)
25032 + pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD;
25033 +#endif // DOT11_N_SUPPORT //
25034 + }
25035 +
25036 + pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
25037 +}
25038 +
25039 +/*
25040 + ==========================================================================
25041 + Description:
25042 + This routine calculates the acumulated TxPER of eaxh TxRate. And
25043 + according to the calculation result, change CommonCfg.TxRate which
25044 + is the stable TX Rate we expect the Radio situation could sustained.
25045 +
25046 + CommonCfg.TxRate will change dynamically within {RATE_1/RATE_6, MaxTxRate}
25047 + Output:
25048 + CommonCfg.TxRate -
25049 +
25050 + IRQL = DISPATCH_LEVEL
25051 +
25052 + NOTE:
25053 + call this routine every second
25054 + ==========================================================================
25055 + */
25056 +VOID MlmeDynamicTxRateSwitching(
25057 + IN PRTMP_ADAPTER pAd)
25058 +{
25059 + UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx;
25060 + ULONG i, AccuTxTotalCnt = 0, TxTotalCnt;
25061 + ULONG TxErrorRatio = 0;
25062 + BOOLEAN bTxRateChanged, bUpgradeQuality = FALSE;
25063 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL;
25064 + PUCHAR pTable;
25065 + UCHAR TableSize = 0;
25066 + UCHAR InitTxRateIdx = 0, TrainUp, TrainDown;
25067 + CHAR Rssi, RssiOffset = 0;
25068 + TX_STA_CNT1_STRUC StaTx1;
25069 + TX_STA_CNT0_STRUC TxStaCnt0;
25070 + ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
25071 + MAC_TABLE_ENTRY *pEntry;
25072 +
25073 +#ifdef RALINK_ATE
25074 + if (ATE_ON(pAd))
25075 + {
25076 + return;
25077 + }
25078 +#endif // RALINK_ATE //
25079 +
25080 + //
25081 + // walk through MAC table, see if need to change AP's TX rate toward each entry
25082 + //
25083 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
25084 + {
25085 + pEntry = &pAd->MacTab.Content[i];
25086 +
25087 + // check if this entry need to switch rate automatically
25088 + if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
25089 + continue;
25090 +
25091 + if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls))
25092 + {
25093 + Rssi = RTMPMaxRssi(pAd,
25094 + pAd->StaCfg.RssiSample.AvgRssi0,
25095 + pAd->StaCfg.RssiSample.AvgRssi1,
25096 + pAd->StaCfg.RssiSample.AvgRssi2);
25097 +
25098 + // Update statistic counter
25099 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
25100 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
25101 + pAd->bUpdateBcnCntDone = TRUE;
25102 + TxRetransmit = StaTx1.field.TxRetransmit;
25103 + TxSuccess = StaTx1.field.TxSuccess;
25104 + TxFailCount = TxStaCnt0.field.TxFailCount;
25105 + TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
25106 +
25107 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
25108 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
25109 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
25110 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
25111 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
25112 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
25113 +
25114 + // if no traffic in the past 1-sec period, don't change TX rate,
25115 + // but clear all bad history. because the bad history may affect the next
25116 + // Chariot throughput test
25117 + AccuTxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
25118 + pAd->RalinkCounters.OneSecTxRetryOkCount +
25119 + pAd->RalinkCounters.OneSecTxFailCount;
25120 +
25121 + if (TxTotalCnt)
25122 + TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt;
25123 + }
25124 + else
25125 + {
25126 + if (INFRA_ON(pAd) && (i == 1))
25127 + Rssi = RTMPMaxRssi(pAd,
25128 + pAd->StaCfg.RssiSample.AvgRssi0,
25129 + pAd->StaCfg.RssiSample.AvgRssi1,
25130 + pAd->StaCfg.RssiSample.AvgRssi2);
25131 + else
25132 + Rssi = RTMPMaxRssi(pAd,
25133 + pEntry->RssiSample.AvgRssi0,
25134 + pEntry->RssiSample.AvgRssi1,
25135 + pEntry->RssiSample.AvgRssi2);
25136 +
25137 + TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
25138 + pEntry->OneSecTxRetryOkCount +
25139 + pEntry->OneSecTxFailCount;
25140 +
25141 + if (TxTotalCnt)
25142 + TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt;
25143 + }
25144 +
25145 + CurrRateIdx = pEntry->CurrTxRateIndex;
25146 +
25147 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx);
25148 +
25149 + if (CurrRateIdx >= TableSize)
25150 + {
25151 + CurrRateIdx = TableSize - 1;
25152 + }
25153 +
25154 + // When switch from Fixed rate -> auto rate, the REAL TX rate might be different from pAd->CommonCfg.TxRateIndex.
25155 + // So need to sync here.
25156 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
25157 + if ((pEntry->HTPhyMode.field.MCS != pCurrTxRate->CurrMCS)
25158 + //&& (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
25159 + )
25160 + {
25161 +
25162 + // Need to sync Real Tx rate and our record.
25163 + // Then return for next DRS.
25164 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(InitTxRateIdx+1)*5];
25165 + pEntry->CurrTxRateIndex = InitTxRateIdx;
25166 + MlmeSetTxRate(pAd, pEntry, pCurrTxRate);
25167 +
25168 + // reset all OneSecTx counters
25169 + RESET_ONE_SEC_TX_CNT(pEntry);
25170 + continue;
25171 + }
25172 +
25173 + // decide the next upgrade rate and downgrade rate, if any
25174 + if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1)))
25175 + {
25176 + UpRateIdx = CurrRateIdx + 1;
25177 + DownRateIdx = CurrRateIdx -1;
25178 + }
25179 + else if (CurrRateIdx == 0)
25180 + {
25181 + UpRateIdx = CurrRateIdx + 1;
25182 + DownRateIdx = CurrRateIdx;
25183 + }
25184 + else if (CurrRateIdx == (TableSize - 1))
25185 + {
25186 + UpRateIdx = CurrRateIdx;
25187 + DownRateIdx = CurrRateIdx - 1;
25188 + }
25189 +
25190 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
25191 +
25192 +#ifdef DOT11_N_SUPPORT
25193 + if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX))
25194 + {
25195 + TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1));
25196 + TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1));
25197 + }
25198 + else
25199 +#endif // DOT11_N_SUPPORT //
25200 + {
25201 + TrainUp = pCurrTxRate->TrainUp;
25202 + TrainDown = pCurrTxRate->TrainDown;
25203 + }
25204 +
25205 + //pAd->DrsCounters.LastTimeTxRateChangeAction = pAd->DrsCounters.LastSecTxRateChangeAction;
25206 +
25207 + //
25208 + // Keep the last time TxRateChangeAction status.
25209 + //
25210 + pEntry->LastTimeTxRateChangeAction = pEntry->LastSecTxRateChangeAction;
25211 +
25212 +
25213 +
25214 + //
25215 + // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI
25216 + // (criteria copied from RT2500 for Netopia case)
25217 + //
25218 + if (TxTotalCnt <= 15)
25219 + {
25220 + CHAR idx = 0;
25221 + UCHAR TxRateIdx;
25222 + //UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS7 = 0, MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0;
25223 + UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS5 =0, MCS6 = 0, MCS7 = 0;
25224 + UCHAR MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0;
25225 + UCHAR MCS20 = 0, MCS21 = 0, MCS22 = 0, MCS23 = 0; // 3*3
25226 +
25227 + // check the existence and index of each needed MCS
25228 + while (idx < pTable[0])
25229 + {
25230 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(idx+1)*5];
25231 +
25232 + if (pCurrTxRate->CurrMCS == MCS_0)
25233 + {
25234 + MCS0 = idx;
25235 + }
25236 + else if (pCurrTxRate->CurrMCS == MCS_1)
25237 + {
25238 + MCS1 = idx;
25239 + }
25240 + else if (pCurrTxRate->CurrMCS == MCS_2)
25241 + {
25242 + MCS2 = idx;
25243 + }
25244 + else if (pCurrTxRate->CurrMCS == MCS_3)
25245 + {
25246 + MCS3 = idx;
25247 + }
25248 + else if (pCurrTxRate->CurrMCS == MCS_4)
25249 + {
25250 + MCS4 = idx;
25251 + }
25252 + else if (pCurrTxRate->CurrMCS == MCS_5)
25253 + {
25254 + MCS5 = idx;
25255 + }
25256 + else if (pCurrTxRate->CurrMCS == MCS_6)
25257 + {
25258 + MCS6 = idx;
25259 + }
25260 + //else if (pCurrTxRate->CurrMCS == MCS_7)
25261 + else if ((pCurrTxRate->CurrMCS == MCS_7) && (pCurrTxRate->ShortGI == GI_800)) // prevent the highest MCS using short GI when 1T and low throughput
25262 + {
25263 + MCS7 = idx;
25264 + }
25265 + else if (pCurrTxRate->CurrMCS == MCS_12)
25266 + {
25267 + MCS12 = idx;
25268 + }
25269 + else if (pCurrTxRate->CurrMCS == MCS_13)
25270 + {
25271 + MCS13 = idx;
25272 + }
25273 + else if (pCurrTxRate->CurrMCS == MCS_14)
25274 + {
25275 + MCS14 = idx;
25276 + }
25277 + else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800))
25278 + {
25279 + MCS15 = idx;
25280 + }
25281 + else if (pCurrTxRate->CurrMCS == MCS_20) // 3*3
25282 + {
25283 + MCS20 = idx;
25284 + }
25285 + else if (pCurrTxRate->CurrMCS == MCS_21)
25286 + {
25287 + MCS21 = idx;
25288 + }
25289 + else if (pCurrTxRate->CurrMCS == MCS_22)
25290 + {
25291 + MCS22 = idx;
25292 + }
25293 + else if (pCurrTxRate->CurrMCS == MCS_23)
25294 + {
25295 + MCS23 = idx;
25296 + }
25297 + idx ++;
25298 + }
25299 +
25300 + if (pAd->LatchRfRegs.Channel <= 14)
25301 + {
25302 + if (pAd->NicConfig2.field.ExternalLNAForG)
25303 + {
25304 + RssiOffset = 2;
25305 + }
25306 + else
25307 + {
25308 + RssiOffset = 5;
25309 + }
25310 + }
25311 + else
25312 + {
25313 + if (pAd->NicConfig2.field.ExternalLNAForA)
25314 + {
25315 + RssiOffset = 5;
25316 + }
25317 + else
25318 + {
25319 + RssiOffset = 8;
25320 + }
25321 + }
25322 +#ifdef DOT11_N_SUPPORT
25323 + /*if (MCS15)*/
25324 + if ((pTable == RateSwitchTable11BGN3S) ||
25325 + (pTable == RateSwitchTable11N3S) ||
25326 + (pTable == RateSwitchTable))
25327 + {// N mode with 3 stream // 3*3
25328 + if (MCS23 && (Rssi >= -70))
25329 + TxRateIdx = MCS15;
25330 + else if (MCS22 && (Rssi >= -72))
25331 + TxRateIdx = MCS14;
25332 + else if (MCS21 && (Rssi >= -76))
25333 + TxRateIdx = MCS13;
25334 + else if (MCS20 && (Rssi >= -78))
25335 + TxRateIdx = MCS12;
25336 + else if (MCS4 && (Rssi >= -82))
25337 + TxRateIdx = MCS4;
25338 + else if (MCS3 && (Rssi >= -84))
25339 + TxRateIdx = MCS3;
25340 + else if (MCS2 && (Rssi >= -86))
25341 + TxRateIdx = MCS2;
25342 + else if (MCS1 && (Rssi >= -88))
25343 + TxRateIdx = MCS1;
25344 + else
25345 + TxRateIdx = MCS0;
25346 + }
25347 +// else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand) || (pTable == RateSwitchTable))
25348 + else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand)) // 3*3
25349 + {// N mode with 2 stream
25350 + if (MCS15 && (Rssi >= (-70+RssiOffset)))
25351 + TxRateIdx = MCS15;
25352 + else if (MCS14 && (Rssi >= (-72+RssiOffset)))
25353 + TxRateIdx = MCS14;
25354 + else if (MCS13 && (Rssi >= (-76+RssiOffset)))
25355 + TxRateIdx = MCS13;
25356 + else if (MCS12 && (Rssi >= (-78+RssiOffset)))
25357 + TxRateIdx = MCS12;
25358 + else if (MCS4 && (Rssi >= (-82+RssiOffset)))
25359 + TxRateIdx = MCS4;
25360 + else if (MCS3 && (Rssi >= (-84+RssiOffset)))
25361 + TxRateIdx = MCS3;
25362 + else if (MCS2 && (Rssi >= (-86+RssiOffset)))
25363 + TxRateIdx = MCS2;
25364 + else if (MCS1 && (Rssi >= (-88+RssiOffset)))
25365 + TxRateIdx = MCS1;
25366 + else
25367 + TxRateIdx = MCS0;
25368 + }
25369 + else if ((pTable == RateSwitchTable11BGN1S) || (pTable == RateSwitchTable11N1S))
25370 + {// N mode with 1 stream
25371 + if (MCS7 && (Rssi > (-72+RssiOffset)))
25372 + TxRateIdx = MCS7;
25373 + else if (MCS6 && (Rssi > (-74+RssiOffset)))
25374 + TxRateIdx = MCS6;
25375 + else if (MCS5 && (Rssi > (-77+RssiOffset)))
25376 + TxRateIdx = MCS5;
25377 + else if (MCS4 && (Rssi > (-79+RssiOffset)))
25378 + TxRateIdx = MCS4;
25379 + else if (MCS3 && (Rssi > (-81+RssiOffset)))
25380 + TxRateIdx = MCS3;
25381 + else if (MCS2 && (Rssi > (-83+RssiOffset)))
25382 + TxRateIdx = MCS2;
25383 + else if (MCS1 && (Rssi > (-86+RssiOffset)))
25384 + TxRateIdx = MCS1;
25385 + else
25386 + TxRateIdx = MCS0;
25387 + }
25388 + else
25389 +#endif // DOT11_N_SUPPORT //
25390 + {// Legacy mode
25391 + if (MCS7 && (Rssi > -70))
25392 + TxRateIdx = MCS7;
25393 + else if (MCS6 && (Rssi > -74))
25394 + TxRateIdx = MCS6;
25395 + else if (MCS5 && (Rssi > -78))
25396 + TxRateIdx = MCS5;
25397 + else if (MCS4 && (Rssi > -82))
25398 + TxRateIdx = MCS4;
25399 + else if (MCS4 == 0) // for B-only mode
25400 + TxRateIdx = MCS3;
25401 + else if (MCS3 && (Rssi > -85))
25402 + TxRateIdx = MCS3;
25403 + else if (MCS2 && (Rssi > -87))
25404 + TxRateIdx = MCS2;
25405 + else if (MCS1 && (Rssi > -90))
25406 + TxRateIdx = MCS1;
25407 + else
25408 + TxRateIdx = MCS0;
25409 + }
25410 +
25411 + // if (TxRateIdx != pAd->CommonCfg.TxRateIndex)
25412 + {
25413 + pEntry->CurrTxRateIndex = TxRateIdx;
25414 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5];
25415 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25416 + }
25417 +
25418 + NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25419 + NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25420 + pEntry->fLastSecAccordingRSSI = TRUE;
25421 + // reset all OneSecTx counters
25422 + RESET_ONE_SEC_TX_CNT(pEntry);
25423 +
25424 + continue;
25425 + }
25426 +
25427 + if (pEntry->fLastSecAccordingRSSI == TRUE)
25428 + {
25429 + pEntry->fLastSecAccordingRSSI = FALSE;
25430 + pEntry->LastSecTxRateChangeAction = 0;
25431 + // reset all OneSecTx counters
25432 + RESET_ONE_SEC_TX_CNT(pEntry);
25433 +
25434 + continue;
25435 + }
25436 +
25437 + do
25438 + {
25439 + BOOLEAN bTrainUpDown = FALSE;
25440 +
25441 + pEntry->CurrTxRateStableTime ++;
25442 +
25443 + // downgrade TX quality if PER >= Rate-Down threshold
25444 + if (TxErrorRatio >= TrainDown)
25445 + {
25446 + bTrainUpDown = TRUE;
25447 + pEntry->TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25448 + }
25449 + // upgrade TX quality if PER <= Rate-Up threshold
25450 + else if (TxErrorRatio <= TrainUp)
25451 + {
25452 + bTrainUpDown = TRUE;
25453 + bUpgradeQuality = TRUE;
25454 + if (pEntry->TxQuality[CurrRateIdx])
25455 + pEntry->TxQuality[CurrRateIdx] --; // quality very good in CurrRate
25456 +
25457 + if (pEntry->TxRateUpPenalty)
25458 + pEntry->TxRateUpPenalty --;
25459 + else if (pEntry->TxQuality[UpRateIdx])
25460 + pEntry->TxQuality[UpRateIdx] --; // may improve next UP rate's quality
25461 + }
25462 +
25463 + pEntry->PER[CurrRateIdx] = (UCHAR)TxErrorRatio;
25464 +
25465 + if (bTrainUpDown)
25466 + {
25467 + // perform DRS - consider TxRate Down first, then rate up.
25468 + if ((CurrRateIdx != DownRateIdx) && (pEntry->TxQuality[CurrRateIdx] >= DRS_TX_QUALITY_WORST_BOUND))
25469 + {
25470 + pEntry->CurrTxRateIndex = DownRateIdx;
25471 + }
25472 + else if ((CurrRateIdx != UpRateIdx) && (pEntry->TxQuality[UpRateIdx] <= 0))
25473 + {
25474 + pEntry->CurrTxRateIndex = UpRateIdx;
25475 + }
25476 + }
25477 + } while (FALSE);
25478 +
25479 + // if rate-up happen, clear all bad history of all TX rates
25480 + if (pEntry->CurrTxRateIndex > CurrRateIdx)
25481 + {
25482 + pEntry->CurrTxRateStableTime = 0;
25483 + pEntry->TxRateUpPenalty = 0;
25484 + pEntry->LastSecTxRateChangeAction = 1; // rate UP
25485 + NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25486 + NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25487 +
25488 + //
25489 + // For TxRate fast train up
25490 + //
25491 + if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning)
25492 + {
25493 + RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100);
25494 +
25495 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE;
25496 + }
25497 + bTxRateChanged = TRUE;
25498 + }
25499 + // if rate-down happen, only clear DownRate's bad history
25500 + else if (pEntry->CurrTxRateIndex < CurrRateIdx)
25501 + {
25502 + pEntry->CurrTxRateStableTime = 0;
25503 + pEntry->TxRateUpPenalty = 0; // no penalty
25504 + pEntry->LastSecTxRateChangeAction = 2; // rate DOWN
25505 + pEntry->TxQuality[pEntry->CurrTxRateIndex] = 0;
25506 + pEntry->PER[pEntry->CurrTxRateIndex] = 0;
25507 +
25508 + //
25509 + // For TxRate fast train down
25510 + //
25511 + if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning)
25512 + {
25513 + RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100);
25514 +
25515 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE;
25516 + }
25517 + bTxRateChanged = TRUE;
25518 + }
25519 + else
25520 + {
25521 + pEntry->LastSecTxRateChangeAction = 0; // rate no change
25522 + bTxRateChanged = FALSE;
25523 + }
25524 +
25525 + pEntry->LastTxOkCount = TxSuccess;
25526 +
25527 + // reset all OneSecTx counters
25528 + RESET_ONE_SEC_TX_CNT(pEntry);
25529 +
25530 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5];
25531 + if (bTxRateChanged && pNextTxRate)
25532 + {
25533 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25534 + }
25535 + }
25536 +}
25537 +
25538 +/*
25539 + ========================================================================
25540 + Routine Description:
25541 + Station side, Auto TxRate faster train up timer call back function.
25542 +
25543 + Arguments:
25544 + SystemSpecific1 - Not used.
25545 + FunctionContext - Pointer to our Adapter context.
25546 + SystemSpecific2 - Not used.
25547 + SystemSpecific3 - Not used.
25548 +
25549 + Return Value:
25550 + None
25551 +
25552 + ========================================================================
25553 +*/
25554 +VOID StaQuickResponeForRateUpExec(
25555 + IN PVOID SystemSpecific1,
25556 + IN PVOID FunctionContext,
25557 + IN PVOID SystemSpecific2,
25558 + IN PVOID SystemSpecific3)
25559 +{
25560 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext;
25561 + UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0;
25562 + ULONG TxTotalCnt;
25563 + ULONG TxErrorRatio = 0;
25564 + BOOLEAN bTxRateChanged; //, bUpgradeQuality = FALSE;
25565 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL;
25566 + PUCHAR pTable;
25567 + UCHAR TableSize = 0;
25568 + UCHAR InitTxRateIdx = 0, TrainUp, TrainDown;
25569 + TX_STA_CNT1_STRUC StaTx1;
25570 + TX_STA_CNT0_STRUC TxStaCnt0;
25571 + CHAR Rssi, ratio;
25572 + ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
25573 + MAC_TABLE_ENTRY *pEntry;
25574 + ULONG i;
25575 +
25576 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
25577 +
25578 + //
25579 + // walk through MAC table, see if need to change AP's TX rate toward each entry
25580 + //
25581 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++)
25582 + {
25583 + pEntry = &pAd->MacTab.Content[i];
25584 +
25585 + // check if this entry need to switch rate automatically
25586 + if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
25587 + continue;
25588 +
25589 + if (INFRA_ON(pAd) && (i == 1))
25590 + Rssi = RTMPMaxRssi(pAd,
25591 + pAd->StaCfg.RssiSample.AvgRssi0,
25592 + pAd->StaCfg.RssiSample.AvgRssi1,
25593 + pAd->StaCfg.RssiSample.AvgRssi2);
25594 + else
25595 + Rssi = RTMPMaxRssi(pAd,
25596 + pEntry->RssiSample.AvgRssi0,
25597 + pEntry->RssiSample.AvgRssi1,
25598 + pEntry->RssiSample.AvgRssi2);
25599 +
25600 + CurrRateIdx = pAd->CommonCfg.TxRateIndex;
25601 +
25602 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx);
25603 +
25604 + // decide the next upgrade rate and downgrade rate, if any
25605 + if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1)))
25606 + {
25607 + UpRateIdx = CurrRateIdx + 1;
25608 + DownRateIdx = CurrRateIdx -1;
25609 + }
25610 + else if (CurrRateIdx == 0)
25611 + {
25612 + UpRateIdx = CurrRateIdx + 1;
25613 + DownRateIdx = CurrRateIdx;
25614 + }
25615 + else if (CurrRateIdx == (TableSize - 1))
25616 + {
25617 + UpRateIdx = CurrRateIdx;
25618 + DownRateIdx = CurrRateIdx - 1;
25619 + }
25620 +
25621 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5];
25622 +
25623 +#ifdef DOT11_N_SUPPORT
25624 + if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX))
25625 + {
25626 + TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1));
25627 + TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1));
25628 + }
25629 + else
25630 +#endif // DOT11_N_SUPPORT //
25631 + {
25632 + TrainUp = pCurrTxRate->TrainUp;
25633 + TrainDown = pCurrTxRate->TrainDown;
25634 + }
25635 +
25636 + if (pAd->MacTab.Size == 1)
25637 + {
25638 + // Update statistic counter
25639 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
25640 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
25641 +
25642 + TxRetransmit = StaTx1.field.TxRetransmit;
25643 + TxSuccess = StaTx1.field.TxSuccess;
25644 + TxFailCount = TxStaCnt0.field.TxFailCount;
25645 + TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
25646 +
25647 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
25648 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
25649 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
25650 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
25651 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
25652 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
25653 +
25654 + if (TxTotalCnt)
25655 + TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt;
25656 + }
25657 + else
25658 + {
25659 + TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
25660 + pEntry->OneSecTxRetryOkCount +
25661 + pEntry->OneSecTxFailCount;
25662 +
25663 + if (TxTotalCnt)
25664 + TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt;
25665 + }
25666 +
25667 +
25668 + //
25669 + // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI
25670 + // (criteria copied from RT2500 for Netopia case)
25671 + //
25672 + if (TxTotalCnt <= 12)
25673 + {
25674 + NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25675 + NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25676 +
25677 + if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx))
25678 + {
25679 + pAd->CommonCfg.TxRateIndex = DownRateIdx;
25680 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25681 + }
25682 + else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx))
25683 + {
25684 + pAd->CommonCfg.TxRateIndex = UpRateIdx;
25685 + }
25686 +
25687 + DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: TxTotalCnt <= 15, train back to original rate \n"));
25688 + return;
25689 + }
25690 +
25691 + do
25692 + {
25693 + ULONG OneSecTxNoRetryOKRationCount;
25694 +
25695 + if (pAd->DrsCounters.LastTimeTxRateChangeAction == 0)
25696 + ratio = 5;
25697 + else
25698 + ratio = 4;
25699 +
25700 + // downgrade TX quality if PER >= Rate-Down threshold
25701 + if (TxErrorRatio >= TrainDown)
25702 + {
25703 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25704 + }
25705 +
25706 + pAd->DrsCounters.PER[CurrRateIdx] = (UCHAR)TxErrorRatio;
25707 +
25708 + OneSecTxNoRetryOKRationCount = (TxSuccess * ratio);
25709 +
25710 + // perform DRS - consider TxRate Down first, then rate up.
25711 + if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx))
25712 + {
25713 + if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount)
25714 + {
25715 + pAd->CommonCfg.TxRateIndex = DownRateIdx;
25716 + pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND;
25717 +
25718 + }
25719 +
25720 + }
25721 + else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx))
25722 + {
25723 + if ((TxErrorRatio >= 50) || (TxErrorRatio >= TrainDown))
25724 + {
25725 +
25726 + }
25727 + else if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount)
25728 + {
25729 + pAd->CommonCfg.TxRateIndex = UpRateIdx;
25730 + }
25731 + }
25732 + }while (FALSE);
25733 +
25734 + // if rate-up happen, clear all bad history of all TX rates
25735 + if (pAd->CommonCfg.TxRateIndex > CurrRateIdx)
25736 + {
25737 + pAd->DrsCounters.TxRateUpPenalty = 0;
25738 + NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH);
25739 + NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH);
25740 + bTxRateChanged = TRUE;
25741 + }
25742 + // if rate-down happen, only clear DownRate's bad history
25743 + else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx)
25744 + {
25745 + DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: --TX rate from %d to %d \n", CurrRateIdx, pAd->CommonCfg.TxRateIndex));
25746 +
25747 + pAd->DrsCounters.TxRateUpPenalty = 0; // no penalty
25748 + pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] = 0;
25749 + pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0;
25750 + bTxRateChanged = TRUE;
25751 + }
25752 + else
25753 + {
25754 + bTxRateChanged = FALSE;
25755 + }
25756 +
25757 + pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pAd->CommonCfg.TxRateIndex+1)*5];
25758 + if (bTxRateChanged && pNextTxRate)
25759 + {
25760 + MlmeSetTxRate(pAd, pEntry, pNextTxRate);
25761 + }
25762 + }
25763 +}
25764 +
25765 +/*
25766 + ==========================================================================
25767 + Description:
25768 + This routine is executed periodically inside MlmePeriodicExec() after
25769 + association with an AP.
25770 + It checks if StaCfg.Psm is consistent with user policy (recorded in
25771 + StaCfg.WindowsPowerMode). If not, enforce user policy. However,
25772 + there're some conditions to consider:
25773 + 1. we don't support power-saving in ADHOC mode, so Psm=PWR_ACTIVE all
25774 + the time when Mibss==TRUE
25775 + 2. When link up in INFRA mode, Psm should not be switch to PWR_SAVE
25776 + if outgoing traffic available in TxRing or MgmtRing.
25777 + Output:
25778 + 1. change pAd->StaCfg.Psm to PWR_SAVE or leave it untouched
25779 +
25780 + IRQL = DISPATCH_LEVEL
25781 +
25782 + ==========================================================================
25783 + */
25784 +VOID MlmeCheckPsmChange(
25785 + IN PRTMP_ADAPTER pAd,
25786 + IN ULONG Now32)
25787 +{
25788 + ULONG PowerMode;
25789 +
25790 + // condition -
25791 + // 1. Psm maybe ON only happen in INFRASTRUCTURE mode
25792 + // 2. user wants either MAX_PSP or FAST_PSP
25793 + // 3. but current psm is not in PWR_SAVE
25794 + // 4. CNTL state machine is not doing SCANning
25795 + // 5. no TX SUCCESS event for the past 1-sec period
25796 +#ifdef NDIS51_MINIPORT
25797 + if (pAd->StaCfg.WindowsPowerProfile == NdisPowerProfileBattery)
25798 + PowerMode = pAd->StaCfg.WindowsBatteryPowerMode;
25799 + else
25800 +#endif
25801 + PowerMode = pAd->StaCfg.WindowsPowerMode;
25802 +
25803 + if (INFRA_ON(pAd) &&
25804 + (PowerMode != Ndis802_11PowerModeCAM) &&
25805 + (pAd->StaCfg.Psm == PWR_ACTIVE) &&
25806 +// (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
25807 + (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) /*&&
25808 + (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) &&
25809 + (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)*/)
25810 + {
25811 + // add by johnli, use Rx OK data count per second to calculate throughput
25812 + // If Ttraffic is too high ( > 400 Rx per second), don't go to sleep mode. If tx rate is low, use low criteria
25813 + // Mode=CCK/MCS=3 => 11 Mbps, Mode=OFDM/MCS=3 => 18 Mbps
25814 + if (((pAd->StaCfg.HTPhyMode.field.MCS <= 3) &&
25815 +/* Iverson mark
25816 + (pAd->StaCfg.HTPhyMode.field.MODE <= MODE_OFDM) &&
25817 +*/
25818 + (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)100)) ||
25819 + ((pAd->StaCfg.HTPhyMode.field.MCS > 3) &&
25820 +/* Iverson mark
25821 + (pAd->StaCfg.HTPhyMode.field.MODE > MODE_OFDM) &&
25822 +*/
25823 + (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)400)))
25824 + {
25825 + // Get this time
25826 + NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime);
25827 + pAd->RalinkCounters.RxCountSinceLastNULL = 0;
25828 + MlmeSetPsmBit(pAd, PWR_SAVE);
25829 + if (!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable))
25830 + {
25831 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE);
25832 + }
25833 + else
25834 + {
25835 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
25836 + }
25837 + }
25838 + }
25839 +}
25840 +
25841 +// IRQL = PASSIVE_LEVEL
25842 +// IRQL = DISPATCH_LEVEL
25843 +VOID MlmeSetPsmBit(
25844 + IN PRTMP_ADAPTER pAd,
25845 + IN USHORT psm)
25846 +{
25847 + AUTO_RSP_CFG_STRUC csr4;
25848 +
25849 + pAd->StaCfg.Psm = psm;
25850 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
25851 + csr4.field.AckCtsPsmBit = (psm == PWR_SAVE)? 1:0;
25852 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
25853 +}
25854 +#endif // CONFIG_STA_SUPPORT //
25855 +
25856 +
25857 +// IRQL = DISPATCH_LEVEL
25858 +VOID MlmeSetTxPreamble(
25859 + IN PRTMP_ADAPTER pAd,
25860 + IN USHORT TxPreamble)
25861 +{
25862 + AUTO_RSP_CFG_STRUC csr4;
25863 +
25864 + //
25865 + // Always use Long preamble before verifiation short preamble functionality works well.
25866 + // Todo: remove the following line if short preamble functionality works
25867 + //
25868 + //TxPreamble = Rt802_11PreambleLong;
25869 +
25870 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
25871 + if (TxPreamble == Rt802_11PreambleLong)
25872 + {
25873 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= LONG PREAMBLE)\n"));
25874 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
25875 + csr4.field.AutoResponderPreamble = 0;
25876 + }
25877 + else
25878 + {
25879 + // NOTE: 1Mbps should always use long preamble
25880 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= SHORT PREAMBLE)\n"));
25881 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
25882 + csr4.field.AutoResponderPreamble = 1;
25883 + }
25884 +
25885 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
25886 +}
25887 +
25888 +/*
25889 + ==========================================================================
25890 + Description:
25891 + Update basic rate bitmap
25892 + ==========================================================================
25893 + */
25894 +
25895 +VOID UpdateBasicRateBitmap(
25896 + IN PRTMP_ADAPTER pAdapter)
25897 +{
25898 + INT i, j;
25899 + /* 1 2 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
25900 + UCHAR rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 };
25901 + UCHAR *sup_p = pAdapter->CommonCfg.SupRate;
25902 + UCHAR *ext_p = pAdapter->CommonCfg.ExtRate;
25903 + ULONG bitmap = pAdapter->CommonCfg.BasicRateBitmap;
25904 +
25905 +
25906 + /* if A mode, always use fix BasicRateBitMap */
25907 + //if (pAdapter->CommonCfg.Channel == PHY_11A)
25908 + if (pAdapter->CommonCfg.Channel > 14)
25909 + pAdapter->CommonCfg.BasicRateBitmap = 0x150; /* 6, 12, 24M */
25910 + /* End of if */
25911 +
25912 + if (pAdapter->CommonCfg.BasicRateBitmap > 4095)
25913 + {
25914 + /* (2 ^ MAX_LEN_OF_SUPPORTED_RATES) -1 */
25915 + return;
25916 + } /* End of if */
25917 +
25918 + for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25919 + {
25920 + sup_p[i] &= 0x7f;
25921 + ext_p[i] &= 0x7f;
25922 + } /* End of for */
25923 +
25924 + for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25925 + {
25926 + if (bitmap & (1 << i))
25927 + {
25928 + for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++)
25929 + {
25930 + if (sup_p[j] == rate[i])
25931 + sup_p[j] |= 0x80;
25932 + /* End of if */
25933 + } /* End of for */
25934 +
25935 + for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++)
25936 + {
25937 + if (ext_p[j] == rate[i])
25938 + ext_p[j] |= 0x80;
25939 + /* End of if */
25940 + } /* End of for */
25941 + } /* End of if */
25942 + } /* End of for */
25943 +} /* End of UpdateBasicRateBitmap */
25944 +
25945 +// IRQL = PASSIVE_LEVEL
25946 +// IRQL = DISPATCH_LEVEL
25947 +// bLinkUp is to identify the inital link speed.
25948 +// TRUE indicates the rate update at linkup, we should not try to set the rate at 54Mbps.
25949 +VOID MlmeUpdateTxRates(
25950 + IN PRTMP_ADAPTER pAd,
25951 + IN BOOLEAN bLinkUp,
25952 + IN UCHAR apidx)
25953 +{
25954 + int i, num;
25955 + UCHAR Rate = RATE_6, MaxDesire = RATE_1, MaxSupport = RATE_1;
25956 + UCHAR MinSupport = RATE_54;
25957 + ULONG BasicRateBitmap = 0;
25958 + UCHAR CurrBasicRate = RATE_1;
25959 + UCHAR *pSupRate, SupRateLen, *pExtRate, ExtRateLen;
25960 + PHTTRANSMIT_SETTING pHtPhy = NULL;
25961 + PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
25962 + PHTTRANSMIT_SETTING pMinHtPhy = NULL;
25963 + BOOLEAN *auto_rate_cur_p;
25964 + UCHAR HtMcs = MCS_AUTO;
25965 +
25966 + // find max desired rate
25967 + UpdateBasicRateBitmap(pAd);
25968 +
25969 + num = 0;
25970 + auto_rate_cur_p = NULL;
25971 + for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
25972 + {
25973 + switch (pAd->CommonCfg.DesireRate[i] & 0x7f)
25974 + {
25975 + case 2: Rate = RATE_1; num++; break;
25976 + case 4: Rate = RATE_2; num++; break;
25977 + case 11: Rate = RATE_5_5; num++; break;
25978 + case 22: Rate = RATE_11; num++; break;
25979 + case 12: Rate = RATE_6; num++; break;
25980 + case 18: Rate = RATE_9; num++; break;
25981 + case 24: Rate = RATE_12; num++; break;
25982 + case 36: Rate = RATE_18; num++; break;
25983 + case 48: Rate = RATE_24; num++; break;
25984 + case 72: Rate = RATE_36; num++; break;
25985 + case 96: Rate = RATE_48; num++; break;
25986 + case 108: Rate = RATE_54; num++; break;
25987 + //default: Rate = RATE_1; break;
25988 + }
25989 + if (MaxDesire < Rate) MaxDesire = Rate;
25990 + }
25991 +
25992 +//===========================================================================
25993 +//===========================================================================
25994 +
25995 +#ifdef CONFIG_STA_SUPPORT
25996 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
25997 + {
25998 + pHtPhy = &pAd->StaCfg.HTPhyMode;
25999 + pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
26000 + pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
26001 +
26002 + auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
26003 + HtMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
26004 +
26005 + if ((pAd->StaCfg.BssType == BSS_ADHOC) &&
26006 + (pAd->CommonCfg.PhyMode == PHY_11B) &&
26007 + (MaxDesire > RATE_11))
26008 + {
26009 + MaxDesire = RATE_11;
26010 + }
26011 + }
26012 +#endif // CONFIG_STA_SUPPORT //
26013 +
26014 + pAd->CommonCfg.MaxDesiredRate = MaxDesire;
26015 + pMinHtPhy->word = 0;
26016 + pMaxHtPhy->word = 0;
26017 + pHtPhy->word = 0;
26018 +
26019 + // Auto rate switching is enabled only if more than one DESIRED RATES are
26020 + // specified; otherwise disabled
26021 + if (num <= 1)
26022 + {
26023 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
26024 + //pAd->CommonCfg.bAutoTxRateSwitch = FALSE;
26025 + *auto_rate_cur_p = FALSE;
26026 + }
26027 + else
26028 + {
26029 + //OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
26030 + //pAd->CommonCfg.bAutoTxRateSwitch = TRUE;
26031 + *auto_rate_cur_p = TRUE;
26032 + }
26033 +
26034 +#if 1
26035 + if (HtMcs != MCS_AUTO)
26036 + {
26037 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
26038 + //pAd->CommonCfg.bAutoTxRateSwitch = FALSE;
26039 + *auto_rate_cur_p = FALSE;
26040 + }
26041 + else
26042 + {
26043 + //OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED);
26044 + //pAd->CommonCfg.bAutoTxRateSwitch = TRUE;
26045 + *auto_rate_cur_p = TRUE;
26046 + }
26047 +#endif
26048 +
26049 +#ifdef CONFIG_STA_SUPPORT
26050 + if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA))
26051 + {
26052 + pSupRate = &pAd->StaActive.SupRate[0];
26053 + pExtRate = &pAd->StaActive.ExtRate[0];
26054 + SupRateLen = pAd->StaActive.SupRateLen;
26055 + ExtRateLen = pAd->StaActive.ExtRateLen;
26056 + }
26057 + else
26058 +#endif // CONFIG_STA_SUPPORT //
26059 + {
26060 + pSupRate = &pAd->CommonCfg.SupRate[0];
26061 + pExtRate = &pAd->CommonCfg.ExtRate[0];
26062 + SupRateLen = pAd->CommonCfg.SupRateLen;
26063 + ExtRateLen = pAd->CommonCfg.ExtRateLen;
26064 + }
26065 +
26066 + // find max supported rate
26067 + for (i=0; i<SupRateLen; i++)
26068 + {
26069 + switch (pSupRate[i] & 0x7f)
26070 + {
26071 + case 2: Rate = RATE_1; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0001; break;
26072 + case 4: Rate = RATE_2; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0002; break;
26073 + case 11: Rate = RATE_5_5; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0004; break;
26074 + case 22: Rate = RATE_11; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0008; break;
26075 + case 12: Rate = RATE_6; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break;
26076 + case 18: Rate = RATE_9; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0020; break;
26077 + case 24: Rate = RATE_12; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break;
26078 + case 36: Rate = RATE_18; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0080; break;
26079 + case 48: Rate = RATE_24; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break;
26080 + case 72: Rate = RATE_36; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0200; break;
26081 + case 96: Rate = RATE_48; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0400; break;
26082 + case 108: Rate = RATE_54; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0800; break;
26083 + default: Rate = RATE_1; break;
26084 + }
26085 + if (MaxSupport < Rate) MaxSupport = Rate;
26086 +
26087 + if (MinSupport > Rate) MinSupport = Rate;
26088 + }
26089 +
26090 + for (i=0; i<ExtRateLen; i++)
26091 + {
26092 + switch (pExtRate[i] & 0x7f)
26093 + {
26094 + case 2: Rate = RATE_1; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0001; break;
26095 + case 4: Rate = RATE_2; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0002; break;
26096 + case 11: Rate = RATE_5_5; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0004; break;
26097 + case 22: Rate = RATE_11; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0008; break;
26098 + case 12: Rate = RATE_6; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break;
26099 + case 18: Rate = RATE_9; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0020; break;
26100 + case 24: Rate = RATE_12; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break;
26101 + case 36: Rate = RATE_18; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0080; break;
26102 + case 48: Rate = RATE_24; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break;
26103 + case 72: Rate = RATE_36; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0200; break;
26104 + case 96: Rate = RATE_48; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0400; break;
26105 + case 108: Rate = RATE_54; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0800; break;
26106 + default: Rate = RATE_1; break;
26107 + }
26108 + if (MaxSupport < Rate) MaxSupport = Rate;
26109 +
26110 + if (MinSupport > Rate) MinSupport = Rate;
26111 + }
26112 +
26113 + RTMP_IO_WRITE32(pAd, LEGACY_BASIC_RATE, BasicRateBitmap);
26114 +
26115 + // calculate the exptected ACK rate for each TX rate. This info is used to caculate
26116 + // the DURATION field of outgoing uniicast DATA/MGMT frame
26117 + for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++)
26118 + {
26119 + if (BasicRateBitmap & (0x01 << i))
26120 + CurrBasicRate = (UCHAR)i;
26121 + pAd->CommonCfg.ExpectedACKRate[i] = CurrBasicRate;
26122 + }
26123 +
26124 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateTxRates[MaxSupport = %d] = MaxDesire %d Mbps\n", RateIdToMbps[MaxSupport], RateIdToMbps[MaxDesire]));
26125 + // max tx rate = min {max desire rate, max supported rate}
26126 + if (MaxSupport < MaxDesire)
26127 + pAd->CommonCfg.MaxTxRate = MaxSupport;
26128 + else
26129 + pAd->CommonCfg.MaxTxRate = MaxDesire;
26130 +
26131 + pAd->CommonCfg.MinTxRate = MinSupport;
26132 + // 2003-07-31 john - 2500 doesn't have good sensitivity at high OFDM rates. to increase the success
26133 + // ratio of initial DHCP packet exchange, TX rate starts from a lower rate depending
26134 + // on average RSSI
26135 + // 1. RSSI >= -70db, start at 54 Mbps (short distance)
26136 + // 2. -70 > RSSI >= -75, start at 24 Mbps (mid distance)
26137 + // 3. -75 > RSSI, start at 11 Mbps (long distance)
26138 + //if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)/* &&
26139 + // OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)*/)
26140 + if (*auto_rate_cur_p)
26141 + {
26142 + short dbm = 0;
26143 +#ifdef CONFIG_STA_SUPPORT
26144 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
26145 + dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta;
26146 +#endif // CONFIG_STA_SUPPORT //
26147 + if (bLinkUp == TRUE)
26148 + pAd->CommonCfg.TxRate = RATE_24;
26149 + else
26150 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
26151 +
26152 + if (dbm < -75)
26153 + pAd->CommonCfg.TxRate = RATE_11;
26154 + else if (dbm < -70)
26155 + pAd->CommonCfg.TxRate = RATE_24;
26156 +
26157 + // should never exceed MaxTxRate (consider 11B-only mode)
26158 + if (pAd->CommonCfg.TxRate > pAd->CommonCfg.MaxTxRate)
26159 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
26160 +
26161 + pAd->CommonCfg.TxRateIndex = 0;
26162 + }
26163 + else
26164 + {
26165 + pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
26166 + pHtPhy->field.MCS = (pAd->CommonCfg.MaxTxRate > 3) ? (pAd->CommonCfg.MaxTxRate - 4) : pAd->CommonCfg.MaxTxRate;
26167 + pHtPhy->field.MODE = (pAd->CommonCfg.MaxTxRate > 3) ? MODE_OFDM : MODE_CCK;
26168 +
26169 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC = pHtPhy->field.STBC;
26170 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI = pHtPhy->field.ShortGI;
26171 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS = pHtPhy->field.MCS;
26172 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE = pHtPhy->field.MODE;
26173 + }
26174 +
26175 + if (pAd->CommonCfg.TxRate <= RATE_11)
26176 + {
26177 + pMaxHtPhy->field.MODE = MODE_CCK;
26178 + pMaxHtPhy->field.MCS = pAd->CommonCfg.TxRate;
26179 + pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;
26180 + }
26181 + else
26182 + {
26183 + pMaxHtPhy->field.MODE = MODE_OFDM;
26184 + pMaxHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.TxRate];
26185 + if (pAd->CommonCfg.MinTxRate >= RATE_6 && (pAd->CommonCfg.MinTxRate <= RATE_54))
26186 + {pMinHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MinTxRate];}
26187 + else
26188 + {pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;}
26189 + }
26190 +
26191 + pHtPhy->word = (pMaxHtPhy->word);
26192 + if (bLinkUp && (pAd->OpMode == OPMODE_STA))
26193 + {
26194 + pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word = pHtPhy->word;
26195 + pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word = pMaxHtPhy->word;
26196 + pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word = pMinHtPhy->word;
26197 + }
26198 + else
26199 + {
26200 + switch (pAd->CommonCfg.PhyMode)
26201 + {
26202 + case PHY_11BG_MIXED:
26203 + case PHY_11B:
26204 +#ifdef DOT11_N_SUPPORT
26205 + case PHY_11BGN_MIXED:
26206 +#endif // DOT11_N_SUPPORT //
26207 + pAd->CommonCfg.MlmeRate = RATE_1;
26208 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
26209 + pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
26210 +
26211 +//#ifdef WIFI_TEST
26212 + pAd->CommonCfg.RtsRate = RATE_11;
26213 +//#else
26214 +// pAd->CommonCfg.RtsRate = RATE_1;
26215 +//#endif
26216 + break;
26217 + case PHY_11G:
26218 + case PHY_11A:
26219 +#ifdef DOT11_N_SUPPORT
26220 + case PHY_11AGN_MIXED:
26221 + case PHY_11GN_MIXED:
26222 + case PHY_11N_2_4G:
26223 + case PHY_11AN_MIXED:
26224 + case PHY_11N_5G:
26225 +#endif // DOT11_N_SUPPORT //
26226 + pAd->CommonCfg.MlmeRate = RATE_6;
26227 + pAd->CommonCfg.RtsRate = RATE_6;
26228 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
26229 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
26230 + break;
26231 + case PHY_11ABG_MIXED:
26232 +#ifdef DOT11_N_SUPPORT
26233 + case PHY_11ABGN_MIXED:
26234 +#endif // DOT11_N_SUPPORT //
26235 + if (pAd->CommonCfg.Channel <= 14)
26236 + {
26237 + pAd->CommonCfg.MlmeRate = RATE_1;
26238 + pAd->CommonCfg.RtsRate = RATE_1;
26239 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
26240 + pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
26241 + }
26242 + else
26243 + {
26244 + pAd->CommonCfg.MlmeRate = RATE_6;
26245 + pAd->CommonCfg.RtsRate = RATE_6;
26246 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
26247 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
26248 + }
26249 + break;
26250 + default: // error
26251 + pAd->CommonCfg.MlmeRate = RATE_6;
26252 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
26253 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
26254 + pAd->CommonCfg.RtsRate = RATE_1;
26255 + break;
26256 + }
26257 + //
26258 + // Keep Basic Mlme Rate.
26259 + //
26260 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.word = pAd->CommonCfg.MlmeTransmit.word;
26261 + if (pAd->CommonCfg.MlmeTransmit.field.MODE == MODE_OFDM)
26262 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[RATE_24];
26263 + else
26264 + pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = RATE_1;
26265 + pAd->CommonCfg.BasicMlmeRate = pAd->CommonCfg.MlmeRate;
26266 + }
26267 +
26268 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (MaxDesire=%d, MaxSupport=%d, MaxTxRate=%d, MinRate=%d, Rate Switching =%d)\n",
26269 + RateIdToMbps[MaxDesire], RateIdToMbps[MaxSupport], RateIdToMbps[pAd->CommonCfg.MaxTxRate], RateIdToMbps[pAd->CommonCfg.MinTxRate],
26270 + /*OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)*/*auto_rate_cur_p));
26271 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (TxRate=%d, RtsRate=%d, BasicRateBitmap=0x%04lx)\n",
26272 + RateIdToMbps[pAd->CommonCfg.TxRate], RateIdToMbps[pAd->CommonCfg.RtsRate], BasicRateBitmap));
26273 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateTxRates (MlmeTransmit=0x%x, MinHTPhyMode=%x, MaxHTPhyMode=0x%x, HTPhyMode=0x%x)\n",
26274 + pAd->CommonCfg.MlmeTransmit.word, pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word ));
26275 +}
26276 +
26277 +#ifdef DOT11_N_SUPPORT
26278 +/*
26279 + ==========================================================================
26280 + Description:
26281 + This function update HT Rate setting.
26282 + Input Wcid value is valid for 2 case :
26283 + 1. it's used for Station in infra mode that copy AP rate to Mactable.
26284 + 2. OR Station in adhoc mode to copy peer's HT rate to Mactable.
26285 +
26286 + IRQL = DISPATCH_LEVEL
26287 +
26288 + ==========================================================================
26289 + */
26290 +VOID MlmeUpdateHtTxRates(
26291 + IN PRTMP_ADAPTER pAd,
26292 + IN UCHAR apidx)
26293 +{
26294 + UCHAR StbcMcs; //j, StbcMcs, bitmask;
26295 + CHAR i; // 3*3
26296 + RT_HT_CAPABILITY *pRtHtCap = NULL;
26297 + RT_HT_PHY_INFO *pActiveHtPhy = NULL;
26298 + ULONG BasicMCS;
26299 + UCHAR j, bitmask;
26300 + PRT_HT_PHY_INFO pDesireHtPhy = NULL;
26301 + PHTTRANSMIT_SETTING pHtPhy = NULL;
26302 + PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
26303 + PHTTRANSMIT_SETTING pMinHtPhy = NULL;
26304 + BOOLEAN *auto_rate_cur_p;
26305 +
26306 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates===> \n"));
26307 +
26308 + auto_rate_cur_p = NULL;
26309 +
26310 +#ifdef CONFIG_STA_SUPPORT
26311 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
26312 + {
26313 + pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
26314 + pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
26315 + pHtPhy = &pAd->StaCfg.HTPhyMode;
26316 + pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
26317 + pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
26318 +
26319 + auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
26320 + }
26321 +#endif // CONFIG_STA_SUPPORT //
26322 +
26323 +#ifdef CONFIG_STA_SUPPORT
26324 + if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA))
26325 + {
26326 + if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
26327 + return;
26328 +
26329 + pRtHtCap = &pAd->StaActive.SupportedHtPhy;
26330 + pActiveHtPhy = &pAd->StaActive.SupportedPhyInfo;
26331 + StbcMcs = (UCHAR)pAd->MlmeAux.AddHtInfo.AddHtInfo3.StbcMcs;
26332 + BasicMCS =pAd->MlmeAux.AddHtInfo.MCSSet[0]+(pAd->MlmeAux.AddHtInfo.MCSSet[1]<<8)+(StbcMcs<<16);
26333 + if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2))
26334 + pMaxHtPhy->field.STBC = STBC_USE;
26335 + else
26336 + pMaxHtPhy->field.STBC = STBC_NONE;
26337 + }
26338 + else
26339 +#endif // CONFIG_STA_SUPPORT //
26340 + {
26341 + if (pDesireHtPhy->bHtEnable == FALSE)
26342 + return;
26343 +
26344 + pRtHtCap = &pAd->CommonCfg.DesiredHtPhy;
26345 + StbcMcs = (UCHAR)pAd->CommonCfg.AddHTInfo.AddHtInfo3.StbcMcs;
26346 + BasicMCS = pAd->CommonCfg.AddHTInfo.MCSSet[0]+(pAd->CommonCfg.AddHTInfo.MCSSet[1]<<8)+(StbcMcs<<16);
26347 + if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2))
26348 + pMaxHtPhy->field.STBC = STBC_USE;
26349 + else
26350 + pMaxHtPhy->field.STBC = STBC_NONE;
26351 + }
26352 +
26353 + // Decide MAX ht rate.
26354 + if ((pRtHtCap->GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
26355 + pMaxHtPhy->field.MODE = MODE_HTGREENFIELD;
26356 + else
26357 + pMaxHtPhy->field.MODE = MODE_HTMIX;
26358 +
26359 + if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth) && (pRtHtCap->ChannelWidth))
26360 + pMaxHtPhy->field.BW = BW_40;
26361 + else
26362 + pMaxHtPhy->field.BW = BW_20;
26363 +
26364 + if (pMaxHtPhy->field.BW == BW_20)
26365 + pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 & pRtHtCap->ShortGIfor20);
26366 + else
26367 + pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 & pRtHtCap->ShortGIfor40);
26368 +
26369 + for (i=23; i>=0; i--) // 3*3
26370 + {
26371 + j = i/8;
26372 + bitmask = (1<<(i-(j*8)));
26373 +
26374 + if ((pActiveHtPhy->MCSSet[j] & bitmask) && (pDesireHtPhy->MCSSet[j] & bitmask))
26375 + {
26376 + pMaxHtPhy->field.MCS = i;
26377 + break;
26378 + }
26379 +
26380 + if (i==0)
26381 + break;
26382 + }
26383 +
26384 + // Copy MIN ht rate. rt2860???
26385 + pMinHtPhy->field.BW = BW_20;
26386 + pMinHtPhy->field.MCS = 0;
26387 + pMinHtPhy->field.STBC = 0;
26388 + pMinHtPhy->field.ShortGI = 0;
26389 + //If STA assigns fixed rate. update to fixed here.
26390 +#ifdef CONFIG_STA_SUPPORT
26391 + if ( (pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff))
26392 + {
26393 + if (pDesireHtPhy->MCSSet[4] != 0)
26394 + {
26395 + pMaxHtPhy->field.MCS = 32;
26396 + pMinHtPhy->field.MCS = 32;
26397 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== Use Fixed MCS = %d\n",pMinHtPhy->field.MCS));
26398 + }
26399 +
26400 + for (i=23; (CHAR)i >= 0; i--) // 3*3
26401 + {
26402 + j = i/8;
26403 + bitmask = (1<<(i-(j*8)));
26404 + if ( (pDesireHtPhy->MCSSet[j] & bitmask) && (pActiveHtPhy->MCSSet[j] & bitmask))
26405 + {
26406 + pMaxHtPhy->field.MCS = i;
26407 + pMinHtPhy->field.MCS = i;
26408 + break;
26409 + }
26410 + if (i==0)
26411 + break;
26412 + }
26413 + }
26414 +#endif // CONFIG_STA_SUPPORT //
26415 +
26416 +
26417 + // Decide ht rate
26418 + pHtPhy->field.STBC = pMaxHtPhy->field.STBC;
26419 + pHtPhy->field.BW = pMaxHtPhy->field.BW;
26420 + pHtPhy->field.MODE = pMaxHtPhy->field.MODE;
26421 + pHtPhy->field.MCS = pMaxHtPhy->field.MCS;
26422 + pHtPhy->field.ShortGI = pMaxHtPhy->field.ShortGI;
26423 +
26424 + // use default now. rt2860
26425 + if (pDesireHtPhy->MCSSet[0] != 0xff)
26426 + *auto_rate_cur_p = FALSE;
26427 + else
26428 + *auto_rate_cur_p = TRUE;
26429 +
26430 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateHtTxRates<---.AMsduSize = %d \n", pAd->CommonCfg.DesiredHtPhy.AmsduSize ));
26431 + DBGPRINT(RT_DEBUG_TRACE,("TX: MCS[0] = %x (choose %d), BW = %d, ShortGI = %d, MODE = %d, \n", pActiveHtPhy->MCSSet[0],pHtPhy->field.MCS,
26432 + pHtPhy->field.BW, pHtPhy->field.ShortGI, pHtPhy->field.MODE));
26433 + DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== \n"));
26434 +}
26435 +#endif // DOT11_N_SUPPORT //
26436 +
26437 +// IRQL = DISPATCH_LEVEL
26438 +VOID MlmeRadioOff(
26439 + IN PRTMP_ADAPTER pAd)
26440 +{
26441 + RT28XX_MLME_RADIO_OFF(pAd);
26442 +}
26443 +
26444 +// IRQL = DISPATCH_LEVEL
26445 +VOID MlmeRadioOn(
26446 + IN PRTMP_ADAPTER pAd)
26447 +{
26448 + RT28XX_MLME_RADIO_ON(pAd);
26449 +}
26450 +
26451 +// ===========================================================================================
26452 +// bss_table.c
26453 +// ===========================================================================================
26454 +
26455 +
26456 +/*! \brief initialize BSS table
26457 + * \param p_tab pointer to the table
26458 + * \return none
26459 + * \pre
26460 + * \post
26461 +
26462 + IRQL = PASSIVE_LEVEL
26463 + IRQL = DISPATCH_LEVEL
26464 +
26465 + */
26466 +VOID BssTableInit(
26467 + IN BSS_TABLE *Tab)
26468 +{
26469 + int i;
26470 +
26471 + Tab->BssNr = 0;
26472 + Tab->BssOverlapNr = 0;
26473 + for (i = 0; i < MAX_LEN_OF_BSS_TABLE; i++)
26474 + {
26475 + NdisZeroMemory(&Tab->BssEntry[i], sizeof(BSS_ENTRY));
26476 + Tab->BssEntry[i].Rssi = -127; // initial the rssi as a minimum value
26477 + }
26478 +}
26479 +
26480 +#ifdef DOT11_N_SUPPORT
26481 +VOID BATableInit(
26482 + IN PRTMP_ADAPTER pAd,
26483 + IN BA_TABLE *Tab)
26484 +{
26485 + int i;
26486 +
26487 + Tab->numAsOriginator = 0;
26488 + Tab->numAsRecipient = 0;
26489 + NdisAllocateSpinLock(&pAd->BATabLock);
26490 + for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++)
26491 + {
26492 + Tab->BARecEntry[i].REC_BA_Status = Recipient_NONE;
26493 + NdisAllocateSpinLock(&(Tab->BARecEntry[i].RxReRingLock));
26494 + }
26495 + for (i = 0; i < MAX_LEN_OF_BA_ORI_TABLE; i++)
26496 + {
26497 + Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE;
26498 + }
26499 +}
26500 +#endif // DOT11_N_SUPPORT //
26501 +
26502 +/*! \brief search the BSS table by SSID
26503 + * \param p_tab pointer to the bss table
26504 + * \param ssid SSID string
26505 + * \return index of the table, BSS_NOT_FOUND if not in the table
26506 + * \pre
26507 + * \post
26508 + * \note search by sequential search
26509 +
26510 + IRQL = DISPATCH_LEVEL
26511 +
26512 + */
26513 +ULONG BssTableSearch(
26514 + IN BSS_TABLE *Tab,
26515 + IN PUCHAR pBssid,
26516 + IN UCHAR Channel)
26517 +{
26518 + UCHAR i;
26519 +
26520 + for (i = 0; i < Tab->BssNr; i++)
26521 + {
26522 + //
26523 + // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G.
26524 + // We should distinguish this case.
26525 + //
26526 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26527 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26528 + MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid))
26529 + {
26530 + return i;
26531 + }
26532 + }
26533 + return (ULONG)BSS_NOT_FOUND;
26534 +}
26535 +
26536 +ULONG BssSsidTableSearch(
26537 + IN BSS_TABLE *Tab,
26538 + IN PUCHAR pBssid,
26539 + IN PUCHAR pSsid,
26540 + IN UCHAR SsidLen,
26541 + IN UCHAR Channel)
26542 +{
26543 + UCHAR i;
26544 +
26545 + for (i = 0; i < Tab->BssNr; i++)
26546 + {
26547 + //
26548 + // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G.
26549 + // We should distinguish this case.
26550 + //
26551 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26552 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26553 + MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid) &&
26554 + SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen))
26555 + {
26556 + return i;
26557 + }
26558 + }
26559 + return (ULONG)BSS_NOT_FOUND;
26560 +}
26561 +
26562 +ULONG BssTableSearchWithSSID(
26563 + IN BSS_TABLE *Tab,
26564 + IN PUCHAR Bssid,
26565 + IN PUCHAR pSsid,
26566 + IN UCHAR SsidLen,
26567 + IN UCHAR Channel)
26568 +{
26569 + UCHAR i;
26570 +
26571 + for (i = 0; i < Tab->BssNr; i++)
26572 + {
26573 + if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
26574 + ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
26575 + MAC_ADDR_EQUAL(&(Tab->BssEntry[i].Bssid), Bssid) &&
26576 + (SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen) ||
26577 + (NdisEqualMemory(pSsid, ZeroSsid, SsidLen)) ||
26578 + (NdisEqualMemory(Tab->BssEntry[i].Ssid, ZeroSsid, Tab->BssEntry[i].SsidLen))))
26579 + {
26580 + return i;
26581 + }
26582 + }
26583 + return (ULONG)BSS_NOT_FOUND;
26584 +}
26585 +
26586 +// IRQL = DISPATCH_LEVEL
26587 +VOID BssTableDeleteEntry(
26588 + IN OUT BSS_TABLE *Tab,
26589 + IN PUCHAR pBssid,
26590 + IN UCHAR Channel)
26591 +{
26592 + UCHAR i, j;
26593 +
26594 + for (i = 0; i < Tab->BssNr; i++)
26595 + {
26596 + if ((Tab->BssEntry[i].Channel == Channel) &&
26597 + (MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid)))
26598 + {
26599 + for (j = i; j < Tab->BssNr - 1; j++)
26600 + {
26601 + NdisMoveMemory(&(Tab->BssEntry[j]), &(Tab->BssEntry[j + 1]), sizeof(BSS_ENTRY));
26602 + }
26603 + NdisZeroMemory(&(Tab->BssEntry[Tab->BssNr - 1]), sizeof(BSS_ENTRY));
26604 + Tab->BssNr -= 1;
26605 + return;
26606 + }
26607 + }
26608 +}
26609 +
26610 +#ifdef DOT11_N_SUPPORT
26611 +/*
26612 + ========================================================================
26613 + Routine Description:
26614 + Delete the Originator Entry in BAtable. Or decrease numAs Originator by 1 if needed.
26615 +
26616 + Arguments:
26617 + // IRQL = DISPATCH_LEVEL
26618 + ========================================================================
26619 +*/
26620 +VOID BATableDeleteORIEntry(
26621 + IN OUT PRTMP_ADAPTER pAd,
26622 + IN BA_ORI_ENTRY *pBAORIEntry)
26623 +{
26624 +
26625 + if (pBAORIEntry->ORI_BA_Status != Originator_NONE)
26626 + {
26627 + NdisAcquireSpinLock(&pAd->BATabLock);
26628 + if (pBAORIEntry->ORI_BA_Status == Originator_Done)
26629 + {
26630 + pAd->BATable.numAsOriginator -= 1;
26631 + DBGPRINT(RT_DEBUG_TRACE, ("BATableDeleteORIEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient));
26632 + // Erase Bitmap flag.
26633 + }
26634 + pAd->MacTab.Content[pBAORIEntry->Wcid].TXBAbitmap &= (~(1<<(pBAORIEntry->TID) )); // If STA mode, erase flag here
26635 + pAd->MacTab.Content[pBAORIEntry->Wcid].BAOriWcidArray[pBAORIEntry->TID] = 0; // If STA mode, erase flag here
26636 + pBAORIEntry->ORI_BA_Status = Originator_NONE;
26637 + pBAORIEntry->Token = 1;
26638 + // Not clear Sequence here.
26639 + NdisReleaseSpinLock(&pAd->BATabLock);
26640 + }
26641 +}
26642 +#endif // DOT11_N_SUPPORT //
26643 +
26644 +/*! \brief
26645 + * \param
26646 + * \return
26647 + * \pre
26648 + * \post
26649 +
26650 + IRQL = DISPATCH_LEVEL
26651 +
26652 + */
26653 +VOID BssEntrySet(
26654 + IN PRTMP_ADAPTER pAd,
26655 + OUT BSS_ENTRY *pBss,
26656 + IN PUCHAR pBssid,
26657 + IN CHAR Ssid[],
26658 + IN UCHAR SsidLen,
26659 + IN UCHAR BssType,
26660 + IN USHORT BeaconPeriod,
26661 + IN PCF_PARM pCfParm,
26662 + IN USHORT AtimWin,
26663 + IN USHORT CapabilityInfo,
26664 + IN UCHAR SupRate[],
26665 + IN UCHAR SupRateLen,
26666 + IN UCHAR ExtRate[],
26667 + IN UCHAR ExtRateLen,
26668 + IN HT_CAPABILITY_IE *pHtCapability,
26669 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
26670 + IN UCHAR HtCapabilityLen,
26671 + IN UCHAR AddHtInfoLen,
26672 + IN UCHAR NewExtChanOffset,
26673 + IN UCHAR Channel,
26674 + IN CHAR Rssi,
26675 + IN LARGE_INTEGER TimeStamp,
26676 + IN UCHAR CkipFlag,
26677 + IN PEDCA_PARM pEdcaParm,
26678 + IN PQOS_CAPABILITY_PARM pQosCapability,
26679 + IN PQBSS_LOAD_PARM pQbssLoad,
26680 + IN USHORT LengthVIE,
26681 + IN PNDIS_802_11_VARIABLE_IEs pVIE)
26682 +{
26683 + COPY_MAC_ADDR(pBss->Bssid, pBssid);
26684 + // Default Hidden SSID to be TRUE, it will be turned to FALSE after coping SSID
26685 + pBss->Hidden = 1;
26686 + if (SsidLen > 0)
26687 + {
26688 + // For hidden SSID AP, it might send beacon with SSID len equal to 0
26689 + // Or send beacon /probe response with SSID len matching real SSID length,
26690 + // but SSID is all zero. such as "00-00-00-00" with length 4.
26691 + // We have to prevent this case overwrite correct table
26692 + if (NdisEqualMemory(Ssid, ZeroSsid, SsidLen) == 0)
26693 + {
26694 + NdisZeroMemory(pBss->Ssid, MAX_LEN_OF_SSID);
26695 + NdisMoveMemory(pBss->Ssid, Ssid, SsidLen);
26696 + pBss->SsidLen = SsidLen;
26697 + pBss->Hidden = 0;
26698 + }
26699 + }
26700 + else
26701 + pBss->SsidLen = 0;
26702 + pBss->BssType = BssType;
26703 + pBss->BeaconPeriod = BeaconPeriod;
26704 + if (BssType == BSS_INFRA)
26705 + {
26706 + if (pCfParm->bValid)
26707 + {
26708 + pBss->CfpCount = pCfParm->CfpCount;
26709 + pBss->CfpPeriod = pCfParm->CfpPeriod;
26710 + pBss->CfpMaxDuration = pCfParm->CfpMaxDuration;
26711 + pBss->CfpDurRemaining = pCfParm->CfpDurRemaining;
26712 + }
26713 + }
26714 + else
26715 + {
26716 + pBss->AtimWin = AtimWin;
26717 + }
26718 +
26719 + pBss->CapabilityInfo = CapabilityInfo;
26720 + // The privacy bit indicate security is ON, it maight be WEP, TKIP or AES
26721 + // Combine with AuthMode, they will decide the connection methods.
26722 + pBss->Privacy = CAP_IS_PRIVACY_ON(pBss->CapabilityInfo);
26723 + ASSERT(SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
26724 + if (SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES)
26725 + NdisMoveMemory(pBss->SupRate, SupRate, SupRateLen);
26726 + else
26727 + NdisMoveMemory(pBss->SupRate, SupRate, MAX_LEN_OF_SUPPORTED_RATES);
26728 + pBss->SupRateLen = SupRateLen;
26729 + ASSERT(ExtRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
26730 + NdisMoveMemory(pBss->ExtRate, ExtRate, ExtRateLen);
26731 + NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen);
26732 + NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen);
26733 + pBss->NewExtChanOffset = NewExtChanOffset;
26734 + pBss->ExtRateLen = ExtRateLen;
26735 + pBss->Channel = Channel;
26736 + pBss->CentralChannel = Channel;
26737 + pBss->Rssi = Rssi;
26738 + // Update CkipFlag. if not exists, the value is 0x0
26739 + pBss->CkipFlag = CkipFlag;
26740 +
26741 + // New for microsoft Fixed IEs
26742 + NdisMoveMemory(pBss->FixIEs.Timestamp, &TimeStamp, 8);
26743 + pBss->FixIEs.BeaconInterval = BeaconPeriod;
26744 + pBss->FixIEs.Capabilities = CapabilityInfo;
26745 +
26746 + // New for microsoft Variable IEs
26747 + if (LengthVIE != 0)
26748 + {
26749 + pBss->VarIELen = LengthVIE;
26750 + NdisMoveMemory(pBss->VarIEs, pVIE, pBss->VarIELen);
26751 + }
26752 + else
26753 + {
26754 + pBss->VarIELen = 0;
26755 + }
26756 +
26757 + pBss->AddHtInfoLen = 0;
26758 + pBss->HtCapabilityLen = 0;
26759 +#ifdef DOT11_N_SUPPORT
26760 + if (HtCapabilityLen> 0)
26761 + {
26762 + pBss->HtCapabilityLen = HtCapabilityLen;
26763 + NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen);
26764 + if (AddHtInfoLen > 0)
26765 + {
26766 + pBss->AddHtInfoLen = AddHtInfoLen;
26767 + NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen);
26768 +
26769 + if ((pAddHtInfo->ControlChan > 2)&& (pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40))
26770 + {
26771 + pBss->CentralChannel = pAddHtInfo->ControlChan - 2;
26772 + }
26773 + else if ((pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40))
26774 + {
26775 + pBss->CentralChannel = pAddHtInfo->ControlChan + 2;
26776 + }
26777 + }
26778 + }
26779 +#endif // DOT11_N_SUPPORT //
26780 +
26781 + BssCipherParse(pBss);
26782 +
26783 + // new for QOS
26784 + if (pEdcaParm)
26785 + NdisMoveMemory(&pBss->EdcaParm, pEdcaParm, sizeof(EDCA_PARM));
26786 + else
26787 + pBss->EdcaParm.bValid = FALSE;
26788 + if (pQosCapability)
26789 + NdisMoveMemory(&pBss->QosCapability, pQosCapability, sizeof(QOS_CAPABILITY_PARM));
26790 + else
26791 + pBss->QosCapability.bValid = FALSE;
26792 + if (pQbssLoad)
26793 + NdisMoveMemory(&pBss->QbssLoad, pQbssLoad, sizeof(QBSS_LOAD_PARM));
26794 + else
26795 + pBss->QbssLoad.bValid = FALSE;
26796 +
26797 +#ifdef CONFIG_STA_SUPPORT
26798 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
26799 + {
26800 + PEID_STRUCT pEid;
26801 + USHORT Length = 0;
26802 +
26803 +
26804 + NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN);
26805 + NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN);
26806 +#ifdef EXT_BUILD_CHANNEL_LIST
26807 + NdisZeroMemory(&pBss->CountryString[0], 3);
26808 + pBss->bHasCountryIE = FALSE;
26809 +#endif // EXT_BUILD_CHANNEL_LIST //
26810 + pEid = (PEID_STRUCT) pVIE;
26811 + while ((Length + 2 + (USHORT)pEid->Len) <= LengthVIE)
26812 + {
26813 + switch(pEid->Eid)
26814 + {
26815 + case IE_WPA:
26816 + if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
26817 + {
26818 + if ((pEid->Len + 2) > MAX_CUSTOM_LEN)
26819 + {
26820 + pBss->WpaIE.IELen = 0;
26821 + break;
26822 + }
26823 + pBss->WpaIE.IELen = pEid->Len + 2;
26824 + NdisMoveMemory(pBss->WpaIE.IE, pEid, pBss->WpaIE.IELen);
26825 + }
26826 + break;
26827 + case IE_RSN:
26828 + if (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
26829 + {
26830 + if ((pEid->Len + 2) > MAX_CUSTOM_LEN)
26831 + {
26832 + pBss->RsnIE.IELen = 0;
26833 + break;
26834 + }
26835 + pBss->RsnIE.IELen = pEid->Len + 2;
26836 + NdisMoveMemory(pBss->RsnIE.IE, pEid, pBss->RsnIE.IELen);
26837 + }
26838 + break;
26839 +#ifdef EXT_BUILD_CHANNEL_LIST
26840 + case IE_COUNTRY:
26841 + NdisMoveMemory(&pBss->CountryString[0], pEid->Octet, 3);
26842 + pBss->bHasCountryIE = TRUE;
26843 + break;
26844 +#endif // EXT_BUILD_CHANNEL_LIST //
26845 + }
26846 + Length = Length + 2 + (USHORT)pEid->Len; // Eid[1] + Len[1]+ content[Len]
26847 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
26848 + }
26849 + }
26850 +#endif // CONFIG_STA_SUPPORT //
26851 +}
26852 +
26853 +/*!
26854 + * \brief insert an entry into the bss table
26855 + * \param p_tab The BSS table
26856 + * \param Bssid BSSID
26857 + * \param ssid SSID
26858 + * \param ssid_len Length of SSID
26859 + * \param bss_type
26860 + * \param beacon_period
26861 + * \param timestamp
26862 + * \param p_cf
26863 + * \param atim_win
26864 + * \param cap
26865 + * \param rates
26866 + * \param rates_len
26867 + * \param channel_idx
26868 + * \return none
26869 + * \pre
26870 + * \post
26871 + * \note If SSID is identical, the old entry will be replaced by the new one
26872 +
26873 + IRQL = DISPATCH_LEVEL
26874 +
26875 + */
26876 +ULONG BssTableSetEntry(
26877 + IN PRTMP_ADAPTER pAd,
26878 + OUT BSS_TABLE *Tab,
26879 + IN PUCHAR pBssid,
26880 + IN CHAR Ssid[],
26881 + IN UCHAR SsidLen,
26882 + IN UCHAR BssType,
26883 + IN USHORT BeaconPeriod,
26884 + IN CF_PARM *CfParm,
26885 + IN USHORT AtimWin,
26886 + IN USHORT CapabilityInfo,
26887 + IN UCHAR SupRate[],
26888 + IN UCHAR SupRateLen,
26889 + IN UCHAR ExtRate[],
26890 + IN UCHAR ExtRateLen,
26891 + IN HT_CAPABILITY_IE *pHtCapability,
26892 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
26893 + IN UCHAR HtCapabilityLen,
26894 + IN UCHAR AddHtInfoLen,
26895 + IN UCHAR NewExtChanOffset,
26896 + IN UCHAR ChannelNo,
26897 + IN CHAR Rssi,
26898 + IN LARGE_INTEGER TimeStamp,
26899 + IN UCHAR CkipFlag,
26900 + IN PEDCA_PARM pEdcaParm,
26901 + IN PQOS_CAPABILITY_PARM pQosCapability,
26902 + IN PQBSS_LOAD_PARM pQbssLoad,
26903 + IN USHORT LengthVIE,
26904 + IN PNDIS_802_11_VARIABLE_IEs pVIE)
26905 +{
26906 + ULONG Idx;
26907 +
26908 + Idx = BssTableSearchWithSSID(Tab, pBssid, Ssid, SsidLen, ChannelNo);
26909 + if (Idx == BSS_NOT_FOUND)
26910 + {
26911 + if (Tab->BssNr >= MAX_LEN_OF_BSS_TABLE)
26912 + {
26913 + //
26914 + // It may happen when BSS Table was full.
26915 + // The desired AP will not be added into BSS Table
26916 + // In this case, if we found the desired AP then overwrite BSS Table.
26917 + //
26918 + if(!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
26919 + {
26920 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, pBssid) ||
26921 + SSID_EQUAL(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Ssid, SsidLen))
26922 + {
26923 + Idx = Tab->BssOverlapNr;
26924 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin,
26925 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26926 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26927 + Tab->BssOverlapNr = (Tab->BssOverlapNr++) % MAX_LEN_OF_BSS_TABLE;
26928 + }
26929 + return Idx;
26930 + }
26931 + else
26932 + {
26933 + return BSS_NOT_FOUND;
26934 + }
26935 + }
26936 + Idx = Tab->BssNr;
26937 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin,
26938 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26939 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26940 + Tab->BssNr++;
26941 + }
26942 + else
26943 + {
26944 + /* avoid Hidden SSID form beacon to overwirite correct SSID from probe response */
26945 + if ((SSID_EQUAL(Ssid, SsidLen, Tab->BssEntry[Idx].Ssid, Tab->BssEntry[Idx].SsidLen)) ||
26946 + (NdisEqualMemory(Tab->BssEntry[Idx].Ssid, ZeroSsid, Tab->BssEntry[Idx].SsidLen)))
26947 + {
26948 + BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod,CfParm, AtimWin,
26949 + CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen,
26950 + NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE);
26951 + }
26952 + }
26953 +
26954 + return Idx;
26955 +}
26956 +
26957 +#ifdef CONFIG_STA_SUPPORT
26958 +#ifdef DOT11_N_SUPPORT
26959 +#ifdef DOT11N_DRAFT3
26960 +VOID TriEventInit(
26961 + IN PRTMP_ADAPTER pAd)
26962 +{
26963 + UCHAR i;
26964 +
26965 + for (i = 0;i < MAX_TRIGGER_EVENT;i++)
26966 + pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE;
26967 +
26968 + pAd->CommonCfg.TriggerEventTab.EventANo = 0;
26969 + pAd->CommonCfg.TriggerEventTab.EventBCountDown = 0;
26970 +}
26971 +
26972 +ULONG TriEventTableSetEntry(
26973 + IN PRTMP_ADAPTER pAd,
26974 + OUT TRIGGER_EVENT_TAB *Tab,
26975 + IN PUCHAR pBssid,
26976 + IN HT_CAPABILITY_IE *pHtCapability,
26977 + IN UCHAR HtCapabilityLen,
26978 + IN UCHAR RegClass,
26979 + IN UCHAR ChannelNo)
26980 +{
26981 + // Event A
26982 + if (HtCapabilityLen == 0)
26983 + {
26984 + if (Tab->EventANo < MAX_TRIGGER_EVENT)
26985 + {
26986 + RTMPMoveMemory(Tab->EventA[Tab->EventANo].BSSID, pBssid, 6);
26987 + Tab->EventA[Tab->EventANo].bValid = TRUE;
26988 + Tab->EventA[Tab->EventANo].Channel = ChannelNo;
26989 + Tab->EventA[Tab->EventANo].CDCounter = pAd->CommonCfg.Dot11BssWidthChanTranDelay;
26990 + if (RegClass != 0)
26991 + {
26992 + // Beacon has Regulatory class IE. So use beacon's
26993 + Tab->EventA[Tab->EventANo].RegClass = RegClass;
26994 + }
26995 + else
26996 + {
26997 + // Use Station's Regulatory class instead.
26998 + if (pAd->StaActive.SupportedHtPhy.bHtEnable == TRUE)
26999 + {
27000 + if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
27001 + {
27002 + Tab->EventA[Tab->EventANo].RegClass = 32;
27003 + }
27004 + else if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
27005 + Tab->EventA[Tab->EventANo].RegClass = 33;
27006 + }
27007 + else
27008 + Tab->EventA[Tab->EventANo].RegClass = ??;
27009 +
27010 + }
27011 +
27012 + Tab->EventANo ++;
27013 + }
27014 + }
27015 + else if (pHtCapability->HtCapInfo.Intolerant40)
27016 + {
27017 + Tab->EventBCountDown = pAd->CommonCfg.Dot11BssWidthChanTranDelay;
27018 + }
27019 +
27020 +}
27021 +
27022 +/*
27023 + ========================================================================
27024 + Routine Description:
27025 + Trigger Event table Maintainence called once every second.
27026 +
27027 + Arguments:
27028 + // IRQL = DISPATCH_LEVEL
27029 + ========================================================================
27030 +*/
27031 +VOID TriEventCounterMaintenance(
27032 + IN PRTMP_ADAPTER pAd)
27033 +{
27034 + UCHAR i;
27035 + BOOLEAN bNotify = FALSE;
27036 + for (i = 0;i < MAX_TRIGGER_EVENT;i++)
27037 + {
27038 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].bValid && (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter > 0))
27039 + {
27040 + pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter--;
27041 + if (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter == 0)
27042 + {
27043 + pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE;
27044 + pAd->CommonCfg.TriggerEventTab.EventANo --;
27045 + // Need to send 20/40 Coexistence Notify frame if has status change.
27046 + bNotify = TRUE;
27047 + }
27048 + }
27049 + }
27050 + if (pAd->CommonCfg.TriggerEventTab.EventBCountDown > 0)
27051 + {
27052 + pAd->CommonCfg.TriggerEventTab.EventBCountDown--;
27053 + if (pAd->CommonCfg.TriggerEventTab.EventBCountDown == 0)
27054 + bNotify = TRUE;
27055 + }
27056 +
27057 + if (bNotify == TRUE)
27058 + Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
27059 +}
27060 +#endif // DOT11N_DRAFT3 //
27061 +#endif // DOT11_N_SUPPORT //
27062 +
27063 +// IRQL = DISPATCH_LEVEL
27064 +VOID BssTableSsidSort(
27065 + IN PRTMP_ADAPTER pAd,
27066 + OUT BSS_TABLE *OutTab,
27067 + IN CHAR Ssid[],
27068 + IN UCHAR SsidLen)
27069 +{
27070 + INT i;
27071 + BssTableInit(OutTab);
27072 +
27073 + for (i = 0; i < pAd->ScanTab.BssNr; i++)
27074 + {
27075 + BSS_ENTRY *pInBss = &pAd->ScanTab.BssEntry[i];
27076 + BOOLEAN bIsHiddenApIncluded = FALSE;
27077 +
27078 + if (((pAd->CommonCfg.bIEEE80211H == 1) &&
27079 + (pAd->MlmeAux.Channel > 14) &&
27080 + RadarChannelCheck(pAd, pInBss->Channel))
27081 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
27082 + || (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
27083 +#endif // CARRIER_DETECTION_SUPPORT //
27084 + )
27085 + {
27086 + if (pInBss->Hidden)
27087 + bIsHiddenApIncluded = TRUE;
27088 + }
27089 +
27090 + if ((pInBss->BssType == pAd->StaCfg.BssType) &&
27091 + (SSID_EQUAL(Ssid, SsidLen, pInBss->Ssid, pInBss->SsidLen) || bIsHiddenApIncluded))
27092 + {
27093 + BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
27094 +
27095 +
27096 +#ifdef EXT_BUILD_CHANNEL_LIST
27097 + // If no Country IE exists no Connection will be established when IEEE80211dClientMode is strict.
27098 + if ((pAd->StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict) &&
27099 + (pInBss->bHasCountryIE == FALSE))
27100 + {
27101 + DBGPRINT(RT_DEBUG_TRACE,("StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict, but this AP doesn't have country IE.\n"));
27102 + continue;
27103 + }
27104 +#endif // EXT_BUILD_CHANNEL_LIST //
27105 +
27106 +#ifdef DOT11_N_SUPPORT
27107 + // 2.4G/5G N only mode
27108 + if ((pInBss->HtCapabilityLen == 0) &&
27109 + ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)))
27110 + {
27111 + DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
27112 + continue;
27113 + }
27114 +#endif // DOT11_N_SUPPORT //
27115 +
27116 + // New for WPA2
27117 + // Check the Authmode first
27118 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
27119 + {
27120 + // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode
27121 + if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux))
27122 + // None matched
27123 + continue;
27124 +
27125 + // Check cipher suite, AP must have more secured cipher than station setting
27126 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
27127 + {
27128 + // If it's not mixed mode, we should only let BSS pass with the same encryption
27129 + if (pInBss->WPA.bMixMode == FALSE)
27130 + if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher)
27131 + continue;
27132 +
27133 + // check group cipher
27134 + if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher)
27135 + continue;
27136 +
27137 + // check pairwise cipher, skip if none matched
27138 + // If profile set to AES, let it pass without question.
27139 + // If profile set to TKIP, we must find one mateched
27140 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
27141 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) &&
27142 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux))
27143 + continue;
27144 + }
27145 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
27146 + {
27147 + // If it's not mixed mode, we should only let BSS pass with the same encryption
27148 + if (pInBss->WPA2.bMixMode == FALSE)
27149 + if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher)
27150 + continue;
27151 +
27152 + // check group cipher
27153 + if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher)
27154 + continue;
27155 +
27156 + // check pairwise cipher, skip if none matched
27157 + // If profile set to AES, let it pass without question.
27158 + // If profile set to TKIP, we must find one mateched
27159 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
27160 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) &&
27161 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux))
27162 + continue;
27163 + }
27164 + }
27165 + // Bss Type matched, SSID matched.
27166 + // We will check wepstatus for qualification Bss
27167 + else if (pAd->StaCfg.WepStatus != pInBss->WepStatus)
27168 + {
27169 + DBGPRINT(RT_DEBUG_TRACE,("StaCfg.WepStatus=%d, while pInBss->WepStatus=%d\n", pAd->StaCfg.WepStatus, pInBss->WepStatus));
27170 + //
27171 + // For the SESv2 case, we will not qualify WepStatus.
27172 + //
27173 + if (!pInBss->bSES)
27174 + continue;
27175 + }
27176 +
27177 + // Since the AP is using hidden SSID, and we are trying to connect to ANY
27178 + // It definitely will fail. So, skip it.
27179 + // CCX also require not even try to connect it!!
27180 + if (SsidLen == 0)
27181 + continue;
27182 +
27183 +#ifdef DOT11_N_SUPPORT
27184 + // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region
27185 + // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead,
27186 + if ((pInBss->CentralChannel != pInBss->Channel) &&
27187 + (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
27188 + {
27189 + if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE)
27190 + {
27191 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
27192 + SetCommonHT(pAd);
27193 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
27194 + }
27195 + else
27196 + {
27197 + if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BAND_WIDTH_20)
27198 + {
27199 + SetCommonHT(pAd);
27200 + }
27201 + }
27202 + }
27203 +#endif // DOT11_N_SUPPORT //
27204 +
27205 + // copy matching BSS from InTab to OutTab
27206 + NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY));
27207 +
27208 + OutTab->BssNr++;
27209 + }
27210 + else if ((pInBss->BssType == pAd->StaCfg.BssType) && (SsidLen == 0))
27211 + {
27212 + BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
27213 +
27214 +
27215 +#ifdef DOT11_N_SUPPORT
27216 + // 2.4G/5G N only mode
27217 + if ((pInBss->HtCapabilityLen == 0) &&
27218 + ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G)))
27219 + {
27220 + DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
27221 + continue;
27222 + }
27223 +#endif // DOT11_N_SUPPORT //
27224 +
27225 + // New for WPA2
27226 + // Check the Authmode first
27227 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
27228 + {
27229 + // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode
27230 + if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux))
27231 + // None matched
27232 + continue;
27233 +
27234 + // Check cipher suite, AP must have more secured cipher than station setting
27235 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
27236 + {
27237 + // If it's not mixed mode, we should only let BSS pass with the same encryption
27238 + if (pInBss->WPA.bMixMode == FALSE)
27239 + if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher)
27240 + continue;
27241 +
27242 + // check group cipher
27243 + if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher)
27244 + continue;
27245 +
27246 + // check pairwise cipher, skip if none matched
27247 + // If profile set to AES, let it pass without question.
27248 + // If profile set to TKIP, we must find one mateched
27249 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
27250 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) &&
27251 + (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux))
27252 + continue;
27253 + }
27254 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
27255 + {
27256 + // If it's not mixed mode, we should only let BSS pass with the same encryption
27257 + if (pInBss->WPA2.bMixMode == FALSE)
27258 + if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher)
27259 + continue;
27260 +
27261 + // check group cipher
27262 + if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher)
27263 + continue;
27264 +
27265 + // check pairwise cipher, skip if none matched
27266 + // If profile set to AES, let it pass without question.
27267 + // If profile set to TKIP, we must find one mateched
27268 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) &&
27269 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) &&
27270 + (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux))
27271 + continue;
27272 + }
27273 + }
27274 + // Bss Type matched, SSID matched.
27275 + // We will check wepstatus for qualification Bss
27276 + else if (pAd->StaCfg.WepStatus != pInBss->WepStatus)
27277 + continue;
27278 +
27279 +#ifdef DOT11_N_SUPPORT
27280 + // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region
27281 + // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead,
27282 + if ((pInBss->CentralChannel != pInBss->Channel) &&
27283 + (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40))
27284 + {
27285 + if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE)
27286 + {
27287 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
27288 + SetCommonHT(pAd);
27289 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
27290 + }
27291 + }
27292 +#endif // DOT11_N_SUPPORT //
27293 +
27294 + // copy matching BSS from InTab to OutTab
27295 + NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY));
27296 +
27297 + OutTab->BssNr++;
27298 + }
27299 +
27300 + if (OutTab->BssNr >= MAX_LEN_OF_BSS_TABLE)
27301 + break;
27302 + }
27303 +
27304 + BssTableSortByRssi(OutTab);
27305 +}
27306 +
27307 +
27308 +// IRQL = DISPATCH_LEVEL
27309 +VOID BssTableSortByRssi(
27310 + IN OUT BSS_TABLE *OutTab)
27311 +{
27312 + INT i, j;
27313 + BSS_ENTRY TmpBss;
27314 +
27315 + for (i = 0; i < OutTab->BssNr - 1; i++)
27316 + {
27317 + for (j = i+1; j < OutTab->BssNr; j++)
27318 + {
27319 + if (OutTab->BssEntry[j].Rssi > OutTab->BssEntry[i].Rssi)
27320 + {
27321 + NdisMoveMemory(&TmpBss, &OutTab->BssEntry[j], sizeof(BSS_ENTRY));
27322 + NdisMoveMemory(&OutTab->BssEntry[j], &OutTab->BssEntry[i], sizeof(BSS_ENTRY));
27323 + NdisMoveMemory(&OutTab->BssEntry[i], &TmpBss, sizeof(BSS_ENTRY));
27324 + }
27325 + }
27326 + }
27327 +}
27328 +#endif // CONFIG_STA_SUPPORT //
27329 +
27330 +
27331 +VOID BssCipherParse(
27332 + IN OUT PBSS_ENTRY pBss)
27333 +{
27334 + PEID_STRUCT pEid;
27335 + PUCHAR pTmp;
27336 + PRSN_IE_HEADER_STRUCT pRsnHeader;
27337 + PCIPHER_SUITE_STRUCT pCipher;
27338 + PAKM_SUITE_STRUCT pAKM;
27339 + USHORT Count;
27340 + INT Length;
27341 + NDIS_802_11_ENCRYPTION_STATUS TmpCipher;
27342 +
27343 + //
27344 + // WepStatus will be reset later, if AP announce TKIP or AES on the beacon frame.
27345 + //
27346 + if (pBss->Privacy)
27347 + {
27348 + pBss->WepStatus = Ndis802_11WEPEnabled;
27349 + }
27350 + else
27351 + {
27352 + pBss->WepStatus = Ndis802_11WEPDisabled;
27353 + }
27354 + // Set default to disable & open authentication before parsing variable IE
27355 + pBss->AuthMode = Ndis802_11AuthModeOpen;
27356 + pBss->AuthModeAux = Ndis802_11AuthModeOpen;
27357 +
27358 + // Init WPA setting
27359 + pBss->WPA.PairCipher = Ndis802_11WEPDisabled;
27360 + pBss->WPA.PairCipherAux = Ndis802_11WEPDisabled;
27361 + pBss->WPA.GroupCipher = Ndis802_11WEPDisabled;
27362 + pBss->WPA.RsnCapability = 0;
27363 + pBss->WPA.bMixMode = FALSE;
27364 +
27365 + // Init WPA2 setting
27366 + pBss->WPA2.PairCipher = Ndis802_11WEPDisabled;
27367 + pBss->WPA2.PairCipherAux = Ndis802_11WEPDisabled;
27368 + pBss->WPA2.GroupCipher = Ndis802_11WEPDisabled;
27369 + pBss->WPA2.RsnCapability = 0;
27370 + pBss->WPA2.bMixMode = FALSE;
27371 +
27372 +
27373 + Length = (INT) pBss->VarIELen;
27374 +
27375 + while (Length > 0)
27376 + {
27377 + // Parse cipher suite base on WPA1 & WPA2, they should be parsed differently
27378 + pTmp = ((PUCHAR) pBss->VarIEs) + pBss->VarIELen - Length;
27379 + pEid = (PEID_STRUCT) pTmp;
27380 + switch (pEid->Eid)
27381 + {
27382 + case IE_WPA:
27383 + //Parse Cisco IE_WPA (LEAP, CCKM, etc.)
27384 + if ( NdisEqualMemory((pTmp+8), CISCO_OUI, 3))
27385 + {
27386 + pTmp += 11;
27387 + switch (*pTmp)
27388 + {
27389 + case 1:
27390 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27391 + pBss->WepStatus = Ndis802_11Encryption1Enabled;
27392 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27393 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27394 + break;
27395 + case 2:
27396 + pBss->WepStatus = Ndis802_11Encryption2Enabled;
27397 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27398 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27399 + break;
27400 + case 4:
27401 + pBss->WepStatus = Ndis802_11Encryption3Enabled;
27402 + pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled;
27403 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27404 + break;
27405 + default:
27406 + break;
27407 + }
27408 +
27409 + // if Cisco IE_WPA, break
27410 + break;
27411 + }
27412 + else if (NdisEqualMemory(pEid->Octet, SES_OUI, 3) && (pEid->Len == 7))
27413 + {
27414 + pBss->bSES = TRUE;
27415 + break;
27416 + }
27417 + else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4) != 1)
27418 + {
27419 + // if unsupported vendor specific IE
27420 + break;
27421 + }
27422 + // Skip OUI, version, and multicast suite
27423 + // This part should be improved in the future when AP supported multiple cipher suite.
27424 + // For now, it's OK since almost all APs have fixed cipher suite supported.
27425 + // pTmp = (PUCHAR) pEid->Octet;
27426 + pTmp += 11;
27427 +
27428 + // Cipher Suite Selectors from Spec P802.11i/D3.2 P26.
27429 + // Value Meaning
27430 + // 0 None
27431 + // 1 WEP-40
27432 + // 2 Tkip
27433 + // 3 WRAP
27434 + // 4 AES
27435 + // 5 WEP-104
27436 + // Parse group cipher
27437 + switch (*pTmp)
27438 + {
27439 + case 1:
27440 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27441 + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled;
27442 + break;
27443 + case 2:
27444 + pBss->WPA.GroupCipher = Ndis802_11Encryption2Enabled;
27445 + break;
27446 + case 4:
27447 + pBss->WPA.GroupCipher = Ndis802_11Encryption3Enabled;
27448 + break;
27449 + default:
27450 + break;
27451 + }
27452 + // number of unicast suite
27453 + pTmp += 1;
27454 +
27455 + // skip all unicast cipher suites
27456 + //Count = *(PUSHORT) pTmp;
27457 + Count = (pTmp[1]<<8) + pTmp[0];
27458 + pTmp += sizeof(USHORT);
27459 +
27460 + // Parsing all unicast cipher suite
27461 + while (Count > 0)
27462 + {
27463 + // Skip OUI
27464 + pTmp += 3;
27465 + TmpCipher = Ndis802_11WEPDisabled;
27466 + switch (*pTmp)
27467 + {
27468 + case 1:
27469 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27470 + TmpCipher = Ndis802_11Encryption1Enabled;
27471 + break;
27472 + case 2:
27473 + TmpCipher = Ndis802_11Encryption2Enabled;
27474 + break;
27475 + case 4:
27476 + TmpCipher = Ndis802_11Encryption3Enabled;
27477 + break;
27478 + default:
27479 + break;
27480 + }
27481 + if (TmpCipher > pBss->WPA.PairCipher)
27482 + {
27483 + // Move the lower cipher suite to PairCipherAux
27484 + pBss->WPA.PairCipherAux = pBss->WPA.PairCipher;
27485 + pBss->WPA.PairCipher = TmpCipher;
27486 + }
27487 + else
27488 + {
27489 + pBss->WPA.PairCipherAux = TmpCipher;
27490 + }
27491 + pTmp++;
27492 + Count--;
27493 + }
27494 +
27495 + // 4. get AKM suite counts
27496 + //Count = *(PUSHORT) pTmp;
27497 + Count = (pTmp[1]<<8) + pTmp[0];
27498 + pTmp += sizeof(USHORT);
27499 + pTmp += 3;
27500 +
27501 + switch (*pTmp)
27502 + {
27503 + case 1:
27504 + // Set AP support WPA mode
27505 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27506 + pBss->AuthMode = Ndis802_11AuthModeWPA;
27507 + else
27508 + pBss->AuthModeAux = Ndis802_11AuthModeWPA;
27509 + break;
27510 + case 2:
27511 + // Set AP support WPA mode
27512 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27513 + pBss->AuthMode = Ndis802_11AuthModeWPAPSK;
27514 + else
27515 + pBss->AuthModeAux = Ndis802_11AuthModeWPAPSK;
27516 + break;
27517 + default:
27518 + break;
27519 + }
27520 + pTmp += 1;
27521 +
27522 + // Fixed for WPA-None
27523 + if (pBss->BssType == BSS_ADHOC)
27524 + {
27525 + pBss->AuthMode = Ndis802_11AuthModeWPANone;
27526 + pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
27527 + pBss->WepStatus = pBss->WPA.GroupCipher;
27528 + if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled)
27529 + pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher;
27530 + }
27531 + else
27532 + pBss->WepStatus = pBss->WPA.PairCipher;
27533 +
27534 + // Check the Pair & Group, if different, turn on mixed mode flag
27535 + if (pBss->WPA.GroupCipher != pBss->WPA.PairCipher)
27536 + pBss->WPA.bMixMode = TRUE;
27537 +
27538 + break;
27539 +
27540 + case IE_RSN:
27541 + pRsnHeader = (PRSN_IE_HEADER_STRUCT) pTmp;
27542 +
27543 + // 0. Version must be 1
27544 + if (le2cpu16(pRsnHeader->Version) != 1)
27545 + break;
27546 + pTmp += sizeof(RSN_IE_HEADER_STRUCT);
27547 +
27548 + // 1. Check group cipher
27549 + pCipher = (PCIPHER_SUITE_STRUCT) pTmp;
27550 + if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
27551 + break;
27552 +
27553 + // Parse group cipher
27554 + switch (pCipher->Type)
27555 + {
27556 + case 1:
27557 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27558 + pBss->WPA2.GroupCipher = Ndis802_11Encryption1Enabled;
27559 + break;
27560 + case 2:
27561 + pBss->WPA2.GroupCipher = Ndis802_11Encryption2Enabled;
27562 + break;
27563 + case 4:
27564 + pBss->WPA2.GroupCipher = Ndis802_11Encryption3Enabled;
27565 + break;
27566 + default:
27567 + break;
27568 + }
27569 + // set to correct offset for next parsing
27570 + pTmp += sizeof(CIPHER_SUITE_STRUCT);
27571 +
27572 + // 2. Get pairwise cipher counts
27573 + //Count = *(PUSHORT) pTmp;
27574 + Count = (pTmp[1]<<8) + pTmp[0];
27575 + pTmp += sizeof(USHORT);
27576 +
27577 + // 3. Get pairwise cipher
27578 + // Parsing all unicast cipher suite
27579 + while (Count > 0)
27580 + {
27581 + // Skip OUI
27582 + pCipher = (PCIPHER_SUITE_STRUCT) pTmp;
27583 + TmpCipher = Ndis802_11WEPDisabled;
27584 + switch (pCipher->Type)
27585 + {
27586 + case 1:
27587 + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway
27588 + TmpCipher = Ndis802_11Encryption1Enabled;
27589 + break;
27590 + case 2:
27591 + TmpCipher = Ndis802_11Encryption2Enabled;
27592 + break;
27593 + case 4:
27594 + TmpCipher = Ndis802_11Encryption3Enabled;
27595 + break;
27596 + default:
27597 + break;
27598 + }
27599 + if (TmpCipher > pBss->WPA2.PairCipher)
27600 + {
27601 + // Move the lower cipher suite to PairCipherAux
27602 + pBss->WPA2.PairCipherAux = pBss->WPA2.PairCipher;
27603 + pBss->WPA2.PairCipher = TmpCipher;
27604 + }
27605 + else
27606 + {
27607 + pBss->WPA2.PairCipherAux = TmpCipher;
27608 + }
27609 + pTmp += sizeof(CIPHER_SUITE_STRUCT);
27610 + Count--;
27611 + }
27612 +
27613 + // 4. get AKM suite counts
27614 + //Count = *(PUSHORT) pTmp;
27615 + Count = (pTmp[1]<<8) + pTmp[0];
27616 + pTmp += sizeof(USHORT);
27617 +
27618 + // 5. Get AKM ciphers
27619 + pAKM = (PAKM_SUITE_STRUCT) pTmp;
27620 + if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
27621 + break;
27622 +
27623 + switch (pAKM->Type)
27624 + {
27625 + case 1:
27626 + // Set AP support WPA mode
27627 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27628 + pBss->AuthMode = Ndis802_11AuthModeWPA2;
27629 + else
27630 + pBss->AuthModeAux = Ndis802_11AuthModeWPA2;
27631 + break;
27632 + case 2:
27633 + // Set AP support WPA mode
27634 + if (pBss->AuthMode == Ndis802_11AuthModeOpen)
27635 + pBss->AuthMode = Ndis802_11AuthModeWPA2PSK;
27636 + else
27637 + pBss->AuthModeAux = Ndis802_11AuthModeWPA2PSK;
27638 + break;
27639 + default:
27640 + break;
27641 + }
27642 + pTmp += (Count * sizeof(AKM_SUITE_STRUCT));
27643 +
27644 + // Fixed for WPA-None
27645 + if (pBss->BssType == BSS_ADHOC)
27646 + {
27647 + pBss->AuthMode = Ndis802_11AuthModeWPANone;
27648 + pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
27649 + pBss->WPA.PairCipherAux = pBss->WPA2.PairCipherAux;
27650 + pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher;
27651 + pBss->WepStatus = pBss->WPA.GroupCipher;
27652 + if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled)
27653 + pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher;
27654 + }
27655 + pBss->WepStatus = pBss->WPA2.PairCipher;
27656 +
27657 + // 6. Get RSN capability
27658 + //pBss->WPA2.RsnCapability = *(PUSHORT) pTmp;
27659 + pBss->WPA2.RsnCapability = (pTmp[1]<<8) + pTmp[0];
27660 + pTmp += sizeof(USHORT);
27661 +
27662 + // Check the Pair & Group, if different, turn on mixed mode flag
27663 + if (pBss->WPA2.GroupCipher != pBss->WPA2.PairCipher)
27664 + pBss->WPA2.bMixMode = TRUE;
27665 +
27666 + break;
27667 + default:
27668 + break;
27669 + }
27670 + Length -= (pEid->Len + 2);
27671 + }
27672 +}
27673 +
27674 +// ===========================================================================================
27675 +// mac_table.c
27676 +// ===========================================================================================
27677 +
27678 +/*! \brief generates a random mac address value for IBSS BSSID
27679 + * \param Addr the bssid location
27680 + * \return none
27681 + * \pre
27682 + * \post
27683 + */
27684 +VOID MacAddrRandomBssid(
27685 + IN PRTMP_ADAPTER pAd,
27686 + OUT PUCHAR pAddr)
27687 +{
27688 + INT i;
27689 +
27690 + for (i = 0; i < MAC_ADDR_LEN; i++)
27691 + {
27692 + pAddr[i] = RandomByte(pAd);
27693 + }
27694 +
27695 + pAddr[0] = (pAddr[0] & 0xfe) | 0x02; // the first 2 bits must be 01xxxxxxxx
27696 +}
27697 +
27698 +/*! \brief init the management mac frame header
27699 + * \param p_hdr mac header
27700 + * \param subtype subtype of the frame
27701 + * \param p_ds destination address, don't care if it is a broadcast address
27702 + * \return none
27703 + * \pre the station has the following information in the pAd->StaCfg
27704 + * - bssid
27705 + * - station address
27706 + * \post
27707 + * \note this function initializes the following field
27708 +
27709 + IRQL = PASSIVE_LEVEL
27710 + IRQL = DISPATCH_LEVEL
27711 +
27712 + */
27713 +VOID MgtMacHeaderInit(
27714 + IN PRTMP_ADAPTER pAd,
27715 + IN OUT PHEADER_802_11 pHdr80211,
27716 + IN UCHAR SubType,
27717 + IN UCHAR ToDs,
27718 + IN PUCHAR pDA,
27719 + IN PUCHAR pBssid)
27720 +{
27721 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
27722 +
27723 + pHdr80211->FC.Type = BTYPE_MGMT;
27724 + pHdr80211->FC.SubType = SubType;
27725 +// if (SubType == SUBTYPE_ACK) // sample, no use, it will conflict with ACTION frame sub type
27726 +// pHdr80211->FC.Type = BTYPE_CNTL;
27727 + pHdr80211->FC.ToDs = ToDs;
27728 + COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
27729 +#ifdef CONFIG_STA_SUPPORT
27730 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27731 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
27732 +#endif // CONFIG_STA_SUPPORT //
27733 + COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
27734 +}
27735 +
27736 +// ===========================================================================================
27737 +// mem_mgmt.c
27738 +// ===========================================================================================
27739 +
27740 +/*!***************************************************************************
27741 + * This routine build an outgoing frame, and fill all information specified
27742 + * in argument list to the frame body. The actual frame size is the summation
27743 + * of all arguments.
27744 + * input params:
27745 + * Buffer - pointer to a pre-allocated memory segment
27746 + * args - a list of <int arg_size, arg> pairs.
27747 + * NOTE NOTE NOTE!!!! the last argument must be NULL, otherwise this
27748 + * function will FAIL!!!
27749 + * return:
27750 + * Size of the buffer
27751 + * usage:
27752 + * MakeOutgoingFrame(Buffer, output_length, 2, &fc, 2, &dur, 6, p_addr1, 6,p_addr2, END_OF_ARGS);
27753 +
27754 + IRQL = PASSIVE_LEVEL
27755 + IRQL = DISPATCH_LEVEL
27756 +
27757 + ****************************************************************************/
27758 +ULONG MakeOutgoingFrame(
27759 + OUT CHAR *Buffer,
27760 + OUT ULONG *FrameLen, ...)
27761 +{
27762 + CHAR *p;
27763 + int leng;
27764 + ULONG TotLeng;
27765 + va_list Args;
27766 +
27767 + // calculates the total length
27768 + TotLeng = 0;
27769 + va_start(Args, FrameLen);
27770 + do
27771 + {
27772 + leng = va_arg(Args, int);
27773 + if (leng == END_OF_ARGS)
27774 + {
27775 + break;
27776 + }
27777 + p = va_arg(Args, PVOID);
27778 + NdisMoveMemory(&Buffer[TotLeng], p, leng);
27779 + TotLeng = TotLeng + leng;
27780 + } while(TRUE);
27781 +
27782 + va_end(Args); /* clean up */
27783 + *FrameLen = TotLeng;
27784 + return TotLeng;
27785 +}
27786 +
27787 +// ===========================================================================================
27788 +// mlme_queue.c
27789 +// ===========================================================================================
27790 +
27791 +/*! \brief Initialize The MLME Queue, used by MLME Functions
27792 + * \param *Queue The MLME Queue
27793 + * \return Always Return NDIS_STATE_SUCCESS in this implementation
27794 + * \pre
27795 + * \post
27796 + * \note Because this is done only once (at the init stage), no need to be locked
27797 +
27798 + IRQL = PASSIVE_LEVEL
27799 +
27800 + */
27801 +NDIS_STATUS MlmeQueueInit(
27802 + IN MLME_QUEUE *Queue)
27803 +{
27804 + INT i;
27805 +
27806 + NdisAllocateSpinLock(&Queue->Lock);
27807 +
27808 + Queue->Num = 0;
27809 + Queue->Head = 0;
27810 + Queue->Tail = 0;
27811 +
27812 + for (i = 0; i < MAX_LEN_OF_MLME_QUEUE; i++)
27813 + {
27814 + Queue->Entry[i].Occupied = FALSE;
27815 + Queue->Entry[i].MsgLen = 0;
27816 + NdisZeroMemory(Queue->Entry[i].Msg, MGMT_DMA_BUFFER_SIZE);
27817 + }
27818 +
27819 + return NDIS_STATUS_SUCCESS;
27820 +}
27821 +
27822 +/*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread
27823 + * \param *Queue The MLME Queue
27824 + * \param Machine The State Machine Id
27825 + * \param MsgType The Message Type
27826 + * \param MsgLen The Message length
27827 + * \param *Msg The message pointer
27828 + * \return TRUE if enqueue is successful, FALSE if the queue is full
27829 + * \pre
27830 + * \post
27831 + * \note The message has to be initialized
27832 +
27833 + IRQL = PASSIVE_LEVEL
27834 + IRQL = DISPATCH_LEVEL
27835 +
27836 + */
27837 +BOOLEAN MlmeEnqueue(
27838 + IN PRTMP_ADAPTER pAd,
27839 + IN ULONG Machine,
27840 + IN ULONG MsgType,
27841 + IN ULONG MsgLen,
27842 + IN VOID *Msg)
27843 +{
27844 + INT Tail;
27845 + MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue;
27846 +
27847 + // Do nothing if the driver is starting halt state.
27848 + // This might happen when timer already been fired before cancel timer with mlmehalt
27849 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
27850 + return FALSE;
27851 +
27852 + // First check the size, it MUST not exceed the mlme queue size
27853 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
27854 + {
27855 + DBGPRINT_ERR(("MlmeEnqueue: msg too large, size = %ld \n", MsgLen));
27856 + return FALSE;
27857 + }
27858 +
27859 + if (MlmeQueueFull(Queue))
27860 + {
27861 + return FALSE;
27862 + }
27863 +
27864 + NdisAcquireSpinLock(&(Queue->Lock));
27865 + Tail = Queue->Tail;
27866 + Queue->Tail++;
27867 + Queue->Num++;
27868 + if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE)
27869 + {
27870 + Queue->Tail = 0;
27871 + }
27872 +
27873 + Queue->Entry[Tail].Wcid = RESERVED_WCID;
27874 + Queue->Entry[Tail].Occupied = TRUE;
27875 + Queue->Entry[Tail].Machine = Machine;
27876 + Queue->Entry[Tail].MsgType = MsgType;
27877 + Queue->Entry[Tail].MsgLen = MsgLen;
27878 +
27879 + if (Msg != NULL)
27880 + {
27881 + NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
27882 + }
27883 +
27884 + NdisReleaseSpinLock(&(Queue->Lock));
27885 + return TRUE;
27886 +}
27887 +
27888 +/*! \brief This function is used when Recv gets a MLME message
27889 + * \param *Queue The MLME Queue
27890 + * \param TimeStampHigh The upper 32 bit of timestamp
27891 + * \param TimeStampLow The lower 32 bit of timestamp
27892 + * \param Rssi The receiving RSSI strength
27893 + * \param MsgLen The length of the message
27894 + * \param *Msg The message pointer
27895 + * \return TRUE if everything ok, FALSE otherwise (like Queue Full)
27896 + * \pre
27897 + * \post
27898 +
27899 + IRQL = DISPATCH_LEVEL
27900 +
27901 + */
27902 +BOOLEAN MlmeEnqueueForRecv(
27903 + IN PRTMP_ADAPTER pAd,
27904 + IN ULONG Wcid,
27905 + IN ULONG TimeStampHigh,
27906 + IN ULONG TimeStampLow,
27907 + IN UCHAR Rssi0,
27908 + IN UCHAR Rssi1,
27909 + IN UCHAR Rssi2,
27910 + IN ULONG MsgLen,
27911 + IN VOID *Msg,
27912 + IN UCHAR Signal)
27913 +{
27914 + INT Tail, Machine;
27915 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
27916 + INT MsgType;
27917 + MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue;
27918 +
27919 +#ifdef RALINK_ATE
27920 + /* Nothing to do in ATE mode */
27921 + if(ATE_ON(pAd))
27922 + return FALSE;
27923 +#endif // RALINK_ATE //
27924 +
27925 + // Do nothing if the driver is starting halt state.
27926 + // This might happen when timer already been fired before cancel timer with mlmehalt
27927 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
27928 + {
27929 + DBGPRINT_ERR(("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n"));
27930 + return FALSE;
27931 + }
27932 +
27933 + // First check the size, it MUST not exceed the mlme queue size
27934 + if (MsgLen > MGMT_DMA_BUFFER_SIZE)
27935 + {
27936 + DBGPRINT_ERR(("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen));
27937 + return FALSE;
27938 + }
27939 +
27940 + if (MlmeQueueFull(Queue))
27941 + {
27942 + return FALSE;
27943 + }
27944 +
27945 +#ifdef CONFIG_STA_SUPPORT
27946 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
27947 + {
27948 + if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType))
27949 + {
27950 + DBGPRINT_ERR(("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n",pFrame->Hdr.FC.SubType));
27951 + return FALSE;
27952 + }
27953 + }
27954 +#endif // CONFIG_STA_SUPPORT //
27955 +
27956 + // OK, we got all the informations, it is time to put things into queue
27957 + NdisAcquireSpinLock(&(Queue->Lock));
27958 + Tail = Queue->Tail;
27959 + Queue->Tail++;
27960 + Queue->Num++;
27961 + if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE)
27962 + {
27963 + Queue->Tail = 0;
27964 + }
27965 + Queue->Entry[Tail].Occupied = TRUE;
27966 + Queue->Entry[Tail].Machine = Machine;
27967 + Queue->Entry[Tail].MsgType = MsgType;
27968 + Queue->Entry[Tail].MsgLen = MsgLen;
27969 + Queue->Entry[Tail].TimeStamp.u.LowPart = TimeStampLow;
27970 + Queue->Entry[Tail].TimeStamp.u.HighPart = TimeStampHigh;
27971 + Queue->Entry[Tail].Rssi0 = Rssi0;
27972 + Queue->Entry[Tail].Rssi1 = Rssi1;
27973 + Queue->Entry[Tail].Rssi2 = Rssi2;
27974 + Queue->Entry[Tail].Signal = Signal;
27975 + Queue->Entry[Tail].Wcid = (UCHAR)Wcid;
27976 +
27977 + Queue->Entry[Tail].Channel = pAd->LatchRfRegs.Channel;
27978 +
27979 + if (Msg != NULL)
27980 + {
27981 + NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
27982 + }
27983 +
27984 + NdisReleaseSpinLock(&(Queue->Lock));
27985 +
27986 + RT28XX_MLME_HANDLER(pAd);
27987 +
27988 + return TRUE;
27989 +}
27990 +
27991 +
27992 +/*! \brief Dequeue a message from the MLME Queue
27993 + * \param *Queue The MLME Queue
27994 + * \param *Elem The message dequeued from MLME Queue
27995 + * \return TRUE if the Elem contains something, FALSE otherwise
27996 + * \pre
27997 + * \post
27998 +
27999 + IRQL = DISPATCH_LEVEL
28000 +
28001 + */
28002 +BOOLEAN MlmeDequeue(
28003 + IN MLME_QUEUE *Queue,
28004 + OUT MLME_QUEUE_ELEM **Elem)
28005 +{
28006 + NdisAcquireSpinLock(&(Queue->Lock));
28007 + *Elem = &(Queue->Entry[Queue->Head]);
28008 + Queue->Num--;
28009 + Queue->Head++;
28010 + if (Queue->Head == MAX_LEN_OF_MLME_QUEUE)
28011 + {
28012 + Queue->Head = 0;
28013 + }
28014 + NdisReleaseSpinLock(&(Queue->Lock));
28015 + return TRUE;
28016 +}
28017 +
28018 +// IRQL = DISPATCH_LEVEL
28019 +VOID MlmeRestartStateMachine(
28020 + IN PRTMP_ADAPTER pAd)
28021 +{
28022 +#ifdef CONFIG_STA_SUPPORT
28023 + BOOLEAN Cancelled;
28024 +#endif // CONFIG_STA_SUPPORT //
28025 +
28026 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n"));
28027 +
28028 +
28029 +#ifdef CONFIG_STA_SUPPORT
28030 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
28031 + {
28032 +#ifdef QOS_DLS_SUPPORT
28033 + UCHAR i;
28034 +#endif // QOS_DLS_SUPPORT //
28035 + // Cancel all timer events
28036 + // Be careful to cancel new added timer
28037 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
28038 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
28039 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
28040 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
28041 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
28042 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
28043 +
28044 +#ifdef QOS_DLS_SUPPORT
28045 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
28046 + {
28047 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled);
28048 + }
28049 +#endif // QOS_DLS_SUPPORT //
28050 + }
28051 +#endif // CONFIG_STA_SUPPORT //
28052 +
28053 + // Change back to original channel in case of doing scan
28054 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
28055 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
28056 +
28057 + // Resume MSDU which is turned off durning scan
28058 + RTMPResumeMsduTransmission(pAd);
28059 +
28060 +#ifdef CONFIG_STA_SUPPORT
28061 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
28062 + {
28063 + // Set all state machines back IDLE
28064 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
28065 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
28066 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
28067 + pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
28068 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
28069 + pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
28070 +#ifdef QOS_DLS_SUPPORT
28071 + pAd->Mlme.DlsMachine.CurrState = DLS_IDLE;
28072 +#endif // QOS_DLS_SUPPORT //
28073 + }
28074 +#endif // CONFIG_STA_SUPPORT //
28075 +
28076 +}
28077 +
28078 +/*! \brief test if the MLME Queue is empty
28079 + * \param *Queue The MLME Queue
28080 + * \return TRUE if the Queue is empty, FALSE otherwise
28081 + * \pre
28082 + * \post
28083 +
28084 + IRQL = DISPATCH_LEVEL
28085 +
28086 + */
28087 +BOOLEAN MlmeQueueEmpty(
28088 + IN MLME_QUEUE *Queue)
28089 +{
28090 + BOOLEAN Ans;
28091 +
28092 + NdisAcquireSpinLock(&(Queue->Lock));
28093 + Ans = (Queue->Num == 0);
28094 + NdisReleaseSpinLock(&(Queue->Lock));
28095 +
28096 + return Ans;
28097 +}
28098 +
28099 +/*! \brief test if the MLME Queue is full
28100 + * \param *Queue The MLME Queue
28101 + * \return TRUE if the Queue is empty, FALSE otherwise
28102 + * \pre
28103 + * \post
28104 +
28105 + IRQL = PASSIVE_LEVEL
28106 + IRQL = DISPATCH_LEVEL
28107 +
28108 + */
28109 +BOOLEAN MlmeQueueFull(
28110 + IN MLME_QUEUE *Queue)
28111 +{
28112 + BOOLEAN Ans;
28113 +
28114 + NdisAcquireSpinLock(&(Queue->Lock));
28115 + Ans = (Queue->Num == MAX_LEN_OF_MLME_QUEUE || Queue->Entry[Queue->Tail].Occupied);
28116 + NdisReleaseSpinLock(&(Queue->Lock));
28117 +
28118 + return Ans;
28119 +}
28120 +
28121 +/*! \brief The destructor of MLME Queue
28122 + * \param
28123 + * \return
28124 + * \pre
28125 + * \post
28126 + * \note Clear Mlme Queue, Set Queue->Num to Zero.
28127 +
28128 + IRQL = PASSIVE_LEVEL
28129 +
28130 + */
28131 +VOID MlmeQueueDestroy(
28132 + IN MLME_QUEUE *pQueue)
28133 +{
28134 + NdisAcquireSpinLock(&(pQueue->Lock));
28135 + pQueue->Num = 0;
28136 + pQueue->Head = 0;
28137 + pQueue->Tail = 0;
28138 + NdisReleaseSpinLock(&(pQueue->Lock));
28139 + NdisFreeSpinLock(&(pQueue->Lock));
28140 +}
28141 +
28142 +/*! \brief To substitute the message type if the message is coming from external
28143 + * \param pFrame The frame received
28144 + * \param *Machine The state machine
28145 + * \param *MsgType the message type for the state machine
28146 + * \return TRUE if the substitution is successful, FALSE otherwise
28147 + * \pre
28148 + * \post
28149 +
28150 + IRQL = DISPATCH_LEVEL
28151 +
28152 + */
28153 +#ifdef CONFIG_STA_SUPPORT
28154 +BOOLEAN MsgTypeSubst(
28155 + IN PRTMP_ADAPTER pAd,
28156 + IN PFRAME_802_11 pFrame,
28157 + OUT INT *Machine,
28158 + OUT INT *MsgType)
28159 +{
28160 + USHORT Seq;
28161 + UCHAR EAPType;
28162 + PUCHAR pData;
28163 +
28164 + // Pointer to start of data frames including SNAP header
28165 + pData = (PUCHAR) pFrame + LENGTH_802_11;
28166 +
28167 + // The only data type will pass to this function is EAPOL frame
28168 + if (pFrame->Hdr.FC.Type == BTYPE_DATA)
28169 + {
28170 + if (NdisEqualMemory(SNAP_AIRONET, pData, LENGTH_802_1_H))
28171 + {
28172 + // Cisco Aironet SNAP header
28173 + *Machine = AIRONET_STATE_MACHINE;
28174 + *MsgType = MT2_AIRONET_MSG;
28175 + return (TRUE);
28176 + }
28177 +#ifdef LEAP_SUPPORT
28178 + if ( pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP ) //LEAP
28179 + {
28180 + // LEAP frames
28181 + *Machine = LEAP_STATE_MACHINE;
28182 + EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1);
28183 + return (LeapMsgTypeSubst(EAPType, MsgType));
28184 + }
28185 + else
28186 +#endif // LEAP_SUPPORT //
28187 + {
28188 + *Machine = WPA_PSK_STATE_MACHINE;
28189 + EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1);
28190 + return(WpaMsgTypeSubst(EAPType, MsgType));
28191 + }
28192 + }
28193 +
28194 + switch (pFrame->Hdr.FC.SubType)
28195 + {
28196 + case SUBTYPE_ASSOC_REQ:
28197 + *Machine = ASSOC_STATE_MACHINE;
28198 + *MsgType = MT2_PEER_ASSOC_REQ;
28199 + break;
28200 + case SUBTYPE_ASSOC_RSP:
28201 + *Machine = ASSOC_STATE_MACHINE;
28202 + *MsgType = MT2_PEER_ASSOC_RSP;
28203 + break;
28204 + case SUBTYPE_REASSOC_REQ:
28205 + *Machine = ASSOC_STATE_MACHINE;
28206 + *MsgType = MT2_PEER_REASSOC_REQ;
28207 + break;
28208 + case SUBTYPE_REASSOC_RSP:
28209 + *Machine = ASSOC_STATE_MACHINE;
28210 + *MsgType = MT2_PEER_REASSOC_RSP;
28211 + break;
28212 + case SUBTYPE_PROBE_REQ:
28213 + *Machine = SYNC_STATE_MACHINE;
28214 + *MsgType = MT2_PEER_PROBE_REQ;
28215 + break;
28216 + case SUBTYPE_PROBE_RSP:
28217 + *Machine = SYNC_STATE_MACHINE;
28218 + *MsgType = MT2_PEER_PROBE_RSP;
28219 + break;
28220 + case SUBTYPE_BEACON:
28221 + *Machine = SYNC_STATE_MACHINE;
28222 + *MsgType = MT2_PEER_BEACON;
28223 + break;
28224 + case SUBTYPE_ATIM:
28225 + *Machine = SYNC_STATE_MACHINE;
28226 + *MsgType = MT2_PEER_ATIM;
28227 + break;
28228 + case SUBTYPE_DISASSOC:
28229 + *Machine = ASSOC_STATE_MACHINE;
28230 + *MsgType = MT2_PEER_DISASSOC_REQ;
28231 + break;
28232 + case SUBTYPE_AUTH:
28233 + // get the sequence number from payload 24 Mac Header + 2 bytes algorithm
28234 + NdisMoveMemory(&Seq, &pFrame->Octet[2], sizeof(USHORT));
28235 + if (Seq == 1 || Seq == 3)
28236 + {
28237 + *Machine = AUTH_RSP_STATE_MACHINE;
28238 + *MsgType = MT2_PEER_AUTH_ODD;
28239 + }
28240 + else if (Seq == 2 || Seq == 4)
28241 + {
28242 + *Machine = AUTH_STATE_MACHINE;
28243 + *MsgType = MT2_PEER_AUTH_EVEN;
28244 + }
28245 + else
28246 + {
28247 + return FALSE;
28248 + }
28249 + break;
28250 + case SUBTYPE_DEAUTH:
28251 + *Machine = AUTH_RSP_STATE_MACHINE;
28252 + *MsgType = MT2_PEER_DEAUTH;
28253 + break;
28254 + case SUBTYPE_ACTION:
28255 + *Machine = ACTION_STATE_MACHINE;
28256 + // Sometimes Sta will return with category bytes with MSB = 1, if they receive catogory out of their support
28257 + if ((pFrame->Octet[0]&0x7F) > MAX_PEER_CATE_MSG)
28258 + {
28259 + *MsgType = MT2_ACT_INVALID;
28260 + }
28261 + else
28262 + {
28263 + *MsgType = (pFrame->Octet[0]&0x7F);
28264 + }
28265 + break;
28266 + default:
28267 + return FALSE;
28268 + break;
28269 + }
28270 +
28271 + return TRUE;
28272 +}
28273 +#endif // CONFIG_STA_SUPPORT //
28274 +
28275 +// ===========================================================================================
28276 +// state_machine.c
28277 +// ===========================================================================================
28278 +
28279 +/*! \brief Initialize the state machine.
28280 + * \param *S pointer to the state machine
28281 + * \param Trans State machine transition function
28282 + * \param StNr number of states
28283 + * \param MsgNr number of messages
28284 + * \param DefFunc default function, when there is invalid state/message combination
28285 + * \param InitState initial state of the state machine
28286 + * \param Base StateMachine base, internal use only
28287 + * \pre p_sm should be a legal pointer
28288 + * \post
28289 +
28290 + IRQL = PASSIVE_LEVEL
28291 +
28292 + */
28293 +VOID StateMachineInit(
28294 + IN STATE_MACHINE *S,
28295 + IN STATE_MACHINE_FUNC Trans[],
28296 + IN ULONG StNr,
28297 + IN ULONG MsgNr,
28298 + IN STATE_MACHINE_FUNC DefFunc,
28299 + IN ULONG InitState,
28300 + IN ULONG Base)
28301 +{
28302 + ULONG i, j;
28303 +
28304 + // set number of states and messages
28305 + S->NrState = StNr;
28306 + S->NrMsg = MsgNr;
28307 + S->Base = Base;
28308 +
28309 + S->TransFunc = Trans;
28310 +
28311 + // init all state transition to default function
28312 + for (i = 0; i < StNr; i++)
28313 + {
28314 + for (j = 0; j < MsgNr; j++)
28315 + {
28316 + S->TransFunc[i * MsgNr + j] = DefFunc;
28317 + }
28318 + }
28319 +
28320 + // set the starting state
28321 + S->CurrState = InitState;
28322 +}
28323 +
28324 +/*! \brief This function fills in the function pointer into the cell in the state machine
28325 + * \param *S pointer to the state machine
28326 + * \param St state
28327 + * \param Msg incoming message
28328 + * \param f the function to be executed when (state, message) combination occurs at the state machine
28329 + * \pre *S should be a legal pointer to the state machine, st, msg, should be all within the range, Base should be set in the initial state
28330 + * \post
28331 +
28332 + IRQL = PASSIVE_LEVEL
28333 +
28334 + */
28335 +VOID StateMachineSetAction(
28336 + IN STATE_MACHINE *S,
28337 + IN ULONG St,
28338 + IN ULONG Msg,
28339 + IN STATE_MACHINE_FUNC Func)
28340 +{
28341 + ULONG MsgIdx;
28342 +
28343 + MsgIdx = Msg - S->Base;
28344 +
28345 + if (St < S->NrState && MsgIdx < S->NrMsg)
28346 + {
28347 + // boundary checking before setting the action
28348 + S->TransFunc[St * S->NrMsg + MsgIdx] = Func;
28349 + }
28350 +}
28351 +
28352 +/*! \brief This function does the state transition
28353 + * \param *Adapter the NIC adapter pointer
28354 + * \param *S the state machine
28355 + * \param *Elem the message to be executed
28356 + * \return None
28357 +
28358 + IRQL = DISPATCH_LEVEL
28359 +
28360 + */
28361 +VOID StateMachinePerformAction(
28362 + IN PRTMP_ADAPTER pAd,
28363 + IN STATE_MACHINE *S,
28364 + IN MLME_QUEUE_ELEM *Elem)
28365 +{
28366 + (*(S->TransFunc[S->CurrState * S->NrMsg + Elem->MsgType - S->Base]))(pAd, Elem);
28367 +}
28368 +
28369 +/*
28370 + ==========================================================================
28371 + Description:
28372 + The drop function, when machine executes this, the message is simply
28373 + ignored. This function does nothing, the message is freed in
28374 + StateMachinePerformAction()
28375 + ==========================================================================
28376 + */
28377 +VOID Drop(
28378 + IN PRTMP_ADAPTER pAd,
28379 + IN MLME_QUEUE_ELEM *Elem)
28380 +{
28381 +}
28382 +
28383 +// ===========================================================================================
28384 +// lfsr.c
28385 +// ===========================================================================================
28386 +
28387 +/*
28388 + ==========================================================================
28389 + Description:
28390 +
28391 + IRQL = PASSIVE_LEVEL
28392 +
28393 + ==========================================================================
28394 + */
28395 +VOID LfsrInit(
28396 + IN PRTMP_ADAPTER pAd,
28397 + IN ULONG Seed)
28398 +{
28399 + if (Seed == 0)
28400 + pAd->Mlme.ShiftReg = 1;
28401 + else
28402 + pAd->Mlme.ShiftReg = Seed;
28403 +}
28404 +
28405 +/*
28406 + ==========================================================================
28407 + Description:
28408 + ==========================================================================
28409 + */
28410 +UCHAR RandomByte(
28411 + IN PRTMP_ADAPTER pAd)
28412 +{
28413 + ULONG i;
28414 + UCHAR R, Result;
28415 +
28416 + R = 0;
28417 +
28418 + if (pAd->Mlme.ShiftReg == 0)
28419 + NdisGetSystemUpTime((ULONG *)&pAd->Mlme.ShiftReg);
28420 +
28421 + for (i = 0; i < 8; i++)
28422 + {
28423 + if (pAd->Mlme.ShiftReg & 0x00000001)
28424 + {
28425 + pAd->Mlme.ShiftReg = ((pAd->Mlme.ShiftReg ^ LFSR_MASK) >> 1) | 0x80000000;
28426 + Result = 1;
28427 + }
28428 + else
28429 + {
28430 + pAd->Mlme.ShiftReg = pAd->Mlme.ShiftReg >> 1;
28431 + Result = 0;
28432 + }
28433 + R = (R << 1) | Result;
28434 + }
28435 +
28436 + return R;
28437 +}
28438 +
28439 +VOID AsicUpdateAutoFallBackTable(
28440 + IN PRTMP_ADAPTER pAd,
28441 + IN PUCHAR pRateTable)
28442 +{
28443 + UCHAR i;
28444 + HT_FBK_CFG0_STRUC HtCfg0;
28445 + HT_FBK_CFG1_STRUC HtCfg1;
28446 + LG_FBK_CFG0_STRUC LgCfg0;
28447 + LG_FBK_CFG1_STRUC LgCfg1;
28448 + PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate;
28449 +
28450 + // set to initial value
28451 + HtCfg0.word = 0x65432100;
28452 + HtCfg1.word = 0xedcba988;
28453 + LgCfg0.word = 0xedcba988;
28454 + LgCfg1.word = 0x00002100;
28455 +
28456 + pNextTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1;
28457 + for (i = 1; i < *((PUCHAR) pRateTable); i++)
28458 + {
28459 + pCurrTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1+i;
28460 + switch (pCurrTxRate->Mode)
28461 + {
28462 + case 0: //CCK
28463 + break;
28464 + case 1: //OFDM
28465 + {
28466 + switch(pCurrTxRate->CurrMCS)
28467 + {
28468 + case 0:
28469 + LgCfg0.field.OFDMMCS0FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28470 + break;
28471 + case 1:
28472 + LgCfg0.field.OFDMMCS1FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28473 + break;
28474 + case 2:
28475 + LgCfg0.field.OFDMMCS2FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28476 + break;
28477 + case 3:
28478 + LgCfg0.field.OFDMMCS3FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28479 + break;
28480 + case 4:
28481 + LgCfg0.field.OFDMMCS4FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28482 + break;
28483 + case 5:
28484 + LgCfg0.field.OFDMMCS5FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28485 + break;
28486 + case 6:
28487 + LgCfg0.field.OFDMMCS6FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28488 + break;
28489 + case 7:
28490 + LgCfg0.field.OFDMMCS7FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS;
28491 + break;
28492 + }
28493 + }
28494 + break;
28495 +#ifdef DOT11_N_SUPPORT
28496 + case 2: //HT-MIX
28497 + case 3: //HT-GF
28498 + {
28499 + if ((pNextTxRate->Mode >= MODE_HTMIX) && (pCurrTxRate->CurrMCS != pNextTxRate->CurrMCS))
28500 + {
28501 + switch(pCurrTxRate->CurrMCS)
28502 + {
28503 + case 0:
28504 + HtCfg0.field.HTMCS0FBK = pNextTxRate->CurrMCS;
28505 + break;
28506 + case 1:
28507 + HtCfg0.field.HTMCS1FBK = pNextTxRate->CurrMCS;
28508 + break;
28509 + case 2:
28510 + HtCfg0.field.HTMCS2FBK = pNextTxRate->CurrMCS;
28511 + break;
28512 + case 3:
28513 + HtCfg0.field.HTMCS3FBK = pNextTxRate->CurrMCS;
28514 + break;
28515 + case 4:
28516 + HtCfg0.field.HTMCS4FBK = pNextTxRate->CurrMCS;
28517 + break;
28518 + case 5:
28519 + HtCfg0.field.HTMCS5FBK = pNextTxRate->CurrMCS;
28520 + break;
28521 + case 6:
28522 + HtCfg0.field.HTMCS6FBK = pNextTxRate->CurrMCS;
28523 + break;
28524 + case 7:
28525 + HtCfg0.field.HTMCS7FBK = pNextTxRate->CurrMCS;
28526 + break;
28527 + case 8:
28528 + HtCfg1.field.HTMCS8FBK = pNextTxRate->CurrMCS;
28529 + break;
28530 + case 9:
28531 + HtCfg1.field.HTMCS9FBK = pNextTxRate->CurrMCS;
28532 + break;
28533 + case 10:
28534 + HtCfg1.field.HTMCS10FBK = pNextTxRate->CurrMCS;
28535 + break;
28536 + case 11:
28537 + HtCfg1.field.HTMCS11FBK = pNextTxRate->CurrMCS;
28538 + break;
28539 + case 12:
28540 + HtCfg1.field.HTMCS12FBK = pNextTxRate->CurrMCS;
28541 + break;
28542 + case 13:
28543 + HtCfg1.field.HTMCS13FBK = pNextTxRate->CurrMCS;
28544 + break;
28545 + case 14:
28546 + HtCfg1.field.HTMCS14FBK = pNextTxRate->CurrMCS;
28547 + break;
28548 + case 15:
28549 + HtCfg1.field.HTMCS15FBK = pNextTxRate->CurrMCS;
28550 + break;
28551 + default:
28552 + DBGPRINT(RT_DEBUG_ERROR, ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n", pCurrTxRate->CurrMCS));
28553 + }
28554 + }
28555 + }
28556 + break;
28557 +#endif // DOT11_N_SUPPORT //
28558 + }
28559 +
28560 + pNextTxRate = pCurrTxRate;
28561 + }
28562 +
28563 + RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word);
28564 + RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word);
28565 + RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word);
28566 + RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word);
28567 +}
28568 +
28569 +/*
28570 + ========================================================================
28571 +
28572 + Routine Description:
28573 + Set MAC register value according operation mode.
28574 + OperationMode AND bNonGFExist are for MM and GF Proteciton.
28575 + If MM or GF mask is not set, those passing argument doesn't not take effect.
28576 +
28577 + Operation mode meaning:
28578 + = 0 : Pure HT, no preotection.
28579 + = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS.
28580 + = 0x10: No Transmission in 40M is protected.
28581 + = 0x11: Transmission in both 40M and 20M shall be protected
28582 + if (bNonGFExist)
28583 + we should choose not to use GF. But still set correct ASIC registers.
28584 + ========================================================================
28585 +*/
28586 +VOID AsicUpdateProtect(
28587 + IN PRTMP_ADAPTER pAd,
28588 + IN USHORT OperationMode,
28589 + IN UCHAR SetMask,
28590 + IN BOOLEAN bDisableBGProtect,
28591 + IN BOOLEAN bNonGFExist)
28592 +{
28593 + PROT_CFG_STRUC ProtCfg, ProtCfg4;
28594 + UINT32 Protect[6];
28595 + USHORT offset;
28596 + UCHAR i;
28597 + UINT32 MacReg = 0;
28598 +
28599 +#ifdef RALINK_ATE
28600 + if (ATE_ON(pAd))
28601 + return;
28602 +#endif // RALINK_ATE //
28603 +
28604 +#ifdef DOT11_N_SUPPORT
28605 + if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8))
28606 + {
28607 + return;
28608 + }
28609 +
28610 + if (pAd->BATable.numAsOriginator)
28611 + {
28612 + //
28613 + // enable the RTS/CTS to avoid channel collision
28614 + //
28615 + SetMask = ALLN_SETPROTECT;
28616 + OperationMode = 8;
28617 + }
28618 +#endif // DOT11_N_SUPPORT //
28619 +
28620 + // Config ASIC RTS threshold register
28621 + RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
28622 + MacReg &= 0xFF0000FF;
28623 +
28624 + // If the user want disable RtsThreshold and enbale Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096
28625 + if ((
28626 +#ifdef DOT11_N_SUPPORT
28627 + (pAd->CommonCfg.BACapability.field.AmsduEnable) ||
28628 +#endif // DOT11_N_SUPPORT //
28629 + (pAd->CommonCfg.bAggregationCapable == TRUE))
28630 + && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD)
28631 + {
28632 + MacReg |= (0x1000 << 8);
28633 + }
28634 + else
28635 + {
28636 + MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
28637 + }
28638 +
28639 + RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
28640 +
28641 + // Initial common protection settings
28642 + RTMPZeroMemory(Protect, sizeof(Protect));
28643 + ProtCfg4.word = 0;
28644 + ProtCfg.word = 0;
28645 + ProtCfg.field.TxopAllowGF40 = 1;
28646 + ProtCfg.field.TxopAllowGF20 = 1;
28647 + ProtCfg.field.TxopAllowMM40 = 1;
28648 + ProtCfg.field.TxopAllowMM20 = 1;
28649 + ProtCfg.field.TxopAllowOfdm = 1;
28650 + ProtCfg.field.TxopAllowCck = 1;
28651 + ProtCfg.field.RTSThEn = 1;
28652 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28653 +
28654 + // update PHY mode and rate
28655 + if (pAd->CommonCfg.Channel > 14)
28656 + ProtCfg.field.ProtectRate = 0x4000;
28657 + ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate;
28658 +
28659 + // Handle legacy(B/G) protection
28660 + if (bDisableBGProtect)
28661 + {
28662 + //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
28663 + ProtCfg.field.ProtectCtrl = 0;
28664 + Protect[0] = ProtCfg.word;
28665 + Protect[1] = ProtCfg.word;
28666 + }
28667 + else
28668 + {
28669 + //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
28670 + ProtCfg.field.ProtectCtrl = 0; // CCK do not need to be protected
28671 + Protect[0] = ProtCfg.word;
28672 + ProtCfg.field.ProtectCtrl = ASIC_CTS; // OFDM needs using CCK to protect
28673 + Protect[1] = ProtCfg.word;
28674 + }
28675 +
28676 +#ifdef DOT11_N_SUPPORT
28677 + // Decide HT frame protection.
28678 + if ((SetMask & ALLN_SETPROTECT) != 0)
28679 + {
28680 + switch(OperationMode)
28681 + {
28682 + case 0x0:
28683 + // NO PROTECT
28684 + // 1.All STAs in the BSS are 20/40 MHz HT
28685 + // 2. in ai 20/40MHz BSS
28686 + // 3. all STAs are 20MHz in a 20MHz BSS
28687 + // Pure HT. no protection.
28688 +
28689 + // MM20_PROT_CFG
28690 + // Reserved (31:27)
28691 + // PROT_TXOP(25:20) -- 010111
28692 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28693 + // PROT_CTRL(17:16) -- 00 (None)
28694 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
28695 + Protect[2] = 0x01744004;
28696 +
28697 + // MM40_PROT_CFG
28698 + // Reserved (31:27)
28699 + // PROT_TXOP(25:20) -- 111111
28700 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28701 + // PROT_CTRL(17:16) -- 00 (None)
28702 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
28703 + Protect[3] = 0x03f44084;
28704 +
28705 + // CF20_PROT_CFG
28706 + // Reserved (31:27)
28707 + // PROT_TXOP(25:20) -- 010111
28708 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28709 + // PROT_CTRL(17:16) -- 00 (None)
28710 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
28711 + Protect[4] = 0x01744004;
28712 +
28713 + // CF40_PROT_CFG
28714 + // Reserved (31:27)
28715 + // PROT_TXOP(25:20) -- 111111
28716 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
28717 + // PROT_CTRL(17:16) -- 00 (None)
28718 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
28719 + Protect[5] = 0x03f44084;
28720 +
28721 + if (bNonGFExist)
28722 + {
28723 + // PROT_NAV(19:18) -- 01 (Short NAV protectiion)
28724 + // PROT_CTRL(17:16) -- 01 (RTS/CTS)
28725 + Protect[4] = 0x01754004;
28726 + Protect[5] = 0x03f54084;
28727 + }
28728 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
28729 + break;
28730 +
28731 + case 1:
28732 + // This is "HT non-member protection mode."
28733 + // If there may be non-HT STAs my BSS
28734 + ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None)
28735 + ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1.
28736 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
28737 + {
28738 + ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18..
28739 + ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083;
28740 + }
28741 + //Assign Protection method for 20&40 MHz packets
28742 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28743 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28744 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28745 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28746 + Protect[2] = ProtCfg.word;
28747 + Protect[3] = ProtCfg4.word;
28748 + Protect[4] = ProtCfg.word;
28749 + Protect[5] = ProtCfg4.word;
28750 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28751 + break;
28752 +
28753 + case 2:
28754 + // If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets
28755 + ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None)
28756 + ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1.
28757 +
28758 + //Assign Protection method for 40MHz packets
28759 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28760 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28761 + Protect[2] = ProtCfg.word;
28762 + Protect[3] = ProtCfg4.word;
28763 + if (bNonGFExist)
28764 + {
28765 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28766 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28767 + }
28768 + Protect[4] = ProtCfg.word;
28769 + Protect[5] = ProtCfg4.word;
28770 +
28771 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
28772 + break;
28773 +
28774 + case 3:
28775 + // HT mixed mode. PROTECT ALL!
28776 + // Assign Rate
28777 + ProtCfg.word = 0x01744004; //duplicaet legacy 24M. BW set 1.
28778 + ProtCfg4.word = 0x03f44084;
28779 + // both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the
28780 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
28781 + {
28782 + ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18..
28783 + ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083
28784 + }
28785 + //Assign Protection method for 20&40 MHz packets
28786 + ProtCfg.field.ProtectCtrl = ASIC_RTS;
28787 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
28788 + ProtCfg4.field.ProtectCtrl = ASIC_RTS;
28789 + ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
28790 + Protect[2] = ProtCfg.word;
28791 + Protect[3] = ProtCfg4.word;
28792 + Protect[4] = ProtCfg.word;
28793 + Protect[5] = ProtCfg4.word;
28794 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28795 + break;
28796 +
28797 + case 8:
28798 + Protect[2] = 0x01754004;
28799 + Protect[3] = 0x03f54084;
28800 + Protect[4] = 0x01754004;
28801 + Protect[5] = 0x03f54084;
28802 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
28803 + break;
28804 + }
28805 + }
28806 +#endif // DOT11_N_SUPPORT //
28807 +
28808 + offset = CCK_PROT_CFG;
28809 + for (i = 0;i < 6;i++)
28810 + {
28811 + if ((SetMask & (1<< i)))
28812 + {
28813 + RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
28814 + }
28815 + }
28816 +}
28817 +
28818 +
28819 +#ifdef RT30xx
28820 +/*
28821 + ========================================================================
28822 +
28823 + Routine Description: Write RT30xx RF register through MAC
28824 +
28825 + Arguments:
28826 +
28827 + Return Value:
28828 +
28829 + IRQL =
28830 +
28831 + Note:
28832 +
28833 + ========================================================================
28834 +*/
28835 +NTSTATUS RT30xxWriteRFRegister(
28836 + IN PRTMP_ADAPTER pAd,
28837 + IN UCHAR RegID,
28838 + IN UCHAR Value)
28839 +{
28840 + RF_CSR_CFG_STRUC rfcsr;
28841 + UINT i = 0;
28842 +
28843 + do
28844 + {
28845 + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
28846 +
28847 + if (!rfcsr.field.RF_CSR_KICK)
28848 + break;
28849 + i++;
28850 + }
28851 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
28852 +
28853 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
28854 + {
28855 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
28856 + return STATUS_UNSUCCESSFUL;
28857 + }
28858 +
28859 + rfcsr.field.RF_CSR_WR = 1;
28860 + rfcsr.field.RF_CSR_KICK = 1;
28861 + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID;
28862 + rfcsr.field.RF_CSR_DATA = Value;
28863 +
28864 + RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
28865 +
28866 + return STATUS_SUCCESS;
28867 +}
28868 +
28869 +
28870 +/*
28871 + ========================================================================
28872 +
28873 + Routine Description: Read RT30xx RF register through MAC
28874 +
28875 + Arguments:
28876 +
28877 + Return Value:
28878 +
28879 + IRQL =
28880 +
28881 + Note:
28882 +
28883 + ========================================================================
28884 +*/
28885 +NTSTATUS RT30xxReadRFRegister(
28886 + IN PRTMP_ADAPTER pAd,
28887 + IN UCHAR RegID,
28888 + IN PUCHAR pValue)
28889 +{
28890 + RF_CSR_CFG_STRUC rfcsr;
28891 + UINT i=0, k=0;
28892 +
28893 + for (i=0; i<MAX_BUSY_COUNT; i++)
28894 + {
28895 + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
28896 +
28897 + if (rfcsr.field.RF_CSR_KICK == BUSY)
28898 + {
28899 + continue;
28900 + }
28901 + rfcsr.word = 0;
28902 + rfcsr.field.RF_CSR_WR = 0;
28903 + rfcsr.field.RF_CSR_KICK = 1;
28904 + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID;
28905 + RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
28906 + for (k=0; k<MAX_BUSY_COUNT; k++)
28907 + {
28908 + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
28909 +
28910 + if (rfcsr.field.RF_CSR_KICK == IDLE)
28911 + break;
28912 + }
28913 + if ((rfcsr.field.RF_CSR_KICK == IDLE) &&
28914 + (rfcsr.field.TESTCSR_RFACC_REGNUM == RegID))
28915 + {
28916 + *pValue = (UCHAR)rfcsr.field.RF_CSR_DATA;
28917 + break;
28918 + }
28919 + }
28920 + if (rfcsr.field.RF_CSR_KICK == BUSY)
28921 + {
28922 + DBGPRINT_ERR(("RF read R%d=0x%x fail, i[%d], k[%d]\n", RegID, rfcsr.word,i,k));
28923 + return STATUS_UNSUCCESSFUL;
28924 + }
28925 +
28926 + return STATUS_SUCCESS;
28927 +}
28928 +#endif // RT30xx //
28929 +
28930 +#ifdef RT30xx
28931 +// add by johnli, RF power sequence setup
28932 +/*
28933 + ==========================================================================
28934 + Description:
28935 +
28936 + Load RF normal operation-mode setup
28937 +
28938 + ==========================================================================
28939 + */
28940 +VOID RT30xxLoadRFNormalModeSetup(
28941 + IN PRTMP_ADAPTER pAd)
28942 +{
28943 + UCHAR RFValue;
28944 +
28945 + // RX0_PD & TX0_PD, RF R1 register Bit 2 & Bit 3 to 0 and RF_BLOCK_en,RX1_PD & TX1_PD, Bit0, Bit 4 & Bit5 to 1
28946 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
28947 + RFValue = (RFValue & (~0x0C)) | 0x31;
28948 + RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
28949 +
28950 + // TX_LO2_en, RF R15 register Bit 3 to 0
28951 + RT30xxReadRFRegister(pAd, RF_R15, &RFValue);
28952 + RFValue &= (~0x08);
28953 + RT30xxWriteRFRegister(pAd, RF_R15, RFValue);
28954 +
28955 + // TX_LO1_en, RF R17 register Bit 3 to 0
28956 + RT30xxReadRFRegister(pAd, RF_R17, &RFValue);
28957 + RFValue &= (~0x08);
28958 + // to fix rx long range issue
28959 + if (((pAd->MACVersion & 0xffff) >= 0x0211) && (pAd->NicConfig2.field.ExternalLNAForG == 0))
28960 + {
28961 + RFValue |= 0x20;
28962 + }
28963 + RT30xxWriteRFRegister(pAd, RF_R17, RFValue);
28964 +
28965 + // RX_LO1_en, RF R20 register Bit 3 to 0
28966 + RT30xxReadRFRegister(pAd, RF_R20, &RFValue);
28967 + RFValue &= (~0x08);
28968 + RT30xxWriteRFRegister(pAd, RF_R20, RFValue);
28969 +
28970 + // RX_LO2_en, RF R21 register Bit 3 to 0
28971 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
28972 + RFValue &= (~0x08);
28973 + RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
28974 +
28975 + // LDORF_VC, RF R27 register Bit 2 to 0
28976 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
28977 + if ((pAd->MACVersion & 0xffff) < 0x0211)
28978 + RFValue = (RFValue & (~0x77)) | 0x3;
28979 + else
28980 + RFValue = (RFValue & (~0x77));
28981 + RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
28982 + /* end johnli */
28983 +}
28984 +
28985 +/*
28986 + ==========================================================================
28987 + Description:
28988 +
28989 + Load RF sleep-mode setup
28990 +
28991 + ==========================================================================
28992 + */
28993 +VOID RT30xxLoadRFSleepModeSetup(
28994 + IN PRTMP_ADAPTER pAd)
28995 +{
28996 + UCHAR RFValue;
28997 + UINT32 MACValue;
28998 +
28999 + // RF_BLOCK_en. RF R1 register Bit 0 to 0
29000 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
29001 + RFValue &= (~0x01);
29002 + RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
29003 +
29004 + // VCO_IC, RF R7 register Bit 4 & Bit 5 to 0
29005 + RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
29006 + RFValue &= (~0x30);
29007 + RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
29008 +
29009 + // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 0
29010 + RT30xxReadRFRegister(pAd, RF_R09, &RFValue);
29011 + RFValue &= (~0x0E);
29012 + RT30xxWriteRFRegister(pAd, RF_R09, RFValue);
29013 +
29014 + // RX_CTB_en, RF R21 register Bit 7 to 0
29015 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
29016 + RFValue &= (~0x80);
29017 + RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
29018 +
29019 + // LDORF_VC, RF R27 register Bit 0, Bit 1 & Bit 2 to 1
29020 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
29021 + RFValue |= 0x77;
29022 + RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
29023 +
29024 + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
29025 + MACValue |= 0x1D000000;
29026 + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
29027 +}
29028 +
29029 +/*
29030 + ==========================================================================
29031 + Description:
29032 +
29033 + Reverse RF sleep-mode setup
29034 +
29035 + ==========================================================================
29036 + */
29037 +VOID RT30xxReverseRFSleepModeSetup(
29038 + IN PRTMP_ADAPTER pAd)
29039 +{
29040 + UCHAR RFValue;
29041 + UINT32 MACValue;
29042 +
29043 + // RF_BLOCK_en, RF R1 register Bit 0 to 1
29044 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
29045 + RFValue |= 0x01;
29046 + RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
29047 +
29048 + // VCO_IC, RF R7 register Bit 4 & Bit 5 to 1
29049 + RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
29050 + RFValue |= 0x30;
29051 + RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
29052 +
29053 + // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1
29054 + RT30xxReadRFRegister(pAd, RF_R09, &RFValue);
29055 + RFValue |= 0x0E;
29056 + RT30xxWriteRFRegister(pAd, RF_R09, RFValue);
29057 +
29058 + // RX_CTB_en, RF R21 register Bit 7 to 1
29059 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
29060 + RFValue |= 0x80;
29061 + RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
29062 +
29063 + // LDORF_VC, RF R27 register Bit 2 to 0
29064 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
29065 + if ((pAd->MACVersion & 0xffff) < 0x0211)
29066 + RFValue = (RFValue & (~0x77)) | 0x3;
29067 + else
29068 + RFValue = (RFValue & (~0x77));
29069 + RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
29070 +
29071 + // RT3071 version E has fixed this issue
29072 + if ((pAd->NicConfig2.field.DACTestBit == 1) && ((pAd->MACVersion & 0xffff) < 0x0211))
29073 + {
29074 + // patch tx EVM issue temporarily
29075 + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
29076 + MACValue = ((MACValue & 0xE0FFFFFF) | 0x0D000000);
29077 + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
29078 + }
29079 + else
29080 + {
29081 + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
29082 + MACValue = ((MACValue & 0xE0FFFFFF) | 0x01000000);
29083 + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
29084 + }
29085 +}
29086 +// end johnli
29087 +#endif // RT30xx //
29088 +
29089 +/*
29090 + ==========================================================================
29091 + Description:
29092 +
29093 + IRQL = PASSIVE_LEVEL
29094 + IRQL = DISPATCH_LEVEL
29095 +
29096 + ==========================================================================
29097 + */
29098 +VOID AsicSwitchChannel(
29099 + IN PRTMP_ADAPTER pAd,
29100 + IN UCHAR Channel,
29101 + IN BOOLEAN bScan)
29102 +{
29103 + ULONG R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0;
29104 + CHAR TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; //Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER;
29105 + UCHAR index;
29106 + UINT32 Value = 0; //BbpReg, Value;
29107 + RTMP_RF_REGS *RFRegTable;
29108 +
29109 + // Search Tx power value
29110 +#if 1
29111 + // We can't use ChannelList to search channel, since some central channl's txpowr doesn't list
29112 + // in ChannelList, so use TxPower array instead.
29113 + //
29114 + for (index = 0; index < MAX_NUM_OF_CHANNELS; index++)
29115 + {
29116 + if (Channel == pAd->TxPower[index].Channel)
29117 + {
29118 + TxPwer = pAd->TxPower[index].Power;
29119 + TxPwer2 = pAd->TxPower[index].Power2;
29120 + break;
29121 + }
29122 + }
29123 +#else
29124 + for (index = 0; index < pAd->ChannelListNum; index++)
29125 + {
29126 + if (Channel == pAd->ChannelList[index].Channel)
29127 + {
29128 + TxPwer = pAd->ChannelList[index].Power;
29129 + TxPwer2 = pAd->ChannelList[index].Power2;
29130 + break;
29131 + }
29132 + }
29133 +#endif
29134 +
29135 + if (index == MAX_NUM_OF_CHANNELS)
29136 + {
29137 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Can't find the Channel#%d \n", Channel));
29138 + }
29139 +
29140 +#ifdef RT30xx
29141 + // The RF programming sequence is difference between 3xxx and 2xxx
29142 + if ((IS_RT3070(pAd) || IS_RT3090(pAd)) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020) ||
29143 + (pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022)))
29144 + {
29145 + /* modify by WY for Read RF Reg. error */
29146 + UCHAR RFValue;
29147 +
29148 + for (index = 0; index < NUM_OF_3020_CHNL; index++)
29149 + {
29150 + if (Channel == FreqItems3020[index].Channel)
29151 + {
29152 + // Programming channel parameters
29153 + RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N);
29154 + RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K);
29155 + RT30xxReadRFRegister(pAd, RF_R06, &RFValue);
29156 + RFValue = (RFValue & 0xFC) | FreqItems3020[index].R;
29157 + RT30xxWriteRFRegister(pAd, RF_R06, RFValue);
29158 +
29159 + // Set Tx0 Power
29160 + RT30xxReadRFRegister(pAd, RF_R12, &RFValue);
29161 + RFValue = (RFValue & 0xE0) | TxPwer;
29162 + RT30xxWriteRFRegister(pAd, RF_R12, RFValue);
29163 +
29164 + // Set Tx1 Power
29165 + RT30xxReadRFRegister(pAd, RF_R13, &RFValue);
29166 + RFValue = (RFValue & 0xE0) | TxPwer2;
29167 + RT30xxWriteRFRegister(pAd, RF_R13, RFValue);
29168 +
29169 + // Tx/Rx Stream setting
29170 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
29171 + //if (IS_RT3090(pAd))
29172 + // RFValue |= 0x01; // Enable RF block.
29173 + RFValue &= 0x03; //clear bit[7~2]
29174 + if (pAd->Antenna.field.TxPath == 1)
29175 + RFValue |= 0xA0;
29176 + else if (pAd->Antenna.field.TxPath == 2)
29177 + RFValue |= 0x80;
29178 + if (pAd->Antenna.field.RxPath == 1)
29179 + RFValue |= 0x50;
29180 + else if (pAd->Antenna.field.RxPath == 2)
29181 + RFValue |= 0x40;
29182 + RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
29183 +
29184 + // Set RF offset
29185 + RT30xxReadRFRegister(pAd, RF_R23, &RFValue);
29186 + RFValue = (RFValue & 0x80) | pAd->RfFreqOffset;
29187 + RT30xxWriteRFRegister(pAd, RF_R23, RFValue);
29188 +
29189 + // Set BW
29190 + if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40))
29191 + {
29192 + RFValue = pAd->Mlme.CaliBW40RfR24;
29193 + //DISABLE_11N_CHECK(pAd);
29194 + }
29195 + else
29196 + {
29197 + RFValue = pAd->Mlme.CaliBW20RfR24;
29198 + }
29199 + RT30xxWriteRFRegister(pAd, RF_R24, RFValue);
29200 + RT30xxWriteRFRegister(pAd, RF_R31, RFValue);
29201 +
29202 + // Enable RF tuning
29203 + RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
29204 + RFValue = RFValue | 0x1;
29205 + RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
29206 +
29207 + // latch channel for future usage.
29208 + pAd->LatchRfRegs.Channel = Channel;
29209 +
29210 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
29211 + Channel,
29212 + pAd->RfIcType,
29213 + TxPwer,
29214 + TxPwer2,
29215 + pAd->Antenna.field.TxPath,
29216 + FreqItems3020[index].N,
29217 + FreqItems3020[index].K,
29218 + FreqItems3020[index].R));
29219 +
29220 + break;
29221 + }
29222 + }
29223 + }
29224 + else
29225 +#endif // RT30xx //
29226 +
29227 + {
29228 + RFRegTable = RF2850RegTable;
29229 +
29230 + switch (pAd->RfIcType)
29231 + {
29232 + case RFIC_2820:
29233 + case RFIC_2850:
29234 + case RFIC_2720:
29235 + case RFIC_2750:
29236 +
29237 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
29238 + {
29239 + if (Channel == RFRegTable[index].Channel)
29240 + {
29241 + R2 = RFRegTable[index].R2;
29242 + if (pAd->Antenna.field.TxPath == 1)
29243 + {
29244 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
29245 + }
29246 +
29247 + if (pAd->Antenna.field.RxPath == 2)
29248 + {
29249 + R2 |= 0x40; // write 1 to off Rxpath.
29250 + }
29251 + else if (pAd->Antenna.field.RxPath == 1)
29252 + {
29253 + R2 |= 0x20040; // write 1 to off RxPath
29254 + }
29255 +
29256 + if (Channel > 14)
29257 + {
29258 + // initialize R3, R4
29259 + R3 = (RFRegTable[index].R3 & 0xffffc1ff);
29260 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15);
29261 +
29262 + // 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
29263 + // R3
29264 + if ((TxPwer >= -7) && (TxPwer < 0))
29265 + {
29266 + TxPwer = (7+TxPwer);
29267 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
29268 + R3 |= (TxPwer << 10);
29269 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer=%d \n", TxPwer));
29270 + }
29271 + else
29272 + {
29273 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
29274 + R3 |= (TxPwer << 10) | (1 << 9);
29275 + }
29276 +
29277 + // R4
29278 + if ((TxPwer2 >= -7) && (TxPwer2 < 0))
29279 + {
29280 + TxPwer2 = (7+TxPwer2);
29281 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
29282 + R4 |= (TxPwer2 << 7);
29283 + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
29284 + }
29285 + else
29286 + {
29287 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
29288 + R4 |= (TxPwer2 << 7) | (1 << 6);
29289 + }
29290 + }
29291 + else
29292 + {
29293 + R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
29294 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 <<6);// Set freq Offset & TxPwr1
29295 + }
29296 +
29297 + // Based on BBP current mode before changing RF channel.
29298 + if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40))
29299 + {
29300 + R4 |=0x200000;
29301 + }
29302 +
29303 + // Update variables
29304 + pAd->LatchRfRegs.Channel = Channel;
29305 + pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
29306 + pAd->LatchRfRegs.R2 = R2;
29307 + pAd->LatchRfRegs.R3 = R3;
29308 + pAd->LatchRfRegs.R4 = R4;
29309 +
29310 + // Set RF value 1's set R3[bit2] = [0]
29311 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
29312 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
29313 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
29314 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
29315 +
29316 + RTMPusecDelay(200);
29317 +
29318 + // Set RF value 2's set R3[bit2] = [1]
29319 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
29320 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
29321 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
29322 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
29323 +
29324 + RTMPusecDelay(200);
29325 +
29326 + // Set RF value 3's set R3[bit2] = [0]
29327 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
29328 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
29329 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
29330 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
29331 +
29332 + break;
29333 + }
29334 + }
29335 + break;
29336 +
29337 + default:
29338 + break;
29339 + }
29340 + }
29341 +
29342 + // Change BBP setting during siwtch from a->g, g->a
29343 + if (Channel <= 14)
29344 + {
29345 + ULONG TxPinCfg = 0x00050F0A;//Gary 2007/08/09 0x050A0A
29346 +
29347 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
29348 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
29349 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
29350 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0);//(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue.
29351 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
29352 +
29353 + // Rx High power VGA offset for LNA select
29354 + if (pAd->NicConfig2.field.ExternalLNAForG)
29355 + {
29356 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
29357 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
29358 + }
29359 + else
29360 + {
29361 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
29362 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
29363 + }
29364 +
29365 + // 5G band selection PIN, bit1 and bit2 are complement
29366 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
29367 + Value &= (~0x6);
29368 + Value |= (0x04);
29369 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
29370 +
29371 + // Turn off unused PA or LNA when only 1T or 1R
29372 + if (pAd->Antenna.field.TxPath == 1)
29373 + {
29374 + TxPinCfg &= 0xFFFFFFF3;
29375 + }
29376 + if (pAd->Antenna.field.RxPath == 1)
29377 + {
29378 + TxPinCfg &= 0xFFFFF3FF;
29379 + }
29380 +
29381 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
29382 + }
29383 + else
29384 + {
29385 + ULONG TxPinCfg = 0x00050F05;//Gary 2007/8/9 0x050505
29386 +
29387 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
29388 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
29389 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
29390 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0);//(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue.
29391 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
29392 +
29393 + // Rx High power VGA offset for LNA select
29394 + if (pAd->NicConfig2.field.ExternalLNAForA)
29395 + {
29396 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
29397 + }
29398 + else
29399 + {
29400 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
29401 + }
29402 +
29403 + // 5G band selection PIN, bit1 and bit2 are complement
29404 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
29405 + Value &= (~0x6);
29406 + Value |= (0x02);
29407 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
29408 +
29409 + // Turn off unused PA or LNA when only 1T or 1R
29410 + if (pAd->Antenna.field.TxPath == 1)
29411 + {
29412 + TxPinCfg &= 0xFFFFFFF3;
29413 + }
29414 + if (pAd->Antenna.field.RxPath == 1)
29415 + {
29416 + TxPinCfg &= 0xFFFFF3FF;
29417 + }
29418 +
29419 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
29420 + }
29421 +
29422 + // R66 should be set according to Channel and use 20MHz when scanning
29423 + //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd)));
29424 + if (bScan)
29425 + RTMPSetAGCInitValue(pAd, BW_20);
29426 + else
29427 + RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
29428 +
29429 + //
29430 + // On 11A, We should delay and wait RF/BBP to be stable
29431 + // and the appropriate time should be 1000 micro seconds
29432 + // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
29433 + //
29434 + RTMPusecDelay(1000);
29435 +
29436 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%lu, Pwr1=%lu, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
29437 + Channel,
29438 + pAd->RfIcType,
29439 + (R3 & 0x00003e00) >> 9,
29440 + (R4 & 0x000007c0) >> 6,
29441 + pAd->Antenna.field.TxPath,
29442 + pAd->LatchRfRegs.R1,
29443 + pAd->LatchRfRegs.R2,
29444 + pAd->LatchRfRegs.R3,
29445 + pAd->LatchRfRegs.R4));
29446 +}
29447 +
29448 +/*
29449 + ==========================================================================
29450 + Description:
29451 + This function is required for 2421 only, and should not be used during
29452 + site survey. It's only required after NIC decided to stay at a channel
29453 + for a longer period.
29454 + When this function is called, it's always after AsicSwitchChannel().
29455 +
29456 + IRQL = PASSIVE_LEVEL
29457 + IRQL = DISPATCH_LEVEL
29458 +
29459 + ==========================================================================
29460 + */
29461 +VOID AsicLockChannel(
29462 + IN PRTMP_ADAPTER pAd,
29463 + IN UCHAR Channel)
29464 +{
29465 +}
29466 +
29467 +/*
29468 + ==========================================================================
29469 + Description:
29470 +
29471 + IRQL = PASSIVE_LEVEL
29472 + IRQL = DISPATCH_LEVEL
29473 +
29474 + ==========================================================================
29475 + */
29476 +VOID AsicAntennaSelect(
29477 + IN PRTMP_ADAPTER pAd,
29478 + IN UCHAR Channel)
29479 +{
29480 + if (pAd->Mlme.OneSecPeriodicRound % 2 == 1)
29481 + {
29482 + // patch for AsicSetRxAnt failed
29483 + pAd->RxAnt.EvaluatePeriod = 0;
29484 +
29485 + // check every 2 second. If rcv-beacon less than 5 in the past 2 second, then AvgRSSI is no longer a
29486 + // valid indication of the distance between this AP and its clients.
29487 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
29488 + {
29489 + SHORT realavgrssi1;
29490 +
29491 + // if no traffic then reset average rssi to trigger evaluation
29492 +#ifdef CONFIG_STA_SUPPORT
29493 + if (pAd->StaCfg.NumOfAvgRssiSample < 5)
29494 + {
29495 + pAd->RxAnt.Pair1LastAvgRssi = (-99);
29496 + pAd->RxAnt.Pair2LastAvgRssi = (-99);
29497 + DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no traffic/beacon, reset RSSI\n"));
29498 + }
29499 +
29500 + pAd->StaCfg.NumOfAvgRssiSample = 0;
29501 +#endif // CONFIG_STA_SUPPORT //
29502 + realavgrssi1 = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt] >> 3);
29503 +
29504 + DBGPRINT(RT_DEBUG_TRACE,("Ant-realrssi0(%d), Lastrssi0(%d), EvaluateStableCnt=%d\n", realavgrssi1, pAd->RxAnt.Pair1LastAvgRssi, pAd->RxAnt.EvaluateStableCnt));
29505 +
29506 + // if the difference between two rssi is larger or less than 5, then evaluate the other antenna
29507 + if ((pAd->RxAnt.EvaluateStableCnt < 2) || (realavgrssi1 > (pAd->RxAnt.Pair1LastAvgRssi + 5)) || (realavgrssi1 < (pAd->RxAnt.Pair1LastAvgRssi - 5)))
29508 + {
29509 + pAd->RxAnt.Pair1LastAvgRssi = realavgrssi1;
29510 + AsicEvaluateRxAnt(pAd);
29511 + }
29512 + }
29513 + else
29514 + {
29515 + // if not connected, always switch antenna to try to connect
29516 + UCHAR temp;
29517 +
29518 + temp = pAd->RxAnt.Pair1PrimaryRxAnt;
29519 + pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt;
29520 + pAd->RxAnt.Pair1SecondaryRxAnt = temp;
29521 +
29522 + DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no connect, switch to another one to try connection\n"));
29523 +
29524 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
29525 + }
29526 + }
29527 +}
29528 +
29529 +/*
29530 + ========================================================================
29531 +
29532 + Routine Description:
29533 + Antenna miscellaneous setting.
29534 +
29535 + Arguments:
29536 + pAd Pointer to our adapter
29537 + BandState Indicate current Band State.
29538 +
29539 + Return Value:
29540 + None
29541 +
29542 + IRQL <= DISPATCH_LEVEL
29543 +
29544 + Note:
29545 + 1.) Frame End type control
29546 + only valid for G only (RF_2527 & RF_2529)
29547 + 0: means DPDT, set BBP R4 bit 5 to 1
29548 + 1: means SPDT, set BBP R4 bit 5 to 0
29549 +
29550 +
29551 + ========================================================================
29552 +*/
29553 +VOID AsicAntennaSetting(
29554 + IN PRTMP_ADAPTER pAd,
29555 + IN ABGBAND_STATE BandState)
29556 +{
29557 +}
29558 +
29559 +VOID AsicRfTuningExec(
29560 + IN PVOID SystemSpecific1,
29561 + IN PVOID FunctionContext,
29562 + IN PVOID SystemSpecific2,
29563 + IN PVOID SystemSpecific3)
29564 +{
29565 +}
29566 +
29567 +/*
29568 + ==========================================================================
29569 + Description:
29570 + Gives CCK TX rate 2 more dB TX power.
29571 + This routine works only in LINK UP in INFRASTRUCTURE mode.
29572 +
29573 + calculate desired Tx power in RF R3.Tx0~5, should consider -
29574 + 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
29575 + 1. TxPowerPercentage
29576 + 2. auto calibration based on TSSI feedback
29577 + 3. extra 2 db for CCK
29578 + 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
29579 +
29580 + NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
29581 + it should be called AFTER MlmeDynamicTxRatSwitching()
29582 + ==========================================================================
29583 + */
29584 +VOID AsicAdjustTxPower(
29585 + IN PRTMP_ADAPTER pAd)
29586 +{
29587 + INT i, j;
29588 + CHAR DeltaPwr = 0;
29589 + BOOLEAN bAutoTxAgc = FALSE;
29590 + UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
29591 + UCHAR BbpR1 = 0, BbpR49 = 0, idx;
29592 + PCHAR pTxAgcCompensate;
29593 + ULONG TxPwr[5];
29594 + CHAR Value;
29595 +
29596 +
29597 +
29598 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
29599 + {
29600 + if (pAd->CommonCfg.CentralChannel > 14)
29601 + {
29602 + TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
29603 + TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
29604 + TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
29605 + TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
29606 + TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
29607 + }
29608 + else
29609 + {
29610 + TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
29611 + TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
29612 + TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
29613 + TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
29614 + TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
29615 + }
29616 + }
29617 + else
29618 + {
29619 + if (pAd->CommonCfg.Channel > 14)
29620 + {
29621 + TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
29622 + TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
29623 + TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
29624 + TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
29625 + TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
29626 + }
29627 + else
29628 + {
29629 + TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
29630 + TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
29631 + TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
29632 + TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
29633 + TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
29634 + }
29635 + }
29636 +
29637 + // TX power compensation for temperature variation based on TSSI. try every 4 second
29638 + if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
29639 + {
29640 + if (pAd->CommonCfg.Channel <= 14)
29641 + {
29642 + /* bg channel */
29643 + bAutoTxAgc = pAd->bAutoTxAgcG;
29644 + TssiRef = pAd->TssiRefG;
29645 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
29646 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
29647 + TxAgcStep = pAd->TxAgcStepG;
29648 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
29649 + }
29650 + else
29651 + {
29652 + /* a channel */
29653 + bAutoTxAgc = pAd->bAutoTxAgcA;
29654 + TssiRef = pAd->TssiRefA;
29655 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
29656 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
29657 + TxAgcStep = pAd->TxAgcStepA;
29658 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
29659 + }
29660 +
29661 + if (bAutoTxAgc)
29662 + {
29663 + /* BbpR1 is unsigned char */
29664 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
29665 +
29666 + /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
29667 + /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
29668 + /* step value is defined in pAd->TxAgcStepG for tx power value */
29669 +
29670 + /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
29671 + /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
29672 + above value are examined in mass factory production */
29673 + /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
29674 +
29675 + /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */
29676 + /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
29677 + /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */
29678 +
29679 + if (BbpR49 > pTssiMinusBoundary[1])
29680 + {
29681 + // Reading is larger than the reference value
29682 + // check for how large we need to decrease the Tx power
29683 + for (idx = 1; idx < 5; idx++)
29684 + {
29685 + if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
29686 + break;
29687 + }
29688 + // The index is the step we should decrease, idx = 0 means there is nothing to compensate
29689 +// if (R3 > (ULONG) (TxAgcStep * (idx-1)))
29690 + *pTxAgcCompensate = -(TxAgcStep * (idx-1));
29691 +// else
29692 +// *pTxAgcCompensate = -((UCHAR)R3);
29693 +
29694 + DeltaPwr += (*pTxAgcCompensate);
29695 + DBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
29696 + BbpR49, TssiRef, TxAgcStep, idx-1));
29697 + }
29698 + else if (BbpR49 < pTssiPlusBoundary[1])
29699 + {
29700 + // Reading is smaller than the reference value
29701 + // check for how large we need to increase the Tx power
29702 + for (idx = 1; idx < 5; idx++)
29703 + {
29704 + if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
29705 + break;
29706 + }
29707 + // The index is the step we should increase, idx = 0 means there is nothing to compensate
29708 + *pTxAgcCompensate = TxAgcStep * (idx-1);
29709 + DeltaPwr += (*pTxAgcCompensate);
29710 + DBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
29711 + BbpR49, TssiRef, TxAgcStep, idx-1));
29712 + }
29713 + else
29714 + {
29715 + *pTxAgcCompensate = 0;
29716 + DBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
29717 + BbpR49, TssiRef, TxAgcStep, 0));
29718 + }
29719 + }
29720 + }
29721 + else
29722 + {
29723 + if (pAd->CommonCfg.Channel <= 14)
29724 + {
29725 + bAutoTxAgc = pAd->bAutoTxAgcG;
29726 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
29727 + }
29728 + else
29729 + {
29730 + bAutoTxAgc = pAd->bAutoTxAgcA;
29731 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
29732 + }
29733 +
29734 + if (bAutoTxAgc)
29735 + DeltaPwr += (*pTxAgcCompensate);
29736 + }
29737 +
29738 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1);
29739 + BbpR1 &= 0xFC;
29740 +
29741 +#ifdef SINGLE_SKU
29742 + // Handle regulatory max tx power constrain
29743 + do
29744 + {
29745 + UCHAR TxPwrInEEPROM = 0xFF, CountryTxPwr = 0xFF, criterion;
29746 + UCHAR AdjustMaxTxPwr[40];
29747 +
29748 + if (pAd->CommonCfg.Channel > 14) // 5G band
29749 + TxPwrInEEPROM = ((pAd->CommonCfg.DefineMaxTxPwr & 0xFF00) >> 8);
29750 + else // 2.4G band
29751 + TxPwrInEEPROM = (pAd->CommonCfg.DefineMaxTxPwr & 0x00FF);
29752 + CountryTxPwr = GetCuntryMaxTxPwr(pAd, pAd->CommonCfg.Channel);
29753 +
29754 + // error handling, range check
29755 + if ((TxPwrInEEPROM > 0x50) || (CountryTxPwr > 0x50))
29756 + {
29757 + DBGPRINT(RT_DEBUG_ERROR,("AsicAdjustTxPower - Invalid max tx power (=0x%02x), CountryTxPwr=%d\n", TxPwrInEEPROM, CountryTxPwr));
29758 + break;
29759 + }
29760 +
29761 + criterion = *((PUCHAR)TxPwr + 2) & 0xF; // FAE use OFDM 6M as criterion
29762 +
29763 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (criterion=%d, TxPwrInEEPROM=%d, CountryTxPwr=%d)\n", criterion, TxPwrInEEPROM, CountryTxPwr));
29764 +
29765 + // Adjust max tx power according to the relationship of tx power in E2PROM
29766 + for (i=0; i<5; i++)
29767 + {
29768 + // CCK will have 4dBm larger than OFDM
29769 + // Therefore, we should separate to parse the tx power field
29770 + if (i == 0)
29771 + {
29772 + for (j=0; j<8; j++)
29773 + {
29774 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29775 +
29776 + if (j < 4)
29777 + {
29778 + // CCK will have 4dBm larger than OFDM
29779 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion) + 4;
29780 + }
29781 + else
29782 + {
29783 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion);
29784 + }
29785 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29786 + }
29787 + }
29788 + else
29789 + {
29790 + for (j=0; j<8; j++)
29791 + {
29792 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29793 +
29794 + AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion);
29795 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29796 + }
29797 + }
29798 + }
29799 +
29800 + // Adjust tx power according to the relationship
29801 + for (i=0; i<5; i++)
29802 + {
29803 + if (TxPwr[i] != 0xffffffff)
29804 + {
29805 + for (j=0; j<8; j++)
29806 + {
29807 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F);
29808 +
29809 + // The system tx power is larger than the regulatory, the power should be restrain
29810 + if (AdjustMaxTxPwr[i*8+j] > CountryTxPwr)
29811 + {
29812 + // decrease to zero and don't need to take care BBPR1
29813 + if ((Value - (AdjustMaxTxPwr[i*8+j] - CountryTxPwr)) > 0)
29814 + Value -= (AdjustMaxTxPwr[i*8+j] - CountryTxPwr);
29815 + else
29816 + Value = 0;
29817 +
29818 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29819 + }
29820 + else
29821 + DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d, no change)\n", i, j, Value, AdjustMaxTxPwr[i*8+j]));
29822 +
29823 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
29824 + }
29825 + }
29826 + }
29827 + } while (FALSE);
29828 +#endif // SINGLE_SKU //
29829 +
29830 + /* calculate delta power based on the percentage specified from UI */
29831 + // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
29832 + // We lower TX power here according to the percentage specified from UI
29833 + if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
29834 + ;
29835 + else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
29836 + ;
29837 + else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1;
29838 + {
29839 + DeltaPwr -= 1;
29840 + }
29841 + else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3;
29842 + {
29843 + DeltaPwr -= 3;
29844 + }
29845 + else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6;
29846 + {
29847 + BbpR1 |= 0x01;
29848 + }
29849 + else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9;
29850 + {
29851 + BbpR1 |= 0x01;
29852 + DeltaPwr -= 3;
29853 + }
29854 + else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12;
29855 + {
29856 + BbpR1 |= 0x02;
29857 + }
29858 +
29859 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1);
29860 +
29861 + /* reset different new tx power for different TX rate */
29862 + for(i=0; i<5; i++)
29863 + {
29864 + if (TxPwr[i] != 0xffffffff)
29865 + {
29866 + for (j=0; j<8; j++)
29867 + {
29868 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
29869 +
29870 + if ((Value + DeltaPwr) < 0)
29871 + {
29872 + Value = 0; /* min */
29873 + }
29874 + else if ((Value + DeltaPwr) > 0xF)
29875 + {
29876 + Value = 0xF; /* max */
29877 + }
29878 + else
29879 + {
29880 + Value += DeltaPwr; /* temperature compensation */
29881 + }
29882 +
29883 + /* fill new value to CSR offset */
29884 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
29885 + }
29886 +
29887 + /* write tx power value to CSR */
29888 + /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
29889 + TX power for OFDM 6M/9M
29890 + TX power for CCK5.5M/11M
29891 + TX power for CCK1M/2M */
29892 + /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
29893 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
29894 + }
29895 + }
29896 +
29897 +
29898 +}
29899 +
29900 +#ifdef CONFIG_STA_SUPPORT
29901 +/*
29902 + ==========================================================================
29903 + Description:
29904 + put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup
29905 + automatically. Instead, MCU will issue a TwakeUpInterrupt to host after
29906 + the wakeup timer timeout. Driver has to issue a separate command to wake
29907 + PHY up.
29908 +
29909 + IRQL = DISPATCH_LEVEL
29910 +
29911 + ==========================================================================
29912 + */
29913 +VOID AsicSleepThenAutoWakeup(
29914 + IN PRTMP_ADAPTER pAd,
29915 + IN USHORT TbttNumToNextWakeUp)
29916 +{
29917 + RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp);
29918 +}
29919 +
29920 +/*
29921 + ==========================================================================
29922 + Description:
29923 + AsicForceWakeup() is used whenever manual wakeup is required
29924 + AsicForceSleep() should only be used when not in INFRA BSS. When
29925 + in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead.
29926 + ==========================================================================
29927 + */
29928 +VOID AsicForceSleep(
29929 + IN PRTMP_ADAPTER pAd)
29930 +{
29931 +
29932 +}
29933 +
29934 +/*
29935 + ==========================================================================
29936 + Description:
29937 + AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup)
29938 + expired.
29939 +
29940 + IRQL = PASSIVE_LEVEL
29941 + IRQL = DISPATCH_LEVEL
29942 + ==========================================================================
29943 + */
29944 +VOID AsicForceWakeup(
29945 + IN PRTMP_ADAPTER pAd,
29946 + IN BOOLEAN bFromTx)
29947 +{
29948 + DBGPRINT(RT_DEBUG_TRACE, ("--> AsicForceWakeup \n"));
29949 + RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx);
29950 +}
29951 +#endif // CONFIG_STA_SUPPORT //
29952 +/*
29953 + ==========================================================================
29954 + Description:
29955 + Set My BSSID
29956 +
29957 + IRQL = DISPATCH_LEVEL
29958 +
29959 + ==========================================================================
29960 + */
29961 +VOID AsicSetBssid(
29962 + IN PRTMP_ADAPTER pAd,
29963 + IN PUCHAR pBssid)
29964 +{
29965 + ULONG Addr4;
29966 + DBGPRINT(RT_DEBUG_TRACE, ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n",
29967 + pBssid[0],pBssid[1],pBssid[2],pBssid[3], pBssid[4],pBssid[5]));
29968 +
29969 + Addr4 = (ULONG)(pBssid[0]) |
29970 + (ULONG)(pBssid[1] << 8) |
29971 + (ULONG)(pBssid[2] << 16) |
29972 + (ULONG)(pBssid[3] << 24);
29973 + RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4);
29974 +
29975 + Addr4 = 0;
29976 + // always one BSSID in STA mode
29977 + Addr4 = (ULONG)(pBssid[4]) | (ULONG)(pBssid[5] << 8);
29978 +
29979 + RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4);
29980 +}
29981 +
29982 +VOID AsicSetMcastWC(
29983 + IN PRTMP_ADAPTER pAd)
29984 +{
29985 + MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[MCAST_WCID];
29986 + USHORT offset;
29987 +
29988 + pEntry->Sst = SST_ASSOC;
29989 + pEntry->Aid = MCAST_WCID; // Softap supports 1 BSSID and use WCID=0 as multicast Wcid index
29990 + pEntry->PsMode = PWR_ACTIVE;
29991 + pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate;
29992 + offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE;
29993 +}
29994 +
29995 +/*
29996 + ==========================================================================
29997 + Description:
29998 +
29999 + IRQL = DISPATCH_LEVEL
30000 +
30001 + ==========================================================================
30002 + */
30003 +VOID AsicDelWcidTab(
30004 + IN PRTMP_ADAPTER pAd,
30005 + IN UCHAR Wcid)
30006 +{
30007 + ULONG Addr0 = 0x0, Addr1 = 0x0;
30008 + ULONG offset;
30009 +
30010 + DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n",Wcid));
30011 + offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE;
30012 + RTMP_IO_WRITE32(pAd, offset, Addr0);
30013 + offset += 4;
30014 + RTMP_IO_WRITE32(pAd, offset, Addr1);
30015 +}
30016 +
30017 +/*
30018 + ==========================================================================
30019 + Description:
30020 +
30021 + IRQL = DISPATCH_LEVEL
30022 +
30023 + ==========================================================================
30024 + */
30025 +VOID AsicEnableRDG(
30026 + IN PRTMP_ADAPTER pAd)
30027 +{
30028 + TX_LINK_CFG_STRUC TxLinkCfg;
30029 + UINT32 Data = 0;
30030 +
30031 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
30032 + TxLinkCfg.field.TxRDGEn = 1;
30033 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
30034 +
30035 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
30036 + Data &= 0xFFFFFF00;
30037 + Data |= 0x80;
30038 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
30039 +
30040 + //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
30041 +}
30042 +
30043 +/*
30044 + ==========================================================================
30045 + Description:
30046 +
30047 + IRQL = DISPATCH_LEVEL
30048 +
30049 + ==========================================================================
30050 + */
30051 +VOID AsicDisableRDG(
30052 + IN PRTMP_ADAPTER pAd)
30053 +{
30054 + TX_LINK_CFG_STRUC TxLinkCfg;
30055 + UINT32 Data = 0;
30056 +
30057 +
30058 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
30059 + TxLinkCfg.field.TxRDGEn = 0;
30060 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
30061 +
30062 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
30063 +
30064 + Data &= 0xFFFFFF00;
30065 + //Data |= 0x20;
30066 +#ifndef WIFI_TEST
30067 + //if ( pAd->CommonCfg.bEnableTxBurst )
30068 + // Data |= 0x60; // for performance issue not set the TXOP to 0
30069 +#endif
30070 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE)
30071 +#ifdef DOT11_N_SUPPORT
30072 + && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE)
30073 +#endif // DOT11_N_SUPPORT //
30074 + )
30075 + {
30076 + // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode
30077 + if (pAd->CommonCfg.bEnableTxBurst)
30078 + Data |= 0x20;
30079 + }
30080 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
30081 +}
30082 +
30083 +/*
30084 + ==========================================================================
30085 + Description:
30086 +
30087 + IRQL = PASSIVE_LEVEL
30088 + IRQL = DISPATCH_LEVEL
30089 +
30090 + ==========================================================================
30091 + */
30092 +VOID AsicDisableSync(
30093 + IN PRTMP_ADAPTER pAd)
30094 +{
30095 + BCN_TIME_CFG_STRUC csr;
30096 +
30097 + DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n"));
30098 +
30099 + // 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect
30100 + // that NIC will never wakes up because TSF stops and no more
30101 + // TBTT interrupts
30102 + pAd->TbttTickCount = 0;
30103 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
30104 + csr.field.bBeaconGen = 0;
30105 + csr.field.bTBTTEnable = 0;
30106 + csr.field.TsfSyncMode = 0;
30107 + csr.field.bTsfTicking = 0;
30108 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
30109 +
30110 +}
30111 +
30112 +/*
30113 + ==========================================================================
30114 + Description:
30115 +
30116 + IRQL = DISPATCH_LEVEL
30117 +
30118 + ==========================================================================
30119 + */
30120 +VOID AsicEnableBssSync(
30121 + IN PRTMP_ADAPTER pAd)
30122 +{
30123 + BCN_TIME_CFG_STRUC csr;
30124 +
30125 + DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n"));
30126 +
30127 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
30128 +// RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, 0x00000000);
30129 +#ifdef CONFIG_STA_SUPPORT
30130 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30131 + {
30132 + csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU
30133 + csr.field.bTsfTicking = 1;
30134 + csr.field.TsfSyncMode = 1; // sync TSF in INFRASTRUCTURE mode
30135 + csr.field.bBeaconGen = 0; // do NOT generate BEACON
30136 + csr.field.bTBTTEnable = 1;
30137 + }
30138 +#endif // CONFIG_STA_SUPPORT //
30139 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
30140 +}
30141 +
30142 +/*
30143 + ==========================================================================
30144 + Description:
30145 + Note:
30146 + BEACON frame in shared memory should be built ok before this routine
30147 + can be called. Otherwise, a garbage frame maybe transmitted out every
30148 + Beacon period.
30149 +
30150 + IRQL = DISPATCH_LEVEL
30151 +
30152 + ==========================================================================
30153 + */
30154 +VOID AsicEnableIbssSync(
30155 + IN PRTMP_ADAPTER pAd)
30156 +{
30157 + BCN_TIME_CFG_STRUC csr9;
30158 + PUCHAR ptr;
30159 + UINT i;
30160 +
30161 + DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n", pAd->BeaconTxWI.MPDUtotalByteCount));
30162 +
30163 + RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word);
30164 + csr9.field.bBeaconGen = 0;
30165 + csr9.field.bTBTTEnable = 0;
30166 + csr9.field.bTsfTicking = 0;
30167 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
30168 +
30169 +
30170 +#ifdef RT2870
30171 + // move BEACON TXD and frame content to on-chip memory
30172 + ptr = (PUCHAR)&pAd->BeaconTxWI;
30173 + for (i=0; i<TXWI_SIZE; i+=2) // 16-byte TXWI field
30174 + {
30175 + //UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
30176 + //RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr);
30177 + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2);
30178 + ptr += 2;
30179 + }
30180 +
30181 + // start right after the 16-byte TXWI field
30182 + ptr = pAd->BeaconBuf;
30183 + for (i=0; i< pAd->BeaconTxWI.MPDUtotalByteCount; i+=2)
30184 + {
30185 + //UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
30186 + //RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr);
30187 + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2);
30188 + ptr +=2;
30189 + }
30190 +#endif // RT2870 //
30191 +
30192 + //
30193 + // For Wi-Fi faily generated beacons between participating stations.
30194 + // Set TBTT phase adaptive adjustment step to 8us (default 16us)
30195 + // don't change settings 2006-5- by Jerry
30196 + //RTMP_IO_WRITE32(pAd, TBTT_SYNC_CFG, 0x00001010);
30197 +
30198 + // start sending BEACON
30199 + csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU
30200 + csr9.field.bTsfTicking = 1;
30201 + csr9.field.TsfSyncMode = 2; // sync TSF in IBSS mode
30202 + csr9.field.bTBTTEnable = 1;
30203 + csr9.field.bBeaconGen = 1;
30204 + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
30205 +}
30206 +
30207 +/*
30208 + ==========================================================================
30209 + Description:
30210 +
30211 + IRQL = PASSIVE_LEVEL
30212 + IRQL = DISPATCH_LEVEL
30213 +
30214 + ==========================================================================
30215 + */
30216 +VOID AsicSetEdcaParm(
30217 + IN PRTMP_ADAPTER pAd,
30218 + IN PEDCA_PARM pEdcaParm)
30219 +{
30220 + EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg;
30221 + AC_TXOP_CSR0_STRUC csr0;
30222 + AC_TXOP_CSR1_STRUC csr1;
30223 + AIFSN_CSR_STRUC AifsnCsr;
30224 + CWMIN_CSR_STRUC CwminCsr;
30225 + CWMAX_CSR_STRUC CwmaxCsr;
30226 + int i;
30227 +
30228 + Ac0Cfg.word = 0;
30229 + Ac1Cfg.word = 0;
30230 + Ac2Cfg.word = 0;
30231 + Ac3Cfg.word = 0;
30232 + if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE))
30233 + {
30234 + DBGPRINT(RT_DEBUG_TRACE,("AsicSetEdcaParm\n"));
30235 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED);
30236 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
30237 + {
30238 + if (pAd->MacTab.Content[i].ValidAsCLI || pAd->MacTab.Content[i].ValidAsApCli)
30239 + CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[i], fCLIENT_STATUS_WMM_CAPABLE);
30240 + }
30241 +
30242 + //========================================================
30243 + // MAC Register has a copy .
30244 + //========================================================
30245 +//#ifndef WIFI_TEST
30246 + if( pAd->CommonCfg.bEnableTxBurst )
30247 + {
30248 + // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode
30249 + Ac0Cfg.field.AcTxop = 0x20; // Suggest by John for TxBurst in HT Mode
30250 + }
30251 + else
30252 + Ac0Cfg.field.AcTxop = 0; // QID_AC_BE
30253 +//#else
30254 +// Ac0Cfg.field.AcTxop = 0; // QID_AC_BE
30255 +//#endif
30256 + Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS;
30257 + Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS;
30258 + Ac0Cfg.field.Aifsn = 2;
30259 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
30260 +
30261 + Ac1Cfg.field.AcTxop = 0; // QID_AC_BK
30262 + Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS;
30263 + Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS;
30264 + Ac1Cfg.field.Aifsn = 2;
30265 + RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
30266 +
30267 + if (pAd->CommonCfg.PhyMode == PHY_11B)
30268 + {
30269 + Ac2Cfg.field.AcTxop = 192; // AC_VI: 192*32us ~= 6ms
30270 + Ac3Cfg.field.AcTxop = 96; // AC_VO: 96*32us ~= 3ms
30271 + }
30272 + else
30273 + {
30274 + Ac2Cfg.field.AcTxop = 96; // AC_VI: 96*32us ~= 3ms
30275 + Ac3Cfg.field.AcTxop = 48; // AC_VO: 48*32us ~= 1.5ms
30276 + }
30277 + Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS;
30278 + Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS;
30279 + Ac2Cfg.field.Aifsn = 2;
30280 + RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
30281 + Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS;
30282 + Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS;
30283 + Ac3Cfg.field.Aifsn = 2;
30284 + RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
30285 +
30286 + //========================================================
30287 + // DMA Register has a copy too.
30288 + //========================================================
30289 + csr0.field.Ac0Txop = 0; // QID_AC_BE
30290 + csr0.field.Ac1Txop = 0; // QID_AC_BK
30291 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
30292 + if (pAd->CommonCfg.PhyMode == PHY_11B)
30293 + {
30294 + csr1.field.Ac2Txop = 192; // AC_VI: 192*32us ~= 6ms
30295 + csr1.field.Ac3Txop = 96; // AC_VO: 96*32us ~= 3ms
30296 + }
30297 + else
30298 + {
30299 + csr1.field.Ac2Txop = 96; // AC_VI: 96*32us ~= 3ms
30300 + csr1.field.Ac3Txop = 48; // AC_VO: 48*32us ~= 1.5ms
30301 + }
30302 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
30303 +
30304 + CwminCsr.word = 0;
30305 + CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS;
30306 + CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS;
30307 + CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS;
30308 + CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS;
30309 + RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
30310 +
30311 + CwmaxCsr.word = 0;
30312 + CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS;
30313 + CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS;
30314 + CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS;
30315 + CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS;
30316 + RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
30317 +
30318 + RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222);
30319 +
30320 + NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(EDCA_PARM));
30321 + }
30322 + else
30323 + {
30324 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED);
30325 + //========================================================
30326 + // MAC Register has a copy.
30327 + //========================================================
30328 + //
30329 + // Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27
30330 + // To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue.
30331 + //
30332 + //pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this
30333 +
30334 + Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE];
30335 + Ac0Cfg.field.Cwmin= pEdcaParm->Cwmin[QID_AC_BE];
30336 + Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE];
30337 + Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; //+1;
30338 +
30339 + Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
30340 + Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; //+2;
30341 + Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK];
30342 + Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; //+1;
30343 +
30344 + Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10;
30345 + Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI];
30346 + Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI];
30347 + Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI];
30348 +#ifdef INF_AMAZON_SE
30349 +#endif // INF_AMAZON_SE //
30350 +
30351 +
30352 +#ifdef CONFIG_STA_SUPPORT
30353 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30354 + {
30355 + // Tuning for Wi-Fi WMM S06
30356 + if (pAd->CommonCfg.bWiFiTest &&
30357 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
30358 + Ac2Cfg.field.Aifsn -= 1;
30359 +
30360 + // Tuning for TGn Wi-Fi 5.2.32
30361 + // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta
30362 + if (STA_TGN_WIFI_ON(pAd) &&
30363 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
30364 + {
30365 + Ac0Cfg.field.Aifsn = 3;
30366 + Ac2Cfg.field.AcTxop = 5;
30367 + }
30368 +
30369 +#ifdef RT30xx
30370 + if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020)
30371 + {
30372 + // Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta.
30373 + Ac2Cfg.field.Aifsn = 5;
30374 + }
30375 +#endif // RT30xx //
30376 + }
30377 +#endif // CONFIG_STA_SUPPORT //
30378 +
30379 + Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO];
30380 + Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO];
30381 + Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO];
30382 + Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO];
30383 +
30384 +//#ifdef WIFI_TEST
30385 + if (pAd->CommonCfg.bWiFiTest)
30386 + {
30387 + if (Ac3Cfg.field.AcTxop == 102)
30388 + {
30389 + Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm->Txop[QID_AC_BE] : 10;
30390 + Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]-1; /* AIFSN must >= 1 */
30391 + Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
30392 + Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK];
30393 + Ac2Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VI];
30394 + } /* End of if */
30395 + }
30396 +//#endif // WIFI_TEST //
30397 +
30398 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
30399 + RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
30400 + RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
30401 + RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
30402 +
30403 +
30404 + //========================================================
30405 + // DMA Register has a copy too.
30406 + //========================================================
30407 + csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop;
30408 + csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop;
30409 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
30410 +
30411 + csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop;
30412 + csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop;
30413 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
30414 +
30415 + CwminCsr.word = 0;
30416 + CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE];
30417 + CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK];
30418 + CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI];
30419 +#ifdef CONFIG_STA_SUPPORT
30420 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30421 + CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; //for TGn wifi test
30422 +#endif // CONFIG_STA_SUPPORT //
30423 + RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
30424 +
30425 + CwmaxCsr.word = 0;
30426 + CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE];
30427 + CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK];
30428 + CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI];
30429 + CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO];
30430 + RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
30431 +
30432 + AifsnCsr.word = 0;
30433 + AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BE];
30434 + AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BK];
30435 + AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_VI];
30436 +#ifdef INF_AMAZON_SE
30437 +#endif // INF_AMAZON_SE //
30438 +
30439 +
30440 +#ifdef CONFIG_STA_SUPPORT
30441 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30442 + {
30443 + // Tuning for Wi-Fi WMM S06
30444 + if (pAd->CommonCfg.bWiFiTest &&
30445 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
30446 + AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4;
30447 +
30448 + // Tuning for TGn Wi-Fi 5.2.32
30449 + // STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta
30450 + if (STA_TGN_WIFI_ON(pAd) &&
30451 + pEdcaParm->Aifsn[QID_AC_VI] == 10)
30452 + {
30453 + AifsnCsr.field.Aifsn0 = 3;
30454 + AifsnCsr.field.Aifsn2 = 7;
30455 + }
30456 +
30457 + if (INFRA_ON(pAd))
30458 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_WMM_CAPABLE);
30459 + }
30460 +#endif // CONFIG_STA_SUPPORT //
30461 +
30462 +#ifdef CONFIG_STA_SUPPORT
30463 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30464 + AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; //pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test
30465 +#ifdef RT30xx
30466 + if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020)
30467 + {
30468 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30469 + AifsnCsr.field.Aifsn2 = 0x2; //pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04.
30470 + }
30471 +#endif // RT30xx //
30472 +#endif // CONFIG_STA_SUPPORT //
30473 + RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word);
30474 +
30475 + NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM));
30476 + if (!ADHOC_ON(pAd))
30477 + {
30478 + DBGPRINT(RT_DEBUG_TRACE,("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n", pEdcaParm->EdcaUpdateCount));
30479 + DBGPRINT(RT_DEBUG_TRACE,(" AC_BE %2d %2d %2d %4d %d\n",
30480 + pEdcaParm->Aifsn[0],
30481 + pEdcaParm->Cwmin[0],
30482 + pEdcaParm->Cwmax[0],
30483 + pEdcaParm->Txop[0]<<5,
30484 + pEdcaParm->bACM[0]));
30485 + DBGPRINT(RT_DEBUG_TRACE,(" AC_BK %2d %2d %2d %4d %d\n",
30486 + pEdcaParm->Aifsn[1],
30487 + pEdcaParm->Cwmin[1],
30488 + pEdcaParm->Cwmax[1],
30489 + pEdcaParm->Txop[1]<<5,
30490 + pEdcaParm->bACM[1]));
30491 + DBGPRINT(RT_DEBUG_TRACE,(" AC_VI %2d %2d %2d %4d %d\n",
30492 + pEdcaParm->Aifsn[2],
30493 + pEdcaParm->Cwmin[2],
30494 + pEdcaParm->Cwmax[2],
30495 + pEdcaParm->Txop[2]<<5,
30496 + pEdcaParm->bACM[2]));
30497 + DBGPRINT(RT_DEBUG_TRACE,(" AC_VO %2d %2d %2d %4d %d\n",
30498 + pEdcaParm->Aifsn[3],
30499 + pEdcaParm->Cwmin[3],
30500 + pEdcaParm->Cwmax[3],
30501 + pEdcaParm->Txop[3]<<5,
30502 + pEdcaParm->bACM[3]));
30503 + }
30504 + }
30505 +}
30506 +
30507 +/*
30508 + ==========================================================================
30509 + Description:
30510 +
30511 + IRQL = PASSIVE_LEVEL
30512 + IRQL = DISPATCH_LEVEL
30513 +
30514 + ==========================================================================
30515 + */
30516 +VOID AsicSetSlotTime(
30517 + IN PRTMP_ADAPTER pAd,
30518 + IN BOOLEAN bUseShortSlotTime)
30519 +{
30520 + ULONG SlotTime;
30521 + UINT32 RegValue = 0;
30522 +
30523 +#ifdef CONFIG_STA_SUPPORT
30524 + if (pAd->CommonCfg.Channel > 14)
30525 + bUseShortSlotTime = TRUE;
30526 +#endif // CONFIG_STA_SUPPORT //
30527 +
30528 + if (bUseShortSlotTime)
30529 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
30530 + else
30531 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
30532 +
30533 + SlotTime = (bUseShortSlotTime)? 9 : 20;
30534 +
30535 +#ifdef CONFIG_STA_SUPPORT
30536 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30537 + {
30538 + // force using short SLOT time for FAE to demo performance when TxBurst is ON
30539 + if (pAd->CommonCfg.bEnableTxBurst)
30540 + SlotTime = 9;
30541 + }
30542 +#endif // CONFIG_STA_SUPPORT //
30543 +
30544 + //
30545 + // For some reasons, always set it to short slot time.
30546 + //
30547 + // ToDo: Should consider capability with 11B
30548 + //
30549 +#ifdef CONFIG_STA_SUPPORT
30550 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
30551 + {
30552 + if (pAd->StaCfg.BssType == BSS_ADHOC)
30553 + SlotTime = 20;
30554 + }
30555 +#endif // CONFIG_STA_SUPPORT //
30556 +
30557 + RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue);
30558 + RegValue = RegValue & 0xFFFFFF00;
30559 +
30560 + RegValue |= SlotTime;
30561 +
30562 + RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue);
30563 +}
30564 +
30565 +/*
30566 + ========================================================================
30567 + Description:
30568 + Add Shared key information into ASIC.
30569 + Update shared key, TxMic and RxMic to Asic Shared key table
30570 + Update its cipherAlg to Asic Shared key Mode.
30571 +
30572 + Return:
30573 + ========================================================================
30574 +*/
30575 +VOID AsicAddSharedKeyEntry(
30576 + IN PRTMP_ADAPTER pAd,
30577 + IN UCHAR BssIndex,
30578 + IN UCHAR KeyIdx,
30579 + IN UCHAR CipherAlg,
30580 + IN PUCHAR pKey,
30581 + IN PUCHAR pTxMic,
30582 + IN PUCHAR pRxMic)
30583 +{
30584 + ULONG offset; //, csr0;
30585 + SHAREDKEY_MODE_STRUC csr1;
30586 +
30587 + DBGPRINT(RT_DEBUG_TRACE, ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,KeyIdx));
30588 +//============================================================================================
30589 +
30590 + DBGPRINT(RT_DEBUG_TRACE,("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg], BssIndex*4 + KeyIdx));
30591 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30592 + pKey[0],pKey[1],pKey[2],pKey[3],pKey[4],pKey[5],pKey[6],pKey[7],pKey[8],pKey[9],pKey[10],pKey[11],pKey[12],pKey[13],pKey[14],pKey[15]));
30593 + if (pRxMic)
30594 + {
30595 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30596 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
30597 + }
30598 + if (pTxMic)
30599 + {
30600 + DBGPRINT_RAW(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30601 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
30602 + }
30603 +//============================================================================================
30604 + //
30605 + // fill key material - key + TX MIC + RX MIC
30606 + //
30607 +
30608 +#ifdef RT2870
30609 +{
30610 + offset = SHARED_KEY_TABLE_BASE + (4*BssIndex + KeyIdx)*HW_KEY_ENTRY_SIZE;
30611 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY);
30612 +
30613 + offset += MAX_LEN_OF_SHARE_KEY;
30614 + if (pTxMic)
30615 + {
30616 + RTUSBMultiWrite(pAd, offset, pTxMic, 8);
30617 + }
30618 +
30619 + offset += 8;
30620 + if (pRxMic)
30621 + {
30622 + RTUSBMultiWrite(pAd, offset, pRxMic, 8);
30623 + }
30624 +}
30625 +#endif // RT2870 //
30626 +
30627 + //
30628 + // Update cipher algorithm. WSTA always use BSS0
30629 + //
30630 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word);
30631 + DBGPRINT(RT_DEBUG_TRACE,("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n", BssIndex,KeyIdx, csr1.word));
30632 + if ((BssIndex%2) == 0)
30633 + {
30634 + if (KeyIdx == 0)
30635 + csr1.field.Bss0Key0CipherAlg = CipherAlg;
30636 + else if (KeyIdx == 1)
30637 + csr1.field.Bss0Key1CipherAlg = CipherAlg;
30638 + else if (KeyIdx == 2)
30639 + csr1.field.Bss0Key2CipherAlg = CipherAlg;
30640 + else
30641 + csr1.field.Bss0Key3CipherAlg = CipherAlg;
30642 + }
30643 + else
30644 + {
30645 + if (KeyIdx == 0)
30646 + csr1.field.Bss1Key0CipherAlg = CipherAlg;
30647 + else if (KeyIdx == 1)
30648 + csr1.field.Bss1Key1CipherAlg = CipherAlg;
30649 + else if (KeyIdx == 2)
30650 + csr1.field.Bss1Key2CipherAlg = CipherAlg;
30651 + else
30652 + csr1.field.Bss1Key3CipherAlg = CipherAlg;
30653 + }
30654 + DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word));
30655 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word);
30656 +
30657 +}
30658 +
30659 +// IRQL = DISPATCH_LEVEL
30660 +VOID AsicRemoveSharedKeyEntry(
30661 + IN PRTMP_ADAPTER pAd,
30662 + IN UCHAR BssIndex,
30663 + IN UCHAR KeyIdx)
30664 +{
30665 + //ULONG SecCsr0;
30666 + SHAREDKEY_MODE_STRUC csr1;
30667 +
30668 + DBGPRINT(RT_DEBUG_TRACE,("AsicRemoveSharedKeyEntry: #%d \n", BssIndex*4 + KeyIdx));
30669 +
30670 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word);
30671 + if ((BssIndex%2) == 0)
30672 + {
30673 + if (KeyIdx == 0)
30674 + csr1.field.Bss0Key0CipherAlg = 0;
30675 + else if (KeyIdx == 1)
30676 + csr1.field.Bss0Key1CipherAlg = 0;
30677 + else if (KeyIdx == 2)
30678 + csr1.field.Bss0Key2CipherAlg = 0;
30679 + else
30680 + csr1.field.Bss0Key3CipherAlg = 0;
30681 + }
30682 + else
30683 + {
30684 + if (KeyIdx == 0)
30685 + csr1.field.Bss1Key0CipherAlg = 0;
30686 + else if (KeyIdx == 1)
30687 + csr1.field.Bss1Key1CipherAlg = 0;
30688 + else if (KeyIdx == 2)
30689 + csr1.field.Bss1Key2CipherAlg = 0;
30690 + else
30691 + csr1.field.Bss1Key3CipherAlg = 0;
30692 + }
30693 + DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word));
30694 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word);
30695 + ASSERT(BssIndex < 4);
30696 + ASSERT(KeyIdx < 4);
30697 +
30698 +}
30699 +
30700 +
30701 +VOID AsicUpdateWCIDAttribute(
30702 + IN PRTMP_ADAPTER pAd,
30703 + IN USHORT WCID,
30704 + IN UCHAR BssIndex,
30705 + IN UCHAR CipherAlg,
30706 + IN BOOLEAN bUsePairewiseKeyTable)
30707 +{
30708 + ULONG WCIDAttri = 0, offset;
30709 +
30710 + //
30711 + // Update WCID attribute.
30712 + // Only TxKey could update WCID attribute.
30713 + //
30714 + offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE);
30715 + WCIDAttri = (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable);
30716 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
30717 +}
30718 +
30719 +VOID AsicUpdateWCIDIVEIV(
30720 + IN PRTMP_ADAPTER pAd,
30721 + IN USHORT WCID,
30722 + IN ULONG uIV,
30723 + IN ULONG uEIV)
30724 +{
30725 + ULONG offset;
30726 +
30727 + offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
30728 +
30729 + RTMP_IO_WRITE32(pAd, offset, uIV);
30730 + RTMP_IO_WRITE32(pAd, offset + 4, uEIV);
30731 +}
30732 +
30733 +VOID AsicUpdateRxWCIDTable(
30734 + IN PRTMP_ADAPTER pAd,
30735 + IN USHORT WCID,
30736 + IN PUCHAR pAddr)
30737 +{
30738 + ULONG offset;
30739 + ULONG Addr;
30740 +
30741 + offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE);
30742 + Addr = pAddr[0] + (pAddr[1] << 8) +(pAddr[2] << 16) +(pAddr[3] << 24);
30743 + RTMP_IO_WRITE32(pAd, offset, Addr);
30744 + Addr = pAddr[4] + (pAddr[5] << 8);
30745 + RTMP_IO_WRITE32(pAd, offset + 4, Addr);
30746 +}
30747 +
30748 +
30749 +/*
30750 + ========================================================================
30751 +
30752 + Routine Description:
30753 + Set Cipher Key, Cipher algorithm, IV/EIV to Asic
30754 +
30755 + Arguments:
30756 + pAd Pointer to our adapter
30757 + WCID WCID Entry number.
30758 + BssIndex BSSID index, station or none multiple BSSID support
30759 + this value should be 0.
30760 + KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled
30761 + pCipherKey Pointer to Cipher Key.
30762 + bUsePairewiseKeyTable TRUE means saved the key in SharedKey table,
30763 + otherwise PairewiseKey table
30764 + bTxKey This is the transmit key if enabled.
30765 +
30766 + Return Value:
30767 + None
30768 +
30769 + Note:
30770 + This routine will set the relative key stuff to Asic including WCID attribute,
30771 + Cipher Key, Cipher algorithm and IV/EIV.
30772 +
30773 + IV/EIV will be update if this CipherKey is the transmission key because
30774 + ASIC will base on IV's KeyID value to select Cipher Key.
30775 +
30776 + If bTxKey sets to FALSE, this is not the TX key, but it could be
30777 + RX key
30778 +
30779 + For AP mode bTxKey must be always set to TRUE.
30780 + ========================================================================
30781 +*/
30782 +VOID AsicAddKeyEntry(
30783 + IN PRTMP_ADAPTER pAd,
30784 + IN USHORT WCID,
30785 + IN UCHAR BssIndex,
30786 + IN UCHAR KeyIdx,
30787 + IN PCIPHER_KEY pCipherKey,
30788 + IN BOOLEAN bUsePairewiseKeyTable,
30789 + IN BOOLEAN bTxKey)
30790 +{
30791 + ULONG offset;
30792 +// ULONG WCIDAttri = 0;
30793 + UCHAR IV4 = 0;
30794 + PUCHAR pKey = pCipherKey->Key;
30795 +// ULONG KeyLen = pCipherKey->KeyLen;
30796 + PUCHAR pTxMic = pCipherKey->TxMic;
30797 + PUCHAR pRxMic = pCipherKey->RxMic;
30798 + PUCHAR pTxtsc = pCipherKey->TxTsc;
30799 + UCHAR CipherAlg = pCipherKey->CipherAlg;
30800 + SHAREDKEY_MODE_STRUC csr1;
30801 +
30802 +// ASSERT(KeyLen <= MAX_LEN_OF_PEER_KEY);
30803 +
30804 + DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n"));
30805 + //
30806 + // 1.) decide key table offset
30807 + //
30808 + if (bUsePairewiseKeyTable)
30809 + offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
30810 + else
30811 + offset = SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE;
30812 +
30813 + //
30814 + // 2.) Set Key to Asic
30815 + //
30816 + //for (i = 0; i < KeyLen; i++)
30817 +
30818 +#ifdef RT2870
30819 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY);
30820 + offset += MAX_LEN_OF_PEER_KEY;
30821 +
30822 + //
30823 + // 3.) Set MIC key if available
30824 + //
30825 + if (pTxMic)
30826 + {
30827 + RTUSBMultiWrite(pAd, offset, pTxMic, 8);
30828 + }
30829 + offset += LEN_TKIP_TXMICK;
30830 +
30831 + if (pRxMic)
30832 + {
30833 + RTUSBMultiWrite(pAd, offset, pRxMic, 8);
30834 + }
30835 +#endif // RT2870 //
30836 +
30837 + //
30838 + // 4.) Modify IV/EIV if needs
30839 + // This will force Asic to use this key ID by setting IV.
30840 + //
30841 + if (bTxKey)
30842 + {
30843 +
30844 +#ifdef RT2870
30845 + UINT32 tmpVal;
30846 +
30847 + //
30848 + // Write IV
30849 + //
30850 + IV4 = (KeyIdx << 6);
30851 + if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) ||(CipherAlg == CIPHER_AES))
30852 + IV4 |= 0x20; // turn on extension bit means EIV existence
30853 +
30854 + tmpVal = pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) + (pTxtsc[0] << 16) + (IV4 << 24);
30855 + RTMP_IO_WRITE32(pAd, offset, tmpVal);
30856 +
30857 + //
30858 + // Write EIV
30859 + //
30860 + offset += 4;
30861 + RTMP_IO_WRITE32(pAd, offset, *(PUINT32)&pCipherKey->TxTsc[2]);
30862 +#endif // RT2870 //
30863 + AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg, bUsePairewiseKeyTable);
30864 + }
30865 +
30866 + if (!bUsePairewiseKeyTable)
30867 + {
30868 + //
30869 + // Only update the shared key security mode
30870 + //
30871 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), &csr1.word);
30872 + if ((BssIndex % 2) == 0)
30873 + {
30874 + if (KeyIdx == 0)
30875 + csr1.field.Bss0Key0CipherAlg = CipherAlg;
30876 + else if (KeyIdx == 1)
30877 + csr1.field.Bss0Key1CipherAlg = CipherAlg;
30878 + else if (KeyIdx == 2)
30879 + csr1.field.Bss0Key2CipherAlg = CipherAlg;
30880 + else
30881 + csr1.field.Bss0Key3CipherAlg = CipherAlg;
30882 + }
30883 + else
30884 + {
30885 + if (KeyIdx == 0)
30886 + csr1.field.Bss1Key0CipherAlg = CipherAlg;
30887 + else if (KeyIdx == 1)
30888 + csr1.field.Bss1Key1CipherAlg = CipherAlg;
30889 + else if (KeyIdx == 2)
30890 + csr1.field.Bss1Key2CipherAlg = CipherAlg;
30891 + else
30892 + csr1.field.Bss1Key3CipherAlg = CipherAlg;
30893 + }
30894 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), csr1.word);
30895 + }
30896 +
30897 + DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n"));
30898 +}
30899 +
30900 +
30901 +/*
30902 + ========================================================================
30903 + Description:
30904 + Add Pair-wise key material into ASIC.
30905 + Update pairwise key, TxMic and RxMic to Asic Pair-wise key table
30906 +
30907 + Return:
30908 + ========================================================================
30909 +*/
30910 +VOID AsicAddPairwiseKeyEntry(
30911 + IN PRTMP_ADAPTER pAd,
30912 + IN PUCHAR pAddr,
30913 + IN UCHAR WCID,
30914 + IN CIPHER_KEY *pCipherKey)
30915 +{
30916 + INT i;
30917 + ULONG offset;
30918 + PUCHAR pKey = pCipherKey->Key;
30919 + PUCHAR pTxMic = pCipherKey->TxMic;
30920 + PUCHAR pRxMic = pCipherKey->RxMic;
30921 +#ifdef DBG
30922 + UCHAR CipherAlg = pCipherKey->CipherAlg;
30923 +#endif // DBG //
30924 +
30925 + // EKEY
30926 + offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
30927 +#ifdef RT2870
30928 + RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY);
30929 +#endif // RT2870 //
30930 + for (i=0; i<MAX_LEN_OF_PEER_KEY; i+=4)
30931 + {
30932 + UINT32 Value;
30933 + RTMP_IO_READ32(pAd, offset + i, &Value);
30934 + }
30935 +
30936 + offset += MAX_LEN_OF_PEER_KEY;
30937 +
30938 + // MIC KEY
30939 + if (pTxMic)
30940 + {
30941 +#ifdef RT2870
30942 + RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8);
30943 +#endif // RT2870 //
30944 + }
30945 + offset += 8;
30946 + if (pRxMic)
30947 + {
30948 +#ifdef RT2870
30949 + RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8);
30950 +#endif // RT2870 //
30951 + }
30952 +
30953 + DBGPRINT(RT_DEBUG_TRACE,("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n",WCID, CipherName[CipherAlg]));
30954 + DBGPRINT(RT_DEBUG_TRACE,(" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30955 + pKey[0],pKey[1],pKey[2],pKey[3],pKey[4],pKey[5],pKey[6],pKey[7],pKey[8],pKey[9],pKey[10],pKey[11],pKey[12],pKey[13],pKey[14],pKey[15]));
30956 + if (pRxMic)
30957 + {
30958 + DBGPRINT(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30959 + pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7]));
30960 + }
30961 + if (pTxMic)
30962 + {
30963 + DBGPRINT(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
30964 + pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7]));
30965 + }
30966 +}
30967 +/*
30968 + ========================================================================
30969 + Description:
30970 + Remove Pair-wise key material from ASIC.
30971 +
30972 + Return:
30973 + ========================================================================
30974 +*/
30975 +VOID AsicRemovePairwiseKeyEntry(
30976 + IN PRTMP_ADAPTER pAd,
30977 + IN UCHAR BssIdx,
30978 + IN UCHAR Wcid)
30979 +{
30980 + ULONG WCIDAttri;
30981 + USHORT offset;
30982 +
30983 + // re-set the entry's WCID attribute as OPEN-NONE.
30984 + offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
30985 + WCIDAttri = (BssIdx<<4) | PAIRWISEKEYTABLE;
30986 + RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
30987 +}
30988 +
30989 +BOOLEAN AsicSendCommandToMcu(
30990 + IN PRTMP_ADAPTER pAd,
30991 + IN UCHAR Command,
30992 + IN UCHAR Token,
30993 + IN UCHAR Arg0,
30994 + IN UCHAR Arg1)
30995 +{
30996 + HOST_CMD_CSR_STRUC H2MCmd;
30997 + H2M_MAILBOX_STRUC H2MMailbox;
30998 + ULONG i = 0;
30999 + do
31000 + {
31001 + RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word);
31002 + if (H2MMailbox.field.Owner == 0)
31003 + break;
31004 +
31005 + RTMPusecDelay(2);
31006 + } while(i++ < 100);
31007 +
31008 + if (i >= 100)
31009 + {
31010 + {
31011 + DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n"));
31012 + }
31013 + return FALSE;
31014 + }
31015 +
31016 +
31017 + H2MMailbox.field.Owner = 1; // pass ownership to MCU
31018 + H2MMailbox.field.CmdToken = Token;
31019 + H2MMailbox.field.HighByte = Arg1;
31020 + H2MMailbox.field.LowByte = Arg0;
31021 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word);
31022 +
31023 + H2MCmd.word = 0;
31024 + H2MCmd.field.HostCommand = Command;
31025 + RTMP_IO_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word);
31026 +
31027 + if (Command != 0x80)
31028 + {
31029 + }
31030 +
31031 + return TRUE;
31032 +}
31033 +
31034 +
31035 +/*
31036 + ========================================================================
31037 +
31038 + Routine Description:
31039 + Verify the support rate for different PHY type
31040 +
31041 + Arguments:
31042 + pAd Pointer to our adapter
31043 +
31044 + Return Value:
31045 + None
31046 +
31047 + IRQL = PASSIVE_LEVEL
31048 +
31049 + ========================================================================
31050 +*/
31051 +VOID RTMPCheckRates(
31052 + IN PRTMP_ADAPTER pAd,
31053 + IN OUT UCHAR SupRate[],
31054 + IN OUT UCHAR *SupRateLen)
31055 +{
31056 + UCHAR RateIdx, i, j;
31057 + UCHAR NewRate[12], NewRateLen;
31058 +
31059 + NewRateLen = 0;
31060 +
31061 + if (pAd->CommonCfg.PhyMode == PHY_11B)
31062 + RateIdx = 4;
31063 + else
31064 + RateIdx = 12;
31065 +
31066 + // Check for support rates exclude basic rate bit
31067 + for (i = 0; i < *SupRateLen; i++)
31068 + for (j = 0; j < RateIdx; j++)
31069 + if ((SupRate[i] & 0x7f) == RateIdTo500Kbps[j])
31070 + NewRate[NewRateLen++] = SupRate[i];
31071 +
31072 + *SupRateLen = NewRateLen;
31073 + NdisMoveMemory(SupRate, NewRate, NewRateLen);
31074 +}
31075 +
31076 +#ifdef CONFIG_STA_SUPPORT
31077 +#ifdef DOT11_N_SUPPORT
31078 +BOOLEAN RTMPCheckChannel(
31079 + IN PRTMP_ADAPTER pAd,
31080 + IN UCHAR CentralChannel,
31081 + IN UCHAR Channel)
31082 +{
31083 + UCHAR k;
31084 + UCHAR UpperChannel = 0, LowerChannel = 0;
31085 + UCHAR NoEffectChannelinList = 0;
31086 +
31087 + // Find upper and lower channel according to 40MHz current operation.
31088 + if (CentralChannel < Channel)
31089 + {
31090 + UpperChannel = Channel;
31091 + if (CentralChannel > 2)
31092 + LowerChannel = CentralChannel - 2;
31093 + else
31094 + return FALSE;
31095 + }
31096 + else if (CentralChannel > Channel)
31097 + {
31098 + UpperChannel = CentralChannel + 2;
31099 + LowerChannel = Channel;
31100 + }
31101 +
31102 + for (k = 0;k < pAd->ChannelListNum;k++)
31103 + {
31104 + if (pAd->ChannelList[k].Channel == UpperChannel)
31105 + {
31106 + NoEffectChannelinList ++;
31107 + }
31108 + if (pAd->ChannelList[k].Channel == LowerChannel)
31109 + {
31110 + NoEffectChannelinList ++;
31111 + }
31112 + }
31113 +
31114 + DBGPRINT(RT_DEBUG_TRACE,("Total Channel in Channel List = [%d]\n", NoEffectChannelinList));
31115 + if (NoEffectChannelinList == 2)
31116 + return TRUE;
31117 + else
31118 + return FALSE;
31119 +}
31120 +
31121 +/*
31122 + ========================================================================
31123 +
31124 + Routine Description:
31125 + Verify the support rate for HT phy type
31126 +
31127 + Arguments:
31128 + pAd Pointer to our adapter
31129 +
31130 + Return Value:
31131 + FALSE if pAd->CommonCfg.SupportedHtPhy doesn't accept the pHtCapability. (AP Mode)
31132 +
31133 + IRQL = PASSIVE_LEVEL
31134 +
31135 + ========================================================================
31136 +*/
31137 +BOOLEAN RTMPCheckHt(
31138 + IN PRTMP_ADAPTER pAd,
31139 + IN UCHAR Wcid,
31140 + IN HT_CAPABILITY_IE *pHtCapability,
31141 + IN ADD_HT_INFO_IE *pAddHtInfo)
31142 +{
31143 + if (Wcid >= MAX_LEN_OF_MAC_TABLE)
31144 + return FALSE;
31145 +
31146 + // If use AMSDU, set flag.
31147 + if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable)
31148 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_AMSDU_INUSED);
31149 + // Save Peer Capability
31150 + if (pHtCapability->HtCapInfo.ShortGIfor20)
31151 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI20_CAPABLE);
31152 + if (pHtCapability->HtCapInfo.ShortGIfor40)
31153 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI40_CAPABLE);
31154 + if (pHtCapability->HtCapInfo.TxSTBC)
31155 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_TxSTBC_CAPABLE);
31156 + if (pHtCapability->HtCapInfo.RxSTBC)
31157 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RxSTBC_CAPABLE);
31158 + if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport)
31159 + {
31160 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RDG_CAPABLE);
31161 + }
31162 +
31163 + if (Wcid < MAX_LEN_OF_MAC_TABLE)
31164 + {
31165 + pAd->MacTab.Content[Wcid].MpduDensity = pHtCapability->HtCapParm.MpduDensity;
31166 + }
31167 +
31168 + // Will check ChannelWidth for MCSSet[4] below
31169 + pAd->MlmeAux.HtCapability.MCSSet[4] = 0x1;
31170 + switch (pAd->CommonCfg.RxStream)
31171 + {
31172 + case 1:
31173 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
31174 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0x00;
31175 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
31176 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
31177 + break;
31178 + case 2:
31179 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
31180 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
31181 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
31182 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
31183 + break;
31184 + case 3:
31185 + pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
31186 + pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
31187 + pAd->MlmeAux.HtCapability.MCSSet[2] = 0xff;
31188 + pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
31189 + break;
31190 + }
31191 +
31192 + pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth = pAddHtInfo->AddHtInfo.RecomWidth & pAd->CommonCfg.DesiredHtPhy.ChannelWidth;
31193 +
31194 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPCheckHt:: HtCapInfo.ChannelWidth=%d, RecomWidth=%d, DesiredHtPhy.ChannelWidth=%d, BW40MAvailForA/G=%d/%d, PhyMode=%d \n",
31195 + pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth, pAddHtInfo->AddHtInfo.RecomWidth, pAd->CommonCfg.DesiredHtPhy.ChannelWidth,
31196 + pAd->NicConfig2.field.BW40MAvailForA, pAd->NicConfig2.field.BW40MAvailForG, pAd->CommonCfg.PhyMode));
31197 +
31198 + pAd->MlmeAux.HtCapability.HtCapInfo.GF = pHtCapability->HtCapInfo.GF &pAd->CommonCfg.DesiredHtPhy.GF;
31199 +
31200 + // Send Assoc Req with my HT capability.
31201 + pAd->MlmeAux.HtCapability.HtCapInfo.AMsduSize = pAd->CommonCfg.DesiredHtPhy.AmsduSize;
31202 + pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs = pAd->CommonCfg.DesiredHtPhy.MimoPs;
31203 + pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (pHtCapability->HtCapInfo.ShortGIfor20);
31204 + pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (pHtCapability->HtCapInfo.ShortGIfor40);
31205 + pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC = (pAd->CommonCfg.DesiredHtPhy.TxSTBC)&(pHtCapability->HtCapInfo.RxSTBC);
31206 + pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC = (pAd->CommonCfg.DesiredHtPhy.RxSTBC)&(pHtCapability->HtCapInfo.TxSTBC);
31207 + pAd->MlmeAux.HtCapability.HtCapParm.MaxRAmpduFactor = pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor;
31208 + pAd->MlmeAux.HtCapability.HtCapParm.MpduDensity = pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity;
31209 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC;
31210 + pAd->MacTab.Content[Wcid].HTCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC;
31211 + if (pAd->CommonCfg.bRdg)
31212 + {
31213 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.RDGSupport = pHtCapability->ExtHtCapInfo.RDGSupport;
31214 + pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = 1;
31215 + }
31216 +
31217 + if (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_20)
31218 + pAd->MlmeAux.HtCapability.MCSSet[4] = 0x0; // BW20 can't transmit MCS32
31219 +
31220 + COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability);
31221 + return TRUE;
31222 +}
31223 +#endif // DOT11_N_SUPPORT //
31224 +#endif // CONFIG_STA_SUPPORT //
31225 +
31226 +/*
31227 + ========================================================================
31228 +
31229 + Routine Description:
31230 + Verify the support rate for different PHY type
31231 +
31232 + Arguments:
31233 + pAd Pointer to our adapter
31234 +
31235 + Return Value:
31236 + None
31237 +
31238 + IRQL = PASSIVE_LEVEL
31239 +
31240 + ========================================================================
31241 +*/
31242 +VOID RTMPUpdateMlmeRate(
31243 + IN PRTMP_ADAPTER pAd)
31244 +{
31245 + UCHAR MinimumRate;
31246 + UCHAR ProperMlmeRate; //= RATE_54;
31247 + UCHAR i, j, RateIdx = 12; //1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
31248 + BOOLEAN bMatch = FALSE;
31249 +
31250 + switch (pAd->CommonCfg.PhyMode)
31251 + {
31252 + case PHY_11B:
31253 + ProperMlmeRate = RATE_11;
31254 + MinimumRate = RATE_1;
31255 + break;
31256 + case PHY_11BG_MIXED:
31257 +#ifdef DOT11_N_SUPPORT
31258 + case PHY_11ABGN_MIXED:
31259 + case PHY_11BGN_MIXED:
31260 +#endif // DOT11_N_SUPPORT //
31261 + if ((pAd->MlmeAux.SupRateLen == 4) &&
31262 + (pAd->MlmeAux.ExtRateLen == 0))
31263 + // B only AP
31264 + ProperMlmeRate = RATE_11;
31265 + else
31266 + ProperMlmeRate = RATE_24;
31267 +
31268 + if (pAd->MlmeAux.Channel <= 14)
31269 + MinimumRate = RATE_1;
31270 + else
31271 + MinimumRate = RATE_6;
31272 + break;
31273 + case PHY_11A:
31274 +#ifdef DOT11_N_SUPPORT
31275 + case PHY_11N_2_4G: // rt2860 need to check mlmerate for 802.11n
31276 + case PHY_11GN_MIXED:
31277 + case PHY_11AGN_MIXED:
31278 + case PHY_11AN_MIXED:
31279 + case PHY_11N_5G:
31280 +#endif // DOT11_N_SUPPORT //
31281 + ProperMlmeRate = RATE_24;
31282 + MinimumRate = RATE_6;
31283 + break;
31284 + case PHY_11ABG_MIXED:
31285 + ProperMlmeRate = RATE_24;
31286 + if (pAd->MlmeAux.Channel <= 14)
31287 + MinimumRate = RATE_1;
31288 + else
31289 + MinimumRate = RATE_6;
31290 + break;
31291 + default: // error
31292 + ProperMlmeRate = RATE_1;
31293 + MinimumRate = RATE_1;
31294 + break;
31295 + }
31296 +
31297 + for (i = 0; i < pAd->MlmeAux.SupRateLen; i++)
31298 + {
31299 + for (j = 0; j < RateIdx; j++)
31300 + {
31301 + if ((pAd->MlmeAux.SupRate[i] & 0x7f) == RateIdTo500Kbps[j])
31302 + {
31303 + if (j == ProperMlmeRate)
31304 + {
31305 + bMatch = TRUE;
31306 + break;
31307 + }
31308 + }
31309 + }
31310 +
31311 + if (bMatch)
31312 + break;
31313 + }
31314 +
31315 + if (bMatch == FALSE)
31316 + {
31317 + for (i = 0; i < pAd->MlmeAux.ExtRateLen; i++)
31318 + {
31319 + for (j = 0; j < RateIdx; j++)
31320 + {
31321 + if ((pAd->MlmeAux.ExtRate[i] & 0x7f) == RateIdTo500Kbps[j])
31322 + {
31323 + if (j == ProperMlmeRate)
31324 + {
31325 + bMatch = TRUE;
31326 + break;
31327 + }
31328 + }
31329 + }
31330 +
31331 + if (bMatch)
31332 + break;
31333 + }
31334 + }
31335 +
31336 + if (bMatch == FALSE)
31337 + {
31338 + ProperMlmeRate = MinimumRate;
31339 + }
31340 +
31341 + pAd->CommonCfg.MlmeRate = MinimumRate;
31342 + pAd->CommonCfg.RtsRate = ProperMlmeRate;
31343 + if (pAd->CommonCfg.MlmeRate >= RATE_6)
31344 + {
31345 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
31346 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
31347 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
31348 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
31349 + }
31350 + else
31351 + {
31352 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
31353 + pAd->CommonCfg.MlmeTransmit.field.MCS = pAd->CommonCfg.MlmeRate;
31354 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_CCK;
31355 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = pAd->CommonCfg.MlmeRate;
31356 + }
31357 +
31358 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateMlmeRate ==> MlmeTransmit = 0x%x \n" , pAd->CommonCfg.MlmeTransmit.word));
31359 +}
31360 +
31361 +CHAR RTMPMaxRssi(
31362 + IN PRTMP_ADAPTER pAd,
31363 + IN CHAR Rssi0,
31364 + IN CHAR Rssi1,
31365 + IN CHAR Rssi2)
31366 +{
31367 + CHAR larger = -127;
31368 +
31369 + if ((pAd->Antenna.field.RxPath == 1) && (Rssi0 != 0))
31370 + {
31371 + larger = Rssi0;
31372 + }
31373 +
31374 + if ((pAd->Antenna.field.RxPath >= 2) && (Rssi1 != 0))
31375 + {
31376 + larger = max(Rssi0, Rssi1);
31377 + }
31378 +
31379 + if ((pAd->Antenna.field.RxPath == 3) && (Rssi2 != 0))
31380 + {
31381 + larger = max(larger, Rssi2);
31382 + }
31383 +
31384 + if (larger == -127)
31385 + larger = 0;
31386 +
31387 + return larger;
31388 +}
31389 +
31390 +
31391 +// Antenna divesity use GPIO3 and EESK pin for control
31392 +// Antenna and EEPROM access are both using EESK pin,
31393 +// Therefor we should avoid accessing EESK at the same time
31394 +// Then restore antenna after EEPROM access
31395 +VOID AsicSetRxAnt(
31396 + IN PRTMP_ADAPTER pAd,
31397 + IN UCHAR Ant)
31398 +{
31399 +#ifdef RT30xx
31400 + UINT32 Value;
31401 + UINT32 x;
31402 +
31403 + if ((pAd->EepromAccess) ||
31404 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
31405 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
31406 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) ||
31407 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
31408 + {
31409 + return;
31410 + }
31411 +
31412 + // the antenna selection is through firmware and MAC register(GPIO3)
31413 + if (Ant == 0)
31414 + {
31415 + // Main antenna
31416 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
31417 + x |= (EESK);
31418 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
31419 +
31420 + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value);
31421 + Value &= ~(0x0808);
31422 + RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value);
31423 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to main antenna\n"));
31424 + }
31425 + else
31426 + {
31427 + // Aux antenna
31428 + RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
31429 + x &= ~(EESK);
31430 + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
31431 +
31432 + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value);
31433 + Value &= ~(0x0808);
31434 + Value |= 0x08;
31435 + RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value);
31436 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to aux antenna\n"));
31437 + }
31438 +#endif // RT30xx //
31439 +}
31440 +
31441 +
31442 +/*
31443 + ========================================================================
31444 + Routine Description:
31445 + Periodic evaluate antenna link status
31446 +
31447 + Arguments:
31448 + pAd - Adapter pointer
31449 +
31450 + Return Value:
31451 + None
31452 +
31453 + ========================================================================
31454 +*/
31455 +VOID AsicEvaluateRxAnt(
31456 + IN PRTMP_ADAPTER pAd)
31457 +{
31458 + UCHAR BBPR3 = 0;
31459 +
31460 +#ifdef RALINK_ATE
31461 + if (ATE_ON(pAd))
31462 + return;
31463 +#endif // RALINK_ATE //
31464 +
31465 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS |
31466 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
31467 + fRTMP_ADAPTER_RADIO_OFF |
31468 + fRTMP_ADAPTER_NIC_NOT_EXIST |
31469 + fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) ||
31470 + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
31471 +#ifdef RT30xx
31472 + || (pAd->EepromAccess)
31473 +#endif // RT30xx //
31474 + )
31475 + return;
31476 +
31477 +
31478 +#ifdef CONFIG_STA_SUPPORT
31479 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31480 + {
31481 + //if (pAd->StaCfg.Psm == PWR_SAVE)
31482 + // return;
31483 + }
31484 +#endif // CONFIG_STA_SUPPORT //
31485 +
31486 + // two antenna selection mechanism- one is antenna diversity, the other is failed antenna remove
31487 + // one is antenna diversity:there is only one antenna can rx and tx
31488 + // the other is failed antenna remove:two physical antenna can rx and tx
31489 + if (pAd->NicConfig2.field.AntDiversity)
31490 + {
31491 + DBGPRINT(RT_DEBUG_TRACE,("AntDiv - before evaluate Pair1-Ant (%d,%d)\n",
31492 + pAd->RxAnt.Pair1PrimaryRxAnt, pAd->RxAnt.Pair1SecondaryRxAnt));
31493 +
31494 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1SecondaryRxAnt);
31495 +
31496 + pAd->RxAnt.EvaluatePeriod = 1; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt
31497 + pAd->RxAnt.FirstPktArrivedWhenEvaluate = FALSE;
31498 + pAd->RxAnt.RcvPktNumWhenEvaluate = 0;
31499 +
31500 + // a one-shot timer to end the evalution
31501 + // dynamic adjust antenna evaluation period according to the traffic
31502 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
31503 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 100);
31504 + else
31505 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300);
31506 + }
31507 + else
31508 + {
31509 +
31510 +#ifdef CONFIG_STA_SUPPORT
31511 + if (pAd->StaCfg.Psm == PWR_SAVE)
31512 + return;
31513 +#endif // CONFIG_STA_SUPPORT //
31514 +
31515 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
31516 + BBPR3 &= (~0x18);
31517 + if(pAd->Antenna.field.RxPath == 3)
31518 + {
31519 + BBPR3 |= (0x10);
31520 + }
31521 + else if(pAd->Antenna.field.RxPath == 2)
31522 + {
31523 + BBPR3 |= (0x8);
31524 + }
31525 + else if(pAd->Antenna.field.RxPath == 1)
31526 + {
31527 + BBPR3 |= (0x0);
31528 + }
31529 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
31530 +#ifdef CONFIG_STA_SUPPORT
31531 +#endif // CONFIG_STA_SUPPORT //
31532 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
31533 + )
31534 + {
31535 + ULONG TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
31536 + pAd->RalinkCounters.OneSecTxRetryOkCount +
31537 + pAd->RalinkCounters.OneSecTxFailCount;
31538 +
31539 + // dynamic adjust antenna evaluation period according to the traffic
31540 + if (TxTotalCnt > 50)
31541 + {
31542 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 20);
31543 + pAd->Mlme.bLowThroughput = FALSE;
31544 + }
31545 + else
31546 + {
31547 + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300);
31548 + pAd->Mlme.bLowThroughput = TRUE;
31549 + }
31550 + }
31551 + }
31552 +}
31553 +
31554 +/*
31555 + ========================================================================
31556 + Routine Description:
31557 + After evaluation, check antenna link status
31558 +
31559 + Arguments:
31560 + pAd - Adapter pointer
31561 +
31562 + Return Value:
31563 + None
31564 +
31565 + ========================================================================
31566 +*/
31567 +VOID AsicRxAntEvalTimeout(
31568 + IN PVOID SystemSpecific1,
31569 + IN PVOID FunctionContext,
31570 + IN PVOID SystemSpecific2,
31571 + IN PVOID SystemSpecific3)
31572 +{
31573 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
31574 +#ifdef CONFIG_STA_SUPPORT
31575 + UCHAR BBPR3 = 0;
31576 + CHAR larger = -127, rssi0, rssi1, rssi2;
31577 +#endif // CONFIG_STA_SUPPORT //
31578 +
31579 +#ifdef RALINK_ATE
31580 + if (ATE_ON(pAd))
31581 + return;
31582 +#endif // RALINK_ATE //
31583 +
31584 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS |
31585 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
31586 + fRTMP_ADAPTER_RADIO_OFF |
31587 + fRTMP_ADAPTER_NIC_NOT_EXIST) ||
31588 + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
31589 +#ifdef RT30xx
31590 + || (pAd->EepromAccess)
31591 +#endif // RT30xx //
31592 + )
31593 + return;
31594 +
31595 +
31596 +#ifdef CONFIG_STA_SUPPORT
31597 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31598 + {
31599 + //if (pAd->StaCfg.Psm == PWR_SAVE)
31600 + // return;
31601 +
31602 + if (pAd->NicConfig2.field.AntDiversity)
31603 + {
31604 + if ((pAd->RxAnt.RcvPktNumWhenEvaluate != 0) && (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >= pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt]))
31605 + {
31606 + UCHAR temp;
31607 +
31608 + //
31609 + // select PrimaryRxAntPair
31610 + // Role change, Used Pair1SecondaryRxAnt as PrimaryRxAntPair.
31611 + // Since Pair1SecondaryRxAnt Quality good than Pair1PrimaryRxAnt
31612 + //
31613 + temp = pAd->RxAnt.Pair1PrimaryRxAnt;
31614 + pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt;
31615 + pAd->RxAnt.Pair1SecondaryRxAnt = temp;
31616 +
31617 + pAd->RxAnt.Pair1LastAvgRssi = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >> 3);
31618 + pAd->RxAnt.EvaluateStableCnt = 0;
31619 + }
31620 + else
31621 + {
31622 + // if the evaluated antenna is not better than original, switch back to original antenna
31623 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
31624 + pAd->RxAnt.EvaluateStableCnt ++;
31625 + }
31626 +
31627 + pAd->RxAnt.EvaluatePeriod = 0; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt
31628 +
31629 + DBGPRINT(RT_DEBUG_TRACE,("AsicRxAntEvalAction::After Eval(fix in #%d), <%d, %d>, RcvPktNumWhenEvaluate=%ld\n",
31630 + pAd->RxAnt.Pair1PrimaryRxAnt, (pAd->RxAnt.Pair1AvgRssi[0] >> 3), (pAd->RxAnt.Pair1AvgRssi[1] >> 3), pAd->RxAnt.RcvPktNumWhenEvaluate));
31631 + }
31632 + else
31633 + {
31634 + if (pAd->StaCfg.Psm == PWR_SAVE)
31635 + return;
31636 +
31637 + // if the traffic is low, use average rssi as the criteria
31638 + if (pAd->Mlme.bLowThroughput == TRUE)
31639 + {
31640 + rssi0 = pAd->StaCfg.RssiSample.LastRssi0;
31641 + rssi1 = pAd->StaCfg.RssiSample.LastRssi1;
31642 + rssi2 = pAd->StaCfg.RssiSample.LastRssi2;
31643 + }
31644 + else
31645 + {
31646 + rssi0 = pAd->StaCfg.RssiSample.AvgRssi0;
31647 + rssi1 = pAd->StaCfg.RssiSample.AvgRssi1;
31648 + rssi2 = pAd->StaCfg.RssiSample.AvgRssi2;
31649 + }
31650 +
31651 + if(pAd->Antenna.field.RxPath == 3)
31652 + {
31653 + larger = max(rssi0, rssi1);
31654 +
31655 + if (larger > (rssi2 + 20))
31656 + pAd->Mlme.RealRxPath = 2;
31657 + else
31658 + pAd->Mlme.RealRxPath = 3;
31659 + }
31660 + else if(pAd->Antenna.field.RxPath == 2)
31661 + {
31662 + if (rssi0 > (rssi1 + 20))
31663 + pAd->Mlme.RealRxPath = 1;
31664 + else
31665 + pAd->Mlme.RealRxPath = 2;
31666 + }
31667 +
31668 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
31669 + BBPR3 &= (~0x18);
31670 + if(pAd->Mlme.RealRxPath == 3)
31671 + {
31672 + BBPR3 |= (0x10);
31673 + }
31674 + else if(pAd->Mlme.RealRxPath == 2)
31675 + {
31676 + BBPR3 |= (0x8);
31677 + }
31678 + else if(pAd->Mlme.RealRxPath == 1)
31679 + {
31680 + BBPR3 |= (0x0);
31681 + }
31682 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
31683 + }
31684 + }
31685 +
31686 +#endif // CONFIG_STA_SUPPORT //
31687 +
31688 +}
31689 +
31690 +
31691 +
31692 +VOID APSDPeriodicExec(
31693 + IN PVOID SystemSpecific1,
31694 + IN PVOID FunctionContext,
31695 + IN PVOID SystemSpecific2,
31696 + IN PVOID SystemSpecific3)
31697 +{
31698 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
31699 +
31700 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
31701 + return;
31702 +
31703 + pAd->CommonCfg.TriggerTimerCount++;
31704 +
31705 +// Driver should not send trigger frame, it should be send by application layer
31706 +/*
31707 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable
31708 + && (pAd->CommonCfg.bNeedSendTriggerFrame ||
31709 + (((pAd->CommonCfg.TriggerTimerCount%20) == 19) && (!pAd->CommonCfg.bAPSDAC_BE || !pAd->CommonCfg.bAPSDAC_BK || !pAd->CommonCfg.bAPSDAC_VI || !pAd->CommonCfg.bAPSDAC_VO))))
31710 + {
31711 + DBGPRINT(RT_DEBUG_TRACE,("Sending trigger frame and enter service period when support APSD\n"));
31712 + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
31713 + pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
31714 + pAd->CommonCfg.TriggerTimerCount = 0;
31715 + pAd->CommonCfg.bInServicePeriod = TRUE;
31716 + }*/
31717 +}
31718 +
31719 +/*
31720 + ========================================================================
31721 + Routine Description:
31722 + Set/reset MAC registers according to bPiggyBack parameter
31723 +
31724 + Arguments:
31725 + pAd - Adapter pointer
31726 + bPiggyBack - Enable / Disable Piggy-Back
31727 +
31728 + Return Value:
31729 + None
31730 +
31731 + ========================================================================
31732 +*/
31733 +VOID RTMPSetPiggyBack(
31734 + IN PRTMP_ADAPTER pAd,
31735 + IN BOOLEAN bPiggyBack)
31736 +{
31737 + TX_LINK_CFG_STRUC TxLinkCfg;
31738 +
31739 + RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
31740 +
31741 + TxLinkCfg.field.TxCFAckEn = bPiggyBack;
31742 + RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
31743 +}
31744 +
31745 +/*
31746 + ========================================================================
31747 + Routine Description:
31748 + check if this entry need to switch rate automatically
31749 +
31750 + Arguments:
31751 + pAd
31752 + pEntry
31753 +
31754 + Return Value:
31755 + TURE
31756 + FALSE
31757 +
31758 + ========================================================================
31759 +*/
31760 +BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(
31761 + IN PRTMP_ADAPTER pAd,
31762 + IN PMAC_TABLE_ENTRY pEntry)
31763 +{
31764 + BOOLEAN result = TRUE;
31765 +
31766 +
31767 +#ifdef CONFIG_STA_SUPPORT
31768 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31769 + {
31770 + // only associated STA counts
31771 + if (pEntry && (pEntry->ValidAsCLI) && (pEntry->Sst == SST_ASSOC))
31772 + {
31773 + result = pAd->StaCfg.bAutoTxRateSwitch;
31774 + }
31775 + else
31776 + result = FALSE;
31777 + }
31778 +#endif // CONFIG_STA_SUPPORT //
31779 +
31780 +
31781 +
31782 + return result;
31783 +}
31784 +
31785 +
31786 +BOOLEAN RTMPAutoRateSwitchCheck(
31787 + IN PRTMP_ADAPTER pAd)
31788 +{
31789 +
31790 +#ifdef CONFIG_STA_SUPPORT
31791 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31792 + {
31793 + if (pAd->StaCfg.bAutoTxRateSwitch)
31794 + return TRUE;
31795 + }
31796 +#endif // CONFIG_STA_SUPPORT //
31797 + return FALSE;
31798 +}
31799 +
31800 +
31801 +/*
31802 + ========================================================================
31803 + Routine Description:
31804 + check if this entry need to fix tx legacy rate
31805 +
31806 + Arguments:
31807 + pAd
31808 + pEntry
31809 +
31810 + Return Value:
31811 + TURE
31812 + FALSE
31813 +
31814 + ========================================================================
31815 +*/
31816 +UCHAR RTMPStaFixedTxMode(
31817 + IN PRTMP_ADAPTER pAd,
31818 + IN PMAC_TABLE_ENTRY pEntry)
31819 +{
31820 + UCHAR tx_mode = FIXED_TXMODE_HT;
31821 +
31822 +
31823 +#ifdef CONFIG_STA_SUPPORT
31824 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
31825 + {
31826 + tx_mode = (UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode;
31827 + }
31828 +#endif // CONFIG_STA_SUPPORT //
31829 +
31830 + return tx_mode;
31831 +}
31832 +
31833 +/*
31834 + ========================================================================
31835 + Routine Description:
31836 + Overwrite HT Tx Mode by Fixed Legency Tx Mode, if specified.
31837 +
31838 + Arguments:
31839 + pAd
31840 + pEntry
31841 +
31842 + Return Value:
31843 + TURE
31844 + FALSE
31845 +
31846 + ========================================================================
31847 +*/
31848 +VOID RTMPUpdateLegacyTxSetting(
31849 + UCHAR fixed_tx_mode,
31850 + PMAC_TABLE_ENTRY pEntry)
31851 +{
31852 + HTTRANSMIT_SETTING TransmitSetting;
31853 +
31854 + if (fixed_tx_mode == FIXED_TXMODE_HT)
31855 + return;
31856 +
31857 + TransmitSetting.word = 0;
31858 +
31859 + TransmitSetting.field.MODE = pEntry->HTPhyMode.field.MODE;
31860 + TransmitSetting.field.MCS = pEntry->HTPhyMode.field.MCS;
31861 +
31862 + if (fixed_tx_mode == FIXED_TXMODE_CCK)
31863 + {
31864 + TransmitSetting.field.MODE = MODE_CCK;
31865 + // CCK mode allow MCS 0~3
31866 + if (TransmitSetting.field.MCS > MCS_3)
31867 + TransmitSetting.field.MCS = MCS_3;
31868 + }
31869 + else
31870 + {
31871 + TransmitSetting.field.MODE = MODE_OFDM;
31872 + // OFDM mode allow MCS 0~7
31873 + if (TransmitSetting.field.MCS > MCS_7)
31874 + TransmitSetting.field.MCS = MCS_7;
31875 + }
31876 +
31877 + if (pEntry->HTPhyMode.field.MODE >= TransmitSetting.field.MODE)
31878 + {
31879 + pEntry->HTPhyMode.word = TransmitSetting.word;
31880 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateLegacyTxSetting : wcid-%d, MODE=%s, MCS=%d \n",
31881 + pEntry->Aid, GetPhyMode(pEntry->HTPhyMode.field.MODE), pEntry->HTPhyMode.field.MCS));
31882 + }
31883 +}
31884 +
31885 +#ifdef CONFIG_STA_SUPPORT
31886 +/*
31887 + ==========================================================================
31888 + Description:
31889 + dynamic tune BBP R66 to find a balance between sensibility and
31890 + noise isolation
31891 +
31892 + IRQL = DISPATCH_LEVEL
31893 +
31894 + ==========================================================================
31895 + */
31896 +VOID AsicStaBbpTuning(
31897 + IN PRTMP_ADAPTER pAd)
31898 +{
31899 + UCHAR OrigR66Value = 0, R66;//, R66UpperBound = 0x30, R66LowerBound = 0x30;
31900 + CHAR Rssi;
31901 +
31902 + // 2860C did not support Fase CCA, therefore can't tune
31903 + if (pAd->MACVersion == 0x28600100)
31904 + return;
31905 +
31906 + //
31907 + // work as a STA
31908 + //
31909 + if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) // no R66 tuning when SCANNING
31910 + return;
31911 +
31912 + if ((pAd->OpMode == OPMODE_STA)
31913 + && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
31914 + )
31915 + && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
31916 + )
31917 + {
31918 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value);
31919 + R66 = OrigR66Value;
31920 +
31921 + if (pAd->Antenna.field.RxPath > 1)
31922 + Rssi = (pAd->StaCfg.RssiSample.AvgRssi0 + pAd->StaCfg.RssiSample.AvgRssi1) >> 1;
31923 + else
31924 + Rssi = pAd->StaCfg.RssiSample.AvgRssi0;
31925 +
31926 + if (pAd->LatchRfRegs.Channel <= 14)
31927 + { //BG band
31928 +#ifdef RT30xx
31929 + // RT3070 is a no LNA solution, it should have different control regarding to AGC gain control
31930 + // Otherwise, it will have some throughput side effect when low RSSI
31931 + if (IS_RT30xx(pAd))
31932 + {
31933 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31934 + {
31935 + R66 = 0x1C + 2*GET_LNA_GAIN(pAd) + 0x20;
31936 + if (OrigR66Value != R66)
31937 + {
31938 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31939 + }
31940 + }
31941 + else
31942 + {
31943 + R66 = 0x1C + 2*GET_LNA_GAIN(pAd);
31944 + if (OrigR66Value != R66)
31945 + {
31946 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31947 + }
31948 + }
31949 + }
31950 + else
31951 +#endif // RT30xx //
31952 + {
31953 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31954 + {
31955 + R66 = (0x2E + GET_LNA_GAIN(pAd)) + 0x10;
31956 + if (OrigR66Value != R66)
31957 + {
31958 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31959 + }
31960 + }
31961 + else
31962 + {
31963 + R66 = 0x2E + GET_LNA_GAIN(pAd);
31964 + if (OrigR66Value != R66)
31965 + {
31966 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31967 + }
31968 + }
31969 + }
31970 +
31971 + }
31972 + else
31973 + { //A band
31974 + if (pAd->CommonCfg.BBPCurrentBW == BW_20)
31975 + {
31976 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31977 + {
31978 + R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3 + 0x10;
31979 + if (OrigR66Value != R66)
31980 + {
31981 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31982 + }
31983 + }
31984 + else
31985 + {
31986 + R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3;
31987 + if (OrigR66Value != R66)
31988 + {
31989 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
31990 + }
31991 + }
31992 + }
31993 + else
31994 + {
31995 + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY)
31996 + {
31997 + R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3 + 0x10;
31998 + if (OrigR66Value != R66)
31999 + {
32000 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
32001 + }
32002 + }
32003 + else
32004 + {
32005 + R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3;
32006 + if (OrigR66Value != R66)
32007 + {
32008 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
32009 + }
32010 + }
32011 + }
32012 + }
32013 +
32014 +
32015 + }
32016 +}
32017 +#endif // CONFIG_STA_SUPPORT //
32018 +
32019 +VOID RTMPSetAGCInitValue(
32020 + IN PRTMP_ADAPTER pAd,
32021 + IN UCHAR BandWidth)
32022 +{
32023 + UCHAR R66 = 0x30;
32024 +
32025 + if (pAd->LatchRfRegs.Channel <= 14)
32026 + { // BG band
32027 + R66 = 0x2E + GET_LNA_GAIN(pAd);
32028 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
32029 + }
32030 + else
32031 + { //A band
32032 + if (BandWidth == BW_20)
32033 + {
32034 + R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
32035 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
32036 + }
32037 +#ifdef DOT11_N_SUPPORT
32038 + else
32039 + {
32040 + R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
32041 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
32042 + }
32043 +#endif // DOT11_N_SUPPORT //
32044 + }
32045 +
32046 +}
32047 +
32048 +VOID AsicTurnOffRFClk(
32049 + IN PRTMP_ADAPTER pAd,
32050 + IN UCHAR Channel)
32051 +{
32052 + // RF R2 bit 18 = 0
32053 + UINT32 R1 = 0, R2 = 0, R3 = 0;
32054 + UCHAR index;
32055 + RTMP_RF_REGS *RFRegTable;
32056 +
32057 +#ifdef RT30xx
32058 + // The RF programming sequence is difference between 3xxx and 2xxx
32059 + if (IS_RT3090(pAd))
32060 + {
32061 + RT30xxLoadRFSleepModeSetup(pAd); // add by johnli, RF power sequence setup, load RF sleep-mode setup
32062 + }
32063 + else
32064 + {
32065 +#endif // RT30xx //
32066 + RFRegTable = RF2850RegTable;
32067 +
32068 + switch (pAd->RfIcType)
32069 + {
32070 + case RFIC_2820:
32071 + case RFIC_2850:
32072 + case RFIC_2720:
32073 + case RFIC_2750:
32074 +
32075 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
32076 + {
32077 + if (Channel == RFRegTable[index].Channel)
32078 + {
32079 + R1 = RFRegTable[index].R1 & 0xffffdfff;
32080 + R2 = RFRegTable[index].R2 & 0xfffbffff;
32081 + R3 = RFRegTable[index].R3 & 0xfff3ffff;
32082 +
32083 + RTMP_RF_IO_WRITE32(pAd, R1);
32084 + RTMP_RF_IO_WRITE32(pAd, R2);
32085 +
32086 + // Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0.
32087 + // Set RF R2 bit18=0, R3 bit[18:19]=0
32088 + //if (pAd->StaCfg.bRadio == FALSE)
32089 + if (1)
32090 + {
32091 + RTMP_RF_IO_WRITE32(pAd, R3);
32092 +
32093 + DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n",
32094 + Channel, pAd->RfIcType, R2, R3));
32095 + }
32096 + else
32097 + DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n",
32098 + Channel, pAd->RfIcType, R2));
32099 + break;
32100 + }
32101 + }
32102 + break;
32103 +
32104 + default:
32105 + break;
32106 + }
32107 +#ifdef RT30xx
32108 + }
32109 +#endif // RT30xx //
32110 +
32111 +}
32112 +
32113 +
32114 +VOID AsicTurnOnRFClk(
32115 + IN PRTMP_ADAPTER pAd,
32116 + IN UCHAR Channel)
32117 +{
32118 + // RF R2 bit 18 = 0
32119 + UINT32 R1 = 0, R2 = 0, R3 = 0;
32120 + UCHAR index;
32121 + RTMP_RF_REGS *RFRegTable;
32122 +
32123 +#ifdef RT30xx
32124 + // The RF programming sequence is difference between 3xxx and 2xxx
32125 + if (IS_RT3090(pAd))
32126 + {
32127 + }
32128 + else
32129 + {
32130 +#endif // RT30xx //
32131 + RFRegTable = RF2850RegTable;
32132 +
32133 + switch (pAd->RfIcType)
32134 + {
32135 + case RFIC_2820:
32136 + case RFIC_2850:
32137 + case RFIC_2720:
32138 + case RFIC_2750:
32139 +
32140 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
32141 + {
32142 + if (Channel == RFRegTable[index].Channel)
32143 + {
32144 + R3 = pAd->LatchRfRegs.R3;
32145 + R3 &= 0xfff3ffff;
32146 + R3 |= 0x00080000;
32147 + RTMP_RF_IO_WRITE32(pAd, R3);
32148 +
32149 + R1 = RFRegTable[index].R1;
32150 + RTMP_RF_IO_WRITE32(pAd, R1);
32151 +
32152 + R2 = RFRegTable[index].R2;
32153 + if (pAd->Antenna.field.TxPath == 1)
32154 + {
32155 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
32156 + }
32157 +
32158 + if (pAd->Antenna.field.RxPath == 2)
32159 + {
32160 + R2 |= 0x40; // write 1 to off Rxpath.
32161 + }
32162 + else if (pAd->Antenna.field.RxPath == 1)
32163 + {
32164 + R2 |= 0x20040; // write 1 to off RxPath
32165 + }
32166 + RTMP_RF_IO_WRITE32(pAd, R2);
32167 +
32168 + break;
32169 + }
32170 + }
32171 + break;
32172 +
32173 + default:
32174 + break;
32175 + }
32176 +
32177 +#ifdef RT30xx
32178 + }
32179 +#endif // RT30xx //
32180 +
32181 +}
32182 +
32183 --- /dev/null
32184 +++ b/drivers/staging/rt3070/common/netif_block.c
32185 @@ -0,0 +1,136 @@
32186 +/*
32187 + *************************************************************************
32188 + * Ralink Tech Inc.
32189 + * 5F., No.36, Taiyuan St., Jhubei City,
32190 + * Hsinchu County 302,
32191 + * Taiwan, R.O.C.
32192 + *
32193 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
32194 + *
32195 + * This program is free software; you can redistribute it and/or modify *
32196 + * it under the terms of the GNU General Public License as published by *
32197 + * the Free Software Foundation; either version 2 of the License, or *
32198 + * (at your option) any later version. *
32199 + * *
32200 + * This program is distributed in the hope that it will be useful, *
32201 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
32202 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32203 + * GNU General Public License for more details. *
32204 + * *
32205 + * You should have received a copy of the GNU General Public License *
32206 + * along with this program; if not, write to the *
32207 + * Free Software Foundation, Inc., *
32208 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
32209 + * *
32210 + *************************************************************************
32211 + */
32212 +
32213 +#include "../rt_config.h"
32214 +#include "netif_block.h"
32215 +
32216 +static NETIF_ENTRY freeNetIfEntryPool[FREE_NETIF_POOL_SIZE];
32217 +static LIST_HEADER freeNetIfEntryList;
32218 +
32219 +void initblockQueueTab(
32220 + IN PRTMP_ADAPTER pAd)
32221 +{
32222 + int i;
32223 +
32224 + initList(&freeNetIfEntryList);
32225 + for (i = 0; i < FREE_NETIF_POOL_SIZE; i++)
32226 + insertTailList(&freeNetIfEntryList, (PLIST_ENTRY)&freeNetIfEntryPool[i]);
32227 +
32228 + for (i=0; i < NUM_OF_TX_RING; i++)
32229 + initList(&pAd->blockQueueTab[i].NetIfList);
32230 +
32231 + return;
32232 +}
32233 +
32234 +BOOLEAN blockNetIf(
32235 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry,
32236 + IN PNET_DEV pNetDev)
32237 +{
32238 + PNETIF_ENTRY pNetIfEntry = NULL;
32239 +
32240 + if ((pNetIfEntry = (PNETIF_ENTRY)removeHeadList(&freeNetIfEntryList)) != NULL)
32241 + {
32242 + netif_stop_queue(pNetDev);
32243 + pNetIfEntry->pNetDev = pNetDev;
32244 + insertTailList(&pBlockQueueEntry->NetIfList, (PLIST_ENTRY)pNetIfEntry);
32245 +
32246 + pBlockQueueEntry->SwTxQueueBlockFlag = TRUE;
32247 + DBGPRINT(RT_DEBUG_TRACE, ("netif_stop_queue(%s)\n", pNetDev->name));
32248 + }
32249 + else
32250 + return FALSE;
32251 +
32252 + return TRUE;
32253 +}
32254 +
32255 +VOID releaseNetIf(
32256 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry)
32257 +{
32258 + PNETIF_ENTRY pNetIfEntry = NULL;
32259 + PLIST_HEADER pNetIfList = &pBlockQueueEntry->NetIfList;
32260 +
32261 + while((pNetIfEntry = (PNETIF_ENTRY)removeHeadList(pNetIfList)) != NULL)
32262 + {
32263 + PNET_DEV pNetDev = pNetIfEntry->pNetDev;
32264 + netif_wake_queue(pNetDev);
32265 + insertTailList(&freeNetIfEntryList, (PLIST_ENTRY)pNetIfEntry);
32266 +
32267 + DBGPRINT(RT_DEBUG_TRACE, ("netif_wake_queue(%s)\n", pNetDev->name));
32268 + }
32269 + pBlockQueueEntry->SwTxQueueBlockFlag = FALSE;
32270 + return;
32271 +}
32272 +
32273 +
32274 +VOID StopNetIfQueue(
32275 + IN PRTMP_ADAPTER pAd,
32276 + IN UCHAR QueIdx,
32277 + IN PNDIS_PACKET pPacket)
32278 +{
32279 + PNET_DEV NetDev = NULL;
32280 + UCHAR IfIdx = 0;
32281 + BOOLEAN valid = FALSE;
32282 +
32283 +#ifdef WDS_SUPPORT
32284 + if (RTMP_GET_PACKET_NET_DEVICE(pPacket) >= MIN_NET_DEVICE_FOR_WDS)
32285 + {
32286 + IfIdx = (RTMP_GET_PACKET_NET_DEVICE(pPacket) - MIN_NET_DEVICE_FOR_WDS) % MAX_WDS_ENTRY;
32287 + NetDev = pAd->WdsTab.WdsEntry[IfIdx].dev;
32288 + }
32289 + else
32290 +#endif // WDS_SUPPORT //
32291 + {
32292 +#ifdef MBSS_SUPPORT
32293 + if (pAd->OpMode == OPMODE_AP)
32294 + {
32295 + IfIdx = (RTMP_GET_PACKET_NET_DEVICE(pPacket) - MIN_NET_DEVICE_FOR_MBSSID) % MAX_MBSSID_NUM;
32296 + NetDev = pAd->ApCfg.MBSSID[IfIdx].MSSIDDev;
32297 + }
32298 + else
32299 + {
32300 + IfIdx = MAIN_MBSSID;
32301 + NetDev = pAd->net_dev;
32302 + }
32303 +#else
32304 + IfIdx = MAIN_MBSSID;
32305 + NetDev = pAd->net_dev;
32306 +#endif
32307 + }
32308 +
32309 + // WMM support 4 software queues.
32310 + // One software queue full doesn't mean device have no capbility to transmit packet.
32311 + // So disable block Net-If queue function while WMM enable.
32312 +#ifdef CONFIG_STA_SUPPORT
32313 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
32314 + valid = (pAd->CommonCfg.bWmmCapable == TRUE) ? FALSE : TRUE;
32315 +#endif // CONFIG_STA_SUPPORT //
32316 +
32317 + if (valid)
32318 + blockNetIf(&pAd->blockQueueTab[QueIdx], NetDev);
32319 + return;
32320 +}
32321 +
32322 --- /dev/null
32323 +++ b/drivers/staging/rt3070/common/rtmp_init.c
32324 @@ -0,0 +1,4197 @@
32325 +/*
32326 + *************************************************************************
32327 + * Ralink Tech Inc.
32328 + * 5F., No.36, Taiyuan St., Jhubei City,
32329 + * Hsinchu County 302,
32330 + * Taiwan, R.O.C.
32331 + *
32332 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
32333 + *
32334 + * This program is free software; you can redistribute it and/or modify *
32335 + * it under the terms of the GNU General Public License as published by *
32336 + * the Free Software Foundation; either version 2 of the License, or *
32337 + * (at your option) any later version. *
32338 + * *
32339 + * This program is distributed in the hope that it will be useful, *
32340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
32341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32342 + * GNU General Public License for more details. *
32343 + * *
32344 + * You should have received a copy of the GNU General Public License *
32345 + * along with this program; if not, write to the *
32346 + * Free Software Foundation, Inc., *
32347 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
32348 + * *
32349 + *************************************************************************
32350 +
32351 + Module Name:
32352 + rtmp_init.c
32353 +
32354 + Abstract:
32355 + Miniport generic portion header file
32356 +
32357 + Revision History:
32358 + Who When What
32359 + -------- ---------- ----------------------------------------------
32360 + Paul Lin 2002-08-01 created
32361 + John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme
32362 + Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT.
32363 +*/
32364 +#include "../rt_config.h"
32365 +#include "../firmware.h"
32366 +
32367 +//#define BIN_IN_FILE /* use *.bin firmware */
32368 +
32369 +UCHAR BIT8[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
32370 +ULONG BIT32[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008,
32371 + 0x00000010, 0x00000020, 0x00000040, 0x00000080,
32372 + 0x00000100, 0x00000200, 0x00000400, 0x00000800,
32373 + 0x00001000, 0x00002000, 0x00004000, 0x00008000,
32374 + 0x00010000, 0x00020000, 0x00040000, 0x00080000,
32375 + 0x00100000, 0x00200000, 0x00400000, 0x00800000,
32376 + 0x01000000, 0x02000000, 0x04000000, 0x08000000,
32377 + 0x10000000, 0x20000000, 0x40000000, 0x80000000};
32378 +
32379 +char* CipherName[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"};
32380 +
32381 +const unsigned short ccitt_16Table[] = {
32382 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
32383 + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
32384 + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
32385 + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
32386 + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
32387 + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
32388 + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
32389 + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
32390 + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
32391 + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
32392 + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
32393 + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
32394 + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
32395 + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
32396 + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
32397 + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
32398 + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
32399 + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
32400 + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
32401 + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
32402 + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
32403 + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
32404 + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
32405 + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
32406 + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
32407 + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
32408 + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
32409 + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
32410 + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
32411 + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
32412 + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
32413 + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
32414 +};
32415 +#define ByteCRC16(v, crc) \
32416 + (unsigned short)((crc << 8) ^ ccitt_16Table[((crc >> 8) ^ (v)) & 255])
32417 +
32418 +unsigned char BitReverse(unsigned char x)
32419 +{
32420 + int i;
32421 + unsigned char Temp=0;
32422 + for(i=0; ; i++)
32423 + {
32424 + if(x & 0x80) Temp |= 0x80;
32425 + if(i==7) break;
32426 + x <<= 1;
32427 + Temp >>= 1;
32428 + }
32429 + return Temp;
32430 +}
32431 +
32432 +//
32433 +// BBP register initialization set
32434 +//
32435 +REG_PAIR BBPRegTable[] = {
32436 + {BBP_R65, 0x2C}, // fix rssi issue
32437 + {BBP_R66, 0x38}, // Also set this default value to pAd->BbpTuning.R66CurrentValue at initial
32438 + {BBP_R69, 0x12},
32439 + {BBP_R70, 0xa}, // BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa
32440 + {BBP_R73, 0x10},
32441 + {BBP_R81, 0x37},
32442 + {BBP_R82, 0x62},
32443 + {BBP_R83, 0x6A},
32444 + {BBP_R84, 0x99}, // 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before
32445 + {BBP_R86, 0x00}, // middle range issue, Rory @2008-01-28
32446 + {BBP_R91, 0x04}, // middle range issue, Rory @2008-01-28
32447 + {BBP_R92, 0x00}, // middle range issue, Rory @2008-01-28
32448 + {BBP_R103, 0x00}, // near range high-power issue, requested from Gary @2008-0528
32449 + {BBP_R105, 0x05}, // 0x05 is for rt2860E to turn on FEQ control. It is safe for rt2860D and before, because Bit 7:2 are reserved in rt2860D and before.
32450 +};
32451 +#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(REG_PAIR))
32452 +
32453 +//
32454 +// RF register initialization set
32455 +//
32456 +#ifdef RT30xx
32457 +REG_PAIR RT30xx_RFRegTable[] = {
32458 + {RF_R04, 0x40},
32459 + {RF_R05, 0x03},
32460 + {RF_R06, 0x02},
32461 + {RF_R07, 0x70},
32462 + {RF_R09, 0x0F},
32463 + {RF_R10, 0x41},
32464 + {RF_R11, 0x21},
32465 + {RF_R12, 0x7B},
32466 + {RF_R14, 0x90},
32467 + {RF_R15, 0x58},
32468 + {RF_R16, 0xB3},
32469 + {RF_R17, 0x92},
32470 + {RF_R18, 0x2C},
32471 + {RF_R19, 0x02},
32472 + {RF_R20, 0xBA},
32473 + {RF_R21, 0xDB},
32474 + {RF_R24, 0x16},
32475 + {RF_R25, 0x01},
32476 + {RF_R29, 0x1F},
32477 +};
32478 +#define NUM_RF_REG_PARMS (sizeof(RT30xx_RFRegTable) / sizeof(REG_PAIR))
32479 +#endif // RT30xx //
32480 +
32481 +//
32482 +// ASIC register initialization sets
32483 +//
32484 +
32485 +RTMP_REG_PAIR MACRegTable[] = {
32486 +#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)
32487 + {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */
32488 + {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */
32489 +#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)
32490 + {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
32491 + {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
32492 +#else
32493 + #error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!!!
32494 +#endif // HW_BEACON_OFFSET //
32495 +
32496 + {LEGACY_BASIC_RATE, 0x0000013f}, // Basic rate set bitmap
32497 + {HT_BASIC_RATE, 0x00008003}, // Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI.
32498 + {MAC_SYS_CTRL, 0x00}, // 0x1004, , default Disable RX
32499 + {RX_FILTR_CFG, 0x17f97}, //0x1400 , RX filter control,
32500 + {BKOFF_SLOT_CFG, 0x209}, // default set short slot time, CC_DELAY_TIME should be 2
32501 + //{TX_SW_CFG0, 0x40a06}, // Gary,2006-08-23
32502 + {TX_SW_CFG0, 0x0}, // Gary,2008-05-21 for CWC test
32503 + {TX_SW_CFG1, 0x80606}, // Gary,2006-08-23
32504 + {TX_LINK_CFG, 0x1020}, // Gary,2006-08-23
32505 + {TX_TIMEOUT_CFG, 0x000a2090},
32506 + {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, // 0x3018, MAX frame length. Max PSDU = 16kbytes.
32507 + {LED_CFG, 0x7f031e46}, // Gary, 2006-08-23
32508 +
32509 +//#ifdef CONFIG_STA_SUPPORT
32510 +// {WMM_AIFSN_CFG, 0x00002273},
32511 +// {WMM_CWMIN_CFG, 0x00002344},
32512 +// {WMM_CWMAX_CFG, 0x000034aa},
32513 +//#endif // CONFIG_STA_SUPPORT //
32514 +#ifdef INF_AMAZON_SE
32515 + {PBF_MAX_PCNT, 0x1F3F6F6F}, //iverson modify for usb issue, 2008/09/19
32516 + // 6F + 6F < total page count FE
32517 + // so that RX doesn't occupy TX's buffer space when WMM congestion.
32518 +#else
32519 + {PBF_MAX_PCNT, 0x1F3FBF9F}, //0x1F3f7f9f}, //Jan, 2006/04/20
32520 +#endif // INF_AMAZON_SE //
32521 + //{TX_RTY_CFG, 0x6bb80408}, // Jan, 2006/11/16
32522 + {TX_RTY_CFG, 0x47d01f0f}, // Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03
32523 + {AUTO_RSP_CFG, 0x00000013}, // Initial Auto_Responder, because QA will turn off Auto-Responder
32524 + {CCK_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
32525 + {OFDM_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
32526 +//PS packets use Tx1Q (for HCCA) when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
32527 +#ifdef RT2870
32528 +#ifdef CONFIG_STA_SUPPORT
32529 + {PBF_CFG, 0xf40006}, // Only enable Queue 2
32530 +#endif // CONFIG_STA_SUPPORT //
32531 + {MM40_PROT_CFG, 0x3F44084}, // Initial Auto_Responder, because QA will turn off Auto-Responder
32532 + {WPDMA_GLO_CFG, 0x00000030},
32533 +#endif // RT2870 //
32534 + {GF20_PROT_CFG, 0x01744004}, // set 19:18 --> Short NAV for MIMO PS
32535 + {GF40_PROT_CFG, 0x03F44084},
32536 + {MM20_PROT_CFG, 0x01744004},
32537 + {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f*/ /*0x000024bf*/}, //Extension channel backoff.
32538 + {TX_RTS_CFG, 0x00092b20},
32539 +//#ifdef WIFI_TEST
32540 + {EXP_ACK_TIME, 0x002400ca}, // default value
32541 +//#else
32542 +// {EXP_ACK_TIME, 0x005400ca}, // suggested by Gray @ 20070323 for 11n intel-sta throughput
32543 +//#endif // end - WIFI_TEST //
32544 + {TXOP_HLDR_ET, 0x00000002},
32545 +
32546 + /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us
32547 + is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0
32548 + and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping
32549 + will always lost. So we change the SIFS of CCK from 10us to 16us. */
32550 + {XIFS_TIME_CFG, 0x33a41010},
32551 + {PWR_PIN_CFG, 0x00000003}, // patch for 2880-E
32552 +};
32553 +
32554 +
32555 +#ifdef CONFIG_STA_SUPPORT
32556 +RTMP_REG_PAIR STAMACRegTable[] = {
32557 + {WMM_AIFSN_CFG, 0x00002273},
32558 + {WMM_CWMIN_CFG, 0x00002344},
32559 + {WMM_CWMAX_CFG, 0x000034aa},
32560 +};
32561 +#endif // CONFIG_STA_SUPPORT //
32562 +
32563 +#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))
32564 +#ifdef CONFIG_STA_SUPPORT
32565 +#define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(RTMP_REG_PAIR))
32566 +#endif // CONFIG_STA_SUPPORT //
32567 +
32568 +#ifdef RT2870
32569 +//
32570 +// RT2870 Firmware Spec only used 1 oct for version expression
32571 +//
32572 +#define FIRMWARE_MINOR_VERSION 7
32573 +
32574 +#endif // RT2870 //
32575 +
32576 +// New 8k byte firmware size for RT3071/RT3072
32577 +#define FIRMWAREIMAGE_MAX_LENGTH 0x2000
32578 +#define FIRMWAREIMAGE_LENGTH (sizeof (FirmwareImage) / sizeof(UCHAR))
32579 +#define FIRMWARE_MAJOR_VERSION 0
32580 +
32581 +#define FIRMWAREIMAGEV1_LENGTH 0x1000
32582 +#define FIRMWAREIMAGEV2_LENGTH 0x1000
32583 +
32584 +
32585 +
32586 +/*
32587 + ========================================================================
32588 +
32589 + Routine Description:
32590 + Allocate RTMP_ADAPTER data block and do some initialization
32591 +
32592 + Arguments:
32593 + Adapter Pointer to our adapter
32594 +
32595 + Return Value:
32596 + NDIS_STATUS_SUCCESS
32597 + NDIS_STATUS_FAILURE
32598 +
32599 + IRQL = PASSIVE_LEVEL
32600 +
32601 + Note:
32602 +
32603 + ========================================================================
32604 +*/
32605 +NDIS_STATUS RTMPAllocAdapterBlock(
32606 + IN PVOID handle,
32607 + OUT PRTMP_ADAPTER *ppAdapter)
32608 +{
32609 + PRTMP_ADAPTER pAd;
32610 + NDIS_STATUS Status;
32611 + INT index;
32612 + UCHAR *pBeaconBuf = NULL;
32613 +
32614 + DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n"));
32615 +
32616 + *ppAdapter = NULL;
32617 +
32618 + do
32619 + {
32620 + // Allocate RTMP_ADAPTER memory block
32621 + pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG);
32622 + if (pBeaconBuf == NULL)
32623 + {
32624 + Status = NDIS_STATUS_FAILURE;
32625 + DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n"));
32626 + break;
32627 + }
32628 +
32629 + Status = AdapterBlockAllocateMemory(handle, (PVOID *)&pAd);
32630 + if (Status != NDIS_STATUS_SUCCESS)
32631 + {
32632 + DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n"));
32633 + break;
32634 + }
32635 + pAd->BeaconBuf = pBeaconBuf;
32636 + printk("\n\n=== pAd = %p, size = %d ===\n\n", pAd, (UINT32)sizeof(RTMP_ADAPTER));
32637 +
32638 +
32639 + // Init spin locks
32640 + NdisAllocateSpinLock(&pAd->MgmtRingLock);
32641 +
32642 + for (index =0 ; index < NUM_OF_TX_RING; index++)
32643 + {
32644 + NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]);
32645 + NdisAllocateSpinLock(&pAd->DeQueueLock[index]);
32646 + pAd->DeQueueRunning[index] = FALSE;
32647 + }
32648 +
32649 + NdisAllocateSpinLock(&pAd->irq_lock);
32650 +
32651 + } while (FALSE);
32652 +
32653 + if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf))
32654 + kfree(pBeaconBuf);
32655 +
32656 + *ppAdapter = pAd;
32657 +
32658 + DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status));
32659 + return Status;
32660 +}
32661 +
32662 +/*
32663 + ========================================================================
32664 +
32665 + Routine Description:
32666 + Read initial Tx power per MCS and BW from EEPROM
32667 +
32668 + Arguments:
32669 + Adapter Pointer to our adapter
32670 +
32671 + Return Value:
32672 + None
32673 +
32674 + IRQL = PASSIVE_LEVEL
32675 +
32676 + Note:
32677 +
32678 + ========================================================================
32679 +*/
32680 +VOID RTMPReadTxPwrPerRate(
32681 + IN PRTMP_ADAPTER pAd)
32682 +{
32683 + ULONG data, Adata, Gdata;
32684 + USHORT i, value, value2;
32685 + INT Apwrdelta, Gpwrdelta;
32686 + UCHAR t1,t2,t3,t4;
32687 + BOOLEAN bValid, bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE;
32688 +
32689 + //
32690 + // Get power delta for 20MHz and 40MHz.
32691 + //
32692 + DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n"));
32693 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2);
32694 + Apwrdelta = 0;
32695 + Gpwrdelta = 0;
32696 +
32697 + if ((value2 & 0xff) != 0xff)
32698 + {
32699 + if ((value2 & 0x80))
32700 + Gpwrdelta = (value2&0xf);
32701 +
32702 + if ((value2 & 0x40))
32703 + bGpwrdeltaMinus = FALSE;
32704 + else
32705 + bGpwrdeltaMinus = TRUE;
32706 + }
32707 + if ((value2 & 0xff00) != 0xff00)
32708 + {
32709 + if ((value2 & 0x8000))
32710 + Apwrdelta = ((value2&0xf00)>>8);
32711 +
32712 + if ((value2 & 0x4000))
32713 + bApwrdeltaMinus = FALSE;
32714 + else
32715 + bApwrdeltaMinus = TRUE;
32716 + }
32717 + DBGPRINT(RT_DEBUG_TRACE, ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta));
32718 +
32719 + //
32720 + // Get Txpower per MCS for 20MHz in 2.4G.
32721 + //
32722 + for (i=0; i<5; i++)
32723 + {
32724 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4, value);
32725 + data = value;
32726 + if (bApwrdeltaMinus == FALSE)
32727 + {
32728 + t1 = (value&0xf)+(Apwrdelta);
32729 + if (t1 > 0xf)
32730 + t1 = 0xf;
32731 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32732 + if (t2 > 0xf)
32733 + t2 = 0xf;
32734 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32735 + if (t3 > 0xf)
32736 + t3 = 0xf;
32737 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32738 + if (t4 > 0xf)
32739 + t4 = 0xf;
32740 + }
32741 + else
32742 + {
32743 + if ((value&0xf) > Apwrdelta)
32744 + t1 = (value&0xf)-(Apwrdelta);
32745 + else
32746 + t1 = 0;
32747 + if (((value&0xf0)>>4) > Apwrdelta)
32748 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32749 + else
32750 + t2 = 0;
32751 + if (((value&0xf00)>>8) > Apwrdelta)
32752 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32753 + else
32754 + t3 = 0;
32755 + if (((value&0xf000)>>12) > Apwrdelta)
32756 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32757 + else
32758 + t4 = 0;
32759 + }
32760 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32761 + if (bGpwrdeltaMinus == FALSE)
32762 + {
32763 + t1 = (value&0xf)+(Gpwrdelta);
32764 + if (t1 > 0xf)
32765 + t1 = 0xf;
32766 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32767 + if (t2 > 0xf)
32768 + t2 = 0xf;
32769 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32770 + if (t3 > 0xf)
32771 + t3 = 0xf;
32772 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32773 + if (t4 > 0xf)
32774 + t4 = 0xf;
32775 + }
32776 + else
32777 + {
32778 + if ((value&0xf) > Gpwrdelta)
32779 + t1 = (value&0xf)-(Gpwrdelta);
32780 + else
32781 + t1 = 0;
32782 + if (((value&0xf0)>>4) > Gpwrdelta)
32783 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32784 + else
32785 + t2 = 0;
32786 + if (((value&0xf00)>>8) > Gpwrdelta)
32787 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32788 + else
32789 + t3 = 0;
32790 + if (((value&0xf000)>>12) > Gpwrdelta)
32791 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32792 + else
32793 + t4 = 0;
32794 + }
32795 + Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32796 +
32797 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4 + 2, value);
32798 + if (bApwrdeltaMinus == FALSE)
32799 + {
32800 + t1 = (value&0xf)+(Apwrdelta);
32801 + if (t1 > 0xf)
32802 + t1 = 0xf;
32803 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
32804 + if (t2 > 0xf)
32805 + t2 = 0xf;
32806 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
32807 + if (t3 > 0xf)
32808 + t3 = 0xf;
32809 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
32810 + if (t4 > 0xf)
32811 + t4 = 0xf;
32812 + }
32813 + else
32814 + {
32815 + if ((value&0xf) > Apwrdelta)
32816 + t1 = (value&0xf)-(Apwrdelta);
32817 + else
32818 + t1 = 0;
32819 + if (((value&0xf0)>>4) > Apwrdelta)
32820 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
32821 + else
32822 + t2 = 0;
32823 + if (((value&0xf00)>>8) > Apwrdelta)
32824 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
32825 + else
32826 + t3 = 0;
32827 + if (((value&0xf000)>>12) > Apwrdelta)
32828 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
32829 + else
32830 + t4 = 0;
32831 + }
32832 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32833 + if (bGpwrdeltaMinus == FALSE)
32834 + {
32835 + t1 = (value&0xf)+(Gpwrdelta);
32836 + if (t1 > 0xf)
32837 + t1 = 0xf;
32838 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32839 + if (t2 > 0xf)
32840 + t2 = 0xf;
32841 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32842 + if (t3 > 0xf)
32843 + t3 = 0xf;
32844 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32845 + if (t4 > 0xf)
32846 + t4 = 0xf;
32847 + }
32848 + else
32849 + {
32850 + if ((value&0xf) > Gpwrdelta)
32851 + t1 = (value&0xf)-(Gpwrdelta);
32852 + else
32853 + t1 = 0;
32854 + if (((value&0xf0)>>4) > Gpwrdelta)
32855 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32856 + else
32857 + t2 = 0;
32858 + if (((value&0xf00)>>8) > Gpwrdelta)
32859 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32860 + else
32861 + t3 = 0;
32862 + if (((value&0xf000)>>12) > Gpwrdelta)
32863 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32864 + else
32865 + t4 = 0;
32866 + }
32867 + Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32868 + data |= (value<<16);
32869 +
32870 + pAd->Tx20MPwrCfgABand[i] = pAd->Tx40MPwrCfgABand[i] = Adata;
32871 + pAd->Tx20MPwrCfgGBand[i] = pAd->Tx40MPwrCfgGBand[i] = Gdata;
32872 +
32873 + if (data != 0xffffffff)
32874 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, data);
32875 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n", data, Adata, Gdata));
32876 + }
32877 +
32878 + //
32879 + // Check this block is valid for 40MHz in 2.4G. If invalid, use parameter for 20MHz in 2.4G
32880 + //
32881 + bValid = TRUE;
32882 + for (i=0; i<6; i++)
32883 + {
32884 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + 2 + i*2, value);
32885 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
32886 + {
32887 + bValid = FALSE;
32888 + break;
32889 + }
32890 + }
32891 +
32892 + //
32893 + // Get Txpower per MCS for 40MHz in 2.4G.
32894 + //
32895 + if (bValid)
32896 + {
32897 + for (i=0; i<4; i++)
32898 + {
32899 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4, value);
32900 + if (bGpwrdeltaMinus == FALSE)
32901 + {
32902 + t1 = (value&0xf)+(Gpwrdelta);
32903 + if (t1 > 0xf)
32904 + t1 = 0xf;
32905 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32906 + if (t2 > 0xf)
32907 + t2 = 0xf;
32908 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32909 + if (t3 > 0xf)
32910 + t3 = 0xf;
32911 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32912 + if (t4 > 0xf)
32913 + t4 = 0xf;
32914 + }
32915 + else
32916 + {
32917 + if ((value&0xf) > Gpwrdelta)
32918 + t1 = (value&0xf)-(Gpwrdelta);
32919 + else
32920 + t1 = 0;
32921 + if (((value&0xf0)>>4) > Gpwrdelta)
32922 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32923 + else
32924 + t2 = 0;
32925 + if (((value&0xf00)>>8) > Gpwrdelta)
32926 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32927 + else
32928 + t3 = 0;
32929 + if (((value&0xf000)>>12) > Gpwrdelta)
32930 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32931 + else
32932 + t4 = 0;
32933 + }
32934 + Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
32935 +
32936 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4 + 2, value);
32937 + if (bGpwrdeltaMinus == FALSE)
32938 + {
32939 + t1 = (value&0xf)+(Gpwrdelta);
32940 + if (t1 > 0xf)
32941 + t1 = 0xf;
32942 + t2 = ((value&0xf0)>>4)+(Gpwrdelta);
32943 + if (t2 > 0xf)
32944 + t2 = 0xf;
32945 + t3 = ((value&0xf00)>>8)+(Gpwrdelta);
32946 + if (t3 > 0xf)
32947 + t3 = 0xf;
32948 + t4 = ((value&0xf000)>>12)+(Gpwrdelta);
32949 + if (t4 > 0xf)
32950 + t4 = 0xf;
32951 + }
32952 + else
32953 + {
32954 + if ((value&0xf) > Gpwrdelta)
32955 + t1 = (value&0xf)-(Gpwrdelta);
32956 + else
32957 + t1 = 0;
32958 + if (((value&0xf0)>>4) > Gpwrdelta)
32959 + t2 = ((value&0xf0)>>4)-(Gpwrdelta);
32960 + else
32961 + t2 = 0;
32962 + if (((value&0xf00)>>8) > Gpwrdelta)
32963 + t3 = ((value&0xf00)>>8)-(Gpwrdelta);
32964 + else
32965 + t3 = 0;
32966 + if (((value&0xf000)>>12) > Gpwrdelta)
32967 + t4 = ((value&0xf000)>>12)-(Gpwrdelta);
32968 + else
32969 + t4 = 0;
32970 + }
32971 + Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
32972 +
32973 + if (i == 0)
32974 + pAd->Tx40MPwrCfgGBand[i+1] = (pAd->Tx40MPwrCfgGBand[i+1] & 0x0000FFFF) | (Gdata & 0xFFFF0000);
32975 + else
32976 + pAd->Tx40MPwrCfgGBand[i+1] = Gdata;
32977 +
32978 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 2.4G band, Gdata = %lx \n", Gdata));
32979 + }
32980 + }
32981 +
32982 + //
32983 + // Check this block is valid for 20MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
32984 + //
32985 + bValid = TRUE;
32986 + for (i=0; i<8; i++)
32987 + {
32988 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + 2 + i*2, value);
32989 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
32990 + {
32991 + bValid = FALSE;
32992 + break;
32993 + }
32994 + }
32995 +
32996 + //
32997 + // Get Txpower per MCS for 20MHz in 5G.
32998 + //
32999 + if (bValid)
33000 + {
33001 + for (i=0; i<5; i++)
33002 + {
33003 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4, value);
33004 + if (bApwrdeltaMinus == FALSE)
33005 + {
33006 + t1 = (value&0xf)+(Apwrdelta);
33007 + if (t1 > 0xf)
33008 + t1 = 0xf;
33009 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
33010 + if (t2 > 0xf)
33011 + t2 = 0xf;
33012 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
33013 + if (t3 > 0xf)
33014 + t3 = 0xf;
33015 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
33016 + if (t4 > 0xf)
33017 + t4 = 0xf;
33018 + }
33019 + else
33020 + {
33021 + if ((value&0xf) > Apwrdelta)
33022 + t1 = (value&0xf)-(Apwrdelta);
33023 + else
33024 + t1 = 0;
33025 + if (((value&0xf0)>>4) > Apwrdelta)
33026 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
33027 + else
33028 + t2 = 0;
33029 + if (((value&0xf00)>>8) > Apwrdelta)
33030 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
33031 + else
33032 + t3 = 0;
33033 + if (((value&0xf000)>>12) > Apwrdelta)
33034 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
33035 + else
33036 + t4 = 0;
33037 + }
33038 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
33039 +
33040 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4 + 2, value);
33041 + if (bApwrdeltaMinus == FALSE)
33042 + {
33043 + t1 = (value&0xf)+(Apwrdelta);
33044 + if (t1 > 0xf)
33045 + t1 = 0xf;
33046 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
33047 + if (t2 > 0xf)
33048 + t2 = 0xf;
33049 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
33050 + if (t3 > 0xf)
33051 + t3 = 0xf;
33052 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
33053 + if (t4 > 0xf)
33054 + t4 = 0xf;
33055 + }
33056 + else
33057 + {
33058 + if ((value&0xf) > Apwrdelta)
33059 + t1 = (value&0xf)-(Apwrdelta);
33060 + else
33061 + t1 = 0;
33062 + if (((value&0xf0)>>4) > Apwrdelta)
33063 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
33064 + else
33065 + t2 = 0;
33066 + if (((value&0xf00)>>8) > Apwrdelta)
33067 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
33068 + else
33069 + t3 = 0;
33070 + if (((value&0xf000)>>12) > Apwrdelta)
33071 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
33072 + else
33073 + t4 = 0;
33074 + }
33075 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
33076 +
33077 + if (i == 0)
33078 + pAd->Tx20MPwrCfgABand[i] = (pAd->Tx20MPwrCfgABand[i] & 0x0000FFFF) | (Adata & 0xFFFF0000);
33079 + else
33080 + pAd->Tx20MPwrCfgABand[i] = Adata;
33081 +
33082 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 5GHz band, Adata = %lx \n", Adata));
33083 + }
33084 + }
33085 +
33086 + //
33087 + // Check this block is valid for 40MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
33088 + //
33089 + bValid = TRUE;
33090 + for (i=0; i<6; i++)
33091 + {
33092 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + 2 + i*2, value);
33093 + if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00))
33094 + {
33095 + bValid = FALSE;
33096 + break;
33097 + }
33098 + }
33099 +
33100 + //
33101 + // Get Txpower per MCS for 40MHz in 5G.
33102 + //
33103 + if (bValid)
33104 + {
33105 + for (i=0; i<4; i++)
33106 + {
33107 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4, value);
33108 + if (bApwrdeltaMinus == FALSE)
33109 + {
33110 + t1 = (value&0xf)+(Apwrdelta);
33111 + if (t1 > 0xf)
33112 + t1 = 0xf;
33113 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
33114 + if (t2 > 0xf)
33115 + t2 = 0xf;
33116 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
33117 + if (t3 > 0xf)
33118 + t3 = 0xf;
33119 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
33120 + if (t4 > 0xf)
33121 + t4 = 0xf;
33122 + }
33123 + else
33124 + {
33125 + if ((value&0xf) > Apwrdelta)
33126 + t1 = (value&0xf)-(Apwrdelta);
33127 + else
33128 + t1 = 0;
33129 + if (((value&0xf0)>>4) > Apwrdelta)
33130 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
33131 + else
33132 + t2 = 0;
33133 + if (((value&0xf00)>>8) > Apwrdelta)
33134 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
33135 + else
33136 + t3 = 0;
33137 + if (((value&0xf000)>>12) > Apwrdelta)
33138 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
33139 + else
33140 + t4 = 0;
33141 + }
33142 + Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12);
33143 +
33144 + RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4 + 2, value);
33145 + if (bApwrdeltaMinus == FALSE)
33146 + {
33147 + t1 = (value&0xf)+(Apwrdelta);
33148 + if (t1 > 0xf)
33149 + t1 = 0xf;
33150 + t2 = ((value&0xf0)>>4)+(Apwrdelta);
33151 + if (t2 > 0xf)
33152 + t2 = 0xf;
33153 + t3 = ((value&0xf00)>>8)+(Apwrdelta);
33154 + if (t3 > 0xf)
33155 + t3 = 0xf;
33156 + t4 = ((value&0xf000)>>12)+(Apwrdelta);
33157 + if (t4 > 0xf)
33158 + t4 = 0xf;
33159 + }
33160 + else
33161 + {
33162 + if ((value&0xf) > Apwrdelta)
33163 + t1 = (value&0xf)-(Apwrdelta);
33164 + else
33165 + t1 = 0;
33166 + if (((value&0xf0)>>4) > Apwrdelta)
33167 + t2 = ((value&0xf0)>>4)-(Apwrdelta);
33168 + else
33169 + t2 = 0;
33170 + if (((value&0xf00)>>8) > Apwrdelta)
33171 + t3 = ((value&0xf00)>>8)-(Apwrdelta);
33172 + else
33173 + t3 = 0;
33174 + if (((value&0xf000)>>12) > Apwrdelta)
33175 + t4 = ((value&0xf000)>>12)-(Apwrdelta);
33176 + else
33177 + t4 = 0;
33178 + }
33179 + Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28));
33180 +
33181 + if (i == 0)
33182 + pAd->Tx40MPwrCfgABand[i+1] = (pAd->Tx40MPwrCfgABand[i+1] & 0x0000FFFF) | (Adata & 0xFFFF0000);
33183 + else
33184 + pAd->Tx40MPwrCfgABand[i+1] = Adata;
33185 +
33186 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 5GHz band, Adata = %lx \n", Adata));
33187 + }
33188 + }
33189 +}
33190 +
33191 +
33192 +/*
33193 + ========================================================================
33194 +
33195 + Routine Description:
33196 + Read initial channel power parameters from EEPROM
33197 +
33198 + Arguments:
33199 + Adapter Pointer to our adapter
33200 +
33201 + Return Value:
33202 + None
33203 +
33204 + IRQL = PASSIVE_LEVEL
33205 +
33206 + Note:
33207 +
33208 + ========================================================================
33209 +*/
33210 +VOID RTMPReadChannelPwr(
33211 + IN PRTMP_ADAPTER pAd)
33212 +{
33213 + UCHAR i, choffset;
33214 + EEPROM_TX_PWR_STRUC Power;
33215 + EEPROM_TX_PWR_STRUC Power2;
33216 +
33217 + // Read Tx power value for all channels
33218 + // Value from 1 - 0x7f. Default value is 24.
33219 + // Power value : 2.4G 0x00 (0) ~ 0x1F (31)
33220 + // : 5.5G 0xF9 (-7) ~ 0x0F (15)
33221 +
33222 + // 0. 11b/g, ch1 - ch 14
33223 + for (i = 0; i < 7; i++)
33224 + {
33225 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2);
33226 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2);
33227 + RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2, Power.word);
33228 + RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2, Power2.word);
33229 + pAd->TxPower[i * 2].Channel = i * 2 + 1;
33230 + pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2;
33231 +
33232 + if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0))
33233 + pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER;
33234 + else
33235 + pAd->TxPower[i * 2].Power = Power.field.Byte0;
33236 +
33237 + if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0))
33238 + pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER;
33239 + else
33240 + pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1;
33241 +
33242 + if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0))
33243 + pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER;
33244 + else
33245 + pAd->TxPower[i * 2].Power2 = Power2.field.Byte0;
33246 +
33247 + if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0))
33248 + pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER;
33249 + else
33250 + pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1;
33251 + }
33252 +
33253 + // 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz)
33254 + // 1.1 Fill up channel
33255 + choffset = 14;
33256 + for (i = 0; i < 4; i++)
33257 + {
33258 + pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0;
33259 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
33260 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
33261 +
33262 + pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2;
33263 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
33264 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
33265 +
33266 + pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4;
33267 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
33268 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
33269 + }
33270 +
33271 + // 1.2 Fill up power
33272 + for (i = 0; i < 6; i++)
33273 + {
33274 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2);
33275 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2);
33276 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2, Power.word);
33277 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2, Power2.word);
33278 +
33279 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
33280 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
33281 +
33282 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
33283 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
33284 +
33285 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
33286 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
33287 +
33288 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
33289 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
33290 + }
33291 +
33292 + // 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz)
33293 + // 2.1 Fill up channel
33294 + choffset = 14 + 12;
33295 + for (i = 0; i < 5; i++)
33296 + {
33297 + pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0;
33298 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
33299 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
33300 +
33301 + pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2;
33302 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
33303 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
33304 +
33305 + pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4;
33306 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
33307 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
33308 + }
33309 + pAd->TxPower[3 * 5 + choffset + 0].Channel = 140;
33310 + pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
33311 + pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
33312 +
33313 + // 2.2 Fill up power
33314 + for (i = 0; i < 8; i++)
33315 + {
33316 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);
33317 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);
33318 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word);
33319 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word);
33320 +
33321 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
33322 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
33323 +
33324 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
33325 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
33326 +
33327 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
33328 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
33329 +
33330 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
33331 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
33332 + }
33333 +
33334 + // 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165 (including central frequency in BW 40MHz)
33335 + // 3.1 Fill up channel
33336 + choffset = 14 + 12 + 16;
33337 + for (i = 0; i < 2; i++)
33338 + {
33339 + pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0;
33340 + pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
33341 + pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
33342 +
33343 + pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2;
33344 + pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
33345 + pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
33346 +
33347 + pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4;
33348 + pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
33349 + pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
33350 + }
33351 + pAd->TxPower[3 * 2 + choffset + 0].Channel = 165;
33352 + pAd->TxPower[3 * 2 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
33353 + pAd->TxPower[3 * 2 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
33354 +
33355 + // 3.2 Fill up power
33356 + for (i = 0; i < 4; i++)
33357 + {
33358 +// Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);
33359 +// Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);
33360 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word);
33361 + RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word);
33362 +
33363 + if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
33364 + pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;
33365 +
33366 + if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
33367 + pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;
33368 +
33369 + if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
33370 + pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;
33371 +
33372 + if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
33373 + pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;
33374 + }
33375 +
33376 + // 4. Print and Debug
33377 + choffset = 14 + 12 + 16 + 7;
33378 +
33379 +}
33380 +
33381 +/*
33382 + ========================================================================
33383 +
33384 + Routine Description:
33385 + Read the following from the registry
33386 + 1. All the parameters
33387 + 2. NetworkAddres
33388 +
33389 + Arguments:
33390 + Adapter Pointer to our adapter
33391 + WrapperConfigurationContext For use by NdisOpenConfiguration
33392 +
33393 + Return Value:
33394 + NDIS_STATUS_SUCCESS
33395 + NDIS_STATUS_FAILURE
33396 + NDIS_STATUS_RESOURCES
33397 +
33398 + IRQL = PASSIVE_LEVEL
33399 +
33400 + Note:
33401 +
33402 + ========================================================================
33403 +*/
33404 +NDIS_STATUS NICReadRegParameters(
33405 + IN PRTMP_ADAPTER pAd,
33406 + IN NDIS_HANDLE WrapperConfigurationContext
33407 + )
33408 +{
33409 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
33410 + DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status));
33411 + return Status;
33412 +}
33413 +
33414 +
33415 +#ifdef RT30xx
33416 +/*
33417 + ========================================================================
33418 +
33419 + Routine Description:
33420 + For RF filter calibration purpose
33421 +
33422 + Arguments:
33423 + pAd Pointer to our adapter
33424 +
33425 + Return Value:
33426 + None
33427 +
33428 + IRQL = PASSIVE_LEVEL
33429 +
33430 + ========================================================================
33431 +*/
33432 +VOID RTMPFilterCalibration(
33433 + IN PRTMP_ADAPTER pAd)
33434 +{
33435 + UCHAR R55x = 0, value, FilterTarget = 0x1E, BBPValue=0;
33436 + UINT loop = 0, count = 0, loopcnt = 0, ReTry = 0;
33437 + UCHAR RF_R24_Value = 0;
33438 +
33439 + // Give bbp filter initial value
33440 + pAd->Mlme.CaliBW20RfR24 = 0x1F;
33441 + pAd->Mlme.CaliBW40RfR24 = 0x2F; //Bit[5] must be 1 for BW 40
33442 +
33443 + do
33444 + {
33445 + if (loop == 1) //BandWidth = 40 MHz
33446 + {
33447 + // Write 0x27 to RF_R24 to program filter
33448 + RF_R24_Value = 0x27;
33449 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
33450 + if (IS_RT3090(pAd))
33451 + FilterTarget = 0x15;
33452 + else
33453 + FilterTarget = 0x19;
33454 +
33455 + // when calibrate BW40, BBP mask must set to BW40.
33456 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
33457 + BBPValue&= (~0x18);
33458 + BBPValue|= (0x10);
33459 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
33460 +
33461 + // set to BW40
33462 + RT30xxReadRFRegister(pAd, RF_R31, &value);
33463 + value |= 0x20;
33464 + RT30xxWriteRFRegister(pAd, RF_R31, value);
33465 + }
33466 + else //BandWidth = 20 MHz
33467 + {
33468 + // Write 0x07 to RF_R24 to program filter
33469 + RF_R24_Value = 0x07;
33470 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
33471 + if (IS_RT3090(pAd))
33472 + FilterTarget = 0x13;
33473 + else
33474 + FilterTarget = 0x16;
33475 +
33476 + // set to BW20
33477 + RT30xxReadRFRegister(pAd, RF_R31, &value);
33478 + value &= (~0x20);
33479 + RT30xxWriteRFRegister(pAd, RF_R31, value);
33480 + }
33481 +
33482 + // Write 0x01 to RF_R22 to enable baseband loopback mode
33483 + RT30xxReadRFRegister(pAd, RF_R22, &value);
33484 + value |= 0x01;
33485 + RT30xxWriteRFRegister(pAd, RF_R22, value);
33486 +
33487 + // Write 0x00 to BBP_R24 to set power & frequency of passband test tone
33488 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0);
33489 +
33490 + do
33491 + {
33492 + // Write 0x90 to BBP_R25 to transmit test tone
33493 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90);
33494 +
33495 + RTMPusecDelay(1000);
33496 + // Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0]
33497 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value);
33498 + R55x = value & 0xFF;
33499 +
33500 + } while ((ReTry++ < 100) && (R55x == 0));
33501 +
33502 + // Write 0x06 to BBP_R24 to set power & frequency of stopband test tone
33503 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0x06);
33504 +
33505 + while(TRUE)
33506 + {
33507 + // Write 0x90 to BBP_R25 to transmit test tone
33508 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90);
33509 +
33510 + //We need to wait for calibration
33511 + RTMPusecDelay(1000);
33512 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value);
33513 + value &= 0xFF;
33514 + if ((R55x - value) < FilterTarget)
33515 + {
33516 + RF_R24_Value ++;
33517 + }
33518 + else if ((R55x - value) == FilterTarget)
33519 + {
33520 + RF_R24_Value ++;
33521 + count ++;
33522 + }
33523 + else
33524 + {
33525 + break;
33526 + }
33527 +
33528 + // prevent infinite loop cause driver hang.
33529 + if (loopcnt++ > 100)
33530 + {
33531 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt));
33532 + break;
33533 + }
33534 +
33535 + // Write RF_R24 to program filter
33536 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
33537 + }
33538 +
33539 + if (count > 0)
33540 + {
33541 + RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0));
33542 + }
33543 +
33544 + // Store for future usage
33545 + if (loopcnt < 100)
33546 + {
33547 + if (loop++ == 0)
33548 + {
33549 + //BandWidth = 20 MHz
33550 + pAd->Mlme.CaliBW20RfR24 = (UCHAR)RF_R24_Value;
33551 + }
33552 + else
33553 + {
33554 + //BandWidth = 40 MHz
33555 + pAd->Mlme.CaliBW40RfR24 = (UCHAR)RF_R24_Value;
33556 + break;
33557 + }
33558 + }
33559 + else
33560 + break;
33561 +
33562 + RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
33563 +
33564 + // reset count
33565 + count = 0;
33566 + } while(TRUE);
33567 +
33568 + //
33569 + // Set back to initial state
33570 + //
33571 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0);
33572 +
33573 + RT30xxReadRFRegister(pAd, RF_R22, &value);
33574 + value &= ~(0x01);
33575 + RT30xxWriteRFRegister(pAd, RF_R22, value);
33576 +
33577 + // set BBP back to BW20
33578 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
33579 + BBPValue&= (~0x18);
33580 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
33581 +
33582 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24));
33583 +}
33584 +#endif // RT30xx //
33585 +
33586 +
33587 +#ifdef RT3070
33588 +VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd)
33589 +{
33590 + INT i;
33591 + // Driver must read EEPROM to get RfIcType before initial RF registers
33592 + // Initialize RF register to default value
33593 + if (IS_RT3070(pAd) || IS_RT3071(pAd))
33594 + {
33595 + // Init RF calibration
33596 + // Driver should toggle RF R30 bit7 before init RF registers
33597 + UINT32 RfReg = 0;
33598 + UINT32 data;
33599 +
33600 + RT30xxReadRFRegister(pAd, RF_R30, (PUCHAR)&RfReg);
33601 + RfReg |= 0x80;
33602 + RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg);
33603 + RTMPusecDelay(1000);
33604 + RfReg &= 0x7F;
33605 + RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg);
33606 +
33607 + // Initialize RF register to default value
33608 + for (i = 0; i < NUM_RF_REG_PARMS; i++)
33609 + {
33610 + RT30xxWriteRFRegister(pAd, RT30xx_RFRegTable[i].Register, RT30xx_RFRegTable[i].Value);
33611 + }
33612 +
33613 + // add by johnli
33614 + if (IS_RT3070(pAd))
33615 + {
33616 + // Update MAC 0x05D4 from 01xxxxxx to 0Dxxxxxx (voltage 1.2V to 1.35V) for RT3070 to improve yield rate
33617 + RTUSBReadMACRegister(pAd, LDO_CFG0, &data);
33618 + data = ((data & 0xF0FFFFFF) | 0x0D000000);
33619 + RTUSBWriteMACRegister(pAd, LDO_CFG0, data);
33620 + }
33621 + else if (IS_RT3071(pAd))
33622 + {
33623 + // Driver should set RF R6 bit6 on before init RF registers
33624 + RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RfReg);
33625 + RfReg |= 0x40;
33626 + RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RfReg);
33627 +
33628 + // init R31
33629 + RT30xxWriteRFRegister(pAd, RF_R31, 0x14);
33630 +
33631 + // RT3071 version E has fixed this issue
33632 + if ((pAd->NicConfig2.field.DACTestBit == 1) && ((pAd->MACVersion & 0xffff) < 0x0211))
33633 + {
33634 + // patch tx EVM issue temporarily
33635 + RTUSBReadMACRegister(pAd, LDO_CFG0, &data);
33636 + data = ((data & 0xE0FFFFFF) | 0x0D000000);
33637 + RTUSBWriteMACRegister(pAd, LDO_CFG0, data);
33638 + }
33639 + else
33640 + {
33641 + RTMP_IO_READ32(pAd, LDO_CFG0, &data);
33642 + data = ((data & 0xE0FFFFFF) | 0x01000000);
33643 + RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
33644 + }
33645 +
33646 + // patch LNA_PE_G1 failed issue
33647 + RTUSBReadMACRegister(pAd, GPIO_SWITCH, &data);
33648 + data &= ~(0x20);
33649 + RTUSBWriteMACRegister(pAd, GPIO_SWITCH, data);
33650 + }
33651 +
33652 + //For RF filter Calibration
33653 + RTMPFilterCalibration(pAd);
33654 +
33655 + // Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration()
33656 + if ((pAd->MACVersion & 0xffff) < 0x0211)
33657 + RT30xxWriteRFRegister(pAd, RF_R27, 0x3);
33658 +
33659 + // set led open drain enable
33660 + RTUSBReadMACRegister(pAd, OPT_14, &data);
33661 + data |= 0x01;
33662 + RTUSBWriteMACRegister(pAd, OPT_14, data);
33663 +
33664 + if (IS_RT3071(pAd))
33665 + {
33666 + // add by johnli, RF power sequence setup, load RF normal operation-mode setup
33667 + RT30xxLoadRFNormalModeSetup(pAd);
33668 + }
33669 + }
33670 +
33671 +}
33672 +#endif // RT3070 //
33673 +
33674 +
33675 +/*
33676 + ========================================================================
33677 +
33678 + Routine Description:
33679 + Read initial parameters from EEPROM
33680 +
33681 + Arguments:
33682 + Adapter Pointer to our adapter
33683 +
33684 + Return Value:
33685 + None
33686 +
33687 + IRQL = PASSIVE_LEVEL
33688 +
33689 + Note:
33690 +
33691 + ========================================================================
33692 +*/
33693 +VOID NICReadEEPROMParameters(
33694 + IN PRTMP_ADAPTER pAd,
33695 + IN PUCHAR mac_addr)
33696 +{
33697 + UINT32 data = 0;
33698 + USHORT i, value, value2;
33699 + UCHAR TmpPhy;
33700 + EEPROM_TX_PWR_STRUC Power;
33701 + EEPROM_VERSION_STRUC Version;
33702 + EEPROM_ANTENNA_STRUC Antenna;
33703 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
33704 +
33705 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n"));
33706 +
33707 + // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8
33708 + RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
33709 + DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data));
33710 +
33711 + if((data & 0x30) == 0)
33712 + pAd->EEPROMAddressNum = 6; // 93C46
33713 + else if((data & 0x30) == 0x10)
33714 + pAd->EEPROMAddressNum = 8; // 93C66
33715 + else
33716 + pAd->EEPROMAddressNum = 8; // 93C86
33717 + DBGPRINT(RT_DEBUG_TRACE, ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum ));
33718 +
33719 + // RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to intialize
33720 + // MAC address registers according to E2PROM setting
33721 + if (mac_addr == NULL ||
33722 + strlen(mac_addr) != 17 ||
33723 + mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' ||
33724 + mac_addr[11] != ':' || mac_addr[14] != ':')
33725 + {
33726 + USHORT Addr01,Addr23,Addr45 ;
33727 +
33728 + RT28xx_EEPROM_READ16(pAd, 0x04, Addr01);
33729 + RT28xx_EEPROM_READ16(pAd, 0x06, Addr23);
33730 + RT28xx_EEPROM_READ16(pAd, 0x08, Addr45);
33731 +
33732 + pAd->PermanentAddress[0] = (UCHAR)(Addr01 & 0xff);
33733 + pAd->PermanentAddress[1] = (UCHAR)(Addr01 >> 8);
33734 + pAd->PermanentAddress[2] = (UCHAR)(Addr23 & 0xff);
33735 + pAd->PermanentAddress[3] = (UCHAR)(Addr23 >> 8);
33736 + pAd->PermanentAddress[4] = (UCHAR)(Addr45 & 0xff);
33737 + pAd->PermanentAddress[5] = (UCHAR)(Addr45 >> 8);
33738 +
33739 + DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from E2PROM \n"));
33740 + }
33741 + else
33742 + {
33743 + INT j;
33744 + PUCHAR macptr;
33745 +
33746 + macptr = mac_addr;
33747 +
33748 + for (j=0; j<MAC_ADDR_LEN; j++)
33749 + {
33750 + AtoH(macptr, &pAd->PermanentAddress[j], 1);
33751 + macptr=macptr+3;
33752 + }
33753 +
33754 + DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from module parameter \n"));
33755 + }
33756 +
33757 +
33758 + {
33759 + //more conveninet to test mbssid, so ap's bssid &0xf1
33760 + if (pAd->PermanentAddress[0] == 0xff)
33761 + pAd->PermanentAddress[0] = RandomByte(pAd)&0xf8;
33762 +
33763 + //if (pAd->PermanentAddress[5] == 0xff)
33764 + // pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8;
33765 +
33766 + DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
33767 + pAd->PermanentAddress[0], pAd->PermanentAddress[1],
33768 + pAd->PermanentAddress[2], pAd->PermanentAddress[3],
33769 + pAd->PermanentAddress[4], pAd->PermanentAddress[5]));
33770 + if (pAd->bLocalAdminMAC == FALSE)
33771 + {
33772 + MAC_DW0_STRUC csr2;
33773 + MAC_DW1_STRUC csr3;
33774 + COPY_MAC_ADDR(pAd->CurrentAddress, pAd->PermanentAddress);
33775 + csr2.field.Byte0 = pAd->CurrentAddress[0];
33776 + csr2.field.Byte1 = pAd->CurrentAddress[1];
33777 + csr2.field.Byte2 = pAd->CurrentAddress[2];
33778 + csr2.field.Byte3 = pAd->CurrentAddress[3];
33779 + RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word);
33780 + csr3.word = 0;
33781 + csr3.field.Byte4 = pAd->CurrentAddress[4];
33782 + csr3.field.Byte5 = pAd->CurrentAddress[5];
33783 + csr3.field.U2MeMask = 0xff;
33784 + RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word);
33785 + DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
33786 + pAd->PermanentAddress[0], pAd->PermanentAddress[1],
33787 + pAd->PermanentAddress[2], pAd->PermanentAddress[3],
33788 + pAd->PermanentAddress[4], pAd->PermanentAddress[5]));
33789 + }
33790 + }
33791 +
33792 + // if not return early. cause fail at emulation.
33793 + // Init the channel number for TX channel power
33794 + RTMPReadChannelPwr(pAd);
33795 +
33796 + // if E2PROM version mismatch with driver's expectation, then skip
33797 + // all subsequent E2RPOM retieval and set a system error bit to notify GUI
33798 + RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word);
33799 + pAd->EepromVersion = Version.field.Version + Version.field.FaeReleaseNumber * 256;
33800 + DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: Version = %d, FAE release #%d\n", Version.field.Version, Version.field.FaeReleaseNumber));
33801 +
33802 + if (Version.field.Version > VALID_EEPROM_VERSION)
33803 + {
33804 + DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n",Version.field.Version, VALID_EEPROM_VERSION));
33805 + /*pAd->SystemErrorBitmap |= 0x00000001;
33806 +
33807 + // hard-code default value when no proper E2PROM installed
33808 + pAd->bAutoTxAgcA = FALSE;
33809 + pAd->bAutoTxAgcG = FALSE;
33810 +
33811 + // Default the channel power
33812 + for (i = 0; i < MAX_NUM_OF_CHANNELS; i++)
33813 + pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER;
33814 +
33815 + // Default the channel power
33816 + for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++)
33817 + pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER;
33818 +
33819 + for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++)
33820 + pAd->EEPROMDefaultValue[i] = 0xffff;
33821 + return; */
33822 + }
33823 +
33824 + // Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd
33825 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value);
33826 + pAd->EEPROMDefaultValue[0] = value;
33827 +
33828 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value);
33829 + pAd->EEPROMDefaultValue[1] = value;
33830 +
33831 + RT28xx_EEPROM_READ16(pAd, 0x38, value); // Country Region
33832 + pAd->EEPROMDefaultValue[2] = value;
33833 +
33834 + for(i = 0; i < 8; i++)
33835 + {
33836 + RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i*2, value);
33837 + pAd->EEPROMDefaultValue[i+3] = value;
33838 + }
33839 +
33840 + // We have to parse NIC configuration 0 at here.
33841 + // If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
33842 + // Therefore, we have to read TxAutoAgc control beforehand.
33843 + // Read Tx AGC control bit
33844 + Antenna.word = pAd->EEPROMDefaultValue[0];
33845 + if (Antenna.word == 0xFFFF)
33846 + {
33847 +#ifdef RT30xx
33848 + if(IS_RT3090(pAd))
33849 + {
33850 + Antenna.word = 0;
33851 + Antenna.field.RfIcType = RFIC_3020;
33852 + Antenna.field.TxPath = 1;
33853 + Antenna.field.RxPath = 1;
33854 + }
33855 + else
33856 + {
33857 +#endif // RT30xx //
33858 + Antenna.word = 0;
33859 + Antenna.field.RfIcType = RFIC_2820;
33860 + Antenna.field.TxPath = 1;
33861 + Antenna.field.RxPath = 2;
33862 + DBGPRINT(RT_DEBUG_WARN, ("E2PROM error, hard code as 0x%04x\n", Antenna.word));
33863 +#ifdef RT30xx
33864 + }
33865 +#endif // RT30xx //
33866 + }
33867 +
33868 + // Choose the desired Tx&Rx stream.
33869 + if ((pAd->CommonCfg.TxStream == 0) || (pAd->CommonCfg.TxStream > Antenna.field.TxPath))
33870 + pAd->CommonCfg.TxStream = Antenna.field.TxPath;
33871 +
33872 + if ((pAd->CommonCfg.RxStream == 0) || (pAd->CommonCfg.RxStream > Antenna.field.RxPath))
33873 + {
33874 + pAd->CommonCfg.RxStream = Antenna.field.RxPath;
33875 +
33876 + if ((pAd->MACVersion < RALINK_2883_VERSION) &&
33877 + (pAd->CommonCfg.RxStream > 2))
33878 + {
33879 + // only 2 Rx streams for RT2860 series
33880 + pAd->CommonCfg.RxStream = 2;
33881 + }
33882 + }
33883 +
33884 + // 3*3
33885 + // read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2
33886 + // yet implement
33887 + for(i=0; i<3; i++)
33888 + {
33889 + }
33890 +
33891 + NicConfig2.word = pAd->EEPROMDefaultValue[1];
33892 +
33893 +
33894 +
33895 +#ifdef CONFIG_STA_SUPPORT
33896 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
33897 + {
33898 + if ((NicConfig2.word & 0x00ff) == 0xff)
33899 + {
33900 + NicConfig2.word &= 0xff00;
33901 + }
33902 +
33903 + if ((NicConfig2.word >> 8) == 0xff)
33904 + {
33905 + NicConfig2.word &= 0x00ff;
33906 + }
33907 + }
33908 +#endif // CONFIG_STA_SUPPORT //
33909 +
33910 + if (NicConfig2.field.DynamicTxAgcControl == 1)
33911 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
33912 + else
33913 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
33914 +
33915 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n", Antenna.field.RxPath, Antenna.field.TxPath));
33916 +
33917 + // Save the antenna for future use
33918 + pAd->Antenna.word = Antenna.word;
33919 +
33920 + //
33921 + // Reset PhyMode if we don't support 802.11a
33922 + // Only RFIC_2850 & RFIC_2750 support 802.11a
33923 + //
33924 + if ((Antenna.field.RfIcType != RFIC_2850) && (Antenna.field.RfIcType != RFIC_2750))
33925 + {
33926 + if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) ||
33927 + (pAd->CommonCfg.PhyMode == PHY_11A))
33928 + pAd->CommonCfg.PhyMode = PHY_11BG_MIXED;
33929 +#ifdef DOT11_N_SUPPORT
33930 + else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) ||
33931 + (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) ||
33932 + (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) ||
33933 + (pAd->CommonCfg.PhyMode == PHY_11N_5G))
33934 + pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED;
33935 +#endif // DOT11_N_SUPPORT //
33936 + }
33937 +
33938 + // Read TSSI reference and TSSI boundary for temperature compensation. This is ugly
33939 + // 0. 11b/g
33940 + {
33941 + /* these are tempature reference value (0x00 ~ 0xFE)
33942 + ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
33943 + TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) +
33944 + TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */
33945 + RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word);
33946 + pAd->TssiMinusBoundaryG[4] = Power.field.Byte0;
33947 + pAd->TssiMinusBoundaryG[3] = Power.field.Byte1;
33948 + RT28xx_EEPROM_READ16(pAd, 0x70, Power.word);
33949 + pAd->TssiMinusBoundaryG[2] = Power.field.Byte0;
33950 + pAd->TssiMinusBoundaryG[1] = Power.field.Byte1;
33951 + RT28xx_EEPROM_READ16(pAd, 0x72, Power.word);
33952 + pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */
33953 + pAd->TssiPlusBoundaryG[1] = Power.field.Byte1;
33954 + RT28xx_EEPROM_READ16(pAd, 0x74, Power.word);
33955 + pAd->TssiPlusBoundaryG[2] = Power.field.Byte0;
33956 + pAd->TssiPlusBoundaryG[3] = Power.field.Byte1;
33957 + RT28xx_EEPROM_READ16(pAd, 0x76, Power.word);
33958 + pAd->TssiPlusBoundaryG[4] = Power.field.Byte0;
33959 + pAd->TxAgcStepG = Power.field.Byte1;
33960 + pAd->TxAgcCompensateG = 0;
33961 + pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG;
33962 + pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG;
33963 +
33964 + // Disable TxAgc if the based value is not right
33965 + if (pAd->TssiRefG == 0xff)
33966 + pAd->bAutoTxAgcG = FALSE;
33967 +
33968 + DBGPRINT(RT_DEBUG_TRACE,("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
33969 + pAd->TssiMinusBoundaryG[4], pAd->TssiMinusBoundaryG[3], pAd->TssiMinusBoundaryG[2], pAd->TssiMinusBoundaryG[1],
33970 + pAd->TssiRefG,
33971 + pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2], pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4],
33972 + pAd->TxAgcStepG, pAd->bAutoTxAgcG));
33973 + }
33974 + // 1. 11a
33975 + {
33976 + RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word);
33977 + pAd->TssiMinusBoundaryA[4] = Power.field.Byte0;
33978 + pAd->TssiMinusBoundaryA[3] = Power.field.Byte1;
33979 + RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word);
33980 + pAd->TssiMinusBoundaryA[2] = Power.field.Byte0;
33981 + pAd->TssiMinusBoundaryA[1] = Power.field.Byte1;
33982 + RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word);
33983 + pAd->TssiRefA = Power.field.Byte0;
33984 + pAd->TssiPlusBoundaryA[1] = Power.field.Byte1;
33985 + RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word);
33986 + pAd->TssiPlusBoundaryA[2] = Power.field.Byte0;
33987 + pAd->TssiPlusBoundaryA[3] = Power.field.Byte1;
33988 + RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word);
33989 + pAd->TssiPlusBoundaryA[4] = Power.field.Byte0;
33990 + pAd->TxAgcStepA = Power.field.Byte1;
33991 + pAd->TxAgcCompensateA = 0;
33992 + pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA;
33993 + pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA;
33994 +
33995 + // Disable TxAgc if the based value is not right
33996 + if (pAd->TssiRefA == 0xff)
33997 + pAd->bAutoTxAgcA = FALSE;
33998 +
33999 + DBGPRINT(RT_DEBUG_TRACE,("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
34000 + pAd->TssiMinusBoundaryA[4], pAd->TssiMinusBoundaryA[3], pAd->TssiMinusBoundaryA[2], pAd->TssiMinusBoundaryA[1],
34001 + pAd->TssiRefA,
34002 + pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2], pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4],
34003 + pAd->TxAgcStepA, pAd->bAutoTxAgcA));
34004 + }
34005 + pAd->BbpRssiToDbmDelta = 0x0;
34006 +
34007 + // Read frequency offset setting for RF
34008 + RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value);
34009 + if ((value & 0x00FF) != 0x00FF)
34010 + pAd->RfFreqOffset = (ULONG) (value & 0x00FF);
34011 + else
34012 + pAd->RfFreqOffset = 0;
34013 + DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset));
34014 +
34015 + //CountryRegion byte offset (38h)
34016 + value = pAd->EEPROMDefaultValue[2] >> 8; // 2.4G band
34017 + value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; // 5G band
34018 +
34019 + if ((value <= REGION_MAXIMUM_BG_BAND) && (value2 <= REGION_MAXIMUM_A_BAND))
34020 + {
34021 + pAd->CommonCfg.CountryRegion = ((UCHAR) value) | 0x80;
34022 + pAd->CommonCfg.CountryRegionForABand = ((UCHAR) value2) | 0x80;
34023 + TmpPhy = pAd->CommonCfg.PhyMode;
34024 + pAd->CommonCfg.PhyMode = 0xff;
34025 + RTMPSetPhyMode(pAd, TmpPhy);
34026 +#ifdef DOT11_N_SUPPORT
34027 + SetCommonHT(pAd);
34028 +#endif // DOT11_N_SUPPORT //
34029 + }
34030 +
34031 + //
34032 + // Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch.
34033 + // The valid value are (-10 ~ 10)
34034 + //
34035 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value);
34036 + pAd->BGRssiOffset0 = value & 0x00ff;
34037 + pAd->BGRssiOffset1 = (value >> 8);
34038 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET+2, value);
34039 + pAd->BGRssiOffset2 = value & 0x00ff;
34040 + pAd->ALNAGain1 = (value >> 8);
34041 + RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value);
34042 + pAd->BLNAGain = value & 0x00ff;
34043 + pAd->ALNAGain0 = (value >> 8);
34044 +
34045 + // Validate 11b/g RSSI_0 offset.
34046 + if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10))
34047 + pAd->BGRssiOffset0 = 0;
34048 +
34049 + // Validate 11b/g RSSI_1 offset.
34050 + if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10))
34051 + pAd->BGRssiOffset1 = 0;
34052 +
34053 + // Validate 11b/g RSSI_2 offset.
34054 + if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10))
34055 + pAd->BGRssiOffset2 = 0;
34056 +
34057 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value);
34058 + pAd->ARssiOffset0 = value & 0x00ff;
34059 + pAd->ARssiOffset1 = (value >> 8);
34060 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET+2), value);
34061 + pAd->ARssiOffset2 = value & 0x00ff;
34062 + pAd->ALNAGain2 = (value >> 8);
34063 +
34064 + if (((UCHAR)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00))
34065 + pAd->ALNAGain1 = pAd->ALNAGain0;
34066 + if (((UCHAR)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00))
34067 + pAd->ALNAGain2 = pAd->ALNAGain0;
34068 +
34069 + // Validate 11a RSSI_0 offset.
34070 + if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10))
34071 + pAd->ARssiOffset0 = 0;
34072 +
34073 + // Validate 11a RSSI_1 offset.
34074 + if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10))
34075 + pAd->ARssiOffset1 = 0;
34076 +
34077 + //Validate 11a RSSI_2 offset.
34078 + if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10))
34079 + pAd->ARssiOffset2 = 0;
34080 +
34081 + //
34082 + // Get LED Setting.
34083 + //
34084 + RT28xx_EEPROM_READ16(pAd, 0x3a, value);
34085 + pAd->LedCntl.word = (value&0xff00) >> 8;
34086 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value);
34087 + pAd->Led1 = value;
34088 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value);
34089 + pAd->Led2 = value;
34090 + RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value);
34091 + pAd->Led3 = value;
34092 +
34093 + RTMPReadTxPwrPerRate(pAd);
34094 +
34095 +#ifdef SINGLE_SKU
34096 + //pAd->CommonCfg.DefineMaxTxPwr = RTMP_EEPROM_READ16(pAd, EEPROM_DEFINE_MAX_TXPWR);
34097 + RT28xx_EEPROM_READ16(pAd, EEPROM_DEFINE_MAX_TXPWR, pAd->CommonCfg.DefineMaxTxPwr);
34098 +#endif // SINGLE_SKU //
34099 +#ifdef RT30xx
34100 + if (IS_RT30xx(pAd))
34101 + {
34102 + eFusePhysicalReadRegisters(pAd, EFUSE_TAG, 2, &value);
34103 + pAd->EFuseTag = (value & 0xff);
34104 + }
34105 +#endif // RT30xx //
34106 +
34107 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n"));
34108 +}
34109 +
34110 +/*
34111 + ========================================================================
34112 +
34113 + Routine Description:
34114 + Set default value from EEPROM
34115 +
34116 + Arguments:
34117 + Adapter Pointer to our adapter
34118 +
34119 + Return Value:
34120 + None
34121 +
34122 + IRQL = PASSIVE_LEVEL
34123 +
34124 + Note:
34125 +
34126 + ========================================================================
34127 +*/
34128 +VOID NICInitAsicFromEEPROM(
34129 + IN PRTMP_ADAPTER pAd)
34130 +{
34131 +#ifdef CONFIG_STA_SUPPORT
34132 + UINT32 data = 0;
34133 + UCHAR BBPR1 = 0;
34134 +#endif // CONFIG_STA_SUPPORT //
34135 + USHORT i;
34136 + EEPROM_ANTENNA_STRUC Antenna;
34137 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
34138 + UCHAR BBPR3 = 0;
34139 +
34140 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n"));
34141 + for(i = 3; i < NUM_EEPROM_BBP_PARMS; i++)
34142 + {
34143 + UCHAR BbpRegIdx, BbpValue;
34144 +
34145 + if ((pAd->EEPROMDefaultValue[i] != 0xFFFF) && (pAd->EEPROMDefaultValue[i] != 0))
34146 + {
34147 + BbpRegIdx = (UCHAR)(pAd->EEPROMDefaultValue[i] >> 8);
34148 + BbpValue = (UCHAR)(pAd->EEPROMDefaultValue[i] & 0xff);
34149 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue);
34150 + }
34151 + }
34152 +
34153 + Antenna.word = pAd->EEPROMDefaultValue[0];
34154 + if (Antenna.word == 0xFFFF)
34155 + {
34156 + DBGPRINT(RT_DEBUG_ERROR, ("E2PROM error, hard code as 0x%04x\n", Antenna.word));
34157 + BUG_ON(Antenna.word == 0xFFFF);
34158 + }
34159 + pAd->Mlme.RealRxPath = (UCHAR) Antenna.field.RxPath;
34160 + pAd->RfIcType = (UCHAR) Antenna.field.RfIcType;
34161 +
34162 + DBGPRINT(RT_DEBUG_WARN, ("pAd->RfIcType = %d, RealRxPath=%d, TxPath = %d\n", pAd->RfIcType, pAd->Mlme.RealRxPath,Antenna.field.TxPath));
34163 +
34164 + // Save the antenna for future use
34165 + pAd->Antenna.word = Antenna.word;
34166 +
34167 + NicConfig2.word = pAd->EEPROMDefaultValue[1];
34168 +
34169 +
34170 +#ifdef CONFIG_STA_SUPPORT
34171 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34172 + {
34173 + if ((NicConfig2.word & 0x00ff) == 0xff)
34174 + {
34175 + NicConfig2.word &= 0xff00;
34176 + }
34177 +
34178 + if ((NicConfig2.word >> 8) == 0xff)
34179 + {
34180 + NicConfig2.word &= 0x00ff;
34181 + }
34182 + }
34183 +#endif // CONFIG_STA_SUPPORT //
34184 +
34185 + // Save the antenna for future use
34186 + pAd->NicConfig2.word = NicConfig2.word;
34187 +
34188 + // set default antenna as main
34189 + if (pAd->RfIcType == RFIC_3020)
34190 + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
34191 +
34192 + //
34193 + // Send LED Setting to MCU.
34194 + //
34195 + if (pAd->LedCntl.word == 0xFF)
34196 + {
34197 + pAd->LedCntl.word = 0x01;
34198 + pAd->Led1 = 0x5555;
34199 + pAd->Led2 = 0x2221;
34200 +
34201 +#ifdef RT2870
34202 + pAd->Led3 = 0x5627;
34203 +#endif // RT2870 //
34204 + }
34205 +
34206 + AsicSendCommandToMcu(pAd, 0x52, 0xff, (UCHAR)pAd->Led1, (UCHAR)(pAd->Led1 >> 8));
34207 + AsicSendCommandToMcu(pAd, 0x53, 0xff, (UCHAR)pAd->Led2, (UCHAR)(pAd->Led2 >> 8));
34208 + AsicSendCommandToMcu(pAd, 0x54, 0xff, (UCHAR)pAd->Led3, (UCHAR)(pAd->Led3 >> 8));
34209 + pAd->LedIndicatorStregth = 0xFF;
34210 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, before link up
34211 +
34212 +#ifdef CONFIG_STA_SUPPORT
34213 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34214 + {
34215 + // Read Hardware controlled Radio state enable bit
34216 + if (NicConfig2.field.HardwareRadioControl == 1)
34217 + {
34218 + pAd->StaCfg.bHardwareRadio = TRUE;
34219 +
34220 + // Read GPIO pin2 as Hardware controlled radio state
34221 + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
34222 + if ((data & 0x04) == 0)
34223 + {
34224 + pAd->StaCfg.bHwRadio = FALSE;
34225 + pAd->StaCfg.bRadio = FALSE;
34226 +// RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818);
34227 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
34228 + }
34229 + }
34230 + else
34231 + pAd->StaCfg.bHardwareRadio = FALSE;
34232 +
34233 + if (pAd->StaCfg.bRadio == FALSE)
34234 + {
34235 + RTMPSetLED(pAd, LED_RADIO_OFF);
34236 + }
34237 + else
34238 + {
34239 + RTMPSetLED(pAd, LED_RADIO_ON);
34240 + }
34241 + }
34242 +#endif // CONFIG_STA_SUPPORT //
34243 +
34244 + // Turn off patching for cardbus controller
34245 + if (NicConfig2.field.CardbusAcceleration == 1)
34246 + {
34247 +// pAd->bTest1 = TRUE;
34248 + }
34249 +
34250 + if (NicConfig2.field.DynamicTxAgcControl == 1)
34251 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
34252 + else
34253 + pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
34254 + //
34255 + // Since BBP has been progamed, to make sure BBP setting will be
34256 + // upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND!!
34257 + //
34258 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
34259 +
34260 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
34261 + BBPR3 &= (~0x18);
34262 + if(pAd->Antenna.field.RxPath == 3)
34263 + {
34264 + BBPR3 |= (0x10);
34265 + }
34266 + else if(pAd->Antenna.field.RxPath == 2)
34267 + {
34268 + BBPR3 |= (0x8);
34269 + }
34270 + else if(pAd->Antenna.field.RxPath == 1)
34271 + {
34272 + BBPR3 |= (0x0);
34273 + }
34274 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
34275 +
34276 +#ifdef CONFIG_STA_SUPPORT
34277 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34278 + {
34279 + // Handle the difference when 1T
34280 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1);
34281 + if(pAd->Antenna.field.TxPath == 1)
34282 + {
34283 + BBPR1 &= (~0x18);
34284 + }
34285 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1);
34286 +
34287 + DBGPRINT(RT_DEBUG_TRACE, ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n", pAd->CommonCfg.bHardwareRadio, pAd->CommonCfg.bHardwareRadio));
34288 + }
34289 +#endif // CONFIG_STA_SUPPORT //
34290 + DBGPRINT(RT_DEBUG_TRACE, ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n", pAd->Antenna.field.TxPath, pAd->Antenna.field.RxPath, pAd->RfIcType, pAd->LedCntl.word));
34291 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n"));
34292 +}
34293 +
34294 +/*
34295 + ========================================================================
34296 +
34297 + Routine Description:
34298 + Initialize NIC hardware
34299 +
34300 + Arguments:
34301 + Adapter Pointer to our adapter
34302 +
34303 + Return Value:
34304 + None
34305 +
34306 + IRQL = PASSIVE_LEVEL
34307 +
34308 + Note:
34309 +
34310 + ========================================================================
34311 +*/
34312 +NDIS_STATUS NICInitializeAdapter(
34313 + IN PRTMP_ADAPTER pAd,
34314 + IN BOOLEAN bHardReset)
34315 +{
34316 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
34317 + WPDMA_GLO_CFG_STRUC GloCfg;
34318 +// INT_MASK_CSR_STRUC IntMask;
34319 + ULONG i =0, j=0;
34320 + AC_TXOP_CSR0_STRUC csr0;
34321 +
34322 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n"));
34323 +
34324 + // 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits:
34325 +retry:
34326 + i = 0;
34327 + do
34328 + {
34329 + RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
34330 + if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
34331 + break;
34332 +
34333 + RTMPusecDelay(1000);
34334 + i++;
34335 + }while ( i<100);
34336 + DBGPRINT(RT_DEBUG_TRACE, ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word));
34337 + GloCfg.word &= 0xff0;
34338 + GloCfg.field.EnTXWriteBackDDONE =1;
34339 + RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
34340 +
34341 + // Record HW Beacon offset
34342 + pAd->BeaconOffset[0] = HW_BEACON_BASE0;
34343 + pAd->BeaconOffset[1] = HW_BEACON_BASE1;
34344 + pAd->BeaconOffset[2] = HW_BEACON_BASE2;
34345 + pAd->BeaconOffset[3] = HW_BEACON_BASE3;
34346 + pAd->BeaconOffset[4] = HW_BEACON_BASE4;
34347 + pAd->BeaconOffset[5] = HW_BEACON_BASE5;
34348 + pAd->BeaconOffset[6] = HW_BEACON_BASE6;
34349 + pAd->BeaconOffset[7] = HW_BEACON_BASE7;
34350 +
34351 + //
34352 + // write all shared Ring's base address into ASIC
34353 + //
34354 +
34355 + // asic simulation sequence put this ahead before loading firmware.
34356 + // pbf hardware reset
34357 +
34358 + // Initialze ASIC for TX & Rx operation
34359 + if (NICInitializeAsic(pAd , bHardReset) != NDIS_STATUS_SUCCESS)
34360 + {
34361 + if (j++ == 0)
34362 + {
34363 + NICLoadFirmware(pAd);
34364 + goto retry;
34365 + }
34366 + return NDIS_STATUS_FAILURE;
34367 + }
34368 +
34369 +
34370 +
34371 +
34372 + // WMM parameter
34373 + csr0.word = 0;
34374 + RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
34375 + if (pAd->CommonCfg.PhyMode == PHY_11B)
34376 + {
34377 + csr0.field.Ac0Txop = 192; // AC_VI: 192*32us ~= 6ms
34378 + csr0.field.Ac1Txop = 96; // AC_VO: 96*32us ~= 3ms
34379 + }
34380 + else
34381 + {
34382 + csr0.field.Ac0Txop = 96; // AC_VI: 96*32us ~= 3ms
34383 + csr0.field.Ac1Txop = 48; // AC_VO: 48*32us ~= 1.5ms
34384 + }
34385 + RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word);
34386 +
34387 +
34388 +
34389 +
34390 + // reset action
34391 + // Load firmware
34392 + // Status = NICLoadFirmware(pAd);
34393 +
34394 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n"));
34395 + return Status;
34396 +}
34397 +
34398 +/*
34399 + ========================================================================
34400 +
34401 + Routine Description:
34402 + Initialize ASIC
34403 +
34404 + Arguments:
34405 + Adapter Pointer to our adapter
34406 +
34407 + Return Value:
34408 + None
34409 +
34410 + IRQL = PASSIVE_LEVEL
34411 +
34412 + Note:
34413 +
34414 + ========================================================================
34415 +*/
34416 +NDIS_STATUS NICInitializeAsic(
34417 + IN PRTMP_ADAPTER pAd,
34418 + IN BOOLEAN bHardReset)
34419 +{
34420 + ULONG Index = 0;
34421 + UCHAR R0 = 0xff;
34422 + UINT32 MacCsr12 = 0, Counter = 0;
34423 +#ifdef RT2870
34424 + UINT32 MacCsr0 = 0;
34425 + NTSTATUS Status;
34426 + UCHAR Value = 0xff;
34427 +#endif // RT2870 //
34428 +#ifdef RT30xx
34429 + UINT32 eFuseCtrl;
34430 +#endif // RT30xx //
34431 + USHORT KeyIdx;
34432 + INT i,apidx;
34433 +
34434 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n"));
34435 +
34436 +
34437 +#ifdef RT2870
34438 + //
34439 + // Make sure MAC gets ready after NICLoadFirmware().
34440 + //
34441 + Index = 0;
34442 +
34443 + //To avoid hang-on issue when interface up in kernel 2.4,
34444 + //we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly.
34445 + do
34446 + {
34447 + RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
34448 +
34449 + if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
34450 + break;
34451 +
34452 + RTMPusecDelay(10);
34453 + } while (Index++ < 100);
34454 +
34455 + pAd->MACVersion = MacCsr0;
34456 + DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
34457 + // turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue.
34458 + RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12);
34459 + MacCsr12 &= (~0x2000);
34460 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12);
34461 +
34462 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
34463 + RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0);
34464 + Status = RTUSBVenderReset(pAd);
34465 +
34466 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
34467 +
34468 + // Initialize MAC register to default value
34469 + for(Index=0; Index<NUM_MAC_REG_PARMS; Index++)
34470 + {
34471 +#ifdef RT3070
34472 + if ((MACRegTable[Index].Register == TX_SW_CFG0) && (IS_RT3070(pAd) || IS_RT3071(pAd)))
34473 + {
34474 + MACRegTable[Index].Value = 0x00000400;
34475 + }
34476 +#endif // RT3070 //
34477 + RTMP_IO_WRITE32(pAd, (USHORT)MACRegTable[Index].Register, MACRegTable[Index].Value);
34478 + }
34479 +
34480 +
34481 +#ifdef CONFIG_STA_SUPPORT
34482 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34483 + {
34484 + for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++)
34485 + {
34486 + RTMP_IO_WRITE32(pAd, (USHORT)STAMACRegTable[Index].Register, STAMACRegTable[Index].Value);
34487 + }
34488 + }
34489 +#endif // CONFIG_STA_SUPPORT //
34490 +#endif // RT2870 //
34491 +
34492 +#ifdef RT30xx
34493 + // Initialize RT3070 serial MAc registers which is different from RT2870 serial
34494 + if (IS_RT3090(pAd))
34495 + {
34496 + RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
34497 +
34498 + // RT3071 version E has fixed this issue
34499 + if ((pAd->MACVersion & 0xffff) < 0x0211)
34500 + {
34501 + if (pAd->NicConfig2.field.DACTestBit == 1)
34502 + {
34503 + RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x1F); // To fix throughput drop drastically
34504 + }
34505 + else
34506 + {
34507 + RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0F); // To fix throughput drop drastically
34508 + }
34509 + }
34510 + else
34511 + {
34512 + RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0);
34513 + }
34514 + }
34515 + else if (IS_RT3070(pAd))
34516 + {
34517 + RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
34518 + RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x1F); // To fix throughput drop drastically
34519 + }
34520 +#endif // RT30xx //
34521 +
34522 + //
34523 + // Before program BBP, we need to wait BBP/RF get wake up.
34524 + //
34525 + Index = 0;
34526 + do
34527 + {
34528 + RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12);
34529 +
34530 + if ((MacCsr12 & 0x03) == 0) // if BB.RF is stable
34531 + break;
34532 +
34533 + DBGPRINT(RT_DEBUG_TRACE, ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12));
34534 + RTMPusecDelay(1000);
34535 + } while (Index++ < 100);
34536 +
34537 + // The commands to firmware should be after these commands, these commands will init firmware
34538 + // PCI and USB are not the same because PCI driver needs to wait for PCI bus ready
34539 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); // initialize BBP R/W access agent
34540 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
34541 + RTMPusecDelay(1000);
34542 +
34543 + // Read BBP register, make sure BBP is up and running before write new data
34544 + Index = 0;
34545 + do
34546 + {
34547 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0);
34548 + DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0));
34549 + } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00)));
34550 + //ASSERT(Index < 20); //this will cause BSOD on Check-build driver
34551 +
34552 + if ((R0 == 0xff) || (R0 == 0x00))
34553 + return NDIS_STATUS_FAILURE;
34554 +
34555 + // Initialize BBP register to default value
34556 + for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++)
34557 + {
34558 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, BBPRegTable[Index].Value);
34559 + }
34560 +
34561 + // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT.
34562 + // RT3090 should not program BBP R84 to 0x19, otherwise TX will block.
34563 + if (((pAd->MACVersion&0xffff) != 0x0101) && (!IS_RT30xx(pAd)))
34564 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19);
34565 +
34566 +// add by johnli, RF power sequence setup
34567 +#ifdef RT30xx
34568 + if (IS_RT30xx(pAd))
34569 + { //update for RT3070/71/72/90/91/92.
34570 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R79, 0x13);
34571 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R80, 0x05);
34572 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R81, 0x33);
34573 + }
34574 +
34575 + if (IS_RT3090(pAd))
34576 + {
34577 + UCHAR bbpreg=0;
34578 +
34579 + // enable DC filter
34580 + if ((pAd->MACVersion & 0xffff) >= 0x0211)
34581 + {
34582 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0);
34583 + }
34584 +
34585 + // improve power consumption
34586 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R138, &bbpreg);
34587 + if (pAd->Antenna.field.TxPath == 1)
34588 + {
34589 + // turn off tx DAC_1
34590 + bbpreg = (bbpreg | 0x20);
34591 + }
34592 +
34593 + if (pAd->Antenna.field.RxPath == 1)
34594 + {
34595 + // turn off tx ADC_1
34596 + bbpreg &= (~0x2);
34597 + }
34598 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R138, bbpreg);
34599 +
34600 + // improve power consumption in RT3071 Ver.E
34601 + if ((pAd->MACVersion & 0xffff) >= 0x0211)
34602 + {
34603 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg);
34604 + bbpreg &= (~0x3);
34605 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg);
34606 + }
34607 + }
34608 +#endif // RT30xx //
34609 +// end johnli
34610 +
34611 + if (pAd->MACVersion == 0x28600100)
34612 + {
34613 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
34614 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12);
34615 + }
34616 +
34617 + if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) // 3*3
34618 + {
34619 + // enlarge MAX_LEN_CFG
34620 + UINT32 csr;
34621 + RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr);
34622 + csr &= 0xFFF;
34623 + csr |= 0x2000;
34624 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr);
34625 + }
34626 +
34627 +#ifdef RT2870
34628 +{
34629 + UCHAR MAC_Value[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0};
34630 +
34631 + //Initialize WCID table
34632 + Value = 0xff;
34633 + for(Index =0 ;Index < 254;Index++)
34634 + {
34635 + RTUSBMultiWrite(pAd, (USHORT)(MAC_WCID_BASE + Index * 8), MAC_Value, 8);
34636 + }
34637 +}
34638 +#endif // RT2870 //
34639 +
34640 + // Add radio off control
34641 +#ifdef CONFIG_STA_SUPPORT
34642 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34643 + {
34644 + if (pAd->StaCfg.bRadio == FALSE)
34645 + {
34646 +// RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818);
34647 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
34648 + DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n"));
34649 + }
34650 + }
34651 +#endif // CONFIG_STA_SUPPORT //
34652 +
34653 + // Clear raw counters
34654 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
34655 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
34656 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
34657 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
34658 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
34659 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
34660 +
34661 + // ASIC will keep garbage value after boot
34662 + // Clear all seared key table when initial
34663 + // This routine can be ignored in radio-ON/OFF operation.
34664 + if (bHardReset)
34665 + {
34666 + for (KeyIdx = 0; KeyIdx < 4; KeyIdx++)
34667 + {
34668 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4*KeyIdx, 0);
34669 + }
34670 +
34671 + // Clear all pairwise key table when initial
34672 + for (KeyIdx = 0; KeyIdx < 256; KeyIdx++)
34673 + {
34674 + RTMP_IO_WRITE32(pAd, MAC_WCID_ATTRIBUTE_BASE + (KeyIdx * HW_WCID_ATTRI_SIZE), 1);
34675 + }
34676 + }
34677 +
34678 + // assert HOST ready bit
34679 +// RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x0); // 2004-09-14 asked by Mark
34680 +// RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x4);
34681 +
34682 + // It isn't necessary to clear this space when not hard reset.
34683 + if (bHardReset == TRUE)
34684 + {
34685 + // clear all on-chip BEACON frame space
34686 + for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++)
34687 + {
34688 + for (i = 0; i < HW_BEACON_OFFSET>>2; i+=4)
34689 + RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[apidx] + i, 0x00);
34690 + }
34691 + }
34692 +#ifdef RT2870
34693 + AsicDisableSync(pAd);
34694 + // Clear raw counters
34695 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
34696 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
34697 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
34698 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
34699 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
34700 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
34701 + // Default PCI clock cycle per ms is different as default setting, which is based on PCI.
34702 + RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter);
34703 + Counter&=0xffffff00;
34704 + Counter|=0x000001e;
34705 + RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter);
34706 +#endif // RT2870 //
34707 +#ifdef RT30xx
34708 + pAd->bUseEfuse=FALSE;
34709 + RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrl);
34710 + pAd->bUseEfuse = ( (eFuseCtrl & 0x80000000) == 0x80000000) ? 1 : 0;
34711 + if(pAd->bUseEfuse)
34712 + {
34713 + DBGPRINT(RT_DEBUG_TRACE, ("NVM is Efuse\n"));
34714 + }
34715 + else
34716 + {
34717 + DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n"));
34718 +
34719 + }
34720 +#endif // RT30xx //
34721 +
34722 +#ifdef CONFIG_STA_SUPPORT
34723 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
34724 + {
34725 + // for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT.
34726 + if ((pAd->MACVersion&0xffff) != 0x0101)
34727 + RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f);
34728 + }
34729 +#endif // CONFIG_STA_SUPPORT //
34730 +
34731 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n"));
34732 + return NDIS_STATUS_SUCCESS;
34733 +}
34734 +
34735 +/*
34736 + ========================================================================
34737 +
34738 + Routine Description:
34739 + Reset NIC Asics
34740 +
34741 + Arguments:
34742 + Adapter Pointer to our adapter
34743 +
34744 + Return Value:
34745 + None
34746 +
34747 + IRQL = PASSIVE_LEVEL
34748 +
34749 + Note:
34750 + Reset NIC to initial state AS IS system boot up time.
34751 +
34752 + ========================================================================
34753 +*/
34754 +VOID NICIssueReset(
34755 + IN PRTMP_ADAPTER pAd)
34756 +{
34757 + UINT32 Value = 0;
34758 + DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n"));
34759 +
34760 + // Abort Tx, prevent ASIC from writing to Host memory
34761 + //RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x001f0000);
34762 +
34763 + // Disable Rx, register value supposed will remain after reset
34764 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
34765 + Value &= (0xfffffff3);
34766 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
34767 +
34768 + // Issue reset and clear from reset state
34769 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); // 2004-09-17 change from 0x01
34770 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00);
34771 +
34772 + DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n"));
34773 +}
34774 +
34775 +/*
34776 + ========================================================================
34777 +
34778 + Routine Description:
34779 + Check ASIC registers and find any reason the system might hang
34780 +
34781 + Arguments:
34782 + Adapter Pointer to our adapter
34783 +
34784 + Return Value:
34785 + None
34786 +
34787 + IRQL = DISPATCH_LEVEL
34788 +
34789 + ========================================================================
34790 +*/
34791 +BOOLEAN NICCheckForHang(
34792 + IN PRTMP_ADAPTER pAd)
34793 +{
34794 + return (FALSE);
34795 +}
34796 +
34797 +VOID NICUpdateFifoStaCounters(
34798 + IN PRTMP_ADAPTER pAd)
34799 +{
34800 + TX_STA_FIFO_STRUC StaFifo;
34801 + MAC_TABLE_ENTRY *pEntry;
34802 + UCHAR i = 0;
34803 + UCHAR pid = 0, wcid = 0;
34804 + CHAR reTry;
34805 + UCHAR succMCS;
34806 +
34807 +#ifdef RALINK_ATE
34808 + /* Nothing to do in ATE mode */
34809 + if (ATE_ON(pAd))
34810 + return;
34811 +#endif // RALINK_ATE //
34812 +
34813 + do
34814 + {
34815 + RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word);
34816 +
34817 + if (StaFifo.field.bValid == 0)
34818 + break;
34819 +
34820 + wcid = (UCHAR)StaFifo.field.wcid;
34821 +
34822 +
34823 + /* ignore NoACK and MGMT frame use 0xFF as WCID */
34824 + if ((StaFifo.field.TxAckRequired == 0) || (wcid >= MAX_LEN_OF_MAC_TABLE))
34825 + {
34826 + i++;
34827 + continue;
34828 + }
34829 +
34830 + /* PID store Tx MCS Rate */
34831 + pid = (UCHAR)StaFifo.field.PidType;
34832 +
34833 + pEntry = &pAd->MacTab.Content[wcid];
34834 +
34835 + pEntry->DebugFIFOCount++;
34836 +
34837 +#ifdef DOT11_N_SUPPORT
34838 + if (StaFifo.field.TxBF) // 3*3
34839 + pEntry->TxBFCount++;
34840 +#endif // DOT11_N_SUPPORT //
34841 +
34842 +#ifdef UAPSD_AP_SUPPORT
34843 + UAPSD_SP_AUE_Handle(pAd, pEntry, StaFifo.field.TxSuccess);
34844 +#endif // UAPSD_AP_SUPPORT //
34845 +
34846 + if (!StaFifo.field.TxSuccess)
34847 + {
34848 + pEntry->FIFOCount++;
34849 + pEntry->OneSecTxFailCount++;
34850 +
34851 + if (pEntry->FIFOCount >= 1)
34852 + {
34853 + DBGPRINT(RT_DEBUG_TRACE, ("#"));
34854 +#ifdef DOT11_N_SUPPORT
34855 + pEntry->NoBADataCountDown = 64;
34856 +#endif // DOT11_N_SUPPORT //
34857 +
34858 + if(pEntry->PsMode == PWR_ACTIVE)
34859 + {
34860 +#ifdef DOT11_N_SUPPORT
34861 + int tid;
34862 + for (tid=0; tid<NUM_OF_TID; tid++)
34863 + {
34864 + BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, FALSE);
34865 + }
34866 +#endif // DOT11_N_SUPPORT //
34867 +
34868 + // Update the continuous transmission counter except PS mode
34869 + pEntry->ContinueTxFailCnt++;
34870 + }
34871 + else
34872 + {
34873 + // Clear the FIFOCount when sta in Power Save mode. Basically we assume
34874 + // this tx error happened due to sta just go to sleep.
34875 + pEntry->FIFOCount = 0;
34876 + pEntry->ContinueTxFailCnt = 0;
34877 + }
34878 + //pEntry->FIFOCount = 0;
34879 + }
34880 + //pEntry->bSendBAR = TRUE;
34881 + }
34882 + else
34883 + {
34884 +#ifdef DOT11_N_SUPPORT
34885 + if ((pEntry->PsMode != PWR_SAVE) && (pEntry->NoBADataCountDown > 0))
34886 + {
34887 + pEntry->NoBADataCountDown--;
34888 + if (pEntry->NoBADataCountDown==0)
34889 + {
34890 + DBGPRINT(RT_DEBUG_TRACE, ("@\n"));
34891 + }
34892 + }
34893 +#endif // DOT11_N_SUPPORT //
34894 + pEntry->FIFOCount = 0;
34895 + pEntry->OneSecTxNoRetryOkCount++;
34896 + // update NoDataIdleCount when sucessful send packet to STA.
34897 + pEntry->NoDataIdleCount = 0;
34898 + pEntry->ContinueTxFailCnt = 0;
34899 + }
34900 +
34901 + succMCS = StaFifo.field.SuccessRate & 0x7F;
34902 +
34903 + reTry = pid - succMCS;
34904 +
34905 + if (StaFifo.field.TxSuccess)
34906 + {
34907 + pEntry->TXMCSExpected[pid]++;
34908 + if (pid == succMCS)
34909 + {
34910 + pEntry->TXMCSSuccessful[pid]++;
34911 + }
34912 + else
34913 + {
34914 + pEntry->TXMCSAutoFallBack[pid][succMCS]++;
34915 + }
34916 + }
34917 + else
34918 + {
34919 + pEntry->TXMCSFailed[pid]++;
34920 + }
34921 +
34922 + if (reTry > 0)
34923 + {
34924 + if ((pid >= 12) && succMCS <=7)
34925 + {
34926 + reTry -= 4;
34927 + }
34928 + pEntry->OneSecTxRetryOkCount += reTry;
34929 + }
34930 +
34931 + i++;
34932 + // ASIC store 16 stack
34933 + } while ( i < (2*TX_RING_SIZE) );
34934 +
34935 +}
34936 +
34937 +/*
34938 + ========================================================================
34939 +
34940 + Routine Description:
34941 + Read statistical counters from hardware registers and record them
34942 + in software variables for later on query
34943 +
34944 + Arguments:
34945 + pAd Pointer to our adapter
34946 +
34947 + Return Value:
34948 + None
34949 +
34950 + IRQL = DISPATCH_LEVEL
34951 +
34952 + ========================================================================
34953 +*/
34954 +VOID NICUpdateRawCounters(
34955 + IN PRTMP_ADAPTER pAd)
34956 +{
34957 + UINT32 OldValue;//, Value2;
34958 + //ULONG PageSum, OneSecTransmitCount;
34959 + //ULONG TxErrorRatio, Retry, Fail;
34960 + RX_STA_CNT0_STRUC RxStaCnt0;
34961 + RX_STA_CNT1_STRUC RxStaCnt1;
34962 + RX_STA_CNT2_STRUC RxStaCnt2;
34963 + TX_STA_CNT0_STRUC TxStaCnt0;
34964 + TX_STA_CNT1_STRUC StaTx1;
34965 + TX_STA_CNT2_STRUC StaTx2;
34966 + TX_AGG_CNT_STRUC TxAggCnt;
34967 + TX_AGG_CNT0_STRUC TxAggCnt0;
34968 + TX_AGG_CNT1_STRUC TxAggCnt1;
34969 + TX_AGG_CNT2_STRUC TxAggCnt2;
34970 + TX_AGG_CNT3_STRUC TxAggCnt3;
34971 + TX_AGG_CNT4_STRUC TxAggCnt4;
34972 + TX_AGG_CNT5_STRUC TxAggCnt5;
34973 + TX_AGG_CNT6_STRUC TxAggCnt6;
34974 + TX_AGG_CNT7_STRUC TxAggCnt7;
34975 +
34976 + RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word);
34977 + RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word);
34978 +
34979 + {
34980 + RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word);
34981 + // Update RX PLCP error counter
34982 + pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr;
34983 + // Update False CCA counter
34984 + pAd->RalinkCounters.OneSecFalseCCACnt += RxStaCnt1.field.FalseCca;
34985 + }
34986 +
34987 + // Update FCS counters
34988 + OldValue= pAd->WlanCounters.FCSErrorCount.u.LowPart;
34989 + pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); // >> 7);
34990 + if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue)
34991 + pAd->WlanCounters.FCSErrorCount.u.HighPart++;
34992 +
34993 + // Add FCS error count to private counters
34994 + pAd->RalinkCounters.OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr;
34995 + OldValue = pAd->RalinkCounters.RealFcsErrCount.u.LowPart;
34996 + pAd->RalinkCounters.RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr;
34997 + if (pAd->RalinkCounters.RealFcsErrCount.u.LowPart < OldValue)
34998 + pAd->RalinkCounters.RealFcsErrCount.u.HighPart++;
34999 +
35000 + // Update Duplicate Rcv check
35001 + pAd->RalinkCounters.DuplicateRcv += RxStaCnt2.field.RxDupliCount;
35002 + pAd->WlanCounters.FrameDuplicateCount.u.LowPart += RxStaCnt2.field.RxDupliCount;
35003 + // Update RX Overflow counter
35004 + pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount);
35005 +
35006 + //pAd->RalinkCounters.RxCount = 0;
35007 +#ifdef RT2870
35008 + if (pAd->RalinkCounters.RxCount != pAd->watchDogRxCnt)
35009 + {
35010 + pAd->watchDogRxCnt = pAd->RalinkCounters.RxCount;
35011 + pAd->watchDogRxOverFlowCnt = 0;
35012 + }
35013 + else
35014 + {
35015 + if (RxStaCnt2.field.RxFifoOverflowCount)
35016 + pAd->watchDogRxOverFlowCnt++;
35017 + else
35018 + pAd->watchDogRxOverFlowCnt = 0;
35019 + }
35020 +#endif // RT2870 //
35021 +
35022 +
35023 + //if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) ||
35024 + // (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) && (pAd->MacTab.Size != 1)))
35025 + if (!pAd->bUpdateBcnCntDone)
35026 + {
35027 + // Update BEACON sent count
35028 + RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
35029 + RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
35030 + RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word);
35031 + pAd->RalinkCounters.OneSecBeaconSentCnt += TxStaCnt0.field.TxBeaconCount;
35032 + pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit;
35033 + pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess;
35034 + pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount;
35035 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess;
35036 + pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit;
35037 + pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount;
35038 + }
35039 +
35040 + //if (pAd->bStaFifoTest == TRUE)
35041 + {
35042 + RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word);
35043 + RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word);
35044 + RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word);
35045 + RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word);
35046 + RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word);
35047 + RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word);
35048 + RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word);
35049 + RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word);
35050 + RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word);
35051 + pAd->RalinkCounters.TxAggCount += TxAggCnt.field.AggTxCount;
35052 + pAd->RalinkCounters.TxNonAggCount += TxAggCnt.field.NonAggTxCount;
35053 + pAd->RalinkCounters.TxAgg1MPDUCount += TxAggCnt0.field.AggSize1Count;
35054 + pAd->RalinkCounters.TxAgg2MPDUCount += TxAggCnt0.field.AggSize2Count;
35055 +
35056 + pAd->RalinkCounters.TxAgg3MPDUCount += TxAggCnt1.field.AggSize3Count;
35057 + pAd->RalinkCounters.TxAgg4MPDUCount += TxAggCnt1.field.AggSize4Count;
35058 + pAd->RalinkCounters.TxAgg5MPDUCount += TxAggCnt2.field.AggSize5Count;
35059 + pAd->RalinkCounters.TxAgg6MPDUCount += TxAggCnt2.field.AggSize6Count;
35060 +
35061 + pAd->RalinkCounters.TxAgg7MPDUCount += TxAggCnt3.field.AggSize7Count;
35062 + pAd->RalinkCounters.TxAgg8MPDUCount += TxAggCnt3.field.AggSize8Count;
35063 + pAd->RalinkCounters.TxAgg9MPDUCount += TxAggCnt4.field.AggSize9Count;
35064 + pAd->RalinkCounters.TxAgg10MPDUCount += TxAggCnt4.field.AggSize10Count;
35065 +
35066 + pAd->RalinkCounters.TxAgg11MPDUCount += TxAggCnt5.field.AggSize11Count;
35067 + pAd->RalinkCounters.TxAgg12MPDUCount += TxAggCnt5.field.AggSize12Count;
35068 + pAd->RalinkCounters.TxAgg13MPDUCount += TxAggCnt6.field.AggSize13Count;
35069 + pAd->RalinkCounters.TxAgg14MPDUCount += TxAggCnt6.field.AggSize14Count;
35070 +
35071 + pAd->RalinkCounters.TxAgg15MPDUCount += TxAggCnt7.field.AggSize15Count;
35072 + pAd->RalinkCounters.TxAgg16MPDUCount += TxAggCnt7.field.AggSize16Count;
35073 +
35074 + // Calculate the transmitted A-MPDU count
35075 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += TxAggCnt0.field.AggSize1Count;
35076 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt0.field.AggSize2Count / 2);
35077 +
35078 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize3Count / 3);
35079 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize4Count / 4);
35080 +
35081 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize5Count / 5);
35082 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize6Count / 6);
35083 +
35084 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize7Count / 7);
35085 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize8Count / 8);
35086 +
35087 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize9Count / 9);
35088 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize10Count / 10);
35089 +
35090 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize11Count / 11);
35091 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize12Count / 12);
35092 +
35093 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize13Count / 13);
35094 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize14Count / 14);
35095 +
35096 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize15Count / 15);
35097 + pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize16Count / 16);
35098 + }
35099 +
35100 +#ifdef DBG_DIAGNOSE
35101 + {
35102 + RtmpDiagStruct *pDiag;
35103 + COUNTER_RALINK *pRalinkCounters;
35104 + UCHAR ArrayCurIdx, i;
35105 +
35106 + pDiag = &pAd->DiagStruct;
35107 + pRalinkCounters = &pAd->RalinkCounters;
35108 + ArrayCurIdx = pDiag->ArrayCurIdx;
35109 +
35110 + if (pDiag->inited == 0)
35111 + {
35112 + NdisZeroMemory(pDiag, sizeof(struct _RtmpDiagStrcut_));
35113 + pDiag->ArrayStartIdx = pDiag->ArrayCurIdx = 0;
35114 + pDiag->inited = 1;
35115 + }
35116 + else
35117 + {
35118 + // Tx
35119 + pDiag->TxFailCnt[ArrayCurIdx] = TxStaCnt0.field.TxFailCount;
35120 + pDiag->TxAggCnt[ArrayCurIdx] = TxAggCnt.field.AggTxCount;
35121 + pDiag->TxNonAggCnt[ArrayCurIdx] = TxAggCnt.field.NonAggTxCount;
35122 + pDiag->TxAMPDUCnt[ArrayCurIdx][0] = TxAggCnt0.field.AggSize1Count;
35123 + pDiag->TxAMPDUCnt[ArrayCurIdx][1] = TxAggCnt0.field.AggSize2Count;
35124 + pDiag->TxAMPDUCnt[ArrayCurIdx][2] = TxAggCnt1.field.AggSize3Count;
35125 + pDiag->TxAMPDUCnt[ArrayCurIdx][3] = TxAggCnt1.field.AggSize4Count;
35126 + pDiag->TxAMPDUCnt[ArrayCurIdx][4] = TxAggCnt2.field.AggSize5Count;
35127 + pDiag->TxAMPDUCnt[ArrayCurIdx][5] = TxAggCnt2.field.AggSize6Count;
35128 + pDiag->TxAMPDUCnt[ArrayCurIdx][6] = TxAggCnt3.field.AggSize7Count;
35129 + pDiag->TxAMPDUCnt[ArrayCurIdx][7] = TxAggCnt3.field.AggSize8Count;
35130 + pDiag->TxAMPDUCnt[ArrayCurIdx][8] = TxAggCnt4.field.AggSize9Count;
35131 + pDiag->TxAMPDUCnt[ArrayCurIdx][9] = TxAggCnt4.field.AggSize10Count;
35132 + pDiag->TxAMPDUCnt[ArrayCurIdx][10] = TxAggCnt5.field.AggSize11Count;
35133 + pDiag->TxAMPDUCnt[ArrayCurIdx][11] = TxAggCnt5.field.AggSize12Count;
35134 + pDiag->TxAMPDUCnt[ArrayCurIdx][12] = TxAggCnt6.field.AggSize13Count;
35135 + pDiag->TxAMPDUCnt[ArrayCurIdx][13] = TxAggCnt6.field.AggSize14Count;
35136 + pDiag->TxAMPDUCnt[ArrayCurIdx][14] = TxAggCnt7.field.AggSize15Count;
35137 + pDiag->TxAMPDUCnt[ArrayCurIdx][15] = TxAggCnt7.field.AggSize16Count;
35138 +
35139 + pDiag->RxCrcErrCnt[ArrayCurIdx] = RxStaCnt0.field.CrcErr;
35140 +
35141 + INC_RING_INDEX(pDiag->ArrayCurIdx, DIAGNOSE_TIME);
35142 + ArrayCurIdx = pDiag->ArrayCurIdx;
35143 + for (i =0; i < 9; i++)
35144 + {
35145 + pDiag->TxDescCnt[ArrayCurIdx][i]= 0;
35146 + pDiag->TxSWQueCnt[ArrayCurIdx][i] =0;
35147 + pDiag->TxMcsCnt[ArrayCurIdx][i] = 0;
35148 + pDiag->RxMcsCnt[ArrayCurIdx][i] = 0;
35149 + }
35150 + pDiag->TxDataCnt[ArrayCurIdx] = 0;
35151 + pDiag->TxFailCnt[ArrayCurIdx] = 0;
35152 + pDiag->RxDataCnt[ArrayCurIdx] = 0;
35153 + pDiag->RxCrcErrCnt[ArrayCurIdx] = 0;
35154 +// for (i = 9; i < 16; i++)
35155 + for (i = 9; i < 24; i++) // 3*3
35156 + {
35157 + pDiag->TxDescCnt[ArrayCurIdx][i] = 0;
35158 + pDiag->TxMcsCnt[ArrayCurIdx][i] = 0;
35159 + pDiag->RxMcsCnt[ArrayCurIdx][i] = 0;
35160 +}
35161 +
35162 + if (pDiag->ArrayCurIdx == pDiag->ArrayStartIdx)
35163 + INC_RING_INDEX(pDiag->ArrayStartIdx, DIAGNOSE_TIME);
35164 + }
35165 +
35166 + }
35167 +#endif // DBG_DIAGNOSE //
35168 +
35169 +
35170 +}
35171 +
35172 +
35173 +/*
35174 + ========================================================================
35175 +
35176 + Routine Description:
35177 + Reset NIC from error
35178 +
35179 + Arguments:
35180 + Adapter Pointer to our adapter
35181 +
35182 + Return Value:
35183 + None
35184 +
35185 + IRQL = PASSIVE_LEVEL
35186 +
35187 + Note:
35188 + Reset NIC from error state
35189 +
35190 + ========================================================================
35191 +*/
35192 +VOID NICResetFromError(
35193 + IN PRTMP_ADAPTER pAd)
35194 +{
35195 + // Reset BBP (according to alex, reset ASIC will force reset BBP
35196 + // Therefore, skip the reset BBP
35197 + // RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2);
35198 +
35199 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
35200 + // Remove ASIC from reset state
35201 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
35202 +
35203 + NICInitializeAdapter(pAd, FALSE);
35204 + NICInitAsicFromEEPROM(pAd);
35205 +
35206 + // Switch to current channel, since during reset process, the connection should remains on.
35207 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
35208 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
35209 +}
35210 +
35211 +/*
35212 + ========================================================================
35213 +
35214 + Routine Description:
35215 + erase 8051 firmware image in MAC ASIC
35216 +
35217 + Arguments:
35218 + Adapter Pointer to our adapter
35219 +
35220 + IRQL = PASSIVE_LEVEL
35221 +
35222 + ========================================================================
35223 +*/
35224 +VOID NICEraseFirmware(
35225 + IN PRTMP_ADAPTER pAd)
35226 +{
35227 + ULONG i;
35228 +
35229 + for(i=0; i<MAX_FIRMWARE_IMAGE_SIZE; i+=4)
35230 + RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, 0);
35231 +
35232 +}/* End of NICEraseFirmware */
35233 +
35234 +/*
35235 + ========================================================================
35236 +
35237 + Routine Description:
35238 + Load 8051 firmware RT2561.BIN file into MAC ASIC
35239 +
35240 + Arguments:
35241 + Adapter Pointer to our adapter
35242 +
35243 + Return Value:
35244 + NDIS_STATUS_SUCCESS firmware image load ok
35245 + NDIS_STATUS_FAILURE image not found
35246 +
35247 + IRQL = PASSIVE_LEVEL
35248 +
35249 + ========================================================================
35250 +*/
35251 +NDIS_STATUS NICLoadFirmware(
35252 + IN PRTMP_ADAPTER pAd)
35253 +{
35254 +#ifdef BIN_IN_FILE
35255 +#define NICLF_DEFAULT_USE() \
35256 + flg_default_firm_use = TRUE; \
35257 + printk("%s - Use default firmware!\n", __FUNCTION__);
35258 +
35259 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
35260 + PUCHAR src;
35261 + struct file *srcf;
35262 + INT retval, orgfsuid, orgfsgid, i;
35263 + mm_segment_t orgfs;
35264 + PUCHAR pFirmwareImage;
35265 + UINT FileLength = 0;
35266 + UINT32 MacReg;
35267 + ULONG Index;
35268 + ULONG firm;
35269 + BOOLEAN flg_default_firm_use = FALSE;
35270 +
35271 +
35272 + DBGPRINT(RT_DEBUG_TRACE, ("===> %s\n", __FUNCTION__));
35273 +
35274 + /* init */
35275 + pFirmwareImage = NULL;
35276 + src = RTMP_FIRMWARE_FILE_NAME;
35277 +
35278 + /* save uid and gid used for filesystem access.
35279 + set user and group to 0 (root) */
35280 + orgfsuid = current->fsuid;
35281 + orgfsgid = current->fsgid;
35282 + current->fsuid = current->fsgid = 0;
35283 + orgfs = get_fs();
35284 + set_fs(KERNEL_DS);
35285 +
35286 + pAd->FirmwareVersion = (FIRMWARE_MAJOR_VERSION << 8) + \
35287 + FIRMWARE_MINOR_VERSION;
35288 +
35289 +
35290 + /* allocate firmware buffer */
35291 + pFirmwareImage = kmalloc(MAX_FIRMWARE_IMAGE_SIZE, MEM_ALLOC_FLAG);
35292 + if (pFirmwareImage == NULL)
35293 + {
35294 + /* allocate fail, use default firmware array in firmware.h */
35295 + printk("%s - Allocate memory fail!\n", __FUNCTION__);
35296 + NICLF_DEFAULT_USE();
35297 + }
35298 + else
35299 + {
35300 + /* allocate ok! zero the firmware buffer */
35301 + memset(pFirmwareImage, 0x00, MAX_FIRMWARE_IMAGE_SIZE);
35302 + } /* End of if */
35303 +
35304 +
35305 + /* if ok, read firmware file from *.bin file */
35306 + if (flg_default_firm_use == FALSE)
35307 + {
35308 + do
35309 + {
35310 + /* open the bin file */
35311 + srcf = filp_open(src, O_RDONLY, 0);
35312 +
35313 + if (IS_ERR(srcf))
35314 + {
35315 + printk("%s - Error %ld opening %s\n",
35316 + __FUNCTION__, -PTR_ERR(srcf), src);
35317 + NICLF_DEFAULT_USE();
35318 + break;
35319 + } /* End of if */
35320 +
35321 + /* the object must have a read method */
35322 + if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
35323 + {
35324 + printk("%s - %s does not have a write method\n", __FUNCTION__, src);
35325 + NICLF_DEFAULT_USE();
35326 + break;
35327 + } /* End of if */
35328 +
35329 + /* read the firmware from the file *.bin */
35330 + FileLength = srcf->f_op->read(srcf,
35331 + pFirmwareImage,
35332 + MAX_FIRMWARE_IMAGE_SIZE,
35333 + &srcf->f_pos);
35334 +
35335 + if (FileLength != MAX_FIRMWARE_IMAGE_SIZE)
35336 + {
35337 + printk("%s: error file length (=%d) in RT2860AP.BIN\n",
35338 + __FUNCTION__, FileLength);
35339 + NICLF_DEFAULT_USE();
35340 + break;
35341 + }
35342 + else
35343 + {
35344 + PUCHAR ptr = pFirmwareImage;
35345 + USHORT crc = 0xffff;
35346 +
35347 +
35348 + /* calculate firmware CRC */
35349 + for(i=0; i<(MAX_FIRMWARE_IMAGE_SIZE-2); i++, ptr++)
35350 + crc = ByteCRC16(BitReverse(*ptr), crc);
35351 + /* End of for */
35352 +
35353 + if ((pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-2] != \
35354 + (UCHAR)BitReverse((UCHAR)(crc>>8))) ||
35355 + (pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-1] != \
35356 + (UCHAR)BitReverse((UCHAR)crc)))
35357 + {
35358 + /* CRC fail */
35359 + printk("%s: CRC = 0x%02x 0x%02x "
35360 + "error, should be 0x%02x 0x%02x\n",
35361 + __FUNCTION__,
35362 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-2],
35363 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-1],
35364 + (UCHAR)(crc>>8), (UCHAR)(crc));
35365 + NICLF_DEFAULT_USE();
35366 + break;
35367 + }
35368 + else
35369 + {
35370 + /* firmware is ok */
35371 + pAd->FirmwareVersion = \
35372 + (pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-4] << 8) +
35373 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-3];
35374 +
35375 + /* check if firmware version of the file is too old */
35376 + if ((pAd->FirmwareVersion) < \
35377 + ((FIRMWARE_MAJOR_VERSION << 8) +
35378 + FIRMWARE_MINOR_VERSION))
35379 + {
35380 + printk("%s: firmware version too old!\n", __FUNCTION__);
35381 + NICLF_DEFAULT_USE();
35382 + break;
35383 + } /* End of if */
35384 + } /* End of if */
35385 +
35386 + DBGPRINT(RT_DEBUG_TRACE,
35387 + ("NICLoadFirmware: CRC ok, ver=%d.%d\n",
35388 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-4],
35389 + pFirmwareImage[MAX_FIRMWARE_IMAGE_SIZE-3]));
35390 + } /* End of if (FileLength == MAX_FIRMWARE_IMAGE_SIZE) */
35391 + break;
35392 + } while(TRUE);
35393 +
35394 + /* close firmware file */
35395 + if (IS_ERR(srcf))
35396 + ;
35397 + else
35398 + {
35399 + retval = filp_close(srcf, NULL);
35400 + if (retval)
35401 + {
35402 + DBGPRINT(RT_DEBUG_ERROR,
35403 + ("--> Error %d closing %s\n", -retval, src));
35404 + } /* End of if */
35405 + } /* End of if */
35406 + } /* End of if */
35407 +
35408 +
35409 + /* write firmware to ASIC */
35410 + if (flg_default_firm_use == TRUE)
35411 + {
35412 + /* use default fimeware, free allocated buffer */
35413 + if (pFirmwareImage != NULL)
35414 + kfree(pFirmwareImage);
35415 + /* End of if */
35416 +
35417 + /* use default *.bin array */
35418 + pFirmwareImage = FirmwareImage;
35419 + FileLength = sizeof(FirmwareImage);
35420 + } /* End of if */
35421 +
35422 + /* enable Host program ram write selection */
35423 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x10000);
35424 +
35425 + for(i=0; i<FileLength; i+=4)
35426 + {
35427 + firm = pFirmwareImage[i] +
35428 + (pFirmwareImage[i+3] << 24) +
35429 + (pFirmwareImage[i+2] << 16) +
35430 + (pFirmwareImage[i+1] << 8);
35431 +
35432 + RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, firm);
35433 + } /* End of for */
35434 +
35435 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x00000);
35436 + RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x00001);
35437 +
35438 + /* initialize BBP R/W access agent */
35439 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0);
35440 + RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
35441 +
35442 + if (flg_default_firm_use == FALSE)
35443 + {
35444 + /* use file firmware, free allocated buffer */
35445 + if (pFirmwareImage != NULL)
35446 + kfree(pFirmwareImage);
35447 + /* End of if */
35448 + } /* End of if */
35449 +
35450 + set_fs(orgfs);
35451 + current->fsuid = orgfsuid;
35452 + current->fsgid = orgfsgid;
35453 +#else
35454 +
35455 + NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
35456 + PUCHAR pFirmwareImage;
35457 + ULONG FileLength, Index;
35458 + //ULONG firm;
35459 + UINT32 MacReg = 0;
35460 + UINT32 Version = (pAd->MACVersion >> 16);
35461 +
35462 + pFirmwareImage = FirmwareImage;
35463 + FileLength = sizeof(FirmwareImage);
35464 +
35465 + // New 8k byte firmware size for RT3071/RT3072
35466 + //printk("Usb Chip\n");
35467 + if (FIRMWAREIMAGE_LENGTH == FIRMWAREIMAGE_MAX_LENGTH)
35468 + //The firmware image consists of two parts. One is the origianl and the other is the new.
35469 + //Use Second Part
35470 + {
35471 +#ifdef RT2870
35472 + if ((Version != 0x2860) && (Version != 0x2872) && (Version != 0x3070))
35473 + { // Use Firmware V2.
35474 + //printk("KH:Use New Version,part2\n");
35475 + pFirmwareImage = (PUCHAR)&FirmwareImage[FIRMWAREIMAGEV1_LENGTH];
35476 + FileLength = FIRMWAREIMAGEV2_LENGTH;
35477 + }
35478 + else
35479 + {
35480 + //printk("KH:Use New Version,part1\n");
35481 + pFirmwareImage = FirmwareImage;
35482 + FileLength = FIRMWAREIMAGEV1_LENGTH;
35483 + }
35484 +#endif // RT2870 //
35485 + }
35486 + else
35487 + {
35488 + DBGPRINT(RT_DEBUG_ERROR, ("KH: bin file should be 8KB.\n"));
35489 + Status = NDIS_STATUS_FAILURE;
35490 + }
35491 +
35492 + RT28XX_WRITE_FIRMWARE(pAd, pFirmwareImage, FileLength);
35493 +
35494 +#endif
35495 +
35496 + /* check if MCU is ready */
35497 + Index = 0;
35498 + do
35499 + {
35500 + RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacReg);
35501 +
35502 + if (MacReg & 0x80)
35503 + break;
35504 +
35505 + RTMPusecDelay(1000);
35506 + } while (Index++ < 1000);
35507 +
35508 + if (Index >= 1000)
35509 + {
35510 + Status = NDIS_STATUS_FAILURE;
35511 + DBGPRINT(RT_DEBUG_ERROR, ("NICLoadFirmware: MCU is not ready\n\n\n"));
35512 + } /* End of if */
35513 +
35514 + DBGPRINT(RT_DEBUG_TRACE,
35515 + ("<=== %s (status=%d)\n", __FUNCTION__, Status));
35516 + return Status;
35517 +} /* End of NICLoadFirmware */
35518 +
35519 +
35520 +/*
35521 + ========================================================================
35522 +
35523 + Routine Description:
35524 + Load Tx rate switching parameters
35525 +
35526 + Arguments:
35527 + Adapter Pointer to our adapter
35528 +
35529 + Return Value:
35530 + NDIS_STATUS_SUCCESS firmware image load ok
35531 + NDIS_STATUS_FAILURE image not found
35532 +
35533 + IRQL = PASSIVE_LEVEL
35534 +
35535 + Rate Table Format:
35536 + 1. (B0: Valid Item number) (B1:Initial item from zero)
35537 + 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec)
35538 +
35539 + ========================================================================
35540 +*/
35541 +NDIS_STATUS NICLoadRateSwitchingParams(
35542 + IN PRTMP_ADAPTER pAd)
35543 +{
35544 + return NDIS_STATUS_SUCCESS;
35545 +}
35546 +
35547 +/*
35548 + ========================================================================
35549 +
35550 + Routine Description:
35551 + if pSrc1 all zero with length Length, return 0.
35552 + If not all zero, return 1
35553 +
35554 + Arguments:
35555 + pSrc1
35556 +
35557 + Return Value:
35558 + 1: not all zero
35559 + 0: all zero
35560 +
35561 + IRQL = DISPATCH_LEVEL
35562 +
35563 + Note:
35564 +
35565 + ========================================================================
35566 +*/
35567 +ULONG RTMPNotAllZero(
35568 + IN PVOID pSrc1,
35569 + IN ULONG Length)
35570 +{
35571 + PUCHAR pMem1;
35572 + ULONG Index = 0;
35573 +
35574 + pMem1 = (PUCHAR) pSrc1;
35575 +
35576 + for (Index = 0; Index < Length; Index++)
35577 + {
35578 + if (pMem1[Index] != 0x0)
35579 + {
35580 + break;
35581 + }
35582 + }
35583 +
35584 + if (Index == Length)
35585 + {
35586 + return (0);
35587 + }
35588 + else
35589 + {
35590 + return (1);
35591 + }
35592 +}
35593 +
35594 +/*
35595 + ========================================================================
35596 +
35597 + Routine Description:
35598 + Compare two memory block
35599 +
35600 + Arguments:
35601 + pSrc1 Pointer to first memory address
35602 + pSrc2 Pointer to second memory address
35603 +
35604 + Return Value:
35605 + 0: memory is equal
35606 + 1: pSrc1 memory is larger
35607 + 2: pSrc2 memory is larger
35608 +
35609 + IRQL = DISPATCH_LEVEL
35610 +
35611 + Note:
35612 +
35613 + ========================================================================
35614 +*/
35615 +ULONG RTMPCompareMemory(
35616 + IN PVOID pSrc1,
35617 + IN PVOID pSrc2,
35618 + IN ULONG Length)
35619 +{
35620 + PUCHAR pMem1;
35621 + PUCHAR pMem2;
35622 + ULONG Index = 0;
35623 +
35624 + pMem1 = (PUCHAR) pSrc1;
35625 + pMem2 = (PUCHAR) pSrc2;
35626 +
35627 + for (Index = 0; Index < Length; Index++)
35628 + {
35629 + if (pMem1[Index] > pMem2[Index])
35630 + return (1);
35631 + else if (pMem1[Index] < pMem2[Index])
35632 + return (2);
35633 + }
35634 +
35635 + // Equal
35636 + return (0);
35637 +}
35638 +
35639 +/*
35640 + ========================================================================
35641 +
35642 + Routine Description:
35643 + Zero out memory block
35644 +
35645 + Arguments:
35646 + pSrc1 Pointer to memory address
35647 + Length Size
35648 +
35649 + Return Value:
35650 + None
35651 +
35652 + IRQL = PASSIVE_LEVEL
35653 + IRQL = DISPATCH_LEVEL
35654 +
35655 + Note:
35656 +
35657 + ========================================================================
35658 +*/
35659 +VOID RTMPZeroMemory(
35660 + IN PVOID pSrc,
35661 + IN ULONG Length)
35662 +{
35663 + PUCHAR pMem;
35664 + ULONG Index = 0;
35665 +
35666 + pMem = (PUCHAR) pSrc;
35667 +
35668 + for (Index = 0; Index < Length; Index++)
35669 + {
35670 + pMem[Index] = 0x00;
35671 + }
35672 +}
35673 +
35674 +VOID RTMPFillMemory(
35675 + IN PVOID pSrc,
35676 + IN ULONG Length,
35677 + IN UCHAR Fill)
35678 +{
35679 + PUCHAR pMem;
35680 + ULONG Index = 0;
35681 +
35682 + pMem = (PUCHAR) pSrc;
35683 +
35684 + for (Index = 0; Index < Length; Index++)
35685 + {
35686 + pMem[Index] = Fill;
35687 + }
35688 +}
35689 +
35690 +/*
35691 + ========================================================================
35692 +
35693 + Routine Description:
35694 + Copy data from memory block 1 to memory block 2
35695 +
35696 + Arguments:
35697 + pDest Pointer to destination memory address
35698 + pSrc Pointer to source memory address
35699 + Length Copy size
35700 +
35701 + Return Value:
35702 + None
35703 +
35704 + IRQL = PASSIVE_LEVEL
35705 + IRQL = DISPATCH_LEVEL
35706 +
35707 + Note:
35708 +
35709 + ========================================================================
35710 +*/
35711 +VOID RTMPMoveMemory(
35712 + OUT PVOID pDest,
35713 + IN PVOID pSrc,
35714 + IN ULONG Length)
35715 +{
35716 + PUCHAR pMem1;
35717 + PUCHAR pMem2;
35718 + UINT Index;
35719 +
35720 + ASSERT((Length==0) || (pDest && pSrc));
35721 +
35722 + pMem1 = (PUCHAR) pDest;
35723 + pMem2 = (PUCHAR) pSrc;
35724 +
35725 + for (Index = 0; Index < Length; Index++)
35726 + {
35727 + pMem1[Index] = pMem2[Index];
35728 + }
35729 +}
35730 +
35731 +/*
35732 + ========================================================================
35733 +
35734 + Routine Description:
35735 + Initialize port configuration structure
35736 +
35737 + Arguments:
35738 + Adapter Pointer to our adapter
35739 +
35740 + Return Value:
35741 + None
35742 +
35743 + IRQL = PASSIVE_LEVEL
35744 +
35745 + Note:
35746 +
35747 + ========================================================================
35748 +*/
35749 +VOID UserCfgInit(
35750 + IN PRTMP_ADAPTER pAd)
35751 +{
35752 +// EDCA_PARM DefaultEdcaParm;
35753 + UINT key_index, bss_index;
35754 +
35755 + DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n"));
35756 +
35757 + //
35758 + // part I. intialize common configuration
35759 + //
35760 +#ifdef RT2870
35761 + pAd->BulkOutReq = 0;
35762 +
35763 + pAd->BulkOutComplete = 0;
35764 + pAd->BulkOutCompleteOther = 0;
35765 + pAd->BulkOutCompleteCancel = 0;
35766 + pAd->BulkInReq = 0;
35767 + pAd->BulkInComplete = 0;
35768 + pAd->BulkInCompleteFail = 0;
35769 +
35770 + //pAd->QuickTimerP = 100;
35771 + //pAd->TurnAggrBulkInCount = 0;
35772 + pAd->bUsbTxBulkAggre = 0;
35773 +
35774 + // init as unsed value to ensure driver will set to MCU once.
35775 + pAd->LedIndicatorStregth = 0xFF;
35776 +
35777 + pAd->CommonCfg.MaxPktOneTxBulk = 2;
35778 + pAd->CommonCfg.TxBulkFactor = 1;
35779 + pAd->CommonCfg.RxBulkFactor =1;
35780 +
35781 + pAd->CommonCfg.TxPower = 100; //mW
35782 +
35783 + NdisZeroMemory(&pAd->CommonCfg.IOTestParm, sizeof(pAd->CommonCfg.IOTestParm));
35784 +#endif // RT2870 //
35785 +
35786 + for(key_index=0; key_index<SHARE_KEY_NUM; key_index++)
35787 + {
35788 + for(bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++)
35789 + {
35790 + pAd->SharedKey[bss_index][key_index].KeyLen = 0;
35791 + pAd->SharedKey[bss_index][key_index].CipherAlg = CIPHER_NONE;
35792 + } /* End of for */
35793 + } /* End of for */
35794 +
35795 + pAd->EepromAccess = FALSE;
35796 +
35797 + pAd->Antenna.word = 0;
35798 + pAd->CommonCfg.BBPCurrentBW = BW_20;
35799 +
35800 + pAd->LedCntl.word = 0;
35801 +
35802 + pAd->bAutoTxAgcA = FALSE; // Default is OFF
35803 + pAd->bAutoTxAgcG = FALSE; // Default is OFF
35804 + pAd->RfIcType = RFIC_2820;
35805 +
35806 + // Init timer for reset complete event
35807 + pAd->CommonCfg.CentralChannel = 1;
35808 + pAd->bForcePrintTX = FALSE;
35809 + pAd->bForcePrintRX = FALSE;
35810 + pAd->bStaFifoTest = FALSE;
35811 + pAd->bProtectionTest = FALSE;
35812 + pAd->bHCCATest = FALSE;
35813 + pAd->bGenOneHCCA = FALSE;
35814 + pAd->CommonCfg.Dsifs = 10; // in units of usec
35815 + pAd->CommonCfg.TxPower = 100; //mW
35816 + pAd->CommonCfg.TxPowerPercentage = 0xffffffff; // AUTO
35817 + pAd->CommonCfg.TxPowerDefault = 0xffffffff; // AUTO
35818 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; // use Long preamble on TX by defaut
35819 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
35820 + pAd->CommonCfg.RtsThreshold = 2347;
35821 + pAd->CommonCfg.FragmentThreshold = 2346;
35822 + pAd->CommonCfg.UseBGProtection = 0; // 0: AUTO
35823 + pAd->CommonCfg.bEnableTxBurst = TRUE; //0;
35824 + pAd->CommonCfg.PhyMode = 0xff; // unknown
35825 + pAd->CommonCfg.BandState = UNKNOWN_BAND;
35826 + pAd->CommonCfg.RadarDetect.CSPeriod = 10;
35827 + pAd->CommonCfg.RadarDetect.CSCount = 0;
35828 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
35829 + pAd->CommonCfg.RadarDetect.ChMovingTime = 65;
35830 + pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3;
35831 + pAd->CommonCfg.bAPSDCapable = FALSE;
35832 + pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
35833 + pAd->CommonCfg.TriggerTimerCount = 0;
35834 + pAd->CommonCfg.bAPSDForcePowerSave = FALSE;
35835 + pAd->CommonCfg.bCountryFlag = FALSE;
35836 + pAd->CommonCfg.TxStream = 0;
35837 + pAd->CommonCfg.RxStream = 0;
35838 +
35839 + NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI));
35840 +
35841 +#ifdef DOT11_N_SUPPORT
35842 + NdisZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
35843 + pAd->HTCEnable = FALSE;
35844 + pAd->bBroadComHT = FALSE;
35845 + pAd->CommonCfg.bRdg = FALSE;
35846 +
35847 +#ifdef DOT11N_DRAFT3
35848 + pAd->CommonCfg.Dot11OBssScanPassiveDwell = dot11OBSSScanPassiveDwell; // Unit : TU. 5~1000
35849 + pAd->CommonCfg.Dot11OBssScanActiveDwell = dot11OBSSScanActiveDwell; // Unit : TU. 10~1000
35850 + pAd->CommonCfg.Dot11BssWidthTriggerScanInt = dot11BSSWidthTriggerScanInterval; // Unit : Second
35851 + pAd->CommonCfg.Dot11OBssScanPassiveTotalPerChannel = dot11OBSSScanPassiveTotalPerChannel; // Unit : TU. 200~10000
35852 + pAd->CommonCfg.Dot11OBssScanActiveTotalPerChannel = dot11OBSSScanActiveTotalPerChannel; // Unit : TU. 20~10000
35853 + pAd->CommonCfg.Dot11BssWidthChanTranDelayFactor = dot11BSSWidthChannelTransactionDelayFactor;
35854 + pAd->CommonCfg.Dot11OBssScanActivityThre = dot11BSSScanActivityThreshold; // Unit : percentage
35855 + pAd->CommonCfg.Dot11BssWidthChanTranDelay = (pAd->CommonCfg.Dot11BssWidthTriggerScanInt * pAd->CommonCfg.Dot11BssWidthChanTranDelayFactor);
35856 +#endif // DOT11N_DRAFT3 //
35857 +
35858 + NdisZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
35859 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
35860 + pAd->CommonCfg.BACapability.field.MpduDensity = 0;
35861 + pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
35862 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; //32;
35863 + pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; //32;
35864 + DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit. BACapability = 0x%x\n", pAd->CommonCfg.BACapability.word));
35865 +
35866 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
35867 + BATableInit(pAd, &pAd->BATable);
35868 +
35869 + pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1;
35870 + pAd->CommonCfg.bHTProtect = 1;
35871 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
35872 + pAd->CommonCfg.bBADecline = FALSE;
35873 + pAd->CommonCfg.bDisableReordering = FALSE;
35874 +
35875 + pAd->CommonCfg.TxBASize = 7;
35876 +
35877 + pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word;
35878 +#endif // DOT11_N_SUPPORT //
35879 +
35880 + //pAd->CommonCfg.HTPhyMode.field.BW = BW_20;
35881 + //pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO;
35882 + //pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800;
35883 + //pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE;
35884 + pAd->CommonCfg.TxRate = RATE_6;
35885 +
35886 + pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6;
35887 + pAd->CommonCfg.MlmeTransmit.field.BW = BW_20;
35888 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
35889 +
35890 + pAd->CommonCfg.BeaconPeriod = 100; // in mSec
35891 +
35892 + //
35893 + // part II. intialize STA specific configuration
35894 + //
35895 +#ifdef CONFIG_STA_SUPPORT
35896 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
35897 + {
35898 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT);
35899 + RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST);
35900 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST);
35901 + RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST);
35902 +
35903 + pAd->StaCfg.Psm = PWR_ACTIVE;
35904 +
35905 + pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled;
35906 + pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled;
35907 + pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled;
35908 + pAd->StaCfg.bMixCipher = FALSE;
35909 + pAd->StaCfg.DefaultKeyId = 0;
35910 +
35911 + // 802.1x port control
35912 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
35913 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
35914 + pAd->StaCfg.LastMicErrorTime = 0;
35915 + pAd->StaCfg.MicErrCnt = 0;
35916 + pAd->StaCfg.bBlockAssoc = FALSE;
35917 + pAd->StaCfg.WpaState = SS_NOTUSE;
35918 +
35919 + pAd->CommonCfg.NdisRadioStateOff = FALSE; // New to support microsoft disable radio with OID command
35920 +
35921 + pAd->StaCfg.RssiTrigger = 0;
35922 + NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(RSSI_SAMPLE));
35923 + pAd->StaCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
35924 + pAd->StaCfg.AtimWin = 0;
35925 + pAd->StaCfg.DefaultListenCount = 3;//default listen count;
35926 + pAd->StaCfg.BssType = BSS_INFRA; // BSS_INFRA or BSS_ADHOC or BSS_MONITOR
35927 + pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
35928 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
35929 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
35930 +
35931 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
35932 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
35933 + }
35934 +
35935 +#ifdef EXT_BUILD_CHANNEL_LIST
35936 + pAd->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
35937 +#endif // EXT_BUILD_CHANNEL_LIST //
35938 +#endif // CONFIG_STA_SUPPORT //
35939 +
35940 + // global variables mXXXX used in MAC protocol state machines
35941 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
35942 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
35943 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
35944 +
35945 + // PHY specification
35946 + pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; // default PHY mode
35947 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); // CCK use LONG preamble
35948 +
35949 +#ifdef CONFIG_STA_SUPPORT
35950 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
35951 + {
35952 + // user desired power mode
35953 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
35954 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
35955 + pAd->StaCfg.bWindowsACCAMEnable = FALSE;
35956 +
35957 +#ifdef LEAP_SUPPORT
35958 + // CCX v1.0 releated init value
35959 + RTMPInitTimer(pAd, &pAd->StaCfg.LeapAuthTimer, GET_TIMER_FUNCTION(LeapAuthTimeout), pAd, FALSE);
35960 + pAd->StaCfg.LeapAuthMode = CISCO_AuthModeLEAPNone;
35961 + pAd->StaCfg.bCkipOn = FALSE;
35962 +#endif // LEAP_SUPPORT //
35963 +
35964 + RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer, GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec), pAd, FALSE);
35965 + pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
35966 +
35967 + // Patch for Ndtest
35968 + pAd->StaCfg.ScanCnt = 0;
35969 +
35970 + // CCX 2.0 control flag init
35971 + pAd->StaCfg.CCXEnable = FALSE;
35972 + pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED;
35973 + pAd->StaCfg.CCXQosECWMin = 4;
35974 + pAd->StaCfg.CCXQosECWMax = 10;
35975 +
35976 + pAd->StaCfg.bHwRadio = TRUE; // Default Hardware Radio status is On
35977 + pAd->StaCfg.bSwRadio = TRUE; // Default Software Radio status is On
35978 + pAd->StaCfg.bRadio = TRUE; // bHwRadio && bSwRadio
35979 + pAd->StaCfg.bHardwareRadio = FALSE; // Default is OFF
35980 + pAd->StaCfg.bShowHiddenSSID = FALSE; // Default no show
35981 +
35982 + // Nitro mode control
35983 + pAd->StaCfg.bAutoReconnect = TRUE;
35984 +
35985 + // Save the init time as last scan time, the system should do scan after 2 seconds.
35986 + // This patch is for driver wake up from standby mode, system will do scan right away.
35987 + pAd->StaCfg.LastScanTime = 0;
35988 + NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE+1);
35989 + sprintf(pAd->nickname, "%s", STA_NIC_DEVICE_NAME);
35990 + RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer, GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc), pAd, FALSE);
35991 +#ifdef WPA_SUPPLICANT_SUPPORT
35992 + pAd->StaCfg.IEEE8021X = FALSE;
35993 + pAd->StaCfg.IEEE8021x_required_keys = FALSE;
35994 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
35995 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
35996 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
35997 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
35998 +#endif // WPA_SUPPLICANT_SUPPORT //
35999 +
36000 + }
36001 +#endif // CONFIG_STA_SUPPORT //
36002 +
36003 + // Default for extra information is not valid
36004 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
36005 +
36006 + // Default Config change flag
36007 + pAd->bConfigChanged = FALSE;
36008 +
36009 + //
36010 + // part III. AP configurations
36011 + //
36012 +
36013 +
36014 + //
36015 + // part IV. others
36016 + //
36017 + // dynamic BBP R66:sensibity tuning to overcome background noise
36018 + pAd->BbpTuning.bEnable = TRUE;
36019 + pAd->BbpTuning.FalseCcaLowerThreshold = 100;
36020 + pAd->BbpTuning.FalseCcaUpperThreshold = 512;
36021 + pAd->BbpTuning.R66Delta = 4;
36022 + pAd->Mlme.bEnableAutoAntennaCheck = TRUE;
36023 +
36024 + //
36025 + // Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value.
36026 + // if not initial this value, the default value will be 0.
36027 + //
36028 + pAd->BbpTuning.R66CurrentValue = 0x38;
36029 +
36030 + pAd->Bbp94 = BBPR94_DEFAULT;
36031 + pAd->BbpForCCK = FALSE;
36032 +
36033 + // Default is FALSE for test bit 1
36034 + //pAd->bTest1 = FALSE;
36035 +
36036 + // initialize MAC table and allocate spin lock
36037 + NdisZeroMemory(&pAd->MacTab, sizeof(MAC_TABLE));
36038 + InitializeQueueHeader(&pAd->MacTab.McastPsQueue);
36039 + NdisAllocateSpinLock(&pAd->MacTabLock);
36040 +
36041 + //RTMPInitTimer(pAd, &pAd->RECBATimer, RECBATimerTimeout, pAd, TRUE);
36042 + //RTMPSetTimer(&pAd->RECBATimer, REORDER_EXEC_INTV);
36043 +
36044 +#ifdef RALINK_ATE
36045 + NdisZeroMemory(&pAd->ate, sizeof(ATE_INFO));
36046 + pAd->ate.Mode = ATE_STOP;
36047 + pAd->ate.TxCount = 200;/* to exceed TX_RING_SIZE ... */
36048 + pAd->ate.TxLength = 1024;
36049 + pAd->ate.TxWI.ShortGI = 0;// LONG GI : 800 ns
36050 + pAd->ate.TxWI.PHYMODE = MODE_CCK;
36051 + pAd->ate.TxWI.MCS = 3;
36052 + pAd->ate.TxWI.BW = BW_20;
36053 + pAd->ate.Channel = 1;
36054 + pAd->ate.QID = QID_AC_BE;
36055 + pAd->ate.Addr1[0] = 0x00;
36056 + pAd->ate.Addr1[1] = 0x11;
36057 + pAd->ate.Addr1[2] = 0x22;
36058 + pAd->ate.Addr1[3] = 0xAA;
36059 + pAd->ate.Addr1[4] = 0xBB;
36060 + pAd->ate.Addr1[5] = 0xCC;
36061 + NdisMoveMemory(pAd->ate.Addr2, pAd->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
36062 + NdisMoveMemory(pAd->ate.Addr3, pAd->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
36063 + pAd->ate.bRxFer = 0;
36064 + pAd->ate.bQATxStart = FALSE;
36065 + pAd->ate.bQARxStart = FALSE;
36066 +#ifdef RALINK_28xx_QA
36067 + //pAd->ate.Repeat = 0;
36068 + pAd->ate.TxStatus = 0;
36069 + pAd->ate.AtePid = 0;
36070 +#endif // RALINK_28xx_QA //
36071 +#endif // RALINK_ATE //
36072 +
36073 +
36074 + pAd->CommonCfg.bWiFiTest = FALSE;
36075 +
36076 +
36077 + DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n"));
36078 +}
36079 +
36080 +// IRQL = PASSIVE_LEVEL
36081 +UCHAR BtoH(char ch)
36082 +{
36083 + if (ch >= '0' && ch <= '9') return (ch - '0'); // Handle numerals
36084 + if (ch >= 'A' && ch <= 'F') return (ch - 'A' + 0xA); // Handle capitol hex digits
36085 + if (ch >= 'a' && ch <= 'f') return (ch - 'a' + 0xA); // Handle small hex digits
36086 + return(255);
36087 +}
36088 +
36089 +//
36090 +// FUNCTION: AtoH(char *, UCHAR *, int)
36091 +//
36092 +// PURPOSE: Converts ascii string to network order hex
36093 +//
36094 +// PARAMETERS:
36095 +// src - pointer to input ascii string
36096 +// dest - pointer to output hex
36097 +// destlen - size of dest
36098 +//
36099 +// COMMENTS:
36100 +//
36101 +// 2 ascii bytes make a hex byte so must put 1st ascii byte of pair
36102 +// into upper nibble and 2nd ascii byte of pair into lower nibble.
36103 +//
36104 +// IRQL = PASSIVE_LEVEL
36105 +
36106 +void AtoH(char * src, UCHAR * dest, int destlen)
36107 +{
36108 + char * srcptr;
36109 + PUCHAR destTemp;
36110 +
36111 + srcptr = src;
36112 + destTemp = (PUCHAR) dest;
36113 +
36114 + while(destlen--)
36115 + {
36116 + *destTemp = BtoH(*srcptr++) << 4; // Put 1st ascii byte in upper nibble.
36117 + *destTemp += BtoH(*srcptr++); // Add 2nd ascii byte to above.
36118 + destTemp++;
36119 + }
36120 +}
36121 +
36122 +VOID RTMPPatchMacBbpBug(
36123 + IN PRTMP_ADAPTER pAd)
36124 +{
36125 + ULONG Index;
36126 +
36127 + // Initialize BBP register to default value
36128 + for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++)
36129 + {
36130 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, (UCHAR)BBPRegTable[Index].Value);
36131 + }
36132 +
36133 + // Initialize RF register to default value
36134 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
36135 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
36136 +
36137 + // Re-init BBP register from EEPROM value
36138 + NICInitAsicFromEEPROM(pAd);
36139 +}
36140 +
36141 +/*
36142 + ========================================================================
36143 +
36144 + Routine Description:
36145 + Init timer objects
36146 +
36147 + Arguments:
36148 + pAd Pointer to our adapter
36149 + pTimer Timer structure
36150 + pTimerFunc Function to execute when timer expired
36151 + Repeat Ture for period timer
36152 +
36153 + Return Value:
36154 + None
36155 +
36156 + Note:
36157 +
36158 + ========================================================================
36159 +*/
36160 +VOID RTMPInitTimer(
36161 + IN PRTMP_ADAPTER pAd,
36162 + IN PRALINK_TIMER_STRUCT pTimer,
36163 + IN PVOID pTimerFunc,
36164 + IN PVOID pData,
36165 + IN BOOLEAN Repeat)
36166 +{
36167 + //
36168 + // Set Valid to TRUE for later used.
36169 + // It will crash if we cancel a timer or set a timer
36170 + // that we haven't initialize before.
36171 + //
36172 + pTimer->Valid = TRUE;
36173 +
36174 + pTimer->PeriodicType = Repeat;
36175 + pTimer->State = FALSE;
36176 + pTimer->cookie = (ULONG) pData;
36177 +
36178 +#ifdef RT2870
36179 + pTimer->pAd = pAd;
36180 +#endif // RT2870 //
36181 +
36182 + RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (PVOID) pTimer);
36183 +}
36184 +
36185 +/*
36186 + ========================================================================
36187 +
36188 + Routine Description:
36189 + Init timer objects
36190 +
36191 + Arguments:
36192 + pTimer Timer structure
36193 + Value Timer value in milliseconds
36194 +
36195 + Return Value:
36196 + None
36197 +
36198 + Note:
36199 + To use this routine, must call RTMPInitTimer before.
36200 +
36201 + ========================================================================
36202 +*/
36203 +VOID RTMPSetTimer(
36204 + IN PRALINK_TIMER_STRUCT pTimer,
36205 + IN ULONG Value)
36206 +{
36207 + if (pTimer->Valid)
36208 + {
36209 + pTimer->TimerValue = Value;
36210 + pTimer->State = FALSE;
36211 + if (pTimer->PeriodicType == TRUE)
36212 + {
36213 + pTimer->Repeat = TRUE;
36214 + RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value);
36215 + }
36216 + else
36217 + {
36218 + pTimer->Repeat = FALSE;
36219 + RTMP_OS_Add_Timer(&pTimer->TimerObj, Value);
36220 + }
36221 + }
36222 + else
36223 + {
36224 + DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n"));
36225 + }
36226 +}
36227 +
36228 +
36229 +/*
36230 + ========================================================================
36231 +
36232 + Routine Description:
36233 + Init timer objects
36234 +
36235 + Arguments:
36236 + pTimer Timer structure
36237 + Value Timer value in milliseconds
36238 +
36239 + Return Value:
36240 + None
36241 +
36242 + Note:
36243 + To use this routine, must call RTMPInitTimer before.
36244 +
36245 + ========================================================================
36246 +*/
36247 +VOID RTMPModTimer(
36248 + IN PRALINK_TIMER_STRUCT pTimer,
36249 + IN ULONG Value)
36250 +{
36251 + BOOLEAN Cancel;
36252 +
36253 + if (pTimer->Valid)
36254 + {
36255 + pTimer->TimerValue = Value;
36256 + pTimer->State = FALSE;
36257 + if (pTimer->PeriodicType == TRUE)
36258 + {
36259 + RTMPCancelTimer(pTimer, &Cancel);
36260 + RTMPSetTimer(pTimer, Value);
36261 + }
36262 + else
36263 + {
36264 + RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value);
36265 + }
36266 + }
36267 + else
36268 + {
36269 + DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n"));
36270 + }
36271 +}
36272 +
36273 +/*
36274 + ========================================================================
36275 +
36276 + Routine Description:
36277 + Cancel timer objects
36278 +
36279 + Arguments:
36280 + Adapter Pointer to our adapter
36281 +
36282 + Return Value:
36283 + None
36284 +
36285 + IRQL = PASSIVE_LEVEL
36286 + IRQL = DISPATCH_LEVEL
36287 +
36288 + Note:
36289 + 1.) To use this routine, must call RTMPInitTimer before.
36290 + 2.) Reset NIC to initial state AS IS system boot up time.
36291 +
36292 + ========================================================================
36293 +*/
36294 +VOID RTMPCancelTimer(
36295 + IN PRALINK_TIMER_STRUCT pTimer,
36296 + OUT BOOLEAN *pCancelled)
36297 +{
36298 + if (pTimer->Valid)
36299 + {
36300 + if (pTimer->State == FALSE)
36301 + pTimer->Repeat = FALSE;
36302 + RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled);
36303 +
36304 + if (*pCancelled == TRUE)
36305 + pTimer->State = TRUE;
36306 +
36307 +#ifdef RT2870
36308 + // We need to go-through the TimerQ to findout this timer handler and remove it if
36309 + // it's still waiting for execution.
36310 +
36311 + RT2870_TimerQ_Remove(pTimer->pAd, pTimer);
36312 +#endif // RT2870 //
36313 + }
36314 + else
36315 + {
36316 + //
36317 + // NdisMCancelTimer just canced the timer and not mean release the timer.
36318 + // And don't set the "Valid" to False. So that we can use this timer again.
36319 + //
36320 + DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n"));
36321 + }
36322 +}
36323 +
36324 +/*
36325 + ========================================================================
36326 +
36327 + Routine Description:
36328 + Set LED Status
36329 +
36330 + Arguments:
36331 + pAd Pointer to our adapter
36332 + Status LED Status
36333 +
36334 + Return Value:
36335 + None
36336 +
36337 + IRQL = PASSIVE_LEVEL
36338 + IRQL = DISPATCH_LEVEL
36339 +
36340 + Note:
36341 +
36342 + ========================================================================
36343 +*/
36344 +VOID RTMPSetLED(
36345 + IN PRTMP_ADAPTER pAd,
36346 + IN UCHAR Status)
36347 +{
36348 + //ULONG data;
36349 + UCHAR HighByte = 0;
36350 + UCHAR LowByte;
36351 +
36352 +// In ATE mode of RT2860 AP/STA, we have erased 8051 firmware.
36353 +// So LED mode is not supported when ATE is running.
36354 +#ifdef RALINK_ATE
36355 + if (ATE_ON(pAd))
36356 + return;
36357 +#endif // RALINK_ATE //
36358 +
36359 + LowByte = pAd->LedCntl.field.LedMode&0x7f;
36360 + switch (Status)
36361 + {
36362 + case LED_LINK_DOWN:
36363 + HighByte = 0x20;
36364 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36365 + pAd->LedIndicatorStregth = 0;
36366 + break;
36367 + case LED_LINK_UP:
36368 + if (pAd->CommonCfg.Channel > 14)
36369 + HighByte = 0xa0;
36370 + else
36371 + HighByte = 0x60;
36372 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36373 + break;
36374 + case LED_RADIO_ON:
36375 + HighByte = 0x20;
36376 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36377 + break;
36378 + case LED_HALT:
36379 + LowByte = 0; // Driver sets MAC register and MAC controls LED
36380 + case LED_RADIO_OFF:
36381 + HighByte = 0;
36382 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36383 + break;
36384 + case LED_WPS:
36385 + HighByte = 0x10;
36386 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36387 + break;
36388 + case LED_ON_SITE_SURVEY:
36389 + HighByte = 0x08;
36390 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36391 + break;
36392 + case LED_POWER_UP:
36393 + HighByte = 0x04;
36394 + AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
36395 + break;
36396 + default:
36397 + DBGPRINT(RT_DEBUG_WARN, ("RTMPSetLED::Unknown Status %d\n", Status));
36398 + break;
36399 + }
36400 +
36401 + //
36402 + // Keep LED status for LED SiteSurvey mode.
36403 + // After SiteSurvey, we will set the LED mode to previous status.
36404 + //
36405 + if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP))
36406 + pAd->LedStatus = Status;
36407 +
36408 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n", pAd->LedCntl.field.LedMode, HighByte, LowByte));
36409 +}
36410 +
36411 +/*
36412 + ========================================================================
36413 +
36414 + Routine Description:
36415 + Set LED Signal Stregth
36416 +
36417 + Arguments:
36418 + pAd Pointer to our adapter
36419 + Dbm Signal Stregth
36420 +
36421 + Return Value:
36422 + None
36423 +
36424 + IRQL = PASSIVE_LEVEL
36425 +
36426 + Note:
36427 + Can be run on any IRQL level.
36428 +
36429 + According to Microsoft Zero Config Wireless Signal Stregth definition as belows.
36430 + <= -90 No Signal
36431 + <= -81 Very Low
36432 + <= -71 Low
36433 + <= -67 Good
36434 + <= -57 Very Good
36435 + > -57 Excellent
36436 + ========================================================================
36437 +*/
36438 +VOID RTMPSetSignalLED(
36439 + IN PRTMP_ADAPTER pAd,
36440 + IN NDIS_802_11_RSSI Dbm)
36441 +{
36442 + UCHAR nLed = 0;
36443 +
36444 + //
36445 + // if not Signal Stregth, then do nothing.
36446 + //
36447 + if (pAd->LedCntl.field.LedMode != LED_MODE_SIGNAL_STREGTH)
36448 + {
36449 + return;
36450 + }
36451 +
36452 + if (Dbm <= -90)
36453 + nLed = 0;
36454 + else if (Dbm <= -81)
36455 + nLed = 1;
36456 + else if (Dbm <= -71)
36457 + nLed = 3;
36458 + else if (Dbm <= -67)
36459 + nLed = 7;
36460 + else if (Dbm <= -57)
36461 + nLed = 15;
36462 + else
36463 + nLed = 31;
36464 +
36465 + //
36466 + // Update Signal Stregth to firmware if changed.
36467 + //
36468 + if (pAd->LedIndicatorStregth != nLed)
36469 + {
36470 + AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed, pAd->LedCntl.field.Polarity);
36471 + pAd->LedIndicatorStregth = nLed;
36472 + }
36473 +}
36474 +
36475 +/*
36476 + ========================================================================
36477 +
36478 + Routine Description:
36479 + Enable RX
36480 +
36481 + Arguments:
36482 + pAd Pointer to our adapter
36483 +
36484 + Return Value:
36485 + None
36486 +
36487 + IRQL <= DISPATCH_LEVEL
36488 +
36489 + Note:
36490 + Before Enable RX, make sure you have enabled Interrupt.
36491 + ========================================================================
36492 +*/
36493 +VOID RTMPEnableRxTx(
36494 + IN PRTMP_ADAPTER pAd)
36495 +{
36496 +// WPDMA_GLO_CFG_STRUC GloCfg;
36497 +// ULONG i = 0;
36498 +
36499 + DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n"));
36500 +
36501 + // Enable Rx DMA.
36502 + RT28XXDMAEnable(pAd);
36503 +
36504 + // enable RX of MAC block
36505 + if (pAd->OpMode == OPMODE_AP)
36506 + {
36507 + UINT32 rx_filter_flag = APNORMAL;
36508 +
36509 +
36510 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); // enable RX of DMA block
36511 + }
36512 + else
36513 + {
36514 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
36515 + }
36516 +
36517 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc);
36518 + DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n"));
36519 +}
36520 +
36521 +
36522 --- /dev/null
36523 +++ b/drivers/staging/rt3070/common/rtmp_tkip.c
36524 @@ -0,0 +1,1613 @@
36525 +/*
36526 + *************************************************************************
36527 + * Ralink Tech Inc.
36528 + * 5F., No.36, Taiyuan St., Jhubei City,
36529 + * Hsinchu County 302,
36530 + * Taiwan, R.O.C.
36531 + *
36532 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
36533 + *
36534 + * This program is free software; you can redistribute it and/or modify *
36535 + * it under the terms of the GNU General Public License as published by *
36536 + * the Free Software Foundation; either version 2 of the License, or *
36537 + * (at your option) any later version. *
36538 + * *
36539 + * This program is distributed in the hope that it will be useful, *
36540 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
36541 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
36542 + * GNU General Public License for more details. *
36543 + * *
36544 + * You should have received a copy of the GNU General Public License *
36545 + * along with this program; if not, write to the *
36546 + * Free Software Foundation, Inc., *
36547 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
36548 + * *
36549 + *************************************************************************
36550 +
36551 + Module Name:
36552 + rtmp_tkip.c
36553 +
36554 + Abstract:
36555 +
36556 + Revision History:
36557 + Who When What
36558 + -------- ---------- ----------------------------------------------
36559 + Paul Wu 02-25-02 Initial
36560 +*/
36561 +
36562 +#include "../rt_config.h"
36563 +
36564 +// Rotation functions on 32 bit values
36565 +#define ROL32( A, n ) \
36566 + ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
36567 +#define ROR32( A, n ) ROL32( (A), 32-(n) )
36568 +
36569 +UINT Tkip_Sbox_Lower[256] =
36570 +{
36571 + 0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54,
36572 + 0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A,
36573 + 0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B,
36574 + 0xEC,0x67,0xFD,0xEA,0xBF,0xF7,0x96,0x5B,
36575 + 0xC2,0x1C,0xAE,0x6A,0x5A,0x41,0x02,0x4F,
36576 + 0x5C,0xF4,0x34,0x08,0x93,0x73,0x53,0x3F,
36577 + 0x0C,0x52,0x65,0x5E,0x28,0xA1,0x0F,0xB5,
36578 + 0x09,0x36,0x9B,0x3D,0x26,0x69,0xCD,0x9F,
36579 + 0x1B,0x9E,0x74,0x2E,0x2D,0xB2,0xEE,0xFB,
36580 + 0xF6,0x4D,0x61,0xCE,0x7B,0x3E,0x71,0x97,
36581 + 0xF5,0x68,0x00,0x2C,0x60,0x1F,0xC8,0xED,
36582 + 0xBE,0x46,0xD9,0x4B,0xDE,0xD4,0xE8,0x4A,
36583 + 0x6B,0x2A,0xE5,0x16,0xC5,0xD7,0x55,0x94,
36584 + 0xCF,0x10,0x06,0x81,0xF0,0x44,0xBA,0xE3,
36585 + 0xF3,0xFE,0xC0,0x8A,0xAD,0xBC,0x48,0x04,
36586 + 0xDF,0xC1,0x75,0x63,0x30,0x1A,0x0E,0x6D,
36587 + 0x4C,0x14,0x35,0x2F,0xE1,0xA2,0xCC,0x39,
36588 + 0x57,0xF2,0x82,0x47,0xAC,0xE7,0x2B,0x95,
36589 + 0xA0,0x98,0xD1,0x7F,0x66,0x7E,0xAB,0x83,
36590 + 0xCA,0x29,0xD3,0x3C,0x79,0xE2,0x1D,0x76,
36591 + 0x3B,0x56,0x4E,0x1E,0xDB,0x0A,0x6C,0xE4,
36592 + 0x5D,0x6E,0xEF,0xA6,0xA8,0xA4,0x37,0x8B,
36593 + 0x32,0x43,0x59,0xB7,0x8C,0x64,0xD2,0xE0,
36594 + 0xB4,0xFA,0x07,0x25,0xAF,0x8E,0xE9,0x18,
36595 + 0xD5,0x88,0x6F,0x72,0x24,0xF1,0xC7,0x51,
36596 + 0x23,0x7C,0x9C,0x21,0xDD,0xDC,0x86,0x85,
36597 + 0x90,0x42,0xC4,0xAA,0xD8,0x05,0x01,0x12,
36598 + 0xA3,0x5F,0xF9,0xD0,0x91,0x58,0x27,0xB9,
36599 + 0x38,0x13,0xB3,0x33,0xBB,0x70,0x89,0xA7,
36600 + 0xB6,0x22,0x92,0x20,0x49,0xFF,0x78,0x7A,
36601 + 0x8F,0xF8,0x80,0x17,0xDA,0x31,0xC6,0xB8,
36602 + 0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A
36603 +};
36604 +
36605 +UINT Tkip_Sbox_Upper[256] =
36606 +{
36607 + 0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91,
36608 + 0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC,
36609 + 0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB,
36610 + 0x41,0xB3,0x5F,0x45,0x23,0x53,0xE4,0x9B,
36611 + 0x75,0xE1,0x3D,0x4C,0x6C,0x7E,0xF5,0x83,
36612 + 0x68,0x51,0xD1,0xF9,0xE2,0xAB,0x62,0x2A,
36613 + 0x08,0x95,0x46,0x9D,0x30,0x37,0x0A,0x2F,
36614 + 0x0E,0x24,0x1B,0xDF,0xCD,0x4E,0x7F,0xEA,
36615 + 0x12,0x1D,0x58,0x34,0x36,0xDC,0xB4,0x5B,
36616 + 0xA4,0x76,0xB7,0x7D,0x52,0xDD,0x5E,0x13,
36617 + 0xA6,0xB9,0x00,0xC1,0x40,0xE3,0x79,0xB6,
36618 + 0xD4,0x8D,0x67,0x72,0x94,0x98,0xB0,0x85,
36619 + 0xBB,0xC5,0x4F,0xED,0x86,0x9A,0x66,0x11,
36620 + 0x8A,0xE9,0x04,0xFE,0xA0,0x78,0x25,0x4B,
36621 + 0xA2,0x5D,0x80,0x05,0x3F,0x21,0x70,0xF1,
36622 + 0x63,0x77,0xAF,0x42,0x20,0xE5,0xFD,0xBF,
36623 + 0x81,0x18,0x26,0xC3,0xBE,0x35,0x88,0x2E,
36624 + 0x93,0x55,0xFC,0x7A,0xC8,0xBA,0x32,0xE6,
36625 + 0xC0,0x19,0x9E,0xA3,0x44,0x54,0x3B,0x0B,
36626 + 0x8C,0xC7,0x6B,0x28,0xA7,0xBC,0x16,0xAD,
36627 + 0xDB,0x64,0x74,0x14,0x92,0x0C,0x48,0xB8,
36628 + 0x9F,0xBD,0x43,0xC4,0x39,0x31,0xD3,0xF2,
36629 + 0xD5,0x8B,0x6E,0xDA,0x01,0xB1,0x9C,0x49,
36630 + 0xD8,0xAC,0xF3,0xCF,0xCA,0xF4,0x47,0x10,
36631 + 0x6F,0xF0,0x4A,0x5C,0x38,0x57,0x73,0x97,
36632 + 0xCB,0xA1,0xE8,0x3E,0x96,0x61,0x0D,0x0F,
36633 + 0xE0,0x7C,0x71,0xCC,0x90,0x06,0xF7,0x1C,
36634 + 0xC2,0x6A,0xAE,0x69,0x17,0x99,0x3A,0x27,
36635 + 0xD9,0xEB,0x2B,0x22,0xD2,0xA9,0x07,0x33,
36636 + 0x2D,0x3C,0x15,0xC9,0x87,0xAA,0x50,0xA5,
36637 + 0x03,0x59,0x09,0x1A,0x65,0xD7,0x84,0xD0,
36638 + 0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C
36639 +};
36640 +
36641 +/*****************************/
36642 +/******** SBOX Table *********/
36643 +/*****************************/
36644 +
36645 +UCHAR SboxTable[256] =
36646 +{
36647 + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
36648 + 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
36649 + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
36650 + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
36651 + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
36652 + 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
36653 + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
36654 + 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
36655 + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
36656 + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
36657 + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
36658 + 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
36659 + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
36660 + 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
36661 + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
36662 + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
36663 + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
36664 + 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
36665 + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
36666 + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
36667 + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
36668 + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
36669 + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
36670 + 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
36671 + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
36672 + 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
36673 + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
36674 + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
36675 + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
36676 + 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
36677 + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
36678 + 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
36679 +};
36680 +
36681 +VOID xor_32(
36682 + IN PUCHAR a,
36683 + IN PUCHAR b,
36684 + OUT PUCHAR out);
36685 +
36686 +VOID xor_128(
36687 + IN PUCHAR a,
36688 + IN PUCHAR b,
36689 + OUT PUCHAR out);
36690 +
36691 +VOID next_key(
36692 + IN PUCHAR key,
36693 + IN INT round);
36694 +
36695 +VOID byte_sub(
36696 + IN PUCHAR in,
36697 + OUT PUCHAR out);
36698 +
36699 +VOID shift_row(
36700 + IN PUCHAR in,
36701 + OUT PUCHAR out);
36702 +
36703 +VOID mix_column(
36704 + IN PUCHAR in,
36705 + OUT PUCHAR out);
36706 +
36707 +UCHAR RTMPCkipSbox(
36708 + IN UCHAR a);
36709 +//
36710 +// Expanded IV for TKIP function.
36711 +//
36712 +typedef struct PACKED _IV_CONTROL_
36713 +{
36714 + union PACKED
36715 + {
36716 + struct PACKED
36717 + {
36718 + UCHAR rc0;
36719 + UCHAR rc1;
36720 + UCHAR rc2;
36721 +
36722 + union PACKED
36723 + {
36724 + struct PACKED
36725 + {
36726 +#ifdef RT_BIG_ENDIAN
36727 + UCHAR KeyID:2;
36728 + UCHAR ExtIV:1;
36729 + UCHAR Rsvd:5;
36730 +#else
36731 + UCHAR Rsvd:5;
36732 + UCHAR ExtIV:1;
36733 + UCHAR KeyID:2;
36734 +#endif
36735 + } field;
36736 + UCHAR Byte;
36737 + } CONTROL;
36738 + } field;
36739 +
36740 + ULONG word;
36741 + } IV16;
36742 +
36743 + ULONG IV32;
36744 +} TKIP_IV, *PTKIP_IV;
36745 +
36746 +
36747 +/*
36748 + ========================================================================
36749 +
36750 + Routine Description:
36751 + Convert from UCHAR[] to ULONG in a portable way
36752 +
36753 + Arguments:
36754 + pMICKey pointer to MIC Key
36755 +
36756 + Return Value:
36757 + None
36758 +
36759 + Note:
36760 +
36761 + ========================================================================
36762 +*/
36763 +ULONG RTMPTkipGetUInt32(
36764 + IN PUCHAR pMICKey)
36765 +{
36766 + ULONG res = 0;
36767 + INT i;
36768 +
36769 + for (i = 0; i < 4; i++)
36770 + {
36771 + res |= (*pMICKey++) << (8 * i);
36772 + }
36773 +
36774 + return res;
36775 +}
36776 +
36777 +/*
36778 + ========================================================================
36779 +
36780 + Routine Description:
36781 + Convert from ULONG to UCHAR[] in a portable way
36782 +
36783 + Arguments:
36784 + pDst pointer to destination for convert ULONG to UCHAR[]
36785 + val the value for convert
36786 +
36787 + Return Value:
36788 + None
36789 +
36790 + IRQL = DISPATCH_LEVEL
36791 +
36792 + Note:
36793 +
36794 + ========================================================================
36795 +*/
36796 +VOID RTMPTkipPutUInt32(
36797 + IN OUT PUCHAR pDst,
36798 + IN ULONG val)
36799 +{
36800 + INT i;
36801 +
36802 + for(i = 0; i < 4; i++)
36803 + {
36804 + *pDst++ = (UCHAR) (val & 0xff);
36805 + val >>= 8;
36806 + }
36807 +}
36808 +
36809 +/*
36810 + ========================================================================
36811 +
36812 + Routine Description:
36813 + Set the MIC Key.
36814 +
36815 + Arguments:
36816 + pAd Pointer to our adapter
36817 + pMICKey pointer to MIC Key
36818 +
36819 + Return Value:
36820 + None
36821 +
36822 + IRQL = DISPATCH_LEVEL
36823 +
36824 + Note:
36825 +
36826 + ========================================================================
36827 +*/
36828 +VOID RTMPTkipSetMICKey(
36829 + IN PTKIP_KEY_INFO pTkip,
36830 + IN PUCHAR pMICKey)
36831 +{
36832 + // Set the key
36833 + pTkip->K0 = RTMPTkipGetUInt32(pMICKey);
36834 + pTkip->K1 = RTMPTkipGetUInt32(pMICKey + 4);
36835 + // and reset the message
36836 + pTkip->L = pTkip->K0;
36837 + pTkip->R = pTkip->K1;
36838 + pTkip->nBytesInM = 0;
36839 + pTkip->M = 0;
36840 +}
36841 +
36842 +/*
36843 + ========================================================================
36844 +
36845 + Routine Description:
36846 + Calculate the MIC Value.
36847 +
36848 + Arguments:
36849 + pAd Pointer to our adapter
36850 + uChar Append this uChar
36851 +
36852 + Return Value:
36853 + None
36854 +
36855 + IRQL = DISPATCH_LEVEL
36856 +
36857 + Note:
36858 +
36859 + ========================================================================
36860 +*/
36861 +VOID RTMPTkipAppendByte(
36862 + IN PTKIP_KEY_INFO pTkip,
36863 + IN UCHAR uChar)
36864 +{
36865 + // Append the byte to our word-sized buffer
36866 + pTkip->M |= (uChar << (8* pTkip->nBytesInM));
36867 + pTkip->nBytesInM++;
36868 + // Process the word if it is full.
36869 + if( pTkip->nBytesInM >= 4 )
36870 + {
36871 + pTkip->L ^= pTkip->M;
36872 + pTkip->R ^= ROL32( pTkip->L, 17 );
36873 + pTkip->L += pTkip->R;
36874 + pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->L & 0x00ff00ff) << 8);
36875 + pTkip->L += pTkip->R;
36876 + pTkip->R ^= ROL32( pTkip->L, 3 );
36877 + pTkip->L += pTkip->R;
36878 + pTkip->R ^= ROR32( pTkip->L, 2 );
36879 + pTkip->L += pTkip->R;
36880 + // Clear the buffer
36881 + pTkip->M = 0;
36882 + pTkip->nBytesInM = 0;
36883 + }
36884 +}
36885 +
36886 +/*
36887 + ========================================================================
36888 +
36889 + Routine Description:
36890 + Calculate the MIC Value.
36891 +
36892 + Arguments:
36893 + pAd Pointer to our adapter
36894 + pSrc Pointer to source data for Calculate MIC Value
36895 + Len Indicate the length of the source data
36896 +
36897 + Return Value:
36898 + None
36899 +
36900 + IRQL = DISPATCH_LEVEL
36901 +
36902 + Note:
36903 +
36904 + ========================================================================
36905 +*/
36906 +VOID RTMPTkipAppend(
36907 + IN PTKIP_KEY_INFO pTkip,
36908 + IN PUCHAR pSrc,
36909 + IN UINT nBytes)
36910 +{
36911 + // This is simple
36912 + while(nBytes > 0)
36913 + {
36914 + RTMPTkipAppendByte(pTkip, *pSrc++);
36915 + nBytes--;
36916 + }
36917 +}
36918 +
36919 +/*
36920 + ========================================================================
36921 +
36922 + Routine Description:
36923 + Get the MIC Value.
36924 +
36925 + Arguments:
36926 + pAd Pointer to our adapter
36927 +
36928 + Return Value:
36929 + None
36930 +
36931 + IRQL = DISPATCH_LEVEL
36932 +
36933 + Note:
36934 + the MIC Value is store in pAd->PrivateInfo.MIC
36935 + ========================================================================
36936 +*/
36937 +VOID RTMPTkipGetMIC(
36938 + IN PTKIP_KEY_INFO pTkip)
36939 +{
36940 + // Append the minimum padding
36941 + RTMPTkipAppendByte(pTkip, 0x5a );
36942 + RTMPTkipAppendByte(pTkip, 0 );
36943 + RTMPTkipAppendByte(pTkip, 0 );
36944 + RTMPTkipAppendByte(pTkip, 0 );
36945 + RTMPTkipAppendByte(pTkip, 0 );
36946 + // and then zeroes until the length is a multiple of 4
36947 + while( pTkip->nBytesInM != 0 )
36948 + {
36949 + RTMPTkipAppendByte(pTkip, 0 );
36950 + }
36951 + // The appendByte function has already computed the result.
36952 + RTMPTkipPutUInt32(pTkip->MIC, pTkip->L);
36953 + RTMPTkipPutUInt32(pTkip->MIC + 4, pTkip->R);
36954 +}
36955 +
36956 +/*
36957 + ========================================================================
36958 +
36959 + Routine Description:
36960 + Init Tkip function.
36961 +
36962 + Arguments:
36963 + pAd Pointer to our adapter
36964 + pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
36965 + KeyId TK Key ID
36966 + pTA Pointer to transmitter address
36967 + pMICKey pointer to MIC Key
36968 +
36969 + Return Value:
36970 + None
36971 +
36972 + IRQL = DISPATCH_LEVEL
36973 +
36974 + Note:
36975 +
36976 + ========================================================================
36977 +*/
36978 +VOID RTMPInitTkipEngine(
36979 + IN PRTMP_ADAPTER pAd,
36980 + IN PUCHAR pKey,
36981 + IN UCHAR KeyId,
36982 + IN PUCHAR pTA,
36983 + IN PUCHAR pMICKey,
36984 + IN PUCHAR pTSC,
36985 + OUT PULONG pIV16,
36986 + OUT PULONG pIV32)
36987 +{
36988 + TKIP_IV tkipIv;
36989 +
36990 + // Prepare 8 bytes TKIP encapsulation for MPDU
36991 + NdisZeroMemory(&tkipIv, sizeof(TKIP_IV));
36992 + tkipIv.IV16.field.rc0 = *(pTSC + 1);
36993 + tkipIv.IV16.field.rc1 = (tkipIv.IV16.field.rc0 | 0x20) & 0x7f;
36994 + tkipIv.IV16.field.rc2 = *pTSC;
36995 + tkipIv.IV16.field.CONTROL.field.ExtIV = 1; // 0: non-extended IV, 1: an extended IV
36996 + tkipIv.IV16.field.CONTROL.field.KeyID = KeyId;
36997 +// tkipIv.IV32 = *(PULONG)(pTSC + 2);
36998 + NdisMoveMemory(&tkipIv.IV32, (pTSC + 2), 4); // Copy IV
36999 +
37000 + *pIV16 = tkipIv.IV16.word;
37001 + *pIV32 = tkipIv.IV32;
37002 +}
37003 +
37004 +/*
37005 + ========================================================================
37006 +
37007 + Routine Description:
37008 + Init MIC Value calculation function which include set MIC key &
37009 + calculate first 16 bytes (DA + SA + priority + 0)
37010 +
37011 + Arguments:
37012 + pAd Pointer to our adapter
37013 + pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
37014 + pDA Pointer to DA address
37015 + pSA Pointer to SA address
37016 + pMICKey pointer to MIC Key
37017 +
37018 + Return Value:
37019 + None
37020 +
37021 + Note:
37022 +
37023 + ========================================================================
37024 +*/
37025 +VOID RTMPInitMICEngine(
37026 + IN PRTMP_ADAPTER pAd,
37027 + IN PUCHAR pKey,
37028 + IN PUCHAR pDA,
37029 + IN PUCHAR pSA,
37030 + IN UCHAR UserPriority,
37031 + IN PUCHAR pMICKey)
37032 +{
37033 + ULONG Priority = UserPriority;
37034 +
37035 + // Init MIC value calculation
37036 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Tx, pMICKey);
37037 + // DA
37038 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pDA, MAC_ADDR_LEN);
37039 + // SA
37040 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSA, MAC_ADDR_LEN);
37041 + // Priority + 3 bytes of 0
37042 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, (PUCHAR)&Priority, 4);
37043 +}
37044 +
37045 +/*
37046 + ========================================================================
37047 +
37048 + Routine Description:
37049 + Compare MIC value of received MSDU
37050 +
37051 + Arguments:
37052 + pAd Pointer to our adapter
37053 + pSrc Pointer to the received Plain text data
37054 + pDA Pointer to DA address
37055 + pSA Pointer to SA address
37056 + pMICKey pointer to MIC Key
37057 + Len the length of the received plain text data exclude MIC value
37058 +
37059 + Return Value:
37060 + TRUE MIC value matched
37061 + FALSE MIC value mismatched
37062 +
37063 + IRQL = DISPATCH_LEVEL
37064 +
37065 + Note:
37066 +
37067 + ========================================================================
37068 +*/
37069 +BOOLEAN RTMPTkipCompareMICValue(
37070 + IN PRTMP_ADAPTER pAd,
37071 + IN PUCHAR pSrc,
37072 + IN PUCHAR pDA,
37073 + IN PUCHAR pSA,
37074 + IN PUCHAR pMICKey,
37075 + IN UCHAR UserPriority,
37076 + IN UINT Len)
37077 +{
37078 + UCHAR OldMic[8];
37079 + ULONG Priority = UserPriority;
37080 +
37081 + // Init MIC value calculation
37082 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey);
37083 + // DA
37084 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN);
37085 + // SA
37086 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN);
37087 + // Priority + 3 bytes of 0
37088 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4);
37089 +
37090 + // Calculate MIC value from plain text data
37091 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len);
37092 +
37093 + // Get MIC valude from received frame
37094 + NdisMoveMemory(OldMic, pSrc + Len, 8);
37095 +
37096 + // Get MIC value from decrypted plain data
37097 + RTMPTkipGetMIC(&pAd->PrivateInfo.Rx);
37098 +
37099 + // Move MIC value from MSDU, this steps should move to data path.
37100 + // Since the MIC value might cross MPDUs.
37101 + if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8))
37102 + {
37103 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValue(): TKIP MIC Error !\n")); //MIC error.
37104 +
37105 +
37106 + return (FALSE);
37107 + }
37108 + return (TRUE);
37109 +}
37110 +
37111 +/*
37112 + ========================================================================
37113 +
37114 + Routine Description:
37115 + Compare MIC value of received MSDU
37116 +
37117 + Arguments:
37118 + pAd Pointer to our adapter
37119 + pLLC LLC header
37120 + pSrc Pointer to the received Plain text data
37121 + pDA Pointer to DA address
37122 + pSA Pointer to SA address
37123 + pMICKey pointer to MIC Key
37124 + Len the length of the received plain text data exclude MIC value
37125 +
37126 + Return Value:
37127 + TRUE MIC value matched
37128 + FALSE MIC value mismatched
37129 +
37130 + IRQL = DISPATCH_LEVEL
37131 +
37132 + Note:
37133 +
37134 + ========================================================================
37135 +*/
37136 +BOOLEAN RTMPTkipCompareMICValueWithLLC(
37137 + IN PRTMP_ADAPTER pAd,
37138 + IN PUCHAR pLLC,
37139 + IN PUCHAR pSrc,
37140 + IN PUCHAR pDA,
37141 + IN PUCHAR pSA,
37142 + IN PUCHAR pMICKey,
37143 + IN UINT Len)
37144 +{
37145 + UCHAR OldMic[8];
37146 + ULONG Priority = 0;
37147 +
37148 + // Init MIC value calculation
37149 + RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey);
37150 + // DA
37151 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN);
37152 + // SA
37153 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN);
37154 + // Priority + 3 bytes of 0
37155 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4);
37156 +
37157 + // Start with LLC header
37158 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pLLC, 8);
37159 +
37160 + // Calculate MIC value from plain text data
37161 + RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len);
37162 +
37163 + // Get MIC valude from received frame
37164 + NdisMoveMemory(OldMic, pSrc + Len, 8);
37165 +
37166 + // Get MIC value from decrypted plain data
37167 + RTMPTkipGetMIC(&pAd->PrivateInfo.Rx);
37168 +
37169 + // Move MIC value from MSDU, this steps should move to data path.
37170 + // Since the MIC value might cross MPDUs.
37171 + if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8))
37172 + {
37173 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValueWithLLC(): TKIP MIC Error !\n")); //MIC error.
37174 +
37175 +
37176 + return (FALSE);
37177 + }
37178 + return (TRUE);
37179 +}
37180 +/*
37181 + ========================================================================
37182 +
37183 + Routine Description:
37184 + Copy frame from waiting queue into relative ring buffer and set
37185 + appropriate ASIC register to kick hardware transmit function
37186 +
37187 + Arguments:
37188 + pAd Pointer to our adapter
37189 + PNDIS_PACKET Pointer to Ndis Packet for MIC calculation
37190 + pEncap Pointer to LLC encap data
37191 + LenEncap Total encap length, might be 0 which indicates no encap
37192 +
37193 + Return Value:
37194 + None
37195 +
37196 + IRQL = DISPATCH_LEVEL
37197 +
37198 + Note:
37199 +
37200 + ========================================================================
37201 +*/
37202 +VOID RTMPCalculateMICValue(
37203 + IN PRTMP_ADAPTER pAd,
37204 + IN PNDIS_PACKET pPacket,
37205 + IN PUCHAR pEncap,
37206 + IN PCIPHER_KEY pKey,
37207 + IN UCHAR apidx)
37208 +{
37209 + PACKET_INFO PacketInfo;
37210 + PUCHAR pSrcBufVA;
37211 + UINT SrcBufLen;
37212 + PUCHAR pSrc;
37213 + UCHAR UserPriority;
37214 + UCHAR vlan_offset = 0;
37215 +
37216 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
37217 +
37218 + UserPriority = RTMP_GET_PACKET_UP(pPacket);
37219 + pSrc = pSrcBufVA;
37220 +
37221 + // determine if this is a vlan packet
37222 + if (((*(pSrc + 12) << 8) + *(pSrc + 13)) == 0x8100)
37223 + vlan_offset = 4;
37224 +
37225 +#ifdef CONFIG_STA_SUPPORT
37226 +#endif // CONFIG_STA_SUPPORT //
37227 + {
37228 + RTMPInitMICEngine(
37229 + pAd,
37230 + pKey->Key,
37231 + pSrc,
37232 + pSrc + 6,
37233 + UserPriority,
37234 + pKey->TxMic);
37235 + }
37236 +
37237 +
37238 + if (pEncap != NULL)
37239 + {
37240 + // LLC encapsulation
37241 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pEncap, 6);
37242 + // Protocol Type
37243 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc + 12 + vlan_offset, 2);
37244 + }
37245 + SrcBufLen -= (14 + vlan_offset);
37246 + pSrc += (14 + vlan_offset);
37247 + do
37248 + {
37249 + if (SrcBufLen > 0)
37250 + {
37251 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc, SrcBufLen);
37252 + }
37253 +
37254 + break; // No need handle next packet
37255 +
37256 + } while (TRUE); // End of copying payload
37257 +
37258 + // Compute the final MIC Value
37259 + RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
37260 +}
37261 +
37262 +
37263 +/************************************************************/
37264 +/* tkip_sbox() */
37265 +/* Returns a 16 bit value from a 64K entry table. The Table */
37266 +/* is synthesized from two 256 entry byte wide tables. */
37267 +/************************************************************/
37268 +
37269 +UINT tkip_sbox(UINT index)
37270 +{
37271 + UINT index_low;
37272 + UINT index_high;
37273 + UINT left, right;
37274 +
37275 + index_low = (index % 256);
37276 + index_high = ((index >> 8) % 256);
37277 +
37278 + left = Tkip_Sbox_Lower[index_low] + (Tkip_Sbox_Upper[index_low] * 256);
37279 + right = Tkip_Sbox_Upper[index_high] + (Tkip_Sbox_Lower[index_high] * 256);
37280 +
37281 + return (left ^ right);
37282 +}
37283 +
37284 +UINT rotr1(UINT a)
37285 +{
37286 + unsigned int b;
37287 +
37288 + if ((a & 0x01) == 0x01)
37289 + {
37290 + b = (a >> 1) | 0x8000;
37291 + }
37292 + else
37293 + {
37294 + b = (a >> 1) & 0x7fff;
37295 + }
37296 + b = b % 65536;
37297 + return b;
37298 +}
37299 +
37300 +VOID RTMPTkipMixKey(
37301 + UCHAR *key,
37302 + UCHAR *ta,
37303 + ULONG pnl, /* Least significant 16 bits of PN */
37304 + ULONG pnh, /* Most significant 32 bits of PN */
37305 + UCHAR *rc4key,
37306 + UINT *p1k)
37307 +{
37308 +
37309 + UINT tsc0;
37310 + UINT tsc1;
37311 + UINT tsc2;
37312 +
37313 + UINT ppk0;
37314 + UINT ppk1;
37315 + UINT ppk2;
37316 + UINT ppk3;
37317 + UINT ppk4;
37318 + UINT ppk5;
37319 +
37320 + INT i;
37321 + INT j;
37322 +
37323 + tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
37324 + tsc1 = (unsigned int)(pnh % 65536);
37325 + tsc2 = (unsigned int)(pnl % 65536); /* lsb */
37326 +
37327 + /* Phase 1, step 1 */
37328 + p1k[0] = tsc1;
37329 + p1k[1] = tsc0;
37330 + p1k[2] = (UINT)(ta[0] + (ta[1]*256));
37331 + p1k[3] = (UINT)(ta[2] + (ta[3]*256));
37332 + p1k[4] = (UINT)(ta[4] + (ta[5]*256));
37333 +
37334 + /* Phase 1, step 2 */
37335 + for (i=0; i<8; i++)
37336 + {
37337 + j = 2*(i & 1);
37338 + p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*key[1+j]) + key[j])) % 65536 )) % 65536;
37339 + p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*key[5+j]) + key[4+j])) % 65536 )) % 65536;
37340 + p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*key[9+j]) + key[8+j])) % 65536 )) % 65536;
37341 + p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*key[13+j]) + key[12+j])) % 65536 )) % 65536;
37342 + p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*key[1+j]) + key[j]))) % 65536 )) % 65536;
37343 + p1k[4] = (p1k[4] + i) % 65536;
37344 + }
37345 +
37346 + /* Phase 2, Step 1 */
37347 + ppk0 = p1k[0];
37348 + ppk1 = p1k[1];
37349 + ppk2 = p1k[2];
37350 + ppk3 = p1k[3];
37351 + ppk4 = p1k[4];
37352 + ppk5 = (p1k[4] + tsc2) % 65536;
37353 +
37354 + /* Phase2, Step 2 */
37355 + ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*key[1]) + key[0])) % 65536);
37356 + ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*key[3]) + key[2])) % 65536);
37357 + ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*key[5]) + key[4])) % 65536);
37358 + ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*key[7]) + key[6])) % 65536);
37359 + ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*key[9]) + key[8])) % 65536);
37360 + ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*key[11]) + key[10])) % 65536);
37361 +
37362 + ppk0 = ppk0 + rotr1(ppk5 ^ ((256*key[13]) + key[12]));
37363 + ppk1 = ppk1 + rotr1(ppk0 ^ ((256*key[15]) + key[14]));
37364 + ppk2 = ppk2 + rotr1(ppk1);
37365 + ppk3 = ppk3 + rotr1(ppk2);
37366 + ppk4 = ppk4 + rotr1(ppk3);
37367 + ppk5 = ppk5 + rotr1(ppk4);
37368 +
37369 + /* Phase 2, Step 3 */
37370 + /* Phase 2, Step 3 */
37371 +
37372 + tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
37373 + tsc1 = (unsigned int)(pnh % 65536);
37374 + tsc2 = (unsigned int)(pnl % 65536); /* lsb */
37375 +
37376 + rc4key[0] = (tsc2 >> 8) % 256;
37377 + rc4key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
37378 + rc4key[2] = tsc2 % 256;
37379 + rc4key[3] = ((ppk5 ^ ((256*key[1]) + key[0])) >> 1) % 256;
37380 +
37381 + rc4key[4] = ppk0 % 256;
37382 + rc4key[5] = (ppk0 >> 8) % 256;
37383 +
37384 + rc4key[6] = ppk1 % 256;
37385 + rc4key[7] = (ppk1 >> 8) % 256;
37386 +
37387 + rc4key[8] = ppk2 % 256;
37388 + rc4key[9] = (ppk2 >> 8) % 256;
37389 +
37390 + rc4key[10] = ppk3 % 256;
37391 + rc4key[11] = (ppk3 >> 8) % 256;
37392 +
37393 + rc4key[12] = ppk4 % 256;
37394 + rc4key[13] = (ppk4 >> 8) % 256;
37395 +
37396 + rc4key[14] = ppk5 % 256;
37397 + rc4key[15] = (ppk5 >> 8) % 256;
37398 +}
37399 +
37400 +
37401 +/************************************************/
37402 +/* construct_mic_header1() */
37403 +/* Builds the first MIC header block from */
37404 +/* header fields. */
37405 +/************************************************/
37406 +
37407 +void construct_mic_header1(
37408 + unsigned char *mic_header1,
37409 + int header_length,
37410 + unsigned char *mpdu)
37411 +{
37412 + mic_header1[0] = (unsigned char)((header_length - 2) / 256);
37413 + mic_header1[1] = (unsigned char)((header_length - 2) % 256);
37414 + mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */
37415 + mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */
37416 + mic_header1[4] = mpdu[4]; /* A1 */
37417 + mic_header1[5] = mpdu[5];
37418 + mic_header1[6] = mpdu[6];
37419 + mic_header1[7] = mpdu[7];
37420 + mic_header1[8] = mpdu[8];
37421 + mic_header1[9] = mpdu[9];
37422 + mic_header1[10] = mpdu[10]; /* A2 */
37423 + mic_header1[11] = mpdu[11];
37424 + mic_header1[12] = mpdu[12];
37425 + mic_header1[13] = mpdu[13];
37426 + mic_header1[14] = mpdu[14];
37427 + mic_header1[15] = mpdu[15];
37428 +}
37429 +
37430 +/************************************************/
37431 +/* construct_mic_header2() */
37432 +/* Builds the last MIC header block from */
37433 +/* header fields. */
37434 +/************************************************/
37435 +
37436 +void construct_mic_header2(
37437 + unsigned char *mic_header2,
37438 + unsigned char *mpdu,
37439 + int a4_exists,
37440 + int qc_exists)
37441 +{
37442 + int i;
37443 +
37444 + for (i = 0; i<16; i++) mic_header2[i]=0x00;
37445 +
37446 + mic_header2[0] = mpdu[16]; /* A3 */
37447 + mic_header2[1] = mpdu[17];
37448 + mic_header2[2] = mpdu[18];
37449 + mic_header2[3] = mpdu[19];
37450 + mic_header2[4] = mpdu[20];
37451 + mic_header2[5] = mpdu[21];
37452 +
37453 + // In Sequence Control field, mute sequence numer bits (12-bit)
37454 + mic_header2[6] = mpdu[22] & 0x0f; /* SC */
37455 + mic_header2[7] = 0x00; /* mpdu[23]; */
37456 +
37457 + if ((!qc_exists) & a4_exists)
37458 + {
37459 + for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
37460 +
37461 + }
37462 +
37463 + if (qc_exists && (!a4_exists))
37464 + {
37465 + mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */
37466 + mic_header2[9] = mpdu[25] & 0x00;
37467 + }
37468 +
37469 + if (qc_exists && a4_exists)
37470 + {
37471 + for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
37472 +
37473 + mic_header2[14] = mpdu[30] & 0x0f;
37474 + mic_header2[15] = mpdu[31] & 0x00;
37475 + }
37476 +}
37477 +
37478 +
37479 +/************************************************/
37480 +/* construct_mic_iv() */
37481 +/* Builds the MIC IV from header fields and PN */
37482 +/************************************************/
37483 +
37484 +void construct_mic_iv(
37485 + unsigned char *mic_iv,
37486 + int qc_exists,
37487 + int a4_exists,
37488 + unsigned char *mpdu,
37489 + unsigned int payload_length,
37490 + unsigned char *pn_vector)
37491 +{
37492 + int i;
37493 +
37494 + mic_iv[0] = 0x59;
37495 + if (qc_exists && a4_exists)
37496 + mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */
37497 + if (qc_exists && !a4_exists)
37498 + mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */
37499 + if (!qc_exists)
37500 + mic_iv[1] = 0x00;
37501 + for (i = 2; i < 8; i++)
37502 + mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */
37503 +#ifdef CONSISTENT_PN_ORDER
37504 + for (i = 8; i < 14; i++)
37505 + mic_iv[i] = pn_vector[i - 8]; /* mic_iv[8:13] = PN[0:5] */
37506 +#else
37507 + for (i = 8; i < 14; i++)
37508 + mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */
37509 +#endif
37510 + i = (payload_length / 256);
37511 + i = (payload_length % 256);
37512 + mic_iv[14] = (unsigned char) (payload_length / 256);
37513 + mic_iv[15] = (unsigned char) (payload_length % 256);
37514 +
37515 +}
37516 +
37517 +
37518 +
37519 +/************************************/
37520 +/* bitwise_xor() */
37521 +/* A 128 bit, bitwise exclusive or */
37522 +/************************************/
37523 +
37524 +void bitwise_xor(unsigned char *ina, unsigned char *inb, unsigned char *out)
37525 +{
37526 + int i;
37527 + for (i=0; i<16; i++)
37528 + {
37529 + out[i] = ina[i] ^ inb[i];
37530 + }
37531 +}
37532 +
37533 +
37534 +void aes128k128d(unsigned char *key, unsigned char *data, unsigned char *ciphertext)
37535 +{
37536 + int round;
37537 + int i;
37538 + unsigned char intermediatea[16];
37539 + unsigned char intermediateb[16];
37540 + unsigned char round_key[16];
37541 +
37542 + for(i=0; i<16; i++) round_key[i] = key[i];
37543 +
37544 + for (round = 0; round < 11; round++)
37545 + {
37546 + if (round == 0)
37547 + {
37548 + xor_128(round_key, data, ciphertext);
37549 + next_key(round_key, round);
37550 + }
37551 + else if (round == 10)
37552 + {
37553 + byte_sub(ciphertext, intermediatea);
37554 + shift_row(intermediatea, intermediateb);
37555 + xor_128(intermediateb, round_key, ciphertext);
37556 + }
37557 + else /* 1 - 9 */
37558 + {
37559 + byte_sub(ciphertext, intermediatea);
37560 + shift_row(intermediatea, intermediateb);
37561 + mix_column(&intermediateb[0], &intermediatea[0]);
37562 + mix_column(&intermediateb[4], &intermediatea[4]);
37563 + mix_column(&intermediateb[8], &intermediatea[8]);
37564 + mix_column(&intermediateb[12], &intermediatea[12]);
37565 + xor_128(intermediatea, round_key, ciphertext);
37566 + next_key(round_key, round);
37567 + }
37568 + }
37569 +
37570 +}
37571 +
37572 +void construct_ctr_preload(
37573 + unsigned char *ctr_preload,
37574 + int a4_exists,
37575 + int qc_exists,
37576 + unsigned char *mpdu,
37577 + unsigned char *pn_vector,
37578 + int c)
37579 +{
37580 +
37581 + int i = 0;
37582 + for (i=0; i<16; i++) ctr_preload[i] = 0x00;
37583 + i = 0;
37584 +
37585 + ctr_preload[0] = 0x01; /* flag */
37586 + if (qc_exists && a4_exists) ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */
37587 + if (qc_exists && !a4_exists) ctr_preload[1] = mpdu[24] & 0x0f;
37588 +
37589 + for (i = 2; i < 8; i++)
37590 + ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
37591 +#ifdef CONSISTENT_PN_ORDER
37592 + for (i = 8; i < 14; i++)
37593 + ctr_preload[i] = pn_vector[i - 8]; /* ctr_preload[8:13] = PN[0:5] */
37594 +#else
37595 + for (i = 8; i < 14; i++)
37596 + ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */
37597 +#endif
37598 + ctr_preload[14] = (unsigned char) (c / 256); // Ctr
37599 + ctr_preload[15] = (unsigned char) (c % 256);
37600 +
37601 +}
37602 +
37603 +
37604 +//
37605 +// TRUE: Success!
37606 +// FALSE: Decrypt Error!
37607 +//
37608 +BOOLEAN RTMPSoftDecryptTKIP(
37609 + IN PRTMP_ADAPTER pAd,
37610 + IN PUCHAR pData,
37611 + IN ULONG DataByteCnt,
37612 + IN UCHAR UserPriority,
37613 + IN PCIPHER_KEY pWpaKey)
37614 +{
37615 + UCHAR KeyID;
37616 + UINT HeaderLen;
37617 + UCHAR fc0;
37618 + UCHAR fc1;
37619 + USHORT fc;
37620 + UINT frame_type;
37621 + UINT frame_subtype;
37622 + UINT from_ds;
37623 + UINT to_ds;
37624 + INT a4_exists;
37625 + INT qc_exists;
37626 + USHORT duration;
37627 + USHORT seq_control;
37628 + USHORT qos_control;
37629 + UCHAR TA[MAC_ADDR_LEN];
37630 + UCHAR DA[MAC_ADDR_LEN];
37631 + UCHAR SA[MAC_ADDR_LEN];
37632 + UCHAR RC4Key[16];
37633 + UINT p1k[5]; //for mix_key;
37634 + ULONG pnl;/* Least significant 16 bits of PN */
37635 + ULONG pnh;/* Most significant 32 bits of PN */
37636 + UINT num_blocks;
37637 + UINT payload_remainder;
37638 + ARCFOURCONTEXT ArcFourContext;
37639 + UINT crc32 = 0;
37640 + UINT trailfcs = 0;
37641 + UCHAR MIC[8];
37642 + UCHAR TrailMIC[8];
37643 +
37644 +#ifdef RT_BIG_ENDIAN
37645 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
37646 +#endif
37647 +
37648 + fc0 = *pData;
37649 + fc1 = *(pData + 1);
37650 +
37651 + fc = *((PUSHORT)pData);
37652 +
37653 + frame_type = ((fc0 >> 2) & 0x03);
37654 + frame_subtype = ((fc0 >> 4) & 0x0f);
37655 +
37656 + from_ds = (fc1 & 0x2) >> 1;
37657 + to_ds = (fc1 & 0x1);
37658 +
37659 + a4_exists = (from_ds & to_ds);
37660 + qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
37661 + (frame_subtype == 0x09) || /* Likely to change. */
37662 + (frame_subtype == 0x0a) ||
37663 + (frame_subtype == 0x0b)
37664 + );
37665 +
37666 + HeaderLen = 24;
37667 + if (a4_exists)
37668 + HeaderLen += 6;
37669 +
37670 + KeyID = *((PUCHAR)(pData+ HeaderLen + 3));
37671 + KeyID = KeyID >> 6;
37672 +
37673 + if (pWpaKey[KeyID].KeyLen == 0)
37674 + {
37675 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP failed!(KeyID[%d] Length can not be 0)\n", KeyID));
37676 + return FALSE;
37677 + }
37678 +
37679 + duration = *((PUSHORT)(pData+2));
37680 +
37681 + seq_control = *((PUSHORT)(pData+22));
37682 +
37683 + if (qc_exists)
37684 + {
37685 + if (a4_exists)
37686 + {
37687 + qos_control = *((PUSHORT)(pData+30));
37688 + }
37689 + else
37690 + {
37691 + qos_control = *((PUSHORT)(pData+24));
37692 + }
37693 + }
37694 +
37695 + if (to_ds == 0 && from_ds == 1)
37696 + {
37697 + NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN);
37698 + NdisMoveMemory(SA, pData+16, MAC_ADDR_LEN);
37699 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); //BSSID
37700 + }
37701 + else if (to_ds == 0 && from_ds == 0 )
37702 + {
37703 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
37704 + NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN);
37705 + NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN);
37706 + }
37707 + else if (to_ds == 1 && from_ds == 0)
37708 + {
37709 + NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN);
37710 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
37711 + NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN);
37712 + }
37713 + else if (to_ds == 1 && from_ds == 1)
37714 + {
37715 + NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN);
37716 + NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN);
37717 + NdisMoveMemory(SA, pData+22, MAC_ADDR_LEN);
37718 + }
37719 +
37720 + num_blocks = (DataByteCnt - 16) / 16;
37721 + payload_remainder = (DataByteCnt - 16) % 16;
37722 +
37723 + pnl = (*(pData + HeaderLen)) * 256 + *(pData + HeaderLen + 2);
37724 + pnh = *((PULONG)(pData + HeaderLen + 4));
37725 + pnh = cpu2le32(pnh);
37726 + RTMPTkipMixKey(pWpaKey[KeyID].Key, TA, pnl, pnh, RC4Key, p1k);
37727 +
37728 + ARCFOUR_INIT(&ArcFourContext, RC4Key, 16);
37729 +
37730 + ARCFOUR_DECRYPT(&ArcFourContext, pData + HeaderLen, pData + HeaderLen + 8, DataByteCnt - HeaderLen - 8);
37731 + NdisMoveMemory(&trailfcs, pData + DataByteCnt - 8 - 4, 4);
37732 + crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 4); //Skip IV+EIV 8 bytes & Skip last 4 bytes(FCS).
37733 + crc32 ^= 0xffffffff; /* complement */
37734 +
37735 + if(crc32 != cpu2le32(trailfcs))
37736 + {
37737 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP, WEP Data ICV Error !\n")); //ICV error.
37738 +
37739 + return (FALSE);
37740 + }
37741 +
37742 + NdisMoveMemory(TrailMIC, pData + DataByteCnt - 8 - 8 - 4, 8);
37743 + RTMPInitMICEngine(pAd, pWpaKey[KeyID].Key, DA, SA, UserPriority, pWpaKey[KeyID].RxMic);
37744 + RTMPTkipAppend(&pAd->PrivateInfo.Tx, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 12);
37745 + RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
37746 + NdisMoveMemory(MIC, pAd->PrivateInfo.Tx.MIC, 8);
37747 +
37748 + if (!NdisEqualMemory(MIC, TrailMIC, 8))
37749 + {
37750 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptTKIP, WEP Data MIC Error !\n")); //MIC error.
37751 + //RTMPReportMicError(pAd, &pWpaKey[KeyID]); // marked by AlbertY @ 20060630
37752 + return (FALSE);
37753 + }
37754 +
37755 +#ifdef RT_BIG_ENDIAN
37756 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
37757 +#endif
37758 + //DBGPRINT(RT_DEBUG_TRACE, "RTMPSoftDecryptTKIP Decript done!!\n");
37759 + return TRUE;
37760 +}
37761 +
37762 +
37763 +
37764 +
37765 +BOOLEAN RTMPSoftDecryptAES(
37766 + IN PRTMP_ADAPTER pAd,
37767 + IN PUCHAR pData,
37768 + IN ULONG DataByteCnt,
37769 + IN PCIPHER_KEY pWpaKey)
37770 +{
37771 + UCHAR KeyID;
37772 + UINT HeaderLen;
37773 + UCHAR PN[6];
37774 + UINT payload_len;
37775 + UINT num_blocks;
37776 + UINT payload_remainder;
37777 + USHORT fc;
37778 + UCHAR fc0;
37779 + UCHAR fc1;
37780 + UINT frame_type;
37781 + UINT frame_subtype;
37782 + UINT from_ds;
37783 + UINT to_ds;
37784 + INT a4_exists;
37785 + INT qc_exists;
37786 + UCHAR aes_out[16];
37787 + int payload_index;
37788 + UINT i;
37789 + UCHAR ctr_preload[16];
37790 + UCHAR chain_buffer[16];
37791 + UCHAR padded_buffer[16];
37792 + UCHAR mic_iv[16];
37793 + UCHAR mic_header1[16];
37794 + UCHAR mic_header2[16];
37795 + UCHAR MIC[8];
37796 + UCHAR TrailMIC[8];
37797 +
37798 +#ifdef RT_BIG_ENDIAN
37799 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
37800 +#endif
37801 +
37802 + fc0 = *pData;
37803 + fc1 = *(pData + 1);
37804 +
37805 + fc = *((PUSHORT)pData);
37806 +
37807 + frame_type = ((fc0 >> 2) & 0x03);
37808 + frame_subtype = ((fc0 >> 4) & 0x0f);
37809 +
37810 + from_ds = (fc1 & 0x2) >> 1;
37811 + to_ds = (fc1 & 0x1);
37812 +
37813 + a4_exists = (from_ds & to_ds);
37814 + qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
37815 + (frame_subtype == 0x09) || /* Likely to change. */
37816 + (frame_subtype == 0x0a) ||
37817 + (frame_subtype == 0x0b)
37818 + );
37819 +
37820 + HeaderLen = 24;
37821 + if (a4_exists)
37822 + HeaderLen += 6;
37823 +
37824 + KeyID = *((PUCHAR)(pData+ HeaderLen + 3));
37825 + KeyID = KeyID >> 6;
37826 +
37827 + if (pWpaKey[KeyID].KeyLen == 0)
37828 + {
37829 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptAES failed!(KeyID[%d] Length can not be 0)\n", KeyID));
37830 + return FALSE;
37831 + }
37832 +
37833 + PN[0] = *(pData+ HeaderLen);
37834 + PN[1] = *(pData+ HeaderLen + 1);
37835 + PN[2] = *(pData+ HeaderLen + 4);
37836 + PN[3] = *(pData+ HeaderLen + 5);
37837 + PN[4] = *(pData+ HeaderLen + 6);
37838 + PN[5] = *(pData+ HeaderLen + 7);
37839 +
37840 + payload_len = DataByteCnt - HeaderLen - 8 - 8; // 8 bytes for CCMP header , 8 bytes for MIC
37841 + payload_remainder = (payload_len) % 16;
37842 + num_blocks = (payload_len) / 16;
37843 +
37844 +
37845 +
37846 + // Find start of payload
37847 + payload_index = HeaderLen + 8; //IV+EIV
37848 +
37849 + for (i=0; i< num_blocks; i++)
37850 + {
37851 + construct_ctr_preload(ctr_preload,
37852 + a4_exists,
37853 + qc_exists,
37854 + pData,
37855 + PN,
37856 + i+1 );
37857 +
37858 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
37859 +
37860 + bitwise_xor(aes_out, pData + payload_index, chain_buffer);
37861 + NdisMoveMemory(pData + payload_index - 8, chain_buffer, 16);
37862 + payload_index += 16;
37863 + }
37864 +
37865 + //
37866 + // If there is a short final block, then pad it
37867 + // encrypt it and copy the unpadded part back
37868 + //
37869 + if (payload_remainder > 0)
37870 + {
37871 + construct_ctr_preload(ctr_preload,
37872 + a4_exists,
37873 + qc_exists,
37874 + pData,
37875 + PN,
37876 + num_blocks + 1);
37877 +
37878 + NdisZeroMemory(padded_buffer, 16);
37879 + NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder);
37880 +
37881 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
37882 +
37883 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
37884 + NdisMoveMemory(pData + payload_index - 8, chain_buffer, payload_remainder);
37885 + payload_index += payload_remainder;
37886 + }
37887 +
37888 + //
37889 + // Descrypt the MIC
37890 + //
37891 + construct_ctr_preload(ctr_preload,
37892 + a4_exists,
37893 + qc_exists,
37894 + pData,
37895 + PN,
37896 + 0);
37897 + NdisZeroMemory(padded_buffer, 16);
37898 + NdisMoveMemory(padded_buffer, pData + payload_index, 8);
37899 +
37900 + aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
37901 +
37902 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
37903 +
37904 + NdisMoveMemory(TrailMIC, chain_buffer, 8);
37905 +
37906 + //
37907 + // Calculate MIC
37908 + //
37909 +
37910 + //Force the protected frame bit on
37911 + *(pData + 1) = *(pData + 1) | 0x40;
37912 +
37913 + // Find start of payload
37914 + // Because the CCMP header has been removed
37915 + payload_index = HeaderLen;
37916 +
37917 + construct_mic_iv(
37918 + mic_iv,
37919 + qc_exists,
37920 + a4_exists,
37921 + pData,
37922 + payload_len,
37923 + PN);
37924 +
37925 + construct_mic_header1(
37926 + mic_header1,
37927 + HeaderLen,
37928 + pData);
37929 +
37930 + construct_mic_header2(
37931 + mic_header2,
37932 + pData,
37933 + a4_exists,
37934 + qc_exists);
37935 +
37936 + aes128k128d(pWpaKey[KeyID].Key, mic_iv, aes_out);
37937 + bitwise_xor(aes_out, mic_header1, chain_buffer);
37938 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37939 + bitwise_xor(aes_out, mic_header2, chain_buffer);
37940 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37941 +
37942 + // iterate through each 16 byte payload block
37943 + for (i = 0; i < num_blocks; i++)
37944 + {
37945 + bitwise_xor(aes_out, pData + payload_index, chain_buffer);
37946 + payload_index += 16;
37947 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37948 + }
37949 +
37950 + // Add on the final payload block if it needs padding
37951 + if (payload_remainder > 0)
37952 + {
37953 + NdisZeroMemory(padded_buffer, 16);
37954 + NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder);
37955 +
37956 + bitwise_xor(aes_out, padded_buffer, chain_buffer);
37957 + aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
37958 + }
37959 +
37960 + // aes_out contains padded mic, discard most significant
37961 + // 8 bytes to generate 64 bit MIC
37962 + for (i = 0 ; i < 8; i++) MIC[i] = aes_out[i];
37963 +
37964 + if (!NdisEqualMemory(MIC, TrailMIC, 8))
37965 + {
37966 + DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptAES, MIC Error !\n")); //MIC error.
37967 + return FALSE;
37968 + }
37969 +
37970 +#ifdef RT_BIG_ENDIAN
37971 + RTMPFrameEndianChange(pAd, (PUCHAR)pData, DIR_READ, FALSE);
37972 +#endif
37973 +
37974 + return TRUE;
37975 +}
37976 +
37977 +/****************************************/
37978 +/* aes128k128d() */
37979 +/* Performs a 128 bit AES encrypt with */
37980 +/* 128 bit data. */
37981 +/****************************************/
37982 +VOID xor_128(
37983 + IN PUCHAR a,
37984 + IN PUCHAR b,
37985 + OUT PUCHAR out)
37986 +{
37987 + INT i;
37988 +
37989 + for (i=0;i<16; i++)
37990 + {
37991 + out[i] = a[i] ^ b[i];
37992 + }
37993 +}
37994 +
37995 +VOID next_key(
37996 + IN PUCHAR key,
37997 + IN INT round)
37998 +{
37999 + UCHAR rcon;
38000 + UCHAR sbox_key[4];
38001 + UCHAR rcon_table[12] =
38002 + {
38003 + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
38004 + 0x1b, 0x36, 0x36, 0x36
38005 + };
38006 +
38007 + sbox_key[0] = RTMPCkipSbox(key[13]);
38008 + sbox_key[1] = RTMPCkipSbox(key[14]);
38009 + sbox_key[2] = RTMPCkipSbox(key[15]);
38010 + sbox_key[3] = RTMPCkipSbox(key[12]);
38011 +
38012 + rcon = rcon_table[round];
38013 +
38014 + xor_32(&key[0], sbox_key, &key[0]);
38015 + key[0] = key[0] ^ rcon;
38016 +
38017 + xor_32(&key[4], &key[0], &key[4]);
38018 + xor_32(&key[8], &key[4], &key[8]);
38019 + xor_32(&key[12], &key[8], &key[12]);
38020 +}
38021 +
38022 +VOID xor_32(
38023 + IN PUCHAR a,
38024 + IN PUCHAR b,
38025 + OUT PUCHAR out)
38026 +{
38027 + INT i;
38028 +
38029 + for (i=0;i<4; i++)
38030 + {
38031 + out[i] = a[i] ^ b[i];
38032 + }
38033 +}
38034 +
38035 +VOID byte_sub(
38036 + IN PUCHAR in,
38037 + OUT PUCHAR out)
38038 +{
38039 + INT i;
38040 +
38041 + for (i=0; i< 16; i++)
38042 + {
38043 + out[i] = RTMPCkipSbox(in[i]);
38044 + }
38045 +}
38046 +
38047 +UCHAR RTMPCkipSbox(
38048 + IN UCHAR a)
38049 +{
38050 + return SboxTable[(int)a];
38051 +}
38052 +
38053 +VOID shift_row(
38054 + IN PUCHAR in,
38055 + OUT PUCHAR out)
38056 +{
38057 + out[0] = in[0];
38058 + out[1] = in[5];
38059 + out[2] = in[10];
38060 + out[3] = in[15];
38061 + out[4] = in[4];
38062 + out[5] = in[9];
38063 + out[6] = in[14];
38064 + out[7] = in[3];
38065 + out[8] = in[8];
38066 + out[9] = in[13];
38067 + out[10] = in[2];
38068 + out[11] = in[7];
38069 + out[12] = in[12];
38070 + out[13] = in[1];
38071 + out[14] = in[6];
38072 + out[15] = in[11];
38073 +}
38074 +
38075 +VOID mix_column(
38076 + IN PUCHAR in,
38077 + OUT PUCHAR out)
38078 +{
38079 + INT i;
38080 + UCHAR add1b[4];
38081 + UCHAR add1bf7[4];
38082 + UCHAR rotl[4];
38083 + UCHAR swap_halfs[4];
38084 + UCHAR andf7[4];
38085 + UCHAR rotr[4];
38086 + UCHAR temp[4];
38087 + UCHAR tempb[4];
38088 +
38089 + for (i=0 ; i<4; i++)
38090 + {
38091 + if ((in[i] & 0x80)== 0x80)
38092 + add1b[i] = 0x1b;
38093 + else
38094 + add1b[i] = 0x00;
38095 + }
38096 +
38097 + swap_halfs[0] = in[2]; /* Swap halfs */
38098 + swap_halfs[1] = in[3];
38099 + swap_halfs[2] = in[0];
38100 + swap_halfs[3] = in[1];
38101 +
38102 + rotl[0] = in[3]; /* Rotate left 8 bits */
38103 + rotl[1] = in[0];
38104 + rotl[2] = in[1];
38105 + rotl[3] = in[2];
38106 +
38107 + andf7[0] = in[0] & 0x7f;
38108 + andf7[1] = in[1] & 0x7f;
38109 + andf7[2] = in[2] & 0x7f;
38110 + andf7[3] = in[3] & 0x7f;
38111 +
38112 + for (i = 3; i>0; i--) /* logical shift left 1 bit */
38113 + {
38114 + andf7[i] = andf7[i] << 1;
38115 + if ((andf7[i-1] & 0x80) == 0x80)
38116 + {
38117 + andf7[i] = (andf7[i] | 0x01);
38118 + }
38119 + }
38120 + andf7[0] = andf7[0] << 1;
38121 + andf7[0] = andf7[0] & 0xfe;
38122 +
38123 + xor_32(add1b, andf7, add1bf7);
38124 +
38125 + xor_32(in, add1bf7, rotr);
38126 +
38127 + temp[0] = rotr[0]; /* Rotate right 8 bits */
38128 + rotr[0] = rotr[1];
38129 + rotr[1] = rotr[2];
38130 + rotr[2] = rotr[3];
38131 + rotr[3] = temp[0];
38132 +
38133 + xor_32(add1bf7, rotr, temp);
38134 + xor_32(swap_halfs, rotl,tempb);
38135 + xor_32(temp, tempb, out);
38136 +}
38137 +
38138 --- /dev/null
38139 +++ b/drivers/staging/rt3070/common/rtmp_wep.c
38140 @@ -0,0 +1,508 @@
38141 +/*
38142 + *************************************************************************
38143 + * Ralink Tech Inc.
38144 + * 5F., No.36, Taiyuan St., Jhubei City,
38145 + * Hsinchu County 302,
38146 + * Taiwan, R.O.C.
38147 + *
38148 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
38149 + *
38150 + * This program is free software; you can redistribute it and/or modify *
38151 + * it under the terms of the GNU General Public License as published by *
38152 + * the Free Software Foundation; either version 2 of the License, or *
38153 + * (at your option) any later version. *
38154 + * *
38155 + * This program is distributed in the hope that it will be useful, *
38156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
38157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
38158 + * GNU General Public License for more details. *
38159 + * *
38160 + * You should have received a copy of the GNU General Public License *
38161 + * along with this program; if not, write to the *
38162 + * Free Software Foundation, Inc., *
38163 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
38164 + * *
38165 + *************************************************************************
38166 +
38167 + Module Name:
38168 + rtmp_wep.c
38169 +
38170 + Abstract:
38171 +
38172 + Revision History:
38173 + Who When What
38174 + -------- ---------- ----------------------------------------------
38175 + Paul Wu 10-28-02 Initial
38176 +*/
38177 +
38178 +#include "../rt_config.h"
38179 +
38180 +UINT FCSTAB_32[256] =
38181 +{
38182 + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
38183 + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
38184 + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
38185 + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
38186 + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
38187 + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
38188 + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
38189 + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
38190 + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
38191 + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
38192 + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
38193 + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
38194 + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
38195 + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
38196 + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
38197 + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
38198 + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
38199 + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
38200 + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
38201 + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
38202 + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
38203 + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
38204 + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
38205 + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
38206 + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
38207 + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
38208 + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
38209 + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
38210 + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
38211 + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
38212 + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
38213 + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
38214 + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
38215 + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
38216 + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
38217 + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
38218 + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
38219 + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
38220 + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
38221 + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
38222 + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
38223 + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
38224 + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
38225 + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
38226 + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
38227 + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
38228 + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
38229 + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
38230 + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
38231 + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
38232 + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
38233 + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
38234 + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
38235 + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
38236 + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
38237 + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
38238 + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
38239 + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
38240 + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
38241 + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
38242 + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
38243 + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
38244 + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
38245 + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
38246 +};
38247 +
38248 +/*
38249 +UCHAR WEPKEY[] = {
38250 + //IV
38251 + 0x00, 0x11, 0x22,
38252 + //WEP KEY
38253 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
38254 + };
38255 + */
38256 +
38257 +/*
38258 + ========================================================================
38259 +
38260 + Routine Description:
38261 + Init WEP function.
38262 +
38263 + Arguments:
38264 + pAd Pointer to our adapter
38265 + pKey Pointer to the WEP KEY
38266 + KeyId WEP Key ID
38267 + KeyLen the length of WEP KEY
38268 + pDest Pointer to the destination which Encryption data will store in.
38269 +
38270 + Return Value:
38271 + None
38272 +
38273 + IRQL = DISPATCH_LEVEL
38274 +
38275 + Note:
38276 +
38277 + ========================================================================
38278 +*/
38279 +VOID RTMPInitWepEngine(
38280 + IN PRTMP_ADAPTER pAd,
38281 + IN PUCHAR pKey,
38282 + IN UCHAR KeyId,
38283 + IN UCHAR KeyLen,
38284 + IN OUT PUCHAR pDest)
38285 +{
38286 + UINT i;
38287 + UCHAR WEPKEY[] = {
38288 + //IV
38289 + 0x00, 0x11, 0x22,
38290 + //WEP KEY
38291 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
38292 + };
38293 +
38294 + pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32.
38295 +
38296 +#ifdef CONFIG_STA_SUPPORT
38297 + if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10) && (pAd->OpMode == OPMODE_STA))
38298 + {
38299 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, pKey, KeyLen); //INIT SBOX, KEYLEN+3(IV)
38300 + NdisMoveMemory(pDest, pKey, 3); //Append Init Vector
38301 + }
38302 + else
38303 +#endif // CONFIG_STA_SUPPORT //
38304 + {
38305 + NdisMoveMemory(WEPKEY + 3, pKey, KeyLen);
38306 +
38307 + for(i = 0; i < 3; i++)
38308 + WEPKEY[i] = RandomByte(pAd); //Call mlme RandomByte() function.
38309 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, KeyLen + 3); //INIT SBOX, KEYLEN+3(IV)
38310 +
38311 + NdisMoveMemory(pDest, WEPKEY, 3); //Append Init Vector
38312 + }
38313 + *(pDest+3) = (KeyId << 6); //Append KEYID
38314 +
38315 +}
38316 +
38317 +/*
38318 + ========================================================================
38319 +
38320 + Routine Description:
38321 + Encrypt transimitted data
38322 +
38323 + Arguments:
38324 + pAd Pointer to our adapter
38325 + pSrc Pointer to the transimitted source data that will be encrypt
38326 + pDest Pointer to the destination where entryption data will be store in.
38327 + Len Indicate the length of the source data
38328 +
38329 + Return Value:
38330 + None
38331 +
38332 + IRQL = DISPATCH_LEVEL
38333 +
38334 + Note:
38335 +
38336 + ========================================================================
38337 +*/
38338 +VOID RTMPEncryptData(
38339 + IN PRTMP_ADAPTER pAd,
38340 + IN PUCHAR pSrc,
38341 + IN PUCHAR pDest,
38342 + IN UINT Len)
38343 +{
38344 + pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, pSrc, Len);
38345 + ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, pSrc, Len);
38346 +}
38347 +
38348 +
38349 +/*
38350 + ========================================================================
38351 +
38352 + Routine Description:
38353 + Decrypt received WEP data
38354 +
38355 + Arguments:
38356 + pAdapter Pointer to our adapter
38357 + pSrc Pointer to the received data
38358 + Len the length of the received data
38359 +
38360 + Return Value:
38361 + TRUE Decrypt WEP data success
38362 + FALSE Decrypt WEP data failed
38363 +
38364 + Note:
38365 +
38366 + ========================================================================
38367 +*/
38368 +BOOLEAN RTMPSoftDecryptWEP(
38369 + IN PRTMP_ADAPTER pAd,
38370 + IN PUCHAR pData,
38371 + IN ULONG DataByteCnt,
38372 + IN PCIPHER_KEY pGroupKey)
38373 +{
38374 + UINT trailfcs;
38375 + UINT crc32;
38376 + UCHAR KeyIdx;
38377 + UCHAR WEPKEY[] = {
38378 + //IV
38379 + 0x00, 0x11, 0x22,
38380 + //WEP KEY
38381 + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
38382 + };
38383 + UCHAR *pPayload = (UCHAR *)pData + LENGTH_802_11;
38384 + ULONG payload_len = DataByteCnt - LENGTH_802_11;
38385 +
38386 + NdisMoveMemory(WEPKEY, pPayload, 3); //Get WEP IV
38387 +
38388 + KeyIdx = (*(pPayload + 3) & 0xc0) >> 6;
38389 + if (pGroupKey[KeyIdx].KeyLen == 0)
38390 + return (FALSE);
38391 +
38392 + NdisMoveMemory(WEPKEY + 3, pGroupKey[KeyIdx].Key, pGroupKey[KeyIdx].KeyLen);
38393 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, pGroupKey[KeyIdx].KeyLen + 3);
38394 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, pPayload, pPayload + 4, payload_len - 4);
38395 + NdisMoveMemory(&trailfcs, pPayload + payload_len - 8, 4);
38396 + crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pPayload, payload_len - 8); //Skip last 4 bytes(FCS).
38397 + crc32 ^= 0xffffffff; /* complement */
38398 +
38399 + if(crc32 != cpu2le32(trailfcs))
38400 + {
38401 + DBGPRINT(RT_DEBUG_TRACE, ("! WEP Data CRC Error !\n")); //CRC error.
38402 + return (FALSE);
38403 + }
38404 + return (TRUE);
38405 +}
38406 +
38407 +/*
38408 + ========================================================================
38409 +
38410 + Routine Description:
38411 + The Stream Cipher Encryption Algorithm "ARCFOUR" initialize
38412 +
38413 + Arguments:
38414 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
38415 + pKey Pointer to the WEP KEY
38416 + KeyLen Indicate the length fo the WEP KEY
38417 +
38418 + Return Value:
38419 + None
38420 +
38421 + IRQL = DISPATCH_LEVEL
38422 +
38423 + Note:
38424 +
38425 + ========================================================================
38426 +*/
38427 +VOID ARCFOUR_INIT(
38428 + IN PARCFOURCONTEXT Ctx,
38429 + IN PUCHAR pKey,
38430 + IN UINT KeyLen)
38431 +{
38432 + UCHAR t, u;
38433 + UINT keyindex;
38434 + UINT stateindex;
38435 + PUCHAR state;
38436 + UINT counter;
38437 +
38438 + state = Ctx->STATE;
38439 + Ctx->X = 0;
38440 + Ctx->Y = 0;
38441 + for (counter = 0; counter < 256; counter++)
38442 + state[counter] = (UCHAR)counter;
38443 + keyindex = 0;
38444 + stateindex = 0;
38445 + for (counter = 0; counter < 256; counter++)
38446 + {
38447 + t = state[counter];
38448 + stateindex = (stateindex + pKey[keyindex] + t) & 0xff;
38449 + u = state[stateindex];
38450 + state[stateindex] = t;
38451 + state[counter] = u;
38452 + if (++keyindex >= KeyLen)
38453 + keyindex = 0;
38454 + }
38455 +}
38456 +
38457 +/*
38458 + ========================================================================
38459 +
38460 + Routine Description:
38461 + Get bytes from ARCFOUR CONTEXT (S-BOX)
38462 +
38463 + Arguments:
38464 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
38465 +
38466 + Return Value:
38467 + UCHAR - the value of the ARCFOUR CONTEXT (S-BOX)
38468 +
38469 + Note:
38470 +
38471 + ========================================================================
38472 +*/
38473 +UCHAR ARCFOUR_BYTE(
38474 + IN PARCFOURCONTEXT Ctx)
38475 +{
38476 + UINT x;
38477 + UINT y;
38478 + UCHAR sx, sy;
38479 + PUCHAR state;
38480 +
38481 + state = Ctx->STATE;
38482 + x = (Ctx->X + 1) & 0xff;
38483 + sx = state[x];
38484 + y = (sx + Ctx->Y) & 0xff;
38485 + sy = state[y];
38486 + Ctx->X = x;
38487 + Ctx->Y = y;
38488 + state[y] = sx;
38489 + state[x] = sy;
38490 +
38491 + return(state[(sx + sy) & 0xff]);
38492 +
38493 +}
38494 +
38495 +/*
38496 + ========================================================================
38497 +
38498 + Routine Description:
38499 + The Stream Cipher Decryption Algorithm
38500 +
38501 + Arguments:
38502 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
38503 + pDest Pointer to the Destination
38504 + pSrc Pointer to the Source data
38505 + Len Indicate the length of the Source data
38506 +
38507 + Return Value:
38508 + None
38509 +
38510 + Note:
38511 +
38512 + ========================================================================
38513 +*/
38514 +VOID ARCFOUR_DECRYPT(
38515 + IN PARCFOURCONTEXT Ctx,
38516 + IN PUCHAR pDest,
38517 + IN PUCHAR pSrc,
38518 + IN UINT Len)
38519 +{
38520 + UINT i;
38521 +
38522 + for (i = 0; i < Len; i++)
38523 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
38524 +}
38525 +
38526 +/*
38527 + ========================================================================
38528 +
38529 + Routine Description:
38530 + The Stream Cipher Encryption Algorithm
38531 +
38532 + Arguments:
38533 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
38534 + pDest Pointer to the Destination
38535 + pSrc Pointer to the Source data
38536 + Len Indicate the length of the Source dta
38537 +
38538 + Return Value:
38539 + None
38540 +
38541 + IRQL = DISPATCH_LEVEL
38542 +
38543 + Note:
38544 +
38545 + ========================================================================
38546 +*/
38547 +VOID ARCFOUR_ENCRYPT(
38548 + IN PARCFOURCONTEXT Ctx,
38549 + IN PUCHAR pDest,
38550 + IN PUCHAR pSrc,
38551 + IN UINT Len)
38552 +{
38553 + UINT i;
38554 +
38555 + for (i = 0; i < Len; i++)
38556 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
38557 +}
38558 +
38559 +/*
38560 + ========================================================================
38561 +
38562 + Routine Description:
38563 + The Stream Cipher Encryption Algorithm which conform to the special requirement to encrypt GTK.
38564 +
38565 + Arguments:
38566 + Ctx Pointer to ARCFOUR CONTEXT (SBOX)
38567 + pDest Pointer to the Destination
38568 + pSrc Pointer to the Source data
38569 + Len Indicate the length of the Source dta
38570 +
38571 +
38572 + ========================================================================
38573 +*/
38574 +
38575 +VOID WPAARCFOUR_ENCRYPT(
38576 + IN PARCFOURCONTEXT Ctx,
38577 + IN PUCHAR pDest,
38578 + IN PUCHAR pSrc,
38579 + IN UINT Len)
38580 +{
38581 + UINT i;
38582 + //discard first 256 bytes
38583 + for (i = 0; i < 256; i++)
38584 + ARCFOUR_BYTE(Ctx);
38585 +
38586 + for (i = 0; i < Len; i++)
38587 + pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
38588 +}
38589 +
38590 +
38591 +/*
38592 + ========================================================================
38593 +
38594 + Routine Description:
38595 + Calculate a new FCS given the current FCS and the new data.
38596 +
38597 + Arguments:
38598 + Fcs the original FCS value
38599 + Cp pointer to the data which will be calculate the FCS
38600 + Len the length of the data
38601 +
38602 + Return Value:
38603 + UINT - FCS 32 bits
38604 +
38605 + IRQL = DISPATCH_LEVEL
38606 +
38607 + Note:
38608 +
38609 + ========================================================================
38610 +*/
38611 +UINT RTMP_CALC_FCS32(
38612 + IN UINT Fcs,
38613 + IN PUCHAR Cp,
38614 + IN INT Len)
38615 +{
38616 + while (Len--)
38617 + Fcs = (((Fcs) >> 8) ^ FCSTAB_32[((Fcs) ^ (*Cp++)) & 0xff]);
38618 +
38619 + return (Fcs);
38620 +}
38621 +
38622 +
38623 +/*
38624 + ========================================================================
38625 +
38626 + Routine Description:
38627 + Get last FCS and encrypt it to the destination
38628 +
38629 + Arguments:
38630 + pDest Pointer to the Destination
38631 +
38632 + Return Value:
38633 + None
38634 +
38635 + Note:
38636 +
38637 + ========================================================================
38638 +*/
38639 +VOID RTMPSetICV(
38640 + IN PRTMP_ADAPTER pAd,
38641 + IN PUCHAR pDest)
38642 +{
38643 + pAd->PrivateInfo.FCSCRC32 ^= 0xffffffff; /* complement */
38644 + pAd->PrivateInfo.FCSCRC32 = cpu2le32(pAd->PrivateInfo.FCSCRC32);
38645 +
38646 + ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, (PUCHAR) &pAd->PrivateInfo.FCSCRC32, 4);
38647 +}
38648 +
38649 --- /dev/null
38650 +++ b/drivers/staging/rt3070/common/rtusb_bulk.c
38651 @@ -0,0 +1,1382 @@
38652 +/*
38653 + *************************************************************************
38654 + * Ralink Tech Inc.
38655 + * 5F., No.36, Taiyuan St., Jhubei City,
38656 + * Hsinchu County 302,
38657 + * Taiwan, R.O.C.
38658 + *
38659 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
38660 + *
38661 + * This program is free software; you can redistribute it and/or modify *
38662 + * it under the terms of the GNU General Public License as published by *
38663 + * the Free Software Foundation; either version 2 of the License, or *
38664 + * (at your option) any later version. *
38665 + * *
38666 + * This program is distributed in the hope that it will be useful, *
38667 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
38668 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
38669 + * GNU General Public License for more details. *
38670 + * *
38671 + * You should have received a copy of the GNU General Public License *
38672 + * along with this program; if not, write to the *
38673 + * Free Software Foundation, Inc., *
38674 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
38675 + * *
38676 + *************************************************************************
38677 +
38678 + Module Name:
38679 + rtusb_bulk.c
38680 +
38681 + Abstract:
38682 +
38683 + Revision History:
38684 + Who When What
38685 + -------- ---------- ----------------------------------------------
38686 + Name Date Modification logs
38687 + Paul Lin 06-25-2004 created
38688 +
38689 +*/
38690 +
38691 +#include "../rt_config.h"
38692 +// Match total 6 bulkout endpoint to corresponding queue.
38693 +UCHAR EpToQueue[6]={FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_MGMT};
38694 +
38695 +//static BOOLEAN SingleBulkOut = FALSE;
38696 +
38697 +void RTUSB_FILL_BULK_URB (struct urb *pUrb,
38698 + struct usb_device *pUsb_Dev,
38699 + unsigned int bulkpipe,
38700 + void *pTransferBuf,
38701 + int BufSize,
38702 + usb_complete_t Complete,
38703 + void *pContext)
38704 +{
38705 +
38706 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38707 + usb_fill_bulk_urb(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize, (usb_complete_t)Complete, pContext);
38708 +#else
38709 + FILL_BULK_URB(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize, Complete, pContext);
38710 +#endif
38711 +
38712 +}
38713 +
38714 +VOID RTUSBInitTxDesc(
38715 + IN PRTMP_ADAPTER pAd,
38716 + IN PTX_CONTEXT pTxContext,
38717 + IN UCHAR BulkOutPipeId,
38718 + IN usb_complete_t Func)
38719 +{
38720 + PURB pUrb;
38721 + PUCHAR pSrc = NULL;
38722 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
38723 +
38724 + pUrb = pTxContext->pUrb;
38725 + ASSERT(pUrb);
38726 +
38727 + // Store BulkOut PipeId
38728 + pTxContext->BulkOutPipeId = BulkOutPipeId;
38729 +
38730 + if (pTxContext->bAggregatible)
38731 + {
38732 + pSrc = &pTxContext->TransferBuffer->Aggregation[2];
38733 + }
38734 + else
38735 + {
38736 + pSrc = (PUCHAR) pTxContext->TransferBuffer->field.WirelessPacket;
38737 + }
38738 +
38739 +
38740 + //Initialize a tx bulk urb
38741 + RTUSB_FILL_BULK_URB(pUrb,
38742 + pObj->pUsb_Dev,
38743 + usb_sndbulkpipe(pObj->pUsb_Dev, pAd->BulkOutEpAddr[BulkOutPipeId]),
38744 + pSrc,
38745 + pTxContext->BulkOutSize,
38746 + Func,
38747 + pTxContext);
38748 +
38749 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38750 + if (pTxContext->bAggregatible)
38751 + pUrb->transfer_dma = (pTxContext->data_dma + TX_BUFFER_NORMSIZE + 2);
38752 + else
38753 + pUrb->transfer_dma = pTxContext->data_dma;
38754 +
38755 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
38756 +#endif
38757 +
38758 +}
38759 +
38760 +VOID RTUSBInitHTTxDesc(
38761 + IN PRTMP_ADAPTER pAd,
38762 + IN PHT_TX_CONTEXT pTxContext,
38763 + IN UCHAR BulkOutPipeId,
38764 + IN ULONG BulkOutSize,
38765 + IN usb_complete_t Func)
38766 +{
38767 + PURB pUrb;
38768 + PUCHAR pSrc = NULL;
38769 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
38770 +
38771 + pUrb = pTxContext->pUrb;
38772 + ASSERT(pUrb);
38773 +
38774 + // Store BulkOut PipeId
38775 + pTxContext->BulkOutPipeId = BulkOutPipeId;
38776 +
38777 + pSrc = &pTxContext->TransferBuffer->field.WirelessPacket[pTxContext->NextBulkOutPosition];
38778 +
38779 +
38780 + //Initialize a tx bulk urb
38781 + RTUSB_FILL_BULK_URB(pUrb,
38782 + pObj->pUsb_Dev,
38783 + usb_sndbulkpipe(pObj->pUsb_Dev, pAd->BulkOutEpAddr[BulkOutPipeId]),
38784 + pSrc,
38785 + BulkOutSize,
38786 + Func,
38787 + pTxContext);
38788 +
38789 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38790 + pUrb->transfer_dma = (pTxContext->data_dma + pTxContext->NextBulkOutPosition);
38791 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
38792 +#endif
38793 +
38794 +}
38795 +
38796 +VOID RTUSBInitRxDesc(
38797 + IN PRTMP_ADAPTER pAd,
38798 + IN PRX_CONTEXT pRxContext)
38799 +{
38800 + PURB pUrb;
38801 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
38802 + ULONG RX_bulk_size;
38803 +
38804 +
38805 + pUrb = pRxContext->pUrb;
38806 + ASSERT(pUrb);
38807 +
38808 + if ( pAd->BulkInMaxPacketSize == 64)
38809 + RX_bulk_size = 4096;
38810 + else
38811 + RX_bulk_size = MAX_RXBULK_SIZE;
38812 +
38813 + //Initialize a rx bulk urb
38814 + RTUSB_FILL_BULK_URB(pUrb,
38815 + pObj->pUsb_Dev,
38816 + usb_rcvbulkpipe(pObj->pUsb_Dev, pAd->BulkInEpAddr),
38817 + &(pRxContext->TransferBuffer[pAd->NextRxBulkInPosition]),
38818 + RX_bulk_size - (pAd->NextRxBulkInPosition),
38819 + (usb_complete_t)RTUSBBulkRxComplete,
38820 + (void *)pRxContext);
38821 +
38822 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38823 + pUrb->transfer_dma = pRxContext->data_dma + pAd->NextRxBulkInPosition;
38824 + pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
38825 +#endif
38826 +
38827 +
38828 +}
38829 +
38830 +/*
38831 + ========================================================================
38832 +
38833 + Routine Description:
38834 +
38835 + Arguments:
38836 +
38837 + Return Value:
38838 +
38839 + Note:
38840 +
38841 + ========================================================================
38842 +*/
38843 +
38844 +#define BULK_OUT_LOCK(pLock, IrqFlags) \
38845 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
38846 + RTMP_IRQ_LOCK((pLock), IrqFlags);
38847 +
38848 +#define BULK_OUT_UNLOCK(pLock, IrqFlags) \
38849 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
38850 + RTMP_IRQ_UNLOCK((pLock), IrqFlags);
38851 +
38852 +
38853 +VOID RTUSBBulkOutDataPacket(
38854 + IN PRTMP_ADAPTER pAd,
38855 + IN UCHAR BulkOutPipeId,
38856 + IN UCHAR Index)
38857 +{
38858 +
38859 + PHT_TX_CONTEXT pHTTXContext;
38860 + PURB pUrb;
38861 + int ret = 0;
38862 + PTXINFO_STRUC pTxInfo, pLastTxInfo = NULL;
38863 + PTXWI_STRUC pTxWI;
38864 + ULONG TmpBulkEndPos, ThisBulkSize;
38865 + unsigned long IrqFlags = 0, IrqFlags2 = 0;
38866 + PUCHAR pWirelessPkt, pAppendant;
38867 + BOOLEAN bTxQLastRound = FALSE;
38868 + UCHAR allzero[4]= {0x0,0x0,0x0,0x0};
38869 +
38870 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38871 + if ((pAd->BulkOutPending[BulkOutPipeId] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
38872 + {
38873 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38874 + return;
38875 + }
38876 + pAd->BulkOutPending[BulkOutPipeId] = TRUE;
38877 +
38878 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
38879 + )
38880 + {
38881 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38882 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38883 + return;
38884 + }
38885 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38886 +
38887 +
38888 + pHTTXContext = &(pAd->TxContext[BulkOutPipeId]);
38889 +
38890 + BULK_OUT_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
38891 + if ((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition)
38892 + || ((pHTTXContext->ENextBulkOutPosition-8) == pHTTXContext->CurWritePosition))
38893 + {
38894 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
38895 +
38896 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38897 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
38898 +
38899 + // Clear Data flag
38900 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId));
38901 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
38902 +
38903 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
38904 + return;
38905 + }
38906 +
38907 + // Clear Data flag
38908 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId));
38909 + RTUSB_CLEAR_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
38910 +
38911 + //DBGPRINT(RT_DEBUG_TRACE,("BulkOut-B:I=0x%lx, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", in_interrupt(),
38912 + // pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition,
38913 + // pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
38914 + pHTTXContext->NextBulkOutPosition = pHTTXContext->ENextBulkOutPosition;
38915 + ThisBulkSize = 0;
38916 + TmpBulkEndPos = pHTTXContext->NextBulkOutPosition;
38917 + pWirelessPkt = &pHTTXContext->TransferBuffer->field.WirelessPacket[0];
38918 +
38919 + if ((pHTTXContext->bCopySavePad == TRUE))
38920 + {
38921 + if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero,4))
38922 + {
38923 + DBGPRINT_RAW(RT_DEBUG_ERROR,("e1, allzero : %x %x %x %x %x %x %x %x \n",
38924 + pHTTXContext->SavedPad[0], pHTTXContext->SavedPad[1], pHTTXContext->SavedPad[2],pHTTXContext->SavedPad[3]
38925 + ,pHTTXContext->SavedPad[4], pHTTXContext->SavedPad[5], pHTTXContext->SavedPad[6],pHTTXContext->SavedPad[7]));
38926 + }
38927 + NdisMoveMemory(&pWirelessPkt[TmpBulkEndPos], pHTTXContext->SavedPad, 8);
38928 + pHTTXContext->bCopySavePad = FALSE;
38929 + if (pAd->bForcePrintTX == TRUE)
38930 + DBGPRINT(RT_DEBUG_TRACE,("RTUSBBulkOutDataPacket --> COPY PAD. CurWrite = %ld, NextBulk = %ld. ENextBulk = %ld.\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition));
38931 + }
38932 +
38933 + do
38934 + {
38935 + pTxInfo = (PTXINFO_STRUC)&pWirelessPkt[TmpBulkEndPos];
38936 + pTxWI = (PTXWI_STRUC)&pWirelessPkt[TmpBulkEndPos + TXINFO_SIZE];
38937 +
38938 + if (pAd->bForcePrintTX == TRUE)
38939 + DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkOutDataPacket AMPDU = %d.\n", pTxWI->AMPDU));
38940 +
38941 + // add by Iverson, limit BulkOut size to 4k to pass WMM b mode 2T1R test items
38942 + //if ((ThisBulkSize != 0) && (pTxWI->AMPDU == 0))
38943 + if ((ThisBulkSize != 0) && (pTxWI->PHYMODE == MODE_CCK))
38944 + {
38945 +#ifdef INF_AMAZON_SE
38946 + /*Iverson Add for AMAZON USB (RT2070 && RT3070) to pass WMM A2-T4 ~ A2-T10*/
38947 + if(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
38948 + {
38949 + /*Iverson patch for WMM A5-T07 ,WirelessStaToWirelessSta do not bulk out aggregate*/
38950 + if(pTxWI->PacketId == 6)
38951 + {
38952 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38953 + break;
38954 + }
38955 + else if (BulkOutPipeId == 1)
38956 + {
38957 + /*BK No Limit BulkOut size .*/
38958 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38959 + break;
38960 + }
38961 + else if (((ThisBulkSize&0xffff8000) != 0) || (((ThisBulkSize&0x1000) == 0x1000) && (BulkOutPipeId == 0) ))
38962 + {
38963 + /*BE Limit BulkOut size to about 4k bytes.*/
38964 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38965 + break;
38966 + }
38967 + else if (((ThisBulkSize&0xffff8000) != 0) || (((ThisBulkSize&0x1c00) == 0x1c00) && (BulkOutPipeId == 2) ))
38968 + {
38969 + /*VI Limit BulkOut size to about 7k bytes.*/
38970 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38971 + break;
38972 + }
38973 + else if (((ThisBulkSize&0xffff8000) != 0) || (((ThisBulkSize&0x2500) == 0x2500) && (BulkOutPipeId == 3) ))
38974 + {
38975 + /*VO Limit BulkOut size to about 9k bytes.*/
38976 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38977 + break;
38978 + }
38979 + }
38980 + else if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x1000) == 0x1000))
38981 + {
38982 + /* Limit BulkOut size to about 4k bytes.*/
38983 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38984 + break;
38985 + }
38986 +#else
38987 + if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x1000) == 0x1000))
38988 + {
38989 + // Limit BulkOut size to about 4k bytes.
38990 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
38991 + break;
38992 + }
38993 +#endif // INF_AMAZON_SE //
38994 +
38995 + else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize&0xfffff800) != 0) ) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0))*/)
38996 + {
38997 + // For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size.
38998 + // For performence in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04.
38999 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39000 + break;
39001 + }
39002 + }
39003 + // end Iverson
39004 + else
39005 + {
39006 +#ifdef INF_AMAZON_SE
39007 +//#ifdef DOT11_N_SUPPORT
39008 +// if(((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x6000) == 0x6000) || ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0)))
39009 +// {
39010 +// /* AMAZON_SE: BG mode Disable BulkOut Aggregate, N mode BulkOut Aggregaet size 24K */
39011 +// pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39012 +// break;
39013 +// }
39014 +// else
39015 +//#endif // DOT11_N_SUPPORT //
39016 +// {
39017 + if(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && (pTxWI->AMPDU == 0))
39018 + {
39019 + if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize&0xfffff800) != 0)) ||
39020 + (ThisBulkSize != 0))
39021 + {
39022 + /* AMAZON_SE: RT2070 Disable BulkOut Aggregate when WMM for USB issue */
39023 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39024 + break;
39025 + }
39026 + }
39027 +/*
39028 + else if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x6000) == 0x6000))
39029 + {
39030 + // Limit BulkOut size to about 24k bytes.
39031 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39032 + break;
39033 + }
39034 + }
39035 +*/
39036 +#endif // INF_AMAZON_SE //
39037 +
39038 + if (((ThisBulkSize&0xffff8000) != 0) || ((ThisBulkSize&0x6000) == 0x6000))
39039 + { // Limit BulkOut size to about 24k bytes.
39040 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39041 + break;
39042 + }
39043 +
39044 + else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize&0xfffff800) != 0) ) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0))*/)
39045 + { // For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size.
39046 + // For performence in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04.
39047 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39048 + break;
39049 + }
39050 + }
39051 +
39052 + if (TmpBulkEndPos == pHTTXContext->CurWritePosition)
39053 + {
39054 + pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
39055 + break;
39056 + }
39057 + //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
39058 +#ifdef CONFIG_STA_SUPPORT
39059 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
39060 + {
39061 + if (pTxInfo->QSEL != FIFO_EDCA)
39062 + {
39063 + printk("%s(): ====> pTxInfo->QueueSel(%d)!= FIFO_EDCA!!!!\n", __FUNCTION__, pTxInfo->QSEL);
39064 + printk("\tCWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad);
39065 + hex_dump("Wrong QSel Pkt:", (PUCHAR)&pWirelessPkt[TmpBulkEndPos], (pHTTXContext->CurWritePosition - pHTTXContext->NextBulkOutPosition));
39066 + }
39067 + }
39068 +#endif // CONFIG_STA_SUPPORT //
39069 +
39070 + if (pTxInfo->USBDMATxPktLen <= 8)
39071 + {
39072 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
39073 + DBGPRINT(RT_DEBUG_ERROR /*RT_DEBUG_TRACE*/,("e2, USBDMATxPktLen==0, Size=%ld, bCSPad=%d, CWPos=%ld, NBPos=%ld, CWRPos=%ld!\n",
39074 + pHTTXContext->BulkOutSize, pHTTXContext->bCopySavePad, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->CurWriteRealPos));
39075 + {
39076 + DBGPRINT_RAW(RT_DEBUG_ERROR /*RT_DEBUG_TRACE*/,("%x %x %x %x %x %x %x %x \n",
39077 + pHTTXContext->SavedPad[0], pHTTXContext->SavedPad[1], pHTTXContext->SavedPad[2],pHTTXContext->SavedPad[3]
39078 + ,pHTTXContext->SavedPad[4], pHTTXContext->SavedPad[5], pHTTXContext->SavedPad[6],pHTTXContext->SavedPad[7]));
39079 + }
39080 + pAd->bForcePrintTX = TRUE;
39081 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39082 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
39083 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39084 + //DBGPRINT(RT_DEBUG_LOUD,("Out:pTxInfo->USBDMATxPktLen=%d!\n", pTxInfo->USBDMATxPktLen));
39085 + return;
39086 + }
39087 +
39088 + // Increase Total transmit byte counter
39089 + pAd->RalinkCounters.OneSecTransmittedByteCount += pTxWI->MPDUtotalByteCount;
39090 + pAd->RalinkCounters.TransmittedByteCount += pTxWI->MPDUtotalByteCount;
39091 +
39092 + pLastTxInfo = pTxInfo;
39093 +
39094 + // Make sure we use EDCA QUEUE.
39095 +#ifdef CONFIG_STA_SUPPORT
39096 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
39097 + pTxInfo->QSEL = FIFO_EDCA; //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
39098 +#endif // CONFIG_STA_SUPPORT //
39099 + ThisBulkSize += (pTxInfo->USBDMATxPktLen+4);
39100 + TmpBulkEndPos += (pTxInfo->USBDMATxPktLen+4);
39101 +
39102 + if (TmpBulkEndPos != pHTTXContext->CurWritePosition)
39103 + pTxInfo->USBDMANextVLD = 1;
39104 +
39105 + if (pTxInfo->SwUseLastRound == 1)
39106 + {
39107 + if (pHTTXContext->CurWritePosition == 8)
39108 + pTxInfo->USBDMANextVLD = 0;
39109 + pTxInfo->SwUseLastRound = 0;
39110 +
39111 + bTxQLastRound = TRUE;
39112 + pHTTXContext->ENextBulkOutPosition = 8;
39113 +
39114 + #ifdef RT_BIG_ENDIAN
39115 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
39116 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
39117 + #endif // RT_BIG_ENDIAN //
39118 +
39119 + break;
39120 + }
39121 +
39122 +#ifdef RT_BIG_ENDIAN
39123 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
39124 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
39125 +#endif // RT_BIG_ENDIAN //
39126 +
39127 + }while (TRUE);
39128 +
39129 + // adjust the pTxInfo->USBDMANextVLD value of last pTxInfo.
39130 + if (pLastTxInfo)
39131 + {
39132 +#ifdef RT_BIG_ENDIAN
39133 + RTMPDescriptorEndianChange((PUCHAR)pLastTxInfo, TYPE_TXINFO);
39134 +#endif // RT_BIG_ENDIAN //
39135 + pLastTxInfo->USBDMANextVLD = 0;
39136 +#ifdef RT_BIG_ENDIAN
39137 + RTMPDescriptorEndianChange((PUCHAR)pLastTxInfo, TYPE_TXINFO);
39138 +#endif // RT_BIG_ENDIAN //
39139 + }
39140 +
39141 + /*
39142 + We need to copy SavedPad when following condition matched!
39143 + 1. Not the last round of the TxQueue and
39144 + 2. any match of following cases:
39145 + (1). The End Position of this bulk out is reach to the Currenct Write position and
39146 + the TxInfo and related header already write to the CurWritePosition.
39147 + =>(ENextBulkOutPosition == CurWritePosition) && (CurWriteRealPos > CurWritePosition)
39148 +
39149 + (2). The EndPosition of the bulk out is not reach to the Current Write Position.
39150 + =>(ENextBulkOutPosition != CurWritePosition)
39151 + */
39152 + if ((bTxQLastRound == FALSE) &&
39153 + (((pHTTXContext->ENextBulkOutPosition == pHTTXContext->CurWritePosition) && (pHTTXContext->CurWriteRealPos > pHTTXContext->CurWritePosition)) ||
39154 + (pHTTXContext->ENextBulkOutPosition != pHTTXContext->CurWritePosition))
39155 + )
39156 + {
39157 + NdisMoveMemory(pHTTXContext->SavedPad, &pWirelessPkt[pHTTXContext->ENextBulkOutPosition], 8);
39158 + pHTTXContext->bCopySavePad = TRUE;
39159 + if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero,4))
39160 + {
39161 + PUCHAR pBuf = &pHTTXContext->SavedPad[0];
39162 + DBGPRINT_RAW(RT_DEBUG_ERROR,("WARNING-Zero-3:%02x%02x%02x%02x%02x%02x%02x%02x,CWPos=%ld, CWRPos=%ld, bCW=%d, NBPos=%ld, TBPos=%ld, TBSize=%ld\n",
39163 + pBuf[0], pBuf[1], pBuf[2],pBuf[3],pBuf[4], pBuf[5], pBuf[6],pBuf[7], pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos,
39164 + pHTTXContext->bCurWriting, pHTTXContext->NextBulkOutPosition, TmpBulkEndPos, ThisBulkSize));
39165 +
39166 + pBuf = &pWirelessPkt[pHTTXContext->CurWritePosition];
39167 + DBGPRINT_RAW(RT_DEBUG_ERROR,("\tCWPos=%02x%02x%02x%02x%02x%02x%02x%02x\n", pBuf[0], pBuf[1], pBuf[2],pBuf[3],pBuf[4], pBuf[5], pBuf[6],pBuf[7]));
39168 + }
39169 + //DBGPRINT(RT_DEBUG_LOUD,("ENPos==CWPos=%ld, CWRPos=%ld, bCSPad=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->bCopySavePad));
39170 + }
39171 +
39172 + if (pAd->bForcePrintTX == TRUE)
39173 + DBGPRINT(RT_DEBUG_TRACE,("BulkOut-A:Size=%ld, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", ThisBulkSize, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad));
39174 + //DBGPRINT(RT_DEBUG_LOUD,("BulkOut-A:Size=%ld, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, bLRound=%d!\n", ThisBulkSize, pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, bTxQLastRound));
39175 +
39176 + // USB DMA engine requires to pad extra 4 bytes. This pad doesn't count into real bulkoutsize.
39177 + pAppendant = &pWirelessPkt[TmpBulkEndPos];
39178 + NdisZeroMemory(pAppendant, 8);
39179 + ThisBulkSize += 4;
39180 + pHTTXContext->LastOne = TRUE;
39181 + if ((ThisBulkSize % pAd->BulkOutMaxPacketSize) == 0)
39182 + ThisBulkSize += 4;
39183 + pHTTXContext->BulkOutSize = ThisBulkSize;
39184 +
39185 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 1;
39186 + BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
39187 +
39188 + // Init Tx context descriptor
39189 + RTUSBInitHTTxDesc(pAd, pHTTXContext, BulkOutPipeId, ThisBulkSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete);
39190 +
39191 + pUrb = pHTTXContext->pUrb;
39192 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39193 + {
39194 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
39195 +
39196 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39197 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
39198 + pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
39199 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39200 +
39201 + return;
39202 + }
39203 +
39204 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39205 + pHTTXContext->IRPPending = TRUE;
39206 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
39207 + pAd->BulkOutReq++;
39208 +
39209 +}
39210 +
39211 +
39212 +VOID RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39213 +{
39214 + PHT_TX_CONTEXT pHTTXContext;
39215 + PRTMP_ADAPTER pAd;
39216 + POS_COOKIE pObj;
39217 + UCHAR BulkOutPipeId;
39218 +
39219 +
39220 + pHTTXContext = (PHT_TX_CONTEXT)pUrb->context;
39221 + pAd = pHTTXContext->pAd;
39222 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39223 +
39224 + // Store BulkOut PipeId
39225 + BulkOutPipeId = pHTTXContext->BulkOutPipeId;
39226 + pAd->BulkOutDataOneSecCount++;
39227 +
39228 + switch (BulkOutPipeId)
39229 + {
39230 + case 0:
39231 + pObj->ac0_dma_done_task.data = (unsigned long)pUrb;
39232 + tasklet_hi_schedule(&pObj->ac0_dma_done_task);
39233 + break;
39234 + case 1:
39235 + pObj->ac1_dma_done_task.data = (unsigned long)pUrb;
39236 + tasklet_hi_schedule(&pObj->ac1_dma_done_task);
39237 + break;
39238 + case 2:
39239 + pObj->ac2_dma_done_task.data = (unsigned long)pUrb;
39240 + tasklet_hi_schedule(&pObj->ac2_dma_done_task);
39241 + break;
39242 + case 3:
39243 + pObj->ac3_dma_done_task.data = (unsigned long)pUrb;
39244 + tasklet_hi_schedule(&pObj->ac3_dma_done_task);
39245 + break;
39246 + case 4:
39247 + pObj->hcca_dma_done_task.data = (unsigned long)pUrb;
39248 + tasklet_hi_schedule(&pObj->hcca_dma_done_task);
39249 + break;
39250 + }
39251 +}
39252 +
39253 +
39254 +/*
39255 + ========================================================================
39256 +
39257 + Routine Description:
39258 +
39259 + Arguments:
39260 +
39261 + Return Value:
39262 +
39263 + Note: NULL frame use BulkOutPipeId = 0
39264 +
39265 + ========================================================================
39266 +*/
39267 +VOID RTUSBBulkOutNullFrame(
39268 + IN PRTMP_ADAPTER pAd)
39269 +{
39270 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
39271 + PURB pUrb;
39272 + int ret = 0;
39273 + unsigned long IrqFlags;
39274 +
39275 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
39276 + if ((pAd->BulkOutPending[0] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
39277 + {
39278 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39279 + return;
39280 + }
39281 + pAd->BulkOutPending[0] = TRUE;
39282 + pAd->watchDogTxPendingCnt[0] = 1;
39283 + pNullContext->IRPPending = TRUE;
39284 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39285 +
39286 + // Increase Total transmit byte counter
39287 + pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
39288 +
39289 +
39290 + // Clear Null frame bulk flag
39291 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
39292 +
39293 +#ifdef RT_BIG_ENDIAN
39294 + RTMPDescriptorEndianChange((PUCHAR)pNullContext->TransferBuffer, TYPE_TXINFO);
39295 +#endif // RT_BIG_ENDIAN //
39296 +
39297 + // Init Tx context descriptor
39298 + RTUSBInitTxDesc(pAd, pNullContext, 0, (usb_complete_t)RTUSBBulkOutNullFrameComplete);
39299 +
39300 + pUrb = pNullContext->pUrb;
39301 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39302 + {
39303 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
39304 + pAd->BulkOutPending[0] = FALSE;
39305 + pAd->watchDogTxPendingCnt[0] = 0;
39306 + pNullContext->IRPPending = FALSE;
39307 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39308 +
39309 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutNullFrame: Submit Tx URB failed %d\n", ret));
39310 + return;
39311 + }
39312 +
39313 +}
39314 +
39315 +// NULL frame use BulkOutPipeId = 0
39316 +VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39317 +{
39318 + PRTMP_ADAPTER pAd;
39319 + PTX_CONTEXT pNullContext;
39320 + NTSTATUS Status;
39321 + POS_COOKIE pObj;
39322 +
39323 +
39324 + pNullContext = (PTX_CONTEXT)pUrb->context;
39325 + pAd = pNullContext->pAd;
39326 + Status = pUrb->status;
39327 +
39328 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39329 + pObj->null_frame_complete_task.data = (unsigned long)pUrb;
39330 + tasklet_hi_schedule(&pObj->null_frame_complete_task);
39331 +
39332 +}
39333 +
39334 +/*
39335 + ========================================================================
39336 +
39337 + Routine Description:
39338 +
39339 + Arguments:
39340 +
39341 + Return Value:
39342 +
39343 + Note: MLME use BulkOutPipeId = 0
39344 +
39345 + ========================================================================
39346 +*/
39347 +VOID RTUSBBulkOutMLMEPacket(
39348 + IN PRTMP_ADAPTER pAd,
39349 + IN UCHAR Index)
39350 +{
39351 + PTX_CONTEXT pMLMEContext;
39352 + PURB pUrb;
39353 + int ret = 0;
39354 + unsigned long IrqFlags;
39355 +
39356 + pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa;
39357 + pUrb = pMLMEContext->pUrb;
39358 +
39359 + if ((pAd->MgmtRing.TxSwFreeIdx >= MGMT_RING_SIZE) ||
39360 + (pMLMEContext->InUse == FALSE) ||
39361 + (pMLMEContext->bWaitingBulkOut == FALSE))
39362 + {
39363 +
39364 +
39365 + // Clear MLME bulk flag
39366 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
39367 +
39368 + return;
39369 + }
39370 +
39371 +
39372 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
39373 + if ((pAd->BulkOutPending[MGMTPIPEIDX] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
39374 + {
39375 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
39376 + return;
39377 + }
39378 +
39379 + pAd->BulkOutPending[MGMTPIPEIDX] = TRUE;
39380 + pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 1;
39381 + pMLMEContext->IRPPending = TRUE;
39382 + pMLMEContext->bWaitingBulkOut = FALSE;
39383 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
39384 +
39385 + // Increase Total transmit byte counter
39386 + pAd->RalinkCounters.TransmittedByteCount += pMLMEContext->BulkOutSize;
39387 +
39388 + // Clear MLME bulk flag
39389 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
39390 +
39391 +#ifdef RT_BIG_ENDIAN
39392 + RTMPDescriptorEndianChange((PUCHAR)pMLMEContext->TransferBuffer, TYPE_TXINFO);
39393 +#endif // RT_BIG_ENDIAN //
39394 +
39395 + // Init Tx context descriptor
39396 + RTUSBInitTxDesc(pAd, pMLMEContext, MGMTPIPEIDX, (usb_complete_t)RTUSBBulkOutMLMEPacketComplete);
39397 +
39398 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
39399 + //For mgmt urb buffer, because we use sk_buff, so we need to notify the USB controller do dma mapping.
39400 + pUrb->transfer_dma = 0;
39401 + pUrb->transfer_flags &= (~URB_NO_TRANSFER_DMA_MAP);
39402 +#endif
39403 +
39404 + pUrb = pMLMEContext->pUrb;
39405 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39406 + {
39407 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutMLMEPacket: Submit MLME URB failed %d\n", ret));
39408 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
39409 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
39410 + pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 0;
39411 + pMLMEContext->IRPPending = FALSE;
39412 + pMLMEContext->bWaitingBulkOut = TRUE;
39413 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
39414 +
39415 + return;
39416 + }
39417 +
39418 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutMLMEPacket \n"));
39419 +// printk("<---RTUSBBulkOutMLMEPacket,Cpu=%d!, Dma=%d, SwIdx=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx);
39420 +}
39421 +
39422 +
39423 +VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39424 +{
39425 + PTX_CONTEXT pMLMEContext;
39426 + PRTMP_ADAPTER pAd;
39427 + NTSTATUS Status;
39428 + POS_COOKIE pObj;
39429 + int index;
39430 +
39431 + //DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutMLMEPacketComplete\n"));
39432 + pMLMEContext = (PTX_CONTEXT)pUrb->context;
39433 + pAd = pMLMEContext->pAd;
39434 + pObj = (POS_COOKIE)pAd->OS_Cookie;
39435 + Status = pUrb->status;
39436 + index = pMLMEContext->SelfIdx;
39437 +
39438 + pObj->mgmt_dma_done_task.data = (unsigned long)pUrb;
39439 + tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
39440 +}
39441 +
39442 +
39443 +/*
39444 + ========================================================================
39445 +
39446 + Routine Description:
39447 +
39448 + Arguments:
39449 +
39450 + Return Value:
39451 +
39452 + Note: PsPoll use BulkOutPipeId = 0
39453 +
39454 + ========================================================================
39455 +*/
39456 +VOID RTUSBBulkOutPsPoll(
39457 + IN PRTMP_ADAPTER pAd)
39458 +{
39459 + PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext);
39460 + PURB pUrb;
39461 + int ret = 0;
39462 + unsigned long IrqFlags;
39463 +
39464 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
39465 + if ((pAd->BulkOutPending[0] == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX))
39466 + {
39467 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39468 + return;
39469 + }
39470 + pAd->BulkOutPending[0] = TRUE;
39471 + pAd->watchDogTxPendingCnt[0] = 1;
39472 + pPsPollContext->IRPPending = TRUE;
39473 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39474 +
39475 +
39476 + // Clear PS-Poll bulk flag
39477 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);
39478 +
39479 +#ifdef RT_BIG_ENDIAN
39480 + RTMPDescriptorEndianChange((PUCHAR)pPsPollContext->TransferBuffer, TYPE_TXINFO);
39481 +#endif // RT_BIG_ENDIAN //
39482 +
39483 + // Init Tx context descriptor
39484 + RTUSBInitTxDesc(pAd, pPsPollContext, MGMTPIPEIDX, (usb_complete_t)RTUSBBulkOutPsPollComplete);
39485 +
39486 + pUrb = pPsPollContext->pUrb;
39487 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39488 + {
39489 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
39490 + pAd->BulkOutPending[0] = FALSE;
39491 + pAd->watchDogTxPendingCnt[0] = 0;
39492 + pPsPollContext->IRPPending = FALSE;
39493 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
39494 +
39495 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkOutPsPoll: Submit Tx URB failed %d\n", ret));
39496 + return;
39497 + }
39498 +
39499 +}
39500 +
39501 +// PS-Poll frame use BulkOutPipeId = 0
39502 +VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb,struct pt_regs *pt_regs)
39503 +{
39504 + PRTMP_ADAPTER pAd;
39505 + PTX_CONTEXT pPsPollContext;
39506 + NTSTATUS Status;
39507 + POS_COOKIE pObj;
39508 +
39509 +
39510 + pPsPollContext= (PTX_CONTEXT)pUrb->context;
39511 + pAd = pPsPollContext->pAd;
39512 + Status = pUrb->status;
39513 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39514 + pObj->pspoll_frame_complete_task.data = (unsigned long)pUrb;
39515 + tasklet_hi_schedule(&pObj->pspoll_frame_complete_task);
39516 +
39517 +}
39518 +
39519 +VOID DoBulkIn(IN RTMP_ADAPTER *pAd)
39520 +{
39521 + PRX_CONTEXT pRxContext;
39522 + PURB pUrb;
39523 + int ret = 0;
39524 + unsigned long IrqFlags;
39525 +
39526 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39527 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
39528 + if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE))
39529 + {
39530 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39531 + return;
39532 + }
39533 + pRxContext->InUse = TRUE;
39534 + pRxContext->IRPPending = TRUE;
39535 + pAd->PendingRx++;
39536 + pAd->BulkInReq++;
39537 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39538 +
39539 + // Init Rx context descriptor
39540 + NdisZeroMemory(pRxContext->TransferBuffer, pRxContext->BulkInOffset);
39541 + RTUSBInitRxDesc(pAd, pRxContext);
39542 +
39543 + pUrb = pRxContext->pUrb;
39544 + if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
39545 + { // fail
39546 +
39547 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39548 + pRxContext->InUse = FALSE;
39549 + pRxContext->IRPPending = FALSE;
39550 + pAd->PendingRx--;
39551 + pAd->BulkInReq--;
39552 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39553 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSBBulkReceive: Submit Rx URB failed %d\n", ret));
39554 + }
39555 + else
39556 + { // success
39557 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
39558 + //printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex);
39559 + }
39560 +}
39561 +
39562 +
39563 +/*
39564 + ========================================================================
39565 +
39566 + Routine Description:
39567 + USB_RxPacket initializes a URB and uses the Rx IRP to submit it
39568 + to USB. It checks if an Rx Descriptor is available and passes the
39569 + the coresponding buffer to be filled. If no descriptor is available
39570 + fails the request. When setting the completion routine we pass our
39571 + Adapter Object as Context.
39572 +
39573 + Arguments:
39574 +
39575 + Return Value:
39576 + TRUE found matched tuple cache
39577 + FALSE no matched found
39578 +
39579 + Note:
39580 +
39581 + ========================================================================
39582 +*/
39583 +#define fRTMP_ADAPTER_NEED_STOP_RX \
39584 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
39585 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
39586 + fRTMP_ADAPTER_REMOVE_IN_PROGRESS | fRTMP_ADAPTER_BULKIN_RESET)
39587 +
39588 +#define fRTMP_ADAPTER_NEED_STOP_HANDLE_RX \
39589 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
39590 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
39591 + fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
39592 +
39593 +VOID RTUSBBulkReceive(
39594 + IN PRTMP_ADAPTER pAd)
39595 +{
39596 + PRX_CONTEXT pRxContext;
39597 + unsigned long IrqFlags;
39598 +
39599 +
39600 + /* sanity check */
39601 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_HANDLE_RX))
39602 + return;
39603 +
39604 + while(1)
39605 + {
39606 +
39607 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39608 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInReadIndex]);
39609 + if (((pRxContext->InUse == FALSE) && (pRxContext->Readable == TRUE)) &&
39610 + (pRxContext->bRxHandling == FALSE))
39611 + {
39612 + pRxContext->bRxHandling = TRUE;
39613 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39614 +
39615 + // read RxContext, Since not
39616 +#ifdef CONFIG_STA_SUPPORT
39617 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
39618 + STARxDoneInterruptHandle(pAd, TRUE);
39619 +#endif // CONFIG_STA_SUPPORT //
39620 +
39621 + // Finish to handle this bulkIn buffer.
39622 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
39623 + pRxContext->BulkInOffset = 0;
39624 + pRxContext->Readable = FALSE;
39625 + pRxContext->bRxHandling = FALSE;
39626 + pAd->ReadPosition = 0;
39627 + pAd->TransferBufferLength = 0;
39628 + INC_RING_INDEX(pAd->NextRxBulkInReadIndex, RX_RING_SIZE);
39629 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39630 +
39631 + }
39632 + else
39633 + {
39634 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
39635 + break;
39636 + }
39637 + }
39638 +
39639 + if (!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_RX)))
39640 + DoBulkIn(pAd);
39641 +
39642 +}
39643 +
39644 +
39645 +/*
39646 + ========================================================================
39647 +
39648 + Routine Description:
39649 + This routine process Rx Irp and call rx complete function.
39650 +
39651 + Arguments:
39652 + DeviceObject Pointer to the device object for next lower
39653 + device. DeviceObject passed in here belongs to
39654 + the next lower driver in the stack because we
39655 + were invoked via IoCallDriver in USB_RxPacket
39656 + AND it is not OUR device object
39657 + Irp Ptr to completed IRP
39658 + Context Ptr to our Adapter object (context specified
39659 + in IoSetCompletionRoutine
39660 +
39661 + Return Value:
39662 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39663 +
39664 + Note:
39665 + Always returns STATUS_MORE_PROCESSING_REQUIRED
39666 + ========================================================================
39667 +*/
39668 +VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs)
39669 +{
39670 + // use a receive tasklet to handle received packets;
39671 + // or sometimes hardware IRQ will be disabled here, so we can not
39672 + // use spin_lock_bh()/spin_unlock_bh() after IRQ is disabled. :<
39673 + PRX_CONTEXT pRxContext;
39674 + PRTMP_ADAPTER pAd;
39675 + POS_COOKIE pObj;
39676 +
39677 +
39678 + pRxContext = (PRX_CONTEXT)pUrb->context;
39679 + pAd = pRxContext->pAd;
39680 + pObj = (POS_COOKIE) pAd->OS_Cookie;
39681 +
39682 + pObj->rx_done_task.data = (unsigned long)pUrb;
39683 + tasklet_hi_schedule(&pObj->rx_done_task);
39684 +
39685 +}
39686 +
39687 +/*
39688 + ========================================================================
39689 +
39690 + Routine Description:
39691 +
39692 + Arguments:
39693 +
39694 + Return Value:
39695 +
39696 + Note:
39697 +
39698 + ========================================================================
39699 +*/
39700 +VOID RTUSBKickBulkOut(
39701 + IN PRTMP_ADAPTER pAd)
39702 +{
39703 + // BulkIn Reset will reset whole USB PHY. So we need to make sure fRTMP_ADAPTER_BULKIN_RESET not flaged.
39704 + if (!RTMP_TEST_FLAG(pAd ,fRTMP_ADAPTER_NEED_STOP_TX)
39705 +#ifdef RALINK_ATE
39706 + && !(ATE_ON(pAd))
39707 +#endif // RALINK_ATE //
39708 + )
39709 + {
39710 + // 2. PS-Poll frame is next
39711 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL))
39712 + {
39713 + RTUSBBulkOutPsPoll(pAd);
39714 + }
39715 +
39716 + // 5. Mlme frame is next
39717 + else if ((RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME)) &&
39718 + (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE))
39719 + {
39720 + RTUSBBulkOutMLMEPacket(pAd, pAd->MgmtRing.TxDmaIdx);
39721 + }
39722 +
39723 + // 6. Data frame normal is next
39724 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL))
39725 + {
39726 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39727 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39728 + ))
39729 + {
39730 + RTUSBBulkOutDataPacket(pAd, 0, pAd->NextBulkOutIndex[0]);
39731 + }
39732 + }
39733 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_2))
39734 + {
39735 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39736 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39737 + ))
39738 + {
39739 + RTUSBBulkOutDataPacket(pAd, 1, pAd->NextBulkOutIndex[1]);
39740 + }
39741 + }
39742 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_3))
39743 + {
39744 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39745 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39746 + ))
39747 + {
39748 + RTUSBBulkOutDataPacket(pAd, 2, pAd->NextBulkOutIndex[2]);
39749 + }
39750 + }
39751 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_4))
39752 + {
39753 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39754 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39755 + ))
39756 + {
39757 + RTUSBBulkOutDataPacket(pAd, 3, pAd->NextBulkOutIndex[3]);
39758 + }
39759 + }
39760 + //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
39761 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_5))
39762 + {
39763 + if (((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
39764 + (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
39765 + ))
39766 + {
39767 + }
39768 + }
39769 +
39770 + // 7. Null frame is the last
39771 + else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL))
39772 + {
39773 + if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
39774 + {
39775 + RTUSBBulkOutNullFrame(pAd);
39776 + }
39777 + }
39778 +
39779 + // 8. No data avaliable
39780 + else
39781 + {
39782 +
39783 + }
39784 + }
39785 +#ifdef RALINK_ATE
39786 + /* If the mode is in ATE mode. */
39787 + else if((ATE_ON(pAd)) &&
39788 + !RTMP_TEST_FLAG(pAd ,fRTMP_ADAPTER_NEED_STOP_TX))// PETER : watch out !
39789 + {
39790 + if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE))
39791 + {
39792 + ATE_RTUSBBulkOutDataPacket(pAd, 0);
39793 + }
39794 + }
39795 +#endif // RALINK_ATE //
39796 +
39797 +}
39798 +
39799 +/*
39800 + ========================================================================
39801 +
39802 + Routine Description:
39803 + Call from Reset action after BulkOut failed.
39804 + Arguments:
39805 +
39806 + Return Value:
39807 +
39808 + Note:
39809 +
39810 + ========================================================================
39811 +*/
39812 +VOID RTUSBCleanUpDataBulkOutQueue(
39813 + IN PRTMP_ADAPTER pAd)
39814 +{
39815 + UCHAR Idx;
39816 + PHT_TX_CONTEXT pTxContext;
39817 +
39818 + DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpDataBulkOutQueue\n"));
39819 +
39820 + for (Idx = 0; Idx < 4; Idx++)
39821 + {
39822 + pTxContext = &pAd->TxContext[Idx];
39823 +
39824 + pTxContext->CurWritePosition = pTxContext->NextBulkOutPosition;
39825 + pTxContext->LastOne = FALSE;
39826 + NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
39827 + pAd->BulkOutPending[Idx] = FALSE;
39828 + NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
39829 + }
39830 +
39831 + DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpDataBulkOutQueue\n"));
39832 +}
39833 +
39834 +/*
39835 + ========================================================================
39836 +
39837 + Routine Description:
39838 +
39839 + Arguments:
39840 +
39841 + Return Value:
39842 +
39843 + Note:
39844 +
39845 + ========================================================================
39846 +*/
39847 +VOID RTUSBCleanUpMLMEBulkOutQueue(
39848 + IN PRTMP_ADAPTER pAd)
39849 +{
39850 + DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpMLMEBulkOutQueue\n"));
39851 + DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpMLMEBulkOutQueue\n"));
39852 +}
39853 +
39854 +
39855 +/*
39856 + ========================================================================
39857 +
39858 + Routine Description:
39859 +
39860 + Arguments:
39861 +
39862 + Return Value:
39863 +
39864 +
39865 + Note:
39866 +
39867 + ========================================================================
39868 +*/
39869 +VOID RTUSBCancelPendingIRPs(
39870 + IN PRTMP_ADAPTER pAd)
39871 +{
39872 + RTUSBCancelPendingBulkInIRP(pAd);
39873 + RTUSBCancelPendingBulkOutIRP(pAd);
39874 +}
39875 +
39876 +/*
39877 + ========================================================================
39878 +
39879 + Routine Description:
39880 +
39881 + Arguments:
39882 +
39883 + Return Value:
39884 +
39885 + Note:
39886 +
39887 + ========================================================================
39888 +*/
39889 +VOID RTUSBCancelPendingBulkInIRP(
39890 + IN PRTMP_ADAPTER pAd)
39891 +{
39892 + PRX_CONTEXT pRxContext;
39893 + UINT i;
39894 +
39895 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->RTUSBCancelPendingBulkInIRP\n"));
39896 + for ( i = 0; i < (RX_RING_SIZE); i++)
39897 + {
39898 + pRxContext = &(pAd->RxContext[i]);
39899 + if(pRxContext->IRPPending == TRUE)
39900 + {
39901 + RTUSB_UNLINK_URB(pRxContext->pUrb);
39902 + pRxContext->IRPPending = FALSE;
39903 + pRxContext->InUse = FALSE;
39904 + //NdisInterlockedDecrement(&pAd->PendingRx);
39905 + //pAd->PendingRx--;
39906 + }
39907 + }
39908 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("<---RTUSBCancelPendingBulkInIRP\n"));
39909 +}
39910 +
39911 +
39912 +/*
39913 + ========================================================================
39914 +
39915 + Routine Description:
39916 +
39917 + Arguments:
39918 +
39919 + Return Value:
39920 +
39921 + Note:
39922 +
39923 + ========================================================================
39924 +*/
39925 +VOID RTUSBCancelPendingBulkOutIRP(
39926 + IN PRTMP_ADAPTER pAd)
39927 +{
39928 + PHT_TX_CONTEXT pHTTXContext;
39929 + PTX_CONTEXT pMLMEContext;
39930 + PTX_CONTEXT pBeaconContext;
39931 + PTX_CONTEXT pNullContext;
39932 + PTX_CONTEXT pPsPollContext;
39933 + PTX_CONTEXT pRTSContext;
39934 + UINT i, Idx;
39935 +// unsigned int IrqFlags;
39936 +// NDIS_SPIN_LOCK *pLock;
39937 +// BOOLEAN *pPending;
39938 +
39939 +
39940 +// pLock = &pAd->BulkOutLock[MGMTPIPEIDX];
39941 +// pPending = &pAd->BulkOutPending[MGMTPIPEIDX];
39942 +
39943 + for (Idx = 0; Idx < 4; Idx++)
39944 + {
39945 + pHTTXContext = &(pAd->TxContext[Idx]);
39946 +
39947 + if (pHTTXContext->IRPPending == TRUE)
39948 + {
39949 +
39950 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
39951 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
39952 + // when the last IRP on the list has been cancelled; that's how we exit this loop
39953 + //
39954 +
39955 + RTUSB_UNLINK_URB(pHTTXContext->pUrb);
39956 +
39957 + // Sleep 200 microseconds to give cancellation time to work
39958 + RTMPusecDelay(200);
39959 + }
39960 +
39961 +#ifdef RALINK_ATE
39962 + pHTTXContext->bCopySavePad = 0;
39963 + pHTTXContext->CurWritePosition = 0;
39964 + pHTTXContext->CurWriteRealPos = 0;
39965 + pHTTXContext->bCurWriting = FALSE;
39966 + pHTTXContext->NextBulkOutPosition = 0;
39967 + pHTTXContext->ENextBulkOutPosition = 0;
39968 +#endif // RALINK_ATE //
39969 + pAd->BulkOutPending[Idx] = FALSE;
39970 + }
39971 +
39972 + //RTMP_IRQ_LOCK(pLock, IrqFlags);
39973 + for (i = 0; i < MGMT_RING_SIZE; i++)
39974 + {
39975 + pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[i].AllocVa;
39976 + if(pMLMEContext && (pMLMEContext->IRPPending == TRUE))
39977 + {
39978 +
39979 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
39980 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
39981 + // when the last IRP on the list has been cancelled; that's how we exit this loop
39982 + //
39983 +
39984 + RTUSB_UNLINK_URB(pMLMEContext->pUrb);
39985 + pMLMEContext->IRPPending = FALSE;
39986 +
39987 + // Sleep 200 microsecs to give cancellation time to work
39988 + RTMPusecDelay(200);
39989 + }
39990 + }
39991 + pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
39992 + //RTMP_IRQ_UNLOCK(pLock, IrqFlags);
39993 +
39994 +
39995 + for (i = 0; i < BEACON_RING_SIZE; i++)
39996 + {
39997 + pBeaconContext = &(pAd->BeaconContext[i]);
39998 +
39999 + if(pBeaconContext->IRPPending == TRUE)
40000 + {
40001 +
40002 + // Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself
40003 + // remove it from the HeadPendingSendList and NULL out HeadPendingSendList
40004 + // when the last IRP on the list has been cancelled; that's how we exit this loop
40005 + //
40006 +
40007 + RTUSB_UNLINK_URB(pBeaconContext->pUrb);
40008 +
40009 + // Sleep 200 microsecs to give cancellation time to work
40010 + RTMPusecDelay(200);
40011 + }
40012 + }
40013 +
40014 + pNullContext = &(pAd->NullContext);
40015 + if (pNullContext->IRPPending == TRUE)
40016 + RTUSB_UNLINK_URB(pNullContext->pUrb);
40017 +
40018 + pRTSContext = &(pAd->RTSContext);
40019 + if (pRTSContext->IRPPending == TRUE)
40020 + RTUSB_UNLINK_URB(pRTSContext->pUrb);
40021 +
40022 + pPsPollContext = &(pAd->PsPollContext);
40023 + if (pPsPollContext->IRPPending == TRUE)
40024 + RTUSB_UNLINK_URB(pPsPollContext->pUrb);
40025 +
40026 + for (Idx = 0; Idx < 4; Idx++)
40027 + {
40028 + NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
40029 + pAd->BulkOutPending[Idx] = FALSE;
40030 + NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
40031 + }
40032 +}
40033 +
40034 --- /dev/null
40035 +++ b/drivers/staging/rt3070/common/rtusb_data.c
40036 @@ -0,0 +1,218 @@
40037 +/*
40038 + *************************************************************************
40039 + * Ralink Tech Inc.
40040 + * 5F., No.36, Taiyuan St., Jhubei City,
40041 + * Hsinchu County 302,
40042 + * Taiwan, R.O.C.
40043 + *
40044 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
40045 + *
40046 + * This program is free software; you can redistribute it and/or modify *
40047 + * it under the terms of the GNU General Public License as published by *
40048 + * the Free Software Foundation; either version 2 of the License, or *
40049 + * (at your option) any later version. *
40050 + * *
40051 + * This program is distributed in the hope that it will be useful, *
40052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
40053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
40054 + * GNU General Public License for more details. *
40055 + * *
40056 + * You should have received a copy of the GNU General Public License *
40057 + * along with this program; if not, write to the *
40058 + * Free Software Foundation, Inc., *
40059 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
40060 + * *
40061 + *************************************************************************
40062 +
40063 + Module Name:
40064 + rtusb_data.c
40065 +
40066 + Abstract:
40067 + Ralink USB driver Tx/Rx functions.
40068 +
40069 + Revision History:
40070 + Who When What
40071 + -------- ---------- ----------------------------------------------
40072 + Jan 03-25-2006 created
40073 +
40074 +*/
40075 +#include "../rt_config.h"
40076 +
40077 +extern UCHAR Phy11BGNextRateUpward[]; // defined in mlme.c
40078 +extern UCHAR EpToQueue[];
40079 +
40080 +
40081 +VOID REPORT_AMSDU_FRAMES_TO_LLC(
40082 + IN PRTMP_ADAPTER pAd,
40083 + IN PUCHAR pData,
40084 + IN ULONG DataSize)
40085 +{
40086 + PNDIS_PACKET pPacket;
40087 + UINT nMSDU;
40088 + struct sk_buff *pSkb;
40089 +
40090 + nMSDU = 0;
40091 + /* allocate a rx packet */
40092 + pSkb = dev_alloc_skb(RX_BUFFER_AGGRESIZE);
40093 + pPacket = (PNDIS_PACKET)OSPKT_TO_RTPKT(pSkb);
40094 + if (pSkb)
40095 + {
40096 +
40097 + /* convert 802.11 to 802.3 packet */
40098 + pSkb->dev = get_netdev_from_bssid(pAd, BSS0);
40099 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
40100 + deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
40101 + }
40102 + else
40103 + {
40104 + DBGPRINT(RT_DEBUG_ERROR,("Can't allocate skb\n"));
40105 + }
40106 +}
40107 +
40108 +NDIS_STATUS RTUSBFreeDescriptorRequest(
40109 + IN PRTMP_ADAPTER pAd,
40110 + IN UCHAR BulkOutPipeId,
40111 + IN UINT32 NumberRequired)
40112 +{
40113 +// UCHAR FreeNumber = 0;
40114 +// UINT Index;
40115 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
40116 + unsigned long IrqFlags;
40117 + HT_TX_CONTEXT *pHTTXContext;
40118 +
40119 +
40120 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
40121 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40122 + if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition) && ((pHTTXContext->CurWritePosition + NumberRequired + LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition))
40123 + {
40124 +
40125 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
40126 + }
40127 + else if ((pHTTXContext->CurWritePosition == 8) && (pHTTXContext->NextBulkOutPosition < (NumberRequired + LOCAL_TXBUF_SIZE)))
40128 + {
40129 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
40130 + }
40131 + else if (pHTTXContext->bCurWriting == TRUE)
40132 + {
40133 + DBGPRINT(RT_DEBUG_TRACE,("RTUSBFreeD c3 --> QueIdx=%d, CWPos=%ld, NBOutPos=%ld!\n", BulkOutPipeId, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition));
40134 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
40135 + }
40136 + else
40137 + {
40138 + Status = NDIS_STATUS_SUCCESS;
40139 + }
40140 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40141 +
40142 +
40143 + return (Status);
40144 +}
40145 +
40146 +
40147 +NDIS_STATUS RTUSBFreeDescriptorRelease(
40148 + IN RTMP_ADAPTER *pAd,
40149 + IN UCHAR BulkOutPipeId)
40150 +{
40151 + unsigned long IrqFlags;
40152 + HT_TX_CONTEXT *pHTTXContext;
40153 +
40154 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
40155 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40156 + pHTTXContext->bCurWriting = FALSE;
40157 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40158 +
40159 + return (NDIS_STATUS_SUCCESS);
40160 +}
40161 +
40162 +
40163 +BOOLEAN RTUSBNeedQueueBackForAgg(
40164 + IN RTMP_ADAPTER *pAd,
40165 + IN UCHAR BulkOutPipeId)
40166 +{
40167 + unsigned long IrqFlags;
40168 + HT_TX_CONTEXT *pHTTXContext;
40169 + BOOLEAN needQueBack = FALSE;
40170 +
40171 + pHTTXContext = &pAd->TxContext[BulkOutPipeId];
40172 +
40173 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40174 + if ((pHTTXContext->IRPPending == TRUE) /*&& (pAd->TxSwQueue[BulkOutPipeId].Number == 0) */)
40175 + {
40176 + if ((pHTTXContext->CurWritePosition < pHTTXContext->ENextBulkOutPosition) &&
40177 + (((pHTTXContext->ENextBulkOutPosition+MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT) || (pHTTXContext->CurWritePosition > MAX_AGGREGATION_SIZE)))
40178 + {
40179 + needQueBack = TRUE;
40180 + }
40181 + else if ((pHTTXContext->CurWritePosition > pHTTXContext->ENextBulkOutPosition) &&
40182 + ((pHTTXContext->ENextBulkOutPosition + MAX_AGGREGATION_SIZE) < pHTTXContext->CurWritePosition))
40183 + {
40184 + needQueBack = TRUE;
40185 + }
40186 + }
40187 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
40188 +
40189 + return needQueBack;
40190 +
40191 +}
40192 +
40193 +
40194 +/*
40195 + ========================================================================
40196 +
40197 + Routine Description:
40198 +
40199 + Arguments:
40200 +
40201 + Return Value:
40202 +
40203 + IRQL =
40204 +
40205 + Note:
40206 +
40207 + ========================================================================
40208 +*/
40209 +VOID RTUSBRejectPendingPackets(
40210 + IN PRTMP_ADAPTER pAd)
40211 +{
40212 + UCHAR Index;
40213 + PQUEUE_ENTRY pEntry;
40214 + PNDIS_PACKET pPacket;
40215 + PQUEUE_HEADER pQueue;
40216 +
40217 +
40218 + for (Index = 0; Index < 4; Index++)
40219 + {
40220 + NdisAcquireSpinLock(&pAd->TxSwQueueLock[Index]);
40221 + while (pAd->TxSwQueue[Index].Head != NULL)
40222 + {
40223 + pQueue = (PQUEUE_HEADER) &(pAd->TxSwQueue[Index]);
40224 + pEntry = RemoveHeadQueue(pQueue);
40225 + pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
40226 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
40227 + }
40228 + NdisReleaseSpinLock(&pAd->TxSwQueueLock[Index]);
40229 +
40230 + }
40231 +
40232 +}
40233 +
40234 +VOID RTMPWriteTxInfo(
40235 + IN PRTMP_ADAPTER pAd,
40236 + IN PTXINFO_STRUC pTxInfo,
40237 + IN USHORT USBDMApktLen,
40238 + IN BOOLEAN bWiv,
40239 + IN UCHAR QueueSel,
40240 + IN UCHAR NextValid,
40241 + IN UCHAR TxBurst)
40242 +{
40243 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
40244 + pTxInfo->QSEL = QueueSel;
40245 + if (QueueSel != FIFO_EDCA)
40246 + DBGPRINT(RT_DEBUG_TRACE, ("====> QueueSel != FIFO_EDCA<============\n"));
40247 + pTxInfo->USBDMANextVLD = FALSE; //NextValid; // Need to check with Jan about this.
40248 + pTxInfo->USBDMATxburst = TxBurst;
40249 + pTxInfo->WIV = bWiv;
40250 + pTxInfo->SwUseLastRound = 0;
40251 + pTxInfo->rsv = 0;
40252 + pTxInfo->rsv2 = 0;
40253 +}
40254 +
40255 --- /dev/null
40256 +++ b/drivers/staging/rt3070/common/rtusb_io.c
40257 @@ -0,0 +1,1908 @@
40258 +/*
40259 + *************************************************************************
40260 + * Ralink Tech Inc.
40261 + * 5F., No.36, Taiyuan St., Jhubei City,
40262 + * Hsinchu County 302,
40263 + * Taiwan, R.O.C.
40264 + *
40265 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
40266 + *
40267 + * This program is free software; you can redistribute it and/or modify *
40268 + * it under the terms of the GNU General Public License as published by *
40269 + * the Free Software Foundation; either version 2 of the License, or *
40270 + * (at your option) any later version. *
40271 + * *
40272 + * This program is distributed in the hope that it will be useful, *
40273 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
40274 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
40275 + * GNU General Public License for more details. *
40276 + * *
40277 + * You should have received a copy of the GNU General Public License *
40278 + * along with this program; if not, write to the *
40279 + * Free Software Foundation, Inc., *
40280 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
40281 + * *
40282 + *************************************************************************
40283 +
40284 + Module Name:
40285 + rtusb_io.c
40286 +
40287 + Abstract:
40288 +
40289 + Revision History:
40290 + Who When What
40291 + -------- ---------- ----------------------------------------------
40292 + Name Date Modification logs
40293 + Paul Lin 06-25-2004 created
40294 +*/
40295 +
40296 +#include "../rt_config.h"
40297 +
40298 +
40299 +/*
40300 + ========================================================================
40301 +
40302 + Routine Description: NIC initialization complete
40303 +
40304 + Arguments:
40305 +
40306 + Return Value:
40307 +
40308 + IRQL =
40309 +
40310 + Note:
40311 +
40312 + ========================================================================
40313 +*/
40314 +
40315 +NTSTATUS RTUSBFirmwareRun(
40316 + IN PRTMP_ADAPTER pAd)
40317 +{
40318 + NTSTATUS Status;
40319 +
40320 + Status = RTUSB_VendorRequest(
40321 + pAd,
40322 + USBD_TRANSFER_DIRECTION_OUT,
40323 + DEVICE_VENDOR_REQUEST_OUT,
40324 + 0x01,
40325 + 0x8,
40326 + 0,
40327 + NULL,
40328 + 0);
40329 +
40330 + return Status;
40331 +}
40332 +
40333 +
40334 +
40335 +/*
40336 + ========================================================================
40337 +
40338 + Routine Description: Write Firmware to NIC.
40339 +
40340 + Arguments:
40341 +
40342 + Return Value:
40343 +
40344 + IRQL =
40345 +
40346 + Note:
40347 +
40348 + ========================================================================
40349 +*/
40350 +NTSTATUS RTUSBFirmwareWrite(
40351 + IN PRTMP_ADAPTER pAd,
40352 + IN PUCHAR pFwImage,
40353 + IN ULONG FwLen)
40354 +{
40355 + UINT32 MacReg;
40356 + NTSTATUS Status;
40357 +// ULONG i;
40358 + USHORT writeLen;
40359 +
40360 + Status = RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg);
40361 +
40362 +
40363 + writeLen = FwLen;
40364 + RTUSBMultiWrite(pAd, FIRMWARE_IMAGE_BASE, pFwImage, writeLen);
40365 +
40366 + Status = RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff);
40367 + Status = RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff);
40368 + Status = RTUSBFirmwareRun(pAd);
40369 +
40370 + RTMPusecDelay(10000);
40371 + RTUSBWriteMACRegister(pAd,H2M_MAILBOX_CSR,0);
40372 + AsicSendCommandToMcu(pAd, 0x72, 0x00, 0x00, 0x00);//reset rf by MCU supported by new firmware
40373 +
40374 + return Status;
40375 +}
40376 +
40377 +
40378 +/*
40379 + ========================================================================
40380 +
40381 + Routine Description: Get current firmware operation mode (Return Value)
40382 +
40383 + Arguments:
40384 +
40385 + Return Value:
40386 + 0 or 1 = Downloaded by host driver
40387 + others = Driver doesn't download firmware
40388 +
40389 + IRQL =
40390 +
40391 + Note:
40392 +
40393 + ========================================================================
40394 +*/
40395 +NTSTATUS RTUSBFirmwareOpmode(
40396 + IN PRTMP_ADAPTER pAd,
40397 + OUT PUINT32 pValue)
40398 +{
40399 + NTSTATUS Status;
40400 +
40401 + Status = RTUSB_VendorRequest(
40402 + pAd,
40403 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40404 + DEVICE_VENDOR_REQUEST_IN,
40405 + 0x1,
40406 + 0x11,
40407 + 0,
40408 + pValue,
40409 + 4);
40410 + return Status;
40411 +}
40412 +NTSTATUS RTUSBVenderReset(
40413 + IN PRTMP_ADAPTER pAd)
40414 +{
40415 + NTSTATUS Status;
40416 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("-->RTUSBVenderReset\n"));
40417 + Status = RTUSB_VendorRequest(
40418 + pAd,
40419 + USBD_TRANSFER_DIRECTION_OUT,
40420 + DEVICE_VENDOR_REQUEST_OUT,
40421 + 0x01,
40422 + 0x1,
40423 + 0,
40424 + NULL,
40425 + 0);
40426 +
40427 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("<--RTUSBVenderReset\n"));
40428 + return Status;
40429 +}
40430 +/*
40431 + ========================================================================
40432 +
40433 + Routine Description: Read various length data from RT2573
40434 +
40435 + Arguments:
40436 +
40437 + Return Value:
40438 +
40439 + IRQL =
40440 +
40441 + Note:
40442 +
40443 + ========================================================================
40444 +*/
40445 +NTSTATUS RTUSBMultiRead(
40446 + IN PRTMP_ADAPTER pAd,
40447 + IN USHORT Offset,
40448 + OUT PUCHAR pData,
40449 + IN USHORT length)
40450 +{
40451 + NTSTATUS Status;
40452 +
40453 + Status = RTUSB_VendorRequest(
40454 + pAd,
40455 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40456 + DEVICE_VENDOR_REQUEST_IN,
40457 + 0x7,
40458 + 0,
40459 + Offset,
40460 + pData,
40461 + length);
40462 +
40463 + return Status;
40464 +}
40465 +
40466 +/*
40467 + ========================================================================
40468 +
40469 + Routine Description: Write various length data to RT2573
40470 +
40471 + Arguments:
40472 +
40473 + Return Value:
40474 +
40475 + IRQL =
40476 +
40477 + Note:
40478 +
40479 + ========================================================================
40480 +*/
40481 +NTSTATUS RTUSBMultiWrite_OneByte(
40482 + IN PRTMP_ADAPTER pAd,
40483 + IN USHORT Offset,
40484 + IN PUCHAR pData)
40485 +{
40486 + NTSTATUS Status;
40487 +
40488 + // TODO: In 2870, use this funciton carefully cause it's not stable.
40489 + Status = RTUSB_VendorRequest(
40490 + pAd,
40491 + USBD_TRANSFER_DIRECTION_OUT,
40492 + DEVICE_VENDOR_REQUEST_OUT,
40493 + 0x6,
40494 + 0,
40495 + Offset,
40496 + pData,
40497 + 1);
40498 +
40499 + return Status;
40500 +}
40501 +
40502 +NTSTATUS RTUSBMultiWrite(
40503 + IN PRTMP_ADAPTER pAd,
40504 + IN USHORT Offset,
40505 + IN PUCHAR pData,
40506 + IN USHORT length)
40507 +{
40508 + NTSTATUS Status;
40509 +
40510 +
40511 + USHORT index = 0,Value;
40512 + PUCHAR pSrc = pData;
40513 + USHORT resude = 0;
40514 +
40515 + resude = length % 2;
40516 + length += resude;
40517 + do
40518 + {
40519 + Value =(USHORT)( *pSrc | (*(pSrc + 1) << 8));
40520 + Status = RTUSBSingleWrite(pAd,Offset + index,Value);
40521 + index +=2;
40522 + length -= 2;
40523 + pSrc = pSrc + 2;
40524 + }while(length > 0);
40525 +
40526 + return Status;
40527 +}
40528 +
40529 +
40530 +NTSTATUS RTUSBSingleWrite(
40531 + IN RTMP_ADAPTER *pAd,
40532 + IN USHORT Offset,
40533 + IN USHORT Value)
40534 +{
40535 + NTSTATUS Status;
40536 +
40537 + Status = RTUSB_VendorRequest(
40538 + pAd,
40539 + USBD_TRANSFER_DIRECTION_OUT,
40540 + DEVICE_VENDOR_REQUEST_OUT,
40541 + 0x2,
40542 + Value,
40543 + Offset,
40544 + NULL,
40545 + 0);
40546 +
40547 + return Status;
40548 +
40549 +}
40550 +
40551 +
40552 +/*
40553 + ========================================================================
40554 +
40555 + Routine Description: Read 32-bit MAC register
40556 +
40557 + Arguments:
40558 +
40559 + Return Value:
40560 +
40561 + IRQL =
40562 +
40563 + Note:
40564 +
40565 + ========================================================================
40566 +*/
40567 +NTSTATUS RTUSBReadMACRegister(
40568 + IN PRTMP_ADAPTER pAd,
40569 + IN USHORT Offset,
40570 + OUT PUINT32 pValue)
40571 +{
40572 + NTSTATUS Status;
40573 + UINT32 localVal;
40574 +
40575 + Status = RTUSB_VendorRequest(
40576 + pAd,
40577 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40578 + DEVICE_VENDOR_REQUEST_IN,
40579 + 0x7,
40580 + 0,
40581 + Offset,
40582 + &localVal,
40583 + 4);
40584 +
40585 + *pValue = le2cpu32(localVal);
40586 +
40587 +
40588 + if (Status < 0)
40589 + *pValue = 0xffffffff;
40590 +
40591 + return Status;
40592 +}
40593 +
40594 +
40595 +/*
40596 + ========================================================================
40597 +
40598 + Routine Description: Write 32-bit MAC register
40599 +
40600 + Arguments:
40601 +
40602 + Return Value:
40603 +
40604 + IRQL =
40605 +
40606 + Note:
40607 +
40608 + ========================================================================
40609 +*/
40610 +NTSTATUS RTUSBWriteMACRegister(
40611 + IN PRTMP_ADAPTER pAd,
40612 + IN USHORT Offset,
40613 + IN UINT32 Value)
40614 +{
40615 + NTSTATUS Status;
40616 + UINT32 localVal;
40617 +
40618 + localVal = Value;
40619 +
40620 + Status = RTUSBSingleWrite(pAd, Offset, (USHORT)(localVal & 0xffff));
40621 + Status = RTUSBSingleWrite(pAd, Offset + 2, (USHORT)((localVal & 0xffff0000) >> 16));
40622 +
40623 + return Status;
40624 +}
40625 +
40626 +
40627 +
40628 +#if 1
40629 +/*
40630 + ========================================================================
40631 +
40632 + Routine Description: Read 8-bit BBP register
40633 +
40634 + Arguments:
40635 +
40636 + Return Value:
40637 +
40638 + IRQL =
40639 +
40640 + Note:
40641 +
40642 + ========================================================================
40643 +*/
40644 +NTSTATUS RTUSBReadBBPRegister(
40645 + IN PRTMP_ADAPTER pAd,
40646 + IN UCHAR Id,
40647 + IN PUCHAR pValue)
40648 +{
40649 + BBP_CSR_CFG_STRUC BbpCsr;
40650 + UINT i = 0;
40651 + NTSTATUS status;
40652 +
40653 + // Verify the busy condition
40654 + do
40655 + {
40656 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40657 + if(status >= 0)
40658 + {
40659 + if (!(BbpCsr.field.Busy == BUSY))
40660 + break;
40661 + }
40662 + printk("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n", i);
40663 + i++;
40664 + }
40665 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40666 +
40667 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40668 + {
40669 + //
40670 + // Read failed then Return Default value.
40671 + //
40672 + *pValue = pAd->BbpWriteLatch[Id];
40673 +
40674 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40675 + return STATUS_UNSUCCESSFUL;
40676 + }
40677 +
40678 + // Prepare for write material
40679 + BbpCsr.word = 0;
40680 + BbpCsr.field.fRead = 1;
40681 + BbpCsr.field.Busy = 1;
40682 + BbpCsr.field.RegNum = Id;
40683 + RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
40684 +
40685 + i = 0;
40686 + // Verify the busy condition
40687 + do
40688 + {
40689 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40690 + if (status >= 0)
40691 + {
40692 + if (!(BbpCsr.field.Busy == BUSY))
40693 + {
40694 + *pValue = (UCHAR)BbpCsr.field.Value;
40695 + break;
40696 + }
40697 + }
40698 + printk("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n", i);
40699 + i++;
40700 + }
40701 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40702 +
40703 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40704 + {
40705 + //
40706 + // Read failed then Return Default value.
40707 + //
40708 + *pValue = pAd->BbpWriteLatch[Id];
40709 +
40710 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40711 + return STATUS_UNSUCCESSFUL;
40712 + }
40713 +
40714 + return STATUS_SUCCESS;
40715 +}
40716 +#else
40717 +/*
40718 + ========================================================================
40719 +
40720 + Routine Description: Read 8-bit BBP register via firmware
40721 +
40722 + Arguments:
40723 +
40724 + Return Value:
40725 +
40726 + IRQL =
40727 +
40728 + Note:
40729 +
40730 + ========================================================================
40731 +*/
40732 +NTSTATUS RTUSBReadBBPRegister(
40733 + IN PRTMP_ADAPTER pAd,
40734 + IN UCHAR Id,
40735 + IN PUCHAR pValue)
40736 +{
40737 + BBP_CSR_CFG_STRUC BbpCsr;
40738 + int i, k;
40739 + for (i=0; i<MAX_BUSY_COUNT; i++)
40740 + {
40741 + RTUSBReadMACRegister(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40742 + if (BbpCsr.field.Busy == BUSY)
40743 + {
40744 + continue;
40745 + }
40746 + BbpCsr.word = 0;
40747 + BbpCsr.field.fRead = 1;
40748 + BbpCsr.field.BBP_RW_MODE = 1;
40749 + BbpCsr.field.Busy = 1;
40750 + BbpCsr.field.RegNum = Id;
40751 + RTUSBWriteMACRegister(pAd, H2M_BBP_AGENT, BbpCsr.word);
40752 + AsicSendCommandToMcu(pAd, 0x80, 0xff, 0x0, 0x0);
40753 + for (k=0; k<MAX_BUSY_COUNT; k++)
40754 + {
40755 + RTUSBReadMACRegister(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40756 + if (BbpCsr.field.Busy == IDLE)
40757 + break;
40758 + }
40759 + if ((BbpCsr.field.Busy == IDLE) &&
40760 + (BbpCsr.field.RegNum == Id))
40761 + {
40762 + *pValue = (UCHAR)BbpCsr.field.Value;
40763 + break;
40764 + }
40765 + }
40766 + if (BbpCsr.field.Busy == BUSY)
40767 + {
40768 + DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", Id, BbpCsr.word));
40769 + *pValue = pAd->BbpWriteLatch[Id];
40770 + return STATUS_UNSUCCESSFUL;
40771 + }
40772 + return STATUS_SUCCESS;
40773 +}
40774 +#endif
40775 +
40776 +#if 1
40777 +/*
40778 + ========================================================================
40779 +
40780 + Routine Description: Write 8-bit BBP register
40781 +
40782 + Arguments:
40783 +
40784 + Return Value:
40785 +
40786 + IRQL =
40787 +
40788 + Note:
40789 +
40790 + ========================================================================
40791 +*/
40792 +NTSTATUS RTUSBWriteBBPRegister(
40793 + IN PRTMP_ADAPTER pAd,
40794 + IN UCHAR Id,
40795 + IN UCHAR Value)
40796 +{
40797 + BBP_CSR_CFG_STRUC BbpCsr;
40798 + UINT i = 0;
40799 + NTSTATUS status;
40800 + // Verify the busy condition
40801 + do
40802 + {
40803 + status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
40804 + if (status >= 0)
40805 + {
40806 + if (!(BbpCsr.field.Busy == BUSY))
40807 + break;
40808 + }
40809 + printk("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n", i);
40810 + i++;
40811 + }
40812 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40813 +
40814 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40815 + {
40816 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40817 + return STATUS_UNSUCCESSFUL;
40818 + }
40819 +
40820 + // Prepare for write material
40821 + BbpCsr.word = 0;
40822 + BbpCsr.field.fRead = 0;
40823 + BbpCsr.field.Value = Value;
40824 + BbpCsr.field.Busy = 1;
40825 + BbpCsr.field.RegNum = Id;
40826 + RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
40827 +
40828 + pAd->BbpWriteLatch[Id] = Value;
40829 +
40830 + return STATUS_SUCCESS;
40831 +}
40832 +#else
40833 +/*
40834 + ========================================================================
40835 +
40836 + Routine Description: Write 8-bit BBP register via firmware
40837 +
40838 + Arguments:
40839 +
40840 + Return Value:
40841 +
40842 + IRQL =
40843 +
40844 + Note:
40845 +
40846 + ========================================================================
40847 +*/
40848 +
40849 +NTSTATUS RTUSBWriteBBPRegister(
40850 + IN PRTMP_ADAPTER pAd,
40851 + IN UCHAR Id,
40852 + IN UCHAR Value)
40853 +
40854 +{
40855 + BBP_CSR_CFG_STRUC BbpCsr;
40856 + int BusyCnt;
40857 + for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)
40858 + {
40859 + RTMP_IO_READ32(pAd, H2M_BBP_AGENT, &BbpCsr.word);
40860 + if (BbpCsr.field.Busy == BUSY)
40861 + continue;
40862 + BbpCsr.word = 0;
40863 + BbpCsr.field.fRead = 0;
40864 + BbpCsr.field.BBP_RW_MODE = 1;
40865 + BbpCsr.field.Busy = 1;
40866 + BbpCsr.field.Value = Value;
40867 + BbpCsr.field.RegNum = Id;
40868 + RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, BbpCsr.word);
40869 + AsicSendCommandToMcu(pAd, 0x80, 0xff, 0x0, 0x0);
40870 + pAd->BbpWriteLatch[Id] = Value;
40871 + break;
40872 + }
40873 + if (BusyCnt == MAX_BUSY_COUNT)
40874 + {
40875 + DBGPRINT_ERR(("BBP write R%d=0x%x fail\n", Id, BbpCsr.word));
40876 + return STATUS_UNSUCCESSFUL;
40877 + }
40878 + return STATUS_SUCCESS;
40879 +}
40880 +#endif
40881 +/*
40882 + ========================================================================
40883 +
40884 + Routine Description: Write RF register through MAC
40885 +
40886 + Arguments:
40887 +
40888 + Return Value:
40889 +
40890 + IRQL =
40891 +
40892 + Note:
40893 +
40894 + ========================================================================
40895 +*/
40896 +NTSTATUS RTUSBWriteRFRegister(
40897 + IN PRTMP_ADAPTER pAd,
40898 + IN UINT32 Value)
40899 +{
40900 + PHY_CSR4_STRUC PhyCsr4;
40901 + UINT i = 0;
40902 + NTSTATUS status;
40903 +
40904 + NdisZeroMemory(&PhyCsr4, sizeof(PHY_CSR4_STRUC));
40905 + do
40906 + {
40907 + status = RTUSBReadMACRegister(pAd, RF_CSR_CFG0, &PhyCsr4.word);
40908 + if (status >= 0)
40909 + {
40910 + if (!(PhyCsr4.field.Busy))
40911 + break;
40912 + }
40913 + printk("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n", i);
40914 + i++;
40915 + }
40916 + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
40917 +
40918 + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
40919 + {
40920 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n"));
40921 + return STATUS_UNSUCCESSFUL;
40922 + }
40923 +
40924 + RTUSBWriteMACRegister(pAd, RF_CSR_CFG0, Value);
40925 +
40926 + return STATUS_SUCCESS;
40927 +}
40928 +
40929 +
40930 +/*
40931 + ========================================================================
40932 +
40933 + Routine Description:
40934 +
40935 + Arguments:
40936 +
40937 + Return Value:
40938 +
40939 + IRQL =
40940 +
40941 + Note:
40942 +
40943 + ========================================================================
40944 +*/
40945 +NTSTATUS RTUSBReadEEPROM(
40946 + IN PRTMP_ADAPTER pAd,
40947 + IN USHORT Offset,
40948 + OUT PUCHAR pData,
40949 + IN USHORT length)
40950 +{
40951 + NTSTATUS Status = STATUS_SUCCESS;
40952 +
40953 +#ifdef RT30xx
40954 + if(pAd->bUseEfuse)
40955 + {
40956 + Status =eFuseRead(pAd, Offset, pData, length);
40957 + }
40958 + else
40959 +#endif // RT30xx //
40960 + {
40961 + Status = RTUSB_VendorRequest(
40962 + pAd,
40963 + (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK),
40964 + DEVICE_VENDOR_REQUEST_IN,
40965 + 0x9,
40966 + 0,
40967 + Offset,
40968 + pData,
40969 + length);
40970 + }
40971 +
40972 + return Status;
40973 +}
40974 +
40975 +/*
40976 + ========================================================================
40977 +
40978 + Routine Description:
40979 +
40980 + Arguments:
40981 +
40982 + Return Value:
40983 +
40984 + IRQL =
40985 +
40986 + Note:
40987 +
40988 + ========================================================================
40989 +*/
40990 +NTSTATUS RTUSBWriteEEPROM(
40991 + IN PRTMP_ADAPTER pAd,
40992 + IN USHORT Offset,
40993 + IN PUCHAR pData,
40994 + IN USHORT length)
40995 +{
40996 + NTSTATUS Status = STATUS_SUCCESS;
40997 +
40998 +#ifdef RT30xx
40999 + if(pAd->bUseEfuse)
41000 + {
41001 + Status = eFuseWrite(pAd, Offset, pData, length);
41002 + }
41003 + else
41004 +#endif // RT30xx //
41005 + {
41006 + Status = RTUSB_VendorRequest(
41007 + pAd,
41008 + USBD_TRANSFER_DIRECTION_OUT,
41009 + DEVICE_VENDOR_REQUEST_OUT,
41010 + 0x8,
41011 + 0,
41012 + Offset,
41013 + pData,
41014 + length);
41015 + }
41016 +
41017 + return Status;
41018 +}
41019 +
41020 +/*
41021 + ========================================================================
41022 +
41023 + Routine Description:
41024 +
41025 + Arguments:
41026 +
41027 + Return Value:
41028 +
41029 + IRQL =
41030 +
41031 + Note:
41032 +
41033 + ========================================================================
41034 +*/
41035 +VOID RTUSBPutToSleep(
41036 + IN PRTMP_ADAPTER pAd)
41037 +{
41038 + UINT32 value;
41039 +
41040 + // Timeout 0x40 x 50us
41041 + value = (SLEEPCID<<16)+(OWNERMCU<<24)+ (0x40<<8)+1;
41042 + RTUSBWriteMACRegister(pAd, 0x7010, value);
41043 + RTUSBWriteMACRegister(pAd, 0x404, 0x30);
41044 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
41045 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Sleep Mailbox testvalue %x\n", value));
41046 +
41047 +}
41048 +
41049 +/*
41050 + ========================================================================
41051 +
41052 + Routine Description:
41053 +
41054 + Arguments:
41055 +
41056 + Return Value:
41057 +
41058 + IRQL =
41059 +
41060 + Note:
41061 +
41062 + ========================================================================
41063 +*/
41064 +NTSTATUS RTUSBWakeUp(
41065 + IN PRTMP_ADAPTER pAd)
41066 +{
41067 + NTSTATUS Status;
41068 +
41069 + Status = RTUSB_VendorRequest(
41070 + pAd,
41071 + USBD_TRANSFER_DIRECTION_OUT,
41072 + DEVICE_VENDOR_REQUEST_OUT,
41073 + 0x01,
41074 + 0x09,
41075 + 0,
41076 + NULL,
41077 + 0);
41078 +
41079 + return Status;
41080 +}
41081 +
41082 +/*
41083 + ========================================================================
41084 +
41085 + Routine Description:
41086 +
41087 + Arguments:
41088 +
41089 + Return Value:
41090 +
41091 + IRQL =
41092 +
41093 + Note:
41094 +
41095 + ========================================================================
41096 +*/
41097 +VOID RTUSBInitializeCmdQ(
41098 + IN PCmdQ cmdq)
41099 +{
41100 + cmdq->head = NULL;
41101 + cmdq->tail = NULL;
41102 + cmdq->size = 0;
41103 + cmdq->CmdQState = RT2870_THREAD_INITED;
41104 +}
41105 +
41106 +/*
41107 + ========================================================================
41108 +
41109 + Routine Description:
41110 +
41111 + Arguments:
41112 +
41113 + Return Value:
41114 +
41115 + IRQL =
41116 +
41117 + Note:
41118 +
41119 + ========================================================================
41120 +*/
41121 +NDIS_STATUS RTUSBEnqueueCmdFromNdis(
41122 + IN PRTMP_ADAPTER pAd,
41123 + IN NDIS_OID Oid,
41124 + IN BOOLEAN SetInformation,
41125 + IN PVOID pInformationBuffer,
41126 + IN UINT32 InformationBufferLength)
41127 +{
41128 + NDIS_STATUS status;
41129 + PCmdQElmt cmdqelmt = NULL;
41130 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
41131 +
41132 +
41133 + if (pObj->RTUSBCmdThr_pid < 0)
41134 + return (NDIS_STATUS_RESOURCES);
41135 +
41136 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt, sizeof(CmdQElmt));
41137 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
41138 + return (NDIS_STATUS_RESOURCES);
41139 +
41140 + cmdqelmt->buffer = NULL;
41141 + if (pInformationBuffer != NULL)
41142 + {
41143 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt->buffer, InformationBufferLength);
41144 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt->buffer == NULL))
41145 + {
41146 + kfree(cmdqelmt);
41147 + return (NDIS_STATUS_RESOURCES);
41148 + }
41149 + else
41150 + {
41151 + NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, InformationBufferLength);
41152 + cmdqelmt->bufferlength = InformationBufferLength;
41153 + }
41154 + }
41155 + else
41156 + cmdqelmt->bufferlength = 0;
41157 +
41158 + cmdqelmt->command = Oid;
41159 + cmdqelmt->CmdFromNdis = TRUE;
41160 + if (SetInformation == TRUE)
41161 + cmdqelmt->SetOperation = TRUE;
41162 + else
41163 + cmdqelmt->SetOperation = FALSE;
41164 +
41165 + NdisAcquireSpinLock(&pAd->CmdQLock);
41166 + if (pAd->CmdQ.CmdQState & RT2870_THREAD_CAN_DO_INSERT)
41167 + {
41168 + EnqueueCmd((&pAd->CmdQ), cmdqelmt);
41169 + status = NDIS_STATUS_SUCCESS;
41170 + }
41171 + else
41172 + {
41173 + status = NDIS_STATUS_FAILURE;
41174 + }
41175 + NdisReleaseSpinLock(&pAd->CmdQLock);
41176 +
41177 + if (status == NDIS_STATUS_FAILURE)
41178 + {
41179 + if (cmdqelmt->buffer)
41180 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
41181 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41182 + }
41183 + else
41184 + RTUSBCMDUp(pAd);
41185 +
41186 +
41187 + return(NDIS_STATUS_SUCCESS);
41188 +}
41189 +
41190 +/*
41191 + ========================================================================
41192 +
41193 + Routine Description:
41194 +
41195 + Arguments:
41196 +
41197 + Return Value:
41198 +
41199 + IRQL =
41200 +
41201 + Note:
41202 +
41203 + ========================================================================
41204 +*/
41205 +NDIS_STATUS RTUSBEnqueueInternalCmd(
41206 + IN PRTMP_ADAPTER pAd,
41207 + IN NDIS_OID Oid,
41208 + IN PVOID pInformationBuffer,
41209 + IN UINT32 InformationBufferLength)
41210 +{
41211 + NDIS_STATUS status;
41212 + PCmdQElmt cmdqelmt = NULL;
41213 +
41214 +
41215 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt, sizeof(CmdQElmt));
41216 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
41217 + return (NDIS_STATUS_RESOURCES);
41218 + NdisZeroMemory(cmdqelmt, sizeof(CmdQElmt));
41219 +
41220 + if(InformationBufferLength > 0)
41221 + {
41222 + status = RTMPAllocateMemory((PVOID *)&cmdqelmt->buffer, InformationBufferLength);
41223 + if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt->buffer == NULL))
41224 + {
41225 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41226 + return (NDIS_STATUS_RESOURCES);
41227 + }
41228 + else
41229 + {
41230 + NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, InformationBufferLength);
41231 + cmdqelmt->bufferlength = InformationBufferLength;
41232 + }
41233 + }
41234 + else
41235 + {
41236 + cmdqelmt->buffer = NULL;
41237 + cmdqelmt->bufferlength = 0;
41238 + }
41239 +
41240 + cmdqelmt->command = Oid;
41241 + cmdqelmt->CmdFromNdis = FALSE;
41242 +
41243 + if (cmdqelmt != NULL)
41244 + {
41245 + NdisAcquireSpinLock(&pAd->CmdQLock);
41246 + if (pAd->CmdQ.CmdQState & RT2870_THREAD_CAN_DO_INSERT)
41247 + {
41248 + EnqueueCmd((&pAd->CmdQ), cmdqelmt);
41249 + status = NDIS_STATUS_SUCCESS;
41250 + }
41251 + else
41252 + {
41253 + status = NDIS_STATUS_FAILURE;
41254 + }
41255 + NdisReleaseSpinLock(&pAd->CmdQLock);
41256 +
41257 + if (status == NDIS_STATUS_FAILURE)
41258 + {
41259 + if (cmdqelmt->buffer)
41260 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
41261 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
41262 + }
41263 + else
41264 + RTUSBCMDUp(pAd);
41265 + }
41266 + return(NDIS_STATUS_SUCCESS);
41267 +}
41268 +
41269 +/*
41270 + ========================================================================
41271 +
41272 + Routine Description:
41273 +
41274 + Arguments:
41275 +
41276 + Return Value:
41277 +
41278 + IRQL =
41279 +
41280 + Note:
41281 +
41282 + ========================================================================
41283 +*/
41284 +VOID RTUSBDequeueCmd(
41285 + IN PCmdQ cmdq,
41286 + OUT PCmdQElmt *pcmdqelmt)
41287 +{
41288 + *pcmdqelmt = cmdq->head;
41289 +
41290 + if (*pcmdqelmt != NULL)
41291 + {
41292 + cmdq->head = cmdq->head->next;
41293 + cmdq->size--;
41294 + if (cmdq->size == 0)
41295 + cmdq->tail = NULL;
41296 + }
41297 +}
41298 +
41299 +/*
41300 + ========================================================================
41301 + usb_control_msg - Builds a control urb, sends it off and waits for completion
41302 + @dev: pointer to the usb device to send the message to
41303 + @pipe: endpoint "pipe" to send the message to
41304 + @request: USB message request value
41305 + @requesttype: USB message request type value
41306 + @value: USB message value
41307 + @index: USB message index value
41308 + @data: pointer to the data to send
41309 + @size: length in bytes of the data to send
41310 + @timeout: time in jiffies to wait for the message to complete before
41311 + timing out (if 0 the wait is forever)
41312 + Context: !in_interrupt ()
41313 +
41314 + This function sends a simple control message to a specified endpoint
41315 + and waits for the message to complete, or timeout.
41316 + If successful, it returns the number of bytes transferred, otherwise a negative error number.
41317 +
41318 + Don't use this function from within an interrupt context, like a
41319 + bottom half handler. If you need an asynchronous message, or need to send
41320 + a message from within interrupt context, use usb_submit_urb()
41321 + If a thread in your driver uses this call, make sure your disconnect()
41322 + method can wait for it to complete. Since you don't have a handle on
41323 + the URB used, you can't cancel the request.
41324 +
41325 +
41326 + Routine Description:
41327 +
41328 + Arguments:
41329 +
41330 + Return Value:
41331 +
41332 + Note:
41333 +
41334 + ========================================================================
41335 +*/
41336 +NTSTATUS RTUSB_VendorRequest(
41337 + IN PRTMP_ADAPTER pAd,
41338 + IN UINT32 TransferFlags,
41339 + IN UCHAR RequestType,
41340 + IN UCHAR Request,
41341 + IN USHORT Value,
41342 + IN USHORT Index,
41343 + IN PVOID TransferBuffer,
41344 + IN UINT32 TransferBufferLength)
41345 +{
41346 + int ret;
41347 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
41348 +
41349 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
41350 + {
41351 + DBGPRINT(RT_DEBUG_ERROR, ("device disconnected\n"));
41352 + return -1;
41353 + }
41354 + else if (in_interrupt())
41355 + {
41356 + DBGPRINT(RT_DEBUG_ERROR, ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n",Request,Value,Index));
41357 +
41358 + return -1;
41359 + }
41360 + else
41361 + {
41362 +#define MAX_RETRY_COUNT 10
41363 +
41364 + int retryCount = 0;
41365 + void *tmpBuf = TransferBuffer;
41366 +
41367 + // Acquire Control token
41368 +#ifdef INF_AMAZON_SE
41369 + ret = down_interruptible(&(pAd->UsbVendorReq_semaphore));
41370 + if (pAd->UsbVendorReqBuf)
41371 + {
41372 + ASSERT(TransferBufferLength <MAX_PARAM_BUFFER_SIZE);
41373 +
41374 + tmpBuf = (void *)pAd->UsbVendorReqBuf;
41375 + NdisZeroMemory(pAd->UsbVendorReqBuf, TransferBufferLength);
41376 +
41377 + if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
41378 + NdisMoveMemory(tmpBuf, TransferBuffer, TransferBufferLength);
41379 + }
41380 +#endif // INF_AMAZON_SE //
41381 + do {
41382 + if( RequestType == DEVICE_VENDOR_REQUEST_OUT)
41383 + ret=usb_control_msg(pObj->pUsb_Dev, usb_sndctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, tmpBuf, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41384 + else if(RequestType == DEVICE_VENDOR_REQUEST_IN)
41385 + ret=usb_control_msg(pObj->pUsb_Dev, usb_rcvctrlpipe( pObj->pUsb_Dev, 0 ), Request, RequestType, Value,Index, tmpBuf, TransferBufferLength, CONTROL_TIMEOUT_JIFFIES);
41386 + else
41387 + {
41388 + DBGPRINT(RT_DEBUG_ERROR, ("vendor request direction is failed\n"));
41389 + ret = -1;
41390 + }
41391 +
41392 + retryCount++;
41393 + if (ret < 0) {
41394 + printk("#\n");
41395 + RTMPusecDelay(5000);
41396 + }
41397 + } while((ret < 0) && (retryCount < MAX_RETRY_COUNT));
41398 +
41399 +#ifdef INF_AMAZON_SE
41400 + if ((pAd->UsbVendorReqBuf) && (RequestType == DEVICE_VENDOR_REQUEST_IN))
41401 + NdisMoveMemory(TransferBuffer, tmpBuf, TransferBufferLength);
41402 + up(&(pAd->UsbVendorReq_semaphore));
41403 +#endif // INF_AMAZON_SE //
41404 +
41405 + if (ret < 0) {
41406 +// DBGPRINT(RT_DEBUG_ERROR, ("USBVendorRequest failed ret=%d \n",ret));
41407 + DBGPRINT(RT_DEBUG_ERROR, ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n",
41408 + ret, TransferFlags, (RequestType == DEVICE_VENDOR_REQUEST_OUT ? "OUT" : "IN"), Request, Index));
41409 + if (Request == 0x2)
41410 + DBGPRINT(RT_DEBUG_ERROR, ("\tRequest Value=0x%04x!\n", Value));
41411 +
41412 + if ((TransferBuffer!= NULL) && (TransferBufferLength > 0))
41413 + hex_dump("Failed TransferBuffer value", TransferBuffer, TransferBufferLength);
41414 + }
41415 + }
41416 + return ret;
41417 +}
41418 +
41419 +/*
41420 + ========================================================================
41421 +
41422 + Routine Description:
41423 + Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT
41424 + synchronously. Callers of this function must be running at
41425 + PASSIVE LEVEL.
41426 +
41427 + Arguments:
41428 +
41429 + Return Value:
41430 +
41431 + Note:
41432 +
41433 + ========================================================================
41434 +*/
41435 +NTSTATUS RTUSB_ResetDevice(
41436 + IN PRTMP_ADAPTER pAd)
41437 +{
41438 + NTSTATUS Status = TRUE;
41439 +
41440 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->USB_ResetDevice\n"));
41441 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
41442 + return Status;
41443 +}
41444 +
41445 +VOID CMDHandler(
41446 + IN PRTMP_ADAPTER pAd)
41447 +{
41448 + PCmdQElmt cmdqelmt;
41449 + PUCHAR pData;
41450 + NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
41451 +// ULONG Now = 0;
41452 + NTSTATUS ntStatus;
41453 +// unsigned long IrqFlags;
41454 +
41455 + while (pAd->CmdQ.size > 0)
41456 + {
41457 + NdisStatus = NDIS_STATUS_SUCCESS;
41458 +
41459 + NdisAcquireSpinLock(&pAd->CmdQLock);
41460 + RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt);
41461 + NdisReleaseSpinLock(&pAd->CmdQLock);
41462 +
41463 + if (cmdqelmt == NULL)
41464 + break;
41465 +
41466 + pData = cmdqelmt->buffer;
41467 +
41468 + if(!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
41469 + {
41470 + switch (cmdqelmt->command)
41471 + {
41472 + case CMDTHREAD_CHECK_GPIO:
41473 + {
41474 +#ifdef CONFIG_STA_SUPPORT
41475 + UINT32 data;
41476 +#endif // CONFIG_STA_SUPPORT //
41477 +#ifdef RALINK_ATE
41478 + if(ATE_ON(pAd))
41479 + {
41480 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
41481 + break;
41482 + }
41483 +#endif // RALINK_ATE //
41484 +
41485 +#ifdef CONFIG_STA_SUPPORT
41486 +
41487 +
41488 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
41489 + {
41490 + // Read GPIO pin2 as Hardware controlled radio state
41491 +
41492 + RTUSBReadMACRegister( pAd, GPIO_CTRL_CFG, &data);
41493 +
41494 + if (data & 0x04)
41495 + {
41496 + pAd->StaCfg.bHwRadio = TRUE;
41497 + }
41498 + else
41499 + {
41500 + pAd->StaCfg.bHwRadio = FALSE;
41501 + }
41502 +
41503 + if(pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
41504 + {
41505 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
41506 + if(pAd->StaCfg.bRadio == TRUE)
41507 + {
41508 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio On !!!\n"));
41509 +
41510 + MlmeRadioOn(pAd);
41511 + // Update extra information
41512 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
41513 + }
41514 + else
41515 + {
41516 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio Off !!!\n"));
41517 +
41518 + MlmeRadioOff(pAd);
41519 + // Update extra information
41520 + pAd->ExtraInfo = HW_RADIO_OFF;
41521 + }
41522 + }
41523 + }
41524 +#endif // CONFIG_STA_SUPPORT //
41525 + }
41526 + break;
41527 +
41528 +#ifdef CONFIG_STA_SUPPORT
41529 + case CMDTHREAD_QKERIODIC_EXECUT:
41530 + {
41531 + StaQuickResponeForRateUpExec(NULL, pAd, NULL, NULL);
41532 + }
41533 + break;
41534 +#endif // CONFIG_STA_SUPPORT //
41535 +
41536 + case CMDTHREAD_RESET_BULK_OUT:
41537 + {
41538 + UINT32 MACValue;
41539 + UCHAR Index;
41540 + int ret=0;
41541 + PHT_TX_CONTEXT pHTTXContext;
41542 +// RTMP_TX_RING *pTxRing;
41543 + unsigned long IrqFlags;
41544 +#ifdef RALINK_ATE
41545 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
41546 +#endif // RALINK_ATE //
41547 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", pAd->bulkResetPipeid));
41548 + // All transfers must be aborted or cancelled before attempting to reset the pipe.
41549 + //RTUSBCancelPendingBulkOutIRP(pAd);
41550 + // Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007
41551 + Index = 0;
41552 + do
41553 + {
41554 + RTUSBReadMACRegister(pAd, TXRXQ_PCNT, &MACValue);
41555 + if ((MACValue & 0xf00000/*0x800000*/) == 0)
41556 + break;
41557 + Index++;
41558 + RTMPusecDelay(10000);
41559 + }while(Index < 100);
41560 + MACValue = 0;
41561 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41562 + // To prevent Read Register error, we 2nd check the validity.
41563 + if ((MACValue & 0xc00000) == 0)
41564 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41565 + // To prevent Read Register error, we 3rd check the validity.
41566 + if ((MACValue & 0xc00000) == 0)
41567 + RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue);
41568 + MACValue |= 0x80000;
41569 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue);
41570 +
41571 + // Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
41572 + RTMPusecDelay(1000);
41573 +
41574 + MACValue &= (~0x80000);
41575 + RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue);
41576 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n"));
41577 +
41578 + // Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
41579 + //RTMPusecDelay(5000);
41580 +
41581 + if ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG)
41582 + {
41583 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41584 + if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */)
41585 + {
41586 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
41587 + }
41588 + RTUSBKickBulkOut(pAd);
41589 +
41590 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tTX MGMT RECOVER Done!\n"));
41591 + }
41592 + else
41593 + {
41594 + pHTTXContext = &(pAd->TxContext[pAd->bulkResetPipeid]);
41595 + //NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41596 + RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41597 + if ( pAd->BulkOutPending[pAd->bulkResetPipeid] == FALSE)
41598 + {
41599 + pAd->BulkOutPending[pAd->bulkResetPipeid] = TRUE;
41600 + pHTTXContext->IRPPending = TRUE;
41601 + pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 1;
41602 +
41603 + // no matter what, clean the flag
41604 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41605 +
41606 + //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41607 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41608 +/*-----------------------------------------------------------------------------------------------*/
41609 +#ifdef RALINK_ATE
41610 + if(ATE_ON(pAd))
41611 + {
41612 + pNullContext->IRPPending = TRUE;
41613 + //
41614 + // If driver is still in ATE TXFRAME mode,
41615 + // keep on transmitting ATE frames.
41616 + //
41617 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("pAd->ate.Mode == %d\npAd->ContinBulkOut == %d\npAd->BulkOutRemained == %d\n", pAd->ate.Mode, pAd->ContinBulkOut, atomic_read(&pAd->BulkOutRemained)));
41618 + if((pAd->ate.Mode == ATE_TXFRAME) && ((pAd->ContinBulkOut == TRUE) || (atomic_read(&pAd->BulkOutRemained) > 0)))
41619 + {
41620 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("After CMDTHREAD_RESET_BULK_OUT, continue to bulk out frames !\n"));
41621 +
41622 + // Init Tx context descriptor
41623 + RTUSBInitTxDesc(pAd, pNullContext, 0/* pAd->bulkResetPipeid */, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
41624 +
41625 + if((ret = RTUSB_SUBMIT_URB(pNullContext->pUrb))!=0)
41626 + {
41627 + DBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
41628 + }
41629 +
41630 + pAd->BulkOutReq++;
41631 + }
41632 + }
41633 + else
41634 +#endif // RALINK_ATE //
41635 +/*-----------------------------------------------------------------------------------------------*/
41636 + {
41637 + RTUSBInitHTTxDesc(pAd, pHTTXContext, pAd->bulkResetPipeid, pHTTXContext->BulkOutSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete);
41638 +
41639 + if((ret = RTUSB_SUBMIT_URB(pHTTXContext->pUrb))!=0)
41640 + {
41641 + RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41642 + pAd->BulkOutPending[pAd->bulkResetPipeid] = FALSE;
41643 + pHTTXContext->IRPPending = FALSE;
41644 + pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 0;
41645 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41646 +
41647 + DBGPRINT(RT_DEBUG_ERROR, ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n", ret));
41648 + }
41649 + else
41650 + {
41651 + RTMP_IRQ_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41652 + DBGPRINT_RAW(RT_DEBUG_TRACE,("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n",
41653 + pAd->bulkResetPipeid, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition,
41654 + pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, pAd->BulkOutPending[pAd->bulkResetPipeid]));
41655 + DBGPRINT_RAW(RT_DEBUG_TRACE,("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
41656 + pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther));
41657 + RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41658 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pHTTXContext->pUrb->status));
41659 +
41660 + }
41661 + }
41662 + }
41663 + else
41664 + {
41665 + //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
41666 + //RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41667 +
41668 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pAd->bulkResetPipeid));
41669 + if (pAd->bulkResetPipeid == 0)
41670 + {
41671 + UCHAR pendingContext = 0;
41672 + PHT_TX_CONTEXT pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[pAd->bulkResetPipeid ]);
41673 + PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
41674 + PTX_CONTEXT pNULLContext = (PTX_CONTEXT)(&pAd->PsPollContext);
41675 + PTX_CONTEXT pPsPollContext = (PTX_CONTEXT)(&pAd->NullContext);
41676 +
41677 + if (pHTTXContext->IRPPending)
41678 + pendingContext |= 1;
41679 + else if (pMLMEContext->IRPPending)
41680 + pendingContext |= 2;
41681 + else if (pNULLContext->IRPPending)
41682 + pendingContext |= 4;
41683 + else if (pPsPollContext->IRPPending)
41684 + pendingContext |= 8;
41685 + else
41686 + pendingContext = 0;
41687 +
41688 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("\tTX Occupied by %d!\n", pendingContext));
41689 + }
41690 +
41691 + // no matter what, clean the flag
41692 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
41693 +
41694 + RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
41695 +
41696 + RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << pAd->bulkResetPipeid));
41697 + }
41698 +
41699 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
41700 + //RTUSBKickBulkOut(pAd);
41701 + }
41702 +
41703 + }
41704 + /*
41705 + // Don't cancel BULKIN.
41706 + while ((atomic_read(&pAd->PendingRx) > 0) &&
41707 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41708 + {
41709 + if (atomic_read(&pAd->PendingRx) > 0)
41710 + {
41711 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n"));
41712 + RTUSBCancelPendingBulkInIRP(pAd);
41713 + }
41714 + RTMPusecDelay(100000);
41715 + }
41716 +
41717 + if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
41718 + {
41719 + UCHAR i;
41720 + RTUSBRxPacket(pAd);
41721 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
41722 + pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
41723 + for (i = 0; i < (RX_RING_SIZE); i++)
41724 + {
41725 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
41726 +
41727 + pRxContext->pAd = pAd;
41728 + pRxContext->InUse = FALSE;
41729 + pRxContext->IRPPending = FALSE;
41730 + pRxContext->Readable = FALSE;
41731 + pRxContext->ReorderInUse = FALSE;
41732 +
41733 + }
41734 + RTUSBBulkReceive(pAd);
41735 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n"));
41736 + }*/
41737 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n"));
41738 + break;
41739 +
41740 + case CMDTHREAD_RESET_BULK_IN:
41741 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n"));
41742 +
41743 + // All transfers must be aborted or cancelled before attempting to reset the pipe.
41744 + {
41745 + UINT32 MACValue;
41746 +/*-----------------------------------------------------------------------------------------------*/
41747 +#ifdef RALINK_ATE
41748 + if (ATE_ON(pAd))
41749 + {
41750 + if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41751 + {
41752 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("ATE : BulkIn IRP Pending!!!\n"));
41753 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
41754 + RTMPusecDelay(100000);
41755 + pAd->PendingRx = 0;
41756 + }
41757 + }
41758 + else
41759 +#endif // RALINK_ATE //
41760 +/*-----------------------------------------------------------------------------------------------*/
41761 + {
41762 + //while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41763 + if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
41764 + {
41765 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!!\n"));
41766 + RTUSBCancelPendingBulkInIRP(pAd);
41767 + RTMPusecDelay(100000);
41768 + pAd->PendingRx = 0;
41769 + }
41770 + }
41771 +
41772 + // Wait 10ms before reading register.
41773 + RTMPusecDelay(10000);
41774 + ntStatus = RTUSBReadMACRegister(pAd, MAC_CSR0, &MACValue);
41775 +
41776 + if ((NT_SUCCESS(ntStatus) == TRUE) &&
41777 + (!(RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF |
41778 + fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))))
41779 + {
41780 + UCHAR i;
41781 +
41782 + if (RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF |
41783 + fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))
41784 + break;
41785 + pAd->NextRxBulkInPosition = pAd->RxContext[pAd->NextRxBulkInIndex].BulkInOffset;
41786 + DBGPRINT(RT_DEBUG_TRACE, ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n",
41787 + pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pAd->NextRxBulkInPosition, pAd->BulkInReq, pAd->BulkInComplete, pAd->BulkInCompleteFail));
41788 + for (i = 0; i < RX_RING_SIZE; i++)
41789 + {
41790 + DBGPRINT(RT_DEBUG_TRACE, ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n"
41791 + , i, pAd->RxContext[i].IRPPending, pAd->RxContext[i].InUse, pAd->RxContext[i].Readable));
41792 + }
41793 + /*
41794 +
41795 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n"));
41796 +
41797 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
41798 + pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
41799 + for (i = 0; i < (RX_RING_SIZE); i++)
41800 + {
41801 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
41802 +
41803 + pRxContext->pAd = pAd;
41804 + pRxContext->InUse = FALSE;
41805 + pRxContext->IRPPending = FALSE;
41806 + pRxContext->Readable = FALSE;
41807 + pRxContext->ReorderInUse = FALSE;
41808 +
41809 + }*/
41810 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
41811 + for (i = 0; i < pAd->CommonCfg.NumOfBulkInIRP; i++)
41812 + {
41813 + //RTUSBBulkReceive(pAd);
41814 + PRX_CONTEXT pRxContext;
41815 + PURB pUrb;
41816 + int ret = 0;
41817 + unsigned long IrqFlags;
41818 +
41819 +
41820 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
41821 + pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
41822 + if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE))
41823 + {
41824 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41825 + break;
41826 + }
41827 + pRxContext->InUse = TRUE;
41828 + pRxContext->IRPPending = TRUE;
41829 + pAd->PendingRx++;
41830 + pAd->BulkInReq++;
41831 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41832 +
41833 + // Init Rx context descriptor
41834 + RTUSBInitRxDesc(pAd, pRxContext);
41835 + pUrb = pRxContext->pUrb;
41836 + if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
41837 + { // fail
41838 +
41839 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
41840 + pRxContext->InUse = FALSE;
41841 + pRxContext->IRPPending = FALSE;
41842 + pAd->PendingRx--;
41843 + pAd->BulkInReq--;
41844 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
41845 + DBGPRINT(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", ret, pUrb->status));
41846 + }
41847 + else
41848 + { // success
41849 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", pUrb->status));
41850 + ASSERT((pRxContext->InUse == pRxContext->IRPPending));
41851 + }
41852 + }
41853 +
41854 + }
41855 + else
41856 + {
41857 + // Card must be removed
41858 + if (NT_SUCCESS(ntStatus) != TRUE)
41859 + {
41860 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
41861 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n"));
41862 + }
41863 + else
41864 + {
41865 + DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", pAd->Flags));
41866 + }
41867 + }
41868 + }
41869 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n"));
41870 + break;
41871 +
41872 + case CMDTHREAD_SET_ASIC_WCID:
41873 + {
41874 + RT_SET_ASIC_WCID SetAsicWcid;
41875 + USHORT offset;
41876 + UINT32 MACValue, MACRValue = 0;
41877 + SetAsicWcid = *((PRT_SET_ASIC_WCID)(pData));
41878 +
41879 + if (SetAsicWcid.WCID >= MAX_LEN_OF_MAC_TABLE)
41880 + return;
41881 +
41882 + offset = MAC_WCID_BASE + ((UCHAR)SetAsicWcid.WCID)*HW_WCID_ENTRY_SIZE;
41883 +
41884 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", SetAsicWcid.WCID, SetAsicWcid.SetTid, SetAsicWcid.DeleteTid));
41885 + MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[3]<<24)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[2]<<16)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[1]<<8)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[0]);
41886 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("1-MACValue= %x,\n", MACValue));
41887 + RTUSBWriteMACRegister(pAd, offset, MACValue);
41888 + // Read bitmask
41889 + RTUSBReadMACRegister(pAd, offset+4, &MACRValue);
41890 + if ( SetAsicWcid.DeleteTid != 0xffffffff)
41891 + MACRValue &= (~SetAsicWcid.DeleteTid);
41892 + if (SetAsicWcid.SetTid != 0xffffffff)
41893 + MACRValue |= (SetAsicWcid.SetTid);
41894 + MACRValue &= 0xffff0000;
41895 +
41896 + MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[5]<<8)+pAd->MacTab.Content[SetAsicWcid.WCID].Addr[4];
41897 + MACValue |= MACRValue;
41898 + RTUSBWriteMACRegister(pAd, offset+4, MACValue);
41899 +
41900 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-MACValue= %x,\n", MACValue));
41901 + }
41902 + break;
41903 +
41904 + case CMDTHREAD_SET_ASIC_WCID_CIPHER:
41905 + {
41906 +#ifdef CONFIG_STA_SUPPORT
41907 + RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri;
41908 + USHORT offset;
41909 + UINT32 MACRValue = 0;
41910 + SHAREDKEY_MODE_STRUC csr1;
41911 + SetAsicWcidAttri = *((PRT_SET_ASIC_WCID_ATTRI)(pData));
41912 +
41913 + if (SetAsicWcidAttri.WCID >= MAX_LEN_OF_MAC_TABLE)
41914 + return;
41915 +
41916 + offset = MAC_WCID_ATTRIBUTE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_WCID_ATTRI_SIZE;
41917 +
41918 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n", SetAsicWcidAttri.WCID, SetAsicWcidAttri.Cipher));
41919 + // Read bitmask
41920 + RTUSBReadMACRegister(pAd, offset, &MACRValue);
41921 + MACRValue = 0;
41922 + MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1);
41923 +
41924 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41925 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue));
41926 +
41927 + offset = PAIRWISE_IVEIV_TABLE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_IVEIV_ENTRY_SIZE;
41928 + MACRValue = 0;
41929 + if ( (SetAsicWcidAttri.Cipher <= CIPHER_WEP128))
41930 + MACRValue |= ( pAd->StaCfg.DefaultKeyId << 30);
41931 + else
41932 + MACRValue |= (0x20000000);
41933 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41934 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue));
41935 +
41936 + //
41937 + // Update cipher algorithm. WSTA always use BSS0
41938 + //
41939 + // for adhoc mode only ,because wep status slow than add key, when use zero config
41940 + if (pAd->StaCfg.BssType == BSS_ADHOC )
41941 + {
41942 + offset = MAC_WCID_ATTRIBUTE_BASE;
41943 +
41944 + RTUSBReadMACRegister(pAd, offset, &MACRValue);
41945 + MACRValue &= (~0xe);
41946 + MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1);
41947 +
41948 + RTUSBWriteMACRegister(pAd, offset, MACRValue);
41949 +
41950 + //Update group key cipher,,because wep status slow than add key, when use zero config
41951 + RTUSBReadMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), &csr1.word);
41952 +
41953 + csr1.field.Bss0Key0CipherAlg = SetAsicWcidAttri.Cipher;
41954 + csr1.field.Bss0Key1CipherAlg = SetAsicWcidAttri.Cipher;
41955 +
41956 + RTUSBWriteMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), csr1.word);
41957 + }
41958 +#endif // CONFIG_STA_SUPPORT //
41959 + }
41960 + break;
41961 +
41962 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 -->
41963 + case RT_CMD_SET_KEY_TABLE: //General call for AsicAddPairwiseKeyEntry()
41964 + {
41965 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
41966 + KeyInfo = *((PRT_ADD_PAIRWISE_KEY_ENTRY)(pData));
41967 + AsicAddPairwiseKeyEntry(pAd,
41968 + KeyInfo.MacAddr,
41969 + (UCHAR)KeyInfo.MacTabMatchWCID,
41970 + &KeyInfo.CipherKey);
41971 + }
41972 + break;
41973 + case RT_CMD_SET_RX_WCID_TABLE: //General call for RTMPAddWcidAttributeEntry()
41974 + {
41975 + PMAC_TABLE_ENTRY pEntry;
41976 + UCHAR KeyIdx;
41977 + UCHAR CipherAlg;
41978 + UCHAR ApIdx;
41979 +
41980 + pEntry = (PMAC_TABLE_ENTRY)(pData);
41981 +
41982 +#ifdef CONFIG_STA_SUPPORT
41983 +#ifdef QOS_DLS_SUPPORT
41984 + KeyIdx = 0;
41985 + CipherAlg = pEntry->PairwiseKey.CipherAlg;
41986 + ApIdx = BSS0;
41987 +#endif // QOS_DLS_SUPPORT //
41988 +#endif // CONFIG_STA_SUPPORT //
41989 +
41990 +
41991 + RTMPAddWcidAttributeEntry(
41992 + pAd,
41993 + ApIdx,
41994 + KeyIdx,
41995 + CipherAlg,
41996 + pEntry);
41997 + }
41998 + break;
41999 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 <--
42000 +
42001 + case CMDTHREAD_SET_CLIENT_MAC_ENTRY:
42002 + {
42003 + MAC_TABLE_ENTRY *pEntry;
42004 + pEntry = (MAC_TABLE_ENTRY *)pData;
42005 +
42006 +
42007 +#ifdef CONFIG_STA_SUPPORT
42008 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
42009 + {
42010 + AsicRemovePairwiseKeyEntry(pAd, pEntry->apidx, (UCHAR)pEntry->Aid);
42011 + if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && (pEntry->WepStatus == Ndis802_11Encryption1Enabled))
42012 + {
42013 + UINT32 uIV = 0;
42014 + PUCHAR ptr;
42015 +
42016 + ptr = (PUCHAR) &uIV;
42017 + *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6);
42018 + AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0);
42019 + AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE);
42020 + }
42021 + else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone)
42022 + {
42023 + UINT32 uIV = 0;
42024 + PUCHAR ptr;
42025 +
42026 + ptr = (PUCHAR) &uIV;
42027 + *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6);
42028 + AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0);
42029 + AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE);
42030 + }
42031 + else
42032 + {
42033 + //
42034 + // Other case, disable engine.
42035 + // Don't worry WPA key, we will add WPA Key after 4-Way handshaking.
42036 + //
42037 + USHORT offset;
42038 + offset = MAC_WCID_ATTRIBUTE_BASE + (pEntry->Aid * HW_WCID_ATTRI_SIZE);
42039 + // RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0
42040 + RTUSBWriteMACRegister(pAd, offset, 0);
42041 + }
42042 + }
42043 +#endif // CONFIG_STA_SUPPORT //
42044 +
42045 + AsicUpdateRxWCIDTable(pAd, pEntry->Aid, pEntry->Addr);
42046 + printk("UpdateRxWCIDTable(): Aid=%d, Addr=%02x:%02x:%02x:%02x:%02x:%02x!\n", pEntry->Aid,
42047 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2], pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
42048 + }
42049 + break;
42050 +
42051 +// add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
42052 + case CMDTHREAD_UPDATE_PROTECT:
42053 + {
42054 + AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT), TRUE, 0);
42055 + }
42056 + break;
42057 +// end johnli
42058 +
42059 + case OID_802_11_ADD_WEP:
42060 + {
42061 +#ifdef CONFIG_STA_SUPPORT
42062 + UINT i;
42063 + UINT32 KeyIdx;
42064 + PNDIS_802_11_WEP pWepKey;
42065 +
42066 + DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP \n"));
42067 +
42068 + pWepKey = (PNDIS_802_11_WEP)pData;
42069 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
42070 +
42071 + // it is a shared key
42072 + if ((KeyIdx >= 4) || ((pWepKey->KeyLength != 5) && (pWepKey->KeyLength != 13)))
42073 + {
42074 + NdisStatus = NDIS_STATUS_INVALID_DATA;
42075 + DBGPRINT(RT_DEBUG_ERROR, ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n"));
42076 + }
42077 + else
42078 + {
42079 + UCHAR CipherAlg;
42080 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
42081 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
42082 + CipherAlg = (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 5)? CIPHER_WEP64 : CIPHER_WEP128;
42083 +
42084 + //
42085 + // Change the WEP cipher to CKIP cipher if CKIP KP on.
42086 + // Funk UI or Meetinghouse UI will add ckip key from this path.
42087 + //
42088 +
42089 + if (pAd->OpMode == OPMODE_STA)
42090 + {
42091 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
42092 + pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = pAd->SharedKey[BSS0][KeyIdx].KeyLen;
42093 + }
42094 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
42095 + if (pWepKey->KeyIndex & 0x80000000)
42096 + {
42097 + // Default key for tx (shared key)
42098 + UCHAR IVEIV[8];
42099 + UINT32 WCIDAttri, Value;
42100 + USHORT offset, offset2;
42101 + NdisZeroMemory(IVEIV, 8);
42102 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
42103 + // Add BSSID to WCTable. because this is Tx wep key.
42104 + // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0
42105 + WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE;
42106 +
42107 + offset = MAC_WCID_ATTRIBUTE_BASE + (BSSID_WCID* HW_WCID_ATTRI_SIZE);
42108 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
42109 + // 1. IV/EIV
42110 + // Specify key index to find shared key.
42111 + IVEIV[3] = (UCHAR)(KeyIdx<< 6); //WEP Eiv bit off. groupkey index is not 0
42112 + offset = PAIRWISE_IVEIV_TABLE_BASE + (BSS0Mcast_WCID * HW_IVEIV_ENTRY_SIZE);
42113 + offset2 = PAIRWISE_IVEIV_TABLE_BASE + (BSSID_WCID* HW_IVEIV_ENTRY_SIZE);
42114 + for (i=0; i<8;)
42115 + {
42116 + Value = IVEIV[i];
42117 + Value += (IVEIV[i+1]<<8);
42118 + Value += (IVEIV[i+2]<<16);
42119 + Value += (IVEIV[i+3]<<24);
42120 + RTUSBWriteMACRegister(pAd, offset+i, Value);
42121 + RTUSBWriteMACRegister(pAd, offset2+i, Value);
42122 + i+=4;
42123 + }
42124 +
42125 + // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0
42126 + WCIDAttri = (pAd->SharedKey[BSS0][KeyIdx].CipherAlg<<1)|SHAREDKEYTABLE;
42127 + offset = MAC_WCID_ATTRIBUTE_BASE + (BSS0Mcast_WCID* HW_WCID_ATTRI_SIZE);
42128 + DBGPRINT(RT_DEBUG_TRACE, ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n", offset, WCIDAttri));
42129 + RTUSBWriteMACRegister(pAd, offset, WCIDAttri);
42130 +
42131 + }
42132 + AsicAddSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx, CipherAlg, pWepKey->KeyMaterial, NULL, NULL);
42133 + DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n", KeyIdx, pWepKey->KeyLength));
42134 + }
42135 +#endif // CONFIG_STA_SUPPORT //
42136 + }
42137 + break;
42138 +
42139 + case CMDTHREAD_802_11_COUNTER_MEASURE:
42140 + break;
42141 +
42142 + default:
42143 + DBGPRINT(RT_DEBUG_ERROR, ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", cmdqelmt->command));
42144 + break;
42145 + }
42146 + }
42147 +
42148 + if (cmdqelmt->CmdFromNdis == TRUE)
42149 + {
42150 + if (cmdqelmt->buffer != NULL)
42151 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
42152 +
42153 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
42154 + }
42155 + else
42156 + {
42157 + if ((cmdqelmt->buffer != NULL) && (cmdqelmt->bufferlength != 0))
42158 + NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0);
42159 + {
42160 + NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0);
42161 + }
42162 + }
42163 + } /* end of while */
42164 +}
42165 +
42166 --- /dev/null
42167 +++ b/drivers/staging/rt3070/common/spectrum.c
42168 @@ -0,0 +1,1876 @@
42169 +/*
42170 + *************************************************************************
42171 + * Ralink Tech Inc.
42172 + * 5F., No.36, Taiyuan St., Jhubei City,
42173 + * Hsinchu County 302,
42174 + * Taiwan, R.O.C.
42175 + *
42176 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
42177 + *
42178 + * This program is free software; you can redistribute it and/or modify *
42179 + * it under the terms of the GNU General Public License as published by *
42180 + * the Free Software Foundation; either version 2 of the License, or *
42181 + * (at your option) any later version. *
42182 + * *
42183 + * This program is distributed in the hope that it will be useful, *
42184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
42185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
42186 + * GNU General Public License for more details. *
42187 + * *
42188 + * You should have received a copy of the GNU General Public License *
42189 + * along with this program; if not, write to the *
42190 + * Free Software Foundation, Inc., *
42191 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
42192 + * *
42193 + *************************************************************************
42194 +
42195 + Module Name:
42196 + action.c
42197 +
42198 + Abstract:
42199 + Handle association related requests either from WSTA or from local MLME
42200 +
42201 + Revision History:
42202 + Who When What
42203 + --------- ---------- ----------------------------------------------
42204 + Fonchi Wu 2008 created for 802.11h
42205 + */
42206 +
42207 +#include "../rt_config.h"
42208 +#include "../action.h"
42209 +
42210 +VOID MeasureReqTabInit(
42211 + IN PRTMP_ADAPTER pAd)
42212 +{
42213 + NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
42214 +
42215 + pAd->CommonCfg.pMeasureReqTab = kmalloc(sizeof(MEASURE_REQ_TAB), GFP_ATOMIC);
42216 + if (pAd->CommonCfg.pMeasureReqTab)
42217 + NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab, sizeof(MEASURE_REQ_TAB));
42218 + else
42219 + DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n", __FUNCTION__));
42220 +
42221 + return;
42222 +}
42223 +
42224 +VOID MeasureReqTabExit(
42225 + IN PRTMP_ADAPTER pAd)
42226 +{
42227 + NdisFreeSpinLock(pAd->CommonCfg.MeasureReqTabLock);
42228 +
42229 + if (pAd->CommonCfg.pMeasureReqTab)
42230 + kfree(pAd->CommonCfg.pMeasureReqTab);
42231 + pAd->CommonCfg.pMeasureReqTab = NULL;
42232 +
42233 + return;
42234 +}
42235 +
42236 +static PMEASURE_REQ_ENTRY MeasureReqLookUp(
42237 + IN PRTMP_ADAPTER pAd,
42238 + IN UINT8 DialogToken)
42239 +{
42240 + UINT HashIdx;
42241 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42242 + PMEASURE_REQ_ENTRY pEntry = NULL;
42243 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42244 +
42245 + if (pTab == NULL)
42246 + {
42247 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42248 + return NULL;
42249 + }
42250 +
42251 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42252 +
42253 + HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
42254 + pEntry = pTab->Hash[HashIdx];
42255 +
42256 + while (pEntry)
42257 + {
42258 + if (pEntry->DialogToken == DialogToken)
42259 + break;
42260 + else
42261 + {
42262 + pPrevEntry = pEntry;
42263 + pEntry = pEntry->pNext;
42264 + }
42265 + }
42266 +
42267 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42268 +
42269 + return pEntry;
42270 +}
42271 +
42272 +static PMEASURE_REQ_ENTRY MeasureReqInsert(
42273 + IN PRTMP_ADAPTER pAd,
42274 + IN UINT8 DialogToken)
42275 +{
42276 + INT i;
42277 + ULONG HashIdx;
42278 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42279 + PMEASURE_REQ_ENTRY pEntry = NULL, pCurrEntry;
42280 + ULONG Now;
42281 +
42282 + if(pTab == NULL)
42283 + {
42284 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42285 + return NULL;
42286 + }
42287 +
42288 + pEntry = MeasureReqLookUp(pAd, DialogToken);
42289 + if (pEntry == NULL)
42290 + {
42291 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42292 + for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++)
42293 + {
42294 + NdisGetSystemUpTime(&Now);
42295 + pEntry = &pTab->Content[i];
42296 +
42297 + if ((pEntry->Valid == TRUE)
42298 + && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + MQ_REQ_AGE_OUT)))
42299 + {
42300 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42301 + ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42302 + PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42303 +
42304 + // update Hash list
42305 + do
42306 + {
42307 + if (pProbeEntry == pEntry)
42308 + {
42309 + if (pPrevEntry == NULL)
42310 + {
42311 + pTab->Hash[HashIdx] = pEntry->pNext;
42312 + }
42313 + else
42314 + {
42315 + pPrevEntry->pNext = pEntry->pNext;
42316 + }
42317 + break;
42318 + }
42319 +
42320 + pPrevEntry = pProbeEntry;
42321 + pProbeEntry = pProbeEntry->pNext;
42322 + } while (pProbeEntry);
42323 +
42324 + NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
42325 + pTab->Size--;
42326 +
42327 + break;
42328 + }
42329 +
42330 + if (pEntry->Valid == FALSE)
42331 + break;
42332 + }
42333 +
42334 + if (i < MAX_MEASURE_REQ_TAB_SIZE)
42335 + {
42336 + NdisGetSystemUpTime(&Now);
42337 + pEntry->lastTime = Now;
42338 + pEntry->Valid = TRUE;
42339 + pEntry->DialogToken = DialogToken;
42340 + pTab->Size++;
42341 + }
42342 + else
42343 + {
42344 + pEntry = NULL;
42345 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab tab full.\n", __FUNCTION__));
42346 + }
42347 +
42348 + // add this Neighbor entry into HASH table
42349 + if (pEntry)
42350 + {
42351 + HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
42352 + if (pTab->Hash[HashIdx] == NULL)
42353 + {
42354 + pTab->Hash[HashIdx] = pEntry;
42355 + }
42356 + else
42357 + {
42358 + pCurrEntry = pTab->Hash[HashIdx];
42359 + while (pCurrEntry->pNext != NULL)
42360 + pCurrEntry = pCurrEntry->pNext;
42361 + pCurrEntry->pNext = pEntry;
42362 + }
42363 + }
42364 +
42365 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42366 + }
42367 +
42368 + return pEntry;
42369 +}
42370 +
42371 +static VOID MeasureReqDelete(
42372 + IN PRTMP_ADAPTER pAd,
42373 + IN UINT8 DialogToken)
42374 +{
42375 + PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
42376 + PMEASURE_REQ_ENTRY pEntry = NULL;
42377 +
42378 + if(pTab == NULL)
42379 + {
42380 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __FUNCTION__));
42381 + return;
42382 + }
42383 +
42384 + // if empty, return
42385 + if (pTab->Size == 0)
42386 + {
42387 + DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n"));
42388 + return;
42389 + }
42390 +
42391 + pEntry = MeasureReqLookUp(pAd, DialogToken);
42392 + if (pEntry != NULL)
42393 + {
42394 + PMEASURE_REQ_ENTRY pPrevEntry = NULL;
42395 + ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42396 + PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42397 +
42398 + RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
42399 + // update Hash list
42400 + do
42401 + {
42402 + if (pProbeEntry == pEntry)
42403 + {
42404 + if (pPrevEntry == NULL)
42405 + {
42406 + pTab->Hash[HashIdx] = pEntry->pNext;
42407 + }
42408 + else
42409 + {
42410 + pPrevEntry->pNext = pEntry->pNext;
42411 + }
42412 + break;
42413 + }
42414 +
42415 + pPrevEntry = pProbeEntry;
42416 + pProbeEntry = pProbeEntry->pNext;
42417 + } while (pProbeEntry);
42418 +
42419 + NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
42420 + pTab->Size--;
42421 +
42422 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
42423 + }
42424 +
42425 + return;
42426 +}
42427 +
42428 +VOID TpcReqTabInit(
42429 + IN PRTMP_ADAPTER pAd)
42430 +{
42431 + NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock);
42432 +
42433 + pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(TPC_REQ_TAB), GFP_ATOMIC);
42434 + if (pAd->CommonCfg.pTpcReqTab)
42435 + NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(TPC_REQ_TAB));
42436 + else
42437 + DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n", __FUNCTION__));
42438 +
42439 + return;
42440 +}
42441 +
42442 +VOID TpcReqTabExit(
42443 + IN PRTMP_ADAPTER pAd)
42444 +{
42445 + NdisFreeSpinLock(pAd->CommonCfg.TpcReqTabLock);
42446 +
42447 + if (pAd->CommonCfg.pTpcReqTab)
42448 + kfree(pAd->CommonCfg.pTpcReqTab);
42449 + pAd->CommonCfg.pTpcReqTab = NULL;
42450 +
42451 + return;
42452 +}
42453 +
42454 +static PTPC_REQ_ENTRY TpcReqLookUp(
42455 + IN PRTMP_ADAPTER pAd,
42456 + IN UINT8 DialogToken)
42457 +{
42458 + UINT HashIdx;
42459 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42460 + PTPC_REQ_ENTRY pEntry = NULL;
42461 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42462 +
42463 + if (pTab == NULL)
42464 + {
42465 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42466 + return NULL;
42467 + }
42468 +
42469 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42470 +
42471 + HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
42472 + pEntry = pTab->Hash[HashIdx];
42473 +
42474 + while (pEntry)
42475 + {
42476 + if (pEntry->DialogToken == DialogToken)
42477 + break;
42478 + else
42479 + {
42480 + pPrevEntry = pEntry;
42481 + pEntry = pEntry->pNext;
42482 + }
42483 + }
42484 +
42485 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42486 +
42487 + return pEntry;
42488 +}
42489 +
42490 +
42491 +static PTPC_REQ_ENTRY TpcReqInsert(
42492 + IN PRTMP_ADAPTER pAd,
42493 + IN UINT8 DialogToken)
42494 +{
42495 + INT i;
42496 + ULONG HashIdx;
42497 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42498 + PTPC_REQ_ENTRY pEntry = NULL, pCurrEntry;
42499 + ULONG Now;
42500 +
42501 + if(pTab == NULL)
42502 + {
42503 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42504 + return NULL;
42505 + }
42506 +
42507 + pEntry = TpcReqLookUp(pAd, DialogToken);
42508 + if (pEntry == NULL)
42509 + {
42510 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42511 + for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++)
42512 + {
42513 + NdisGetSystemUpTime(&Now);
42514 + pEntry = &pTab->Content[i];
42515 +
42516 + if ((pEntry->Valid == TRUE)
42517 + && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + TPC_REQ_AGE_OUT)))
42518 + {
42519 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42520 + ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42521 + PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42522 +
42523 + // update Hash list
42524 + do
42525 + {
42526 + if (pProbeEntry == pEntry)
42527 + {
42528 + if (pPrevEntry == NULL)
42529 + {
42530 + pTab->Hash[HashIdx] = pEntry->pNext;
42531 + }
42532 + else
42533 + {
42534 + pPrevEntry->pNext = pEntry->pNext;
42535 + }
42536 + break;
42537 + }
42538 +
42539 + pPrevEntry = pProbeEntry;
42540 + pProbeEntry = pProbeEntry->pNext;
42541 + } while (pProbeEntry);
42542 +
42543 + NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
42544 + pTab->Size--;
42545 +
42546 + break;
42547 + }
42548 +
42549 + if (pEntry->Valid == FALSE)
42550 + break;
42551 + }
42552 +
42553 + if (i < MAX_TPC_REQ_TAB_SIZE)
42554 + {
42555 + NdisGetSystemUpTime(&Now);
42556 + pEntry->lastTime = Now;
42557 + pEntry->Valid = TRUE;
42558 + pEntry->DialogToken = DialogToken;
42559 + pTab->Size++;
42560 + }
42561 + else
42562 + {
42563 + pEntry = NULL;
42564 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab tab full.\n", __FUNCTION__));
42565 + }
42566 +
42567 + // add this Neighbor entry into HASH table
42568 + if (pEntry)
42569 + {
42570 + HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
42571 + if (pTab->Hash[HashIdx] == NULL)
42572 + {
42573 + pTab->Hash[HashIdx] = pEntry;
42574 + }
42575 + else
42576 + {
42577 + pCurrEntry = pTab->Hash[HashIdx];
42578 + while (pCurrEntry->pNext != NULL)
42579 + pCurrEntry = pCurrEntry->pNext;
42580 + pCurrEntry->pNext = pEntry;
42581 + }
42582 + }
42583 +
42584 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42585 + }
42586 +
42587 + return pEntry;
42588 +}
42589 +
42590 +static VOID TpcReqDelete(
42591 + IN PRTMP_ADAPTER pAd,
42592 + IN UINT8 DialogToken)
42593 +{
42594 + PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
42595 + PTPC_REQ_ENTRY pEntry = NULL;
42596 +
42597 + if(pTab == NULL)
42598 + {
42599 + DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __FUNCTION__));
42600 + return;
42601 + }
42602 +
42603 + // if empty, return
42604 + if (pTab->Size == 0)
42605 + {
42606 + DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n"));
42607 + return;
42608 + }
42609 +
42610 + pEntry = TpcReqLookUp(pAd, DialogToken);
42611 + if (pEntry != NULL)
42612 + {
42613 + PTPC_REQ_ENTRY pPrevEntry = NULL;
42614 + ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
42615 + PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
42616 +
42617 + RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
42618 + // update Hash list
42619 + do
42620 + {
42621 + if (pProbeEntry == pEntry)
42622 + {
42623 + if (pPrevEntry == NULL)
42624 + {
42625 + pTab->Hash[HashIdx] = pEntry->pNext;
42626 + }
42627 + else
42628 + {
42629 + pPrevEntry->pNext = pEntry->pNext;
42630 + }
42631 + break;
42632 + }
42633 +
42634 + pPrevEntry = pProbeEntry;
42635 + pProbeEntry = pProbeEntry->pNext;
42636 + } while (pProbeEntry);
42637 +
42638 + NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
42639 + pTab->Size--;
42640 +
42641 + RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
42642 + }
42643 +
42644 + return;
42645 +}
42646 +
42647 +/*
42648 + ==========================================================================
42649 + Description:
42650 + Get Current TimeS tamp.
42651 +
42652 + Parametrs:
42653 +
42654 + Return : Current Time Stamp.
42655 + ==========================================================================
42656 + */
42657 +static UINT64 GetCurrentTimeStamp(
42658 + IN PRTMP_ADAPTER pAd)
42659 +{
42660 + // get current time stamp.
42661 + return 0;
42662 +}
42663 +
42664 +/*
42665 + ==========================================================================
42666 + Description:
42667 + Get Current Transmit Power.
42668 +
42669 + Parametrs:
42670 +
42671 + Return : Current Time Stamp.
42672 + ==========================================================================
42673 + */
42674 +static UINT8 GetCurTxPwr(
42675 + IN PRTMP_ADAPTER pAd,
42676 + IN UINT8 Wcid)
42677 +{
42678 + return 16; /* 16 dBm */
42679 +}
42680 +
42681 +/*
42682 + ==========================================================================
42683 + Description:
42684 + Insert Dialog Token into frame.
42685 +
42686 + Parametrs:
42687 + 1. frame buffer pointer.
42688 + 2. frame length.
42689 + 3. Dialog token.
42690 +
42691 + Return : None.
42692 + ==========================================================================
42693 + */
42694 +static VOID InsertDialogToken(
42695 + IN PRTMP_ADAPTER pAd,
42696 + OUT PUCHAR pFrameBuf,
42697 + OUT PULONG pFrameLen,
42698 + IN UINT8 DialogToken)
42699 +{
42700 + ULONG TempLen;
42701 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42702 + 1, &DialogToken,
42703 + END_OF_ARGS);
42704 +
42705 + *pFrameLen = *pFrameLen + TempLen;
42706 +
42707 + return;
42708 +}
42709 +
42710 +/*
42711 + ==========================================================================
42712 + Description:
42713 + Insert TPC Request IE into frame.
42714 +
42715 + Parametrs:
42716 + 1. frame buffer pointer.
42717 + 2. frame length.
42718 +
42719 + Return : None.
42720 + ==========================================================================
42721 + */
42722 + static VOID InsertTpcReqIE(
42723 + IN PRTMP_ADAPTER pAd,
42724 + OUT PUCHAR pFrameBuf,
42725 + OUT PULONG pFrameLen)
42726 +{
42727 + ULONG TempLen;
42728 + ULONG Len = 0;
42729 + UINT8 ElementID = IE_TPC_REQUEST;
42730 +
42731 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42732 + 1, &ElementID,
42733 + 1, &Len,
42734 + END_OF_ARGS);
42735 +
42736 + *pFrameLen = *pFrameLen + TempLen;
42737 +
42738 + return;
42739 +}
42740 +
42741 +/*
42742 + ==========================================================================
42743 + Description:
42744 + Insert TPC Report IE into frame.
42745 +
42746 + Parametrs:
42747 + 1. frame buffer pointer.
42748 + 2. frame length.
42749 + 3. Transmit Power.
42750 + 4. Link Margin.
42751 +
42752 + Return : None.
42753 + ==========================================================================
42754 + */
42755 + static VOID InsertTpcReportIE(
42756 + IN PRTMP_ADAPTER pAd,
42757 + OUT PUCHAR pFrameBuf,
42758 + OUT PULONG pFrameLen,
42759 + IN UINT8 TxPwr,
42760 + IN UINT8 LinkMargin)
42761 +{
42762 + ULONG TempLen;
42763 + ULONG Len = sizeof(TPC_REPORT_INFO);
42764 + UINT8 ElementID = IE_TPC_REPORT;
42765 + TPC_REPORT_INFO TpcReportIE;
42766 +
42767 + TpcReportIE.TxPwr = TxPwr;
42768 + TpcReportIE.LinkMargin = LinkMargin;
42769 +
42770 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42771 + 1, &ElementID,
42772 + 1, &Len,
42773 + Len, &TpcReportIE,
42774 + END_OF_ARGS);
42775 +
42776 + *pFrameLen = *pFrameLen + TempLen;
42777 +
42778 +
42779 + return;
42780 +}
42781 +
42782 +/*
42783 + ==========================================================================
42784 + Description:
42785 + Insert Channel Switch Announcement IE into frame.
42786 +
42787 + Parametrs:
42788 + 1. frame buffer pointer.
42789 + 2. frame length.
42790 + 3. channel switch announcement mode.
42791 + 4. new selected channel.
42792 + 5. channel switch announcement count.
42793 +
42794 + Return : None.
42795 + ==========================================================================
42796 + */
42797 +static VOID InsertChSwAnnIE(
42798 + IN PRTMP_ADAPTER pAd,
42799 + OUT PUCHAR pFrameBuf,
42800 + OUT PULONG pFrameLen,
42801 + IN UINT8 ChSwMode,
42802 + IN UINT8 NewChannel,
42803 + IN UINT8 ChSwCnt)
42804 +{
42805 + ULONG TempLen;
42806 + ULONG Len = sizeof(CH_SW_ANN_INFO);
42807 + UINT8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT;
42808 + CH_SW_ANN_INFO ChSwAnnIE;
42809 +
42810 + ChSwAnnIE.ChSwMode = ChSwMode;
42811 + ChSwAnnIE.Channel = NewChannel;
42812 + ChSwAnnIE.ChSwCnt = ChSwCnt;
42813 +
42814 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42815 + 1, &ElementID,
42816 + 1, &Len,
42817 + Len, &ChSwAnnIE,
42818 + END_OF_ARGS);
42819 +
42820 + *pFrameLen = *pFrameLen + TempLen;
42821 +
42822 +
42823 + return;
42824 +}
42825 +
42826 +/*
42827 + ==========================================================================
42828 + Description:
42829 + Insert Measure Request IE into frame.
42830 +
42831 + Parametrs:
42832 + 1. frame buffer pointer.
42833 + 2. frame length.
42834 + 3. Measure Token.
42835 + 4. Measure Request Mode.
42836 + 5. Measure Request Type.
42837 + 6. Measure Channel.
42838 + 7. Measure Start time.
42839 + 8. Measure Duration.
42840 +
42841 +
42842 + Return : None.
42843 + ==========================================================================
42844 + */
42845 +static VOID InsertMeasureReqIE(
42846 + IN PRTMP_ADAPTER pAd,
42847 + OUT PUCHAR pFrameBuf,
42848 + OUT PULONG pFrameLen,
42849 + IN PMEASURE_REQ_INFO pMeasureReqIE)
42850 +{
42851 + ULONG TempLen;
42852 + UINT8 Len = sizeof(MEASURE_REQ_INFO);
42853 + UINT8 ElementID = IE_MEASUREMENT_REQUEST;
42854 +
42855 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42856 + 1, &ElementID,
42857 + 1, &Len,
42858 + Len, pMeasureReqIE,
42859 + END_OF_ARGS);
42860 +
42861 + *pFrameLen = *pFrameLen + TempLen;
42862 +
42863 + return;
42864 +}
42865 +
42866 +/*
42867 + ==========================================================================
42868 + Description:
42869 + Insert Measure Report IE into frame.
42870 +
42871 + Parametrs:
42872 + 1. frame buffer pointer.
42873 + 2. frame length.
42874 + 3. Measure Token.
42875 + 4. Measure Request Mode.
42876 + 5. Measure Request Type.
42877 + 6. Length of Report Infomation
42878 + 7. Pointer of Report Infomation Buffer.
42879 +
42880 + Return : None.
42881 + ==========================================================================
42882 + */
42883 +static VOID InsertMeasureReportIE(
42884 + IN PRTMP_ADAPTER pAd,
42885 + OUT PUCHAR pFrameBuf,
42886 + OUT PULONG pFrameLen,
42887 + IN PMEASURE_REPORT_INFO pMeasureReportIE,
42888 + IN UINT8 ReportLnfoLen,
42889 + IN PUINT8 pReportInfo)
42890 +{
42891 + ULONG TempLen;
42892 + ULONG Len;
42893 + UINT8 ElementID = IE_MEASUREMENT_REPORT;
42894 +
42895 + Len = sizeof(MEASURE_REPORT_INFO) + ReportLnfoLen;
42896 +
42897 + MakeOutgoingFrame(pFrameBuf, &TempLen,
42898 + 1, &ElementID,
42899 + 1, &Len,
42900 + Len, pMeasureReportIE,
42901 + END_OF_ARGS);
42902 +
42903 + *pFrameLen = *pFrameLen + TempLen;
42904 +
42905 + if ((ReportLnfoLen > 0) && (pReportInfo != NULL))
42906 + {
42907 + MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen,
42908 + ReportLnfoLen, pReportInfo,
42909 + END_OF_ARGS);
42910 +
42911 + *pFrameLen = *pFrameLen + TempLen;
42912 + }
42913 + return;
42914 +}
42915 +
42916 +/*
42917 + ==========================================================================
42918 + Description:
42919 + Prepare Measurement request action frame and enqueue it into
42920 + management queue waiting for transmition.
42921 +
42922 + Parametrs:
42923 + 1. the destination mac address of the frame.
42924 +
42925 + Return : None.
42926 + ==========================================================================
42927 + */
42928 +VOID EnqueueMeasurementReq(
42929 + IN PRTMP_ADAPTER pAd,
42930 + IN PUCHAR pDA,
42931 + IN UINT8 MeasureToken,
42932 + IN UINT8 MeasureReqMode,
42933 + IN UINT8 MeasureReqType,
42934 + IN UINT8 MeasureCh,
42935 + IN UINT16 MeasureDuration)
42936 +{
42937 + PUCHAR pOutBuffer = NULL;
42938 + NDIS_STATUS NStatus;
42939 + ULONG FrameLen;
42940 + HEADER_802_11 ActHdr;
42941 + MEASURE_REQ_INFO MeasureReqIE;
42942 + UINT8 RmReqDailogToken = RandomByte(pAd);
42943 + UINT64 MeasureStartTime = GetCurrentTimeStamp(pAd);
42944 +
42945 + // build action frame header.
42946 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
42947 + pAd->CurrentAddress);
42948 +
42949 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
42950 + if(NStatus != NDIS_STATUS_SUCCESS)
42951 + {
42952 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
42953 + return;
42954 + }
42955 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
42956 + FrameLen = sizeof(HEADER_802_11);
42957 +
42958 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRQ);
42959 +
42960 + // fill Dialog Token
42961 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, MeasureToken);
42962 +
42963 + // prepare Measurement IE.
42964 + NdisZeroMemory(&MeasureReqIE, sizeof(MEASURE_REQ_INFO));
42965 + MeasureReqIE.Token = RmReqDailogToken;
42966 + MeasureReqIE.ReqMode.word = MeasureReqMode;
42967 + MeasureReqIE.ReqType = MeasureReqType;
42968 + MeasureReqIE.MeasureReq.ChNum = MeasureCh;
42969 + MeasureReqIE.MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
42970 + MeasureReqIE.MeasureReq.MeasureDuration = cpu2le16(MeasureDuration);
42971 + InsertMeasureReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureReqIE);
42972 +
42973 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
42974 + MlmeFreeMemory(pAd, pOutBuffer);
42975 +
42976 + return;
42977 +}
42978 +
42979 +/*
42980 + ==========================================================================
42981 + Description:
42982 + Prepare Measurement report action frame and enqueue it into
42983 + management queue waiting for transmition.
42984 +
42985 + Parametrs:
42986 + 1. the destination mac address of the frame.
42987 +
42988 + Return : None.
42989 + ==========================================================================
42990 + */
42991 +VOID EnqueueMeasurementRep(
42992 + IN PRTMP_ADAPTER pAd,
42993 + IN PUCHAR pDA,
42994 + IN UINT8 DialogToken,
42995 + IN UINT8 MeasureToken,
42996 + IN UINT8 MeasureReqMode,
42997 + IN UINT8 MeasureReqType,
42998 + IN UINT8 ReportInfoLen,
42999 + IN PUINT8 pReportInfo)
43000 +{
43001 + PUCHAR pOutBuffer = NULL;
43002 + NDIS_STATUS NStatus;
43003 + ULONG FrameLen;
43004 + HEADER_802_11 ActHdr;
43005 + MEASURE_REPORT_INFO MeasureRepIE;
43006 +
43007 + // build action frame header.
43008 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
43009 + pAd->CurrentAddress);
43010 +
43011 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
43012 + if(NStatus != NDIS_STATUS_SUCCESS)
43013 + {
43014 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
43015 + return;
43016 + }
43017 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
43018 + FrameLen = sizeof(HEADER_802_11);
43019 +
43020 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRP);
43021 +
43022 + // fill Dialog Token
43023 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
43024 +
43025 + // prepare Measurement IE.
43026 + NdisZeroMemory(&MeasureRepIE, sizeof(MEASURE_REPORT_INFO));
43027 + MeasureRepIE.Token = MeasureToken;
43028 + MeasureRepIE.ReportMode.word = MeasureReqMode;
43029 + MeasureRepIE.ReportType = MeasureReqType;
43030 + InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureRepIE, ReportInfoLen, pReportInfo);
43031 +
43032 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
43033 + MlmeFreeMemory(pAd, pOutBuffer);
43034 +
43035 + return;
43036 +}
43037 +
43038 +/*
43039 + ==========================================================================
43040 + Description:
43041 + Prepare TPC Request action frame and enqueue it into
43042 + management queue waiting for transmition.
43043 +
43044 + Parametrs:
43045 + 1. the destination mac address of the frame.
43046 +
43047 + Return : None.
43048 + ==========================================================================
43049 + */
43050 +VOID EnqueueTPCReq(
43051 + IN PRTMP_ADAPTER pAd,
43052 + IN PUCHAR pDA,
43053 + IN UCHAR DialogToken)
43054 +{
43055 + PUCHAR pOutBuffer = NULL;
43056 + NDIS_STATUS NStatus;
43057 + ULONG FrameLen;
43058 +
43059 + HEADER_802_11 ActHdr;
43060 +
43061 + // build action frame header.
43062 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
43063 + pAd->CurrentAddress);
43064 +
43065 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
43066 + if(NStatus != NDIS_STATUS_SUCCESS)
43067 + {
43068 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
43069 + return;
43070 + }
43071 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
43072 + FrameLen = sizeof(HEADER_802_11);
43073 +
43074 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRQ);
43075 +
43076 + // fill Dialog Token
43077 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
43078 +
43079 + // Insert TPC Request IE.
43080 + InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen);
43081 +
43082 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
43083 + MlmeFreeMemory(pAd, pOutBuffer);
43084 +
43085 + return;
43086 +}
43087 +
43088 +/*
43089 + ==========================================================================
43090 + Description:
43091 + Prepare TPC Report action frame and enqueue it into
43092 + management queue waiting for transmition.
43093 +
43094 + Parametrs:
43095 + 1. the destination mac address of the frame.
43096 +
43097 + Return : None.
43098 + ==========================================================================
43099 + */
43100 +VOID EnqueueTPCRep(
43101 + IN PRTMP_ADAPTER pAd,
43102 + IN PUCHAR pDA,
43103 + IN UINT8 DialogToken,
43104 + IN UINT8 TxPwr,
43105 + IN UINT8 LinkMargin)
43106 +{
43107 + PUCHAR pOutBuffer = NULL;
43108 + NDIS_STATUS NStatus;
43109 + ULONG FrameLen;
43110 +
43111 + HEADER_802_11 ActHdr;
43112 +
43113 + // build action frame header.
43114 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
43115 + pAd->CurrentAddress);
43116 +
43117 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
43118 + if(NStatus != NDIS_STATUS_SUCCESS)
43119 + {
43120 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
43121 + return;
43122 + }
43123 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
43124 + FrameLen = sizeof(HEADER_802_11);
43125 +
43126 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRP);
43127 +
43128 + // fill Dialog Token
43129 + InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
43130 +
43131 + // Insert TPC Request IE.
43132 + InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr, LinkMargin);
43133 +
43134 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
43135 + MlmeFreeMemory(pAd, pOutBuffer);
43136 +
43137 + return;
43138 +}
43139 +
43140 +/*
43141 + ==========================================================================
43142 + Description:
43143 + Prepare Channel Switch Announcement action frame and enqueue it into
43144 + management queue waiting for transmition.
43145 +
43146 + Parametrs:
43147 + 1. the destination mac address of the frame.
43148 + 2. Channel switch announcement mode.
43149 + 2. a New selected channel.
43150 +
43151 + Return : None.
43152 + ==========================================================================
43153 + */
43154 +VOID EnqueueChSwAnn(
43155 + IN PRTMP_ADAPTER pAd,
43156 + IN PUCHAR pDA,
43157 + IN UINT8 ChSwMode,
43158 + IN UINT8 NewCh)
43159 +{
43160 + PUCHAR pOutBuffer = NULL;
43161 + NDIS_STATUS NStatus;
43162 + ULONG FrameLen;
43163 +
43164 + HEADER_802_11 ActHdr;
43165 +
43166 + // build action frame header.
43167 + MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
43168 + pAd->CurrentAddress);
43169 +
43170 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
43171 + if(NStatus != NDIS_STATUS_SUCCESS)
43172 + {
43173 + DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __FUNCTION__));
43174 + return;
43175 + }
43176 + NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
43177 + FrameLen = sizeof(HEADER_802_11);
43178 +
43179 + InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH);
43180 +
43181 + InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode, NewCh, 0);
43182 +
43183 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
43184 + MlmeFreeMemory(pAd, pOutBuffer);
43185 +
43186 + return;
43187 +}
43188 +
43189 +static BOOLEAN DfsRequirementCheck(
43190 + IN PRTMP_ADAPTER pAd,
43191 + IN UINT8 Channel)
43192 +{
43193 + BOOLEAN Result = FALSE;
43194 + INT i;
43195 +
43196 + do
43197 + {
43198 + // check DFS procedure is running.
43199 + // make sure DFS procedure won't start twice.
43200 + if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
43201 + {
43202 + Result = FALSE;
43203 + break;
43204 + }
43205 +
43206 + // check the new channel carried from Channel Switch Announcemnet is valid.
43207 + for (i=0; i<pAd->ChannelListNum; i++)
43208 + {
43209 + if ((Channel == pAd->ChannelList[i].Channel)
43210 + &&(pAd->ChannelList[i].RemainingTimeForUse == 0))
43211 + {
43212 + // found radar signal in the channel. the channel can't use at least for 30 minutes.
43213 + pAd->ChannelList[i].RemainingTimeForUse = 1800;//30 min = 1800 sec
43214 + Result = TRUE;
43215 + break;
43216 + }
43217 + }
43218 + } while(FALSE);
43219 +
43220 + return Result;
43221 +}
43222 +
43223 +VOID NotifyChSwAnnToPeerAPs(
43224 + IN PRTMP_ADAPTER pAd,
43225 + IN PUCHAR pRA,
43226 + IN PUCHAR pTA,
43227 + IN UINT8 ChSwMode,
43228 + IN UINT8 Channel)
43229 +{
43230 +#ifdef WDS_SUPPORT
43231 + if (!((pRA[0] & 0xff) == 0xff)) // is pRA a broadcase address.
43232 + {
43233 + INT i;
43234 + // info neighbor APs that Radar signal found throgh WDS link.
43235 + for (i = 0; i < MAX_WDS_ENTRY; i++)
43236 + {
43237 + if (ValidWdsEntry(pAd, i))
43238 + {
43239 + PUCHAR pDA = pAd->WdsTab.WdsEntry[i].PeerWdsAddr;
43240 +
43241 + // DA equal to SA. have no necessary orignal AP which found Radar signal.
43242 + if (MAC_ADDR_EQUAL(pTA, pDA))
43243 + continue;
43244 +
43245 + // send Channel Switch Action frame to info Neighbro APs.
43246 + EnqueueChSwAnn(pAd, pDA, ChSwMode, Channel);
43247 + }
43248 + }
43249 + }
43250 +#endif // WDS_SUPPORT //
43251 +}
43252 +
43253 +static VOID StartDFSProcedure(
43254 + IN PRTMP_ADAPTER pAd,
43255 + IN UCHAR Channel,
43256 + IN UINT8 ChSwMode)
43257 +{
43258 + // start DFS procedure
43259 + pAd->CommonCfg.Channel = Channel;
43260 +#ifdef DOT11_N_SUPPORT
43261 + N_ChannelCheck(pAd);
43262 +#endif // DOT11_N_SUPPORT //
43263 + pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE;
43264 + pAd->CommonCfg.RadarDetect.CSCount = 0;
43265 +}
43266 +
43267 +/*
43268 + ==========================================================================
43269 + Description:
43270 + Channel Switch Announcement action frame sanity check.
43271 +
43272 + Parametrs:
43273 + 1. MLME message containing the received frame
43274 + 2. message length.
43275 + 3. Channel switch announcement infomation buffer.
43276 +
43277 +
43278 + Return : None.
43279 + ==========================================================================
43280 + */
43281 +
43282 +/*
43283 + Channel Switch Announcement IE.
43284 + +----+-----+-----------+------------+-----------+
43285 + | ID | Len |Ch Sw Mode | New Ch Num | Ch Sw Cnt |
43286 + +----+-----+-----------+------------+-----------+
43287 + 1 1 1 1 1
43288 +*/
43289 +static BOOLEAN PeerChSwAnnSanity(
43290 + IN PRTMP_ADAPTER pAd,
43291 + IN VOID *pMsg,
43292 + IN ULONG MsgLen,
43293 + OUT PCH_SW_ANN_INFO pChSwAnnInfo)
43294 +{
43295 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43296 + PUCHAR pFramePtr = Fr->Octet;
43297 + BOOLEAN result = FALSE;
43298 + PEID_STRUCT eid_ptr;
43299 +
43300 + // skip 802.11 header.
43301 + MsgLen -= sizeof(HEADER_802_11);
43302 +
43303 + // skip category and action code.
43304 + pFramePtr += 2;
43305 + MsgLen -= 2;
43306 +
43307 + if (pChSwAnnInfo == NULL)
43308 + return result;
43309 +
43310 + eid_ptr = (PEID_STRUCT)pFramePtr;
43311 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43312 + {
43313 + switch(eid_ptr->Eid)
43314 + {
43315 + case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
43316 + NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet, 1);
43317 + NdisMoveMemory(&pChSwAnnInfo->Channel, eid_ptr->Octet + 1, 1);
43318 + NdisMoveMemory(&pChSwAnnInfo->ChSwCnt, eid_ptr->Octet + 2, 1);
43319 +
43320 + result = TRUE;
43321 + break;
43322 +
43323 + default:
43324 + break;
43325 + }
43326 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43327 + }
43328 +
43329 + return result;
43330 +}
43331 +
43332 +/*
43333 + ==========================================================================
43334 + Description:
43335 + Measurement request action frame sanity check.
43336 +
43337 + Parametrs:
43338 + 1. MLME message containing the received frame
43339 + 2. message length.
43340 + 3. Measurement request infomation buffer.
43341 +
43342 + Return : None.
43343 + ==========================================================================
43344 + */
43345 +static BOOLEAN PeerMeasureReqSanity(
43346 + IN PRTMP_ADAPTER pAd,
43347 + IN VOID *pMsg,
43348 + IN ULONG MsgLen,
43349 + OUT PUINT8 pDialogToken,
43350 + OUT PMEASURE_REQ_INFO pMeasureReqInfo)
43351 +{
43352 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43353 + PUCHAR pFramePtr = Fr->Octet;
43354 + BOOLEAN result = FALSE;
43355 + PEID_STRUCT eid_ptr;
43356 + PUCHAR ptr;
43357 + UINT64 MeasureStartTime;
43358 + UINT16 MeasureDuration;
43359 +
43360 + // skip 802.11 header.
43361 + MsgLen -= sizeof(HEADER_802_11);
43362 +
43363 + // skip category and action code.
43364 + pFramePtr += 2;
43365 + MsgLen -= 2;
43366 +
43367 + if (pMeasureReqInfo == NULL)
43368 + return result;
43369 +
43370 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43371 + pFramePtr += 1;
43372 + MsgLen -= 1;
43373 +
43374 + eid_ptr = (PEID_STRUCT)pFramePtr;
43375 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43376 + {
43377 + switch(eid_ptr->Eid)
43378 + {
43379 + case IE_MEASUREMENT_REQUEST:
43380 + NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, 1);
43381 + NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, eid_ptr->Octet + 1, 1);
43382 + NdisMoveMemory(&pMeasureReqInfo->ReqType, eid_ptr->Octet + 2, 1);
43383 + ptr = eid_ptr->Octet + 3;
43384 + NdisMoveMemory(&pMeasureReqInfo->MeasureReq.ChNum, ptr, 1);
43385 + NdisMoveMemory(&MeasureStartTime, ptr + 1, 8);
43386 + pMeasureReqInfo->MeasureReq.MeasureStartTime = SWAP64(MeasureStartTime);
43387 + NdisMoveMemory(&MeasureDuration, ptr + 9, 2);
43388 + pMeasureReqInfo->MeasureReq.MeasureDuration = SWAP16(MeasureDuration);
43389 +
43390 + result = TRUE;
43391 + break;
43392 +
43393 + default:
43394 + break;
43395 + }
43396 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43397 + }
43398 +
43399 + return result;
43400 +}
43401 +
43402 +/*
43403 + ==========================================================================
43404 + Description:
43405 + Measurement report action frame sanity check.
43406 +
43407 + Parametrs:
43408 + 1. MLME message containing the received frame
43409 + 2. message length.
43410 + 3. Measurement report infomation buffer.
43411 + 4. basic report infomation buffer.
43412 +
43413 + Return : None.
43414 + ==========================================================================
43415 + */
43416 +
43417 +/*
43418 + Measurement Report IE.
43419 + +----+-----+-------+-------------+--------------+----------------+
43420 + | ID | Len | Token | Report Mode | Measure Type | Measure Report |
43421 + +----+-----+-------+-------------+--------------+----------------+
43422 + 1 1 1 1 1 variable
43423 +
43424 + Basic Report.
43425 + +--------+------------+----------+-----+
43426 + | Ch Num | Start Time | Duration | Map |
43427 + +--------+------------+----------+-----+
43428 + 1 8 2 1
43429 +
43430 + Map Field Bit Format.
43431 + +-----+---------------+---------------------+-------+------------+----------+
43432 + | Bss | OFDM Preamble | Unidentified signal | Radar | Unmeasured | Reserved |
43433 + +-----+---------------+---------------------+-------+------------+----------+
43434 + 0 1 2 3 4 5-7
43435 +*/
43436 +static BOOLEAN PeerMeasureReportSanity(
43437 + IN PRTMP_ADAPTER pAd,
43438 + IN VOID *pMsg,
43439 + IN ULONG MsgLen,
43440 + OUT PUINT8 pDialogToken,
43441 + OUT PMEASURE_REPORT_INFO pMeasureReportInfo,
43442 + OUT PUINT8 pReportBuf)
43443 +{
43444 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43445 + PUCHAR pFramePtr = Fr->Octet;
43446 + BOOLEAN result = FALSE;
43447 + PEID_STRUCT eid_ptr;
43448 + PUCHAR ptr;
43449 +
43450 + // skip 802.11 header.
43451 + MsgLen -= sizeof(HEADER_802_11);
43452 +
43453 + // skip category and action code.
43454 + pFramePtr += 2;
43455 + MsgLen -= 2;
43456 +
43457 + if (pMeasureReportInfo == NULL)
43458 + return result;
43459 +
43460 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43461 + pFramePtr += 1;
43462 + MsgLen -= 1;
43463 +
43464 + eid_ptr = (PEID_STRUCT)pFramePtr;
43465 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43466 + {
43467 + switch(eid_ptr->Eid)
43468 + {
43469 + case IE_MEASUREMENT_REPORT:
43470 + NdisMoveMemory(&pMeasureReportInfo->Token, eid_ptr->Octet, 1);
43471 + NdisMoveMemory(&pMeasureReportInfo->ReportMode, eid_ptr->Octet + 1, 1);
43472 + NdisMoveMemory(&pMeasureReportInfo->ReportType, eid_ptr->Octet + 2, 1);
43473 + if (pMeasureReportInfo->ReportType == RM_BASIC)
43474 + {
43475 + PMEASURE_BASIC_REPORT pReport = (PMEASURE_BASIC_REPORT)pReportBuf;
43476 + ptr = eid_ptr->Octet + 3;
43477 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43478 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43479 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43480 + NdisMoveMemory(&pReport->Map, ptr + 11, 1);
43481 +
43482 + }
43483 + else if (pMeasureReportInfo->ReportType == RM_CCA)
43484 + {
43485 + PMEASURE_CCA_REPORT pReport = (PMEASURE_CCA_REPORT)pReportBuf;
43486 + ptr = eid_ptr->Octet + 3;
43487 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43488 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43489 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43490 + NdisMoveMemory(&pReport->CCA_Busy_Fraction, ptr + 11, 1);
43491 +
43492 + }
43493 + else if (pMeasureReportInfo->ReportType == RM_RPI_HISTOGRAM)
43494 + {
43495 + PMEASURE_RPI_REPORT pReport = (PMEASURE_RPI_REPORT)pReportBuf;
43496 + ptr = eid_ptr->Octet + 3;
43497 + NdisMoveMemory(&pReport->ChNum, ptr, 1);
43498 + NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
43499 + NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
43500 + NdisMoveMemory(&pReport->RPI_Density, ptr + 11, 8);
43501 + }
43502 + result = TRUE;
43503 + break;
43504 +
43505 + default:
43506 + break;
43507 + }
43508 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43509 + }
43510 +
43511 + return result;
43512 +}
43513 +
43514 +/*
43515 + ==========================================================================
43516 + Description:
43517 + TPC Request action frame sanity check.
43518 +
43519 + Parametrs:
43520 + 1. MLME message containing the received frame
43521 + 2. message length.
43522 + 3. Dialog Token.
43523 +
43524 + Return : None.
43525 + ==========================================================================
43526 + */
43527 +static BOOLEAN PeerTpcReqSanity(
43528 + IN PRTMP_ADAPTER pAd,
43529 + IN VOID *pMsg,
43530 + IN ULONG MsgLen,
43531 + OUT PUINT8 pDialogToken)
43532 +{
43533 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43534 + PUCHAR pFramePtr = Fr->Octet;
43535 + BOOLEAN result = FALSE;
43536 + PEID_STRUCT eid_ptr;
43537 +
43538 + MsgLen -= sizeof(HEADER_802_11);
43539 +
43540 + // skip category and action code.
43541 + pFramePtr += 2;
43542 + MsgLen -= 2;
43543 +
43544 + if (pDialogToken == NULL)
43545 + return result;
43546 +
43547 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43548 + pFramePtr += 1;
43549 + MsgLen -= 1;
43550 +
43551 + eid_ptr = (PEID_STRUCT)pFramePtr;
43552 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43553 + {
43554 + switch(eid_ptr->Eid)
43555 + {
43556 + case IE_TPC_REQUEST:
43557 + result = TRUE;
43558 + break;
43559 +
43560 + default:
43561 + break;
43562 + }
43563 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43564 + }
43565 +
43566 + return result;
43567 +}
43568 +
43569 +/*
43570 + ==========================================================================
43571 + Description:
43572 + TPC Report action frame sanity check.
43573 +
43574 + Parametrs:
43575 + 1. MLME message containing the received frame
43576 + 2. message length.
43577 + 3. Dialog Token.
43578 + 4. TPC Report IE.
43579 +
43580 + Return : None.
43581 + ==========================================================================
43582 + */
43583 +static BOOLEAN PeerTpcRepSanity(
43584 + IN PRTMP_ADAPTER pAd,
43585 + IN VOID *pMsg,
43586 + IN ULONG MsgLen,
43587 + OUT PUINT8 pDialogToken,
43588 + OUT PTPC_REPORT_INFO pTpcRepInfo)
43589 +{
43590 + PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
43591 + PUCHAR pFramePtr = Fr->Octet;
43592 + BOOLEAN result = FALSE;
43593 + PEID_STRUCT eid_ptr;
43594 +
43595 + MsgLen -= sizeof(HEADER_802_11);
43596 +
43597 + // skip category and action code.
43598 + pFramePtr += 2;
43599 + MsgLen -= 2;
43600 +
43601 + if (pDialogToken == NULL)
43602 + return result;
43603 +
43604 + NdisMoveMemory(pDialogToken, pFramePtr, 1);
43605 + pFramePtr += 1;
43606 + MsgLen -= 1;
43607 +
43608 + eid_ptr = (PEID_STRUCT)pFramePtr;
43609 + while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
43610 + {
43611 + switch(eid_ptr->Eid)
43612 + {
43613 + case IE_TPC_REPORT:
43614 + NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1);
43615 + NdisMoveMemory(&pTpcRepInfo->LinkMargin, eid_ptr->Octet + 1, 1);
43616 + result = TRUE;
43617 + break;
43618 +
43619 + default:
43620 + break;
43621 + }
43622 + eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
43623 + }
43624 +
43625 + return result;
43626 +}
43627 +
43628 +/*
43629 + ==========================================================================
43630 + Description:
43631 + Channel Switch Announcement action frame handler.
43632 +
43633 + Parametrs:
43634 + Elme - MLME message containing the received frame
43635 +
43636 + Return : None.
43637 + ==========================================================================
43638 + */
43639 +static VOID PeerChSwAnnAction(
43640 + IN PRTMP_ADAPTER pAd,
43641 + IN MLME_QUEUE_ELEM *Elem)
43642 +{
43643 + CH_SW_ANN_INFO ChSwAnnInfo;
43644 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43645 +#ifdef CONFIG_STA_SUPPORT
43646 + UCHAR index = 0, Channel = 0, NewChannel = 0;
43647 + ULONG Bssidx = 0;
43648 +#endif // CONFIG_STA_SUPPORT //
43649 +
43650 + NdisZeroMemory(&ChSwAnnInfo, sizeof(CH_SW_ANN_INFO));
43651 + if (! PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo))
43652 + {
43653 + DBGPRINT(RT_DEBUG_TRACE, ("Invalid Channel Switch Action Frame.\n"));
43654 + return;
43655 + }
43656 +
43657 +
43658 +#ifdef CONFIG_STA_SUPPORT
43659 + if (pAd->OpMode == OPMODE_STA)
43660 + {
43661 + Bssidx = BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3, pAd->CommonCfg.Channel);
43662 + if (Bssidx == BSS_NOT_FOUND)
43663 + {
43664 + DBGPRINT(RT_DEBUG_TRACE, ("PeerChSwAnnAction - Bssidx is not found\n"));
43665 + return;
43666 + }
43667 +
43668 + DBGPRINT(RT_DEBUG_TRACE, ("\n****Bssidx is %d, Channel = %d\n", index, pAd->ScanTab.BssEntry[Bssidx].Channel));
43669 + hex_dump("SSID",pAd->ScanTab.BssEntry[Bssidx].Bssid ,6);
43670 +
43671 + Channel = pAd->CommonCfg.Channel;
43672 + NewChannel = ChSwAnnInfo.Channel;
43673 +
43674 + if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
43675 + {
43676 + // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
43677 + // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
43678 + AsicSwitchChannel(pAd, 1, FALSE);
43679 + AsicLockChannel(pAd, 1);
43680 + LinkDown(pAd, FALSE);
43681 + MlmeQueueInit(&pAd->Mlme.Queue);
43682 + BssTableInit(&pAd->ScanTab);
43683 + RTMPusecDelay(1000000); // use delay to prevent STA do reassoc
43684 +
43685 + // channel sanity check
43686 + for (index = 0 ; index < pAd->ChannelListNum; index++)
43687 + {
43688 + if (pAd->ChannelList[index].Channel == NewChannel)
43689 + {
43690 + pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
43691 + pAd->CommonCfg.Channel = NewChannel;
43692 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
43693 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
43694 + DBGPRINT(RT_DEBUG_TRACE, ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
43695 + break;
43696 + }
43697 + }
43698 +
43699 + if (index >= pAd->ChannelListNum)
43700 + {
43701 + DBGPRINT_ERR(("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
43702 + }
43703 + }
43704 + }
43705 +#endif // CONFIG_STA_SUPPORT //
43706 +
43707 + return;
43708 +}
43709 +
43710 +
43711 +/*
43712 + ==========================================================================
43713 + Description:
43714 + Measurement Request action frame handler.
43715 +
43716 + Parametrs:
43717 + Elme - MLME message containing the received frame
43718 +
43719 + Return : None.
43720 + ==========================================================================
43721 + */
43722 +static VOID PeerMeasureReqAction(
43723 + IN PRTMP_ADAPTER pAd,
43724 + IN MLME_QUEUE_ELEM *Elem)
43725 +{
43726 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43727 + UINT8 DialogToken;
43728 + MEASURE_REQ_INFO MeasureReqInfo;
43729 + MEASURE_REPORT_MODE ReportMode;
43730 +
43731 + if(PeerMeasureReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo))
43732 + {
43733 + ReportMode.word = 0;
43734 + ReportMode.field.Incapable = 1;
43735 + EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken, MeasureReqInfo.Token, ReportMode.word, MeasureReqInfo.ReqType, 0, NULL);
43736 + }
43737 +
43738 + return;
43739 +}
43740 +
43741 +/*
43742 + ==========================================================================
43743 + Description:
43744 + Measurement Report action frame handler.
43745 +
43746 + Parametrs:
43747 + Elme - MLME message containing the received frame
43748 +
43749 + Return : None.
43750 + ==========================================================================
43751 + */
43752 +static VOID PeerMeasureReportAction(
43753 + IN PRTMP_ADAPTER pAd,
43754 + IN MLME_QUEUE_ELEM *Elem)
43755 +{
43756 + MEASURE_REPORT_INFO MeasureReportInfo;
43757 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43758 + UINT8 DialogToken;
43759 + PUINT8 pMeasureReportInfo;
43760 +
43761 +// if (pAd->CommonCfg.bIEEE80211H != TRUE)
43762 +// return;
43763 +
43764 + if ((pMeasureReportInfo = kmalloc(sizeof(MEASURE_RPI_REPORT), GFP_ATOMIC)) == NULL)
43765 + {
43766 + DBGPRINT(RT_DEBUG_ERROR, ("%s unable to alloc memory for measure report buffer (size=%d).\n", __FUNCTION__, sizeof(MEASURE_RPI_REPORT)));
43767 + return;
43768 + }
43769 +
43770 + NdisZeroMemory(&MeasureReportInfo, sizeof(MEASURE_REPORT_INFO));
43771 + NdisZeroMemory(pMeasureReportInfo, sizeof(MEASURE_RPI_REPORT));
43772 + if (PeerMeasureReportSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo, pMeasureReportInfo))
43773 + {
43774 + do {
43775 + PMEASURE_REQ_ENTRY pEntry = NULL;
43776 +
43777 + // Not a autonomous measure report.
43778 + // check the dialog token field. drop it if the dialog token doesn't match.
43779 + if ((DialogToken != 0)
43780 + && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) == NULL))
43781 + break;
43782 +
43783 + if (pEntry != NULL)
43784 + MeasureReqDelete(pAd, pEntry->DialogToken);
43785 +
43786 + if (MeasureReportInfo.ReportType == RM_BASIC)
43787 + {
43788 + PMEASURE_BASIC_REPORT pBasicReport = (PMEASURE_BASIC_REPORT)pMeasureReportInfo;
43789 + if ((pBasicReport->Map.field.Radar)
43790 + && (DfsRequirementCheck(pAd, pBasicReport->ChNum) == TRUE))
43791 + {
43792 + NotifyChSwAnnToPeerAPs(pAd, pFr->Hdr.Addr1, pFr->Hdr.Addr2, 1, pBasicReport->ChNum);
43793 + StartDFSProcedure(pAd, pBasicReport->ChNum, 1);
43794 + }
43795 + }
43796 + } while (FALSE);
43797 + }
43798 + else
43799 + DBGPRINT(RT_DEBUG_TRACE, ("Invalid Measurement Report Frame.\n"));
43800 +
43801 + kfree(pMeasureReportInfo);
43802 +
43803 + return;
43804 +}
43805 +
43806 +/*
43807 + ==========================================================================
43808 + Description:
43809 + TPC Request action frame handler.
43810 +
43811 + Parametrs:
43812 + Elme - MLME message containing the received frame
43813 +
43814 + Return : None.
43815 + ==========================================================================
43816 + */
43817 +static VOID PeerTpcReqAction(
43818 + IN PRTMP_ADAPTER pAd,
43819 + IN MLME_QUEUE_ELEM *Elem)
43820 +{
43821 + PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
43822 + PUCHAR pFramePtr = pFr->Octet;
43823 + UINT8 DialogToken;
43824 + UINT8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid);
43825 + UINT8 LinkMargin = 0;
43826 + CHAR RealRssi;
43827 +
43828 + // link margin: Ratio of the received signal power to the minimum desired by the station (STA). The
43829 + // STA may incorporate rate information and channel conditions, including interference, into its computation
43830 + // of link margin.
43831 +
43832 + RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
43833 + ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
43834 + ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
43835 +
43836 + // skip Category and action code.
43837 + pFramePtr += 2;
43838 +
43839 + // Dialog token.
43840 + NdisMoveMemory(&DialogToken, pFramePtr, 1);
43841 +
43842 + LinkMargin = (RealRssi / MIN_RCV_PWR);
43843 + if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken))
43844 + EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr, LinkMargin);
43845 +
43846 + return;
43847 +}
43848 +
43849 +/*
43850 + ==========================================================================
43851 + Description:
43852 + TPC Report action frame handler.
43853 +
43854 + Parametrs:
43855 + Elme - MLME message containing the received frame
43856 +
43857 + Return : None.
43858 + ==========================================================================
43859 + */
43860 +static VOID PeerTpcRepAction(
43861 + IN PRTMP_ADAPTER pAd,
43862 + IN MLME_QUEUE_ELEM *Elem)
43863 +{
43864 + UINT8 DialogToken;
43865 + TPC_REPORT_INFO TpcRepInfo;
43866 + PTPC_REQ_ENTRY pEntry = NULL;
43867 +
43868 + NdisZeroMemory(&TpcRepInfo, sizeof(TPC_REPORT_INFO));
43869 + if (PeerTpcRepSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo))
43870 + {
43871 + if ((pEntry = TpcReqLookUp(pAd, DialogToken)) != NULL)
43872 + {
43873 + TpcReqDelete(pAd, pEntry->DialogToken);
43874 + DBGPRINT(RT_DEBUG_TRACE, ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n",
43875 + __FUNCTION__, DialogToken, TpcRepInfo.TxPwr, TpcRepInfo.LinkMargin));
43876 + }
43877 + }
43878 +
43879 + return;
43880 +}
43881 +
43882 +/*
43883 + ==========================================================================
43884 + Description:
43885 + Spectrun action frames Handler such as channel switch annoucement,
43886 + measurement report, measurement request actions frames.
43887 +
43888 + Parametrs:
43889 + Elme - MLME message containing the received frame
43890 +
43891 + Return : None.
43892 + ==========================================================================
43893 + */
43894 +VOID PeerSpectrumAction(
43895 + IN PRTMP_ADAPTER pAd,
43896 + IN MLME_QUEUE_ELEM *Elem)
43897 +{
43898 +
43899 + UCHAR Action = Elem->Msg[LENGTH_802_11+1];
43900 +
43901 + if (pAd->CommonCfg.bIEEE80211H != TRUE)
43902 + return;
43903 +
43904 + switch(Action)
43905 + {
43906 + case SPEC_MRQ:
43907 + // current rt2860 unable do such measure specified in Measurement Request.
43908 + // reject all measurement request.
43909 + PeerMeasureReqAction(pAd, Elem);
43910 + break;
43911 +
43912 + case SPEC_MRP:
43913 + PeerMeasureReportAction(pAd, Elem);
43914 + break;
43915 +
43916 + case SPEC_TPCRQ:
43917 + PeerTpcReqAction(pAd, Elem);
43918 + break;
43919 +
43920 + case SPEC_TPCRP:
43921 + PeerTpcRepAction(pAd, Elem);
43922 + break;
43923 +
43924 + case SPEC_CHANNEL_SWITCH:
43925 +{
43926 +#ifdef DOT11N_DRAFT3
43927 + SEC_CHA_OFFSET_IE Secondary;
43928 + CHA_SWITCH_ANNOUNCE_IE ChannelSwitch;
43929 +
43930 + // 802.11h only has Channel Switch Announcement IE.
43931 + RTMPMoveMemory(&ChannelSwitch, &Elem->Msg[LENGTH_802_11+4], sizeof (CHA_SWITCH_ANNOUNCE_IE));
43932 +
43933 + // 802.11n D3.03 adds secondary channel offset element in the end.
43934 + if (Elem->MsgLen == (LENGTH_802_11 + 2 + sizeof (CHA_SWITCH_ANNOUNCE_IE) + sizeof (SEC_CHA_OFFSET_IE)))
43935 + {
43936 + RTMPMoveMemory(&Secondary, &Elem->Msg[LENGTH_802_11+9], sizeof (SEC_CHA_OFFSET_IE));
43937 + }
43938 + else
43939 + {
43940 + Secondary.SecondaryChannelOffset = 0;
43941 + }
43942 +
43943 + if ((Elem->Msg[LENGTH_802_11+2] == IE_CHANNEL_SWITCH_ANNOUNCEMENT) && (Elem->Msg[LENGTH_802_11+3] == 3))
43944 + {
43945 + ChannelSwitchAction(pAd, Elem->Wcid, ChannelSwitch.NewChannel, Secondary.SecondaryChannelOffset);
43946 + }
43947 +#endif // DOT11N_DRAFT3 //
43948 +}
43949 + PeerChSwAnnAction(pAd, Elem);
43950 + break;
43951 + }
43952 +
43953 + return;
43954 +}
43955 +
43956 +/*
43957 + ==========================================================================
43958 + Description:
43959 +
43960 + Parametrs:
43961 +
43962 + Return : None.
43963 + ==========================================================================
43964 + */
43965 +INT Set_MeasureReq_Proc(
43966 + IN PRTMP_ADAPTER pAd,
43967 + IN PUCHAR arg)
43968 +{
43969 + UINT Aid = 1;
43970 + UINT ArgIdx;
43971 + PUCHAR thisChar;
43972 +
43973 + MEASURE_REQ_MODE MeasureReqMode;
43974 + UINT8 MeasureReqToken = RandomByte(pAd);
43975 + UINT8 MeasureReqType = RM_BASIC;
43976 + UINT8 MeasureCh = 1;
43977 +
43978 + ArgIdx = 1;
43979 + while ((thisChar = strsep((char **)&arg, "-")) != NULL)
43980 + {
43981 + switch(ArgIdx)
43982 + {
43983 + case 1: // Aid.
43984 + Aid = simple_strtol(thisChar, 0, 16);
43985 + break;
43986 +
43987 + case 2: // Measurement Request Type.
43988 + MeasureReqType = simple_strtol(thisChar, 0, 16);
43989 + if (MeasureReqType > 3)
43990 + {
43991 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow MeasureReqType(%d)\n", __FUNCTION__, MeasureReqType));
43992 + return TRUE;
43993 + }
43994 + break;
43995 +
43996 + case 3: // Measurement channel.
43997 + MeasureCh = simple_strtol(thisChar, 0, 16);
43998 + break;
43999 + }
44000 + ArgIdx++;
44001 + }
44002 +
44003 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __FUNCTION__, Aid, MeasureReqType, MeasureCh));
44004 + if (!VALID_WCID(Aid))
44005 + {
44006 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __FUNCTION__, Aid));
44007 + return TRUE;
44008 + }
44009 +
44010 + MeasureReqMode.word = 0;
44011 + MeasureReqMode.field.Enable = 1;
44012 +
44013 + MeasureReqInsert(pAd, MeasureReqToken);
44014 +
44015 + EnqueueMeasurementReq(pAd, pAd->MacTab.Content[Aid].Addr,
44016 + MeasureReqToken, MeasureReqMode.word, MeasureReqType, MeasureCh, 2000);
44017 +
44018 + return TRUE;
44019 +}
44020 +
44021 +INT Set_TpcReq_Proc(
44022 + IN PRTMP_ADAPTER pAd,
44023 + IN PUCHAR arg)
44024 +{
44025 + UINT Aid;
44026 +
44027 + UINT8 TpcReqToken = RandomByte(pAd);
44028 +
44029 + Aid = simple_strtol(arg, 0, 16);
44030 +
44031 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __FUNCTION__, Aid));
44032 + if (!VALID_WCID(Aid))
44033 + {
44034 + DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __FUNCTION__, Aid));
44035 + return TRUE;
44036 + }
44037 +
44038 + TpcReqInsert(pAd, TpcReqToken);
44039 +
44040 + EnqueueTPCReq(pAd, pAd->MacTab.Content[Aid].Addr, TpcReqToken);
44041 +
44042 + return TRUE;
44043 +}
44044 +
44045 --- /dev/null
44046 +++ b/drivers/staging/rt3070/dfs.h
44047 @@ -0,0 +1,100 @@
44048 +/*
44049 + *************************************************************************
44050 + * Ralink Tech Inc.
44051 + * 5F., No.36, Taiyuan St., Jhubei City,
44052 + * Hsinchu County 302,
44053 + * Taiwan, R.O.C.
44054 + *
44055 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44056 + *
44057 + * This program is free software; you can redistribute it and/or modify *
44058 + * it under the terms of the GNU General Public License as published by *
44059 + * the Free Software Foundation; either version 2 of the License, or *
44060 + * (at your option) any later version. *
44061 + * *
44062 + * This program is distributed in the hope that it will be useful, *
44063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44065 + * GNU General Public License for more details. *
44066 + * *
44067 + * You should have received a copy of the GNU General Public License *
44068 + * along with this program; if not, write to the *
44069 + * Free Software Foundation, Inc., *
44070 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44071 + * *
44072 + *************************************************************************
44073 +
44074 + Module Name:
44075 + dfs.h
44076 +
44077 + Abstract:
44078 + Support DFS function.
44079 +
44080 + Revision History:
44081 + Who When What
44082 + -------- ---------- ----------------------------------------------
44083 + Fonchi 03-12-2007 created
44084 +*/
44085 +
44086 +#define RADAR_PULSE 1
44087 +#define RADAR_WIDTH 2
44088 +
44089 +#define WIDTH_RD_IDLE 0
44090 +#define WIDTH_RD_CHECK 1
44091 +
44092 +
44093 +VOID BbpRadarDetectionStart(
44094 + IN PRTMP_ADAPTER pAd);
44095 +
44096 +VOID BbpRadarDetectionStop(
44097 + IN PRTMP_ADAPTER pAd);
44098 +
44099 +VOID RadarDetectionStart(
44100 + IN PRTMP_ADAPTER pAd,
44101 + IN BOOLEAN CTS_Protect,
44102 + IN UINT8 CTSPeriod);
44103 +
44104 +VOID RadarDetectionStop(
44105 + IN PRTMP_ADAPTER pAd);
44106 +
44107 +VOID RadarDetectPeriodic(
44108 + IN PRTMP_ADAPTER pAd);
44109 +
44110 +
44111 +BOOLEAN RadarChannelCheck(
44112 + IN PRTMP_ADAPTER pAd,
44113 + IN UCHAR Ch);
44114 +
44115 +ULONG JapRadarType(
44116 + IN PRTMP_ADAPTER pAd);
44117 +
44118 +ULONG RTMPBbpReadRadarDuration(
44119 + IN PRTMP_ADAPTER pAd);
44120 +
44121 +ULONG RTMPReadRadarDuration(
44122 + IN PRTMP_ADAPTER pAd);
44123 +
44124 +VOID RTMPCleanRadarDuration(
44125 + IN PRTMP_ADAPTER pAd);
44126 +
44127 +VOID RTMPPrepareRDCTSFrame(
44128 + IN PRTMP_ADAPTER pAd,
44129 + IN PUCHAR pDA,
44130 + IN ULONG Duration,
44131 + IN UCHAR RTSRate,
44132 + IN ULONG CTSBaseAddr,
44133 + IN UCHAR FrameGap);
44134 +
44135 +VOID RTMPPrepareRadarDetectParams(
44136 + IN PRTMP_ADAPTER pAd);
44137 +
44138 +
44139 +INT Set_ChMovingTime_Proc(
44140 + IN PRTMP_ADAPTER pAd,
44141 + IN PUCHAR arg);
44142 +
44143 +INT Set_LongPulseRadarTh_Proc(
44144 + IN PRTMP_ADAPTER pAd,
44145 + IN PUCHAR arg);
44146 +
44147 +
44148 --- /dev/null
44149 +++ b/drivers/staging/rt3070/firmware.h
44150 @@ -0,0 +1,558 @@
44151 +/*
44152 + Copyright (c) 2007, Ralink Technology Corporation
44153 + All rights reserved.
44154 +
44155 + Redistribution. Redistribution and use in binary form, without
44156 + modification, are permitted provided that the following conditions are
44157 + met:
44158 +
44159 + * Redistributions must reproduce the above copyright notice and the
44160 + following disclaimer in the documentation and/or other materials
44161 + provided with the distribution.
44162 + * Neither the name of Ralink Technology Corporation nor the names of its
44163 + suppliers may be used to endorse or promote products derived from this
44164 + software without specific prior written permission.
44165 + * No reverse engineering, decompilation, or disassembly of this software
44166 + is permitted.
44167 +
44168 + Limited patent license. Ralink Technology Corporation grants a world-wide,
44169 + royalty-free, non-exclusive license under patents it now or hereafter
44170 + owns or controls to make, have made, use, import, offer to sell and
44171 + sell ("Utilize") this software, but solely to the extent that any
44172 + such patent is necessary to Utilize the software alone, or in
44173 + combination with an operating system licensed under an approved Open
44174 + Source license as listed by the Open Source Initiative at
44175 + http://opensource.org/licenses. The patent license shall not apply to
44176 + any other combinations which include this software. No hardware per
44177 + se is licensed hereunder.
44178 +
44179 + DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
44180 + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
44181 + BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
44182 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
44183 + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
44184 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44185 + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
44186 + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44187 + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44188 + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
44189 + USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
44190 + DAMAGE.
44191 +*/
44192 +/* AUTO GEN PLEASE DO NOT MODIFY IT */
44193 +/* AUTO GEN PLEASE DO NOT MODIFY IT */
44194 +
44195 +
44196 +UCHAR FirmwareImage [] = {
44197 +0xff, 0xff, 0xff, 0x02, 0x10, 0x28, 0x02, 0x10, 0x32, 0x02, 0x10, 0x78, 0x02, 0x12, 0x67, 0x02,
44198 +0x12, 0x68, 0x02, 0x12, 0x87, 0x02, 0x12, 0x8c, 0x12, 0x12, 0x88, 0x22, 0x02, 0x16, 0x49, 0x02,
44199 +0x17, 0x1f, 0x02, 0x13, 0x77, 0x02, 0x12, 0x8d, 0x30, 0x05, 0x06, 0x20, 0x0d, 0x03, 0x12, 0x17,
44200 +0xc1, 0x22, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe3, 0x1b, 0xe5, 0x4c, 0x30, 0xe0, 0x04, 0x7f, 0x40,
44201 +0x80, 0x02, 0x7f, 0x00, 0x90, 0x10, 0x2f, 0xef, 0xf0, 0x90, 0x01, 0x8c, 0x74, 0x08, 0xf0, 0xe4,
44202 +0x90, 0x01, 0xa7, 0xf0, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe0, 0x1c, 0x90, 0x01, 0x80, 0xe0, 0xb4,
44203 +0x02, 0x15, 0xa3, 0xe0, 0xb4, 0x01, 0x10, 0x90, 0x01, 0x84, 0xe0, 0xb4, 0x81, 0x09, 0x90, 0x01,
44204 +0x8c, 0x74, 0x01, 0xf0, 0x12, 0x0d, 0xc8, 0x22, 0x90, 0x04, 0x14, 0xe0, 0x20, 0xe7, 0x03, 0x02,
44205 +0x12, 0x66, 0x90, 0x70, 0x12, 0xe0, 0xf5, 0x56, 0x90, 0x04, 0x04, 0xe0, 0x12, 0x0a, 0x9d, 0x10,
44206 +0xb7, 0x31, 0x10, 0xe0, 0x50, 0x11, 0x04, 0x51, 0x11, 0x0d, 0x52, 0x11, 0x0d, 0x53, 0x11, 0x0d,
44207 +0x54, 0x11, 0x4e, 0x55, 0x11, 0x7e, 0x70, 0x11, 0xa9, 0x71, 0x11, 0xd7, 0x72, 0x12, 0x1d, 0x73,
44208 +0x12, 0x3e, 0x80, 0x00, 0x00, 0x12, 0x66, 0x20, 0x02, 0x03, 0x30, 0x03, 0x1d, 0x7d, 0x02, 0xaf,
44209 +0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5,
44210 +0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x85, 0x56, 0x41, 0xd2, 0x02, 0x22,
44211 +0x90, 0x70, 0x10, 0xe0, 0x54, 0x7f, 0x64, 0x02, 0x60, 0x03, 0x02, 0x12, 0x66, 0x90, 0x70, 0x11,
44212 +0xe0, 0x64, 0x08, 0x60, 0x08, 0xe0, 0x64, 0x20, 0x60, 0x03, 0x02, 0x12, 0x66, 0x75, 0x4e, 0x03,
44213 +0x75, 0x4f, 0x20, 0x22, 0x90, 0x70, 0x11, 0xe0, 0x24, 0xff, 0x92, 0x47, 0x22, 0x90, 0x04, 0x04,
44214 +0xe0, 0x25, 0xe0, 0x24, 0x5d, 0xf5, 0x57, 0x90, 0x70, 0x10, 0xe0, 0xff, 0x74, 0x47, 0x25, 0x57,
44215 +0xf8, 0xc6, 0xef, 0xc6, 0x90, 0x70, 0x11, 0xe0, 0xff, 0x74, 0x48, 0x25, 0x57, 0xf8, 0xc6, 0xef,
44216 +0xc6, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90,
44217 +0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0xe5, 0x47,
44218 +0x64, 0x07, 0x60, 0x0b, 0xe5, 0x47, 0x64, 0x08, 0x60, 0x05, 0xe5, 0x47, 0xb4, 0x09, 0x08, 0x90,
44219 +0x70, 0x11, 0xe0, 0x54, 0x0f, 0xf5, 0x3a, 0xe5, 0x47, 0xb4, 0x09, 0x08, 0xe5, 0x3a, 0xb4, 0x03,
44220 +0x03, 0xe4, 0xf5, 0x46, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0xd2, 0x04, 0x22, 0x90, 0x70,
44221 +0x10, 0xe0, 0xfe, 0x90, 0x70, 0x11, 0xe0, 0xfd, 0xed, 0xf8, 0xe6, 0xf5, 0x57, 0xfd, 0xaf, 0x56,
44222 +0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56,
44223 +0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90, 0x70,
44224 +0x11, 0xe0, 0xfd, 0xed, 0xf5, 0x82, 0x8e, 0x83, 0xe0, 0xf5, 0x57, 0xfd, 0xaf, 0x56, 0x12, 0x0b,
44225 +0x91, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70,
44226 +0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x90, 0x10, 0x02, 0xe0, 0xb4, 0x70, 0x1e, 0xa3, 0xe0,
44227 +0xb4, 0x30, 0x19, 0x90, 0x05, 0x08, 0xe0, 0x44, 0x01, 0xf0, 0xfd, 0x90, 0x05, 0x05, 0xe0, 0x54,
44228 +0xfb, 0xf0, 0x44, 0x04, 0xf0, 0xed, 0x54, 0xfe, 0x90, 0x05, 0x08, 0xf0, 0xe4, 0xf5, 0x4e, 0xf5,
44229 +0x4f, 0x75, 0x3a, 0xff, 0xad, 0x57, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74, 0x80,
44230 +0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x4b, 0x80, 0x42, 0x90, 0x70, 0x10,
44231 +0xe0, 0x24, 0xff, 0x92, 0x93, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90, 0x04, 0x14, 0x74,
44232 +0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x2a, 0x80, 0x21, 0x90, 0x70,
44233 +0x10, 0xe0, 0x24, 0xff, 0x92, 0x4a, 0xd2, 0x05, 0xad, 0x57, 0xaf, 0x56, 0x12, 0x0b, 0x91, 0x90,
44234 +0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x07, 0x90,
44235 +0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x22, 0x22, 0xe5, 0x53, 0x70, 0x1a, 0x30, 0x60, 0x09, 0xb2,
44236 +0x4d, 0x30, 0x4d, 0x04, 0x05, 0x46, 0xc2, 0x04, 0xe5, 0x4f, 0x45, 0x4e, 0x60, 0x08, 0xe5, 0x4f,
44237 +0x15, 0x4f, 0x70, 0x02, 0x15, 0x4e, 0x22, 0x22, 0xc2, 0x42, 0xd3, 0x22, 0x22, 0xc2, 0x4b, 0xc2,
44238 +0x4c, 0xe5, 0x44, 0x12, 0x0a, 0x9d, 0x12, 0xaf, 0x00, 0x13, 0x42, 0x04, 0x13, 0x3e, 0x08, 0x13,
44239 +0x19, 0x10, 0x12, 0xc3, 0x20, 0x12, 0xe3, 0x60, 0x12, 0xf4, 0xa0, 0x00, 0x00, 0x13, 0x44, 0x85,
44240 +0x48, 0x43, 0x85, 0x4a, 0x42, 0x85, 0x4c, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x60, 0x03, 0x02, 0x13,
44241 +0x44, 0x80, 0x1b, 0xe5, 0x48, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4a, 0xc4, 0x54, 0x0f, 0xf5,
44242 +0x42, 0xe5, 0x4c, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x66, 0x53, 0x43,
44243 +0x0f, 0x80, 0x61, 0x85, 0x49, 0x43, 0x85, 0x4b, 0x42, 0x85, 0x4d, 0x5e, 0xe5, 0x47, 0x64, 0x06,
44244 +0x70, 0x52, 0x80, 0x1b, 0xe5, 0x49, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4b, 0xc4, 0x54, 0x0f,
44245 +0xf5, 0x42, 0xe5, 0x4d, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x35, 0xe5,
44246 +0x43, 0x54, 0x0f, 0x44, 0x10, 0xf5, 0x43, 0x80, 0x2b, 0xe5, 0x47, 0xb4, 0x04, 0x06, 0x53, 0x5e,
44247 +0xfb, 0x75, 0x42, 0x09, 0xe5, 0x47, 0xb4, 0x05, 0x06, 0x43, 0x5e, 0x04, 0x75, 0x42, 0x09, 0xe5,
44248 +0x47, 0xb4, 0x06, 0x10, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x30, 0xf5, 0x43, 0x80, 0x06, 0xd2, 0x4b,
44249 +0x80, 0x02, 0xd2, 0x4c, 0xe4, 0xf5, 0x25, 0xe5, 0x42, 0xc4, 0x54, 0xf0, 0xff, 0xe5, 0x43, 0x54,
44250 +0x0f, 0x4f, 0xf5, 0x5f, 0x90, 0x70, 0x44, 0xf0, 0xa3, 0xe5, 0x5e, 0xf0, 0xa3, 0xe5, 0x4a, 0xf0,
44251 +0xa3, 0xe5, 0x48, 0xf0, 0xa3, 0xe5, 0x4c, 0xf0, 0xa3, 0xe5, 0x44, 0xf0, 0xa3, 0xe5, 0x42, 0xf0,
44252 +0xa3, 0xe5, 0x43, 0xf0, 0xd2, 0x60, 0x22, 0xe5, 0x47, 0x60, 0x10, 0x24, 0xc0, 0x70, 0x03, 0x12,
44253 +0x16, 0x29, 0x12, 0x13, 0x8c, 0xc2, 0xaf, 0xc2, 0x04, 0xd2, 0xaf, 0x22, 0xc2, 0xaf, 0x90, 0x04,
44254 +0x14, 0xe0, 0x54, 0x0e, 0x60, 0x04, 0xd2, 0x18, 0x80, 0x08, 0xe5, 0x4e, 0x45, 0x4f, 0x24, 0xff,
44255 +0x92, 0x18, 0xd2, 0xaf, 0x90, 0x04, 0x14, 0xe0, 0xa2, 0xe4, 0x92, 0x19, 0x74, 0x1e, 0xf0, 0xe5,
44256 +0x5f, 0x54, 0x0f, 0xf5, 0x2d, 0xe5, 0x25, 0x70, 0x13, 0x30, 0x18, 0x05, 0xe5, 0x5f, 0x20, 0xe5,
44257 +0x0b, 0x30, 0x19, 0x19, 0xe5, 0x5f, 0x54, 0x30, 0xff, 0xbf, 0x30, 0x11, 0xe5, 0x25, 0x70, 0x05,
44258 +0x75, 0x25, 0x0c, 0x80, 0x02, 0x15, 0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0x80, 0x0f, 0xe5, 0x5f, 0x30,
44259 +0xe6, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x04, 0xd2, 0x6c, 0xc2, 0x6d, 0xe5, 0x47, 0x64, 0x03,
44260 +0x70, 0x21, 0x30, 0x4b, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x18, 0xe5, 0x25, 0x70, 0x03, 0x30,
44261 +0x4c, 0x11, 0xc2, 0x4c, 0xe5, 0x25, 0x70, 0x05, 0x75, 0x25, 0x07, 0x80, 0x02, 0x15, 0x25, 0xd2,
44262 +0x6c, 0xd2, 0x6d, 0xe5, 0x47, 0xb4, 0x09, 0x14, 0xe5, 0x44, 0x20, 0xe3, 0x0b, 0xe5, 0x3a, 0x64,
44263 +0x02, 0x60, 0x05, 0xe5, 0x3a, 0xb4, 0x03, 0x04, 0xc2, 0x6c, 0xd2, 0x6d, 0x90, 0x70, 0x46, 0xe5,
44264 +0x2d, 0xf0, 0x20, 0x69, 0x07, 0xe5, 0x5e, 0x20, 0xe0, 0x02, 0xb2, 0x68, 0x20, 0x6b, 0x07, 0xe5,
44265 +0x5e, 0x20, 0xe1, 0x02, 0xb2, 0x6a, 0x20, 0x6d, 0x07, 0xe5, 0x5e, 0x20, 0xe2, 0x02, 0xb2, 0x6c,
44266 +0x90, 0x70, 0x47, 0xe5, 0x2d, 0xf0, 0x75, 0x2e, 0x40, 0x20, 0x69, 0x04, 0xa2, 0x68, 0x80, 0x26,
44267 +0x30, 0x68, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe2, 0x04, 0x7f, 0x01,
44268 +0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01, 0x80, 0x02,
44269 +0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x73, 0x92, 0x72, 0x20, 0x6b, 0x04, 0xa2, 0x6a, 0x80,
44270 +0x26, 0x30, 0x6a, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe0, 0x04, 0x7f,
44271 +0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01, 0x80,
44272 +0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x75, 0x92, 0x74, 0x20, 0x6d, 0x04, 0xa2, 0x6c,
44273 +0x80, 0x26, 0x30, 0x6c, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe1, 0x04,
44274 +0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01,
44275 +0x80, 0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x71, 0x92, 0x70, 0x90, 0x10, 0x00, 0xe0,
44276 +0x90, 0x10, 0x2f, 0xf0, 0x90, 0x10, 0x03, 0xe0, 0xc3, 0x94, 0x30, 0x40, 0x14, 0xa2, 0x71, 0x92,
44277 +0x77, 0xa2, 0x70, 0x92, 0x76, 0xe5, 0x2e, 0x13, 0x13, 0x54, 0x3f, 0xf5, 0x2e, 0xc2, 0x77, 0xd2,
44278 +0x76, 0x90, 0x10, 0x2f, 0xe5, 0x2e, 0xf0, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x4c, 0x90, 0x02, 0x29,
44279 +0xe0, 0x54, 0xfe, 0xf0, 0xe5, 0x43, 0xc4, 0x54, 0x0f, 0x14, 0x60, 0x14, 0x24, 0xfe, 0x60, 0x23,
44280 +0x24, 0x03, 0x60, 0x03, 0x02, 0x16, 0x18, 0x90, 0x02, 0x28, 0xe0, 0x30, 0x47, 0x0f, 0x80, 0x07,
44281 +0x90, 0x02, 0x28, 0xe0, 0x20, 0x47, 0x06, 0x54, 0xfe, 0xf0, 0x02, 0x16, 0x18, 0x44, 0x01, 0xf0,
44282 +0x02, 0x16, 0x18, 0xe5, 0x46, 0x30, 0xe2, 0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0x90, 0x02,
44283 +0x28, 0xe0, 0x54, 0xfe, 0x4f, 0xf0, 0x02, 0x16, 0x18, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x0f, 0xe5,
44284 +0x47, 0x64, 0x08, 0x60, 0x09, 0xe5, 0x47, 0x64, 0x09, 0x60, 0x03, 0x02, 0x16, 0x18, 0xe4, 0xf5,
44285 +0x27, 0x90, 0x02, 0x29, 0xe0, 0x54, 0xfc, 0xf0, 0xe5, 0x3a, 0x14, 0x60, 0x2d, 0x14, 0x60, 0x2e,
44286 +0x14, 0x60, 0x36, 0x24, 0xfc, 0x60, 0x5f, 0x24, 0xf9, 0x60, 0x1f, 0x24, 0x0e, 0x70, 0x69, 0xe5,
44287 +0x46, 0x13, 0x13, 0x54, 0x3f, 0x75, 0xf0, 0x03, 0x84, 0xaf, 0xf0, 0x20, 0x47, 0x04, 0x7e, 0x01,
44288 +0x80, 0x02, 0x7e, 0x00, 0xef, 0x6e, 0x24, 0xff, 0x80, 0x45, 0xa2, 0x47, 0x80, 0x41, 0xe5, 0x46,
44289 +0x30, 0xe2, 0x03, 0xd3, 0x80, 0x27, 0xc3, 0x80, 0x24, 0xe5, 0x46, 0x30, 0xe2, 0x0d, 0x54, 0x38,
44290 +0xc3, 0x94, 0x30, 0x50, 0x06, 0x7e, 0x00, 0x7f, 0x01, 0x80, 0x04, 0x7e, 0x00, 0x7f, 0x00, 0x20,
44291 +0x47, 0x04, 0x7d, 0x01, 0x80, 0x02, 0x7d, 0x00, 0xef, 0x6d, 0x4e, 0x24, 0xff, 0x92, 0x38, 0xa2,
44292 +0x47, 0xb3, 0x92, 0x39, 0x80, 0x19, 0xe5, 0x46, 0x30, 0xe2, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92,
44293 +0x39, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x80, 0x07, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x92, 0x39, 0x90,
44294 +0x02, 0x28, 0xe0, 0x54, 0xfc, 0x45, 0x27, 0xf0, 0x90, 0x70, 0x9c, 0xe5, 0x3a, 0xf0, 0xa3, 0xe5,
44295 +0x47, 0xf0, 0x90, 0x70, 0x41, 0xe5, 0x3a, 0xf0, 0x22, 0xe4, 0x90, 0x02, 0x29, 0xf0, 0x30, 0x47,
44296 +0x04, 0xaf, 0x45, 0x80, 0x04, 0xe5, 0x45, 0xf4, 0xff, 0x90, 0x02, 0x28, 0xef, 0xf0, 0x22, 0x8f,
44297 +0x50, 0xd2, 0x59, 0x22, 0x8f, 0x54, 0xd2, 0x58, 0x22, 0xe4, 0xf5, 0x62, 0xc2, 0xaf, 0xe5, 0x51,
44298 +0x14, 0x60, 0x46, 0x14, 0x60, 0x62, 0x24, 0x02, 0x60, 0x03, 0x02, 0x17, 0x03, 0xd2, 0x59, 0x75,
44299 +0x55, 0x01, 0x90, 0x02, 0xa2, 0xe0, 0x54, 0x7f, 0xf0, 0xa3, 0xe0, 0x20, 0xe7, 0x22, 0x90, 0x04,
44300 +0x34, 0xe0, 0xb4, 0x02, 0x1b, 0xa3, 0xe0, 0xb4, 0x02, 0x16, 0xa3, 0xe0, 0xb4, 0x02, 0x11, 0x7f,
44301 +0x20, 0x12, 0x16, 0x3f, 0x90, 0x10, 0x04, 0xe0, 0x54, 0xf3, 0xf0, 0x75, 0x51, 0x01, 0x80, 0x73,
44302 +0xe5, 0x50, 0x70, 0x05, 0x75, 0x62, 0x03, 0x80, 0x6a, 0x90, 0x12, 0x00, 0xe0, 0x54, 0x03, 0x70,
44303 +0x11, 0x7f, 0x20, 0x12, 0x16, 0x3f, 0x90, 0x02, 0xa2, 0xe0, 0x54, 0xbf, 0xf0, 0x75, 0x51, 0x02,
44304 +0x80, 0x51, 0xe5, 0x50, 0x70, 0x02, 0x80, 0x46, 0x90, 0x02, 0xa3, 0xe0, 0x20, 0xe6, 0x3b, 0x90,
44305 +0x04, 0x37, 0xe0, 0x64, 0x22, 0x70, 0x33, 0x90, 0x01, 0x8a, 0x74, 0x7e, 0xf0, 0x90, 0x01, 0x96,
44306 +0xf0, 0x90, 0x12, 0x04, 0x74, 0x0a, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x54, 0xf0, 0xf0, 0xa3, 0xe0,
44307 +0x54, 0xf0, 0xf0, 0xa3, 0xe0, 0x54, 0xfa, 0xf0, 0x90, 0x04, 0x01, 0xe0, 0x54, 0xf9, 0xf0, 0x75,
44308 +0x62, 0x01, 0x75, 0x55, 0x02, 0xe4, 0xf5, 0x51, 0x80, 0x09, 0xe5, 0x50, 0x70, 0x05, 0x75, 0x62,
44309 +0x03, 0xf5, 0x51, 0xe5, 0x62, 0x60, 0x15, 0xc2, 0x01, 0xe4, 0xf5, 0x51, 0xc2, 0x59, 0xad, 0x62,
44310 +0xaf, 0x40, 0x12, 0x17, 0x8d, 0xe5, 0x62, 0xb4, 0x03, 0x02, 0xd2, 0x03, 0xd2, 0xaf, 0x22, 0xc2,
44311 +0xaf, 0x30, 0x01, 0x12, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xf5, 0x51, 0xc2, 0x59, 0xc2, 0x01, 0x7d,
44312 +0x02, 0xaf, 0x40, 0x12, 0x17, 0x8d, 0xe5, 0x52, 0x14, 0x60, 0x09, 0x04, 0x70, 0x4c, 0x75, 0x52,
44313 +0x01, 0x75, 0x55, 0x03, 0x90, 0x04, 0x01, 0xe0, 0x44, 0x0e, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x44,
44314 +0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x05, 0xf0, 0x90, 0x12, 0x04, 0x74,
44315 +0x03, 0xf0, 0x90, 0x02, 0xa2, 0xe0, 0x44, 0xc0, 0xf0, 0x90, 0x10, 0x04, 0xe0, 0x44, 0x0c, 0xf0,
44316 +0xe4, 0xf5, 0x52, 0xf5, 0x55, 0x30, 0x02, 0x0b, 0xc2, 0x02, 0x7d, 0x01, 0xaf, 0x41, 0x12, 0x17,
44317 +0x8d, 0x80, 0x02, 0xc2, 0x03, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xd2, 0xaf, 0x22, 0xef, 0xf4, 0x60,
44318 +0x2d, 0xe4, 0xfe, 0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xe0, 0xb4, 0xff,
44319 +0x19, 0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xef, 0xf0, 0x74, 0x1c, 0x2e,
44320 +0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xed, 0xf0, 0x22, 0x0e, 0xbe, 0x04, 0xd5, 0x22, 0x22,
44321 +0x22, 0x90, 0x70, 0x2a, 0xe0, 0x30, 0xe1, 0x4d, 0xc2, 0xaf, 0x90, 0x70, 0x28, 0xe0, 0x90, 0x10,
44322 +0x1c, 0xf0, 0x90, 0x70, 0x29, 0xe0, 0x90, 0x10, 0x1d, 0xf0, 0x90, 0x70, 0x2a, 0xe0, 0x90, 0x10,
44323 +0x1e, 0xf0, 0x90, 0x10, 0x1c, 0xe0, 0xf5, 0x62, 0x90, 0x10, 0x1e, 0xe0, 0x20, 0xe1, 0xf3, 0x90,
44324 +0x10, 0x1c, 0xe0, 0x90, 0x70, 0x28, 0xf0, 0x90, 0x10, 0x1d, 0xe0, 0x90, 0x70, 0x29, 0xf0, 0x90,
44325 +0x10, 0x1e, 0xe0, 0x90, 0x70, 0x2a, 0xf0, 0x30, 0x4a, 0x07, 0x90, 0x70, 0x24, 0xe0, 0x44, 0x01,
44326 +0xf0, 0xc2, 0x05, 0xd2, 0xaf, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44327 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44328 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44329 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44330 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44331 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44332 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44333 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44334 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44335 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44336 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44337 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44338 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44339 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44340 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44341 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44342 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44343 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44344 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44345 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44346 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44347 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44348 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44349 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44350 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44351 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44352 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44353 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44354 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44355 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44356 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44357 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44358 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44359 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44360 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44361 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44362 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44363 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44364 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44365 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44366 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44367 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44368 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44369 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44370 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44371 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44372 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44373 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44374 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44375 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44376 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44377 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44378 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44379 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44380 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44381 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44382 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44383 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44384 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44385 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44386 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44387 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44388 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44389 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44390 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44391 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44392 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44393 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44394 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44395 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44396 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44397 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44398 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44399 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44400 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44401 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44402 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44403 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44404 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44405 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44406 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44407 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44408 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44409 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44410 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44411 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44412 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44413 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44414 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44415 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44416 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44417 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44418 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44419 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44420 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44421 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44422 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44423 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44424 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44425 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44426 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44427 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44428 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44429 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44430 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44431 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44432 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44433 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44434 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44435 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44436 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44437 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44438 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44439 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44440 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44441 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44442 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44443 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44444 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44445 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44446 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44447 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44448 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44449 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44450 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44451 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44452 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x94, 0x3f,
44453 +0xff, 0xff, 0xff, 0x02, 0x10, 0x28, 0x02, 0x10, 0x32, 0x02, 0x10, 0x78, 0x02, 0x12, 0x67, 0x02,
44454 +0x12, 0x68, 0x02, 0x12, 0x87, 0x02, 0x12, 0x8c, 0x12, 0x12, 0x88, 0x22, 0x02, 0x16, 0x49, 0x02,
44455 +0x17, 0x1f, 0x02, 0x13, 0x77, 0x02, 0x12, 0x8d, 0x30, 0x05, 0x06, 0x20, 0x0d, 0x03, 0x12, 0x17,
44456 +0xc1, 0x22, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe3, 0x1b, 0xe5, 0x4c, 0x30, 0xe0, 0x04, 0x7f, 0x40,
44457 +0x80, 0x02, 0x7f, 0x00, 0x90, 0x10, 0x2f, 0xef, 0xf0, 0x90, 0x01, 0x8c, 0x74, 0x08, 0xf0, 0xe4,
44458 +0x90, 0x01, 0xa7, 0xf0, 0x90, 0x01, 0x8c, 0xe0, 0x30, 0xe0, 0x1c, 0x90, 0x01, 0x80, 0xe0, 0xb4,
44459 +0x02, 0x15, 0xa3, 0xe0, 0xb4, 0x01, 0x10, 0x90, 0x01, 0x84, 0xe0, 0xb4, 0x81, 0x09, 0x90, 0x01,
44460 +0x8c, 0x74, 0x01, 0xf0, 0x12, 0x0d, 0xdd, 0x22, 0x90, 0x04, 0x14, 0xe0, 0x20, 0xe7, 0x03, 0x02,
44461 +0x12, 0x66, 0x90, 0x70, 0x12, 0xe0, 0xf5, 0x56, 0x90, 0x04, 0x04, 0xe0, 0x12, 0x0a, 0xb6, 0x10,
44462 +0xb7, 0x31, 0x10, 0xe0, 0x50, 0x11, 0x04, 0x51, 0x11, 0x0d, 0x52, 0x11, 0x0d, 0x53, 0x11, 0x0d,
44463 +0x54, 0x11, 0x4e, 0x55, 0x11, 0x7e, 0x70, 0x11, 0xa9, 0x71, 0x11, 0xd7, 0x72, 0x12, 0x1d, 0x73,
44464 +0x12, 0x3e, 0x80, 0x00, 0x00, 0x12, 0x66, 0x20, 0x02, 0x03, 0x30, 0x03, 0x1d, 0x7d, 0x02, 0xaf,
44465 +0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5,
44466 +0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x85, 0x56, 0x41, 0xd2, 0x02, 0x22,
44467 +0x90, 0x70, 0x10, 0xe0, 0x54, 0x7f, 0x64, 0x02, 0x60, 0x03, 0x02, 0x12, 0x66, 0x90, 0x70, 0x11,
44468 +0xe0, 0x64, 0x08, 0x60, 0x08, 0xe0, 0x64, 0x20, 0x60, 0x03, 0x02, 0x12, 0x66, 0x75, 0x4e, 0x03,
44469 +0x75, 0x4f, 0x20, 0x22, 0x90, 0x70, 0x11, 0xe0, 0x24, 0xff, 0x92, 0x47, 0x22, 0x90, 0x04, 0x04,
44470 +0xe0, 0x25, 0xe0, 0x24, 0x5d, 0xf5, 0x57, 0x90, 0x70, 0x10, 0xe0, 0xff, 0x74, 0x47, 0x25, 0x57,
44471 +0xf8, 0xc6, 0xef, 0xc6, 0x90, 0x70, 0x11, 0xe0, 0xff, 0x74, 0x48, 0x25, 0x57, 0xf8, 0xc6, 0xef,
44472 +0xc6, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90,
44473 +0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0xe5, 0x47,
44474 +0x64, 0x07, 0x60, 0x0b, 0xe5, 0x47, 0x64, 0x08, 0x60, 0x05, 0xe5, 0x47, 0xb4, 0x09, 0x08, 0x90,
44475 +0x70, 0x11, 0xe0, 0x54, 0x0f, 0xf5, 0x3a, 0xe5, 0x47, 0xb4, 0x09, 0x08, 0xe5, 0x3a, 0xb4, 0x03,
44476 +0x03, 0xe4, 0xf5, 0x46, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0xd2, 0x04, 0x22, 0x90, 0x70,
44477 +0x10, 0xe0, 0xfe, 0x90, 0x70, 0x11, 0xe0, 0xfd, 0xed, 0xf8, 0xe6, 0xf5, 0x57, 0xfd, 0xaf, 0x56,
44478 +0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56,
44479 +0xf4, 0x70, 0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x90, 0x70, 0x10, 0xe0, 0xfe, 0x90, 0x70,
44480 +0x11, 0xe0, 0xfd, 0xed, 0xf5, 0x82, 0x8e, 0x83, 0xe0, 0xf5, 0x57, 0xfd, 0xaf, 0x56, 0x12, 0x0b,
44481 +0xaa, 0x90, 0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x70,
44482 +0x03, 0x02, 0x12, 0x66, 0x02, 0x12, 0x5f, 0x90, 0x10, 0x02, 0xe0, 0xb4, 0x70, 0x1e, 0xa3, 0xe0,
44483 +0xb4, 0x30, 0x19, 0x90, 0x05, 0x08, 0xe0, 0x44, 0x01, 0xf0, 0xfd, 0x90, 0x05, 0x05, 0xe0, 0x54,
44484 +0xfb, 0xf0, 0x44, 0x04, 0xf0, 0xed, 0x54, 0xfe, 0x90, 0x05, 0x08, 0xf0, 0xe4, 0xf5, 0x4e, 0xf5,
44485 +0x4f, 0x75, 0x3a, 0xff, 0xad, 0x57, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74, 0x80,
44486 +0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x4b, 0x80, 0x42, 0x90, 0x70, 0x10,
44487 +0xe0, 0x24, 0xff, 0x92, 0x93, 0xe4, 0xfd, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90, 0x04, 0x14, 0x74,
44488 +0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x2a, 0x80, 0x21, 0x90, 0x70,
44489 +0x10, 0xe0, 0x24, 0xff, 0x92, 0x4a, 0xd2, 0x05, 0xad, 0x57, 0xaf, 0x56, 0x12, 0x0b, 0xaa, 0x90,
44490 +0x04, 0x14, 0x74, 0x80, 0xf0, 0xe4, 0x90, 0x70, 0x13, 0xf0, 0xe5, 0x56, 0xf4, 0x60, 0x07, 0x90,
44491 +0x70, 0x25, 0xe0, 0x44, 0x01, 0xf0, 0x22, 0x22, 0xe5, 0x53, 0x70, 0x1a, 0x30, 0x60, 0x09, 0xb2,
44492 +0x4d, 0x30, 0x4d, 0x04, 0x05, 0x46, 0xc2, 0x04, 0xe5, 0x4f, 0x45, 0x4e, 0x60, 0x08, 0xe5, 0x4f,
44493 +0x15, 0x4f, 0x70, 0x02, 0x15, 0x4e, 0x22, 0x22, 0xc2, 0x42, 0xd3, 0x22, 0x22, 0xc2, 0x4b, 0xc2,
44494 +0x4c, 0xe5, 0x44, 0x12, 0x0a, 0xb6, 0x12, 0xaf, 0x00, 0x13, 0x42, 0x04, 0x13, 0x3e, 0x08, 0x13,
44495 +0x19, 0x10, 0x12, 0xc3, 0x20, 0x12, 0xe3, 0x60, 0x12, 0xf4, 0xa0, 0x00, 0x00, 0x13, 0x44, 0x85,
44496 +0x48, 0x43, 0x85, 0x4a, 0x42, 0x85, 0x4c, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x60, 0x03, 0x02, 0x13,
44497 +0x44, 0x80, 0x1b, 0xe5, 0x48, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4a, 0xc4, 0x54, 0x0f, 0xf5,
44498 +0x42, 0xe5, 0x4c, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x66, 0x53, 0x43,
44499 +0x0f, 0x80, 0x61, 0x85, 0x49, 0x43, 0x85, 0x4b, 0x42, 0x85, 0x4d, 0x5e, 0xe5, 0x47, 0x64, 0x06,
44500 +0x70, 0x52, 0x80, 0x1b, 0xe5, 0x49, 0xc4, 0x54, 0x0f, 0xf5, 0x43, 0xe5, 0x4b, 0xc4, 0x54, 0x0f,
44501 +0xf5, 0x42, 0xe5, 0x4d, 0xc4, 0x54, 0x0f, 0xf5, 0x5e, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x35, 0xe5,
44502 +0x43, 0x54, 0x0f, 0x44, 0x10, 0xf5, 0x43, 0x80, 0x2b, 0xe5, 0x47, 0xb4, 0x04, 0x06, 0x53, 0x5e,
44503 +0xfb, 0x75, 0x42, 0x09, 0xe5, 0x47, 0xb4, 0x05, 0x06, 0x43, 0x5e, 0x04, 0x75, 0x42, 0x09, 0xe5,
44504 +0x47, 0xb4, 0x06, 0x10, 0xe5, 0x43, 0x54, 0x0f, 0x44, 0x30, 0xf5, 0x43, 0x80, 0x06, 0xd2, 0x4b,
44505 +0x80, 0x02, 0xd2, 0x4c, 0xe4, 0xf5, 0x25, 0xe5, 0x42, 0xc4, 0x54, 0xf0, 0xff, 0xe5, 0x43, 0x54,
44506 +0x0f, 0x4f, 0xf5, 0x5f, 0x90, 0x70, 0x44, 0xf0, 0xa3, 0xe5, 0x5e, 0xf0, 0xa3, 0xe5, 0x4a, 0xf0,
44507 +0xa3, 0xe5, 0x48, 0xf0, 0xa3, 0xe5, 0x4c, 0xf0, 0xa3, 0xe5, 0x44, 0xf0, 0xa3, 0xe5, 0x42, 0xf0,
44508 +0xa3, 0xe5, 0x43, 0xf0, 0xd2, 0x60, 0x22, 0xe5, 0x47, 0x60, 0x10, 0x24, 0xc0, 0x70, 0x03, 0x12,
44509 +0x16, 0x29, 0x12, 0x13, 0x8c, 0xc2, 0xaf, 0xc2, 0x04, 0xd2, 0xaf, 0x22, 0xc2, 0xaf, 0x90, 0x04,
44510 +0x14, 0xe0, 0x54, 0x0e, 0x60, 0x04, 0xd2, 0x18, 0x80, 0x08, 0xe5, 0x4e, 0x45, 0x4f, 0x24, 0xff,
44511 +0x92, 0x18, 0xd2, 0xaf, 0x90, 0x04, 0x14, 0xe0, 0xa2, 0xe4, 0x92, 0x19, 0x74, 0x1e, 0xf0, 0xe5,
44512 +0x5f, 0x54, 0x0f, 0xf5, 0x2d, 0xe5, 0x25, 0x70, 0x13, 0x30, 0x18, 0x05, 0xe5, 0x5f, 0x20, 0xe5,
44513 +0x0b, 0x30, 0x19, 0x19, 0xe5, 0x5f, 0x54, 0x30, 0xff, 0xbf, 0x30, 0x11, 0xe5, 0x25, 0x70, 0x05,
44514 +0x75, 0x25, 0x0c, 0x80, 0x02, 0x15, 0x25, 0xd2, 0x6c, 0xd2, 0x6d, 0x80, 0x0f, 0xe5, 0x5f, 0x30,
44515 +0xe6, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x04, 0xd2, 0x6c, 0xc2, 0x6d, 0xe5, 0x47, 0x64, 0x03,
44516 +0x70, 0x21, 0x30, 0x4b, 0x06, 0xc2, 0x6c, 0xd2, 0x6d, 0x80, 0x18, 0xe5, 0x25, 0x70, 0x03, 0x30,
44517 +0x4c, 0x11, 0xc2, 0x4c, 0xe5, 0x25, 0x70, 0x05, 0x75, 0x25, 0x07, 0x80, 0x02, 0x15, 0x25, 0xd2,
44518 +0x6c, 0xd2, 0x6d, 0xe5, 0x47, 0xb4, 0x09, 0x14, 0xe5, 0x44, 0x20, 0xe3, 0x0b, 0xe5, 0x3a, 0x64,
44519 +0x02, 0x60, 0x05, 0xe5, 0x3a, 0xb4, 0x03, 0x04, 0xc2, 0x6c, 0xd2, 0x6d, 0x90, 0x70, 0x46, 0xe5,
44520 +0x2d, 0xf0, 0x20, 0x69, 0x07, 0xe5, 0x5e, 0x20, 0xe0, 0x02, 0xb2, 0x68, 0x20, 0x6b, 0x07, 0xe5,
44521 +0x5e, 0x20, 0xe1, 0x02, 0xb2, 0x6a, 0x20, 0x6d, 0x07, 0xe5, 0x5e, 0x20, 0xe2, 0x02, 0xb2, 0x6c,
44522 +0x90, 0x70, 0x47, 0xe5, 0x2d, 0xf0, 0x75, 0x2e, 0x40, 0x20, 0x69, 0x04, 0xa2, 0x68, 0x80, 0x26,
44523 +0x30, 0x68, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe2, 0x04, 0x7f, 0x01,
44524 +0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01, 0x80, 0x02,
44525 +0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x73, 0x92, 0x72, 0x20, 0x6b, 0x04, 0xa2, 0x6a, 0x80,
44526 +0x26, 0x30, 0x6a, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe0, 0x04, 0x7f,
44527 +0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01, 0x80,
44528 +0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x75, 0x92, 0x74, 0x20, 0x6d, 0x04, 0xa2, 0x6c,
44529 +0x80, 0x26, 0x30, 0x6c, 0x06, 0xe5, 0x46, 0xa2, 0xe2, 0x80, 0x1d, 0xe5, 0x5e, 0x20, 0xe1, 0x04,
44530 +0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0xe5, 0x46, 0x54, 0xf0, 0xfe, 0xbe, 0xf0, 0x04, 0x7e, 0x01,
44531 +0x80, 0x02, 0x7e, 0x00, 0xee, 0x6f, 0x24, 0xff, 0x92, 0x71, 0x92, 0x70, 0x90, 0x10, 0x00, 0xe0,
44532 +0x90, 0x10, 0x2f, 0xf0, 0x90, 0x10, 0x03, 0xe0, 0xc3, 0x94, 0x30, 0x40, 0x14, 0xa2, 0x71, 0x92,
44533 +0x77, 0xa2, 0x70, 0x92, 0x76, 0xe5, 0x2e, 0x13, 0x13, 0x54, 0x3f, 0xf5, 0x2e, 0xc2, 0x77, 0xd2,
44534 +0x76, 0x90, 0x10, 0x2f, 0xe5, 0x2e, 0xf0, 0xe5, 0x47, 0x64, 0x06, 0x70, 0x4c, 0x90, 0x02, 0x29,
44535 +0xe0, 0x54, 0xfe, 0xf0, 0xe5, 0x43, 0xc4, 0x54, 0x0f, 0x14, 0x60, 0x14, 0x24, 0xfe, 0x60, 0x23,
44536 +0x24, 0x03, 0x60, 0x03, 0x02, 0x16, 0x18, 0x90, 0x02, 0x28, 0xe0, 0x30, 0x47, 0x0f, 0x80, 0x07,
44537 +0x90, 0x02, 0x28, 0xe0, 0x20, 0x47, 0x06, 0x54, 0xfe, 0xf0, 0x02, 0x16, 0x18, 0x44, 0x01, 0xf0,
44538 +0x02, 0x16, 0x18, 0xe5, 0x46, 0x30, 0xe2, 0x04, 0x7f, 0x01, 0x80, 0x02, 0x7f, 0x00, 0x90, 0x02,
44539 +0x28, 0xe0, 0x54, 0xfe, 0x4f, 0xf0, 0x02, 0x16, 0x18, 0xe5, 0x47, 0x64, 0x07, 0x60, 0x0f, 0xe5,
44540 +0x47, 0x64, 0x08, 0x60, 0x09, 0xe5, 0x47, 0x64, 0x09, 0x60, 0x03, 0x02, 0x16, 0x18, 0xe4, 0xf5,
44541 +0x27, 0x90, 0x02, 0x29, 0xe0, 0x54, 0xfc, 0xf0, 0xe5, 0x3a, 0x14, 0x60, 0x2d, 0x14, 0x60, 0x2e,
44542 +0x14, 0x60, 0x36, 0x24, 0xfc, 0x60, 0x5f, 0x24, 0xf9, 0x60, 0x1f, 0x24, 0x0e, 0x70, 0x69, 0xe5,
44543 +0x46, 0x13, 0x13, 0x54, 0x3f, 0x75, 0xf0, 0x03, 0x84, 0xaf, 0xf0, 0x20, 0x47, 0x04, 0x7e, 0x01,
44544 +0x80, 0x02, 0x7e, 0x00, 0xef, 0x6e, 0x24, 0xff, 0x80, 0x45, 0xa2, 0x47, 0x80, 0x41, 0xe5, 0x46,
44545 +0x30, 0xe2, 0x03, 0xd3, 0x80, 0x27, 0xc3, 0x80, 0x24, 0xe5, 0x46, 0x30, 0xe2, 0x0d, 0x54, 0x38,
44546 +0xc3, 0x94, 0x30, 0x50, 0x06, 0x7e, 0x00, 0x7f, 0x01, 0x80, 0x04, 0x7e, 0x00, 0x7f, 0x00, 0x20,
44547 +0x47, 0x04, 0x7d, 0x01, 0x80, 0x02, 0x7d, 0x00, 0xef, 0x6d, 0x4e, 0x24, 0xff, 0x92, 0x38, 0xa2,
44548 +0x47, 0xb3, 0x92, 0x39, 0x80, 0x19, 0xe5, 0x46, 0x30, 0xe2, 0x03, 0xd3, 0x80, 0x01, 0xc3, 0x92,
44549 +0x39, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x80, 0x07, 0xa2, 0x47, 0xb3, 0x92, 0x38, 0x92, 0x39, 0x90,
44550 +0x02, 0x28, 0xe0, 0x54, 0xfc, 0x45, 0x27, 0xf0, 0x90, 0x70, 0x9c, 0xe5, 0x3a, 0xf0, 0xa3, 0xe5,
44551 +0x47, 0xf0, 0x90, 0x70, 0x41, 0xe5, 0x3a, 0xf0, 0x22, 0xe4, 0x90, 0x02, 0x29, 0xf0, 0x30, 0x47,
44552 +0x04, 0xaf, 0x45, 0x80, 0x04, 0xe5, 0x45, 0xf4, 0xff, 0x90, 0x02, 0x28, 0xef, 0xf0, 0x22, 0x8f,
44553 +0x50, 0xd2, 0x59, 0x22, 0x8f, 0x54, 0xd2, 0x58, 0x22, 0xe4, 0xf5, 0x62, 0xc2, 0xaf, 0xe5, 0x51,
44554 +0x14, 0x60, 0x46, 0x14, 0x60, 0x62, 0x24, 0x02, 0x60, 0x03, 0x02, 0x17, 0x03, 0xd2, 0x59, 0x75,
44555 +0x55, 0x01, 0x90, 0x02, 0xa2, 0xe0, 0x54, 0x7f, 0xf0, 0xa3, 0xe0, 0x20, 0xe7, 0x22, 0x90, 0x04,
44556 +0x34, 0xe0, 0xb4, 0x02, 0x1b, 0xa3, 0xe0, 0xb4, 0x02, 0x16, 0xa3, 0xe0, 0xb4, 0x02, 0x11, 0x7f,
44557 +0x20, 0x12, 0x16, 0x3f, 0x90, 0x10, 0x04, 0xe0, 0x54, 0xf3, 0xf0, 0x75, 0x51, 0x01, 0x80, 0x73,
44558 +0xe5, 0x50, 0x70, 0x05, 0x75, 0x62, 0x03, 0x80, 0x6a, 0x90, 0x12, 0x00, 0xe0, 0x54, 0x03, 0x70,
44559 +0x11, 0x7f, 0x20, 0x12, 0x16, 0x3f, 0x90, 0x02, 0xa2, 0xe0, 0x54, 0xbf, 0xf0, 0x75, 0x51, 0x02,
44560 +0x80, 0x51, 0xe5, 0x50, 0x70, 0x02, 0x80, 0x46, 0x90, 0x02, 0xa3, 0xe0, 0x20, 0xe6, 0x3b, 0x90,
44561 +0x04, 0x37, 0xe0, 0x64, 0x22, 0x70, 0x33, 0x90, 0x01, 0x8a, 0x74, 0x7e, 0xf0, 0x90, 0x01, 0x96,
44562 +0xf0, 0x90, 0x12, 0x04, 0x74, 0x0a, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x54, 0xf0, 0xf0, 0xa3, 0xe0,
44563 +0x54, 0xf0, 0xf0, 0xa3, 0xe0, 0x54, 0xfa, 0xf0, 0x90, 0x04, 0x01, 0xe0, 0x54, 0xf9, 0xf0, 0x75,
44564 +0x62, 0x01, 0x75, 0x55, 0x02, 0xe4, 0xf5, 0x51, 0x80, 0x09, 0xe5, 0x50, 0x70, 0x05, 0x75, 0x62,
44565 +0x03, 0xf5, 0x51, 0xe5, 0x62, 0x60, 0x15, 0xc2, 0x01, 0xe4, 0xf5, 0x51, 0xc2, 0x59, 0xad, 0x62,
44566 +0xaf, 0x40, 0x12, 0x17, 0x8d, 0xe5, 0x62, 0xb4, 0x03, 0x02, 0xd2, 0x03, 0xd2, 0xaf, 0x22, 0xc2,
44567 +0xaf, 0x30, 0x01, 0x12, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xf5, 0x51, 0xc2, 0x59, 0xc2, 0x01, 0x7d,
44568 +0x02, 0xaf, 0x40, 0x12, 0x17, 0x8d, 0xe5, 0x52, 0x14, 0x60, 0x09, 0x04, 0x70, 0x4c, 0x75, 0x52,
44569 +0x01, 0x75, 0x55, 0x03, 0x90, 0x04, 0x01, 0xe0, 0x44, 0x0e, 0xf0, 0x90, 0x13, 0x28, 0xe0, 0x44,
44570 +0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x0f, 0xf0, 0xa3, 0xe0, 0x44, 0x05, 0xf0, 0x90, 0x12, 0x04, 0x74,
44571 +0x03, 0xf0, 0x90, 0x02, 0xa2, 0xe0, 0x44, 0xc0, 0xf0, 0x90, 0x10, 0x04, 0xe0, 0x44, 0x0c, 0xf0,
44572 +0xe4, 0xf5, 0x52, 0xf5, 0x55, 0x30, 0x02, 0x0b, 0xc2, 0x02, 0x7d, 0x01, 0xaf, 0x41, 0x12, 0x17,
44573 +0x8d, 0x80, 0x02, 0xc2, 0x03, 0xe4, 0x90, 0x01, 0x96, 0xf0, 0xd2, 0xaf, 0x22, 0xef, 0xf4, 0x60,
44574 +0x2d, 0xe4, 0xfe, 0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xe0, 0xb4, 0xff,
44575 +0x19, 0x74, 0x14, 0x2e, 0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xef, 0xf0, 0x74, 0x1c, 0x2e,
44576 +0xf5, 0x82, 0xe4, 0x34, 0x70, 0xf5, 0x83, 0xed, 0xf0, 0x22, 0x0e, 0xbe, 0x04, 0xd5, 0x22, 0x22,
44577 +0x22, 0x90, 0x70, 0x2a, 0xe0, 0x30, 0xe1, 0x4d, 0xc2, 0xaf, 0x90, 0x70, 0x28, 0xe0, 0x90, 0x10,
44578 +0x1c, 0xf0, 0x90, 0x70, 0x29, 0xe0, 0x90, 0x10, 0x1d, 0xf0, 0x90, 0x70, 0x2a, 0xe0, 0x90, 0x10,
44579 +0x1e, 0xf0, 0x90, 0x10, 0x1c, 0xe0, 0xf5, 0x62, 0x90, 0x10, 0x1e, 0xe0, 0x20, 0xe1, 0xf3, 0x90,
44580 +0x10, 0x1c, 0xe0, 0x90, 0x70, 0x28, 0xf0, 0x90, 0x10, 0x1d, 0xe0, 0x90, 0x70, 0x29, 0xf0, 0x90,
44581 +0x10, 0x1e, 0xe0, 0x90, 0x70, 0x2a, 0xf0, 0x30, 0x4a, 0x07, 0x90, 0x70, 0x24, 0xe0, 0x44, 0x01,
44582 +0xf0, 0xc2, 0x05, 0xd2, 0xaf, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44583 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44584 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44585 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44586 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44587 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44588 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44589 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44590 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44591 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44592 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44593 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44594 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44595 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44596 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44597 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44598 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44599 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44600 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44601 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44602 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44603 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44604 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44605 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44606 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44607 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44608 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44609 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44610 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44611 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44612 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44613 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44614 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44615 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44616 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44617 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44618 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44619 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44620 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44621 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44622 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44623 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44624 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44625 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44626 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44627 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44628 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44629 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44630 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44631 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44632 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44633 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44634 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44635 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44636 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44637 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44638 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44639 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44640 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44641 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44642 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44643 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44644 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44645 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44646 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44647 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44648 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44649 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44650 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44651 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44652 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44653 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44654 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44655 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44656 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44657 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44658 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44659 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44660 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44661 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44662 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44663 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44664 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44665 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44666 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44667 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44668 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44669 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44670 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44671 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44672 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44673 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44674 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44675 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44676 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44677 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44678 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44679 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44680 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44681 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44682 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44683 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44684 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44685 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44686 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44687 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44688 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44689 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44690 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44691 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44692 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44693 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44694 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44695 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44696 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44697 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44698 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44699 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44700 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44701 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44702 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44703 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44704 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44705 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44706 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44707 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44708 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x9b, 0xc0, } ;
44709 --- /dev/null
44710 +++ b/drivers/staging/rt3070/Kconfig
44711 @@ -0,0 +1,6 @@
44712 +config RT3070
44713 + tristate "Ralink 3070 wireless support"
44714 + depends on USB && X86 && WLAN_80211
44715 + ---help---
44716 + This is an experimental driver for the Ralink 3070 wireless chip.
44717 +
44718 --- /dev/null
44719 +++ b/drivers/staging/rt3070/leap.h
44720 @@ -0,0 +1,215 @@
44721 +/*
44722 + *************************************************************************
44723 + * Ralink Tech Inc.
44724 + * 5F., No.36, Taiyuan St., Jhubei City,
44725 + * Hsinchu County 302,
44726 + * Taiwan, R.O.C.
44727 + *
44728 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44729 + *
44730 + * This program is free software; you can redistribute it and/or modify *
44731 + * it under the terms of the GNU General Public License as published by *
44732 + * the Free Software Foundation; either version 2 of the License, or *
44733 + * (at your option) any later version. *
44734 + * *
44735 + * This program is distributed in the hope that it will be useful, *
44736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44738 + * GNU General Public License for more details. *
44739 + * *
44740 + * You should have received a copy of the GNU General Public License *
44741 + * along with this program; if not, write to the *
44742 + * Free Software Foundation, Inc., *
44743 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44744 + * *
44745 + *************************************************************************
44746 +
44747 + Module Name:
44748 + leap.h
44749 +
44750 + Abstract:
44751 +
44752 + Revision History:
44753 + Who When What
44754 + -------- ---------- ----------------------------------------------
44755 + Name Date Modification logs
44756 +*/
44757 +#ifndef __LEAP_H__
44758 +#define __LEAP_H__
44759 +
44760 +// Messages for Associate state machine
44761 +#define LEAP_MACHINE_BASE 30
44762 +
44763 +#define LEAP_MSG_REQUEST_IDENTITY 31
44764 +#define LEAP_MSG_REQUEST_LEAP 32
44765 +#define LEAP_MSG_SUCCESS 33
44766 +#define LEAP_MSG_FAILED 34
44767 +#define LEAP_MSG_RESPONSE_LEAP 35
44768 +#define LEAP_MSG_EAPOLKEY 36
44769 +#define LEAP_MSG_UNKNOWN 37
44770 +#define LEAP_MSG 38
44771 +//! assoc state-machine states
44772 +#define LEAP_IDLE 0
44773 +#define LEAP_WAIT_IDENTITY_REQUEST 1
44774 +#define LEAP_WAIT_CHANLLENGE_REQUEST 2
44775 +#define LEAP_WAIT_SUCCESS 3
44776 +#define LEAP_WAIT_CHANLLENGE_RESPONSE 4
44777 +#define LEAP_WAIT_EAPOLKEY 5
44778 +
44779 +#define LEAP_REASON_INVALID_AUTH 0x01
44780 +#define LEAP_REASON_AUTH_TIMEOUT 0x02
44781 +#define LEAP_REASON_CHALLENGE_FROM_AP_FAILED 0x03
44782 +#define LEAP_REASON_CHALLENGE_TO_AP_FAILED 0x04
44783 +
44784 +#define CISCO_AuthModeLEAP 0x80
44785 +#define CISCO_AuthModeLEAPNone 0x00
44786 +#define LEAP_AUTH_TIMEOUT 30000
44787 +#define LEAP_CHALLENGE_RESPONSE_LENGTH 24
44788 +#define LEAP_CHALLENGE_REQUEST_LENGTH 8
44789 +
44790 +typedef struct _LEAP_EAPOL_HEADER_ {
44791 + UCHAR Version;
44792 + UCHAR Type;
44793 + UCHAR Length[2];
44794 +} LEAP_EAPOL_HEADER, *PLEAP_EAPOL_HEADER;
44795 +
44796 +typedef struct _LEAP_EAPOL_PACKET_ {
44797 + UCHAR Code;
44798 + UCHAR Identifier;
44799 + UCHAR Length[2];
44800 + UCHAR Type;
44801 +} LEAP_EAPOL_PACKET, *PLEAP_EAPOL_PACKET;
44802 +
44803 +typedef struct _LEAP_EAP_CONTENTS_ {
44804 + UCHAR Version;
44805 + UCHAR Reserved;
44806 + UCHAR Length;
44807 +} LEAP_EAP_CONTENTS, *PLEAP_EAP_CONTENTS;
44808 +
44809 +/*** EAPOL key ***/
44810 +typedef struct _EAPOL_KEY_HEADER_ {
44811 + UCHAR Type;
44812 + UCHAR Length[2];
44813 + UCHAR Counter[8];
44814 + UCHAR IV[16];
44815 + UCHAR Index;
44816 + UCHAR Signature[16];
44817 +} EAPOL_KEY_HEADER, *PEAPOL_KEY_HEADER;
44818 +
44819 +BOOLEAN LeapMsgTypeSubst(
44820 + IN UCHAR EAPType,
44821 + OUT ULONG *MsgType);
44822 +
44823 +VOID LeapMachinePerformAction(
44824 + IN PRTMP_ADAPTER pAd,
44825 + IN STATE_MACHINE *S,
44826 + IN MLME_QUEUE_ELEM *Elem);
44827 +
44828 +VOID LeapMacHeaderInit(
44829 + IN PRTMP_ADAPTER pAd,
44830 + IN OUT PHEADER_802_11 pHdr80211,
44831 + IN UCHAR wep,
44832 + IN PUCHAR pAddr3);
44833 +
44834 +VOID LeapStartAction(
44835 + IN PRTMP_ADAPTER pAd,
44836 + IN MLME_QUEUE_ELEM *Elem);
44837 +
44838 +VOID LeapIdentityAction(
44839 + IN PRTMP_ADAPTER pAd,
44840 + IN MLME_QUEUE_ELEM *Elem);
44841 +
44842 +VOID LeapPeerChallengeAction(
44843 + IN PRTMP_ADAPTER pAd,
44844 + IN MLME_QUEUE_ELEM *Elem);
44845 +
44846 +VOID HashPwd(
44847 + IN PUCHAR pwd,
44848 + IN INT pwdlen,
44849 + OUT PUCHAR hash);
44850 +
44851 +VOID PeerChallengeResponse(
44852 + IN PUCHAR szChallenge,
44853 + IN PUCHAR smbPasswd,
44854 + OUT PUCHAR szResponse);
44855 +
44856 +VOID ParityKey(
44857 + OUT PUCHAR szOut,
44858 + IN PUCHAR szIn);
44859 +
44860 +VOID DesKey(
44861 + OUT ULONG k[16][2],
44862 + IN PUCHAR key,
44863 + IN INT decrypt);
44864 +
44865 +VOID Des(
44866 + IN ULONG ks[16][2],
44867 + OUT UCHAR block[8]);
44868 +
44869 +VOID DesEncrypt(
44870 + IN PUCHAR szClear,
44871 + IN PUCHAR szKey,
44872 + OUT PUCHAR szOut);
44873 +
44874 +VOID LeapNetworkChallengeAction(
44875 + IN PRTMP_ADAPTER pAd,
44876 + IN MLME_QUEUE_ELEM *Elem);
44877 +
44878 +VOID LeapNetworkChallengeResponse(
44879 + IN PRTMP_ADAPTER pAd,
44880 + IN MLME_QUEUE_ELEM *Elem);
44881 +
44882 +VOID HashpwdHash(
44883 + IN PUCHAR hash,
44884 + IN PUCHAR hashhash);
44885 +
44886 +VOID ProcessSessionKey(
44887 + OUT PUCHAR SessionKey,
44888 + IN PUCHAR hash2,
44889 + IN PUCHAR ChallengeToRadius,
44890 + IN PUCHAR ChallengeResponseFromRadius,
44891 + IN PUCHAR ChallengeFromRadius,
44892 + IN PUCHAR ChallengeResponseToRadius);
44893 +
44894 +VOID LeapEapolKeyAction(
44895 + IN PRTMP_ADAPTER pAd,
44896 + IN MLME_QUEUE_ELEM *Elem);
44897 +
44898 +VOID RogueApTableInit(
44899 + IN ROGUEAP_TABLE *Tab);
44900 +
44901 +ULONG RogueApTableSearch(
44902 + IN ROGUEAP_TABLE *Tab,
44903 + IN PUCHAR pAddr);
44904 +
44905 +VOID RogueApEntrySet(
44906 + IN PRTMP_ADAPTER pAd,
44907 + OUT ROGUEAP_ENTRY *pRogueAp,
44908 + IN PUCHAR pAddr,
44909 + IN UCHAR FaileCode);
44910 +
44911 +ULONG RogueApTableSetEntry(
44912 + IN PRTMP_ADAPTER pAd,
44913 + OUT ROGUEAP_TABLE *Tab,
44914 + IN PUCHAR pAddr,
44915 + IN UCHAR FaileCode);
44916 +
44917 +VOID RogueApTableDeleteEntry(
44918 + IN OUT ROGUEAP_TABLE *Tab,
44919 + IN PUCHAR pAddr);
44920 +
44921 +VOID LeapAuthTimeout(
44922 + IN PVOID SystemSpecific1,
44923 + IN PVOID FunctionContext,
44924 + IN PVOID SystemSpecific2,
44925 + IN PVOID SystemSpecific3);
44926 +
44927 +VOID LeapSendRogueAPReport(
44928 + IN PRTMP_ADAPTER pAd);
44929 +
44930 +BOOLEAN CCKMAssocRspSanity(
44931 + IN PRTMP_ADAPTER pAd,
44932 + IN VOID *Msg,
44933 + IN ULONG MsgLen);
44934 +
44935 +#endif // __LEAP_H__
44936 --- /dev/null
44937 +++ b/drivers/staging/rt3070/link_list.h
44938 @@ -0,0 +1,134 @@
44939 +/*
44940 + *************************************************************************
44941 + * Ralink Tech Inc.
44942 + * 5F., No.36, Taiyuan St., Jhubei City,
44943 + * Hsinchu County 302,
44944 + * Taiwan, R.O.C.
44945 + *
44946 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
44947 + *
44948 + * This program is free software; you can redistribute it and/or modify *
44949 + * it under the terms of the GNU General Public License as published by *
44950 + * the Free Software Foundation; either version 2 of the License, or *
44951 + * (at your option) any later version. *
44952 + * *
44953 + * This program is distributed in the hope that it will be useful, *
44954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
44955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
44956 + * GNU General Public License for more details. *
44957 + * *
44958 + * You should have received a copy of the GNU General Public License *
44959 + * along with this program; if not, write to the *
44960 + * Free Software Foundation, Inc., *
44961 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
44962 + * *
44963 + *************************************************************************
44964 + */
44965 +
44966 +#ifndef __LINK_LIST_H__
44967 +#define __LINK_LIST_H__
44968 +
44969 +typedef struct _LIST_ENTRY
44970 +{
44971 + struct _LIST_ENTRY *pNext;
44972 +} LIST_ENTRY, *PLIST_ENTRY;
44973 +
44974 +typedef struct _LIST_HEADR
44975 +{
44976 + PLIST_ENTRY pHead;
44977 + PLIST_ENTRY pTail;
44978 + UCHAR size;
44979 +} LIST_HEADER, *PLIST_HEADER;
44980 +
44981 +static inline VOID initList(
44982 + IN PLIST_HEADER pList)
44983 +{
44984 + pList->pHead = pList->pTail = NULL;
44985 + pList->size = 0;
44986 + return;
44987 +}
44988 +
44989 +static inline VOID insertTailList(
44990 + IN PLIST_HEADER pList,
44991 + IN PLIST_ENTRY pEntry)
44992 +{
44993 + pEntry->pNext = NULL;
44994 + if (pList->pTail)
44995 + pList->pTail->pNext = pEntry;
44996 + else
44997 + pList->pHead = pEntry;
44998 + pList->pTail = pEntry;
44999 + pList->size++;
45000 +
45001 + return;
45002 +}
45003 +
45004 +static inline PLIST_ENTRY removeHeadList(
45005 + IN PLIST_HEADER pList)
45006 +{
45007 + PLIST_ENTRY pNext;
45008 + PLIST_ENTRY pEntry;
45009 +
45010 + pEntry = pList->pHead;
45011 + if (pList->pHead != NULL)
45012 + {
45013 + pNext = pList->pHead->pNext;
45014 + pList->pHead = pNext;
45015 + if (pNext == NULL)
45016 + pList->pTail = NULL;
45017 + pList->size--;
45018 + }
45019 + return pEntry;
45020 +}
45021 +
45022 +static inline int getListSize(
45023 + IN PLIST_HEADER pList)
45024 +{
45025 + return pList->size;
45026 +}
45027 +
45028 +static inline PLIST_ENTRY delEntryList(
45029 + IN PLIST_HEADER pList,
45030 + IN PLIST_ENTRY pEntry)
45031 +{
45032 + PLIST_ENTRY pCurEntry;
45033 + PLIST_ENTRY pPrvEntry;
45034 +
45035 + if(pList->pHead == NULL)
45036 + return NULL;
45037 +
45038 + if(pEntry == pList->pHead)
45039 + {
45040 + pCurEntry = pList->pHead;
45041 + pList->pHead = pCurEntry->pNext;
45042 +
45043 + if(pList->pHead == NULL)
45044 + pList->pTail = NULL;
45045 +
45046 + pList->size--;
45047 + return pCurEntry;
45048 + }
45049 +
45050 + pPrvEntry = pList->pHead;
45051 + pCurEntry = pPrvEntry->pNext;
45052 + while(pCurEntry != NULL)
45053 + {
45054 + if (pEntry == pCurEntry)
45055 + {
45056 + pPrvEntry->pNext = pCurEntry->pNext;
45057 +
45058 + if(pEntry == pList->pTail)
45059 + pList->pTail = pPrvEntry;
45060 +
45061 + pList->size--;
45062 + break;
45063 + }
45064 + pPrvEntry = pCurEntry;
45065 + pCurEntry = pPrvEntry->pNext;
45066 + }
45067 +
45068 + return pCurEntry;
45069 +}
45070 +
45071 +#endif // ___LINK_LIST_H__ //
45072 +
45073 --- /dev/null
45074 +++ b/drivers/staging/rt3070/Makefile
45075 @@ -0,0 +1,47 @@
45076 +obj-$(CONFIG_RT3070) += rt3070sta.o
45077 +
45078 +# TODO: all of these should be removed
45079 +EXTRA_CFLAGS += -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT
45080 +EXTRA_CFLAGS += -DRT2870 -DRT30xx -DRT3070
45081 +EXTRA_CFLAGS += -DCONFIG_STA_SUPPORT
45082 +EXTRA_CFLAGS += -DDBG
45083 +EXTRA_CFLAGS += -DDOT11_N_SUPPORT
45084 +EXTRA_CFLAGS += -DWPA_SUPPLICANT_SUPPORT
45085 +EXTRA_CFLAGS += -DNATIVE_WPA_SUPPLICANT_SUPPORT
45086 +
45087 +rt3070sta-objs := \
45088 + common/md5.o \
45089 + common/mlme.o \
45090 + common/rtmp_wep.o \
45091 + common/action.o \
45092 + common/cmm_data.o \
45093 + common/rtmp_init.o \
45094 + common/rtmp_tkip.o \
45095 + common/cmm_sync.o \
45096 + common/eeprom.o \
45097 + common/cmm_sanity.o \
45098 + common/cmm_info.o \
45099 + common/cmm_wpa.o \
45100 + common/dfs.o \
45101 + common/spectrum.o \
45102 + sta/assoc.o \
45103 + sta/aironet.o \
45104 + sta/auth.o \
45105 + sta/auth_rsp.o \
45106 + sta/sync.o \
45107 + sta/sanity.o \
45108 + sta/rtmp_data.o \
45109 + sta/connect.o \
45110 + sta/wpa.o \
45111 + rt_linux.o \
45112 + rt_profile.o \
45113 + rt_main_dev.o \
45114 + sta_ioctl.o \
45115 + common/ba_action.o \
45116 + 2870_main_dev.o \
45117 + common/2870_rtmp_init.o \
45118 + common/rtusb_io.o \
45119 + common/rtusb_bulk.o \
45120 + common/rtusb_data.o \
45121 + common/cmm_data_2870.o
45122 +
45123 --- /dev/null
45124 +++ b/drivers/staging/rt3070/md4.h
45125 @@ -0,0 +1,42 @@
45126 +/*
45127 + *************************************************************************
45128 + * Ralink Tech Inc.
45129 + * 5F., No.36, Taiyuan St., Jhubei City,
45130 + * Hsinchu County 302,
45131 + * Taiwan, R.O.C.
45132 + *
45133 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
45134 + *
45135 + * This program is free software; you can redistribute it and/or modify *
45136 + * it under the terms of the GNU General Public License as published by *
45137 + * the Free Software Foundation; either version 2 of the License, or *
45138 + * (at your option) any later version. *
45139 + * *
45140 + * This program is distributed in the hope that it will be useful, *
45141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
45142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
45143 + * GNU General Public License for more details. *
45144 + * *
45145 + * You should have received a copy of the GNU General Public License *
45146 + * along with this program; if not, write to the *
45147 + * Free Software Foundation, Inc., *
45148 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
45149 + * *
45150 + *************************************************************************
45151 + */
45152 +
45153 +#ifndef __MD4_H__
45154 +#define __MD4_H__
45155 +
45156 +/* MD4 context. */
45157 +typedef struct _MD4_CTX_ {
45158 + ULONG state[4]; /* state (ABCD) */
45159 + ULONG count[2]; /* number of bits, modulo 2^64 (lsb first) */
45160 + UCHAR buffer[64]; /* input buffer */
45161 +} MD4_CTX;
45162 +
45163 +VOID MD4Init (MD4_CTX *);
45164 +VOID MD4Update (MD4_CTX *, PUCHAR, UINT);
45165 +VOID MD4Final (UCHAR [16], MD4_CTX *);
45166 +
45167 +#endif //__MD4_H__
45168 \ No newline at end of file
45169 --- /dev/null
45170 +++ b/drivers/staging/rt3070/md5.h
45171 @@ -0,0 +1,107 @@
45172 +/*
45173 + *************************************************************************
45174 + * Ralink Tech Inc.
45175 + * 5F., No.36, Taiyuan St., Jhubei City,
45176 + * Hsinchu County 302,
45177 + * Taiwan, R.O.C.
45178 + *
45179 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
45180 + *
45181 + * This program is free software; you can redistribute it and/or modify *
45182 + * it under the terms of the GNU General Public License as published by *
45183 + * the Free Software Foundation; either version 2 of the License, or *
45184 + * (at your option) any later version. *
45185 + * *
45186 + * This program is distributed in the hope that it will be useful, *
45187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
45188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
45189 + * GNU General Public License for more details. *
45190 + * *
45191 + * You should have received a copy of the GNU General Public License *
45192 + * along with this program; if not, write to the *
45193 + * Free Software Foundation, Inc., *
45194 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
45195 + * *
45196 + *************************************************************************
45197 +
45198 + Module Name:
45199 + md5.h
45200 +
45201 + Abstract:
45202 +
45203 + Revision History:
45204 + Who When What
45205 + -------- ---------- ----------------------------------------------
45206 + Name Date Modification logs
45207 + jan 10-28-03 Initial
45208 + Rita 11-23-04 Modify MD5 and SHA-1
45209 +*/
45210 +
45211 +#ifndef uint8
45212 +#define uint8 unsigned char
45213 +#endif
45214 +
45215 +#ifndef uint32
45216 +#define uint32 unsigned long int
45217 +#endif
45218 +
45219 +
45220 +#ifndef __MD5_H__
45221 +#define __MD5_H__
45222 +
45223 +#define MD5_MAC_LEN 16
45224 +
45225 +typedef struct _MD5_CTX {
45226 + UINT32 Buf[4]; // buffers of four states
45227 + UCHAR Input[64]; // input message
45228 + UINT32 LenInBitCount[2]; // length counter for input message, 0 up to 64 bits
45229 +} MD5_CTX;
45230 +
45231 +VOID MD5Init(MD5_CTX *pCtx);
45232 +VOID MD5Update(MD5_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes);
45233 +VOID MD5Final(UCHAR Digest[16], MD5_CTX *pCtx);
45234 +VOID MD5Transform(UINT32 Buf[4], UINT32 Mes[16]);
45235 +
45236 +void md5_mac(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac);
45237 +void hmac_md5(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac);
45238 +
45239 +//
45240 +// SHA context
45241 +//
45242 +typedef struct _SHA_CTX
45243 +{
45244 + UINT32 Buf[5]; // buffers of five states
45245 + UCHAR Input[80]; // input message
45246 + UINT32 LenInBitCount[2]; // length counter for input message, 0 up to 64 bits
45247 +
45248 +} SHA_CTX;
45249 +
45250 +VOID SHAInit(SHA_CTX *pCtx);
45251 +UCHAR SHAUpdate(SHA_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes);
45252 +VOID SHAFinal(SHA_CTX *pCtx, UCHAR Digest[20]);
45253 +VOID SHATransform(UINT32 Buf[5], UINT32 Mes[20]);
45254 +
45255 +#define SHA_DIGEST_LEN 20
45256 +#endif // __MD5_H__
45257 +
45258 +/******************************************************************************/
45259 +#ifndef _AES_H
45260 +#define _AES_H
45261 +
45262 +typedef struct
45263 +{
45264 + uint32 erk[64]; /* encryption round keys */
45265 + uint32 drk[64]; /* decryption round keys */
45266 + int nr; /* number of rounds */
45267 +}
45268 +aes_context;
45269 +
45270 +int rtmp_aes_set_key( aes_context *ctx, uint8 *key, int nbits );
45271 +void rtmp_aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
45272 +void rtmp_aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
45273 +
45274 +void F(char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output);
45275 +int PasswordHash(char *password, unsigned char *ssid, int ssidlength, unsigned char *output);
45276 +
45277 +#endif /* aes.h */
45278 +
45279 --- /dev/null
45280 +++ b/drivers/staging/rt3070/mlme.h
45281 @@ -0,0 +1,1468 @@
45282 +/*
45283 + *************************************************************************
45284 + * Ralink Tech Inc.
45285 + * 5F., No.36, Taiyuan St., Jhubei City,
45286 + * Hsinchu County 302,
45287 + * Taiwan, R.O.C.
45288 + *
45289 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
45290 + *
45291 + * This program is free software; you can redistribute it and/or modify *
45292 + * it under the terms of the GNU General Public License as published by *
45293 + * the Free Software Foundation; either version 2 of the License, or *
45294 + * (at your option) any later version. *
45295 + * *
45296 + * This program is distributed in the hope that it will be useful, *
45297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
45298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
45299 + * GNU General Public License for more details. *
45300 + * *
45301 + * You should have received a copy of the GNU General Public License *
45302 + * along with this program; if not, write to the *
45303 + * Free Software Foundation, Inc., *
45304 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
45305 + * *
45306 + *************************************************************************
45307 +
45308 + Module Name:
45309 + mlme.h
45310 +
45311 + Abstract:
45312 +
45313 + Revision History:
45314 + Who When What
45315 + -------- ---------- ----------------------------------------------
45316 + John Chang 2003-08-28 Created
45317 + John Chang 2004-09-06 modified for RT2600
45318 +
45319 +*/
45320 +#ifndef __MLME_H__
45321 +#define __MLME_H__
45322 +
45323 +//extern UCHAR BROADCAST_ADDR[];
45324 +
45325 +// maximum supported capability information -
45326 +// ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot
45327 +#define SUPPORTED_CAPABILITY_INFO 0x0533
45328 +
45329 +#define END_OF_ARGS -1
45330 +#define LFSR_MASK 0x80000057
45331 +#define MLME_TASK_EXEC_INTV 100/*200*/ //
45332 +#define LEAD_TIME 5
45333 +#define MLME_TASK_EXEC_MULTIPLE 10 /*5*/ // MLME_TASK_EXEC_MULTIPLE * MLME_TASK_EXEC_INTV = 1 sec
45334 +#define REORDER_EXEC_INTV 100 // 0.1 sec
45335 +//#define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
45336 +
45337 +// The definition of Radar detection duration region
45338 +#define CE 0
45339 +#define FCC 1
45340 +#define JAP 2
45341 +#define JAP_W53 3
45342 +#define JAP_W56 4
45343 +#define MAX_RD_REGION 5
45344 +
45345 +#ifdef NDIS51_MINIPORT
45346 +#define BEACON_LOST_TIME 4000 // 2048 msec = 2 sec
45347 +#else
45348 +#define BEACON_LOST_TIME 4 * OS_HZ // 2048 msec = 2 sec
45349 +#endif
45350 +
45351 +#define DLS_TIMEOUT 1200 // unit: msec
45352 +#define AUTH_TIMEOUT 300 // unit: msec
45353 +#define ASSOC_TIMEOUT 300 // unit: msec
45354 +#define JOIN_TIMEOUT 2 * OS_HZ // unit: msec
45355 +#define SHORT_CHANNEL_TIME 90 // unit: msec
45356 +#define MIN_CHANNEL_TIME 110 // unit: msec, for dual band scan
45357 +#define MAX_CHANNEL_TIME 140 // unit: msec, for single band scan
45358 +#define FAST_ACTIVE_SCAN_TIME 30 // Active scan waiting for probe response time
45359 +#define CW_MIN_IN_BITS 4 // actual CwMin = 2^CW_MIN_IN_BITS - 1
45360 +
45361 +
45362 +#ifdef CONFIG_STA_SUPPORT
45363 +#ifndef CONFIG_AP_SUPPORT
45364 +#define CW_MAX_IN_BITS 10 // actual CwMax = 2^CW_MAX_IN_BITS - 1
45365 +#endif
45366 +#endif // CONFIG_STA_SUPPORT //
45367 +
45368 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
45369 +extern UINT32 CW_MAX_IN_BITS;
45370 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
45371 +
45372 +// Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720).
45373 +// SHould not refer to this constant anymore
45374 +//#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm
45375 +#define RSSI_FOR_MID_TX_POWER -55 // -55 db is considered mid-distance
45376 +#define RSSI_FOR_LOW_TX_POWER -45 // -45 db is considered very short distance and
45377 + // eligible to use a lower TX power
45378 +#define RSSI_FOR_LOWEST_TX_POWER -30
45379 +//#define MID_TX_POWER_DELTA 0 // 0 db from full TX power upon mid-distance to AP
45380 +#define LOW_TX_POWER_DELTA 6 // -3 db from full TX power upon very short distance. 1 grade is 0.5 db
45381 +#define LOWEST_TX_POWER_DELTA 16 // -8 db from full TX power upon shortest distance. 1 grade is 0.5 db
45382 +
45383 +#define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0
45384 +#define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1
45385 +#define RSSI_THRESHOLD_FOR_ROAMING 25
45386 +#define RSSI_DELTA 5
45387 +
45388 +// Channel Quality Indication
45389 +#define CQI_IS_GOOD(cqi) ((cqi) >= 50)
45390 +//#define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50))
45391 +#define CQI_IS_POOR(cqi) (cqi < 50) //(((cqi) >= 5) && ((cqi) < 20))
45392 +#define CQI_IS_BAD(cqi) (cqi < 5)
45393 +#define CQI_IS_DEAD(cqi) (cqi == 0)
45394 +
45395 +// weighting factor to calculate Channel quality, total should be 100%
45396 +#define RSSI_WEIGHTING 50
45397 +#define TX_WEIGHTING 30
45398 +#define RX_WEIGHTING 20
45399 +
45400 +//#define PEER_KEY_NOT_USED 0
45401 +//#define PEER_KEY_64_BIT 64
45402 +//#define PEER_KEY_128_BIT 128
45403 +
45404 +//#define PEER_KEY_64BIT_LEN 8
45405 +//#define PEER_KEY_128BIT_LEN 16
45406 +
45407 +#define BSS_NOT_FOUND 0xFFFFFFFF
45408 +
45409 +
45410 +#ifdef CONFIG_STA_SUPPORT
45411 +#define MAX_LEN_OF_MLME_QUEUE 40 //10
45412 +#endif // CONFIG_STA_SUPPORT //
45413 +
45414 +#define SCAN_PASSIVE 18 // scan with no probe request, only wait beacon and probe response
45415 +#define SCAN_ACTIVE 19 // scan with probe request, and wait beacon and probe response
45416 +#define SCAN_CISCO_PASSIVE 20 // Single channel passive scan
45417 +#define SCAN_CISCO_ACTIVE 21 // Single channel active scan
45418 +#define SCAN_CISCO_NOISE 22 // Single channel passive scan for noise histogram collection
45419 +#define SCAN_CISCO_CHANNEL_LOAD 23 // Single channel passive scan for channel load collection
45420 +#define FAST_SCAN_ACTIVE 24 // scan with probe request, and wait beacon and probe response
45421 +
45422 +#ifdef DOT11N_DRAFT3
45423 +#define SCAN_2040_BSS_COEXIST 26
45424 +#endif // DOT11N_DRAFT3 //
45425 +
45426 +//#define BSS_TABLE_EMPTY(x) ((x).BssNr == 0)
45427 +#define MAC_ADDR_IS_GROUP(Addr) (((Addr[0]) & 0x01))
45428 +#define MAC_ADDR_HASH(Addr) (Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
45429 +#define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
45430 +#define TID_MAC_HASH(Addr,TID) (TID^Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
45431 +#define TID_MAC_HASH_INDEX(Addr,TID) (TID_MAC_HASH(Addr,TID) % HASH_TABLE_SIZE)
45432 +
45433 +// LED Control
45434 +// assoiation ON. one LED ON. another blinking when TX, OFF when idle
45435 +// no association, both LED off
45436 +#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46)
45437 +#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46)
45438 +
45439 +// bit definition of the 2-byte pBEACON->Capability field
45440 +#define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0)
45441 +#define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0)
45442 +#define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0)
45443 +#define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0)
45444 +#define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0)
45445 +#define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0)
45446 +#define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0)
45447 +#define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0)
45448 +#define CAP_IS_SPECTRUM_MGMT(x) (((x) & 0x0100) != 0) // 802.11e d9
45449 +#define CAP_IS_QOS(x) (((x) & 0x0200) != 0) // 802.11e d9
45450 +#define CAP_IS_SHORT_SLOT(x) (((x) & 0x0400) != 0)
45451 +#define CAP_IS_APSD(x) (((x) & 0x0800) != 0) // 802.11e d9
45452 +#define CAP_IS_IMMED_BA(x) (((x) & 0x1000) != 0) // 802.11e d9
45453 +#define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0)
45454 +#define CAP_IS_DELAY_BA(x) (((x) & 0x4000) != 0) // 802.11e d9
45455 +
45456 +#define CAP_GENERATE(ess,ibss,priv,s_pre,s_slot,spectrum) (((ess) ? 0x0001 : 0x0000) | ((ibss) ? 0x0002 : 0x0000) | ((priv) ? 0x0010 : 0x0000) | ((s_pre) ? 0x0020 : 0x0000) | ((s_slot) ? 0x0400 : 0x0000) | ((spectrum) ? 0x0100 : 0x0000))
45457 +
45458 +//#define STA_QOS_CAPABILITY 0 // 1-byte. see 802.11e d9.0 for bit definition
45459 +
45460 +#define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) // 802.11g
45461 +#define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) // 802.11g
45462 +#define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) // 802.11g
45463 +
45464 +#define DRS_TX_QUALITY_WORST_BOUND 8// 3 // just test by gary
45465 +#define DRS_PENALTY 8
45466 +
45467 +#define BA_NOTUSE 2
45468 +//BA Policy subfiled value in ADDBA frame
45469 +#define IMMED_BA 1
45470 +#define DELAY_BA 0
45471 +
45472 +// BA Initiator subfield in DELBA frame
45473 +#define ORIGINATOR 1
45474 +#define RECIPIENT 0
45475 +
45476 +// ADDBA Status Code
45477 +#define ADDBA_RESULTCODE_SUCCESS 0
45478 +#define ADDBA_RESULTCODE_REFUSED 37
45479 +#define ADDBA_RESULTCODE_INVALID_PARAMETERS 38
45480 +
45481 +// DELBA Reason Code
45482 +#define DELBA_REASONCODE_QSTA_LEAVING 36
45483 +#define DELBA_REASONCODE_END_BA 37
45484 +#define DELBA_REASONCODE_UNKNOWN_BA 38
45485 +#define DELBA_REASONCODE_TIMEOUT 39
45486 +
45487 +// reset all OneSecTx counters
45488 +#define RESET_ONE_SEC_TX_CNT(__pEntry) \
45489 +if (((__pEntry)) != NULL) \
45490 +{ \
45491 + (__pEntry)->OneSecTxRetryOkCount = 0; \
45492 + (__pEntry)->OneSecTxFailCount = 0; \
45493 + (__pEntry)->OneSecTxNoRetryOkCount = 0; \
45494 +}
45495 +
45496 +//
45497 +// 802.11 frame formats
45498 +//
45499 +// HT Capability INFO field in HT Cap IE .
45500 +typedef struct PACKED {
45501 +#ifdef RT_BIG_ENDIAN
45502 + USHORT LSIGTxopProSup:1;
45503 + USHORT Forty_Mhz_Intolerant:1;
45504 + USHORT PSMP:1;
45505 + USHORT CCKmodein40:1;
45506 + USHORT AMsduSize:1;
45507 + USHORT DelayedBA:1; //rt2860c not support
45508 + USHORT RxSTBC:2;
45509 + USHORT TxSTBC:1;
45510 + USHORT ShortGIfor40:1; //for40MHz
45511 + USHORT ShortGIfor20:1;
45512 + USHORT GF:1; //green field
45513 + USHORT MimoPs:2;//momi power safe
45514 + USHORT ChannelWidth:1;
45515 + USHORT AdvCoding:1;
45516 +#else
45517 + USHORT AdvCoding:1;
45518 + USHORT ChannelWidth:1;
45519 + USHORT MimoPs:2;//momi power safe
45520 + USHORT GF:1; //green field
45521 + USHORT ShortGIfor20:1;
45522 + USHORT ShortGIfor40:1; //for40MHz
45523 + USHORT TxSTBC:1;
45524 + USHORT RxSTBC:2;
45525 + USHORT DelayedBA:1; //rt2860c not support
45526 + USHORT AMsduSize:1; // only support as zero
45527 + USHORT CCKmodein40:1;
45528 + USHORT PSMP:1;
45529 + USHORT Forty_Mhz_Intolerant:1;
45530 + USHORT LSIGTxopProSup:1;
45531 +#endif /* !RT_BIG_ENDIAN */
45532 +} HT_CAP_INFO, *PHT_CAP_INFO;
45533 +
45534 +// HT Capability INFO field in HT Cap IE .
45535 +typedef struct PACKED {
45536 +#ifdef RT_BIG_ENDIAN
45537 + UCHAR rsv:3;//momi power safe
45538 + UCHAR MpduDensity:3;
45539 + UCHAR MaxRAmpduFactor:2;
45540 +#else
45541 + UCHAR MaxRAmpduFactor:2;
45542 + UCHAR MpduDensity:3;
45543 + UCHAR rsv:3;//momi power safe
45544 +#endif /* !RT_BIG_ENDIAN */
45545 +} HT_CAP_PARM, *PHT_CAP_PARM;
45546 +
45547 +// HT Capability INFO field in HT Cap IE .
45548 +typedef struct PACKED {
45549 + UCHAR MCSSet[10];
45550 + UCHAR SupRate[2]; // unit : 1Mbps
45551 +#ifdef RT_BIG_ENDIAN
45552 + UCHAR rsv:3;
45553 + UCHAR MpduDensity:1;
45554 + UCHAR TxStream:2;
45555 + UCHAR TxRxNotEqual:1;
45556 + UCHAR TxMCSSetDefined:1;
45557 +#else
45558 + UCHAR TxMCSSetDefined:1;
45559 + UCHAR TxRxNotEqual:1;
45560 + UCHAR TxStream:2;
45561 + UCHAR MpduDensity:1;
45562 + UCHAR rsv:3;
45563 +#endif // RT_BIG_ENDIAN //
45564 + UCHAR rsv3[3];
45565 +} HT_MCS_SET, *PHT_MCS_SET;
45566 +
45567 +// HT Capability INFO field in HT Cap IE .
45568 +typedef struct PACKED {
45569 +#ifdef RT_BIG_ENDIAN
45570 + USHORT rsv2:4;
45571 + USHORT RDGSupport:1; //reverse Direction Grant support
45572 + USHORT PlusHTC:1; //+HTC control field support
45573 + USHORT MCSFeedback:2; //0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv.
45574 + USHORT rsv:5;//momi power safe
45575 + USHORT TranTime:2;
45576 + USHORT Pco:1;
45577 +#else
45578 + USHORT Pco:1;
45579 + USHORT TranTime:2;
45580 + USHORT rsv:5;//momi power safe
45581 + USHORT MCSFeedback:2; //0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv.
45582 + USHORT PlusHTC:1; //+HTC control field support
45583 + USHORT RDGSupport:1; //reverse Direction Grant support
45584 + USHORT rsv2:4;
45585 +#endif /* RT_BIG_ENDIAN */
45586 +} EXT_HT_CAP_INFO, *PEXT_HT_CAP_INFO;
45587 +
45588 +// HT Beamforming field in HT Cap IE .
45589 +typedef struct PACKED _HT_BF_CAP{
45590 +#ifdef RT_BIG_ENDIAN
45591 + ULONG rsv:3;
45592 + ULONG ChanEstimation:2;
45593 + ULONG CSIRowBFSup:2;
45594 + ULONG ComSteerBFAntSup:2;
45595 + ULONG NoComSteerBFAntSup:2;
45596 + ULONG CSIBFAntSup:2;
45597 + ULONG MinGrouping:2;
45598 + ULONG ExpComBF:2;
45599 + ULONG ExpNoComBF:2;
45600 + ULONG ExpCSIFbk:2;
45601 + ULONG ExpComSteerCapable:1;
45602 + ULONG ExpNoComSteerCapable:1;
45603 + ULONG ExpCSICapable:1;
45604 + ULONG Calibration:2;
45605 + ULONG ImpTxBFCapable:1;
45606 + ULONG TxNDPCapable:1;
45607 + ULONG RxNDPCapable:1;
45608 + ULONG TxSoundCapable:1;
45609 + ULONG RxSoundCapable:1;
45610 + ULONG TxBFRecCapable:1;
45611 +#else
45612 + ULONG TxBFRecCapable:1;
45613 + ULONG RxSoundCapable:1;
45614 + ULONG TxSoundCapable:1;
45615 + ULONG RxNDPCapable:1;
45616 + ULONG TxNDPCapable:1;
45617 + ULONG ImpTxBFCapable:1;
45618 + ULONG Calibration:2;
45619 + ULONG ExpCSICapable:1;
45620 + ULONG ExpNoComSteerCapable:1;
45621 + ULONG ExpComSteerCapable:1;
45622 + ULONG ExpCSIFbk:2;
45623 + ULONG ExpNoComBF:2;
45624 + ULONG ExpComBF:2;
45625 + ULONG MinGrouping:2;
45626 + ULONG CSIBFAntSup:2;
45627 + ULONG NoComSteerBFAntSup:2;
45628 + ULONG ComSteerBFAntSup:2;
45629 + ULONG CSIRowBFSup:2;
45630 + ULONG ChanEstimation:2;
45631 + ULONG rsv:3;
45632 +#endif // RT_BIG_ENDIAN //
45633 +} HT_BF_CAP, *PHT_BF_CAP;
45634 +
45635 +// HT antenna selection field in HT Cap IE .
45636 +typedef struct PACKED _HT_AS_CAP{
45637 +#ifdef RT_BIG_ENDIAN
45638 + UCHAR rsv:1;
45639 + UCHAR TxSoundPPDU:1;
45640 + UCHAR RxASel:1;
45641 + UCHAR AntIndFbk:1;
45642 + UCHAR ExpCSIFbk:1;
45643 + UCHAR AntIndFbkTxASEL:1;
45644 + UCHAR ExpCSIFbkTxASEL:1;
45645 + UCHAR AntSelect:1;
45646 +#else
45647 + UCHAR AntSelect:1;
45648 + UCHAR ExpCSIFbkTxASEL:1;
45649 + UCHAR AntIndFbkTxASEL:1;
45650 + UCHAR ExpCSIFbk:1;
45651 + UCHAR AntIndFbk:1;
45652 + UCHAR RxASel:1;
45653 + UCHAR TxSoundPPDU:1;
45654 + UCHAR rsv:1;
45655 +#endif // RT_BIG_ENDIAN //
45656 +} HT_AS_CAP, *PHT_AS_CAP;
45657 +
45658 +// Draft 1.0 set IE length 26, but is extensible..
45659 +#define SIZE_HT_CAP_IE 26
45660 +// The structure for HT Capability IE.
45661 +typedef struct PACKED _HT_CAPABILITY_IE{
45662 + HT_CAP_INFO HtCapInfo;
45663 + HT_CAP_PARM HtCapParm;
45664 +// HT_MCS_SET HtMCSSet;
45665 + UCHAR MCSSet[16];
45666 + EXT_HT_CAP_INFO ExtHtCapInfo;
45667 + HT_BF_CAP TxBFCap; // beamforming cap. rt2860c not support beamforming.
45668 + HT_AS_CAP ASCap; //antenna selection.
45669 +} HT_CAPABILITY_IE, *PHT_CAPABILITY_IE;
45670 +
45671 +
45672 +// 802.11n draft3 related structure definitions.
45673 +// 7.3.2.60
45674 +#define dot11OBSSScanPassiveDwell 20 // in TU. min amount of time that the STA continously scans each channel when performing an active OBSS scan.
45675 +#define dot11OBSSScanActiveDwell 10 // in TU.min amount of time that the STA continously scans each channel when performing an passive OBSS scan.
45676 +#define dot11BSSWidthTriggerScanInterval 300 // in sec. max interval between scan operations to be performed to detect BSS channel width trigger events.
45677 +#define dot11OBSSScanPassiveTotalPerChannel 200 // in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan.
45678 +#define dot11OBSSScanActiveTotalPerChannel 20 //in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan
45679 +#define dot11BSSWidthChannelTransactionDelayFactor 5 // min ratio between the delay time in performing a switch from 20MHz BSS to 20/40 BSS operation and the maxima
45680 + // interval between overlapping BSS scan operations.
45681 +#define dot11BSSScanActivityThreshold 25 // in %%, max total time that a STA may be active on the medium during a period of
45682 + // (dot11BSSWidthChannelTransactionDelayFactor * dot11BSSWidthTriggerScanInterval) seconds without
45683 + // being obligated to perform OBSS Scan operations. default is 25(== 0.25%)
45684 +
45685 +typedef struct PACKED _OVERLAP_BSS_SCAN_IE{
45686 + USHORT ScanPassiveDwell;
45687 + USHORT ScanActiveDwell;
45688 + USHORT TriggerScanInt; // Trigger scan interval
45689 + USHORT PassiveTalPerChannel; // passive total per channel
45690 + USHORT ActiveTalPerChannel; // active total per channel
45691 + USHORT DelayFactor; // BSS width channel transition delay factor
45692 + USHORT ScanActThre; // Scan Activity threshold
45693 +}OVERLAP_BSS_SCAN_IE, *POVERLAP_BSS_SCAN_IE;
45694 +
45695 +
45696 +// 7.3.2.56. 20/40 Coexistence element used in Element ID = 72 = IE_2040_BSS_COEXIST
45697 +typedef union PACKED _BSS_2040_COEXIST_IE{
45698 + struct PACKED {
45699 + #ifdef RT_BIG_ENDIAN
45700 + UCHAR rsv:5;
45701 + UCHAR BSS20WidthReq:1;
45702 + UCHAR Intolerant40:1;
45703 + UCHAR InfoReq:1;
45704 + #else
45705 + UCHAR InfoReq:1;
45706 + UCHAR Intolerant40:1; // Inter-BSS. set 1 when prohibits a receiving BSS from operating as a 20/40 Mhz BSS.
45707 + UCHAR BSS20WidthReq:1; // Intra-BSS set 1 when prohibits a receiving AP from operating its BSS as a 20/40MHz BSS.
45708 + UCHAR rsv:5;
45709 +#endif // RT_BIG_ENDIAN //
45710 + } field;
45711 + UCHAR word;
45712 +} BSS_2040_COEXIST_IE, *PBSS_2040_COEXIST_IE;
45713 +
45714 +
45715 +typedef struct _TRIGGER_EVENTA{
45716 + BOOLEAN bValid;
45717 + UCHAR BSSID[6];
45718 + UCHAR RegClass; // Regulatory Class
45719 + USHORT Channel;
45720 + ULONG CDCounter; // Maintain a seperate count down counter for each Event A.
45721 +} TRIGGER_EVENTA, *PTRIGGER_EVENTA;
45722 +
45723 +// 20/40 trigger event table
45724 +// If one Event A delete or created, or if Event B is detected or not detected, STA should send 2040BSSCoexistence to AP.
45725 +#define MAX_TRIGGER_EVENT 64
45726 +typedef struct _TRIGGER_EVENT_TAB{
45727 + UCHAR EventANo;
45728 + TRIGGER_EVENTA EventA[MAX_TRIGGER_EVENT];
45729 + ULONG EventBCountDown; // Count down counter for Event B.
45730 +} TRIGGER_EVENT_TAB, *PTRIGGER_EVENT_TAB;
45731 +
45732 +// 7.3.27 20/40 Bss Coexistence Mgmt capability used in extended capabilities information IE( ID = 127 = IE_EXT_CAPABILITY).
45733 +// This is the first octet and was defined in 802.11n D3.03 and 802.11yD9.0
45734 +typedef struct PACKED _EXT_CAP_INFO_ELEMENT{
45735 +#ifdef RT_BIG_ENDIAN
45736 + UCHAR rsv2:5;
45737 + UCHAR ExtendChannelSwitch:1;
45738 + UCHAR rsv:1;
45739 + UCHAR BssCoexistMgmtSupport:1;
45740 +#else
45741 + UCHAR BssCoexistMgmtSupport:1;
45742 + UCHAR rsv:1;
45743 + UCHAR ExtendChannelSwitch:1;
45744 + UCHAR rsv2:5;
45745 +#endif // RT_BIG_ENDIAN //
45746 +}EXT_CAP_INFO_ELEMENT, *PEXT_CAP_INFO_ELEMENT;
45747 +
45748 +
45749 +// 802.11n 7.3.2.61
45750 +typedef struct PACKED _BSS_2040_COEXIST_ELEMENT{
45751 + UCHAR ElementID; // ID = IE_2040_BSS_COEXIST = 72
45752 + UCHAR Len;
45753 + BSS_2040_COEXIST_IE BssCoexistIe;
45754 +}BSS_2040_COEXIST_ELEMENT, *PBSS_2040_COEXIST_ELEMENT;
45755 +
45756 +
45757 +//802.11n 7.3.2.59
45758 +typedef struct PACKED _BSS_2040_INTOLERANT_CH_REPORT{
45759 + UCHAR ElementID; // ID = IE_2040_BSS_INTOLERANT_REPORT = 73
45760 + UCHAR Len;
45761 + UCHAR RegulatoryClass;
45762 + UCHAR ChList[0];
45763 +}BSS_2040_INTOLERANT_CH_REPORT, *PBSS_2040_INTOLERANT_CH_REPORT;
45764 +
45765 +
45766 +// The structure for channel switch annoucement IE. This is in 802.11n D3.03
45767 +typedef struct PACKED _CHA_SWITCH_ANNOUNCE_IE{
45768 + UCHAR SwitchMode; //channel switch mode
45769 + UCHAR NewChannel; //
45770 + UCHAR SwitchCount; //
45771 +} CHA_SWITCH_ANNOUNCE_IE, *PCHA_SWITCH_ANNOUNCE_IE;
45772 +
45773 +
45774 +// The structure for channel switch annoucement IE. This is in 802.11n D3.03
45775 +typedef struct PACKED _SEC_CHA_OFFSET_IE{
45776 + UCHAR SecondaryChannelOffset; // 1: Secondary above, 3: Secondary below, 0: no Secondary
45777 +} SEC_CHA_OFFSET_IE, *PSEC_CHA_OFFSET_IE;
45778 +
45779 +
45780 +// This structure is extracted from struct RT_HT_CAPABILITY
45781 +typedef struct {
45782 + BOOLEAN bHtEnable; // If we should use ht rate.
45783 + BOOLEAN bPreNHt; // If we should use ht rate.
45784 + //Substract from HT Capability IE
45785 + UCHAR MCSSet[16]; //only supoort MCS=0-15,32 ,
45786 +} RT_HT_PHY_INFO, *PRT_HT_PHY_INFO;
45787 +
45788 +//This structure substracts ralink supports from all 802.11n-related features.
45789 +//Features not listed here but contained in 802.11n spec are not supported in rt2860.
45790 +typedef struct {
45791 +#ifdef RT_BIG_ENDIAN
45792 + USHORT rsv:5;
45793 + USHORT AmsduSize:1; // Max receiving A-MSDU size
45794 + USHORT AmsduEnable:1; // Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n
45795 + USHORT RxSTBC:2; // 2 bits
45796 + USHORT TxSTBC:1;
45797 + USHORT ShortGIfor40:1; //for40MHz
45798 + USHORT ShortGIfor20:1;
45799 + USHORT GF:1; //green field
45800 + USHORT MimoPs:2;//mimo power safe MMPS_
45801 + USHORT ChannelWidth:1;
45802 +#else
45803 + USHORT ChannelWidth:1;
45804 + USHORT MimoPs:2;//mimo power safe MMPS_
45805 + USHORT GF:1; //green field
45806 + USHORT ShortGIfor20:1;
45807 + USHORT ShortGIfor40:1; //for40MHz
45808 + USHORT TxSTBC:1;
45809 + USHORT RxSTBC:2; // 2 bits
45810 + USHORT AmsduEnable:1; // Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n
45811 + USHORT AmsduSize:1; // Max receiving A-MSDU size
45812 + USHORT rsv:5;
45813 +#endif
45814 +
45815 + //Substract from Addiont HT INFO IE
45816 +#ifdef RT_BIG_ENDIAN
45817 + UCHAR RecomWidth:1;
45818 + UCHAR ExtChanOffset:2; // Please not the difference with following UCHAR NewExtChannelOffset; from 802.11n
45819 + UCHAR MpduDensity:3;
45820 + UCHAR MaxRAmpduFactor:2;
45821 +#else
45822 + UCHAR MaxRAmpduFactor:2;
45823 + UCHAR MpduDensity:3;
45824 + UCHAR ExtChanOffset:2; // Please not the difference with following UCHAR NewExtChannelOffset; from 802.11n
45825 + UCHAR RecomWidth:1;
45826 +#endif
45827 +
45828 +#ifdef RT_BIG_ENDIAN
45829 + USHORT rsv2:11;
45830 + USHORT OBSS_NonHTExist:1;
45831 + USHORT rsv3:1;
45832 + USHORT NonGfPresent:1;
45833 + USHORT OperaionMode:2;
45834 +#else
45835 + USHORT OperaionMode:2;
45836 + USHORT NonGfPresent:1;
45837 + USHORT rsv3:1;
45838 + USHORT OBSS_NonHTExist:1;
45839 + USHORT rsv2:11;
45840 +#endif
45841 +
45842 + // New Extension Channel Offset IE
45843 + UCHAR NewExtChannelOffset;
45844 + // Extension Capability IE = 127
45845 + UCHAR BSSCoexist2040;
45846 +} RT_HT_CAPABILITY, *PRT_HT_CAPABILITY;
45847 +
45848 +// field in Addtional HT Information IE .
45849 +typedef struct PACKED {
45850 +#ifdef RT_BIG_ENDIAN
45851 + UCHAR SerInterGranu:3;
45852 + UCHAR S_PSMPSup:1;
45853 + UCHAR RifsMode:1;
45854 + UCHAR RecomWidth:1;
45855 + UCHAR ExtChanOffset:2;
45856 +#else
45857 + UCHAR ExtChanOffset:2;
45858 + UCHAR RecomWidth:1;
45859 + UCHAR RifsMode:1;
45860 + UCHAR S_PSMPSup:1; //Indicate support for scheduled PSMP
45861 + UCHAR SerInterGranu:3; //service interval granularity
45862 +#endif
45863 +} ADD_HTINFO, *PADD_HTINFO;
45864 +
45865 +typedef struct PACKED{
45866 +#ifdef RT_BIG_ENDIAN
45867 + USHORT rsv2:11;
45868 + USHORT OBSS_NonHTExist:1;
45869 + USHORT rsv:1;
45870 + USHORT NonGfPresent:1;
45871 + USHORT OperaionMode:2;
45872 +#else
45873 + USHORT OperaionMode:2;
45874 + USHORT NonGfPresent:1;
45875 + USHORT rsv:1;
45876 + USHORT OBSS_NonHTExist:1;
45877 + USHORT rsv2:11;
45878 +#endif
45879 +} ADD_HTINFO2, *PADD_HTINFO2;
45880 +
45881 +
45882 +// TODO: Need sync with spec about the definition of StbcMcs. In Draft 3.03, it's reserved.
45883 +typedef struct PACKED{
45884 +#ifdef RT_BIG_ENDIAN
45885 + USHORT rsv:4;
45886 + USHORT PcoPhase:1;
45887 + USHORT PcoActive:1;
45888 + USHORT LsigTxopProt:1;
45889 + USHORT STBCBeacon:1;
45890 + USHORT DualCTSProtect:1;
45891 + USHORT DualBeacon:1;
45892 + USHORT StbcMcs:6;
45893 +#else
45894 + USHORT StbcMcs:6;
45895 + USHORT DualBeacon:1;
45896 + USHORT DualCTSProtect:1;
45897 + USHORT STBCBeacon:1;
45898 + USHORT LsigTxopProt:1; // L-SIG TXOP protection full support
45899 + USHORT PcoActive:1;
45900 + USHORT PcoPhase:1;
45901 + USHORT rsv:4;
45902 +#endif // RT_BIG_ENDIAN //
45903 +} ADD_HTINFO3, *PADD_HTINFO3;
45904 +
45905 +#define SIZE_ADD_HT_INFO_IE 22
45906 +typedef struct PACKED{
45907 + UCHAR ControlChan;
45908 + ADD_HTINFO AddHtInfo;
45909 + ADD_HTINFO2 AddHtInfo2;
45910 + ADD_HTINFO3 AddHtInfo3;
45911 + UCHAR MCSSet[16]; // Basic MCS set
45912 +} ADD_HT_INFO_IE, *PADD_HT_INFO_IE;
45913 +
45914 +typedef struct PACKED{
45915 + UCHAR NewExtChanOffset;
45916 +} NEW_EXT_CHAN_IE, *PNEW_EXT_CHAN_IE;
45917 +
45918 +
45919 +// 4-byte HTC field. maybe included in any frame except non-QOS data frame. The Order bit must set 1.
45920 +typedef struct PACKED {
45921 +#ifdef RT_BIG_ENDIAN
45922 + UINT32 RDG:1; //RDG / More PPDU
45923 + UINT32 ACConstraint:1; //feedback request
45924 + UINT32 rsv:5; //calibration sequence
45925 + UINT32 ZLFAnnouce:1; // ZLF announcement
45926 + UINT32 CSISTEERING:2; //CSI/ STEERING
45927 + UINT32 FBKReq:2; //feedback request
45928 + UINT32 CalSeq:2; //calibration sequence
45929 + UINT32 CalPos:2; // calibration position
45930 + UINT32 MFBorASC:7; //Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available
45931 + UINT32 MFS:3; //SET to the received value of MRS. 0x111 for unsolicited MFB.
45932 + UINT32 MRSorASI:3; // MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110.
45933 + UINT32 MRQ:1; //MCS feedback. Request for a MCS feedback
45934 + UINT32 TRQ:1; //sounding request
45935 + UINT32 MA:1; //management action payload exist in (QoS Null+HTC)
45936 +#else
45937 + UINT32 MA:1; //management action payload exist in (QoS Null+HTC)
45938 + UINT32 TRQ:1; //sounding request
45939 + UINT32 MRQ:1; //MCS feedback. Request for a MCS feedback
45940 + UINT32 MRSorASI:3; // MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110.
45941 + UINT32 MFS:3; //SET to the received value of MRS. 0x111 for unsolicited MFB.
45942 + UINT32 MFBorASC:7; //Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available
45943 + UINT32 CalPos:2; // calibration position
45944 + UINT32 CalSeq:2; //calibration sequence
45945 + UINT32 FBKReq:2; //feedback request
45946 + UINT32 CSISTEERING:2; //CSI/ STEERING
45947 + UINT32 ZLFAnnouce:1; // ZLF announcement
45948 + UINT32 rsv:5; //calibration sequence
45949 + UINT32 ACConstraint:1; //feedback request
45950 + UINT32 RDG:1; //RDG / More PPDU
45951 +#endif /* !RT_BIG_ENDIAN */
45952 +} HT_CONTROL, *PHT_CONTROL;
45953 +
45954 +// 2-byte QOS CONTROL field
45955 +typedef struct PACKED {
45956 +#ifdef RT_BIG_ENDIAN
45957 + USHORT Txop_QueueSize:8;
45958 + USHORT AMsduPresent:1;
45959 + USHORT AckPolicy:2; //0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA
45960 + USHORT EOSP:1;
45961 + USHORT TID:4;
45962 +#else
45963 + USHORT TID:4;
45964 + USHORT EOSP:1;
45965 + USHORT AckPolicy:2; //0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA
45966 + USHORT AMsduPresent:1;
45967 + USHORT Txop_QueueSize:8;
45968 +#endif /* !RT_BIG_ENDIAN */
45969 +} QOS_CONTROL, *PQOS_CONTROL;
45970 +
45971 +// 2-byte Frame control field
45972 +typedef struct PACKED {
45973 +#ifdef RT_BIG_ENDIAN
45974 + USHORT Order:1; // Strict order expected
45975 + USHORT Wep:1; // Wep data
45976 + USHORT MoreData:1; // More data bit
45977 + USHORT PwrMgmt:1; // Power management bit
45978 + USHORT Retry:1; // Retry status bit
45979 + USHORT MoreFrag:1; // More fragment bit
45980 + USHORT FrDs:1; // From DS indication
45981 + USHORT ToDs:1; // To DS indication
45982 + USHORT SubType:4; // MSDU subtype
45983 + USHORT Type:2; // MSDU type
45984 + USHORT Ver:2; // Protocol version
45985 +#else
45986 + USHORT Ver:2; // Protocol version
45987 + USHORT Type:2; // MSDU type
45988 + USHORT SubType:4; // MSDU subtype
45989 + USHORT ToDs:1; // To DS indication
45990 + USHORT FrDs:1; // From DS indication
45991 + USHORT MoreFrag:1; // More fragment bit
45992 + USHORT Retry:1; // Retry status bit
45993 + USHORT PwrMgmt:1; // Power management bit
45994 + USHORT MoreData:1; // More data bit
45995 + USHORT Wep:1; // Wep data
45996 + USHORT Order:1; // Strict order expected
45997 +#endif /* !RT_BIG_ENDIAN */
45998 +} FRAME_CONTROL, *PFRAME_CONTROL;
45999 +
46000 +typedef struct PACKED _HEADER_802_11 {
46001 + FRAME_CONTROL FC;
46002 + USHORT Duration;
46003 + UCHAR Addr1[MAC_ADDR_LEN];
46004 + UCHAR Addr2[MAC_ADDR_LEN];
46005 + UCHAR Addr3[MAC_ADDR_LEN];
46006 +#ifdef RT_BIG_ENDIAN
46007 + USHORT Sequence:12;
46008 + USHORT Frag:4;
46009 +#else
46010 + USHORT Frag:4;
46011 + USHORT Sequence:12;
46012 +#endif /* !RT_BIG_ENDIAN */
46013 + UCHAR Octet[0];
46014 +} HEADER_802_11, *PHEADER_802_11;
46015 +
46016 +typedef struct PACKED _FRAME_802_11 {
46017 + HEADER_802_11 Hdr;
46018 + UCHAR Octet[1];
46019 +} FRAME_802_11, *PFRAME_802_11;
46020 +
46021 +// QoSNull embedding of management action. When HT Control MA field set to 1.
46022 +typedef struct PACKED _MA_BODY {
46023 + UCHAR Category;
46024 + UCHAR Action;
46025 + UCHAR Octet[1];
46026 +} MA_BODY, *PMA_BODY;
46027 +
46028 +typedef struct PACKED _HEADER_802_3 {
46029 + UCHAR DAAddr1[MAC_ADDR_LEN];
46030 + UCHAR SAAddr2[MAC_ADDR_LEN];
46031 + UCHAR Octet[2];
46032 +} HEADER_802_3, *PHEADER_802_3;
46033 +////Block ACK related format
46034 +// 2-byte BA Parameter field in DELBA frames to terminate an already set up bA
46035 +typedef struct PACKED{
46036 +#ifdef RT_BIG_ENDIAN
46037 + USHORT TID:4; // value of TC os TS
46038 + USHORT Initiator:1; // 1: originator 0:recipient
46039 + USHORT Rsv:11; // always set to 0
46040 +#else
46041 + USHORT Rsv:11; // always set to 0
46042 + USHORT Initiator:1; // 1: originator 0:recipient
46043 + USHORT TID:4; // value of TC os TS
46044 +#endif /* !RT_BIG_ENDIAN */
46045 +} DELBA_PARM, *PDELBA_PARM;
46046 +
46047 +// 2-byte BA Parameter Set field in ADDBA frames to signal parm for setting up a BA
46048 +typedef struct PACKED {
46049 +#ifdef RT_BIG_ENDIAN
46050 + USHORT BufSize:10; // number of buffe of size 2304 octetsr
46051 + USHORT TID:4; // value of TC os TS
46052 + USHORT BAPolicy:1; // 1: immediately BA 0:delayed BA
46053 + USHORT AMSDUSupported:1; // 0: not permitted 1: permitted
46054 +#else
46055 + USHORT AMSDUSupported:1; // 0: not permitted 1: permitted
46056 + USHORT BAPolicy:1; // 1: immediately BA 0:delayed BA
46057 + USHORT TID:4; // value of TC os TS
46058 + USHORT BufSize:10; // number of buffe of size 2304 octetsr
46059 +#endif /* !RT_BIG_ENDIAN */
46060 +} BA_PARM, *PBA_PARM;
46061 +
46062 +// 2-byte BA Starting Seq CONTROL field
46063 +typedef union PACKED {
46064 + struct PACKED {
46065 +#ifdef RT_BIG_ENDIAN
46066 + USHORT StartSeq:12; // sequence number of the 1st MSDU for which this BAR is sent
46067 + USHORT FragNum:4; // always set to 0
46068 +#else
46069 + USHORT FragNum:4; // always set to 0
46070 + USHORT StartSeq:12; // sequence number of the 1st MSDU for which this BAR is sent
46071 +#endif /* RT_BIG_ENDIAN */
46072 + } field;
46073 + USHORT word;
46074 +} BASEQ_CONTROL, *PBASEQ_CONTROL;
46075 +
46076 +//BAControl and BARControl are the same
46077 +// 2-byte BA CONTROL field in BA frame
46078 +typedef struct PACKED {
46079 +#ifdef RT_BIG_ENDIAN
46080 + USHORT TID:4;
46081 + USHORT Rsv:9;
46082 + USHORT Compressed:1;
46083 + USHORT MTID:1; //EWC V1.24
46084 + USHORT ACKPolicy:1; // only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK
46085 +#else
46086 + USHORT ACKPolicy:1; // only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK
46087 + USHORT MTID:1; //EWC V1.24
46088 + USHORT Compressed:1;
46089 + USHORT Rsv:9;
46090 + USHORT TID:4;
46091 +#endif /* !RT_BIG_ENDIAN */
46092 +} BA_CONTROL, *PBA_CONTROL;
46093 +
46094 +// 2-byte BAR CONTROL field in BAR frame
46095 +typedef struct PACKED {
46096 +#ifdef RT_BIG_ENDIAN
46097 + USHORT TID:4;
46098 + USHORT Rsv1:9;
46099 + USHORT Compressed:1;
46100 + USHORT MTID:1; //if this bit1, use FRAME_MTBA_REQ, if 0, use FRAME_BA_REQ
46101 + USHORT ACKPolicy:1;
46102 +#else
46103 + USHORT ACKPolicy:1; // 0:normal ack, 1:no ack.
46104 + USHORT MTID:1; //if this bit1, use FRAME_MTBA_REQ, if 0, use FRAME_BA_REQ
46105 + USHORT Compressed:1;
46106 + USHORT Rsv1:9;
46107 + USHORT TID:4;
46108 +#endif /* !RT_BIG_ENDIAN */
46109 +} BAR_CONTROL, *PBAR_CONTROL;
46110 +
46111 +// BARControl in MTBAR frame
46112 +typedef struct PACKED {
46113 +#ifdef RT_BIG_ENDIAN
46114 + USHORT NumTID:4;
46115 + USHORT Rsv1:9;
46116 + USHORT Compressed:1;
46117 + USHORT MTID:1;
46118 + USHORT ACKPolicy:1;
46119 +#else
46120 + USHORT ACKPolicy:1;
46121 + USHORT MTID:1;
46122 + USHORT Compressed:1;
46123 + USHORT Rsv1:9;
46124 + USHORT NumTID:4;
46125 +#endif /* !RT_BIG_ENDIAN */
46126 +} MTBAR_CONTROL, *PMTBAR_CONTROL;
46127 +
46128 +typedef struct PACKED {
46129 +#ifdef RT_BIG_ENDIAN
46130 + USHORT TID:4;
46131 + USHORT Rsv1:12;
46132 +#else
46133 + USHORT Rsv1:12;
46134 + USHORT TID:4;
46135 +#endif /* !RT_BIG_ENDIAN */
46136 +} PER_TID_INFO, *PPER_TID_INFO;
46137 +
46138 +typedef struct {
46139 + PER_TID_INFO PerTID;
46140 + BASEQ_CONTROL BAStartingSeq;
46141 +} EACH_TID, *PEACH_TID;
46142 +
46143 +
46144 +typedef struct PACKED _PSPOLL_FRAME {
46145 + FRAME_CONTROL FC;
46146 + USHORT Aid;
46147 + UCHAR Bssid[MAC_ADDR_LEN];
46148 + UCHAR Ta[MAC_ADDR_LEN];
46149 +} PSPOLL_FRAME, *PPSPOLL_FRAME;
46150 +
46151 +typedef struct PACKED _RTS_FRAME {
46152 + FRAME_CONTROL FC;
46153 + USHORT Duration;
46154 + UCHAR Addr1[MAC_ADDR_LEN];
46155 + UCHAR Addr2[MAC_ADDR_LEN];
46156 +}RTS_FRAME, *PRTS_FRAME;
46157 +
46158 +// BAREQ AND MTBAREQ have the same subtype BAR, 802.11n BAR use compressed bitmap.
46159 +typedef struct PACKED _FRAME_BA_REQ {
46160 + FRAME_CONTROL FC;
46161 + USHORT Duration;
46162 + UCHAR Addr1[MAC_ADDR_LEN];
46163 + UCHAR Addr2[MAC_ADDR_LEN];
46164 + BAR_CONTROL BARControl;
46165 + BASEQ_CONTROL BAStartingSeq;
46166 +} FRAME_BA_REQ, *PFRAME_BA_REQ;
46167 +
46168 +typedef struct PACKED _FRAME_MTBA_REQ {
46169 + FRAME_CONTROL FC;
46170 + USHORT Duration;
46171 + UCHAR Addr1[MAC_ADDR_LEN];
46172 + UCHAR Addr2[MAC_ADDR_LEN];
46173 + MTBAR_CONTROL MTBARControl;
46174 + PER_TID_INFO PerTIDInfo;
46175 + BASEQ_CONTROL BAStartingSeq;
46176 +} FRAME_MTBA_REQ, *PFRAME_MTBA_REQ;
46177 +
46178 +// Compressed format is mandantory in HT STA
46179 +typedef struct PACKED _FRAME_MTBA {
46180 + FRAME_CONTROL FC;
46181 + USHORT Duration;
46182 + UCHAR Addr1[MAC_ADDR_LEN];
46183 + UCHAR Addr2[MAC_ADDR_LEN];
46184 + BA_CONTROL BAControl;
46185 + BASEQ_CONTROL BAStartingSeq;
46186 + UCHAR BitMap[8];
46187 +} FRAME_MTBA, *PFRAME_MTBA;
46188 +
46189 +typedef struct PACKED _FRAME_PSMP_ACTION {
46190 + HEADER_802_11 Hdr;
46191 + UCHAR Category;
46192 + UCHAR Action;
46193 + UCHAR Psmp; // 7.3.1.25
46194 +} FRAME_PSMP_ACTION, *PFRAME_PSMP_ACTION;
46195 +
46196 +typedef struct PACKED _FRAME_ACTION_HDR {
46197 + HEADER_802_11 Hdr;
46198 + UCHAR Category;
46199 + UCHAR Action;
46200 +} FRAME_ACTION_HDR, *PFRAME_ACTION_HDR;
46201 +
46202 +//Action Frame
46203 +//Action Frame Category:Spectrum, Action:Channel Switch. 7.3.2.20
46204 +typedef struct PACKED _CHAN_SWITCH_ANNOUNCE {
46205 + UCHAR ElementID; // ID = IE_CHANNEL_SWITCH_ANNOUNCEMENT = 37
46206 + UCHAR Len;
46207 + CHA_SWITCH_ANNOUNCE_IE CSAnnounceIe;
46208 +} CHAN_SWITCH_ANNOUNCE, *PCHAN_SWITCH_ANNOUNCE;
46209 +
46210 +
46211 +//802.11n : 7.3.2.20a
46212 +typedef struct PACKED _SECOND_CHAN_OFFSET {
46213 + UCHAR ElementID; // ID = IE_SECONDARY_CH_OFFSET = 62
46214 + UCHAR Len;
46215 + SEC_CHA_OFFSET_IE SecChOffsetIe;
46216 +} SECOND_CHAN_OFFSET, *PSECOND_CHAN_OFFSET;
46217 +
46218 +
46219 +typedef struct PACKED _FRAME_SPETRUM_CS {
46220 + HEADER_802_11 Hdr;
46221 + UCHAR Category;
46222 + UCHAR Action;
46223 + CHAN_SWITCH_ANNOUNCE CSAnnounce;
46224 + SECOND_CHAN_OFFSET SecondChannel;
46225 +} FRAME_SPETRUM_CS, *PFRAME_SPETRUM_CS;
46226 +
46227 +
46228 +typedef struct PACKED _FRAME_ADDBA_REQ {
46229 + HEADER_802_11 Hdr;
46230 + UCHAR Category;
46231 + UCHAR Action;
46232 + UCHAR Token; // 1
46233 + BA_PARM BaParm; // 2 - 10
46234 + USHORT TimeOutValue; // 0 - 0
46235 + BASEQ_CONTROL BaStartSeq; // 0-0
46236 +} FRAME_ADDBA_REQ, *PFRAME_ADDBA_REQ;
46237 +
46238 +typedef struct PACKED _FRAME_ADDBA_RSP {
46239 + HEADER_802_11 Hdr;
46240 + UCHAR Category;
46241 + UCHAR Action;
46242 + UCHAR Token;
46243 + USHORT StatusCode;
46244 + BA_PARM BaParm; //0 - 2
46245 + USHORT TimeOutValue;
46246 +} FRAME_ADDBA_RSP, *PFRAME_ADDBA_RSP;
46247 +
46248 +typedef struct PACKED _FRAME_DELBA_REQ {
46249 + HEADER_802_11 Hdr;
46250 + UCHAR Category;
46251 + UCHAR Action;
46252 + DELBA_PARM DelbaParm;
46253 + USHORT ReasonCode;
46254 +} FRAME_DELBA_REQ, *PFRAME_DELBA_REQ;
46255 +
46256 +
46257 +//7.2.1.7
46258 +typedef struct PACKED _FRAME_BAR {
46259 + FRAME_CONTROL FC;
46260 + USHORT Duration;
46261 + UCHAR Addr1[MAC_ADDR_LEN];
46262 + UCHAR Addr2[MAC_ADDR_LEN];
46263 + BAR_CONTROL BarControl;
46264 + BASEQ_CONTROL StartingSeq;
46265 +} FRAME_BAR, *PFRAME_BAR;
46266 +
46267 +//7.2.1.7
46268 +typedef struct PACKED _FRAME_BA {
46269 + FRAME_CONTROL FC;
46270 + USHORT Duration;
46271 + UCHAR Addr1[MAC_ADDR_LEN];
46272 + UCHAR Addr2[MAC_ADDR_LEN];
46273 + BAR_CONTROL BarControl;
46274 + BASEQ_CONTROL StartingSeq;
46275 + UCHAR bitmask[8];
46276 +} FRAME_BA, *PFRAME_BA;
46277 +
46278 +
46279 +// Radio Measuement Request Frame Format
46280 +typedef struct PACKED _FRAME_RM_REQ_ACTION {
46281 + HEADER_802_11 Hdr;
46282 + UCHAR Category;
46283 + UCHAR Action;
46284 + UCHAR Token;
46285 + USHORT Repetition;
46286 + UCHAR data[0];
46287 +} FRAME_RM_REQ_ACTION, *PFRAME_RM_REQ_ACTION;
46288 +
46289 +typedef struct PACKED {
46290 + UCHAR ID;
46291 + UCHAR Length;
46292 + UCHAR ChannelSwitchMode;
46293 + UCHAR NewRegClass;
46294 + UCHAR NewChannelNum;
46295 + UCHAR ChannelSwitchCount;
46296 +} HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE, *PHT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE;
46297 +
46298 +
46299 +//
46300 +// _Limit must be the 2**n - 1
46301 +// _SEQ1 , _SEQ2 must be within 0 ~ _Limit
46302 +//
46303 +#define SEQ_STEPONE(_SEQ1, _SEQ2, _Limit) ((_SEQ1 == ((_SEQ2+1) & _Limit)))
46304 +#define SEQ_SMALLER(_SEQ1, _SEQ2, _Limit) (((_SEQ1-_SEQ2) & ((_Limit+1)>>1)))
46305 +#define SEQ_LARGER(_SEQ1, _SEQ2, _Limit) ((_SEQ1 != _SEQ2) && !(((_SEQ1-_SEQ2) & ((_Limit+1)>>1))))
46306 +#define SEQ_WITHIN_WIN(_SEQ1, _SEQ2, _WIN, _Limit) (SEQ_LARGER(_SEQ1, _SEQ2, _Limit) && \
46307 + SEQ_SMALLER(_SEQ1, ((_SEQ2+_WIN+1)&_Limit), _Limit))
46308 +
46309 +//
46310 +// Contention-free parameter (without ID and Length)
46311 +//
46312 +typedef struct PACKED {
46313 + BOOLEAN bValid; // 1: variable contains valid value
46314 + UCHAR CfpCount;
46315 + UCHAR CfpPeriod;
46316 + USHORT CfpMaxDuration;
46317 + USHORT CfpDurRemaining;
46318 +} CF_PARM, *PCF_PARM;
46319 +
46320 +typedef struct _CIPHER_SUITE {
46321 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher 1, this one has more secured cipher suite
46322 + NDIS_802_11_ENCRYPTION_STATUS PairCipherAux; // Unicast cipher 2 if AP announce two unicast cipher suite
46323 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Group cipher
46324 + USHORT RsnCapability; // RSN capability from beacon
46325 + BOOLEAN bMixMode; // Indicate Pair & Group cipher might be different
46326 +} CIPHER_SUITE, *PCIPHER_SUITE;
46327 +
46328 +// EDCA configuration from AP's BEACON/ProbeRsp
46329 +typedef struct {
46330 + BOOLEAN bValid; // 1: variable contains valid value
46331 + BOOLEAN bAdd; // 1: variable contains valid value
46332 + BOOLEAN bQAck;
46333 + BOOLEAN bQueueRequest;
46334 + BOOLEAN bTxopRequest;
46335 + BOOLEAN bAPSDCapable;
46336 +// BOOLEAN bMoreDataAck;
46337 + UCHAR EdcaUpdateCount;
46338 + UCHAR Aifsn[4]; // 0:AC_BK, 1:AC_BE, 2:AC_VI, 3:AC_VO
46339 + UCHAR Cwmin[4];
46340 + UCHAR Cwmax[4];
46341 + USHORT Txop[4]; // in unit of 32-us
46342 + BOOLEAN bACM[4]; // 1: Admission Control of AC_BK is mandattory
46343 +} EDCA_PARM, *PEDCA_PARM;
46344 +
46345 +// QBSS LOAD information from QAP's BEACON/ProbeRsp
46346 +typedef struct {
46347 + BOOLEAN bValid; // 1: variable contains valid value
46348 + USHORT StaNum;
46349 + UCHAR ChannelUtilization;
46350 + USHORT RemainingAdmissionControl; // in unit of 32-us
46351 +} QBSS_LOAD_PARM, *PQBSS_LOAD_PARM;
46352 +
46353 +// QBSS Info field in QSTA's assoc req
46354 +typedef struct PACKED {
46355 +#ifdef RT_BIG_ENDIAN
46356 + UCHAR Rsv2:1;
46357 + UCHAR MaxSPLength:2;
46358 + UCHAR Rsv1:1;
46359 + UCHAR UAPSD_AC_BE:1;
46360 + UCHAR UAPSD_AC_BK:1;
46361 + UCHAR UAPSD_AC_VI:1;
46362 + UCHAR UAPSD_AC_VO:1;
46363 +#else
46364 + UCHAR UAPSD_AC_VO:1;
46365 + UCHAR UAPSD_AC_VI:1;
46366 + UCHAR UAPSD_AC_BK:1;
46367 + UCHAR UAPSD_AC_BE:1;
46368 + UCHAR Rsv1:1;
46369 + UCHAR MaxSPLength:2;
46370 + UCHAR Rsv2:1;
46371 +#endif /* !RT_BIG_ENDIAN */
46372 +} QBSS_STA_INFO_PARM, *PQBSS_STA_INFO_PARM;
46373 +
46374 +// QBSS Info field in QAP's Beacon/ProbeRsp
46375 +typedef struct PACKED {
46376 +#ifdef RT_BIG_ENDIAN
46377 + UCHAR UAPSD:1;
46378 + UCHAR Rsv:3;
46379 + UCHAR ParamSetCount:4;
46380 +#else
46381 + UCHAR ParamSetCount:4;
46382 + UCHAR Rsv:3;
46383 + UCHAR UAPSD:1;
46384 +#endif /* !RT_BIG_ENDIAN */
46385 +} QBSS_AP_INFO_PARM, *PQBSS_AP_INFO_PARM;
46386 +
46387 +// QOS Capability reported in QAP's BEACON/ProbeRsp
46388 +// QOS Capability sent out in QSTA's AssociateReq/ReAssociateReq
46389 +typedef struct {
46390 + BOOLEAN bValid; // 1: variable contains valid value
46391 + BOOLEAN bQAck;
46392 + BOOLEAN bQueueRequest;
46393 + BOOLEAN bTxopRequest;
46394 +// BOOLEAN bMoreDataAck;
46395 + UCHAR EdcaUpdateCount;
46396 +} QOS_CAPABILITY_PARM, *PQOS_CAPABILITY_PARM;
46397 +
46398 +#ifdef CONFIG_STA_SUPPORT
46399 +typedef struct {
46400 + UCHAR IELen;
46401 + UCHAR IE[MAX_CUSTOM_LEN];
46402 +} WPA_IE_;
46403 +#endif // CONFIG_STA_SUPPORT //
46404 +
46405 +
46406 +typedef struct {
46407 + UCHAR Bssid[MAC_ADDR_LEN];
46408 + UCHAR Channel;
46409 + UCHAR CentralChannel; //Store the wide-band central channel for 40MHz. .used in 40MHz AP. Or this is the same as Channel.
46410 + UCHAR BssType;
46411 + USHORT AtimWin;
46412 + USHORT BeaconPeriod;
46413 +
46414 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
46415 + UCHAR SupRateLen;
46416 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
46417 + UCHAR ExtRateLen;
46418 + HT_CAPABILITY_IE HtCapability;
46419 + UCHAR HtCapabilityLen;
46420 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
46421 + UCHAR AddHtInfoLen;
46422 + UCHAR NewExtChanOffset;
46423 + CHAR Rssi;
46424 + UCHAR Privacy; // Indicate security function ON/OFF. Don't mess up with auth mode.
46425 + UCHAR Hidden;
46426 +
46427 + USHORT DtimPeriod;
46428 + USHORT CapabilityInfo;
46429 +
46430 + USHORT CfpCount;
46431 + USHORT CfpPeriod;
46432 + USHORT CfpMaxDuration;
46433 + USHORT CfpDurRemaining;
46434 + UCHAR SsidLen;
46435 + CHAR Ssid[MAX_LEN_OF_SSID];
46436 +
46437 + ULONG LastBeaconRxTime; // OS's timestamp
46438 +
46439 + BOOLEAN bSES;
46440 +
46441 + // New for WPA2
46442 + CIPHER_SUITE WPA; // AP announced WPA cipher suite
46443 + CIPHER_SUITE WPA2; // AP announced WPA2 cipher suite
46444 +
46445 + // New for microsoft WPA support
46446 + NDIS_802_11_FIXED_IEs FixIEs;
46447 + NDIS_802_11_AUTHENTICATION_MODE AuthModeAux; // Addition mode for WPA2 / WPA capable AP
46448 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
46449 + NDIS_802_11_WEP_STATUS WepStatus; // Unicast Encryption Algorithm extract from VAR_IE
46450 + USHORT VarIELen; // Length of next VIE include EID & Length
46451 + UCHAR VarIEs[MAX_VIE_LEN];
46452 +
46453 + // CCX Ckip information
46454 + UCHAR CkipFlag;
46455 +
46456 + // CCX 2 TSF
46457 + UCHAR PTSF[4]; // Parent TSF
46458 + UCHAR TTSF[8]; // Target TSF
46459 +
46460 + // 802.11e d9, and WMM
46461 + EDCA_PARM EdcaParm;
46462 + QOS_CAPABILITY_PARM QosCapability;
46463 + QBSS_LOAD_PARM QbssLoad;
46464 +#ifdef CONFIG_STA_SUPPORT
46465 + WPA_IE_ WpaIE;
46466 + WPA_IE_ RsnIE;
46467 +#ifdef EXT_BUILD_CHANNEL_LIST
46468 + UCHAR CountryString[3];
46469 + BOOLEAN bHasCountryIE;
46470 +#endif // EXT_BUILD_CHANNEL_LIST //
46471 +#endif // CONFIG_STA_SUPPORT //
46472 +} BSS_ENTRY, *PBSS_ENTRY;
46473 +
46474 +typedef struct {
46475 + UCHAR BssNr;
46476 + UCHAR BssOverlapNr;
46477 + BSS_ENTRY BssEntry[MAX_LEN_OF_BSS_TABLE];
46478 +} BSS_TABLE, *PBSS_TABLE;
46479 +
46480 +
46481 +typedef struct _MLME_QUEUE_ELEM {
46482 + ULONG Machine;
46483 + ULONG MsgType;
46484 + ULONG MsgLen;
46485 + UCHAR Msg[MGMT_DMA_BUFFER_SIZE];
46486 + LARGE_INTEGER TimeStamp;
46487 + UCHAR Rssi0;
46488 + UCHAR Rssi1;
46489 + UCHAR Rssi2;
46490 + UCHAR Signal;
46491 + UCHAR Channel;
46492 + UCHAR Wcid;
46493 + BOOLEAN Occupied;
46494 +#ifdef MLME_EX
46495 + USHORT Idx;
46496 +#endif // MLME_EX //
46497 +} MLME_QUEUE_ELEM, *PMLME_QUEUE_ELEM;
46498 +
46499 +typedef struct _MLME_QUEUE {
46500 + ULONG Num;
46501 + ULONG Head;
46502 + ULONG Tail;
46503 + NDIS_SPIN_LOCK Lock;
46504 + MLME_QUEUE_ELEM Entry[MAX_LEN_OF_MLME_QUEUE];
46505 +} MLME_QUEUE, *PMLME_QUEUE;
46506 +
46507 +typedef VOID (*STATE_MACHINE_FUNC)(VOID *Adaptor, MLME_QUEUE_ELEM *Elem);
46508 +
46509 +typedef struct _STATE_MACHINE {
46510 + ULONG Base;
46511 + ULONG NrState;
46512 + ULONG NrMsg;
46513 + ULONG CurrState;
46514 + STATE_MACHINE_FUNC *TransFunc;
46515 +} STATE_MACHINE, *PSTATE_MACHINE;
46516 +
46517 +
46518 +// MLME AUX data structure that hold temporarliy settings during a connection attempt.
46519 +// Once this attemp succeeds, all settings will be copy to pAd->StaActive.
46520 +// A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of
46521 +// several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely
46522 +// separate this under-trial settings away from pAd->StaActive so that once
46523 +// this new attempt failed, driver can auto-recover back to the active settings.
46524 +typedef struct _MLME_AUX {
46525 + UCHAR BssType;
46526 + UCHAR Ssid[MAX_LEN_OF_SSID];
46527 + UCHAR SsidLen;
46528 + UCHAR Bssid[MAC_ADDR_LEN];
46529 + UCHAR AutoReconnectSsid[MAX_LEN_OF_SSID];
46530 + UCHAR AutoReconnectSsidLen;
46531 + USHORT Alg;
46532 + UCHAR ScanType;
46533 + UCHAR Channel;
46534 + UCHAR CentralChannel;
46535 + USHORT Aid;
46536 + USHORT CapabilityInfo;
46537 + USHORT BeaconPeriod;
46538 + USHORT CfpMaxDuration;
46539 + USHORT CfpPeriod;
46540 + USHORT AtimWin;
46541 +
46542 + // Copy supported rate from desired AP's beacon. We are trying to match
46543 + // AP's supported and extended rate settings.
46544 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
46545 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
46546 + UCHAR SupRateLen;
46547 + UCHAR ExtRateLen;
46548 + HT_CAPABILITY_IE HtCapability;
46549 + UCHAR HtCapabilityLen;
46550 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
46551 + UCHAR NewExtChannelOffset;
46552 + //RT_HT_CAPABILITY SupportedHtPhy;
46553 +
46554 + // new for QOS
46555 + QOS_CAPABILITY_PARM APQosCapability; // QOS capability of the current associated AP
46556 + EDCA_PARM APEdcaParm; // EDCA parameters of the current associated AP
46557 + QBSS_LOAD_PARM APQbssLoad; // QBSS load of the current associated AP
46558 +
46559 + // new to keep Ralink specific feature
46560 + ULONG APRalinkIe;
46561 +
46562 + BSS_TABLE SsidBssTab; // AP list for the same SSID
46563 + BSS_TABLE RoamTab; // AP list eligible for roaming
46564 + ULONG BssIdx;
46565 + ULONG RoamIdx;
46566 +
46567 + BOOLEAN CurrReqIsFromNdis;
46568 +
46569 + RALINK_TIMER_STRUCT BeaconTimer, ScanTimer;
46570 + RALINK_TIMER_STRUCT AuthTimer;
46571 + RALINK_TIMER_STRUCT AssocTimer, ReassocTimer, DisassocTimer;
46572 +} MLME_AUX, *PMLME_AUX;
46573 +
46574 +typedef struct _MLME_ADDBA_REQ_STRUCT{
46575 + UCHAR Wcid; //
46576 + UCHAR pAddr[MAC_ADDR_LEN];
46577 + UCHAR BaBufSize;
46578 + USHORT TimeOutValue;
46579 + UCHAR TID;
46580 + UCHAR Token;
46581 + USHORT BaStartSeq;
46582 +} MLME_ADDBA_REQ_STRUCT, *PMLME_ADDBA_REQ_STRUCT;
46583 +
46584 +
46585 +typedef struct _MLME_DELBA_REQ_STRUCT{
46586 + UCHAR Wcid; //
46587 + UCHAR Addr[MAC_ADDR_LEN];
46588 + UCHAR TID;
46589 + UCHAR Initiator;
46590 +} MLME_DELBA_REQ_STRUCT, *PMLME_DELBA_REQ_STRUCT;
46591 +
46592 +// assoc struct is equal to reassoc
46593 +typedef struct _MLME_ASSOC_REQ_STRUCT{
46594 + UCHAR Addr[MAC_ADDR_LEN];
46595 + USHORT CapabilityInfo;
46596 + USHORT ListenIntv;
46597 + ULONG Timeout;
46598 +} MLME_ASSOC_REQ_STRUCT, *PMLME_ASSOC_REQ_STRUCT, MLME_REASSOC_REQ_STRUCT, *PMLME_REASSOC_REQ_STRUCT;
46599 +
46600 +typedef struct _MLME_DISASSOC_REQ_STRUCT{
46601 + UCHAR Addr[MAC_ADDR_LEN];
46602 + USHORT Reason;
46603 +} MLME_DISASSOC_REQ_STRUCT, *PMLME_DISASSOC_REQ_STRUCT;
46604 +
46605 +typedef struct _MLME_AUTH_REQ_STRUCT {
46606 + UCHAR Addr[MAC_ADDR_LEN];
46607 + USHORT Alg;
46608 + ULONG Timeout;
46609 +} MLME_AUTH_REQ_STRUCT, *PMLME_AUTH_REQ_STRUCT;
46610 +
46611 +typedef struct _MLME_DEAUTH_REQ_STRUCT {
46612 + UCHAR Addr[MAC_ADDR_LEN];
46613 + USHORT Reason;
46614 +} MLME_DEAUTH_REQ_STRUCT, *PMLME_DEAUTH_REQ_STRUCT;
46615 +
46616 +typedef struct {
46617 + ULONG BssIdx;
46618 +} MLME_JOIN_REQ_STRUCT;
46619 +
46620 +typedef struct _MLME_SCAN_REQ_STRUCT {
46621 + UCHAR Bssid[MAC_ADDR_LEN];
46622 + UCHAR BssType;
46623 + UCHAR ScanType;
46624 + UCHAR SsidLen;
46625 + CHAR Ssid[MAX_LEN_OF_SSID];
46626 +} MLME_SCAN_REQ_STRUCT, *PMLME_SCAN_REQ_STRUCT;
46627 +
46628 +typedef struct _MLME_START_REQ_STRUCT {
46629 + CHAR Ssid[MAX_LEN_OF_SSID];
46630 + UCHAR SsidLen;
46631 +} MLME_START_REQ_STRUCT, *PMLME_START_REQ_STRUCT;
46632 +
46633 +#ifdef CONFIG_STA_SUPPORT
46634 +#ifdef QOS_DLS_SUPPORT
46635 +// structure for DLS
46636 +typedef struct _RT_802_11_DLS {
46637 + USHORT TimeOut; // Use to time out while slience, unit: second , set by UI
46638 + USHORT CountDownTimer; // Use to time out while slience,unit: second , used by driver only
46639 + NDIS_802_11_MAC_ADDRESS MacAddr; // set by UI
46640 + UCHAR Status; // 0: none , 1: wait STAkey, 2: finish DLS setup , set by driver only
46641 + BOOLEAN Valid; // 1: valid , 0: invalid , set by UI, use to setup or tear down DLS link
46642 + RALINK_TIMER_STRUCT Timer; // Use to time out while handshake
46643 + USHORT Sequence;
46644 + USHORT MacTabMatchWCID; // ASIC
46645 + BOOLEAN bHTCap;
46646 + PVOID pAd;
46647 +} RT_802_11_DLS, *PRT_802_11_DLS;
46648 +
46649 +typedef struct _MLME_DLS_REQ_STRUCT {
46650 + PRT_802_11_DLS pDLS;
46651 + USHORT Reason;
46652 +} MLME_DLS_REQ_STRUCT, *PMLME_DLS_REQ_STRUCT;
46653 +#endif // QOS_DLS_SUPPORT //
46654 +#endif // CONFIG_STA_SUPPORT //
46655 +
46656 +typedef struct PACKED {
46657 + UCHAR Eid;
46658 + UCHAR Len;
46659 + CHAR Octet[1];
46660 +} EID_STRUCT,*PEID_STRUCT, BEACON_EID_STRUCT, *PBEACON_EID_STRUCT;
46661 +
46662 +typedef struct PACKED _RTMP_TX_RATE_SWITCH
46663 +{
46664 + UCHAR ItemNo;
46665 +#ifdef RT_BIG_ENDIAN
46666 + UCHAR Rsv2:2;
46667 + UCHAR Mode:2;
46668 + UCHAR Rsv1:1;
46669 + UCHAR BW:1;
46670 + UCHAR ShortGI:1;
46671 + UCHAR STBC:1;
46672 +#else
46673 + UCHAR STBC:1;
46674 + UCHAR ShortGI:1;
46675 + UCHAR BW:1;
46676 + UCHAR Rsv1:1;
46677 + UCHAR Mode:2;
46678 + UCHAR Rsv2:2;
46679 +#endif
46680 + UCHAR CurrMCS;
46681 + UCHAR TrainUp;
46682 + UCHAR TrainDown;
46683 +} RRTMP_TX_RATE_SWITCH, *PRTMP_TX_RATE_SWITCH;
46684 +
46685 +// ========================== AP mlme.h ===============================
46686 +#define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
46687 +#define DEFAULT_DTIM_PERIOD 1
46688 +
46689 +// weighting factor to calculate Channel quality, total should be 100%
46690 +//#define RSSI_WEIGHTING 0
46691 +//#define TX_WEIGHTING 40
46692 +//#define RX_WEIGHTING 60
46693 +
46694 +#define MAC_TABLE_AGEOUT_TIME 300 // unit: sec
46695 +#define MAC_TABLE_ASSOC_TIMEOUT 5 // unit: sec
46696 +#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE)
46697 +
46698 +// AP shall drop the sta if contine Tx fail count reach it.
46699 +#define MAC_ENTRY_LIFE_CHECK_CNT 20 // packet cnt.
46700 +
46701 +// Value domain of pMacEntry->Sst
46702 +typedef enum _Sst {
46703 + SST_NOT_AUTH, // 0: equivalent to IEEE 802.11/1999 state 1
46704 + SST_AUTH, // 1: equivalent to IEEE 802.11/1999 state 2
46705 + SST_ASSOC // 2: equivalent to IEEE 802.11/1999 state 3
46706 +} SST;
46707 +
46708 +// value domain of pMacEntry->AuthState
46709 +typedef enum _AuthState {
46710 + AS_NOT_AUTH,
46711 + AS_AUTH_OPEN, // STA has been authenticated using OPEN SYSTEM
46712 + AS_AUTH_KEY, // STA has been authenticated using SHARED KEY
46713 + AS_AUTHENTICATING // STA is waiting for AUTH seq#3 using SHARED KEY
46714 +} AUTH_STATE;
46715 +
46716 +//for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
46717 +typedef enum _ApWpaState {
46718 + AS_NOTUSE, // 0
46719 + AS_DISCONNECT, // 1
46720 + AS_DISCONNECTED, // 2
46721 + AS_INITIALIZE, // 3
46722 + AS_AUTHENTICATION, // 4
46723 + AS_AUTHENTICATION2, // 5
46724 + AS_INITPMK, // 6
46725 + AS_INITPSK, // 7
46726 + AS_PTKSTART, // 8
46727 + AS_PTKINIT_NEGOTIATING, // 9
46728 + AS_PTKINITDONE, // 10
46729 + AS_UPDATEKEYS, // 11
46730 + AS_INTEGRITY_FAILURE, // 12
46731 + AS_KEYUPDATE, // 13
46732 +} AP_WPA_STATE;
46733 +
46734 +// for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
46735 +typedef enum _GTKState {
46736 + REKEY_NEGOTIATING,
46737 + REKEY_ESTABLISHED,
46738 + KEYERROR,
46739 +} GTK_STATE;
46740 +
46741 +// for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114
46742 +typedef enum _WpaGTKState {
46743 + SETKEYS,
46744 + SETKEYS_DONE,
46745 +} WPA_GTK_STATE;
46746 +// ====================== end of AP mlme.h ============================
46747 +
46748 +
46749 +#endif // MLME_H__
46750 --- /dev/null
46751 +++ b/drivers/staging/rt3070/netif_block.h
46752 @@ -0,0 +1,58 @@
46753 +/*
46754 + *************************************************************************
46755 + * Ralink Tech Inc.
46756 + * 5F., No.36, Taiyuan St., Jhubei City,
46757 + * Hsinchu County 302,
46758 + * Taiwan, R.O.C.
46759 + *
46760 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
46761 + *
46762 + * This program is free software; you can redistribute it and/or modify *
46763 + * it under the terms of the GNU General Public License as published by *
46764 + * the Free Software Foundation; either version 2 of the License, or *
46765 + * (at your option) any later version. *
46766 + * *
46767 + * This program is distributed in the hope that it will be useful, *
46768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
46770 + * GNU General Public License for more details. *
46771 + * *
46772 + * You should have received a copy of the GNU General Public License *
46773 + * along with this program; if not, write to the *
46774 + * Free Software Foundation, Inc., *
46775 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
46776 + * *
46777 + *************************************************************************
46778 + */
46779 +
46780 +#ifndef __NET_IF_BLOCK_H__
46781 +#define __NET_IF_BLOCK_H__
46782 +
46783 +//#include <linux/device.h>
46784 +#include "link_list.h"
46785 +#include "rtmp.h"
46786 +
46787 +#define FREE_NETIF_POOL_SIZE 32
46788 +
46789 +typedef struct _NETIF_ENTRY
46790 +{
46791 + struct _NETIF_ENTRY *pNext;
46792 + PNET_DEV pNetDev;
46793 +} NETIF_ENTRY, *PNETIF_ENTRY;
46794 +
46795 +void initblockQueueTab(
46796 + IN PRTMP_ADAPTER pAd);
46797 +
46798 +BOOLEAN blockNetIf(
46799 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry,
46800 + IN PNET_DEV pNetDev);
46801 +
46802 +VOID releaseNetIf(
46803 + IN PBLOCK_QUEUE_ENTRY pBlockQueueEntry);
46804 +
46805 +VOID StopNetIfQueue(
46806 + IN PRTMP_ADAPTER pAd,
46807 + IN UCHAR QueIdx,
46808 + IN PNDIS_PACKET pPacket);
46809 +#endif // __NET_IF_BLOCK_H__
46810 +
46811 --- /dev/null
46812 +++ b/drivers/staging/rt3070/oid.h
46813 @@ -0,0 +1,1142 @@
46814 +/*
46815 + *************************************************************************
46816 + * Ralink Tech Inc.
46817 + * 5F., No.36, Taiyuan St., Jhubei City,
46818 + * Hsinchu County 302,
46819 + * Taiwan, R.O.C.
46820 + *
46821 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
46822 + *
46823 + * This program is free software; you can redistribute it and/or modify *
46824 + * it under the terms of the GNU General Public License as published by *
46825 + * the Free Software Foundation; either version 2 of the License, or *
46826 + * (at your option) any later version. *
46827 + * *
46828 + * This program is distributed in the hope that it will be useful, *
46829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
46831 + * GNU General Public License for more details. *
46832 + * *
46833 + * You should have received a copy of the GNU General Public License *
46834 + * along with this program; if not, write to the *
46835 + * Free Software Foundation, Inc., *
46836 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
46837 + * *
46838 + *************************************************************************
46839 +
46840 + Module Name:
46841 + oid.h
46842 +
46843 + Abstract:
46844 +
46845 + Revision History:
46846 + Who When What
46847 + -------- ---------- ----------------------------------------------
46848 + Name Date Modification logs
46849 +*/
46850 +#ifndef _OID_H_
46851 +#define _OID_H_
46852 +
46853 +//#include <linux/wireless.h>
46854 +
46855 +
46856 +#define TRUE 1
46857 +#define FALSE 0
46858 +//
46859 +// IEEE 802.11 Structures and definitions
46860 +//
46861 +#define MAX_TX_POWER_LEVEL 100 /* mW */
46862 +#define MAX_RSSI_TRIGGER -10 /* dBm */
46863 +#define MIN_RSSI_TRIGGER -200 /* dBm */
46864 +#define MAX_FRAG_THRESHOLD 2346 /* byte count */
46865 +#define MIN_FRAG_THRESHOLD 256 /* byte count */
46866 +#define MAX_RTS_THRESHOLD 2347 /* byte count */
46867 +
46868 +// new types for Media Specific Indications
46869 +// Extension channel offset
46870 +#define EXTCHA_NONE 0
46871 +#define EXTCHA_ABOVE 0x1
46872 +#define EXTCHA_BELOW 0x3
46873 +
46874 +// BW
46875 +#define BAND_WIDTH_20 0
46876 +#define BAND_WIDTH_40 1
46877 +#define BAND_WIDTH_BOTH 2
46878 +#define BAND_WIDTH_10 3 // 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field.
46879 +// SHORTGI
46880 +#define GAP_INTERVAL_400 1 // only support in HT mode
46881 +#define GAP_INTERVAL_800 0
46882 +#define GAP_INTERVAL_BOTH 2
46883 +
46884 +#define NdisMediaStateConnected 1
46885 +#define NdisMediaStateDisconnected 0
46886 +
46887 +#define NDIS_802_11_LENGTH_SSID 32
46888 +#define NDIS_802_11_LENGTH_RATES 8
46889 +#define NDIS_802_11_LENGTH_RATES_EX 16
46890 +#define MAC_ADDR_LENGTH 6
46891 +#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL terminationc
46892 +#define MAX_NUMBER_OF_EVENT 10 // entry # in EVENT table
46893 +#define MAX_NUMBER_OF_MAC 32 // if MAX_MBSSID_NUM is 8, this value can't be larger than 211
46894 +#define MAX_NUMBER_OF_ACL 64
46895 +#define MAX_LENGTH_OF_SUPPORT_RATES 12 // 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
46896 +#define MAX_NUMBER_OF_DLS_ENTRY 4
46897 +
46898 +
46899 +
46900 +#ifndef UNDER_CE
46901 +// OID definition, since NDIS 5.0 didn't define these, we need to define for our own
46902 +//#if _WIN32_WINNT<=0x0500
46903 +
46904 +#define OID_GEN_MACHINE_NAME 0x0001021A
46905 +
46906 +#ifdef RALINK_ATE
46907 +#define RT_QUERY_ATE_TXDONE_COUNT 0x0401
46908 +#endif // RALINK_ATE //
46909 +#define RT_QUERY_SIGNAL_CONTEXT 0x0402
46910 +#define RT_SET_IAPP_PID 0x0404
46911 +#define RT_SET_APD_PID 0x0405
46912 +#define RT_SET_DEL_MAC_ENTRY 0x0406
46913 +
46914 +//
46915 +// IEEE 802.11 OIDs
46916 +//
46917 +#define OID_GET_SET_TOGGLE 0x8000
46918 +
46919 +#define OID_802_11_NETWORK_TYPES_SUPPORTED 0x0103
46920 +#define OID_802_11_NETWORK_TYPE_IN_USE 0x0104
46921 +#define OID_802_11_RSSI_TRIGGER 0x0107
46922 +#define RT_OID_802_11_RSSI 0x0108 //rt2860 only , kathy
46923 +#define RT_OID_802_11_RSSI_1 0x0109 //rt2860 only , kathy
46924 +#define RT_OID_802_11_RSSI_2 0x010A //rt2860 only , kathy
46925 +#define OID_802_11_NUMBER_OF_ANTENNAS 0x010B
46926 +#define OID_802_11_RX_ANTENNA_SELECTED 0x010C
46927 +#define OID_802_11_TX_ANTENNA_SELECTED 0x010D
46928 +#define OID_802_11_SUPPORTED_RATES 0x010E
46929 +#define OID_802_11_ADD_WEP 0x0112
46930 +#define OID_802_11_REMOVE_WEP 0x0113
46931 +#define OID_802_11_DISASSOCIATE 0x0114
46932 +#define OID_802_11_PRIVACY_FILTER 0x0118
46933 +#define OID_802_11_ASSOCIATION_INFORMATION 0x011E
46934 +#define OID_802_11_TEST 0x011F
46935 +#define RT_OID_802_11_COUNTRY_REGION 0x0507
46936 +#define OID_802_11_BSSID_LIST_SCAN 0x0508
46937 +#define OID_802_11_SSID 0x0509
46938 +#define OID_802_11_BSSID 0x050A
46939 +#define RT_OID_802_11_RADIO 0x050B
46940 +#define RT_OID_802_11_PHY_MODE 0x050C
46941 +#define RT_OID_802_11_STA_CONFIG 0x050D
46942 +#define OID_802_11_DESIRED_RATES 0x050E
46943 +#define RT_OID_802_11_PREAMBLE 0x050F
46944 +#define OID_802_11_WEP_STATUS 0x0510
46945 +#define OID_802_11_AUTHENTICATION_MODE 0x0511
46946 +#define OID_802_11_INFRASTRUCTURE_MODE 0x0512
46947 +#define RT_OID_802_11_RESET_COUNTERS 0x0513
46948 +#define OID_802_11_RTS_THRESHOLD 0x0514
46949 +#define OID_802_11_FRAGMENTATION_THRESHOLD 0x0515
46950 +#define OID_802_11_POWER_MODE 0x0516
46951 +#define OID_802_11_TX_POWER_LEVEL 0x0517
46952 +#define RT_OID_802_11_ADD_WPA 0x0518
46953 +#define OID_802_11_REMOVE_KEY 0x0519
46954 +#define OID_802_11_ADD_KEY 0x0520
46955 +#define OID_802_11_CONFIGURATION 0x0521
46956 +#define OID_802_11_TX_PACKET_BURST 0x0522
46957 +#define RT_OID_802_11_QUERY_NOISE_LEVEL 0x0523
46958 +#define RT_OID_802_11_EXTRA_INFO 0x0524
46959 +#ifdef DBG
46960 +#define RT_OID_802_11_HARDWARE_REGISTER 0x0525
46961 +#endif
46962 +#define OID_802_11_ENCRYPTION_STATUS OID_802_11_WEP_STATUS
46963 +#define OID_802_11_DEAUTHENTICATION 0x0526
46964 +#define OID_802_11_DROP_UNENCRYPTED 0x0527
46965 +#define OID_802_11_MIC_FAILURE_REPORT_FRAME 0x0528
46966 +
46967 +// For 802.1x daemin using to require current driver configuration
46968 +#define OID_802_11_RADIUS_QUERY_SETTING 0x0540
46969 +
46970 +#define RT_OID_DEVICE_NAME 0x0607
46971 +#define RT_OID_VERSION_INFO 0x0608
46972 +#define OID_802_11_BSSID_LIST 0x0609
46973 +#define OID_802_3_CURRENT_ADDRESS 0x060A
46974 +#define OID_GEN_MEDIA_CONNECT_STATUS 0x060B
46975 +#define RT_OID_802_11_QUERY_LINK_STATUS 0x060C
46976 +#define OID_802_11_RSSI 0x060D
46977 +#define OID_802_11_STATISTICS 0x060E
46978 +#define OID_GEN_RCV_OK 0x060F
46979 +#define OID_GEN_RCV_NO_BUFFER 0x0610
46980 +#define RT_OID_802_11_QUERY_EEPROM_VERSION 0x0611
46981 +#define RT_OID_802_11_QUERY_FIRMWARE_VERSION 0x0612
46982 +#define RT_OID_802_11_QUERY_LAST_RX_RATE 0x0613
46983 +#define RT_OID_802_11_TX_POWER_LEVEL_1 0x0614
46984 +#define RT_OID_802_11_QUERY_PIDVID 0x0615
46985 +//for WPA_SUPPLICANT_SUPPORT
46986 +#define OID_SET_COUNTERMEASURES 0x0616
46987 +#define OID_802_11_SET_IEEE8021X 0x0617
46988 +#define OID_802_11_SET_IEEE8021X_REQUIRE_KEY 0x0618
46989 +#define OID_802_11_PMKID 0x0620
46990 +#define RT_OID_WPA_SUPPLICANT_SUPPORT 0x0621
46991 +#define RT_OID_WE_VERSION_COMPILED 0x0622
46992 +#define RT_OID_NEW_DRIVER 0x0623
46993 +
46994 +
46995 +//rt2860 , kathy
46996 +#define RT_OID_802_11_SNR_0 0x0630
46997 +#define RT_OID_802_11_SNR_1 0x0631
46998 +#define RT_OID_802_11_QUERY_LAST_TX_RATE 0x0632
46999 +#define RT_OID_802_11_QUERY_HT_PHYMODE 0x0633
47000 +#define RT_OID_802_11_SET_HT_PHYMODE 0x0634
47001 +#define OID_802_11_RELOAD_DEFAULTS 0x0635
47002 +#define RT_OID_802_11_QUERY_APSD_SETTING 0x0636
47003 +#define RT_OID_802_11_SET_APSD_SETTING 0x0637
47004 +#define RT_OID_802_11_QUERY_APSD_PSM 0x0638
47005 +#define RT_OID_802_11_SET_APSD_PSM 0x0639
47006 +#define RT_OID_802_11_QUERY_DLS 0x063A
47007 +#define RT_OID_802_11_SET_DLS 0x063B
47008 +#define RT_OID_802_11_QUERY_DLS_PARAM 0x063C
47009 +#define RT_OID_802_11_SET_DLS_PARAM 0x063D
47010 +#define RT_OID_802_11_QUERY_WMM 0x063E
47011 +#define RT_OID_802_11_SET_WMM 0x063F
47012 +#define RT_OID_802_11_QUERY_IMME_BA_CAP 0x0640
47013 +#define RT_OID_802_11_SET_IMME_BA_CAP 0x0641
47014 +#define RT_OID_802_11_QUERY_BATABLE 0x0642
47015 +#define RT_OID_802_11_ADD_IMME_BA 0x0643
47016 +#define RT_OID_802_11_TEAR_IMME_BA 0x0644
47017 +#define RT_OID_DRIVER_DEVICE_NAME 0x0645
47018 +#define RT_OID_802_11_QUERY_DAT_HT_PHYMODE 0x0646
47019 +#define RT_OID_QUERY_MULTIPLE_CARD_SUPPORT 0x0647
47020 +
47021 +// Ralink defined OIDs
47022 +// Dennis Lee move to platform specific
47023 +
47024 +#define RT_OID_802_11_BSSID (OID_GET_SET_TOGGLE | OID_802_11_BSSID)
47025 +#define RT_OID_802_11_SSID (OID_GET_SET_TOGGLE | OID_802_11_SSID)
47026 +#define RT_OID_802_11_INFRASTRUCTURE_MODE (OID_GET_SET_TOGGLE | OID_802_11_INFRASTRUCTURE_MODE)
47027 +#define RT_OID_802_11_ADD_WEP (OID_GET_SET_TOGGLE | OID_802_11_ADD_WEP)
47028 +#define RT_OID_802_11_ADD_KEY (OID_GET_SET_TOGGLE | OID_802_11_ADD_KEY)
47029 +#define RT_OID_802_11_REMOVE_WEP (OID_GET_SET_TOGGLE | OID_802_11_REMOVE_WEP)
47030 +#define RT_OID_802_11_REMOVE_KEY (OID_GET_SET_TOGGLE | OID_802_11_REMOVE_KEY)
47031 +#define RT_OID_802_11_DISASSOCIATE (OID_GET_SET_TOGGLE | OID_802_11_DISASSOCIATE)
47032 +#define RT_OID_802_11_AUTHENTICATION_MODE (OID_GET_SET_TOGGLE | OID_802_11_AUTHENTICATION_MODE)
47033 +#define RT_OID_802_11_PRIVACY_FILTER (OID_GET_SET_TOGGLE | OID_802_11_PRIVACY_FILTER)
47034 +#define RT_OID_802_11_BSSID_LIST_SCAN (OID_GET_SET_TOGGLE | OID_802_11_BSSID_LIST_SCAN)
47035 +#define RT_OID_802_11_WEP_STATUS (OID_GET_SET_TOGGLE | OID_802_11_WEP_STATUS)
47036 +#define RT_OID_802_11_RELOAD_DEFAULTS (OID_GET_SET_TOGGLE | OID_802_11_RELOAD_DEFAULTS)
47037 +#define RT_OID_802_11_NETWORK_TYPE_IN_USE (OID_GET_SET_TOGGLE | OID_802_11_NETWORK_TYPE_IN_USE)
47038 +#define RT_OID_802_11_TX_POWER_LEVEL (OID_GET_SET_TOGGLE | OID_802_11_TX_POWER_LEVEL)
47039 +#define RT_OID_802_11_RSSI_TRIGGER (OID_GET_SET_TOGGLE | OID_802_11_RSSI_TRIGGER)
47040 +#define RT_OID_802_11_FRAGMENTATION_THRESHOLD (OID_GET_SET_TOGGLE | OID_802_11_FRAGMENTATION_THRESHOLD)
47041 +#define RT_OID_802_11_RTS_THRESHOLD (OID_GET_SET_TOGGLE | OID_802_11_RTS_THRESHOLD)
47042 +#define RT_OID_802_11_RX_ANTENNA_SELECTED (OID_GET_SET_TOGGLE | OID_802_11_RX_ANTENNA_SELECTED)
47043 +#define RT_OID_802_11_TX_ANTENNA_SELECTED (OID_GET_SET_TOGGLE | OID_802_11_TX_ANTENNA_SELECTED)
47044 +#define RT_OID_802_11_SUPPORTED_RATES (OID_GET_SET_TOGGLE | OID_802_11_SUPPORTED_RATES)
47045 +#define RT_OID_802_11_DESIRED_RATES (OID_GET_SET_TOGGLE | OID_802_11_DESIRED_RATES)
47046 +#define RT_OID_802_11_CONFIGURATION (OID_GET_SET_TOGGLE | OID_802_11_CONFIGURATION)
47047 +#define RT_OID_802_11_POWER_MODE (OID_GET_SET_TOGGLE | OID_802_11_POWER_MODE)
47048 +
47049 +
47050 +
47051 +typedef enum _NDIS_802_11_STATUS_TYPE
47052 +{
47053 + Ndis802_11StatusType_Authentication,
47054 + Ndis802_11StatusType_MediaStreamMode,
47055 + Ndis802_11StatusType_PMKID_CandidateList,
47056 + Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
47057 +} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
47058 +
47059 +typedef UCHAR NDIS_802_11_MAC_ADDRESS[6];
47060 +
47061 +typedef struct _NDIS_802_11_STATUS_INDICATION
47062 +{
47063 + NDIS_802_11_STATUS_TYPE StatusType;
47064 +} NDIS_802_11_STATUS_INDICATION, *PNDIS_802_11_STATUS_INDICATION;
47065 +
47066 +// mask for authentication/integrity fields
47067 +#define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS 0x0f
47068 +
47069 +#define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
47070 +#define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
47071 +#define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
47072 +#define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
47073 +
47074 +typedef struct _NDIS_802_11_AUTHENTICATION_REQUEST
47075 +{
47076 + ULONG Length; // Length of structure
47077 + NDIS_802_11_MAC_ADDRESS Bssid;
47078 + ULONG Flags;
47079 +} NDIS_802_11_AUTHENTICATION_REQUEST, *PNDIS_802_11_AUTHENTICATION_REQUEST;
47080 +
47081 +//Added new types for PMKID Candidate lists.
47082 +typedef struct _PMKID_CANDIDATE {
47083 + NDIS_802_11_MAC_ADDRESS BSSID;
47084 + ULONG Flags;
47085 +} PMKID_CANDIDATE, *PPMKID_CANDIDATE;
47086 +
47087 +typedef struct _NDIS_802_11_PMKID_CANDIDATE_LIST
47088 +{
47089 + ULONG Version; // Version of the structure
47090 + ULONG NumCandidates; // No. of pmkid candidates
47091 + PMKID_CANDIDATE CandidateList[1];
47092 +} NDIS_802_11_PMKID_CANDIDATE_LIST, *PNDIS_802_11_PMKID_CANDIDATE_LIST;
47093 +
47094 +//Flags for PMKID Candidate list structure
47095 +#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
47096 +
47097 +// Added new types for OFDM 5G and 2.4G
47098 +typedef enum _NDIS_802_11_NETWORK_TYPE
47099 +{
47100 + Ndis802_11FH,
47101 + Ndis802_11DS,
47102 + Ndis802_11OFDM5,
47103 + Ndis802_11OFDM5_N,
47104 + Ndis802_11OFDM24,
47105 + Ndis802_11OFDM24_N,
47106 + Ndis802_11Automode,
47107 + Ndis802_11NetworkTypeMax // not a real type, defined as an upper bound
47108 +} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
47109 +
47110 +typedef struct _NDIS_802_11_NETWORK_TYPE_LIST
47111 +{
47112 + UINT NumberOfItems; // in list below, at least 1
47113 + NDIS_802_11_NETWORK_TYPE NetworkType [1];
47114 +} NDIS_802_11_NETWORK_TYPE_LIST, *PNDIS_802_11_NETWORK_TYPE_LIST;
47115 +
47116 +typedef enum _NDIS_802_11_POWER_MODE
47117 +{
47118 + Ndis802_11PowerModeCAM,
47119 + Ndis802_11PowerModeMAX_PSP,
47120 + Ndis802_11PowerModeFast_PSP,
47121 + Ndis802_11PowerModeLegacy_PSP,
47122 + Ndis802_11PowerModeMax // not a real mode, defined as an upper bound
47123 +} NDIS_802_11_POWER_MODE, *PNDIS_802_11_POWER_MODE;
47124 +
47125 +typedef ULONG NDIS_802_11_TX_POWER_LEVEL; // in milliwatts
47126 +
47127 +//
47128 +// Received Signal Strength Indication
47129 +//
47130 +typedef LONG NDIS_802_11_RSSI; // in dBm
47131 +
47132 +typedef struct _NDIS_802_11_CONFIGURATION_FH
47133 +{
47134 + ULONG Length; // Length of structure
47135 + ULONG HopPattern; // As defined by 802.11, MSB set
47136 + ULONG HopSet; // to one if non-802.11
47137 + ULONG DwellTime; // units are Kusec
47138 +} NDIS_802_11_CONFIGURATION_FH, *PNDIS_802_11_CONFIGURATION_FH;
47139 +
47140 +typedef struct _NDIS_802_11_CONFIGURATION
47141 +{
47142 + ULONG Length; // Length of structure
47143 + ULONG BeaconPeriod; // units are Kusec
47144 + ULONG ATIMWindow; // units are Kusec
47145 + ULONG DSConfig; // Frequency, units are kHz
47146 + NDIS_802_11_CONFIGURATION_FH FHConfig;
47147 +} NDIS_802_11_CONFIGURATION, *PNDIS_802_11_CONFIGURATION;
47148 +
47149 +typedef struct _NDIS_802_11_STATISTICS
47150 +{
47151 + ULONG Length; // Length of structure
47152 + LARGE_INTEGER TransmittedFragmentCount;
47153 + LARGE_INTEGER MulticastTransmittedFrameCount;
47154 + LARGE_INTEGER FailedCount;
47155 + LARGE_INTEGER RetryCount;
47156 + LARGE_INTEGER MultipleRetryCount;
47157 + LARGE_INTEGER RTSSuccessCount;
47158 + LARGE_INTEGER RTSFailureCount;
47159 + LARGE_INTEGER ACKFailureCount;
47160 + LARGE_INTEGER FrameDuplicateCount;
47161 + LARGE_INTEGER ReceivedFragmentCount;
47162 + LARGE_INTEGER MulticastReceivedFrameCount;
47163 + LARGE_INTEGER FCSErrorCount;
47164 + LARGE_INTEGER TKIPLocalMICFailures;
47165 + LARGE_INTEGER TKIPRemoteMICErrors;
47166 + LARGE_INTEGER TKIPICVErrors;
47167 + LARGE_INTEGER TKIPCounterMeasuresInvoked;
47168 + LARGE_INTEGER TKIPReplays;
47169 + LARGE_INTEGER CCMPFormatErrors;
47170 + LARGE_INTEGER CCMPReplays;
47171 + LARGE_INTEGER CCMPDecryptErrors;
47172 + LARGE_INTEGER FourWayHandshakeFailures;
47173 +} NDIS_802_11_STATISTICS, *PNDIS_802_11_STATISTICS;
47174 +
47175 +typedef ULONG NDIS_802_11_KEY_INDEX;
47176 +typedef ULONGLONG NDIS_802_11_KEY_RSC;
47177 +
47178 +#define MAX_RADIUS_SRV_NUM 2 // 802.1x failover number
47179 +
47180 +typedef struct PACKED _RADIUS_SRV_INFO {
47181 + UINT32 radius_ip;
47182 + UINT32 radius_port;
47183 + UCHAR radius_key[64];
47184 + UCHAR radius_key_len;
47185 +} RADIUS_SRV_INFO, *PRADIUS_SRV_INFO;
47186 +
47187 +typedef struct PACKED _RADIUS_KEY_INFO
47188 +{
47189 + UCHAR radius_srv_num;
47190 + RADIUS_SRV_INFO radius_srv_info[MAX_RADIUS_SRV_NUM];
47191 + UCHAR ieee8021xWEP; // dynamic WEP
47192 + UCHAR key_index;
47193 + UCHAR key_length; // length of key in bytes
47194 + UCHAR key_material[13];
47195 +} RADIUS_KEY_INFO, *PRADIUS_KEY_INFO;
47196 +
47197 +// It's used by 802.1x daemon to require relative configuration
47198 +typedef struct PACKED _RADIUS_CONF
47199 +{
47200 + UINT32 Length; // Length of this structure
47201 + UCHAR mbss_num; // indicate multiple BSS number
47202 + UINT32 own_ip_addr;
47203 + UINT32 retry_interval;
47204 + UINT32 session_timeout_interval;
47205 + UCHAR EAPifname[IFNAMSIZ];
47206 + UCHAR EAPifname_len;
47207 + UCHAR PreAuthifname[IFNAMSIZ];
47208 + UCHAR PreAuthifname_len;
47209 + RADIUS_KEY_INFO RadiusInfo[8/*MAX_MBSSID_NUM*/];
47210 +} RADIUS_CONF, *PRADIUS_CONF;
47211 +
47212 +
47213 +
47214 +#ifdef CONFIG_STA_SUPPORT
47215 +// Key mapping keys require a BSSID
47216 +typedef struct _NDIS_802_11_KEY
47217 +{
47218 + UINT Length; // Length of this structure
47219 + UINT KeyIndex;
47220 + UINT KeyLength; // length of key in bytes
47221 + NDIS_802_11_MAC_ADDRESS BSSID;
47222 + NDIS_802_11_KEY_RSC KeyRSC;
47223 + UCHAR KeyMaterial[1]; // variable length depending on above field
47224 +} NDIS_802_11_KEY, *PNDIS_802_11_KEY;
47225 +#endif // CONFIG_STA_SUPPORT //
47226 +
47227 +typedef struct _NDIS_802_11_REMOVE_KEY
47228 +{
47229 + UINT Length; // Length of this structure
47230 + UINT KeyIndex;
47231 + NDIS_802_11_MAC_ADDRESS BSSID;
47232 +} NDIS_802_11_REMOVE_KEY, *PNDIS_802_11_REMOVE_KEY;
47233 +
47234 +typedef struct _NDIS_802_11_WEP
47235 +{
47236 + UINT Length; // Length of this structure
47237 + UINT KeyIndex; // 0 is the per-client key, 1-N are the
47238 + // global keys
47239 + UINT KeyLength; // length of key in bytes
47240 + UCHAR KeyMaterial[1];// variable length depending on above field
47241 +} NDIS_802_11_WEP, *PNDIS_802_11_WEP;
47242 +
47243 +
47244 +typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE
47245 +{
47246 + Ndis802_11IBSS,
47247 + Ndis802_11Infrastructure,
47248 + Ndis802_11AutoUnknown,
47249 + Ndis802_11Monitor,
47250 + Ndis802_11InfrastructureMax // Not a real value, defined as upper bound
47251 +} NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE;
47252 +
47253 +// Add new authentication modes
47254 +typedef enum _NDIS_802_11_AUTHENTICATION_MODE
47255 +{
47256 + Ndis802_11AuthModeOpen,
47257 + Ndis802_11AuthModeShared,
47258 + Ndis802_11AuthModeAutoSwitch,
47259 + Ndis802_11AuthModeWPA,
47260 + Ndis802_11AuthModeWPAPSK,
47261 + Ndis802_11AuthModeWPANone,
47262 + Ndis802_11AuthModeWPA2,
47263 + Ndis802_11AuthModeWPA2PSK,
47264 + Ndis802_11AuthModeWPA1WPA2,
47265 + Ndis802_11AuthModeWPA1PSKWPA2PSK,
47266 + Ndis802_11AuthModeMax // Not a real mode, defined as upper bound
47267 +} NDIS_802_11_AUTHENTICATION_MODE, *PNDIS_802_11_AUTHENTICATION_MODE;
47268 +
47269 +typedef UCHAR NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; // Set of 8 data rates
47270 +typedef UCHAR NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; // Set of 16 data rates
47271 +
47272 +typedef struct PACKED _NDIS_802_11_SSID
47273 +{
47274 + UINT SsidLength; // length of SSID field below, in bytes;
47275 + // this can be zero.
47276 + UCHAR Ssid[NDIS_802_11_LENGTH_SSID]; // SSID information field
47277 +} NDIS_802_11_SSID, *PNDIS_802_11_SSID;
47278 +
47279 +
47280 +typedef struct PACKED _NDIS_WLAN_BSSID
47281 +{
47282 + ULONG Length; // Length of this structure
47283 + NDIS_802_11_MAC_ADDRESS MacAddress; // BSSID
47284 + UCHAR Reserved[2];
47285 + NDIS_802_11_SSID Ssid; // SSID
47286 + ULONG Privacy; // WEP encryption requirement
47287 + NDIS_802_11_RSSI Rssi; // receive signal strength in dBm
47288 + NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
47289 + NDIS_802_11_CONFIGURATION Configuration;
47290 + NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
47291 + NDIS_802_11_RATES SupportedRates;
47292 +} NDIS_WLAN_BSSID, *PNDIS_WLAN_BSSID;
47293 +
47294 +typedef struct PACKED _NDIS_802_11_BSSID_LIST
47295 +{
47296 + UINT NumberOfItems; // in list below, at least 1
47297 + NDIS_WLAN_BSSID Bssid[1];
47298 +} NDIS_802_11_BSSID_LIST, *PNDIS_802_11_BSSID_LIST;
47299 +
47300 +// Added Capabilities, IELength and IEs for each BSSID
47301 +typedef struct PACKED _NDIS_WLAN_BSSID_EX
47302 +{
47303 + ULONG Length; // Length of this structure
47304 + NDIS_802_11_MAC_ADDRESS MacAddress; // BSSID
47305 + UCHAR Reserved[2];
47306 + NDIS_802_11_SSID Ssid; // SSID
47307 + UINT Privacy; // WEP encryption requirement
47308 + NDIS_802_11_RSSI Rssi; // receive signal
47309 + // strength in dBm
47310 + NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
47311 + NDIS_802_11_CONFIGURATION Configuration;
47312 + NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
47313 + NDIS_802_11_RATES_EX SupportedRates;
47314 + ULONG IELength;
47315 + UCHAR IEs[1];
47316 +} NDIS_WLAN_BSSID_EX, *PNDIS_WLAN_BSSID_EX;
47317 +
47318 +typedef struct PACKED _NDIS_802_11_BSSID_LIST_EX
47319 +{
47320 + UINT NumberOfItems; // in list below, at least 1
47321 + NDIS_WLAN_BSSID_EX Bssid[1];
47322 +} NDIS_802_11_BSSID_LIST_EX, *PNDIS_802_11_BSSID_LIST_EX;
47323 +
47324 +typedef struct PACKED _NDIS_802_11_FIXED_IEs
47325 +{
47326 + UCHAR Timestamp[8];
47327 + USHORT BeaconInterval;
47328 + USHORT Capabilities;
47329 +} NDIS_802_11_FIXED_IEs, *PNDIS_802_11_FIXED_IEs;
47330 +
47331 +typedef struct _NDIS_802_11_VARIABLE_IEs
47332 +{
47333 + UCHAR ElementID;
47334 + UCHAR Length; // Number of bytes in data field
47335 + UCHAR data[1];
47336 +} NDIS_802_11_VARIABLE_IEs, *PNDIS_802_11_VARIABLE_IEs;
47337 +
47338 +typedef ULONG NDIS_802_11_FRAGMENTATION_THRESHOLD;
47339 +
47340 +typedef ULONG NDIS_802_11_RTS_THRESHOLD;
47341 +
47342 +typedef ULONG NDIS_802_11_ANTENNA;
47343 +
47344 +typedef enum _NDIS_802_11_PRIVACY_FILTER
47345 +{
47346 + Ndis802_11PrivFilterAcceptAll,
47347 + Ndis802_11PrivFilter8021xWEP
47348 +} NDIS_802_11_PRIVACY_FILTER, *PNDIS_802_11_PRIVACY_FILTER;
47349 +
47350 +// Added new encryption types
47351 +// Also aliased typedef to new name
47352 +typedef enum _NDIS_802_11_WEP_STATUS
47353 +{
47354 + Ndis802_11WEPEnabled,
47355 + Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
47356 + Ndis802_11WEPDisabled,
47357 + Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
47358 + Ndis802_11WEPKeyAbsent,
47359 + Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
47360 + Ndis802_11WEPNotSupported,
47361 + Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
47362 + Ndis802_11Encryption2Enabled,
47363 + Ndis802_11Encryption2KeyAbsent,
47364 + Ndis802_11Encryption3Enabled,
47365 + Ndis802_11Encryption3KeyAbsent,
47366 + Ndis802_11Encryption4Enabled, // TKIP or AES mix
47367 + Ndis802_11Encryption4KeyAbsent,
47368 +} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
47369 + NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
47370 +
47371 +typedef enum _NDIS_802_11_RELOAD_DEFAULTS
47372 +{
47373 + Ndis802_11ReloadWEPKeys
47374 +} NDIS_802_11_RELOAD_DEFAULTS, *PNDIS_802_11_RELOAD_DEFAULTS;
47375 +
47376 +#define NDIS_802_11_AI_REQFI_CAPABILITIES 1
47377 +#define NDIS_802_11_AI_REQFI_LISTENINTERVAL 2
47378 +#define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS 4
47379 +
47380 +#define NDIS_802_11_AI_RESFI_CAPABILITIES 1
47381 +#define NDIS_802_11_AI_RESFI_STATUSCODE 2
47382 +#define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4
47383 +
47384 +typedef struct _NDIS_802_11_AI_REQFI
47385 +{
47386 + USHORT Capabilities;
47387 + USHORT ListenInterval;
47388 + NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
47389 +} NDIS_802_11_AI_REQFI, *PNDIS_802_11_AI_REQFI;
47390 +
47391 +typedef struct _NDIS_802_11_AI_RESFI
47392 +{
47393 + USHORT Capabilities;
47394 + USHORT StatusCode;
47395 + USHORT AssociationId;
47396 +} NDIS_802_11_AI_RESFI, *PNDIS_802_11_AI_RESFI;
47397 +
47398 +typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION
47399 +{
47400 + ULONG Length;
47401 + USHORT AvailableRequestFixedIEs;
47402 + NDIS_802_11_AI_REQFI RequestFixedIEs;
47403 + ULONG RequestIELength;
47404 + ULONG OffsetRequestIEs;
47405 + USHORT AvailableResponseFixedIEs;
47406 + NDIS_802_11_AI_RESFI ResponseFixedIEs;
47407 + ULONG ResponseIELength;
47408 + ULONG OffsetResponseIEs;
47409 +} NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
47410 +
47411 +typedef struct _NDIS_802_11_AUTHENTICATION_EVENT
47412 +{
47413 + NDIS_802_11_STATUS_INDICATION Status;
47414 + NDIS_802_11_AUTHENTICATION_REQUEST Request[1];
47415 +} NDIS_802_11_AUTHENTICATION_EVENT, *PNDIS_802_11_AUTHENTICATION_EVENT;
47416 +
47417 +/*
47418 +typedef struct _NDIS_802_11_TEST
47419 +{
47420 + ULONG Length;
47421 + ULONG Type;
47422 + union
47423 + {
47424 + NDIS_802_11_AUTHENTICATION_EVENT AuthenticationEvent;
47425 + NDIS_802_11_RSSI RssiTrigger;
47426 + };
47427 +} NDIS_802_11_TEST, *PNDIS_802_11_TEST;
47428 + */
47429 +
47430 +// 802.11 Media stream constraints, associated with OID_802_11_MEDIA_STREAM_MODE
47431 +typedef enum _NDIS_802_11_MEDIA_STREAM_MODE
47432 +{
47433 + Ndis802_11MediaStreamOff,
47434 + Ndis802_11MediaStreamOn,
47435 +} NDIS_802_11_MEDIA_STREAM_MODE, *PNDIS_802_11_MEDIA_STREAM_MODE;
47436 +
47437 +// PMKID Structures
47438 +typedef UCHAR NDIS_802_11_PMKID_VALUE[16];
47439 +
47440 +#ifdef CONFIG_STA_SUPPORT
47441 +typedef struct _BSSID_INFO
47442 +{
47443 + NDIS_802_11_MAC_ADDRESS BSSID;
47444 + NDIS_802_11_PMKID_VALUE PMKID;
47445 +} BSSID_INFO, *PBSSID_INFO;
47446 +
47447 +typedef struct _NDIS_802_11_PMKID
47448 +{
47449 + UINT Length;
47450 + UINT BSSIDInfoCount;
47451 + BSSID_INFO BSSIDInfo[1];
47452 +} NDIS_802_11_PMKID, *PNDIS_802_11_PMKID;
47453 +#endif // CONFIG_STA_SUPPORT //
47454 +
47455 +
47456 +typedef struct _NDIS_802_11_AUTHENTICATION_ENCRYPTION
47457 +{
47458 + NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported;
47459 + NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported;
47460 +} NDIS_802_11_AUTHENTICATION_ENCRYPTION, *PNDIS_802_11_AUTHENTICATION_ENCRYPTION;
47461 +
47462 +typedef struct _NDIS_802_11_CAPABILITY
47463 +{
47464 + ULONG Length;
47465 + ULONG Version;
47466 + ULONG NoOfPMKIDs;
47467 + ULONG NoOfAuthEncryptPairsSupported;
47468 + NDIS_802_11_AUTHENTICATION_ENCRYPTION AuthenticationEncryptionSupported[1];
47469 +} NDIS_802_11_CAPABILITY, *PNDIS_802_11_CAPABILITY;
47470 +
47471 +//#endif //of WIN 2k
47472 +#endif //UNDER_CE
47473 +
47474 +#if WIRELESS_EXT <= 11
47475 +#ifndef SIOCDEVPRIVATE
47476 +#define SIOCDEVPRIVATE 0x8BE0
47477 +#endif
47478 +#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
47479 +#endif
47480 +
47481 +#ifdef CONFIG_STA_SUPPORT
47482 +#define RT_PRIV_IOCTL_EXT (SIOCIWFIRSTPRIV + 0x01) // Sync. with AP for wsc upnp daemon
47483 +#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
47484 +
47485 +#ifdef DBG
47486 +#define RTPRIV_IOCTL_BBP (SIOCIWFIRSTPRIV + 0x03)
47487 +#define RTPRIV_IOCTL_MAC (SIOCIWFIRSTPRIV + 0x05)
47488 +#define RTPRIV_IOCTL_RF (SIOCIWFIRSTPRIV + 0x13)
47489 +#define RTPRIV_IOCTL_E2P (SIOCIWFIRSTPRIV + 0x07)
47490 +#endif
47491 +
47492 +#ifdef RALINK_ATE
47493 +#ifdef RALINK_28xx_QA
47494 +#define RTPRIV_IOCTL_ATE (SIOCIWFIRSTPRIV + 0x08)
47495 +#endif // RALINK_28xx_QA //
47496 +#endif // RALINK_ATE //
47497 +
47498 +#define RTPRIV_IOCTL_STATISTICS (SIOCIWFIRSTPRIV + 0x09)
47499 +#define RTPRIV_IOCTL_ADD_PMKID_CACHE (SIOCIWFIRSTPRIV + 0x0A)
47500 +#define RTPRIV_IOCTL_RADIUS_DATA (SIOCIWFIRSTPRIV + 0x0C)
47501 +#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
47502 +#define RT_PRIV_IOCTL (SIOCIWFIRSTPRIV + 0x0E) // Sync. with RT61 (for wpa_supplicant)
47503 +#define RTPRIV_IOCTL_GET_MAC_TABLE (SIOCIWFIRSTPRIV + 0x0F)
47504 +
47505 +#define RTPRIV_IOCTL_SHOW (SIOCIWFIRSTPRIV + 0x11)
47506 +enum {
47507 + SHOW_CONN_STATUS = 4,
47508 + SHOW_DRVIER_VERION = 5,
47509 + SHOW_BA_INFO = 6,
47510 + SHOW_DESC_INFO = 7,
47511 +#ifdef RT2870
47512 + SHOW_RXBULK_INFO = 8,
47513 + SHOW_TXBULK_INFO = 9,
47514 +#endif // RT2870 //
47515 + RAIO_OFF = 10,
47516 + RAIO_ON = 11,
47517 +#ifdef QOS_DLS_SUPPORT
47518 + SHOW_DLS_ENTRY_INFO = 19,
47519 +#endif // QOS_DLS_SUPPORT //
47520 + SHOW_CFG_VALUE = 20,
47521 +};
47522 +
47523 +
47524 +#endif // CONFIG_STA_SUPPORT //
47525 +
47526 +
47527 +
47528 +#ifdef SNMP_SUPPORT
47529 +//SNMP ieee 802dot11, kathy , 2008_0220
47530 +// dot11res(3)
47531 +#define RT_OID_802_11_MANUFACTUREROUI 0x0700
47532 +#define RT_OID_802_11_MANUFACTURERNAME 0x0701
47533 +#define RT_OID_802_11_RESOURCETYPEIDNAME 0x0702
47534 +
47535 +// dot11smt(1)
47536 +#define RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED 0x0703
47537 +#define RT_OID_802_11_POWERMANAGEMENTMODE 0x0704
47538 +#define OID_802_11_WEPDEFAULTKEYVALUE 0x0705 // read , write
47539 +#define OID_802_11_WEPDEFAULTKEYID 0x0706
47540 +#define RT_OID_802_11_WEPKEYMAPPINGLENGTH 0x0707
47541 +#define OID_802_11_SHORTRETRYLIMIT 0x0708
47542 +#define OID_802_11_LONGRETRYLIMIT 0x0709
47543 +#define RT_OID_802_11_PRODUCTID 0x0710
47544 +#define RT_OID_802_11_MANUFACTUREID 0x0711
47545 +
47546 +// //dot11Phy(4)
47547 +#define OID_802_11_CURRENTCHANNEL 0x0712
47548 +
47549 +//dot11mac
47550 +#define RT_OID_802_11_MAC_ADDRESS 0x0713
47551 +#endif // SNMP_SUPPORT //
47552 +
47553 +#define OID_802_11_BUILD_CHANNEL_EX 0x0714
47554 +#define OID_802_11_GET_CH_LIST 0x0715
47555 +#define OID_802_11_GET_COUNTRY_CODE 0x0716
47556 +#define OID_802_11_GET_CHANNEL_GEOGRAPHY 0x0717
47557 +
47558 +//#define RT_OID_802_11_STATISTICS (OID_GET_SET_TOGGLE | OID_802_11_STATISTICS)
47559 +
47560 +#ifdef CONFIG_STA_SUPPORT
47561 +#define RT_OID_WSC_SET_PASSPHRASE 0x0740 // passphrase for wpa(2)-psk
47562 +#define RT_OID_WSC_DRIVER_AUTO_CONNECT 0x0741
47563 +#define RT_OID_WSC_QUERY_DEFAULT_PROFILE 0x0742
47564 +#define RT_OID_WSC_SET_CONN_BY_PROFILE_INDEX 0x0743
47565 +#define RT_OID_WSC_SET_ACTION 0x0744
47566 +#define RT_OID_WSC_SET_SSID 0x0745
47567 +#define RT_OID_WSC_SET_PIN_CODE 0x0746
47568 +#define RT_OID_WSC_SET_MODE 0x0747 // PIN or PBC
47569 +#define RT_OID_WSC_SET_CONF_MODE 0x0748 // Enrollee or Registrar
47570 +#define RT_OID_WSC_SET_PROFILE 0x0749
47571 +#endif // CONFIG_STA_SUPPORT //
47572 +#define RT_OID_802_11_WSC_QUERY_PROFILE 0x0750
47573 +// for consistency with RT61
47574 +#define RT_OID_WSC_QUERY_STATUS 0x0751
47575 +#define RT_OID_WSC_PIN_CODE 0x0752
47576 +#define RT_OID_WSC_UUID 0x0753
47577 +#define RT_OID_WSC_SET_SELECTED_REGISTRAR 0x0754
47578 +#define RT_OID_WSC_EAPMSG 0x0755
47579 +#define RT_OID_WSC_MANUFACTURER 0x0756
47580 +#define RT_OID_WSC_MODEL_NAME 0x0757
47581 +#define RT_OID_WSC_MODEL_NO 0x0758
47582 +#define RT_OID_WSC_SERIAL_NO 0x0759
47583 +#define RT_OID_WSC_MAC_ADDRESS 0x0760
47584 +
47585 +#ifdef LLTD_SUPPORT
47586 +// for consistency with RT61
47587 +#define RT_OID_GET_PHY_MODE 0x761
47588 +#endif // LLTD_SUPPORT //
47589 +
47590 +#ifdef NINTENDO_AP
47591 +//#define RT_OID_NINTENDO 0x0D010770
47592 +#define RT_OID_802_11_NINTENDO_GET_TABLE 0x0771 //((RT_OID_NINTENDO + 0x01) & 0xffff)
47593 +#define RT_OID_802_11_NINTENDO_SET_TABLE 0x0772 //((RT_OID_NINTENDO + 0x02) & 0xffff)
47594 +#define RT_OID_802_11_NINTENDO_CAPABLE 0x0773 //((RT_OID_NINTENDO + 0x03) & 0xffff)
47595 +#endif // NINTENDO_AP //
47596 +
47597 +//Add Paul Chen for Accton
47598 +//#define RT_OID_TX_POWER_LEVEL 0xFF020010
47599 +//#define RT_OID_SET_TX_POWER_LEVEL (OID_GET_SET_TOGGLE | RT_OID_TX_POWER_LEVEL)
47600 +
47601 +// New for MeetingHouse Api support
47602 +#define OID_MH_802_1X_SUPPORTED 0xFFEDC100
47603 +
47604 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition!!!
47605 +typedef union _HTTRANSMIT_SETTING {
47606 +#ifdef RT_BIG_ENDIAN
47607 + struct {
47608 + USHORT MODE:2; // Use definition MODE_xxx.
47609 +// USHORT rsv:3;
47610 + USHORT TxBF:1;
47611 + USHORT rsv:2;
47612 + USHORT STBC:2; //SPACE
47613 + USHORT ShortGI:1;
47614 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
47615 + USHORT MCS:7; // MCS
47616 + } field;
47617 +#else
47618 + struct {
47619 + USHORT MCS:7; // MCS
47620 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
47621 + USHORT ShortGI:1;
47622 + USHORT STBC:2; //SPACE
47623 +// USHORT rsv:3;
47624 + USHORT rsv:2;
47625 + USHORT TxBF:1;
47626 + USHORT MODE:2; // Use definition MODE_xxx.
47627 + } field;
47628 +#endif
47629 + USHORT word;
47630 + } HTTRANSMIT_SETTING, *PHTTRANSMIT_SETTING;
47631 +
47632 +typedef enum _RT_802_11_PREAMBLE {
47633 + Rt802_11PreambleLong,
47634 + Rt802_11PreambleShort,
47635 + Rt802_11PreambleAuto
47636 +} RT_802_11_PREAMBLE, *PRT_802_11_PREAMBLE;
47637 +
47638 +// Only for STA, need to sync with AP
47639 +// 2005-03-08 match current RaConfig.
47640 +typedef enum _RT_802_11_PHY_MODE {
47641 + PHY_11BG_MIXED = 0,
47642 + PHY_11B,
47643 + PHY_11A,
47644 + PHY_11ABG_MIXED,
47645 + PHY_11G,
47646 +#ifdef DOT11_N_SUPPORT
47647 + PHY_11ABGN_MIXED, // both band 5
47648 + PHY_11N_2_4G, // 11n-only with 2.4G band 6
47649 + PHY_11GN_MIXED, // 2.4G band 7
47650 + PHY_11AN_MIXED, // 5G band 8
47651 + PHY_11BGN_MIXED, // if check 802.11b. 9
47652 + PHY_11AGN_MIXED, // if check 802.11b. 10
47653 + PHY_11N_5G, // 11n-only with 5G band 11
47654 +#endif // DOT11_N_SUPPORT //
47655 +} RT_802_11_PHY_MODE;
47656 +
47657 +// put all proprietery for-query objects here to reduce # of Query_OID
47658 +typedef struct _RT_802_11_LINK_STATUS {
47659 + ULONG CurrTxRate; // in units of 0.5Mbps
47660 + ULONG ChannelQuality; // 0..100 %
47661 + ULONG TxByteCount; // both ok and fail
47662 + ULONG RxByteCount; // both ok and fail
47663 + ULONG CentralChannel; // 40MHz central channel number
47664 +} RT_802_11_LINK_STATUS, *PRT_802_11_LINK_STATUS;
47665 +
47666 +typedef struct _RT_802_11_EVENT_LOG {
47667 + LARGE_INTEGER SystemTime; // timestammp via NdisGetCurrentSystemTime()
47668 + UCHAR Addr[MAC_ADDR_LENGTH];
47669 + USHORT Event; // EVENT_xxx
47670 +} RT_802_11_EVENT_LOG, *PRT_802_11_EVENT_LOG;
47671 +
47672 +typedef struct _RT_802_11_EVENT_TABLE {
47673 + ULONG Num;
47674 + ULONG Rsv; // to align Log[] at LARGE_INEGER boundary
47675 + RT_802_11_EVENT_LOG Log[MAX_NUMBER_OF_EVENT];
47676 +} RT_802_11_EVENT_TABLE, PRT_802_11_EVENT_TABLE;
47677 +
47678 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition!!!
47679 +typedef union _MACHTTRANSMIT_SETTING {
47680 + struct {
47681 + USHORT MCS:7; // MCS
47682 + USHORT BW:1; //channel bandwidth 20MHz or 40 MHz
47683 + USHORT ShortGI:1;
47684 + USHORT STBC:2; //SPACE
47685 + USHORT rsv:3;
47686 + USHORT MODE:2; // Use definition MODE_xxx.
47687 + } field;
47688 + USHORT word;
47689 + } MACHTTRANSMIT_SETTING, *PMACHTTRANSMIT_SETTING;
47690 +
47691 +typedef struct _RT_802_11_MAC_ENTRY {
47692 + UCHAR Addr[MAC_ADDR_LENGTH];
47693 + UCHAR Aid;
47694 + UCHAR Psm; // 0:PWR_ACTIVE, 1:PWR_SAVE
47695 + UCHAR MimoPs; // 0:MMPS_STATIC, 1:MMPS_DYNAMIC, 3:MMPS_Enabled
47696 + CHAR AvgRssi0;
47697 + CHAR AvgRssi1;
47698 + CHAR AvgRssi2;
47699 + UINT32 ConnectedTime;
47700 + MACHTTRANSMIT_SETTING TxRate;
47701 +} RT_802_11_MAC_ENTRY, *PRT_802_11_MAC_ENTRY;
47702 +
47703 +typedef struct _RT_802_11_MAC_TABLE {
47704 + ULONG Num;
47705 + RT_802_11_MAC_ENTRY Entry[MAX_NUMBER_OF_MAC];
47706 +} RT_802_11_MAC_TABLE, *PRT_802_11_MAC_TABLE;
47707 +
47708 +// structure for query/set hardware register - MAC, BBP, RF register
47709 +typedef struct _RT_802_11_HARDWARE_REGISTER {
47710 + ULONG HardwareType; // 0:MAC, 1:BBP, 2:RF register, 3:EEPROM
47711 + ULONG Offset; // Q/S register offset addr
47712 + ULONG Data; // R/W data buffer
47713 +} RT_802_11_HARDWARE_REGISTER, *PRT_802_11_HARDWARE_REGISTER;
47714 +
47715 +// structure to tune BBP R17 "RX AGC VGC init"
47716 +//typedef struct _RT_802_11_RX_AGC_VGC_TUNING {
47717 +// UCHAR FalseCcaLowerThreshold; // 0-255, def 10
47718 +// UCHAR FalseCcaUpperThreshold; // 0-255, def 100
47719 +// UCHAR VgcDelta; // R17 +-= VgcDelta whenever flase CCA over UpprThreshold
47720 +// // or lower than LowerThresholdupper threshold
47721 +// UCHAR VgcUpperBound; // max value of R17
47722 +//} RT_802_11_RX_AGC_VGC_TUNING, *PRT_802_11_RX_AGC_VGC_TUNING;
47723 +
47724 +typedef struct _RT_802_11_AP_CONFIG {
47725 + ULONG EnableTxBurst; // 0-disable, 1-enable
47726 + ULONG EnableTurboRate; // 0-disable, 1-enable 72/100mbps turbo rate
47727 + ULONG IsolateInterStaTraffic; // 0-disable, 1-enable isolation
47728 + ULONG HideSsid; // 0-disable, 1-enable hiding
47729 + ULONG UseBGProtection; // 0-AUTO, 1-always ON, 2-always OFF
47730 + ULONG UseShortSlotTime; // 0-no use, 1-use 9-us short slot time
47731 + ULONG Rsv1; // must be 0
47732 + ULONG SystemErrorBitmap; // ignore upon SET, return system error upon QUERY
47733 +} RT_802_11_AP_CONFIG, *PRT_802_11_AP_CONFIG;
47734 +
47735 +// structure to query/set STA_CONFIG
47736 +typedef struct _RT_802_11_STA_CONFIG {
47737 + ULONG EnableTxBurst; // 0-disable, 1-enable
47738 + ULONG EnableTurboRate; // 0-disable, 1-enable 72/100mbps turbo rate
47739 + ULONG UseBGProtection; // 0-AUTO, 1-always ON, 2-always OFF
47740 + ULONG UseShortSlotTime; // 0-no use, 1-use 9-us short slot time when applicable
47741 + ULONG AdhocMode; // 0-11b rates only (WIFI spec), 1 - b/g mixed, 2 - g only
47742 + ULONG HwRadioStatus; // 0-OFF, 1-ON, default is 1, Read-Only
47743 + ULONG Rsv1; // must be 0
47744 + ULONG SystemErrorBitmap; // ignore upon SET, return system error upon QUERY
47745 +} RT_802_11_STA_CONFIG, *PRT_802_11_STA_CONFIG;
47746 +
47747 +//
47748 +// For OID Query or Set about BA structure
47749 +//
47750 +typedef struct _OID_BACAP_STRUC {
47751 + UCHAR RxBAWinLimit;
47752 + UCHAR TxBAWinLimit;
47753 + UCHAR Policy; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid
47754 + UCHAR MpduDensity; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid
47755 + UCHAR AmsduEnable; //Enable AMSDU transmisstion
47756 + UCHAR AmsduSize; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
47757 + UCHAR MMPSmode; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
47758 + BOOLEAN AutoBA; // Auto BA will automatically
47759 +} OID_BACAP_STRUC, *POID_BACAP_STRUC;
47760 +
47761 +typedef struct _RT_802_11_ACL_ENTRY {
47762 + UCHAR Addr[MAC_ADDR_LENGTH];
47763 + USHORT Rsv;
47764 +} RT_802_11_ACL_ENTRY, *PRT_802_11_ACL_ENTRY;
47765 +
47766 +typedef struct PACKED _RT_802_11_ACL {
47767 + ULONG Policy; // 0-disable, 1-positive list, 2-negative list
47768 + ULONG Num;
47769 + RT_802_11_ACL_ENTRY Entry[MAX_NUMBER_OF_ACL];
47770 +} RT_802_11_ACL, *PRT_802_11_ACL;
47771 +
47772 +typedef struct _RT_802_11_WDS {
47773 + ULONG Num;
47774 + NDIS_802_11_MAC_ADDRESS Entry[24/*MAX_NUM_OF_WDS_LINK*/];
47775 + ULONG KeyLength;
47776 + UCHAR KeyMaterial[32];
47777 +} RT_802_11_WDS, *PRT_802_11_WDS;
47778 +
47779 +typedef struct _RT_802_11_TX_RATES_ {
47780 + UCHAR SupRateLen;
47781 + UCHAR SupRate[MAX_LENGTH_OF_SUPPORT_RATES];
47782 + UCHAR ExtRateLen;
47783 + UCHAR ExtRate[MAX_LENGTH_OF_SUPPORT_RATES];
47784 +} RT_802_11_TX_RATES, *PRT_802_11_TX_RATES;
47785 +
47786 +
47787 +// Definition of extra information code
47788 +#define GENERAL_LINK_UP 0x0 // Link is Up
47789 +#define GENERAL_LINK_DOWN 0x1 // Link is Down
47790 +#define HW_RADIO_OFF 0x2 // Hardware radio off
47791 +#define SW_RADIO_OFF 0x3 // Software radio off
47792 +#define AUTH_FAIL 0x4 // Open authentication fail
47793 +#define AUTH_FAIL_KEYS 0x5 // Shared authentication fail
47794 +#define ASSOC_FAIL 0x6 // Association failed
47795 +#define EAP_MIC_FAILURE 0x7 // Deauthencation because MIC failure
47796 +#define EAP_4WAY_TIMEOUT 0x8 // Deauthencation on 4-way handshake timeout
47797 +#define EAP_GROUP_KEY_TIMEOUT 0x9 // Deauthencation on group key handshake timeout
47798 +#define EAP_SUCCESS 0xa // EAP succeed
47799 +#define DETECT_RADAR_SIGNAL 0xb // Radar signal occur in current channel
47800 +#define EXTRA_INFO_MAX 0xb // Indicate Last OID
47801 +
47802 +#define EXTRA_INFO_CLEAR 0xffffffff
47803 +
47804 +// This is OID setting structure. So only GF or MM as Mode. This is valid when our wirelss mode has 802.11n in use.
47805 +typedef struct {
47806 + RT_802_11_PHY_MODE PhyMode; //
47807 + UCHAR TransmitNo;
47808 + UCHAR HtMode; //HTMODE_GF or HTMODE_MM
47809 + UCHAR ExtOffset; //extension channel above or below
47810 + UCHAR MCS;
47811 + UCHAR BW;
47812 + UCHAR STBC;
47813 + UCHAR SHORTGI;
47814 + UCHAR rsv;
47815 +} OID_SET_HT_PHYMODE, *POID_SET_HT_PHYMODE;
47816 +
47817 +#ifdef NINTENDO_AP
47818 +#define NINTENDO_MAX_ENTRY 16
47819 +#define NINTENDO_SSID_NAME_LN 8
47820 +#define NINTENDO_SSID_NAME "NWCUSBAP"
47821 +#define NINTENDO_PROBE_REQ_FLAG_MASK 0x03
47822 +#define NINTENDO_PROBE_REQ_ON 0x01
47823 +#define NINTENDO_PROBE_REQ_SIGNAL 0x02
47824 +#define NINTENDO_PROBE_RSP_ON 0x01
47825 +#define NINTENDO_SSID_NICKNAME_LN 20
47826 +
47827 +#define NINTENDO_WEPKEY_LN 13
47828 +
47829 +typedef struct _NINTENDO_SSID
47830 +{
47831 + UCHAR NINTENDOFixChar[NINTENDO_SSID_NAME_LN];
47832 + UCHAR zero1;
47833 + UCHAR registe;
47834 + UCHAR ID;
47835 + UCHAR zero2;
47836 + UCHAR NICKname[NINTENDO_SSID_NICKNAME_LN];
47837 +} RT_NINTENDO_SSID, *PRT_NINTENDO_SSID;
47838 +
47839 +typedef struct _NINTENDO_ENTRY
47840 +{
47841 + UCHAR NICKname[NINTENDO_SSID_NICKNAME_LN];
47842 + UCHAR DS_Addr[ETH_LENGTH_OF_ADDRESS];
47843 + UCHAR registe;
47844 + UCHAR UserSpaceAck;
47845 +} RT_NINTENDO_ENTRY, *PRT_NINTENDO_ENTRY;
47846 +
47847 +//RTPRIV_IOCTL_NINTENDO_GET_TABLE
47848 +//RTPRIV_IOCTL_NINTENDO_SET_TABLE
47849 +typedef struct _NINTENDO_TABLE
47850 +{
47851 + UINT number;
47852 + RT_NINTENDO_ENTRY entry[NINTENDO_MAX_ENTRY];
47853 +} RT_NINTENDO_TABLE, *PRT_NINTENDO_TABLE;
47854 +
47855 +//RTPRIV_IOCTL_NINTENDO_SEED_WEPKEY
47856 +typedef struct _NINTENDO_SEED_WEPKEY
47857 +{
47858 + UCHAR seed[NINTENDO_SSID_NICKNAME_LN];
47859 + UCHAR wepkey[16];//use 13 for 104 bits wep key
47860 +} RT_NINTENDO_SEED_WEPKEY, *PRT_NINTENDO_SEED_WEPKEY;
47861 +#endif // NINTENDO_AP //
47862 +
47863 +#ifdef LLTD_SUPPORT
47864 +typedef struct _RT_LLTD_ASSOICATION_ENTRY {
47865 + UCHAR Addr[ETH_LENGTH_OF_ADDRESS];
47866 + unsigned short MOR; // maximum operational rate
47867 + UCHAR phyMode;
47868 +} RT_LLTD_ASSOICATION_ENTRY, *PRT_LLTD_ASSOICATION_ENTRY;
47869 +
47870 +typedef struct _RT_LLTD_ASSOICATION_TABLE {
47871 + unsigned int Num;
47872 + RT_LLTD_ASSOICATION_ENTRY Entry[MAX_NUMBER_OF_MAC];
47873 +} RT_LLTD_ASSOICATION_TABLE, *PRT_LLTD_ASSOICATION_TABLE;
47874 +#endif // LLTD_SUPPORT //
47875 +
47876 +#ifdef CONFIG_STA_SUPPORT
47877 +#ifdef QOS_DLS_SUPPORT
47878 +//rt2860, kathy 2007-0118
47879 +// structure for DLS
47880 +typedef struct _RT_802_11_DLS_UI {
47881 + USHORT TimeOut; // unit: second , set by UI
47882 + USHORT CountDownTimer; // unit: second , used by driver only
47883 + NDIS_802_11_MAC_ADDRESS MacAddr; // set by UI
47884 + UCHAR Status; // 0: none , 1: wait STAkey, 2: finish DLS setup , set by driver only
47885 + BOOLEAN Valid; // 1: valid , 0: invalid , set by UI, use to setup or tear down DLS link
47886 +} RT_802_11_DLS_UI, *PRT_802_11_DLS_UI;
47887 +
47888 +typedef struct _RT_802_11_DLS_INFO {
47889 + RT_802_11_DLS_UI Entry[MAX_NUMBER_OF_DLS_ENTRY];
47890 + UCHAR num;
47891 +} RT_802_11_DLS_INFO, *PRT_802_11_DLS_INFO;
47892 +
47893 +typedef enum _RT_802_11_DLS_MODE {
47894 + DLS_NONE,
47895 + DLS_WAIT_KEY,
47896 + DLS_FINISH
47897 +} RT_802_11_DLS_MODE;
47898 +#endif // QOS_DLS_SUPPORT //
47899 +
47900 +#ifdef WPA_SUPPLICANT_SUPPORT
47901 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
47902 +#define RT_ASSOC_EVENT_FLAG 0x0101
47903 +#define RT_DISASSOC_EVENT_FLAG 0x0102
47904 +#define RT_REQIE_EVENT_FLAG 0x0103
47905 +#define RT_RESPIE_EVENT_FLAG 0x0104
47906 +#define RT_ASSOCINFO_EVENT_FLAG 0x0105
47907 +#define RT_PMKIDCAND_FLAG 0x0106
47908 +#define RT_INTERFACE_DOWN 0x0107
47909 +#define RT_INTERFACE_UP 0x0108
47910 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
47911 +#endif // WPA_SUPPLICANT_SUPPORT //
47912 +#endif // CONFIG_STA_SUPPORT //
47913 +
47914 +
47915 +#define MAX_CUSTOM_LEN 128
47916 +
47917 +#ifdef CONFIG_STA_SUPPORT
47918 +typedef enum _RT_802_11_D_CLIENT_MODE
47919 +{
47920 + Rt802_11_D_None,
47921 + Rt802_11_D_Flexible,
47922 + Rt802_11_D_Strict,
47923 +} RT_802_11_D_CLIENT_MODE, *PRT_802_11_D_CLIENT_MODE;
47924 +#endif // CONFIG_STA_SUPPORT //
47925 +
47926 +typedef struct _RT_CHANNEL_LIST_INFO
47927 +{
47928 + UCHAR ChannelList[MAX_NUM_OF_CHS]; // list all supported channels for site survey
47929 + UCHAR ChannelListNum; // number of channel in ChannelList[]
47930 +} RT_CHANNEL_LIST_INFO, *PRT_CHANNEL_LIST_INFO;
47931 +
47932 +// WSC configured credential
47933 +typedef struct _WSC_CREDENTIAL
47934 +{
47935 + NDIS_802_11_SSID SSID; // mandatory
47936 + USHORT AuthType; // mandatory, 1: open, 2: wpa-psk, 4: shared, 8:wpa, 0x10: wpa2, 0x20: wpa2-psk
47937 + USHORT EncrType; // mandatory, 1: none, 2: wep, 4: tkip, 8: aes
47938 + UCHAR Key[64]; // mandatory, Maximum 64 byte
47939 + USHORT KeyLength;
47940 + UCHAR MacAddr[6]; // mandatory, AP MAC address
47941 + UCHAR KeyIndex; // optional, default is 1
47942 + UCHAR Rsvd[3]; // Make alignment
47943 +} WSC_CREDENTIAL, *PWSC_CREDENTIAL;
47944 +
47945 +// WSC configured profiles
47946 +typedef struct _WSC_PROFILE
47947 +{
47948 + UINT ProfileCnt;
47949 + WSC_CREDENTIAL Profile[8]; // Support up to 8 profiles
47950 +} WSC_PROFILE, *PWSC_PROFILE;
47951 +
47952 +
47953 +
47954 +#endif // _OID_H_
47955 +
47956 --- /dev/null
47957 +++ b/drivers/staging/rt3070/rt2870.h
47958 @@ -0,0 +1,756 @@
47959 +/*
47960 + *************************************************************************
47961 + * Ralink Tech Inc.
47962 + * 5F., No.36, Taiyuan St., Jhubei City,
47963 + * Hsinchu County 302,
47964 + * Taiwan, R.O.C.
47965 + *
47966 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
47967 + *
47968 + * This program is free software; you can redistribute it and/or modify *
47969 + * it under the terms of the GNU General Public License as published by *
47970 + * the Free Software Foundation; either version 2 of the License, or *
47971 + * (at your option) any later version. *
47972 + * *
47973 + * This program is distributed in the hope that it will be useful, *
47974 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
47975 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
47976 + * GNU General Public License for more details. *
47977 + * *
47978 + * You should have received a copy of the GNU General Public License *
47979 + * along with this program; if not, write to the *
47980 + * Free Software Foundation, Inc., *
47981 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
47982 + * *
47983 + *************************************************************************
47984 + */
47985 +
47986 +#ifndef __RT2870_H__
47987 +#define __RT2870_H__
47988 +
47989 +//usb header files
47990 +#include <linux/usb.h>
47991 +
47992 +/* rtmp_def.h */
47993 +//
47994 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
47995 +#define BULKAGGRE_ZISE 100
47996 +#define RT28XX_DRVDATA_SET(_a) usb_set_intfdata(_a, pAd);
47997 +#define RT28XX_PUT_DEVICE usb_put_dev
47998 +#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC)
47999 +#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, GFP_ATOMIC)
48000 +#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_buffer_alloc(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)
48001 +#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) usb_buffer_free(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)
48002 +#else
48003 +#define BULKAGGRE_ZISE 60
48004 +#define RT28XX_DRVDATA_SET(_a)
48005 +#define RT28XX_PUT_DEVICE(dev_p)
48006 +#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso)
48007 +#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb)
48008 +#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) kmalloc(BufSize, GFP_ATOMIC)
48009 +#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) kfree(pTransferBuf)
48010 +#endif
48011 +
48012 +#define RXBULKAGGRE_ZISE 12
48013 +#define MAX_TXBULK_LIMIT (LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1))
48014 +#define MAX_TXBULK_SIZE (LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE)
48015 +#define MAX_RXBULK_SIZE (LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE)
48016 +#define MAX_MLME_HANDLER_MEMORY 20
48017 +#define BUFFER_SIZE 2400 //2048
48018 +#define TX_RING 0xa
48019 +#define PRIO_RING 0xc
48020 +
48021 +
48022 +// Flags for Bulkflags control for bulk out data
48023 +//
48024 +#define fRTUSB_BULK_OUT_DATA_NULL 0x00000001
48025 +#define fRTUSB_BULK_OUT_RTS 0x00000002
48026 +#define fRTUSB_BULK_OUT_MLME 0x00000004
48027 +
48028 +#define fRTUSB_BULK_OUT_DATA_NORMAL 0x00010000
48029 +#define fRTUSB_BULK_OUT_DATA_NORMAL_2 0x00020000
48030 +#define fRTUSB_BULK_OUT_DATA_NORMAL_3 0x00040000
48031 +#define fRTUSB_BULK_OUT_DATA_NORMAL_4 0x00080000
48032 +#define fRTUSB_BULK_OUT_DATA_NORMAL_5 0x00100000
48033 +
48034 +#define fRTUSB_BULK_OUT_PSPOLL 0x00000020
48035 +#define fRTUSB_BULK_OUT_DATA_FRAG 0x00000040
48036 +#define fRTUSB_BULK_OUT_DATA_FRAG_2 0x00000080
48037 +#define fRTUSB_BULK_OUT_DATA_FRAG_3 0x00000100
48038 +#define fRTUSB_BULK_OUT_DATA_FRAG_4 0x00000200
48039 +
48040 +#ifdef RALINK_ATE
48041 +#define fRTUSB_BULK_OUT_DATA_ATE 0x00100000
48042 +#endif // RALINK_ATE //
48043 +
48044 +#define RT2870_USB_DEVICES \
48045 +{ \
48046 + {USB_DEVICE(0x148F,0x2770)}, /* Ralink */ \
48047 + {USB_DEVICE(0x148F,0x2870)}, /* Ralink */ \
48048 + {USB_DEVICE(0x148F,0x3070)}, /* Ralink 3070 */ \
48049 + {USB_DEVICE(0x148F,0x3071)}, /* Ralink 3071 */ \
48050 + {USB_DEVICE(0x148F,0x3072)}, /* Ralink 3072 */ \
48051 + {USB_DEVICE(0x0B05,0x1731)}, /* Asus */ \
48052 + {USB_DEVICE(0x0B05,0x1732)}, /* Asus */ \
48053 + {USB_DEVICE(0x0B05,0x1742)}, /* Asus */ \
48054 + {USB_DEVICE(0x0DF6,0x0017)}, /* Sitecom */ \
48055 + {USB_DEVICE(0x0DF6,0x002B)}, /* Sitecom */ \
48056 + {USB_DEVICE(0x0DF6,0x002C)}, /* Sitecom */ \
48057 + {USB_DEVICE(0x0DF6,0x003E)}, /* Sitecom 3070 */ \
48058 + {USB_DEVICE(0x0DF6,0x002D)}, /* Sitecom */ \
48059 + {USB_DEVICE(0x0DF6,0x0039)}, /* Sitecom 2770 */ \
48060 + {USB_DEVICE(0x14B2,0x3C06)}, /* Conceptronic */ \
48061 + {USB_DEVICE(0x14B2,0x3C28)}, /* Conceptronic */ \
48062 + {USB_DEVICE(0x2019,0xED06)}, /* Planex Communications, Inc. */ \
48063 + {USB_DEVICE(0x2019,0xAB25)}, /* Planex Communications, Inc. RT3070 */ \
48064 + {USB_DEVICE(0x07D1,0x3C09)}, /* D-Link */ \
48065 + {USB_DEVICE(0x07D1,0x3C11)}, /* D-Link */ \
48066 + {USB_DEVICE(0x2001,0x3C09)}, /* D-Link */ \
48067 + {USB_DEVICE(0x2001,0x3C0A)}, /* D-Link 3072*/ \
48068 + {USB_DEVICE(0x14B2,0x3C07)}, /* AL */ \
48069 + {USB_DEVICE(0x14B2,0x3C12)}, /* AL 3070 */ \
48070 + {USB_DEVICE(0x050D,0x8053)}, /* Belkin */ \
48071 + {USB_DEVICE(0x14B2,0x3C23)}, /* Airlink */ \
48072 + {USB_DEVICE(0x14B2,0x3C27)}, /* Airlink */ \
48073 + {USB_DEVICE(0x07AA,0x002F)}, /* Corega */ \
48074 + {USB_DEVICE(0x07AA,0x003C)}, /* Corega */ \
48075 + {USB_DEVICE(0x07AA,0x003F)}, /* Corega */ \
48076 + {USB_DEVICE(0x18C5,0x0012)}, /* Corega 3070 */ \
48077 + {USB_DEVICE(0x1044,0x800B)}, /* Gigabyte */ \
48078 + {USB_DEVICE(0x1044,0x800D)}, /* Gigabyte GN-WB32L 3070 */ \
48079 + {USB_DEVICE(0x15A9,0x0006)}, /* Sparklan */ \
48080 + {USB_DEVICE(0x083A,0xB522)}, /* SMC */ \
48081 + {USB_DEVICE(0x083A,0xA618)}, /* SMC */ \
48082 + {USB_DEVICE(0x083A,0x8522)}, /* Arcadyan */ \
48083 + {USB_DEVICE(0x083A,0x7512)}, /* Arcadyan 2770 */ \
48084 + {USB_DEVICE(0x083A,0x7522)}, /* Arcadyan */ \
48085 + {USB_DEVICE(0x083A,0x7511)}, /* Arcadyan 3070 */ \
48086 + {USB_DEVICE(0x0CDE,0x0022)}, /* ZCOM */ \
48087 + {USB_DEVICE(0x0586,0x3416)}, /* Zyxel */ \
48088 + {USB_DEVICE(0x0CDE,0x0025)}, /* Zyxel */ \
48089 + {USB_DEVICE(0x1740,0x9701)}, /* EnGenius */ \
48090 + {USB_DEVICE(0x1740,0x9702)}, /* EnGenius */ \
48091 + {USB_DEVICE(0x1740,0x9703)}, /* EnGenius 3070 */ \
48092 + {USB_DEVICE(0x0471,0x200f)}, /* Philips */ \
48093 + {USB_DEVICE(0x14B2,0x3C25)}, /* Draytek */ \
48094 + {USB_DEVICE(0x13D3,0x3247)}, /* AzureWave */ \
48095 + {USB_DEVICE(0x13D3,0x3273)}, /* AzureWave 3070*/ \
48096 + {USB_DEVICE(0x083A,0x6618)}, /* Accton */ \
48097 + {USB_DEVICE(0x15c5,0x0008)}, /* Amit */ \
48098 + {USB_DEVICE(0x0E66,0x0001)}, /* Hawking */ \
48099 + {USB_DEVICE(0x0E66,0x0003)}, /* Hawking */ \
48100 + {USB_DEVICE(0x129B,0x1828)}, /* Siemens */ \
48101 + {USB_DEVICE(0x157E,0x300E)}, /* U-Media */ \
48102 + {USB_DEVICE(0x050d,0x805c)}, \
48103 + {USB_DEVICE(0x1482,0x3C09)}, /* Abocom*/ \
48104 + {USB_DEVICE(0x14B2,0x3C09)}, /* Alpha */ \
48105 + {USB_DEVICE(0x04E8,0x2018)}, /* samsung */ \
48106 + {USB_DEVICE(0x07B8,0x3070)}, /* AboCom 3070 */ \
48107 + {USB_DEVICE(0x07B8,0x3071)}, /* AboCom 3071 */ \
48108 + {USB_DEVICE(0x07B8,0x3072)}, /* Abocom 3072 */ \
48109 + {USB_DEVICE(0x7392,0x7711)}, /* Edimax 3070 */ \
48110 + {USB_DEVICE(0x5A57,0x0280)}, /* Zinwell */ \
48111 + {USB_DEVICE(0x5A57,0x0282)}, /* Zinwell */ \
48112 + {USB_DEVICE(0x1A32,0x0304)}, /* Quanta 3070 */ \
48113 + {USB_DEVICE(0x0789,0x0162)}, /* Logitec 2870 */ \
48114 + {USB_DEVICE(0x0789,0x0163)}, /* Logitec 2870 */ \
48115 + {USB_DEVICE(0x0789,0x0164)}, /* Logitec 2870 */ \
48116 + {USB_DEVICE(0x1EDA,0x2310)}, /* AirTies 3070 */ \
48117 + { }/* Terminating entry */ \
48118 +}
48119 +
48120 +#define FREE_HTTX_RING(_p, _b, _t) \
48121 +{ \
48122 + if ((_t)->ENextBulkOutPosition == (_t)->CurWritePosition) \
48123 + { \
48124 + (_t)->bRingEmpty = TRUE; \
48125 + } \
48126 + /*NdisInterlockedDecrement(&(_p)->TxCount); */\
48127 +}
48128 +
48129 +//
48130 +// RXINFO appends at the end of each rx packet.
48131 +//
48132 +#ifdef RT_BIG_ENDIAN
48133 +typedef struct PACKED _RXINFO_STRUC {
48134 + UINT32 PlcpSignal:12;
48135 + UINT32 LastAMSDU:1;
48136 + UINT32 CipherAlg:1;
48137 + UINT32 PlcpRssil:1;
48138 + UINT32 Decrypted:1;
48139 + UINT32 AMPDU:1; // To be moved
48140 + UINT32 L2PAD:1;
48141 + UINT32 RSSI:1;
48142 + UINT32 HTC:1;
48143 + UINT32 AMSDU:1; // rx with 802.3 header, not 802.11 header.
48144 + UINT32 CipherErr:2; // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
48145 + UINT32 Crc:1; // 1: CRC error
48146 + UINT32 MyBss:1; // 1: this frame belongs to the same BSSID
48147 + UINT32 Bcast:1; // 1: this is a broadcast frame
48148 + UINT32 Mcast:1; // 1: this is a multicast frame
48149 + UINT32 U2M:1; // 1: this RX frame is unicast to me
48150 + UINT32 FRAG:1;
48151 + UINT32 NULLDATA:1;
48152 + UINT32 DATA:1;
48153 + UINT32 BA:1;
48154 +} RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
48155 +#else
48156 +typedef struct PACKED _RXINFO_STRUC {
48157 + UINT32 BA:1;
48158 + UINT32 DATA:1;
48159 + UINT32 NULLDATA:1;
48160 + UINT32 FRAG:1;
48161 + UINT32 U2M:1; // 1: this RX frame is unicast to me
48162 + UINT32 Mcast:1; // 1: this is a multicast frame
48163 + UINT32 Bcast:1; // 1: this is a broadcast frame
48164 + UINT32 MyBss:1; // 1: this frame belongs to the same BSSID
48165 + UINT32 Crc:1; // 1: CRC error
48166 + UINT32 CipherErr:2; // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
48167 + UINT32 AMSDU:1; // rx with 802.3 header, not 802.11 header.
48168 + UINT32 HTC:1;
48169 + UINT32 RSSI:1;
48170 + UINT32 L2PAD:1;
48171 + UINT32 AMPDU:1; // To be moved
48172 + UINT32 Decrypted:1;
48173 + UINT32 PlcpRssil:1;
48174 + UINT32 CipherAlg:1;
48175 + UINT32 LastAMSDU:1;
48176 + UINT32 PlcpSignal:12;
48177 +} RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
48178 +#endif
48179 +
48180 +
48181 +//
48182 +// TXINFO
48183 +//
48184 +#ifdef RT_BIG_ENDIAN
48185 +typedef struct _TXINFO_STRUC {
48186 + // Word 0
48187 + UINT32 USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
48188 + UINT32 USBDMANextVLD:1; //used ONLY in USB bulk Aggregation, NextValid
48189 + UINT32 rsv2:2; // Software use.
48190 + UINT32 SwUseLastRound:1; // Software use.
48191 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
48192 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
48193 + UINT32 rsv:8;
48194 + UINT32 USBDMATxPktLen:16; //used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame.
48195 +} TXINFO_STRUC, *PTXINFO_STRUC;
48196 +#else
48197 +typedef struct _TXINFO_STRUC {
48198 + // Word 0
48199 + UINT32 USBDMATxPktLen:16; //used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame.
48200 + UINT32 rsv:8;
48201 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
48202 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
48203 + UINT32 SwUseLastRound:1; // Software use.
48204 + UINT32 rsv2:2; // Software use.
48205 + UINT32 USBDMANextVLD:1; //used ONLY in USB bulk Aggregation, NextValid
48206 + UINT32 USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
48207 +} TXINFO_STRUC, *PTXINFO_STRUC;
48208 +#endif
48209 +
48210 +#define TXINFO_SIZE 4
48211 +#define RXINFO_SIZE 4
48212 +#define TXPADDING_SIZE 11
48213 +
48214 +//
48215 +// Management ring buffer format
48216 +//
48217 +typedef struct _MGMT_STRUC {
48218 + BOOLEAN Valid;
48219 + PUCHAR pBuffer;
48220 + ULONG Length;
48221 +} MGMT_STRUC, *PMGMT_STRUC;
48222 +
48223 +
48224 +/* ----------------- EEPROM Related MACRO ----------------- */
48225 +#ifdef RT30xx
48226 +#define RT28xx_EEPROM_READ16(pAd, offset, var) \
48227 + do { \
48228 + RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2); \
48229 + if(!pAd->bUseEfuse) \
48230 + var = le2cpu16(var); \
48231 + }while(0)
48232 +
48233 +#define RT28xx_EEPROM_WRITE16(pAd, offset, var) \
48234 + do{ \
48235 + USHORT _tmpVar=var; \
48236 + if(!pAd->bUseEfuse) \
48237 + _tmpVar = cpu2le16(var); \
48238 + RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2); \
48239 + }while(0)
48240 +#endif // RT30xx //
48241 +#ifndef RT30xx
48242 +#define RT28xx_EEPROM_READ16(pAd, offset, var) \
48243 + do { \
48244 + RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2); \
48245 + var = le2cpu16(var); \
48246 + }while(0)
48247 +
48248 +#define RT28xx_EEPROM_WRITE16(pAd, offset, var) \
48249 + do{ \
48250 + USHORT _tmpVar=var; \
48251 + _tmpVar = cpu2le16(var); \
48252 + RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2); \
48253 + }while(0)
48254 +#endif // RT30xx //
48255 +
48256 +/* ----------------- TASK/THREAD Related MACRO ----------------- */
48257 +#define RT28XX_TASK_THREAD_INIT(pAd, Status) \
48258 + Status = CreateThreads(net_dev);
48259 +
48260 +
48261 +/* ----------------- Frimware Related MACRO ----------------- */
48262 +#define RT28XX_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
48263 + RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
48264 +
48265 +/* ----------------- TX Related MACRO ----------------- */
48266 +#define RT28XX_START_DEQUEUE(pAd, QueIdx, irqFlags) \
48267 + { \
48268 + RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
48269 + if (pAd->DeQueueRunning[QueIdx]) \
48270 + { \
48271 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
48272 + printk("DeQueueRunning[%d]= TRUE!\n", QueIdx); \
48273 + continue; \
48274 + } \
48275 + else \
48276 + { \
48277 + pAd->DeQueueRunning[QueIdx] = TRUE; \
48278 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
48279 + } \
48280 + }
48281 +#define RT28XX_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
48282 + do{ \
48283 + RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
48284 + pAd->DeQueueRunning[QueIdx] = FALSE; \
48285 + RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
48286 + }while(0)
48287 +
48288 +
48289 +#define RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
48290 + (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
48291 +
48292 +#define RT28XX_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
48293 + do{}while(0)
48294 +
48295 +#define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
48296 + ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
48297 +
48298 +
48299 +
48300 +#define fRTMP_ADAPTER_NEED_STOP_TX \
48301 + (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
48302 + fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
48303 + fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
48304 +
48305 +
48306 +#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
48307 + RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
48308 +
48309 +#define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber) \
48310 + RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
48311 +
48312 +#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
48313 + RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
48314 +
48315 +#define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber) \
48316 + RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
48317 +
48318 +#define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
48319 + RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
48320 +
48321 +#define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
48322 + /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx)*/
48323 +
48324 +#define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
48325 + RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
48326 +
48327 +
48328 +#define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
48329 + RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
48330 +
48331 +#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
48332 + RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
48333 +
48334 +#define RTMP_PKT_TAIL_PADDING 11 // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
48335 +
48336 +extern UCHAR EpToQueue[6];
48337 +
48338 +
48339 +#ifdef RT2870
48340 +#define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
48341 +#define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
48342 +#endif // RT2870 //
48343 +
48344 +
48345 +/* ----------------- RX Related MACRO ----------------- */
48346 +//#define RT28XX_RX_ERROR_CHECK RTMPCheckRxWI
48347 +
48348 +#define RT28XX_RV_ALL_BUF_END(bBulkReceive) \
48349 + /* We return STATUS_MORE_PROCESSING_REQUIRED so that the completion */ \
48350 + /* routine (IofCompleteRequest) will stop working on the irp. */ \
48351 + if (bBulkReceive == TRUE) RTUSBBulkReceive(pAd);
48352 +
48353 +
48354 +/* ----------------- ASIC Related MACRO ----------------- */
48355 +// reset MAC of a station entry to 0xFFFFFFFFFFFF
48356 +#define RT28XX_STA_ENTRY_MAC_RESET(pAd, Wcid) \
48357 + { RT_SET_ASIC_WCID SetAsicWcid; \
48358 + SetAsicWcid.WCID = Wcid; \
48359 + SetAsicWcid.SetTid = 0xffffffff; \
48360 + SetAsicWcid.DeleteTid = 0xffffffff; \
48361 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID, \
48362 + &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); }
48363 +
48364 +// add this entry into ASIC RX WCID search table
48365 +#define RT28XX_STA_ENTRY_ADD(pAd, pEntry) \
48366 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY, \
48367 + pEntry, sizeof(MAC_TABLE_ENTRY));
48368 +
48369 +// add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
48370 +// Set MAC register value according operation mode
48371 +#define RT28XX_UPDATE_PROTECT(pAd) \
48372 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_UPDATE_PROTECT, NULL, 0);
48373 +// end johnli
48374 +
48375 +// remove Pair-wise key material from ASIC
48376 +// yet implement
48377 +#define RT28XX_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid)
48378 +
48379 +// add Client security information into ASIC WCID table and IVEIV table
48380 +#define RT28XX_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \
48381 + { RT28XX_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid); \
48382 + if (pEntry->Aid >= 1) { \
48383 + RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri; \
48384 + SetAsicWcidAttri.WCID = pEntry->Aid; \
48385 + if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && \
48386 + (pEntry->WepStatus == Ndis802_11Encryption1Enabled)) \
48387 + { \
48388 + SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
48389 + } \
48390 + else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone) \
48391 + { \
48392 + SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
48393 + } \
48394 + else SetAsicWcidAttri.Cipher = 0; \
48395 + DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher)); \
48396 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER, \
48397 + &SetAsicWcidAttri, sizeof(RT_SET_ASIC_WCID_ATTRI)); } }
48398 +
48399 +// Insert the BA bitmap to ASIC for the Wcid entry
48400 +#define RT28XX_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \
48401 + do{ \
48402 + RT_SET_ASIC_WCID SetAsicWcid; \
48403 + SetAsicWcid.WCID = (_Aid); \
48404 + SetAsicWcid.SetTid = (0x10000<<(_TID)); \
48405 + SetAsicWcid.DeleteTid = 0xffffffff; \
48406 + RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); \
48407 + }while(0)
48408 +
48409 +// Remove the BA bitmap from ASIC for the Wcid entry
48410 +#define RT28XX_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \
48411 + do{ \
48412 + RT_SET_ASIC_WCID SetAsicWcid; \
48413 + SetAsicWcid.WCID = (_Wcid); \
48414 + SetAsicWcid.SetTid = (0xffffffff); \
48415 + SetAsicWcid.DeleteTid = (0x10000<<(_TID) ); \
48416 + RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID)); \
48417 + }while(0)
48418 +
48419 +
48420 +/* ----------------- PCI/USB Related MACRO ----------------- */
48421 +#define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p) \
48422 + ((POS_COOKIE)handle)->pUsb_Dev = dev_p;
48423 +
48424 +// no use
48425 +#define RT28XX_UNMAP()
48426 +#define RT28XX_IRQ_REQUEST(net_dev)
48427 +#define RT28XX_IRQ_RELEASE(net_dev)
48428 +#define RT28XX_IRQ_INIT(pAd)
48429 +#define RT28XX_IRQ_ENABLE(pAd)
48430 +
48431 +
48432 +/* ----------------- MLME Related MACRO ----------------- */
48433 +#define RT28XX_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
48434 +
48435 +#define RT28XX_MLME_PRE_SANITY_CHECK(pAd) \
48436 + { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \
48437 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \
48438 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \
48439 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
48440 +
48441 +#define RT28XX_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
48442 + { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
48443 + RTUSBMlmeUp(pAd); }
48444 +
48445 +#define RT28XX_MLME_RESET_STATE_MACHINE(pAd) \
48446 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
48447 + RTUSBMlmeUp(pAd);
48448 +
48449 +#define RT28XX_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
48450 + { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY)); \
48451 + RTUSBMlmeUp(_pAd); \
48452 + }
48453 +
48454 +
48455 +/* ----------------- Power Save Related MACRO ----------------- */
48456 +#define RT28XX_PS_POLL_ENQUEUE(pAd) \
48457 + { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
48458 + RTUSBKickBulkOut(pAd); }
48459 +
48460 +#define RT28xx_CHIP_NAME "RT2870"
48461 +#define USB_CYC_CFG 0x02a4
48462 +#define NT_SUCCESS(status) (((status) > 0) ? (1):(0))
48463 +#define InterlockedIncrement atomic_inc
48464 +#define NdisInterlockedIncrement atomic_inc
48465 +#define InterlockedDecrement atomic_dec
48466 +#define NdisInterlockedDecrement atomic_dec
48467 +#define InterlockedExchange atomic_set
48468 +//#define NdisMSendComplete RTMP_SendComplete
48469 +#define NdisMCancelTimer RTMPCancelTimer
48470 +#define NdisAllocMemory(_ptr, _size, _flag) \
48471 + do{_ptr = kmalloc((_size),(_flag));}while(0)
48472 +#define NdisFreeMemory(a, b, c) kfree((a))
48473 +#define NdisMSleep RTMPusecDelay /* unit: microsecond */
48474 +
48475 +
48476 +#define USBD_TRANSFER_DIRECTION_OUT 0
48477 +#define USBD_TRANSFER_DIRECTION_IN 0
48478 +#define USBD_SHORT_TRANSFER_OK 0
48479 +#define PURB purbb_t
48480 +
48481 +#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb)
48482 +
48483 +//#undef MlmeAllocateMemory
48484 +//#undef MlmeFreeMemory
48485 +
48486 +typedef struct usb_device * PUSB_DEV;
48487 +
48488 +/* MACRO for linux usb */
48489 +typedef struct urb *purbb_t;
48490 +typedef struct usb_ctrlrequest devctrlrequest;
48491 +#define PIRP PVOID
48492 +#define PMDL PVOID
48493 +#define NDIS_OID UINT
48494 +#ifndef USB_ST_NOERROR
48495 +#define USB_ST_NOERROR 0
48496 +#endif
48497 +
48498 +// vendor-specific control operations
48499 +#define CONTROL_TIMEOUT_JIFFIES ( (100 * HZ) / 1000)
48500 +#define UNLINK_TIMEOUT_MS 3
48501 +
48502 +/* unlink urb */
48503 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,7)
48504 +#define RTUSB_UNLINK_URB(pUrb) usb_kill_urb(pUrb)
48505 +#else
48506 +#define RTUSB_UNLINK_URB(pUrb) usb_unlink_urb(pUrb)
48507 +#endif
48508 +
48509 +// Prototypes of completion funuc.
48510 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
48511 +#define RTUSBBulkOutDataPacketComplete(purb, pt_regs) RTUSBBulkOutDataPacketComplete(purb)
48512 +#define RTUSBBulkOutMLMEPacketComplete(pUrb, pt_regs) RTUSBBulkOutMLMEPacketComplete(pUrb)
48513 +#define RTUSBBulkOutNullFrameComplete(pUrb, pt_regs) RTUSBBulkOutNullFrameComplete(pUrb)
48514 +#define RTUSBBulkOutRTSFrameComplete(pUrb, pt_regs) RTUSBBulkOutRTSFrameComplete(pUrb)
48515 +#define RTUSBBulkOutPsPollComplete(pUrb, pt_regs) RTUSBBulkOutPsPollComplete(pUrb)
48516 +#define RTUSBBulkRxComplete(pUrb, pt_regs) RTUSBBulkRxComplete(pUrb)
48517 +#endif
48518 +
48519 +
48520 +VOID RTUSBBulkOutDataPacketComplete(purbb_t purb, struct pt_regs *pt_regs);
48521 +VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs);
48522 +VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
48523 +VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
48524 +VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb, struct pt_regs *pt_regs);
48525 +VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs);
48526 +
48527 +
48528 +#define RTUSBMlmeUp(pAd) \
48529 +{ \
48530 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie; \
48531 + if(pObj->MLMEThr_pid>0) \
48532 + up(&(pAd->mlme_semaphore)); \
48533 +}
48534 +
48535 +#define RTUSBCMDUp(pAd) \
48536 +{ \
48537 + POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie; \
48538 + if(pObj->RTUSBCmdThr_pid>0) \
48539 + up(&(pAd->RTUSBCmd_semaphore)); \
48540 +}
48541 +
48542 +
48543 +static inline NDIS_STATUS RTMPAllocateMemory(
48544 + OUT PVOID *ptr,
48545 + IN size_t size)
48546 +{
48547 + *ptr = kmalloc(size, GFP_ATOMIC);
48548 + if(*ptr)
48549 + return NDIS_STATUS_SUCCESS;
48550 + else
48551 + return NDIS_STATUS_RESOURCES;
48552 +}
48553 +
48554 +/* rtmp.h */
48555 +#define BEACON_RING_SIZE 2
48556 +#define DEVICE_VENDOR_REQUEST_OUT 0x40
48557 +#define DEVICE_VENDOR_REQUEST_IN 0xc0
48558 +#define INTERFACE_VENDOR_REQUEST_OUT 0x41
48559 +#define INTERFACE_VENDOR_REQUEST_IN 0xc1
48560 +#define MGMTPIPEIDX 0 // EP6 is highest priority
48561 +
48562 +#define BULKOUT_MGMT_RESET_FLAG 0x80
48563 +
48564 +#define RTUSB_SET_BULK_FLAG(_M, _F) ((_M)->BulkFlags |= (_F))
48565 +#define RTUSB_CLEAR_BULK_FLAG(_M, _F) ((_M)->BulkFlags &= ~(_F))
48566 +#define RTUSB_TEST_BULK_FLAG(_M, _F) (((_M)->BulkFlags & (_F)) != 0)
48567 +
48568 +#define EnqueueCmd(cmdq, cmdqelmt) \
48569 +{ \
48570 + if (cmdq->size == 0) \
48571 + cmdq->head = cmdqelmt; \
48572 + else \
48573 + cmdq->tail->next = cmdqelmt; \
48574 + cmdq->tail = cmdqelmt; \
48575 + cmdqelmt->next = NULL; \
48576 + cmdq->size++; \
48577 +}
48578 +
48579 +typedef struct _RT_SET_ASIC_WCID {
48580 + ULONG WCID; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
48581 + ULONG SetTid; // time-based: seconds, packet-based: kilo-packets
48582 + ULONG DeleteTid; // time-based: seconds, packet-based: kilo-packets
48583 +} RT_SET_ASIC_WCID,*PRT_SET_ASIC_WCID;
48584 +
48585 +typedef struct _RT_SET_ASIC_WCID_ATTRI {
48586 + ULONG WCID; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
48587 + ULONG Cipher; // ASIC Cipher definition
48588 + UCHAR Addr[ETH_LENGTH_OF_ADDRESS];
48589 +} RT_SET_ASIC_WCID_ATTRI,*PRT_SET_ASIC_WCID_ATTRI;
48590 +
48591 +typedef struct _MLME_MEMORY_STRUCT {
48592 + PVOID AllocVa; //Pointer to the base virtual address of the allocated memory
48593 + struct _MLME_MEMORY_STRUCT *Next; //Pointer to the next virtual address of the allocated memory
48594 +} MLME_MEMORY_STRUCT, *PMLME_MEMORY_STRUCT;
48595 +
48596 +typedef struct _MLME_MEMORY_HANDLER {
48597 + BOOLEAN MemRunning; //The flag of the Mlme memory handler's status
48598 + UINT MemoryCount; //Total nonpaged system-space memory not size
48599 + UINT InUseCount; //Nonpaged system-space memory in used counts
48600 + UINT UnUseCount; //Nonpaged system-space memory available counts
48601 + INT PendingCount; //Nonpaged system-space memory for free counts
48602 + PMLME_MEMORY_STRUCT pInUseHead; //Pointer to the first nonpaed memory not used
48603 + PMLME_MEMORY_STRUCT pInUseTail; //Pointer to the last nonpaged memory not used
48604 + PMLME_MEMORY_STRUCT pUnUseHead; //Pointer to the first nonpaged memory in used
48605 + PMLME_MEMORY_STRUCT pUnUseTail; //Pointer to the last nonpaged memory in used
48606 + PULONG MemFreePending[MAX_MLME_HANDLER_MEMORY]; //an array to keep pending free-memory's pointer (32bits)
48607 +} MLME_MEMORY_HANDLER, *PMLME_MEMORY_HANDLER;
48608 +
48609 +typedef struct _CmdQElmt {
48610 + UINT command;
48611 + PVOID buffer;
48612 + ULONG bufferlength;
48613 + BOOLEAN CmdFromNdis;
48614 + BOOLEAN SetOperation;
48615 + struct _CmdQElmt *next;
48616 +} CmdQElmt, *PCmdQElmt;
48617 +
48618 +typedef struct _CmdQ {
48619 + UINT size;
48620 + CmdQElmt *head;
48621 + CmdQElmt *tail;
48622 + UINT32 CmdQState;
48623 +}CmdQ, *PCmdQ;
48624 +
48625 +//
48626 +// For WPA SUPPLICANT: WIRELESS EXT support wireless events: v14 or newer
48627 +//
48628 +#if WIRELESS_EXT >= 14
48629 +//#define WPA_SUPPLICANT_SUPPORT 1
48630 +#endif
48631 +
48632 +/* oid.h */
48633 +// Cipher suite type for mixed mode group cipher, P802.11i-2004
48634 +typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
48635 + Cipher_Type_NONE,
48636 + Cipher_Type_WEP40,
48637 + Cipher_Type_TKIP,
48638 + Cipher_Type_RSVD,
48639 + Cipher_Type_CCMP,
48640 + Cipher_Type_WEP104
48641 +} RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
48642 +
48643 +//CMDTHREAD_MULTI_READ_MAC
48644 +//CMDTHREAD_MULTI_WRITE_MAC
48645 +//CMDTHREAD_VENDOR_EEPROM_READ
48646 +//CMDTHREAD_VENDOR_EEPROM_WRITE
48647 +typedef struct _CMDHandler_TLV {
48648 + USHORT Offset;
48649 + USHORT Length;
48650 + UCHAR DataFirst;
48651 +} CMDHandler_TLV, *PCMDHandler_TLV;
48652 +
48653 +// New for MeetingHouse Api support
48654 +#define CMDTHREAD_VENDOR_RESET 0x0D730101 // cmd
48655 +#define CMDTHREAD_VENDOR_UNPLUG 0x0D730102 // cmd
48656 +#define CMDTHREAD_VENDOR_SWITCH_FUNCTION 0x0D730103 // cmd
48657 +#define CMDTHREAD_MULTI_WRITE_MAC 0x0D730107 // cmd
48658 +#define CMDTHREAD_MULTI_READ_MAC 0x0D730108 // cmd
48659 +#define CMDTHREAD_VENDOR_EEPROM_WRITE 0x0D73010A // cmd
48660 +#define CMDTHREAD_VENDOR_EEPROM_READ 0x0D73010B // cmd
48661 +#define CMDTHREAD_VENDOR_ENTER_TESTMODE 0x0D73010C // cmd
48662 +#define CMDTHREAD_VENDOR_EXIT_TESTMODE 0x0D73010D // cmd
48663 +#define CMDTHREAD_VENDOR_WRITE_BBP 0x0D730119 // cmd
48664 +#define CMDTHREAD_VENDOR_READ_BBP 0x0D730118 // cmd
48665 +#define CMDTHREAD_VENDOR_WRITE_RF 0x0D73011A // cmd
48666 +#define CMDTHREAD_VENDOR_FLIP_IQ 0x0D73011D // cmd
48667 +#define CMDTHREAD_RESET_BULK_OUT 0x0D730210 // cmd
48668 +#define CMDTHREAD_RESET_BULK_IN 0x0D730211 // cmd
48669 +#define CMDTHREAD_SET_PSM_BIT_SAVE 0x0D730212 // cmd
48670 +#define CMDTHREAD_SET_RADIO 0x0D730214 // cmd
48671 +#define CMDTHREAD_UPDATE_TX_RATE 0x0D730216 // cmd
48672 +#define CMDTHREAD_802_11_ADD_KEY_WEP 0x0D730218 // cmd
48673 +#define CMDTHREAD_RESET_FROM_ERROR 0x0D73021A // cmd
48674 +#define CMDTHREAD_LINK_DOWN 0x0D73021B // cmd
48675 +#define CMDTHREAD_RESET_FROM_NDIS 0x0D73021C // cmd
48676 +#define CMDTHREAD_CHECK_GPIO 0x0D730215 // cmd
48677 +#define CMDTHREAD_FORCE_WAKE_UP 0x0D730222 // cmd
48678 +#define CMDTHREAD_SET_BW 0x0D730225 // cmd
48679 +#define CMDTHREAD_SET_ASIC_WCID 0x0D730226 // cmd
48680 +#define CMDTHREAD_SET_ASIC_WCID_CIPHER 0x0D730227 // cmd
48681 +#define CMDTHREAD_QKERIODIC_EXECUT 0x0D73023D // cmd
48682 +#define RT_CMD_SET_KEY_TABLE 0x0D730228 // cmd
48683 +#define RT_CMD_SET_RX_WCID_TABLE 0x0D730229 // cmd
48684 +#define CMDTHREAD_SET_CLIENT_MAC_ENTRY 0x0D73023E // cmd
48685 +#define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER 0x0D710105 // cmd
48686 +#define CMDTHREAD_802_11_SET_PHY_MODE 0x0D79010C // cmd
48687 +#define CMDTHREAD_802_11_SET_STA_CONFIG 0x0D790111 // cmd
48688 +#define CMDTHREAD_802_11_SET_PREAMBLE 0x0D790101 // cmd
48689 +#define CMDTHREAD_802_11_COUNTER_MEASURE 0x0D790102 // cmd
48690 +// add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
48691 +#define CMDTHREAD_UPDATE_PROTECT 0x0D790103 // cmd
48692 +// end johnli
48693 +
48694 +#define WPA1AKMBIT 0x01
48695 +#define WPA2AKMBIT 0x02
48696 +#define WPA1PSKAKMBIT 0x04
48697 +#define WPA2PSKAKMBIT 0x08
48698 +#define TKIPBIT 0x01
48699 +#define CCMPBIT 0x02
48700 +
48701 +
48702 +#define RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx) \
48703 + RT28xxUsbStaAsicForceWakeup(pAd, bFromTx);
48704 +
48705 +#define RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
48706 + RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
48707 +
48708 +#define RT28XX_MLME_RADIO_ON(pAd) \
48709 + RT28xxUsbMlmeRadioOn(pAd);
48710 +
48711 +#define RT28XX_MLME_RADIO_OFF(pAd) \
48712 + RT28xxUsbMlmeRadioOFF(pAd);
48713 +
48714 +#endif //__RT2870_H__
48715 --- /dev/null
48716 +++ b/drivers/staging/rt3070/rt28xx.h
48717 @@ -0,0 +1,2725 @@
48718 +/*
48719 + *************************************************************************
48720 + * Ralink Tech Inc.
48721 + * 5F., No.36, Taiyuan St., Jhubei City,
48722 + * Hsinchu County 302,
48723 + * Taiwan, R.O.C.
48724 + *
48725 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
48726 + *
48727 + * This program is free software; you can redistribute it and/or modify *
48728 + * it under the terms of the GNU General Public License as published by *
48729 + * the Free Software Foundation; either version 2 of the License, or *
48730 + * (at your option) any later version. *
48731 + * *
48732 + * This program is distributed in the hope that it will be useful, *
48733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
48734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
48735 + * GNU General Public License for more details. *
48736 + * *
48737 + * You should have received a copy of the GNU General Public License *
48738 + * along with this program; if not, write to the *
48739 + * Free Software Foundation, Inc., *
48740 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
48741 + * *
48742 + *************************************************************************
48743 +
48744 + Module Name:
48745 + rt28xx.h
48746 +
48747 + Abstract:
48748 + RT28xx ASIC related definition & structures
48749 +
48750 + Revision History:
48751 + Who When What
48752 + -------- ---------- ----------------------------------------------
48753 + Jan Lee Jan-3-2006 created for RT2860c
48754 +*/
48755 +
48756 +#ifndef __RT28XX_H__
48757 +#define __RT28XX_H__
48758 +
48759 +
48760 +//
48761 +// PCI registers - base address 0x0000
48762 +//
48763 +#define PCI_CFG 0x0000
48764 +#define PCI_EECTRL 0x0004
48765 +#define PCI_MCUCTRL 0x0008
48766 +
48767 +#define OPT_14 0x114
48768 +
48769 +typedef int NTSTATUS;
48770 +#define RETRY_LIMIT 10
48771 +#define STATUS_SUCCESS 0x00
48772 +#define STATUS_UNSUCCESSFUL 0x01
48773 +
48774 +//
48775 +// SCH/DMA registers - base address 0x0200
48776 +//
48777 +// INT_SOURCE_CSR: Interrupt source register. Write one to clear corresponding bit
48778 +//
48779 +#define DMA_CSR0 0x200
48780 +#define INT_SOURCE_CSR 0x200
48781 +#ifdef RT_BIG_ENDIAN
48782 +typedef union _INT_SOURCE_CSR_STRUC {
48783 + struct {
48784 + UINT32 :14;
48785 + UINT32 TxCoherent:1;
48786 + UINT32 RxCoherent:1;
48787 + UINT32 GPTimer:1;
48788 + UINT32 AutoWakeup:1;//bit14
48789 + UINT32 TXFifoStatusInt:1;//FIFO Statistics is full, sw should read 0x171c
48790 + UINT32 PreTBTT:1;
48791 + UINT32 TBTTInt:1;
48792 + UINT32 RxTxCoherent:1;
48793 + UINT32 MCUCommandINT:1;
48794 + UINT32 MgmtDmaDone:1;
48795 + UINT32 HccaDmaDone:1;
48796 + UINT32 Ac3DmaDone:1;
48797 + UINT32 Ac2DmaDone:1;
48798 + UINT32 Ac1DmaDone:1;
48799 + UINT32 Ac0DmaDone:1;
48800 + UINT32 RxDone:1;
48801 + UINT32 TxDelayINT:1; //delayed interrupt, not interrupt until several int or time limit hit
48802 + UINT32 RxDelayINT:1; //dealyed interrupt
48803 + } field;
48804 + UINT32 word;
48805 +} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC;
48806 +#else
48807 +typedef union _INT_SOURCE_CSR_STRUC {
48808 + struct {
48809 + UINT32 RxDelayINT:1;
48810 + UINT32 TxDelayINT:1;
48811 + UINT32 RxDone:1;
48812 + UINT32 Ac0DmaDone:1;//4
48813 + UINT32 Ac1DmaDone:1;
48814 + UINT32 Ac2DmaDone:1;
48815 + UINT32 Ac3DmaDone:1;
48816 + UINT32 HccaDmaDone:1; // bit7
48817 + UINT32 MgmtDmaDone:1;
48818 + UINT32 MCUCommandINT:1;//bit 9
48819 + UINT32 RxTxCoherent:1;
48820 + UINT32 TBTTInt:1;
48821 + UINT32 PreTBTT:1;
48822 + UINT32 TXFifoStatusInt:1;//FIFO Statistics is full, sw should read 0x171c
48823 + UINT32 AutoWakeup:1;//bit14
48824 + UINT32 GPTimer:1;
48825 + UINT32 RxCoherent:1;//bit16
48826 + UINT32 TxCoherent:1;
48827 + UINT32 :14;
48828 + } field;
48829 + UINT32 word;
48830 +} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC;
48831 +#endif
48832 +
48833 +//
48834 +// INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF
48835 +//
48836 +#define INT_MASK_CSR 0x204
48837 +#ifdef RT_BIG_ENDIAN
48838 +typedef union _INT_MASK_CSR_STRUC {
48839 + struct {
48840 + UINT32 TxCoherent:1;
48841 + UINT32 RxCoherent:1;
48842 + UINT32 :20;
48843 + UINT32 MCUCommandINT:1;
48844 + UINT32 MgmtDmaDone:1;
48845 + UINT32 HccaDmaDone:1;
48846 + UINT32 Ac3DmaDone:1;
48847 + UINT32 Ac2DmaDone:1;
48848 + UINT32 Ac1DmaDone:1;
48849 + UINT32 Ac0DmaDone:1;
48850 + UINT32 RxDone:1;
48851 + UINT32 TxDelay:1;
48852 + UINT32 RXDelay_INT_MSK:1;
48853 + } field;
48854 + UINT32 word;
48855 +}INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC;
48856 +#else
48857 +typedef union _INT_MASK_CSR_STRUC {
48858 + struct {
48859 + UINT32 RXDelay_INT_MSK:1;
48860 + UINT32 TxDelay:1;
48861 + UINT32 RxDone:1;
48862 + UINT32 Ac0DmaDone:1;
48863 + UINT32 Ac1DmaDone:1;
48864 + UINT32 Ac2DmaDone:1;
48865 + UINT32 Ac3DmaDone:1;
48866 + UINT32 HccaDmaDone:1;
48867 + UINT32 MgmtDmaDone:1;
48868 + UINT32 MCUCommandINT:1;
48869 + UINT32 :20;
48870 + UINT32 RxCoherent:1;
48871 + UINT32 TxCoherent:1;
48872 + } field;
48873 + UINT32 word;
48874 +} INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC;
48875 +#endif
48876 +#define WPDMA_GLO_CFG 0x208
48877 +#ifdef RT_BIG_ENDIAN
48878 +typedef union _WPDMA_GLO_CFG_STRUC {
48879 + struct {
48880 + UINT32 HDR_SEG_LEN:16;
48881 + UINT32 RXHdrScater:8;
48882 + UINT32 BigEndian:1;
48883 + UINT32 EnTXWriteBackDDONE:1;
48884 + UINT32 WPDMABurstSIZE:2;
48885 + UINT32 RxDMABusy:1;
48886 + UINT32 EnableRxDMA:1;
48887 + UINT32 TxDMABusy:1;
48888 + UINT32 EnableTxDMA:1;
48889 + } field;
48890 + UINT32 word;
48891 +}WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC;
48892 +#else
48893 +typedef union _WPDMA_GLO_CFG_STRUC {
48894 + struct {
48895 + UINT32 EnableTxDMA:1;
48896 + UINT32 TxDMABusy:1;
48897 + UINT32 EnableRxDMA:1;
48898 + UINT32 RxDMABusy:1;
48899 + UINT32 WPDMABurstSIZE:2;
48900 + UINT32 EnTXWriteBackDDONE:1;
48901 + UINT32 BigEndian:1;
48902 + UINT32 RXHdrScater:8;
48903 + UINT32 HDR_SEG_LEN:16;
48904 + } field;
48905 + UINT32 word;
48906 +} WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC;
48907 +#endif
48908 +#define WPDMA_RST_IDX 0x20c
48909 +#ifdef RT_BIG_ENDIAN
48910 +typedef union _WPDMA_RST_IDX_STRUC {
48911 + struct {
48912 + UINT32 :15;
48913 + UINT32 RST_DRX_IDX0:1;
48914 + UINT32 rsv:10;
48915 + UINT32 RST_DTX_IDX5:1;
48916 + UINT32 RST_DTX_IDX4:1;
48917 + UINT32 RST_DTX_IDX3:1;
48918 + UINT32 RST_DTX_IDX2:1;
48919 + UINT32 RST_DTX_IDX1:1;
48920 + UINT32 RST_DTX_IDX0:1;
48921 + } field;
48922 + UINT32 word;
48923 +}WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC;
48924 +#else
48925 +typedef union _WPDMA_RST_IDX_STRUC {
48926 + struct {
48927 + UINT32 RST_DTX_IDX0:1;
48928 + UINT32 RST_DTX_IDX1:1;
48929 + UINT32 RST_DTX_IDX2:1;
48930 + UINT32 RST_DTX_IDX3:1;
48931 + UINT32 RST_DTX_IDX4:1;
48932 + UINT32 RST_DTX_IDX5:1;
48933 + UINT32 rsv:10;
48934 + UINT32 RST_DRX_IDX0:1;
48935 + UINT32 :15;
48936 + } field;
48937 + UINT32 word;
48938 +} WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC;
48939 +#endif
48940 +#define DELAY_INT_CFG 0x0210
48941 +#ifdef RT_BIG_ENDIAN
48942 +typedef union _DELAY_INT_CFG_STRUC {
48943 + struct {
48944 + UINT32 TXDLY_INT_EN:1;
48945 + UINT32 TXMAX_PINT:7;
48946 + UINT32 TXMAX_PTIME:8;
48947 + UINT32 RXDLY_INT_EN:1;
48948 + UINT32 RXMAX_PINT:7;
48949 + UINT32 RXMAX_PTIME:8;
48950 + } field;
48951 + UINT32 word;
48952 +}DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC;
48953 +#else
48954 +typedef union _DELAY_INT_CFG_STRUC {
48955 + struct {
48956 + UINT32 RXMAX_PTIME:8;
48957 + UINT32 RXMAX_PINT:7;
48958 + UINT32 RXDLY_INT_EN:1;
48959 + UINT32 TXMAX_PTIME:8;
48960 + UINT32 TXMAX_PINT:7;
48961 + UINT32 TXDLY_INT_EN:1;
48962 + } field;
48963 + UINT32 word;
48964 +} DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC;
48965 +#endif
48966 +#define WMM_AIFSN_CFG 0x0214
48967 +#ifdef RT_BIG_ENDIAN
48968 +typedef union _AIFSN_CSR_STRUC {
48969 + struct {
48970 + UINT32 Rsv:16;
48971 + UINT32 Aifsn3:4; // for AC_VO
48972 + UINT32 Aifsn2:4; // for AC_VI
48973 + UINT32 Aifsn1:4; // for AC_BK
48974 + UINT32 Aifsn0:4; // for AC_BE
48975 + } field;
48976 + UINT32 word;
48977 +} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC;
48978 +#else
48979 +typedef union _AIFSN_CSR_STRUC {
48980 + struct {
48981 + UINT32 Aifsn0:4; // for AC_BE
48982 + UINT32 Aifsn1:4; // for AC_BK
48983 + UINT32 Aifsn2:4; // for AC_VI
48984 + UINT32 Aifsn3:4; // for AC_VO
48985 + UINT32 Rsv:16;
48986 + } field;
48987 + UINT32 word;
48988 +} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC;
48989 +#endif
48990 +//
48991 +// CWMIN_CSR: CWmin for each EDCA AC
48992 +//
48993 +#define WMM_CWMIN_CFG 0x0218
48994 +#ifdef RT_BIG_ENDIAN
48995 +typedef union _CWMIN_CSR_STRUC {
48996 + struct {
48997 + UINT32 Rsv:16;
48998 + UINT32 Cwmin3:4; // for AC_VO
48999 + UINT32 Cwmin2:4; // for AC_VI
49000 + UINT32 Cwmin1:4; // for AC_BK
49001 + UINT32 Cwmin0:4; // for AC_BE
49002 + } field;
49003 + UINT32 word;
49004 +} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC;
49005 +#else
49006 +typedef union _CWMIN_CSR_STRUC {
49007 + struct {
49008 + UINT32 Cwmin0:4; // for AC_BE
49009 + UINT32 Cwmin1:4; // for AC_BK
49010 + UINT32 Cwmin2:4; // for AC_VI
49011 + UINT32 Cwmin3:4; // for AC_VO
49012 + UINT32 Rsv:16;
49013 + } field;
49014 + UINT32 word;
49015 +} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC;
49016 +#endif
49017 +
49018 +//
49019 +// CWMAX_CSR: CWmin for each EDCA AC
49020 +//
49021 +#define WMM_CWMAX_CFG 0x021c
49022 +#ifdef RT_BIG_ENDIAN
49023 +typedef union _CWMAX_CSR_STRUC {
49024 + struct {
49025 + UINT32 Rsv:16;
49026 + UINT32 Cwmax3:4; // for AC_VO
49027 + UINT32 Cwmax2:4; // for AC_VI
49028 + UINT32 Cwmax1:4; // for AC_BK
49029 + UINT32 Cwmax0:4; // for AC_BE
49030 + } field;
49031 + UINT32 word;
49032 +} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC;
49033 +#else
49034 +typedef union _CWMAX_CSR_STRUC {
49035 + struct {
49036 + UINT32 Cwmax0:4; // for AC_BE
49037 + UINT32 Cwmax1:4; // for AC_BK
49038 + UINT32 Cwmax2:4; // for AC_VI
49039 + UINT32 Cwmax3:4; // for AC_VO
49040 + UINT32 Rsv:16;
49041 + } field;
49042 + UINT32 word;
49043 +} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC;
49044 +#endif
49045 +
49046 +
49047 +//
49048 +// AC_TXOP_CSR0: AC_BK/AC_BE TXOP register
49049 +//
49050 +#define WMM_TXOP0_CFG 0x0220
49051 +#ifdef RT_BIG_ENDIAN
49052 +typedef union _AC_TXOP_CSR0_STRUC {
49053 + struct {
49054 + USHORT Ac1Txop; // for AC_BE, in unit of 32us
49055 + USHORT Ac0Txop; // for AC_BK, in unit of 32us
49056 + } field;
49057 + UINT32 word;
49058 +} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC;
49059 +#else
49060 +typedef union _AC_TXOP_CSR0_STRUC {
49061 + struct {
49062 + USHORT Ac0Txop; // for AC_BK, in unit of 32us
49063 + USHORT Ac1Txop; // for AC_BE, in unit of 32us
49064 + } field;
49065 + UINT32 word;
49066 +} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC;
49067 +#endif
49068 +
49069 +//
49070 +// AC_TXOP_CSR1: AC_VO/AC_VI TXOP register
49071 +//
49072 +#define WMM_TXOP1_CFG 0x0224
49073 +#ifdef RT_BIG_ENDIAN
49074 +typedef union _AC_TXOP_CSR1_STRUC {
49075 + struct {
49076 + USHORT Ac3Txop; // for AC_VO, in unit of 32us
49077 + USHORT Ac2Txop; // for AC_VI, in unit of 32us
49078 + } field;
49079 + UINT32 word;
49080 +} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC;
49081 +#else
49082 +typedef union _AC_TXOP_CSR1_STRUC {
49083 + struct {
49084 + USHORT Ac2Txop; // for AC_VI, in unit of 32us
49085 + USHORT Ac3Txop; // for AC_VO, in unit of 32us
49086 + } field;
49087 + UINT32 word;
49088 +} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC;
49089 +#endif
49090 +#define RINGREG_DIFF 0x10
49091 +#define GPIO_CTRL_CFG 0x0228 //MAC_CSR13
49092 +#define MCU_CMD_CFG 0x022c
49093 +#define TX_BASE_PTR0 0x0230 //AC_BK base address
49094 +#define TX_MAX_CNT0 0x0234
49095 +#define TX_CTX_IDX0 0x0238
49096 +#define TX_DTX_IDX0 0x023c
49097 +#define TX_BASE_PTR1 0x0240 //AC_BE base address
49098 +#define TX_MAX_CNT1 0x0244
49099 +#define TX_CTX_IDX1 0x0248
49100 +#define TX_DTX_IDX1 0x024c
49101 +#define TX_BASE_PTR2 0x0250 //AC_VI base address
49102 +#define TX_MAX_CNT2 0x0254
49103 +#define TX_CTX_IDX2 0x0258
49104 +#define TX_DTX_IDX2 0x025c
49105 +#define TX_BASE_PTR3 0x0260 //AC_VO base address
49106 +#define TX_MAX_CNT3 0x0264
49107 +#define TX_CTX_IDX3 0x0268
49108 +#define TX_DTX_IDX3 0x026c
49109 +#define TX_BASE_PTR4 0x0270 //HCCA base address
49110 +#define TX_MAX_CNT4 0x0274
49111 +#define TX_CTX_IDX4 0x0278
49112 +#define TX_DTX_IDX4 0x027c
49113 +#define TX_BASE_PTR5 0x0280 //MGMT base address
49114 +#define TX_MAX_CNT5 0x0284
49115 +#define TX_CTX_IDX5 0x0288
49116 +#define TX_DTX_IDX5 0x028c
49117 +#define TX_MGMTMAX_CNT TX_MAX_CNT5
49118 +#define TX_MGMTCTX_IDX TX_CTX_IDX5
49119 +#define TX_MGMTDTX_IDX TX_DTX_IDX5
49120 +#define RX_BASE_PTR 0x0290 //RX base address
49121 +#define RX_MAX_CNT 0x0294
49122 +#define RX_CRX_IDX 0x0298
49123 +#define RX_DRX_IDX 0x029c
49124 +#define USB_DMA_CFG 0x02a0
49125 +#ifdef RT_BIG_ENDIAN
49126 +typedef union _USB_DMA_CFG_STRUC {
49127 + struct {
49128 + UINT32 TxBusy:1; //USB DMA TX FSM busy . debug only
49129 + UINT32 RxBusy:1; //USB DMA RX FSM busy . debug only
49130 + UINT32 EpoutValid:6; //OUT endpoint data valid. debug only
49131 + UINT32 TxBulkEn:1; //Enable USB DMA Tx
49132 + UINT32 RxBulkEn:1; //Enable USB DMA Rx
49133 + UINT32 RxBulkAggEn:1; //Enable Rx Bulk Aggregation
49134 + UINT32 TxopHalt:1; //Halt TXOP count down when TX buffer is full.
49135 + UINT32 TxClear:1; //Clear USB DMA TX path
49136 + UINT32 rsv:2;
49137 + UINT32 phyclear:1; //phy watch dog enable. write 1
49138 + UINT32 RxBulkAggLmt:8; //Rx Bulk Aggregation Limit in unit of 1024 bytes
49139 + UINT32 RxBulkAggTOut:8; //Rx Bulk Aggregation TimeOut in unit of 33ns
49140 + } field;
49141 + UINT32 word;
49142 +} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC;
49143 +#else
49144 +typedef union _USB_DMA_CFG_STRUC {
49145 + struct {
49146 + UINT32 RxBulkAggTOut:8; //Rx Bulk Aggregation TimeOut in unit of 33ns
49147 + UINT32 RxBulkAggLmt:8; //Rx Bulk Aggregation Limit in unit of 256 bytes
49148 + UINT32 phyclear:1; //phy watch dog enable. write 1
49149 + UINT32 rsv:2;
49150 + UINT32 TxClear:1; //Clear USB DMA TX path
49151 + UINT32 TxopHalt:1; //Halt TXOP count down when TX buffer is full.
49152 + UINT32 RxBulkAggEn:1; //Enable Rx Bulk Aggregation
49153 + UINT32 RxBulkEn:1; //Enable USB DMA Rx
49154 + UINT32 TxBulkEn:1; //Enable USB DMA Tx
49155 + UINT32 EpoutValid:6; //OUT endpoint data valid
49156 + UINT32 RxBusy:1; //USB DMA RX FSM busy
49157 + UINT32 TxBusy:1; //USB DMA TX FSM busy
49158 + } field;
49159 + UINT32 word;
49160 +} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC;
49161 +#endif
49162 +
49163 +//
49164 +// 3 PBF registers
49165 +//
49166 +//
49167 +// Most are for debug. Driver doesn't touch PBF register.
49168 +#define PBF_SYS_CTRL 0x0400
49169 +#define PBF_CFG 0x0408
49170 +#define PBF_MAX_PCNT 0x040C
49171 +#define PBF_CTRL 0x0410
49172 +#define PBF_INT_STA 0x0414
49173 +#define PBF_INT_ENA 0x0418
49174 +#define TXRXQ_PCNT 0x0438
49175 +#define PBF_DBG 0x043c
49176 +#define PBF_CAP_CTRL 0x0440
49177 +
49178 +
49179 +// eFuse registers
49180 +#define EFUSE_CTRL 0x0580
49181 +#define EFUSE_DATA0 0x0590
49182 +#define EFUSE_DATA1 0x0594
49183 +#define EFUSE_DATA2 0x0598
49184 +#define EFUSE_DATA3 0x059c
49185 +#define EFUSE_USAGE_MAP_START 0x2d0
49186 +#define EFUSE_USAGE_MAP_END 0x2fc
49187 +#define EFUSE_TAG 0x2fe
49188 +#define EFUSE_USAGE_MAP_SIZE 45
49189 +
49190 +#ifdef RT_BIG_ENDIAN
49191 +typedef union _EFUSE_CTRL_STRUC {
49192 + struct {
49193 + UINT32 SEL_EFUSE:1;
49194 + UINT32 EFSROM_KICK:1;
49195 + UINT32 RESERVED:4;
49196 + UINT32 EFSROM_AIN:10;
49197 + UINT32 EFSROM_LDO_ON_TIME:2;
49198 + UINT32 EFSROM_LDO_OFF_TIME:6;
49199 + UINT32 EFSROM_MODE:2;
49200 + UINT32 EFSROM_AOUT:6;
49201 + } field;
49202 + UINT32 word;
49203 +} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC;
49204 +#else
49205 +typedef union _EFUSE_CTRL_STRUC {
49206 + struct {
49207 + UINT32 EFSROM_AOUT:6;
49208 + UINT32 EFSROM_MODE:2;
49209 + UINT32 EFSROM_LDO_OFF_TIME:6;
49210 + UINT32 EFSROM_LDO_ON_TIME:2;
49211 + UINT32 EFSROM_AIN:10;
49212 + UINT32 RESERVED:4;
49213 + UINT32 EFSROM_KICK:1;
49214 + UINT32 SEL_EFUSE:1;
49215 + } field;
49216 + UINT32 word;
49217 +} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC;
49218 +#endif // RT_BIG_ENDIAN //
49219 +
49220 +#define LDO_CFG0 0x05d4
49221 +#define GPIO_SWITCH 0x05dc
49222 +
49223 +//
49224 +// 4 MAC registers
49225 +//
49226 +//
49227 +// 4.1 MAC SYSTEM configuration registers (offset:0x1000)
49228 +//
49229 +#define MAC_CSR0 0x1000
49230 +#ifdef RT_BIG_ENDIAN
49231 +typedef union _ASIC_VER_ID_STRUC {
49232 + struct {
49233 + USHORT ASICVer; // version : 2860
49234 + USHORT ASICRev; // reversion : 0
49235 + } field;
49236 + UINT32 word;
49237 +} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC;
49238 +#else
49239 +typedef union _ASIC_VER_ID_STRUC {
49240 + struct {
49241 + USHORT ASICRev; // reversion : 0
49242 + USHORT ASICVer; // version : 2860
49243 + } field;
49244 + UINT32 word;
49245 +} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC;
49246 +#endif
49247 +#define MAC_SYS_CTRL 0x1004 //MAC_CSR1
49248 +#define MAC_ADDR_DW0 0x1008 // MAC ADDR DW0
49249 +#define MAC_ADDR_DW1 0x100c // MAC ADDR DW1
49250 +//
49251 +// MAC_CSR2: STA MAC register 0
49252 +//
49253 +#ifdef RT_BIG_ENDIAN
49254 +typedef union _MAC_DW0_STRUC {
49255 + struct {
49256 + UCHAR Byte3; // MAC address byte 3
49257 + UCHAR Byte2; // MAC address byte 2
49258 + UCHAR Byte1; // MAC address byte 1
49259 + UCHAR Byte0; // MAC address byte 0
49260 + } field;
49261 + UINT32 word;
49262 +} MAC_DW0_STRUC, *PMAC_DW0_STRUC;
49263 +#else
49264 +typedef union _MAC_DW0_STRUC {
49265 + struct {
49266 + UCHAR Byte0; // MAC address byte 0
49267 + UCHAR Byte1; // MAC address byte 1
49268 + UCHAR Byte2; // MAC address byte 2
49269 + UCHAR Byte3; // MAC address byte 3
49270 + } field;
49271 + UINT32 word;
49272 +} MAC_DW0_STRUC, *PMAC_DW0_STRUC;
49273 +#endif
49274 +
49275 +//
49276 +// MAC_CSR3: STA MAC register 1
49277 +//
49278 +#ifdef RT_BIG_ENDIAN
49279 +typedef union _MAC_DW1_STRUC {
49280 + struct {
49281 + UCHAR Rsvd1;
49282 + UCHAR U2MeMask;
49283 + UCHAR Byte5; // MAC address byte 5
49284 + UCHAR Byte4; // MAC address byte 4
49285 + } field;
49286 + UINT32 word;
49287 +} MAC_DW1_STRUC, *PMAC_DW1_STRUC;
49288 +#else
49289 +typedef union _MAC_DW1_STRUC {
49290 + struct {
49291 + UCHAR Byte4; // MAC address byte 4
49292 + UCHAR Byte5; // MAC address byte 5
49293 + UCHAR U2MeMask;
49294 + UCHAR Rsvd1;
49295 + } field;
49296 + UINT32 word;
49297 +} MAC_DW1_STRUC, *PMAC_DW1_STRUC;
49298 +#endif
49299 +
49300 +#define MAC_BSSID_DW0 0x1010 // MAC BSSID DW0
49301 +#define MAC_BSSID_DW1 0x1014 // MAC BSSID DW1
49302 +
49303 +//
49304 +// MAC_CSR5: BSSID register 1
49305 +//
49306 +#ifdef RT_BIG_ENDIAN
49307 +typedef union _MAC_CSR5_STRUC {
49308 + struct {
49309 + USHORT Rsvd:11;
49310 + USHORT MBssBcnNum:3;
49311 + USHORT BssIdMode:2; // 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID
49312 + UCHAR Byte5; // BSSID byte 5
49313 + UCHAR Byte4; // BSSID byte 4
49314 + } field;
49315 + UINT32 word;
49316 +} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC;
49317 +#else
49318 +typedef union _MAC_CSR5_STRUC {
49319 + struct {
49320 + UCHAR Byte4; // BSSID byte 4
49321 + UCHAR Byte5; // BSSID byte 5
49322 + USHORT BssIdMask:2; // 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID
49323 + USHORT MBssBcnNum:3;
49324 + USHORT Rsvd:11;
49325 + } field;
49326 + UINT32 word;
49327 +} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC;
49328 +#endif
49329 +
49330 +#define MAX_LEN_CFG 0x1018 // rt2860b max 16k bytes. bit12:13 Maximum PSDU length (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
49331 +#define BBP_CSR_CFG 0x101c //
49332 +//
49333 +// BBP_CSR_CFG: BBP serial control register
49334 +//
49335 +#ifdef RT_BIG_ENDIAN
49336 +typedef union _BBP_CSR_CFG_STRUC {
49337 + struct {
49338 + UINT32 :12;
49339 + UINT32 BBP_RW_MODE:1; // 0: use serial mode 1:parallel
49340 + UINT32 BBP_PAR_DUR:1; // 0: 4 MAC clock cycles 1: 8 MAC clock cycles
49341 + UINT32 Busy:1; // 1: ASIC is busy execute BBP programming.
49342 + UINT32 fRead:1; // 0: Write BBP, 1: Read BBP
49343 + UINT32 RegNum:8; // Selected BBP register
49344 + UINT32 Value:8; // Register value to program into BBP
49345 + } field;
49346 + UINT32 word;
49347 +} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC;
49348 +#else
49349 +typedef union _BBP_CSR_CFG_STRUC {
49350 + struct {
49351 + UINT32 Value:8; // Register value to program into BBP
49352 + UINT32 RegNum:8; // Selected BBP register
49353 + UINT32 fRead:1; // 0: Write BBP, 1: Read BBP
49354 + UINT32 Busy:1; // 1: ASIC is busy execute BBP programming.
49355 + UINT32 BBP_PAR_DUR:1; // 0: 4 MAC clock cycles 1: 8 MAC clock cycles
49356 + UINT32 BBP_RW_MODE:1; // 0: use serial mode 1:parallel
49357 + UINT32 :12;
49358 + } field;
49359 + UINT32 word;
49360 +} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC;
49361 +#endif
49362 +#define RF_CSR_CFG0 0x1020
49363 +//
49364 +// RF_CSR_CFG: RF control register
49365 +//
49366 +#ifdef RT_BIG_ENDIAN
49367 +typedef union _RF_CSR_CFG0_STRUC {
49368 + struct {
49369 + UINT32 Busy:1; // 0: idle 1: 8busy
49370 + UINT32 Sel:1; // 0:RF_LE0 activate 1:RF_LE1 activate
49371 + UINT32 StandbyMode:1; // 0: high when stand by 1: low when standby
49372 + UINT32 bitwidth:5; // Selected BBP register
49373 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49374 + } field;
49375 + UINT32 word;
49376 +} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC;
49377 +#else
49378 +typedef union _RF_CSR_CFG0_STRUC {
49379 + struct {
49380 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49381 + UINT32 bitwidth:5; // Selected BBP register
49382 + UINT32 StandbyMode:1; // 0: high when stand by 1: low when standby
49383 + UINT32 Sel:1; // 0:RF_LE0 activate 1:RF_LE1 activate
49384 + UINT32 Busy:1; // 0: idle 1: 8busy
49385 + } field;
49386 + UINT32 word;
49387 +} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC;
49388 +#endif
49389 +#define RF_CSR_CFG1 0x1024
49390 +#ifdef RT_BIG_ENDIAN
49391 +typedef union _RF_CSR_CFG1_STRUC {
49392 + struct {
49393 + UINT32 rsv:7; // 0: idle 1: 8busy
49394 + UINT32 RFGap:5; // Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec)
49395 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49396 + } field;
49397 + UINT32 word;
49398 +} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC;
49399 +#else
49400 +typedef union _RF_CSR_CFG1_STRUC {
49401 + struct {
49402 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49403 + UINT32 RFGap:5; // Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec)
49404 + UINT32 rsv:7; // 0: idle 1: 8busy
49405 + } field;
49406 + UINT32 word;
49407 +} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC;
49408 +#endif
49409 +#define RF_CSR_CFG2 0x1028 //
49410 +#ifdef RT_BIG_ENDIAN
49411 +typedef union _RF_CSR_CFG2_STRUC {
49412 + struct {
49413 + UINT32 rsv:8; // 0: idle 1: 8busy
49414 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49415 + } field;
49416 + UINT32 word;
49417 +} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC;
49418 +#else
49419 +typedef union _RF_CSR_CFG2_STRUC {
49420 + struct {
49421 + UINT32 RegIdAndContent:24; // Register value to program into BBP
49422 + UINT32 rsv:8; // 0: idle 1: 8busy
49423 + } field;
49424 + UINT32 word;
49425 +} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC;
49426 +#endif
49427 +#define LED_CFG 0x102c // MAC_CSR14
49428 +#ifdef RT_BIG_ENDIAN
49429 +typedef union _LED_CFG_STRUC {
49430 + struct {
49431 + UINT32 :1;
49432 + UINT32 LedPolar:1; // Led Polarity. 0: active low1: active high
49433 + UINT32 YLedMode:2; // yellow Led Mode
49434 + UINT32 GLedMode:2; // green Led Mode
49435 + UINT32 RLedMode:2; // red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on
49436 + UINT32 rsv:2;
49437 + UINT32 SlowBlinkPeriod:6; // slow blinking period. unit:1ms
49438 + UINT32 OffPeriod:8; // blinking off period unit 1ms
49439 + UINT32 OnPeriod:8; // blinking on period unit 1ms
49440 + } field;
49441 + UINT32 word;
49442 +} LED_CFG_STRUC, *PLED_CFG_STRUC;
49443 +#else
49444 +typedef union _LED_CFG_STRUC {
49445 + struct {
49446 + UINT32 OnPeriod:8; // blinking on period unit 1ms
49447 + UINT32 OffPeriod:8; // blinking off period unit 1ms
49448 + UINT32 SlowBlinkPeriod:6; // slow blinking period. unit:1ms
49449 + UINT32 rsv:2;
49450 + UINT32 RLedMode:2; // red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on
49451 + UINT32 GLedMode:2; // green Led Mode
49452 + UINT32 YLedMode:2; // yellow Led Mode
49453 + UINT32 LedPolar:1; // Led Polarity. 0: active low1: active high
49454 + UINT32 :1;
49455 + } field;
49456 + UINT32 word;
49457 +} LED_CFG_STRUC, *PLED_CFG_STRUC;
49458 +#endif
49459 +//
49460 +// 4.2 MAC TIMING configuration registers (offset:0x1100)
49461 +//
49462 +#define XIFS_TIME_CFG 0x1100 // MAC_CSR8 MAC_CSR9
49463 +#ifdef RT_BIG_ENDIAN
49464 +typedef union _IFS_SLOT_CFG_STRUC {
49465 + struct {
49466 + UINT32 rsv:2;
49467 + UINT32 BBRxendEnable:1; // reference RXEND signal to begin XIFS defer
49468 + UINT32 EIFS:9; // unit 1us
49469 + UINT32 OfdmXifsTime:4; //OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND
49470 + UINT32 OfdmSifsTime:8; // unit 1us. Applied after OFDM RX/TX
49471 + UINT32 CckmSifsTime:8; // unit 1us. Applied after CCK RX/TX
49472 + } field;
49473 + UINT32 word;
49474 +} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC;
49475 +#else
49476 +typedef union _IFS_SLOT_CFG_STRUC {
49477 + struct {
49478 + UINT32 CckmSifsTime:8; // unit 1us. Applied after CCK RX/TX
49479 + UINT32 OfdmSifsTime:8; // unit 1us. Applied after OFDM RX/TX
49480 + UINT32 OfdmXifsTime:4; //OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND
49481 + UINT32 EIFS:9; // unit 1us
49482 + UINT32 BBRxendEnable:1; // reference RXEND signal to begin XIFS defer
49483 + UINT32 rsv:2;
49484 + } field;
49485 + UINT32 word;
49486 +} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC;
49487 +#endif
49488 +
49489 +#define BKOFF_SLOT_CFG 0x1104 // mac_csr9 last 8 bits
49490 +#define NAV_TIME_CFG 0x1108 // NAV (MAC_CSR15)
49491 +#define CH_TIME_CFG 0x110C // Count as channel busy
49492 +#define PBF_LIFE_TIMER 0x1110 //TX/RX MPDU timestamp timer (free run)Unit: 1us
49493 +#define BCN_TIME_CFG 0x1114 // TXRX_CSR9
49494 +
49495 +#define BCN_OFFSET0 0x042C
49496 +#define BCN_OFFSET1 0x0430
49497 +
49498 +//
49499 +// BCN_TIME_CFG : Synchronization control register
49500 +//
49501 +#ifdef RT_BIG_ENDIAN
49502 +typedef union _BCN_TIME_CFG_STRUC {
49503 + struct {
49504 + UINT32 TxTimestampCompensate:8;
49505 + UINT32 :3;
49506 + UINT32 bBeaconGen:1; // Enable beacon generator
49507 + UINT32 bTBTTEnable:1;
49508 + UINT32 TsfSyncMode:2; // Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
49509 + UINT32 bTsfTicking:1; // Enable TSF auto counting
49510 + UINT32 BeaconInterval:16; // in unit of 1/16 TU
49511 + } field;
49512 + UINT32 word;
49513 +} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC;
49514 +#else
49515 +typedef union _BCN_TIME_CFG_STRUC {
49516 + struct {
49517 + UINT32 BeaconInterval:16; // in unit of 1/16 TU
49518 + UINT32 bTsfTicking:1; // Enable TSF auto counting
49519 + UINT32 TsfSyncMode:2; // Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
49520 + UINT32 bTBTTEnable:1;
49521 + UINT32 bBeaconGen:1; // Enable beacon generator
49522 + UINT32 :3;
49523 + UINT32 TxTimestampCompensate:8;
49524 + } field;
49525 + UINT32 word;
49526 +} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC;
49527 +#endif
49528 +#define TBTT_SYNC_CFG 0x1118 // txrx_csr10
49529 +#define TSF_TIMER_DW0 0x111C // Local TSF timer lsb 32 bits. Read-only
49530 +#define TSF_TIMER_DW1 0x1120 // msb 32 bits. Read-only.
49531 +#define TBTT_TIMER 0x1124 // TImer remains till next TBTT. Read-only. TXRX_CSR14
49532 +#define INT_TIMER_CFG 0x1128 //
49533 +#define INT_TIMER_EN 0x112c // GP-timer and pre-tbtt Int enable
49534 +#define CH_IDLE_STA 0x1130 // channel idle time
49535 +#define CH_BUSY_STA 0x1134 // channle busy time
49536 +//
49537 +// 4.2 MAC POWER configuration registers (offset:0x1200)
49538 +//
49539 +#define MAC_STATUS_CFG 0x1200 // old MAC_CSR12
49540 +#define PWR_PIN_CFG 0x1204 // old MAC_CSR12
49541 +#define AUTO_WAKEUP_CFG 0x1208 // old MAC_CSR10
49542 +//
49543 +// AUTO_WAKEUP_CFG: Manual power control / status register
49544 +//
49545 +#ifdef RT_BIG_ENDIAN
49546 +typedef union _AUTO_WAKEUP_STRUC {
49547 + struct {
49548 + UINT32 :16;
49549 + UINT32 EnableAutoWakeup:1; // 0:sleep, 1:awake
49550 + UINT32 NumofSleepingTbtt:7; // ForceWake has high privilege than PutToSleep when both set
49551 + UINT32 AutoLeadTime:8;
49552 + } field;
49553 + UINT32 word;
49554 +} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC;
49555 +#else
49556 +typedef union _AUTO_WAKEUP_STRUC {
49557 + struct {
49558 + UINT32 AutoLeadTime:8;
49559 + UINT32 NumofSleepingTbtt:7; // ForceWake has high privilege than PutToSleep when both set
49560 + UINT32 EnableAutoWakeup:1; // 0:sleep, 1:awake
49561 + UINT32 :16;
49562 + } field;
49563 + UINT32 word;
49564 +} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC;
49565 +#endif
49566 +//
49567 +// 4.3 MAC TX configuration registers (offset:0x1300)
49568 +//
49569 +
49570 +#define EDCA_AC0_CFG 0x1300 //AC_TXOP_CSR0 0x3474
49571 +#define EDCA_AC1_CFG 0x1304
49572 +#define EDCA_AC2_CFG 0x1308
49573 +#define EDCA_AC3_CFG 0x130c
49574 +#ifdef RT_BIG_ENDIAN
49575 +typedef union _EDCA_AC_CFG_STRUC {
49576 + struct {
49577 + UINT32 :12; //
49578 + UINT32 Cwmax:4; //unit power of 2
49579 + UINT32 Cwmin:4; //
49580 + UINT32 Aifsn:4; // # of slot time
49581 + UINT32 AcTxop:8; // in unit of 32us
49582 + } field;
49583 + UINT32 word;
49584 +} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC;
49585 +#else
49586 +typedef union _EDCA_AC_CFG_STRUC {
49587 + struct {
49588 + UINT32 AcTxop:8; // in unit of 32us
49589 + UINT32 Aifsn:4; // # of slot time
49590 + UINT32 Cwmin:4; //
49591 + UINT32 Cwmax:4; //unit power of 2
49592 + UINT32 :12; //
49593 + } field;
49594 + UINT32 word;
49595 +} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC;
49596 +#endif
49597 +
49598 +#define EDCA_TID_AC_MAP 0x1310
49599 +#define TX_PWR_CFG_0 0x1314
49600 +#define TX_PWR_CFG_1 0x1318
49601 +#define TX_PWR_CFG_2 0x131C
49602 +#define TX_PWR_CFG_3 0x1320
49603 +#define TX_PWR_CFG_4 0x1324
49604 +#define TX_PIN_CFG 0x1328
49605 +#define TX_BAND_CFG 0x132c // 0x1 use upper 20MHz. 0 juse lower 20MHz
49606 +#define TX_SW_CFG0 0x1330
49607 +#define TX_SW_CFG1 0x1334
49608 +#define TX_SW_CFG2 0x1338
49609 +#define TXOP_THRES_CFG 0x133c
49610 +#define TXOP_CTRL_CFG 0x1340
49611 +#define TX_RTS_CFG 0x1344
49612 +
49613 +#ifdef RT_BIG_ENDIAN
49614 +typedef union _TX_RTS_CFG_STRUC {
49615 + struct {
49616 + UINT32 rsv:7;
49617 + UINT32 RtsFbkEn:1; // enable rts rate fallback
49618 + UINT32 RtsThres:16; // unit:byte
49619 + UINT32 AutoRtsRetryLimit:8;
49620 + } field;
49621 + UINT32 word;
49622 +} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC;
49623 +#else
49624 +typedef union _TX_RTS_CFG_STRUC {
49625 + struct {
49626 + UINT32 AutoRtsRetryLimit:8;
49627 + UINT32 RtsThres:16; // unit:byte
49628 + UINT32 RtsFbkEn:1; // enable rts rate fallback
49629 + UINT32 rsv:7; // 1: HT non-STBC control frame enable
49630 + } field;
49631 + UINT32 word;
49632 +} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC;
49633 +#endif
49634 +#define TX_TIMEOUT_CFG 0x1348
49635 +#ifdef RT_BIG_ENDIAN
49636 +typedef union _TX_TIMEOUT_CFG_STRUC {
49637 + struct {
49638 + UINT32 rsv2:8;
49639 + UINT32 TxopTimeout:8; //TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
49640 + UINT32 RxAckTimeout:8; // unit:slot. Used for TX precedure
49641 + UINT32 MpduLifeTime:4; // expiration time = 2^(9+MPDU LIFE TIME) us
49642 + UINT32 rsv:4;
49643 + } field;
49644 + UINT32 word;
49645 +} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC;
49646 +#else
49647 +typedef union _TX_TIMEOUT_CFG_STRUC {
49648 + struct {
49649 + UINT32 rsv:4;
49650 + UINT32 MpduLifeTime:4; // expiration time = 2^(9+MPDU LIFE TIME) us
49651 + UINT32 RxAckTimeout:8; // unit:slot. Used for TX precedure
49652 + UINT32 TxopTimeout:8; //TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
49653 + UINT32 rsv2:8; // 1: HT non-STBC control frame enable
49654 + } field;
49655 + UINT32 word;
49656 +} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC;
49657 +#endif
49658 +#define TX_RTY_CFG 0x134c
49659 +#ifdef RT_BIG_ENDIAN
49660 +typedef union PACKED _TX_RTY_CFG_STRUC {
49661 + struct {
49662 + UINT32 rsv:1;
49663 + UINT32 TxautoFBEnable:1; // Tx retry PHY rate auto fallback enable
49664 + UINT32 AggRtyMode:1; // Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
49665 + UINT32 NonAggRtyMode:1; // Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
49666 + UINT32 LongRtyThre:12; // Long retry threshoold
49667 + UINT32 LongRtyLimit:8; //long retry limit
49668 + UINT32 ShortRtyLimit:8; // short retry limit
49669 +
49670 + } field;
49671 + UINT32 word;
49672 +} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC;
49673 +#else
49674 +typedef union PACKED _TX_RTY_CFG_STRUC {
49675 + struct {
49676 + UINT32 ShortRtyLimit:8; // short retry limit
49677 + UINT32 LongRtyLimit:8; //long retry limit
49678 + UINT32 LongRtyThre:12; // Long retry threshoold
49679 + UINT32 NonAggRtyMode:1; // Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
49680 + UINT32 AggRtyMode:1; // Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer
49681 + UINT32 TxautoFBEnable:1; // Tx retry PHY rate auto fallback enable
49682 + UINT32 rsv:1; // 1: HT non-STBC control frame enable
49683 + } field;
49684 + UINT32 word;
49685 +} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC;
49686 +#endif
49687 +#define TX_LINK_CFG 0x1350
49688 +#ifdef RT_BIG_ENDIAN
49689 +typedef union PACKED _TX_LINK_CFG_STRUC {
49690 + struct PACKED {
49691 + UINT32 RemotMFS:8; //remote MCS feedback sequence number
49692 + UINT32 RemotMFB:8; // remote MCS feedback
49693 + UINT32 rsv:3; //
49694 + UINT32 TxCFAckEn:1; // Piggyback CF-ACK enable
49695 + UINT32 TxRDGEn:1; // RDG TX enable
49696 + UINT32 TxMRQEn:1; // MCS request TX enable
49697 + UINT32 RemoteUMFSEnable:1; // remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7)
49698 + UINT32 MFBEnable:1; // TX apply remote MFB 1:enable
49699 + UINT32 RemoteMFBLifeTime:8; //remote MFB life time. unit : 32us
49700 + } field;
49701 + UINT32 word;
49702 +} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC;
49703 +#else
49704 +typedef union PACKED _TX_LINK_CFG_STRUC {
49705 + struct PACKED {
49706 + UINT32 RemoteMFBLifeTime:8; //remote MFB life time. unit : 32us
49707 + UINT32 MFBEnable:1; // TX apply remote MFB 1:enable
49708 + UINT32 RemoteUMFSEnable:1; // remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7)
49709 + UINT32 TxMRQEn:1; // MCS request TX enable
49710 + UINT32 TxRDGEn:1; // RDG TX enable
49711 + UINT32 TxCFAckEn:1; // Piggyback CF-ACK enable
49712 + UINT32 rsv:3; //
49713 + UINT32 RemotMFB:8; // remote MCS feedback
49714 + UINT32 RemotMFS:8; //remote MCS feedback sequence number
49715 + } field;
49716 + UINT32 word;
49717 +} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC;
49718 +#endif
49719 +#define HT_FBK_CFG0 0x1354
49720 +#ifdef RT_BIG_ENDIAN
49721 +typedef union PACKED _HT_FBK_CFG0_STRUC {
49722 + struct {
49723 + UINT32 HTMCS7FBK:4;
49724 + UINT32 HTMCS6FBK:4;
49725 + UINT32 HTMCS5FBK:4;
49726 + UINT32 HTMCS4FBK:4;
49727 + UINT32 HTMCS3FBK:4;
49728 + UINT32 HTMCS2FBK:4;
49729 + UINT32 HTMCS1FBK:4;
49730 + UINT32 HTMCS0FBK:4;
49731 + } field;
49732 + UINT32 word;
49733 +} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC;
49734 +#else
49735 +typedef union PACKED _HT_FBK_CFG0_STRUC {
49736 + struct {
49737 + UINT32 HTMCS0FBK:4;
49738 + UINT32 HTMCS1FBK:4;
49739 + UINT32 HTMCS2FBK:4;
49740 + UINT32 HTMCS3FBK:4;
49741 + UINT32 HTMCS4FBK:4;
49742 + UINT32 HTMCS5FBK:4;
49743 + UINT32 HTMCS6FBK:4;
49744 + UINT32 HTMCS7FBK:4;
49745 + } field;
49746 + UINT32 word;
49747 +} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC;
49748 +#endif
49749 +#define HT_FBK_CFG1 0x1358
49750 +#ifdef RT_BIG_ENDIAN
49751 +typedef union _HT_FBK_CFG1_STRUC {
49752 + struct {
49753 + UINT32 HTMCS15FBK:4;
49754 + UINT32 HTMCS14FBK:4;
49755 + UINT32 HTMCS13FBK:4;
49756 + UINT32 HTMCS12FBK:4;
49757 + UINT32 HTMCS11FBK:4;
49758 + UINT32 HTMCS10FBK:4;
49759 + UINT32 HTMCS9FBK:4;
49760 + UINT32 HTMCS8FBK:4;
49761 + } field;
49762 + UINT32 word;
49763 +} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC;
49764 +#else
49765 +typedef union _HT_FBK_CFG1_STRUC {
49766 + struct {
49767 + UINT32 HTMCS8FBK:4;
49768 + UINT32 HTMCS9FBK:4;
49769 + UINT32 HTMCS10FBK:4;
49770 + UINT32 HTMCS11FBK:4;
49771 + UINT32 HTMCS12FBK:4;
49772 + UINT32 HTMCS13FBK:4;
49773 + UINT32 HTMCS14FBK:4;
49774 + UINT32 HTMCS15FBK:4;
49775 + } field;
49776 + UINT32 word;
49777 +} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC;
49778 +#endif
49779 +#define LG_FBK_CFG0 0x135c
49780 +#ifdef RT_BIG_ENDIAN
49781 +typedef union _LG_FBK_CFG0_STRUC {
49782 + struct {
49783 + UINT32 OFDMMCS7FBK:4; //initial value is 6
49784 + UINT32 OFDMMCS6FBK:4; //initial value is 5
49785 + UINT32 OFDMMCS5FBK:4; //initial value is 4
49786 + UINT32 OFDMMCS4FBK:4; //initial value is 3
49787 + UINT32 OFDMMCS3FBK:4; //initial value is 2
49788 + UINT32 OFDMMCS2FBK:4; //initial value is 1
49789 + UINT32 OFDMMCS1FBK:4; //initial value is 0
49790 + UINT32 OFDMMCS0FBK:4; //initial value is 0
49791 + } field;
49792 + UINT32 word;
49793 +} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC;
49794 +#else
49795 +typedef union _LG_FBK_CFG0_STRUC {
49796 + struct {
49797 + UINT32 OFDMMCS0FBK:4; //initial value is 0
49798 + UINT32 OFDMMCS1FBK:4; //initial value is 0
49799 + UINT32 OFDMMCS2FBK:4; //initial value is 1
49800 + UINT32 OFDMMCS3FBK:4; //initial value is 2
49801 + UINT32 OFDMMCS4FBK:4; //initial value is 3
49802 + UINT32 OFDMMCS5FBK:4; //initial value is 4
49803 + UINT32 OFDMMCS6FBK:4; //initial value is 5
49804 + UINT32 OFDMMCS7FBK:4; //initial value is 6
49805 + } field;
49806 + UINT32 word;
49807 +} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC;
49808 +#endif
49809 +#define LG_FBK_CFG1 0x1360
49810 +#ifdef RT_BIG_ENDIAN
49811 +typedef union _LG_FBK_CFG1_STRUC {
49812 + struct {
49813 + UINT32 rsv:16;
49814 + UINT32 CCKMCS3FBK:4; //initial value is 2
49815 + UINT32 CCKMCS2FBK:4; //initial value is 1
49816 + UINT32 CCKMCS1FBK:4; //initial value is 0
49817 + UINT32 CCKMCS0FBK:4; //initial value is 0
49818 + } field;
49819 + UINT32 word;
49820 +} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC;
49821 +#else
49822 +typedef union _LG_FBK_CFG1_STRUC {
49823 + struct {
49824 + UINT32 CCKMCS0FBK:4; //initial value is 0
49825 + UINT32 CCKMCS1FBK:4; //initial value is 0
49826 + UINT32 CCKMCS2FBK:4; //initial value is 1
49827 + UINT32 CCKMCS3FBK:4; //initial value is 2
49828 + UINT32 rsv:16;
49829 + } field;
49830 + UINT32 word;
49831 +} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC;
49832 +#endif
49833 +
49834 +//=======================================================
49835 +//================ Protection Paramater================================
49836 +//=======================================================
49837 +#define CCK_PROT_CFG 0x1364 //CCK Protection
49838 +#define ASIC_SHORTNAV 1
49839 +#define ASIC_LONGNAV 2
49840 +#define ASIC_RTS 1
49841 +#define ASIC_CTS 2
49842 +#ifdef RT_BIG_ENDIAN
49843 +typedef union _PROT_CFG_STRUC {
49844 + struct {
49845 + UINT32 rsv:5;
49846 + UINT32 RTSThEn:1; //RTS threshold enable on CCK TX
49847 + UINT32 TxopAllowGF40:1; //CCK TXOP allowance.0:disallow.
49848 + UINT32 TxopAllowGF20:1; //CCK TXOP allowance.0:disallow.
49849 + UINT32 TxopAllowMM40:1; //CCK TXOP allowance.0:disallow.
49850 + UINT32 TxopAllowMM20:1; //CCK TXOP allowance. 0:disallow.
49851 + UINT32 TxopAllowOfdm:1; //CCK TXOP allowance.0:disallow.
49852 + UINT32 TxopAllowCck:1; //CCK TXOP allowance.0:disallow.
49853 + UINT32 ProtectNav:2; //TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv
49854 + UINT32 ProtectCtrl:2; //Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv
49855 + UINT32 ProtectRate:16; //Protection control frame rate for CCK TX(RTS/CTS/CFEnd).
49856 + } field;
49857 + UINT32 word;
49858 +} PROT_CFG_STRUC, *PPROT_CFG_STRUC;
49859 +#else
49860 +typedef union _PROT_CFG_STRUC {
49861 + struct {
49862 + UINT32 ProtectRate:16; //Protection control frame rate for CCK TX(RTS/CTS/CFEnd).
49863 + UINT32 ProtectCtrl:2; //Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv
49864 + UINT32 ProtectNav:2; //TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv
49865 + UINT32 TxopAllowCck:1; //CCK TXOP allowance.0:disallow.
49866 + UINT32 TxopAllowOfdm:1; //CCK TXOP allowance.0:disallow.
49867 + UINT32 TxopAllowMM20:1; //CCK TXOP allowance. 0:disallow.
49868 + UINT32 TxopAllowMM40:1; //CCK TXOP allowance.0:disallow.
49869 + UINT32 TxopAllowGF20:1; //CCK TXOP allowance.0:disallow.
49870 + UINT32 TxopAllowGF40:1; //CCK TXOP allowance.0:disallow.
49871 + UINT32 RTSThEn:1; //RTS threshold enable on CCK TX
49872 + UINT32 rsv:5;
49873 + } field;
49874 + UINT32 word;
49875 +} PROT_CFG_STRUC, *PPROT_CFG_STRUC;
49876 +#endif
49877 +
49878 +#define OFDM_PROT_CFG 0x1368 //OFDM Protection
49879 +#define MM20_PROT_CFG 0x136C //MM20 Protection
49880 +#define MM40_PROT_CFG 0x1370 //MM40 Protection
49881 +#define GF20_PROT_CFG 0x1374 //GF20 Protection
49882 +#define GF40_PROT_CFG 0x1378 //GR40 Protection
49883 +#define EXP_CTS_TIME 0x137C //
49884 +#define EXP_ACK_TIME 0x1380 //
49885 +
49886 +//
49887 +// 4.4 MAC RX configuration registers (offset:0x1400)
49888 +//
49889 +#define RX_FILTR_CFG 0x1400 //TXRX_CSR0
49890 +#define AUTO_RSP_CFG 0x1404 //TXRX_CSR4
49891 +//
49892 +// TXRX_CSR4: Auto-Responder/
49893 +//
49894 +#ifdef RT_BIG_ENDIAN
49895 +typedef union _AUTO_RSP_CFG_STRUC {
49896 + struct {
49897 + UINT32 :24;
49898 + UINT32 AckCtsPsmBit:1; // Power bit value in conrtrol frame
49899 + UINT32 DualCTSEn:1; // Power bit value in conrtrol frame
49900 + UINT32 rsv:1; // Power bit value in conrtrol frame
49901 + UINT32 AutoResponderPreamble:1; // 0:long, 1:short preamble
49902 + UINT32 CTS40MRef:1; // Response CTS 40MHz duplicate mode
49903 + UINT32 CTS40MMode:1; // Response CTS 40MHz duplicate mode
49904 + UINT32 BACAckPolicyEnable:1; // 0:long, 1:short preamble
49905 + UINT32 AutoResponderEnable:1;
49906 + } field;
49907 + UINT32 word;
49908 +} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC;
49909 +#else
49910 +typedef union _AUTO_RSP_CFG_STRUC {
49911 + struct {
49912 + UINT32 AutoResponderEnable:1;
49913 + UINT32 BACAckPolicyEnable:1; // 0:long, 1:short preamble
49914 + UINT32 CTS40MMode:1; // Response CTS 40MHz duplicate mode
49915 + UINT32 CTS40MRef:1; // Response CTS 40MHz duplicate mode
49916 + UINT32 AutoResponderPreamble:1; // 0:long, 1:short preamble
49917 + UINT32 rsv:1; // Power bit value in conrtrol frame
49918 + UINT32 DualCTSEn:1; // Power bit value in conrtrol frame
49919 + UINT32 AckCtsPsmBit:1; // Power bit value in conrtrol frame
49920 + UINT32 :24;
49921 + } field;
49922 + UINT32 word;
49923 +} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC;
49924 +#endif
49925 +
49926 +#define LEGACY_BASIC_RATE 0x1408 // TXRX_CSR5 0x3054
49927 +#define HT_BASIC_RATE 0x140c
49928 +#define HT_CTRL_CFG 0x1410
49929 +#define SIFS_COST_CFG 0x1414
49930 +#define RX_PARSER_CFG 0x1418 //Set NAV for all received frames
49931 +
49932 +//
49933 +// 4.5 MAC Security configuration (offset:0x1500)
49934 +//
49935 +#define TX_SEC_CNT0 0x1500 //
49936 +#define RX_SEC_CNT0 0x1504 //
49937 +#define CCMP_FC_MUTE 0x1508 //
49938 +//
49939 +// 4.6 HCCA/PSMP (offset:0x1600)
49940 +//
49941 +#define TXOP_HLDR_ADDR0 0x1600
49942 +#define TXOP_HLDR_ADDR1 0x1604
49943 +#define TXOP_HLDR_ET 0x1608
49944 +#define QOS_CFPOLL_RA_DW0 0x160c
49945 +#define QOS_CFPOLL_A1_DW1 0x1610
49946 +#define QOS_CFPOLL_QC 0x1614
49947 +//
49948 +// 4.7 MAC Statistis registers (offset:0x1700)
49949 +//
49950 +#define RX_STA_CNT0 0x1700 //
49951 +#define RX_STA_CNT1 0x1704 //
49952 +#define RX_STA_CNT2 0x1708 //
49953 +
49954 +//
49955 +// RX_STA_CNT0_STRUC: RX PLCP error count & RX CRC error count
49956 +//
49957 +#ifdef RT_BIG_ENDIAN
49958 +typedef union _RX_STA_CNT0_STRUC {
49959 + struct {
49960 + USHORT PhyErr;
49961 + USHORT CrcErr;
49962 + } field;
49963 + UINT32 word;
49964 +} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC;
49965 +#else
49966 +typedef union _RX_STA_CNT0_STRUC {
49967 + struct {
49968 + USHORT CrcErr;
49969 + USHORT PhyErr;
49970 + } field;
49971 + UINT32 word;
49972 +} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC;
49973 +#endif
49974 +
49975 +//
49976 +// RX_STA_CNT1_STRUC: RX False CCA count & RX LONG frame count
49977 +//
49978 +#ifdef RT_BIG_ENDIAN
49979 +typedef union _RX_STA_CNT1_STRUC {
49980 + struct {
49981 + USHORT PlcpErr;
49982 + USHORT FalseCca;
49983 + } field;
49984 + UINT32 word;
49985 +} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC;
49986 +#else
49987 +typedef union _RX_STA_CNT1_STRUC {
49988 + struct {
49989 + USHORT FalseCca;
49990 + USHORT PlcpErr;
49991 + } field;
49992 + UINT32 word;
49993 +} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC;
49994 +#endif
49995 +
49996 +//
49997 +// RX_STA_CNT2_STRUC:
49998 +//
49999 +#ifdef RT_BIG_ENDIAN
50000 +typedef union _RX_STA_CNT2_STRUC {
50001 + struct {
50002 + USHORT RxFifoOverflowCount;
50003 + USHORT RxDupliCount;
50004 + } field;
50005 + UINT32 word;
50006 +} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC;
50007 +#else
50008 +typedef union _RX_STA_CNT2_STRUC {
50009 + struct {
50010 + USHORT RxDupliCount;
50011 + USHORT RxFifoOverflowCount;
50012 + } field;
50013 + UINT32 word;
50014 +} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC;
50015 +#endif
50016 +#define TX_STA_CNT0 0x170C //
50017 +//
50018 +// STA_CSR3: TX Beacon count
50019 +//
50020 +#ifdef RT_BIG_ENDIAN
50021 +typedef union _TX_STA_CNT0_STRUC {
50022 + struct {
50023 + USHORT TxBeaconCount;
50024 + USHORT TxFailCount;
50025 + } field;
50026 + UINT32 word;
50027 +} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC;
50028 +#else
50029 +typedef union _TX_STA_CNT0_STRUC {
50030 + struct {
50031 + USHORT TxFailCount;
50032 + USHORT TxBeaconCount;
50033 + } field;
50034 + UINT32 word;
50035 +} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC;
50036 +#endif
50037 +#define TX_STA_CNT1 0x1710 //
50038 +//
50039 +// TX_STA_CNT1: TX tx count
50040 +//
50041 +#ifdef RT_BIG_ENDIAN
50042 +typedef union _TX_STA_CNT1_STRUC {
50043 + struct {
50044 + USHORT TxRetransmit;
50045 + USHORT TxSuccess;
50046 + } field;
50047 + UINT32 word;
50048 +} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC;
50049 +#else
50050 +typedef union _TX_STA_CNT1_STRUC {
50051 + struct {
50052 + USHORT TxSuccess;
50053 + USHORT TxRetransmit;
50054 + } field;
50055 + UINT32 word;
50056 +} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC;
50057 +#endif
50058 +#define TX_STA_CNT2 0x1714 //
50059 +//
50060 +// TX_STA_CNT2: TX tx count
50061 +//
50062 +#ifdef RT_BIG_ENDIAN
50063 +typedef union _TX_STA_CNT2_STRUC {
50064 + struct {
50065 + USHORT TxUnderFlowCount;
50066 + USHORT TxZeroLenCount;
50067 + } field;
50068 + UINT32 word;
50069 +} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC;
50070 +#else
50071 +typedef union _TX_STA_CNT2_STRUC {
50072 + struct {
50073 + USHORT TxZeroLenCount;
50074 + USHORT TxUnderFlowCount;
50075 + } field;
50076 + UINT32 word;
50077 +} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC;
50078 +#endif
50079 +#define TX_STA_FIFO 0x1718 //
50080 +//
50081 +// TX_STA_FIFO_STRUC: TX Result for specific PID status fifo register
50082 +//
50083 +#ifdef RT_BIG_ENDIAN
50084 +typedef union PACKED _TX_STA_FIFO_STRUC {
50085 + struct {
50086 + UINT32 Reserve:2;
50087 + UINT32 TxBF:1; // 3*3
50088 + UINT32 SuccessRate:13; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
50089 +// UINT32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
50090 + UINT32 wcid:8; //wireless client index
50091 + UINT32 TxAckRequired:1; // ack required
50092 + UINT32 TxAggre:1; // Tx is aggregated
50093 + UINT32 TxSuccess:1; // Tx success. whether success or not
50094 + UINT32 PidType:4;
50095 + UINT32 bValid:1; // 1:This register contains a valid TX result
50096 + } field;
50097 + UINT32 word;
50098 +} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC;
50099 +#else
50100 +typedef union PACKED _TX_STA_FIFO_STRUC {
50101 + struct {
50102 + UINT32 bValid:1; // 1:This register contains a valid TX result
50103 + UINT32 PidType:4;
50104 + UINT32 TxSuccess:1; // Tx No retry success
50105 + UINT32 TxAggre:1; // Tx Retry Success
50106 + UINT32 TxAckRequired:1; // Tx fail
50107 + UINT32 wcid:8; //wireless client index
50108 +// UINT32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
50109 + UINT32 SuccessRate:13; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16.
50110 + UINT32 TxBF:1;
50111 + UINT32 Reserve:2;
50112 + } field;
50113 + UINT32 word;
50114 +} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC;
50115 +#endif
50116 +// Debug counter
50117 +#define TX_AGG_CNT 0x171c
50118 +#ifdef RT_BIG_ENDIAN
50119 +typedef union _TX_AGG_CNT_STRUC {
50120 + struct {
50121 + USHORT AggTxCount;
50122 + USHORT NonAggTxCount;
50123 + } field;
50124 + UINT32 word;
50125 +} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC;
50126 +#else
50127 +typedef union _TX_AGG_CNT_STRUC {
50128 + struct {
50129 + USHORT NonAggTxCount;
50130 + USHORT AggTxCount;
50131 + } field;
50132 + UINT32 word;
50133 +} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC;
50134 +#endif
50135 +// Debug counter
50136 +#define TX_AGG_CNT0 0x1720
50137 +#ifdef RT_BIG_ENDIAN
50138 +typedef union _TX_AGG_CNT0_STRUC {
50139 + struct {
50140 + USHORT AggSize2Count;
50141 + USHORT AggSize1Count;
50142 + } field;
50143 + UINT32 word;
50144 +} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC;
50145 +#else
50146 +typedef union _TX_AGG_CNT0_STRUC {
50147 + struct {
50148 + USHORT AggSize1Count;
50149 + USHORT AggSize2Count;
50150 + } field;
50151 + UINT32 word;
50152 +} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC;
50153 +#endif
50154 +// Debug counter
50155 +#define TX_AGG_CNT1 0x1724
50156 +#ifdef RT_BIG_ENDIAN
50157 +typedef union _TX_AGG_CNT1_STRUC {
50158 + struct {
50159 + USHORT AggSize4Count;
50160 + USHORT AggSize3Count;
50161 + } field;
50162 + UINT32 word;
50163 +} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC;
50164 +#else
50165 +typedef union _TX_AGG_CNT1_STRUC {
50166 + struct {
50167 + USHORT AggSize3Count;
50168 + USHORT AggSize4Count;
50169 + } field;
50170 + UINT32 word;
50171 +} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC;
50172 +#endif
50173 +#define TX_AGG_CNT2 0x1728
50174 +#ifdef RT_BIG_ENDIAN
50175 +typedef union _TX_AGG_CNT2_STRUC {
50176 + struct {
50177 + USHORT AggSize6Count;
50178 + USHORT AggSize5Count;
50179 + } field;
50180 + UINT32 word;
50181 +} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC;
50182 +#else
50183 +typedef union _TX_AGG_CNT2_STRUC {
50184 + struct {
50185 + USHORT AggSize5Count;
50186 + USHORT AggSize6Count;
50187 + } field;
50188 + UINT32 word;
50189 +} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC;
50190 +#endif
50191 +// Debug counter
50192 +#define TX_AGG_CNT3 0x172c
50193 +#ifdef RT_BIG_ENDIAN
50194 +typedef union _TX_AGG_CNT3_STRUC {
50195 + struct {
50196 + USHORT AggSize8Count;
50197 + USHORT AggSize7Count;
50198 + } field;
50199 + UINT32 word;
50200 +} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC;
50201 +#else
50202 +typedef union _TX_AGG_CNT3_STRUC {
50203 + struct {
50204 + USHORT AggSize7Count;
50205 + USHORT AggSize8Count;
50206 + } field;
50207 + UINT32 word;
50208 +} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC;
50209 +#endif
50210 +// Debug counter
50211 +#define TX_AGG_CNT4 0x1730
50212 +#ifdef RT_BIG_ENDIAN
50213 +typedef union _TX_AGG_CNT4_STRUC {
50214 + struct {
50215 + USHORT AggSize10Count;
50216 + USHORT AggSize9Count;
50217 + } field;
50218 + UINT32 word;
50219 +} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC;
50220 +#else
50221 +typedef union _TX_AGG_CNT4_STRUC {
50222 + struct {
50223 + USHORT AggSize9Count;
50224 + USHORT AggSize10Count;
50225 + } field;
50226 + UINT32 word;
50227 +} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC;
50228 +#endif
50229 +#define TX_AGG_CNT5 0x1734
50230 +#ifdef RT_BIG_ENDIAN
50231 +typedef union _TX_AGG_CNT5_STRUC {
50232 + struct {
50233 + USHORT AggSize12Count;
50234 + USHORT AggSize11Count;
50235 + } field;
50236 + UINT32 word;
50237 +} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC;
50238 +#else
50239 +typedef union _TX_AGG_CNT5_STRUC {
50240 + struct {
50241 + USHORT AggSize11Count;
50242 + USHORT AggSize12Count;
50243 + } field;
50244 + UINT32 word;
50245 +} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC;
50246 +#endif
50247 +#define TX_AGG_CNT6 0x1738
50248 +#ifdef RT_BIG_ENDIAN
50249 +typedef union _TX_AGG_CNT6_STRUC {
50250 + struct {
50251 + USHORT AggSize14Count;
50252 + USHORT AggSize13Count;
50253 + } field;
50254 + UINT32 word;
50255 +} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC;
50256 +#else
50257 +typedef union _TX_AGG_CNT6_STRUC {
50258 + struct {
50259 + USHORT AggSize13Count;
50260 + USHORT AggSize14Count;
50261 + } field;
50262 + UINT32 word;
50263 +} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC;
50264 +#endif
50265 +#define TX_AGG_CNT7 0x173c
50266 +#ifdef RT_BIG_ENDIAN
50267 +typedef union _TX_AGG_CNT7_STRUC {
50268 + struct {
50269 + USHORT AggSize16Count;
50270 + USHORT AggSize15Count;
50271 + } field;
50272 + UINT32 word;
50273 +} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC;
50274 +#else
50275 +typedef union _TX_AGG_CNT7_STRUC {
50276 + struct {
50277 + USHORT AggSize15Count;
50278 + USHORT AggSize16Count;
50279 + } field;
50280 + UINT32 word;
50281 +} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC;
50282 +#endif
50283 +#define MPDU_DENSITY_CNT 0x1740
50284 +#ifdef RT_BIG_ENDIAN
50285 +typedef union _MPDU_DEN_CNT_STRUC {
50286 + struct {
50287 + USHORT RXZeroDelCount; //RX zero length delimiter count
50288 + USHORT TXZeroDelCount; //TX zero length delimiter count
50289 + } field;
50290 + UINT32 word;
50291 +} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC;
50292 +#else
50293 +typedef union _MPDU_DEN_CNT_STRUC {
50294 + struct {
50295 + USHORT TXZeroDelCount; //TX zero length delimiter count
50296 + USHORT RXZeroDelCount; //RX zero length delimiter count
50297 + } field;
50298 + UINT32 word;
50299 +} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC;
50300 +#endif
50301 +//
50302 +// TXRX control registers - base address 0x3000
50303 +//
50304 +// rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
50305 +#define TXRX_CSR1 0x77d0
50306 +
50307 +//
50308 +// Security key table memory, base address = 0x1000
50309 +//
50310 +#define MAC_WCID_BASE 0x1800 //8-bytes(use only 6-bytes) * 256 entry =
50311 +#define HW_WCID_ENTRY_SIZE 8
50312 +#define PAIRWISE_KEY_TABLE_BASE 0x4000 // 32-byte * 256-entry = -byte
50313 +#define HW_KEY_ENTRY_SIZE 0x20
50314 +#define PAIRWISE_IVEIV_TABLE_BASE 0x6000 // 8-byte * 256-entry = -byte
50315 +#define MAC_IVEIV_TABLE_BASE 0x6000 // 8-byte * 256-entry = -byte
50316 +#define HW_IVEIV_ENTRY_SIZE 8
50317 +#define MAC_WCID_ATTRIBUTE_BASE 0x6800 // 4-byte * 256-entry = -byte
50318 +#define HW_WCID_ATTRI_SIZE 4
50319 +#define WCID_RESERVED 0x6bfc
50320 +#define SHARED_KEY_TABLE_BASE 0x6c00 // 32-byte * 16-entry = 512-byte
50321 +#define SHARED_KEY_MODE_BASE 0x7000 // 32-byte * 16-entry = 512-byte
50322 +#define HW_SHARED_KEY_MODE_SIZE 4
50323 +#define SHAREDKEYTABLE 0
50324 +#define PAIRWISEKEYTABLE 1
50325 +
50326 +
50327 +#ifdef RT_BIG_ENDIAN
50328 +typedef union _SHAREDKEY_MODE_STRUC {
50329 + struct {
50330 + UINT32 :1;
50331 + UINT32 Bss1Key3CipherAlg:3;
50332 + UINT32 :1;
50333 + UINT32 Bss1Key2CipherAlg:3;
50334 + UINT32 :1;
50335 + UINT32 Bss1Key1CipherAlg:3;
50336 + UINT32 :1;
50337 + UINT32 Bss1Key0CipherAlg:3;
50338 + UINT32 :1;
50339 + UINT32 Bss0Key3CipherAlg:3;
50340 + UINT32 :1;
50341 + UINT32 Bss0Key2CipherAlg:3;
50342 + UINT32 :1;
50343 + UINT32 Bss0Key1CipherAlg:3;
50344 + UINT32 :1;
50345 + UINT32 Bss0Key0CipherAlg:3;
50346 + } field;
50347 + UINT32 word;
50348 +} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC;
50349 +#else
50350 +typedef union _SHAREDKEY_MODE_STRUC {
50351 + struct {
50352 + UINT32 Bss0Key0CipherAlg:3;
50353 + UINT32 :1;
50354 + UINT32 Bss0Key1CipherAlg:3;
50355 + UINT32 :1;
50356 + UINT32 Bss0Key2CipherAlg:3;
50357 + UINT32 :1;
50358 + UINT32 Bss0Key3CipherAlg:3;
50359 + UINT32 :1;
50360 + UINT32 Bss1Key0CipherAlg:3;
50361 + UINT32 :1;
50362 + UINT32 Bss1Key1CipherAlg:3;
50363 + UINT32 :1;
50364 + UINT32 Bss1Key2CipherAlg:3;
50365 + UINT32 :1;
50366 + UINT32 Bss1Key3CipherAlg:3;
50367 + UINT32 :1;
50368 + } field;
50369 + UINT32 word;
50370 +} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC;
50371 +#endif
50372 +// 64-entry for pairwise key table
50373 +typedef struct _HW_WCID_ENTRY { // 8-byte per entry
50374 + UCHAR Address[6];
50375 + UCHAR Rsv[2];
50376 +} HW_WCID_ENTRY, PHW_WCID_ENTRY;
50377 +
50378 +
50379 +
50380 +//
50381 +// Other on-chip shared memory space, base = 0x2000
50382 +//
50383 +
50384 +// CIS space - base address = 0x2000
50385 +#define HW_CIS_BASE 0x2000
50386 +
50387 +// Carrier-sense CTS frame base address. It's where mac stores carrier-sense frame for carrier-sense function.
50388 +#define HW_CS_CTS_BASE 0x7700
50389 +// DFS CTS frame base address. It's where mac stores CTS frame for DFS.
50390 +#define HW_DFS_CTS_BASE 0x7780
50391 +#define HW_CTS_FRAME_SIZE 0x80
50392 +
50393 +// 2004-11-08 john - since NULL frame won't be that long (256 byte). We steal 16 tail bytes
50394 +// to save debugging settings
50395 +#define HW_DEBUG_SETTING_BASE 0x77f0 // 0x77f0~0x77ff total 16 bytes
50396 +#define HW_DEBUG_SETTING_BASE2 0x7770 // 0x77f0~0x77ff total 16 bytes
50397 +
50398 +// In order to support maximum 8 MBSS and its maximum length is 512 for each beacon
50399 +// Three section discontinue memory segments will be used.
50400 +// 1. The original region for BCN 0~3
50401 +// 2. Extract memory from FCE table for BCN 4~5
50402 +// 3. Extract memory from Pair-wise key table for BCN 6~7
50403 +// It occupied those memory of wcid 238~253 for BCN 6
50404 +// and wcid 222~237 for BCN 7
50405 +#define HW_BEACON_MAX_SIZE 0x1000 /* unit: byte */
50406 +#define HW_BEACON_BASE0 0x7800
50407 +#define HW_BEACON_BASE1 0x7A00
50408 +#define HW_BEACON_BASE2 0x7C00
50409 +#define HW_BEACON_BASE3 0x7E00
50410 +#define HW_BEACON_BASE4 0x7200
50411 +#define HW_BEACON_BASE5 0x7400
50412 +#define HW_BEACON_BASE6 0x5DC0
50413 +#define HW_BEACON_BASE7 0x5BC0
50414 +
50415 +#define HW_BEACON_MAX_COUNT 8
50416 +#define HW_BEACON_OFFSET 0x0200
50417 +#define HW_BEACON_CONTENT_LEN (HW_BEACON_OFFSET - TXWI_SIZE)
50418 +
50419 +// HOST-MCU shared memory - base address = 0x2100
50420 +#define HOST_CMD_CSR 0x404
50421 +#define H2M_MAILBOX_CSR 0x7010
50422 +#define H2M_MAILBOX_CID 0x7014
50423 +#define H2M_MAILBOX_STATUS 0x701c
50424 +#define H2M_INT_SRC 0x7024
50425 +#define H2M_BBP_AGENT 0x7028
50426 +#define M2H_CMD_DONE_CSR 0x000c
50427 +#define MCU_TXOP_ARRAY_BASE 0x000c // TODO: to be provided by Albert
50428 +#define MCU_TXOP_ENTRY_SIZE 32 // TODO: to be provided by Albert
50429 +#define MAX_NUM_OF_TXOP_ENTRY 16 // TODO: must be same with 8051 firmware
50430 +#define MCU_MBOX_VERSION 0x01 // TODO: to be confirmed by Albert
50431 +#define MCU_MBOX_VERSION_OFFSET 5 // TODO: to be provided by Albert
50432 +
50433 +//
50434 +// Host DMA registers - base address 0x200 . TX0-3=EDCAQid0-3, TX4=HCCA, TX5=MGMT,
50435 +//
50436 +//
50437 +// DMA RING DESCRIPTOR
50438 +//
50439 +#define E2PROM_CSR 0x0004
50440 +#define IO_CNTL_CSR 0x77d0
50441 +
50442 +#ifdef RT2870
50443 +// 8051 firmware image for usb - use last-half base address = 0x3000
50444 +#define FIRMWARE_IMAGE_BASE 0x3000
50445 +#define MAX_FIRMWARE_IMAGE_SIZE 0x1000 // 4kbyte
50446 +#endif // RT2870 //
50447 +
50448 +// TODO: ????? old RT2560 registers. to keep them or remove them?
50449 +//#define MCAST0 0x0178 // multicast filter register 0
50450 +//#define MCAST1 0x017c // multicast filter register 1
50451 +
50452 +
50453 +// ================================================================
50454 +// Tx / Rx / Mgmt ring descriptor definition
50455 +// ================================================================
50456 +
50457 +// the following PID values are used to mark outgoing frame type in TXD->PID so that
50458 +// proper TX statistics can be collected based on these categories
50459 +// b3-2 of PID field -
50460 +#define PID_MGMT 0x05
50461 +#define PID_BEACON 0x0c
50462 +#define PID_DATA_NORMALUCAST 0x02
50463 +#define PID_DATA_AMPDU 0x04
50464 +#define PID_DATA_NO_ACK 0x08
50465 +#define PID_DATA_NOT_NORM_ACK 0x03
50466 +// value domain of pTxD->HostQId (4-bit: 0~15)
50467 +#define QID_AC_BK 1 // meet ACI definition in 802.11e
50468 +#define QID_AC_BE 0 // meet ACI definition in 802.11e
50469 +#define QID_AC_VI 2
50470 +#define QID_AC_VO 3
50471 +#define QID_HCCA 4
50472 +#define NUM_OF_TX_RING 5
50473 +#define QID_MGMT 13
50474 +#define QID_RX 14
50475 +#define QID_OTHER 15
50476 +
50477 +
50478 +// ------------------------------------------------------
50479 +// BBP & RF definition
50480 +// ------------------------------------------------------
50481 +#define BUSY 1
50482 +#define IDLE 0
50483 +
50484 +#define RF_R00 0
50485 +#define RF_R01 1
50486 +#define RF_R02 2
50487 +#define RF_R03 3
50488 +#define RF_R04 4
50489 +#define RF_R05 5
50490 +#define RF_R06 6
50491 +#define RF_R07 7
50492 +#define RF_R08 8
50493 +#define RF_R09 9
50494 +#define RF_R10 10
50495 +#define RF_R11 11
50496 +#define RF_R12 12
50497 +#define RF_R13 13
50498 +#define RF_R14 14
50499 +#define RF_R15 15
50500 +#define RF_R16 16
50501 +#define RF_R17 17
50502 +#define RF_R18 18
50503 +#define RF_R19 19
50504 +#define RF_R20 20
50505 +#define RF_R21 21
50506 +#define RF_R22 22
50507 +#define RF_R23 23
50508 +#define RF_R24 24
50509 +#define RF_R25 25
50510 +#define RF_R26 26
50511 +#define RF_R27 27
50512 +#define RF_R28 28
50513 +#define RF_R29 29
50514 +#define RF_R30 30
50515 +#define RF_R31 31
50516 +
50517 +#define BBP_R0 0 // version
50518 +#define BBP_R1 1 // TSSI
50519 +#define BBP_R2 2 // TX configure
50520 +#define BBP_R3 3
50521 +#define BBP_R4 4
50522 +#define BBP_R5 5
50523 +#define BBP_R6 6
50524 +#define BBP_R14 14 // RX configure
50525 +#define BBP_R16 16
50526 +#define BBP_R17 17 // RX sensibility
50527 +#define BBP_R18 18
50528 +#define BBP_R21 21
50529 +#define BBP_R22 22
50530 +#define BBP_R24 24
50531 +#define BBP_R25 25
50532 +#define BBP_R31 31
50533 +#define BBP_R49 49 //TSSI
50534 +#define BBP_R50 50
50535 +#define BBP_R51 51
50536 +#define BBP_R52 52
50537 +#define BBP_R55 55
50538 +#define BBP_R62 62 // Rx SQ0 Threshold HIGH
50539 +#define BBP_R63 63
50540 +#define BBP_R64 64
50541 +#define BBP_R65 65
50542 +#define BBP_R66 66
50543 +#define BBP_R67 67
50544 +#define BBP_R68 68
50545 +#define BBP_R69 69
50546 +#define BBP_R70 70 // Rx AGC SQ CCK Xcorr threshold
50547 +#define BBP_R73 73
50548 +#define BBP_R75 75
50549 +#define BBP_R77 77
50550 +#define BBP_R79 79
50551 +#define BBP_R80 80
50552 +#define BBP_R81 81
50553 +#define BBP_R82 82
50554 +#define BBP_R83 83
50555 +#define BBP_R84 84
50556 +#define BBP_R86 86
50557 +#define BBP_R91 91
50558 +#define BBP_R92 92
50559 +#define BBP_R94 94 // Tx Gain Control
50560 +#define BBP_R103 103
50561 +#define BBP_R105 105
50562 +#define BBP_R113 113
50563 +#define BBP_R114 114
50564 +#define BBP_R115 115
50565 +#define BBP_R116 116
50566 +#define BBP_R117 117
50567 +#define BBP_R118 118
50568 +#define BBP_R119 119
50569 +#define BBP_R120 120
50570 +#define BBP_R121 121
50571 +#define BBP_R122 122
50572 +#define BBP_R123 123
50573 +#ifdef RT30xx
50574 +#define BBP_R138 138 // add by johnli, RF power sequence setup, ADC dynamic on/off control
50575 +#endif // RT30xx //
50576 +
50577 +
50578 +#define BBPR94_DEFAULT 0x06 // Add 1 value will gain 1db
50579 +
50580 +//#define PHY_TR_SWITCH_TIME 5 // usec
50581 +
50582 +//#define BBP_R17_LOW_SENSIBILITY 0x50
50583 +//#define BBP_R17_MID_SENSIBILITY 0x41
50584 +//#define BBP_R17_DYNAMIC_UP_BOUND 0x40
50585 +#define RSSI_FOR_VERY_LOW_SENSIBILITY -35
50586 +#define RSSI_FOR_LOW_SENSIBILITY -58
50587 +#define RSSI_FOR_MID_LOW_SENSIBILITY -80
50588 +#define RSSI_FOR_MID_SENSIBILITY -90
50589 +
50590 +//-------------------------------------------------------------------------
50591 +// EEPROM definition
50592 +//-------------------------------------------------------------------------
50593 +#define EEDO 0x08
50594 +#define EEDI 0x04
50595 +#define EECS 0x02
50596 +#define EESK 0x01
50597 +#define EERL 0x80
50598 +
50599 +#define EEPROM_WRITE_OPCODE 0x05
50600 +#define EEPROM_READ_OPCODE 0x06
50601 +#define EEPROM_EWDS_OPCODE 0x10
50602 +#define EEPROM_EWEN_OPCODE 0x13
50603 +
50604 +#define NUM_EEPROM_BBP_PARMS 19 // Include NIC Config 0, 1, CR, TX ALC step, BBPs
50605 +#define NUM_EEPROM_TX_G_PARMS 7
50606 +#define EEPROM_NIC1_OFFSET 0x34 // The address is from NIC config 0, not BBP register ID
50607 +#define EEPROM_NIC2_OFFSET 0x36 // The address is from NIC config 0, not BBP register ID
50608 +#define EEPROM_BBP_BASE_OFFSET 0xf0 // The address is from NIC config 0, not BBP register ID
50609 +#define EEPROM_G_TX_PWR_OFFSET 0x52
50610 +#define EEPROM_G_TX2_PWR_OFFSET 0x60
50611 +#define EEPROM_LED1_OFFSET 0x3c
50612 +#define EEPROM_LED2_OFFSET 0x3e
50613 +#define EEPROM_LED3_OFFSET 0x40
50614 +#define EEPROM_LNA_OFFSET 0x44
50615 +#define EEPROM_RSSI_BG_OFFSET 0x46
50616 +#define EEPROM_RSSI_A_OFFSET 0x4a
50617 +#define EEPROM_DEFINE_MAX_TXPWR 0x4e
50618 +#define EEPROM_TXPOWER_BYRATE_20MHZ_2_4G 0xde // 20MHZ 2.4G tx power.
50619 +#define EEPROM_TXPOWER_BYRATE_40MHZ_2_4G 0xee // 40MHZ 2.4G tx power.
50620 +#define EEPROM_TXPOWER_BYRATE_20MHZ_5G 0xfa // 20MHZ 5G tx power.
50621 +#define EEPROM_TXPOWER_BYRATE_40MHZ_5G 0x10a // 40MHZ 5G tx power.
50622 +#define EEPROM_A_TX_PWR_OFFSET 0x78
50623 +#define EEPROM_A_TX2_PWR_OFFSET 0xa6
50624 +//#define EEPROM_Japan_TX_PWR_OFFSET 0x90 // 802.11j
50625 +//#define EEPROM_Japan_TX2_PWR_OFFSET 0xbe
50626 +//#define EEPROM_TSSI_REF_OFFSET 0x54
50627 +//#define EEPROM_TSSI_DELTA_OFFSET 0x24
50628 +//#define EEPROM_CCK_TX_PWR_OFFSET 0x62
50629 +//#define EEPROM_CALIBRATE_OFFSET 0x7c
50630 +#define EEPROM_VERSION_OFFSET 0x02
50631 +#define EEPROM_FREQ_OFFSET 0x3a
50632 +#define EEPROM_TXPOWER_BYRATE 0xde // 20MHZ power.
50633 +#define EEPROM_TXPOWER_DELTA 0x50 // 20MHZ AND 40 MHZ use different power. This is delta in 40MHZ.
50634 +#define VALID_EEPROM_VERSION 1
50635 +
50636 +// PairKeyMode definition
50637 +#define PKMODE_NONE 0
50638 +#define PKMODE_WEP64 1
50639 +#define PKMODE_WEP128 2
50640 +#define PKMODE_TKIP 3
50641 +#define PKMODE_AES 4
50642 +#define PKMODE_CKIP64 5
50643 +#define PKMODE_CKIP128 6
50644 +#define PKMODE_TKIP_NO_MIC 7 // MIC appended by driver: not a valid value in hardware key table
50645 +
50646 +// =================================================================================
50647 +// WCID format
50648 +// =================================================================================
50649 +//7.1 WCID ENTRY format : 8bytes
50650 +typedef struct _WCID_ENTRY_STRUC {
50651 + UCHAR RXBABitmap7; // bit0 for TID8, bit7 for TID 15
50652 + UCHAR RXBABitmap0; // bit0 for TID0, bit7 for TID 7
50653 + UCHAR MAC[6]; // 0 for shared key table. 1 for pairwise key table
50654 +} WCID_ENTRY_STRUC, *PWCID_ENTRY_STRUC;
50655 +
50656 +//8.1.1 SECURITY KEY format : 8DW
50657 +// 32-byte per entry, total 16-entry for shared key table, 64-entry for pairwise key table
50658 +typedef struct _HW_KEY_ENTRY { // 32-byte per entry
50659 + UCHAR Key[16];
50660 + UCHAR TxMic[8];
50661 + UCHAR RxMic[8];
50662 +} HW_KEY_ENTRY, *PHW_KEY_ENTRY;
50663 +
50664 +//8.1.2 IV/EIV format : 2DW
50665 +
50666 +//8.1.3 RX attribute entry format : 1DW
50667 +#ifdef RT_BIG_ENDIAN
50668 +typedef struct _MAC_ATTRIBUTE_STRUC {
50669 + UINT32 rsv:22;
50670 + UINT32 RXWIUDF:3;
50671 + UINT32 BSSIDIdx:3; //multipleBSS index for the WCID
50672 + UINT32 PairKeyMode:3;
50673 + UINT32 KeyTab:1; // 0 for shared key table. 1 for pairwise key table
50674 +} MAC_ATTRIBUTE_STRUC, *PMAC_ATTRIBUTE_STRUC;
50675 +#else
50676 +typedef struct _MAC_ATTRIBUTE_STRUC {
50677 + UINT32 KeyTab:1; // 0 for shared key table. 1 for pairwise key table
50678 + UINT32 PairKeyMode:3;
50679 + UINT32 BSSIDIdx:3; //multipleBSS index for the WCID
50680 + UINT32 RXWIUDF:3;
50681 + UINT32 rsv:22;
50682 +} MAC_ATTRIBUTE_STRUC, *PMAC_ATTRIBUTE_STRUC;
50683 +#endif
50684 +
50685 +
50686 +// =================================================================================
50687 +// TX / RX ring descriptor format
50688 +// =================================================================================
50689 +
50690 +// the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO.
50691 +// MAC block use this TXINFO to control the transmission behavior of this frame.
50692 +#define FIFO_MGMT 0
50693 +#define FIFO_HCCA 1
50694 +#define FIFO_EDCA 2
50695 +
50696 +//
50697 +// TX descriptor format, Tx ring, Mgmt Ring
50698 +//
50699 +#ifdef RT_BIG_ENDIAN
50700 +typedef struct PACKED _TXD_STRUC {
50701 + // Word 0
50702 + UINT32 SDPtr0;
50703 + // Word 1
50704 + UINT32 DMADONE:1;
50705 + UINT32 LastSec0:1;
50706 + UINT32 SDLen0:14;
50707 + UINT32 Burst:1;
50708 + UINT32 LastSec1:1;
50709 + UINT32 SDLen1:14;
50710 + // Word 2
50711 + UINT32 SDPtr1;
50712 + // Word 3
50713 + UINT32 ICO:1;
50714 + UINT32 UCO:1;
50715 + UINT32 TCO:1;
50716 + UINT32 rsv:2;
50717 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
50718 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
50719 + UINT32 rsv2:24;
50720 +} TXD_STRUC, *PTXD_STRUC;
50721 +#else
50722 +typedef struct PACKED _TXD_STRUC {
50723 + // Word 0
50724 + UINT32 SDPtr0;
50725 + // Word 1
50726 + UINT32 SDLen1:14;
50727 + UINT32 LastSec1:1;
50728 + UINT32 Burst:1;
50729 + UINT32 SDLen0:14;
50730 + UINT32 LastSec0:1;
50731 + UINT32 DMADONE:1;
50732 + //Word2
50733 + UINT32 SDPtr1;
50734 + //Word3
50735 + UINT32 rsv2:24;
50736 + UINT32 WIV:1; // Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition
50737 + UINT32 QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
50738 + UINT32 rsv:2;
50739 + UINT32 TCO:1; //
50740 + UINT32 UCO:1; //
50741 + UINT32 ICO:1; //
50742 +} TXD_STRUC, *PTXD_STRUC;
50743 +#endif
50744 +
50745 +
50746 +//
50747 +// TXD Wireless Information format for Tx ring and Mgmt Ring
50748 +//
50749 +//txop : for txop mode
50750 +// 0:txop for the MPDU frame will be handles by ASIC by register
50751 +// 1/2/3:the MPDU frame is send after PIFS/backoff/SIFS
50752 +#ifdef RT_BIG_ENDIAN
50753 +typedef struct PACKED _TXWI_STRUC {
50754 + // Word 0
50755 + UINT32 PHYMODE:2;
50756 + UINT32 TxBF:1; // 3*3
50757 + UINT32 rsv2:1;
50758 +// UINT32 rsv2:2;
50759 + UINT32 Ifs:1; //
50760 + UINT32 STBC:2; //channel bandwidth 20MHz or 40 MHz
50761 + UINT32 ShortGI:1;
50762 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
50763 + UINT32 MCS:7;
50764 +
50765 + UINT32 rsv:6;
50766 + UINT32 txop:2; //tx back off mode 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs only when previous frame exchange is successful.
50767 + UINT32 MpduDensity:3;
50768 + UINT32 AMPDU:1;
50769 +
50770 + UINT32 TS:1;
50771 + UINT32 CFACK:1;
50772 + UINT32 MIMOps:1; // the remote peer is in dynamic MIMO-PS mode
50773 + UINT32 FRAG:1; // 1 to inform TKIP engine this is a fragment.
50774 + // Word 1
50775 + UINT32 PacketId:4;
50776 + UINT32 MPDUtotalByteCount:12;
50777 + UINT32 WirelessCliID:8;
50778 + UINT32 BAWinSize:6;
50779 + UINT32 NSEQ:1;
50780 + UINT32 ACK:1;
50781 + // Word 2
50782 + UINT32 IV;
50783 + // Word 3
50784 + UINT32 EIV;
50785 +} TXWI_STRUC, *PTXWI_STRUC;
50786 +#else
50787 +typedef struct PACKED _TXWI_STRUC {
50788 + // Word 0
50789 + UINT32 FRAG:1; // 1 to inform TKIP engine this is a fragment.
50790 + UINT32 MIMOps:1; // the remote peer is in dynamic MIMO-PS mode
50791 + UINT32 CFACK:1;
50792 + UINT32 TS:1;
50793 +
50794 + UINT32 AMPDU:1;
50795 + UINT32 MpduDensity:3;
50796 + UINT32 txop:2; //FOR "THIS" frame. 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs only when previous frame exchange is successful.
50797 + UINT32 rsv:6;
50798 +
50799 + UINT32 MCS:7;
50800 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
50801 + UINT32 ShortGI:1;
50802 + UINT32 STBC:2; // 1: STBC support MCS =0-7, 2,3 : RESERVE
50803 + UINT32 Ifs:1; //
50804 +// UINT32 rsv2:2; //channel bandwidth 20MHz or 40 MHz
50805 + UINT32 rsv2:1;
50806 + UINT32 TxBF:1; // 3*3
50807 + UINT32 PHYMODE:2;
50808 + // Word 1
50809 + UINT32 ACK:1;
50810 + UINT32 NSEQ:1;
50811 + UINT32 BAWinSize:6;
50812 + UINT32 WirelessCliID:8;
50813 + UINT32 MPDUtotalByteCount:12;
50814 + UINT32 PacketId:4;
50815 + //Word2
50816 + UINT32 IV;
50817 + //Word3
50818 + UINT32 EIV;
50819 +} TXWI_STRUC, *PTXWI_STRUC;
50820 +#endif
50821 +//
50822 +// Rx descriptor format, Rx Ring
50823 +//
50824 +//
50825 +// RXWI wireless information format, in PBF. invisible in driver.
50826 +//
50827 +#ifdef RT_BIG_ENDIAN
50828 +typedef struct PACKED _RXWI_STRUC {
50829 + // Word 0
50830 + UINT32 TID:4;
50831 + UINT32 MPDUtotalByteCount:12;
50832 + UINT32 UDF:3;
50833 + UINT32 BSSID:3;
50834 + UINT32 KeyIndex:2;
50835 + UINT32 WirelessCliID:8;
50836 + // Word 1
50837 + UINT32 PHYMODE:2; // 1: this RX frame is unicast to me
50838 + UINT32 rsv:3;
50839 + UINT32 STBC:2;
50840 + UINT32 ShortGI:1;
50841 + UINT32 BW:1;
50842 + UINT32 MCS:7;
50843 + UINT32 SEQUENCE:12;
50844 + UINT32 FRAG:4;
50845 + // Word 2
50846 + UINT32 rsv1:8;
50847 + UINT32 RSSI2:8;
50848 + UINT32 RSSI1:8;
50849 + UINT32 RSSI0:8;
50850 + // Word 3
50851 + UINT32 rsv2:16;
50852 + UINT32 SNR1:8;
50853 + UINT32 SNR0:8;
50854 +} RXWI_STRUC, *PRXWI_STRUC;
50855 +#else
50856 +typedef struct PACKED _RXWI_STRUC {
50857 + // Word 0
50858 + UINT32 WirelessCliID:8;
50859 + UINT32 KeyIndex:2;
50860 + UINT32 BSSID:3;
50861 + UINT32 UDF:3;
50862 + UINT32 MPDUtotalByteCount:12;
50863 + UINT32 TID:4;
50864 + // Word 1
50865 + UINT32 FRAG:4;
50866 + UINT32 SEQUENCE:12;
50867 + UINT32 MCS:7;
50868 + UINT32 BW:1;
50869 + UINT32 ShortGI:1;
50870 + UINT32 STBC:2;
50871 + UINT32 rsv:3;
50872 + UINT32 PHYMODE:2; // 1: this RX frame is unicast to me
50873 + //Word2
50874 + UINT32 RSSI0:8;
50875 + UINT32 RSSI1:8;
50876 + UINT32 RSSI2:8;
50877 + UINT32 rsv1:8;
50878 + //Word3
50879 + UINT32 SNR0:8;
50880 + UINT32 SNR1:8;
50881 + UINT32 rsv2:16;
50882 +} RXWI_STRUC, *PRXWI_STRUC;
50883 +#endif
50884 +
50885 +
50886 +// =================================================================================
50887 +// HOST-MCU communication data structure
50888 +// =================================================================================
50889 +
50890 +//
50891 +// H2M_MAILBOX_CSR: Host-to-MCU Mailbox
50892 +//
50893 +#ifdef RT_BIG_ENDIAN
50894 +typedef union _H2M_MAILBOX_STRUC {
50895 + struct {
50896 + UINT32 Owner:8;
50897 + UINT32 CmdToken:8; // 0xff tells MCU not to report CmdDoneInt after excuting the command
50898 + UINT32 HighByte:8;
50899 + UINT32 LowByte:8;
50900 + } field;
50901 + UINT32 word;
50902 +} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC;
50903 +#else
50904 +typedef union _H2M_MAILBOX_STRUC {
50905 + struct {
50906 + UINT32 LowByte:8;
50907 + UINT32 HighByte:8;
50908 + UINT32 CmdToken:8;
50909 + UINT32 Owner:8;
50910 + } field;
50911 + UINT32 word;
50912 +} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC;
50913 +#endif
50914 +
50915 +//
50916 +// M2H_CMD_DONE_CSR: MCU-to-Host command complete indication
50917 +//
50918 +#ifdef RT_BIG_ENDIAN
50919 +typedef union _M2H_CMD_DONE_STRUC {
50920 + struct {
50921 + UINT32 CmdToken3;
50922 + UINT32 CmdToken2;
50923 + UINT32 CmdToken1;
50924 + UINT32 CmdToken0;
50925 + } field;
50926 + UINT32 word;
50927 +} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC;
50928 +#else
50929 +typedef union _M2H_CMD_DONE_STRUC {
50930 + struct {
50931 + UINT32 CmdToken0;
50932 + UINT32 CmdToken1;
50933 + UINT32 CmdToken2;
50934 + UINT32 CmdToken3;
50935 + } field;
50936 + UINT32 word;
50937 +} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC;
50938 +#endif
50939 +
50940 +
50941 +
50942 +//
50943 +// MCU_LEDCS: MCU LED Control Setting.
50944 +//
50945 +#ifdef RT_BIG_ENDIAN
50946 +typedef union _MCU_LEDCS_STRUC {
50947 + struct {
50948 + UCHAR Polarity:1;
50949 + UCHAR LedMode:7;
50950 + } field;
50951 + UCHAR word;
50952 +} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC;
50953 +#else
50954 +typedef union _MCU_LEDCS_STRUC {
50955 + struct {
50956 + UCHAR LedMode:7;
50957 + UCHAR Polarity:1;
50958 + } field;
50959 + UCHAR word;
50960 +} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC;
50961 +#endif
50962 +// =================================================================================
50963 +// Register format
50964 +// =================================================================================
50965 +
50966 +
50967 +
50968 +//NAV_TIME_CFG :NAV
50969 +#ifdef RT_BIG_ENDIAN
50970 +typedef union _NAV_TIME_CFG_STRUC {
50971 + struct {
50972 + USHORT rsv:6;
50973 + USHORT ZeroSifs:1; // Applied zero SIFS timer after OFDM RX 0: disable
50974 + USHORT Eifs:9; // in unit of 1-us
50975 + UCHAR SlotTime; // in unit of 1-us
50976 + UCHAR Sifs; // in unit of 1-us
50977 + } field;
50978 + UINT32 word;
50979 +} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC;
50980 +#else
50981 +typedef union _NAV_TIME_CFG_STRUC {
50982 + struct {
50983 + UCHAR Sifs; // in unit of 1-us
50984 + UCHAR SlotTime; // in unit of 1-us
50985 + USHORT Eifs:9; // in unit of 1-us
50986 + USHORT ZeroSifs:1; // Applied zero SIFS timer after OFDM RX 0: disable
50987 + USHORT rsv:6;
50988 + } field;
50989 + UINT32 word;
50990 +} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC;
50991 +#endif
50992 +
50993 +
50994 +
50995 +
50996 +
50997 +//
50998 +// RX_FILTR_CFG: /RX configuration register
50999 +//
51000 +#ifdef RT_BIG_ENDIAN
51001 +typedef union RX_FILTR_CFG_STRUC {
51002 + struct {
51003 + UINT32 :15;
51004 + UINT32 DropRsvCntlType:1;
51005 +
51006 + UINT32 DropBAR:1; //
51007 + UINT32 DropBA:1; //
51008 + UINT32 DropPsPoll:1; // Drop Ps-Poll
51009 + UINT32 DropRts:1; // Drop Ps-Poll
51010 +
51011 + UINT32 DropCts:1; // Drop Ps-Poll
51012 + UINT32 DropAck:1; // Drop Ps-Poll
51013 + UINT32 DropCFEnd:1; // Drop Ps-Poll
51014 + UINT32 DropCFEndAck:1; // Drop Ps-Poll
51015 +
51016 + UINT32 DropDuplicate:1; // Drop duplicate frame
51017 + UINT32 DropBcast:1; // Drop broadcast frames
51018 + UINT32 DropMcast:1; // Drop multicast frames
51019 + UINT32 DropVerErr:1; // Drop version error frame
51020 +
51021 + UINT32 DropNotMyBSSID:1; // Drop fram ToDs bit is true
51022 + UINT32 DropNotToMe:1; // Drop not to me unicast frame
51023 + UINT32 DropPhyErr:1; // Drop physical error
51024 + UINT32 DropCRCErr:1; // Drop CRC error
51025 + } field;
51026 + UINT32 word;
51027 +} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC;
51028 +#else
51029 +typedef union _RX_FILTR_CFG_STRUC {
51030 + struct {
51031 + UINT32 DropCRCErr:1; // Drop CRC error
51032 + UINT32 DropPhyErr:1; // Drop physical error
51033 + UINT32 DropNotToMe:1; // Drop not to me unicast frame
51034 + UINT32 DropNotMyBSSID:1; // Drop fram ToDs bit is true
51035 +
51036 + UINT32 DropVerErr:1; // Drop version error frame
51037 + UINT32 DropMcast:1; // Drop multicast frames
51038 + UINT32 DropBcast:1; // Drop broadcast frames
51039 + UINT32 DropDuplicate:1; // Drop duplicate frame
51040 +
51041 + UINT32 DropCFEndAck:1; // Drop Ps-Poll
51042 + UINT32 DropCFEnd:1; // Drop Ps-Poll
51043 + UINT32 DropAck:1; // Drop Ps-Poll
51044 + UINT32 DropCts:1; // Drop Ps-Poll
51045 +
51046 + UINT32 DropRts:1; // Drop Ps-Poll
51047 + UINT32 DropPsPoll:1; // Drop Ps-Poll
51048 + UINT32 DropBA:1; //
51049 + UINT32 DropBAR:1; //
51050 +
51051 + UINT32 DropRsvCntlType:1;
51052 + UINT32 :15;
51053 + } field;
51054 + UINT32 word;
51055 +} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC;
51056 +#endif
51057 +
51058 +
51059 +
51060 +
51061 +//
51062 +// PHY_CSR4: RF serial control register
51063 +//
51064 +#ifdef RT_BIG_ENDIAN
51065 +typedef union _PHY_CSR4_STRUC {
51066 + struct {
51067 + UINT32 Busy:1; // 1: ASIC is busy execute RF programming.
51068 + UINT32 PLL_LD:1; // RF PLL_LD status
51069 + UINT32 IFSelect:1; // 1: select IF to program, 0: select RF to program
51070 + UINT32 NumberOfBits:5; // Number of bits used in RFRegValue (I:20, RFMD:22)
51071 + UINT32 RFRegValue:24; // Register value (include register id) serial out to RF/IF chip.
51072 + } field;
51073 + UINT32 word;
51074 +} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC;
51075 +#else
51076 +typedef union _PHY_CSR4_STRUC {
51077 + struct {
51078 + UINT32 RFRegValue:24; // Register value (include register id) serial out to RF/IF chip.
51079 + UINT32 NumberOfBits:5; // Number of bits used in RFRegValue (I:20, RFMD:22)
51080 + UINT32 IFSelect:1; // 1: select IF to program, 0: select RF to program
51081 + UINT32 PLL_LD:1; // RF PLL_LD status
51082 + UINT32 Busy:1; // 1: ASIC is busy execute RF programming.
51083 + } field;
51084 + UINT32 word;
51085 +} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC;
51086 +#endif
51087 +
51088 +
51089 +//
51090 +// SEC_CSR5: shared key table security mode register
51091 +//
51092 +#ifdef RT_BIG_ENDIAN
51093 +typedef union _SEC_CSR5_STRUC {
51094 + struct {
51095 + UINT32 :1;
51096 + UINT32 Bss3Key3CipherAlg:3;
51097 + UINT32 :1;
51098 + UINT32 Bss3Key2CipherAlg:3;
51099 + UINT32 :1;
51100 + UINT32 Bss3Key1CipherAlg:3;
51101 + UINT32 :1;
51102 + UINT32 Bss3Key0CipherAlg:3;
51103 + UINT32 :1;
51104 + UINT32 Bss2Key3CipherAlg:3;
51105 + UINT32 :1;
51106 + UINT32 Bss2Key2CipherAlg:3;
51107 + UINT32 :1;
51108 + UINT32 Bss2Key1CipherAlg:3;
51109 + UINT32 :1;
51110 + UINT32 Bss2Key0CipherAlg:3;
51111 + } field;
51112 + UINT32 word;
51113 +} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC;
51114 +#else
51115 +typedef union _SEC_CSR5_STRUC {
51116 + struct {
51117 + UINT32 Bss2Key0CipherAlg:3;
51118 + UINT32 :1;
51119 + UINT32 Bss2Key1CipherAlg:3;
51120 + UINT32 :1;
51121 + UINT32 Bss2Key2CipherAlg:3;
51122 + UINT32 :1;
51123 + UINT32 Bss2Key3CipherAlg:3;
51124 + UINT32 :1;
51125 + UINT32 Bss3Key0CipherAlg:3;
51126 + UINT32 :1;
51127 + UINT32 Bss3Key1CipherAlg:3;
51128 + UINT32 :1;
51129 + UINT32 Bss3Key2CipherAlg:3;
51130 + UINT32 :1;
51131 + UINT32 Bss3Key3CipherAlg:3;
51132 + UINT32 :1;
51133 + } field;
51134 + UINT32 word;
51135 +} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC;
51136 +#endif
51137 +
51138 +
51139 +//
51140 +// HOST_CMD_CSR: For HOST to interrupt embedded processor
51141 +//
51142 +#ifdef RT_BIG_ENDIAN
51143 +typedef union _HOST_CMD_CSR_STRUC {
51144 + struct {
51145 + UINT32 Rsv:24;
51146 + UINT32 HostCommand:8;
51147 + } field;
51148 + UINT32 word;
51149 +} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC;
51150 +#else
51151 +typedef union _HOST_CMD_CSR_STRUC {
51152 + struct {
51153 + UINT32 HostCommand:8;
51154 + UINT32 Rsv:24;
51155 + } field;
51156 + UINT32 word;
51157 +} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC;
51158 +#endif
51159 +
51160 +
51161 +//
51162 +// AIFSN_CSR: AIFSN for each EDCA AC
51163 +//
51164 +
51165 +
51166 +
51167 +//
51168 +// E2PROM_CSR: EEPROM control register
51169 +//
51170 +#ifdef RT_BIG_ENDIAN
51171 +typedef union _E2PROM_CSR_STRUC {
51172 + struct {
51173 + UINT32 Rsvd:25;
51174 + UINT32 LoadStatus:1; // 1:loading, 0:done
51175 + UINT32 Type:1; // 1: 93C46, 0:93C66
51176 + UINT32 EepromDO:1;
51177 + UINT32 EepromDI:1;
51178 + UINT32 EepromCS:1;
51179 + UINT32 EepromSK:1;
51180 + UINT32 Reload:1; // Reload EEPROM content, write one to reload, self-cleared.
51181 + } field;
51182 + UINT32 word;
51183 +} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC;
51184 +#else
51185 +typedef union _E2PROM_CSR_STRUC {
51186 + struct {
51187 + UINT32 Reload:1; // Reload EEPROM content, write one to reload, self-cleared.
51188 + UINT32 EepromSK:1;
51189 + UINT32 EepromCS:1;
51190 + UINT32 EepromDI:1;
51191 + UINT32 EepromDO:1;
51192 + UINT32 Type:1; // 1: 93C46, 0:93C66
51193 + UINT32 LoadStatus:1; // 1:loading, 0:done
51194 + UINT32 Rsvd:25;
51195 + } field;
51196 + UINT32 word;
51197 +} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC;
51198 +#endif
51199 +
51200 +
51201 +// -------------------------------------------------------------------
51202 +// E2PROM data layout
51203 +// -------------------------------------------------------------------
51204 +
51205 +//
51206 +// EEPROM antenna select format
51207 +//
51208 +#ifdef RT_BIG_ENDIAN
51209 +typedef union _EEPROM_ANTENNA_STRUC {
51210 + struct {
51211 + USHORT Rsv:4;
51212 + USHORT RfIcType:4; // see E2PROM document
51213 + USHORT TxPath:4; // 1: 1T, 2: 2T
51214 + USHORT RxPath:4; // 1: 1R, 2: 2R, 3: 3R
51215 + } field;
51216 + USHORT word;
51217 +} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC;
51218 +#else
51219 +typedef union _EEPROM_ANTENNA_STRUC {
51220 + struct {
51221 + USHORT RxPath:4; // 1: 1R, 2: 2R, 3: 3R
51222 + USHORT TxPath:4; // 1: 1T, 2: 2T
51223 + USHORT RfIcType:4; // see E2PROM document
51224 + USHORT Rsv:4;
51225 + } field;
51226 + USHORT word;
51227 +} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC;
51228 +#endif
51229 +
51230 +#ifdef RT_BIG_ENDIAN
51231 +typedef union _EEPROM_NIC_CINFIG2_STRUC {
51232 + struct {
51233 + USHORT DACTestBit:1; // control if driver should patch the DAC issue
51234 + USHORT Rsv2:3; // must be 0
51235 + USHORT AntDiversity:1; // Antenna diversity
51236 + USHORT Rsv1:1; // must be 0
51237 + USHORT BW40MAvailForA:1; // 0:enable, 1:disable
51238 + USHORT BW40MAvailForG:1; // 0:enable, 1:disable
51239 + USHORT EnableWPSPBC:1; // WPS PBC Control bit
51240 + USHORT BW40MSidebandForA:1;
51241 + USHORT BW40MSidebandForG:1;
51242 + USHORT CardbusAcceleration:1; // !!! NOTE: 0 - enable, 1 - disable
51243 + USHORT ExternalLNAForA:1; // external LNA enable for 5G
51244 + USHORT ExternalLNAForG:1; // external LNA enable for 2.4G
51245 + USHORT DynamicTxAgcControl:1; //
51246 + USHORT HardwareRadioControl:1; // Whether RF is controlled by driver or HW. 1:enable hw control, 0:disable
51247 + } field;
51248 + USHORT word;
51249 +} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC;
51250 +#else
51251 +typedef union _EEPROM_NIC_CINFIG2_STRUC {
51252 + struct {
51253 + USHORT HardwareRadioControl:1; // 1:enable, 0:disable
51254 + USHORT DynamicTxAgcControl:1; //
51255 + USHORT ExternalLNAForG:1; //
51256 + USHORT ExternalLNAForA:1; // external LNA enable for 2.4G
51257 + USHORT CardbusAcceleration:1; // !!! NOTE: 0 - enable, 1 - disable
51258 + USHORT BW40MSidebandForG:1;
51259 + USHORT BW40MSidebandForA:1;
51260 + USHORT EnableWPSPBC:1; // WPS PBC Control bit
51261 + USHORT BW40MAvailForG:1; // 0:enable, 1:disable
51262 + USHORT BW40MAvailForA:1; // 0:enable, 1:disable
51263 + USHORT Rsv1:1; // must be 0
51264 + USHORT AntDiversity:1; // Antenna diversity
51265 + USHORT Rsv2:3; // must be 0
51266 + USHORT DACTestBit:1; // control if driver should patch the DAC issue
51267 + } field;
51268 + USHORT word;
51269 +} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC;
51270 +#endif
51271 +
51272 +//
51273 +// TX_PWR Value valid range 0xFA(-6) ~ 0x24(36)
51274 +//
51275 +#ifdef RT_BIG_ENDIAN
51276 +typedef union _EEPROM_TX_PWR_STRUC {
51277 + struct {
51278 + CHAR Byte1; // High Byte
51279 + CHAR Byte0; // Low Byte
51280 + } field;
51281 + USHORT word;
51282 +} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC;
51283 +#else
51284 +typedef union _EEPROM_TX_PWR_STRUC {
51285 + struct {
51286 + CHAR Byte0; // Low Byte
51287 + CHAR Byte1; // High Byte
51288 + } field;
51289 + USHORT word;
51290 +} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC;
51291 +#endif
51292 +
51293 +#ifdef RT_BIG_ENDIAN
51294 +typedef union _EEPROM_VERSION_STRUC {
51295 + struct {
51296 + UCHAR Version; // High Byte
51297 + UCHAR FaeReleaseNumber; // Low Byte
51298 + } field;
51299 + USHORT word;
51300 +} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC;
51301 +#else
51302 +typedef union _EEPROM_VERSION_STRUC {
51303 + struct {
51304 + UCHAR FaeReleaseNumber; // Low Byte
51305 + UCHAR Version; // High Byte
51306 + } field;
51307 + USHORT word;
51308 +} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC;
51309 +#endif
51310 +
51311 +#ifdef RT_BIG_ENDIAN
51312 +typedef union _EEPROM_LED_STRUC {
51313 + struct {
51314 + USHORT Rsvd:3; // Reserved
51315 + USHORT LedMode:5; // Led mode.
51316 + USHORT PolarityGPIO_4:1; // Polarity GPIO#4 setting.
51317 + USHORT PolarityGPIO_3:1; // Polarity GPIO#3 setting.
51318 + USHORT PolarityGPIO_2:1; // Polarity GPIO#2 setting.
51319 + USHORT PolarityGPIO_1:1; // Polarity GPIO#1 setting.
51320 + USHORT PolarityGPIO_0:1; // Polarity GPIO#0 setting.
51321 + USHORT PolarityACT:1; // Polarity ACT setting.
51322 + USHORT PolarityRDY_A:1; // Polarity RDY_A setting.
51323 + USHORT PolarityRDY_G:1; // Polarity RDY_G setting.
51324 + } field;
51325 + USHORT word;
51326 +} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC;
51327 +#else
51328 +typedef union _EEPROM_LED_STRUC {
51329 + struct {
51330 + USHORT PolarityRDY_G:1; // Polarity RDY_G setting.
51331 + USHORT PolarityRDY_A:1; // Polarity RDY_A setting.
51332 + USHORT PolarityACT:1; // Polarity ACT setting.
51333 + USHORT PolarityGPIO_0:1; // Polarity GPIO#0 setting.
51334 + USHORT PolarityGPIO_1:1; // Polarity GPIO#1 setting.
51335 + USHORT PolarityGPIO_2:1; // Polarity GPIO#2 setting.
51336 + USHORT PolarityGPIO_3:1; // Polarity GPIO#3 setting.
51337 + USHORT PolarityGPIO_4:1; // Polarity GPIO#4 setting.
51338 + USHORT LedMode:5; // Led mode.
51339 + USHORT Rsvd:3; // Reserved
51340 + } field;
51341 + USHORT word;
51342 +} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC;
51343 +#endif
51344 +
51345 +#ifdef RT_BIG_ENDIAN
51346 +typedef union _EEPROM_TXPOWER_DELTA_STRUC {
51347 + struct {
51348 + UCHAR TxPowerEnable:1;// Enable
51349 + UCHAR Type:1; // 1: plus the delta value, 0: minus the delta value
51350 + UCHAR DeltaValue:6; // Tx Power dalta value (MAX=4)
51351 + } field;
51352 + UCHAR value;
51353 +} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC;
51354 +#else
51355 +typedef union _EEPROM_TXPOWER_DELTA_STRUC {
51356 + struct {
51357 + UCHAR DeltaValue:6; // Tx Power dalta value (MAX=4)
51358 + UCHAR Type:1; // 1: plus the delta value, 0: minus the delta value
51359 + UCHAR TxPowerEnable:1;// Enable
51360 + } field;
51361 + UCHAR value;
51362 +} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC;
51363 +#endif
51364 +
51365 +//
51366 +// QOS_CSR0: TXOP holder address0 register
51367 +//
51368 +#ifdef RT_BIG_ENDIAN
51369 +typedef union _QOS_CSR0_STRUC {
51370 + struct {
51371 + UCHAR Byte3; // MAC address byte 3
51372 + UCHAR Byte2; // MAC address byte 2
51373 + UCHAR Byte1; // MAC address byte 1
51374 + UCHAR Byte0; // MAC address byte 0
51375 + } field;
51376 + UINT32 word;
51377 +} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC;
51378 +#else
51379 +typedef union _QOS_CSR0_STRUC {
51380 + struct {
51381 + UCHAR Byte0; // MAC address byte 0
51382 + UCHAR Byte1; // MAC address byte 1
51383 + UCHAR Byte2; // MAC address byte 2
51384 + UCHAR Byte3; // MAC address byte 3
51385 + } field;
51386 + UINT32 word;
51387 +} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC;
51388 +#endif
51389 +
51390 +//
51391 +// QOS_CSR1: TXOP holder address1 register
51392 +//
51393 +#ifdef RT_BIG_ENDIAN
51394 +typedef union _QOS_CSR1_STRUC {
51395 + struct {
51396 + UCHAR Rsvd1;
51397 + UCHAR Rsvd0;
51398 + UCHAR Byte5; // MAC address byte 5
51399 + UCHAR Byte4; // MAC address byte 4
51400 + } field;
51401 + UINT32 word;
51402 +} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC;
51403 +#else
51404 +typedef union _QOS_CSR1_STRUC {
51405 + struct {
51406 + UCHAR Byte4; // MAC address byte 4
51407 + UCHAR Byte5; // MAC address byte 5
51408 + UCHAR Rsvd0;
51409 + UCHAR Rsvd1;
51410 + } field;
51411 + UINT32 word;
51412 +} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC;
51413 +#endif
51414 +
51415 +#define RF_CSR_CFG 0x500
51416 +#ifdef RT_BIG_ENDIAN
51417 +typedef union _RF_CSR_CFG_STRUC {
51418 + struct {
51419 + UINT Rsvd1:14; // Reserved
51420 + UINT RF_CSR_KICK:1; // kick RF register read/write
51421 + UINT RF_CSR_WR:1; // 0: read 1: write
51422 + UINT Rsvd2:3; // Reserved
51423 + UINT TESTCSR_RFACC_REGNUM:5; // RF register ID
51424 + UINT RF_CSR_DATA:8; // DATA
51425 + } field;
51426 + UINT word;
51427 +} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC;
51428 +#else
51429 +typedef union _RF_CSR_CFG_STRUC {
51430 + struct {
51431 + UINT RF_CSR_DATA:8; // DATA
51432 + UINT TESTCSR_RFACC_REGNUM:5; // RF register ID
51433 + UINT Rsvd2:3; // Reserved
51434 + UINT RF_CSR_WR:1; // 0: read 1: write
51435 + UINT RF_CSR_KICK:1; // kick RF register read/write
51436 + UINT Rsvd1:14; // Reserved
51437 + } field;
51438 + UINT word;
51439 +} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC;
51440 +#endif
51441 +
51442 +#endif // __RT28XX_H__
51443 --- /dev/null
51444 +++ b/drivers/staging/rt3070/rt_ate.c
51445 @@ -0,0 +1,6506 @@
51446 +/*
51447 + *************************************************************************
51448 + * Ralink Tech Inc.
51449 + * 5F., No.36, Taiyuan St., Jhubei City,
51450 + * Hsinchu County 302,
51451 + * Taiwan, R.O.C.
51452 + *
51453 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
51454 + *
51455 + * This program is free software; you can redistribute it and/or modify *
51456 + * it under the terms of the GNU General Public License as published by *
51457 + * the Free Software Foundation; either version 2 of the License, or *
51458 + * (at your option) any later version. *
51459 + * *
51460 + * This program is distributed in the hope that it will be useful, *
51461 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
51462 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
51463 + * GNU General Public License for more details. *
51464 + * *
51465 + * You should have received a copy of the GNU General Public License *
51466 + * along with this program; if not, write to the *
51467 + * Free Software Foundation, Inc., *
51468 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
51469 + * *
51470 + *************************************************************************
51471 + */
51472 +
51473 +#include "rt_config.h"
51474 +
51475 +#ifdef UCOS
51476 +INT IoctlResponse(PUCHAR payload, PUCHAR msg, INT len);
51477 +#endif // UCOS //
51478 +
51479 +#define ATE_BBP_REG_NUM 168
51480 +UCHAR restore_BBP[ATE_BBP_REG_NUM]={0};
51481 +
51482 +#ifdef RALINK_ATE
51483 +UCHAR TemplateFrame[24] = {0x08/* Data type */,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xAA,0xBB,0x12,0x34,0x56,0x00,0x11,0x22,0xAA,0xBB,0xCC,0x00,0x00}; // 802.11 MAC Header, Type:Data, Length:24bytes
51484 +extern RTMP_RF_REGS RF2850RegTable[];
51485 +extern UCHAR NUM_OF_2850_CHNL;
51486 +
51487 +#ifdef RT2870
51488 +extern UCHAR EpToQueue[];
51489 +extern VOID RTUSBRejectPendingPackets( IN PRTMP_ADAPTER pAd);
51490 +#endif // RT2870 //
51491 +
51492 +#ifdef RT30xx
51493 +//2008/07/10:KH adds to support 3070 ATE<--
51494 +extern FREQUENCY_ITEM FreqItems3020[];
51495 +extern UCHAR NUM_OF_3020_CHNL;
51496 +//2008/07/10:KH adds to support 3070 ATE-->
51497 +#endif // RT30xx //
51498 +
51499 +#ifdef UCOS
51500 +extern INT ConsoleResponse(IN PUCHAR buff);
51501 +extern int (*remote_display)(char *);
51502 +#endif // UCOS //
51503 +
51504 +static CHAR CCKRateTable[] = {0, 1, 2, 3, 8, 9, 10, 11, -1}; /* CCK Mode. */
51505 +static CHAR OFDMRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, -1}; /* OFDM Mode. */
51506 +static CHAR HTMIXRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}; /* HT Mix Mode. */
51507 +
51508 +static INT TxDmaBusy(
51509 + IN PRTMP_ADAPTER pAd);
51510 +
51511 +static INT RxDmaBusy(
51512 + IN PRTMP_ADAPTER pAd);
51513 +
51514 +static VOID RtmpDmaEnable(
51515 + IN PRTMP_ADAPTER pAd,
51516 + IN INT Enable);
51517 +
51518 +static VOID BbpSoftReset(
51519 + IN PRTMP_ADAPTER pAd);
51520 +
51521 +static VOID RtmpRfIoWrite(
51522 + IN PRTMP_ADAPTER pAd);
51523 +
51524 +static INT ATESetUpFrame(
51525 + IN PRTMP_ADAPTER pAd,
51526 + IN UINT32 TxIdx);
51527 +
51528 +static INT ATETxPwrHandler(
51529 + IN PRTMP_ADAPTER pAd,
51530 + IN char index);
51531 +
51532 +static INT ATECmdHandler(
51533 + IN PRTMP_ADAPTER pAd,
51534 + IN PUCHAR arg);
51535 +
51536 +static int CheckMCSValid(
51537 + IN UCHAR Mode,
51538 + IN UCHAR Mcs);
51539 +
51540 +
51541 +#ifdef RT2870
51542 +static VOID ATEWriteTxInfo(
51543 + IN PRTMP_ADAPTER pAd,
51544 + IN PTXINFO_STRUC pTxInfo,
51545 + IN USHORT USBDMApktLen,
51546 + IN BOOLEAN bWiv,
51547 + IN UCHAR QueueSel,
51548 + IN UCHAR NextValid,
51549 + IN UCHAR TxBurst);
51550 +
51551 +static VOID ATEWriteTxWI(
51552 + IN PRTMP_ADAPTER pAd,
51553 + IN PTXWI_STRUC pTxWI,
51554 + IN BOOLEAN FRAG,
51555 + IN BOOLEAN InsTimestamp,
51556 + IN BOOLEAN AMPDU,
51557 + IN BOOLEAN Ack,
51558 + IN BOOLEAN NSeq, // HW new a sequence.
51559 + IN UCHAR BASize,
51560 + IN UCHAR WCID,
51561 + IN ULONG Length,
51562 + IN UCHAR PID,
51563 + IN UCHAR MIMOps,
51564 + IN UCHAR Txopmode,
51565 + IN BOOLEAN CfAck,
51566 + IN HTTRANSMIT_SETTING Transmit);
51567 +
51568 +#endif // RT2870 //
51569 +
51570 +static VOID SetJapanFilter(
51571 + IN PRTMP_ADAPTER pAd);
51572 +
51573 +/*=========================end of prototype=========================*/
51574 +
51575 +
51576 +#ifdef RT2870
51577 +static INT TxDmaBusy(
51578 + IN PRTMP_ADAPTER pAd)
51579 +{
51580 + INT result;
51581 + USB_DMA_CFG_STRUC UsbCfg;
51582 +
51583 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
51584 + if (UsbCfg.field.TxBusy)
51585 + result = 1;
51586 + else
51587 + result = 0;
51588 +
51589 + return result;
51590 +}
51591 +
51592 +static INT RxDmaBusy(
51593 + IN PRTMP_ADAPTER pAd)
51594 +{
51595 + INT result;
51596 + USB_DMA_CFG_STRUC UsbCfg;
51597 +
51598 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
51599 + if (UsbCfg.field.RxBusy)
51600 + result = 1;
51601 + else
51602 + result = 0;
51603 +
51604 + return result;
51605 +}
51606 +
51607 +static VOID RtmpDmaEnable(
51608 + IN PRTMP_ADAPTER pAd,
51609 + IN INT Enable)
51610 +{
51611 + BOOLEAN value;
51612 + ULONG WaitCnt;
51613 + USB_DMA_CFG_STRUC UsbCfg;
51614 +
51615 + value = Enable > 0 ? 1 : 0;
51616 +
51617 + // check DMA is in busy mode.
51618 + WaitCnt = 0;
51619 + while (TxDmaBusy(pAd) || RxDmaBusy(pAd))
51620 + {
51621 + RTMPusecDelay(10);
51622 + if (WaitCnt++ > 100)
51623 + break;
51624 + }
51625 +
51626 + //Why not to clear USB DMA TX path first ???
51627 + RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
51628 + UsbCfg.field.TxBulkEn = value;
51629 + UsbCfg.field.RxBulkEn = value;
51630 + RTMP_IO_WRITE32(pAd, USB_DMA_CFG, UsbCfg.word); // abort all TX rings
51631 + RTMPusecDelay(5000);
51632 +
51633 + return;
51634 +}
51635 +#endif // RT2870 //
51636 +
51637 +static VOID BbpSoftReset(
51638 + IN PRTMP_ADAPTER pAd)
51639 +{
51640 + UCHAR BbpData = 0;
51641 +
51642 + // Soft reset, set BBP R21 bit0=1->0
51643 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
51644 + BbpData |= 0x00000001; //set bit0=1
51645 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
51646 +
51647 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
51648 + BbpData &= ~(0x00000001); //set bit0=0
51649 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
51650 +
51651 + return;
51652 +}
51653 +
51654 +static VOID RtmpRfIoWrite(
51655 + IN PRTMP_ADAPTER pAd)
51656 +{
51657 + // Set RF value 1's set R3[bit2] = [0]
51658 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
51659 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
51660 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
51661 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
51662 +
51663 + RTMPusecDelay(200);
51664 +
51665 + // Set RF value 2's set R3[bit2] = [1]
51666 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
51667 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
51668 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
51669 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
51670 +
51671 + RTMPusecDelay(200);
51672 +
51673 + // Set RF value 3's set R3[bit2] = [0]
51674 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
51675 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
51676 + RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
51677 + RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
51678 +
51679 + return;
51680 +}
51681 +
51682 +static int CheckMCSValid(
51683 + UCHAR Mode,
51684 + UCHAR Mcs)
51685 +{
51686 + int i;
51687 + PCHAR pRateTab;
51688 +
51689 + switch(Mode)
51690 + {
51691 + case 0:
51692 + pRateTab = CCKRateTable;
51693 + break;
51694 + case 1:
51695 + pRateTab = OFDMRateTable;
51696 + break;
51697 + case 2:
51698 + case 3:
51699 + pRateTab = HTMIXRateTable;
51700 + break;
51701 + default:
51702 + ATEDBGPRINT(RT_DEBUG_ERROR, ("unrecognizable Tx Mode %d\n", Mode));
51703 + return -1;
51704 + break;
51705 + }
51706 +
51707 + i = 0;
51708 + while(pRateTab[i] != -1)
51709 + {
51710 + if (pRateTab[i] == Mcs)
51711 + return 0;
51712 + i++;
51713 + }
51714 +
51715 + return -1;
51716 +}
51717 +
51718 +#if 1
51719 +static INT ATETxPwrHandler(
51720 + IN PRTMP_ADAPTER pAd,
51721 + IN char index)
51722 +{
51723 + ULONG R;
51724 + CHAR TxPower;
51725 + UCHAR Bbp94 = 0;
51726 + BOOLEAN bPowerReduce = FALSE;
51727 +#ifdef RT30xx
51728 + UCHAR RFValue;
51729 +#endif // RT30xx //
51730 +#ifdef RALINK_28xx_QA
51731 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
51732 + {
51733 + /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
51734 + ** are not synchronized.
51735 + */
51736 +/*
51737 + pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
51738 + pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
51739 +*/
51740 + return 0;
51741 + }
51742 + else
51743 +#endif // RALINK_28xx_QA //
51744 + {
51745 + TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
51746 +
51747 + if (pAd->ate.Channel <= 14)
51748 + {
51749 + if (TxPower > 31)
51750 + {
51751 + //
51752 + // R3, R4 can't large than 31 (0x24), 31 ~ 36 used by BBP 94
51753 + //
51754 + R = 31;
51755 + if (TxPower <= 36)
51756 + Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
51757 + }
51758 + else if (TxPower < 0)
51759 + {
51760 + //
51761 + // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
51762 + //
51763 + R = 0;
51764 + if (TxPower >= -6)
51765 + Bbp94 = BBPR94_DEFAULT + TxPower;
51766 + }
51767 + else
51768 + {
51769 + // 0 ~ 31
51770 + R = (ULONG) TxPower;
51771 + Bbp94 = BBPR94_DEFAULT;
51772 + }
51773 +
51774 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
51775 + }
51776 + else// 5.5 GHz
51777 + {
51778 + if (TxPower > 15)
51779 + {
51780 + //
51781 + // R3, R4 can't large than 15 (0x0F)
51782 + //
51783 + R = 15;
51784 + }
51785 + else if (TxPower < 0)
51786 + {
51787 + //
51788 + // R3, R4 can't less than 0
51789 + //
51790 + // -1 ~ -7
51791 + ASSERT((TxPower >= -7));
51792 + R = (ULONG)(TxPower + 7);
51793 + bPowerReduce = TRUE;
51794 + }
51795 + else
51796 + {
51797 + // 0 ~ 15
51798 + R = (ULONG) TxPower;
51799 + }
51800 +
51801 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%lu)\n", __FUNCTION__, TxPower, R));
51802 + }
51803 +//2008/09/10:KH adds to support 3070 ATE TX Power tunning real time<--
51804 +#ifdef RT30xx
51805 + if(IS_RT30xx(pAd))
51806 + {
51807 + // Set Tx Power
51808 +
51809 + RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
51810 + RFValue = (RFValue & 0xE0) | TxPower;
51811 + RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
51812 + ATEDBGPRINT(RT_DEBUG_TRACE, ("3070 or 2070:%s (TxPower=%d, RFValue=%x)\n", __FUNCTION__, TxPower, RFValue));
51813 +
51814 + }
51815 + else
51816 +#endif // RT30xx //
51817 + {
51818 + if (pAd->ate.Channel <= 14)
51819 + {
51820 + if (index == 0)
51821 + {
51822 + R = R << 9; // shift TX power control to correct RF(R3) register bit position
51823 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51824 + pAd->LatchRfRegs.R3 = R;
51825 + }
51826 + else
51827 + {
51828 + R = R << 6; // shift TX power control to correct RF(R4) register bit position
51829 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51830 + pAd->LatchRfRegs.R4 = R;
51831 + }
51832 + }
51833 + else// 5.5GHz
51834 + {
51835 + if (bPowerReduce == FALSE)
51836 + {
51837 + if (index == 0)
51838 + {
51839 + R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
51840 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51841 + pAd->LatchRfRegs.R3 = R;
51842 + }
51843 + else
51844 + {
51845 + R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
51846 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51847 + pAd->LatchRfRegs.R4 = R;
51848 + }
51849 + }
51850 + else
51851 + {
51852 + if (index == 0)
51853 + {
51854 + R = (R << 10); // shift TX power control to correct RF(R3) register bit position
51855 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51856 +
51857 + /* Clear bit 9 of R3 to reduce 7dB. */
51858 + pAd->LatchRfRegs.R3 = (R & (~(1 << 9)));
51859 + }
51860 + else
51861 + {
51862 + R = (R << 7); // shift TX power control to correct RF(R4) register bit position
51863 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51864 +
51865 + /* Clear bit 6 of R4 to reduce 7dB. */
51866 + pAd->LatchRfRegs.R4 = (R & (~(1 << 6)));
51867 + }
51868 + }
51869 + }
51870 + RtmpRfIoWrite(pAd);
51871 + }
51872 +//2008/09/10:KH adds to support 3070 ATE TX Power tunning real time-->
51873 +
51874 + return 0;
51875 + }
51876 +}
51877 +#else// 1 //
51878 +static INT ATETxPwrHandler(
51879 + IN PRTMP_ADAPTER pAd,
51880 + IN char index)
51881 +{
51882 + ULONG R;
51883 + CHAR TxPower;
51884 + UCHAR Bbp94 = 0;
51885 +
51886 +#ifdef RALINK_28xx_QA
51887 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
51888 + {
51889 + // TODO: how to get current TxPower0/1 from pAd->LatchRfRegs ?
51890 + /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
51891 + ** are not synchronized.
51892 + */
51893 +/*
51894 + pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
51895 + pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
51896 +*/
51897 + return 0;
51898 + }
51899 + else
51900 +#endif // RALINK_28xx_QA //
51901 + {
51902 + TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
51903 +
51904 + if (TxPower > 31)
51905 + {
51906 + //
51907 + // R3, R4 can't large than 36 (0x24), 31 ~ 36 used by BBP 94
51908 + //
51909 + R = 31;
51910 + if (TxPower <= 36)
51911 + Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
51912 + }
51913 + else if (TxPower < 0)
51914 + {
51915 + //
51916 + // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
51917 + //
51918 + R = 0;
51919 + if (TxPower >= -6)
51920 + Bbp94 = BBPR94_DEFAULT + TxPower;
51921 + }
51922 + else
51923 + {
51924 + // 0 ~ 31
51925 + R = (ULONG) TxPower;
51926 + Bbp94 = BBPR94_DEFAULT;
51927 + }
51928 +
51929 + ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R3=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
51930 +
51931 + if (pAd->ate.Channel <= 14)
51932 + {
51933 + if (index == 0)
51934 + {
51935 + R = R << 9; // shift TX power control to correct RF(R3) register bit position
51936 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51937 + pAd->LatchRfRegs.R3 = R;
51938 + }
51939 + else
51940 + {
51941 + R = R << 6; // shift TX power control to correct RF(R4) register bit position
51942 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51943 + pAd->LatchRfRegs.R4 = R;
51944 + }
51945 + }
51946 + else
51947 + {
51948 + if (index == 0)
51949 + {
51950 + R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
51951 + R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
51952 + pAd->LatchRfRegs.R3 = R;
51953 + }
51954 + else
51955 + {
51956 + R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
51957 + R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
51958 + pAd->LatchRfRegs.R4 = R;
51959 + }
51960 + }
51961 +
51962 + RtmpRfIoWrite(pAd);
51963 +
51964 + return 0;
51965 + }
51966 +}
51967 +#endif // 1 //
51968 +/*
51969 + ==========================================================================
51970 + Description:
51971 + Set ATE operation mode to
51972 + 0. ATESTART = Start ATE Mode
51973 + 1. ATESTOP = Stop ATE Mode
51974 + 2. TXCONT = Continuous Transmit
51975 + 3. TXCARR = Transmit Carrier
51976 + 4. TXFRAME = Transmit Frames
51977 + 5. RXFRAME = Receive Frames
51978 +#ifdef RALINK_28xx_QA
51979 + 6. TXSTOP = Stop Any Type of Transmition
51980 + 7. RXSTOP = Stop Receiving Frames
51981 +#endif // RALINK_28xx_QA //
51982 + Return:
51983 + TRUE if all parameters are OK, FALSE otherwise
51984 + ==========================================================================
51985 +*/
51986 +/* */
51987 +/* */
51988 +/*=======================End of RT2860=======================*/
51989 +
51990 +
51991 +/*======================Start of RT2870======================*/
51992 +/* */
51993 +/* */
51994 +
51995 +#ifdef RT2870
51996 +static INT ATECmdHandler(
51997 + IN PRTMP_ADAPTER pAd,
51998 + IN PUCHAR arg)
51999 +{
52000 + UINT32 Value;
52001 + UCHAR BbpData;
52002 + UINT32 MacData;
52003 + UINT i=0, atemode;
52004 + //NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
52005 + //PUCHAR pDest;
52006 + UINT32 temp;
52007 + ULONG IrqFlags;
52008 +
52009 + ATEDBGPRINT(RT_DEBUG_TRACE, ("===> ATECmdHandler()\n"));
52010 + ATEAsicSwitchChannel(pAd);
52011 + /* AsicLockChannel() is empty function so far in fact */
52012 + AsicLockChannel(pAd, pAd->ate.Channel);
52013 +
52014 + RTMPusecDelay(5000);
52015 +
52016 + // Default value in BBP R22 is 0x0.
52017 + BbpData = 0;
52018 +
52019 + /* Enter ATE mode and set Tx/Rx Idle */
52020 + if (!strcmp(arg, "ATESTART"))
52021 + {
52022 +#ifdef CONFIG_STA_SUPPORT
52023 + BOOLEAN Cancelled;
52024 +#endif // CONFIG_STA_SUPPORT //
52025 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTART\n"));
52026 +
52027 + netif_stop_queue(pAd->net_dev);
52028 +
52029 + atemode = pAd->ate.Mode;
52030 + pAd->ate.Mode = ATE_START;
52031 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
52032 + // Disable Rx
52033 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52034 + Value &= ~(1 << 3);
52035 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52036 +
52037 + // Disable auto responder
52038 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
52039 + temp = temp & 0xFFFFFFFE;
52040 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
52041 +
52042 + // read MAC_SYS_CTRL and backup MAC_SYS_CTRL value.
52043 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52044 + // clean bit4 to stop continuous Tx production test.
52045 + MacData &= 0xFFFFFFEF;
52046 + // Stop continuous TX production test.
52047 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);//disable or cancel pending irp first ???
52048 +
52049 + if (atemode & ATE_TXCARR
52050 +#ifdef RT30xx
52051 + || atemode & ATE_TXCONT
52052 +#endif // RT30xx //
52053 +)
52054 + {
52055 +#ifdef RT30xx
52056 + //Hardware Reset BBP
52057 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
52058 + temp = temp |0x00000002;
52059 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
52060 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
52061 + temp = temp & ~(0x00000002);
52062 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
52063 + //Restore All BBP Value
52064 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52065 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
52066 +#endif // RT30xx //
52067 +
52068 + // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
52069 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52070 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
52071 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52072 + }
52073 + else if (atemode & ATE_TXCARRSUPP)
52074 + {
52075 +#ifdef RT30xx
52076 + //Hardware Reset BBP
52077 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
52078 + temp = temp |0x00000002;
52079 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
52080 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
52081 + temp = temp & ~(0x00000002);
52082 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
52083 + //Restore All BBP Value
52084 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52085 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
52086 +#endif // RT30xx //
52087 +
52088 + // No Cont. TX set BBP R22 bit7=0
52089 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52090 + BbpData &= ~(1 << 7); //set bit7=0
52091 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52092 +
52093 + // No Carrier Suppression set BBP R24 bit0=0
52094 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
52095 + BbpData &= 0xFFFFFFFE; //clear bit0
52096 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
52097 + }
52098 + // We should free some resource which allocate when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
52099 + // TODO:Should we free some resource which was allocated when LoopBack and ATE_STOP ?
52100 + else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
52101 + {
52102 + if (atemode & ATE_TXCONT)
52103 + {
52104 + // Not Cont. TX anymore, so set BBP R22 bit7=0
52105 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52106 + BbpData &= ~(1 << 7); //set bit7=0
52107 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52108 + }
52109 + // Abort Tx, Rx DMA.
52110 + RtmpDmaEnable(pAd, 0);
52111 +
52112 + {
52113 + // It seems nothing to free,
52114 + // because we didn't allocate any resource when we entered ATE_TXFRAME mode latestly.
52115 + }
52116 +
52117 + // Start Tx, RX DMA
52118 + RtmpDmaEnable(pAd, 1);
52119 + }
52120 +
52121 + RTUSBRejectPendingPackets(pAd);
52122 + RTUSBCleanUpDataBulkOutQueue(pAd);
52123 +
52124 +#ifdef CONFIG_STA_SUPPORT
52125 + //
52126 + // It will be called in MlmeSuspend().
52127 + //
52128 + // Cancel pending timers
52129 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
52130 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
52131 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
52132 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
52133 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
52134 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
52135 +#endif // CONFIG_STA_SUPPORT //
52136 +
52137 + //RTUSBCleanUpMLMEWaitQueue(pAd); /* not used in RT28xx */
52138 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
52139 +
52140 + // Sometimes kernel will hang on, so we avoid calling MlmeSuspend().
52141 +// MlmeSuspend(pAd, TRUE);
52142 + //RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
52143 +
52144 + // Disable Rx
52145 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52146 + Value &= ~(1 << 3);
52147 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52148 +
52149 + // Abort Tx, RX DMA.
52150 + RtmpDmaEnable(pAd, 0);
52151 +
52152 + // Disable Tx
52153 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52154 + Value &= ~(1 << 2);
52155 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52156 +
52157 + // Make sure there are no pending bulk in/out IRPs before we go on.
52158 +/*=========================================================================*/
52159 + /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
52160 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
52161 + while ((pAd->PendingRx > 0)) //pAd->BulkFlags != 0 wait bulk out finish
52162 + {
52163 +#if 1
52164 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
52165 +#else
52166 + NdisInterlockedDecrement(&pAd->PendingRx);
52167 +#endif
52168 + /* delay 0.5 seconds */
52169 + RTMPusecDelay(500000);
52170 + pAd->PendingRx = 0;
52171 + }
52172 + /* peter : why don't we have to get BulkOutLock first ? */
52173 + while (((pAd->BulkOutPending[0] == TRUE) ||
52174 + (pAd->BulkOutPending[1] == TRUE) ||
52175 + (pAd->BulkOutPending[2] == TRUE) ||
52176 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
52177 + {
52178 + do
52179 + {
52180 + /* pAd->BulkOutPending[y] will be set to FALSE in RTUSBCancelPendingBulkOutIRP(pAd) */
52181 + RTUSBCancelPendingBulkOutIRP(pAd);
52182 + } while (FALSE);
52183 +
52184 + /* we have enough time delay in RTUSBCancelPendingBulkOutIRP(pAd)
52185 + ** so this is not necessary
52186 + */
52187 +// RTMPusecDelay(500000);
52188 + }
52189 +
52190 + /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
52191 +// ASSERT(atomic_read(&pAd->PendingRx) == 0);
52192 + ASSERT(pAd->PendingRx == 0);
52193 +/*=========================================================================*/
52194 +
52195 + // reset Rx statistics.
52196 + pAd->ate.LastSNR0 = 0;
52197 + pAd->ate.LastSNR1 = 0;
52198 + pAd->ate.LastRssi0 = 0;
52199 + pAd->ate.LastRssi1 = 0;
52200 + pAd->ate.LastRssi2 = 0;
52201 + pAd->ate.AvgRssi0 = 0;
52202 + pAd->ate.AvgRssi1 = 0;
52203 + pAd->ate.AvgRssi2 = 0;
52204 + pAd->ate.AvgRssi0X8 = 0;
52205 + pAd->ate.AvgRssi1X8 = 0;
52206 + pAd->ate.AvgRssi2X8 = 0;
52207 + pAd->ate.NumOfAvgRssiSample = 0;
52208 +
52209 +#ifdef RALINK_28xx_QA
52210 + // Tx frame
52211 + pAd->ate.bQATxStart = FALSE;
52212 + pAd->ate.bQARxStart = FALSE;
52213 + pAd->ate.seq = 0;
52214 +
52215 + // counters
52216 + pAd->ate.U2M = 0;
52217 + pAd->ate.OtherData = 0;
52218 + pAd->ate.Beacon = 0;
52219 + pAd->ate.OtherCount = 0;
52220 + pAd->ate.TxAc0 = 0;
52221 + pAd->ate.TxAc1 = 0;
52222 + pAd->ate.TxAc2 = 0;
52223 + pAd->ate.TxAc3 = 0;
52224 + pAd->ate.TxHCCA = 0;
52225 + pAd->ate.TxMgmt = 0;
52226 + pAd->ate.RSSI0 = 0;
52227 + pAd->ate.RSSI1 = 0;
52228 + pAd->ate.RSSI2 = 0;
52229 + pAd->ate.SNR0 = 0;
52230 + pAd->ate.SNR1 = 0;
52231 +
52232 + // control
52233 + pAd->ate.TxDoneCount = 0;
52234 + pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
52235 +#endif // RALINK_28xx_QA //
52236 +
52237 + // Soft reset BBP.
52238 + BbpSoftReset(pAd);
52239 +
52240 +
52241 +#ifdef CONFIG_STA_SUPPORT
52242 + AsicDisableSync(pAd);
52243 +
52244 + /*
52245 + ** If we skip "LinkDown()", we should disable protection
52246 + ** to prevent from sending out RTS or CTS-to-self.
52247 + */
52248 + ATEDisableAsicProtect(pAd);
52249 + RTMPStationStop(pAd);
52250 +#endif // CONFIG_STA_SUPPORT //
52251 +
52252 + // Default value in BBP R22 is 0x0.
52253 + BbpData = 0;
52254 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52255 +
52256 + // Clean bit4 to stop continuous Tx production test.
52257 + MacData &= 0xFFFFFFEF;
52258 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52259 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52260 + //Clean ATE Bulk in/out counter and continue setup
52261 + InterlockedExchange(&pAd->BulkOutRemained, 0);
52262 +
52263 + /* NdisAcquireSpinLock()/NdisReleaseSpinLock() need only one argument in RT28xx */
52264 + NdisAcquireSpinLock(&pAd->GenericLock);
52265 + pAd->ContinBulkOut = FALSE;
52266 + pAd->ContinBulkIn = FALSE;
52267 + NdisReleaseSpinLock(&pAd->GenericLock);
52268 +
52269 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
52270 + }
52271 + else if (!strcmp(arg, "ATESTOP"))
52272 + {
52273 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE : ATESTOP ===>\n"));
52274 +
52275 + // Default value in BBP R22 is 0x0.
52276 + BbpData = 0;
52277 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);//0820
52278 + // Clean bit4 to stop continuous Tx production test.
52279 + MacData &= 0xFFFFFFEF;
52280 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52281 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData); // recover the MAC_SYS_CTRL register back.
52282 +
52283 + // Disable Rx
52284 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52285 + Value &= ~(1 << 3);
52286 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52287 +
52288 + /*
52289 + ** Abort Tx, RX DMA.
52290 + ** Q : How to do the following I/O if Tx, Rx DMA is aborted ?
52291 + ** Ans : Bulk endpoints are aborted, while the control endpoint is not.
52292 + */
52293 + RtmpDmaEnable(pAd, 0);
52294 +
52295 + // Disable Tx
52296 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52297 + Value &= ~(1 << 2);
52298 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52299 +
52300 + /* Make sure there are no pending bulk in/out IRPs before we go on. */
52301 +/*=========================================================================*/
52302 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
52303 + while (pAd->PendingRx > 0)
52304 + {
52305 +#if 1
52306 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
52307 +#else
52308 +// NdisInterlockedDecrement(&pAd->PendingRx);
52309 + pAd->PendingRx--;
52310 +#endif
52311 + RTMPusecDelay(500000);
52312 + }
52313 +
52314 + while (((pAd->BulkOutPending[0] == TRUE) ||
52315 + (pAd->BulkOutPending[1] == TRUE) ||
52316 + (pAd->BulkOutPending[2] == TRUE) ||
52317 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
52318 + {
52319 + do
52320 + {
52321 + RTUSBCancelPendingBulkOutIRP(pAd);
52322 + } while (FALSE);
52323 +
52324 + RTMPusecDelay(500000);
52325 + }
52326 +
52327 +// ASSERT(atomic_read(&pAd->PendingRx) == 0);
52328 + ASSERT(pAd->PendingRx == 0);
52329 +/*=========================================================================*/
52330 +/* Reset Rx RING */
52331 +/*=========================================================================*/
52332 +// InterlockedExchange(&pAd->PendingRx, 0);
52333 + pAd->PendingRx = 0;
52334 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
52335 + pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
52336 + pAd->NextRxBulkInPosition = 0;
52337 + for (i = 0; i < (RX_RING_SIZE); i++)
52338 + {
52339 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
52340 + NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
52341 + /* peter : why don't we have to get BulkInLock first ? */
52342 + pRxContext->pAd = pAd;
52343 + pRxContext->pIrp = NULL;
52344 + /* peter debug ++ */
52345 + pRxContext->BulkInOffset = 0;
52346 + pRxContext->bRxHandling = FALSE;
52347 + /* peter debug -- */
52348 + pRxContext->InUse = FALSE;
52349 + pRxContext->IRPPending = FALSE;
52350 + pRxContext->Readable = FALSE;
52351 +// pRxContext->ReorderInUse = FALSE;
52352 +// pRxContext->ReadPosOffset = 0;
52353 + }
52354 +
52355 +/*=========================================================================*/
52356 +/* Reset Tx RING */
52357 +/*=========================================================================*/
52358 + do
52359 + {
52360 + RTUSBCancelPendingBulkOutIRP(pAd);
52361 + } while (FALSE);
52362 +
52363 +/*=========================================================================*/
52364 + // Enable auto responder.
52365 + RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
52366 + temp = temp | (0x01);
52367 + RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
52368 +
52369 +/*================================================*/
52370 + AsicEnableBssSync(pAd);
52371 +
52372 + /* Soft reset BBP.*/
52373 + /* In 2870 chipset, ATE_BBP_IO_READ8_BY_REG_ID() == RTMP_BBP_IO_READ8_BY_REG_ID() */
52374 + /* Both rt2870ap and rt2870sta use BbpSoftReset(pAd) to do BBP soft reset */
52375 + BbpSoftReset(pAd);
52376 +/*================================================*/
52377 + {
52378 +#ifdef CONFIG_STA_SUPPORT
52379 + // Set all state machines back IDLE
52380 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
52381 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
52382 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
52383 + pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
52384 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
52385 + pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
52386 +#endif // CONFIG_STA_SUPPORT //
52387 +
52388 + //
52389 + // ===> refer to MlmeRestartStateMachine().
52390 + // When we entered ATE_START mode, PeriodicTimer was not cancelled.
52391 + // So we don't have to set it here.
52392 + //
52393 + //RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
52394 +
52395 + ASSERT(pAd->CommonCfg.Channel != 0);
52396 +
52397 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
52398 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
52399 +
52400 +
52401 +#ifdef CONFIG_STA_SUPPORT
52402 + RTMPStationStart(pAd);
52403 +#endif // CONFIG_STA_SUPPORT //
52404 + }
52405 +//
52406 +// These two steps have been done when entering ATE_STOP mode.
52407 +//
52408 + // Clean ATE Bulk in/out counter and continue setup.
52409 + InterlockedExchange(&pAd->BulkOutRemained, 0);
52410 + NdisAcquireSpinLock(&pAd->GenericLock);
52411 + pAd->ContinBulkOut = FALSE;
52412 + pAd->ContinBulkIn = FALSE;
52413 + NdisReleaseSpinLock(&pAd->GenericLock);
52414 +
52415 + /* Wait 50ms to prevent next URB to bulkout during HW reset. */
52416 + /* todo : remove this if not necessary */
52417 + NdisMSleep(50000);
52418 +
52419 + pAd->ate.Mode = ATE_STOP;
52420 +
52421 + // Enable Tx
52422 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52423 + Value |= (1 << 2);
52424 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52425 +
52426 +/*=========================================================================*/
52427 + /* restore RX_FILTR_CFG */
52428 +#ifdef CONFIG_STA_SUPPORT
52429 + /* restore RX_FILTR_CFG in order that QA maybe set it to 0x3 */
52430 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL);
52431 +#endif // CONFIG_STA_SUPPORT //
52432 +/*=========================================================================*/
52433 +
52434 + // Enable Tx, RX DMA.
52435 + RtmpDmaEnable(pAd, 1);
52436 +
52437 + // Enable Rx
52438 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52439 + Value |= (1 << 3);
52440 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52441 +
52442 + // Wait 10ms to wait all of the bulk-in URBs to complete.
52443 + /* todo : remove this if not necessary */
52444 + NdisMSleep(10000);
52445 +
52446 + // Everything is ready to start normal Tx/Rx.
52447 + RTUSBBulkReceive(pAd);
52448 + netif_start_queue(pAd->net_dev);
52449 +
52450 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATE : ATESTOP \n"));
52451 + }
52452 + else if (!strcmp(arg, "TXCARR")) // Tx Carrier
52453 + {
52454 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCARR\n"));
52455 + pAd->ate.Mode |= ATE_TXCARR;
52456 +
52457 +#ifdef RT30xx
52458 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52459 + restore_BBP[i]=0;
52460 + //Record All BBP Value
52461 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52462 + ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
52463 +#endif // RT30xx //
52464 +
52465 + // Disable Rx
52466 + // May be we need not to do this, because these have been done in ATE_START mode ???
52467 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52468 + Value &= ~(1 << 3);
52469 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52470 +
52471 + // QA has done the following steps if it is used.
52472 + if (pAd->ate.bQATxStart == FALSE)
52473 + {
52474 + // Soft reset BBP.
52475 + BbpSoftReset(pAd);
52476 +
52477 + // Carrier Test set BBP R22 bit7=1, bit6=1, bit[5~0]=0x01
52478 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52479 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
52480 + BbpData |= 0x000000C1; //set bit7=1, bit6=1, bit[5~0]=0x01
52481 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52482 +
52483 + // set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1
52484 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52485 + Value = Value | 0x00000010;
52486 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52487 + }
52488 + }
52489 + else if (!strcmp(arg, "TXCONT")) // Tx Continue
52490 + {
52491 + if (pAd->ate.bQATxStart == TRUE)
52492 + {
52493 + /* set MAC_SYS_CTRL(0x1004) bit4(Continuous Tx Production Test)
52494 + and bit2(MAC TX enable) back to zero. */
52495 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52496 + MacData &= 0xFFFFFFEB;
52497 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52498 +
52499 + // set BBP R22 bit7=0
52500 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52501 + BbpData &= 0xFFFFFF7F; //set bit7=0
52502 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52503 + }
52504 +
52505 + /* for TxCont mode.
52506 + ** Step 1: Send 50 packets first then wait for a moment.
52507 + ** Step 2: Send more 50 packet then start continue mode.
52508 + */
52509 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCONT\n"));
52510 +
52511 +#ifdef RT30xx
52512 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52513 + restore_BBP[i]=0;
52514 + //Record All BBP Value
52515 + for(i=0;i<ATE_BBP_REG_NUM;i++)
52516 + ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
52517 +#endif // RT30xx //
52518 +
52519 + // Step 1: send 50 packets first.
52520 + pAd->ate.Mode |= ATE_TXCONT;
52521 + pAd->ate.TxCount = 50;
52522 + pAd->ate.TxDoneCount = 0;
52523 +
52524 + // Soft reset BBP.
52525 + BbpSoftReset(pAd);
52526 +
52527 + // Abort Tx, RX DMA.
52528 + RtmpDmaEnable(pAd, 0);
52529 +
52530 +
52531 + /* Only needed if we have to send some normal frames. */
52532 + SetJapanFilter(pAd);
52533 +
52534 + // Setup frame format.
52535 + ATESetUpFrame(pAd, 0);
52536 +
52537 + // Enable Tx
52538 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52539 + Value |= (1 << 2);
52540 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52541 +
52542 + // Disable Rx
52543 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52544 + Value &= ~(1 << 3);
52545 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52546 +
52547 + // Start Tx, RX DMA.
52548 + RtmpDmaEnable(pAd, 1);
52549 +
52550 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
52551 +
52552 +#ifdef RALINK_28xx_QA
52553 + if (pAd->ate.bQATxStart == TRUE)
52554 + {
52555 + pAd->ate.TxStatus = 1;
52556 + //pAd->ate.Repeat = 0;
52557 + }
52558 +#endif // RALINK_28xx_QA //
52559 +
52560 + NdisAcquireSpinLock(&pAd->GenericLock);//0820
52561 + pAd->ContinBulkOut = FALSE;
52562 + NdisReleaseSpinLock(&pAd->GenericLock);
52563 +
52564 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
52565 +
52566 + // Kick bulk out
52567 + RTUSBKickBulkOut(pAd);
52568 +
52569 + /* To make sure all the 50 frames have been bulk out before executing step 2 */
52570 + while (atomic_read(&pAd->BulkOutRemained) > 0)
52571 + {
52572 + RTMPusecDelay(5000);
52573 + }
52574 +
52575 + // Step 2: send more 50 packets then start continue mode.
52576 + // Abort Tx, RX DMA.
52577 + RtmpDmaEnable(pAd, 0);
52578 +
52579 + // Cont. TX set BBP R22 bit7=1
52580 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52581 + BbpData |= 0x00000080; //set bit7=1
52582 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52583 +
52584 + pAd->ate.TxCount = 50;
52585 + pAd->ate.TxDoneCount = 0;
52586 +
52587 + SetJapanFilter(pAd);
52588 +
52589 + // Setup frame format.
52590 + ATESetUpFrame(pAd, 0);
52591 +
52592 + // Enable Tx
52593 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52594 + Value |= (1 << 2);
52595 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52596 +
52597 + // Disable Rx
52598 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52599 + Value &= ~(1 << 3);
52600 +
52601 + // Start Tx, RX DMA.
52602 + RtmpDmaEnable(pAd, 1);
52603 +
52604 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
52605 +
52606 +#ifdef RALINK_28xx_QA
52607 + if (pAd->ate.bQATxStart == TRUE)
52608 + {
52609 + pAd->ate.TxStatus = 1;
52610 + //pAd->ate.Repeat = 0;
52611 + }
52612 +#endif // RALINK_28xx_QA //
52613 +
52614 + NdisAcquireSpinLock(&pAd->GenericLock);//0820
52615 + pAd->ContinBulkOut = FALSE;
52616 + NdisReleaseSpinLock(&pAd->GenericLock);
52617 +
52618 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
52619 + // Kick bulk out
52620 + RTUSBKickBulkOut(pAd);
52621 +
52622 +#if 1
52623 + RTMPusecDelay(500);
52624 +#else
52625 + while (atomic_read(&pAd->BulkOutRemained) > 0)
52626 + {
52627 + RTMPusecDelay(5000);
52628 + }
52629 +#endif // 1 //
52630 +
52631 + // Set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1.
52632 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52633 + MacData |= 0x00000010;
52634 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52635 + }
52636 + else if (!strcmp(arg, "TXFRAME")) // Tx Frames
52637 + {
52638 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXFRAME(Count=0x%08x)\n", pAd->ate.TxCount));
52639 + pAd->ate.Mode |= ATE_TXFRAME;
52640 +
52641 + // Soft reset BBP.
52642 + BbpSoftReset(pAd);
52643 +
52644 + // Default value in BBP R22 is 0x0.
52645 + BbpData = 0;
52646 +
52647 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52648 +
52649 + // Clean bit4 to stop continuous Tx production test.
52650 + MacData &= 0xFFFFFFEF;
52651 +
52652 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52653 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52654 +
52655 +#ifdef RALINK_28xx_QA
52656 + // add this for LoopBack mode
52657 + if (pAd->ate.bQARxStart == FALSE)
52658 + {
52659 + // Disable Rx
52660 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52661 + Value &= ~(1 << 3);
52662 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52663 + }
52664 +
52665 + if (pAd->ate.bQATxStart == TRUE)
52666 + {
52667 + pAd->ate.TxStatus = 1;
52668 + //pAd->ate.Repeat = 0;
52669 + }
52670 +#else
52671 + // Disable Rx
52672 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52673 + Value &= ~(1 << 3);
52674 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52675 +#endif // RALINK_28xx_QA //
52676 +
52677 + // Enable Tx
52678 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52679 + Value |= (1 << 2);
52680 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52681 +
52682 + SetJapanFilter(pAd);
52683 +
52684 + // Abort Tx, RX DMA.
52685 + RtmpDmaEnable(pAd, 0);
52686 +
52687 + pAd->ate.TxDoneCount = 0;
52688 +
52689 + // Setup frame format
52690 + ATESetUpFrame(pAd, 0);
52691 +
52692 + // Start Tx, RX DMA.
52693 + RtmpDmaEnable(pAd, 1);
52694 +
52695 + // Check count is continuous or not yet.
52696 + //
52697 + // Due to the type mismatch between "pAd->BulkOutRemained"(atomic_t) and "pAd->ate.TxCount"(UINT32)
52698 + //
52699 + if (pAd->ate.TxCount == 0)
52700 + {
52701 + InterlockedExchange(&pAd->BulkOutRemained, 0);
52702 + }
52703 + else
52704 + {
52705 + InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
52706 + }
52707 + ATEDBGPRINT(RT_DEBUG_TRACE, ("bulk out count = %d\n", atomic_read(&pAd->BulkOutRemained)));
52708 + ASSERT((atomic_read(&pAd->BulkOutRemained) >= 0));
52709 +
52710 + if (atomic_read(&pAd->BulkOutRemained) == 0)
52711 + {
52712 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packet countinuously\n"));
52713 +
52714 + /* In 28xx, NdisAcquireSpinLock() == spin_lock_bh() */
52715 + /* NdisAcquireSpinLock only need one argument in 28xx. */
52716 + NdisAcquireSpinLock(&pAd->GenericLock);
52717 + pAd->ContinBulkOut = TRUE;
52718 + NdisReleaseSpinLock(&pAd->GenericLock);
52719 +
52720 + /* In 28xx, BULK_OUT_LOCK() == spin_lock_irqsave() */
52721 + BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
52722 + pAd->BulkOutPending[0] = FALSE;
52723 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
52724 + }
52725 + else
52726 + {
52727 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packets depend on counter\n"));
52728 +
52729 + NdisAcquireSpinLock(&pAd->GenericLock);
52730 + pAd->ContinBulkOut = FALSE;
52731 + NdisReleaseSpinLock(&pAd->GenericLock);
52732 +
52733 + BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);
52734 + pAd->BulkOutPending[0] = FALSE;
52735 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
52736 + }
52737 +
52738 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
52739 +
52740 + // Kick bulk out
52741 + RTUSBKickBulkOut(pAd);
52742 + }
52743 +#ifdef RALINK_28xx_QA
52744 + else if (!strcmp(arg, "TXSTOP")) //Enter ATE mode and set Tx/Rx Idle
52745 + {
52746 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXSTOP\n"));
52747 +
52748 + atemode = pAd->ate.Mode;
52749 + pAd->ate.Mode &= ATE_TXSTOP;
52750 + pAd->ate.bQATxStart = FALSE;
52751 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
52752 +
52753 +/*=========================================================================*/
52754 + if (atemode & ATE_TXCARR)
52755 + {
52756 + // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
52757 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52758 + BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
52759 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52760 + }
52761 + else if (atemode & ATE_TXCARRSUPP)
52762 + {
52763 + // No Cont. TX set BBP R22 bit7=0
52764 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52765 + BbpData &= ~(1 << 7); //set bit7=0
52766 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52767 +
52768 + // No Carrier Suppression set BBP R24 bit0=0
52769 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
52770 + BbpData &= 0xFFFFFFFE; //clear bit0
52771 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
52772 + }
52773 + else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
52774 + {
52775 + if (atemode & ATE_TXCONT)
52776 + {
52777 + // No Cont. TX set BBP R22 bit7=0
52778 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
52779 + BbpData &= ~(1 << 7); //set bit7=0
52780 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52781 + }
52782 + }
52783 +
52784 +/*=========================================================================*/
52785 + RTUSBRejectPendingPackets(pAd);
52786 + RTUSBCleanUpDataBulkOutQueue(pAd);
52787 +
52788 + /* not used in RT28xx */
52789 + //RTUSBCleanUpMLMEWaitQueue(pAd);
52790 + /* empty function so far */
52791 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
52792 +/*=========================================================================*/
52793 + // Abort Tx, RX DMA.
52794 + RtmpDmaEnable(pAd, 0);
52795 +/*=========================================================================*/
52796 +
52797 + /* In 28xx, pAd->PendingRx is not of type atomic_t anymore */
52798 +// while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
52799 + /* peter todo : BulkInLock */
52800 + while (pAd->PendingRx > 0)
52801 + {
52802 +#if 1
52803 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
52804 +#else
52805 +// NdisInterlockedDecrement(&pAd->PendingRx);
52806 + pAd->PendingRx--;
52807 +#endif
52808 + RTMPusecDelay(500000);
52809 + }
52810 +
52811 + while (((pAd->BulkOutPending[0] == TRUE) ||
52812 + (pAd->BulkOutPending[1] == TRUE) ||
52813 + (pAd->BulkOutPending[2] == TRUE) ||
52814 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
52815 + {
52816 + do
52817 + {
52818 + RTUSBCancelPendingBulkOutIRP(pAd);
52819 + } while (FALSE);
52820 +
52821 + RTMPusecDelay(500000);
52822 + }
52823 +
52824 + ASSERT(pAd->PendingRx == 0);
52825 +/*=========================================================================*/
52826 + // Enable Tx, Rx DMA.
52827 + RtmpDmaEnable(pAd, 1);
52828 +
52829 + /* task Tx status : 0 --> task is idle, 1 --> task is running */
52830 + pAd->ate.TxStatus = 0;
52831 +
52832 + // Soft reset BBP.
52833 + BbpSoftReset(pAd);
52834 +
52835 + // Disable Tx
52836 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52837 + MacData &= (0xfffffffb);
52838 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52839 +
52840 + //Clean ATE Bulk in/out counter and continue setup
52841 + InterlockedExchange(&pAd->BulkOutRemained, 0);
52842 +
52843 + pAd->ContinBulkOut = FALSE;
52844 + }
52845 + else if (!strcmp(arg, "RXSTOP"))
52846 + {
52847 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXSTOP\n"));
52848 + atemode = pAd->ate.Mode;
52849 +
52850 + // Disable Rx
52851 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52852 + Value &= ~(1 << 3);
52853 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52854 +
52855 + pAd->ate.Mode &= ATE_RXSTOP;
52856 + pAd->ate.bQARxStart = FALSE;
52857 +// pAd->ate.TxDoneCount = pAd->ate.TxCount;
52858 +
52859 +/*=========================================================================*/
52860 + RTUSBRejectPendingPackets(pAd);
52861 + RTUSBCleanUpDataBulkOutQueue(pAd);
52862 +
52863 + /* not used in RT28xx */
52864 + //RTUSBCleanUpMLMEWaitQueue(pAd);
52865 + RTUSBCleanUpMLMEBulkOutQueue(pAd);
52866 +/*=========================================================================*/
52867 +
52868 + // Abort Tx, RX DMA.
52869 + RtmpDmaEnable(pAd, 0);
52870 +/*=========================================================================*/
52871 +// while ((atomic_read(&pAd->PendingRx) > 0))
52872 + while (pAd->PendingRx > 0)
52873 + {
52874 +#if 1
52875 + ATE_RTUSBCancelPendingBulkInIRP(pAd);
52876 +#else
52877 +// NdisInterlockedDecrement(&pAd->PendingRx);
52878 + pAd->PendingRx--;
52879 +#endif
52880 + RTMPusecDelay(500000);
52881 + }
52882 +
52883 + while (((pAd->BulkOutPending[0] == TRUE) ||
52884 + (pAd->BulkOutPending[1] == TRUE) ||
52885 + (pAd->BulkOutPending[2] == TRUE) ||
52886 + (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
52887 + {
52888 + do
52889 + {
52890 + RTUSBCancelPendingBulkOutIRP(pAd);
52891 + } while (FALSE);
52892 +
52893 + RTMPusecDelay(500000);
52894 + }
52895 +
52896 + ASSERT(pAd->PendingRx == 0);
52897 +/*=========================================================================*/
52898 +
52899 + // Soft reset BBP.
52900 + BbpSoftReset(pAd);
52901 + pAd->ContinBulkIn = FALSE;
52902 + }
52903 +#endif // RALINK_28xx_QA //
52904 + else if (!strcmp(arg, "RXFRAME")) // Rx Frames
52905 + {
52906 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXFRAME\n"));
52907 +
52908 + // Disable Rx of MAC block
52909 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52910 + Value &= ~(1 << 3);
52911 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52912 +
52913 + // Default value in BBP R22 is 0x0.
52914 + BbpData = 0;
52915 +
52916 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
52917 + // Clean bit4 to stop continuous Tx production test.
52918 + MacData &= 0xFFFFFFEF;
52919 +
52920 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
52921 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
52922 +
52923 + pAd->ate.Mode |= ATE_RXFRAME;
52924 +
52925 + // Abort Tx, RX DMA.
52926 + RtmpDmaEnable(pAd, 0);
52927 +
52928 + // Disable TX of MAC block
52929 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52930 + Value &= ~(1 << 2);
52931 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52932 +
52933 + // Reset Rx RING.
52934 + for ( i = 0; i < (RX_RING_SIZE); i++)
52935 + {
52936 + PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
52937 +
52938 + pRxContext->InUse = FALSE;
52939 + pRxContext->IRPPending = FALSE;
52940 + pRxContext->Readable = FALSE;
52941 +
52942 + //
52943 + // Get the urb from kernel back to driver.
52944 + //
52945 + RTUSB_UNLINK_URB(pRxContext->pUrb);
52946 +
52947 + /* Sleep 200 microsecs to give cancellation time to work. */
52948 + NdisMSleep(200);
52949 + pAd->BulkInReq = 0;
52950 +
52951 +// InterlockedExchange(&pAd->PendingRx, 0);
52952 + pAd->PendingRx = 0;
52953 + pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
52954 + pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
52955 + pAd->NextRxBulkInPosition = 0;
52956 + }
52957 +
52958 + // read to clear counters
52959 + RTUSBReadMACRegister(pAd, RX_STA_CNT0, &temp); //RX PHY & RX CRC count
52960 + RTUSBReadMACRegister(pAd, RX_STA_CNT1, &temp); //RX PLCP error count & CCA false alarm count
52961 + RTUSBReadMACRegister(pAd, RX_STA_CNT2, &temp); //RX FIFO overflow frame count & RX duplicated filtered frame count
52962 +
52963 + pAd->ContinBulkIn = TRUE;
52964 +
52965 + // Enable Tx, RX DMA.
52966 + RtmpDmaEnable(pAd, 1);
52967 +
52968 + // Enable RX of MAC block
52969 + RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
52970 + Value |= (1 << 3);
52971 + RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
52972 +
52973 + // Kick bulk in
52974 + RTUSBBulkReceive(pAd);
52975 + }
52976 + else
52977 + {
52978 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: Invalid arg!\n"));
52979 + return FALSE;
52980 + }
52981 + RTMPusecDelay(5000);
52982 +
52983 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATECmdHandler()\n"));
52984 +
52985 + return TRUE;
52986 +}
52987 +#endif // RT2870 //
52988 +
52989 +INT Set_ATE_Proc(
52990 + IN PRTMP_ADAPTER pAd,
52991 + IN PUCHAR arg)
52992 +{
52993 + if (ATECmdHandler(pAd, arg))
52994 + {
52995 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Success\n"));
52996 +
52997 +
52998 + return TRUE;
52999 + }
53000 + else
53001 + {
53002 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Failed\n"));
53003 + return FALSE;
53004 + }
53005 +}
53006 +
53007 +/*
53008 + ==========================================================================
53009 + Description:
53010 + Set ATE ADDR1=DA for TxFrame(AP : To DS = 0 ; From DS = 1)
53011 + or
53012 + Set ATE ADDR3=DA for TxFrame(STA : To DS = 1 ; From DS = 0)
53013 +
53014 + Return:
53015 + TRUE if all parameters are OK, FALSE otherwise
53016 + ==========================================================================
53017 +*/
53018 +INT Set_ATE_DA_Proc(
53019 + IN PRTMP_ADAPTER pAd,
53020 + IN PUCHAR arg)
53021 +{
53022 + CHAR *value;
53023 + INT i;
53024 +
53025 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
53026 + return FALSE;
53027 +
53028 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
53029 + {
53030 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
53031 + return FALSE; //Invalid
53032 +
53033 +
53034 +#ifdef CONFIG_STA_SUPPORT
53035 + AtoH(value, &pAd->ate.Addr3[i++], 1);
53036 +#endif // CONFIG_STA_SUPPORT //
53037 + }
53038 +
53039 + if(i != 6)
53040 + return FALSE; //Invalid
53041 +
53042 +
53043 +#ifdef CONFIG_STA_SUPPORT
53044 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_DA_Proc (DA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr3[0],
53045 + pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]));
53046 +#endif // CONFIG_STA_SUPPORT //
53047 +
53048 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_DA_Proc Success\n"));
53049 +
53050 + return TRUE;
53051 +}
53052 +
53053 +/*
53054 + ==========================================================================
53055 + Description:
53056 + Set ATE ADDR3=SA for TxFrame(AP : To DS = 0 ; From DS = 1)
53057 + or
53058 + Set ATE ADDR2=SA for TxFrame(STA : To DS = 1 ; From DS = 0)
53059 +
53060 + Return:
53061 + TRUE if all parameters are OK, FALSE otherwise
53062 + ==========================================================================
53063 +*/
53064 +INT Set_ATE_SA_Proc(
53065 + IN PRTMP_ADAPTER pAd,
53066 + IN PUCHAR arg)
53067 +{
53068 + CHAR *value;
53069 + INT i;
53070 +
53071 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
53072 + return FALSE;
53073 +
53074 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
53075 + {
53076 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
53077 + return FALSE; //Invalid
53078 +
53079 +
53080 +#ifdef CONFIG_STA_SUPPORT
53081 + AtoH(value, &pAd->ate.Addr2[i++], 1);
53082 +#endif // CONFIG_STA_SUPPORT //
53083 + }
53084 +
53085 + if(i != 6)
53086 + return FALSE; //Invalid
53087 +
53088 +
53089 +#ifdef CONFIG_STA_SUPPORT
53090 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_SA_Proc (SA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr2[0],
53091 + pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]));
53092 +#endif // CONFIG_STA_SUPPORT //
53093 +
53094 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_SA_Proc Success\n"));
53095 +
53096 + return TRUE;
53097 +}
53098 +
53099 +/*
53100 + ==========================================================================
53101 + Description:
53102 + Set ATE ADDR2=BSSID for TxFrame(AP : To DS = 0 ; From DS = 1)
53103 + or
53104 + Set ATE ADDR1=BSSID for TxFrame(STA : To DS = 1 ; From DS = 0)
53105 +
53106 + Return:
53107 + TRUE if all parameters are OK, FALSE otherwise
53108 + ==========================================================================
53109 +*/
53110 +INT Set_ATE_BSSID_Proc(
53111 + IN PRTMP_ADAPTER pAd,
53112 + IN PUCHAR arg)
53113 +{
53114 + CHAR *value;
53115 + INT i;
53116 +
53117 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
53118 + return FALSE;
53119 +
53120 + for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
53121 + {
53122 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
53123 + return FALSE; //Invalid
53124 +
53125 +
53126 +#ifdef CONFIG_STA_SUPPORT
53127 + AtoH(value, &pAd->ate.Addr1[i++], 1);
53128 +#endif // CONFIG_STA_SUPPORT //
53129 + }
53130 +
53131 + if(i != 6)
53132 + return FALSE; //Invalid
53133 +
53134 +
53135 +#ifdef CONFIG_STA_SUPPORT
53136 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_BSSID_Proc (BSSID = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr1[0],
53137 + pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]));
53138 +#endif // CONFIG_STA_SUPPORT //
53139 +
53140 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_BSSID_Proc Success\n"));
53141 +
53142 + return TRUE;
53143 +}
53144 +
53145 +/*
53146 + ==========================================================================
53147 + Description:
53148 + Set ATE Tx Channel
53149 +
53150 + Return:
53151 + TRUE if all parameters are OK, FALSE otherwise
53152 + ==========================================================================
53153 +*/
53154 +INT Set_ATE_CHANNEL_Proc(
53155 + IN PRTMP_ADAPTER pAd,
53156 + IN PUCHAR arg)
53157 +{
53158 + UCHAR channel;
53159 +
53160 + channel = simple_strtol(arg, 0, 10);
53161 +
53162 + if ((channel < 1) || (channel > 216))// to allow A band channel : ((channel < 1) || (channel > 14))
53163 + {
53164 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_CHANNEL_Proc::Out of range, it should be in range of 1~14.\n"));
53165 + return FALSE;
53166 + }
53167 + pAd->ate.Channel = channel;
53168 +
53169 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAd->ate.Channel));
53170 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_CHANNEL_Proc Success\n"));
53171 +
53172 +
53173 + return TRUE;
53174 +}
53175 +
53176 +/*
53177 + ==========================================================================
53178 + Description:
53179 + Set ATE Tx Power0
53180 +
53181 + Return:
53182 + TRUE if all parameters are OK, FALSE otherwise
53183 + ==========================================================================
53184 +*/
53185 +INT Set_ATE_TX_POWER0_Proc(
53186 + IN PRTMP_ADAPTER pAd,
53187 + IN PUCHAR arg)
53188 +{
53189 + CHAR TxPower;
53190 +
53191 + TxPower = simple_strtol(arg, 0, 10);
53192 +
53193 + if (pAd->ate.Channel <= 14)
53194 + {
53195 + if ((TxPower > 31) || (TxPower < 0))
53196 + {
53197 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
53198 + return FALSE;
53199 + }
53200 + }
53201 + else// 5.5GHz
53202 + {
53203 + if ((TxPower > 15) || (TxPower < -7))
53204 + {
53205 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
53206 + return FALSE;
53207 + }
53208 + }
53209 +
53210 + pAd->ate.TxPower0 = TxPower;
53211 + ATETxPwrHandler(pAd, 0);
53212 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER0_Proc Success\n"));
53213 +
53214 +
53215 + return TRUE;
53216 +}
53217 +
53218 +/*
53219 + ==========================================================================
53220 + Description:
53221 + Set ATE Tx Power1
53222 +
53223 + Return:
53224 + TRUE if all parameters are OK, FALSE otherwise
53225 + ==========================================================================
53226 +*/
53227 +INT Set_ATE_TX_POWER1_Proc(
53228 + IN PRTMP_ADAPTER pAd,
53229 + IN PUCHAR arg)
53230 +{
53231 + CHAR TxPower;
53232 +
53233 + TxPower = simple_strtol(arg, 0, 10);
53234 +
53235 + if (pAd->ate.Channel <= 14)
53236 + {
53237 + if ((TxPower > 31) || (TxPower < 0))
53238 + {
53239 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
53240 + return FALSE;
53241 + }
53242 + }
53243 + else
53244 + {
53245 + if ((TxPower > 15) || (TxPower < -7))
53246 + {
53247 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
53248 + return FALSE;
53249 + }
53250 + }
53251 +
53252 + pAd->ate.TxPower1 = TxPower;
53253 + ATETxPwrHandler(pAd, 1);
53254 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER1_Proc Success\n"));
53255 +
53256 +
53257 + return TRUE;
53258 +}
53259 +
53260 +/*
53261 + ==========================================================================
53262 + Description:
53263 + Set ATE Tx Antenna
53264 +
53265 + Return:
53266 + TRUE if all parameters are OK, FALSE otherwise
53267 + ==========================================================================
53268 +*/
53269 +INT Set_ATE_TX_Antenna_Proc(
53270 + IN PRTMP_ADAPTER pAd,
53271 + IN PUCHAR arg)
53272 +{
53273 + CHAR value;
53274 +
53275 + value = simple_strtol(arg, 0, 10);
53276 +
53277 + if ((value > 2) || (value < 0))
53278 + {
53279 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_Antenna_Proc::Out of range (Value=%d)\n", value));
53280 + return FALSE;
53281 + }
53282 +
53283 + pAd->ate.TxAntennaSel = value;
53284 +
53285 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_Antenna_Proc (Antenna = %d)\n", pAd->ate.TxAntennaSel));
53286 + ATEDBGPRINT(RT_DEBUG_TRACE,("Ralink: Set_ATE_TX_Antenna_Proc Success\n"));
53287 +
53288 +
53289 + return TRUE;
53290 +}
53291 +
53292 +/*
53293 + ==========================================================================
53294 + Description:
53295 + Set ATE Rx Antenna
53296 +
53297 + Return:
53298 + TRUE if all parameters are OK, FALSE otherwise
53299 + ==========================================================================
53300 +*/
53301 +INT Set_ATE_RX_Antenna_Proc(
53302 + IN PRTMP_ADAPTER pAd,
53303 + IN PUCHAR arg)
53304 +{
53305 + CHAR value;
53306 +
53307 + value = simple_strtol(arg, 0, 10);
53308 +
53309 + if ((value > 3) || (value < 0))
53310 + {
53311 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_RX_Antenna_Proc::Out of range (Value=%d)\n", value));
53312 + return FALSE;
53313 + }
53314 +
53315 + pAd->ate.RxAntennaSel = value;
53316 +
53317 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_Antenna_Proc (Antenna = %d)\n", pAd->ate.RxAntennaSel));
53318 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_Antenna_Proc Success\n"));
53319 +
53320 +
53321 + return TRUE;
53322 +}
53323 +
53324 +/*
53325 + ==========================================================================
53326 + Description:
53327 + Set ATE RF frequence offset
53328 +
53329 + Return:
53330 + TRUE if all parameters are OK, FALSE otherwise
53331 + ==========================================================================
53332 +*/
53333 +INT Set_ATE_TX_FREQOFFSET_Proc(
53334 + IN PRTMP_ADAPTER pAd,
53335 + IN PUCHAR arg)
53336 +{
53337 + UCHAR RFFreqOffset;
53338 + ULONG R4;
53339 +
53340 + RFFreqOffset = simple_strtol(arg, 0, 10);
53341 +#ifndef RT30xx
53342 + if(RFFreqOffset >= 64)
53343 +#endif // RT30xx //
53344 +#ifdef RT30xx
53345 +//2008/08/06: KH modified the limit of offset value from 65 to 95(0x5F)
53346 + if(RFFreqOffset >= 95)
53347 +#endif // RT30xx //
53348 + {
53349 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_FREQOFFSET_Proc::Out of range, it should be in range of 0~63.\n"));
53350 + return FALSE;
53351 + }
53352 +
53353 + pAd->ate.RFFreqOffset = RFFreqOffset;
53354 +#ifdef RT30xx
53355 + if(IS_RT30xx(pAd))
53356 + {
53357 + // Set RF offset
53358 + UCHAR RFValue;
53359 + RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
53360 + //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
53361 + RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
53362 + RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
53363 + }
53364 + else
53365 +#endif // RT30xx //
53366 + {
53367 +
53368 + R4 = pAd->ate.RFFreqOffset << 15; // shift TX power control to correct RF register bit position
53369 + R4 |= (pAd->LatchRfRegs.R4 & ((~0x001f8000)));
53370 + pAd->LatchRfRegs.R4 = R4;
53371 +
53372 + RtmpRfIoWrite(pAd);
53373 + }
53374 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_FREQOFFSET_Proc (RFFreqOffset = %d)\n", pAd->ate.RFFreqOffset));
53375 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_FREQOFFSET_Proc Success\n"));
53376 +
53377 +
53378 + return TRUE;
53379 +}
53380 +
53381 +/*
53382 + ==========================================================================
53383 + Description:
53384 + Set ATE RF BW
53385 +
53386 + Return:
53387 + TRUE if all parameters are OK, FALSE otherwise
53388 + ==========================================================================
53389 +*/
53390 +INT Set_ATE_TX_BW_Proc(
53391 + IN PRTMP_ADAPTER pAd,
53392 + IN PUCHAR arg)
53393 +{
53394 + int i;
53395 + UCHAR value = 0;
53396 + UCHAR BBPCurrentBW;
53397 +
53398 + BBPCurrentBW = simple_strtol(arg, 0, 10);
53399 +
53400 + if(BBPCurrentBW == 0)
53401 + pAd->ate.TxWI.BW = BW_20;
53402 + else
53403 + pAd->ate.TxWI.BW = BW_40;
53404 +
53405 + if(pAd->ate.TxWI.BW == BW_20)
53406 + {
53407 + if(pAd->ate.Channel <= 14)
53408 + {
53409 + for (i=0; i<5; i++)
53410 + {
53411 + if (pAd->Tx20MPwrCfgGBand[i] != 0xffffffff)
53412 + {
53413 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgGBand[i]);
53414 + RTMPusecDelay(5000);
53415 + }
53416 + }
53417 + }
53418 + else
53419 + {
53420 + for (i=0; i<5; i++)
53421 + {
53422 + if (pAd->Tx20MPwrCfgABand[i] != 0xffffffff)
53423 + {
53424 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgABand[i]);
53425 + RTMPusecDelay(5000);
53426 + }
53427 + }
53428 + }
53429 +
53430 + //Set BBP R4 bit[4:3]=0:0
53431 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
53432 + value &= (~0x18);
53433 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
53434 +
53435 + //Set BBP R66=0x3C
53436 + value = 0x3C;
53437 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
53438 + //Set BBP R68=0x0B
53439 + //to improve Rx sensitivity.
53440 + value = 0x0B;
53441 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
53442 + //Set BBP R69=0x16
53443 + value = 0x16;
53444 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
53445 + //Set BBP R70=0x08
53446 + value = 0x08;
53447 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
53448 + //Set BBP R73=0x11
53449 + value = 0x11;
53450 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
53451 +
53452 + // If Channel=14, Bandwidth=20M and Mode=CCK, Set BBP R4 bit5=1
53453 + // (Japan filter coefficients)
53454 + // This segment of code will only works when ATETXMODE and ATECHANNEL
53455 + // were set to MODE_CCK and 14 respectively before ATETXBW is set to 0.
53456 + //=====================================================================
53457 + if (pAd->ate.Channel == 14)
53458 + {
53459 + int TxMode = pAd->ate.TxWI.PHYMODE;
53460 + if (TxMode == MODE_CCK)
53461 + {
53462 + // when Channel==14 && Mode==CCK && BandWidth==20M, BBP R4 bit5=1
53463 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
53464 + value |= 0x20; //set bit5=1
53465 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
53466 + }
53467 + }
53468 +
53469 + //=====================================================================
53470 + // If bandwidth != 40M, RF Reg4 bit 21 = 0.
53471 +#ifdef RT30xx
53472 + // Set BW
53473 + if(IS_RT30xx(pAd))
53474 + RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW20RfR24);
53475 + else
53476 +#endif // RT30xx //
53477 + {
53478 + pAd->LatchRfRegs.R4 &= ~0x00200000;
53479 + RtmpRfIoWrite(pAd);
53480 + }
53481 +
53482 + }
53483 + else if(pAd->ate.TxWI.BW == BW_40)
53484 + {
53485 + if(pAd->ate.Channel <= 14)
53486 + {
53487 + for (i=0; i<5; i++)
53488 + {
53489 + if (pAd->Tx40MPwrCfgGBand[i] != 0xffffffff)
53490 + {
53491 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgGBand[i]);
53492 + RTMPusecDelay(5000);
53493 + }
53494 + }
53495 + }
53496 + else
53497 + {
53498 + for (i=0; i<5; i++)
53499 + {
53500 + if (pAd->Tx40MPwrCfgABand[i] != 0xffffffff)
53501 + {
53502 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgABand[i]);
53503 + RTMPusecDelay(5000);
53504 + }
53505 + }
53506 +#ifdef DOT11_N_SUPPORT
53507 + if ((pAd->ate.TxWI.PHYMODE >= MODE_HTMIX) && (pAd->ate.TxWI.MCS == 7))
53508 + {
53509 + value = 0x28;
53510 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R67, value);
53511 + }
53512 +#endif // DOT11_N_SUPPORT //
53513 + }
53514 +
53515 + //Set BBP R4 bit[4:3]=1:0
53516 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
53517 + value &= (~0x18);
53518 + value |= 0x10;
53519 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
53520 +
53521 + //Set BBP R66=0x3C
53522 + value = 0x3C;
53523 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
53524 + //Set BBP R68=0x0C
53525 + //to improve Rx sensitivity.
53526 + value = 0x0C;
53527 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
53528 + //Set BBP R69=0x1A
53529 + value = 0x1A;
53530 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
53531 + //Set BBP R70=0x0A
53532 + value = 0x0A;
53533 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
53534 + //Set BBP R73=0x16
53535 + value = 0x16;
53536 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
53537 +
53538 + // If bandwidth = 40M, set RF Reg4 bit 21 = 1.
53539 +#ifdef RT30xx
53540 + // Set BW
53541 + if(IS_RT30xx(pAd))
53542 + RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW40RfR24);
53543 + else
53544 +#endif // RT30xx //
53545 + {
53546 + pAd->LatchRfRegs.R4 |= 0x00200000;
53547 + RtmpRfIoWrite(pAd);
53548 + }
53549 + }
53550 +
53551 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_BW_Proc (BBPCurrentBW = %d)\n", pAd->ate.TxWI.BW));
53552 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_BW_Proc Success\n"));
53553 +
53554 +
53555 + return TRUE;
53556 +}
53557 +
53558 +/*
53559 + ==========================================================================
53560 + Description:
53561 + Set ATE Tx frame length
53562 +
53563 + Return:
53564 + TRUE if all parameters are OK, FALSE otherwise
53565 + ==========================================================================
53566 +*/
53567 +INT Set_ATE_TX_LENGTH_Proc(
53568 + IN PRTMP_ADAPTER pAd,
53569 + IN PUCHAR arg)
53570 +{
53571 + pAd->ate.TxLength = simple_strtol(arg, 0, 10);
53572 +
53573 + if((pAd->ate.TxLength < 24) || (pAd->ate.TxLength > (MAX_FRAME_SIZE - 34/* == 2312 */)))
53574 + {
53575 + pAd->ate.TxLength = (MAX_FRAME_SIZE - 34/* == 2312 */);
53576 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_LENGTH_Proc::Out of range, it should be in range of 24~%d.\n", (MAX_FRAME_SIZE - 34/* == 2312 */)));
53577 + return FALSE;
53578 + }
53579 +
53580 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_LENGTH_Proc (TxLength = %d)\n", pAd->ate.TxLength));
53581 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_LENGTH_Proc Success\n"));
53582 +
53583 +
53584 + return TRUE;
53585 +}
53586 +
53587 +/*
53588 + ==========================================================================
53589 + Description:
53590 + Set ATE Tx frame count
53591 +
53592 + Return:
53593 + TRUE if all parameters are OK, FALSE otherwise
53594 + ==========================================================================
53595 +*/
53596 +INT Set_ATE_TX_COUNT_Proc(
53597 + IN PRTMP_ADAPTER pAd,
53598 + IN PUCHAR arg)
53599 +{
53600 + pAd->ate.TxCount = simple_strtol(arg, 0, 10);
53601 +
53602 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAd->ate.TxCount));
53603 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
53604 +
53605 +
53606 + return TRUE;
53607 +}
53608 +
53609 +/*
53610 + ==========================================================================
53611 + Description:
53612 + Set ATE Tx frame MCS
53613 +
53614 + Return:
53615 + TRUE if all parameters are OK, FALSE otherwise
53616 + ==========================================================================
53617 +*/
53618 +INT Set_ATE_TX_MCS_Proc(
53619 + IN PRTMP_ADAPTER pAd,
53620 + IN PUCHAR arg)
53621 +{
53622 + UCHAR MCS;
53623 + int result;
53624 +
53625 + MCS = simple_strtol(arg, 0, 10);
53626 + result = CheckMCSValid(pAd->ate.TxWI.PHYMODE, MCS);
53627 +
53628 + if (result != -1)
53629 + {
53630 + pAd->ate.TxWI.MCS = (UCHAR)MCS;
53631 + }
53632 + else
53633 + {
53634 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MCS_Proc::Out of range, refer to rate table.\n"));
53635 + return FALSE;
53636 + }
53637 +
53638 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MCS_Proc (MCS = %d)\n", pAd->ate.TxWI.MCS));
53639 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MCS_Proc Success\n"));
53640 +
53641 +
53642 + return TRUE;
53643 +}
53644 +
53645 +/*
53646 + ==========================================================================
53647 + Description:
53648 + Set ATE Tx frame Mode
53649 + 0: MODE_CCK
53650 + 1: MODE_OFDM
53651 + 2: MODE_HTMIX
53652 + 3: MODE_HTGREENFIELD
53653 +
53654 + Return:
53655 + TRUE if all parameters are OK, FALSE otherwise
53656 + ==========================================================================
53657 +*/
53658 +INT Set_ATE_TX_MODE_Proc(
53659 + IN PRTMP_ADAPTER pAd,
53660 + IN PUCHAR arg)
53661 +{
53662 + pAd->ate.TxWI.PHYMODE = simple_strtol(arg, 0, 10);
53663 +
53664 + if(pAd->ate.TxWI.PHYMODE > 3)
53665 + {
53666 + pAd->ate.TxWI.PHYMODE = 0;
53667 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MODE_Proc::Out of range. it should be in range of 0~3\n"));
53668 + ATEDBGPRINT(RT_DEBUG_ERROR, ("0: CCK, 1: OFDM, 2: HT_MIX, 3: HT_GREEN_FIELD.\n"));
53669 + return FALSE;
53670 + }
53671 +
53672 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MODE_Proc (TxMode = %d)\n", pAd->ate.TxWI.PHYMODE));
53673 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MODE_Proc Success\n"));
53674 +
53675 +
53676 + return TRUE;
53677 +}
53678 +
53679 +/*
53680 + ==========================================================================
53681 + Description:
53682 + Set ATE Tx frame GI
53683 +
53684 + Return:
53685 + TRUE if all parameters are OK, FALSE otherwise
53686 + ==========================================================================
53687 +*/
53688 +INT Set_ATE_TX_GI_Proc(
53689 + IN PRTMP_ADAPTER pAd,
53690 + IN PUCHAR arg)
53691 +{
53692 + pAd->ate.TxWI.ShortGI = simple_strtol(arg, 0, 10);
53693 +
53694 + if(pAd->ate.TxWI.ShortGI > 1)
53695 + {
53696 + pAd->ate.TxWI.ShortGI = 0;
53697 + ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_GI_Proc::Out of range\n"));
53698 + return FALSE;
53699 + }
53700 +
53701 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_GI_Proc (GI = %d)\n", pAd->ate.TxWI.ShortGI));
53702 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_GI_Proc Success\n"));
53703 +
53704 +
53705 + return TRUE;
53706 +}
53707 +
53708 +/*
53709 + ==========================================================================
53710 + Description:
53711 + ==========================================================================
53712 + */
53713 +INT Set_ATE_RX_FER_Proc(
53714 + IN PRTMP_ADAPTER pAd,
53715 + IN PUCHAR arg)
53716 +{
53717 + pAd->ate.bRxFer = simple_strtol(arg, 0, 10);
53718 +
53719 + if (pAd->ate.bRxFer == 1)
53720 + {
53721 + pAd->ate.RxCntPerSec = 0;
53722 + pAd->ate.RxTotalCnt = 0;
53723 + }
53724 +
53725 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_FER_Proc (bRxFer = %d)\n", pAd->ate.bRxFer));
53726 + ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_FER_Proc Success\n"));
53727 +
53728 +
53729 + return TRUE;
53730 +}
53731 +
53732 +INT Set_ATE_Read_RF_Proc(
53733 + IN PRTMP_ADAPTER pAd,
53734 + IN PUCHAR arg)
53735 +{
53736 +#ifdef RT30xx
53737 +//2008/07/10:KH add to support RT30xx ATE<--
53738 + if(IS_RT30xx(pAd))
53739 + {
53740 + /* modify by WY for Read RF Reg. error */
53741 + UCHAR RFValue;
53742 + INT index=0;
53743 + for (index = 0; index < 32; index++)
53744 + {
53745 + RT30xxReadRFRegister(pAd, index, (PUCHAR)&RFValue);
53746 + printk("R%d=%d\n",index,RFValue);
53747 + }
53748 + }
53749 + else
53750 +//2008/07/10:KH add to support RT30xx ATE-->
53751 +#endif // RT30xx //
53752 + {
53753 + ate_print(KERN_EMERG "R1 = %lx\n", pAd->LatchRfRegs.R1);
53754 + ate_print(KERN_EMERG "R2 = %lx\n", pAd->LatchRfRegs.R2);
53755 + ate_print(KERN_EMERG "R3 = %lx\n", pAd->LatchRfRegs.R3);
53756 + ate_print(KERN_EMERG "R4 = %lx\n", pAd->LatchRfRegs.R4);
53757 + }
53758 + return TRUE;
53759 +}
53760 +
53761 +INT Set_ATE_Write_RF1_Proc(
53762 + IN PRTMP_ADAPTER pAd,
53763 + IN PUCHAR arg)
53764 +{
53765 +#ifdef RT30xx
53766 +//2008/07/10:KH add to support 3070 ATE<--
53767 + if(IS_RT30xx(pAd))
53768 + {
53769 + printk("Warning!! RT30xx Don't Support\n");
53770 + return FALSE;
53771 +
53772 + }
53773 + else
53774 +//2008/07/10:KH add to support 3070 ATE-->
53775 +#endif // RT30xx //
53776 + {
53777 + UINT32 value = simple_strtol(arg, 0, 16);
53778 +
53779 + pAd->LatchRfRegs.R1 = value;
53780 + RtmpRfIoWrite(pAd);
53781 + }
53782 + return TRUE;
53783 +
53784 +}
53785 +
53786 +INT Set_ATE_Write_RF2_Proc(
53787 + IN PRTMP_ADAPTER pAd,
53788 + IN PUCHAR arg)
53789 +{
53790 +#ifdef RT30xx
53791 +//2008/07/10:KH add to support 3070 ATE<--
53792 + if(IS_RT30xx(pAd))
53793 + {
53794 + printk("Warning!! RT30xx Don't Support\n");
53795 + return FALSE;
53796 +
53797 + }
53798 + else
53799 +//2008/07/10:KH add to support 3070 ATE-->
53800 +#endif // RT30xx //
53801 + {
53802 + UINT32 value = simple_strtol(arg, 0, 16);
53803 +
53804 + pAd->LatchRfRegs.R2 = value;
53805 + RtmpRfIoWrite(pAd);
53806 + }
53807 + return TRUE;
53808 +}
53809 +
53810 +INT Set_ATE_Write_RF3_Proc(
53811 + IN PRTMP_ADAPTER pAd,
53812 + IN PUCHAR arg)
53813 +{
53814 +#ifdef RT30xx
53815 +//2008/07/10:KH add to support 3070 ATE<--
53816 + if(IS_RT30xx(pAd))
53817 + {
53818 + printk("Warning!! RT30xx Don't Support\n");
53819 + return FALSE;
53820 +
53821 + }
53822 + else
53823 +//2008/07/10:KH add to support 3070 ATE-->
53824 +#endif // RT30xx //
53825 + {
53826 + UINT32 value = simple_strtol(arg, 0, 16);
53827 +
53828 + pAd->LatchRfRegs.R3 = value;
53829 + RtmpRfIoWrite(pAd);
53830 + }
53831 + return TRUE;
53832 +}
53833 +
53834 +INT Set_ATE_Write_RF4_Proc(
53835 + IN PRTMP_ADAPTER pAd,
53836 + IN PUCHAR arg)
53837 +{
53838 +#ifdef RT30xx
53839 +//2008/07/10:KH add to support 3070 ATE<--
53840 + if(IS_RT30xx(pAd))
53841 + {
53842 + printk("Warning!! RT30xx Don't Support\n");
53843 + return FALSE;
53844 +
53845 + }
53846 + else
53847 +//2008/07/10:KH add to support 3070 ATE-->
53848 +#endif // RT30xx //
53849 + {
53850 + UINT32 value = simple_strtol(arg, 0, 16);
53851 +
53852 + pAd->LatchRfRegs.R4 = value;
53853 + RtmpRfIoWrite(pAd);
53854 + }
53855 + return TRUE;
53856 +}
53857 +#ifdef RT30xx
53858 +//2008/07/10:KH add to support 3070 ATE<--
53859 +INT SET_ATE_3070RF_Proc(
53860 + IN PRTMP_ADAPTER pAd,
53861 + IN PUCHAR arg)
53862 +{
53863 + CHAR *this_char;
53864 + CHAR *value;
53865 + UINT32 Reg,RFValue;
53866 + if(IS_RT30xx(pAd))
53867 + {
53868 + printk("SET_ATE_3070RF_Proc=%s\n",arg);
53869 + this_char =arg;
53870 + if ((value = strchr(this_char, ':')) != NULL)
53871 + *value++ = 0;
53872 + Reg= simple_strtol(this_char, 0, 16);
53873 + RFValue= simple_strtol(value, 0, 16);
53874 + printk("RF Reg[%d]=%d\n",Reg,RFValue);
53875 + RT30xxWriteRFRegister(pAd, Reg,RFValue);
53876 + }
53877 + else
53878 + printk("Warning!! Only 3070 Support\n");
53879 + return TRUE;
53880 +}
53881 +//2008/07/10:KH add to support 3070 ATE-->
53882 +#endif // RT30xx //
53883 +/*
53884 + ==========================================================================
53885 + Description:
53886 + Load and Write EEPROM from a binary file prepared in advance.
53887 +
53888 + Return:
53889 + TRUE if all parameters are OK, FALSE otherwise
53890 + ==========================================================================
53891 +*/
53892 +#ifndef UCOS
53893 +INT Set_ATE_Load_E2P_Proc(
53894 + IN PRTMP_ADAPTER pAd,
53895 + IN PUCHAR arg)
53896 +{
53897 + BOOLEAN ret = FALSE;
53898 + PUCHAR src = EEPROM_BIN_FILE_NAME;
53899 + struct file *srcf;
53900 + INT32 retval, orgfsuid, orgfsgid;
53901 + mm_segment_t orgfs;
53902 + USHORT WriteEEPROM[(EEPROM_SIZE/2)];
53903 + UINT32 FileLength = 0;
53904 + UINT32 value = simple_strtol(arg, 0, 10);
53905 +
53906 + ATEDBGPRINT(RT_DEBUG_ERROR, ("===> %s (value=%d)\n\n", __FUNCTION__, value));
53907 +
53908 + if (value > 0)
53909 + {
53910 + /* zero the e2p buffer */
53911 + NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
53912 +
53913 + /* save uid and gid used for filesystem access.
53914 + ** set user and group to 0 (root)
53915 + */
53916 + orgfsuid = current->fsuid;
53917 + orgfsgid = current->fsgid;
53918 + /* as root */
53919 + current->fsuid = current->fsgid = 0;
53920 + orgfs = get_fs();
53921 + set_fs(KERNEL_DS);
53922 +
53923 + do
53924 + {
53925 + /* open the bin file */
53926 + srcf = filp_open(src, O_RDONLY, 0);
53927 +
53928 + if (IS_ERR(srcf))
53929 + {
53930 + ate_print("%s - Error %ld opening %s\n", __FUNCTION__, -PTR_ERR(srcf), src);
53931 + break;
53932 + }
53933 +
53934 + /* the object must have a read method */
53935 + if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
53936 + {
53937 + ate_print("%s - %s does not have a read method\n", __FUNCTION__, src);
53938 + break;
53939 + }
53940 +
53941 + /* read the firmware from the file *.bin */
53942 + FileLength = srcf->f_op->read(srcf,
53943 + (PUCHAR)WriteEEPROM,
53944 + EEPROM_SIZE,
53945 + &srcf->f_pos);
53946 +
53947 + if (FileLength != EEPROM_SIZE)
53948 + {
53949 + ate_print("%s: error file length (=%d) in e2p.bin\n",
53950 + __FUNCTION__, FileLength);
53951 + break;
53952 + }
53953 + else
53954 + {
53955 + /* write the content of .bin file to EEPROM */
53956 + rt_ee_write_all(pAd, WriteEEPROM);
53957 + ret = TRUE;
53958 + }
53959 + break;
53960 + } while(TRUE);
53961 +
53962 + /* close firmware file */
53963 + if (IS_ERR(srcf))
53964 + {
53965 + ;
53966 + }
53967 + else
53968 + {
53969 + retval = filp_close(srcf, NULL);
53970 + if (retval)
53971 + {
53972 + ATEDBGPRINT(RT_DEBUG_ERROR, ("--> Error %d closing %s\n", -retval, src));
53973 +
53974 + }
53975 + }
53976 +
53977 + /* restore */
53978 + set_fs(orgfs);
53979 + current->fsuid = orgfsuid;
53980 + current->fsgid = orgfsgid;
53981 + }
53982 + ATEDBGPRINT(RT_DEBUG_ERROR, ("<=== %s (ret=%d)\n", __FUNCTION__, ret));
53983 +
53984 + return ret;
53985 +
53986 +}
53987 +#else
53988 +INT Set_ATE_Load_E2P_Proc(
53989 + IN PRTMP_ADAPTER pAd,
53990 + IN PUCHAR arg)
53991 +{
53992 + USHORT WriteEEPROM[(EEPROM_SIZE/2)];
53993 + struct iwreq *wrq = (struct iwreq *)arg;
53994 +
53995 + ATEDBGPRINT(RT_DEBUG_TRACE, ("===> %s (wrq->u.data.length = %d)\n\n", __FUNCTION__, wrq->u.data.length));
53996 +
53997 + if (wrq->u.data.length != EEPROM_SIZE)
53998 + {
53999 + ate_print("%s: error length (=%d) from host\n",
54000 + __FUNCTION__, wrq->u.data.length);
54001 + return FALSE;
54002 + }
54003 + else/* (wrq->u.data.length == EEPROM_SIZE) */
54004 + {
54005 + /* zero the e2p buffer */
54006 + NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
54007 +
54008 + /* fill the local buffer */
54009 + NdisMoveMemory((PUCHAR)WriteEEPROM, wrq->u.data.pointer, wrq->u.data.length);
54010 +
54011 + do
54012 + {
54013 + /* write the content of .bin file to EEPROM */
54014 + rt_ee_write_all(pAd, WriteEEPROM);
54015 +
54016 + } while(FALSE);
54017 + }
54018 +
54019 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== %s\n", __FUNCTION__));
54020 +
54021 + return TRUE;
54022 +
54023 +}
54024 +#endif // !UCOS //
54025 +
54026 +INT Set_ATE_Read_E2P_Proc(
54027 + IN PRTMP_ADAPTER pAd,
54028 + IN PUCHAR arg)
54029 +{
54030 + USHORT buffer[EEPROM_SIZE/2];
54031 + USHORT *p;
54032 + int i;
54033 +
54034 + rt_ee_read_all(pAd, (USHORT *)buffer);
54035 + p = buffer;
54036 + for (i = 0; i < (EEPROM_SIZE/2); i++)
54037 + {
54038 + ate_print("%4.4x ", *p);
54039 + if (((i+1) % 16) == 0)
54040 + ate_print("\n");
54041 + p++;
54042 + }
54043 + return TRUE;
54044 +}
54045 +
54046 +INT Set_ATE_Show_Proc(
54047 + IN PRTMP_ADAPTER pAd,
54048 + IN PUCHAR arg)
54049 +{
54050 + ate_print("Mode=%d\n", pAd->ate.Mode);
54051 + ate_print("TxPower0=%d\n", pAd->ate.TxPower0);
54052 + ate_print("TxPower1=%d\n", pAd->ate.TxPower1);
54053 + ate_print("TxAntennaSel=%d\n", pAd->ate.TxAntennaSel);
54054 + ate_print("RxAntennaSel=%d\n", pAd->ate.RxAntennaSel);
54055 + ate_print("BBPCurrentBW=%d\n", pAd->ate.TxWI.BW);
54056 + ate_print("GI=%d\n", pAd->ate.TxWI.ShortGI);
54057 + ate_print("MCS=%d\n", pAd->ate.TxWI.MCS);
54058 + ate_print("TxMode=%d\n", pAd->ate.TxWI.PHYMODE);
54059 + ate_print("Addr1=%02x:%02x:%02x:%02x:%02x:%02x\n",
54060 + pAd->ate.Addr1[0], pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]);
54061 + ate_print("Addr2=%02x:%02x:%02x:%02x:%02x:%02x\n",
54062 + pAd->ate.Addr2[0], pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]);
54063 + ate_print("Addr3=%02x:%02x:%02x:%02x:%02x:%02x\n",
54064 + pAd->ate.Addr3[0], pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]);
54065 + ate_print("Channel=%d\n", pAd->ate.Channel);
54066 + ate_print("TxLength=%d\n", pAd->ate.TxLength);
54067 + ate_print("TxCount=%u\n", pAd->ate.TxCount);
54068 + ate_print("RFFreqOffset=%d\n", pAd->ate.RFFreqOffset);
54069 + ate_print(KERN_EMERG "Set_ATE_Show_Proc Success\n");
54070 + return TRUE;
54071 +}
54072 +
54073 +INT Set_ATE_Help_Proc(
54074 + IN PRTMP_ADAPTER pAd,
54075 + IN PUCHAR arg)
54076 +{
54077 + ate_print("ATE=ATESTART, ATESTOP, TXCONT, TXCARR, TXFRAME, RXFRAME\n");
54078 + ate_print("ATEDA\n");
54079 + ate_print("ATESA\n");
54080 + ate_print("ATEBSSID\n");
54081 + ate_print("ATECHANNEL, range:0~14(unless A band !)\n");
54082 + ate_print("ATETXPOW0, set power level of antenna 1.\n");
54083 + ate_print("ATETXPOW1, set power level of antenna 2.\n");
54084 + ate_print("ATETXANT, set TX antenna. 0:all, 1:antenna one, 2:antenna two.\n");
54085 + ate_print("ATERXANT, set RX antenna.0:all, 1:antenna one, 2:antenna two, 3:antenna three.\n");
54086 + ate_print("ATETXFREQOFFSET, set frequency offset, range 0~63\n");
54087 + ate_print("ATETXBW, set BandWidth, 0:20MHz, 1:40MHz.\n");
54088 + ate_print("ATETXLEN, set Frame length, range 24~%d\n", (MAX_FRAME_SIZE - 34/* == 2312 */));
54089 + ate_print("ATETXCNT, set how many frame going to transmit.\n");
54090 + ate_print("ATETXMCS, set MCS, reference to rate table.\n");
54091 + ate_print("ATETXMODE, set Mode 0:CCK, 1:OFDM, 2:HT-Mix, 3:GreenField, reference to rate table.\n");
54092 + ate_print("ATETXGI, set GI interval, 0:Long, 1:Short\n");
54093 + ate_print("ATERXFER, 0:disable Rx Frame error rate. 1:enable Rx Frame error rate.\n");
54094 + ate_print("ATERRF, show all RF registers.\n");
54095 + ate_print("ATEWRF1, set RF1 register.\n");
54096 + ate_print("ATEWRF2, set RF2 register.\n");
54097 + ate_print("ATEWRF3, set RF3 register.\n");
54098 + ate_print("ATEWRF4, set RF4 register.\n");
54099 + ate_print("ATELDE2P, load EEPROM from .bin file.\n");
54100 + ate_print("ATERE2P, display all EEPROM content.\n");
54101 + ate_print("ATESHOW, display all parameters of ATE.\n");
54102 + ate_print("ATEHELP, online help.\n");
54103 +
54104 + return TRUE;
54105 +}
54106 +
54107 +/*
54108 + ==========================================================================
54109 + Description:
54110 +
54111 + AsicSwitchChannel() dedicated for ATE.
54112 +
54113 + ==========================================================================
54114 +*/
54115 +VOID ATEAsicSwitchChannel(
54116 + IN PRTMP_ADAPTER pAd)
54117 +{
54118 + UINT32 R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0, Value = 0;
54119 + CHAR TxPwer = 0, TxPwer2 = 0;
54120 + UCHAR index, BbpValue = 0, R66 = 0x30;
54121 + RTMP_RF_REGS *RFRegTable;
54122 + UCHAR Channel;
54123 +
54124 +#ifdef RALINK_28xx_QA
54125 + if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
54126 + {
54127 + if (pAd->ate.Channel != pAd->LatchRfRegs.Channel)
54128 + {
54129 + pAd->ate.Channel = pAd->LatchRfRegs.Channel;
54130 + }
54131 + return;
54132 + }
54133 + else
54134 +#endif // RALINK_28xx_QA //
54135 + Channel = pAd->ate.Channel;
54136 +
54137 + // Select antenna
54138 + AsicAntennaSelect(pAd, Channel);
54139 +
54140 + // fill Tx power value
54141 + TxPwer = pAd->ate.TxPower0;
54142 + TxPwer2 = pAd->ate.TxPower1;
54143 +#ifdef RT30xx
54144 +//2008/07/10:KH add to support 3070 ATE<--
54145 +
54146 + // The RF programming sequence is difference between 3xxx and 2xxx
54147 + // The 3070 is 1T1R. Therefore, we don't need to set the number of Tx/Rx path and the only job is to set the parameters of channels.
54148 + if (IS_RT30xx(pAd) && ((pAd->RfIcType == RFIC_3020) ||
54149 +(pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022) ||
54150 +(pAd->RfIcType == RFIC_2020)))
54151 + {
54152 + /* modify by WY for Read RF Reg. error */
54153 + UCHAR RFValue;
54154 +
54155 + for (index = 0; index < NUM_OF_3020_CHNL; index++)
54156 + {
54157 + if (Channel == FreqItems3020[index].Channel)
54158 + {
54159 + // Programming channel parameters
54160 + RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N);
54161 + RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K);
54162 +
54163 + RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue);
54164 + RFValue = (RFValue & 0xFC) | FreqItems3020[index].R;
54165 + RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue);
54166 +
54167 + // Set Tx Power
54168 + RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
54169 + RFValue = (RFValue & 0xE0) | TxPwer;
54170 + RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
54171 +
54172 + // Set RF offset
54173 + RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
54174 + //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
54175 + RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
54176 + RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
54177 +
54178 + // Set BW
54179 + if (pAd->ate.TxWI.BW == BW_40)
54180 + {
54181 + RFValue = pAd->Mlme.CaliBW40RfR24;
54182 + //DISABLE_11N_CHECK(pAd);
54183 + }
54184 + else
54185 + {
54186 + RFValue = pAd->Mlme.CaliBW20RfR24;
54187 + }
54188 + RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue);
54189 +
54190 + // Enable RF tuning
54191 + RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue);
54192 + RFValue = RFValue | 0x1;
54193 + RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue);
54194 +
54195 + // latch channel for future usage.
54196 + pAd->LatchRfRegs.Channel = Channel;
54197 +
54198 + break;
54199 + }
54200 + }
54201 +
54202 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
54203 + Channel,
54204 + pAd->RfIcType,
54205 + TxPwer,
54206 + TxPwer2,
54207 + pAd->Antenna.field.TxPath,
54208 + FreqItems3020[index].N,
54209 + FreqItems3020[index].K,
54210 + FreqItems3020[index].R));
54211 + }
54212 + else
54213 +//2008/07/10:KH add to support 3070 ATE-->
54214 +#endif // RT30xx //
54215 +{
54216 + RFRegTable = RF2850RegTable;
54217 +
54218 + switch (pAd->RfIcType)
54219 + {
54220 + /* But only 2850 and 2750 support 5.5GHz band... */
54221 + case RFIC_2820:
54222 + case RFIC_2850:
54223 + case RFIC_2720:
54224 + case RFIC_2750:
54225 +
54226 + for (index = 0; index < NUM_OF_2850_CHNL; index++)
54227 + {
54228 + if (Channel == RFRegTable[index].Channel)
54229 + {
54230 + R2 = RFRegTable[index].R2;
54231 + if (pAd->Antenna.field.TxPath == 1)
54232 + {
54233 + R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
54234 + }
54235 +
54236 + if (pAd->Antenna.field.RxPath == 2)
54237 + {
54238 + switch (pAd->ate.RxAntennaSel)
54239 + {
54240 + case 1:
54241 + R2 |= 0x20040;
54242 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54243 + BbpValue &= 0xE4;
54244 + BbpValue |= 0x00;
54245 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54246 + break;
54247 + case 2:
54248 + R2 |= 0x10040;
54249 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54250 + BbpValue &= 0xE4;
54251 + BbpValue |= 0x01;
54252 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54253 + break;
54254 + default:
54255 + R2 |= 0x40;
54256 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54257 + BbpValue &= 0xE4;
54258 + /* Only enable two Antenna to receive. */
54259 + BbpValue |= 0x08;
54260 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54261 + break;
54262 + }
54263 + }
54264 + else if (pAd->Antenna.field.RxPath == 1)
54265 + {
54266 + R2 |= 0x20040; // write 1 to off RxPath
54267 + }
54268 +
54269 + if (pAd->Antenna.field.TxPath == 2)
54270 + {
54271 + if (pAd->ate.TxAntennaSel == 1)
54272 + {
54273 + R2 |= 0x4000; // If TX Antenna select is 1 , bit 14 = 1; Disable Ant 2
54274 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
54275 + BbpValue &= 0xE7; //11100111B
54276 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
54277 + }
54278 + else if (pAd->ate.TxAntennaSel == 2)
54279 + {
54280 + R2 |= 0x8000; // If TX Antenna select is 2 , bit 15 = 1; Disable Ant 1
54281 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
54282 + BbpValue &= 0xE7;
54283 + BbpValue |= 0x08;
54284 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
54285 + }
54286 + else
54287 + {
54288 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
54289 + BbpValue &= 0xE7;
54290 + BbpValue |= 0x10;
54291 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
54292 + }
54293 + }
54294 + if (pAd->Antenna.field.RxPath == 3)
54295 + {
54296 + switch (pAd->ate.RxAntennaSel)
54297 + {
54298 + case 1:
54299 + R2 |= 0x20040;
54300 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54301 + BbpValue &= 0xE4;
54302 + BbpValue |= 0x00;
54303 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54304 + break;
54305 + case 2:
54306 + R2 |= 0x10040;
54307 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54308 + BbpValue &= 0xE4;
54309 + BbpValue |= 0x01;
54310 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54311 + break;
54312 + case 3:
54313 + R2 |= 0x30000;
54314 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54315 + BbpValue &= 0xE4;
54316 + BbpValue |= 0x02;
54317 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54318 + break;
54319 + default:
54320 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
54321 + BbpValue &= 0xE4;
54322 + BbpValue |= 0x10;
54323 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
54324 + break;
54325 + }
54326 + }
54327 +
54328 + if (Channel > 14)
54329 + {
54330 + // initialize R3, R4
54331 + R3 = (RFRegTable[index].R3 & 0xffffc1ff);
54332 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15);
54333 +
54334 + // According the Rory's suggestion to solve the middle range issue.
54335 + // 5.5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
54336 + // R3
54337 + if ((TxPwer >= -7) && (TxPwer < 0))
54338 + {
54339 + TxPwer = (7+TxPwer);
54340 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
54341 + R3 |= (TxPwer << 10);
54342 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer=%d \n", TxPwer));
54343 + }
54344 + else
54345 + {
54346 + TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
54347 + R3 |= (TxPwer << 10) | (1 << 9);
54348 + }
54349 +
54350 + // R4
54351 + if ((TxPwer2 >= -7) && (TxPwer2 < 0))
54352 + {
54353 + TxPwer2 = (7+TxPwer2);
54354 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
54355 + R4 |= (TxPwer2 << 7);
54356 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
54357 + }
54358 + else
54359 + {
54360 + TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
54361 + R4 |= (TxPwer2 << 7) | (1 << 6);
54362 + }
54363 + }
54364 + else
54365 + {
54366 + R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
54367 + R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15) | (TxPwer2 <<6);// Set freq offset & TxPwr1
54368 + }
54369 +
54370 + // Based on BBP current mode before changing RF channel.
54371 + if (pAd->ate.TxWI.BW == BW_40)
54372 + {
54373 + R4 |=0x200000;
54374 + }
54375 +
54376 + // Update variables
54377 + pAd->LatchRfRegs.Channel = Channel;
54378 + pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
54379 + pAd->LatchRfRegs.R2 = R2;
54380 + pAd->LatchRfRegs.R3 = R3;
54381 + pAd->LatchRfRegs.R4 = R4;
54382 +
54383 + RtmpRfIoWrite(pAd);
54384 +
54385 + break;
54386 + }
54387 + }
54388 + break;
54389 +
54390 + default:
54391 + break;
54392 + }
54393 +}
54394 + // Change BBP setting during switch from a->g, g->a
54395 + if (Channel <= 14)
54396 + {
54397 + ULONG TxPinCfg = 0x00050F0A;// 2007.10.09 by Brian : 0x0005050A ==> 0x00050F0A
54398 +
54399 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
54400 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
54401 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
54402 +
54403 + /* For 1T/2R chip only... */
54404 + if (pAd->NicConfig2.field.ExternalLNAForG)
54405 + {
54406 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
54407 + }
54408 + else
54409 + {
54410 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
54411 + }
54412 +
54413 + // According the Rory's suggestion to solve the middle range issue.
54414 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
54415 + ASSERT((BbpValue == 0x00));
54416 + if ((BbpValue != 0x00))
54417 + {
54418 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
54419 + }
54420 +
54421 + // 5.5GHz band selection PIN, bit1 and bit2 are complement
54422 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
54423 + Value &= (~0x6);
54424 + Value |= (0x04);
54425 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
54426 +
54427 + // Turn off unused PA or LNA when only 1T or 1R.
54428 + if (pAd->Antenna.field.TxPath == 1)
54429 + {
54430 + TxPinCfg &= 0xFFFFFFF3;
54431 + }
54432 + if (pAd->Antenna.field.RxPath == 1)
54433 + {
54434 + TxPinCfg &= 0xFFFFF3FF;
54435 + }
54436 +
54437 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
54438 + }
54439 + else
54440 + {
54441 + ULONG TxPinCfg = 0x00050F05;//2007.10.09 by Brian : 0x00050505 ==> 0x00050F05
54442 +
54443 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
54444 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
54445 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
54446 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
54447 +
54448 + // According the Rory's suggestion to solve the middle range issue.
54449 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
54450 + ASSERT((BbpValue == 0x00));
54451 + if ((BbpValue != 0x00))
54452 + {
54453 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
54454 + }
54455 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R91, &BbpValue);
54456 + ASSERT((BbpValue == 0x04));
54457 +
54458 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R92, &BbpValue);
54459 + ASSERT((BbpValue == 0x00));
54460 +
54461 + // 5.5GHz band selection PIN, bit1 and bit2 are complement
54462 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
54463 + Value &= (~0x6);
54464 + Value |= (0x02);
54465 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
54466 +
54467 + // Turn off unused PA or LNA when only 1T or 1R.
54468 + if (pAd->Antenna.field.TxPath == 1)
54469 + {
54470 + TxPinCfg &= 0xFFFFFFF3;
54471 + }
54472 + if (pAd->Antenna.field.RxPath == 1)
54473 + {
54474 + TxPinCfg &= 0xFFFFF3FF;
54475 + }
54476 +
54477 + RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
54478 + }
54479 +
54480 + // R66 should be set according to Channel and use 20MHz when scanning
54481 + if (Channel <= 14)
54482 + {
54483 + // BG band
54484 + R66 = 0x2E + GET_LNA_GAIN(pAd);
54485 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
54486 + }
54487 + else
54488 + {
54489 + // 5.5 GHz band
54490 + if (pAd->ate.TxWI.BW == BW_20)
54491 + {
54492 + R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
54493 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
54494 + }
54495 + else
54496 + {
54497 + R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
54498 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
54499 + }
54500 + }
54501 +
54502 + //
54503 + // On 11A, We should delay and wait RF/BBP to be stable
54504 + // and the appropriate time should be 1000 micro seconds
54505 + // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
54506 + //
54507 + RTMPusecDelay(1000);
54508 +
54509 + if (Channel > 14)
54510 + {
54511 + // When 5.5GHz band the LSB of TxPwr will be used to reduced 7dB or not.
54512 + ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
54513 + Channel,
54514 + pAd->RfIcType,
54515 + pAd->Antenna.field.TxPath,
54516 + pAd->LatchRfRegs.R1,
54517 + pAd->LatchRfRegs.R2,
54518 + pAd->LatchRfRegs.R3,
54519 + pAd->LatchRfRegs.R4));
54520 + }
54521 + else
54522 + {
54523 + ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%u, Pwr1=%u, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
54524 + Channel,
54525 + pAd->RfIcType,
54526 + (R3 & 0x00003e00) >> 9,
54527 + (R4 & 0x000007c0) >> 6,
54528 + pAd->Antenna.field.TxPath,
54529 + pAd->LatchRfRegs.R1,
54530 + pAd->LatchRfRegs.R2,
54531 + pAd->LatchRfRegs.R3,
54532 + pAd->LatchRfRegs.R4));
54533 + }
54534 +}
54535 +
54536 +//
54537 +// In fact, no one will call this routine so far !
54538 +//
54539 +/*
54540 + ==========================================================================
54541 + Description:
54542 + Gives CCK TX rate 2 more dB TX power.
54543 + This routine works only in ATE mode.
54544 +
54545 + calculate desired Tx power in RF R3.Tx0~5, should consider -
54546 + 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
54547 + 1. TxPowerPercentage
54548 + 2. auto calibration based on TSSI feedback
54549 + 3. extra 2 db for CCK
54550 + 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
54551 +
54552 + NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
54553 + it should be called AFTER MlmeDynamicTxRateSwitching()
54554 + ==========================================================================
54555 + */
54556 +VOID ATEAsicAdjustTxPower(
54557 + IN PRTMP_ADAPTER pAd)
54558 +{
54559 + INT i, j;
54560 + CHAR DeltaPwr = 0;
54561 + BOOLEAN bAutoTxAgc = FALSE;
54562 + UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
54563 + UCHAR BbpR49 = 0, idx;
54564 + PCHAR pTxAgcCompensate;
54565 + ULONG TxPwr[5];
54566 + CHAR Value;
54567 +
54568 + /* no one calls this procedure so far */
54569 + if (pAd->ate.TxWI.BW == BW_40)
54570 + {
54571 + if (pAd->ate.Channel > 14)
54572 + {
54573 + TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
54574 + TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
54575 + TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
54576 + TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
54577 + TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
54578 + }
54579 + else
54580 + {
54581 + TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
54582 + TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
54583 + TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
54584 + TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
54585 + TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
54586 + }
54587 + }
54588 + else
54589 + {
54590 + if (pAd->ate.Channel > 14)
54591 + {
54592 + TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
54593 + TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
54594 + TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
54595 + TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
54596 + TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
54597 + }
54598 + else
54599 + {
54600 + TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
54601 + TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
54602 + TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
54603 + TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
54604 + TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
54605 + }
54606 + }
54607 +
54608 + // TX power compensation for temperature variation based on TSSI.
54609 + // Do it per 4 seconds.
54610 + if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
54611 + {
54612 + if (pAd->ate.Channel <= 14)
54613 + {
54614 + /* bg channel */
54615 + bAutoTxAgc = pAd->bAutoTxAgcG;
54616 + TssiRef = pAd->TssiRefG;
54617 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
54618 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
54619 + TxAgcStep = pAd->TxAgcStepG;
54620 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
54621 + }
54622 + else
54623 + {
54624 + /* a channel */
54625 + bAutoTxAgc = pAd->bAutoTxAgcA;
54626 + TssiRef = pAd->TssiRefA;
54627 + pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
54628 + pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
54629 + TxAgcStep = pAd->TxAgcStepA;
54630 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
54631 + }
54632 +
54633 + if (bAutoTxAgc)
54634 + {
54635 + /* BbpR49 is unsigned char */
54636 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
54637 +
54638 + /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
54639 + /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
54640 + /* step value is defined in pAd->TxAgcStepG for tx power value */
54641 +
54642 + /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
54643 + /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
54644 + above value are examined in mass factory production */
54645 + /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
54646 +
54647 + /* plus is 0x10 ~ 0x40, minus is 0x60 ~ 0x90 */
54648 + /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
54649 + /* if value is 0x65, tx power will be -= TxAgcStep*(2-1) */
54650 +
54651 + if (BbpR49 > pTssiMinusBoundary[1])
54652 + {
54653 + // Reading is larger than the reference value.
54654 + // Check for how large we need to decrease the Tx power.
54655 + for (idx = 1; idx < 5; idx++)
54656 + {
54657 + if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
54658 + break;
54659 + }
54660 + // The index is the step we should decrease, idx = 0 means there is nothing to compensate
54661 +// if (R3 > (ULONG) (TxAgcStep * (idx-1)))
54662 + *pTxAgcCompensate = -(TxAgcStep * (idx-1));
54663 +// else
54664 +// *pTxAgcCompensate = -((UCHAR)R3);
54665 +
54666 + DeltaPwr += (*pTxAgcCompensate);
54667 + ATEDBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
54668 + BbpR49, TssiRef, TxAgcStep, idx-1));
54669 + }
54670 + else if (BbpR49 < pTssiPlusBoundary[1])
54671 + {
54672 + // Reading is smaller than the reference value
54673 + // check for how large we need to increase the Tx power
54674 + for (idx = 1; idx < 5; idx++)
54675 + {
54676 + if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
54677 + break;
54678 + }
54679 + // The index is the step we should increase, idx = 0 means there is nothing to compensate
54680 + *pTxAgcCompensate = TxAgcStep * (idx-1);
54681 + DeltaPwr += (*pTxAgcCompensate);
54682 + ATEDBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
54683 + BbpR49, TssiRef, TxAgcStep, idx-1));
54684 + }
54685 + else
54686 + {
54687 + *pTxAgcCompensate = 0;
54688 + ATEDBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
54689 + BbpR49, TssiRef, TxAgcStep, 0));
54690 + }
54691 + }
54692 + }
54693 + else
54694 + {
54695 + if (pAd->ate.Channel <= 14)
54696 + {
54697 + bAutoTxAgc = pAd->bAutoTxAgcG;
54698 + pTxAgcCompensate = &pAd->TxAgcCompensateG;
54699 + }
54700 + else
54701 + {
54702 + bAutoTxAgc = pAd->bAutoTxAgcA;
54703 + pTxAgcCompensate = &pAd->TxAgcCompensateA;
54704 + }
54705 +
54706 + if (bAutoTxAgc)
54707 + DeltaPwr += (*pTxAgcCompensate);
54708 + }
54709 +
54710 + /* calculate delta power based on the percentage specified from UI */
54711 + // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
54712 + // We lower TX power here according to the percentage specified from UI
54713 + if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
54714 + ;
54715 + else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
54716 + ;
54717 + else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW
54718 + {
54719 + DeltaPwr -= 1;
54720 + }
54721 + else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW
54722 + {
54723 + DeltaPwr -= 3;
54724 + }
54725 + else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW
54726 + {
54727 + DeltaPwr -= 6;
54728 + }
54729 + else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW
54730 + {
54731 + DeltaPwr -= 9;
54732 + }
54733 + else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW
54734 + {
54735 + DeltaPwr -= 12;
54736 + }
54737 +
54738 + /* reset different new tx power for different TX rate */
54739 + for(i=0; i<5; i++)
54740 + {
54741 + if (TxPwr[i] != 0xffffffff)
54742 + {
54743 + for (j=0; j<8; j++)
54744 + {
54745 + Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
54746 +
54747 + if ((Value + DeltaPwr) < 0)
54748 + {
54749 + Value = 0; /* min */
54750 + }
54751 + else if ((Value + DeltaPwr) > 0xF)
54752 + {
54753 + Value = 0xF; /* max */
54754 + }
54755 + else
54756 + {
54757 + Value += DeltaPwr; /* temperature compensation */
54758 + }
54759 +
54760 + /* fill new value to CSR offset */
54761 + TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
54762 + }
54763 +
54764 + /* write tx power value to CSR */
54765 + /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
54766 + TX power for OFDM 6M/9M
54767 + TX power for CCK5.5M/11M
54768 + TX power for CCK1M/2M */
54769 + /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
54770 + RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
54771 +
54772 +
54773 + }
54774 + }
54775 +
54776 +}
54777 +
54778 +/*
54779 + ========================================================================
54780 + Routine Description:
54781 + Write TxWI for ATE mode.
54782 +
54783 + Return Value:
54784 + None
54785 + ========================================================================
54786 +*/
54787 +
54788 +#ifdef RT2870
54789 +static VOID ATEWriteTxWI(
54790 + IN PRTMP_ADAPTER pAd,
54791 + IN PTXWI_STRUC pTxWI,
54792 + IN BOOLEAN FRAG,
54793 + IN BOOLEAN InsTimestamp,
54794 + IN BOOLEAN AMPDU,
54795 + IN BOOLEAN Ack,
54796 + IN BOOLEAN NSeq, // HW new a sequence.
54797 + IN UCHAR BASize,
54798 + IN UCHAR WCID,
54799 + IN ULONG Length,
54800 + IN UCHAR PID,
54801 + IN UCHAR MIMOps,
54802 + IN UCHAR Txopmode,
54803 + IN BOOLEAN CfAck,
54804 + IN HTTRANSMIT_SETTING Transmit)
54805 +{
54806 + //
54807 + // Always use Long preamble before verifiation short preamble functionality works well.
54808 + // Todo: remove the following line if short preamble functionality works
54809 + //
54810 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
54811 + pTxWI->FRAG= FRAG;
54812 + pTxWI->TS= InsTimestamp;
54813 + pTxWI->AMPDU = AMPDU;
54814 +
54815 + pTxWI->MIMOps = PWR_ACTIVE;
54816 + pTxWI->MpduDensity = 4;
54817 + pTxWI->ACK = Ack;
54818 + pTxWI->txop = Txopmode;
54819 + pTxWI->NSEQ = NSeq;
54820 + pTxWI->BAWinSize = BASize;
54821 +
54822 + pTxWI->WirelessCliID = WCID;
54823 + pTxWI->MPDUtotalByteCount = Length;
54824 + pTxWI->PacketId = PID;
54825 +
54826 + pTxWI->BW = Transmit.field.BW;
54827 + pTxWI->ShortGI = Transmit.field.ShortGI;
54828 + pTxWI->STBC= Transmit.field.STBC;
54829 +
54830 + pTxWI->MCS = Transmit.field.MCS;
54831 + pTxWI->PHYMODE= Transmit.field.MODE;
54832 +
54833 +#ifdef DOT11_N_SUPPORT
54834 + //
54835 + // MMPS is 802.11n features. Because TxWI->MCS > 7 must be HT mode,
54836 + // so need not check if it's HT rate.
54837 + //
54838 + if ((MIMOps == MMPS_STATIC) && (pTxWI->MCS > 7))
54839 + pTxWI->MCS = 7;
54840 +
54841 + if ((MIMOps == MMPS_DYNAMIC) && (pTxWI->MCS > 7)) // SMPS protect 2 spatial.
54842 + pTxWI->MIMOps = 1;
54843 +#endif // DOT11_N_SUPPORT //
54844 +
54845 + pTxWI->CFACK = CfAck;
54846 +
54847 + return;
54848 +}
54849 +#endif // RT2870 //
54850 +/*
54851 + ========================================================================
54852 +
54853 + Routine Description:
54854 + Disable protection for ATE.
54855 + ========================================================================
54856 +*/
54857 +VOID ATEDisableAsicProtect(
54858 + IN PRTMP_ADAPTER pAd)
54859 +{
54860 + PROT_CFG_STRUC ProtCfg, ProtCfg4;
54861 + UINT32 Protect[6];
54862 + USHORT offset;
54863 + UCHAR i;
54864 + UINT32 MacReg = 0;
54865 +
54866 + // Config ASIC RTS threshold register
54867 + RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
54868 + MacReg &= 0xFF0000FF;
54869 + MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
54870 + RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
54871 +
54872 + // Initial common protection settings
54873 + RTMPZeroMemory(Protect, sizeof(Protect));
54874 + ProtCfg4.word = 0;
54875 + ProtCfg.word = 0;
54876 + ProtCfg.field.TxopAllowGF40 = 1;
54877 + ProtCfg.field.TxopAllowGF20 = 1;
54878 + ProtCfg.field.TxopAllowMM40 = 1;
54879 + ProtCfg.field.TxopAllowMM20 = 1;
54880 + ProtCfg.field.TxopAllowOfdm = 1;
54881 + ProtCfg.field.TxopAllowCck = 1;
54882 + ProtCfg.field.RTSThEn = 1;
54883 + ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
54884 +
54885 + // Handle legacy(B/G) protection
54886 + ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
54887 + ProtCfg.field.ProtectCtrl = 0;
54888 + Protect[0] = ProtCfg.word;
54889 + Protect[1] = ProtCfg.word;
54890 +
54891 + // NO PROTECT
54892 + // 1.All STAs in the BSS are 20/40 MHz HT
54893 + // 2. in ai 20/40MHz BSS
54894 + // 3. all STAs are 20MHz in a 20MHz BSS
54895 + // Pure HT. no protection.
54896 +
54897 + // MM20_PROT_CFG
54898 + // Reserved (31:27)
54899 + // PROT_TXOP(25:20) -- 010111
54900 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
54901 + // PROT_CTRL(17:16) -- 00 (None)
54902 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
54903 + Protect[2] = 0x01744004;
54904 +
54905 + // MM40_PROT_CFG
54906 + // Reserved (31:27)
54907 + // PROT_TXOP(25:20) -- 111111
54908 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
54909 + // PROT_CTRL(17:16) -- 00 (None)
54910 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
54911 + Protect[3] = 0x03f44084;
54912 +
54913 + // CF20_PROT_CFG
54914 + // Reserved (31:27)
54915 + // PROT_TXOP(25:20) -- 010111
54916 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
54917 + // PROT_CTRL(17:16) -- 00 (None)
54918 + // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
54919 + Protect[4] = 0x01744004;
54920 +
54921 + // CF40_PROT_CFG
54922 + // Reserved (31:27)
54923 + // PROT_TXOP(25:20) -- 111111
54924 + // PROT_NAV(19:18) -- 01 (Short NAV protection)
54925 + // PROT_CTRL(17:16) -- 00 (None)
54926 + // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
54927 + Protect[5] = 0x03f44084;
54928 +
54929 + pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
54930 +
54931 + offset = CCK_PROT_CFG;
54932 + for (i = 0;i < 6;i++)
54933 + RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
54934 +
54935 +}
54936 +
54937 +#ifdef RT2870
54938 +/*
54939 + ========================================================================
54940 + Routine Description:
54941 + Write TxInfo for ATE mode.
54942 +
54943 + Return Value:
54944 + None
54945 + ========================================================================
54946 +*/
54947 +static VOID ATEWriteTxInfo(
54948 + IN PRTMP_ADAPTER pAd,
54949 + IN PTXINFO_STRUC pTxInfo,
54950 + IN USHORT USBDMApktLen,
54951 + IN BOOLEAN bWiv,
54952 + IN UCHAR QueueSel,
54953 + IN UCHAR NextValid,
54954 + IN UCHAR TxBurst)
54955 +{
54956 + pTxInfo->USBDMATxPktLen = USBDMApktLen;
54957 + pTxInfo->QSEL = QueueSel;
54958 +
54959 + if (QueueSel != FIFO_EDCA)
54960 + ATEDBGPRINT(RT_DEBUG_TRACE, ("=======> QueueSel != FIFO_EDCA<=======\n"));
54961 +
54962 + pTxInfo->USBDMANextVLD = NextValid;
54963 + pTxInfo->USBDMATxburst = TxBurst;
54964 + pTxInfo->WIV = bWiv;
54965 + pTxInfo->SwUseLastRound = 0;
54966 + pTxInfo->rsv = 0;
54967 + pTxInfo->rsv2 = 0;
54968 +
54969 + return;
54970 +}
54971 +#endif // RT2870 //
54972 +
54973 +/* There are two ways to convert Rssi */
54974 +#if 1
54975 +//
54976 +// The way used with GET_LNA_GAIN().
54977 +//
54978 +CHAR ATEConvertToRssi(
54979 + IN PRTMP_ADAPTER pAd,
54980 + IN CHAR Rssi,
54981 + IN UCHAR RssiNumber)
54982 +{
54983 + UCHAR RssiOffset, LNAGain;
54984 +
54985 + // Rssi equals to zero should be an invalid value
54986 + if (Rssi == 0)
54987 + return -99;
54988 +
54989 + LNAGain = GET_LNA_GAIN(pAd);
54990 + if (pAd->LatchRfRegs.Channel > 14)
54991 + {
54992 + if (RssiNumber == 0)
54993 + RssiOffset = pAd->ARssiOffset0;
54994 + else if (RssiNumber == 1)
54995 + RssiOffset = pAd->ARssiOffset1;
54996 + else
54997 + RssiOffset = pAd->ARssiOffset2;
54998 + }
54999 + else
55000 + {
55001 + if (RssiNumber == 0)
55002 + RssiOffset = pAd->BGRssiOffset0;
55003 + else if (RssiNumber == 1)
55004 + RssiOffset = pAd->BGRssiOffset1;
55005 + else
55006 + RssiOffset = pAd->BGRssiOffset2;
55007 + }
55008 +
55009 + return (-12 - RssiOffset - LNAGain - Rssi);
55010 +}
55011 +#else
55012 +//
55013 +// The way originally used in ATE of rt2860ap.
55014 +//
55015 +CHAR ATEConvertToRssi(
55016 + IN PRTMP_ADAPTER pAd,
55017 + IN CHAR Rssi,
55018 + IN UCHAR RssiNumber)
55019 +{
55020 + UCHAR RssiOffset, LNAGain;
55021 +
55022 + // Rssi equals to zero should be an invalid value
55023 + if (Rssi == 0)
55024 + return -99;
55025 +
55026 + if (pAd->LatchRfRegs.Channel > 14)
55027 + {
55028 + LNAGain = pAd->ALNAGain;
55029 + if (RssiNumber == 0)
55030 + RssiOffset = pAd->ARssiOffset0;
55031 + else if (RssiNumber == 1)
55032 + RssiOffset = pAd->ARssiOffset1;
55033 + else
55034 + RssiOffset = pAd->ARssiOffset2;
55035 + }
55036 + else
55037 + {
55038 + LNAGain = pAd->BLNAGain;
55039 + if (RssiNumber == 0)
55040 + RssiOffset = pAd->BGRssiOffset0;
55041 + else if (RssiNumber == 1)
55042 + RssiOffset = pAd->BGRssiOffset1;
55043 + else
55044 + RssiOffset = pAd->BGRssiOffset2;
55045 + }
55046 +
55047 + return (-32 - RssiOffset + LNAGain - Rssi);
55048 +}
55049 +#endif /* end of #if 1 */
55050 +
55051 +/*
55052 + ========================================================================
55053 +
55054 + Routine Description:
55055 + Set Japan filter coefficients if needed.
55056 + Note:
55057 + This routine should only be called when
55058 + entering TXFRAME mode or TXCONT mode.
55059 +
55060 + ========================================================================
55061 +*/
55062 +static VOID SetJapanFilter(
55063 + IN PRTMP_ADAPTER pAd)
55064 +{
55065 + UCHAR BbpData = 0;
55066 +
55067 + //
55068 + // If Channel=14 and Bandwidth=20M and Mode=CCK, set BBP R4 bit5=1
55069 + // (Japan Tx filter coefficients)when (TXFRAME or TXCONT).
55070 + //
55071 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BbpData);
55072 +
55073 + if ((pAd->ate.TxWI.PHYMODE == MODE_CCK) && (pAd->ate.Channel == 14) && (pAd->ate.TxWI.BW == BW_20))
55074 + {
55075 + BbpData |= 0x20; // turn on
55076 + ATEDBGPRINT(RT_DEBUG_TRACE, ("SetJapanFilter!!!\n"));
55077 + }
55078 + else
55079 + {
55080 + BbpData &= 0xdf; // turn off
55081 + ATEDBGPRINT(RT_DEBUG_TRACE, ("ClearJapanFilter!!!\n"));
55082 + }
55083 +
55084 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BbpData);
55085 +}
55086 +
55087 +VOID ATESampleRssi(
55088 + IN PRTMP_ADAPTER pAd,
55089 + IN PRXWI_STRUC pRxWI)
55090 +{
55091 + /* There are two ways to collect RSSI. */
55092 +#if 1
55093 + //pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
55094 + if (pRxWI->RSSI0 != 0)
55095 + {
55096 + pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
55097 + pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
55098 + pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
55099 + }
55100 + if (pRxWI->RSSI1 != 0)
55101 + {
55102 + pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
55103 + pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
55104 + pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
55105 + }
55106 + if (pRxWI->RSSI2 != 0)
55107 + {
55108 + pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
55109 + pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
55110 + pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
55111 + }
55112 +
55113 + pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);// CHAR ==> UCHAR ?
55114 + pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);// CHAR ==> UCHAR ?
55115 +
55116 + pAd->ate.NumOfAvgRssiSample ++;
55117 +#else
55118 + pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);
55119 + pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);
55120 + pAd->ate.RxCntPerSec++;
55121 + pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
55122 + pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
55123 + pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
55124 + pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
55125 + pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
55126 + pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
55127 + pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
55128 + pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
55129 + pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
55130 + pAd->ate.NumOfAvgRssiSample ++;
55131 +#endif
55132 +}
55133 +
55134 +#ifdef CONFIG_STA_SUPPORT
55135 +VOID RTMPStationStop(
55136 + IN PRTMP_ADAPTER pAd)
55137 +{
55138 +// BOOLEAN Cancelled;
55139 +
55140 + ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStop\n"));
55141 +
55142 + // For rx statistics, we need to keep this timer running.
55143 +// RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
55144 +
55145 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStop\n"));
55146 +}
55147 +
55148 +VOID RTMPStationStart(
55149 + IN PRTMP_ADAPTER pAd)
55150 +{
55151 + ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStart\n"));
55152 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStart\n"));
55153 +}
55154 +#endif // CONFIG_STA_SUPPORT //
55155 +
55156 +/*
55157 + ==========================================================================
55158 + Description:
55159 + Setup Frame format.
55160 + NOTE:
55161 + This routine should only be used in ATE mode.
55162 + ==========================================================================
55163 + */
55164 +
55165 +#ifdef RT2870
55166 +/*======================Start of RT2870======================*/
55167 +/* */
55168 +/* */
55169 +static INT ATESetUpFrame(
55170 + IN PRTMP_ADAPTER pAd,
55171 + IN UINT32 TxIdx)
55172 +{
55173 + UINT j;
55174 + PTX_CONTEXT pNullContext;
55175 + PUCHAR pDest;
55176 + HTTRANSMIT_SETTING TxHTPhyMode;
55177 + PTXWI_STRUC pTxWI;
55178 + PTXINFO_STRUC pTxInfo;
55179 + UINT32 TransferBufferLength, OrgBufferLength = 0;
55180 + UCHAR padLen = 0;
55181 +#ifdef RALINK_28xx_QA
55182 + PHEADER_802_11 pHeader80211 = NULL;
55183 +#endif // RALINK_28xx_QA //
55184 +
55185 + if ((RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
55186 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) ||
55187 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
55188 + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
55189 + {
55190 + return -1;
55191 + }
55192 +
55193 + /* We always use QID_AC_BE and FIFO_EDCA in ATE mode. */
55194 +
55195 + pNullContext = &(pAd->NullContext);
55196 + ASSERT(pNullContext != NULL);
55197 +
55198 + if (pNullContext->InUse == FALSE)
55199 + {
55200 + // Set the in use bit
55201 + pNullContext->InUse = TRUE;
55202 + NdisZeroMemory(&(pAd->NullFrame), sizeof(HEADER_802_11));
55203 +
55204 + // Fill 802.11 header.
55205 +#ifdef RALINK_28xx_QA
55206 + if (pAd->ate.bQATxStart == TRUE)
55207 + {
55208 + pHeader80211 = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
55209 +// pDest = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
55210 +// pHeader80211 = (PHEADER_802_11)pDest;
55211 + }
55212 + else
55213 +#endif // RALINK_28xx_QA //
55214 + {
55215 + // Fill 802.11 header.
55216 + NdisMoveMemory(&(pAd->NullFrame), TemplateFrame, sizeof(HEADER_802_11));
55217 + }
55218 +#ifdef RT_BIG_ENDIAN
55219 + RTMPFrameEndianChange(pAd, (PUCHAR)&(pAd->NullFrame), DIR_READ, FALSE);
55220 +#endif // RT_BIG_ENDIAN //
55221 +
55222 +#ifdef RALINK_28xx_QA
55223 + if (pAd->ate.bQATxStart == TRUE)
55224 + {
55225 + /* modify sequence number.... */
55226 + if (pAd->ate.TxDoneCount == 0)
55227 + {
55228 + pAd->ate.seq = pHeader80211->Sequence;
55229 + }
55230 + else
55231 + {
55232 + pHeader80211->Sequence = ++pAd->ate.seq;
55233 + }
55234 + /* We already got all the addr. fields from QA GUI. */
55235 + }
55236 + else
55237 +#endif // RALINK_28xx_QA //
55238 + {
55239 + COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->ate.Addr1);
55240 + COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->ate.Addr2);
55241 + COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->ate.Addr3);
55242 + }
55243 +
55244 + RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], TX_BUFFER_NORMSIZE);//???
55245 + pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
55246 +
55247 +#ifdef RALINK_28xx_QA
55248 + if (pAd->ate.bQATxStart == TRUE)
55249 + {
55250 + // Avoid to exceed the range of WirelessPacket[].
55251 + ASSERT(pAd->ate.TxInfo.USBDMATxPktLen <= (MAX_FRAME_SIZE - 34/* == 2312 */));
55252 + NdisMoveMemory(pTxInfo, &(pAd->ate.TxInfo), sizeof(pAd->ate.TxInfo));
55253 + }
55254 + else
55255 +#endif // RALINK_28xx_QA //
55256 + {
55257 + // Avoid to exceed the range of WirelessPacket[].
55258 + ASSERT(pAd->ate.TxLength <= (MAX_FRAME_SIZE - 34/* == 2312 */));
55259 +
55260 + // pTxInfo->USBDMATxPktLen will be updated to include padding later.
55261 + ATEWriteTxInfo(pAd, pTxInfo, (USHORT)(TXWI_SIZE + pAd->ate.TxLength), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
55262 + pTxInfo->QSEL = FIFO_EDCA;
55263 + }
55264 +
55265 + pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
55266 +
55267 + // Fill TxWI.
55268 + if (pAd->ate.bQATxStart == TRUE)
55269 + {
55270 + TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
55271 + TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
55272 + TxHTPhyMode.field.STBC = pAd->ate.TxWI.STBC;
55273 + TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
55274 + TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
55275 + ATEWriteTxWI(pAd, pTxWI, pAd->ate.TxWI.FRAG, pAd->ate.TxWI.TS, pAd->ate.TxWI.AMPDU, pAd->ate.TxWI.ACK, pAd->ate.TxWI.NSEQ,
55276 + pAd->ate.TxWI.BAWinSize, BSSID_WCID, pAd->ate.TxWI.MPDUtotalByteCount/* include 802.11 header */, pAd->ate.TxWI.PacketId, 0, pAd->ate.TxWI.txop/*IFS_HTTXOP*/, pAd->ate.TxWI.CFACK/*FALSE*/, TxHTPhyMode);
55277 + }
55278 + else
55279 + {
55280 + TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
55281 + TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
55282 + TxHTPhyMode.field.STBC = 0;
55283 + TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
55284 + TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
55285 +
55286 + ATEWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE/* No ack required. */, FALSE, 0, BSSID_WCID, pAd->ate.TxLength,
55287 + 0, 0, IFS_HTTXOP, FALSE, TxHTPhyMode);// "MMPS_STATIC" instead of "MMPS_DYNAMIC" ???
55288 + }
55289 +
55290 + RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
55291 +
55292 + pDest = &(pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE+sizeof(HEADER_802_11)]);
55293 +
55294 + // Prepare frame payload
55295 +#ifdef RALINK_28xx_QA
55296 + if (pAd->ate.bQATxStart == TRUE)
55297 + {
55298 + // copy pattern
55299 + if ((pAd->ate.PLen != 0))
55300 + {
55301 + for (j = 0; j < pAd->ate.DLen; j+=pAd->ate.PLen)
55302 + {
55303 + RTMPMoveMemory(pDest, pAd->ate.Pattern, pAd->ate.PLen);
55304 + pDest += pAd->ate.PLen;
55305 + }
55306 + }
55307 + TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxWI.MPDUtotalByteCount;
55308 + }
55309 + else
55310 +#endif // RALINK_28xx_QA //
55311 + {
55312 + for (j = 0; j < (pAd->ate.TxLength - sizeof(HEADER_802_11)); j++)
55313 + {
55314 + *pDest = 0xA5;
55315 + pDest += 1;
55316 + }
55317 + TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxLength;
55318 + }
55319 +
55320 +#if 1
55321 + OrgBufferLength = TransferBufferLength;
55322 + TransferBufferLength = (TransferBufferLength + 3) & (~3);
55323 +
55324 + // Always add 4 extra bytes at every packet.
55325 + padLen = TransferBufferLength - OrgBufferLength + 4;/* 4 == last packet padding */
55326 + ASSERT((padLen <= (RTMP_PKT_TAIL_PADDING - 4/* 4 == MaxBulkOutsize alignment padding */)));
55327 +
55328 + /* Now memzero all extra padding bytes. */
55329 + NdisZeroMemory(pDest, padLen);
55330 + pDest += padLen;
55331 +#else
55332 + if ((TransferBufferLength % 4) == 1)
55333 + {
55334 + NdisZeroMemory(pDest, 7);
55335 + pDest += 7;
55336 + TransferBufferLength += 3;
55337 + }
55338 + else if ((TransferBufferLength % 4) == 2)
55339 + {
55340 + NdisZeroMemory(pDest, 6);
55341 + pDest += 6;
55342 + TransferBufferLength += 2;
55343 + }
55344 + else if ((TransferBufferLength % 4) == 3)
55345 + {
55346 + NdisZeroMemory(pDest, 5);
55347 + pDest += 5;
55348 + TransferBufferLength += 1;
55349 + }
55350 +#endif // 1 //
55351 +
55352 + // Update pTxInfo->USBDMATxPktLen to include padding.
55353 + pTxInfo->USBDMATxPktLen = TransferBufferLength - TXINFO_SIZE;
55354 +
55355 + TransferBufferLength += 4;
55356 +
55357 + // If TransferBufferLength is multiple of 64, add extra 4 bytes again.
55358 + if ((TransferBufferLength % pAd->BulkOutMaxPacketSize) == 0)
55359 + {
55360 + NdisZeroMemory(pDest, 4);
55361 + TransferBufferLength += 4;
55362 + }
55363 +
55364 + // Fill out frame length information for global Bulk out arbitor
55365 + pAd->NullContext.BulkOutSize = TransferBufferLength;
55366 + }
55367 +#ifdef RT_BIG_ENDIAN
55368 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
55369 + RTMPFrameEndianChange(pAd, (((PUCHAR)pTxInfo)+TXWI_SIZE+TXINFO_SIZE), DIR_WRITE, FALSE);
55370 + RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
55371 +#endif // RT_BIG_ENDIAN //
55372 + return 0;
55373 +}
55374 +
55375 +VOID ATE_RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
55376 +{
55377 + PRTMP_ADAPTER pAd;
55378 + PTX_CONTEXT pNullContext;
55379 + UCHAR BulkOutPipeId;
55380 + NTSTATUS Status;
55381 + unsigned long IrqFlags;
55382 + ULONG OldValue;
55383 +
55384 + pNullContext = (PTX_CONTEXT)pUrb->context;
55385 + pAd = pNullContext->pAd;
55386 +
55387 +
55388 + // Reset Null frame context flags
55389 + pNullContext->IRPPending = FALSE;
55390 + pNullContext->InUse = FALSE;
55391 + Status = pUrb->status;
55392 +
55393 + // Store BulkOut PipeId
55394 + BulkOutPipeId = pNullContext->BulkOutPipeId;
55395 + pAd->BulkOutDataOneSecCount++;
55396 +
55397 + if (Status == USB_ST_NOERROR)
55398 + {
55399 +#ifdef RALINK_28xx_QA
55400 + if ((ATE_ON(pAd)) && (pAd->ate.bQATxStart == TRUE))
55401 + {
55402 + if (pAd->ate.QID == BulkOutPipeId)
55403 + {
55404 + // Let Rx can have a chance to break in during Tx process,
55405 + // especially for loopback mode in QA ATE.
55406 + // To trade off between tx performance and loopback mode integrity.
55407 + /* Q : Now Rx is handled by tasklet, do we still need this delay ? */
55408 + /* Ans : Even tasklet is used, Rx/Tx < 1 if we do not delay for a while right here. */
55409 + RTMPusecDelay(500);
55410 + pAd->ate.TxDoneCount++;
55411 + pAd->RalinkCounters.KickTxCount++;
55412 + ASSERT(pAd->ate.QID == 0);
55413 + pAd->ate.TxAc0++;
55414 + }
55415 + }
55416 +#endif // RALINK_28xx_QA //
55417 + pAd->BulkOutComplete++;
55418 +
55419 + pAd->Counters8023.GoodTransmits++;
55420 +
55421 + /* Don't worry about the queue is empty or not. This function will check itself. */
55422 + RTMPDeQueuePacket(pAd, TRUE, BulkOutPipeId, MAX_TX_PROCESS);
55423 +
55424 + /* In 28xx, SendTxWaitQueue ==> TxSwQueue */
55425 +/*
55426 + if (pAd->SendTxWaitQueue[BulkOutPipeId].Number > 0)
55427 + {
55428 + RTMPDeQueuePacket(pAd, BulkOutPipeId);
55429 + }
55430 +*/
55431 + }
55432 + else // STATUS_OTHER
55433 + {
55434 + pAd->BulkOutCompleteOther++;
55435 +
55436 + ATEDBGPRINT(RT_DEBUG_ERROR, ("BulkOutDataPacket Failed STATUS_OTHER = 0x%x . \n", Status));
55437 + ATEDBGPRINT(RT_DEBUG_ERROR, (">>BulkOutReq=0x%lx, BulkOutComplete=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete));
55438 +
55439 + if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
55440 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
55441 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
55442 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
55443 + {
55444 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
55445 + /* In 28xx, RT_OID_USB_RESET_BULK_OUT ==> CMDTHREAD_RESET_BULK_OUT */
55446 + RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
55447 + // Check
55448 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55449 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
55450 + pAd->bulkResetPipeid = BulkOutPipeId;
55451 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55452 + return;
55453 + }
55454 + }
55455 +
55456 +
55457 +
55458 + if (atomic_read(&pAd->BulkOutRemained) > 0)
55459 + {
55460 + atomic_dec(&pAd->BulkOutRemained);
55461 + }
55462 +
55463 + // 1st - Transmit Success
55464 + OldValue = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart;
55465 + pAd->WlanCounters.TransmittedFragmentCount.u.LowPart++;
55466 +
55467 + if (pAd->WlanCounters.TransmittedFragmentCount.u.LowPart < OldValue)
55468 + {
55469 + pAd->WlanCounters.TransmittedFragmentCount.u.HighPart++;
55470 + }
55471 +
55472 + if(((pAd->ContinBulkOut == TRUE ) ||(atomic_read(&pAd->BulkOutRemained) > 0)) && (pAd->ate.Mode & ATE_TXFRAME))
55473 + {
55474 + RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
55475 + }
55476 + else
55477 + {
55478 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
55479 +#ifdef RALINK_28xx_QA
55480 + pAd->ate.TxStatus = 0;
55481 +#endif // RALINK_28xx_QA //
55482 + }
55483 +
55484 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55485 + pAd->BulkOutPending[BulkOutPipeId] = FALSE;
55486 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55487 +
55488 + // Always call Bulk routine, even reset bulk.
55489 + // The protection of rest bulk should be in BulkOut routine.
55490 + RTUSBKickBulkOut(pAd);
55491 +}
55492 +
55493 +/*
55494 + ========================================================================
55495 +
55496 + Routine Description:
55497 +
55498 + Arguments:
55499 +
55500 + Return Value:
55501 +
55502 + Note:
55503 +
55504 + ========================================================================
55505 +*/
55506 +VOID ATE_RTUSBBulkOutDataPacket(
55507 + IN PRTMP_ADAPTER pAd,
55508 + IN UCHAR BulkOutPipeId)
55509 +{
55510 + PTX_CONTEXT pNullContext = &(pAd->NullContext);
55511 + PURB pUrb;
55512 + int ret = 0;
55513 + unsigned long IrqFlags;
55514 +
55515 +
55516 + ASSERT(BulkOutPipeId == 0);
55517 +
55518 + /* Build up the frame first. */
55519 +// ATESetUpFrame(pAd, 0);
55520 +
55521 + BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55522 +
55523 + if (pAd->BulkOutPending[BulkOutPipeId] == TRUE)
55524 + {
55525 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55526 + return;
55527 + }
55528 +
55529 + pAd->BulkOutPending[BulkOutPipeId] = TRUE;
55530 + BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
55531 +
55532 + // Increase Total transmit byte counter
55533 + pAd->RalinkCounters.OneSecTransmittedByteCount += pNullContext->BulkOutSize;
55534 + pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
55535 +
55536 + // Clear ATE frame bulk out flag
55537 + RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
55538 +
55539 + // Init Tx context descriptor
55540 + pNullContext->IRPPending = TRUE;
55541 + RTUSBInitTxDesc(pAd, pNullContext, BulkOutPipeId, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
55542 + pUrb = pNullContext->pUrb;
55543 +
55544 + if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
55545 + {
55546 + ATEDBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
55547 + return;
55548 + }
55549 +
55550 + pAd->BulkOutReq++;
55551 + return;
55552 +
55553 +}
55554 +
55555 +/*
55556 + ========================================================================
55557 +
55558 + Routine Description:
55559 +
55560 + Arguments:
55561 +
55562 + Return Value:
55563 +
55564 + Note:
55565 +
55566 + ========================================================================
55567 +*/
55568 +VOID ATE_RTUSBCancelPendingBulkInIRP(
55569 + IN PRTMP_ADAPTER pAd)
55570 +{
55571 + PRX_CONTEXT pRxContext;
55572 + UINT i;
55573 +
55574 + ATEDBGPRINT(RT_DEBUG_TRACE, ("--->ATE_RTUSBCancelPendingBulkInIRP\n"));
55575 +#if 1
55576 + for ( i = 0; i < (RX_RING_SIZE); i++)
55577 + {
55578 + pRxContext = &(pAd->RxContext[i]);
55579 + if(pRxContext->IRPPending == TRUE)
55580 + {
55581 + RTUSB_UNLINK_URB(pRxContext->pUrb);
55582 + pRxContext->IRPPending = FALSE;
55583 + pRxContext->InUse = FALSE;
55584 + //NdisInterlockedDecrement(&pAd->PendingRx);
55585 + //pAd->PendingRx--;
55586 + }
55587 + }
55588 +#else
55589 + for ( i = 0; i < (RX_RING_SIZE); i++)
55590 + {
55591 + pRxContext = &(pAd->RxContext[i]);
55592 + if(atomic_read(&pRxContext->IrpLock) == IRPLOCK_CANCELABLE)
55593 + {
55594 + RTUSB_UNLINK_URB(pRxContext->pUrb);
55595 + }
55596 + InterlockedExchange(&pRxContext->IrpLock, IRPLOCK_CANCE_START);
55597 + }
55598 +#endif // 1 //
55599 + ATEDBGPRINT(RT_DEBUG_TRACE, ("<---ATE_RTUSBCancelPendingBulkInIRP\n"));
55600 + return;
55601 +}
55602 +#endif // RT2870 //
55603 +
55604 +VOID rt_ee_read_all(PRTMP_ADAPTER pAd, USHORT *Data)
55605 +{
55606 + USHORT i;
55607 + USHORT value;
55608 +
55609 + for (i = 0 ; i < EEPROM_SIZE/2 ; )
55610 + {
55611 + /* "value" is expecially for some compilers... */
55612 + RT28xx_EEPROM_READ16(pAd, i*2, value);
55613 + Data[i] = value;
55614 + i++;
55615 + }
55616 +}
55617 +
55618 +VOID rt_ee_write_all(PRTMP_ADAPTER pAd, USHORT *Data)
55619 +{
55620 + USHORT i;
55621 + USHORT value;
55622 +
55623 + for (i = 0 ; i < EEPROM_SIZE/2 ; )
55624 + {
55625 + /* "value" is expecially for some compilers... */
55626 + value = Data[i];
55627 + RT28xx_EEPROM_WRITE16(pAd, i*2, value);
55628 + i ++;
55629 + }
55630 +}
55631 +#ifdef RALINK_28xx_QA
55632 +VOID ATE_QA_Statistics(
55633 + IN PRTMP_ADAPTER pAd,
55634 + IN PRXWI_STRUC pRxWI,
55635 + IN PRT28XX_RXD_STRUC pRxD,
55636 + IN PHEADER_802_11 pHeader)
55637 +{
55638 + // update counter first
55639 + if (pHeader != NULL)
55640 + {
55641 + if (pHeader->FC.Type == BTYPE_DATA)
55642 + {
55643 + if (pRxD->U2M)
55644 + pAd->ate.U2M++;
55645 + else
55646 + pAd->ate.OtherData++;
55647 + }
55648 + else if (pHeader->FC.Type == BTYPE_MGMT)
55649 + {
55650 + if (pHeader->FC.SubType == SUBTYPE_BEACON)
55651 + pAd->ate.Beacon++;
55652 + else
55653 + pAd->ate.OtherCount++;
55654 + }
55655 + else if (pHeader->FC.Type == BTYPE_CNTL)
55656 + {
55657 + pAd->ate.OtherCount++;
55658 + }
55659 + }
55660 + pAd->ate.RSSI0 = pRxWI->RSSI0;
55661 + pAd->ate.RSSI1 = pRxWI->RSSI1;
55662 + pAd->ate.RSSI2 = pRxWI->RSSI2;
55663 + pAd->ate.SNR0 = pRxWI->SNR0;
55664 + pAd->ate.SNR1 = pRxWI->SNR1;
55665 +}
55666 +
55667 +/* command id with Cmd Type == 0x0008(for 28xx)/0x0005(for iNIC) */
55668 +#define RACFG_CMD_RF_WRITE_ALL 0x0000
55669 +#define RACFG_CMD_E2PROM_READ16 0x0001
55670 +#define RACFG_CMD_E2PROM_WRITE16 0x0002
55671 +#define RACFG_CMD_E2PROM_READ_ALL 0x0003
55672 +#define RACFG_CMD_E2PROM_WRITE_ALL 0x0004
55673 +#define RACFG_CMD_IO_READ 0x0005
55674 +#define RACFG_CMD_IO_WRITE 0x0006
55675 +#define RACFG_CMD_IO_READ_BULK 0x0007
55676 +#define RACFG_CMD_BBP_READ8 0x0008
55677 +#define RACFG_CMD_BBP_WRITE8 0x0009
55678 +#define RACFG_CMD_BBP_READ_ALL 0x000a
55679 +#define RACFG_CMD_GET_COUNTER 0x000b
55680 +#define RACFG_CMD_CLEAR_COUNTER 0x000c
55681 +
55682 +#define RACFG_CMD_RSV1 0x000d
55683 +#define RACFG_CMD_RSV2 0x000e
55684 +#define RACFG_CMD_RSV3 0x000f
55685 +
55686 +#define RACFG_CMD_TX_START 0x0010
55687 +#define RACFG_CMD_GET_TX_STATUS 0x0011
55688 +#define RACFG_CMD_TX_STOP 0x0012
55689 +#define RACFG_CMD_RX_START 0x0013
55690 +#define RACFG_CMD_RX_STOP 0x0014
55691 +#define RACFG_CMD_GET_NOISE_LEVEL 0x0015
55692 +
55693 +#define RACFG_CMD_ATE_START 0x0080
55694 +#define RACFG_CMD_ATE_STOP 0x0081
55695 +
55696 +#define RACFG_CMD_ATE_START_TX_CARRIER 0x0100
55697 +#define RACFG_CMD_ATE_START_TX_CONT 0x0101
55698 +#define RACFG_CMD_ATE_START_TX_FRAME 0x0102
55699 +#define RACFG_CMD_ATE_SET_BW 0x0103
55700 +#define RACFG_CMD_ATE_SET_TX_POWER0 0x0104
55701 +#define RACFG_CMD_ATE_SET_TX_POWER1 0x0105
55702 +#define RACFG_CMD_ATE_SET_FREQ_OFFSET 0x0106
55703 +#define RACFG_CMD_ATE_GET_STATISTICS 0x0107
55704 +#define RACFG_CMD_ATE_RESET_COUNTER 0x0108
55705 +#define RACFG_CMD_ATE_SEL_TX_ANTENNA 0x0109
55706 +#define RACFG_CMD_ATE_SEL_RX_ANTENNA 0x010a
55707 +#define RACFG_CMD_ATE_SET_PREAMBLE 0x010b
55708 +#define RACFG_CMD_ATE_SET_CHANNEL 0x010c
55709 +#define RACFG_CMD_ATE_SET_ADDR1 0x010d
55710 +#define RACFG_CMD_ATE_SET_ADDR2 0x010e
55711 +#define RACFG_CMD_ATE_SET_ADDR3 0x010f
55712 +#define RACFG_CMD_ATE_SET_RATE 0x0110
55713 +#define RACFG_CMD_ATE_SET_TX_FRAME_LEN 0x0111
55714 +#define RACFG_CMD_ATE_SET_TX_FRAME_COUNT 0x0112
55715 +#define RACFG_CMD_ATE_START_RX_FRAME 0x0113
55716 +#define RACFG_CMD_ATE_E2PROM_READ_BULK 0x0114
55717 +#define RACFG_CMD_ATE_E2PROM_WRITE_BULK 0x0115
55718 +#define RACFG_CMD_ATE_IO_WRITE_BULK 0x0116
55719 +#define RACFG_CMD_ATE_BBP_READ_BULK 0x0117
55720 +#define RACFG_CMD_ATE_BBP_WRITE_BULK 0x0118
55721 +#define RACFG_CMD_ATE_RF_READ_BULK 0x0119
55722 +#define RACFG_CMD_ATE_RF_WRITE_BULK 0x011a
55723 +
55724 +
55725 +
55726 +#define A2Hex(_X, _p) \
55727 +{ \
55728 + UCHAR *p; \
55729 + _X = 0; \
55730 + p = _p; \
55731 + while (((*p >= 'a') && (*p <= 'f')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= '0') && (*p <= '9'))) \
55732 + { \
55733 + if ((*p >= 'a') && (*p <= 'f')) \
55734 + _X = _X * 16 + *p - 87; \
55735 + else if ((*p >= 'A') && (*p <= 'F')) \
55736 + _X = _X * 16 + *p - 55; \
55737 + else if ((*p >= '0') && (*p <= '9')) \
55738 + _X = _X * 16 + *p - 48; \
55739 + p++; \
55740 + } \
55741 +}
55742 +
55743 +
55744 +static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
55745 +static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
55746 +static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len);
55747 +
55748 +#ifdef UCOS
55749 +int ate_copy_to_user(
55750 + IN PUCHAR payload,
55751 + IN PUCHAR msg,
55752 + IN INT len)
55753 +{
55754 + memmove(payload, msg, len);
55755 + return 0;
55756 +}
55757 +
55758 +#undef copy_to_user
55759 +#define copy_to_user(x,y,z) ate_copy_to_user((PUCHAR)x, (PUCHAR)y, z)
55760 +#endif // UCOS //
55761 +
55762 +#define LEN_OF_ARG 16
55763 +
55764 +VOID RtmpDoAte(
55765 + IN PRTMP_ADAPTER pAdapter,
55766 + IN struct iwreq *wrq)
55767 +{
55768 + unsigned short Command_Id;
55769 + struct ate_racfghdr *pRaCfg;
55770 + INT Status = NDIS_STATUS_SUCCESS;
55771 +
55772 +
55773 +
55774 + if((pRaCfg = kmalloc(sizeof(struct ate_racfghdr), GFP_KERNEL)) == NULL)
55775 + {
55776 + Status = -EINVAL;
55777 + return;
55778 + }
55779 +
55780 + NdisZeroMemory(pRaCfg, sizeof(struct ate_racfghdr));
55781 +
55782 + if (copy_from_user((PUCHAR)pRaCfg, wrq->u.data.pointer, wrq->u.data.length))
55783 + {
55784 + Status = -EFAULT;
55785 + kfree(pRaCfg);
55786 + return;
55787 + }
55788 +
55789 +
55790 + Command_Id = ntohs(pRaCfg->command_id);
55791 +
55792 + ATEDBGPRINT(RT_DEBUG_TRACE,("\n%s: Command_Id = 0x%04x !\n", __FUNCTION__, Command_Id));
55793 +
55794 + switch (Command_Id)
55795 + {
55796 + // We will get this command when QA starts.
55797 + case RACFG_CMD_ATE_START:
55798 + {
55799 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START\n"));
55800 +
55801 + // prepare feedback as soon as we can to avoid QA timeout.
55802 + pRaCfg->length = htons(2);
55803 + pRaCfg->status = htons(0);
55804 +
55805 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55806 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55807 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55808 +
55809 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55810 +
55811 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55812 + {
55813 + ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_ATE_START\n"));
55814 + Status = -EFAULT;
55815 + }
55816 + else
55817 + {
55818 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START is done !\n"));
55819 + }
55820 + Set_ATE_Proc(pAdapter, "ATESTART");
55821 + }
55822 + break;
55823 +
55824 + // We will get this command either QA is closed or ated is killed by user.
55825 + case RACFG_CMD_ATE_STOP:
55826 + {
55827 +#ifndef UCOS
55828 + INT32 ret;
55829 +#endif // !UCOS //
55830 +
55831 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_STOP\n"));
55832 +
55833 + // Distinguish this command came from QA(via ated)
55834 + // or ate daemon according to the existence of pid in payload.
55835 + // No need to prepare feedback if this cmd came directly from ate daemon.
55836 + pRaCfg->length = ntohs(pRaCfg->length);
55837 +
55838 + if (pRaCfg->length == sizeof(pAdapter->ate.AtePid))
55839 + {
55840 + // This command came from QA.
55841 + // Get the pid of ATE daemon.
55842 + memcpy((UCHAR *)&pAdapter->ate.AtePid,
55843 + (&pRaCfg->data[0]) - 2/* == &(pRaCfg->status) */,
55844 + sizeof(pAdapter->ate.AtePid));
55845 +
55846 + // prepare feedback as soon as we can to avoid QA timeout.
55847 + pRaCfg->length = htons(2);
55848 + pRaCfg->status = htons(0);
55849 +
55850 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55851 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55852 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55853 +
55854 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55855 +
55856 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55857 + {
55858 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_STOP\n"));
55859 + Status = -EFAULT;
55860 + }
55861 +
55862 + //
55863 + // kill ATE daemon when leaving ATE mode.
55864 + // We must kill ATE daemon first before setting ATESTOP,
55865 + // or Microsoft will report sth. wrong.
55866 +#ifndef UCOS
55867 + ret = kill_proc(pAdapter->ate.AtePid, SIGTERM, 1);
55868 + if (ret)
55869 + {
55870 + ATEDBGPRINT(RT_DEBUG_ERROR, ("%s: unable to signal thread\n", pAdapter->net_dev->name));
55871 + }
55872 +#endif // !UCOS //
55873 + }
55874 +
55875 +#ifdef UCOS
55876 + // Roger add to avoid error message after close QA
55877 + if (pAdapter->CSRBaseAddress == RT2860_CSR_ADDR)
55878 + {
55879 +
55880 + // prepare feedback as soon as we can to avoid QA timeout.
55881 + pRaCfg->length = htons(2);
55882 + pRaCfg->status = htons(0);
55883 +
55884 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55885 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55886 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55887 +
55888 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55889 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55890 + {
55891 + ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_AP_START\n"));
55892 + Status = -EFAULT;
55893 + }
55894 + }
55895 +#endif // UCOS //
55896 +
55897 + // AP might have in ATE_STOP mode due to cmd from QA.
55898 + if (ATE_ON(pAdapter))
55899 + {
55900 + // Someone has killed ate daemon while QA GUI is still open.
55901 + Set_ATE_Proc(pAdapter, "ATESTOP");
55902 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_AP_START is done !\n"));
55903 + }
55904 + }
55905 + break;
55906 +
55907 + case RACFG_CMD_RF_WRITE_ALL:
55908 + {
55909 + UINT32 R1, R2, R3, R4;
55910 + USHORT channel;
55911 +
55912 + memcpy(&R1, pRaCfg->data-2, 4);
55913 + memcpy(&R2, pRaCfg->data+2, 4);
55914 + memcpy(&R3, pRaCfg->data+6, 4);
55915 + memcpy(&R4, pRaCfg->data+10, 4);
55916 + memcpy(&channel, pRaCfg->data+14, 2);
55917 +
55918 + pAdapter->LatchRfRegs.R1 = ntohl(R1);
55919 + pAdapter->LatchRfRegs.R2 = ntohl(R2);
55920 + pAdapter->LatchRfRegs.R3 = ntohl(R3);
55921 + pAdapter->LatchRfRegs.R4 = ntohl(R4);
55922 + pAdapter->LatchRfRegs.Channel = ntohs(channel);
55923 +
55924 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R1);
55925 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R2);
55926 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R3);
55927 + RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R4);
55928 +
55929 + // prepare feedback
55930 + pRaCfg->length = htons(2);
55931 + pRaCfg->status = htons(0);
55932 +
55933 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55934 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55935 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55936 +
55937 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55938 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55939 + {
55940 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RF_WRITE_ALL\n"));
55941 + Status = -EFAULT;
55942 + }
55943 + else
55944 + {
55945 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RF_WRITE_ALL is done !\n"));
55946 + }
55947 + }
55948 + break;
55949 +
55950 + case RACFG_CMD_E2PROM_READ16:
55951 + {
55952 + USHORT offset, value, tmp;
55953 +
55954 + offset = ntohs(pRaCfg->status);
55955 + /* "tmp" is expecially for some compilers... */
55956 + RT28xx_EEPROM_READ16(pAdapter, offset, tmp);
55957 + value = tmp;
55958 + value = htons(value);
55959 +
55960 + ATEDBGPRINT(RT_DEBUG_TRACE,("EEPROM Read offset = 0x%04x, value = 0x%04x\n", offset, value));
55961 +
55962 + // prepare feedback
55963 + pRaCfg->length = htons(4);
55964 + pRaCfg->status = htons(0);
55965 + memcpy(pRaCfg->data, &value, 2);
55966 +
55967 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55968 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
55969 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
55970 +
55971 + ATEDBGPRINT(RT_DEBUG_TRACE, ("sizeof(struct ate_racfghdr) = %d\n", sizeof(struct ate_racfghdr)));
55972 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
55973 +
55974 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
55975 + {
55976 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ16\n"));
55977 + Status = -EFAULT;
55978 + }
55979 + else
55980 + {
55981 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ16 is done !\n"));
55982 + }
55983 + }
55984 + break;
55985 +
55986 + case RACFG_CMD_E2PROM_WRITE16:
55987 + {
55988 + USHORT offset, value;
55989 +
55990 + offset = ntohs(pRaCfg->status);
55991 + memcpy(&value, pRaCfg->data, 2);
55992 + value = ntohs(value);
55993 + RT28xx_EEPROM_WRITE16(pAdapter, offset, value);
55994 +
55995 + // prepare feedback
55996 + pRaCfg->length = htons(2);
55997 + pRaCfg->status = htons(0);
55998 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
55999 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56000 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56001 +
56002 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56003 + {
56004 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE16\n"));
56005 + Status = -EFAULT;
56006 + }
56007 + else
56008 + {
56009 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_WRITE16 is done !\n"));
56010 + }
56011 + }
56012 + break;
56013 +
56014 + case RACFG_CMD_E2PROM_READ_ALL:
56015 + {
56016 + USHORT buffer[EEPROM_SIZE/2];
56017 +
56018 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
56019 + memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer, EEPROM_SIZE);
56020 +
56021 + // prepare feedback
56022 + pRaCfg->length = htons(2+EEPROM_SIZE);
56023 + pRaCfg->status = htons(0);
56024 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56025 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56026 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56027 +
56028 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56029 + {
56030 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ_ALL\n"));
56031 + Status = -EFAULT;
56032 + }
56033 + else
56034 + {
56035 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ_ALL is done !\n"));
56036 + }
56037 + }
56038 + break;
56039 +
56040 + case RACFG_CMD_E2PROM_WRITE_ALL:
56041 + {
56042 + USHORT buffer[EEPROM_SIZE/2];
56043 +
56044 + NdisZeroMemory((UCHAR *)buffer, EEPROM_SIZE);
56045 + memcpy_exs(pAdapter, (UCHAR *)buffer, (UCHAR *)&pRaCfg->status, EEPROM_SIZE);
56046 + rt_ee_write_all(pAdapter,(USHORT *)buffer);
56047 +
56048 + // prepare feedback
56049 + pRaCfg->length = htons(2);
56050 + pRaCfg->status = htons(0);
56051 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56052 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56053 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56054 +
56055 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56056 + {
56057 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE_ALL\n"));
56058 + Status = -EFAULT;
56059 + }
56060 + else
56061 + {
56062 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_E2PROM_WRITE_ALL is done !\n"));
56063 + }
56064 +
56065 + }
56066 + break;
56067 +
56068 + case RACFG_CMD_IO_READ:
56069 + {
56070 + UINT32 offset;
56071 + UINT32 value;
56072 +
56073 + memcpy(&offset, &pRaCfg->status, 4);
56074 + offset = ntohl(offset);
56075 +
56076 + // We do not need the base address.
56077 + // So just extract the offset out.
56078 + offset &= 0x0000FFFF;
56079 + RTMP_IO_READ32(pAdapter, offset, &value);
56080 + value = htonl(value);
56081 +
56082 + // prepare feedback
56083 + pRaCfg->length = htons(6);
56084 + pRaCfg->status = htons(0);
56085 + memcpy(pRaCfg->data, &value, 4);
56086 +
56087 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56088 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56089 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56090 +
56091 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56092 + {
56093 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ\n"));
56094 + Status = -EFAULT;
56095 + }
56096 + else
56097 + {
56098 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ is done !\n"));
56099 + }
56100 + }
56101 + break;
56102 +
56103 + case RACFG_CMD_IO_WRITE:
56104 + {
56105 + UINT32 offset, value;
56106 +
56107 + memcpy(&offset, pRaCfg->data-2, 4);
56108 + memcpy(&value, pRaCfg->data+2, 4);
56109 +
56110 + offset = ntohl(offset);
56111 +
56112 + // We do not need the base address.
56113 + // So just extract out the offset.
56114 + offset &= 0x0000FFFF;
56115 + value = ntohl(value);
56116 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_IO_WRITE: offset = %x, value = %x\n", offset, value));
56117 + RTMP_IO_WRITE32(pAdapter, offset, value);
56118 +
56119 + // prepare feedback
56120 + pRaCfg->length = htons(2);
56121 + pRaCfg->status = htons(0);
56122 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56123 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56124 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56125 +
56126 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56127 + {
56128 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_WRITE\n"));
56129 + Status = -EFAULT;
56130 + }
56131 + else
56132 + {
56133 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_WRITE is done !\n"));
56134 + }
56135 + }
56136 + break;
56137 +
56138 + case RACFG_CMD_IO_READ_BULK:
56139 + {
56140 + UINT32 offset;
56141 + USHORT len;
56142 +
56143 + memcpy(&offset, &pRaCfg->status, 4);
56144 + offset = ntohl(offset);
56145 +
56146 + // We do not need the base address.
56147 + // So just extract the offset.
56148 + offset &= 0x0000FFFF;
56149 + memcpy(&len, pRaCfg->data+2, 2);
56150 + len = ntohs(len);
56151 +
56152 + if (len > 371)
56153 + {
56154 + ATEDBGPRINT(RT_DEBUG_TRACE,("len is too large, make it smaller\n"));
56155 + pRaCfg->length = htons(2);
56156 + pRaCfg->status = htons(1);
56157 + break;
56158 + }
56159 +
56160 + RTMP_IO_READ_BULK(pAdapter, pRaCfg->data, (UCHAR *)offset, len*4);// unit in four bytes
56161 +
56162 + // prepare feedback
56163 + pRaCfg->length = htons(2+len*4);// unit in four bytes
56164 + pRaCfg->status = htons(0);
56165 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56166 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56167 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56168 +
56169 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56170 + {
56171 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ_BULK\n"));
56172 + Status = -EFAULT;
56173 + }
56174 + else
56175 + {
56176 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ_BULK is done !\n"));
56177 + }
56178 + }
56179 + break;
56180 +
56181 + case RACFG_CMD_BBP_READ8:
56182 + {
56183 + USHORT offset;
56184 + UCHAR value;
56185 +
56186 + value = 0;
56187 + offset = ntohs(pRaCfg->status);
56188 +
56189 + if (ATE_ON(pAdapter))
56190 + {
56191 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
56192 + }
56193 + else
56194 + {
56195 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
56196 + }
56197 + // prepare feedback
56198 + pRaCfg->length = htons(3);
56199 + pRaCfg->status = htons(0);
56200 + pRaCfg->data[0] = value;
56201 +
56202 + ATEDBGPRINT(RT_DEBUG_TRACE,("BBP value = %x\n", value));
56203 +
56204 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56205 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56206 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56207 +
56208 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56209 + {
56210 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ8\n"));
56211 + Status = -EFAULT;
56212 + }
56213 + else
56214 + {
56215 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ8 is done !\n"));
56216 + }
56217 + }
56218 + break;
56219 + case RACFG_CMD_BBP_WRITE8:
56220 + {
56221 + USHORT offset;
56222 + UCHAR value;
56223 +
56224 + offset = ntohs(pRaCfg->status);
56225 + memcpy(&value, pRaCfg->data, 1);
56226 +
56227 + if (ATE_ON(pAdapter))
56228 + {
56229 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
56230 + }
56231 + else
56232 + {
56233 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
56234 + }
56235 +
56236 + if ((offset == BBP_R1) || (offset == BBP_R3))
56237 + {
56238 + SyncTxRxConfig(pAdapter, offset, value);
56239 + }
56240 +
56241 + // prepare feedback
56242 + pRaCfg->length = htons(2);
56243 + pRaCfg->status = htons(0);
56244 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56245 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56246 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56247 +
56248 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56249 + {
56250 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_WRITE8\n"));
56251 + Status = -EFAULT;
56252 + }
56253 + else
56254 + {
56255 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_WRITE8 is done !\n"));
56256 + }
56257 + }
56258 + break;
56259 +
56260 + case RACFG_CMD_BBP_READ_ALL:
56261 + {
56262 + USHORT j;
56263 +
56264 + for (j = 0; j < 137; j++)
56265 + {
56266 + pRaCfg->data[j] = 0;
56267 +
56268 + if (ATE_ON(pAdapter))
56269 + {
56270 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
56271 + }
56272 + else
56273 + {
56274 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
56275 + }
56276 + }
56277 +
56278 + // prepare feedback
56279 + pRaCfg->length = htons(2+137);
56280 + pRaCfg->status = htons(0);
56281 +
56282 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56283 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56284 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56285 +
56286 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56287 + {
56288 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ_ALL\n"));
56289 + Status = -EFAULT;
56290 + }
56291 + else
56292 + {
56293 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ_ALL is done !\n"));
56294 + }
56295 + }
56296 +
56297 + break;
56298 +
56299 + case RACFG_CMD_ATE_E2PROM_READ_BULK:
56300 + {
56301 + USHORT offset;
56302 + USHORT len;
56303 + USHORT buffer[EEPROM_SIZE/2];
56304 +
56305 + offset = ntohs(pRaCfg->status);
56306 + memcpy(&len, pRaCfg->data, 2);
56307 + len = ntohs(len);
56308 +
56309 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
56310 + if (offset + len <= EEPROM_SIZE)
56311 + memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer+offset, len);
56312 + else
56313 + ATEDBGPRINT(RT_DEBUG_ERROR, ("exceed EEPROM size\n"));
56314 +
56315 + // prepare feedback
56316 + pRaCfg->length = htons(2+len);
56317 + pRaCfg->status = htons(0);
56318 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56319 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56320 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56321 +
56322 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56323 + {
56324 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_READ_BULK\n"));
56325 + Status = -EFAULT;
56326 + }
56327 + else
56328 + {
56329 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_E2PROM_READ_BULK is done !\n"));
56330 + }
56331 +
56332 + }
56333 + break;
56334 +
56335 + case RACFG_CMD_ATE_E2PROM_WRITE_BULK:
56336 + {
56337 + USHORT offset;
56338 + USHORT len;
56339 + USHORT buffer[EEPROM_SIZE/2];
56340 +
56341 + offset = ntohs(pRaCfg->status);
56342 + memcpy(&len, pRaCfg->data, 2);
56343 + len = ntohs(len);
56344 +
56345 + rt_ee_read_all(pAdapter,(USHORT *)buffer);
56346 + memcpy_exs(pAdapter, (UCHAR *)buffer + offset, (UCHAR *)pRaCfg->data + 2, len);
56347 + rt_ee_write_all(pAdapter,(USHORT *)buffer);
56348 +
56349 + // prepare feedback
56350 + pRaCfg->length = htons(2);
56351 + pRaCfg->status = htons(0);
56352 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56353 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56354 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56355 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56356 + {
56357 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_WRITE_BULK\n"));
56358 + Status = -EFAULT;
56359 + }
56360 + else
56361 + {
56362 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_E2PROM_WRITE_BULK is done !\n"));
56363 + }
56364 +
56365 + }
56366 + break;
56367 +
56368 + case RACFG_CMD_ATE_IO_WRITE_BULK:
56369 + {
56370 + UINT32 offset, i, value;
56371 + USHORT len;
56372 +
56373 + memcpy(&offset, &pRaCfg->status, 4);
56374 + offset = ntohl(offset);
56375 + memcpy(&len, pRaCfg->data+2, 2);
56376 + len = ntohs(len);
56377 +
56378 + for (i = 0; i < len; i += 4)
56379 + {
56380 + memcpy_exl(pAdapter, (UCHAR *)&value, pRaCfg->data+4+i, 4);
56381 + printk("Write %x %x\n", offset + i, value);
56382 + RTMP_IO_WRITE32(pAdapter, (offset +i) & 0xffff, value);
56383 + }
56384 +
56385 + // prepare feedback
56386 + pRaCfg->length = htons(2);
56387 + pRaCfg->status = htons(0);
56388 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56389 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56390 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56391 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56392 + {
56393 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_IO_WRITE_BULK\n"));
56394 + Status = -EFAULT;
56395 + }
56396 + else
56397 + {
56398 + ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_IO_WRITE_BULK is done !\n"));
56399 + }
56400 +
56401 + }
56402 + break;
56403 +
56404 + case RACFG_CMD_ATE_BBP_READ_BULK:
56405 + {
56406 + USHORT offset;
56407 + USHORT len;
56408 + USHORT j;
56409 +
56410 + offset = ntohs(pRaCfg->status);
56411 + memcpy(&len, pRaCfg->data, 2);
56412 + len = ntohs(len);
56413 +
56414 +
56415 + for (j = offset; j < (offset+len); j++)
56416 + {
56417 + pRaCfg->data[j - offset] = 0;
56418 +
56419 + if (pAdapter->ate.Mode == ATE_STOP)
56420 + {
56421 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
56422 + }
56423 + else
56424 + {
56425 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
56426 + }
56427 + }
56428 +
56429 + // prepare feedback
56430 + pRaCfg->length = htons(2+len);
56431 + pRaCfg->status = htons(0);
56432 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56433 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56434 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56435 +
56436 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56437 + {
56438 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_READ_BULK\n"));
56439 + Status = -EFAULT;
56440 + }
56441 + else
56442 + {
56443 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_READ_BULK is done !\n"));
56444 + }
56445 +
56446 + }
56447 + break;
56448 +
56449 + case RACFG_CMD_ATE_BBP_WRITE_BULK:
56450 + {
56451 + USHORT offset;
56452 + USHORT len;
56453 + USHORT j;
56454 + UCHAR *value;
56455 +
56456 + offset = ntohs(pRaCfg->status);
56457 + memcpy(&len, pRaCfg->data, 2);
56458 + len = ntohs(len);
56459 +
56460 + for (j = offset; j < (offset+len); j++)
56461 + {
56462 + value = pRaCfg->data + 2 + (j - offset);
56463 + if (pAdapter->ate.Mode == ATE_STOP)
56464 + {
56465 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
56466 + }
56467 + else
56468 + {
56469 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
56470 + }
56471 + }
56472 +
56473 + // prepare feedback
56474 + pRaCfg->length = htons(2);
56475 + pRaCfg->status = htons(0);
56476 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56477 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56478 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56479 +
56480 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56481 + {
56482 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_WRITE_BULK\n"));
56483 + Status = -EFAULT;
56484 + }
56485 + else
56486 + {
56487 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_WRITE_BULK is done !\n"));
56488 + }
56489 + }
56490 + break;
56491 +
56492 +#ifdef CONFIG_RALINK_RT3052
56493 + case RACFG_CMD_ATE_RF_READ_BULK:
56494 + {
56495 + USHORT offset;
56496 + USHORT len;
56497 + USHORT j;
56498 +
56499 + offset = ntohs(pRaCfg->status);
56500 + memcpy(&len, pRaCfg->data, 2);
56501 + len = ntohs(len);
56502 +
56503 + for (j = offset; j < (offset+len); j++)
56504 + {
56505 + pRaCfg->data[j - offset] = 0;
56506 + RT30xxReadRFRegister(pAdapter, j, &pRaCfg->data[j - offset]);
56507 + }
56508 +
56509 + // prepare feedback
56510 + pRaCfg->length = htons(2+len);
56511 + pRaCfg->status = htons(0);
56512 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56513 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56514 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56515 +
56516 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56517 + {
56518 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_READ_BULK\n"));
56519 + Status = -EFAULT;
56520 + }
56521 + else
56522 + {
56523 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_READ_BULK is done !\n"));
56524 + }
56525 +
56526 + }
56527 + break;
56528 +
56529 + case RACFG_CMD_ATE_RF_WRITE_BULK:
56530 + {
56531 + USHORT offset;
56532 + USHORT len;
56533 + USHORT j;
56534 + UCHAR *value;
56535 +
56536 + offset = ntohs(pRaCfg->status);
56537 + memcpy(&len, pRaCfg->data, 2);
56538 + len = ntohs(len);
56539 +
56540 + for (j = offset; j < (offset+len); j++)
56541 + {
56542 + value = pRaCfg->data + 2 + (j - offset);
56543 + RT30xxWriteRFRegister(pAdapter, j, *value);
56544 + }
56545 +
56546 + // prepare feedback
56547 + pRaCfg->length = htons(2);
56548 + pRaCfg->status = htons(0);
56549 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56550 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56551 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56552 +
56553 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56554 + {
56555 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_WRITE_BULK\n"));
56556 + Status = -EFAULT;
56557 + }
56558 + else
56559 + {
56560 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_WRITE_BULK is done !\n"));
56561 + }
56562 +
56563 + }
56564 + break;
56565 +#endif
56566 +
56567 +
56568 + case RACFG_CMD_GET_NOISE_LEVEL:
56569 + {
56570 + UCHAR channel;
56571 + INT32 buffer[3][10];/* 3 : RxPath ; 10 : no. of per rssi samples */
56572 +
56573 + channel = (ntohs(pRaCfg->status) & 0x00FF);
56574 + CalNoiseLevel(pAdapter, channel, buffer);
56575 + memcpy_exl(pAdapter, (UCHAR *)pRaCfg->data, (UCHAR *)&(buffer[0][0]), (sizeof(INT32)*3*10));
56576 +
56577 + // prepare feedback
56578 + pRaCfg->length = htons(2 + (sizeof(INT32)*3*10));
56579 + pRaCfg->status = htons(0);
56580 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56581 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56582 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56583 +
56584 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56585 + {
56586 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_NOISE_LEVEL\n"));
56587 + Status = -EFAULT;
56588 + }
56589 + else
56590 + {
56591 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_NOISE_LEVEL is done !\n"));
56592 + }
56593 + }
56594 + break;
56595 +
56596 + case RACFG_CMD_GET_COUNTER:
56597 + {
56598 + memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.U2M, 4);
56599 + memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->ate.OtherData, 4);
56600 + memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->ate.Beacon, 4);
56601 + memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->ate.OtherCount, 4);
56602 + memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->ate.TxAc0, 4);
56603 + memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->ate.TxAc1, 4);
56604 + memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->ate.TxAc2, 4);
56605 + memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->ate.TxAc3, 4);
56606 + memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->ate.TxHCCA, 4);
56607 + memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->ate.TxMgmt, 4);
56608 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&pAdapter->ate.RSSI0, 4);
56609 + memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&pAdapter->ate.RSSI1, 4);
56610 + memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&pAdapter->ate.RSSI2, 4);
56611 + memcpy_exl(pAdapter, &pRaCfg->data[52], (UCHAR *)&pAdapter->ate.SNR0, 4);
56612 + memcpy_exl(pAdapter, &pRaCfg->data[56], (UCHAR *)&pAdapter->ate.SNR1, 4);
56613 +
56614 + pRaCfg->length = htons(2+60);
56615 + pRaCfg->status = htons(0);
56616 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56617 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56618 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56619 +
56620 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56621 + {
56622 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_COUNTER\n"));
56623 + Status = -EFAULT;
56624 + }
56625 + else
56626 + {
56627 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_COUNTER is done !\n"));
56628 + }
56629 + }
56630 + break;
56631 +
56632 + case RACFG_CMD_CLEAR_COUNTER:
56633 + {
56634 + pAdapter->ate.U2M = 0;
56635 + pAdapter->ate.OtherData = 0;
56636 + pAdapter->ate.Beacon = 0;
56637 + pAdapter->ate.OtherCount = 0;
56638 + pAdapter->ate.TxAc0 = 0;
56639 + pAdapter->ate.TxAc1 = 0;
56640 + pAdapter->ate.TxAc2 = 0;
56641 + pAdapter->ate.TxAc3 = 0;
56642 + pAdapter->ate.TxHCCA = 0;
56643 + pAdapter->ate.TxMgmt = 0;
56644 + pAdapter->ate.TxDoneCount = 0;
56645 +
56646 + pRaCfg->length = htons(2);
56647 + pRaCfg->status = htons(0);
56648 +
56649 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56650 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56651 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56652 +
56653 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56654 + {
56655 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_CLEAR_COUNTER\n"));
56656 + Status = -EFAULT;
56657 + }
56658 + else
56659 + {
56660 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_CLEAR_COUNTER is done !\n"));
56661 + }
56662 + }
56663 +
56664 + break;
56665 +
56666 + case RACFG_CMD_TX_START:
56667 + {
56668 + USHORT *p;
56669 + USHORT err = 1;
56670 + UCHAR Bbp22Value = 0, Bbp24Value = 0;
56671 +
56672 + if ((pAdapter->ate.TxStatus != 0) && (pAdapter->ate.Mode & ATE_TXFRAME))
56673 + {
56674 + ATEDBGPRINT(RT_DEBUG_TRACE,("Ate Tx is already running, to run next Tx, you must stop it first\n"));
56675 + err = 2;
56676 + goto TX_START_ERROR;
56677 + }
56678 + else if ((pAdapter->ate.TxStatus != 0) && !(pAdapter->ate.Mode & ATE_TXFRAME))
56679 + {
56680 + int i = 0;
56681 +
56682 + while ((i++ < 10) && (pAdapter->ate.TxStatus != 0))
56683 + {
56684 + RTMPusecDelay(5000);
56685 + }
56686 +
56687 + // force it to stop
56688 + pAdapter->ate.TxStatus = 0;
56689 + pAdapter->ate.TxDoneCount = 0;
56690 + //pAdapter->ate.Repeat = 0;
56691 + pAdapter->ate.bQATxStart = FALSE;
56692 + }
56693 +
56694 + // If pRaCfg->length == 0, this "RACFG_CMD_TX_START" is for Carrier test or Carrier Suppression.
56695 + if (ntohs(pRaCfg->length) != 0)
56696 + {
56697 + // Get frame info
56698 +#ifdef RT2870
56699 + NdisMoveMemory(&pAdapter->ate.TxInfo, pRaCfg->data - 2, 4);
56700 +#ifdef RT_BIG_ENDIAN
56701 + RTMPDescriptorEndianChange((PUCHAR) &pAdapter->ate.TxInfo, TYPE_TXINFO);
56702 +#endif // RT_BIG_ENDIAN //
56703 +#endif // RT2870 //
56704 +
56705 + NdisMoveMemory(&pAdapter->ate.TxWI, pRaCfg->data + 2, 16);
56706 +#ifdef RT_BIG_ENDIAN
56707 + RTMPWIEndianChange((PUCHAR)&pAdapter->ate.TxWI, TYPE_TXWI);
56708 +#endif // RT_BIG_ENDIAN //
56709 +
56710 + NdisMoveMemory(&pAdapter->ate.TxCount, pRaCfg->data + 18, 4);
56711 + pAdapter->ate.TxCount = ntohl(pAdapter->ate.TxCount);
56712 +
56713 + p = (USHORT *)(&pRaCfg->data[22]);
56714 + //p = pRaCfg->data + 22;
56715 + // always use QID_AC_BE
56716 + pAdapter->ate.QID = 0;
56717 + p = (USHORT *)(&pRaCfg->data[24]);
56718 + //p = pRaCfg->data + 24;
56719 + pAdapter->ate.HLen = ntohs(*p);
56720 +
56721 + if (pAdapter->ate.HLen > 32)
56722 + {
56723 + ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.HLen > 32\n"));
56724 + err = 3;
56725 + goto TX_START_ERROR;
56726 + }
56727 +
56728 + NdisMoveMemory(&pAdapter->ate.Header, pRaCfg->data + 26, pAdapter->ate.HLen);
56729 +
56730 +
56731 + pAdapter->ate.PLen = ntohs(pRaCfg->length) - (pAdapter->ate.HLen + 28);
56732 +
56733 + if (pAdapter->ate.PLen > 32)
56734 + {
56735 + ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.PLen > 32\n"));
56736 + err = 4;
56737 + goto TX_START_ERROR;
56738 + }
56739 +
56740 + NdisMoveMemory(&pAdapter->ate.Pattern, pRaCfg->data + 26 + pAdapter->ate.HLen, pAdapter->ate.PLen);
56741 + pAdapter->ate.DLen = pAdapter->ate.TxWI.MPDUtotalByteCount - pAdapter->ate.HLen;
56742 + }
56743 +
56744 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R22, &Bbp22Value);
56745 +
56746 + switch (Bbp22Value)
56747 + {
56748 + case BBP22_TXFRAME:
56749 + {
56750 + if (pAdapter->ate.TxCount == 0)
56751 + {
56752 + }
56753 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXFRAME\n"));
56754 + pAdapter->ate.bQATxStart = TRUE;
56755 + Set_ATE_Proc(pAdapter, "TXFRAME");
56756 + }
56757 + break;
56758 +
56759 + case BBP22_TXCONT_OR_CARRSUPP:
56760 + {
56761 + ATEDBGPRINT(RT_DEBUG_TRACE,("BBP22_TXCONT_OR_CARRSUPP\n"));
56762 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, 24, &Bbp24Value);
56763 +
56764 + switch (Bbp24Value)
56765 + {
56766 + case BBP24_TXCONT:
56767 + {
56768 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCONT\n"));
56769 + pAdapter->ate.bQATxStart = TRUE;
56770 + Set_ATE_Proc(pAdapter, "TXCONT");
56771 + }
56772 + break;
56773 +
56774 + case BBP24_CARRSUPP:
56775 + {
56776 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARRSUPP\n"));
56777 + pAdapter->ate.bQATxStart = TRUE;
56778 + pAdapter->ate.Mode |= ATE_TXCARRSUPP;
56779 + }
56780 + break;
56781 +
56782 + default:
56783 + {
56784 + ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
56785 + }
56786 + break;
56787 + }
56788 + }
56789 + break;
56790 +
56791 + case BBP22_TXCARR:
56792 + {
56793 + ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARR\n"));
56794 + pAdapter->ate.bQATxStart = TRUE;
56795 + Set_ATE_Proc(pAdapter, "TXCARR");
56796 + }
56797 + break;
56798 +
56799 + default:
56800 + {
56801 + ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
56802 + }
56803 + break;
56804 + }
56805 +
56806 + if (pAdapter->ate.bQATxStart == TRUE)
56807 + {
56808 + // prepare feedback
56809 + pRaCfg->length = htons(2);
56810 + pRaCfg->status = htons(0);
56811 +
56812 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56813 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56814 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56815 +
56816 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56817 + {
56818 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() was failed in case RACFG_CMD_TX_START\n"));
56819 + Status = -EFAULT;
56820 + }
56821 + else
56822 + {
56823 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_START is done !\n"));
56824 + }
56825 + break;
56826 + }
56827 +
56828 +TX_START_ERROR:
56829 + // prepare feedback
56830 + pRaCfg->length = htons(2);
56831 + pRaCfg->status = htons(err);
56832 +
56833 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56834 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56835 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56836 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56837 + {
56838 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_TX_START\n"));
56839 + Status = -EFAULT;
56840 + }
56841 + else
56842 + {
56843 + ATEDBGPRINT(RT_DEBUG_TRACE, ("feedback of TX_START_ERROR is done !\n"));
56844 + }
56845 + }
56846 + break;
56847 +
56848 + case RACFG_CMD_GET_TX_STATUS:
56849 + {
56850 + UINT32 count;
56851 +
56852 + // prepare feedback
56853 + pRaCfg->length = htons(6);
56854 + pRaCfg->status = htons(0);
56855 + count = htonl(pAdapter->ate.TxDoneCount);
56856 + NdisMoveMemory(pRaCfg->data, &count, 4);
56857 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56858 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56859 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56860 +
56861 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56862 + {
56863 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_TX_STATUS\n"));
56864 + Status = -EFAULT;
56865 + }
56866 + else
56867 + {
56868 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_TX_STATUS is done !\n"));
56869 + }
56870 + }
56871 + break;
56872 +
56873 + case RACFG_CMD_TX_STOP:
56874 + {
56875 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_TX_STOP\n"));
56876 +
56877 + Set_ATE_Proc(pAdapter, "TXSTOP");
56878 +
56879 + // prepare feedback
56880 + pRaCfg->length = htons(2);
56881 + pRaCfg->status = htons(0);
56882 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56883 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56884 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56885 +
56886 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56887 + {
56888 + ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_TX_STOP\n"));
56889 + Status = -EFAULT;
56890 + }
56891 + else
56892 + {
56893 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_STOP is done !\n"));
56894 + }
56895 + }
56896 + break;
56897 +
56898 + case RACFG_CMD_RX_START:
56899 + {
56900 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
56901 +
56902 + pAdapter->ate.bQARxStart = TRUE;
56903 + Set_ATE_Proc(pAdapter, "RXFRAME");
56904 +
56905 + // prepare feedback
56906 + pRaCfg->length = htons(2);
56907 + pRaCfg->status = htons(0);
56908 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56909 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56910 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56911 +
56912 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56913 + {
56914 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
56915 + Status = -EFAULT;
56916 + }
56917 + else
56918 + {
56919 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
56920 + }
56921 + }
56922 + break;
56923 +
56924 + case RACFG_CMD_RX_STOP:
56925 + {
56926 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_STOP\n"));
56927 +
56928 + Set_ATE_Proc(pAdapter, "RXSTOP");
56929 +
56930 + // prepare feedback
56931 + pRaCfg->length = htons(2);
56932 + pRaCfg->status = htons(0);
56933 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56934 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56935 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56936 +
56937 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56938 + {
56939 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_STOP\n"));
56940 + Status = -EFAULT;
56941 + }
56942 + else
56943 + {
56944 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_STOP is done !\n"));
56945 + }
56946 + }
56947 + break;
56948 +
56949 + /* The following cases are for new ATE GUI(not QA). */
56950 + /*==================================================*/
56951 + case RACFG_CMD_ATE_START_TX_CARRIER:
56952 + {
56953 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CARRIER\n"));
56954 +
56955 + Set_ATE_Proc(pAdapter, "TXCARR");
56956 +
56957 + pRaCfg->length = htons(2);
56958 + pRaCfg->status = htons(0);
56959 +
56960 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56961 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56962 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56963 +
56964 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
56965 +
56966 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56967 + {
56968 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CARRIER\n"));
56969 + Status = -EFAULT;
56970 + }
56971 + else
56972 + {
56973 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CARRIER is done !\n"));
56974 + }
56975 + }
56976 + break;
56977 +
56978 + case RACFG_CMD_ATE_START_TX_CONT:
56979 + {
56980 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CONT\n"));
56981 +
56982 + Set_ATE_Proc(pAdapter, "TXCONT");
56983 +
56984 + pRaCfg->length = htons(2);
56985 + pRaCfg->status = htons(0);
56986 +
56987 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
56988 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
56989 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
56990 +
56991 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
56992 +
56993 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
56994 + {
56995 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CONT\n"));
56996 + Status = -EFAULT;
56997 + }
56998 + else
56999 + {
57000 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CONT is done !\n"));
57001 + }
57002 + }
57003 + break;
57004 +
57005 + case RACFG_CMD_ATE_START_TX_FRAME:
57006 + {
57007 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_FRAME\n"));
57008 +
57009 + Set_ATE_Proc(pAdapter, "TXFRAME");
57010 +
57011 + pRaCfg->length = htons(2);
57012 + pRaCfg->status = htons(0);
57013 +
57014 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57015 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57016 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57017 +
57018 + ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
57019 +
57020 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57021 + {
57022 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_FRAME\n"));
57023 + Status = -EFAULT;
57024 + }
57025 + else
57026 + {
57027 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_FRAME is done !\n"));
57028 + }
57029 + }
57030 + break;
57031 +
57032 + case RACFG_CMD_ATE_SET_BW:
57033 + {
57034 + SHORT value = 0;
57035 + UCHAR str[LEN_OF_ARG];
57036 +
57037 + NdisZeroMemory(str, LEN_OF_ARG);
57038 +
57039 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_BW\n"));
57040 +
57041 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57042 + value = ntohs(value);
57043 + sprintf((PCHAR)str, "%d", value);
57044 +
57045 + Set_ATE_TX_BW_Proc(pAdapter, str);
57046 +
57047 + // prepare feedback
57048 + pRaCfg->length = htons(2);
57049 + pRaCfg->status = htons(0);
57050 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57051 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57052 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57053 +
57054 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57055 + {
57056 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_BW\n"));
57057 + Status = -EFAULT;
57058 + }
57059 + else
57060 + {
57061 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_BW is done !\n"));
57062 + }
57063 + }
57064 + break;
57065 +
57066 + case RACFG_CMD_ATE_SET_TX_POWER0:
57067 + {
57068 + SHORT value = 0;
57069 + UCHAR str[LEN_OF_ARG];
57070 +
57071 + NdisZeroMemory(str, LEN_OF_ARG);
57072 +
57073 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER0\n"));
57074 +
57075 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57076 + value = ntohs(value);
57077 + sprintf((PCHAR)str, "%d", value);
57078 + Set_ATE_TX_POWER0_Proc(pAdapter, str);
57079 +
57080 + // prepare feedback
57081 + pRaCfg->length = htons(2);
57082 + pRaCfg->status = htons(0);
57083 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57084 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57085 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57086 +
57087 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57088 + {
57089 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER0\n"));
57090 + Status = -EFAULT;
57091 + }
57092 + else
57093 + {
57094 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER0 is done !\n"));
57095 + }
57096 + }
57097 + break;
57098 +
57099 + case RACFG_CMD_ATE_SET_TX_POWER1:
57100 + {
57101 + SHORT value = 0;
57102 + UCHAR str[LEN_OF_ARG];
57103 +
57104 + NdisZeroMemory(str, LEN_OF_ARG);
57105 +
57106 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER1\n"));
57107 +
57108 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57109 + value = ntohs(value);
57110 + sprintf((PCHAR)str, "%d", value);
57111 + Set_ATE_TX_POWER1_Proc(pAdapter, str);
57112 +
57113 + // prepare feedback
57114 + pRaCfg->length = htons(2);
57115 + pRaCfg->status = htons(0);
57116 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57117 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57118 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57119 +
57120 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57121 + {
57122 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER1\n"));
57123 + Status = -EFAULT;
57124 + }
57125 + else
57126 + {
57127 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER1 is done !\n"));
57128 + }
57129 + }
57130 + break;
57131 +
57132 + case RACFG_CMD_ATE_SET_FREQ_OFFSET:
57133 + {
57134 + SHORT value = 0;
57135 + UCHAR str[LEN_OF_ARG];
57136 +
57137 + NdisZeroMemory(str, LEN_OF_ARG);
57138 +
57139 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
57140 +
57141 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57142 + value = ntohs(value);
57143 + sprintf((PCHAR)str, "%d", value);
57144 + Set_ATE_TX_FREQOFFSET_Proc(pAdapter, str);
57145 +
57146 + // prepare feedback
57147 + pRaCfg->length = htons(2);
57148 + pRaCfg->status = htons(0);
57149 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57150 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57151 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57152 +
57153 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57154 + {
57155 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
57156 + Status = -EFAULT;
57157 + }
57158 + else
57159 + {
57160 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_FREQ_OFFSET is done !\n"));
57161 + }
57162 + }
57163 + break;
57164 +
57165 + case RACFG_CMD_ATE_GET_STATISTICS:
57166 + {
57167 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_GET_STATISTICS\n"));
57168 +
57169 + memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.TxDoneCount, 4);
57170 + memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->WlanCounters.RetryCount.u.LowPart, 4);
57171 + memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->WlanCounters.FailedCount.u.LowPart, 4);
57172 + memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->WlanCounters.RTSSuccessCount.u.LowPart, 4);
57173 + memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->WlanCounters.RTSFailureCount.u.LowPart, 4);
57174 + memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart, 4);
57175 + memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->WlanCounters.FCSErrorCount.u.LowPart, 4);
57176 + memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->Counters8023.RxNoBuffer, 4);
57177 + memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart, 4);
57178 + memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->RalinkCounters.OneSecFalseCCACnt, 4);
57179 +
57180 + if (pAdapter->ate.RxAntennaSel == 0)
57181 + {
57182 + INT32 RSSI0 = 0;
57183 + INT32 RSSI1 = 0;
57184 + INT32 RSSI2 = 0;
57185 +
57186 + RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
57187 + RSSI1 = (INT32)(pAdapter->ate.LastRssi1 - pAdapter->BbpRssiToDbmDelta);
57188 + RSSI2 = (INT32)(pAdapter->ate.LastRssi2 - pAdapter->BbpRssiToDbmDelta);
57189 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
57190 + memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&RSSI1, 4);
57191 + memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&RSSI2, 4);
57192 + pRaCfg->length = htons(2+52);
57193 + }
57194 + else
57195 + {
57196 + INT32 RSSI0 = 0;
57197 +
57198 + RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
57199 + memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
57200 + pRaCfg->length = htons(2+44);
57201 + }
57202 + pRaCfg->status = htons(0);
57203 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57204 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57205 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57206 +
57207 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57208 + {
57209 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_GET_STATISTICS\n"));
57210 + Status = -EFAULT;
57211 + }
57212 + else
57213 + {
57214 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_GET_STATISTICS is done !\n"));
57215 + }
57216 + }
57217 + break;
57218 +
57219 + case RACFG_CMD_ATE_RESET_COUNTER:
57220 + {
57221 + SHORT value = 1;
57222 + UCHAR str[LEN_OF_ARG];
57223 +
57224 + NdisZeroMemory(str, LEN_OF_ARG);
57225 +
57226 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_RESET_COUNTER\n"));
57227 +
57228 + sprintf((PCHAR)str, "%d", value);
57229 + Set_ResetStatCounter_Proc(pAdapter, str);
57230 +
57231 + pAdapter->ate.TxDoneCount = 0;
57232 +
57233 + pRaCfg->length = htons(2);
57234 + pRaCfg->status = htons(0);
57235 +
57236 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57237 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57238 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57239 +
57240 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57241 + {
57242 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RESET_COUNTER\n"));
57243 + Status = -EFAULT;
57244 + }
57245 + else
57246 + {
57247 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RESET_COUNTER is done !\n"));
57248 + }
57249 + }
57250 +
57251 + break;
57252 +
57253 + case RACFG_CMD_ATE_SEL_TX_ANTENNA:
57254 + {
57255 + SHORT value = 0;
57256 + UCHAR str[LEN_OF_ARG];
57257 +
57258 + NdisZeroMemory(str, LEN_OF_ARG);
57259 +
57260 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
57261 +
57262 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57263 + value = ntohs(value);
57264 + sprintf((PCHAR)str, "%d", value);
57265 + Set_ATE_TX_Antenna_Proc(pAdapter, str);
57266 +
57267 + // prepare feedback
57268 + pRaCfg->length = htons(2);
57269 + pRaCfg->status = htons(0);
57270 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57271 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57272 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57273 +
57274 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57275 + {
57276 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
57277 + Status = -EFAULT;
57278 + }
57279 + else
57280 + {
57281 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_TX_ANTENNA is done !\n"));
57282 + }
57283 + }
57284 + break;
57285 +
57286 + case RACFG_CMD_ATE_SEL_RX_ANTENNA:
57287 + {
57288 + SHORT value = 0;
57289 + UCHAR str[LEN_OF_ARG];
57290 +
57291 + NdisZeroMemory(str, LEN_OF_ARG);
57292 +
57293 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
57294 +
57295 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57296 + value = ntohs(value);
57297 + sprintf((PCHAR)str, "%d", value);
57298 + Set_ATE_RX_Antenna_Proc(pAdapter, str);
57299 +
57300 + // prepare feedback
57301 + pRaCfg->length = htons(2);
57302 + pRaCfg->status = htons(0);
57303 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57304 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57305 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57306 +
57307 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57308 + {
57309 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
57310 + Status = -EFAULT;
57311 + }
57312 + else
57313 + {
57314 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_RX_ANTENNA is done !\n"));
57315 + }
57316 + }
57317 + break;
57318 +
57319 + case RACFG_CMD_ATE_SET_PREAMBLE:
57320 + {
57321 + SHORT value = 0;
57322 + UCHAR str[LEN_OF_ARG];
57323 +
57324 + NdisZeroMemory(str, LEN_OF_ARG);
57325 +
57326 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_PREAMBLE\n"));
57327 +
57328 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57329 + value = ntohs(value);
57330 + sprintf((PCHAR)str, "%d", value);
57331 + Set_ATE_TX_MODE_Proc(pAdapter, str);
57332 +
57333 + // prepare feedback
57334 + pRaCfg->length = htons(2);
57335 + pRaCfg->status = htons(0);
57336 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57337 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57338 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57339 +
57340 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57341 + {
57342 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_PREAMBLE\n"));
57343 + Status = -EFAULT;
57344 + }
57345 + else
57346 + {
57347 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_PREAMBLE is done !\n"));
57348 + }
57349 + }
57350 + break;
57351 +
57352 + case RACFG_CMD_ATE_SET_CHANNEL:
57353 + {
57354 + SHORT value = 0;
57355 + UCHAR str[LEN_OF_ARG];
57356 +
57357 + NdisZeroMemory(str, LEN_OF_ARG);
57358 +
57359 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_CHANNEL\n"));
57360 +
57361 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57362 + value = ntohs(value);
57363 + sprintf((PCHAR)str, "%d", value);
57364 + Set_ATE_CHANNEL_Proc(pAdapter, str);
57365 +
57366 + // prepare feedback
57367 + pRaCfg->length = htons(2);
57368 + pRaCfg->status = htons(0);
57369 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57370 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57371 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57372 +
57373 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57374 + {
57375 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_CHANNEL\n"));
57376 + Status = -EFAULT;
57377 + }
57378 + else
57379 + {
57380 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_CHANNEL is done !\n"));
57381 + }
57382 + }
57383 + break;
57384 +
57385 + case RACFG_CMD_ATE_SET_ADDR1:
57386 + {
57387 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR1\n"));
57388 +
57389 + // Addr is an array of UCHAR,
57390 + // so no need to perform endian swap.
57391 + memcpy(pAdapter->ate.Addr1, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
57392 +
57393 + // prepare feedback
57394 + pRaCfg->length = htons(2);
57395 + pRaCfg->status = htons(0);
57396 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57397 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57398 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57399 +
57400 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57401 + {
57402 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR1\n"));
57403 + Status = -EFAULT;
57404 + }
57405 + else
57406 + {
57407 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR1 is done !\n (ADDR1 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr1[0],
57408 + pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]));
57409 + }
57410 + }
57411 + break;
57412 +
57413 + case RACFG_CMD_ATE_SET_ADDR2:
57414 + {
57415 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR2\n"));
57416 +
57417 + // Addr is an array of UCHAR,
57418 + // so no need to perform endian swap.
57419 + memcpy(pAdapter->ate.Addr2, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
57420 +
57421 + // prepare feedback
57422 + pRaCfg->length = htons(2);
57423 + pRaCfg->status = htons(0);
57424 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57425 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57426 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57427 +
57428 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57429 + {
57430 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR2\n"));
57431 + Status = -EFAULT;
57432 + }
57433 + else
57434 + {
57435 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR2 is done !\n (ADDR2 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr2[0],
57436 + pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]));
57437 + }
57438 + }
57439 + break;
57440 +
57441 + case RACFG_CMD_ATE_SET_ADDR3:
57442 + {
57443 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR3\n"));
57444 +
57445 + // Addr is an array of UCHAR,
57446 + // so no need to perform endian swap.
57447 + memcpy(pAdapter->ate.Addr3, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
57448 +
57449 + // prepare feedback
57450 + pRaCfg->length = htons(2);
57451 + pRaCfg->status = htons(0);
57452 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57453 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57454 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57455 +
57456 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57457 + {
57458 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR3\n"));
57459 + Status = -EFAULT;
57460 + }
57461 + else
57462 + {
57463 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR3 is done !\n (ADDR3 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr3[0],
57464 + pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]));
57465 + }
57466 + }
57467 + break;
57468 +
57469 + case RACFG_CMD_ATE_SET_RATE:
57470 + {
57471 + SHORT value = 0;
57472 + UCHAR str[LEN_OF_ARG];
57473 +
57474 + NdisZeroMemory(str, LEN_OF_ARG);
57475 +
57476 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_RATE\n"));
57477 +
57478 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57479 + value = ntohs(value);
57480 + sprintf((PCHAR)str, "%d", value);
57481 + Set_ATE_TX_MCS_Proc(pAdapter, str);
57482 +
57483 + // prepare feedback
57484 + pRaCfg->length = htons(2);
57485 + pRaCfg->status = htons(0);
57486 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57487 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57488 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57489 +
57490 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57491 + {
57492 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_RATE\n"));
57493 + Status = -EFAULT;
57494 + }
57495 + else
57496 + {
57497 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_RATE is done !\n"));
57498 + }
57499 + }
57500 + break;
57501 +
57502 + case RACFG_CMD_ATE_SET_TX_FRAME_LEN:
57503 + {
57504 + SHORT value = 0;
57505 + UCHAR str[LEN_OF_ARG];
57506 +
57507 + NdisZeroMemory(str, LEN_OF_ARG);
57508 +
57509 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
57510 +
57511 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57512 + value = ntohs(value);
57513 + sprintf((PCHAR)str, "%d", value);
57514 + Set_ATE_TX_LENGTH_Proc(pAdapter, str);
57515 +
57516 + // prepare feedback
57517 + pRaCfg->length = htons(2);
57518 + pRaCfg->status = htons(0);
57519 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57520 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57521 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57522 +
57523 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57524 + {
57525 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
57526 + Status = -EFAULT;
57527 + }
57528 + else
57529 + {
57530 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_LEN is done !\n"));
57531 + }
57532 + }
57533 + break;
57534 +
57535 + case RACFG_CMD_ATE_SET_TX_FRAME_COUNT:
57536 + {
57537 + USHORT value = 0;
57538 + UCHAR str[LEN_OF_ARG];
57539 +
57540 + NdisZeroMemory(str, LEN_OF_ARG);
57541 +
57542 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
57543 +
57544 + memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
57545 + value = ntohs(value);
57546 + {
57547 + sprintf((PCHAR)str, "%d", value);
57548 + Set_ATE_TX_COUNT_Proc(pAdapter, str);
57549 + }
57550 +
57551 + // prepare feedback
57552 + pRaCfg->length = htons(2);
57553 + pRaCfg->status = htons(0);
57554 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57555 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57556 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57557 +
57558 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57559 + {
57560 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
57561 + Status = -EFAULT;
57562 + }
57563 + else
57564 + {
57565 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_COUNT is done !\n"));
57566 + }
57567 + }
57568 + break;
57569 +
57570 + case RACFG_CMD_ATE_START_RX_FRAME:
57571 + {
57572 + ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
57573 +
57574 + Set_ATE_Proc(pAdapter, "RXFRAME");
57575 +
57576 + // prepare feedback
57577 + pRaCfg->length = htons(2);
57578 + pRaCfg->status = htons(0);
57579 + wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
57580 + + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
57581 + + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
57582 +
57583 + if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
57584 + {
57585 + ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
57586 + Status = -EFAULT;
57587 + }
57588 + else
57589 + {
57590 + ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
57591 + }
57592 + }
57593 + break;
57594 + default:
57595 + break;
57596 + }
57597 + ASSERT(pRaCfg != NULL);
57598 + if (pRaCfg != NULL)
57599 + {
57600 + kfree(pRaCfg);
57601 + }
57602 + return;
57603 +}
57604 +
57605 +VOID BubbleSort(INT32 n, INT32 a[])
57606 +{
57607 + INT32 k, j, temp;
57608 +
57609 + for (k = n-1; k>0; k--)
57610 + {
57611 + for (j = 0; j<k; j++)
57612 + {
57613 + if(a[j] > a[j+1])
57614 + {
57615 + temp = a[j];
57616 + a[j]=a[j+1];
57617 + a[j+1]=temp;
57618 + }
57619 + }
57620 + }
57621 +}
57622 +
57623 +VOID CalNoiseLevel(PRTMP_ADAPTER pAd, UCHAR channel, INT32 RSSI[3][10])
57624 +{
57625 + INT32 RSSI0, RSSI1, RSSI2;
57626 + CHAR Rssi0Offset, Rssi1Offset, Rssi2Offset;
57627 + UCHAR BbpR50Rssi0 = 0, BbpR51Rssi1 = 0, BbpR52Rssi2 = 0;
57628 + UCHAR Org_BBP66value = 0, Org_BBP69value = 0, Org_BBP70value = 0, data = 0;
57629 + USHORT LNA_Gain = 0;
57630 + INT32 j = 0;
57631 + UCHAR Org_Channel = pAd->ate.Channel;
57632 + USHORT GainValue = 0, OffsetValue = 0;
57633 +
57634 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &Org_BBP66value);
57635 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R69, &Org_BBP69value);
57636 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R70, &Org_BBP70value);
57637 +
57638 + //**********************************************************************
57639 + // Read the value of LNA gain and Rssi offset
57640 + //**********************************************************************
57641 + RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, GainValue);
57642 +
57643 + // for Noise Level
57644 + if (channel <= 14)
57645 + {
57646 + LNA_Gain = GainValue & 0x00FF;
57647 +
57648 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, OffsetValue);
57649 + Rssi0Offset = OffsetValue & 0x00FF;
57650 + Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
57651 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_BG_OFFSET + 2)/* 0x48 */, OffsetValue);
57652 + Rssi2Offset = OffsetValue & 0x00FF;
57653 + }
57654 + else
57655 + {
57656 + LNA_Gain = (GainValue & 0xFF00) >> 8;
57657 +
57658 + RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, OffsetValue);
57659 + Rssi0Offset = OffsetValue & 0x00FF;
57660 + Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
57661 + RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2)/* 0x4C */, OffsetValue);
57662 + Rssi2Offset = OffsetValue & 0x00FF;
57663 + }
57664 + //**********************************************************************
57665 + {
57666 + pAd->ate.Channel = channel;
57667 + ATEAsicSwitchChannel(pAd);
57668 + mdelay(5);
57669 +
57670 + data = 0x10;
57671 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, data);
57672 + data = 0x40;
57673 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, data);
57674 + data = 0x40;
57675 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, data);
57676 + mdelay(5);
57677 +
57678 + // Start Rx
57679 + pAd->ate.bQARxStart = TRUE;
57680 + Set_ATE_Proc(pAd, "RXFRAME");
57681 +
57682 + mdelay(5);
57683 +
57684 + for (j = 0; j < 10; j++)
57685 + {
57686 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R50, &BbpR50Rssi0);
57687 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R51, &BbpR51Rssi1);
57688 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R52, &BbpR52Rssi2);
57689 +
57690 + mdelay(10);
57691 +
57692 + // Calculate RSSI 0
57693 + if (BbpR50Rssi0 == 0)
57694 + {
57695 + RSSI0 = -100;
57696 + }
57697 + else
57698 + {
57699 + RSSI0 = (INT32)(-12 - BbpR50Rssi0 - LNA_Gain - Rssi0Offset);
57700 + }
57701 + RSSI[0][j] = RSSI0;
57702 +
57703 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
57704 + {
57705 + // Calculate RSSI 1
57706 + if (BbpR51Rssi1 == 0)
57707 + {
57708 + RSSI1 = -100;
57709 + }
57710 + else
57711 + {
57712 + RSSI1 = (INT32)(-12 - BbpR51Rssi1 - LNA_Gain - Rssi1Offset);
57713 + }
57714 + RSSI[1][j] = RSSI1;
57715 + }
57716 +
57717 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
57718 + {
57719 + // Calculate RSSI 2
57720 + if (BbpR52Rssi2 == 0)
57721 + RSSI2 = -100;
57722 + else
57723 + RSSI2 = (INT32)(-12 - BbpR52Rssi2 - LNA_Gain - Rssi2Offset);
57724 +
57725 + RSSI[2][j] = RSSI2;
57726 + }
57727 + }
57728 +
57729 + // Stop Rx
57730 + Set_ATE_Proc(pAd, "RXSTOP");
57731 +
57732 + mdelay(5);
57733 +
57734 + BubbleSort(10, RSSI[0]); // 1R
57735 +
57736 + if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
57737 + {
57738 + BubbleSort(10, RSSI[1]);
57739 + }
57740 +
57741 + if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
57742 + {
57743 + BubbleSort(10, RSSI[2]);
57744 + }
57745 +
57746 + }
57747 +
57748 + pAd->ate.Channel = Org_Channel;
57749 + ATEAsicSwitchChannel(pAd);
57750 +
57751 + // Restore original value
57752 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, Org_BBP66value);
57753 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, Org_BBP69value);
57754 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, Org_BBP70value);
57755 +
57756 + return;
57757 +}
57758 +
57759 +BOOLEAN SyncTxRxConfig(PRTMP_ADAPTER pAd, USHORT offset, UCHAR value)
57760 +{
57761 + UCHAR tmp = 0, bbp_data = 0;
57762 +
57763 + if (ATE_ON(pAd))
57764 + {
57765 + ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
57766 + }
57767 + else
57768 + {
57769 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
57770 + }
57771 +
57772 + /* confirm again */
57773 + ASSERT(bbp_data == value);
57774 +
57775 + switch(offset)
57776 + {
57777 + case BBP_R1:
57778 + /* Need to sync. tx configuration with legacy ATE. */
57779 + tmp = (bbp_data & ((1 << 4) | (1 << 3))/* 0x18 */) >> 3;
57780 + switch(tmp)
57781 + {
57782 + /* The BBP R1 bit[4:3] = 2 :: Both DACs will be used by QA. */
57783 + case 2:
57784 + /* All */
57785 + pAd->ate.TxAntennaSel = 0;
57786 + break;
57787 + /* The BBP R1 bit[4:3] = 0 :: DAC 0 will be used by QA. */
57788 + case 0:
57789 + /* Antenna one */
57790 + pAd->ate.TxAntennaSel = 1;
57791 + break;
57792 + /* The BBP R1 bit[4:3] = 1 :: DAC 1 will be used by QA. */
57793 + case 1:
57794 + /* Antenna two */
57795 + pAd->ate.TxAntennaSel = 2;
57796 + break;
57797 + default:
57798 + DBGPRINT(RT_DEBUG_TRACE, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
57799 + return FALSE;
57800 + }
57801 + break;/* case BBP_R1 */
57802 +
57803 + case BBP_R3:
57804 + /* Need to sync. rx configuration with legacy ATE. */
57805 + tmp = (bbp_data & ((1 << 1) | (1 << 0))/* 0x03 */);
57806 + switch(tmp)
57807 + {
57808 + /* The BBP R3 bit[1:0] = 3 :: All ADCs will be used by QA. */
57809 + case 3:
57810 + /* All */
57811 + pAd->ate.RxAntennaSel = 0;
57812 + break;
57813 + /* The BBP R3 bit[1:0] = 0 :: ADC 0 will be used by QA, */
57814 + /* unless the BBP R3 bit[4:3] = 2 */
57815 + case 0:
57816 + /* Antenna one */
57817 + pAd->ate.RxAntennaSel = 1;
57818 + tmp = ((bbp_data & ((1 << 4) | (1 << 3))/* 0x03 */) >> 3);
57819 + if (tmp == 2)// 3R
57820 + {
57821 + /* Default : All ADCs will be used by QA */
57822 + pAd->ate.RxAntennaSel = 0;
57823 + }
57824 + break;
57825 + /* The BBP R3 bit[1:0] = 1 :: ADC 1 will be used by QA. */
57826 + case 1:
57827 + /* Antenna two */
57828 + pAd->ate.RxAntennaSel = 2;
57829 + break;
57830 + /* The BBP R3 bit[1:0] = 2 :: ADC 2 will be used by QA. */
57831 + case 2:
57832 + /* Antenna three */
57833 + pAd->ate.RxAntennaSel = 3;
57834 + break;
57835 + default:
57836 + DBGPRINT(RT_DEBUG_ERROR, ("%s -- Impossible! : return FALSE; \n", __FUNCTION__));
57837 + return FALSE;
57838 + }
57839 + break;/* case BBP_R3 */
57840 +
57841 + default:
57842 + DBGPRINT(RT_DEBUG_ERROR, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
57843 + return FALSE;
57844 +
57845 + }
57846 + return TRUE;
57847 +}
57848 +
57849 +static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
57850 +{
57851 + ULONG i, Value = 0;
57852 + ULONG *pDst, *pSrc;
57853 + UCHAR *p8;
57854 +
57855 + p8 = src;
57856 + pDst = (ULONG *) dst;
57857 + pSrc = (ULONG *) src;
57858 +
57859 + for (i = 0 ; i < (len/4); i++)
57860 + {
57861 + /* For alignment issue, we need a variable "Value". */
57862 + memmove(&Value, pSrc, 4);
57863 + Value = htonl(Value);
57864 + memmove(pDst, &Value, 4);
57865 + pDst++;
57866 + pSrc++;
57867 + }
57868 + if ((len % 4) != 0)
57869 + {
57870 + /* wish that it will never reach here */
57871 + memmove(&Value, pSrc, (len % 4));
57872 + Value = htonl(Value);
57873 + memmove(pDst, &Value, (len % 4));
57874 + }
57875 +}
57876 +
57877 +static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
57878 +{
57879 + ULONG i;
57880 + UCHAR *pDst, *pSrc;
57881 +
57882 + pDst = dst;
57883 + pSrc = src;
57884 +
57885 + for (i = 0; i < (len/2); i++)
57886 + {
57887 + memmove(pDst, pSrc, 2);
57888 + *((USHORT *)pDst) = htons(*((USHORT *)pDst));
57889 + pDst+=2;
57890 + pSrc+=2;
57891 + }
57892 +
57893 + if ((len % 2) != 0)
57894 + {
57895 + memmove(pDst, pSrc, 1);
57896 + }
57897 +}
57898 +
57899 +static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len)
57900 +{
57901 + UINT32 i, Value;
57902 + UINT32 *pDst, *pSrc;
57903 +
57904 + pDst = (UINT32 *) dst;
57905 + pSrc = (UINT32 *) src;
57906 +
57907 + for (i = 0 ; i < (len/4); i++)
57908 + {
57909 + RTMP_IO_READ32(pAd, (ULONG)pSrc, &Value);
57910 + Value = htonl(Value);
57911 + memmove(pDst, &Value, 4);
57912 + pDst++;
57913 + pSrc++;
57914 + }
57915 + return;
57916 +}
57917 +
57918 +INT Set_TxStop_Proc(
57919 + IN PRTMP_ADAPTER pAd,
57920 + IN PUCHAR arg)
57921 +{
57922 + ATEDBGPRINT(RT_DEBUG_TRACE,("Set_TxStop_Proc\n"));
57923 +
57924 + if (Set_ATE_Proc(pAd, "TXSTOP"))
57925 + {
57926 + return TRUE;
57927 +}
57928 + else
57929 + {
57930 + return FALSE;
57931 + }
57932 +}
57933 +
57934 +INT Set_RxStop_Proc(
57935 + IN PRTMP_ADAPTER pAd,
57936 + IN PUCHAR arg)
57937 +{
57938 + ATEDBGPRINT(RT_DEBUG_TRACE,("Set_RxStop_Proc\n"));
57939 +
57940 + if (Set_ATE_Proc(pAd, "RXSTOP"))
57941 + {
57942 + return TRUE;
57943 +}
57944 + else
57945 + {
57946 + return FALSE;
57947 + }
57948 +}
57949 +#endif // RALINK_28xx_QA //
57950 +#endif // RALINK_ATE //
57951 +
57952 --- /dev/null
57953 +++ b/drivers/staging/rt3070/rt_ate.h
57954 @@ -0,0 +1,294 @@
57955 +/*
57956 + *************************************************************************
57957 + * Ralink Tech Inc.
57958 + * 5F., No.36, Taiyuan St., Jhubei City,
57959 + * Hsinchu County 302,
57960 + * Taiwan, R.O.C.
57961 + *
57962 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
57963 + *
57964 + * This program is free software; you can redistribute it and/or modify *
57965 + * it under the terms of the GNU General Public License as published by *
57966 + * the Free Software Foundation; either version 2 of the License, or *
57967 + * (at your option) any later version. *
57968 + * *
57969 + * This program is distributed in the hope that it will be useful, *
57970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
57971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
57972 + * GNU General Public License for more details. *
57973 + * *
57974 + * You should have received a copy of the GNU General Public License *
57975 + * along with this program; if not, write to the *
57976 + * Free Software Foundation, Inc., *
57977 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
57978 + * *
57979 + *************************************************************************
57980 + */
57981 +
57982 +#ifndef __ATE_H__
57983 +#define __ATE_H__
57984 +
57985 +#ifndef UCOS
57986 +#define ate_print printk
57987 +#define ATEDBGPRINT DBGPRINT
57988 +
57989 +#ifdef RT2870
57990 +#define EEPROM_SIZE 0x400
57991 +#ifdef CONFIG_STA_SUPPORT
57992 +#define EEPROM_BIN_FILE_NAME "/etc/Wireless/RT2870STA/e2p.bin"
57993 +#endif // CONFIG_STA_SUPPORT //
57994 +#endif // RT2870 //
57995 +#else // !UCOS //
57996 +#define fATE_LOAD_EEPROM 0x0C43
57997 +#ifdef CONFIG_PRINTK
57998 +extern INT ConsoleResponse(IN PUCHAR buff);
57999 +extern int (*remote_display)(char *);
58000 +extern void puts (const char *s);
58001 +
58002 +/* specificly defined to redirect and show ate-related messages to host. */
58003 +/* Try to define ate_print as a macro. */
58004 +#define ate_print(fmt, args...) \
58005 +do{ int (*org_remote_display)(char *) = NULL; \
58006 + org_remote_display = remote_display;\
58007 + /* Save original "remote_display" */\
58008 + remote_display = (int (*)(char *))ConsoleResponse; \
58009 + printk(fmt, ## args); \
58010 + /* Restore the remote_display function pointer */ \
58011 + remote_display = org_remote_display; }while(0)
58012 +
58013 +#define ATEDBGPRINT(Level, Fmt) \
58014 +{ \
58015 + if ((Level) <= RTDebugLevel) \
58016 + { \
58017 + ate_print Fmt; \
58018 + } \
58019 +}
58020 +#endif // CONFIG_PRINTK //
58021 +#endif // !UCOS //
58022 +
58023 +#define ATE_ON(_p) (((_p)->ate.Mode) != ATE_STOP)
58024 +
58025 +/* RT2880_iNIC will define "RT2860". */
58026 +
58027 +/* RT2880_iNIC will define RT2860. */
58028 +
58029 +#ifdef RT2870
58030 +#define EEPROM_SIZE 0x400
58031 +#ifdef CONFIG_STA_SUPPORT
58032 +#define EEPROM_BIN_FILE_NAME "/etc/Wireless/RT2870STA/e2p.bin"
58033 +#endif // CONFIG_STA_SUPPORT //
58034 +#endif // RT2870 //
58035 +
58036 +#ifdef RT2870
58037 +#define ATE_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)
58038 +#define ATE_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)
58039 +
58040 +#define BULK_OUT_LOCK(pLock, IrqFlags) \
58041 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
58042 + RTMP_IRQ_LOCK((pLock), IrqFlags);
58043 +
58044 +#define BULK_OUT_UNLOCK(pLock, IrqFlags) \
58045 + if(1 /*!(in_interrupt() & 0xffff0000)*/) \
58046 + RTMP_IRQ_UNLOCK((pLock), IrqFlags);
58047 +
58048 +// Prototypes of completion funuc.
58049 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58050 +#define ATE_RTUSBBulkOutDataPacketComplete(purb, pt_regs) ATE_RTUSBBulkOutDataPacketComplete(purb)
58051 +#endif
58052 +
58053 +VOID ATE_RTUSBBulkOutDataPacketComplete(
58054 + IN purbb_t purb,
58055 + OUT struct pt_regs *pt_regs);
58056 +
58057 +VOID ATE_RTUSBBulkOutDataPacket(
58058 + IN PRTMP_ADAPTER pAd,
58059 + IN UCHAR BulkOutPipeId);
58060 +
58061 +VOID ATE_RTUSBCancelPendingBulkInIRP(
58062 + IN PRTMP_ADAPTER pAd);
58063 +#endif // RT2870 //
58064 +
58065 +#ifdef RT30xx
58066 +#define ATE_RF_IO_READ8_BY_REG_ID(_A, _I, _pV) RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV)
58067 +#define ATE_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V)
58068 +#endif // RT30xx //
58069 +
58070 +
58071 +VOID rt_ee_read_all(
58072 + IN PRTMP_ADAPTER pAd,
58073 + OUT USHORT *Data);
58074 +
58075 +
58076 +VOID rt_ee_write_all(
58077 + IN PRTMP_ADAPTER pAd,
58078 + IN USHORT *Data);
58079 +
58080 +INT Set_ATE_Proc(
58081 + IN PRTMP_ADAPTER pAd,
58082 + IN PUCHAR arg);
58083 +
58084 +INT Set_ATE_DA_Proc(
58085 + IN PRTMP_ADAPTER pAd,
58086 + IN PUCHAR arg);
58087 +
58088 +INT Set_ATE_SA_Proc(
58089 + IN PRTMP_ADAPTER pAd,
58090 + IN PUCHAR arg);
58091 +
58092 +INT Set_ATE_BSSID_Proc(
58093 + IN PRTMP_ADAPTER pAd,
58094 + IN PUCHAR arg);
58095 +
58096 +INT Set_ATE_CHANNEL_Proc(
58097 + IN PRTMP_ADAPTER pAd,
58098 + IN PUCHAR arg);
58099 +
58100 +INT Set_ATE_TX_POWER0_Proc(
58101 + IN PRTMP_ADAPTER pAd,
58102 + IN PUCHAR arg);
58103 +
58104 +INT Set_ATE_TX_POWER1_Proc(
58105 + IN PRTMP_ADAPTER pAd,
58106 + IN PUCHAR arg);
58107 +
58108 +INT Set_ATE_TX_Antenna_Proc(
58109 + IN PRTMP_ADAPTER pAd,
58110 + IN PUCHAR arg);
58111 +
58112 +INT Set_ATE_RX_Antenna_Proc(
58113 + IN PRTMP_ADAPTER pAd,
58114 + IN PUCHAR arg);
58115 +
58116 +INT Set_ATE_TX_FREQOFFSET_Proc(
58117 + IN PRTMP_ADAPTER pAd,
58118 + IN PUCHAR arg);
58119 +
58120 +INT Set_ATE_TX_BW_Proc(
58121 + IN PRTMP_ADAPTER pAd,
58122 + IN PUCHAR arg);
58123 +
58124 +INT Set_ATE_TX_LENGTH_Proc(
58125 + IN PRTMP_ADAPTER pAd,
58126 + IN PUCHAR arg);
58127 +
58128 +INT Set_ATE_TX_COUNT_Proc(
58129 + IN PRTMP_ADAPTER pAd,
58130 + IN PUCHAR arg);
58131 +
58132 +INT Set_ATE_TX_MCS_Proc(
58133 + IN PRTMP_ADAPTER pAd,
58134 + IN PUCHAR arg);
58135 +
58136 +INT Set_ATE_TX_MODE_Proc(
58137 + IN PRTMP_ADAPTER pAd,
58138 + IN PUCHAR arg);
58139 +
58140 +INT Set_ATE_TX_GI_Proc(
58141 + IN PRTMP_ADAPTER pAd,
58142 + IN PUCHAR arg);
58143 +
58144 +
58145 +INT Set_ATE_RX_FER_Proc(
58146 + IN PRTMP_ADAPTER pAd,
58147 + IN PUCHAR arg);
58148 +
58149 +INT Set_ATE_Read_RF_Proc(
58150 + IN PRTMP_ADAPTER pAd,
58151 + IN PUCHAR arg);
58152 +
58153 +INT Set_ATE_Write_RF1_Proc(
58154 + IN PRTMP_ADAPTER pAd,
58155 + IN PUCHAR arg);
58156 +
58157 +INT Set_ATE_Write_RF2_Proc(
58158 + IN PRTMP_ADAPTER pAd,
58159 + IN PUCHAR arg);
58160 +
58161 +INT Set_ATE_Write_RF3_Proc(
58162 + IN PRTMP_ADAPTER pAd,
58163 + IN PUCHAR arg);
58164 +
58165 +INT Set_ATE_Write_RF4_Proc(
58166 + IN PRTMP_ADAPTER pAd,
58167 + IN PUCHAR arg);
58168 +
58169 +INT Set_ATE_Load_E2P_Proc(
58170 + IN PRTMP_ADAPTER pAd,
58171 + IN PUCHAR arg);
58172 +
58173 +INT Set_ATE_Read_E2P_Proc(
58174 + IN PRTMP_ADAPTER pAd,
58175 + IN PUCHAR arg);
58176 +
58177 +INT Set_ATE_Show_Proc(
58178 + IN PRTMP_ADAPTER pAd,
58179 + IN PUCHAR arg);
58180 +
58181 +INT Set_ATE_Help_Proc(
58182 + IN PRTMP_ADAPTER pAd,
58183 + IN PUCHAR arg);
58184 +
58185 +#ifdef RALINK_ATE
58186 +#ifdef RALINK_28xx_QA
58187 +VOID ATE_QA_Statistics(
58188 + IN PRTMP_ADAPTER pAd,
58189 + IN PRXWI_STRUC pRxWI,
58190 + IN PRT28XX_RXD_STRUC p28xxRxD,
58191 + IN PHEADER_802_11 pHeader);
58192 +
58193 +VOID RtmpDoAte(
58194 + IN PRTMP_ADAPTER pAdapter,
58195 + IN struct iwreq *wrq);
58196 +
58197 +VOID BubbleSort(
58198 + IN INT32 n,
58199 + IN INT32 a[]);
58200 +
58201 +VOID CalNoiseLevel(
58202 + IN PRTMP_ADAPTER pAdapter,
58203 + IN UCHAR channel,
58204 + OUT INT32 buffer[3][10]);
58205 +
58206 +BOOLEAN SyncTxRxConfig(
58207 + IN PRTMP_ADAPTER pAdapter,
58208 + IN USHORT offset,
58209 + IN UCHAR value);
58210 +
58211 +INT Set_TxStop_Proc(
58212 + IN PRTMP_ADAPTER pAd,
58213 + IN PUCHAR arg);
58214 +
58215 +INT Set_RxStop_Proc(
58216 + IN PRTMP_ADAPTER pAd,
58217 + IN PUCHAR arg);
58218 +
58219 +#endif // RALINK_28xx_QA //
58220 +#endif // RALINK_ATE //
58221 +
58222 +VOID ATEAsicSwitchChannel(
58223 + IN PRTMP_ADAPTER pAd);
58224 +
58225 +VOID ATEAsicAdjustTxPower(
58226 + IN PRTMP_ADAPTER pAd);
58227 +
58228 +VOID ATEDisableAsicProtect(
58229 + IN PRTMP_ADAPTER pAd);
58230 +
58231 +CHAR ATEConvertToRssi(
58232 + IN PRTMP_ADAPTER pAd,
58233 + IN CHAR Rssi,
58234 + IN UCHAR RssiNumber);
58235 +
58236 +VOID ATESampleRssi(
58237 + IN PRTMP_ADAPTER pAd,
58238 + IN PRXWI_STRUC pRxWI);
58239 +
58240 +
58241 +#ifdef CONFIG_STA_SUPPORT
58242 +VOID RTMPStationStop(
58243 + IN PRTMP_ADAPTER pAd);
58244 +
58245 +VOID RTMPStationStart(
58246 + IN PRTMP_ADAPTER pAd);
58247 +#endif // CONFIG_STA_SUPPORT //
58248 +#endif // __ATE_H__ //
58249 --- /dev/null
58250 +++ b/drivers/staging/rt3070/rt_config.h
58251 @@ -0,0 +1,121 @@
58252 +/*
58253 + *************************************************************************
58254 + * Ralink Tech Inc.
58255 + * 5F., No.36, Taiyuan St., Jhubei City,
58256 + * Hsinchu County 302,
58257 + * Taiwan, R.O.C.
58258 + *
58259 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
58260 + *
58261 + * This program is free software; you can redistribute it and/or modify *
58262 + * it under the terms of the GNU General Public License as published by *
58263 + * the Free Software Foundation; either version 2 of the License, or *
58264 + * (at your option) any later version. *
58265 + * *
58266 + * This program is distributed in the hope that it will be useful, *
58267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
58268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
58269 + * GNU General Public License for more details. *
58270 + * *
58271 + * You should have received a copy of the GNU General Public License *
58272 + * along with this program; if not, write to the *
58273 + * Free Software Foundation, Inc., *
58274 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
58275 + * *
58276 + *************************************************************************
58277 +
58278 + Module Name:
58279 + rt_config.h
58280 +
58281 + Abstract:
58282 + Central header file to maintain all include files for all NDIS
58283 + miniport driver routines.
58284 +
58285 + Revision History:
58286 + Who When What
58287 + -------- ---------- ----------------------------------------------
58288 + Paul Lin 08-01-2002 created
58289 +
58290 +*/
58291 +#ifndef __RT_CONFIG_H__
58292 +#define __RT_CONFIG_H__
58293 +
58294 +#include "rtmp_type.h"
58295 +#ifdef UCOS
58296 +#include "includes.h"
58297 +#include <stdio.h>
58298 +#include "rt_ucos.h"
58299 +#endif
58300 +
58301 +#ifdef LINUX
58302 +#include "rt_linux.h"
58303 +#endif
58304 +#include "rtmp_def.h"
58305 +#include "rt28xx.h"
58306 +
58307 +
58308 +#ifdef RT2870
58309 +#include "rt2870.h"
58310 +#endif // RT2870 //
58311 +
58312 +#include "oid.h"
58313 +#include "mlme.h"
58314 +#include "wpa.h"
58315 +#include "md5.h"
58316 +#include "rtmp.h"
58317 +#include "ap.h"
58318 +#include "dfs.h"
58319 +#include "chlist.h"
58320 +#include "spectrum.h"
58321 +#ifdef MLME_EX
58322 +#include "mlme_ex_def.h"
58323 +#include "mlme_ex.h"
58324 +#endif // MLME_EX //
58325 +
58326 +#undef AP_WSC_INCLUDED
58327 +#undef STA_WSC_INCLUDED
58328 +#undef WSC_INCLUDED
58329 +
58330 +
58331 +#ifdef LEAP_SUPPORT
58332 +#include "leap.h"
58333 +#endif // LEAP_SUPPORT //
58334 +
58335 +#ifdef CONFIG_STA_SUPPORT
58336 +#endif // CONFIG_STA_SUPPORT //
58337 +
58338 +#ifdef BLOCK_NET_IF
58339 +#include "netif_block.h"
58340 +#endif // BLOCK_NET_IF //
58341 +
58342 +#ifdef IGMP_SNOOP_SUPPORT
58343 +#include "igmp_snoop.h"
58344 +#endif // IGMP_SNOOP_SUPPORT //
58345 +
58346 +#ifdef RALINK_ATE
58347 +#include "rt_ate.h"
58348 +#endif // RALINK_ATE //
58349 +
58350 +
58351 +
58352 +#if defined(AP_WSC_INCLUDED) || defined(STA_WSC_INCLUDED)
58353 +#define WSC_INCLUDED
58354 +#endif
58355 +
58356 +
58357 +#ifdef CONFIG_STA_SUPPORT
58358 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
58359 +#ifndef WPA_SUPPLICANT_SUPPORT
58360 +#error "Build for being controlled by NetworkManager or wext, please set HAS_WPA_SUPPLICANT=y and HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y"
58361 +#endif // WPA_SUPPLICANT_SUPPORT //
58362 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
58363 +
58364 +#endif // CONFIG_STA_SUPPORT //
58365 +
58366 +
58367 +#ifdef IKANOS_VX_1X0
58368 +#include "vr_ikans.h"
58369 +#endif // IKANOS_VX_1X0 //
58370 +
58371 +#endif // __RT_CONFIG_H__
58372 +
58373 --- /dev/null
58374 +++ b/drivers/staging/rt3070/rt_linux.c
58375 @@ -0,0 +1,1063 @@
58376 +/*
58377 + *************************************************************************
58378 + * Ralink Tech Inc.
58379 + * 5F., No.36, Taiyuan St., Jhubei City,
58380 + * Hsinchu County 302,
58381 + * Taiwan, R.O.C.
58382 + *
58383 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
58384 + *
58385 + * This program is free software; you can redistribute it and/or modify *
58386 + * it under the terms of the GNU General Public License as published by *
58387 + * the Free Software Foundation; either version 2 of the License, or *
58388 + * (at your option) any later version. *
58389 + * *
58390 + * This program is distributed in the hope that it will be useful, *
58391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
58392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
58393 + * GNU General Public License for more details. *
58394 + * *
58395 + * You should have received a copy of the GNU General Public License *
58396 + * along with this program; if not, write to the *
58397 + * Free Software Foundation, Inc., *
58398 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
58399 + * *
58400 + *************************************************************************
58401 + */
58402 +
58403 +#include "rt_config.h"
58404 +
58405 +ULONG RTDebugLevel = RT_DEBUG_ERROR;
58406 +
58407 +BUILD_TIMER_FUNCTION(MlmePeriodicExec);
58408 +//BUILD_TIMER_FUNCTION(MlmeRssiReportExec);
58409 +BUILD_TIMER_FUNCTION(AsicRxAntEvalTimeout);
58410 +BUILD_TIMER_FUNCTION(APSDPeriodicExec);
58411 +BUILD_TIMER_FUNCTION(AsicRfTuningExec);
58412 +#ifdef RT2870
58413 +BUILD_TIMER_FUNCTION(BeaconUpdateExec);
58414 +#endif // RT2870 //
58415 +
58416 +
58417 +#ifdef CONFIG_STA_SUPPORT
58418 +BUILD_TIMER_FUNCTION(BeaconTimeout);
58419 +BUILD_TIMER_FUNCTION(ScanTimeout);
58420 +BUILD_TIMER_FUNCTION(AuthTimeout);
58421 +BUILD_TIMER_FUNCTION(AssocTimeout);
58422 +BUILD_TIMER_FUNCTION(ReassocTimeout);
58423 +BUILD_TIMER_FUNCTION(DisassocTimeout);
58424 +BUILD_TIMER_FUNCTION(LinkDownExec);
58425 +#ifdef LEAP_SUPPORT
58426 +BUILD_TIMER_FUNCTION(LeapAuthTimeout);
58427 +#endif
58428 +BUILD_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
58429 +BUILD_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
58430 +#ifdef QOS_DLS_SUPPORT
58431 +BUILD_TIMER_FUNCTION(DlsTimeoutAction);
58432 +#endif // QOS_DLS_SUPPORT //
58433 +#endif // CONFIG_STA_SUPPORT //
58434 +
58435 +
58436 +
58437 +
58438 +// for wireless system event message
58439 +char const *pWirelessSysEventText[IW_SYS_EVENT_TYPE_NUM] = {
58440 + // system status event
58441 + "had associated successfully", /* IW_ASSOC_EVENT_FLAG */
58442 + "had disassociated", /* IW_DISASSOC_EVENT_FLAG */
58443 + "had deauthenticated", /* IW_DEAUTH_EVENT_FLAG */
58444 + "had been aged-out and disassociated", /* IW_AGEOUT_EVENT_FLAG */
58445 + "occurred CounterMeasures attack", /* IW_COUNTER_MEASURES_EVENT_FLAG */
58446 + "occurred replay counter different in Key Handshaking", /* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */
58447 + "occurred RSNIE different in Key Handshaking", /* IW_RSNIE_DIFF_EVENT_FLAG */
58448 + "occurred MIC different in Key Handshaking", /* IW_MIC_DIFF_EVENT_FLAG */
58449 + "occurred ICV error in RX", /* IW_ICV_ERROR_EVENT_FLAG */
58450 + "occurred MIC error in RX", /* IW_MIC_ERROR_EVENT_FLAG */
58451 + "Group Key Handshaking timeout", /* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */
58452 + "Pairwise Key Handshaking timeout", /* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */
58453 + "RSN IE sanity check failure", /* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */
58454 + "set key done in WPA/WPAPSK", /* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */
58455 + "set key done in WPA2/WPA2PSK", /* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */
58456 + "connects with our wireless client", /* IW_STA_LINKUP_EVENT_FLAG */
58457 + "disconnects with our wireless client", /* IW_STA_LINKDOWN_EVENT_FLAG */
58458 + "scan completed" /* IW_SCAN_COMPLETED_EVENT_FLAG */
58459 + "scan terminate!! Busy!! Enqueue fail!!" /* IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG */
58460 + };
58461 +
58462 +// for wireless IDS_spoof_attack event message
58463 +char const *pWirelessSpoofEventText[IW_SPOOF_EVENT_TYPE_NUM] = {
58464 + "detected conflict SSID", /* IW_CONFLICT_SSID_EVENT_FLAG */
58465 + "detected spoofed association response", /* IW_SPOOF_ASSOC_RESP_EVENT_FLAG */
58466 + "detected spoofed reassociation responses", /* IW_SPOOF_REASSOC_RESP_EVENT_FLAG */
58467 + "detected spoofed probe response", /* IW_SPOOF_PROBE_RESP_EVENT_FLAG */
58468 + "detected spoofed beacon", /* IW_SPOOF_BEACON_EVENT_FLAG */
58469 + "detected spoofed disassociation", /* IW_SPOOF_DISASSOC_EVENT_FLAG */
58470 + "detected spoofed authentication", /* IW_SPOOF_AUTH_EVENT_FLAG */
58471 + "detected spoofed deauthentication", /* IW_SPOOF_DEAUTH_EVENT_FLAG */
58472 + "detected spoofed unknown management frame", /* IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG */
58473 + "detected replay attack" /* IW_REPLAY_ATTACK_EVENT_FLAG */
58474 + };
58475 +
58476 +// for wireless IDS_flooding_attack event message
58477 +char const *pWirelessFloodEventText[IW_FLOOD_EVENT_TYPE_NUM] = {
58478 + "detected authentication flooding", /* IW_FLOOD_AUTH_EVENT_FLAG */
58479 + "detected association request flooding", /* IW_FLOOD_ASSOC_REQ_EVENT_FLAG */
58480 + "detected reassociation request flooding", /* IW_FLOOD_REASSOC_REQ_EVENT_FLAG */
58481 + "detected probe request flooding", /* IW_FLOOD_PROBE_REQ_EVENT_FLAG */
58482 + "detected disassociation flooding", /* IW_FLOOD_DISASSOC_EVENT_FLAG */
58483 + "detected deauthentication flooding", /* IW_FLOOD_DEAUTH_EVENT_FLAG */
58484 + "detected 802.1x eap-request flooding" /* IW_FLOOD_EAP_REQ_EVENT_FLAG */
58485 + };
58486 +
58487 +
58488 +/* timeout -- ms */
58489 +VOID RTMP_SetPeriodicTimer(
58490 + IN NDIS_MINIPORT_TIMER *pTimer,
58491 + IN unsigned long timeout)
58492 +{
58493 + timeout = ((timeout*HZ) / 1000);
58494 + pTimer->expires = jiffies + timeout;
58495 + add_timer(pTimer);
58496 +}
58497 +
58498 +/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */
58499 +VOID RTMP_OS_Init_Timer(
58500 + IN PRTMP_ADAPTER pAd,
58501 + IN NDIS_MINIPORT_TIMER *pTimer,
58502 + IN TIMER_FUNCTION function,
58503 + IN PVOID data)
58504 +{
58505 + init_timer(pTimer);
58506 + pTimer->data = (unsigned long)data;
58507 + pTimer->function = function;
58508 +}
58509 +
58510 +
58511 +VOID RTMP_OS_Add_Timer(
58512 + IN NDIS_MINIPORT_TIMER *pTimer,
58513 + IN unsigned long timeout)
58514 +{
58515 + if (timer_pending(pTimer))
58516 + return;
58517 +
58518 + timeout = ((timeout*HZ) / 1000);
58519 + pTimer->expires = jiffies + timeout;
58520 + add_timer(pTimer);
58521 +}
58522 +
58523 +VOID RTMP_OS_Mod_Timer(
58524 + IN NDIS_MINIPORT_TIMER *pTimer,
58525 + IN unsigned long timeout)
58526 +{
58527 + timeout = ((timeout*HZ) / 1000);
58528 + mod_timer(pTimer, jiffies + timeout);
58529 +}
58530 +
58531 +VOID RTMP_OS_Del_Timer(
58532 + IN NDIS_MINIPORT_TIMER *pTimer,
58533 + OUT BOOLEAN *pCancelled)
58534 +{
58535 + if (timer_pending(pTimer))
58536 + {
58537 + *pCancelled = del_timer_sync(pTimer);
58538 + }
58539 + else
58540 + {
58541 + *pCancelled = TRUE;
58542 + }
58543 +
58544 +}
58545 +
58546 +VOID RTMP_OS_Release_Packet(
58547 + IN PRTMP_ADAPTER pAd,
58548 + IN PQUEUE_ENTRY pEntry)
58549 +{
58550 + //RTMPFreeNdisPacket(pAd, (struct sk_buff *)pEntry);
58551 +}
58552 +
58553 +// Unify all delay routine by using udelay
58554 +VOID RTMPusecDelay(
58555 + IN ULONG usec)
58556 +{
58557 + ULONG i;
58558 +
58559 + for (i = 0; i < (usec / 50); i++)
58560 + udelay(50);
58561 +
58562 + if (usec % 50)
58563 + udelay(usec % 50);
58564 +}
58565 +
58566 +void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time)
58567 +{
58568 + time->u.LowPart = jiffies;
58569 +}
58570 +
58571 +// pAd MUST allow to be NULL
58572 +NDIS_STATUS os_alloc_mem(
58573 + IN PRTMP_ADAPTER pAd,
58574 + OUT PUCHAR *mem,
58575 + IN ULONG size)
58576 +{
58577 + *mem = (PUCHAR) kmalloc(size, GFP_ATOMIC);
58578 + if (*mem)
58579 + return (NDIS_STATUS_SUCCESS);
58580 + else
58581 + return (NDIS_STATUS_FAILURE);
58582 +}
58583 +
58584 +// pAd MUST allow to be NULL
58585 +NDIS_STATUS os_free_mem(
58586 + IN PRTMP_ADAPTER pAd,
58587 + IN PUCHAR mem)
58588 +{
58589 +
58590 + ASSERT(mem);
58591 + kfree(mem);
58592 + return (NDIS_STATUS_SUCCESS);
58593 +}
58594 +
58595 +
58596 +PNDIS_PACKET RTMP_AllocateFragPacketBuffer(
58597 + IN PRTMP_ADAPTER pAd,
58598 + IN ULONG Length)
58599 +{
58600 + struct sk_buff *pkt;
58601 +
58602 + pkt = dev_alloc_skb(Length);
58603 +
58604 + if (pkt == NULL)
58605 + {
58606 + DBGPRINT(RT_DEBUG_ERROR, ("can't allocate frag rx %ld size packet\n",Length));
58607 + }
58608 +
58609 + if (pkt)
58610 + {
58611 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
58612 + }
58613 +
58614 + return (PNDIS_PACKET) pkt;
58615 +}
58616 +
58617 +
58618 +PNDIS_PACKET RTMP_AllocateTxPacketBuffer(
58619 + IN PRTMP_ADAPTER pAd,
58620 + IN ULONG Length,
58621 + IN BOOLEAN Cached,
58622 + OUT PVOID *VirtualAddress)
58623 +{
58624 + struct sk_buff *pkt;
58625 +
58626 + pkt = dev_alloc_skb(Length);
58627 +
58628 + if (pkt == NULL)
58629 + {
58630 + DBGPRINT(RT_DEBUG_ERROR, ("can't allocate tx %ld size packet\n",Length));
58631 + }
58632 +
58633 + if (pkt)
58634 + {
58635 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
58636 + *VirtualAddress = (PVOID) pkt->data;
58637 + }
58638 + else
58639 + {
58640 + *VirtualAddress = (PVOID) NULL;
58641 + }
58642 +
58643 + return (PNDIS_PACKET) pkt;
58644 +}
58645 +
58646 +
58647 +VOID build_tx_packet(
58648 + IN PRTMP_ADAPTER pAd,
58649 + IN PNDIS_PACKET pPacket,
58650 + IN PUCHAR pFrame,
58651 + IN ULONG FrameLen)
58652 +{
58653 +
58654 + struct sk_buff *pTxPkt;
58655 +
58656 + ASSERT(pPacket);
58657 + pTxPkt = RTPKT_TO_OSPKT(pPacket);
58658 +
58659 + NdisMoveMemory(skb_put(pTxPkt, FrameLen), pFrame, FrameLen);
58660 +}
58661 +
58662 +VOID RTMPFreeAdapter(
58663 + IN PRTMP_ADAPTER pAd)
58664 +{
58665 + POS_COOKIE os_cookie;
58666 + int index;
58667 +
58668 + os_cookie=(POS_COOKIE)pAd->OS_Cookie;
58669 +
58670 + kfree(pAd->BeaconBuf);
58671 +
58672 +
58673 + NdisFreeSpinLock(&pAd->MgmtRingLock);
58674 +
58675 +
58676 + for (index =0 ; index < NUM_OF_TX_RING; index++)
58677 + {
58678 + NdisFreeSpinLock(&pAd->TxSwQueueLock[index]);
58679 + NdisFreeSpinLock(&pAd->DeQueueLock[index]);
58680 + pAd->DeQueueRunning[index] = FALSE;
58681 + }
58682 +
58683 + NdisFreeSpinLock(&pAd->irq_lock);
58684 +
58685 +
58686 + vfree(pAd); // pci_free_consistent(os_cookie->pci_dev,sizeof(RTMP_ADAPTER),pAd,os_cookie->pAd_pa);
58687 + kfree(os_cookie);
58688 +}
58689 +
58690 +BOOLEAN OS_Need_Clone_Packet(void)
58691 +{
58692 + return (FALSE);
58693 +}
58694 +
58695 +
58696 +
58697 +/*
58698 + ========================================================================
58699 +
58700 + Routine Description:
58701 + clone an input NDIS PACKET to another one. The new internally created NDIS PACKET
58702 + must have only one NDIS BUFFER
58703 + return - byte copied. 0 means can't create NDIS PACKET
58704 + NOTE: internally created NDIS_PACKET should be destroyed by RTMPFreeNdisPacket
58705 +
58706 + Arguments:
58707 + pAd Pointer to our adapter
58708 + pInsAMSDUHdr EWC A-MSDU format has extra 14-bytes header. if TRUE, insert this 14-byte hdr in front of MSDU.
58709 + *pSrcTotalLen return total packet length. This lenght is calculated with 802.3 format packet.
58710 +
58711 + Return Value:
58712 + NDIS_STATUS_SUCCESS
58713 + NDIS_STATUS_FAILURE
58714 +
58715 + Note:
58716 +
58717 + ========================================================================
58718 +*/
58719 +NDIS_STATUS RTMPCloneNdisPacket(
58720 + IN PRTMP_ADAPTER pAd,
58721 + IN BOOLEAN pInsAMSDUHdr,
58722 + IN PNDIS_PACKET pInPacket,
58723 + OUT PNDIS_PACKET *ppOutPacket)
58724 +{
58725 +
58726 + struct sk_buff *pkt;
58727 +
58728 + ASSERT(pInPacket);
58729 + ASSERT(ppOutPacket);
58730 +
58731 + // 1. Allocate a packet
58732 + pkt = dev_alloc_skb(2048);
58733 +
58734 + if (pkt == NULL)
58735 + {
58736 + return NDIS_STATUS_FAILURE;
58737 + }
58738 +
58739 + skb_put(pkt, GET_OS_PKT_LEN(pInPacket));
58740 + NdisMoveMemory(pkt->data, GET_OS_PKT_DATAPTR(pInPacket), GET_OS_PKT_LEN(pInPacket));
58741 + *ppOutPacket = OSPKT_TO_RTPKT(pkt);
58742 +
58743 +
58744 + RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
58745 +
58746 + printk("###Clone###\n");
58747 +
58748 + return NDIS_STATUS_SUCCESS;
58749 +}
58750 +
58751 +
58752 +// the allocated NDIS PACKET must be freed via RTMPFreeNdisPacket()
58753 +NDIS_STATUS RTMPAllocateNdisPacket(
58754 + IN PRTMP_ADAPTER pAd,
58755 + OUT PNDIS_PACKET *ppPacket,
58756 + IN PUCHAR pHeader,
58757 + IN UINT HeaderLen,
58758 + IN PUCHAR pData,
58759 + IN UINT DataLen)
58760 +{
58761 + PNDIS_PACKET pPacket;
58762 + ASSERT(pData);
58763 + ASSERT(DataLen);
58764 +
58765 + // 1. Allocate a packet
58766 + pPacket = (PNDIS_PACKET *) dev_alloc_skb(HeaderLen + DataLen + TXPADDING_SIZE);
58767 + if (pPacket == NULL)
58768 + {
58769 + *ppPacket = NULL;
58770 +#ifdef DEBUG
58771 + printk("RTMPAllocateNdisPacket Fail\n\n");
58772 +#endif
58773 + return NDIS_STATUS_FAILURE;
58774 + }
58775 +
58776 + // 2. clone the frame content
58777 + if (HeaderLen > 0)
58778 + NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket), pHeader, HeaderLen);
58779 + if (DataLen > 0)
58780 + NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket) + HeaderLen, pData, DataLen);
58781 +
58782 + // 3. update length of packet
58783 + skb_put(GET_OS_PKT_TYPE(pPacket), HeaderLen+DataLen);
58784 +
58785 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
58786 +// printk("%s : pPacket = %p, len = %d\n", __FUNCTION__, pPacket, GET_OS_PKT_LEN(pPacket));
58787 + *ppPacket = pPacket;
58788 + return NDIS_STATUS_SUCCESS;
58789 +}
58790 +
58791 +/*
58792 + ========================================================================
58793 + Description:
58794 + This routine frees a miniport internally allocated NDIS_PACKET and its
58795 + corresponding NDIS_BUFFER and allocated memory.
58796 + ========================================================================
58797 +*/
58798 +VOID RTMPFreeNdisPacket(
58799 + IN PRTMP_ADAPTER pAd,
58800 + IN PNDIS_PACKET pPacket)
58801 +{
58802 + dev_kfree_skb_any(RTPKT_TO_OSPKT(pPacket));
58803 +}
58804 +
58805 +
58806 +// IRQL = DISPATCH_LEVEL
58807 +// NOTE: we do have an assumption here, that Byte0 and Byte1 always reasid at the same
58808 +// scatter gather buffer
58809 +NDIS_STATUS Sniff2BytesFromNdisBuffer(
58810 + IN PNDIS_BUFFER pFirstBuffer,
58811 + IN UCHAR DesiredOffset,
58812 + OUT PUCHAR pByte0,
58813 + OUT PUCHAR pByte1)
58814 +{
58815 + *pByte0 = *(PUCHAR)(pFirstBuffer + DesiredOffset);
58816 + *pByte1 = *(PUCHAR)(pFirstBuffer + DesiredOffset + 1);
58817 +
58818 + return NDIS_STATUS_SUCCESS;
58819 +}
58820 +
58821 +
58822 +void RTMP_QueryPacketInfo(
58823 + IN PNDIS_PACKET pPacket,
58824 + OUT PACKET_INFO *pPacketInfo,
58825 + OUT PUCHAR *pSrcBufVA,
58826 + OUT UINT *pSrcBufLen)
58827 +{
58828 + pPacketInfo->BufferCount = 1;
58829 + pPacketInfo->pFirstBuffer = GET_OS_PKT_DATAPTR(pPacket);
58830 + pPacketInfo->PhysicalBufferCount = 1;
58831 + pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
58832 +
58833 + *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
58834 + *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
58835 +}
58836 +
58837 +void RTMP_QueryNextPacketInfo(
58838 + IN PNDIS_PACKET *ppPacket,
58839 + OUT PACKET_INFO *pPacketInfo,
58840 + OUT PUCHAR *pSrcBufVA,
58841 + OUT UINT *pSrcBufLen)
58842 +{
58843 + PNDIS_PACKET pPacket = NULL;
58844 +
58845 + if (*ppPacket)
58846 + pPacket = GET_OS_PKT_NEXT(*ppPacket);
58847 +
58848 + if (pPacket)
58849 + {
58850 + pPacketInfo->BufferCount = 1;
58851 + pPacketInfo->pFirstBuffer = GET_OS_PKT_DATAPTR(pPacket);
58852 + pPacketInfo->PhysicalBufferCount = 1;
58853 + pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
58854 +
58855 + *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
58856 + *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
58857 + *ppPacket = GET_OS_PKT_NEXT(pPacket);
58858 + }
58859 + else
58860 + {
58861 + pPacketInfo->BufferCount = 0;
58862 + pPacketInfo->pFirstBuffer = NULL;
58863 + pPacketInfo->PhysicalBufferCount = 0;
58864 + pPacketInfo->TotalPacketLength = 0;
58865 +
58866 + *pSrcBufVA = NULL;
58867 + *pSrcBufLen = 0;
58868 + *ppPacket = NULL;
58869 + }
58870 +}
58871 +
58872 +// not yet support MBSS
58873 +PNET_DEV get_netdev_from_bssid(
58874 + IN PRTMP_ADAPTER pAd,
58875 + IN UCHAR FromWhichBSSID)
58876 +{
58877 + PNET_DEV dev_p = NULL;
58878 +
58879 +
58880 +#ifdef CONFIG_STA_SUPPORT
58881 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
58882 + {
58883 + dev_p = pAd->net_dev;
58884 + }
58885 +#endif // CONFIG_STA_SUPPORT //
58886 +
58887 + ASSERT(dev_p);
58888 + return dev_p; /* return one of MBSS */
58889 +}
58890 +
58891 +PNDIS_PACKET DuplicatePacket(
58892 + IN PRTMP_ADAPTER pAd,
58893 + IN PNDIS_PACKET pPacket,
58894 + IN UCHAR FromWhichBSSID)
58895 +{
58896 + struct sk_buff *skb;
58897 + PNDIS_PACKET pRetPacket = NULL;
58898 + USHORT DataSize;
58899 + UCHAR *pData;
58900 +
58901 + DataSize = (USHORT) GET_OS_PKT_LEN(pPacket);
58902 + pData = (PUCHAR) GET_OS_PKT_DATAPTR(pPacket);
58903 +
58904 +
58905 + skb = skb_clone(RTPKT_TO_OSPKT(pPacket), MEM_ALLOC_FLAG);
58906 + if (skb)
58907 + {
58908 + skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58909 + pRetPacket = OSPKT_TO_RTPKT(skb);
58910 + }
58911 +
58912 + return pRetPacket;
58913 +
58914 +}
58915 +
58916 +PNDIS_PACKET duplicate_pkt(
58917 + IN PRTMP_ADAPTER pAd,
58918 + IN PUCHAR pHeader802_3,
58919 + IN UINT HdrLen,
58920 + IN PUCHAR pData,
58921 + IN ULONG DataSize,
58922 + IN UCHAR FromWhichBSSID)
58923 +{
58924 + struct sk_buff *skb;
58925 + PNDIS_PACKET pPacket = NULL;
58926 +
58927 +
58928 + if ((skb = __dev_alloc_skb(HdrLen + DataSize + 2, MEM_ALLOC_FLAG)) != NULL)
58929 + {
58930 + skb_reserve(skb, 2);
58931 + NdisMoveMemory(skb->tail, pHeader802_3, HdrLen);
58932 + skb_put(skb, HdrLen);
58933 + NdisMoveMemory(skb->tail, pData, DataSize);
58934 + skb_put(skb, DataSize);
58935 + skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
58936 + pPacket = OSPKT_TO_RTPKT(skb);
58937 + }
58938 +
58939 + return pPacket;
58940 +}
58941 +
58942 +
58943 +#define TKIP_TX_MIC_SIZE 8
58944 +PNDIS_PACKET duplicate_pkt_with_TKIP_MIC(
58945 + IN PRTMP_ADAPTER pAd,
58946 + IN PNDIS_PACKET pPacket)
58947 +{
58948 + struct sk_buff *skb, *newskb;
58949 +
58950 +
58951 + skb = RTPKT_TO_OSPKT(pPacket);
58952 + if (skb_tailroom(skb) < TKIP_TX_MIC_SIZE)
58953 + {
58954 + // alloc a new skb and copy the packet
58955 + newskb = skb_copy_expand(skb, skb_headroom(skb), TKIP_TX_MIC_SIZE, GFP_ATOMIC);
58956 + dev_kfree_skb_any(skb);
58957 + if (newskb == NULL)
58958 + {
58959 + DBGPRINT(RT_DEBUG_ERROR, ("Extend Tx.MIC for packet failed!, dropping packet!\n"));
58960 + return NULL;
58961 + }
58962 + skb = newskb;
58963 + }
58964 +
58965 + return OSPKT_TO_RTPKT(skb);
58966 +}
58967 +
58968 +
58969 +
58970 +
58971 +PNDIS_PACKET ClonePacket(
58972 + IN PRTMP_ADAPTER pAd,
58973 + IN PNDIS_PACKET pPacket,
58974 + IN PUCHAR pData,
58975 + IN ULONG DataSize)
58976 +{
58977 + struct sk_buff *pRxPkt;
58978 + struct sk_buff *pClonedPkt;
58979 +
58980 + ASSERT(pPacket);
58981 + pRxPkt = RTPKT_TO_OSPKT(pPacket);
58982 +
58983 + // clone the packet
58984 + pClonedPkt = skb_clone(pRxPkt, MEM_ALLOC_FLAG);
58985 +
58986 + if (pClonedPkt)
58987 + {
58988 + // set the correct dataptr and data len
58989 + pClonedPkt->dev = pRxPkt->dev;
58990 + pClonedPkt->data = pData;
58991 + pClonedPkt->len = DataSize;
58992 + pClonedPkt->tail = pClonedPkt->data + pClonedPkt->len;
58993 + ASSERT(DataSize < 1530);
58994 + }
58995 + return pClonedPkt;
58996 +}
58997 +
58998 +//
58999 +// change OS packet DataPtr and DataLen
59000 +//
59001 +void update_os_packet_info(
59002 + IN PRTMP_ADAPTER pAd,
59003 + IN RX_BLK *pRxBlk,
59004 + IN UCHAR FromWhichBSSID)
59005 +{
59006 + struct sk_buff *pOSPkt;
59007 +
59008 + ASSERT(pRxBlk->pRxPacket);
59009 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
59010 +
59011 + pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
59012 + pOSPkt->data = pRxBlk->pData;
59013 + pOSPkt->len = pRxBlk->DataSize;
59014 + pOSPkt->tail = pOSPkt->data + pOSPkt->len;
59015 +}
59016 +
59017 +
59018 +void wlan_802_11_to_802_3_packet(
59019 + IN PRTMP_ADAPTER pAd,
59020 + IN RX_BLK *pRxBlk,
59021 + IN PUCHAR pHeader802_3,
59022 + IN UCHAR FromWhichBSSID)
59023 +{
59024 + struct sk_buff *pOSPkt;
59025 +
59026 + ASSERT(pRxBlk->pRxPacket);
59027 + ASSERT(pHeader802_3);
59028 +
59029 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
59030 +
59031 + pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
59032 + pOSPkt->data = pRxBlk->pData;
59033 + pOSPkt->len = pRxBlk->DataSize;
59034 + pOSPkt->tail = pOSPkt->data + pOSPkt->len;
59035 +
59036 + //
59037 + // copy 802.3 header
59038 + //
59039 + //
59040 +
59041 +#ifdef CONFIG_STA_SUPPORT
59042 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
59043 + NdisMoveMemory(skb_push(pOSPkt, LENGTH_802_3), pHeader802_3, LENGTH_802_3);
59044 +#endif // CONFIG_STA_SUPPORT //
59045 + }
59046 +
59047 +
59048 +
59049 +void announce_802_3_packet(
59050 + IN PRTMP_ADAPTER pAd,
59051 + IN PNDIS_PACKET pPacket)
59052 +{
59053 +
59054 + struct sk_buff *pRxPkt;
59055 +
59056 + ASSERT(pPacket);
59057 +
59058 + pRxPkt = RTPKT_TO_OSPKT(pPacket);
59059 +
59060 +#ifdef CONFIG_STA_SUPPORT
59061 +#endif // CONFIG_STA_SUPPORT //
59062 +
59063 + /* Push up the protocol stack */
59064 +#ifdef IKANOS_VX_1X0
59065 + IKANOS_DataFrameRx(pAd, pRxPkt->dev, pRxPkt, pRxPkt->len);
59066 +#else
59067 + pRxPkt->protocol = eth_type_trans(pRxPkt, pRxPkt->dev);
59068 +
59069 +//#ifdef CONFIG_5VT_ENHANCE
59070 +// *(int*)(pRxPkt->cb) = BRIDGE_TAG;
59071 +//#endif
59072 + netif_rx(pRxPkt);
59073 +#endif // IKANOS_VX_1X0 //
59074 +}
59075 +
59076 +
59077 +PRTMP_SCATTER_GATHER_LIST
59078 +rt_get_sg_list_from_packet(PNDIS_PACKET pPacket, RTMP_SCATTER_GATHER_LIST *sg)
59079 +{
59080 + sg->NumberOfElements = 1;
59081 + sg->Elements[0].Address = GET_OS_PKT_DATAPTR(pPacket);
59082 + sg->Elements[0].Length = GET_OS_PKT_LEN(pPacket);
59083 + return (sg);
59084 +}
59085 +
59086 +void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen)
59087 +{
59088 + unsigned char *pt;
59089 + int x;
59090 +
59091 + if (RTDebugLevel < RT_DEBUG_TRACE)
59092 + return;
59093 +
59094 + pt = pSrcBufVA;
59095 + printk("%s: %p, len = %d\n",str, pSrcBufVA, SrcBufLen);
59096 + for (x=0; x<SrcBufLen; x++)
59097 + {
59098 + if (x % 16 == 0)
59099 + printk("0x%04x : ", x);
59100 + printk("%02x ", ((unsigned char)pt[x]));
59101 + if (x%16 == 15) printk("\n");
59102 + }
59103 + printk("\n");
59104 +}
59105 +
59106 +/*
59107 + ========================================================================
59108 +
59109 + Routine Description:
59110 + Send log message through wireless event
59111 +
59112 + Support standard iw_event with IWEVCUSTOM. It is used below.
59113 +
59114 + iwreq_data.data.flags is used to store event_flag that is defined by user.
59115 + iwreq_data.data.length is the length of the event log.
59116 +
59117 + The format of the event log is composed of the entry's MAC address and
59118 + the desired log message (refer to pWirelessEventText).
59119 +
59120 + ex: 11:22:33:44:55:66 has associated successfully
59121 +
59122 + p.s. The requirement of Wireless Extension is v15 or newer.
59123 +
59124 + ========================================================================
59125 +*/
59126 +VOID RTMPSendWirelessEvent(
59127 + IN PRTMP_ADAPTER pAd,
59128 + IN USHORT Event_flag,
59129 + IN PUCHAR pAddr,
59130 + IN UCHAR BssIdx,
59131 + IN CHAR Rssi)
59132 +{
59133 +#if WIRELESS_EXT >= 15
59134 +
59135 + union iwreq_data wrqu;
59136 + PUCHAR pBuf = NULL, pBufPtr = NULL;
59137 + USHORT event, type, BufLen;
59138 + UCHAR event_table_len = 0;
59139 +
59140 + type = Event_flag & 0xFF00;
59141 + event = Event_flag & 0x00FF;
59142 +
59143 + switch (type)
59144 + {
59145 + case IW_SYS_EVENT_FLAG_START:
59146 + event_table_len = IW_SYS_EVENT_TYPE_NUM;
59147 + break;
59148 +
59149 + case IW_SPOOF_EVENT_FLAG_START:
59150 + event_table_len = IW_SPOOF_EVENT_TYPE_NUM;
59151 + break;
59152 +
59153 + case IW_FLOOD_EVENT_FLAG_START:
59154 + event_table_len = IW_FLOOD_EVENT_TYPE_NUM;
59155 + break;
59156 + }
59157 +
59158 + if (event_table_len == 0)
59159 + {
59160 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The type(%0x02x) is not valid.\n", __FUNCTION__, type));
59161 + return;
59162 + }
59163 +
59164 + if (event >= event_table_len)
59165 + {
59166 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The event(%0x02x) is not valid.\n", __FUNCTION__, event));
59167 + return;
59168 + }
59169 +
59170 + //Allocate memory and copy the msg.
59171 + if((pBuf = kmalloc(IW_CUSTOM_MAX_LEN, GFP_ATOMIC)) != NULL)
59172 + {
59173 + //Prepare the payload
59174 + memset(pBuf, 0, IW_CUSTOM_MAX_LEN);
59175 +
59176 + pBufPtr = pBuf;
59177 +
59178 + if (pAddr)
59179 + pBufPtr += sprintf(pBufPtr, "(RT2860) STA(%02x:%02x:%02x:%02x:%02x:%02x) ", PRINT_MAC(pAddr));
59180 + else if (BssIdx < MAX_MBSSID_NUM)
59181 + pBufPtr += sprintf(pBufPtr, "(RT2860) BSS(ra%d) ", BssIdx);
59182 + else
59183 + pBufPtr += sprintf(pBufPtr, "(RT2860) ");
59184 +
59185 + if (type == IW_SYS_EVENT_FLAG_START)
59186 + pBufPtr += sprintf(pBufPtr, "%s", pWirelessSysEventText[event]);
59187 + else if (type == IW_SPOOF_EVENT_FLAG_START)
59188 + pBufPtr += sprintf(pBufPtr, "%s (RSSI=%d)", pWirelessSpoofEventText[event], Rssi);
59189 + else if (type == IW_FLOOD_EVENT_FLAG_START)
59190 + pBufPtr += sprintf(pBufPtr, "%s", pWirelessFloodEventText[event]);
59191 + else
59192 + pBufPtr += sprintf(pBufPtr, "%s", "unknown event");
59193 +
59194 + pBufPtr[pBufPtr - pBuf] = '\0';
59195 + BufLen = pBufPtr - pBuf;
59196 +
59197 + memset(&wrqu, 0, sizeof(wrqu));
59198 + wrqu.data.flags = Event_flag;
59199 + wrqu.data.length = BufLen;
59200 +
59201 + //send wireless event
59202 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, pBuf);
59203 +
59204 + //DBGPRINT(RT_DEBUG_TRACE, ("%s : %s\n", __FUNCTION__, pBuf));
59205 +
59206 + kfree(pBuf);
59207 + }
59208 + else
59209 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Can't allocate memory for wireless event.\n", __FUNCTION__));
59210 +#else
59211 + DBGPRINT(RT_DEBUG_ERROR, ("%s : The Wireless Extension MUST be v15 or newer.\n", __FUNCTION__));
59212 +#endif /* WIRELESS_EXT >= 15 */
59213 +}
59214 +
59215 +
59216 +#ifdef CONFIG_STA_SUPPORT
59217 +void send_monitor_packets(
59218 + IN PRTMP_ADAPTER pAd,
59219 + IN RX_BLK *pRxBlk)
59220 +{
59221 + struct sk_buff *pOSPkt;
59222 + wlan_ng_prism2_header *ph;
59223 + int rate_index = 0;
59224 + USHORT header_len = 0;
59225 + UCHAR temp_header[40] = {0};
59226 +
59227 + u_int32_t ralinkrate[256] = {2,4,11,22, 12,18,24,36,48,72,96, 108, 109, 110, 111, 112, 13, 26, 39, 52,78,104, 117, 130, 26, 52, 78,104, 156, 208, 234, 260, 27, 54,81,108,162, 216, 243, 270, // Last 38
59228 + 54, 108, 162, 216, 324, 432, 486, 540, 14, 29, 43, 57, 87, 115, 130, 144, 29, 59,87,115, 173, 230,260, 288, 30, 60,90,120,180,240,270,300,60,120,180,240,360,480,540,600, 0,1,2,3,4,5,6,7,8,9,10,
59229 + 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80};
59230 +
59231 +
59232 + ASSERT(pRxBlk->pRxPacket);
59233 + if (pRxBlk->DataSize < 10)
59234 + {
59235 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Size is too small! (%d)\n", __FUNCTION__, pRxBlk->DataSize));
59236 + goto err_free_sk_buff;
59237 + }
59238 +
59239 + if (pRxBlk->DataSize + sizeof(wlan_ng_prism2_header) > RX_BUFFER_AGGRESIZE)
59240 + {
59241 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Size is too large! (%d)\n", __FUNCTION__, pRxBlk->DataSize + sizeof(wlan_ng_prism2_header)));
59242 + goto err_free_sk_buff;
59243 + }
59244 +
59245 + pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
59246 + pOSPkt->dev = get_netdev_from_bssid(pAd, BSS0);
59247 + if (pRxBlk->pHeader->FC.Type == BTYPE_DATA)
59248 + {
59249 + pRxBlk->DataSize -= LENGTH_802_11;
59250 + if ((pRxBlk->pHeader->FC.ToDs == 1) &&
59251 + (pRxBlk->pHeader->FC.FrDs == 1))
59252 + header_len = LENGTH_802_11_WITH_ADDR4;
59253 + else
59254 + header_len = LENGTH_802_11;
59255 +
59256 + // QOS
59257 + if (pRxBlk->pHeader->FC.SubType & 0x08)
59258 + {
59259 + header_len += 2;
59260 + // Data skip QOS contorl field
59261 + pRxBlk->DataSize -=2;
59262 + }
59263 +
59264 + // Order bit: A-Ralink or HTC+
59265 + if (pRxBlk->pHeader->FC.Order)
59266 + {
59267 + header_len += 4;
59268 + // Data skip HTC contorl field
59269 + pRxBlk->DataSize -= 4;
59270 + }
59271 +
59272 + // Copy Header
59273 + if (header_len <= 40)
59274 + NdisMoveMemory(temp_header, pRxBlk->pData, header_len);
59275 +
59276 + // skip HW padding
59277 + if (pRxBlk->RxD.L2PAD)
59278 + pRxBlk->pData += (header_len + 2);
59279 + else
59280 + pRxBlk->pData += header_len;
59281 + } //end if
59282 +
59283 +
59284 + if (pRxBlk->DataSize < pOSPkt->len) {
59285 + skb_trim(pOSPkt,pRxBlk->DataSize);
59286 + } else {
59287 + skb_put(pOSPkt,(pRxBlk->DataSize - pOSPkt->len));
59288 + } //end if
59289 +
59290 + if ((pRxBlk->pData - pOSPkt->data) > 0) {
59291 + skb_put(pOSPkt,(pRxBlk->pData - pOSPkt->data));
59292 + skb_pull(pOSPkt,(pRxBlk->pData - pOSPkt->data));
59293 + } //end if
59294 +
59295 + if (skb_headroom(pOSPkt) < (sizeof(wlan_ng_prism2_header)+ header_len)) {
59296 + if (pskb_expand_head(pOSPkt, (sizeof(wlan_ng_prism2_header) + header_len), 0, GFP_ATOMIC)) {
59297 + DBGPRINT(RT_DEBUG_ERROR, ("%s : Reallocate header size of sk_buff fail!\n", __FUNCTION__));
59298 + goto err_free_sk_buff;
59299 + } //end if
59300 + } //end if
59301 +
59302 + if (header_len > 0)
59303 + NdisMoveMemory(skb_push(pOSPkt, header_len), temp_header, header_len);
59304 +
59305 + ph = (wlan_ng_prism2_header *) skb_push(pOSPkt, sizeof(wlan_ng_prism2_header));
59306 + NdisZeroMemory(ph, sizeof(wlan_ng_prism2_header));
59307 +
59308 + ph->msgcode = DIDmsg_lnxind_wlansniffrm;
59309 + ph->msglen = sizeof(wlan_ng_prism2_header);
59310 + strcpy(ph->devname, pAd->net_dev->name);
59311 +
59312 + ph->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime;
59313 + ph->hosttime.status = 0;
59314 + ph->hosttime.len = 4;
59315 + ph->hosttime.data = jiffies;
59316 +
59317 + ph->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime;
59318 + ph->mactime.status = 0;
59319 + ph->mactime.len = 0;
59320 + ph->mactime.data = 0;
59321 +
59322 + ph->istx.did = DIDmsg_lnxind_wlansniffrm_istx;
59323 + ph->istx.status = 0;
59324 + ph->istx.len = 0;
59325 + ph->istx.data = 0;
59326 +
59327 + ph->channel.did = DIDmsg_lnxind_wlansniffrm_channel;
59328 + ph->channel.status = 0;
59329 + ph->channel.len = 4;
59330 +
59331 + ph->channel.data = (u_int32_t)pAd->CommonCfg.Channel;
59332 +
59333 + ph->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi;
59334 + ph->rssi.status = 0;
59335 + ph->rssi.len = 4;
59336 + ph->rssi.data = (u_int32_t)RTMPMaxRssi(pAd, ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI0, RSSI_0), ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI1, RSSI_1), ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI2, RSSI_2));;
59337 +
59338 + ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal;
59339 + ph->signal.status = 0;
59340 + ph->signal.len = 4;
59341 + ph->signal.data = 0; //rssi + noise;
59342 +
59343 + ph->noise.did = DIDmsg_lnxind_wlansniffrm_noise;
59344 + ph->noise.status = 0;
59345 + ph->noise.len = 4;
59346 + ph->noise.data = 0;
59347 +
59348 +#ifdef DOT11_N_SUPPORT
59349 + if (pRxBlk->pRxWI->PHYMODE >= MODE_HTMIX)
59350 + {
59351 + rate_index = 16 + ((UCHAR)pRxBlk->pRxWI->BW *16) + ((UCHAR)pRxBlk->pRxWI->ShortGI *32) + ((UCHAR)pRxBlk->pRxWI->MCS);
59352 + }
59353 + else
59354 +#endif // DOT11_N_SUPPORT //
59355 + if (pRxBlk->pRxWI->PHYMODE == MODE_OFDM)
59356 + rate_index = (UCHAR)(pRxBlk->pRxWI->MCS) + 4;
59357 + else
59358 + rate_index = (UCHAR)(pRxBlk->pRxWI->MCS);
59359 + if (rate_index < 0)
59360 + rate_index = 0;
59361 + if (rate_index > 255)
59362 + rate_index = 255;
59363 +
59364 + ph->rate.did = DIDmsg_lnxind_wlansniffrm_rate;
59365 + ph->rate.status = 0;
59366 + ph->rate.len = 4;
59367 + ph->rate.data = ralinkrate[rate_index];
59368 +
59369 + ph->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen;
59370 + ph->frmlen.status = 0;
59371 + ph->frmlen.len = 4;
59372 + ph->frmlen.data = (u_int32_t)pRxBlk->DataSize;
59373 +
59374 +
59375 + pOSPkt->pkt_type = PACKET_OTHERHOST;
59376 + pOSPkt->protocol = eth_type_trans(pOSPkt, pOSPkt->dev);
59377 + pOSPkt->ip_summed = CHECKSUM_NONE;
59378 + netif_rx(pOSPkt);
59379 +
59380 + return;
59381 +
59382 +err_free_sk_buff:
59383 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
59384 + return;
59385 +
59386 +}
59387 +#endif // CONFIG_STA_SUPPORT //
59388 +
59389 +
59390 +void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify)
59391 +{
59392 +
59393 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
59394 + daemonize(pThreadName /*"%s",pAd->net_dev->name*/);
59395 +
59396 + allow_signal(SIGTERM);
59397 + allow_signal(SIGKILL);
59398 + current->flags |= PF_NOFREEZE;
59399 +#else
59400 + unsigned long flags;
59401 +
59402 + daemonize();
59403 + reparent_to_init();
59404 + strcpy(current->comm, pThreadName);
59405 +
59406 + siginitsetinv(&current->blocked, sigmask(SIGTERM) | sigmask(SIGKILL));
59407 +
59408 + /* Allow interception of SIGKILL only
59409 + * Don't allow other signals to interrupt the transmission */
59410 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22)
59411 + spin_lock_irqsave(&current->sigmask_lock, flags);
59412 + flush_signals(current);
59413 + recalc_sigpending(current);
59414 + spin_unlock_irqrestore(&current->sigmask_lock, flags);
59415 +#endif
59416 +#endif
59417 +
59418 + /* signal that we've started the thread */
59419 + complete(pNotify);
59420 +
59421 +}
59422 +
59423 +void RTMP_IndicateMediaState(
59424 + IN PRTMP_ADAPTER pAd)
59425 +{
59426 + if (pAd->CommonCfg.bWirelessEvent)
59427 + {
59428 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
59429 + {
59430 + RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
59431 + }
59432 + else
59433 + {
59434 + RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
59435 + }
59436 + }
59437 +}
59438 +
59439 --- /dev/null
59440 +++ b/drivers/staging/rt3070/rt_linux.h
59441 @@ -0,0 +1,887 @@
59442 +/*
59443 + *************************************************************************
59444 + * Ralink Tech Inc.
59445 + * 5F., No.36, Taiyuan St., Jhubei City,
59446 + * Hsinchu County 302,
59447 + * Taiwan, R.O.C.
59448 + *
59449 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
59450 + *
59451 + * This program is free software; you can redistribute it and/or modify *
59452 + * it under the terms of the GNU General Public License as published by *
59453 + * the Free Software Foundation; either version 2 of the License, or *
59454 + * (at your option) any later version. *
59455 + * *
59456 + * This program is distributed in the hope that it will be useful, *
59457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
59458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
59459 + * GNU General Public License for more details. *
59460 + * *
59461 + * You should have received a copy of the GNU General Public License *
59462 + * along with this program; if not, write to the *
59463 + * Free Software Foundation, Inc., *
59464 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
59465 + * *
59466 + *************************************************************************
59467 + */
59468 +
59469 +/***********************************************************************/
59470 +/* */
59471 +/* Program: rt_linux.c */
59472 +/* Created: 4/21/2006 1:17:38 PM */
59473 +/* Author: Wu Xi-Kun */
59474 +/* Comments: `description` */
59475 +/* */
59476 +/*---------------------------------------------------------------------*/
59477 +/* */
59478 +/* History: */
59479 +/* Revision 1.1 4/21/2006 1:17:38 PM xsikun */
59480 +/* Initial revision */
59481 +/* */
59482 +/***********************************************************************/
59483 +
59484 +#include "rtmp_type.h"
59485 +#include <linux/module.h>
59486 +#include <linux/version.h>
59487 +#include <linux/kernel.h>
59488 +
59489 +#include <linux/spinlock.h>
59490 +#include <linux/init.h>
59491 +#include <linux/string.h>
59492 +#include <linux/timer.h>
59493 +#include <linux/errno.h>
59494 +#include <linux/slab.h>
59495 +#include <linux/interrupt.h>
59496 +#include <linux/pci.h>
59497 +#include <linux/netdevice.h>
59498 +#include <linux/etherdevice.h>
59499 +#include <linux/skbuff.h>
59500 +#include <linux/ethtool.h>
59501 +#include <linux/wireless.h>
59502 +#include <linux/proc_fs.h>
59503 +#include <linux/delay.h>
59504 +#include <linux/if_arp.h>
59505 +#include <linux/ctype.h>
59506 +#include <linux/vmalloc.h>
59507 +
59508 +
59509 +#include <linux/wireless.h>
59510 +#include <net/iw_handler.h>
59511 +
59512 +// load firmware
59513 +#define __KERNEL_SYSCALLS__
59514 +#include <linux/unistd.h>
59515 +#include <asm/uaccess.h>
59516 +
59517 +
59518 +#define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
59519 +
59520 +#ifndef IFNAMSIZ
59521 +#define IFNAMSIZ 16
59522 +#endif
59523 +
59524 +//#define CONFIG_CKIP_SUPPORT
59525 +
59526 +#undef __inline
59527 +#define __inline static inline
59528 +
59529 +typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
59530 +
59531 +// add by kathy
59532 +
59533 +#ifdef CONFIG_STA_SUPPORT
59534 +
59535 +#ifdef RT2870
59536 +#define STA_PROFILE_PATH "/etc/Wireless/RT2870STA/RT2870STA.dat"
59537 +#define STA_RT2870_IMAGE_FILE_NAME "/etc/Wireless/RT2870STA/rt2870.bin"
59538 +#define STA_NIC_DEVICE_NAME "RT2870STA"
59539 +#define STA_DRIVER_VERSION "2.0.1.0"
59540 +#ifdef MULTIPLE_CARD_SUPPORT
59541 +#define CARD_INFO_PATH "/etc/Wireless/RT2870STA/RT2870STACard.dat"
59542 +#endif // MULTIPLE_CARD_SUPPORT //
59543 +#endif // RT2870 //
59544 +
59545 +#endif // CONFIG_STA_SUPPORT //
59546 +
59547 +
59548 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
59549 +
59550 +#define RTMP_TIME_AFTER(a,b) \
59551 + (typecheck(unsigned long, (unsigned long)a) && \
59552 + typecheck(unsigned long, (unsigned long)b) && \
59553 + ((long)(b) - (long)(a) < 0))
59554 +
59555 +#define RTMP_TIME_AFTER_EQ(a,b) \
59556 + (typecheck(unsigned long, (unsigned long)a) && \
59557 + typecheck(unsigned long, (unsigned long)b) && \
59558 + ((long)(a) - (long)(b) >= 0))
59559 +#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
59560 +#else
59561 +#define RTMP_TIME_AFTER(a,b) time_after(a, b)
59562 +#endif
59563 +
59564 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
59565 +#define RT_MOD_INC_USE_COUNT() \
59566 + if (!try_module_get(THIS_MODULE)) \
59567 + { \
59568 + DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __FUNCTION__)); \
59569 + return -1; \
59570 + }
59571 +
59572 +#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
59573 +#else
59574 +#define RT_MOD_INC_USE_COUNT() MOD_INC_USE_COUNT;
59575 +#define RT_MOD_DEC_USE_COUNT() MOD_DEC_USE_COUNT;
59576 +#endif
59577 +
59578 +#define OS_HZ HZ
59579 +
59580 +#define ETH_LENGTH_OF_ADDRESS 6
59581 +
59582 +#define IN
59583 +#define OUT
59584 +
59585 +#define NDIS_STATUS INT
59586 +#define NDIS_STATUS_SUCCESS 0x00
59587 +#define NDIS_STATUS_FAILURE 0x01
59588 +#define NDIS_STATUS_INVALID_DATA 0x02
59589 +#define NDIS_STATUS_RESOURCES 0x03
59590 +
59591 +#define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
59592 +#define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
59593 +#define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
59594 +#define MIN_NET_DEVICE_FOR_APCLI 0x20
59595 +#define MIN_NET_DEVICE_FOR_MESH 0x30
59596 +#ifdef CONFIG_STA_SUPPORT
59597 +#define MIN_NET_DEVICE_FOR_DLS 0x40
59598 +#endif // CONFIG_STA_SUPPORT //
59599 +
59600 +
59601 +#ifdef CONFIG_STA_SUPPORT
59602 +#define NDIS_PACKET_TYPE_DIRECTED 0
59603 +#define NDIS_PACKET_TYPE_MULTICAST 1
59604 +#define NDIS_PACKET_TYPE_BROADCAST 2
59605 +#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
59606 +#endif // CONFIG_STA_SUPPORT //
59607 +
59608 +struct os_lock {
59609 + spinlock_t lock;
59610 + unsigned long flags;
59611 +};
59612 +
59613 +
59614 +struct os_cookie {
59615 +
59616 +#ifdef RT2870
59617 + struct usb_device *pUsb_Dev;
59618 +
59619 + struct pid * MLMEThr_pid;
59620 + struct pid * RTUSBCmdThr_pid;
59621 + struct pid * TimerQThr_pid;
59622 +#endif // RT2870 //
59623 +
59624 + struct tasklet_struct rx_done_task;
59625 + struct tasklet_struct mgmt_dma_done_task;
59626 + struct tasklet_struct ac0_dma_done_task;
59627 + struct tasklet_struct ac1_dma_done_task;
59628 + struct tasklet_struct ac2_dma_done_task;
59629 + struct tasklet_struct ac3_dma_done_task;
59630 + struct tasklet_struct hcca_dma_done_task;
59631 + struct tasklet_struct tbtt_task;
59632 +#ifdef RT2870
59633 + struct tasklet_struct null_frame_complete_task;
59634 + struct tasklet_struct rts_frame_complete_task;
59635 + struct tasklet_struct pspoll_frame_complete_task;
59636 +#endif // RT2870 //
59637 +
59638 +
59639 + unsigned long apd_pid; //802.1x daemon pid
59640 + INT ioctl_if_type;
59641 + INT ioctl_if;
59642 +};
59643 +
59644 +typedef struct _VIRTUAL_ADAPTER
59645 +{
59646 + struct net_device *RtmpDev;
59647 + struct net_device *VirtualDev;
59648 +} VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
59649 +
59650 +#undef ASSERT
59651 +#define ASSERT(x) \
59652 +{ \
59653 + if (!(x)) \
59654 + { \
59655 + printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
59656 + } \
59657 +}
59658 +
59659 +typedef struct os_cookie * POS_COOKIE;
59660 +typedef struct pci_dev * PPCI_DEV;
59661 +typedef struct net_device * PNET_DEV;
59662 +typedef void * PNDIS_PACKET;
59663 +typedef char NDIS_PACKET;
59664 +typedef PNDIS_PACKET * PPNDIS_PACKET;
59665 +typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
59666 +typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
59667 +//typedef struct timer_list RALINK_TIMER_STRUCT;
59668 +//typedef struct timer_list * PRALINK_TIMER_STRUCT;
59669 +//typedef struct os_lock NDIS_SPIN_LOCK;
59670 +typedef spinlock_t NDIS_SPIN_LOCK;
59671 +typedef struct timer_list NDIS_MINIPORT_TIMER;
59672 +typedef void * NDIS_HANDLE;
59673 +typedef char * PNDIS_BUFFER;
59674 +
59675 +
59676 +
59677 +void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
59678 +
59679 +dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
59680 +void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
59681 +
59682 +
59683 +////////////////////////////////////////
59684 +// MOVE TO rtmp.h ?
59685 +/////////////////////////////////////////
59686 +#define PKTSRC_NDIS 0x7f
59687 +#define PKTSRC_DRIVER 0x0f
59688 +#define PRINT_MAC(addr) \
59689 + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
59690 +
59691 +
59692 +#define RT2860_PCI_DEVICE_ID 0x0601
59693 +
59694 +#ifdef RT2870
59695 +#define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
59696 +
59697 +#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
59698 +#endif // RT2870 //
59699 +
59700 +
59701 +#define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
59702 + dma_cache_wback(_ptr, _size)
59703 +
59704 +
59705 +//////////////////////////////////////////
59706 +//
59707 +//////////////////////////////////////////
59708 +
59709 +
59710 +#define NdisMIndicateStatus(_w, _x, _y, _z)
59711 +
59712 +
59713 +typedef struct timer_list RTMP_OS_TIMER;
59714 +
59715 +#ifdef RT2870
59716 +/* ----------------- Timer Related MARCO ---------------*/
59717 +// In RT2870, we have a lot of timer functions and will read/write register, it's
59718 +// not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
59719 +// to ctrl pipe). So we need a wrapper function to take care it.
59720 +
59721 +typedef VOID (*RT2870_TIMER_HANDLE)(
59722 + IN PVOID SystemSpecific1,
59723 + IN PVOID FunctionContext,
59724 + IN PVOID SystemSpecific2,
59725 + IN PVOID SystemSpecific3);
59726 +#endif // RT2870 //
59727 +
59728 +
59729 +typedef struct _RALINK_TIMER_STRUCT {
59730 + RTMP_OS_TIMER TimerObj; // Ndis Timer object
59731 + BOOLEAN Valid; // Set to True when call RTMPInitTimer
59732 + BOOLEAN State; // True if timer cancelled
59733 + BOOLEAN PeriodicType; // True if timer is periodic timer
59734 + BOOLEAN Repeat; // True if periodic timer
59735 + ULONG TimerValue; // Timer value in milliseconds
59736 + ULONG cookie; // os specific object
59737 +#ifdef RT2870
59738 + RT2870_TIMER_HANDLE handle;
59739 + void *pAd;
59740 +#endif // RT2870 //
59741 +} RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
59742 +
59743 +
59744 +#ifdef RT2870
59745 +
59746 +typedef enum _RT2870_KERNEL_THREAD_STATUS_
59747 +{
59748 + RT2870_THREAD_UNKNOWN = 0,
59749 + RT2870_THREAD_INITED = 1,
59750 + RT2870_THREAD_RUNNING = 2,
59751 + RT2870_THREAD_STOPED = 4,
59752 +}RT2870_KERNEL_THREAD_STATUS;
59753 +
59754 +#define RT2870_THREAD_CAN_DO_INSERT (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
59755 +
59756 +typedef struct _RT2870_TIMER_ENTRY_
59757 +{
59758 + RALINK_TIMER_STRUCT *pRaTimer;
59759 + struct _RT2870_TIMER_ENTRY_ *pNext;
59760 +}RT2870_TIMER_ENTRY;
59761 +
59762 +
59763 +#define TIMER_QUEUE_SIZE_MAX 128
59764 +typedef struct _RT2870_TIMER_QUEUE_
59765 +{
59766 + unsigned int status;
59767 + //wait_queue_head_t timerWaitQ;
59768 + //atomic_t count;
59769 + UCHAR *pTimerQPoll;
59770 + RT2870_TIMER_ENTRY *pQPollFreeList;
59771 + RT2870_TIMER_ENTRY *pQHead;
59772 + RT2870_TIMER_ENTRY *pQTail;
59773 +}RT2870_TIMER_QUEUE;
59774 +#endif // RT2870 //
59775 +
59776 +
59777 +//#define DBG 1
59778 +
59779 +//
59780 +// MACRO for debugging information
59781 +//
59782 +
59783 +#ifdef DBG
59784 +extern ULONG RTDebugLevel;
59785 +
59786 +#define DBGPRINT_RAW(Level, Fmt) \
59787 +{ \
59788 + if (Level <= RTDebugLevel) \
59789 + { \
59790 + printk Fmt; \
59791 + } \
59792 +}
59793 +
59794 +#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
59795 +
59796 +
59797 +#define DBGPRINT_ERR(Fmt) \
59798 +{ \
59799 + printk("ERROR!!! "); \
59800 + printk Fmt; \
59801 +}
59802 +
59803 +#define DBGPRINT_S(Status, Fmt) \
59804 +{ \
59805 + printk Fmt; \
59806 +}
59807 +
59808 +
59809 +#else
59810 +#define DBGPRINT(Level, Fmt)
59811 +#define DBGPRINT_RAW(Level, Fmt)
59812 +#define DBGPRINT_S(Status, Fmt)
59813 +#define DBGPRINT_ERR(Fmt)
59814 +#endif
59815 +
59816 +
59817 +//
59818 +// spin_lock enhanced for Nested spin lock
59819 +//
59820 +#define NdisAllocateSpinLock(__lock) \
59821 +{ \
59822 + spin_lock_init((spinlock_t *)(__lock)); \
59823 +}
59824 +
59825 +#define NdisFreeSpinLock(lock) \
59826 +{ \
59827 +}
59828 +
59829 +
59830 +#define RTMP_SEM_LOCK(__lock) \
59831 +{ \
59832 + spin_lock_bh((spinlock_t *)(__lock)); \
59833 +}
59834 +
59835 +#define RTMP_SEM_UNLOCK(__lock) \
59836 +{ \
59837 + spin_unlock_bh((spinlock_t *)(__lock)); \
59838 +}
59839 +
59840 +// sample, use semaphore lock to replace IRQ lock, 2007/11/15
59841 +#define RTMP_IRQ_LOCK(__lock, __irqflags) \
59842 +{ \
59843 + __irqflags = 0; \
59844 + spin_lock_bh((spinlock_t *)(__lock)); \
59845 + pAd->irq_disabled |= 1; \
59846 +}
59847 +
59848 +#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
59849 +{ \
59850 + pAd->irq_disabled &= 0; \
59851 + spin_unlock_bh((spinlock_t *)(__lock)); \
59852 +}
59853 +
59854 +#define RTMP_INT_LOCK(__lock, __irqflags) \
59855 +{ \
59856 + spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
59857 +}
59858 +
59859 +#define RTMP_INT_UNLOCK(__lock, __irqflag) \
59860 +{ \
59861 + spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
59862 +}
59863 +
59864 +#ifdef RT2870
59865 +#define RTMP_IO_READ32(_A, _R, _pV) \
59866 + RTUSBReadMACRegister(_A, _R, _pV)
59867 +
59868 +#define RTMP_IO_READ8(_A, _R, _pV) \
59869 +{ \
59870 +}
59871 +
59872 +#define RTMP_IO_WRITE32(_A, _R, _V) \
59873 + RTUSBWriteMACRegister(_A, _R, _V)
59874 +
59875 +
59876 +#define RTMP_IO_WRITE8(_A, _R, _V) \
59877 +{ \
59878 + USHORT _Val = _V; \
59879 + RTUSBSingleWrite(_A, _R, _Val); \
59880 +}
59881 +
59882 +
59883 +#define RTMP_IO_WRITE16(_A, _R, _V) \
59884 +{ \
59885 + RTUSBSingleWrite(_A, _R, _V); \
59886 +}
59887 +#endif // RT2870 //
59888 +
59889 +#ifndef wait_event_interruptible_timeout
59890 +#define __wait_event_interruptible_timeout(wq, condition, ret) \
59891 +do { \
59892 + wait_queue_t __wait; \
59893 + init_waitqueue_entry(&__wait, current); \
59894 + add_wait_queue(&wq, &__wait); \
59895 + for (;;) { \
59896 + set_current_state(TASK_INTERRUPTIBLE); \
59897 + if (condition) \
59898 + break; \
59899 + if (!signal_pending(current)) { \
59900 + ret = schedule_timeout(ret); \
59901 + if (!ret) \
59902 + break; \
59903 + continue; \
59904 + } \
59905 + ret = -ERESTARTSYS; \
59906 + break; \
59907 + } \
59908 + current->state = TASK_RUNNING; \
59909 + remove_wait_queue(&wq, &__wait); \
59910 +} while (0)
59911 +
59912 +#define wait_event_interruptible_timeout(wq, condition, timeout) \
59913 +({ \
59914 + long __ret = timeout; \
59915 + if (!(condition)) \
59916 + __wait_event_interruptible_timeout(wq, condition, __ret); \
59917 + __ret; \
59918 +})
59919 +#endif
59920 +#define ONE_TICK 1
59921 +#define OS_WAIT(_time) \
59922 +{ int _i; \
59923 + long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
59924 + wait_queue_head_t _wait; \
59925 + init_waitqueue_head(&_wait); \
59926 + for (_i=0; _i<(_loop); _i++) \
59927 + wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
59928 +
59929 +
59930 +/* Modified by Wu Xi-Kun 4/21/2006 */
59931 +typedef void (*TIMER_FUNCTION)(unsigned long);
59932 +
59933 +#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
59934 +
59935 +#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
59936 +#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
59937 +
59938 +
59939 +#ifdef RT2870
59940 +#define BUILD_TIMER_FUNCTION(_func) \
59941 +void linux_##_func(unsigned long data) \
59942 +{ \
59943 + PRALINK_TIMER_STRUCT _pTimer = (PRALINK_TIMER_STRUCT)data; \
59944 + RT2870_TIMER_ENTRY *_pQNode; \
59945 + RTMP_ADAPTER *_pAd; \
59946 + \
59947 + _pTimer->handle = _func; \
59948 + _pAd = (RTMP_ADAPTER *)_pTimer->pAd; \
59949 + _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer); \
59950 + if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)) \
59951 + RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ); \
59952 +}
59953 +#endif // RT2870 //
59954 +
59955 +
59956 +#define DECLARE_TIMER_FUNCTION(_func) \
59957 +void linux_##_func(unsigned long data)
59958 +
59959 +#define GET_TIMER_FUNCTION(_func) \
59960 + linux_##_func
59961 +
59962 +DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
59963 +DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
59964 +DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
59965 +DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
59966 +DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
59967 +#ifdef RT2870
59968 +DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
59969 +#endif // RT2870 //
59970 +
59971 +
59972 +#ifdef CONFIG_STA_SUPPORT
59973 +DECLARE_TIMER_FUNCTION(BeaconTimeout);
59974 +DECLARE_TIMER_FUNCTION(ScanTimeout);
59975 +DECLARE_TIMER_FUNCTION(AuthTimeout);
59976 +DECLARE_TIMER_FUNCTION(AssocTimeout);
59977 +DECLARE_TIMER_FUNCTION(ReassocTimeout);
59978 +DECLARE_TIMER_FUNCTION(DisassocTimeout);
59979 +DECLARE_TIMER_FUNCTION(LinkDownExec);
59980 +#ifdef LEAP_SUPPORT
59981 +DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
59982 +#endif
59983 +DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
59984 +DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
59985 +DECLARE_TIMER_FUNCTION(PsPollWakeExec);
59986 +DECLARE_TIMER_FUNCTION(RadioOnExec);
59987 +
59988 +#ifdef QOS_DLS_SUPPORT
59989 +DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
59990 +#endif // QOS_DLS_SUPPORT //
59991 +#endif // CONFIG_STA_SUPPORT //
59992 +
59993 +#undef AP_WSC_INCLUDED
59994 +#undef STA_WSC_INCLUDED
59995 +#undef WSC_INCLUDED
59996 +
59997 +
59998 +#ifdef CONFIG_STA_SUPPORT
59999 +#endif // CONFIG_STA_SUPPORT //
60000 +
60001 +#if defined(AP_WSC_INCLUDED) || defined(STA_WSC_INCLUDED)
60002 +#define WSC_INCLUDED
60003 +#endif
60004 +
60005 +
60006 +
60007 +void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
60008 +
60009 +
60010 +/*
60011 + * packet helper
60012 + * - convert internal rt packet to os packet or
60013 + * os packet to rt packet
60014 + */
60015 +#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
60016 +#define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
60017 +
60018 +#define GET_OS_PKT_DATAPTR(_pkt) \
60019 + (RTPKT_TO_OSPKT(_pkt)->data)
60020 +
60021 +#define GET_OS_PKT_LEN(_pkt) \
60022 + (RTPKT_TO_OSPKT(_pkt)->len)
60023 +
60024 +#define GET_OS_PKT_DATATAIL(_pkt) \
60025 + (RTPKT_TO_OSPKT(_pkt)->tail)
60026 +
60027 +#define GET_OS_PKT_HEAD(_pkt) \
60028 + (RTPKT_TO_OSPKT(_pkt)->head)
60029 +
60030 +#define GET_OS_PKT_END(_pkt) \
60031 + (RTPKT_TO_OSPKT(_pkt)->end)
60032 +
60033 +#define GET_OS_PKT_NETDEV(_pkt) \
60034 + (RTPKT_TO_OSPKT(_pkt)->dev)
60035 +
60036 +#define GET_OS_PKT_TYPE(_pkt) \
60037 + (RTPKT_TO_OSPKT(_pkt))
60038 +
60039 +#define GET_OS_PKT_NEXT(_pkt) \
60040 + (RTPKT_TO_OSPKT(_pkt)->next)
60041 +
60042 +
60043 +#define OS_NTOHS(_Val) \
60044 + (ntohs(_Val))
60045 +#define OS_HTONS(_Val) \
60046 + (htons(_Val))
60047 +#define OS_NTOHL(_Val) \
60048 + (ntohl(_Val))
60049 +#define OS_HTONL(_Val) \
60050 + (htonl(_Val))
60051 +
60052 +/* statistics counter */
60053 +#define STATS_INC_RX_PACKETS(_pAd, _dev)
60054 +#define STATS_INC_TX_PACKETS(_pAd, _dev)
60055 +
60056 +#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
60057 +#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
60058 +
60059 +#define STATS_INC_RX_ERRORS(_pAd, _dev)
60060 +#define STATS_INC_TX_ERRORS(_pAd, _dev)
60061 +
60062 +#define STATS_INC_RX_DROPPED(_pAd, _dev)
60063 +#define STATS_INC_TX_DROPPED(_pAd, _dev)
60064 +
60065 +
60066 +#define CB_OFF 10
60067 +
60068 +
60069 +// check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
60070 +// ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
60071 +//
60072 +//#define RTMP_GET_PACKET_MR(_p) (RTPKT_TO_OSPKT(_p))
60073 +
60074 +// User Priority
60075 +#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
60076 +#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
60077 +
60078 +// Fragment #
60079 +#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
60080 +#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
60081 +
60082 +// 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too.
60083 +//(this value also as MAC(on-chip WCID) table index)
60084 +// 0x80~0xff: TX to a WDS link. b0~6: WDS index
60085 +#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
60086 +#define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
60087 +
60088 +// 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
60089 +#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
60090 +#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
60091 +
60092 +// RTS/CTS-to-self protection method
60093 +#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
60094 +#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
60095 +// see RTMP_S(G)ET_PACKET_EMACTAB
60096 +
60097 +// TX rate index
60098 +#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
60099 +#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
60100 +
60101 +// From which Interface
60102 +#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
60103 +#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
60104 +#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
60105 +#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
60106 +#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
60107 +#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
60108 +#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
60109 +#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
60110 +
60111 +#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
60112 +#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
60113 +
60114 +//#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
60115 +//#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) (RTPKT_TO_OSPKT(_p)->cb[8])
60116 +
60117 +//
60118 +// Sepcific Pakcet Type definition
60119 +//
60120 +#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
60121 +
60122 +#define RTMP_PACKET_SPECIFIC_DHCP 0x01
60123 +#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
60124 +#define RTMP_PACKET_SPECIFIC_IPV4 0x04
60125 +#define RTMP_PACKET_SPECIFIC_WAI 0x08
60126 +#define RTMP_PACKET_SPECIFIC_VLAN 0x10
60127 +#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
60128 +
60129 +//Specific
60130 +#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
60131 +
60132 +//DHCP
60133 +#define RTMP_SET_PACKET_DHCP(_p, _flg) \
60134 + do{ \
60135 + if (_flg) \
60136 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
60137 + else \
60138 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
60139 + }while(0)
60140 +#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
60141 +
60142 +//EAPOL
60143 +#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
60144 + do{ \
60145 + if (_flg) \
60146 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
60147 + else \
60148 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
60149 + }while(0)
60150 +#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
60151 +
60152 +//WAI
60153 +#define RTMP_SET_PACKET_WAI(_p, _flg) \
60154 + do{ \
60155 + if (_flg) \
60156 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
60157 + else \
60158 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
60159 + }while(0)
60160 +#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
60161 +
60162 +#define RTMP_GET_PACKET_LOWRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI))
60163 +
60164 +//VLAN
60165 +#define RTMP_SET_PACKET_VLAN(_p, _flg) \
60166 + do{ \
60167 + if (_flg) \
60168 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
60169 + else \
60170 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
60171 + }while(0)
60172 +#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
60173 +
60174 +//LLC/SNAP
60175 +#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
60176 + do{ \
60177 + if (_flg) \
60178 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
60179 + else \
60180 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
60181 + }while(0)
60182 +
60183 +#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
60184 +
60185 +// IP
60186 +#define RTMP_SET_PACKET_IPV4(_p, _flg) \
60187 + do{ \
60188 + if (_flg) \
60189 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
60190 + else \
60191 + (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
60192 + }while(0)
60193 +
60194 +#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
60195 +
60196 +// If this flag is set, it indicates that this EAPoL frame MUST be clear.
60197 +#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
60198 +#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
60199 +
60200 +#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
60201 +#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
60202 +
60203 +
60204 +#ifdef INF_AMAZON_SE
60205 +/*Iverson patch for WMM A5-T07 ,WirelessStaToWirelessSta do not bulk out aggregate */
60206 +#define RTMP_SET_PACKET_NOBULKOUT(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+23] = _morebit)
60207 +#define RTMP_GET_PACKET_NOBULKOUT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+23])
60208 +#endif // INF_AMAZON_SE //
60209 +
60210 +
60211 +
60212 +#ifdef CONFIG_5VT_ENHANCE
60213 +#define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
60214 +#endif
60215 +
60216 +
60217 +#define NDIS_SET_PACKET_STATUS(_p, _status)
60218 +
60219 +
60220 +#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
60221 + rt_get_sg_list_from_packet(_p, _sc)
60222 +
60223 +#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
60224 +#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
60225 +#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
60226 +#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
60227 +#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
60228 +
60229 +
60230 +#define RTMP_INC_REF(_A) 0
60231 +#define RTMP_DEC_REF(_A) 0
60232 +#define RTMP_GET_REF(_A) 0
60233 +
60234 +
60235 +
60236 +/*
60237 + * ULONG
60238 + * RTMP_GetPhysicalAddressLow(
60239 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
60240 + */
60241 +#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
60242 +
60243 +/*
60244 + * ULONG
60245 + * RTMP_GetPhysicalAddressHigh(
60246 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
60247 + */
60248 +#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
60249 +
60250 +/*
60251 + * VOID
60252 + * RTMP_SetPhysicalAddressLow(
60253 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
60254 + * IN ULONG Value);
60255 + */
60256 +#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
60257 + PhysicalAddress = Value;
60258 +
60259 +/*
60260 + * VOID
60261 + * RTMP_SetPhysicalAddressHigh(
60262 + * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
60263 + * IN ULONG Value);
60264 + */
60265 +#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
60266 +
60267 +
60268 +//CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
60269 +#define QUEUE_ENTRY_TO_PACKET(pEntry) \
60270 + (PNDIS_PACKET)(pEntry)
60271 +
60272 +#define PACKET_TO_QUEUE_ENTRY(pPacket) \
60273 + (PQUEUE_ENTRY)(pPacket)
60274 +
60275 +
60276 +#ifndef CONTAINING_RECORD
60277 +#define CONTAINING_RECORD(address, type, field) \
60278 +((type *)((PCHAR)(address) - offsetof(type, field)))
60279 +#endif
60280 +
60281 +
60282 +#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
60283 +{ \
60284 + RTMPFreeNdisPacket(_pAd, _pPacket); \
60285 +}
60286 +
60287 +
60288 +#define SWITCH_PhyAB(_pAA, _pBB) \
60289 +{ \
60290 + ULONG AABasePaHigh; \
60291 + ULONG AABasePaLow; \
60292 + ULONG BBBasePaHigh; \
60293 + ULONG BBBasePaLow; \
60294 + BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
60295 + BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
60296 + AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
60297 + AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
60298 + RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
60299 + RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
60300 + RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
60301 + RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
60302 +}
60303 +
60304 +
60305 +#define NdisWriteErrorLogEntry(_a, _b, _c, _d)
60306 +#define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
60307 +
60308 +
60309 +#define NdisAcquireSpinLock RTMP_SEM_LOCK
60310 +#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
60311 +
60312 +static inline void NdisGetSystemUpTime(ULONG *time)
60313 +{
60314 + *time = jiffies;
60315 +}
60316 +
60317 +//pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
60318 +#define QUEUE_ENTRY_TO_PKT(pEntry) \
60319 + ((PNDIS_PACKET) (pEntry))
60320 +
60321 +int rt28xx_packet_xmit(struct sk_buff *skb);
60322 +
60323 +
60324 +
60325 +void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
60326 +
60327 +
60328 +
60329 --- /dev/null
60330 +++ b/drivers/staging/rt3070/rt_main_dev.c
60331 @@ -0,0 +1,1800 @@
60332 +/*
60333 + *************************************************************************
60334 + * Ralink Tech Inc.
60335 + * 5F., No.36, Taiyuan St., Jhubei City,
60336 + * Hsinchu County 302,
60337 + * Taiwan, R.O.C.
60338 + *
60339 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
60340 + *
60341 + * This program is free software; you can redistribute it and/or modify *
60342 + * it under the terms of the GNU General Public License as published by *
60343 + * the Free Software Foundation; either version 2 of the License, or *
60344 + * (at your option) any later version. *
60345 + * *
60346 + * This program is distributed in the hope that it will be useful, *
60347 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
60348 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
60349 + * GNU General Public License for more details. *
60350 + * *
60351 + * You should have received a copy of the GNU General Public License *
60352 + * along with this program; if not, write to the *
60353 + * Free Software Foundation, Inc., *
60354 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
60355 + * *
60356 + *************************************************************************
60357 +
60358 + Module Name:
60359 + rt_main_dev.c
60360 +
60361 + Abstract:
60362 + Create and register network interface.
60363 +
60364 + Revision History:
60365 + Who When What
60366 + -------- ---------- ----------------------------------------------
60367 + Sample Mar/21/07 Merge RT2870 and RT2860 drivers.
60368 +*/
60369 +
60370 +#include "rt_config.h"
60371 +
60372 +#define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min
60373 +
60374 +#ifdef MULTIPLE_CARD_SUPPORT
60375 +// record whether the card in the card list is used in the card file
60376 +UINT8 MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
60377 +// record used card mac address in the card list
60378 +static UINT8 MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
60379 +#endif // MULTIPLE_CARD_SUPPORT //
60380 +
60381 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
60382 +UINT32 CW_MAX_IN_BITS;
60383 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
60384 +
60385 +/*---------------------------------------------------------------------*/
60386 +/* Private Variables Used */
60387 +/*---------------------------------------------------------------------*/
60388 +//static RALINK_TIMER_STRUCT PeriodicTimer;
60389 +
60390 +char *mac = ""; // default 00:00:00:00:00:00
60391 +char *hostname = ""; // default CMPC
60392 +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
60393 +MODULE_PARM (mac, "s");
60394 +#else
60395 +module_param (mac, charp, 0);
60396 +#endif
60397 +MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
60398 +
60399 +
60400 +/*---------------------------------------------------------------------*/
60401 +/* Prototypes of Functions Used */
60402 +/*---------------------------------------------------------------------*/
60403 +#ifdef DOT11_N_SUPPORT
60404 +extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
60405 +extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
60406 +#endif // DOT11_N_SUPPORT //
60407 +extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
60408 +
60409 +
60410 +// public function prototype
60411 +INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
60412 + IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
60413 +
60414 +// private function prototype
60415 +static int rt28xx_init(IN struct net_device *net_dev);
60416 +INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
60417 +
60418 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
60419 +struct net_device *alloc_netdev(
60420 + int sizeof_priv,
60421 + const char *mask,
60422 + void (*setup)(struct net_device *));
60423 +#endif // LINUX_VERSION_CODE //
60424 +
60425 +static void CfgInitHook(PRTMP_ADAPTER pAd);
60426 +//static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
60427 +
60428 +#ifdef CONFIG_STA_SUPPORT
60429 +extern const struct iw_handler_def rt28xx_iw_handler_def;
60430 +#endif // CONFIG_STA_SUPPORT //
60431 +
60432 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
60433 +extern const struct iw_handler_def rt28xx_ap_iw_handler_def;
60434 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
60435 +
60436 +#if WIRELESS_EXT >= 12
60437 +// This function will be called when query /proc
60438 +struct iw_statistics *rt28xx_get_wireless_stats(
60439 + IN struct net_device *net_dev);
60440 +#endif
60441 +
60442 +struct net_device_stats *RT28xx_get_ether_stats(
60443 + IN struct net_device *net_dev);
60444 +
60445 +/*
60446 +========================================================================
60447 +Routine Description:
60448 + Close raxx interface.
60449 +
60450 +Arguments:
60451 + *net_dev the raxx interface pointer
60452 +
60453 +Return Value:
60454 + 0 Open OK
60455 + otherwise Open Fail
60456 +
60457 +Note:
60458 + 1. if open fail, kernel will not call the close function.
60459 + 2. Free memory for
60460 + (1) Mlme Memory Handler: MlmeHalt()
60461 + (2) TX & RX: RTMPFreeTxRxRingMemory()
60462 + (3) BA Reordering: ba_reordering_resource_release()
60463 +========================================================================
60464 +*/
60465 +int MainVirtualIF_close(IN struct net_device *net_dev)
60466 +{
60467 + RTMP_ADAPTER *pAd = net_dev->ml_priv;
60468 +
60469 + // Sanity check for pAd
60470 + if (pAd == NULL)
60471 + return 0; // close ok
60472 +
60473 + netif_carrier_off(pAd->net_dev);
60474 + netif_stop_queue(pAd->net_dev);
60475 +
60476 +
60477 +
60478 + VIRTUAL_IF_DOWN(pAd);
60479 +
60480 + RT_MOD_DEC_USE_COUNT();
60481 +
60482 + return 0; // close ok
60483 +}
60484 +
60485 +/*
60486 +========================================================================
60487 +Routine Description:
60488 + Open raxx interface.
60489 +
60490 +Arguments:
60491 + *net_dev the raxx interface pointer
60492 +
60493 +Return Value:
60494 + 0 Open OK
60495 + otherwise Open Fail
60496 +
60497 +Note:
60498 + 1. if open fail, kernel will not call the close function.
60499 + 2. Free memory for
60500 + (1) Mlme Memory Handler: MlmeHalt()
60501 + (2) TX & RX: RTMPFreeTxRxRingMemory()
60502 + (3) BA Reordering: ba_reordering_resource_release()
60503 +========================================================================
60504 +*/
60505 +int MainVirtualIF_open(IN struct net_device *net_dev)
60506 +{
60507 + RTMP_ADAPTER *pAd = net_dev->ml_priv;
60508 +
60509 + // Sanity check for pAd
60510 + if (pAd == NULL)
60511 + return 0; // close ok
60512 +
60513 + if (VIRTUAL_IF_UP(pAd) != 0)
60514 + return -1;
60515 +
60516 + // increase MODULE use count
60517 + RT_MOD_INC_USE_COUNT();
60518 +
60519 + netif_start_queue(net_dev);
60520 + netif_carrier_on(net_dev);
60521 + netif_wake_queue(net_dev);
60522 +
60523 + return 0;
60524 +}
60525 +
60526 +/*
60527 +========================================================================
60528 +Routine Description:
60529 + Close raxx interface.
60530 +
60531 +Arguments:
60532 + *net_dev the raxx interface pointer
60533 +
60534 +Return Value:
60535 + 0 Open OK
60536 + otherwise Open Fail
60537 +
60538 +Note:
60539 + 1. if open fail, kernel will not call the close function.
60540 + 2. Free memory for
60541 + (1) Mlme Memory Handler: MlmeHalt()
60542 + (2) TX & RX: RTMPFreeTxRxRingMemory()
60543 + (3) BA Reordering: ba_reordering_resource_release()
60544 +========================================================================
60545 +*/
60546 +int rt28xx_close(IN PNET_DEV dev)
60547 +{
60548 + struct net_device * net_dev = (struct net_device *)dev;
60549 + RTMP_ADAPTER *pAd = net_dev->ml_priv;
60550 + BOOLEAN Cancelled = FALSE;
60551 + UINT32 i = 0;
60552 +#ifdef RT2870
60553 + DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
60554 + DECLARE_WAITQUEUE(wait, current);
60555 +
60556 + //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
60557 +#endif // RT2870 //
60558 +
60559 +
60560 + DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
60561 +
60562 + // Sanity check for pAd
60563 + if (pAd == NULL)
60564 + return 0; // close ok
60565 +
60566 +
60567 +#ifdef WDS_SUPPORT
60568 + WdsDown(pAd);
60569 +#endif // WDS_SUPPORT //
60570 +
60571 +#ifdef CONFIG_STA_SUPPORT
60572 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60573 + {
60574 +
60575 + // If dirver doesn't wake up firmware here,
60576 + // NICLoadFirmware will hang forever when interface is up again.
60577 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
60578 + {
60579 + AsicForceWakeup(pAd, TRUE);
60580 + }
60581 +
60582 +#ifdef QOS_DLS_SUPPORT
60583 + // send DLS-TEAR_DOWN message,
60584 + if (pAd->CommonCfg.bDLSCapable)
60585 + {
60586 + UCHAR i;
60587 +
60588 + // tear down local dls table entry
60589 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
60590 + {
60591 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
60592 + {
60593 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
60594 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
60595 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
60596 + }
60597 + }
60598 +
60599 + // tear down peer dls table entry
60600 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
60601 + {
60602 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
60603 + {
60604 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
60605 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
60606 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
60607 + }
60608 + }
60609 + RT28XX_MLME_HANDLER(pAd);
60610 + }
60611 +#endif // QOS_DLS_SUPPORT //
60612 +
60613 + if (INFRA_ON(pAd) &&
60614 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
60615 + {
60616 + MLME_DISASSOC_REQ_STRUCT DisReq;
60617 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
60618 +
60619 + COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
60620 + DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
60621 +
60622 + MsgElem->Machine = ASSOC_STATE_MACHINE;
60623 + MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
60624 + MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
60625 + NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
60626 +
60627 + // Prevent to connect AP again in STAMlmePeriodicExec
60628 + pAd->MlmeAux.AutoReconnectSsidLen= 32;
60629 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
60630 +
60631 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
60632 + MlmeDisassocReqAction(pAd, MsgElem);
60633 + kfree(MsgElem);
60634 +
60635 + RTMPusecDelay(1000);
60636 + }
60637 +
60638 +#ifdef RT2870
60639 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
60640 +#endif // RT2870 //
60641 +
60642 +#ifdef CCX_SUPPORT
60643 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
60644 +#endif
60645 +
60646 + RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
60647 + RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
60648 +
60649 +#ifdef WPA_SUPPLICANT_SUPPORT
60650 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
60651 + {
60652 + union iwreq_data wrqu;
60653 + // send wireless event to wpa_supplicant for infroming interface down.
60654 + memset(&wrqu, 0, sizeof(wrqu));
60655 + wrqu.data.flags = RT_INTERFACE_DOWN;
60656 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
60657 + }
60658 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
60659 +#endif // WPA_SUPPLICANT_SUPPORT //
60660 +
60661 + MlmeRadioOff(pAd);
60662 + }
60663 +#endif // CONFIG_STA_SUPPORT //
60664 +
60665 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
60666 +
60667 + for (i = 0 ; i < NUM_OF_TX_RING; i++)
60668 + {
60669 + while (pAd->DeQueueRunning[i] == TRUE)
60670 + {
60671 + printk("Waiting for TxQueue[%d] done..........\n", i);
60672 + RTMPusecDelay(1000);
60673 + }
60674 + }
60675 +
60676 +#ifdef RT2870
60677 + // ensure there are no more active urbs.
60678 + add_wait_queue (&unlink_wakeup, &wait);
60679 + pAd->wait = &unlink_wakeup;
60680 +
60681 + // maybe wait for deletions to finish.
60682 + i = 0;
60683 + //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
60684 + while(i < 25)
60685 + {
60686 + unsigned long IrqFlags;
60687 +
60688 + RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
60689 + if (pAd->PendingRx == 0)
60690 + {
60691 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
60692 + break;
60693 + }
60694 + RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
60695 +
60696 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
60697 + msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
60698 +#else
60699 + RTMPusecDelay(UNLINK_TIMEOUT_MS*1000); //Time in microsecond
60700 +#endif
60701 + i++;
60702 + }
60703 + pAd->wait = NULL;
60704 + remove_wait_queue (&unlink_wakeup, &wait);
60705 +#endif // RT2870 //
60706 +
60707 + //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
60708 +
60709 +
60710 +#ifdef RT2870
60711 + // We need clear timerQ related structure before exits of the timer thread.
60712 + RT2870_TimerQ_Exit(pAd);
60713 + // Close kernel threads or tasklets
60714 + RT28xxThreadTerminate(pAd);
60715 +#endif // RT2870 //
60716 +
60717 + // Stop Mlme state machine
60718 + MlmeHalt(pAd);
60719 +
60720 + // Close kernel threads or tasklets
60721 + kill_thread_task(pAd);
60722 +
60723 +
60724 +#ifdef CONFIG_STA_SUPPORT
60725 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60726 + {
60727 + MacTableReset(pAd);
60728 + }
60729 +#endif // CONFIG_STA_SUPPORT //
60730 +
60731 +
60732 + MeasureReqTabExit(pAd);
60733 + TpcReqTabExit(pAd);
60734 +
60735 +
60736 +
60737 +
60738 + // Free Ring or USB buffers
60739 + RTMPFreeTxRxRingMemory(pAd);
60740 +
60741 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
60742 +
60743 +#ifdef DOT11_N_SUPPORT
60744 + // Free BA reorder resource
60745 + ba_reordering_resource_release(pAd);
60746 +#endif // DOT11_N_SUPPORT //
60747 +
60748 +#ifdef RT2870
60749 +#ifdef INF_AMAZON_SE
60750 + if (pAd->UsbVendorReqBuf)
60751 + os_free_mem(pAd, pAd->UsbVendorReqBuf);
60752 +#endif // INF_AMAZON_SE //
60753 +#endif // RT2870 //
60754 +
60755 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
60756 +
60757 + return 0; // close ok
60758 +} /* End of rt28xx_close */
60759 +
60760 +static int rt28xx_init(IN struct net_device *net_dev)
60761 +{
60762 + PRTMP_ADAPTER pAd = net_dev->ml_priv;
60763 + UINT index;
60764 + UCHAR TmpPhy;
60765 +// ULONG Value=0;
60766 + NDIS_STATUS Status;
60767 +// OID_SET_HT_PHYMODE SetHT;
60768 +// WPDMA_GLO_CFG_STRUC GloCfg;
60769 + UINT32 MacCsr0 = 0;
60770 + UINT32 MacValue = 0;
60771 +
60772 +#ifdef RT2870
60773 +#ifdef INF_AMAZON_SE
60774 + init_MUTEX(&(pAd->UsbVendorReq_semaphore));
60775 + os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
60776 + if (pAd->UsbVendorReqBuf == NULL)
60777 + {
60778 + DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
60779 + goto err0;
60780 + }
60781 +#endif // INF_AMAZON_SE //
60782 +#endif // RT2870 //
60783 +
60784 +#ifdef DOT11_N_SUPPORT
60785 + // Allocate BA Reordering memory
60786 + ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
60787 +#endif // DOT11_N_SUPPORT //
60788 +
60789 + // Make sure MAC gets ready.
60790 + index = 0;
60791 + do
60792 + {
60793 + RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
60794 + pAd->MACVersion = MacCsr0;
60795 +
60796 + if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
60797 + break;
60798 +
60799 + RTMPusecDelay(10);
60800 + } while (index++ < 100);
60801 +
60802 + DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
60803 +/*Iverson patch PCIE L1 issue */
60804 +
60805 + // Disable DMA
60806 + RT28XXDMADisable(pAd);
60807 +
60808 +
60809 + // Load 8051 firmware
60810 + Status = NICLoadFirmware(pAd);
60811 + if (Status != NDIS_STATUS_SUCCESS)
60812 + {
60813 + DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
60814 + goto err1;
60815 + }
60816 +
60817 + NICLoadRateSwitchingParams(pAd);
60818 +
60819 + // Disable interrupts here which is as soon as possible
60820 + // This statement should never be true. We might consider to remove it later
60821 +
60822 + Status = RTMPAllocTxRxRingMemory(pAd);
60823 + if (Status != NDIS_STATUS_SUCCESS)
60824 + {
60825 + DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
60826 + goto err1;
60827 + }
60828 +
60829 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
60830 +
60831 + // initialize MLME
60832 + //
60833 +
60834 + Status = MlmeInit(pAd);
60835 + if (Status != NDIS_STATUS_SUCCESS)
60836 + {
60837 + DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
60838 + goto err2;
60839 + }
60840 +
60841 + // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
60842 + //
60843 + UserCfgInit(pAd);
60844 +
60845 +#ifdef RT2870
60846 + // We need init timerQ related structure before create the timer thread.
60847 + RT2870_TimerQ_Init(pAd);
60848 +#endif // RT2870 //
60849 +
60850 + RT28XX_TASK_THREAD_INIT(pAd, Status);
60851 + if (Status != NDIS_STATUS_SUCCESS)
60852 + goto err1;
60853 +
60854 +// COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
60855 +// pAd->bForcePrintTX = TRUE;
60856 +
60857 + CfgInitHook(pAd);
60858 +
60859 +
60860 +#ifdef BLOCK_NET_IF
60861 + initblockQueueTab(pAd);
60862 +#endif // BLOCK_NET_IF //
60863 +
60864 +#ifdef CONFIG_STA_SUPPORT
60865 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
60866 + NdisAllocateSpinLock(&pAd->MacTabLock);
60867 +#endif // CONFIG_STA_SUPPORT //
60868 +
60869 + MeasureReqTabInit(pAd);
60870 + TpcReqTabInit(pAd);
60871 +
60872 + //
60873 + // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
60874 + //
60875 + Status = NICInitializeAdapter(pAd, TRUE);
60876 + if (Status != NDIS_STATUS_SUCCESS)
60877 + {
60878 + DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
60879 + if (Status != NDIS_STATUS_SUCCESS)
60880 + goto err3;
60881 + }
60882 +
60883 + // Read parameters from Config File
60884 + Status = RTMPReadParametersHook(pAd);
60885 +
60886 + printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60887 + if (Status != NDIS_STATUS_SUCCESS)
60888 + {
60889 + DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
60890 + goto err4;
60891 + }
60892 +
60893 +#ifdef RT2870
60894 + pAd->CommonCfg.bMultipleIRP = FALSE;
60895 +
60896 + if (pAd->CommonCfg.bMultipleIRP)
60897 + pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
60898 + else
60899 + pAd->CommonCfg.NumOfBulkInIRP = 1;
60900 +#endif // RT2870 //
60901 +
60902 +
60903 + //Init Ba Capability parameters.
60904 +// RT28XX_BA_INIT(pAd);
60905 +#ifdef DOT11_N_SUPPORT
60906 + pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
60907 + pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
60908 + pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
60909 + pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
60910 + // UPdata to HT IE
60911 + pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
60912 + pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
60913 + pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
60914 +#endif // DOT11_N_SUPPORT //
60915 +
60916 + // after reading Registry, we now know if in AP mode or STA mode
60917 +
60918 + // Load 8051 firmware; crash when FW image not existent
60919 + // Status = NICLoadFirmware(pAd);
60920 + // if (Status != NDIS_STATUS_SUCCESS)
60921 + // break;
60922 +
60923 + printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60924 +
60925 + // We should read EEPROM for all cases. rt2860b
60926 + NICReadEEPROMParameters(pAd, mac);
60927 +#ifdef CONFIG_STA_SUPPORT
60928 +#endif // CONFIG_STA_SUPPORT //
60929 +
60930 + printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
60931 +
60932 + NICInitAsicFromEEPROM(pAd); //rt2860b
60933 +
60934 + // Set PHY to appropriate mode
60935 + TmpPhy = pAd->CommonCfg.PhyMode;
60936 + pAd->CommonCfg.PhyMode = 0xff;
60937 + RTMPSetPhyMode(pAd, TmpPhy);
60938 +#ifdef DOT11_N_SUPPORT
60939 + SetCommonHT(pAd);
60940 +#endif // DOT11_N_SUPPORT //
60941 +
60942 + // No valid channels.
60943 + if (pAd->ChannelListNum == 0)
60944 + {
60945 + printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
60946 + goto err4;
60947 + }
60948 +
60949 +#ifdef DOT11_N_SUPPORT
60950 + printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
60951 + pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
60952 + pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
60953 +#endif // DOT11_N_SUPPORT //
60954 +
60955 +#ifdef RT30xx
60956 + //Init RT30xx RFRegisters after read RFIC type from EEPROM
60957 + NICInitRT30xxRFRegisters(pAd);
60958 +#endif // RT30xx //
60959 +
60960 +// APInitialize(pAd);
60961 +
60962 +#ifdef IKANOS_VX_1X0
60963 + VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
60964 +#endif // IKANOS_VX_1X0 //
60965 +
60966 + //
60967 + // Initialize RF register to default value
60968 + //
60969 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
60970 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
60971 +
60972 + if (pAd && (Status != NDIS_STATUS_SUCCESS))
60973 + {
60974 + //
60975 + // Undo everything if it failed
60976 + //
60977 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
60978 + {
60979 +// NdisMDeregisterInterrupt(&pAd->Interrupt);
60980 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
60981 + }
60982 +// RTMPFreeAdapter(pAd); // we will free it in disconnect()
60983 + }
60984 + else if (pAd)
60985 + {
60986 + // Microsoft HCT require driver send a disconnect event after driver initialization.
60987 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
60988 +// pAd->IndicateMediaState = NdisMediaStateDisconnected;
60989 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
60990 +
60991 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
60992 +
60993 +
60994 +#ifdef RT2870
60995 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
60996 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
60997 +
60998 + //
60999 + // Support multiple BulkIn IRP,
61000 + // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
61001 + //
61002 + for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
61003 + {
61004 + RTUSBBulkReceive(pAd);
61005 + DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
61006 + }
61007 +#endif // RT2870 //
61008 + }// end of else
61009 +
61010 +
61011 + DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
61012 +
61013 + return TRUE;
61014 +
61015 +
61016 +err4:
61017 +err3:
61018 + MlmeHalt(pAd);
61019 +err2:
61020 + RTMPFreeTxRxRingMemory(pAd);
61021 +// RTMPFreeAdapter(pAd);
61022 +err1:
61023 +
61024 +#ifdef DOT11_N_SUPPORT
61025 + os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
61026 +#endif // DOT11_N_SUPPORT //
61027 + RT28XX_IRQ_RELEASE(net_dev);
61028 +
61029 + // shall not set priv to NULL here because the priv didn't been free yet.
61030 + //net_dev->ml_priv = 0;
61031 +#ifdef INF_AMAZON_SE
61032 +err0:
61033 +#endif // INF_AMAZON_SE //
61034 + printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
61035 + return FALSE;
61036 +} /* End of rt28xx_init */
61037 +
61038 +
61039 +/*
61040 +========================================================================
61041 +Routine Description:
61042 + Open raxx interface.
61043 +
61044 +Arguments:
61045 + *net_dev the raxx interface pointer
61046 +
61047 +Return Value:
61048 + 0 Open OK
61049 + otherwise Open Fail
61050 +
61051 +Note:
61052 +========================================================================
61053 +*/
61054 +int rt28xx_open(IN PNET_DEV dev)
61055 +{
61056 + struct net_device * net_dev = (struct net_device *)dev;
61057 + PRTMP_ADAPTER pAd = net_dev->ml_priv;
61058 + int retval = 0;
61059 + POS_COOKIE pObj;
61060 +
61061 +
61062 + // Sanity check for pAd
61063 + if (pAd == NULL)
61064 + {
61065 + /* if 1st open fail, pAd will be free;
61066 + So the net_dev->ml_priv will be NULL in 2rd open */
61067 + return -1;
61068 + }
61069 +
61070 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
61071 + if (pAd->OpMode == OPMODE_AP)
61072 + {
61073 + CW_MAX_IN_BITS = 6;
61074 + }
61075 + else if (pAd->OpMode == OPMODE_STA)
61076 + {
61077 + CW_MAX_IN_BITS = 10;
61078 + }
61079 +
61080 +#if WIRELESS_EXT >= 12
61081 + if (net_dev->ml_priv_flags == INT_MAIN)
61082 + {
61083 + if (pAd->OpMode == OPMODE_AP)
61084 + net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
61085 + else if (pAd->OpMode == OPMODE_STA)
61086 + net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
61087 + }
61088 +#endif // WIRELESS_EXT >= 12 //
61089 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
61090 +
61091 +#ifdef CONFIG_STA_SUPPORT
61092 +#endif // CONFIG_STA_SUPPORT //
61093 +
61094 + // Init
61095 + pObj = (POS_COOKIE)pAd->OS_Cookie;
61096 +
61097 + // reset Adapter flags
61098 + RTMP_CLEAR_FLAGS(pAd);
61099 +
61100 + // Request interrupt service routine for PCI device
61101 + // register the interrupt routine with the os
61102 + RT28XX_IRQ_REQUEST(net_dev);
61103 +
61104 +
61105 + // Init BssTab & ChannelInfo tabbles for auto channel select.
61106 +
61107 +
61108 + // Chip & other init
61109 + if (rt28xx_init(net_dev) == FALSE)
61110 + goto err;
61111 +
61112 +#ifdef CONFIG_STA_SUPPORT
61113 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61114 + {
61115 + NdisZeroMemory(pAd->StaCfg.dev_name, 16);
61116 + NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
61117 + }
61118 +#endif // CONFIG_STA_SUPPORT //
61119 +
61120 + // Set up the Mac address
61121 + NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
61122 +
61123 + // Init IRQ parameters
61124 + RT28XX_IRQ_INIT(pAd);
61125 +
61126 + // Various AP function init
61127 +
61128 +
61129 +
61130 +#ifdef CONFIG_STA_SUPPORT
61131 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61132 + {
61133 +#ifdef WPA_SUPPLICANT_SUPPORT
61134 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
61135 + {
61136 + union iwreq_data wrqu;
61137 + // send wireless event to wpa_supplicant for infroming interface down.
61138 + memset(&wrqu, 0, sizeof(wrqu));
61139 + wrqu.data.flags = RT_INTERFACE_UP;
61140 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
61141 + }
61142 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
61143 +#endif // WPA_SUPPLICANT_SUPPORT //
61144 +
61145 + }
61146 +#endif // CONFIG_STA_SUPPORT //
61147 +
61148 + // Enable Interrupt
61149 + RT28XX_IRQ_ENABLE(pAd);
61150 +
61151 + // Now Enable RxTx
61152 + RTMPEnableRxTx(pAd);
61153 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
61154 +
61155 + {
61156 + UINT32 reg = 0;
61157 + RTMP_IO_READ32(pAd, 0x1300, &reg); // clear garbage interrupts
61158 + printk("0x1300 = %08x\n", reg);
61159 + }
61160 +
61161 + {
61162 +// u32 reg;
61163 +// u8 byte;
61164 +// u16 tmp;
61165 +
61166 +// RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg);
61167 +
61168 +// tmp = 0x0805;
61169 +// reg = (reg & 0xffff0000) | tmp;
61170 +// RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
61171 +
61172 + }
61173 +
61174 +#ifdef CONFIG_STA_SUPPORT
61175 +#endif // CONFIG_STA_SUPPORT //
61176 +
61177 + return (retval);
61178 +
61179 +err:
61180 + return (-1);
61181 +} /* End of rt28xx_open */
61182 +
61183 +
61184 +/* Must not be called for mdev and apdev */
61185 +static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
61186 +{
61187 + NDIS_STATUS Status;
61188 + INT i=0;
61189 + CHAR slot_name[IFNAMSIZ];
61190 + struct net_device *device;
61191 +
61192 +
61193 + //ether_setup(dev);
61194 + dev->hard_start_xmit = rt28xx_send_packets;
61195 +
61196 +#ifdef IKANOS_VX_1X0
61197 + dev->hard_start_xmit = IKANOS_DataFramesTx;
61198 +#endif // IKANOS_VX_1X0 //
61199 +
61200 +// dev->set_multicast_list = ieee80211_set_multicast_list;
61201 +// dev->change_mtu = ieee80211_change_mtu;
61202 +#ifdef CONFIG_STA_SUPPORT
61203 +#if WIRELESS_EXT >= 12
61204 + if (pAd->OpMode == OPMODE_STA)
61205 + {
61206 + dev->wireless_handlers = &rt28xx_iw_handler_def;
61207 + }
61208 +#endif //WIRELESS_EXT >= 12
61209 +#endif // CONFIG_STA_SUPPORT //
61210 +
61211 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
61212 +#if WIRELESS_EXT >= 12
61213 + if (pAd->OpMode == OPMODE_AP)
61214 + {
61215 + dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
61216 + }
61217 +#endif //WIRELESS_EXT >= 12
61218 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
61219 +
61220 +#if WIRELESS_EXT < 21
61221 + dev->get_wireless_stats = rt28xx_get_wireless_stats;
61222 +#endif
61223 + dev->get_stats = RT28xx_get_ether_stats;
61224 + dev->open = MainVirtualIF_open; //rt28xx_open;
61225 + dev->stop = MainVirtualIF_close; //rt28xx_close;
61226 +// dev->uninit = ieee80211_if_reinit;
61227 +// dev->destructor = ieee80211_if_free;
61228 + dev->priv_flags = INT_MAIN;
61229 + dev->do_ioctl = rt28xx_ioctl;
61230 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
61231 + dev->validate_addr = NULL;
61232 +#endif
61233 + // find available device name
61234 + for (i = 0; i < 8; i++)
61235 + {
61236 +#ifdef MULTIPLE_CARD_SUPPORT
61237 + if (pAd->MC_RowID >= 0)
61238 + sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
61239 + else
61240 +#endif // MULTIPLE_CARD_SUPPORT //
61241 + sprintf(slot_name, "ra%d", i);
61242 +
61243 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
61244 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
61245 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
61246 + device = dev_get_by_name(dev_net(dev), slot_name);
61247 +#else
61248 + device = dev_get_by_name(dev->nd_net, slot_name);
61249 +#endif
61250 +#else
61251 + device = dev_get_by_name(slot_name);
61252 +#endif
61253 + if (device != NULL) dev_put(device);
61254 +#else
61255 + for (device = dev_base; device != NULL; device = device->next)
61256 + {
61257 + if (strncmp(device->name, slot_name, 4) == 0)
61258 + break;
61259 + }
61260 +#endif
61261 + if(device == NULL)
61262 + break;
61263 + }
61264 +
61265 + if(i == 8)
61266 + {
61267 + DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
61268 + Status = NDIS_STATUS_FAILURE;
61269 + }
61270 + else
61271 + {
61272 +#ifdef MULTIPLE_CARD_SUPPORT
61273 + if (pAd->MC_RowID >= 0)
61274 + sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
61275 + else
61276 +#endif // MULTIPLE_CARD_SUPPORT //
61277 + sprintf(dev->name, "ra%d", i);
61278 + Status = NDIS_STATUS_SUCCESS;
61279 + }
61280 +
61281 + return Status;
61282 +
61283 +}
61284 +
61285 +
61286 +#ifdef MULTIPLE_CARD_SUPPORT
61287 +/*
61288 +========================================================================
61289 +Routine Description:
61290 + Get card profile path.
61291 +
61292 +Arguments:
61293 + pAd
61294 +
61295 +Return Value:
61296 + TRUE - Find a card profile
61297 + FALSE - use default profile
61298 +
61299 +Note:
61300 +========================================================================
61301 +*/
61302 +extern INT RTMPGetKeyParameter(
61303 + IN PCHAR key,
61304 + OUT PCHAR dest,
61305 + IN INT destsize,
61306 + IN PCHAR buffer);
61307 +
61308 +BOOLEAN RTMP_CardInfoRead(
61309 + IN PRTMP_ADAPTER pAd)
61310 +{
61311 +#define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
61312 +#define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
61313 +#define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
61314 +
61315 +#define LETTER_CASE_TRANSLATE(txt_p, card_id) \
61316 + { UINT32 _len; char _char; \
61317 + for(_len=0; _len<strlen(card_id); _len++) { \
61318 + _char = *(txt_p + _len); \
61319 + if (('A' <= _char) && (_char <= 'Z')) \
61320 + *(txt_p+_len) = 'a'+(_char-'A'); \
61321 + } }
61322 +
61323 + struct file *srcf;
61324 + INT retval, orgfsuid, orgfsgid;
61325 + mm_segment_t orgfs;
61326 + CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
61327 + BOOLEAN flg_match_ok = FALSE;
61328 + INT32 card_select_method;
61329 + INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
61330 + EEPROM_ANTENNA_STRUC antenna;
61331 + USHORT addr01, addr23, addr45;
61332 + UINT8 mac[6];
61333 + UINT32 data, card_index;
61334 + UCHAR *start_ptr;
61335 +
61336 +
61337 + // init
61338 + buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
61339 + if (buffer == NULL)
61340 + return FALSE;
61341 +
61342 + tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
61343 + if(tmpbuf == NULL)
61344 + {
61345 + kfree(buffer);
61346 + return NDIS_STATUS_FAILURE;
61347 + }
61348 +
61349 + orgfsuid = current->fsuid;
61350 + orgfsgid = current->fsgid;
61351 + current->fsuid = current->fsgid = 0;
61352 + orgfs = get_fs();
61353 + set_fs(KERNEL_DS);
61354 +
61355 + // get RF IC type
61356 + RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
61357 +
61358 + if ((data & 0x30) == 0)
61359 + pAd->EEPROMAddressNum = 6; // 93C46
61360 + else if ((data & 0x30) == 0x10)
61361 + pAd->EEPROMAddressNum = 8; // 93C66
61362 + else
61363 + pAd->EEPROMAddressNum = 8; // 93C86
61364 +
61365 + //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
61366 + RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
61367 +
61368 + if ((antenna.field.RfIcType == RFIC_2850) ||
61369 + (antenna.field.RfIcType == RFIC_2750))
61370 + {
61371 + /* ABGN card */
61372 + strcpy(RFIC_word, "abgn");
61373 + }
61374 + else
61375 + {
61376 + /* BGN card */
61377 + strcpy(RFIC_word, "bgn");
61378 + }
61379 +
61380 + // get MAC address
61381 + //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
61382 + //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
61383 + //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
61384 + RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
61385 + RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
61386 + RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
61387 +
61388 + mac[0] = (UCHAR)(addr01 & 0xff);
61389 + mac[1] = (UCHAR)(addr01 >> 8);
61390 + mac[2] = (UCHAR)(addr23 & 0xff);
61391 + mac[3] = (UCHAR)(addr23 >> 8);
61392 + mac[4] = (UCHAR)(addr45 & 0xff);
61393 + mac[5] = (UCHAR)(addr45 >> 8);
61394 +
61395 + // open card information file
61396 + srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
61397 + if (IS_ERR(srcf))
61398 + {
61399 + /* card information file does not exist */
61400 + DBGPRINT(RT_DEBUG_TRACE,
61401 + ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
61402 + return FALSE;
61403 + }
61404 +
61405 + if (srcf->f_op && srcf->f_op->read)
61406 + {
61407 + /* card information file exists so reading the card information */
61408 + memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
61409 + retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
61410 + if (retval < 0)
61411 + {
61412 + /* read fail */
61413 + DBGPRINT(RT_DEBUG_TRACE,
61414 + ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
61415 + }
61416 + else
61417 + {
61418 + /* get card selection method */
61419 + memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
61420 + card_select_method = MC_SELECT_CARDTYPE; // default
61421 +
61422 + if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
61423 + {
61424 + if (strcmp(tmpbuf, "CARDID") == 0)
61425 + card_select_method = MC_SELECT_CARDID;
61426 + else if (strcmp(tmpbuf, "MAC") == 0)
61427 + card_select_method = MC_SELECT_MAC;
61428 + else if (strcmp(tmpbuf, "CARDTYPE") == 0)
61429 + card_select_method = MC_SELECT_CARDTYPE;
61430 + }
61431 +
61432 + DBGPRINT(RT_DEBUG_TRACE,
61433 + ("MC> Card Selection = %d\n", card_select_method));
61434 +
61435 + // init
61436 + card_free_id = -1;
61437 + card_nouse_id = -1;
61438 + card_same_mac_id = -1;
61439 + card_match_id = -1;
61440 +
61441 + // search current card information records
61442 + for(card_index=0;
61443 + card_index<MAX_NUM_OF_MULTIPLE_CARD;
61444 + card_index++)
61445 + {
61446 + if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
61447 + (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
61448 + {
61449 + // MAC is all-0 so the entry is available
61450 + MC_CardUsed[card_index] = 0;
61451 +
61452 + if (card_free_id < 0)
61453 + card_free_id = card_index; // 1st free entry
61454 + }
61455 + else
61456 + {
61457 + if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
61458 + {
61459 + // we find the entry with same MAC
61460 + if (card_same_mac_id < 0)
61461 + card_same_mac_id = card_index; // 1st same entry
61462 + }
61463 + else
61464 + {
61465 + // MAC is not all-0 but used flag == 0
61466 + if ((MC_CardUsed[card_index] == 0) &&
61467 + (card_nouse_id < 0))
61468 + {
61469 + card_nouse_id = card_index; // 1st available entry
61470 + }
61471 + }
61472 + }
61473 + }
61474 +
61475 + DBGPRINT(RT_DEBUG_TRACE,
61476 + ("MC> Free = %d, Same = %d, NOUSE = %d\n",
61477 + card_free_id, card_same_mac_id, card_nouse_id));
61478 +
61479 + if ((card_same_mac_id >= 0) &&
61480 + ((card_select_method == MC_SELECT_CARDID) ||
61481 + (card_select_method == MC_SELECT_CARDTYPE)))
61482 + {
61483 + // same MAC entry is found
61484 + card_match_id = card_same_mac_id;
61485 +
61486 + if (card_select_method == MC_SELECT_CARDTYPE)
61487 + {
61488 + // for CARDTYPE
61489 + sprintf(card_id_buf, "%02dCARDTYPE%s",
61490 + card_match_id, RFIC_word);
61491 +
61492 + if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
61493 + {
61494 + // we found the card ID
61495 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
61496 + }
61497 + }
61498 + }
61499 + else
61500 + {
61501 + // the card is 1st plug-in, try to find the match card profile
61502 + switch(card_select_method)
61503 + {
61504 + case MC_SELECT_CARDID: // CARDID
61505 + default:
61506 + if (card_free_id >= 0)
61507 + card_match_id = card_free_id;
61508 + else
61509 + card_match_id = card_nouse_id;
61510 + break;
61511 +
61512 + case MC_SELECT_MAC: // MAC
61513 + sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
61514 + mac[0], mac[1], mac[2],
61515 + mac[3], mac[4], mac[5]);
61516 +
61517 + /* try to find the key word in the card file */
61518 + if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
61519 + {
61520 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
61521 +
61522 + /* get the row ID (2 ASCII characters) */
61523 + start_ptr -= 2;
61524 + card_id_buf[0] = *(start_ptr);
61525 + card_id_buf[1] = *(start_ptr+1);
61526 + card_id_buf[2] = 0x00;
61527 +
61528 + card_match_id = simple_strtol(card_id_buf, 0, 10);
61529 + }
61530 + break;
61531 +
61532 + case MC_SELECT_CARDTYPE: // CARDTYPE
61533 + card_nouse_id = -1;
61534 +
61535 + for(card_index=0;
61536 + card_index<MAX_NUM_OF_MULTIPLE_CARD;
61537 + card_index++)
61538 + {
61539 + sprintf(card_id_buf, "%02dCARDTYPE%s",
61540 + card_index, RFIC_word);
61541 +
61542 + if ((start_ptr=rtstrstruncasecmp(buffer,
61543 + card_id_buf)) != NULL)
61544 + {
61545 + LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
61546 +
61547 + if (MC_CardUsed[card_index] == 0)
61548 + {
61549 + /* current the card profile is not used */
61550 + if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
61551 + (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
61552 + {
61553 + // find it and no previous card use it
61554 + card_match_id = card_index;
61555 + break;
61556 + }
61557 + else
61558 + {
61559 + // ever a card use it
61560 + if (card_nouse_id < 0)
61561 + card_nouse_id = card_index;
61562 + }
61563 + }
61564 + }
61565 + }
61566 +
61567 + // if not find a free one, use the available one
61568 + if (card_match_id < 0)
61569 + card_match_id = card_nouse_id;
61570 + break;
61571 + }
61572 + }
61573 +
61574 + if (card_match_id >= 0)
61575 + {
61576 + // make up search keyword
61577 + switch(card_select_method)
61578 + {
61579 + case MC_SELECT_CARDID: // CARDID
61580 + sprintf(card_id_buf, "%02dCARDID", card_match_id);
61581 + break;
61582 +
61583 + case MC_SELECT_MAC: // MAC
61584 + sprintf(card_id_buf,
61585 + "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
61586 + card_match_id,
61587 + mac[0], mac[1], mac[2],
61588 + mac[3], mac[4], mac[5]);
61589 + break;
61590 +
61591 + case MC_SELECT_CARDTYPE: // CARDTYPE
61592 + default:
61593 + sprintf(card_id_buf, "%02dcardtype%s",
61594 + card_match_id, RFIC_word);
61595 + break;
61596 + }
61597 +
61598 + DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
61599 +
61600 + // read card file path
61601 + if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
61602 + {
61603 + if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
61604 + {
61605 + // backup card information
61606 + pAd->MC_RowID = card_match_id; /* base 0 */
61607 + MC_CardUsed[card_match_id] = 1;
61608 + memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
61609 +
61610 + // backup card file path
61611 + NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
61612 + pAd->MC_FileName[strlen(tmpbuf)] = '\0';
61613 + flg_match_ok = TRUE;
61614 +
61615 + DBGPRINT(RT_DEBUG_TRACE,
61616 + ("Card Profile Name = %s\n", pAd->MC_FileName));
61617 + }
61618 + else
61619 + {
61620 + DBGPRINT(RT_DEBUG_ERROR,
61621 + ("Card Profile Name length too large!\n"));
61622 + }
61623 + }
61624 + else
61625 + {
61626 + DBGPRINT(RT_DEBUG_ERROR,
61627 + ("Can not find search key word in card.dat!\n"));
61628 + }
61629 +
61630 + if ((flg_match_ok != TRUE) &&
61631 + (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
61632 + {
61633 + MC_CardUsed[card_match_id] = 0;
61634 + memset(MC_CardMac[card_match_id], 0, sizeof(mac));
61635 + }
61636 + } // if (card_match_id >= 0)
61637 + }
61638 + }
61639 +
61640 + // close file
61641 + retval = filp_close(srcf, NULL);
61642 + set_fs(orgfs);
61643 + current->fsuid = orgfsuid;
61644 + current->fsgid = orgfsgid;
61645 + kfree(buffer);
61646 + kfree(tmpbuf);
61647 + return flg_match_ok;
61648 +}
61649 +#endif // MULTIPLE_CARD_SUPPORT //
61650 +
61651 +
61652 +/*
61653 +========================================================================
61654 +Routine Description:
61655 + Probe RT28XX chipset.
61656 +
61657 +Arguments:
61658 + _dev_p Point to the PCI or USB device
61659 + _dev_id_p Point to the PCI or USB device ID
61660 +
61661 +Return Value:
61662 + 0 Probe OK
61663 + -ENODEV Probe Fail
61664 +
61665 +Note:
61666 +========================================================================
61667 +*/
61668 +INT __devinit rt28xx_probe(
61669 + IN void *_dev_p,
61670 + IN void *_dev_id_p,
61671 + IN UINT argc,
61672 + OUT PRTMP_ADAPTER *ppAd)
61673 +{
61674 + struct net_device *net_dev;
61675 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
61676 + INT status;
61677 + PVOID handle;
61678 +#ifdef RT2870
61679 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
61680 + struct usb_device *dev_p = (struct usb_device *)_dev_p;
61681 +#else
61682 + struct usb_interface *intf = (struct usb_interface *)_dev_p;
61683 + struct usb_device *dev_p = interface_to_usbdev(intf);
61684 +
61685 + dev_p = usb_get_dev(dev_p);
61686 +#endif // LINUX_VERSION_CODE //
61687 +#endif // RT2870 //
61688 +
61689 +
61690 +#ifdef CONFIG_STA_SUPPORT
61691 + DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
61692 +#endif // CONFIG_STA_SUPPORT //
61693 +
61694 + // Check chipset vendor/product ID
61695 +// if (RT28XXChipsetCheck(_dev_p) == FALSE)
61696 +// goto err_out;
61697 +
61698 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
61699 + net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
61700 +#else
61701 + net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
61702 +#endif
61703 + if (net_dev == NULL)
61704 + {
61705 + printk("alloc_netdev failed\n");
61706 +
61707 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
61708 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
61709 + module_put(THIS_MODULE);
61710 +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
61711 +#else
61712 + MOD_DEC_USE_COUNT;
61713 +#endif
61714 + goto err_out;
61715 + }
61716 +
61717 +// sample
61718 +// if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
61719 +// goto err_out;
61720 +
61721 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
61722 + SET_MODULE_OWNER(net_dev);
61723 +#endif
61724 +
61725 + netif_stop_queue(net_dev);
61726 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
61727 +/* for supporting Network Manager */
61728 +/* Set the sysfs physical device reference for the network logical device
61729 + * if set prior to registration will cause a symlink during initialization.
61730 + */
61731 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
61732 + SET_NETDEV_DEV(net_dev, &(dev_p->dev));
61733 +#endif
61734 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
61735 +
61736 + // Allocate RTMP_ADAPTER miniport adapter structure
61737 + handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
61738 + RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
61739 +
61740 + status = RTMPAllocAdapterBlock(handle, &pAd);
61741 + if (status != NDIS_STATUS_SUCCESS)
61742 + goto err_out_free_netdev;
61743 +
61744 + net_dev->ml_priv = (PVOID)pAd;
61745 + pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
61746 +
61747 + RT28XXNetDevInit(_dev_p, net_dev, pAd);
61748 +
61749 +#ifdef CONFIG_STA_SUPPORT
61750 + pAd->StaCfg.OriDevType = net_dev->type;
61751 +#endif // CONFIG_STA_SUPPORT //
61752 +
61753 + // Find and assign a free interface name, raxx
61754 +// RT28XXAvailRANameAssign(net_dev->name);
61755 +
61756 + // Post config
61757 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
61758 + if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
61759 + goto err_out_unmap;
61760 +#else
61761 + if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
61762 + goto err_out_unmap;
61763 +#endif // LINUX_VERSION_CODE //
61764 +
61765 +#ifdef CONFIG_STA_SUPPORT
61766 + pAd->OpMode = OPMODE_STA;
61767 +#endif // CONFIG_STA_SUPPORT //
61768 +
61769 +
61770 +#ifdef MULTIPLE_CARD_SUPPORT
61771 + // find its profile path
61772 + pAd->MC_RowID = -1; // use default profile path
61773 + RTMP_CardInfoRead(pAd);
61774 +
61775 + if (pAd->MC_RowID == -1)
61776 +#ifdef CONFIG_STA_SUPPORT
61777 + strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
61778 +#endif // CONFIG_STA_SUPPORT //
61779 +
61780 + DBGPRINT(RT_DEBUG_TRACE,
61781 + ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
61782 +#endif // MULTIPLE_CARD_SUPPORT //
61783 +
61784 + // sample move
61785 + if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
61786 + goto err_out_unmap;
61787 +
61788 + // Register this device
61789 + status = register_netdev(net_dev);
61790 + if (status)
61791 + goto err_out_unmap;
61792 +
61793 + // Set driver data
61794 + RT28XX_DRVDATA_SET(_dev_p);
61795 +
61796 +
61797 +
61798 + *ppAd = pAd;
61799 + return 0; // probe ok
61800 +
61801 +
61802 + /* --------------------------- ERROR HANDLE --------------------------- */
61803 +err_out_unmap:
61804 + RTMPFreeAdapter(pAd);
61805 + RT28XX_UNMAP();
61806 +
61807 +err_out_free_netdev:
61808 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
61809 + free_netdev(net_dev);
61810 +#else
61811 + kfree(net_dev);
61812 +#endif
61813 +
61814 +err_out:
61815 + RT28XX_PUT_DEVICE(dev_p);
61816 +
61817 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
61818 + return (LONG)NULL;
61819 +#else
61820 + return -ENODEV; /* probe fail */
61821 +#endif // LINUX_VERSION_CODE //
61822 +} /* End of rt28xx_probe */
61823 +
61824 +
61825 +/*
61826 +========================================================================
61827 +Routine Description:
61828 + The entry point for Linux kernel sent packet to our driver.
61829 +
61830 +Arguments:
61831 + sk_buff *skb the pointer refer to a sk_buffer.
61832 +
61833 +Return Value:
61834 + 0
61835 +
61836 +Note:
61837 + This function is the entry point of Tx Path for Os delivery packet to
61838 + our driver. You only can put OS-depened & STA/AP common handle procedures
61839 + in here.
61840 +========================================================================
61841 +*/
61842 +int rt28xx_packet_xmit(struct sk_buff *skb)
61843 +{
61844 + struct net_device *net_dev = skb->dev;
61845 + PRTMP_ADAPTER pAd = net_dev->ml_priv;
61846 + int status = 0;
61847 + PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
61848 +
61849 + /* RT2870STA does this in RTMPSendPackets() */
61850 +#ifdef RALINK_ATE
61851 + if (ATE_ON(pAd))
61852 + {
61853 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
61854 + return 0;
61855 + }
61856 +#endif // RALINK_ATE //
61857 +
61858 +#ifdef CONFIG_STA_SUPPORT
61859 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61860 + {
61861 + // Drop send request since we are in monitor mode
61862 + if (MONITOR_ON(pAd))
61863 + {
61864 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
61865 + goto done;
61866 + }
61867 + }
61868 +#endif // CONFIG_STA_SUPPORT //
61869 +
61870 + // EapolStart size is 18
61871 + if (skb->len < 14)
61872 + {
61873 + //printk("bad packet size: %d\n", pkt->len);
61874 + hex_dump("bad packet", skb->data, skb->len);
61875 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
61876 + goto done;
61877 + }
61878 +
61879 + RTMP_SET_PACKET_5VT(pPacket, 0);
61880 +// MiniportMMRequest(pAd, pkt->data, pkt->len);
61881 +#ifdef CONFIG_5VT_ENHANCE
61882 + if (*(int*)(skb->cb) == BRIDGE_TAG) {
61883 + RTMP_SET_PACKET_5VT(pPacket, 1);
61884 + }
61885 +#endif
61886 +
61887 +
61888 +
61889 +#ifdef CONFIG_STA_SUPPORT
61890 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
61891 + {
61892 +
61893 + STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
61894 + }
61895 +
61896 +#endif // CONFIG_STA_SUPPORT //
61897 +
61898 + status = 0;
61899 +done:
61900 +
61901 + return status;
61902 +}
61903 +
61904 +
61905 +/*
61906 +========================================================================
61907 +Routine Description:
61908 + Send a packet to WLAN.
61909 +
61910 +Arguments:
61911 + skb_p points to our adapter
61912 + dev_p which WLAN network interface
61913 +
61914 +Return Value:
61915 + 0: transmit successfully
61916 + otherwise: transmit fail
61917 +
61918 +Note:
61919 +========================================================================
61920 +*/
61921 +INT rt28xx_send_packets(
61922 + IN struct sk_buff *skb_p,
61923 + IN struct net_device *net_dev)
61924 +{
61925 + RTMP_ADAPTER *pAd = net_dev->ml_priv;
61926 +
61927 + if (!(net_dev->flags & IFF_UP))
61928 + {
61929 + RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
61930 + return 0;
61931 + }
61932 +
61933 + NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
61934 + RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
61935 +
61936 + return rt28xx_packet_xmit(skb_p);
61937 +} /* End of MBSS_VirtualIF_PacketSend */
61938 +
61939 +
61940 +
61941 +
61942 +#if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
61943 +//static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
61944 +struct net_device *alloc_netdev(
61945 + int sizeof_priv,
61946 + const char *mask,
61947 + void (*setup)(struct net_device *))
61948 +{
61949 + struct net_device *dev;
61950 + INT alloc_size;
61951 +
61952 +
61953 + /* ensure 32-byte alignment of the private area */
61954 + alloc_size = sizeof (*dev) + sizeof_priv + 31;
61955 +
61956 + dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
61957 + if (dev == NULL)
61958 + {
61959 + DBGPRINT(RT_DEBUG_ERROR,
61960 + ("alloc_netdev: Unable to allocate device memory.\n"));
61961 + return NULL;
61962 + }
61963 +
61964 + memset(dev, 0, alloc_size);
61965 +
61966 + if (sizeof_priv)
61967 + dev->ml_priv = (void *) (((long)(dev + 1) + 31) & ~31);
61968 +
61969 + setup(dev);
61970 + strcpy(dev->name, mask);
61971 +
61972 + return dev;
61973 +}
61974 +#endif // LINUX_VERSION_CODE //
61975 +
61976 +
61977 +void CfgInitHook(PRTMP_ADAPTER pAd)
61978 +{
61979 + pAd->bBroadComHT = TRUE;
61980 +} /* End of CfgInitHook */
61981 +
61982 +
61983 +#if WIRELESS_EXT >= 12
61984 +// This function will be called when query /proc
61985 +struct iw_statistics *rt28xx_get_wireless_stats(
61986 + IN struct net_device *net_dev)
61987 +{
61988 + PRTMP_ADAPTER pAd = net_dev->ml_priv;
61989 +
61990 +
61991 + DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
61992 +
61993 + pAd->iw_stats.status = 0; // Status - device dependent for now
61994 +
61995 + // link quality
61996 + pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
61997 + if(pAd->iw_stats.qual.qual > 100)
61998 + pAd->iw_stats.qual.qual = 100;
61999 +
62000 +#ifdef CONFIG_STA_SUPPORT
62001 + if (pAd->OpMode == OPMODE_STA)
62002 + pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
62003 +#endif // CONFIG_STA_SUPPORT //
62004 +
62005 + pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
62006 +
62007 + pAd->iw_stats.qual.noise += 256 - 143;
62008 + pAd->iw_stats.qual.updated = 1; // Flags to know if updated
62009 +#ifdef IW_QUAL_DBM
62010 + pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
62011 +#endif // IW_QUAL_DBM //
62012 +
62013 + pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
62014 + pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
62015 +
62016 + DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
62017 + return &pAd->iw_stats;
62018 +} /* End of rt28xx_get_wireless_stats */
62019 +#endif // WIRELESS_EXT //
62020 +
62021 +
62022 +
62023 +void tbtt_tasklet(unsigned long data)
62024 +{
62025 +#define MAX_TX_IN_TBTT (16)
62026 +
62027 +}
62028 +
62029 +INT rt28xx_ioctl(
62030 + IN struct net_device *net_dev,
62031 + IN OUT struct ifreq *rq,
62032 + IN INT cmd)
62033 +{
62034 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
62035 + RTMP_ADAPTER *pAd = NULL;
62036 + INT ret = 0;
62037 +
62038 + if (net_dev->priv_flags == INT_MAIN)
62039 + {
62040 + pAd = net_dev->ml_priv;
62041 + }
62042 + else
62043 + {
62044 + pVirtualAd = net_dev->ml_priv;
62045 + pAd = pVirtualAd->RtmpDev->ml_priv;
62046 + }
62047 +
62048 + if (pAd == NULL)
62049 + {
62050 + /* if 1st open fail, pAd will be free;
62051 + So the net_dev->ml_priv will be NULL in 2rd open */
62052 + return -ENETDOWN;
62053 + }
62054 +
62055 +
62056 +#ifdef CONFIG_STA_SUPPORT
62057 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
62058 + {
62059 + ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
62060 + }
62061 +#endif // CONFIG_STA_SUPPORT //
62062 +
62063 + return ret;
62064 +}
62065 +
62066 +/*
62067 + ========================================================================
62068 +
62069 + Routine Description:
62070 + return ethernet statistics counter
62071 +
62072 + Arguments:
62073 + net_dev Pointer to net_device
62074 +
62075 + Return Value:
62076 + net_device_stats*
62077 +
62078 + Note:
62079 +
62080 + ========================================================================
62081 +*/
62082 +struct net_device_stats *RT28xx_get_ether_stats(
62083 + IN struct net_device *net_dev)
62084 +{
62085 + RTMP_ADAPTER *pAd = NULL;
62086 +
62087 + if (net_dev)
62088 + pAd = net_dev->ml_priv;
62089 +
62090 + if (pAd)
62091 + {
62092 +
62093 + pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
62094 + pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
62095 +
62096 + pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
62097 + pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
62098 +
62099 + pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
62100 + pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
62101 +
62102 + pAd->stats.rx_dropped = 0;
62103 + pAd->stats.tx_dropped = 0;
62104 +
62105 + pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
62106 + pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
62107 +
62108 + pAd->stats.rx_length_errors = 0;
62109 + pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
62110 + pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
62111 + pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
62112 + pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
62113 + pAd->stats.rx_missed_errors = 0; // receiver missed packet
62114 +
62115 + // detailed tx_errors
62116 + pAd->stats.tx_aborted_errors = 0;
62117 + pAd->stats.tx_carrier_errors = 0;
62118 + pAd->stats.tx_fifo_errors = 0;
62119 + pAd->stats.tx_heartbeat_errors = 0;
62120 + pAd->stats.tx_window_errors = 0;
62121 +
62122 + // for cslip etc
62123 + pAd->stats.rx_compressed = 0;
62124 + pAd->stats.tx_compressed = 0;
62125 +
62126 + return &pAd->stats;
62127 + }
62128 + else
62129 + return NULL;
62130 +}
62131 +
62132 --- /dev/null
62133 +++ b/drivers/staging/rt3070/rtmp_ckipmic.h
62134 @@ -0,0 +1,113 @@
62135 +/*
62136 + *************************************************************************
62137 + * Ralink Tech Inc.
62138 + * 5F., No.36, Taiyuan St., Jhubei City,
62139 + * Hsinchu County 302,
62140 + * Taiwan, R.O.C.
62141 + *
62142 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
62143 + *
62144 + * This program is free software; you can redistribute it and/or modify *
62145 + * it under the terms of the GNU General Public License as published by *
62146 + * the Free Software Foundation; either version 2 of the License, or *
62147 + * (at your option) any later version. *
62148 + * *
62149 + * This program is distributed in the hope that it will be useful, *
62150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
62151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
62152 + * GNU General Public License for more details. *
62153 + * *
62154 + * You should have received a copy of the GNU General Public License *
62155 + * along with this program; if not, write to the *
62156 + * Free Software Foundation, Inc., *
62157 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
62158 + * *
62159 + *************************************************************************
62160 +
62161 + Module Name:
62162 + rtmp_ckipmic.h
62163 +
62164 + Abstract:
62165 +
62166 + Revision History:
62167 + Who When What
62168 + -------- ---------- ----------------------------------------------
62169 + Name Date Modification logs
62170 +*/
62171 +#ifndef __RTMP_CKIPMIC_H__
62172 +#define __RTMP_CKIPMIC_H__
62173 +
62174 +typedef struct _MIC_CONTEXT {
62175 + /* --- MMH context */
62176 + UCHAR CK[16]; /* the key */
62177 + UCHAR coefficient[16]; /* current aes counter mode coefficients */
62178 + ULONGLONG accum; /* accumulated mic, reduced to u32 in final() */
62179 + UINT position; /* current position (byte offset) in message */
62180 + UCHAR part[4]; /* for conversion of message to u32 for mmh */
62181 +} MIC_CONTEXT, *PMIC_CONTEXT;
62182 +
62183 +VOID CKIP_key_permute(
62184 + OUT UCHAR *PK, /* output permuted key */
62185 + IN UCHAR *CK, /* input CKIP key */
62186 + IN UCHAR toDsFromDs, /* input toDs/FromDs bits */
62187 + IN UCHAR *piv); /* input pointer to IV */
62188 +
62189 +VOID RTMPCkipMicInit(
62190 + IN PMIC_CONTEXT pContext,
62191 + IN PUCHAR CK);
62192 +
62193 +VOID RTMPMicUpdate(
62194 + IN PMIC_CONTEXT pContext,
62195 + IN PUCHAR pOctets,
62196 + IN INT len);
62197 +
62198 +ULONG RTMPMicGetCoefficient(
62199 + IN PMIC_CONTEXT pContext);
62200 +
62201 +VOID xor_128(
62202 + IN PUCHAR a,
62203 + IN PUCHAR b,
62204 + OUT PUCHAR out);
62205 +
62206 +UCHAR RTMPCkipSbox(
62207 + IN UCHAR a);
62208 +
62209 +VOID xor_32(
62210 + IN PUCHAR a,
62211 + IN PUCHAR b,
62212 + OUT PUCHAR out);
62213 +
62214 +VOID next_key(
62215 + IN PUCHAR key,
62216 + IN INT round);
62217 +
62218 +VOID byte_sub(
62219 + IN PUCHAR in,
62220 + OUT PUCHAR out);
62221 +
62222 +VOID shift_row(
62223 + IN PUCHAR in,
62224 + OUT PUCHAR out);
62225 +
62226 +VOID mix_column(
62227 + IN PUCHAR in,
62228 + OUT PUCHAR out);
62229 +
62230 +VOID RTMPAesEncrypt(
62231 + IN PUCHAR key,
62232 + IN PUCHAR data,
62233 + IN PUCHAR ciphertext);
62234 +
62235 +VOID RTMPMicFinal(
62236 + IN PMIC_CONTEXT pContext,
62237 + OUT UCHAR digest[4]);
62238 +
62239 +VOID RTMPCkipInsertCMIC(
62240 + IN PRTMP_ADAPTER pAd,
62241 + OUT PUCHAR pMIC,
62242 + IN PUCHAR p80211hdr,
62243 + IN PNDIS_PACKET pPacket,
62244 + IN PCIPHER_KEY pKey,
62245 + IN PUCHAR mic_snap);
62246 +
62247 +#endif //__RTMP_CKIPMIC_H__
62248 --- /dev/null
62249 +++ b/drivers/staging/rt3070/rtmp_def.h
62250 @@ -0,0 +1,1559 @@
62251 +/*
62252 + *************************************************************************
62253 + * Ralink Tech Inc.
62254 + * 5F., No.36, Taiyuan St., Jhubei City,
62255 + * Hsinchu County 302,
62256 + * Taiwan, R.O.C.
62257 + *
62258 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
62259 + *
62260 + * This program is free software; you can redistribute it and/or modify *
62261 + * it under the terms of the GNU General Public License as published by *
62262 + * the Free Software Foundation; either version 2 of the License, or *
62263 + * (at your option) any later version. *
62264 + * *
62265 + * This program is distributed in the hope that it will be useful, *
62266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
62267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
62268 + * GNU General Public License for more details. *
62269 + * *
62270 + * You should have received a copy of the GNU General Public License *
62271 + * along with this program; if not, write to the *
62272 + * Free Software Foundation, Inc., *
62273 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
62274 + * *
62275 + *************************************************************************
62276 +
62277 + Module Name:
62278 + rtmp_def.h
62279 +
62280 + Abstract:
62281 + Miniport related definition header
62282 +
62283 + Revision History:
62284 + Who When What
62285 + -------- ---------- ----------------------------------------------
62286 + Paul Lin 08-01-2002 created
62287 + John Chang 08-05-2003 add definition for 11g & other drafts
62288 +*/
62289 +#ifndef __RTMP_DEF_H__
62290 +#define __RTMP_DEF_H__
62291 +
62292 +#include "oid.h"
62293 +
62294 +#undef AP_WSC_INCLUDED
62295 +#undef STA_WSC_INCLUDED
62296 +#undef WSC_INCLUDED
62297 +
62298 +
62299 +#ifdef CONFIG_STA_SUPPORT
62300 +#endif // CONFIG_STA_SUPPORT //
62301 +
62302 +#if defined(AP_WSC_INCLUDED) || defined(STA_WSC_INCLUDED)
62303 +#define WSC_INCLUDED
62304 +#endif
62305 +//
62306 +// Debug information verbosity: lower values indicate higher urgency
62307 +//
62308 +#define RT_DEBUG_OFF 0
62309 +#define RT_DEBUG_ERROR 1
62310 +#define RT_DEBUG_WARN 2
62311 +#define RT_DEBUG_TRACE 3
62312 +#define RT_DEBUG_INFO 4
62313 +#define RT_DEBUG_LOUD 5
62314 +
62315 +#define NIC_TAG ((ULONG)'0682')
62316 +#define NIC_DBG_STRING ("**RT28xx**")
62317 +
62318 +#ifdef SNMP_SUPPORT
62319 +// for snmp
62320 +// to get manufacturer OUI, kathy, 2008_0220
62321 +#define ManufacturerOUI_LEN 3
62322 +#define ManufacturerNAME ("Ralink Technology Company.")
62323 +#define ResourceTypeIdName ("Ralink_ID")
62324 +#endif
62325 +
62326 +
62327 +//#define PACKED
62328 +
62329 +#define RALINK_2883_VERSION ((UINT32)0x28830300)
62330 +#define RALINK_2880E_VERSION ((UINT32)0x28720200)
62331 +#define RALINK_3070_VERSION ((UINT32)0x30700200)
62332 +
62333 +//
62334 +// NDIS version in use by the NIC driver.
62335 +// The high byte is the major version. The low byte is the minor version.
62336 +//
62337 +#ifdef NDIS51_MINIPORT
62338 +#define NIC_DRIVER_VERSION 0x0501
62339 +#else
62340 +#define NIC_DRIVER_VERSION 0x0500
62341 +#endif
62342 +
62343 +//
62344 +// NDIS media type, current is ethernet, change if native wireless supported
62345 +//
62346 +#define NIC_MEDIA_TYPE NdisMedium802_3
62347 +#define NIC_PCI_HDR_LENGTH 0xe2
62348 +#define NIC_MAX_PACKET_SIZE 2304
62349 +#define NIC_HEADER_SIZE 14
62350 +#define MAX_MAP_REGISTERS_NEEDED 32
62351 +#define MIN_MAP_REGISTERS_NEEDED 2 //Todo: should consider fragment issue.
62352 +
62353 +//
62354 +// interface type, we use PCI
62355 +//
62356 +#define NIC_INTERFACE_TYPE NdisInterfacePci
62357 +#define NIC_INTERRUPT_MODE NdisInterruptLevelSensitive
62358 +
62359 +//
62360 +// buffer size passed in NdisMQueryAdapterResources
62361 +// We should only need three adapter resources (IO, interrupt and memory),
62362 +// Some devices get extra resources, so have room for 10 resources
62363 +// UF_SIZE (sizeof(NDIS_RESOURCE_LIST) + (10*sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)))
62364 +
62365 +
62366 +#define NIC_RESOURCE_B//
62367 +// IO space length
62368 +//
62369 +#define NIC_MAP_IOSPACE_LENGTH sizeof(CSR_STRUC)
62370 +
62371 +#define MAX_RX_PKT_LEN 1520
62372 +
62373 +//
62374 +// Entry number for each DMA descriptor ring
62375 +//
62376 +
62377 +
62378 +#ifdef RT2870
62379 +#define TX_RING_SIZE 8 // 1
62380 +#define PRIO_RING_SIZE 8
62381 +#define MGMT_RING_SIZE 32 // PRIO_RING_SIZE
62382 +#define RX_RING_SIZE 8
62383 +#define MAX_TX_PROCESS 4
62384 +#define LOCAL_TXBUF_SIZE 2048
62385 +#endif // RT2870 //
62386 +
62387 +#ifdef MULTIPLE_CARD_SUPPORT
62388 +// MC: Multple Cards
62389 +#define MAX_NUM_OF_MULTIPLE_CARD 32
62390 +#endif // MULTIPLE_CARD_SUPPORT //
62391 +
62392 +#define MAX_RX_PROCESS 128 //64 //32
62393 +#define NUM_OF_LOCAL_TXBUF 2
62394 +#define TXD_SIZE 16
62395 +#define TXWI_SIZE 16
62396 +#define RXD_SIZE 16
62397 +#define RXWI_SIZE 16
62398 +// TXINFO_SIZE + TXWI_SIZE + 802.11 Header Size + AMSDU sub frame header
62399 +#define TX_DMA_1ST_BUFFER_SIZE 96 // only the 1st physical buffer is pre-allocated
62400 +#define MGMT_DMA_BUFFER_SIZE 1536 //2048
62401 +#define RX_BUFFER_AGGRESIZE 3840 //3904 //3968 //4096 //2048 //4096
62402 +#define RX_BUFFER_NORMSIZE 3840 //3904 //3968 //4096 //2048 //4096
62403 +#define TX_BUFFER_NORMSIZE RX_BUFFER_NORMSIZE
62404 +#define MAX_FRAME_SIZE 2346 // Maximum 802.11 frame size
62405 +#define MAX_AGGREGATION_SIZE 3840 //3904 //3968 //4096
62406 +#define MAX_NUM_OF_TUPLE_CACHE 2
62407 +#define MAX_MCAST_LIST_SIZE 32
62408 +#define MAX_LEN_OF_VENDOR_DESC 64
62409 +//#define MAX_SIZE_OF_MCAST_PSQ (NUM_OF_LOCAL_TXBUF >> 2) // AP won't spend more than 1/4 of total buffers on M/BCAST PSQ
62410 +#define MAX_SIZE_OF_MCAST_PSQ 32
62411 +
62412 +#define MAX_RX_PROCESS_CNT (RX_RING_SIZE)
62413 +
62414 +
62415 +#define MAX_PACKETS_IN_QUEUE (512) //(512) // to pass WMM A5-WPAPSK
62416 +#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32
62417 +#define MAX_PACKETS_IN_PS_QUEUE 128 //32
62418 +#define WMM_NUM_OF_AC 4 /* AC0, AC1, AC2, and AC3 */
62419 +
62420 +
62421 +//2008/09/11:KH add to support efuse<--
62422 +#define MAX_EEPROM_BIN_FILE_SIZE 1024
62423 +//2008/09/11:KH add to support efuse-->
62424 +
62425 +// RxFilter
62426 +#define STANORMAL 0x17f97
62427 +#define APNORMAL 0x15f97
62428 +//
62429 +// RTMP_ADAPTER flags
62430 +//
62431 +#define fRTMP_ADAPTER_MAP_REGISTER 0x00000001
62432 +#define fRTMP_ADAPTER_INTERRUPT_IN_USE 0x00000002
62433 +#define fRTMP_ADAPTER_HARDWARE_ERROR 0x00000004
62434 +#define fRTMP_ADAPTER_SCATTER_GATHER 0x00000008
62435 +#define fRTMP_ADAPTER_SEND_PACKET_ERROR 0x00000010
62436 +#define fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS 0x00000020
62437 +#define fRTMP_ADAPTER_HALT_IN_PROGRESS 0x00000040
62438 +#define fRTMP_ADAPTER_RESET_IN_PROGRESS 0x00000080
62439 +#define fRTMP_ADAPTER_NIC_NOT_EXIST 0x00000100
62440 +#define fRTMP_ADAPTER_TX_RING_ALLOCATED 0x00000200
62441 +#define fRTMP_ADAPTER_REMOVE_IN_PROGRESS 0x00000400
62442 +#define fRTMP_ADAPTER_MIMORATE_INUSED 0x00000800
62443 +#define fRTMP_ADAPTER_RX_RING_ALLOCATED 0x00001000
62444 +#define fRTMP_ADAPTER_INTERRUPT_ACTIVE 0x00002000
62445 +#define fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS 0x00004000
62446 +#define fRTMP_ADAPTER_REASSOC_IN_PROGRESS 0x00008000
62447 +#define fRTMP_ADAPTER_MEDIA_STATE_PENDING 0x00010000
62448 +#define fRTMP_ADAPTER_RADIO_OFF 0x00020000
62449 +#define fRTMP_ADAPTER_BULKOUT_RESET 0x00040000
62450 +#define fRTMP_ADAPTER_BULKIN_RESET 0x00080000
62451 +#define fRTMP_ADAPTER_RDG_ACTIVE 0x00100000
62452 +#define fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE 0x00200000
62453 +#define fRTMP_ADAPTER_SCAN_2040 0x04000000
62454 +#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000
62455 +
62456 +#define fRTMP_ADAPTER_START_UP 0x10000000 //Devive already initialized and enabled Tx/Rx.
62457 +#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000
62458 +#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000
62459 +
62460 +// Lock bit for accessing different ring buffers
62461 +//#define fRTMP_ADAPTER_TX_RING_BUSY 0x80000000
62462 +//#define fRTMP_ADAPTER_MGMT_RING_BUSY 0x40000000
62463 +//#define fRTMP_ADAPTER_ATIM_RING_BUSY 0x20000000
62464 +//#define fRTMP_ADAPTER_RX_RING_BUSY 0x10000000
62465 +
62466 +// Lock bit for accessing different queue
62467 +//#define fRTMP_ADAPTER_TX_QUEUE_BUSY 0x08000000
62468 +//#define fRTMP_ADAPTER_MGMT_QUEUE_BUSY 0x04000000
62469 +
62470 +//
62471 +// STA operation status flags
62472 +//
62473 +#define fOP_STATUS_INFRA_ON 0x00000001
62474 +#define fOP_STATUS_ADHOC_ON 0x00000002
62475 +#define fOP_STATUS_BG_PROTECTION_INUSED 0x00000004
62476 +#define fOP_STATUS_SHORT_SLOT_INUSED 0x00000008
62477 +#define fOP_STATUS_SHORT_PREAMBLE_INUSED 0x00000010
62478 +#define fOP_STATUS_RECEIVE_DTIM 0x00000020
62479 +//#define fOP_STATUS_TX_RATE_SWITCH_ENABLED 0x00000040
62480 +#define fOP_STATUS_MEDIA_STATE_CONNECTED 0x00000080
62481 +#define fOP_STATUS_WMM_INUSED 0x00000100
62482 +#define fOP_STATUS_AGGREGATION_INUSED 0x00000200
62483 +#define fOP_STATUS_DOZE 0x00000400 // debug purpose
62484 +#define fOP_STATUS_PIGGYBACK_INUSED 0x00000800 // piggy-back, and aggregation
62485 +#define fOP_STATUS_APSD_INUSED 0x00001000
62486 +#define fOP_STATUS_TX_AMSDU_INUSED 0x00002000
62487 +#define fOP_STATUS_MAX_RETRY_ENABLED 0x00004000
62488 +#define fOP_STATUS_WAKEUP_NOW 0x00008000
62489 +#define fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE 0x00020000
62490 +
62491 +#ifdef DOT11N_DRAFT3
62492 +#define fOP_STATUS_SCAN_2040 0x00040000
62493 +#endif // DOT11N_DRAFT3 //
62494 +
62495 +#define CCKSETPROTECT 0x1
62496 +#define OFDMSETPROTECT 0x2
62497 +#define MM20SETPROTECT 0x4
62498 +#define MM40SETPROTECT 0x8
62499 +#define GF20SETPROTECT 0x10
62500 +#define GR40SETPROTECT 0x20
62501 +#define ALLN_SETPROTECT (GR40SETPROTECT | GF20SETPROTECT | MM40SETPROTECT | MM20SETPROTECT)
62502 +
62503 +//
62504 +// AP's client table operation status flags
62505 +//
62506 +#define fCLIENT_STATUS_WMM_CAPABLE 0x00000001 // CLIENT can parse QOS DATA frame
62507 +#define fCLIENT_STATUS_AGGREGATION_CAPABLE 0x00000002 // CLIENT can receive Ralink's proprietary TX aggregation frame
62508 +#define fCLIENT_STATUS_PIGGYBACK_CAPABLE 0x00000004 // CLIENT support piggy-back
62509 +#define fCLIENT_STATUS_AMSDU_INUSED 0x00000008
62510 +#define fCLIENT_STATUS_SGI20_CAPABLE 0x00000010
62511 +#define fCLIENT_STATUS_SGI40_CAPABLE 0x00000020
62512 +#define fCLIENT_STATUS_TxSTBC_CAPABLE 0x00000040
62513 +#define fCLIENT_STATUS_RxSTBC_CAPABLE 0x00000080
62514 +#define fCLIENT_STATUS_HTC_CAPABLE 0x00000100
62515 +#define fCLIENT_STATUS_RDG_CAPABLE 0x00000200
62516 +#define fCLIENT_STATUS_MCSFEEDBACK_CAPABLE 0x00000400
62517 +#define fCLIENT_STATUS_APSD_CAPABLE 0x00000800 /* UAPSD STATION */
62518 +
62519 +#ifdef DOT11N_DRAFT3
62520 +#define fCLIENT_STATUS_BSSCOEXIST_CAPABLE 0x00001000
62521 +#endif // DOT11N_DRAFT3 //
62522 +
62523 +#define fCLIENT_STATUS_RALINK_CHIPSET 0x00100000
62524 +//
62525 +// STA configuration flags
62526 +//
62527 +//#define fSTA_CFG_ENABLE_TX_BURST 0x00000001
62528 +
62529 +// 802.11n Operating Mode Definition. 0-3 also used in ASICUPdateProtect switch case
62530 +#define HT_NO_PROTECT 0
62531 +#define HT_LEGACY_PROTECT 1
62532 +#define HT_40_PROTECT 2
62533 +#define HT_2040_PROTECT 3
62534 +#define HT_RTSCTS_6M 7
62535 +//following is our own definition in order to turn on our ASIC protection register in INFRASTRUCTURE.
62536 +#define HT_ATHEROS 8
62537 +#define HT_FORCERTSCTS 9 // Force turn on RTS/CTS first. then go to evaluate if this force RTS is necessary.
62538 +
62539 +//
62540 +// RX Packet Filter control flags. Apply on pAd->PacketFilter
62541 +//
62542 +#define fRX_FILTER_ACCEPT_DIRECT NDIS_PACKET_TYPE_DIRECTED
62543 +#define fRX_FILTER_ACCEPT_MULTICAST NDIS_PACKET_TYPE_MULTICAST
62544 +#define fRX_FILTER_ACCEPT_BROADCAST NDIS_PACKET_TYPE_BROADCAST
62545 +#define fRX_FILTER_ACCEPT_ALL_MULTICAST NDIS_PACKET_TYPE_ALL_MULTICAST
62546 +
62547 +//
62548 +// Error code section
62549 +//
62550 +// NDIS_ERROR_CODE_ADAPTER_NOT_FOUND
62551 +#define ERRLOG_READ_PCI_SLOT_FAILED 0x00000101L
62552 +#define ERRLOG_WRITE_PCI_SLOT_FAILED 0x00000102L
62553 +#define ERRLOG_VENDOR_DEVICE_NOMATCH 0x00000103L
62554 +
62555 +// NDIS_ERROR_CODE_ADAPTER_DISABLED
62556 +#define ERRLOG_BUS_MASTER_DISABLED 0x00000201L
62557 +
62558 +// NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION
62559 +#define ERRLOG_INVALID_SPEED_DUPLEX 0x00000301L
62560 +#define ERRLOG_SET_SECONDARY_FAILED 0x00000302L
62561 +
62562 +// NDIS_ERROR_CODE_OUT_OF_RESOURCES
62563 +#define ERRLOG_OUT_OF_MEMORY 0x00000401L
62564 +#define ERRLOG_OUT_OF_SHARED_MEMORY 0x00000402L
62565 +#define ERRLOG_OUT_OF_MAP_REGISTERS 0x00000403L
62566 +#define ERRLOG_OUT_OF_BUFFER_POOL 0x00000404L
62567 +#define ERRLOG_OUT_OF_NDIS_BUFFER 0x00000405L
62568 +#define ERRLOG_OUT_OF_PACKET_POOL 0x00000406L
62569 +#define ERRLOG_OUT_OF_NDIS_PACKET 0x00000407L
62570 +#define ERRLOG_OUT_OF_LOOKASIDE_MEMORY 0x00000408L
62571 +
62572 +// NDIS_ERROR_CODE_HARDWARE_FAILURE
62573 +#define ERRLOG_SELFTEST_FAILED 0x00000501L
62574 +#define ERRLOG_INITIALIZE_ADAPTER 0x00000502L
62575 +#define ERRLOG_REMOVE_MINIPORT 0x00000503L
62576 +
62577 +// NDIS_ERROR_CODE_RESOURCE_CONFLICT
62578 +#define ERRLOG_MAP_IO_SPACE 0x00000601L
62579 +#define ERRLOG_QUERY_ADAPTER_RESOURCES 0x00000602L
62580 +#define ERRLOG_NO_IO_RESOURCE 0x00000603L
62581 +#define ERRLOG_NO_INTERRUPT_RESOURCE 0x00000604L
62582 +#define ERRLOG_NO_MEMORY_RESOURCE 0x00000605L
62583 +
62584 +
62585 +// WDS definition
62586 +#define MAX_WDS_ENTRY 4
62587 +#define WDS_PAIRWISE_KEY_OFFSET 60 // WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table
62588 +
62589 +#define WDS_DISABLE_MODE 0
62590 +#define WDS_RESTRICT_MODE 1
62591 +#define WDS_BRIDGE_MODE 2
62592 +#define WDS_REPEATER_MODE 3
62593 +#define WDS_LAZY_MODE 4
62594 +
62595 +
62596 +#define MAX_MESH_NUM 0
62597 +
62598 +#define MAX_APCLI_NUM 0
62599 +
62600 +#define MAX_MBSSID_NUM 1
62601 +#ifdef MBSS_SUPPORT
62602 +#undef MAX_MBSSID_NUM
62603 +#define MAX_MBSSID_NUM (8 - MAX_MESH_NUM - MAX_APCLI_NUM)
62604 +#endif // MBSS_SUPPORT //
62605 +
62606 +/* sanity check for apidx */
62607 +#define MBSS_MR_APIDX_SANITY_CHECK(apidx) \
62608 + { if (apidx > MAX_MBSSID_NUM) { \
62609 + printk("%s> Error! apidx = %d > MAX_MBSSID_NUM!\n", __FUNCTION__, apidx); \
62610 + apidx = MAIN_MBSSID; } }
62611 +
62612 +#define VALID_WCID(_wcid) ((_wcid) > 0 && (_wcid) < MAX_LEN_OF_MAC_TABLE )
62613 +
62614 +#define MAIN_MBSSID 0
62615 +#define FIRST_MBSSID 1
62616 +
62617 +
62618 +#define MAX_BEACON_SIZE 512
62619 +// If the MAX_MBSSID_NUM is larger than 6,
62620 +// it shall reserve some WCID space(wcid 222~253) for beacon frames.
62621 +// - these wcid 238~253 are reserved for beacon#6(ra6).
62622 +// - these wcid 222~237 are reserved for beacon#7(ra7).
62623 +#if defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 8)
62624 +#define HW_RESERVED_WCID 222
62625 +#elif defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 7)
62626 +#define HW_RESERVED_WCID 238
62627 +#else
62628 +#define HW_RESERVED_WCID 255
62629 +#endif
62630 +
62631 +// Then dedicate wcid of DFS and Carrier-Sense.
62632 +#define DFS_CTS_WCID (HW_RESERVED_WCID - 1)
62633 +#define CS_CTS_WCID (HW_RESERVED_WCID - 2)
62634 +#define LAST_SPECIFIC_WCID (HW_RESERVED_WCID - 2)
62635 +
62636 +// If MAX_MBSSID_NUM is 8, the maximum available wcid for the associated STA is 211.
62637 +// If MAX_MBSSID_NUM is 7, the maximum available wcid for the associated STA is 228.
62638 +#define MAX_AVAILABLE_CLIENT_WCID (LAST_SPECIFIC_WCID - MAX_MBSSID_NUM - 1)
62639 +
62640 +// TX need WCID to find Cipher Key
62641 +// these wcid 212 ~ 219 are reserved for bc/mc packets if MAX_MBSSID_NUM is 8.
62642 +#define GET_GroupKey_WCID(__wcid, __bssidx) \
62643 + { \
62644 + __wcid = LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM) + __bssidx; \
62645 + }
62646 +
62647 +#define IsGroupKeyWCID(__wcid) (((__wcid) < LAST_SPECIFIC_WCID) && ((__wcid) >= (LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM))))
62648 +
62649 +
62650 +// definition to support multiple BSSID
62651 +#define BSS0 0
62652 +#define BSS1 1
62653 +#define BSS2 2
62654 +#define BSS3 3
62655 +#define BSS4 4
62656 +#define BSS5 5
62657 +#define BSS6 6
62658 +#define BSS7 7
62659 +
62660 +
62661 +//============================================================
62662 +// Length definitions
62663 +#define PEER_KEY_NO 2
62664 +#define MAC_ADDR_LEN 6
62665 +#define TIMESTAMP_LEN 8
62666 +#define MAX_LEN_OF_SUPPORTED_RATES MAX_LENGTH_OF_SUPPORT_RATES // 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54
62667 +#define MAX_LEN_OF_KEY 32 // 32 octets == 256 bits, Redefine for WPA
62668 +#define MAX_NUM_OF_CHANNELS MAX_NUM_OF_CHS // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination
62669 +#define MAX_NUM_OF_11JCHANNELS 20 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination
62670 +#define MAX_LEN_OF_SSID 32
62671 +#define CIPHER_TEXT_LEN 128
62672 +#define HASH_TABLE_SIZE 256
62673 +#define MAX_VIE_LEN 1024 // New for WPA cipher suite variable IE sizes.
62674 +#define MAX_SUPPORT_MCS 32
62675 +
62676 +//============================================================
62677 +// ASIC WCID Table definition.
62678 +//============================================================
62679 +#define BSSID_WCID 1 // in infra mode, always put bssid with this WCID
62680 +#define MCAST_WCID 0x0
62681 +#define BSS0Mcast_WCID 0x0
62682 +#define BSS1Mcast_WCID 0xf8
62683 +#define BSS2Mcast_WCID 0xf9
62684 +#define BSS3Mcast_WCID 0xfa
62685 +#define BSS4Mcast_WCID 0xfb
62686 +#define BSS5Mcast_WCID 0xfc
62687 +#define BSS6Mcast_WCID 0xfd
62688 +#define BSS7Mcast_WCID 0xfe
62689 +#define RESERVED_WCID 0xff
62690 +
62691 +#define MAX_NUM_OF_ACL_LIST MAX_NUMBER_OF_ACL
62692 +
62693 +#define MAX_LEN_OF_MAC_TABLE MAX_NUMBER_OF_MAC // if MAX_MBSSID_NUM is 8, this value can't be larger than 211
62694 +
62695 +#if MAX_LEN_OF_MAC_TABLE>MAX_AVAILABLE_CLIENT_WCID
62696 +#error MAX_LEN_OF_MAC_TABLE can not be larger than MAX_AVAILABLE_CLIENT_WCID!!!!
62697 +#endif
62698 +
62699 +#define MAX_NUM_OF_WDS_LINK_PERBSSID 3
62700 +#define MAX_NUM_OF_WDS_LINK (MAX_NUM_OF_WDS_LINK_PERBSSID*MAX_MBSSID_NUM)
62701 +#define MAX_NUM_OF_EVENT MAX_NUMBER_OF_EVENT
62702 +#define WDS_LINK_START_WCID (MAX_LEN_OF_MAC_TABLE-1)
62703 +
62704 +#define NUM_OF_TID 8
62705 +#define MAX_AID_BA 4
62706 +#define MAX_LEN_OF_BA_REC_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2)// (NUM_OF_TID*MAX_AID_BA + 32) //Block ACK recipient
62707 +#define MAX_LEN_OF_BA_ORI_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2)// (NUM_OF_TID*MAX_AID_BA + 32) // Block ACK originator
62708 +#define MAX_LEN_OF_BSS_TABLE 64
62709 +#define MAX_REORDERING_MPDU_NUM 512
62710 +
62711 +// key related definitions
62712 +#define SHARE_KEY_NUM 4
62713 +#define MAX_LEN_OF_SHARE_KEY 16 // byte count
62714 +#define MAX_LEN_OF_PEER_KEY 16 // byte count
62715 +#define PAIRWISE_KEY_NUM 64 // in MAC ASIC pairwise key table
62716 +#define GROUP_KEY_NUM 4
62717 +#define PMK_LEN 32
62718 +#define WDS_PAIRWISE_KEY_OFFSET 60 // WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table
62719 +#define PMKID_NO 4 // Number of PMKID saved supported
62720 +#define MAX_LEN_OF_MLME_BUFFER 2048
62721 +
62722 +// power status related definitions
62723 +#define PWR_ACTIVE 0
62724 +#define PWR_SAVE 1
62725 +#define PWR_MMPS 2 //MIMO power save
62726 +//#define PWR_UNKNOWN 2
62727 +
62728 +// Auth and Assoc mode related definitions
62729 +#define AUTH_MODE_OPEN 0x00
62730 +#define AUTH_MODE_KEY 0x01
62731 +//#define AUTH_MODE_AUTO_SWITCH 0x03
62732 +//#define AUTH_MODE_DEAUTH 0x04
62733 +//#define AUTH_MODE_UPLAYER 0x05 // reserved for 802.11i use
62734 +
62735 +// BSS Type definitions
62736 +#define BSS_ADHOC 0 // = Ndis802_11IBSS
62737 +#define BSS_INFRA 1 // = Ndis802_11Infrastructure
62738 +#define BSS_ANY 2 // = Ndis802_11AutoUnknown
62739 +#define BSS_MONITOR 3 // = Ndis802_11Monitor
62740 +
62741 +
62742 +// Reason code definitions
62743 +#define REASON_RESERVED 0
62744 +#define REASON_UNSPECIFY 1
62745 +#define REASON_NO_LONGER_VALID 2
62746 +#define REASON_DEAUTH_STA_LEAVING 3
62747 +#define REASON_DISASSOC_INACTIVE 4
62748 +#define REASON_DISASSPC_AP_UNABLE 5
62749 +#define REASON_CLS2ERR 6
62750 +#define REASON_CLS3ERR 7
62751 +#define REASON_DISASSOC_STA_LEAVING 8
62752 +#define REASON_STA_REQ_ASSOC_NOT_AUTH 9
62753 +#define REASON_INVALID_IE 13
62754 +#define REASON_MIC_FAILURE 14
62755 +#define REASON_4_WAY_TIMEOUT 15
62756 +#define REASON_GROUP_KEY_HS_TIMEOUT 16
62757 +#define REASON_IE_DIFFERENT 17
62758 +#define REASON_MCIPHER_NOT_VALID 18
62759 +#define REASON_UCIPHER_NOT_VALID 19
62760 +#define REASON_AKMP_NOT_VALID 20
62761 +#define REASON_UNSUPPORT_RSNE_VER 21
62762 +#define REASON_INVALID_RSNE_CAP 22
62763 +#define REASON_8021X_AUTH_FAIL 23
62764 +#define REASON_CIPHER_SUITE_REJECTED 24
62765 +#define REASON_DECLINED 37
62766 +
62767 +#define REASON_QOS_UNSPECIFY 32
62768 +#define REASON_QOS_LACK_BANDWIDTH 33
62769 +#define REASON_POOR_CHANNEL_CONDITION 34
62770 +#define REASON_QOS_OUTSIDE_TXOP_LIMITION 35
62771 +#define REASON_QOS_QSTA_LEAVING_QBSS 36
62772 +#define REASON_QOS_UNWANTED_MECHANISM 37
62773 +#define REASON_QOS_MECH_SETUP_REQUIRED 38
62774 +#define REASON_QOS_REQUEST_TIMEOUT 39
62775 +#define REASON_QOS_CIPHER_NOT_SUPPORT 45
62776 +
62777 +// Status code definitions
62778 +#define MLME_SUCCESS 0
62779 +#define MLME_UNSPECIFY_FAIL 1
62780 +#define MLME_CANNOT_SUPPORT_CAP 10
62781 +#define MLME_REASSOC_DENY_ASSOC_EXIST 11
62782 +#define MLME_ASSOC_DENY_OUT_SCOPE 12
62783 +#define MLME_ALG_NOT_SUPPORT 13
62784 +#define MLME_SEQ_NR_OUT_OF_SEQUENCE 14
62785 +#define MLME_REJ_CHALLENGE_FAILURE 15
62786 +#define MLME_REJ_TIMEOUT 16
62787 +#define MLME_ASSOC_REJ_UNABLE_HANDLE_STA 17
62788 +#define MLME_ASSOC_REJ_DATA_RATE 18
62789 +
62790 +#define MLME_ASSOC_REJ_NO_EXT_RATE 22
62791 +#define MLME_ASSOC_REJ_NO_EXT_RATE_PBCC 23
62792 +#define MLME_ASSOC_REJ_NO_CCK_OFDM 24
62793 +
62794 +#define MLME_QOS_UNSPECIFY 32
62795 +#define MLME_REQUEST_DECLINED 37
62796 +#define MLME_REQUEST_WITH_INVALID_PARAM 38
62797 +#define MLME_DLS_NOT_ALLOW_IN_QBSS 48
62798 +#define MLME_DEST_STA_NOT_IN_QBSS 49
62799 +#define MLME_DEST_STA_IS_NOT_A_QSTA 50
62800 +
62801 +#define MLME_INVALID_FORMAT 0x51
62802 +#define MLME_FAIL_NO_RESOURCE 0x52
62803 +#define MLME_STATE_MACHINE_REJECT 0x53
62804 +#define MLME_MAC_TABLE_FAIL 0x54
62805 +
62806 +// IE code
62807 +#define IE_SSID 0
62808 +#define IE_SUPP_RATES 1
62809 +#define IE_FH_PARM 2
62810 +#define IE_DS_PARM 3
62811 +#define IE_CF_PARM 4
62812 +#define IE_TIM 5
62813 +#define IE_IBSS_PARM 6
62814 +#define IE_COUNTRY 7 // 802.11d
62815 +#define IE_802_11D_REQUEST 10 // 802.11d
62816 +#define IE_QBSS_LOAD 11 // 802.11e d9
62817 +#define IE_EDCA_PARAMETER 12 // 802.11e d9
62818 +#define IE_TSPEC 13 // 802.11e d9
62819 +#define IE_TCLAS 14 // 802.11e d9
62820 +#define IE_SCHEDULE 15 // 802.11e d9
62821 +#define IE_CHALLENGE_TEXT 16
62822 +#define IE_POWER_CONSTRAINT 32 // 802.11h d3.3
62823 +#define IE_POWER_CAPABILITY 33 // 802.11h d3.3
62824 +#define IE_TPC_REQUEST 34 // 802.11h d3.3
62825 +#define IE_TPC_REPORT 35 // 802.11h d3.3
62826 +#define IE_SUPP_CHANNELS 36 // 802.11h d3.3
62827 +#define IE_CHANNEL_SWITCH_ANNOUNCEMENT 37 // 802.11h d3.3
62828 +#define IE_MEASUREMENT_REQUEST 38 // 802.11h d3.3
62829 +#define IE_MEASUREMENT_REPORT 39 // 802.11h d3.3
62830 +#define IE_QUIET 40 // 802.11h d3.3
62831 +#define IE_IBSS_DFS 41 // 802.11h d3.3
62832 +#define IE_ERP 42 // 802.11g
62833 +#define IE_TS_DELAY 43 // 802.11e d9
62834 +#define IE_TCLAS_PROCESSING 44 // 802.11e d9
62835 +#define IE_QOS_CAPABILITY 46 // 802.11e d6
62836 +#define IE_HT_CAP 45 // 802.11n d1. HT CAPABILITY. ELEMENT ID TBD
62837 +#define IE_AP_CHANNEL_REPORT 51 // 802.11k d6
62838 +#define IE_HT_CAP2 52 // 802.11n d1. HT CAPABILITY. ELEMENT ID TBD
62839 +#define IE_RSN 48 // 802.11i d3.0
62840 +#define IE_WPA2 48 // WPA2
62841 +#define IE_EXT_SUPP_RATES 50 // 802.11g
62842 +#define IE_SUPP_REG_CLASS 59 // 802.11y. Supported regulatory classes.
62843 +#define IE_EXT_CHANNEL_SWITCH_ANNOUNCEMENT 60 // 802.11n
62844 +#define IE_ADD_HT 61 // 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD
62845 +#define IE_ADD_HT2 53 // 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD
62846 +
62847 +
62848 +// For 802.11n D3.03
62849 +//#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset elemet
62850 +#define IE_SECONDARY_CH_OFFSET 62 // 802.11n D3.03 Secondary Channel Offset element
62851 +#define IE_WAPI 68 // WAPI information element
62852 +#define IE_2040_BSS_COEXIST 72 // 802.11n D3.0.3
62853 +#define IE_2040_BSS_INTOLERANT_REPORT 73 // 802.11n D3.03
62854 +#define IE_OVERLAPBSS_SCAN_PARM 74 // 802.11n D3.03
62855 +#define IE_EXT_CAPABILITY 127 // 802.11n D3.03
62856 +
62857 +
62858 +#define IE_WPA 221 // WPA
62859 +#define IE_VENDOR_SPECIFIC 221 // Wifi WMM (WME)
62860 +
62861 +#define OUI_BROADCOM_HT 51 //
62862 +#define OUI_BROADCOM_HTADD 52 //
62863 +#define OUI_PREN_HT_CAP 51 //
62864 +#define OUI_PREN_ADD_HT 52 //
62865 +
62866 +// CCX information
62867 +#define IE_AIRONET_CKIP 133 // CCX1.0 ID 85H for CKIP
62868 +#define IE_AP_TX_POWER 150 // CCX 2.0 for AP transmit power
62869 +#define IE_MEASUREMENT_CAPABILITY 221 // CCX 2.0
62870 +#define IE_CCX_V2 221
62871 +#define IE_AIRONET_IPADDRESS 149 // CCX ID 95H for IP Address
62872 +#define IE_AIRONET_CCKMREASSOC 156 // CCX ID 9CH for CCKM Reassociation Request element
62873 +#define CKIP_NEGOTIATION_LENGTH 30
62874 +#define AIRONET_IPADDRESS_LENGTH 10
62875 +#define AIRONET_CCKMREASSOC_LENGTH 24
62876 +
62877 +// ========================================================
62878 +// MLME state machine definition
62879 +// ========================================================
62880 +
62881 +// STA MLME state mahcines
62882 +#define ASSOC_STATE_MACHINE 1
62883 +#define AUTH_STATE_MACHINE 2
62884 +#define AUTH_RSP_STATE_MACHINE 3
62885 +#define SYNC_STATE_MACHINE 4
62886 +#define MLME_CNTL_STATE_MACHINE 5
62887 +#define WPA_PSK_STATE_MACHINE 6
62888 +#define LEAP_STATE_MACHINE 7
62889 +#define AIRONET_STATE_MACHINE 8
62890 +#define ACTION_STATE_MACHINE 9
62891 +
62892 +// AP MLME state machines
62893 +#define AP_ASSOC_STATE_MACHINE 11
62894 +#define AP_AUTH_STATE_MACHINE 12
62895 +#define AP_AUTH_RSP_STATE_MACHINE 13
62896 +#define AP_SYNC_STATE_MACHINE 14
62897 +#define AP_CNTL_STATE_MACHINE 15
62898 +#define AP_WPA_STATE_MACHINE 16
62899 +
62900 +#define WSC_STATE_MACHINE 17
62901 +#define WSC_UPNP_STATE_MACHINE 18
62902 +
62903 +
62904 +
62905 +#ifdef QOS_DLS_SUPPORT
62906 +#define DLS_STATE_MACHINE 26
62907 +#endif // QOS_DLS_SUPPORT //
62908 +
62909 +//
62910 +// STA's CONTROL/CONNECT state machine: states, events, total function #
62911 +//
62912 +#define CNTL_IDLE 0
62913 +#define CNTL_WAIT_DISASSOC 1
62914 +#define CNTL_WAIT_JOIN 2
62915 +#define CNTL_WAIT_REASSOC 3
62916 +#define CNTL_WAIT_START 4
62917 +#define CNTL_WAIT_AUTH 5
62918 +#define CNTL_WAIT_ASSOC 6
62919 +#define CNTL_WAIT_AUTH2 7
62920 +#define CNTL_WAIT_OID_LIST_SCAN 8
62921 +#define CNTL_WAIT_OID_DISASSOC 9
62922 +#ifdef RT2870
62923 +#define CNTL_WAIT_SCAN_FOR_CONNECT 10
62924 +#endif // RT2870 //
62925 +
62926 +#define MT2_ASSOC_CONF 34
62927 +#define MT2_AUTH_CONF 35
62928 +#define MT2_DEAUTH_CONF 36
62929 +#define MT2_DISASSOC_CONF 37
62930 +#define MT2_REASSOC_CONF 38
62931 +#define MT2_PWR_MGMT_CONF 39
62932 +#define MT2_JOIN_CONF 40
62933 +#define MT2_SCAN_CONF 41
62934 +#define MT2_START_CONF 42
62935 +#define MT2_GET_CONF 43
62936 +#define MT2_SET_CONF 44
62937 +#define MT2_RESET_CONF 45
62938 +#define MT2_MLME_ROAMING_REQ 52
62939 +
62940 +#define CNTL_FUNC_SIZE 1
62941 +
62942 +//
62943 +// STA's ASSOC state machine: states, events, total function #
62944 +//
62945 +#define ASSOC_IDLE 0
62946 +#define ASSOC_WAIT_RSP 1
62947 +#define REASSOC_WAIT_RSP 2
62948 +#define DISASSOC_WAIT_RSP 3
62949 +#define MAX_ASSOC_STATE 4
62950 +
62951 +#define ASSOC_MACHINE_BASE 0
62952 +#define MT2_MLME_ASSOC_REQ 0
62953 +#define MT2_MLME_REASSOC_REQ 1
62954 +#define MT2_MLME_DISASSOC_REQ 2
62955 +#define MT2_PEER_DISASSOC_REQ 3
62956 +#define MT2_PEER_ASSOC_REQ 4
62957 +#define MT2_PEER_ASSOC_RSP 5
62958 +#define MT2_PEER_REASSOC_REQ 6
62959 +#define MT2_PEER_REASSOC_RSP 7
62960 +#define MT2_DISASSOC_TIMEOUT 8
62961 +#define MT2_ASSOC_TIMEOUT 9
62962 +#define MT2_REASSOC_TIMEOUT 10
62963 +#define MAX_ASSOC_MSG 11
62964 +
62965 +#define ASSOC_FUNC_SIZE (MAX_ASSOC_STATE * MAX_ASSOC_MSG)
62966 +
62967 +//
62968 +// ACT state machine: states, events, total function #
62969 +//
62970 +#define ACT_IDLE 0
62971 +#define MAX_ACT_STATE 1
62972 +
62973 +#define ACT_MACHINE_BASE 0
62974 +
62975 +//Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please don'es modify it by your self.
62976 +//Category
62977 +#define MT2_PEER_SPECTRUM_CATE 0
62978 +#define MT2_PEER_QOS_CATE 1
62979 +#define MT2_PEER_DLS_CATE 2
62980 +#define MT2_PEER_BA_CATE 3
62981 +#define MT2_PEER_PUBLIC_CATE 4
62982 +#define MT2_PEER_RM_CATE 5
62983 +#define MT2_PEER_HT_CATE 7 // 7.4.7
62984 +#define MAX_PEER_CATE_MSG 7
62985 +#define MT2_MLME_ADD_BA_CATE 8
62986 +#define MT2_MLME_ORI_DELBA_CATE 9
62987 +#define MT2_MLME_REC_DELBA_CATE 10
62988 +#define MT2_MLME_QOS_CATE 11
62989 +#define MT2_MLME_DLS_CATE 12
62990 +#define MT2_ACT_INVALID 13
62991 +#define MAX_ACT_MSG 14
62992 +
62993 +//Category field
62994 +#define CATEGORY_SPECTRUM 0
62995 +#define CATEGORY_QOS 1
62996 +#define CATEGORY_DLS 2
62997 +#define CATEGORY_BA 3
62998 +#define CATEGORY_PUBLIC 4
62999 +#define CATEGORY_RM 5
63000 +#define CATEGORY_HT 7
63001 +
63002 +
63003 +// DLS Action frame definition
63004 +#define ACTION_DLS_REQUEST 0
63005 +#define ACTION_DLS_RESPONSE 1
63006 +#define ACTION_DLS_TEARDOWN 2
63007 +
63008 +//Spectrum Action field value 802.11h 7.4.1
63009 +#define SPEC_MRQ 0 // Request
63010 +#define SPEC_MRP 1 //Report
63011 +#define SPEC_TPCRQ 2
63012 +#define SPEC_TPCRP 3
63013 +#define SPEC_CHANNEL_SWITCH 4
63014 +
63015 +
63016 +//BA Action field value
63017 +#define ADDBA_REQ 0
63018 +#define ADDBA_RESP 1
63019 +#define DELBA 2
63020 +
63021 +//Public's Action field value in Public Category. Some in 802.11y and some in 11n
63022 +#define ACTION_BSS_2040_COEXIST 0 // 11n
63023 +#define ACTION_DSE_ENABLEMENT 1 // 11y D9.0
63024 +#define ACTION_DSE_DEENABLEMENT 2 // 11y D9.0
63025 +#define ACTION_DSE_REG_LOCATION_ANNOUNCE 3 // 11y D9.0
63026 +#define ACTION_EXT_CH_SWITCH_ANNOUNCE 4 // 11y D9.0
63027 +#define ACTION_DSE_MEASUREMENT_REQ 5 // 11y D9.0
63028 +#define ACTION_DSE_MEASUREMENT_REPORT 6 // 11y D9.0
63029 +#define ACTION_MEASUREMENT_PILOT_ACTION 7 // 11y D9.0
63030 +#define ACTION_DSE_POWER_CONSTRAINT 8 // 11y D9.0
63031 +
63032 +
63033 +//HT Action field value
63034 +#define NOTIFY_BW_ACTION 0
63035 +#define SMPS_ACTION 1
63036 +#define PSMP_ACTION 2
63037 +#define SETPCO_ACTION 3
63038 +#define MIMO_CHA_MEASURE_ACTION 4
63039 +#define MIMO_N_BEACONFORM 5
63040 +#define MIMO_BEACONFORM 6
63041 +#define ANTENNA_SELECT 7
63042 +#define HT_INFO_EXCHANGE 8
63043 +
63044 +#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG)
63045 +//
63046 +// STA's AUTHENTICATION state machine: states, evvents, total function #
63047 +//
63048 +#define AUTH_REQ_IDLE 0
63049 +#define AUTH_WAIT_SEQ2 1
63050 +#define AUTH_WAIT_SEQ4 2
63051 +#define MAX_AUTH_STATE 3
63052 +
63053 +#define AUTH_MACHINE_BASE 0
63054 +#define MT2_MLME_AUTH_REQ 0
63055 +#define MT2_PEER_AUTH_EVEN 1
63056 +#define MT2_AUTH_TIMEOUT 2
63057 +#define MAX_AUTH_MSG 3
63058 +
63059 +#define AUTH_FUNC_SIZE (MAX_AUTH_STATE * MAX_AUTH_MSG)
63060 +
63061 +//
63062 +// STA's AUTH_RSP state machine: states, events, total function #
63063 +//
63064 +#define AUTH_RSP_IDLE 0
63065 +#define AUTH_RSP_WAIT_CHAL 1
63066 +#define MAX_AUTH_RSP_STATE 2
63067 +
63068 +#define AUTH_RSP_MACHINE_BASE 0
63069 +#define MT2_AUTH_CHALLENGE_TIMEOUT 0
63070 +#define MT2_PEER_AUTH_ODD 1
63071 +#define MT2_PEER_DEAUTH 2
63072 +#define MAX_AUTH_RSP_MSG 3
63073 +
63074 +#define AUTH_RSP_FUNC_SIZE (MAX_AUTH_RSP_STATE * MAX_AUTH_RSP_MSG)
63075 +
63076 +//
63077 +// STA's SYNC state machine: states, events, total function #
63078 +//
63079 +#define SYNC_IDLE 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
63080 +#define JOIN_WAIT_BEACON 1
63081 +#define SCAN_LISTEN 2
63082 +#define MAX_SYNC_STATE 3
63083 +
63084 +#define SYNC_MACHINE_BASE 0
63085 +#define MT2_MLME_SCAN_REQ 0
63086 +#define MT2_MLME_JOIN_REQ 1
63087 +#define MT2_MLME_START_REQ 2
63088 +#define MT2_PEER_BEACON 3
63089 +#define MT2_PEER_PROBE_RSP 4
63090 +#define MT2_PEER_ATIM 5
63091 +#define MT2_SCAN_TIMEOUT 6
63092 +#define MT2_BEACON_TIMEOUT 7
63093 +#define MT2_ATIM_TIMEOUT 8
63094 +#define MT2_PEER_PROBE_REQ 9
63095 +#define MAX_SYNC_MSG 10
63096 +
63097 +#define SYNC_FUNC_SIZE (MAX_SYNC_STATE * MAX_SYNC_MSG)
63098 +
63099 +//Messages for the DLS state machine
63100 +#define DLS_IDLE 0
63101 +#define MAX_DLS_STATE 1
63102 +
63103 +#define DLS_MACHINE_BASE 0
63104 +#define MT2_MLME_DLS_REQ 0
63105 +#define MT2_PEER_DLS_REQ 1
63106 +#define MT2_PEER_DLS_RSP 2
63107 +#define MT2_MLME_DLS_TEAR_DOWN 3
63108 +#define MT2_PEER_DLS_TEAR_DOWN 4
63109 +#define MAX_DLS_MSG 5
63110 +
63111 +#define DLS_FUNC_SIZE (MAX_DLS_STATE * MAX_DLS_MSG)
63112 +
63113 +//
63114 +// STA's WPA-PSK State machine: states, events, total function #
63115 +//
63116 +#define WPA_PSK_IDLE 0
63117 +#define MAX_WPA_PSK_STATE 1
63118 +
63119 +#define WPA_MACHINE_BASE 0
63120 +#define MT2_EAPPacket 0
63121 +#define MT2_EAPOLStart 1
63122 +#define MT2_EAPOLLogoff 2
63123 +#define MT2_EAPOLKey 3
63124 +#define MT2_EAPOLASFAlert 4
63125 +#define MAX_WPA_PSK_MSG 5
63126 +
63127 +#define WPA_PSK_FUNC_SIZE (MAX_WPA_PSK_STATE * MAX_WPA_PSK_MSG)
63128 +
63129 +//
63130 +// STA's CISCO-AIRONET State machine: states, events, total function #
63131 +//
63132 +#define AIRONET_IDLE 0
63133 +#define AIRONET_SCANNING 1
63134 +#define MAX_AIRONET_STATE 2
63135 +
63136 +#define AIRONET_MACHINE_BASE 0
63137 +#define MT2_AIRONET_MSG 0
63138 +#define MT2_AIRONET_SCAN_REQ 1
63139 +#define MT2_AIRONET_SCAN_DONE 2
63140 +#define MAX_AIRONET_MSG 3
63141 +
63142 +#define AIRONET_FUNC_SIZE (MAX_AIRONET_STATE * MAX_AIRONET_MSG)
63143 +
63144 +//
63145 +// WSC State machine: states, events, total function #
63146 +//
63147 +
63148 +//
63149 +// AP's CONTROL/CONNECT state machine: states, events, total function #
63150 +//
63151 +#define AP_CNTL_FUNC_SIZE 1
63152 +
63153 +//
63154 +// AP's ASSOC state machine: states, events, total function #
63155 +//
63156 +#define AP_ASSOC_IDLE 0
63157 +#define AP_MAX_ASSOC_STATE 1
63158 +
63159 +#define AP_ASSOC_MACHINE_BASE 0
63160 +#define APMT2_MLME_DISASSOC_REQ 0
63161 +#define APMT2_PEER_DISASSOC_REQ 1
63162 +#define APMT2_PEER_ASSOC_REQ 2
63163 +#define APMT2_PEER_REASSOC_REQ 3
63164 +#define APMT2_CLS3ERR 4
63165 +#define AP_MAX_ASSOC_MSG 5
63166 +
63167 +#define AP_ASSOC_FUNC_SIZE (AP_MAX_ASSOC_STATE * AP_MAX_ASSOC_MSG)
63168 +
63169 +//
63170 +// AP's AUTHENTICATION state machine: states, events, total function #
63171 +//
63172 +#define AP_AUTH_REQ_IDLE 0
63173 +#define AP_MAX_AUTH_STATE 1
63174 +
63175 +#define AP_AUTH_MACHINE_BASE 0
63176 +#define APMT2_MLME_DEAUTH_REQ 0
63177 +#define APMT2_CLS2ERR 1
63178 +#define AP_MAX_AUTH_MSG 2
63179 +
63180 +#define AP_AUTH_FUNC_SIZE (AP_MAX_AUTH_STATE * AP_MAX_AUTH_MSG)
63181 +
63182 +//
63183 +// AP's AUTH-RSP state machine: states, events, total function #
63184 +//
63185 +#define AP_AUTH_RSP_IDLE 0
63186 +#define AP_MAX_AUTH_RSP_STATE 1
63187 +
63188 +#define AP_AUTH_RSP_MACHINE_BASE 0
63189 +#define APMT2_AUTH_CHALLENGE_TIMEOUT 0
63190 +#define APMT2_PEER_AUTH_ODD 1
63191 +#define APMT2_PEER_DEAUTH 2
63192 +#define AP_MAX_AUTH_RSP_MSG 3
63193 +
63194 +#define AP_AUTH_RSP_FUNC_SIZE (AP_MAX_AUTH_RSP_STATE * AP_MAX_AUTH_RSP_MSG)
63195 +
63196 +//
63197 +// AP's SYNC state machine: states, events, total function #
63198 +//
63199 +#define AP_SYNC_IDLE 0
63200 +#define AP_SCAN_LISTEN 1
63201 +#define AP_MAX_SYNC_STATE 2
63202 +
63203 +#define AP_SYNC_MACHINE_BASE 0
63204 +#define APMT2_PEER_PROBE_REQ 0
63205 +#define APMT2_PEER_BEACON 1
63206 +#define APMT2_MLME_SCAN_REQ 2
63207 +#define APMT2_PEER_PROBE_RSP 3
63208 +#define APMT2_SCAN_TIMEOUT 4
63209 +#define APMT2_MLME_SCAN_CNCL 5
63210 +#define AP_MAX_SYNC_MSG 6
63211 +
63212 +#define AP_SYNC_FUNC_SIZE (AP_MAX_SYNC_STATE * AP_MAX_SYNC_MSG)
63213 +
63214 +//
63215 +// AP's WPA state machine: states, events, total function #
63216 +//
63217 +#define AP_WPA_PTK 0
63218 +#define AP_MAX_WPA_PTK_STATE 1
63219 +
63220 +#define AP_WPA_MACHINE_BASE 0
63221 +#define APMT2_EAPPacket 0
63222 +#define APMT2_EAPOLStart 1
63223 +#define APMT2_EAPOLLogoff 2
63224 +#define APMT2_EAPOLKey 3
63225 +#define APMT2_EAPOLASFAlert 4
63226 +#define AP_MAX_WPA_MSG 5
63227 +
63228 +#define AP_WPA_FUNC_SIZE (AP_MAX_WPA_PTK_STATE * AP_MAX_WPA_MSG)
63229 +
63230 +
63231 +
63232 +// =============================================================================
63233 +
63234 +// value domain of 802.11 header FC.Tyte, which is b3..b2 of the 1st-byte of MAC header
63235 +#define BTYPE_MGMT 0
63236 +#define BTYPE_CNTL 1
63237 +#define BTYPE_DATA 2
63238 +
63239 +// value domain of 802.11 MGMT frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
63240 +#define SUBTYPE_ASSOC_REQ 0
63241 +#define SUBTYPE_ASSOC_RSP 1
63242 +#define SUBTYPE_REASSOC_REQ 2
63243 +#define SUBTYPE_REASSOC_RSP 3
63244 +#define SUBTYPE_PROBE_REQ 4
63245 +#define SUBTYPE_PROBE_RSP 5
63246 +#define SUBTYPE_BEACON 8
63247 +#define SUBTYPE_ATIM 9
63248 +#define SUBTYPE_DISASSOC 10
63249 +#define SUBTYPE_AUTH 11
63250 +#define SUBTYPE_DEAUTH 12
63251 +#define SUBTYPE_ACTION 13
63252 +#define SUBTYPE_ACTION_NO_ACK 14
63253 +
63254 +// value domain of 802.11 CNTL frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
63255 +#define SUBTYPE_WRAPPER 7
63256 +#define SUBTYPE_BLOCK_ACK_REQ 8
63257 +#define SUBTYPE_BLOCK_ACK 9
63258 +#define SUBTYPE_PS_POLL 10
63259 +#define SUBTYPE_RTS 11
63260 +#define SUBTYPE_CTS 12
63261 +#define SUBTYPE_ACK 13
63262 +#define SUBTYPE_CFEND 14
63263 +#define SUBTYPE_CFEND_CFACK 15
63264 +
63265 +// value domain of 802.11 DATA frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header
63266 +#define SUBTYPE_DATA 0
63267 +#define SUBTYPE_DATA_CFACK 1
63268 +#define SUBTYPE_DATA_CFPOLL 2
63269 +#define SUBTYPE_DATA_CFACK_CFPOLL 3
63270 +#define SUBTYPE_NULL_FUNC 4
63271 +#define SUBTYPE_CFACK 5
63272 +#define SUBTYPE_CFPOLL 6
63273 +#define SUBTYPE_CFACK_CFPOLL 7
63274 +#define SUBTYPE_QDATA 8
63275 +#define SUBTYPE_QDATA_CFACK 9
63276 +#define SUBTYPE_QDATA_CFPOLL 10
63277 +#define SUBTYPE_QDATA_CFACK_CFPOLL 11
63278 +#define SUBTYPE_QOS_NULL 12
63279 +#define SUBTYPE_QOS_CFACK 13
63280 +#define SUBTYPE_QOS_CFPOLL 14
63281 +#define SUBTYPE_QOS_CFACK_CFPOLL 15
63282 +
63283 +// ACK policy of QOS Control field bit 6:5
63284 +#define NORMAL_ACK 0x00 // b6:5 = 00
63285 +#define NO_ACK 0x20 // b6:5 = 01
63286 +#define NO_EXPLICIT_ACK 0x40 // b6:5 = 10
63287 +#define BLOCK_ACK 0x60 // b6:5 = 11
63288 +
63289 +//
63290 +// rtmp_data.c use these definition
63291 +//
63292 +#define LENGTH_802_11 24
63293 +#define LENGTH_802_11_AND_H 30
63294 +#define LENGTH_802_11_CRC_H 34
63295 +#define LENGTH_802_11_CRC 28
63296 +#define LENGTH_802_11_WITH_ADDR4 30
63297 +#define LENGTH_802_3 14
63298 +#define LENGTH_802_3_TYPE 2
63299 +#define LENGTH_802_1_H 8
63300 +#define LENGTH_EAPOL_H 4
63301 +#define LENGTH_WMMQOS_H 2
63302 +#define LENGTH_CRC 4
63303 +#define MAX_SEQ_NUMBER 0x0fff
63304 +#define LENGTH_802_3_NO_TYPE 12
63305 +#define LENGTH_802_1Q 4 /* VLAN related */
63306 +
63307 +// STA_CSR4.field.TxResult
63308 +#define TX_RESULT_SUCCESS 0
63309 +#define TX_RESULT_ZERO_LENGTH 1
63310 +#define TX_RESULT_UNDER_RUN 2
63311 +#define TX_RESULT_OHY_ERROR 4
63312 +#define TX_RESULT_RETRY_FAIL 6
63313 +
63314 +// All PHY rate summary in TXD
63315 +// Preamble MODE in TxD
63316 +#define MODE_CCK 0
63317 +#define MODE_OFDM 1
63318 +#ifdef DOT11_N_SUPPORT
63319 +#define MODE_HTMIX 2
63320 +#define MODE_HTGREENFIELD 3
63321 +#endif // DOT11_N_SUPPORT //
63322 +// MCS for CCK. BW.SGI.STBC are reserved
63323 +#define MCS_LONGP_RATE_1 0 // long preamble CCK 1Mbps
63324 +#define MCS_LONGP_RATE_2 1 // long preamble CCK 1Mbps
63325 +#define MCS_LONGP_RATE_5_5 2
63326 +#define MCS_LONGP_RATE_11 3
63327 +#define MCS_SHORTP_RATE_1 4 // long preamble CCK 1Mbps. short is forbidden in 1Mbps
63328 +#define MCS_SHORTP_RATE_2 5 // short preamble CCK 2Mbps
63329 +#define MCS_SHORTP_RATE_5_5 6
63330 +#define MCS_SHORTP_RATE_11 7
63331 +// To send duplicate legacy OFDM. set BW=BW_40. SGI.STBC are reserved
63332 +#define MCS_RATE_6 0 // legacy OFDM
63333 +#define MCS_RATE_9 1 // OFDM
63334 +#define MCS_RATE_12 2 // OFDM
63335 +#define MCS_RATE_18 3 // OFDM
63336 +#define MCS_RATE_24 4 // OFDM
63337 +#define MCS_RATE_36 5 // OFDM
63338 +#define MCS_RATE_48 6 // OFDM
63339 +#define MCS_RATE_54 7 // OFDM
63340 +// HT
63341 +#define MCS_0 0 // 1S
63342 +#define MCS_1 1
63343 +#define MCS_2 2
63344 +#define MCS_3 3
63345 +#define MCS_4 4
63346 +#define MCS_5 5
63347 +#define MCS_6 6
63348 +#define MCS_7 7
63349 +#define MCS_8 8 // 2S
63350 +#define MCS_9 9
63351 +#define MCS_10 10
63352 +#define MCS_11 11
63353 +#define MCS_12 12
63354 +#define MCS_13 13
63355 +#define MCS_14 14
63356 +#define MCS_15 15
63357 +#define MCS_16 16 // 3*3
63358 +#define MCS_17 17
63359 +#define MCS_18 18
63360 +#define MCS_19 19
63361 +#define MCS_20 20
63362 +#define MCS_21 21
63363 +#define MCS_22 22
63364 +#define MCS_23 23
63365 +#define MCS_32 32
63366 +#define MCS_AUTO 33
63367 +
63368 +#ifdef DOT11_N_SUPPORT
63369 +// OID_HTPHYMODE
63370 +// MODE
63371 +#define HTMODE_MM 0
63372 +#define HTMODE_GF 1
63373 +#endif // DOT11_N_SUPPORT //
63374 +
63375 +// Fixed Tx MODE - HT, CCK or OFDM
63376 +#define FIXED_TXMODE_HT 0
63377 +#define FIXED_TXMODE_CCK 1
63378 +#define FIXED_TXMODE_OFDM 2
63379 +// BW
63380 +#define BW_20 BAND_WIDTH_20
63381 +#define BW_40 BAND_WIDTH_40
63382 +#define BW_BOTH BAND_WIDTH_BOTH
63383 +#define BW_10 BAND_WIDTH_10 // 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field.
63384 +
63385 +#ifdef DOT11_N_SUPPORT
63386 +// SHORTGI
63387 +#define GI_400 GAP_INTERVAL_400 // only support in HT mode
63388 +#define GI_BOTH GAP_INTERVAL_BOTH
63389 +#endif // DOT11_N_SUPPORT //
63390 +#define GI_800 GAP_INTERVAL_800
63391 +// STBC
63392 +#define STBC_NONE 0
63393 +#ifdef DOT11_N_SUPPORT
63394 +#define STBC_USE 1 // limited use in rt2860b phy
63395 +#define RXSTBC_ONE 1 // rx support of one spatial stream
63396 +#define RXSTBC_TWO 2 // rx support of 1 and 2 spatial stream
63397 +#define RXSTBC_THR 3 // rx support of 1~3 spatial stream
63398 +// MCS FEEDBACK
63399 +#define MCSFBK_NONE 0 // not support mcs feedback /
63400 +#define MCSFBK_RSV 1 // reserved
63401 +#define MCSFBK_UNSOLICIT 2 // only support unsolict mcs feedback
63402 +#define MCSFBK_MRQ 3 // response to both MRQ and unsolict mcs feedback
63403 +
63404 +// MIMO power safe
63405 +#define MMPS_STATIC 0
63406 +#define MMPS_DYNAMIC 1
63407 +#define MMPS_RSV 2
63408 +#define MMPS_ENABLE 3
63409 +
63410 +
63411 +// A-MSDU size
63412 +#define AMSDU_0 0
63413 +#define AMSDU_1 1
63414 +
63415 +#endif // DOT11_N_SUPPORT //
63416 +
63417 +// MCS use 7 bits
63418 +#define TXRATEMIMO 0x80
63419 +#define TXRATEMCS 0x7F
63420 +#define TXRATEOFDM 0x7F
63421 +#define RATE_1 0
63422 +#define RATE_2 1
63423 +#define RATE_5_5 2
63424 +#define RATE_11 3
63425 +#define RATE_6 4 // OFDM
63426 +#define RATE_9 5 // OFDM
63427 +#define RATE_12 6 // OFDM
63428 +#define RATE_18 7 // OFDM
63429 +#define RATE_24 8 // OFDM
63430 +#define RATE_36 9 // OFDM
63431 +#define RATE_48 10 // OFDM
63432 +#define RATE_54 11 // OFDM
63433 +#define RATE_FIRST_OFDM_RATE RATE_6
63434 +#define RATE_LAST_OFDM_RATE RATE_54
63435 +#define RATE_6_5 12 // HT mix
63436 +#define RATE_13 13 // HT mix
63437 +#define RATE_19_5 14 // HT mix
63438 +#define RATE_26 15 // HT mix
63439 +#define RATE_39 16 // HT mix
63440 +#define RATE_52 17 // HT mix
63441 +#define RATE_58_5 18 // HT mix
63442 +#define RATE_65 19 // HT mix
63443 +#define RATE_78 20 // HT mix
63444 +#define RATE_104 21 // HT mix
63445 +#define RATE_117 22 // HT mix
63446 +#define RATE_130 23 // HT mix
63447 +//#define RATE_AUTO_SWITCH 255 // for StaCfg.FixedTxRate only
63448 +#define HTRATE_0 12
63449 +#define RATE_FIRST_MM_RATE HTRATE_0
63450 +#define RATE_FIRST_HT_RATE HTRATE_0
63451 +#define RATE_LAST_HT_RATE HTRATE_0
63452 +
63453 +// pTxWI->txop
63454 +#define IFS_HTTXOP 0 // The txop will be handles by ASIC.
63455 +#define IFS_PIFS 1
63456 +#define IFS_SIFS 2
63457 +#define IFS_BACKOFF 3
63458 +
63459 +// pTxD->RetryMode
63460 +#define LONG_RETRY 1
63461 +#define SHORT_RETRY 0
63462 +
63463 +// Country Region definition
63464 +#define REGION_MINIMUM_BG_BAND 0
63465 +#define REGION_0_BG_BAND 0 // 1-11
63466 +#define REGION_1_BG_BAND 1 // 1-13
63467 +#define REGION_2_BG_BAND 2 // 10-11
63468 +#define REGION_3_BG_BAND 3 // 10-13
63469 +#define REGION_4_BG_BAND 4 // 14
63470 +#define REGION_5_BG_BAND 5 // 1-14
63471 +#define REGION_6_BG_BAND 6 // 3-9
63472 +#define REGION_7_BG_BAND 7 // 5-13
63473 +#define REGION_31_BG_BAND 31 // 5-13
63474 +#define REGION_MAXIMUM_BG_BAND 7
63475 +
63476 +#define REGION_MINIMUM_A_BAND 0
63477 +#define REGION_0_A_BAND 0 // 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165
63478 +#define REGION_1_A_BAND 1 // 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
63479 +#define REGION_2_A_BAND 2 // 36, 40, 44, 48, 52, 56, 60, 64
63480 +#define REGION_3_A_BAND 3 // 52, 56, 60, 64, 149, 153, 157, 161
63481 +#define REGION_4_A_BAND 4 // 149, 153, 157, 161, 165
63482 +#define REGION_5_A_BAND 5 // 149, 153, 157, 161
63483 +#define REGION_6_A_BAND 6 // 36, 40, 44, 48
63484 +#define REGION_7_A_BAND 7 // 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165
63485 +#define REGION_8_A_BAND 8 // 52, 56, 60, 64
63486 +#define REGION_9_A_BAND 9 // 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165
63487 +#define REGION_10_A_BAND 10 // 36, 40, 44, 48, 149, 153, 157, 161, 165
63488 +#define REGION_11_A_BAND 11 // 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161
63489 +#define REGION_MAXIMUM_A_BAND 11
63490 +
63491 +// pTxD->CipherAlg
63492 +#define CIPHER_NONE 0
63493 +#define CIPHER_WEP64 1
63494 +#define CIPHER_WEP128 2
63495 +#define CIPHER_TKIP 3
63496 +#define CIPHER_AES 4
63497 +#define CIPHER_CKIP64 5
63498 +#define CIPHER_CKIP128 6
63499 +#define CIPHER_TKIP_NO_MIC 7 // MIC appended by driver: not a valid value in hardware key table
63500 +#define CIPHER_SMS4 8
63501 +
63502 +// value domain of pAd->RfIcType
63503 +#define RFIC_2820 1 // 2.4G 2T3R
63504 +#define RFIC_2850 2 // 2.4G/5G 2T3R
63505 +#define RFIC_2720 3 // 2.4G 1T2R
63506 +#define RFIC_2750 4 // 2.4G/5G 1T2R
63507 +#define RFIC_3020 5 // 2.4G 1T1R
63508 +#define RFIC_2020 6 // 2.4G B/G
63509 +#define RFIC_3021 7 // 2.4G 1T2R
63510 +#define RFIC_3022 8 // 2.4G 2T2R
63511 +
63512 +// LED Status.
63513 +#define LED_LINK_DOWN 0
63514 +#define LED_LINK_UP 1
63515 +#define LED_RADIO_OFF 2
63516 +#define LED_RADIO_ON 3
63517 +#define LED_HALT 4
63518 +#define LED_WPS 5
63519 +#define LED_ON_SITE_SURVEY 6
63520 +#define LED_POWER_UP 7
63521 +
63522 +// value domain of pAd->LedCntl.LedMode and E2PROM
63523 +#define LED_MODE_DEFAULT 0
63524 +#define LED_MODE_TWO_LED 1
63525 +#define LED_MODE_SIGNAL_STREGTH 8 // EEPROM define =8
63526 +
63527 +// RC4 init value, used fro WEP & TKIP
63528 +#define PPPINITFCS32 0xffffffff /* Initial FCS value */
63529 +
63530 +// value domain of pAd->StaCfg.PortSecured. 802.1X controlled port definition
63531 +#define WPA_802_1X_PORT_SECURED 1
63532 +#define WPA_802_1X_PORT_NOT_SECURED 2
63533 +
63534 +#define PAIRWISE_KEY 1
63535 +#define GROUP_KEY 2
63536 +
63537 +//definition of DRS
63538 +#define MAX_STEP_OF_TX_RATE_SWITCH 32
63539 +
63540 +
63541 +// pre-allocated free NDIS PACKET/BUFFER poll for internal usage
63542 +#define MAX_NUM_OF_FREE_NDIS_PACKET 128
63543 +
63544 +//Block ACK
63545 +#define MAX_TX_REORDERBUF 64
63546 +#define MAX_RX_REORDERBUF 64
63547 +#define DEFAULT_TX_TIMEOUT 30
63548 +#define DEFAULT_RX_TIMEOUT 30
63549 +
63550 +// definition of Recipient or Originator
63551 +#define I_RECIPIENT TRUE
63552 +#define I_ORIGINATOR FALSE
63553 +
63554 +#define DEFAULT_BBP_TX_POWER 0
63555 +#define DEFAULT_RF_TX_POWER 5
63556 +
63557 +#define MAX_INI_BUFFER_SIZE 4096
63558 +#define MAX_PARAM_BUFFER_SIZE (2048) // enough for ACL (18*64)
63559 + //18 : the length of Mac address acceptable format "01:02:03:04:05:06;")
63560 + //64 : MAX_NUM_OF_ACL_LIST
63561 +// definition of pAd->OpMode
63562 +#define OPMODE_STA 0
63563 +#define OPMODE_AP 1
63564 +//#define OPMODE_L3_BRG 2 // as AP and STA at the same time
63565 +
63566 +#ifdef RT_BIG_ENDIAN
63567 +#define DIR_READ 0
63568 +#define DIR_WRITE 1
63569 +#define TYPE_TXD 0
63570 +#define TYPE_RXD 1
63571 +#define TYPE_TXINFO 0
63572 +#define TYPE_RXINFO 1
63573 +#define TYPE_TXWI 0
63574 +#define TYPE_RXWI 1
63575 +#endif
63576 +
63577 +// ========================= AP rtmp_def.h ===========================
63578 +// value domain for pAd->EventTab.Log[].Event
63579 +#define EVENT_RESET_ACCESS_POINT 0 // Log = "hh:mm:ss Restart Access Point"
63580 +#define EVENT_ASSOCIATED 1 // Log = "hh:mm:ss STA 00:01:02:03:04:05 associated"
63581 +#define EVENT_DISASSOCIATED 2 // Log = "hh:mm:ss STA 00:01:02:03:04:05 left this BSS"
63582 +#define EVENT_AGED_OUT 3 // Log = "hh:mm:ss STA 00:01:02:03:04:05 was aged-out and removed from this BSS"
63583 +#define EVENT_COUNTER_M 4
63584 +#define EVENT_INVALID_PSK 5
63585 +#define EVENT_MAX_EVENT_TYPE 6
63586 +// ==== end of AP rtmp_def.h ============
63587 +
63588 +// definition RSSI Number
63589 +#define RSSI_0 0
63590 +#define RSSI_1 1
63591 +#define RSSI_2 2
63592 +
63593 +// definition of radar detection
63594 +#define RD_NORMAL_MODE 0 // Not found radar signal
63595 +#define RD_SWITCHING_MODE 1 // Found radar signal, and doing channel switch
63596 +#define RD_SILENCE_MODE 2 // After channel switch, need to be silence a while to ensure radar not found
63597 +
63598 +//Driver defined cid for mapping status and command.
63599 +#define SLEEPCID 0x11
63600 +#define WAKECID 0x22
63601 +#define QUERYPOWERCID 0x33
63602 +#define OWNERMCU 0x1
63603 +#define OWNERCPU 0x0
63604 +
63605 +// MBSSID definition
63606 +#define ENTRY_NOT_FOUND 0xFF
63607 +
63608 +
63609 +/* After Linux 2.6.9,
63610 + * VLAN module use Private (from user) interface flags (netdevice->priv_flags).
63611 + * #define IFF_802_1Q_VLAN 0x1 -- 802.1Q VLAN device. in if.h
63612 + * ref to ip_sabotage_out() [ out->priv_flags & IFF_802_1Q_VLAN ] in br_netfilter.c
63613 + *
63614 + * For this reason, we MUST use EVEN value in priv_flags
63615 + */
63616 +#define INT_MAIN 0x0100
63617 +#define INT_MBSSID 0x0200
63618 +#define INT_WDS 0x0300
63619 +#define INT_APCLI 0x0400
63620 +#define INT_MESH 0x0500
63621 +
63622 +// Use bitmap to allow coexist of ATE_TXFRAME and ATE_RXFRAME(i.e.,to support LoopBack mode)
63623 +#ifdef RALINK_ATE
63624 +#define ATE_START 0x00 // Start ATE
63625 +#define ATE_STOP 0x80 // Stop ATE
63626 +#define ATE_TXCONT 0x05 // Continuous Transmit
63627 +#define ATE_TXCARR 0x09 // Transmit Carrier
63628 +#define ATE_TXCARRSUPP 0x11 // Transmit Carrier Suppression
63629 +#define ATE_TXFRAME 0x01 // Transmit Frames
63630 +#define ATE_RXFRAME 0x02 // Receive Frames
63631 +#ifdef RALINK_28xx_QA
63632 +#define ATE_TXSTOP 0xe2 // Stop Transmition(i.e., TXCONT, TXCARR, TXCARRSUPP, and TXFRAME)
63633 +#define ATE_RXSTOP 0xfd // Stop receiving Frames
63634 +#define BBP22_TXFRAME 0x00 // Transmit Frames
63635 +#define BBP22_TXCONT_OR_CARRSUPP 0x80 // Continuous Transmit or Carrier Suppression
63636 +#define BBP22_TXCARR 0xc1 // Transmit Carrier
63637 +#define BBP24_TXCONT 0x00 // Continuous Transmit
63638 +#define BBP24_CARRSUPP 0x01 // Carrier Suppression
63639 +#endif // RALINK_28xx_QA //
63640 +#endif // RALINK_ATE //
63641 +
63642 +// WEP Key TYPE
63643 +#define WEP_HEXADECIMAL_TYPE 0
63644 +#define WEP_ASCII_TYPE 1
63645 +
63646 +
63647 +
63648 +// WIRELESS EVENTS definition
63649 +/* Max number of char in custom event, refer to wireless_tools.28/wireless.20.h */
63650 +#define IW_CUSTOM_MAX_LEN 255 /* In bytes */
63651 +
63652 +// For system event - start
63653 +#define IW_SYS_EVENT_FLAG_START 0x0200
63654 +#define IW_ASSOC_EVENT_FLAG 0x0200
63655 +#define IW_DISASSOC_EVENT_FLAG 0x0201
63656 +#define IW_DEAUTH_EVENT_FLAG 0x0202
63657 +#define IW_AGEOUT_EVENT_FLAG 0x0203
63658 +#define IW_COUNTER_MEASURES_EVENT_FLAG 0x0204
63659 +#define IW_REPLAY_COUNTER_DIFF_EVENT_FLAG 0x0205
63660 +#define IW_RSNIE_DIFF_EVENT_FLAG 0x0206
63661 +#define IW_MIC_DIFF_EVENT_FLAG 0x0207
63662 +#define IW_ICV_ERROR_EVENT_FLAG 0x0208
63663 +#define IW_MIC_ERROR_EVENT_FLAG 0x0209
63664 +#define IW_GROUP_HS_TIMEOUT_EVENT_FLAG 0x020A
63665 +#define IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG 0x020B
63666 +#define IW_RSNIE_SANITY_FAIL_EVENT_FLAG 0x020C
63667 +#define IW_SET_KEY_DONE_WPA1_EVENT_FLAG 0x020D
63668 +#define IW_SET_KEY_DONE_WPA2_EVENT_FLAG 0x020E
63669 +#define IW_STA_LINKUP_EVENT_FLAG 0x020F
63670 +#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210
63671 +#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211
63672 +#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212
63673 +// if add new system event flag, please upadte the IW_SYS_EVENT_FLAG_END
63674 +#define IW_SYS_EVENT_FLAG_END 0x0212
63675 +#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1)
63676 +// For system event - end
63677 +
63678 +// For spoof attack event - start
63679 +#define IW_SPOOF_EVENT_FLAG_START 0x0300
63680 +#define IW_CONFLICT_SSID_EVENT_FLAG 0x0300
63681 +#define IW_SPOOF_ASSOC_RESP_EVENT_FLAG 0x0301
63682 +#define IW_SPOOF_REASSOC_RESP_EVENT_FLAG 0x0302
63683 +#define IW_SPOOF_PROBE_RESP_EVENT_FLAG 0x0303
63684 +#define IW_SPOOF_BEACON_EVENT_FLAG 0x0304
63685 +#define IW_SPOOF_DISASSOC_EVENT_FLAG 0x0305
63686 +#define IW_SPOOF_AUTH_EVENT_FLAG 0x0306
63687 +#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307
63688 +#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308
63689 +#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309
63690 +// if add new spoof attack event flag, please upadte the IW_SPOOF_EVENT_FLAG_END
63691 +#define IW_SPOOF_EVENT_FLAG_END 0x0309
63692 +#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1)
63693 +// For spoof attack event - end
63694 +
63695 +// For flooding attack event - start
63696 +#define IW_FLOOD_EVENT_FLAG_START 0x0400
63697 +#define IW_FLOOD_AUTH_EVENT_FLAG 0x0400
63698 +#define IW_FLOOD_ASSOC_REQ_EVENT_FLAG 0x0401
63699 +#define IW_FLOOD_REASSOC_REQ_EVENT_FLAG 0x0402
63700 +#define IW_FLOOD_PROBE_REQ_EVENT_FLAG 0x0403
63701 +#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404
63702 +#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405
63703 +#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406
63704 +// if add new flooding attack event flag, please upadte the IW_FLOOD_EVENT_FLAG_END
63705 +#define IW_FLOOD_EVENT_FLAG_END 0x0406
63706 +#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1)
63707 +// For flooding attack - end
63708 +
63709 +// End - WIRELESS EVENTS definition
63710 +
63711 +#ifdef CONFIG_STA_SUPPORT
63712 +// definition for DLS, kathy
63713 +#define MAX_NUM_OF_INIT_DLS_ENTRY 1
63714 +#define MAX_NUM_OF_DLS_ENTRY MAX_NUMBER_OF_DLS_ENTRY
63715 +
63716 +//Block ACK , rt2860, kathy
63717 +#define MAX_TX_REORDERBUF 64
63718 +#define MAX_RX_REORDERBUF 64
63719 +#define DEFAULT_TX_TIMEOUT 30
63720 +#define DEFAULT_RX_TIMEOUT 30
63721 +#ifndef CONFIG_AP_SUPPORT
63722 +#define MAX_BARECI_SESSION 8
63723 +#endif
63724 +
63725 +#ifndef IW_ESSID_MAX_SIZE
63726 +/* Maximum size of the ESSID and pAd->nickname strings */
63727 +#define IW_ESSID_MAX_SIZE 32
63728 +#endif
63729 +#endif // CONFIG_STA_SUPPORT //
63730 +
63731 +#ifdef MCAST_RATE_SPECIFIC
63732 +#define MCAST_DISABLE 0
63733 +#define MCAST_CCK 1
63734 +#define MCAST_OFDM 2
63735 +#define MCAST_HTMIX 3
63736 +#endif // MCAST_RATE_SPECIFIC //
63737 +
63738 +// For AsicRadioOff/AsicRadioOn function
63739 +#define DOT11POWERSAVE 0
63740 +#define GUIRADIO_OFF 1
63741 +#define RTMP_HALT 2
63742 +#define GUI_IDLE_POWER_SAVE 3
63743 +// --
63744 +
63745 +
63746 +// definition for WpaSupport flag
63747 +#define WPA_SUPPLICANT_DISABLE 0
63748 +#define WPA_SUPPLICANT_ENABLE 1
63749 +#define WPA_SUPPLICANT_ENABLE_WITH_WEB_UI 2
63750 +
63751 +// Endian byte swapping codes
63752 +#define SWAP16(x) \
63753 + ((UINT16)( \
63754 + (((UINT16)(x) & (UINT16) 0x00ffU) << 8) | \
63755 + (((UINT16)(x) & (UINT16) 0xff00U) >> 8) ))
63756 +
63757 +#define SWAP32(x) \
63758 + ((UINT32)( \
63759 + (((UINT32)(x) & (UINT32) 0x000000ffUL) << 24) | \
63760 + (((UINT32)(x) & (UINT32) 0x0000ff00UL) << 8) | \
63761 + (((UINT32)(x) & (UINT32) 0x00ff0000UL) >> 8) | \
63762 + (((UINT32)(x) & (UINT32) 0xff000000UL) >> 24) ))
63763 +
63764 +#define SWAP64(x) \
63765 + ((UINT64)( \
63766 + (UINT64)(((UINT64)(x) & (UINT64) 0x00000000000000ffULL) << 56) | \
63767 + (UINT64)(((UINT64)(x) & (UINT64) 0x000000000000ff00ULL) << 40) | \
63768 + (UINT64)(((UINT64)(x) & (UINT64) 0x0000000000ff0000ULL) << 24) | \
63769 + (UINT64)(((UINT64)(x) & (UINT64) 0x00000000ff000000ULL) << 8) | \
63770 + (UINT64)(((UINT64)(x) & (UINT64) 0x000000ff00000000ULL) >> 8) | \
63771 + (UINT64)(((UINT64)(x) & (UINT64) 0x0000ff0000000000ULL) >> 24) | \
63772 + (UINT64)(((UINT64)(x) & (UINT64) 0x00ff000000000000ULL) >> 40) | \
63773 + (UINT64)(((UINT64)(x) & (UINT64) 0xff00000000000000ULL) >> 56) ))
63774 +
63775 +#ifdef RT_BIG_ENDIAN
63776 +
63777 +#define cpu2le64(x) SWAP64((x))
63778 +#define le2cpu64(x) SWAP64((x))
63779 +#define cpu2le32(x) SWAP32((x))
63780 +#define le2cpu32(x) SWAP32((x))
63781 +#define cpu2le16(x) SWAP16((x))
63782 +#define le2cpu16(x) SWAP16((x))
63783 +#define cpu2be64(x) ((UINT64)(x))
63784 +#define be2cpu64(x) ((UINT64)(x))
63785 +#define cpu2be32(x) ((UINT32)(x))
63786 +#define be2cpu32(x) ((UINT32)(x))
63787 +#define cpu2be16(x) ((UINT16)(x))
63788 +#define be2cpu16(x) ((UINT16)(x))
63789 +
63790 +#else // Little_Endian
63791 +
63792 +#define cpu2le64(x) ((UINT64)(x))
63793 +#define le2cpu64(x) ((UINT64)(x))
63794 +#define cpu2le32(x) ((UINT32)(x))
63795 +#define le2cpu32(x) ((UINT32)(x))
63796 +#define cpu2le16(x) ((UINT16)(x))
63797 +#define le2cpu16(x) ((UINT16)(x))
63798 +#define cpu2be64(x) SWAP64((x))
63799 +#define be2cpu64(x) SWAP64((x))
63800 +#define cpu2be32(x) SWAP32((x))
63801 +#define be2cpu32(x) SWAP32((x))
63802 +#define cpu2be16(x) SWAP16((x))
63803 +#define be2cpu16(x) SWAP16((x))
63804 +
63805 +#endif // RT_BIG_ENDIAN
63806 +
63807 +#endif // __RTMP_DEF_H__
63808 +
63809 +
63810 --- /dev/null
63811 +++ b/drivers/staging/rt3070/rtmp.h
63812 @@ -0,0 +1,7728 @@
63813 +/*
63814 + *************************************************************************
63815 + * Ralink Tech Inc.
63816 + * 5F., No.36, Taiyuan St., Jhubei City,
63817 + * Hsinchu County 302,
63818 + * Taiwan, R.O.C.
63819 + *
63820 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
63821 + *
63822 + * This program is free software; you can redistribute it and/or modify *
63823 + * it under the terms of the GNU General Public License as published by *
63824 + * the Free Software Foundation; either version 2 of the License, or *
63825 + * (at your option) any later version. *
63826 + * *
63827 + * This program is distributed in the hope that it will be useful, *
63828 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
63829 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
63830 + * GNU General Public License for more details. *
63831 + * *
63832 + * You should have received a copy of the GNU General Public License *
63833 + * along with this program; if not, write to the *
63834 + * Free Software Foundation, Inc., *
63835 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
63836 + * *
63837 + *************************************************************************
63838 +
63839 + Module Name:
63840 + rtmp.h
63841 +
63842 + Abstract:
63843 + Miniport generic portion header file
63844 +
63845 + Revision History:
63846 + Who When What
63847 + -------- ---------- ----------------------------------------------
63848 + Paul Lin 2002-08-01 created
63849 + James Tan 2002-09-06 modified (Revise NTCRegTable)
63850 + John Chang 2004-09-06 modified for RT2600
63851 +*/
63852 +#ifndef __RTMP_H__
63853 +#define __RTMP_H__
63854 +
63855 +#include "link_list.h"
63856 +#include "spectrum_def.h"
63857 +
63858 +#ifdef MLME_EX
63859 +#include "mlme_ex_def.h"
63860 +#endif // MLME_EX //
63861 +
63862 +#ifdef CONFIG_STA_SUPPORT
63863 +#include "aironet.h"
63864 +#endif // CONFIG_STA_SUPPORT //
63865 +
63866 +#undef AP_WSC_INCLUDED
63867 +#undef STA_WSC_INCLUDED
63868 +#undef WSC_INCLUDED
63869 +
63870 +
63871 +#ifdef CONFIG_STA_SUPPORT
63872 +#endif // CONFIG_STA_SUPPORT //
63873 +
63874 +#if defined(AP_WSC_INCLUDED) || defined(STA_WSC_INCLUDED)
63875 +#define WSC_INCLUDED
63876 +#endif
63877 +
63878 +
63879 +
63880 +
63881 +
63882 +//#define DBG 1
63883 +
63884 +//#define DBG_DIAGNOSE 1
63885 +
63886 +#if defined(CONFIG_AP_SUPPORT) && defined(CONFIG_STA_SUPPORT)
63887 +#define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd) if(_pAd->OpMode == OPMODE_AP)
63888 +#define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd) if(_pAd->OpMode == OPMODE_STA)
63889 +#else
63890 +#define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd)
63891 +#define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd)
63892 +#endif
63893 +
63894 +#define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
63895 +#define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
63896 +#define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
63897 +
63898 +#ifdef RT2870
63899 +////////////////////////////////////////////////////////////////////////////
63900 +// The TX_BUFFER structure forms the transmitted USB packet to the device
63901 +////////////////////////////////////////////////////////////////////////////
63902 +typedef struct __TX_BUFFER{
63903 + union {
63904 + UCHAR WirelessPacket[TX_BUFFER_NORMSIZE];
63905 + HEADER_802_11 NullFrame;
63906 + PSPOLL_FRAME PsPollPacket;
63907 + RTS_FRAME RTSFrame;
63908 + }field;
63909 + UCHAR Aggregation[4]; //Buffer for save Aggregation size.
63910 +} TX_BUFFER, *PTX_BUFFER;
63911 +
63912 +typedef struct __HTTX_BUFFER{
63913 + union {
63914 + UCHAR WirelessPacket[MAX_TXBULK_SIZE];
63915 + HEADER_802_11 NullFrame;
63916 + PSPOLL_FRAME PsPollPacket;
63917 + RTS_FRAME RTSFrame;
63918 + }field;
63919 + UCHAR Aggregation[4]; //Buffer for save Aggregation size.
63920 +} HTTX_BUFFER, *PHTTX_BUFFER;
63921 +
63922 +
63923 +// used to track driver-generated write irps
63924 +typedef struct _TX_CONTEXT
63925 +{
63926 + PVOID pAd; //Initialized in MiniportInitialize
63927 + PURB pUrb; //Initialized in MiniportInitialize
63928 + PIRP pIrp; //used to cancel pending bulk out.
63929 + //Initialized in MiniportInitialize
63930 + PTX_BUFFER TransferBuffer; //Initialized in MiniportInitialize
63931 + ULONG BulkOutSize;
63932 + UCHAR BulkOutPipeId;
63933 + UCHAR SelfIdx;
63934 + BOOLEAN InUse;
63935 + BOOLEAN bWaitingBulkOut; // at least one packet is in this TxContext, ready for making IRP anytime.
63936 + BOOLEAN bFullForBulkOut; // all tx buffer are full , so waiting for tx bulkout.
63937 + BOOLEAN IRPPending;
63938 + BOOLEAN LastOne;
63939 + BOOLEAN bAggregatible;
63940 + UCHAR Header_802_3[LENGTH_802_3];
63941 + UCHAR Rsv[2];
63942 + ULONG DataOffset;
63943 + UINT TxRate;
63944 + dma_addr_t data_dma; // urb dma on linux
63945 +
63946 +} TX_CONTEXT, *PTX_CONTEXT, **PPTX_CONTEXT;
63947 +
63948 +
63949 +// used to track driver-generated write irps
63950 +typedef struct _HT_TX_CONTEXT
63951 +{
63952 + PVOID pAd; //Initialized in MiniportInitialize
63953 + PURB pUrb; //Initialized in MiniportInitialize
63954 + PIRP pIrp; //used to cancel pending bulk out.
63955 + //Initialized in MiniportInitialize
63956 + PHTTX_BUFFER TransferBuffer; //Initialized in MiniportInitialize
63957 + ULONG BulkOutSize; // Indicate the total bulk-out size in bytes in one bulk-transmission
63958 + UCHAR BulkOutPipeId;
63959 + BOOLEAN IRPPending;
63960 + BOOLEAN LastOne;
63961 + BOOLEAN bCurWriting;
63962 + BOOLEAN bRingEmpty;
63963 + BOOLEAN bCopySavePad;
63964 + UCHAR SavedPad[8];
63965 + UCHAR Header_802_3[LENGTH_802_3];
63966 + ULONG CurWritePosition; // Indicate the buffer offset which packet will be inserted start from.
63967 + ULONG CurWriteRealPos; // Indicate the buffer offset which packet now are writing to.
63968 + ULONG NextBulkOutPosition; // Indicate the buffer start offset of a bulk-transmission
63969 + ULONG ENextBulkOutPosition; // Indicate the buffer end offset of a bulk-transmission
63970 + UINT TxRate;
63971 + dma_addr_t data_dma; // urb dma on linux
63972 +} HT_TX_CONTEXT, *PHT_TX_CONTEXT, **PPHT_TX_CONTEXT;
63973 +
63974 +
63975 +//
63976 +// Structure to keep track of receive packets and buffers to indicate
63977 +// receive data to the protocol.
63978 +//
63979 +typedef struct _RX_CONTEXT
63980 +{
63981 + PUCHAR TransferBuffer;
63982 + PVOID pAd;
63983 + PIRP pIrp;//used to cancel pending bulk in.
63984 + PURB pUrb;
63985 + //These 2 Boolean shouldn't both be 1 at the same time.
63986 + ULONG BulkInOffset; // number of packets waiting for reordering .
63987 +// BOOLEAN ReorderInUse; // At least one packet in this buffer are in reordering buffer and wait for receive indication
63988 + BOOLEAN bRxHandling; // Notify this packet is being process now.
63989 + BOOLEAN InUse; // USB Hardware Occupied. Wait for USB HW to put packet.
63990 + BOOLEAN Readable; // Receive Complete back. OK for driver to indicate receiving packet.
63991 + BOOLEAN IRPPending; // TODO: To be removed
63992 + atomic_t IrpLock;
63993 + NDIS_SPIN_LOCK RxContextLock;
63994 + dma_addr_t data_dma; // urb dma on linux
63995 +} RX_CONTEXT, *PRX_CONTEXT;
63996 +#endif // RT2870 //
63997 +
63998 +
63999 +//
64000 +// NDIS Version definitions
64001 +//
64002 +#ifdef NDIS50_MINIPORT
64003 +#define RTMP_NDIS_MAJOR_VERSION 5
64004 +#define RTMP_NDIS_MINOR_VERSION 0
64005 +#endif
64006 +
64007 +#ifdef NDIS51_MINIPORT
64008 +#define RTMP_NDIS_MAJOR_VERSION 5
64009 +#define RTMP_NDIS_MINOR_VERSION 1
64010 +#endif
64011 +
64012 +extern char NIC_VENDOR_DESC[];
64013 +extern int NIC_VENDOR_DESC_LEN;
64014 +
64015 +extern unsigned char SNAP_AIRONET[];
64016 +extern unsigned char CipherSuiteCiscoCCKM[];
64017 +extern unsigned char CipherSuiteCiscoCCKMLen;
64018 +extern unsigned char CipherSuiteCiscoCCKM24[];
64019 +extern unsigned char CipherSuiteCiscoCCKM24Len;
64020 +extern unsigned char CipherSuiteCCXTkip[];
64021 +extern unsigned char CipherSuiteCCXTkipLen;
64022 +extern unsigned char CISCO_OUI[];
64023 +extern UCHAR BaSizeArray[4];
64024 +
64025 +extern UCHAR BROADCAST_ADDR[MAC_ADDR_LEN];
64026 +extern UCHAR MULTICAST_ADDR[MAC_ADDR_LEN];
64027 +extern UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN];
64028 +extern ULONG BIT32[32];
64029 +extern UCHAR BIT8[8];
64030 +extern char* CipherName[];
64031 +extern char* MCSToMbps[];
64032 +extern UCHAR RxwiMCSToOfdmRate[12];
64033 +extern UCHAR SNAP_802_1H[6];
64034 +extern UCHAR SNAP_BRIDGE_TUNNEL[6];
64035 +extern UCHAR SNAP_AIRONET[8];
64036 +extern UCHAR CKIP_LLC_SNAP[8];
64037 +extern UCHAR EAPOL_LLC_SNAP[8];
64038 +extern UCHAR EAPOL[2];
64039 +extern UCHAR IPX[2];
64040 +extern UCHAR APPLE_TALK[2];
64041 +extern UCHAR RateIdToPlcpSignal[12]; // see IEEE802.11a-1999 p.14
64042 +extern UCHAR OfdmRateToRxwiMCS[];
64043 +extern UCHAR OfdmSignalToRateId[16] ;
64044 +extern UCHAR default_cwmin[4];
64045 +extern UCHAR default_cwmax[4];
64046 +extern UCHAR default_sta_aifsn[4];
64047 +extern UCHAR MapUserPriorityToAccessCategory[8];
64048 +
64049 +extern USHORT RateUpPER[];
64050 +extern USHORT RateDownPER[];
64051 +extern UCHAR Phy11BNextRateDownward[];
64052 +extern UCHAR Phy11BNextRateUpward[];
64053 +extern UCHAR Phy11BGNextRateDownward[];
64054 +extern UCHAR Phy11BGNextRateUpward[];
64055 +extern UCHAR Phy11ANextRateDownward[];
64056 +extern UCHAR Phy11ANextRateUpward[];
64057 +extern CHAR RssiSafeLevelForTxRate[];
64058 +extern UCHAR RateIdToMbps[];
64059 +extern USHORT RateIdTo500Kbps[];
64060 +
64061 +extern UCHAR CipherSuiteWpaNoneTkip[];
64062 +extern UCHAR CipherSuiteWpaNoneTkipLen;
64063 +
64064 +extern UCHAR CipherSuiteWpaNoneAes[];
64065 +extern UCHAR CipherSuiteWpaNoneAesLen;
64066 +
64067 +extern UCHAR SsidIe;
64068 +extern UCHAR SupRateIe;
64069 +extern UCHAR ExtRateIe;
64070 +
64071 +#ifdef DOT11_N_SUPPORT
64072 +extern UCHAR HtCapIe;
64073 +extern UCHAR AddHtInfoIe;
64074 +extern UCHAR NewExtChanIe;
64075 +#ifdef DOT11N_DRAFT3
64076 +extern UCHAR ExtHtCapIe;
64077 +#endif // DOT11N_DRAFT3 //
64078 +#endif // DOT11_N_SUPPORT //
64079 +
64080 +extern UCHAR ErpIe;
64081 +extern UCHAR DsIe;
64082 +extern UCHAR TimIe;
64083 +extern UCHAR WpaIe;
64084 +extern UCHAR Wpa2Ie;
64085 +extern UCHAR IbssIe;
64086 +extern UCHAR Ccx2Ie;
64087 +extern UCHAR WapiIe;
64088 +
64089 +extern UCHAR WPA_OUI[];
64090 +extern UCHAR RSN_OUI[];
64091 +extern UCHAR WAPI_OUI[];
64092 +extern UCHAR WME_INFO_ELEM[];
64093 +extern UCHAR WME_PARM_ELEM[];
64094 +extern UCHAR Ccx2QosInfo[];
64095 +extern UCHAR Ccx2IeInfo[];
64096 +extern UCHAR RALINK_OUI[];
64097 +extern UCHAR PowerConstraintIE[];
64098 +
64099 +
64100 +extern UCHAR RateSwitchTable[];
64101 +extern UCHAR RateSwitchTable11B[];
64102 +extern UCHAR RateSwitchTable11G[];
64103 +extern UCHAR RateSwitchTable11BG[];
64104 +
64105 +#ifdef DOT11_N_SUPPORT
64106 +extern UCHAR RateSwitchTable11BGN1S[];
64107 +extern UCHAR RateSwitchTable11BGN2S[];
64108 +extern UCHAR RateSwitchTable11BGN2SForABand[];
64109 +extern UCHAR RateSwitchTable11N1S[];
64110 +extern UCHAR RateSwitchTable11N2S[];
64111 +extern UCHAR RateSwitchTable11N2SForABand[];
64112 +
64113 +#ifdef CONFIG_STA_SUPPORT
64114 +extern UCHAR PRE_N_HT_OUI[];
64115 +#endif // CONFIG_STA_SUPPORT //
64116 +#endif // DOT11_N_SUPPORT //
64117 +
64118 +#define MAXSEQ (0xFFF)
64119 +
64120 +#ifdef RALINK_ATE
64121 +typedef struct _ATE_INFO {
64122 + UCHAR Mode;
64123 + CHAR TxPower0;
64124 + CHAR TxPower1;
64125 + CHAR TxAntennaSel;
64126 + CHAR RxAntennaSel;
64127 + TXWI_STRUC TxWI; // TXWI
64128 + USHORT QID;
64129 + UCHAR Addr1[MAC_ADDR_LEN];
64130 + UCHAR Addr2[MAC_ADDR_LEN];
64131 + UCHAR Addr3[MAC_ADDR_LEN];
64132 + UCHAR Channel;
64133 + UINT32 TxLength;
64134 + UINT32 TxCount;
64135 + UINT32 TxDoneCount; // Tx DMA Done
64136 + UINT32 RFFreqOffset;
64137 + BOOLEAN bRxFer;
64138 + BOOLEAN bQATxStart; // Have compiled QA in and use it to ATE tx.
64139 + BOOLEAN bQARxStart; // Have compiled QA in and use it to ATE rx.
64140 + UINT32 RxTotalCnt;
64141 + UINT32 RxCntPerSec;
64142 +
64143 + CHAR LastSNR0; // last received SNR
64144 + CHAR LastSNR1; // last received SNR for 2nd antenna
64145 + CHAR LastRssi0; // last received RSSI
64146 + CHAR LastRssi1; // last received RSSI for 2nd antenna
64147 + CHAR LastRssi2; // last received RSSI for 3rd antenna
64148 + CHAR AvgRssi0; // last 8 frames' average RSSI
64149 + CHAR AvgRssi1; // last 8 frames' average RSSI
64150 + CHAR AvgRssi2; // last 8 frames' average RSSI
64151 + SHORT AvgRssi0X8; // sum of last 8 frames' RSSI
64152 + SHORT AvgRssi1X8; // sum of last 8 frames' RSSI
64153 + SHORT AvgRssi2X8; // sum of last 8 frames' RSSI
64154 +
64155 + UINT32 NumOfAvgRssiSample;
64156 +
64157 +#ifdef RALINK_28xx_QA
64158 + // Tx frame
64159 +#ifdef RT2870
64160 + /* not used in RT2860 */
64161 + TXINFO_STRUC TxInfo; // TxInfo
64162 +#endif // RT2870 //
64163 + USHORT HLen; // Header Length
64164 + USHORT PLen; // Pattern Length
64165 + UCHAR Header[32]; // Header buffer
64166 + UCHAR Pattern[32]; // Pattern buffer
64167 + USHORT DLen; // Data Length
64168 + USHORT seq;
64169 + UINT32 CID;
64170 + pid_t AtePid;
64171 + // counters
64172 + UINT32 U2M;
64173 + UINT32 OtherData;
64174 + UINT32 Beacon;
64175 + UINT32 OtherCount;
64176 + UINT32 TxAc0;
64177 + UINT32 TxAc1;
64178 + UINT32 TxAc2;
64179 + UINT32 TxAc3;
64180 + UINT32 TxHCCA;
64181 + UINT32 TxMgmt;
64182 + UINT32 RSSI0;
64183 + UINT32 RSSI1;
64184 + UINT32 RSSI2;
64185 + UINT32 SNR0;
64186 + UINT32 SNR1;
64187 + // control
64188 + //UINT32 Repeat; // Tx Cpu count
64189 + UCHAR TxStatus; // task Tx status // 0 --> task is idle, 1 --> task is running
64190 +#endif // RALINK_28xx_QA //
64191 +} ATE_INFO, *PATE_INFO;
64192 +
64193 +#ifdef RALINK_28xx_QA
64194 +struct ate_racfghdr {
64195 + UINT32 magic_no;
64196 + USHORT command_type;
64197 + USHORT command_id;
64198 + USHORT length;
64199 + USHORT sequence;
64200 + USHORT status;
64201 + UCHAR data[2046];
64202 +} __attribute__((packed));
64203 +#endif // RALINK_28xx_QA //
64204 +#endif // RALINK_ATE //
64205 +
64206 +#ifdef DOT11_N_SUPPORT
64207 +struct reordering_mpdu
64208 +{
64209 + struct reordering_mpdu *next;
64210 + PNDIS_PACKET pPacket; /* coverted to 802.3 frame */
64211 + int Sequence; /* sequence number of MPDU */
64212 + BOOLEAN bAMSDU;
64213 +};
64214 +
64215 +struct reordering_list
64216 +{
64217 + struct reordering_mpdu *next;
64218 + int qlen;
64219 +};
64220 +
64221 +struct reordering_mpdu_pool
64222 +{
64223 + PVOID mem;
64224 + NDIS_SPIN_LOCK lock;
64225 + struct reordering_list freelist;
64226 +};
64227 +#endif // DOT11_N_SUPPORT //
64228 +
64229 +typedef struct _RSSI_SAMPLE {
64230 + CHAR LastRssi0; // last received RSSI
64231 + CHAR LastRssi1; // last received RSSI
64232 + CHAR LastRssi2; // last received RSSI
64233 + CHAR AvgRssi0;
64234 + CHAR AvgRssi1;
64235 + CHAR AvgRssi2;
64236 + SHORT AvgRssi0X8;
64237 + SHORT AvgRssi1X8;
64238 + SHORT AvgRssi2X8;
64239 +} RSSI_SAMPLE;
64240 +
64241 +//
64242 +// Queue structure and macros
64243 +//
64244 +typedef struct _QUEUE_ENTRY {
64245 + struct _QUEUE_ENTRY *Next;
64246 +} QUEUE_ENTRY, *PQUEUE_ENTRY;
64247 +
64248 +// Queue structure
64249 +typedef struct _QUEUE_HEADER {
64250 + PQUEUE_ENTRY Head;
64251 + PQUEUE_ENTRY Tail;
64252 + ULONG Number;
64253 +} QUEUE_HEADER, *PQUEUE_HEADER;
64254 +
64255 +#define InitializeQueueHeader(QueueHeader) \
64256 +{ \
64257 + (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \
64258 + (QueueHeader)->Number = 0; \
64259 +}
64260 +
64261 +#define RemoveHeadQueue(QueueHeader) \
64262 +(QueueHeader)->Head; \
64263 +{ \
64264 + PQUEUE_ENTRY pNext; \
64265 + if ((QueueHeader)->Head != NULL) \
64266 + { \
64267 + pNext = (QueueHeader)->Head->Next; \
64268 + (QueueHeader)->Head = pNext; \
64269 + if (pNext == NULL) \
64270 + (QueueHeader)->Tail = NULL; \
64271 + (QueueHeader)->Number--; \
64272 + } \
64273 +}
64274 +
64275 +#define InsertHeadQueue(QueueHeader, QueueEntry) \
64276 +{ \
64277 + ((PQUEUE_ENTRY)QueueEntry)->Next = (QueueHeader)->Head; \
64278 + (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
64279 + if ((QueueHeader)->Tail == NULL) \
64280 + (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
64281 + (QueueHeader)->Number++; \
64282 +}
64283 +
64284 +#define InsertTailQueue(QueueHeader, QueueEntry) \
64285 +{ \
64286 + ((PQUEUE_ENTRY)QueueEntry)->Next = NULL; \
64287 + if ((QueueHeader)->Tail) \
64288 + (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
64289 + else \
64290 + (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
64291 + (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
64292 + (QueueHeader)->Number++; \
64293 +}
64294 +
64295 +//
64296 +// Macros for flag and ref count operations
64297 +//
64298 +#define RTMP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
64299 +#define RTMP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
64300 +#define RTMP_CLEAR_FLAGS(_M) ((_M)->Flags = 0)
64301 +#define RTMP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
64302 +#define RTMP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
64303 +
64304 +#define OPSTATUS_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
64305 +#define OPSTATUS_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
64306 +#define OPSTATUS_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
64307 +
64308 +#define CLIENT_STATUS_SET_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags |= (_F))
64309 +#define CLIENT_STATUS_CLEAR_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags &= ~(_F))
64310 +#define CLIENT_STATUS_TEST_FLAG(_pEntry,_F) (((_pEntry)->ClientStatusFlags & (_F)) != 0)
64311 +
64312 +#define RX_FILTER_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter |= (_F))
64313 +#define RX_FILTER_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
64314 +#define RX_FILTER_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
64315 +
64316 +#ifdef CONFIG_STA_SUPPORT
64317 +#define STA_NO_SECURITY_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
64318 +#define STA_WEP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
64319 +#define STA_TKIP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
64320 +#define STA_AES_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
64321 +
64322 +#define STA_TGN_WIFI_ON(_p) (_p->StaCfg.bTGnWifiTest == TRUE)
64323 +#endif // CONFIG_STA_SUPPORT //
64324 +
64325 +#define CKIP_KP_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
64326 +#define CKIP_CMIC_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
64327 +
64328 +
64329 +#define INC_RING_INDEX(_idx, _RingSize) \
64330 +{ \
64331 + (_idx) = (_idx+1) % (_RingSize); \
64332 +}
64333 +
64334 +// We will have a cost down version which mac version is 0x3090xxxx
64335 +#define IS_RT3090(_pAd) ((((_pAd)->MACVersion & 0xffff0000) == 0x30710000) || (((_pAd)->MACVersion & 0xffff0000) == 0x30900000))
64336 +
64337 +#define IS_RT3070(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30700000)
64338 +#define IS_RT3071(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30710000)
64339 +#define IS_RT2070(_pAd) (((_pAd)->RfIcType == RFIC_2020) || ((_pAd)->EFuseTag == 0x27))
64340 +
64341 +#define IS_RT30xx(_pAd) (((_pAd)->MACVersion & 0xfff00000) == 0x30700000)
64342 +
64343 +#define RING_PACKET_INIT(_TxRing, _idx) \
64344 +{ \
64345 + _TxRing->Cell[_idx].pNdisPacket = NULL; \
64346 + _TxRing->Cell[_idx].pNextNdisPacket = NULL; \
64347 +}
64348 +
64349 +#define TXDT_INIT(_TxD) \
64350 +{ \
64351 + NdisZeroMemory(_TxD, TXD_SIZE); \
64352 + _TxD->DMADONE = 1; \
64353 +}
64354 +
64355 +//Set last data segment
64356 +#define RING_SET_LASTDS(_TxD, _IsSD0) \
64357 +{ \
64358 + if (_IsSD0) {_TxD->LastSec0 = 1;} \
64359 + else {_TxD->LastSec1 = 1;} \
64360 +}
64361 +
64362 +// Increase TxTsc value for next transmission
64363 +// TODO:
64364 +// When i==6, means TSC has done one full cycle, do re-keying stuff follow specs
64365 +// Should send a special event microsoft defined to request re-key
64366 +#define INC_TX_TSC(_tsc) \
64367 +{ \
64368 + int i=0; \
64369 + while (++_tsc[i] == 0x0) \
64370 + { \
64371 + i++; \
64372 + if (i == 6) \
64373 + break; \
64374 + } \
64375 +}
64376 +
64377 +#ifdef DOT11_N_SUPPORT
64378 +// StaActive.SupportedHtPhy.MCSSet is copied from AP beacon. Don't need to update here.
64379 +#define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
64380 +{ \
64381 + _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth; \
64382 + _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs; \
64383 + _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF; \
64384 + _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20; \
64385 + _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40; \
64386 + _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC; \
64387 + _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC; \
64388 + _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset; \
64389 + _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth; \
64390 + _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode; \
64391 + _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent; \
64392 + NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(UCHAR) * 16);\
64393 +}
64394 +
64395 +#define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability) \
64396 +{ \
64397 + _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (UCHAR)(_pHtCapability->HtCapInfo.AMsduSize); \
64398 + _pAd->MacTab.Content[BSSID_WCID].MmpsMode= (UCHAR)(_pHtCapability->HtCapInfo.MimoPs); \
64399 + _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (UCHAR)(_pHtCapability->HtCapParm.MaxRAmpduFactor); \
64400 +}
64401 +#endif // DOT11_N_SUPPORT //
64402 +
64403 +//
64404 +// MACRO for 32-bit PCI register read / write
64405 +//
64406 +// Usage : RTMP_IO_READ32(
64407 +// PRTMP_ADAPTER pAd,
64408 +// ULONG Register_Offset,
64409 +// PULONG pValue)
64410 +//
64411 +// RTMP_IO_WRITE32(
64412 +// PRTMP_ADAPTER pAd,
64413 +// ULONG Register_Offset,
64414 +// ULONG Value)
64415 +//
64416 +
64417 +//
64418 +// BBP & RF are using indirect access. Before write any value into it.
64419 +// We have to make sure there is no outstanding command pending via checking busy bit.
64420 +//
64421 +#define MAX_BUSY_COUNT 100 // Number of retry before failing access BBP & RF indirect register
64422 +//
64423 +
64424 +#ifdef RT2870
64425 +#define RTMP_RF_IO_WRITE32(_A, _V) RTUSBWriteRFRegister(_A, _V)
64426 +#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
64427 +#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
64428 +
64429 +#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
64430 +#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
64431 +#endif // RT2870 //
64432 +
64433 +#ifdef RT30xx
64434 +#define RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV) RT30xxReadRFRegister(_A, _I, _pV)
64435 +#define RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V) RT30xxWriteRFRegister(_A, _I, _V)
64436 +#endif // RT30xx //
64437 +
64438 +#define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \
64439 + switch (ch) \
64440 + { \
64441 + case 1: khz = 2412000; break; \
64442 + case 2: khz = 2417000; break; \
64443 + case 3: khz = 2422000; break; \
64444 + case 4: khz = 2427000; break; \
64445 + case 5: khz = 2432000; break; \
64446 + case 6: khz = 2437000; break; \
64447 + case 7: khz = 2442000; break; \
64448 + case 8: khz = 2447000; break; \
64449 + case 9: khz = 2452000; break; \
64450 + case 10: khz = 2457000; break; \
64451 + case 11: khz = 2462000; break; \
64452 + case 12: khz = 2467000; break; \
64453 + case 13: khz = 2472000; break; \
64454 + case 14: khz = 2484000; break; \
64455 + case 36: /* UNII */ khz = 5180000; break; \
64456 + case 40: /* UNII */ khz = 5200000; break; \
64457 + case 44: /* UNII */ khz = 5220000; break; \
64458 + case 48: /* UNII */ khz = 5240000; break; \
64459 + case 52: /* UNII */ khz = 5260000; break; \
64460 + case 56: /* UNII */ khz = 5280000; break; \
64461 + case 60: /* UNII */ khz = 5300000; break; \
64462 + case 64: /* UNII */ khz = 5320000; break; \
64463 + case 149: /* UNII */ khz = 5745000; break; \
64464 + case 153: /* UNII */ khz = 5765000; break; \
64465 + case 157: /* UNII */ khz = 5785000; break; \
64466 + case 161: /* UNII */ khz = 5805000; break; \
64467 + case 165: /* UNII */ khz = 5825000; break; \
64468 + case 100: /* HiperLAN2 */ khz = 5500000; break; \
64469 + case 104: /* HiperLAN2 */ khz = 5520000; break; \
64470 + case 108: /* HiperLAN2 */ khz = 5540000; break; \
64471 + case 112: /* HiperLAN2 */ khz = 5560000; break; \
64472 + case 116: /* HiperLAN2 */ khz = 5580000; break; \
64473 + case 120: /* HiperLAN2 */ khz = 5600000; break; \
64474 + case 124: /* HiperLAN2 */ khz = 5620000; break; \
64475 + case 128: /* HiperLAN2 */ khz = 5640000; break; \
64476 + case 132: /* HiperLAN2 */ khz = 5660000; break; \
64477 + case 136: /* HiperLAN2 */ khz = 5680000; break; \
64478 + case 140: /* HiperLAN2 */ khz = 5700000; break; \
64479 + case 34: /* Japan MMAC */ khz = 5170000; break; \
64480 + case 38: /* Japan MMAC */ khz = 5190000; break; \
64481 + case 42: /* Japan MMAC */ khz = 5210000; break; \
64482 + case 46: /* Japan MMAC */ khz = 5230000; break; \
64483 + case 184: /* Japan */ khz = 4920000; break; \
64484 + case 188: /* Japan */ khz = 4940000; break; \
64485 + case 192: /* Japan */ khz = 4960000; break; \
64486 + case 196: /* Japan */ khz = 4980000; break; \
64487 + case 208: /* Japan, means J08 */ khz = 5040000; break; \
64488 + case 212: /* Japan, means J12 */ khz = 5060000; break; \
64489 + case 216: /* Japan, means J16 */ khz = 5080000; break; \
64490 + default: khz = 2412000; break; \
64491 + } \
64492 + }
64493 +
64494 +#define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \
64495 + switch (khz) \
64496 + { \
64497 + case 2412000: ch = 1; break; \
64498 + case 2417000: ch = 2; break; \
64499 + case 2422000: ch = 3; break; \
64500 + case 2427000: ch = 4; break; \
64501 + case 2432000: ch = 5; break; \
64502 + case 2437000: ch = 6; break; \
64503 + case 2442000: ch = 7; break; \
64504 + case 2447000: ch = 8; break; \
64505 + case 2452000: ch = 9; break; \
64506 + case 2457000: ch = 10; break; \
64507 + case 2462000: ch = 11; break; \
64508 + case 2467000: ch = 12; break; \
64509 + case 2472000: ch = 13; break; \
64510 + case 2484000: ch = 14; break; \
64511 + case 5180000: ch = 36; /* UNII */ break; \
64512 + case 5200000: ch = 40; /* UNII */ break; \
64513 + case 5220000: ch = 44; /* UNII */ break; \
64514 + case 5240000: ch = 48; /* UNII */ break; \
64515 + case 5260000: ch = 52; /* UNII */ break; \
64516 + case 5280000: ch = 56; /* UNII */ break; \
64517 + case 5300000: ch = 60; /* UNII */ break; \
64518 + case 5320000: ch = 64; /* UNII */ break; \
64519 + case 5745000: ch = 149; /* UNII */ break; \
64520 + case 5765000: ch = 153; /* UNII */ break; \
64521 + case 5785000: ch = 157; /* UNII */ break; \
64522 + case 5805000: ch = 161; /* UNII */ break; \
64523 + case 5825000: ch = 165; /* UNII */ break; \
64524 + case 5500000: ch = 100; /* HiperLAN2 */ break; \
64525 + case 5520000: ch = 104; /* HiperLAN2 */ break; \
64526 + case 5540000: ch = 108; /* HiperLAN2 */ break; \
64527 + case 5560000: ch = 112; /* HiperLAN2 */ break; \
64528 + case 5580000: ch = 116; /* HiperLAN2 */ break; \
64529 + case 5600000: ch = 120; /* HiperLAN2 */ break; \
64530 + case 5620000: ch = 124; /* HiperLAN2 */ break; \
64531 + case 5640000: ch = 128; /* HiperLAN2 */ break; \
64532 + case 5660000: ch = 132; /* HiperLAN2 */ break; \
64533 + case 5680000: ch = 136; /* HiperLAN2 */ break; \
64534 + case 5700000: ch = 140; /* HiperLAN2 */ break; \
64535 + case 5170000: ch = 34; /* Japan MMAC */ break; \
64536 + case 5190000: ch = 38; /* Japan MMAC */ break; \
64537 + case 5210000: ch = 42; /* Japan MMAC */ break; \
64538 + case 5230000: ch = 46; /* Japan MMAC */ break; \
64539 + case 4920000: ch = 184; /* Japan */ break; \
64540 + case 4940000: ch = 188; /* Japan */ break; \
64541 + case 4960000: ch = 192; /* Japan */ break; \
64542 + case 4980000: ch = 196; /* Japan */ break; \
64543 + case 5040000: ch = 208; /* Japan, means J08 */ break; \
64544 + case 5060000: ch = 212; /* Japan, means J12 */ break; \
64545 + case 5080000: ch = 216; /* Japan, means J16 */ break; \
64546 + default: ch = 1; break; \
64547 + } \
64548 + }
64549 +
64550 +//
64551 +// Common fragment list structure - Identical to the scatter gather frag list structure
64552 +//
64553 +//#define RTMP_SCATTER_GATHER_ELEMENT SCATTER_GATHER_ELEMENT
64554 +//#define PRTMP_SCATTER_GATHER_ELEMENT PSCATTER_GATHER_ELEMENT
64555 +#define NIC_MAX_PHYS_BUF_COUNT 8
64556 +
64557 +typedef struct _RTMP_SCATTER_GATHER_ELEMENT {
64558 + PVOID Address;
64559 + ULONG Length;
64560 + PULONG Reserved;
64561 +} RTMP_SCATTER_GATHER_ELEMENT, *PRTMP_SCATTER_GATHER_ELEMENT;
64562 +
64563 +
64564 +typedef struct _RTMP_SCATTER_GATHER_LIST {
64565 + ULONG NumberOfElements;
64566 + PULONG Reserved;
64567 + RTMP_SCATTER_GATHER_ELEMENT Elements[NIC_MAX_PHYS_BUF_COUNT];
64568 +} RTMP_SCATTER_GATHER_LIST, *PRTMP_SCATTER_GATHER_LIST;
64569 +
64570 +//
64571 +// Some utility macros
64572 +//
64573 +#ifndef min
64574 +#define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
64575 +#endif
64576 +
64577 +#ifndef max
64578 +#define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
64579 +#endif
64580 +
64581 +#define GET_LNA_GAIN(_pAd) ((_pAd->LatchRfRegs.Channel <= 14) ? (_pAd->BLNAGain) : ((_pAd->LatchRfRegs.Channel <= 64) ? (_pAd->ALNAGain0) : ((_pAd->LatchRfRegs.Channel <= 128) ? (_pAd->ALNAGain1) : (_pAd->ALNAGain2))))
64582 +
64583 +#define INC_COUNTER64(Val) (Val.QuadPart++)
64584 +
64585 +#define INFRA_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
64586 +#define ADHOC_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
64587 +#define MONITOR_ON(_p) (((_p)->StaCfg.BssType) == BSS_MONITOR)
64588 +#define IDLE_ON(_p) (!INFRA_ON(_p) && !ADHOC_ON(_p))
64589 +
64590 +// Check LEAP & CCKM flags
64591 +#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
64592 +#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
64593 +
64594 +// if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required
64595 +#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \
64596 +{ \
64597 + if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) \
64598 + { \
64599 + _pExtraLlcSnapEncap = SNAP_802_1H; \
64600 + if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || \
64601 + NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) \
64602 + { \
64603 + _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
64604 + } \
64605 + } \
64606 + else \
64607 + { \
64608 + _pExtraLlcSnapEncap = NULL; \
64609 + } \
64610 +}
64611 +
64612 +// New Define for new Tx Path.
64613 +#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap) \
64614 +{ \
64615 + if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) \
64616 + { \
64617 + _pExtraLlcSnapEncap = SNAP_802_1H; \
64618 + if (NdisEqualMemory(IPX, _pBufVA, 2) || \
64619 + NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) \
64620 + { \
64621 + _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
64622 + } \
64623 + } \
64624 + else \
64625 + { \
64626 + _pExtraLlcSnapEncap = NULL; \
64627 + } \
64628 +}
64629 +
64630 +
64631 +#define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType) \
64632 +{ \
64633 + NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN); \
64634 + NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN); \
64635 + NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
64636 +}
64637 +
64638 +// if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way.
64639 +// else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field
64640 +// else remove the LLC/SNAP field from the result Ethernet frame
64641 +// Patch for WHQL only, which did not turn on Netbios but use IPX within its payload
64642 +// Note:
64643 +// _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO
64644 +// _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed
64645 +#define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP) \
64646 +{ \
64647 + char LLC_Len[2]; \
64648 + \
64649 + _pRemovedLLCSNAP = NULL; \
64650 + if (NdisEqualMemory(SNAP_802_1H, _pData, 6) || \
64651 + NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) \
64652 + { \
64653 + PUCHAR pProto = _pData + 6; \
64654 + \
64655 + if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) && \
64656 + NdisEqualMemory(SNAP_802_1H, _pData, 6)) \
64657 + { \
64658 + LLC_Len[0] = (UCHAR)(_DataSize / 256); \
64659 + LLC_Len[1] = (UCHAR)(_DataSize % 256); \
64660 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
64661 + } \
64662 + else \
64663 + { \
64664 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto); \
64665 + _pRemovedLLCSNAP = _pData; \
64666 + _DataSize -= LENGTH_802_1_H; \
64667 + _pData += LENGTH_802_1_H; \
64668 + } \
64669 + } \
64670 + else \
64671 + { \
64672 + LLC_Len[0] = (UCHAR)(_DataSize / 256); \
64673 + LLC_Len[1] = (UCHAR)(_DataSize % 256); \
64674 + MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
64675 + } \
64676 +}
64677 +
64678 +#define SWITCH_AB( _pAA, _pBB) \
64679 +{ \
64680 + PVOID pCC; \
64681 + pCC = _pBB; \
64682 + _pBB = _pAA; \
64683 + _pAA = pCC; \
64684 +}
64685 +
64686 +// Enqueue this frame to MLME engine
64687 +// We need to enqueue the whole frame because MLME need to pass data type
64688 +// information from 802.11 header
64689 +#ifdef RT2870
64690 +#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \
64691 +{ \
64692 + UINT32 High32TSF=0, Low32TSF=0; \
64693 + MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (UCHAR)_Rssi0, (UCHAR)_Rssi1,(UCHAR)_Rssi2,_FrameSize, _pFrame, (UCHAR)_PlcpSignal); \
64694 +}
64695 +#endif // RT2870 //
64696 +
64697 +#ifdef RT30xx
64698 +//Need to collect each ant's rssi concurrently
64699 +//rssi1 is report to pair2 Ant and rss2 is reprot to pair1 Ant when 4 Ant
64700 +#define COLLECT_RX_ANTENNA_AVERAGE_RSSI(_pAd, _rssi1, _rssi2) \
64701 +{ \
64702 + SHORT AvgRssi; \
64703 + UCHAR UsedAnt; \
64704 + if (_pAd->RxAnt.EvaluatePeriod == 0) \
64705 + { \
64706 + UsedAnt = _pAd->RxAnt.Pair1PrimaryRxAnt; \
64707 + AvgRssi = _pAd->RxAnt.Pair1AvgRssi[UsedAnt]; \
64708 + if (AvgRssi < 0) \
64709 + AvgRssi = AvgRssi - (AvgRssi >> 3) + _rssi1; \
64710 + else \
64711 + AvgRssi = _rssi1 << 3; \
64712 + _pAd->RxAnt.Pair1AvgRssi[UsedAnt] = AvgRssi; \
64713 + } \
64714 + else \
64715 + { \
64716 + UsedAnt = _pAd->RxAnt.Pair1SecondaryRxAnt; \
64717 + AvgRssi = _pAd->RxAnt.Pair1AvgRssi[UsedAnt]; \
64718 + if ((AvgRssi < 0) && (_pAd->RxAnt.FirstPktArrivedWhenEvaluate)) \
64719 + AvgRssi = AvgRssi - (AvgRssi >> 3) + _rssi1; \
64720 + else \
64721 + { \
64722 + _pAd->RxAnt.FirstPktArrivedWhenEvaluate = TRUE; \
64723 + AvgRssi = _rssi1 << 3; \
64724 + } \
64725 + _pAd->RxAnt.Pair1AvgRssi[UsedAnt] = AvgRssi; \
64726 + _pAd->RxAnt.RcvPktNumWhenEvaluate++; \
64727 + } \
64728 +}
64729 +#endif // RT30xx //
64730 +
64731 +
64732 +#define NDIS_QUERY_BUFFER(_NdisBuf, _ppVA, _pBufLen) \
64733 + NdisQueryBuffer(_NdisBuf, _ppVA, _pBufLen)
64734 +
64735 +#define MAC_ADDR_EQUAL(pAddr1,pAddr2) RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
64736 +#define SSID_EQUAL(ssid1, len1, ssid2, len2) ((len1==len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
64737 +
64738 +//
64739 +// Check if it is Japan W53(ch52,56,60,64) channel.
64740 +//
64741 +#define JapanChannelCheck(channel) ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
64742 +
64743 +#ifdef CONFIG_STA_SUPPORT
64744 +#define STA_PORT_SECURED(_pAd) \
64745 +{ \
64746 + _pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
64747 + NdisAcquireSpinLock(&_pAd->MacTabLock); \
64748 + _pAd->MacTab.Content[BSSID_WCID].PortSecured = _pAd->StaCfg.PortSecured; \
64749 + NdisReleaseSpinLock(&_pAd->MacTabLock); \
64750 +}
64751 +#endif // CONFIG_STA_SUPPORT //
64752 +
64753 +
64754 +//
64755 +// Register set pair for initialzation register set definition
64756 +//
64757 +typedef struct _RTMP_REG_PAIR
64758 +{
64759 + ULONG Register;
64760 + ULONG Value;
64761 +} RTMP_REG_PAIR, *PRTMP_REG_PAIR;
64762 +
64763 +typedef struct _REG_PAIR
64764 +{
64765 + UCHAR Register;
64766 + UCHAR Value;
64767 +} REG_PAIR, *PREG_PAIR;
64768 +
64769 +//
64770 +// Register set pair for initialzation register set definition
64771 +//
64772 +typedef struct _RTMP_RF_REGS
64773 +{
64774 + UCHAR Channel;
64775 + ULONG R1;
64776 + ULONG R2;
64777 + ULONG R3;
64778 + ULONG R4;
64779 +} RTMP_RF_REGS, *PRTMP_RF_REGS;
64780 +
64781 +typedef struct _FREQUENCY_ITEM {
64782 + UCHAR Channel;
64783 + UCHAR N;
64784 + UCHAR R;
64785 + UCHAR K;
64786 +} FREQUENCY_ITEM, *PFREQUENCY_ITEM;
64787 +
64788 +//
64789 +// Data buffer for DMA operation, the buffer must be contiguous physical memory
64790 +// Both DMA to / from CPU use the same structure.
64791 +//
64792 +typedef struct _RTMP_DMABUF
64793 +{
64794 + ULONG AllocSize;
64795 + PVOID AllocVa; // TxBuf virtual address
64796 + NDIS_PHYSICAL_ADDRESS AllocPa; // TxBuf physical address
64797 +} RTMP_DMABUF, *PRTMP_DMABUF;
64798 +
64799 +
64800 +typedef union _HEADER_802_11_SEQ{
64801 +#ifdef RT_BIG_ENDIAN
64802 + struct {
64803 + USHORT Sequence:12;
64804 + USHORT Frag:4;
64805 + } field;
64806 +#else
64807 + struct {
64808 + USHORT Frag:4;
64809 + USHORT Sequence:12;
64810 + } field;
64811 +#endif
64812 + USHORT value;
64813 +} HEADER_802_11_SEQ, *PHEADER_802_11_SEQ;
64814 +
64815 +//
64816 +// Data buffer for DMA operation, the buffer must be contiguous physical memory
64817 +// Both DMA to / from CPU use the same structure.
64818 +//
64819 +typedef struct _RTMP_REORDERBUF
64820 +{
64821 + BOOLEAN IsFull;
64822 + PVOID AllocVa; // TxBuf virtual address
64823 + UCHAR Header802_3[14];
64824 + HEADER_802_11_SEQ Sequence; //support compressed bitmap BA, so no consider fragment in BA
64825 + UCHAR DataOffset;
64826 + USHORT Datasize;
64827 + ULONG AllocSize;
64828 +#ifdef RT2870
64829 + PUCHAR AllocPa;
64830 +#endif // RT2870 //
64831 +} RTMP_REORDERBUF, *PRTMP_REORDERBUF;
64832 +
64833 +//
64834 +// Control block (Descriptor) for all ring descriptor DMA operation, buffer must be
64835 +// contiguous physical memory. NDIS_PACKET stored the binding Rx packet descriptor
64836 +// which won't be released, driver has to wait until upper layer return the packet
64837 +// before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair
64838 +// to describe the packet buffer. For Tx, NDIS_PACKET stored the tx packet descriptor
64839 +// which driver should ACK upper layer when the tx is physically done or failed.
64840 +//
64841 +typedef struct _RTMP_DMACB
64842 +{
64843 + ULONG AllocSize; // Control block size
64844 + PVOID AllocVa; // Control block virtual address
64845 + NDIS_PHYSICAL_ADDRESS AllocPa; // Control block physical address
64846 + PNDIS_PACKET pNdisPacket;
64847 + PNDIS_PACKET pNextNdisPacket;
64848 +
64849 + RTMP_DMABUF DmaBuf; // Associated DMA buffer structure
64850 +} RTMP_DMACB, *PRTMP_DMACB;
64851 +
64852 +typedef struct _RTMP_TX_BUF
64853 +{
64854 + PQUEUE_ENTRY Next;
64855 + UCHAR Index;
64856 + ULONG AllocSize; // Control block size
64857 + PVOID AllocVa; // Control block virtual address
64858 + NDIS_PHYSICAL_ADDRESS AllocPa; // Control block physical address
64859 +} RTMP_TXBUF, *PRTMP_TXBUF;
64860 +
64861 +typedef struct _RTMP_RX_BUF
64862 +{
64863 + BOOLEAN InUse;
64864 + ULONG ByBaRecIndex;
64865 + RTMP_REORDERBUF MAP_RXBuf[MAX_RX_REORDERBUF];
64866 +} RTMP_RXBUF, *PRTMP_RXBUF;
64867 +typedef struct _RTMP_TX_RING
64868 +{
64869 + RTMP_DMACB Cell[TX_RING_SIZE];
64870 + UINT32 TxCpuIdx;
64871 + UINT32 TxDmaIdx;
64872 + UINT32 TxSwFreeIdx; // software next free tx index
64873 +} RTMP_TX_RING, *PRTMP_TX_RING;
64874 +
64875 +typedef struct _RTMP_RX_RING
64876 +{
64877 + RTMP_DMACB Cell[RX_RING_SIZE];
64878 + UINT32 RxCpuIdx;
64879 + UINT32 RxDmaIdx;
64880 + INT32 RxSwReadIdx; // software next read index
64881 +} RTMP_RX_RING, *PRTMP_RX_RING;
64882 +
64883 +typedef struct _RTMP_MGMT_RING
64884 +{
64885 + RTMP_DMACB Cell[MGMT_RING_SIZE];
64886 + UINT32 TxCpuIdx;
64887 + UINT32 TxDmaIdx;
64888 + UINT32 TxSwFreeIdx; // software next free tx index
64889 +} RTMP_MGMT_RING, *PRTMP_MGMT_RING;
64890 +
64891 +//
64892 +// Statistic counter structure
64893 +//
64894 +typedef struct _COUNTER_802_3
64895 +{
64896 + // General Stats
64897 + ULONG GoodTransmits;
64898 + ULONG GoodReceives;
64899 + ULONG TxErrors;
64900 + ULONG RxErrors;
64901 + ULONG RxNoBuffer;
64902 +
64903 + // Ethernet Stats
64904 + ULONG RcvAlignmentErrors;
64905 + ULONG OneCollision;
64906 + ULONG MoreCollisions;
64907 +
64908 +} COUNTER_802_3, *PCOUNTER_802_3;
64909 +
64910 +typedef struct _COUNTER_802_11 {
64911 + ULONG Length;
64912 + LARGE_INTEGER LastTransmittedFragmentCount;
64913 + LARGE_INTEGER TransmittedFragmentCount;
64914 + LARGE_INTEGER MulticastTransmittedFrameCount;
64915 + LARGE_INTEGER FailedCount;
64916 + LARGE_INTEGER RetryCount;
64917 + LARGE_INTEGER MultipleRetryCount;
64918 + LARGE_INTEGER RTSSuccessCount;
64919 + LARGE_INTEGER RTSFailureCount;
64920 + LARGE_INTEGER ACKFailureCount;
64921 + LARGE_INTEGER FrameDuplicateCount;
64922 + LARGE_INTEGER ReceivedFragmentCount;
64923 + LARGE_INTEGER MulticastReceivedFrameCount;
64924 + LARGE_INTEGER FCSErrorCount;
64925 +} COUNTER_802_11, *PCOUNTER_802_11;
64926 +
64927 +typedef struct _COUNTER_RALINK {
64928 + ULONG TransmittedByteCount; // both successful and failure, used to calculate TX throughput
64929 + ULONG ReceivedByteCount; // both CRC okay and CRC error, used to calculate RX throughput
64930 + ULONG BeenDisassociatedCount;
64931 + ULONG BadCQIAutoRecoveryCount;
64932 + ULONG PoorCQIRoamingCount;
64933 + ULONG MgmtRingFullCount;
64934 + ULONG RxCountSinceLastNULL;
64935 + ULONG RxCount;
64936 + ULONG RxRingErrCount;
64937 + ULONG KickTxCount;
64938 + ULONG TxRingErrCount;
64939 + LARGE_INTEGER RealFcsErrCount;
64940 + ULONG PendingNdisPacketCount;
64941 +
64942 + ULONG OneSecOsTxCount[NUM_OF_TX_RING];
64943 + ULONG OneSecDmaDoneCount[NUM_OF_TX_RING];
64944 + UINT32 OneSecTxDoneCount;
64945 + ULONG OneSecRxCount;
64946 + UINT32 OneSecTxAggregationCount;
64947 + UINT32 OneSecRxAggregationCount;
64948 +
64949 + UINT32 OneSecFrameDuplicateCount;
64950 +
64951 +#ifdef RT2870
64952 + ULONG OneSecTransmittedByteCount; // both successful and failure, used to calculate TX throughput
64953 +#endif // RT2870 //
64954 +
64955 + UINT32 OneSecTxNoRetryOkCount;
64956 + UINT32 OneSecTxRetryOkCount;
64957 + UINT32 OneSecTxFailCount;
64958 + UINT32 OneSecFalseCCACnt; // CCA error count, for debug purpose, might move to global counter
64959 + UINT32 OneSecRxOkCnt; // RX without error
64960 + UINT32 OneSecRxOkDataCnt; // unicast-to-me DATA frame count
64961 + UINT32 OneSecRxFcsErrCnt; // CRC error
64962 + UINT32 OneSecBeaconSentCnt;
64963 + UINT32 LastOneSecTotalTxCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
64964 + UINT32 LastOneSecRxOkDataCnt; // OneSecRxOkDataCnt
64965 + ULONG DuplicateRcv;
64966 + ULONG TxAggCount;
64967 + ULONG TxNonAggCount;
64968 + ULONG TxAgg1MPDUCount;
64969 + ULONG TxAgg2MPDUCount;
64970 + ULONG TxAgg3MPDUCount;
64971 + ULONG TxAgg4MPDUCount;
64972 + ULONG TxAgg5MPDUCount;
64973 + ULONG TxAgg6MPDUCount;
64974 + ULONG TxAgg7MPDUCount;
64975 + ULONG TxAgg8MPDUCount;
64976 + ULONG TxAgg9MPDUCount;
64977 + ULONG TxAgg10MPDUCount;
64978 + ULONG TxAgg11MPDUCount;
64979 + ULONG TxAgg12MPDUCount;
64980 + ULONG TxAgg13MPDUCount;
64981 + ULONG TxAgg14MPDUCount;
64982 + ULONG TxAgg15MPDUCount;
64983 + ULONG TxAgg16MPDUCount;
64984 +
64985 + LARGE_INTEGER TransmittedOctetsInAMSDU;
64986 + LARGE_INTEGER TransmittedAMSDUCount;
64987 + LARGE_INTEGER ReceivedOctesInAMSDUCount;
64988 + LARGE_INTEGER ReceivedAMSDUCount;
64989 + LARGE_INTEGER TransmittedAMPDUCount;
64990 + LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
64991 + LARGE_INTEGER TransmittedOctetsInAMPDUCount;
64992 + LARGE_INTEGER MPDUInReceivedAMPDUCount;
64993 +} COUNTER_RALINK, *PCOUNTER_RALINK;
64994 +
64995 +typedef struct _PID_COUNTER {
64996 + ULONG TxAckRequiredCount; // CRC error
64997 + ULONG TxAggreCount;
64998 + ULONG TxSuccessCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
64999 + ULONG LastSuccessRate;
65000 +} PID_COUNTER, *PPID_COUNTER;
65001 +
65002 +typedef struct _COUNTER_DRS {
65003 + // to record the each TX rate's quality. 0 is best, the bigger the worse.
65004 + USHORT TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
65005 + UCHAR PER[MAX_STEP_OF_TX_RATE_SWITCH];
65006 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
65007 + ULONG CurrTxRateStableTime; // # of second in current TX rate
65008 + BOOLEAN fNoisyEnvironment;
65009 + BOOLEAN fLastSecAccordingRSSI;
65010 + UCHAR LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
65011 + UCHAR LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
65012 + ULONG LastTxOkCount;
65013 +} COUNTER_DRS, *PCOUNTER_DRS;
65014 +
65015 +//
65016 +// Arcfour Structure Added by PaulWu
65017 +//
65018 +typedef struct _ARCFOUR
65019 +{
65020 + UINT X;
65021 + UINT Y;
65022 + UCHAR STATE[256];
65023 +} ARCFOURCONTEXT, *PARCFOURCONTEXT;
65024 +
65025 +// MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI too. just copy to TXWI.
65026 +typedef struct _RECEIVE_SETTING {
65027 +#ifdef RT_BIG_ENDIAN
65028 + USHORT MIMO:1;
65029 + USHORT OFDM:1;
65030 + USHORT rsv:3;
65031 + USHORT STBC:2; //SPACE
65032 + USHORT ShortGI:1;
65033 + USHORT Mode:2; //channel bandwidth 20MHz or 40 MHz
65034 + USHORT NumOfRX:2; // MIMO. WE HAVE 3R
65035 +#else
65036 + USHORT NumOfRX:2; // MIMO. WE HAVE 3R
65037 + USHORT Mode:2; //channel bandwidth 20MHz or 40 MHz
65038 + USHORT ShortGI:1;
65039 + USHORT STBC:2; //SPACE
65040 + USHORT rsv:3;
65041 + USHORT OFDM:1;
65042 + USHORT MIMO:1;
65043 +#endif
65044 + } RECEIVE_SETTING, *PRECEIVE_SETTING;
65045 +
65046 +// Shared key data structure
65047 +typedef struct _WEP_KEY {
65048 + UCHAR KeyLen; // Key length for each key, 0: entry is invalid
65049 + UCHAR Key[MAX_LEN_OF_KEY]; // right now we implement 4 keys, 128 bits max
65050 +} WEP_KEY, *PWEP_KEY;
65051 +
65052 +typedef struct _CIPHER_KEY {
65053 + UCHAR Key[16]; // right now we implement 4 keys, 128 bits max
65054 + UCHAR RxMic[8]; // make alignment
65055 + UCHAR TxMic[8];
65056 + UCHAR TxTsc[6]; // 48bit TSC value
65057 + UCHAR RxTsc[6]; // 48bit TSC value
65058 + UCHAR CipherAlg; // 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128
65059 + UCHAR KeyLen;
65060 +#ifdef CONFIG_STA_SUPPORT
65061 + UCHAR BssId[6];
65062 +#endif // CONFIG_STA_SUPPORT //
65063 + // Key length for each key, 0: entry is invalid
65064 + UCHAR Type; // Indicate Pairwise/Group when reporting MIC error
65065 +} CIPHER_KEY, *PCIPHER_KEY;
65066 +
65067 +typedef struct _BBP_TUNING_STRUCT {
65068 + BOOLEAN Enable;
65069 + UCHAR FalseCcaCountUpperBound; // 100 per sec
65070 + UCHAR FalseCcaCountLowerBound; // 10 per sec
65071 + UCHAR R17LowerBound; // specified in E2PROM
65072 + UCHAR R17UpperBound; // 0x68 according to David Tung
65073 + UCHAR CurrentR17Value;
65074 +} BBP_TUNING, *PBBP_TUNING;
65075 +
65076 +typedef struct _SOFT_RX_ANT_DIVERSITY_STRUCT {
65077 + UCHAR EvaluatePeriod; // 0:not evalute status, 1: evaluate status, 2: switching status
65078 + UCHAR EvaluateStableCnt;
65079 + UCHAR Pair1PrimaryRxAnt; // 0:Ant-E1, 1:Ant-E2
65080 + UCHAR Pair1SecondaryRxAnt; // 0:Ant-E1, 1:Ant-E2
65081 + UCHAR Pair2PrimaryRxAnt; // 0:Ant-E3, 1:Ant-E4
65082 + UCHAR Pair2SecondaryRxAnt; // 0:Ant-E3, 1:Ant-E4
65083 + SHORT Pair1AvgRssi[2]; // AvgRssi[0]:E1, AvgRssi[1]:E2
65084 + SHORT Pair2AvgRssi[2]; // AvgRssi[0]:E3, AvgRssi[1]:E4
65085 + SHORT Pair1LastAvgRssi; //
65086 + SHORT Pair2LastAvgRssi; //
65087 + ULONG RcvPktNumWhenEvaluate;
65088 + BOOLEAN FirstPktArrivedWhenEvaluate;
65089 + RALINK_TIMER_STRUCT RxAntDiversityTimer;
65090 +} SOFT_RX_ANT_DIVERSITY, *PSOFT_RX_ANT_DIVERSITY;
65091 +
65092 +typedef struct _LEAP_AUTH_INFO {
65093 + BOOLEAN Enabled; //Ture: Enable LEAP Authentication
65094 + BOOLEAN CCKM; //Ture: Use Fast Reauthentication with CCKM
65095 + UCHAR Reserve[2];
65096 + UCHAR UserName[256]; //LEAP, User name
65097 + ULONG UserNameLen;
65098 + UCHAR Password[256]; //LEAP, User Password
65099 + ULONG PasswordLen;
65100 +} LEAP_AUTH_INFO, *PLEAP_AUTH_INFO;
65101 +
65102 +typedef struct {
65103 + UCHAR Addr[MAC_ADDR_LEN];
65104 + UCHAR ErrorCode[2]; //00 01-Invalid authentication type
65105 + //00 02-Authentication timeout
65106 + //00 03-Challenge from AP failed
65107 + //00 04-Challenge to AP failed
65108 + BOOLEAN Reported;
65109 +} ROGUEAP_ENTRY, *PROGUEAP_ENTRY;
65110 +
65111 +typedef struct {
65112 + UCHAR RogueApNr;
65113 + ROGUEAP_ENTRY RogueApEntry[MAX_LEN_OF_BSS_TABLE];
65114 +} ROGUEAP_TABLE, *PROGUEAP_TABLE;
65115 +
65116 +typedef struct {
65117 + BOOLEAN Enable;
65118 + UCHAR Delta;
65119 + BOOLEAN PlusSign;
65120 +} CCK_TX_POWER_CALIBRATE, *PCCK_TX_POWER_CALIBRATE;
65121 +
65122 +//
65123 +// Receive Tuple Cache Format
65124 +//
65125 +typedef struct _TUPLE_CACHE {
65126 + BOOLEAN Valid;
65127 + UCHAR MacAddress[MAC_ADDR_LEN];
65128 + USHORT Sequence;
65129 + USHORT Frag;
65130 +} TUPLE_CACHE, *PTUPLE_CACHE;
65131 +
65132 +//
65133 +// Fragment Frame structure
65134 +//
65135 +typedef struct _FRAGMENT_FRAME {
65136 + PNDIS_PACKET pFragPacket;
65137 + ULONG RxSize;
65138 + USHORT Sequence;
65139 + USHORT LastFrag;
65140 + ULONG Flags; // Some extra frame information. bit 0: LLC presented
65141 +} FRAGMENT_FRAME, *PFRAGMENT_FRAME;
65142 +
65143 +
65144 +//
65145 +// Packet information for NdisQueryPacket
65146 +//
65147 +typedef struct _PACKET_INFO {
65148 + UINT PhysicalBufferCount; // Physical breaks of buffer descripor chained
65149 + UINT BufferCount ; // Number of Buffer descriptor chained
65150 + UINT TotalPacketLength ; // Self explained
65151 + PNDIS_BUFFER pFirstBuffer; // Pointer to first buffer descriptor
65152 +} PACKET_INFO, *PPACKET_INFO;
65153 +
65154 +//
65155 +// Tkip Key structure which RC4 key & MIC calculation
65156 +//
65157 +typedef struct _TKIP_KEY_INFO {
65158 + UINT nBytesInM; // # bytes in M for MICKEY
65159 + ULONG IV16;
65160 + ULONG IV32;
65161 + ULONG K0; // for MICKEY Low
65162 + ULONG K1; // for MICKEY Hig
65163 + ULONG L; // Current state for MICKEY
65164 + ULONG R; // Current state for MICKEY
65165 + ULONG M; // Message accumulator for MICKEY
65166 + UCHAR RC4KEY[16];
65167 + UCHAR MIC[8];
65168 +} TKIP_KEY_INFO, *PTKIP_KEY_INFO;
65169 +
65170 +//
65171 +// Private / Misc data, counters for driver internal use
65172 +//
65173 +typedef struct __PRIVATE_STRUC {
65174 + UINT SystemResetCnt; // System reset counter
65175 + UINT TxRingFullCnt; // Tx ring full occurrance number
65176 + UINT PhyRxErrCnt; // PHY Rx error count, for debug purpose, might move to global counter
65177 + // Variables for WEP encryption / decryption in rtmp_wep.c
65178 + UINT FCSCRC32;
65179 + ARCFOURCONTEXT WEPCONTEXT;
65180 + // Tkip stuff
65181 + TKIP_KEY_INFO Tx;
65182 + TKIP_KEY_INFO Rx;
65183 +} PRIVATE_STRUC, *PPRIVATE_STRUC;
65184 +
65185 +// structure to tune BBP R66 (BBP TUNING)
65186 +typedef struct _BBP_R66_TUNING {
65187 + BOOLEAN bEnable;
65188 + USHORT FalseCcaLowerThreshold; // default 100
65189 + USHORT FalseCcaUpperThreshold; // default 512
65190 + UCHAR R66Delta;
65191 + UCHAR R66CurrentValue;
65192 + BOOLEAN R66LowerUpperSelect; //Before LinkUp, Used LowerBound or UpperBound as R66 value.
65193 +} BBP_R66_TUNING, *PBBP_R66_TUNING;
65194 +
65195 +// structure to store channel TX power
65196 +typedef struct _CHANNEL_TX_POWER {
65197 + USHORT RemainingTimeForUse; //unit: sec
65198 + UCHAR Channel;
65199 +#ifdef DOT11N_DRAFT3
65200 + BOOLEAN bEffectedChannel; // For BW 40 operating in 2.4GHz , the "effected channel" is the channel that is covered in 40Mhz.
65201 +#endif // DOT11N_DRAFT3 //
65202 + CHAR Power;
65203 + CHAR Power2;
65204 + UCHAR MaxTxPwr;
65205 + UCHAR DfsReq;
65206 +} CHANNEL_TX_POWER, *PCHANNEL_TX_POWER;
65207 +
65208 +// structure to store 802.11j channel TX power
65209 +typedef struct _CHANNEL_11J_TX_POWER {
65210 + UCHAR Channel;
65211 + UCHAR BW; // BW_10 or BW_20
65212 + CHAR Power;
65213 + CHAR Power2;
65214 + USHORT RemainingTimeForUse; //unit: sec
65215 +} CHANNEL_11J_TX_POWER, *PCHANNEL_11J_TX_POWER;
65216 +
65217 +typedef enum _ABGBAND_STATE_ {
65218 + UNKNOWN_BAND,
65219 + BG_BAND,
65220 + A_BAND,
65221 +} ABGBAND_STATE;
65222 +
65223 +typedef struct _MLME_STRUCT {
65224 +#ifdef CONFIG_STA_SUPPORT
65225 + // STA state machines
65226 + STATE_MACHINE CntlMachine;
65227 + STATE_MACHINE AssocMachine;
65228 + STATE_MACHINE AuthMachine;
65229 + STATE_MACHINE AuthRspMachine;
65230 + STATE_MACHINE SyncMachine;
65231 + STATE_MACHINE WpaPskMachine;
65232 + STATE_MACHINE LeapMachine;
65233 + STATE_MACHINE AironetMachine;
65234 + STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
65235 + STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
65236 + STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
65237 + STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
65238 + STATE_MACHINE_FUNC WpaPskFunc[WPA_PSK_FUNC_SIZE];
65239 + STATE_MACHINE_FUNC AironetFunc[AIRONET_FUNC_SIZE];
65240 +#endif // CONFIG_STA_SUPPORT //
65241 + STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
65242 + // Action
65243 + STATE_MACHINE ActMachine;
65244 +
65245 +
65246 +#ifdef QOS_DLS_SUPPORT
65247 + STATE_MACHINE DlsMachine;
65248 + STATE_MACHINE_FUNC DlsFunc[DLS_FUNC_SIZE];
65249 +#endif // QOS_DLS_SUPPORT //
65250 +
65251 +
65252 +
65253 +
65254 + ULONG ChannelQuality; // 0..100, Channel Quality Indication for Roaming
65255 + ULONG Now32; // latch the value of NdisGetSystemUpTime()
65256 + ULONG LastSendNULLpsmTime;
65257 +
65258 + BOOLEAN bRunning;
65259 + NDIS_SPIN_LOCK TaskLock;
65260 + MLME_QUEUE Queue;
65261 +
65262 + UINT ShiftReg;
65263 +
65264 + RALINK_TIMER_STRUCT PeriodicTimer;
65265 + RALINK_TIMER_STRUCT APSDPeriodicTimer;
65266 + RALINK_TIMER_STRUCT LinkDownTimer;
65267 + RALINK_TIMER_STRUCT LinkUpTimer;
65268 + ULONG PeriodicRound;
65269 + ULONG OneSecPeriodicRound;
65270 +
65271 + UCHAR RealRxPath;
65272 + BOOLEAN bLowThroughput;
65273 + BOOLEAN bEnableAutoAntennaCheck;
65274 + RALINK_TIMER_STRUCT RxAntEvalTimer;
65275 +
65276 +#ifdef RT30xx
65277 + UCHAR CaliBW40RfR24;
65278 + UCHAR CaliBW20RfR24;
65279 +#endif // RT30xx //
65280 +
65281 +} MLME_STRUCT, *PMLME_STRUCT;
65282 +
65283 +// structure for radar detection and channel switch
65284 +typedef struct _RADAR_DETECT_STRUCT {
65285 + //BOOLEAN IEEE80211H; // 0: disable, 1: enable IEEE802.11h
65286 + UCHAR CSCount; //Channel switch counter
65287 + UCHAR CSPeriod; //Channel switch period (beacon count)
65288 + UCHAR RDCount; //Radar detection counter
65289 + UCHAR RDMode; //Radar Detection mode
65290 + UCHAR RDDurRegion; //Radar detection duration region
65291 + UCHAR BBPR16;
65292 + UCHAR BBPR17;
65293 + UCHAR BBPR18;
65294 + UCHAR BBPR21;
65295 + UCHAR BBPR22;
65296 + UCHAR BBPR64;
65297 + ULONG InServiceMonitorCount; // unit: sec
65298 + UINT8 DfsSessionTime;
65299 + BOOLEAN bFastDfs;
65300 + UINT8 ChMovingTime;
65301 + UINT8 LongPulseRadarTh;
65302 +} RADAR_DETECT_STRUCT, *PRADAR_DETECT_STRUCT;
65303 +
65304 +#ifdef CARRIER_DETECTION_SUPPORT
65305 +typedef enum CD_STATE_n
65306 +{
65307 + CD_NORMAL,
65308 + CD_SILENCE,
65309 + CD_MAX_STATE
65310 +} CD_STATE;
65311 +
65312 +typedef struct CARRIER_DETECTION_s
65313 +{
65314 + BOOLEAN Enable;
65315 + UINT8 CDSessionTime;
65316 + UINT8 CDPeriod;
65317 + CD_STATE CD_State;
65318 +} CARRIER_DETECTION, *PCARRIER_DETECTION;
65319 +#endif // CARRIER_DETECTION_SUPPORT //
65320 +
65321 +typedef enum _REC_BLOCKACK_STATUS
65322 +{
65323 + Recipient_NONE=0,
65324 + Recipient_USED,
65325 + Recipient_HandleRes,
65326 + Recipient_Accept
65327 +} REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
65328 +
65329 +typedef enum _ORI_BLOCKACK_STATUS
65330 +{
65331 + Originator_NONE=0,
65332 + Originator_USED,
65333 + Originator_WaitRes,
65334 + Originator_Done
65335 +} ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
65336 +
65337 +#ifdef DOT11_N_SUPPORT
65338 +typedef struct _BA_ORI_ENTRY{
65339 + UCHAR Wcid;
65340 + UCHAR TID;
65341 + UCHAR BAWinSize;
65342 + UCHAR Token;
65343 +// Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header.
65344 + USHORT Sequence;
65345 + USHORT TimeOutValue;
65346 + ORI_BLOCKACK_STATUS ORI_BA_Status;
65347 + RALINK_TIMER_STRUCT ORIBATimer;
65348 + PVOID pAdapter;
65349 +} BA_ORI_ENTRY, *PBA_ORI_ENTRY;
65350 +
65351 +typedef struct _BA_REC_ENTRY {
65352 + UCHAR Wcid;
65353 + UCHAR TID;
65354 + UCHAR BAWinSize; // 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU.
65355 + //UCHAR NumOfRxPkt;
65356 + //UCHAR Curindidx; // the head in the RX reordering buffer
65357 + USHORT LastIndSeq;
65358 +// USHORT LastIndSeqAtTimer;
65359 + USHORT TimeOutValue;
65360 + RALINK_TIMER_STRUCT RECBATimer;
65361 + ULONG LastIndSeqAtTimer;
65362 + ULONG nDropPacket;
65363 + ULONG rcvSeq;
65364 + REC_BLOCKACK_STATUS REC_BA_Status;
65365 +// UCHAR RxBufIdxUsed;
65366 + // corresponding virtual address for RX reordering packet storage.
65367 + //RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF];
65368 + NDIS_SPIN_LOCK RxReRingLock; // Rx Ring spinlock
65369 +// struct _BA_REC_ENTRY *pNext;
65370 + PVOID pAdapter;
65371 + struct reordering_list list;
65372 +} BA_REC_ENTRY, *PBA_REC_ENTRY;
65373 +
65374 +
65375 +typedef struct {
65376 + ULONG numAsRecipient; // I am recipient of numAsRecipient clients. These client are in the BARecEntry[]
65377 + ULONG numAsOriginator; // I am originator of numAsOriginator clients. These clients are in the BAOriEntry[]
65378 + BA_ORI_ENTRY BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
65379 + BA_REC_ENTRY BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
65380 +} BA_TABLE, *PBA_TABLE;
65381 +
65382 +//For QureyBATableOID use;
65383 +typedef struct PACKED _OID_BA_REC_ENTRY{
65384 + UCHAR MACAddr[MAC_ADDR_LEN];
65385 + UCHAR BaBitmap; // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize
65386 + UCHAR rsv;
65387 + UCHAR BufSize[8];
65388 + REC_BLOCKACK_STATUS REC_BA_Status[8];
65389 +} OID_BA_REC_ENTRY, *POID_BA_REC_ENTRY;
65390 +
65391 +//For QureyBATableOID use;
65392 +typedef struct PACKED _OID_BA_ORI_ENTRY{
65393 + UCHAR MACAddr[MAC_ADDR_LEN];
65394 + UCHAR BaBitmap; // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status
65395 + UCHAR rsv;
65396 + UCHAR BufSize[8];
65397 + ORI_BLOCKACK_STATUS ORI_BA_Status[8];
65398 +} OID_BA_ORI_ENTRY, *POID_BA_ORI_ENTRY;
65399 +
65400 +typedef struct _QUERYBA_TABLE{
65401 + OID_BA_ORI_ENTRY BAOriEntry[32];
65402 + OID_BA_REC_ENTRY BARecEntry[32];
65403 + UCHAR OriNum;// Number of below BAOriEntry
65404 + UCHAR RecNum;// Number of below BARecEntry
65405 +} QUERYBA_TABLE, *PQUERYBA_TABLE;
65406 +
65407 +typedef union _BACAP_STRUC {
65408 +#ifdef RT_BIG_ENDIAN
65409 + struct {
65410 + UINT32 :4;
65411 + UINT32 b2040CoexistScanSup:1; //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
65412 + UINT32 bHtAdhoc:1; // adhoc can use ht rate.
65413 + UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
65414 + UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
65415 + UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
65416 + UINT32 MpduDensity:3;
65417 + UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
65418 + UINT32 AutoBA:1; // automatically BA
65419 + UINT32 TxBAWinLimit:8;
65420 + UINT32 RxBAWinLimit:8;
65421 + } field;
65422 +#else
65423 + struct {
65424 + UINT32 RxBAWinLimit:8;
65425 + UINT32 TxBAWinLimit:8;
65426 + UINT32 AutoBA:1; // automatically BA
65427 + UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
65428 + UINT32 MpduDensity:3;
65429 + UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
65430 + UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
65431 + UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
65432 + UINT32 bHtAdhoc:1; // adhoc can use ht rate.
65433 + UINT32 b2040CoexistScanSup:1; //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
65434 + UINT32 :4;
65435 + } field;
65436 +#endif
65437 + UINT32 word;
65438 +} BACAP_STRUC, *PBACAP_STRUC;
65439 +#endif // DOT11_N_SUPPORT //
65440 +
65441 +//This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second. (Details see MLMEPeriodic)
65442 +typedef struct _IOT_STRUC {
65443 + UCHAR Threshold[2];
65444 + UCHAR ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[0]
65445 + UCHAR RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[1]
65446 + ULONG OneSecInWindowCount;
65447 + ULONG OneSecFrameDuplicateCount;
65448 + ULONG OneSecOutWindowCount;
65449 + UCHAR DelOriAct;
65450 + UCHAR DelRecAct;
65451 + UCHAR RTSShortProt;
65452 + UCHAR RTSLongProt;
65453 + BOOLEAN bRTSLongProtOn;
65454 +#ifdef CONFIG_STA_SUPPORT
65455 + BOOLEAN bLastAtheros;
65456 + BOOLEAN bCurrentAtheros;
65457 + BOOLEAN bNowAtherosBurstOn;
65458 + BOOLEAN bNextDisableRxBA;
65459 + BOOLEAN bToggle;
65460 +#endif // CONFIG_STA_SUPPORT //
65461 +} IOT_STRUC, *PIOT_STRUC;
65462 +
65463 +// This is the registry setting for 802.11n transmit setting. Used in advanced page.
65464 +typedef union _REG_TRANSMIT_SETTING {
65465 +#ifdef RT_BIG_ENDIAN
65466 + struct {
65467 + UINT32 rsv:13;
65468 + UINT32 EXTCHA:2;
65469 + UINT32 HTMODE:1;
65470 + UINT32 TRANSNO:2;
65471 + UINT32 STBC:1; //SPACE
65472 + UINT32 ShortGI:1;
65473 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
65474 + UINT32 TxBF:1; // 3*3
65475 + UINT32 rsv0:10;
65476 + //UINT32 MCS:7; // MCS
65477 + //UINT32 PhyMode:4;
65478 + } field;
65479 +#else
65480 + struct {
65481 + //UINT32 PhyMode:4;
65482 + //UINT32 MCS:7; // MCS
65483 + UINT32 rsv0:10;
65484 + UINT32 TxBF:1;
65485 + UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
65486 + UINT32 ShortGI:1;
65487 + UINT32 STBC:1; //SPACE
65488 + UINT32 TRANSNO:2;
65489 + UINT32 HTMODE:1;
65490 + UINT32 EXTCHA:2;
65491 + UINT32 rsv:13;
65492 + } field;
65493 +#endif
65494 + UINT32 word;
65495 +} REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
65496 +
65497 +typedef union _DESIRED_TRANSMIT_SETTING {
65498 +#ifdef RT_BIG_ENDIAN
65499 + struct {
65500 + USHORT rsv:3;
65501 + USHORT FixedTxMode:2; // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
65502 + USHORT PhyMode:4;
65503 + USHORT MCS:7; // MCS
65504 + } field;
65505 +#else
65506 + struct {
65507 + USHORT MCS:7; // MCS
65508 + USHORT PhyMode:4;
65509 + USHORT FixedTxMode:2; // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
65510 + USHORT rsv:3;
65511 + } field;
65512 +#endif
65513 + USHORT word;
65514 + } DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
65515 +
65516 +typedef struct {
65517 + BOOLEAN IsRecipient;
65518 + UCHAR MACAddr[MAC_ADDR_LEN];
65519 + UCHAR TID;
65520 + UCHAR nMSDU;
65521 + USHORT TimeOut;
65522 + BOOLEAN bAllTid; // If True, delete all TID for BA sessions with this MACaddr.
65523 +} OID_ADD_BA_ENTRY, *POID_ADD_BA_ENTRY;
65524 +
65525 +//
65526 +// Multiple SSID structure
65527 +//
65528 +#define WLAN_MAX_NUM_OF_TIM ((MAX_LEN_OF_MAC_TABLE >> 3) + 1) /* /8 + 1 */
65529 +#define WLAN_CT_TIM_BCMC_OFFSET 0 /* unit: 32B */
65530 +
65531 +/* clear bcmc TIM bit */
65532 +#define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
65533 + pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
65534 +
65535 +/* set bcmc TIM bit */
65536 +#define WLAN_MR_TIM_BCMC_SET(apidx) \
65537 + pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
65538 +
65539 +/* clear a station PS TIM bit */
65540 +#define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
65541 + { UCHAR tim_offset = wcid >> 3; \
65542 + UCHAR bit_offset = wcid & 0x7; \
65543 + ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
65544 +
65545 +/* set a station PS TIM bit */
65546 +#define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
65547 + { UCHAR tim_offset = wcid >> 3; \
65548 + UCHAR bit_offset = wcid & 0x7; \
65549 + ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
65550 +
65551 +#ifdef RT2870
65552 +#define BEACON_BITMAP_MASK 0xff
65553 +typedef struct _BEACON_SYNC_STRUCT_
65554 +{
65555 + UCHAR BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET];
65556 + UCHAR BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE];
65557 + ULONG TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
65558 + ULONG CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
65559 + BOOLEAN EnableBeacon; // trigger to enable beacon transmission.
65560 + UCHAR BeaconBitMap; // NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change.
65561 + UCHAR DtimBitOn; // NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change.
65562 +}BEACON_SYNC_STRUCT;
65563 +#endif // RT2870 //
65564 +
65565 +typedef struct _MULTISSID_STRUCT {
65566 + UCHAR Bssid[MAC_ADDR_LEN];
65567 + UCHAR SsidLen;
65568 + CHAR Ssid[MAX_LEN_OF_SSID];
65569 + USHORT CapabilityInfo;
65570 +
65571 + PNET_DEV MSSIDDev;
65572 +
65573 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
65574 + NDIS_802_11_WEP_STATUS WepStatus;
65575 + NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
65576 + WPA_MIX_PAIR_CIPHER WpaMixPairCipher;
65577 +
65578 + ULONG TxCount;
65579 + ULONG RxCount;
65580 + ULONG ReceivedByteCount;
65581 + ULONG TransmittedByteCount;
65582 + ULONG RxErrorCount;
65583 + ULONG RxDropCount;
65584 +
65585 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
65586 + RT_HT_PHY_INFO DesiredHtPhyInfo;
65587 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting. this is for reading registry setting only. not useful.
65588 + BOOLEAN bAutoTxRateSwitch;
65589 +
65590 + //CIPHER_KEY SharedKey[SHARE_KEY_NUM]; // ref pAd->SharedKey[BSS][4]
65591 + UCHAR DefaultKeyId;
65592 +
65593 + UCHAR TxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11, ...
65594 + UCHAR DesiredRates[MAX_LEN_OF_SUPPORTED_RATES];// OID_802_11_DESIRED_RATES
65595 + UCHAR DesiredRatesIndex;
65596 + UCHAR MaxTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
65597 +
65598 +// ULONG TimBitmap; // bit0 for broadcast, 1 for AID1, 2 for AID2, ...so on
65599 +// ULONG TimBitmap2; // b0 for AID32, b1 for AID33, ... and so on
65600 + UCHAR TimBitmaps[WLAN_MAX_NUM_OF_TIM];
65601 +
65602 + // WPA
65603 + UCHAR GMK[32];
65604 + UCHAR PMK[32];
65605 + UCHAR GTK[32];
65606 + BOOLEAN IEEE8021X;
65607 + BOOLEAN PreAuth;
65608 + UCHAR GNonce[32];
65609 + UCHAR PortSecured;
65610 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter;
65611 + UCHAR BANClass3Data;
65612 + ULONG IsolateInterStaTraffic;
65613 +
65614 + UCHAR RSNIE_Len[2];
65615 + UCHAR RSN_IE[2][MAX_LEN_OF_RSNIE];
65616 +
65617 +
65618 + UCHAR TimIELocationInBeacon;
65619 + UCHAR CapabilityInfoLocationInBeacon;
65620 + // outgoing BEACON frame buffer and corresponding TXWI
65621 + // PTXWI_STRUC BeaconTxWI; //
65622 + CHAR BeaconBuf[MAX_BEACON_SIZE]; // NOTE: BeaconBuf should be 4-byte aligned
65623 +
65624 + BOOLEAN bHideSsid;
65625 + UINT16 StationKeepAliveTime; // unit: second
65626 +
65627 + USHORT VLAN_VID;
65628 + USHORT VLAN_Priority;
65629 +
65630 + RT_802_11_ACL AccessControlList;
65631 +
65632 + // EDCA Qos
65633 + BOOLEAN bWmmCapable; // 0:disable WMM, 1:enable WMM
65634 + BOOLEAN bDLSCapable; // 0:disable DLS, 1:enable DLS
65635 +
65636 + UCHAR DlsPTK[64]; // Due to windows dirver count on meetinghouse to handle 4-way shake
65637 +
65638 + // For 802.1x daemon setting per BSS
65639 + UCHAR radius_srv_num;
65640 + RADIUS_SRV_INFO radius_srv_info[MAX_RADIUS_SRV_NUM];
65641 +
65642 +#ifdef RTL865X_SOC
65643 + unsigned int mylinkid;
65644 +#endif
65645 +
65646 +
65647 + UINT32 RcvdConflictSsidCount;
65648 + UINT32 RcvdSpoofedAssocRespCount;
65649 + UINT32 RcvdSpoofedReassocRespCount;
65650 + UINT32 RcvdSpoofedProbeRespCount;
65651 + UINT32 RcvdSpoofedBeaconCount;
65652 + UINT32 RcvdSpoofedDisassocCount;
65653 + UINT32 RcvdSpoofedAuthCount;
65654 + UINT32 RcvdSpoofedDeauthCount;
65655 + UINT32 RcvdSpoofedUnknownMgmtCount;
65656 + UINT32 RcvdReplayAttackCount;
65657 +
65658 + CHAR RssiOfRcvdConflictSsid;
65659 + CHAR RssiOfRcvdSpoofedAssocResp;
65660 + CHAR RssiOfRcvdSpoofedReassocResp;
65661 + CHAR RssiOfRcvdSpoofedProbeResp;
65662 + CHAR RssiOfRcvdSpoofedBeacon;
65663 + CHAR RssiOfRcvdSpoofedDisassoc;
65664 + CHAR RssiOfRcvdSpoofedAuth;
65665 + CHAR RssiOfRcvdSpoofedDeauth;
65666 + CHAR RssiOfRcvdSpoofedUnknownMgmt;
65667 + CHAR RssiOfRcvdReplayAttack;
65668 +
65669 + BOOLEAN bBcnSntReq;
65670 + UCHAR BcnBufIdx;
65671 +} MULTISSID_STRUCT, *PMULTISSID_STRUCT;
65672 +
65673 +
65674 +
65675 +#ifdef DOT11N_DRAFT3
65676 +typedef enum _BSS2040COEXIST_FLAG{
65677 + BSS_2040_COEXIST_DISABLE = 0,
65678 + BSS_2040_COEXIST_TIMER_FIRED = 1,
65679 + BSS_2040_COEXIST_INFO_SYNC = 2,
65680 + BSS_2040_COEXIST_INFO_NOTIFY = 4,
65681 +}BSS2040COEXIST_FLAG;
65682 +#endif // DOT11N_DRAFT3 //
65683 +
65684 +// configuration common to OPMODE_AP as well as OPMODE_STA
65685 +typedef struct _COMMON_CONFIG {
65686 +
65687 + BOOLEAN bCountryFlag;
65688 + UCHAR CountryCode[3];
65689 + UCHAR Geography;
65690 + UCHAR CountryRegion; // Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel
65691 + UCHAR CountryRegionForABand; // Enum of country region for A band
65692 + UCHAR PhyMode; // PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED
65693 + USHORT Dsifs; // in units of usec
65694 + ULONG PacketFilter; // Packet filter for receiving
65695 +
65696 + CHAR Ssid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
65697 + UCHAR SsidLen; // the actual ssid length in used
65698 + UCHAR LastSsidLen; // the actual ssid length in used
65699 + CHAR LastSsid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
65700 + UCHAR LastBssid[MAC_ADDR_LEN];
65701 +
65702 + UCHAR Bssid[MAC_ADDR_LEN];
65703 + USHORT BeaconPeriod;
65704 + UCHAR Channel;
65705 + UCHAR CentralChannel; // Central Channel when using 40MHz is indicating. not real channel.
65706 +
65707 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
65708 + UCHAR SupRateLen;
65709 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
65710 + UCHAR ExtRateLen;
65711 + UCHAR DesireRate[MAX_LEN_OF_SUPPORTED_RATES]; // OID_802_11_DESIRED_RATES
65712 + UCHAR MaxDesiredRate;
65713 + UCHAR ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
65714 +
65715 + ULONG BasicRateBitmap; // backup basic ratebitmap
65716 +
65717 + BOOLEAN bAPSDCapable;
65718 + BOOLEAN bInServicePeriod;
65719 + BOOLEAN bAPSDAC_BE;
65720 + BOOLEAN bAPSDAC_BK;
65721 + BOOLEAN bAPSDAC_VI;
65722 + BOOLEAN bAPSDAC_VO;
65723 + BOOLEAN bNeedSendTriggerFrame;
65724 + BOOLEAN bAPSDForcePowerSave; // Force power save mode, should only use in APSD-STAUT
65725 + ULONG TriggerTimerCount;
65726 + UCHAR MaxSPLength;
65727 + UCHAR BBPCurrentBW; // BW_10, BW_20, BW_40
65728 + // move to MULTISSID_STRUCT for MBSS
65729 + //HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
65730 + REG_TRANSMIT_SETTING RegTransmitSetting; //registry transmit setting. this is for reading registry setting only. not useful.
65731 + //UCHAR FixedTxMode; // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode
65732 + UCHAR TxRate; // Same value to fill in TXD. TxRate is 6-bit
65733 + UCHAR MaxTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
65734 + UCHAR TxRateIndex; // Tx rate index in RateSwitchTable
65735 + UCHAR TxRateTableSize; // Valid Tx rate table size in RateSwitchTable
65736 + //BOOLEAN bAutoTxRateSwitch;
65737 + UCHAR MinTxRate; // RATE_1, RATE_2, RATE_5_5, RATE_11
65738 + UCHAR RtsRate; // RATE_xxx
65739 + HTTRANSMIT_SETTING MlmeTransmit; // MGMT frame PHY rate setting when operatin at Ht rate.
65740 + UCHAR MlmeRate; // RATE_xxx, used to send MLME frames
65741 + UCHAR BasicMlmeRate; // Default Rate for sending MLME frames
65742 +
65743 + USHORT RtsThreshold; // in unit of BYTE
65744 + USHORT FragmentThreshold; // in unit of BYTE
65745 +
65746 + UCHAR TxPower; // in unit of mW
65747 + ULONG TxPowerPercentage; // 0~100 %
65748 + ULONG TxPowerDefault; // keep for TxPowerPercentage
65749 +
65750 +#ifdef DOT11_N_SUPPORT
65751 + BACAP_STRUC BACapability; // NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0
65752 + BACAP_STRUC REGBACapability; // NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0
65753 +#endif // DOT11_N_SUPPORT //
65754 + IOT_STRUC IOTestParm; // 802.11n InterOpbility Test Parameter;
65755 + ULONG TxPreamble; // Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto
65756 + BOOLEAN bUseZeroToDisableFragment; // Microsoft use 0 as disable
65757 + ULONG UseBGProtection; // 0: auto, 1: always use, 2: always not use
65758 + BOOLEAN bUseShortSlotTime; // 0: disable, 1 - use short slot (9us)
65759 + BOOLEAN bEnableTxBurst; // 1: enble TX PACKET BURST, 0: disable TX PACKET BURST
65760 + BOOLEAN bAggregationCapable; // 1: enable TX aggregation when the peer supports it
65761 + BOOLEAN bPiggyBackCapable; // 1: enable TX piggy-back according MAC's version
65762 + BOOLEAN bIEEE80211H; // 1: enable IEEE802.11h spec.
65763 + ULONG DisableOLBCDetect; // 0: enable OLBC detect; 1 disable OLBC detect
65764 +
65765 +#ifdef DOT11_N_SUPPORT
65766 + BOOLEAN bRdg;
65767 +#endif // DOT11_N_SUPPORT //
65768 + BOOLEAN bWmmCapable; // 0:disable WMM, 1:enable WMM
65769 + QOS_CAPABILITY_PARM APQosCapability; // QOS capability of the current associated AP
65770 + EDCA_PARM APEdcaParm; // EDCA parameters of the current associated AP
65771 + QBSS_LOAD_PARM APQbssLoad; // QBSS load of the current associated AP
65772 + UCHAR AckPolicy[4]; // ACK policy of the specified AC. see ACK_xxx
65773 +#ifdef CONFIG_STA_SUPPORT
65774 + BOOLEAN bDLSCapable; // 0:disable DLS, 1:enable DLS
65775 +#endif // CONFIG_STA_SUPPORT //
65776 + // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
65777 + // BOOLEAN control, either ON or OFF. These flags should always be accessed via
65778 + // OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros.
65779 + // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition
65780 + ULONG OpStatusFlags;
65781 +
65782 + BOOLEAN NdisRadioStateOff; //For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff.
65783 + ABGBAND_STATE BandState; // For setting BBP used on B/G or A mode.
65784 + BOOLEAN bRxAntDiversity; // 0:disable, 1:enable Software Rx Antenna Diversity.
65785 +
65786 + // IEEE802.11H--DFS.
65787 + RADAR_DETECT_STRUCT RadarDetect;
65788 +
65789 +#ifdef CARRIER_DETECTION_SUPPORT
65790 + CARRIER_DETECTION CarrierDetect;
65791 +#endif // CARRIER_DETECTION_SUPPORT //
65792 +
65793 +#ifdef DOT11_N_SUPPORT
65794 + // HT
65795 + UCHAR BASize; // USer desired BAWindowSize. Should not exceed our max capability
65796 + //RT_HT_CAPABILITY SupportedHtPhy;
65797 + RT_HT_CAPABILITY DesiredHtPhy;
65798 + HT_CAPABILITY_IE HtCapability;
65799 + ADD_HT_INFO_IE AddHTInfo; // Useful as AP.
65800 + //This IE is used with channel switch announcement element when changing to a new 40MHz.
65801 + //This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp.
65802 + NEW_EXT_CHAN_IE NewExtChanOffset; //7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present
65803 +
65804 +#ifdef DOT11N_DRAFT3
65805 + UCHAR Bss2040CoexistFlag; // bit 0: bBssCoexistTimerRunning, bit 1: NeedSyncAddHtInfo.
65806 + RALINK_TIMER_STRUCT Bss2040CoexistTimer;
65807 +
65808 + //This IE is used for 20/40 BSS Coexistence.
65809 + BSS_2040_COEXIST_IE BSS2040CoexistInfo;
65810 + // ====== 11n D3.0 =======================>
65811 + USHORT Dot11OBssScanPassiveDwell; // Unit : TU. 5~1000
65812 + USHORT Dot11OBssScanActiveDwell; // Unit : TU. 10~1000
65813 + USHORT Dot11BssWidthTriggerScanInt; // Unit : Second
65814 + USHORT Dot11OBssScanPassiveTotalPerChannel; // Unit : TU. 200~10000
65815 + USHORT Dot11OBssScanActiveTotalPerChannel; // Unit : TU. 20~10000
65816 + USHORT Dot11BssWidthChanTranDelayFactor;
65817 + USHORT Dot11OBssScanActivityThre; // Unit : percentage
65818 +
65819 + ULONG Dot11BssWidthChanTranDelay; // multiple of (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
65820 + ULONG CountDownCtr; // CountDown Counter from (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
65821 +
65822 + NDIS_SPIN_LOCK TriggerEventTabLock;
65823 + BSS_2040_COEXIST_IE LastBSSCoexist2040;
65824 + BSS_2040_COEXIST_IE BSSCoexist2040;
65825 + TRIGGER_EVENT_TAB TriggerEventTab;
65826 + UCHAR ChannelListIdx;
65827 + // <====== 11n D3.0 =======================
65828 + BOOLEAN bOverlapScanning;
65829 +#endif // DOT11N_DRAFT3 //
65830 +
65831 + BOOLEAN bHTProtect;
65832 + BOOLEAN bMIMOPSEnable;
65833 + BOOLEAN bBADecline;
65834 + BOOLEAN bDisableReordering;
65835 + BOOLEAN bForty_Mhz_Intolerant;
65836 + BOOLEAN bExtChannelSwitchAnnouncement;
65837 + BOOLEAN bRcvBSSWidthTriggerEvents;
65838 + ULONG LastRcvBSSWidthTriggerEventsTime;
65839 +
65840 + UCHAR TxBASize;
65841 +#endif // DOT11_N_SUPPORT //
65842 +
65843 + // Enable wireless event
65844 + BOOLEAN bWirelessEvent;
65845 + BOOLEAN bWiFiTest; // Enable this parameter for WiFi test
65846 +
65847 + // Tx & Rx Stream number selection
65848 + UCHAR TxStream;
65849 + UCHAR RxStream;
65850 +
65851 + // transmit phy mode, trasmit rate for Multicast.
65852 +#ifdef MCAST_RATE_SPECIFIC
65853 + UCHAR McastTransmitMcs;
65854 + UCHAR McastTransmitPhyMode;
65855 +#endif // MCAST_RATE_SPECIFIC //
65856 +
65857 + BOOLEAN bHardwareRadio; // Hardware controlled Radio enabled
65858 +
65859 +#ifdef RT2870
65860 + BOOLEAN bMultipleIRP; // Multiple Bulk IN flag
65861 + UCHAR NumOfBulkInIRP; // if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1
65862 + RT_HT_CAPABILITY SupportedHtPhy;
65863 + ULONG MaxPktOneTxBulk;
65864 + UCHAR TxBulkFactor;
65865 + UCHAR RxBulkFactor;
65866 +
65867 + BEACON_SYNC_STRUCT *pBeaconSync;
65868 + RALINK_TIMER_STRUCT BeaconUpdateTimer;
65869 + UINT32 BeaconAdjust;
65870 + UINT32 BeaconFactor;
65871 + UINT32 BeaconRemain;
65872 +#endif // RT2870 //
65873 +
65874 +
65875 + NDIS_SPIN_LOCK MeasureReqTabLock;
65876 + PMEASURE_REQ_TAB pMeasureReqTab;
65877 +
65878 + NDIS_SPIN_LOCK TpcReqTabLock;
65879 + PTPC_REQ_TAB pTpcReqTab;
65880 +
65881 + // transmit phy mode, trasmit rate for Multicast.
65882 +#ifdef MCAST_RATE_SPECIFIC
65883 + HTTRANSMIT_SETTING MCastPhyMode;
65884 +#endif // MCAST_RATE_SPECIFIC //
65885 +
65886 +#ifdef SINGLE_SKU
65887 + UINT16 DefineMaxTxPwr;
65888 +#endif // SINGLE_SKU //
65889 +
65890 +
65891 +} COMMON_CONFIG, *PCOMMON_CONFIG;
65892 +
65893 +
65894 +#ifdef CONFIG_STA_SUPPORT
65895 +/* Modified by Wu Xi-Kun 4/21/2006 */
65896 +// STA configuration and status
65897 +typedef struct _STA_ADMIN_CONFIG {
65898 + // GROUP 1 -
65899 + // User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
65900 + // the user intended configuration, but not necessary fully equal to the final
65901 + // settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either
65902 + // AP or IBSS holder).
65903 + // Once initialized, user configuration can only be changed via OID_xxx
65904 + UCHAR BssType; // BSS_INFRA or BSS_ADHOC
65905 + USHORT AtimWin; // used when starting a new IBSS
65906 +
65907 + // GROUP 2 -
65908 + // User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
65909 + // the user intended configuration, and should be always applied to the final
65910 + // settings in ACTIVE BSS without compromising with the BSS holder.
65911 + // Once initialized, user configuration can only be changed via OID_xxx
65912 + UCHAR RssiTrigger;
65913 + UCHAR RssiTriggerMode; // RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD
65914 + USHORT DefaultListenCount; // default listen count;
65915 + ULONG WindowsPowerMode; // Power mode for AC power
65916 + ULONG WindowsBatteryPowerMode; // Power mode for battery if exists
65917 + BOOLEAN bWindowsACCAMEnable; // Enable CAM power mode when AC on
65918 + BOOLEAN bAutoReconnect; // Set to TRUE when setting OID_802_11_SSID with no matching BSSID
65919 + ULONG WindowsPowerProfile; // Windows power profile, for NDIS5.1 PnP
65920 +
65921 + // MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1)
65922 + USHORT Psm; // power management mode (PWR_ACTIVE|PWR_SAVE)
65923 + USHORT DisassocReason;
65924 + UCHAR DisassocSta[MAC_ADDR_LEN];
65925 + USHORT DeauthReason;
65926 + UCHAR DeauthSta[MAC_ADDR_LEN];
65927 + USHORT AuthFailReason;
65928 + UCHAR AuthFailSta[MAC_ADDR_LEN];
65929 +
65930 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter; // PrivacyFilter enum for 802.1X
65931 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
65932 + NDIS_802_11_WEP_STATUS WepStatus;
65933 + NDIS_802_11_WEP_STATUS OrigWepStatus; // Original wep status set from OID
65934 +
65935 + // Add to support different cipher suite for WPA2/WPA mode
65936 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Multicast cipher suite
65937 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher suite
65938 + BOOLEAN bMixCipher; // Indicate current Pair & Group use different cipher suites
65939 + USHORT RsnCapability;
65940 +
65941 + NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
65942 +
65943 + UCHAR PMK[32]; // WPA PSK mode PMK
65944 + UCHAR PTK[64]; // WPA PSK mode PTK
65945 + UCHAR GTK[32]; // GTK from authenticator
65946 + BSSID_INFO SavedPMK[PMKID_NO];
65947 + UINT SavedPMKNum; // Saved PMKID number
65948 +
65949 + UCHAR DefaultKeyId;
65950 +
65951 +
65952 + // WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED
65953 + UCHAR PortSecured;
65954 +
65955 + // For WPA countermeasures
65956 + ULONG LastMicErrorTime; // record last MIC error time
65957 + ULONG MicErrCnt; // Should be 0, 1, 2, then reset to zero (after disassoiciation).
65958 + BOOLEAN bBlockAssoc; // Block associate attempt for 60 seconds after counter measure occurred.
65959 + // For WPA-PSK supplicant state
65960 + WPA_STATE WpaState; // Default is SS_NOTUSE and handled by microsoft 802.1x
65961 + UCHAR ReplayCounter[8];
65962 + UCHAR ANonce[32]; // ANonce for WPA-PSK from aurhenticator
65963 + UCHAR SNonce[32]; // SNonce for WPA-PSK
65964 +
65965 + UCHAR LastSNR0; // last received BEACON's SNR
65966 + UCHAR LastSNR1; // last received BEACON's SNR for 2nd antenna
65967 + RSSI_SAMPLE RssiSample;
65968 + ULONG NumOfAvgRssiSample;
65969 +
65970 + ULONG LastBeaconRxTime; // OS's timestamp of the last BEACON RX time
65971 + ULONG Last11bBeaconRxTime; // OS's timestamp of the last 11B BEACON RX time
65972 + ULONG Last11gBeaconRxTime; // OS's timestamp of the last 11G BEACON RX time
65973 + ULONG Last20NBeaconRxTime; // OS's timestamp of the last 20MHz N BEACON RX time
65974 +
65975 + ULONG LastScanTime; // Record last scan time for issue BSSID_SCAN_LIST
65976 + ULONG ScanCnt; // Scan counts since most recent SSID, BSSID, SCAN OID request
65977 + BOOLEAN bSwRadio; // Software controlled Radio On/Off, TRUE: On
65978 + BOOLEAN bHwRadio; // Hardware controlled Radio On/Off, TRUE: On
65979 + BOOLEAN bRadio; // Radio state, And of Sw & Hw radio state
65980 + BOOLEAN bHardwareRadio; // Hardware controlled Radio enabled
65981 + BOOLEAN bShowHiddenSSID; // Show all known SSID in SSID list get operation
65982 +
65983 + //BOOLEAN AdhocBOnlyJoined; // Indicate Adhoc B Join.
65984 + //BOOLEAN AdhocBGJoined; // Indicate Adhoc B/G Join.
65985 + //BOOLEAN Adhoc20NJoined; // Indicate Adhoc 20MHz N Join.
65986 +
65987 + // New for WPA, windows want us to to keep association information and
65988 + // Fixed IEs from last association response
65989 + NDIS_802_11_ASSOCIATION_INFORMATION AssocInfo;
65990 + USHORT ReqVarIELen; // Length of next VIE include EID & Length
65991 + UCHAR ReqVarIEs[MAX_VIE_LEN]; // The content saved here should be little-endian format.
65992 + USHORT ResVarIELen; // Length of next VIE include EID & Length
65993 + UCHAR ResVarIEs[MAX_VIE_LEN];
65994 +
65995 + UCHAR RSNIE_Len;
65996 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE]; // The content saved here should be little-endian format.
65997 +
65998 + // New variables used for CCX 1.0
65999 + BOOLEAN bCkipOn;
66000 + BOOLEAN bCkipCmicOn;
66001 + UCHAR CkipFlag;
66002 + UCHAR GIV[3]; //for CCX iv
66003 + UCHAR RxSEQ[4];
66004 + UCHAR TxSEQ[4];
66005 + UCHAR CKIPMIC[4];
66006 + UCHAR LeapAuthMode;
66007 + LEAP_AUTH_INFO LeapAuthInfo;
66008 + UCHAR HashPwd[16];
66009 + UCHAR NetworkChallenge[8];
66010 + UCHAR NetworkChallengeResponse[24];
66011 + UCHAR PeerChallenge[8];
66012 +
66013 + UCHAR PeerChallengeResponse[24];
66014 + UCHAR SessionKey[16]; //Network session keys (NSK)
66015 + RALINK_TIMER_STRUCT LeapAuthTimer;
66016 + ROGUEAP_TABLE RogueApTab; //Cisco CCX1 Rogue AP Detection
66017 +
66018 + // New control flags for CCX
66019 + CCX_CONTROL CCXControl; // Master administration state
66020 + BOOLEAN CCXEnable; // Actual CCX state
66021 + UCHAR CCXScanChannel; // Selected channel for CCX beacon request
66022 + USHORT CCXScanTime; // Time out to wait for beacon and probe response
66023 + UCHAR CCXReqType; // Current processing CCX request type
66024 + BSS_TABLE CCXBssTab; // BSS Table
66025 + UCHAR FrameReportBuf[2048]; // Buffer for creating frame report
66026 + USHORT FrameReportLen; // Current Frame report length
66027 + ULONG CLBusyBytes; // Save the total bytes received durning channel load scan time
66028 + USHORT RPIDensity[8]; // Array for RPI density collection
66029 + // Start address of each BSS table within FrameReportBuf
66030 + // It's important to update the RxPower of the corresponding Bss
66031 + USHORT BssReportOffset[MAX_LEN_OF_BSS_TABLE];
66032 + USHORT BeaconToken; // Token for beacon report
66033 + ULONG LastBssIndex; // Most current reported Bss index
66034 + RM_REQUEST_ACTION MeasurementRequest[16]; // Saved measurement request
66035 + UCHAR RMReqCnt; // Number of measurement request saved.
66036 + UCHAR CurrentRMReqIdx; // Number of measurement request saved.
66037 + BOOLEAN ParallelReq; // Parallel measurement, only one request performed,
66038 + // It must be the same channel with maximum duration
66039 + USHORT ParallelDuration; // Maximum duration for parallel measurement
66040 + UCHAR ParallelChannel; // Only one channel with parallel measurement
66041 + USHORT IAPPToken; // IAPP dialog token
66042 + UCHAR CCXQosECWMin; // Cisco QOS ECWMin for AC 0
66043 + UCHAR CCXQosECWMax; // Cisco QOS ECWMax for AC 0
66044 + // Hack for channel load and noise histogram parameters
66045 + UCHAR NHFactor; // Parameter for Noise histogram
66046 + UCHAR CLFactor; // Parameter for channel load
66047 +
66048 + UCHAR KRK[16]; //Key Refresh Key.
66049 + UCHAR BTK[32]; //Base Transient Key
66050 + BOOLEAN CCKMLinkUpFlag;
66051 + ULONG CCKMRN; //(Re)Association request number.
66052 + LARGE_INTEGER CCKMBeaconAtJoinTimeStamp; //TSF timer for Re-assocaite to the new AP
66053 + UCHAR AironetCellPowerLimit; //in dBm
66054 + UCHAR AironetIPAddress[4]; //eg. 192.168.1.1
66055 + BOOLEAN CCXAdjacentAPReportFlag; //flag for determining report Assoc Lost time
66056 + CHAR CCXAdjacentAPSsid[MAX_LEN_OF_SSID]; //Adjacent AP's SSID report
66057 + UCHAR CCXAdjacentAPSsidLen; // the actual ssid length in used
66058 + UCHAR CCXAdjacentAPBssid[MAC_ADDR_LEN]; //Adjacent AP's BSSID report
66059 + USHORT CCXAdjacentAPChannel;
66060 + ULONG CCXAdjacentAPLinkDownTime; //for Spec S32.
66061 +
66062 + RALINK_TIMER_STRUCT StaQuickResponeForRateUpTimer;
66063 + BOOLEAN StaQuickResponeForRateUpTimerRunning;
66064 +
66065 + UCHAR DtimCount; // 0.. DtimPeriod-1
66066 + UCHAR DtimPeriod; // default = 3
66067 +
66068 +#ifdef QOS_DLS_SUPPORT
66069 + RT_802_11_DLS DLSEntry[MAX_NUM_OF_DLS_ENTRY];
66070 + UCHAR DlsReplayCounter[8];
66071 +#endif // QOS_DLS_SUPPORT //
66072 + ////////////////////////////////////////////////////////////////////////////////////////
66073 + // This is only for WHQL test.
66074 + BOOLEAN WhqlTest;
66075 + ////////////////////////////////////////////////////////////////////////////////////////
66076 +
66077 + RALINK_TIMER_STRUCT WpaDisassocAndBlockAssocTimer;
66078 + // Fast Roaming
66079 + BOOLEAN bFastRoaming; // 0:disable fast roaming, 1:enable fast roaming
66080 + CHAR dBmToRoam; // the condition to roam when receiving Rssi less than this value. It's negative value.
66081 +
66082 +#ifdef WPA_SUPPLICANT_SUPPORT
66083 + BOOLEAN IEEE8021X;
66084 + BOOLEAN IEEE8021x_required_keys;
66085 + CIPHER_KEY DesireSharedKey[4]; // Record user desired WEP keys
66086 + UCHAR DesireSharedKeyId;
66087 +
66088 + // 0: driver ignores wpa_supplicant
66089 + // 1: wpa_supplicant initiates scanning and AP selection
66090 + // 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters
66091 + UCHAR WpaSupplicantUP;
66092 + UCHAR WpaSupplicantScanCount;
66093 +#endif // WPA_SUPPLICANT_SUPPORT //
66094 +
66095 + CHAR dev_name[16];
66096 + USHORT OriDevType;
66097 +
66098 + BOOLEAN bTGnWifiTest;
66099 + BOOLEAN bScanReqIsFromWebUI;
66100 +
66101 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
66102 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting;
66103 + RT_HT_PHY_INFO DesiredHtPhyInfo;
66104 + BOOLEAN bAutoTxRateSwitch;
66105 +
66106 +
66107 +#ifdef EXT_BUILD_CHANNEL_LIST
66108 + UCHAR IEEE80211dClientMode;
66109 + UCHAR StaOriCountryCode[3];
66110 + UCHAR StaOriGeography;
66111 +#endif // EXT_BUILD_CHANNEL_LIST //
66112 +} STA_ADMIN_CONFIG, *PSTA_ADMIN_CONFIG;
66113 +
66114 +// This data structure keep the current active BSS/IBSS's configuration that this STA
66115 +// had agreed upon joining the network. Which means these parameters are usually decided
66116 +// by the BSS/IBSS creator instead of user configuration. Data in this data structurre
66117 +// is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE.
66118 +// Normally, after SCAN or failed roaming attempts, we need to recover back to
66119 +// the current active settings.
66120 +typedef struct _STA_ACTIVE_CONFIG {
66121 + USHORT Aid;
66122 + USHORT AtimWin; // in kusec; IBSS parameter set element
66123 + USHORT CapabilityInfo;
66124 + USHORT CfpMaxDuration;
66125 + USHORT CfpPeriod;
66126 +
66127 + // Copy supported rate from desired AP's beacon. We are trying to match
66128 + // AP's supported and extended rate settings.
66129 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
66130 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
66131 + UCHAR SupRateLen;
66132 + UCHAR ExtRateLen;
66133 + // Copy supported ht from desired AP's beacon. We are trying to match
66134 + RT_HT_PHY_INFO SupportedPhyInfo;
66135 + RT_HT_CAPABILITY SupportedHtPhy;
66136 +} STA_ACTIVE_CONFIG, *PSTA_ACTIVE_CONFIG;
66137 +#endif // CONFIG_STA_SUPPORT //
66138 +
66139 +#ifdef RT2870
66140 +typedef struct RT_ADD_PAIRWISE_KEY_ENTRY {
66141 + NDIS_802_11_MAC_ADDRESS MacAddr;
66142 + USHORT MacTabMatchWCID; // ASIC
66143 + CIPHER_KEY CipherKey;
66144 +} RT_ADD_PAIRWISE_KEY_ENTRY,*PRT_ADD_PAIRWISE_KEY_ENTRY;
66145 +#endif // RT2870 //
66146 +
66147 +// ----------- start of AP --------------------------
66148 +// AUTH-RSP State Machine Aux data structure
66149 +typedef struct _AP_MLME_AUX {
66150 + UCHAR Addr[MAC_ADDR_LEN];
66151 + USHORT Alg;
66152 + CHAR Challenge[CIPHER_TEXT_LEN];
66153 +} AP_MLME_AUX, *PAP_MLME_AUX;
66154 +
66155 +// structure to define WPA Group Key Rekey Interval
66156 +typedef struct PACKED _RT_802_11_WPA_REKEY {
66157 + ULONG ReKeyMethod; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
66158 + ULONG ReKeyInterval; // time-based: seconds, packet-based: kilo-packets
66159 +} RT_WPA_REKEY,*PRT_WPA_REKEY, RT_802_11_WPA_REKEY, *PRT_802_11_WPA_REKEY;
66160 +
66161 +typedef struct _MAC_TABLE_ENTRY {
66162 + //Choose 1 from ValidAsWDS and ValidAsCLI to validize.
66163 + BOOLEAN ValidAsCLI; // Sta mode, set this TRUE after Linkup,too.
66164 + BOOLEAN ValidAsWDS; // This is WDS Entry. only for AP mode.
66165 + BOOLEAN ValidAsApCli; //This is a AP-Client entry, only for AP mode which enable AP-Client functions.
66166 + BOOLEAN ValidAsMesh;
66167 + BOOLEAN ValidAsDls; // This is DLS Entry. only for STA mode.
66168 + BOOLEAN isCached;
66169 + BOOLEAN bIAmBadAtheros;
66170 +
66171 + UCHAR EnqueueEapolStartTimerRunning; // Enqueue EAPoL-Start for triggering EAP SM
66172 + //jan for wpa
66173 + // record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB
66174 + UCHAR CMTimerRunning;
66175 + UCHAR apidx; // MBSS number
66176 + UCHAR RSNIE_Len;
66177 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE];
66178 + UCHAR ANonce[LEN_KEY_DESC_NONCE];
66179 + UCHAR R_Counter[LEN_KEY_DESC_REPLAY];
66180 + UCHAR PTK[64];
66181 + UCHAR ReTryCounter;
66182 + RALINK_TIMER_STRUCT RetryTimer;
66183 + RALINK_TIMER_STRUCT EnqueueStartForPSKTimer; // A timer which enqueue EAPoL-Start for triggering PSK SM
66184 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
66185 + NDIS_802_11_WEP_STATUS WepStatus;
66186 + AP_WPA_STATE WpaState;
66187 + GTK_STATE GTKState;
66188 + USHORT PortSecured;
66189 + NDIS_802_11_PRIVACY_FILTER PrivacyFilter; // PrivacyFilter enum for 802.1X
66190 + CIPHER_KEY PairwiseKey;
66191 + PVOID pAd;
66192 + INT PMKID_CacheIdx;
66193 + UCHAR PMKID[LEN_PMKID];
66194 +
66195 +
66196 + UCHAR Addr[MAC_ADDR_LEN];
66197 + UCHAR PsMode;
66198 + SST Sst;
66199 + AUTH_STATE AuthState; // for SHARED KEY authentication state machine used only
66200 + BOOLEAN IsReassocSta; // Indicate whether this is a reassociation procedure
66201 + USHORT Aid;
66202 + USHORT CapabilityInfo;
66203 + UCHAR LastRssi;
66204 + ULONG NoDataIdleCount;
66205 + UINT16 StationKeepAliveCount; // unit: second
66206 + ULONG PsQIdleCount;
66207 + QUEUE_HEADER PsQueue;
66208 +
66209 + UINT32 StaConnectTime; // the live time of this station since associated with AP
66210 +
66211 +
66212 +#ifdef DOT11_N_SUPPORT
66213 + BOOLEAN bSendBAR;
66214 + USHORT NoBADataCountDown;
66215 +
66216 + UINT32 CachedBuf[16]; // UINT (4 bytes) for alignment
66217 + UINT TxBFCount; // 3*3
66218 +#endif // DOT11_N_SUPPORT //
66219 + UINT FIFOCount;
66220 + UINT DebugFIFOCount;
66221 + UINT DebugTxCount;
66222 + BOOLEAN bDlsInit;
66223 +
66224 +
66225 +//====================================================
66226 +//WDS entry needs these
66227 +// rt2860 add this. if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab
66228 + UINT MatchWDSTabIdx;
66229 + UCHAR MaxSupportedRate;
66230 + UCHAR CurrTxRate;
66231 + UCHAR CurrTxRateIndex;
66232 + // to record the each TX rate's quality. 0 is best, the bigger the worse.
66233 + USHORT TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
66234 +// USHORT OneSecTxOkCount;
66235 + UINT32 OneSecTxNoRetryOkCount;
66236 + UINT32 OneSecTxRetryOkCount;
66237 + UINT32 OneSecTxFailCount;
66238 + UINT32 ContinueTxFailCnt;
66239 + UINT32 CurrTxRateStableTime; // # of second in current TX rate
66240 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
66241 +//====================================================
66242 +
66243 +
66244 +
66245 +#ifdef CONFIG_STA_SUPPORT
66246 +#ifdef QOS_DLS_SUPPORT
66247 + UINT MatchDlsEntryIdx; // indicate the index in pAd->StaCfg.DLSEntry
66248 +#endif // QOS_DLS_SUPPORT //
66249 +#endif // CONFIG_STA_SUPPORT //
66250 +
66251 + BOOLEAN fNoisyEnvironment;
66252 + BOOLEAN fLastSecAccordingRSSI;
66253 + UCHAR LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
66254 + CHAR LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
66255 + ULONG LastTxOkCount;
66256 + UCHAR PER[MAX_STEP_OF_TX_RATE_SWITCH];
66257 +
66258 + // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
66259 + // BOOLEAN control, either ON or OFF. These flags should always be accessed via
66260 + // CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros.
66261 + // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED
66262 + ULONG ClientStatusFlags;
66263 +
66264 + // TODO: Shall we move that to DOT11_N_SUPPORT???
66265 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
66266 +
66267 +#ifdef DOT11_N_SUPPORT
66268 + // HT EWC MIMO-N used parameters
66269 + USHORT RXBAbitmap; // fill to on-chip RXWI_BA_BITMASK in 8.1.3RX attribute entry format
66270 + USHORT TXBAbitmap; // This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI
66271 + USHORT TXAutoBAbitmap;
66272 + USHORT BADeclineBitmap;
66273 + USHORT BARecWcidArray[NUM_OF_TID]; // The mapping wcid of recipient session. if RXBAbitmap bit is masked
66274 + USHORT BAOriWcidArray[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
66275 + USHORT BAOriSequence[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
66276 +
66277 + // 802.11n features.
66278 + UCHAR MpduDensity;
66279 + UCHAR MaxRAmpduFactor;
66280 + UCHAR AMsduSize;
66281 + UCHAR MmpsMode; // MIMO power save more.
66282 +
66283 + HT_CAPABILITY_IE HTCapability;
66284 +
66285 +#ifdef DOT11N_DRAFT3
66286 + UCHAR BSS2040CoexistenceMgmtSupport;
66287 +#endif // DOT11N_DRAFT3 //
66288 +#endif // DOT11_N_SUPPORT //
66289 +
66290 + BOOLEAN bAutoTxRateSwitch;
66291 +
66292 + UCHAR RateLen;
66293 + struct _MAC_TABLE_ENTRY *pNext;
66294 + USHORT TxSeq[NUM_OF_TID];
66295 + USHORT NonQosDataSeq;
66296 +
66297 + RSSI_SAMPLE RssiSample;
66298 +
66299 + UINT32 TXMCSExpected[16];
66300 + UINT32 TXMCSSuccessful[16];
66301 + UINT32 TXMCSFailed[16];
66302 + UINT32 TXMCSAutoFallBack[16][16];
66303 +
66304 +#ifdef CONFIG_STA_SUPPORT
66305 + ULONG LastBeaconRxTime;
66306 +#endif // CONFIG_STA_SUPPORT //
66307 +} MAC_TABLE_ENTRY, *PMAC_TABLE_ENTRY;
66308 +
66309 +typedef struct _MAC_TABLE {
66310 + USHORT Size;
66311 + MAC_TABLE_ENTRY *Hash[HASH_TABLE_SIZE];
66312 + MAC_TABLE_ENTRY Content[MAX_LEN_OF_MAC_TABLE];
66313 + QUEUE_HEADER McastPsQueue;
66314 + ULONG PsQIdleCount;
66315 + BOOLEAN fAnyStationInPsm;
66316 + BOOLEAN fAnyStationBadAtheros; // Check if any Station is atheros 802.11n Chip. We need to use RTS/CTS with Atheros 802,.11n chip.
66317 + BOOLEAN fAnyTxOPForceDisable; // Check if it is necessary to disable BE TxOP
66318 + BOOLEAN fAllStationAsRalink; // Check if all stations are ralink-chipset
66319 +#ifdef DOT11_N_SUPPORT
66320 + BOOLEAN fAnyStationIsLegacy; // Check if I use legacy rate to transmit to my BSS Station/
66321 + BOOLEAN fAnyStationNonGF; // Check if any Station can't support GF.
66322 + BOOLEAN fAnyStation20Only; // Check if any Station can't support GF.
66323 + BOOLEAN fAnyStationMIMOPSDynamic; // Check if any Station is MIMO Dynamic
66324 + BOOLEAN fAnyBASession; // Check if there is BA session. Force turn on RTS/CTS
66325 +#endif // DOT11_N_SUPPORT //
66326 +} MAC_TABLE, *PMAC_TABLE;
66327 +
66328 +#ifdef DOT11_N_SUPPORT
66329 +#define IS_HT_STA(_pMacEntry) \
66330 + (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
66331 +
66332 +#define IS_HT_RATE(_pMacEntry) \
66333 + (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
66334 +
66335 +#define PEER_IS_HT_RATE(_pMacEntry) \
66336 + (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
66337 +#endif // DOT11_N_SUPPORT //
66338 +
66339 +typedef struct _WDS_ENTRY {
66340 + BOOLEAN Valid;
66341 + UCHAR Addr[MAC_ADDR_LEN];
66342 + ULONG NoDataIdleCount;
66343 + struct _WDS_ENTRY *pNext;
66344 +} WDS_ENTRY, *PWDS_ENTRY;
66345 +
66346 +typedef struct _WDS_TABLE_ENTRY {
66347 + USHORT Size;
66348 + UCHAR WdsAddr[MAC_ADDR_LEN];
66349 + WDS_ENTRY *Hash[HASH_TABLE_SIZE];
66350 + WDS_ENTRY Content[MAX_LEN_OF_MAC_TABLE];
66351 + UCHAR MaxSupportedRate;
66352 + UCHAR CurrTxRate;
66353 + USHORT TxQuality[MAX_LEN_OF_SUPPORTED_RATES];
66354 + USHORT OneSecTxOkCount;
66355 + USHORT OneSecTxRetryOkCount;
66356 + USHORT OneSecTxFailCount;
66357 + ULONG CurrTxRateStableTime; // # of second in current TX rate
66358 + UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
66359 +} WDS_TABLE_ENTRY, *PWDS_TABLE_ENTRY;
66360 +
66361 +typedef struct _RT_802_11_WDS_ENTRY {
66362 + PNET_DEV dev;
66363 + UCHAR Valid;
66364 + UCHAR PhyMode;
66365 + UCHAR PeerWdsAddr[MAC_ADDR_LEN];
66366 + UCHAR MacTabMatchWCID; // ASIC
66367 + NDIS_802_11_WEP_STATUS WepStatus;
66368 + UCHAR KeyIdx;
66369 + CIPHER_KEY WdsKey;
66370 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
66371 + RT_HT_PHY_INFO DesiredHtPhyInfo;
66372 + BOOLEAN bAutoTxRateSwitch;
66373 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting.
66374 +} RT_802_11_WDS_ENTRY, *PRT_802_11_WDS_ENTRY;
66375 +
66376 +typedef struct _WDS_TABLE {
66377 + UCHAR Mode;
66378 + ULONG Size;
66379 + RT_802_11_WDS_ENTRY WdsEntry[MAX_WDS_ENTRY];
66380 +} WDS_TABLE, *PWDS_TABLE;
66381 +
66382 +typedef struct _APCLI_STRUCT {
66383 + PNET_DEV dev;
66384 +#ifdef RTL865X_SOC
66385 + unsigned int mylinkid;
66386 +#endif
66387 + BOOLEAN Enable; // Set it as 1 if the apcli interface was configured to "1" or by iwpriv cmd "ApCliEnable"
66388 + BOOLEAN Valid; // Set it as 1 if the apcli interface associated success to remote AP.
66389 + UCHAR MacTabWCID; //WCID value, which point to the entry of ASIC Mac table.
66390 + UCHAR SsidLen;
66391 + CHAR Ssid[MAX_LEN_OF_SSID];
66392 +
66393 + UCHAR CfgSsidLen;
66394 + CHAR CfgSsid[MAX_LEN_OF_SSID];
66395 + UCHAR CfgApCliBssid[ETH_LENGTH_OF_ADDRESS];
66396 + UCHAR CurrentAddress[ETH_LENGTH_OF_ADDRESS];
66397 +
66398 + ULONG ApCliRcvBeaconTime;
66399 +
66400 + ULONG CtrlCurrState;
66401 + ULONG SyncCurrState;
66402 + ULONG AuthCurrState;
66403 + ULONG AssocCurrState;
66404 + ULONG WpaPskCurrState;
66405 +
66406 + USHORT AuthReqCnt;
66407 + USHORT AssocReqCnt;
66408 +
66409 + ULONG ClientStatusFlags;
66410 + UCHAR MpduDensity;
66411 +
66412 + NDIS_802_11_AUTHENTICATION_MODE AuthMode; // This should match to whatever microsoft defined
66413 + NDIS_802_11_WEP_STATUS WepStatus;
66414 +
66415 + // Add to support different cipher suite for WPA2/WPA mode
66416 + NDIS_802_11_ENCRYPTION_STATUS GroupCipher; // Multicast cipher suite
66417 + NDIS_802_11_ENCRYPTION_STATUS PairCipher; // Unicast cipher suite
66418 + BOOLEAN bMixCipher; // Indicate current Pair & Group use different cipher suites
66419 + USHORT RsnCapability;
66420 +
66421 + UCHAR PSK[100]; // reserve PSK key material
66422 + UCHAR PSKLen;
66423 + UCHAR PMK[32]; // WPA PSK mode PMK
66424 + //UCHAR PTK[64]; // WPA PSK mode PTK
66425 + UCHAR GTK[32]; // GTK from authenticator
66426 +
66427 + //CIPHER_KEY PairwiseKey;
66428 + CIPHER_KEY SharedKey[SHARE_KEY_NUM];
66429 + UCHAR DefaultKeyId;
66430 +
66431 + // WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED
66432 + //UCHAR PortSecured;
66433 +
66434 + // store RSN_IE built by driver
66435 + UCHAR RSN_IE[MAX_LEN_OF_RSNIE]; // The content saved here should be convert to little-endian format.
66436 + UCHAR RSNIE_Len;
66437 +
66438 + // For WPA countermeasures
66439 + ULONG LastMicErrorTime; // record last MIC error time
66440 + //ULONG MicErrCnt; // Should be 0, 1, 2, then reset to zero (after disassoiciation).
66441 + BOOLEAN bBlockAssoc; // Block associate attempt for 60 seconds after counter measure occurred.
66442 +
66443 + // For WPA-PSK supplicant state
66444 + //WPA_STATE WpaState; // Default is SS_NOTUSE
66445 + //UCHAR ReplayCounter[8];
66446 + //UCHAR ANonce[32]; // ANonce for WPA-PSK from authenticator
66447 + UCHAR SNonce[32]; // SNonce for WPA-PSK
66448 + UCHAR GNonce[32]; // GNonce for WPA-PSK from authenticator
66449 +
66450 + HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
66451 + RT_HT_PHY_INFO DesiredHtPhyInfo;
66452 + BOOLEAN bAutoTxRateSwitch;
66453 + DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; // Desired transmit setting.
66454 +} APCLI_STRUCT, *PAPCLI_STRUCT;
66455 +
66456 +// ----------- end of AP ----------------------------
66457 +
66458 +#ifdef BLOCK_NET_IF
66459 +typedef struct _BLOCK_QUEUE_ENTRY
66460 +{
66461 + BOOLEAN SwTxQueueBlockFlag;
66462 + LIST_HEADER NetIfList;
66463 +} BLOCK_QUEUE_ENTRY, *PBLOCK_QUEUE_ENTRY;
66464 +#endif // BLOCK_NET_IF //
66465 +
66466 +
66467 +struct wificonf
66468 +{
66469 + BOOLEAN bShortGI;
66470 + BOOLEAN bGreenField;
66471 +};
66472 +
66473 +
66474 +
66475 +
66476 +typedef struct _INF_PCI_CONFIG
66477 +{
66478 + PUCHAR CSRBaseAddress; // PCI MMIO Base Address, all access will use
66479 +}INF_PCI_CONFIG;
66480 +
66481 +typedef struct _INF_USB_CONFIG
66482 +{
66483 + UINT BulkInEpAddr; // bulk-in endpoint address
66484 + UINT BulkOutEpAddr[6]; // bulk-out endpoint address
66485 +
66486 +}INF_USB_CONFIG;
66487 +
66488 +#ifdef IKANOS_VX_1X0
66489 + typedef void (*IkanosWlanTxCbFuncP)(void *, void *);
66490 +
66491 + struct IKANOS_TX_INFO
66492 + {
66493 + struct net_device *netdev;
66494 + IkanosWlanTxCbFuncP *fp;
66495 + };
66496 +#endif // IKANOS_VX_1X0 //
66497 +
66498 +#ifdef NINTENDO_AP
66499 +typedef struct _NINDO_CTRL_BLOCK {
66500 +
66501 + RT_NINTENDO_TABLE DS_TABLE;
66502 +
66503 +#ifdef CHIP25XX
66504 + spinlock_t NINTENDO_TABLE_Lock;
66505 +#else
66506 + NDIS_SPIN_LOCK NINTENDO_TABLE_Lock;
66507 +#endif // CHIP25XX //
66508 +
66509 + UCHAR NINTENDO_UP_BUFFER[512];
66510 + UCHAR Local_KeyIdx;
66511 + CIPHER_KEY Local_SharedKey;
66512 + UCHAR Local_bHideSsid;
66513 + UCHAR Local_AuthMode;
66514 + UCHAR Local_WepStatus;
66515 + USHORT Local_CapabilityInfo;
66516 +} NINDO_CTRL_BLOCK;
66517 +#endif // NINTENDO_AP //
66518 +
66519 +
66520 +#ifdef DBG_DIAGNOSE
66521 +#define DIAGNOSE_TIME 10 // 10 sec
66522 +typedef struct _RtmpDiagStrcut_
66523 +{ // Diagnosis Related element
66524 + unsigned char inited;
66525 + unsigned char qIdx;
66526 + unsigned char ArrayStartIdx;
66527 + unsigned char ArrayCurIdx;
66528 + // Tx Related Count
66529 + USHORT TxDataCnt[DIAGNOSE_TIME];
66530 + USHORT TxFailCnt[DIAGNOSE_TIME];
66531 +// USHORT TxDescCnt[DIAGNOSE_TIME][16]; // TxDesc queue length in scale of 0~14, >=15
66532 + USHORT TxDescCnt[DIAGNOSE_TIME][24]; // 3*3 // TxDesc queue length in scale of 0~14, >=15
66533 +// USHORT TxMcsCnt[DIAGNOSE_TIME][16]; // TxDate MCS Count in range from 0 to 15, step in 1.
66534 + USHORT TxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
66535 + USHORT TxSWQueCnt[DIAGNOSE_TIME][9]; // TxSwQueue length in scale of 0, 1, 2, 3, 4, 5, 6, 7, >=8
66536 +
66537 + USHORT TxAggCnt[DIAGNOSE_TIME];
66538 + USHORT TxNonAggCnt[DIAGNOSE_TIME];
66539 +// USHORT TxAMPDUCnt[DIAGNOSE_TIME][16]; // 10 sec, TxDMA APMDU Aggregation count in range from 0 to 15, in setp of 1.
66540 + USHORT TxAMPDUCnt[DIAGNOSE_TIME][24]; // 3*3 // 10 sec, TxDMA APMDU Aggregation count in range from 0 to 15, in setp of 1.
66541 + USHORT TxRalinkCnt[DIAGNOSE_TIME]; // TxRalink Aggregation Count in 1 sec scale.
66542 + USHORT TxAMSDUCnt[DIAGNOSE_TIME]; // TxAMSUD Aggregation Count in 1 sec scale.
66543 +
66544 + // Rx Related Count
66545 + USHORT RxDataCnt[DIAGNOSE_TIME]; // Rx Total Data count.
66546 + USHORT RxCrcErrCnt[DIAGNOSE_TIME];
66547 +// USHORT RxMcsCnt[DIAGNOSE_TIME][16]; // Rx MCS Count in range from 0 to 15, step in 1.
66548 + USHORT RxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
66549 +}RtmpDiagStruct;
66550 +#endif // DBG_DIAGNOSE //
66551 +
66552 +
66553 +//
66554 +// The miniport adapter structure
66555 +//
66556 +typedef struct _RTMP_ADAPTER
66557 +{
66558 + PVOID OS_Cookie; // save specific structure relative to OS
66559 + PNET_DEV net_dev;
66560 + ULONG VirtualIfCnt;
66561 +
66562 +
66563 +
66564 + NDIS_SPIN_LOCK irq_lock;
66565 + UCHAR irq_disabled;
66566 +
66567 +#ifdef RT2870
66568 +/*****************************************************************************************/
66569 +/* USB related parameters */
66570 +/*****************************************************************************************/
66571 + struct usb_config_descriptor *config;
66572 + UINT BulkInEpAddr; // bulk-in endpoint address
66573 + UINT BulkOutEpAddr[6]; // bulk-out endpoint address
66574 +
66575 + UINT NumberOfPipes;
66576 + USHORT BulkOutMaxPacketSize;
66577 + USHORT BulkInMaxPacketSize;
66578 +
66579 + //======Control Flags
66580 + LONG PendingIoCount;
66581 + ULONG BulkFlags;
66582 + BOOLEAN bUsbTxBulkAggre; // Flags for bulk out data priority
66583 +
66584 +
66585 + //======Timer Thread
66586 + RT2870_TIMER_QUEUE TimerQ;
66587 + NDIS_SPIN_LOCK TimerQLock;
66588 +
66589 +
66590 + //======Cmd Thread
66591 + CmdQ CmdQ;
66592 + NDIS_SPIN_LOCK CmdQLock; // CmdQLock spinlock
66593 +
66594 + BOOLEAN TimerFunc_kill;
66595 + BOOLEAN mlme_kill;
66596 +
66597 +
66598 + //======Semaphores (event)
66599 + struct semaphore mlme_semaphore; /* to sleep thread on */
66600 + struct semaphore RTUSBCmd_semaphore; /* to sleep thread on */
66601 + struct semaphore RTUSBTimer_semaphore;
66602 +#ifdef INF_AMAZON_SE
66603 + struct semaphore UsbVendorReq_semaphore;
66604 + PVOID UsbVendorReqBuf;
66605 +#endif // INF_AMAZON_SE //
66606 + struct completion TimerQComplete;
66607 + struct completion mlmeComplete;
66608 + struct completion CmdQComplete;
66609 + wait_queue_head_t *wait;
66610 +
66611 + //======Lock for 2870 ATE
66612 +#ifdef RALINK_ATE
66613 + NDIS_SPIN_LOCK GenericLock; // ATE Tx/Rx generic spinlock
66614 +#endif // RALINK_ATE //
66615 +
66616 +#endif // RT2870 //
66617 +
66618 +
66619 +/*****************************************************************************************/
66620 + /* Both PCI/USB related parameters */
66621 +/*****************************************************************************************/
66622 +
66623 +
66624 +/*****************************************************************************************/
66625 +/* Tx related parameters */
66626 +/*****************************************************************************************/
66627 + BOOLEAN DeQueueRunning[NUM_OF_TX_RING]; // for ensuring RTUSBDeQueuePacket get call once
66628 + NDIS_SPIN_LOCK DeQueueLock[NUM_OF_TX_RING];
66629 +
66630 +#ifdef RT2870
66631 + // Data related context and AC specified, 4 AC supported
66632 + NDIS_SPIN_LOCK BulkOutLock[6]; // BulkOut spinlock for 4 ACs
66633 + NDIS_SPIN_LOCK MLMEBulkOutLock; // MLME BulkOut lock
66634 +
66635 + HT_TX_CONTEXT TxContext[NUM_OF_TX_RING];
66636 + NDIS_SPIN_LOCK TxContextQueueLock[NUM_OF_TX_RING]; // TxContextQueue spinlock
66637 +
66638 + // 4 sets of Bulk Out index and pending flag
66639 + UCHAR NextBulkOutIndex[4]; // only used for 4 EDCA bulkout pipe
66640 +
66641 + BOOLEAN BulkOutPending[6]; // used for total 6 bulkout pipe
66642 + UCHAR bulkResetPipeid;
66643 + BOOLEAN MgmtBulkPending;
66644 + ULONG bulkResetReq[6];
66645 +#endif // RT2870 //
66646 +
66647 + // resource for software backlog queues
66648 + QUEUE_HEADER TxSwQueue[NUM_OF_TX_RING]; // 4 AC + 1 HCCA
66649 + NDIS_SPIN_LOCK TxSwQueueLock[NUM_OF_TX_RING]; // TxSwQueue spinlock
66650 +
66651 + RTMP_DMABUF MgmtDescRing; // Shared memory for MGMT descriptors
66652 + RTMP_MGMT_RING MgmtRing;
66653 + NDIS_SPIN_LOCK MgmtRingLock; // Prio Ring spinlock
66654 +
66655 +
66656 +/*****************************************************************************************/
66657 +/* Rx related parameters */
66658 +/*****************************************************************************************/
66659 +
66660 +
66661 +#ifdef RT2870
66662 + RX_CONTEXT RxContext[RX_RING_SIZE]; // 1 for redundant multiple IRP bulk in.
66663 + NDIS_SPIN_LOCK BulkInLock; // BulkIn spinlock for 4 ACs
66664 + UCHAR PendingRx; // The Maxima pending Rx value should be RX_RING_SIZE.
66665 + UCHAR NextRxBulkInIndex; // Indicate the current RxContext Index which hold by Host controller.
66666 + UCHAR NextRxBulkInReadIndex; // Indicate the current RxContext Index which driver can read & process it.
66667 + ULONG NextRxBulkInPosition; // Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength.
66668 + ULONG TransferBufferLength; // current length of the packet buffer
66669 + ULONG ReadPosition; // current read position in a packet buffer
66670 +#endif // RT2870 //
66671 +
66672 +
66673 +/*****************************************************************************************/
66674 +/* ASIC related parameters */
66675 +/*****************************************************************************************/
66676 + UINT32 MACVersion; // MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101)..
66677 +
66678 + // ---------------------------
66679 + // E2PROM
66680 + // ---------------------------
66681 + ULONG EepromVersion; // byte 0: version, byte 1: revision, byte 2~3: unused
66682 + UCHAR EEPROMAddressNum; // 93c46=6 93c66=8
66683 + USHORT EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
66684 + BOOLEAN EepromAccess;
66685 + UCHAR EFuseTag;
66686 + ULONG FirmwareVersion; // byte 0: Minor version, byte 1: Major version, otherwise unused.
66687 +
66688 + // ---------------------------
66689 + // BBP Control
66690 + // ---------------------------
66691 + UCHAR BbpWriteLatch[140]; // record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID
66692 + UCHAR BbpRssiToDbmDelta;
66693 + BBP_R66_TUNING BbpTuning;
66694 +
66695 + // ----------------------------
66696 + // RFIC control
66697 + // ----------------------------
66698 + UCHAR RfIcType; // RFIC_xxx
66699 + ULONG RfFreqOffset; // Frequency offset for channel switching
66700 + RTMP_RF_REGS LatchRfRegs; // latch th latest RF programming value since RF IC doesn't support READ
66701 +
66702 + EEPROM_ANTENNA_STRUC Antenna; // Since ANtenna definition is different for a & g. We need to save it for future reference.
66703 + EEPROM_NIC_CONFIG2_STRUC NicConfig2;
66704 +
66705 + // This soft Rx Antenna Diversity mechanism is used only when user set
66706 + // RX Antenna = DIVERSITY ON
66707 + SOFT_RX_ANT_DIVERSITY RxAnt;
66708 +
66709 + UCHAR RFProgSeq;
66710 + CHANNEL_TX_POWER TxPower[MAX_NUM_OF_CHANNELS]; // Store Tx power value for all channels.
66711 + CHANNEL_TX_POWER ChannelList[MAX_NUM_OF_CHANNELS]; // list all supported channels for site survey
66712 + CHANNEL_11J_TX_POWER TxPower11J[MAX_NUM_OF_11JCHANNELS]; // 802.11j channel and bw
66713 + CHANNEL_11J_TX_POWER ChannelList11J[MAX_NUM_OF_11JCHANNELS]; // list all supported channels for site survey
66714 +
66715 + UCHAR ChannelListNum; // number of channel in ChannelList[]
66716 + UCHAR Bbp94;
66717 + BOOLEAN BbpForCCK;
66718 + ULONG Tx20MPwrCfgABand[5];
66719 + ULONG Tx20MPwrCfgGBand[5];
66720 + ULONG Tx40MPwrCfgABand[5];
66721 + ULONG Tx40MPwrCfgGBand[5];
66722 +
66723 + BOOLEAN bAutoTxAgcA; // Enable driver auto Tx Agc control
66724 + UCHAR TssiRefA; // Store Tssi reference value as 25 temperature.
66725 + UCHAR TssiPlusBoundaryA[5]; // Tssi boundary for increase Tx power to compensate.
66726 + UCHAR TssiMinusBoundaryA[5]; // Tssi boundary for decrease Tx power to compensate.
66727 + UCHAR TxAgcStepA; // Store Tx TSSI delta increment / decrement value
66728 + CHAR TxAgcCompensateA; // Store the compensation (TxAgcStep * (idx-1))
66729 +
66730 + BOOLEAN bAutoTxAgcG; // Enable driver auto Tx Agc control
66731 + UCHAR TssiRefG; // Store Tssi reference value as 25 temperature.
66732 + UCHAR TssiPlusBoundaryG[5]; // Tssi boundary for increase Tx power to compensate.
66733 + UCHAR TssiMinusBoundaryG[5]; // Tssi boundary for decrease Tx power to compensate.
66734 + UCHAR TxAgcStepG; // Store Tx TSSI delta increment / decrement value
66735 + CHAR TxAgcCompensateG; // Store the compensation (TxAgcStep * (idx-1))
66736 +
66737 + //+++For RT2870, the parameteres is start from BGRssiOffset1 ~ BGRssiOffset3
66738 + CHAR BGRssiOffset0; // Store B/G RSSI#0 Offset value on EEPROM 0x46h
66739 + CHAR BGRssiOffset1; // Store B/G RSSI#1 Offset value
66740 + CHAR BGRssiOffset2; // Store B/G RSSI#2 Offset value
66741 + //---
66742 +
66743 + //+++For RT2870, the parameteres is start from ARssiOffset1 ~ ARssiOffset3
66744 + CHAR ARssiOffset0; // Store A RSSI#0 Offset value on EEPROM 0x4Ah
66745 + CHAR ARssiOffset1; // Store A RSSI#1 Offset value
66746 + CHAR ARssiOffset2; // Store A RSSI#2 Offset value
66747 + //---
66748 +
66749 + CHAR BLNAGain; // Store B/G external LNA#0 value on EEPROM 0x44h
66750 + CHAR ALNAGain0; // Store A external LNA#0 value for ch36~64
66751 + CHAR ALNAGain1; // Store A external LNA#1 value for ch100~128
66752 + CHAR ALNAGain2; // Store A external LNA#2 value for ch132~165
66753 +
66754 + // ----------------------------
66755 + // LED control
66756 + // ----------------------------
66757 + MCU_LEDCS_STRUC LedCntl;
66758 + USHORT Led1; // read from EEPROM 0x3c
66759 + USHORT Led2; // EEPROM 0x3e
66760 + USHORT Led3; // EEPROM 0x40
66761 + UCHAR LedIndicatorStregth;
66762 + UCHAR RssiSingalstrengthOffet;
66763 + BOOLEAN bLedOnScanning;
66764 + UCHAR LedStatus;
66765 +
66766 +/*****************************************************************************************/
66767 +/* 802.11 related parameters */
66768 +/*****************************************************************************************/
66769 + // outgoing BEACON frame buffer and corresponding TXD
66770 + TXWI_STRUC BeaconTxWI;
66771 + PUCHAR BeaconBuf;
66772 + USHORT BeaconOffset[HW_BEACON_MAX_COUNT];
66773 +
66774 + // pre-build PS-POLL and NULL frame upon link up. for efficiency purpose.
66775 + PSPOLL_FRAME PsPollFrame;
66776 + HEADER_802_11 NullFrame;
66777 +
66778 +#ifdef RT2870
66779 + TX_CONTEXT BeaconContext[BEACON_RING_SIZE];
66780 + TX_CONTEXT NullContext;
66781 + TX_CONTEXT PsPollContext;
66782 + TX_CONTEXT RTSContext;
66783 +#endif // RT2870 //
66784 +
66785 +
66786 +
66787 +//=========AP===========
66788 +
66789 +
66790 +//=======STA===========
66791 +#ifdef CONFIG_STA_SUPPORT
66792 +/* Modified by Wu Xi-Kun 4/21/2006 */
66793 + // -----------------------------------------------
66794 + // STA specific configuration & operation status
66795 + // used only when pAd->OpMode == OPMODE_STA
66796 + // -----------------------------------------------
66797 + STA_ADMIN_CONFIG StaCfg; // user desired settings
66798 + STA_ACTIVE_CONFIG StaActive; // valid only when ADHOC_ON(pAd) || INFRA_ON(pAd)
66799 + CHAR nickname[IW_ESSID_MAX_SIZE+1]; // nickname, only used in the iwconfig i/f
66800 + NDIS_MEDIA_STATE PreMediaState;
66801 +#endif // CONFIG_STA_SUPPORT //
66802 +
66803 +//=======Common===========
66804 + // OP mode: either AP or STA
66805 + UCHAR OpMode; // OPMODE_STA, OPMODE_AP
66806 +
66807 + NDIS_MEDIA_STATE IndicateMediaState; // Base on Indication state, default is NdisMediaStateDisConnected
66808 +
66809 +
66810 + // MAT related parameters
66811 +
66812 + // configuration: read from Registry & E2PROM
66813 + BOOLEAN bLocalAdminMAC; // Use user changed MAC
66814 + UCHAR PermanentAddress[MAC_ADDR_LEN]; // Factory default MAC address
66815 + UCHAR CurrentAddress[MAC_ADDR_LEN]; // User changed MAC address
66816 +
66817 + // ------------------------------------------------------
66818 + // common configuration to both OPMODE_STA and OPMODE_AP
66819 + // ------------------------------------------------------
66820 + COMMON_CONFIG CommonCfg;
66821 + MLME_STRUCT Mlme;
66822 +
66823 + // AP needs those vaiables for site survey feature.
66824 + MLME_AUX MlmeAux; // temporary settings used during MLME state machine
66825 + BSS_TABLE ScanTab; // store the latest SCAN result
66826 +
66827 + //About MacTab, the sta driver will use #0 and #1 for multicast and AP.
66828 + MAC_TABLE MacTab; // ASIC on-chip WCID entry table. At TX, ASIC always use key according to this on-chip table.
66829 + NDIS_SPIN_LOCK MacTabLock;
66830 +
66831 +#ifdef DOT11_N_SUPPORT
66832 + BA_TABLE BATable;
66833 +#endif // DOT11_N_SUPPORT //
66834 + NDIS_SPIN_LOCK BATabLock;
66835 + RALINK_TIMER_STRUCT RECBATimer;
66836 +
66837 + // encryption/decryption KEY tables
66838 + CIPHER_KEY SharedKey[MAX_MBSSID_NUM][4]; // STA always use SharedKey[BSS0][0..3]
66839 +
66840 + // RX re-assembly buffer for fragmentation
66841 + FRAGMENT_FRAME FragFrame; // Frame storage for fragment frame
66842 +
66843 + // various Counters
66844 + COUNTER_802_3 Counters8023; // 802.3 counters
66845 + COUNTER_802_11 WlanCounters; // 802.11 MIB counters
66846 + COUNTER_RALINK RalinkCounters; // Ralink propriety counters
66847 + COUNTER_DRS DrsCounters; // counters for Dynamic TX Rate Switching
66848 + PRIVATE_STRUC PrivateInfo; // Private information & counters
66849 +
66850 + // flags, see fRTMP_ADAPTER_xxx flags
66851 + ULONG Flags; // Represent current device status
66852 +
66853 + // current TX sequence #
66854 + USHORT Sequence;
66855 +
66856 +#ifdef UNDER_CE
66857 + NDIS_HANDLE hGiISR;
66858 +#endif
66859 +
66860 +
66861 + // Control disconnect / connect event generation
66862 + //+++Didn't used anymore
66863 + ULONG LinkDownTime;
66864 + //---
66865 + ULONG LastRxRate;
66866 + ULONG LastTxRate;
66867 + //+++Used only for Station
66868 + BOOLEAN bConfigChanged; // Config Change flag for the same SSID setting
66869 + //---
66870 +
66871 + ULONG ExtraInfo; // Extra information for displaying status
66872 + ULONG SystemErrorBitmap; // b0: E2PROM version error
66873 +
66874 + //+++Didn't used anymore
66875 + ULONG MacIcVersion; // MAC/BBP serial interface issue solved after ver.D
66876 + //---
66877 +
66878 + // ---------------------------
66879 + // System event log
66880 + // ---------------------------
66881 + RT_802_11_EVENT_TABLE EventTab;
66882 +
66883 +
66884 + BOOLEAN HTCEnable;
66885 +
66886 + /*****************************************************************************************/
66887 + /* Statistic related parameters */
66888 + /*****************************************************************************************/
66889 +#ifdef RT2870
66890 + ULONG BulkOutDataOneSecCount;
66891 + ULONG BulkInDataOneSecCount;
66892 + ULONG BulkLastOneSecCount; // BulkOutDataOneSecCount + BulkInDataOneSecCount
66893 + ULONG watchDogRxCnt;
66894 + ULONG watchDogRxOverFlowCnt;
66895 + ULONG watchDogTxPendingCnt[NUM_OF_TX_RING];
66896 +#endif // RT2870 //
66897 +
66898 + BOOLEAN bUpdateBcnCntDone;
66899 + ULONG watchDogMacDeadlock; // prevent MAC/BBP into deadlock condition
66900 + // ----------------------------
66901 + // DEBUG paramerts
66902 + // ----------------------------
66903 + //ULONG DebugSetting[4];
66904 + BOOLEAN bBanAllBaSetup;
66905 + BOOLEAN bPromiscuous;
66906 +
66907 + // ----------------------------
66908 + // rt2860c emulation-use Parameters
66909 + // ----------------------------
66910 + ULONG rtsaccu[30];
66911 + ULONG ctsaccu[30];
66912 + ULONG cfendaccu[30];
66913 + ULONG bacontent[16];
66914 + ULONG rxint[RX_RING_SIZE+1];
66915 + UCHAR rcvba[60];
66916 + BOOLEAN bLinkAdapt;
66917 + BOOLEAN bForcePrintTX;
66918 + BOOLEAN bForcePrintRX;
66919 + BOOLEAN bDisablescanning; //defined in RT2870 USB
66920 + BOOLEAN bStaFifoTest;
66921 + BOOLEAN bProtectionTest;
66922 + BOOLEAN bHCCATest;
66923 + BOOLEAN bGenOneHCCA;
66924 + BOOLEAN bBroadComHT;
66925 + //+++Following add from RT2870 USB.
66926 + ULONG BulkOutReq;
66927 + ULONG BulkOutComplete;
66928 + ULONG BulkOutCompleteOther;
66929 + ULONG BulkOutCompleteCancel; // seems not use now?
66930 + ULONG BulkInReq;
66931 + ULONG BulkInComplete;
66932 + ULONG BulkInCompleteFail;
66933 + //---
66934 +
66935 + struct wificonf WIFItestbed;
66936 +
66937 +#ifdef RALINK_ATE
66938 + ATE_INFO ate;
66939 +#ifdef RT2870
66940 + BOOLEAN ContinBulkOut; //ATE bulk out control
66941 + BOOLEAN ContinBulkIn; //ATE bulk in control
66942 + atomic_t BulkOutRemained;
66943 + atomic_t BulkInRemained;
66944 +#endif // RT2870 //
66945 +#endif // RALINK_ATE //
66946 +
66947 +#ifdef DOT11_N_SUPPORT
66948 + struct reordering_mpdu_pool mpdu_blk_pool;
66949 +#endif // DOT11_N_SUPPORT //
66950 +
66951 + ULONG OneSecondnonBEpackets; // record non BE packets per second
66952 +
66953 +#if WIRELESS_EXT >= 12
66954 + struct iw_statistics iw_stats;
66955 +#endif
66956 +
66957 + struct net_device_stats stats;
66958 +
66959 +#ifdef BLOCK_NET_IF
66960 + BLOCK_QUEUE_ENTRY blockQueueTab[NUM_OF_TX_RING];
66961 +#endif // BLOCK_NET_IF //
66962 +
66963 +
66964 +
66965 +#ifdef MULTIPLE_CARD_SUPPORT
66966 + INT32 MC_RowID;
66967 + UCHAR MC_FileName[256];
66968 +#endif // MULTIPLE_CARD_SUPPORT //
66969 +
66970 + ULONG TbttTickCount;
66971 +#ifdef PCI_MSI_SUPPORT
66972 + BOOLEAN HaveMsi;
66973 +#endif // PCI_MSI_SUPPORT //
66974 +
66975 +
66976 + UCHAR is_on;
66977 +
66978 +#define TIME_BASE (1000000/OS_HZ)
66979 +#define TIME_ONE_SECOND (1000000/TIME_BASE)
66980 + UCHAR flg_be_adjust;
66981 + ULONG be_adjust_last_time;
66982 +
66983 +#ifdef NINTENDO_AP
66984 + NINDO_CTRL_BLOCK nindo_ctrl_block;
66985 +#endif // NINTENDO_AP //
66986 +
66987 +
66988 +#ifdef IKANOS_VX_1X0
66989 + struct IKANOS_TX_INFO IkanosTxInfo;
66990 + struct IKANOS_TX_INFO IkanosRxInfo[MAX_MBSSID_NUM + MAX_WDS_ENTRY + MAX_APCLI_NUM + MAX_MESH_NUM];
66991 +#endif // IKANOS_VX_1X0 //
66992 +
66993 +
66994 +#ifdef DBG_DIAGNOSE
66995 + RtmpDiagStruct DiagStruct;
66996 +#endif // DBG_DIAGNOSE //
66997 +
66998 +
66999 + UINT8 PM_FlgSuspend;
67000 +
67001 +#ifdef RT30xx
67002 +//======efuse
67003 + BOOLEAN bUseEfuse;
67004 + BOOLEAN bEEPROMFile;
67005 +#endif // RT30xx //
67006 +
67007 +} RTMP_ADAPTER, *PRTMP_ADAPTER;
67008 +
67009 +//
67010 +// Cisco IAPP format
67011 +//
67012 +typedef struct _CISCO_IAPP_CONTENT_
67013 +{
67014 + USHORT Length; //IAPP Length
67015 + UCHAR MessageType; //IAPP type
67016 + UCHAR FunctionCode; //IAPP function type
67017 + UCHAR DestinaionMAC[MAC_ADDR_LEN];
67018 + UCHAR SourceMAC[MAC_ADDR_LEN];
67019 + USHORT Tag; //Tag(element IE) - Adjacent AP report
67020 + USHORT TagLength; //Length of element not including 4 byte header
67021 + UCHAR OUI[4]; //0x00, 0x40, 0x96, 0x00
67022 + UCHAR PreviousAP[MAC_ADDR_LEN]; //MAC Address of access point
67023 + USHORT Channel;
67024 + USHORT SsidLen;
67025 + UCHAR Ssid[MAX_LEN_OF_SSID];
67026 + USHORT Seconds; //Seconds that the client has been disassociated.
67027 +} CISCO_IAPP_CONTENT, *PCISCO_IAPP_CONTENT;
67028 +
67029 +#define DELAYINTMASK 0x0003fffb
67030 +#define INTMASK 0x0003fffb
67031 +#define IndMask 0x0003fffc
67032 +#define RxINT 0x00000005 // Delayed Rx or indivi rx
67033 +#define TxDataInt 0x000000fa // Delayed Tx or indivi tx
67034 +#define TxMgmtInt 0x00000102 // Delayed Tx or indivi tx
67035 +#define TxCoherent 0x00020000 // tx coherent
67036 +#define RxCoherent 0x00010000 // rx coherent
67037 +#define McuCommand 0x00000200 // mcu
67038 +#define PreTBTTInt 0x00001000 // Pre-TBTT interrupt
67039 +#define TBTTInt 0x00000800 // TBTT interrupt
67040 +#define GPTimeOutInt 0x00008000 // GPtimeout interrupt
67041 +#define AutoWakeupInt 0x00004000 // AutoWakeupInt interrupt
67042 +#define FifoStaFullInt 0x00002000 // fifo statistics full interrupt
67043 +
67044 +
67045 +typedef struct _RX_BLK_
67046 +{
67047 +// RXD_STRUC RxD; // sample
67048 + RT28XX_RXD_STRUC RxD;
67049 + PRXWI_STRUC pRxWI;
67050 + PHEADER_802_11 pHeader;
67051 + PNDIS_PACKET pRxPacket;
67052 + UCHAR *pData;
67053 + USHORT DataSize;
67054 + USHORT Flags;
67055 + UCHAR UserPriority; // for calculate TKIP MIC using
67056 +} RX_BLK;
67057 +
67058 +
67059 +#define RX_BLK_SET_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags |= _flag)
67060 +#define RX_BLK_TEST_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags & _flag)
67061 +#define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags &= ~(_flag))
67062 +
67063 +
67064 +#define fRX_WDS 0x0001
67065 +#define fRX_AMSDU 0x0002
67066 +#define fRX_ARALINK 0x0004
67067 +#define fRX_HTC 0x0008
67068 +#define fRX_PAD 0x0010
67069 +#define fRX_AMPDU 0x0020
67070 +#define fRX_QOS 0x0040
67071 +#define fRX_INFRA 0x0080
67072 +#define fRX_EAP 0x0100
67073 +#define fRX_MESH 0x0200
67074 +#define fRX_APCLI 0x0400
67075 +#define fRX_DLS 0x0800
67076 +#define fRX_WPI 0x1000
67077 +
67078 +#define LENGTH_AMSDU_SUBFRAMEHEAD 14
67079 +#define LENGTH_ARALINK_SUBFRAMEHEAD 14
67080 +#define LENGTH_ARALINK_HEADER_FIELD 2
67081 +
67082 +#define TX_UNKOWN_FRAME 0x00
67083 +#define TX_MCAST_FRAME 0x01
67084 +#define TX_LEGACY_FRAME 0x02
67085 +#define TX_AMPDU_FRAME 0x04
67086 +#define TX_AMSDU_FRAME 0x08
67087 +#define TX_RALINK_FRAME 0x10
67088 +#define TX_FRAG_FRAME 0x20
67089 +
67090 +
67091 +// Currently the sizeof(TX_BLK) is 148 bytes.
67092 +typedef struct _TX_BLK_
67093 +{
67094 + UCHAR QueIdx;
67095 + UCHAR TxFrameType; // Indicate the Transmission type of the all frames in one batch
67096 + UCHAR TotalFrameNum; // Total frame number want to send-out in one batch
67097 + USHORT TotalFragNum; // Total frame fragments required in one batch
67098 + USHORT TotalFrameLen; // Total length of all frames want to send-out in one batch
67099 +
67100 + QUEUE_HEADER TxPacketList;
67101 + MAC_TABLE_ENTRY *pMacEntry; // NULL: packet with 802.11 RA field is multicast/broadcast address
67102 + HTTRANSMIT_SETTING *pTransmit;
67103 +
67104 + // Following structure used for the characteristics of a specific packet.
67105 + PNDIS_PACKET pPacket;
67106 + PUCHAR pSrcBufHeader; // Reference to the head of sk_buff->data
67107 + PUCHAR pSrcBufData; // Reference to the sk_buff->data, will changed depends on hanlding progresss
67108 + UINT SrcBufLen; // Length of packet payload which not including Layer 2 header
67109 + PUCHAR pExtraLlcSnapEncap; // NULL means no extra LLC/SNAP is required
67110 + UCHAR HeaderBuf[80]; // TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP
67111 + UCHAR MpduHeaderLen; // 802.11 header length NOT including the padding
67112 + UCHAR HdrPadLen; // recording Header Padding Length;
67113 + UCHAR apidx; // The interface associated to this packet
67114 + UCHAR Wcid; // The MAC entry associated to this packet
67115 + UCHAR UserPriority; // priority class of packet
67116 + UCHAR FrameGap; // what kind of IFS this packet use
67117 + UCHAR MpduReqNum; // number of fragments of this frame
67118 + UCHAR TxRate; // TODO: Obsoleted? Should change to MCS?
67119 + UCHAR CipherAlg; // cipher alogrithm
67120 + PCIPHER_KEY pKey;
67121 +
67122 +
67123 +
67124 + USHORT Flags; //See following definitions for detail.
67125 +
67126 + //YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer.
67127 + ULONG Priv; // Hardware specific value saved in here.
67128 +} TX_BLK, *PTX_BLK;
67129 +
67130 +
67131 +#define fTX_bRtsRequired 0x0001 // Indicate if need send RTS frame for protection. Not used in RT2860/RT2870.
67132 +#define fTX_bAckRequired 0x0002 // the packet need ack response
67133 +#define fTX_bPiggyBack 0x0004 // Legacy device use Piggback or not
67134 +#define fTX_bHTRate 0x0008 // allow to use HT rate
67135 +//#define fTX_bForceLowRate 0x0010 // force to use Low Rate
67136 +#define fTX_bForceNonQoS 0x0010 // force to transmit frame without WMM-QoS in HT mode
67137 +#define fTX_bAllowFrag 0x0020 // allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment
67138 +#define fTX_bMoreData 0x0040 // there are more data packets in PowerSave Queue
67139 +#define fTX_bWMM 0x0080 // QOS Data
67140 +
67141 +#define fTX_bClearEAPFrame 0x0100
67142 +
67143 +
67144 +#ifdef CONFIG_STA_SUPPORT
67145 +#endif // CONFIG_STA_SUPPORT //
67146 +
67147 +
67148 +
67149 +#define TX_BLK_ASSIGN_FLAG(_pTxBlk, _flag, value) \
67150 + do { \
67151 + if (value) \
67152 + (_pTxBlk->Flags |= _flag) \
67153 + else \
67154 + (_pTxBlk->Flags &= ~(_flag)) \
67155 + }while(0)
67156 +
67157 +#define TX_BLK_SET_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags |= _flag)
67158 +#define TX_BLK_TEST_FLAG(_pTxBlk, _flag) (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
67159 +#define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags &= ~(_flag))
67160 +
67161 +
67162 +
67163 +
67164 +
67165 +//------------------------------------------------------------------------------------------
67166 +
67167 +
67168 +
67169 +#ifdef RT_BIG_ENDIAN
67170 +static inline VOID WriteBackToDescriptor(
67171 + IN PUCHAR Dest,
67172 + IN PUCHAR Src,
67173 + IN BOOLEAN DoEncrypt,
67174 + IN ULONG DescriptorType)
67175 +{
67176 + UINT32 *p1, *p2;
67177 +
67178 + p1 = ((UINT32 *)Dest);
67179 + p2 = ((UINT32 *)Src);
67180 +
67181 + *p1 = *p2;
67182 + *(p1+2) = *(p2+2);
67183 + *(p1+3) = *(p2+3);
67184 + *(p1+1) = *(p2+1); // Word 1; this must be written back last
67185 +}
67186 +
67187 +/*
67188 + ========================================================================
67189 +
67190 + Routine Description:
67191 + Endian conversion of Tx/Rx descriptor .
67192 +
67193 + Arguments:
67194 + pAd Pointer to our adapter
67195 + pData Pointer to Tx/Rx descriptor
67196 + DescriptorType Direction of the frame
67197 +
67198 + Return Value:
67199 + None
67200 +
67201 + Note:
67202 + Call this function when read or update descriptor
67203 + ========================================================================
67204 +*/
67205 +static inline VOID RTMPWIEndianChange(
67206 + IN PUCHAR pData,
67207 + IN ULONG DescriptorType)
67208 +{
67209 + int size;
67210 + int i;
67211 +
67212 + size = ((DescriptorType == TYPE_TXWI) ? TXWI_SIZE : RXWI_SIZE);
67213 +
67214 + if(DescriptorType == TYPE_TXWI)
67215 + {
67216 + *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData))); // Byte 0~3
67217 + *((UINT32 *)(pData + 4)) = SWAP32(*((UINT32 *)(pData+4))); // Byte 4~7
67218 + }
67219 + else
67220 + {
67221 + for(i=0; i < size/4 ; i++)
67222 + *(((UINT32 *)pData) +i) = SWAP32(*(((UINT32 *)pData)+i));
67223 + }
67224 +}
67225 +
67226 +/*
67227 + ========================================================================
67228 +
67229 + Routine Description:
67230 + Endian conversion of Tx/Rx descriptor .
67231 +
67232 + Arguments:
67233 + pAd Pointer to our adapter
67234 + pData Pointer to Tx/Rx descriptor
67235 + DescriptorType Direction of the frame
67236 +
67237 + Return Value:
67238 + None
67239 +
67240 + Note:
67241 + Call this function when read or update descriptor
67242 + ========================================================================
67243 +*/
67244 +
67245 +#ifdef RT2870
67246 +static inline VOID RTMPDescriptorEndianChange(
67247 + IN PUCHAR pData,
67248 + IN ULONG DescriptorType)
67249 +{
67250 + *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData)));
67251 +}
67252 +#endif // RT2870 //
67253 +/*
67254 + ========================================================================
67255 +
67256 + Routine Description:
67257 + Endian conversion of all kinds of 802.11 frames .
67258 +
67259 + Arguments:
67260 + pAd Pointer to our adapter
67261 + pData Pointer to the 802.11 frame structure
67262 + Dir Direction of the frame
67263 + FromRxDoneInt Caller is from RxDone interrupt
67264 +
67265 + Return Value:
67266 + None
67267 +
67268 + Note:
67269 + Call this function when read or update buffer data
67270 + ========================================================================
67271 +*/
67272 +static inline VOID RTMPFrameEndianChange(
67273 + IN PRTMP_ADAPTER pAd,
67274 + IN PUCHAR pData,
67275 + IN ULONG Dir,
67276 + IN BOOLEAN FromRxDoneInt)
67277 +{
67278 + PHEADER_802_11 pFrame;
67279 + PUCHAR pMacHdr;
67280 +
67281 + // swab 16 bit fields - Frame Control field
67282 + if(Dir == DIR_READ)
67283 + {
67284 + *(USHORT *)pData = SWAP16(*(USHORT *)pData);
67285 + }
67286 +
67287 + pFrame = (PHEADER_802_11) pData;
67288 + pMacHdr = (PUCHAR) pFrame;
67289 +
67290 + // swab 16 bit fields - Duration/ID field
67291 + *(USHORT *)(pMacHdr + 2) = SWAP16(*(USHORT *)(pMacHdr + 2));
67292 +
67293 + // swab 16 bit fields - Sequence Control field
67294 + *(USHORT *)(pMacHdr + 22) = SWAP16(*(USHORT *)(pMacHdr + 22));
67295 +
67296 + if(pFrame->FC.Type == BTYPE_MGMT)
67297 + {
67298 + switch(pFrame->FC.SubType)
67299 + {
67300 + case SUBTYPE_ASSOC_REQ:
67301 + case SUBTYPE_REASSOC_REQ:
67302 + // swab 16 bit fields - CapabilityInfo field
67303 + pMacHdr += sizeof(HEADER_802_11);
67304 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67305 +
67306 + // swab 16 bit fields - Listen Interval field
67307 + pMacHdr += 2;
67308 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67309 + break;
67310 +
67311 + case SUBTYPE_ASSOC_RSP:
67312 + case SUBTYPE_REASSOC_RSP:
67313 + // swab 16 bit fields - CapabilityInfo field
67314 + pMacHdr += sizeof(HEADER_802_11);
67315 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67316 +
67317 + // swab 16 bit fields - Status Code field
67318 + pMacHdr += 2;
67319 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67320 +
67321 + // swab 16 bit fields - AID field
67322 + pMacHdr += 2;
67323 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67324 + break;
67325 +
67326 + case SUBTYPE_AUTH:
67327 + // If from APHandleRxDoneInterrupt routine, it is still a encrypt format.
67328 + // The convertion is delayed to RTMPHandleDecryptionDoneInterrupt.
67329 + if(!FromRxDoneInt && pFrame->FC.Wep == 1)
67330 + break;
67331 + else
67332 + {
67333 + // swab 16 bit fields - Auth Alg No. field
67334 + pMacHdr += sizeof(HEADER_802_11);
67335 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67336 +
67337 + // swab 16 bit fields - Auth Seq No. field
67338 + pMacHdr += 2;
67339 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67340 +
67341 + // swab 16 bit fields - Status Code field
67342 + pMacHdr += 2;
67343 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67344 + }
67345 + break;
67346 +
67347 + case SUBTYPE_BEACON:
67348 + case SUBTYPE_PROBE_RSP:
67349 + // swab 16 bit fields - BeaconInterval field
67350 + pMacHdr += (sizeof(HEADER_802_11) + TIMESTAMP_LEN);
67351 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67352 +
67353 + // swab 16 bit fields - CapabilityInfo field
67354 + pMacHdr += sizeof(USHORT);
67355 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67356 + break;
67357 +
67358 + case SUBTYPE_DEAUTH:
67359 + case SUBTYPE_DISASSOC:
67360 + // swab 16 bit fields - Reason code field
67361 + pMacHdr += sizeof(HEADER_802_11);
67362 + *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
67363 + break;
67364 + }
67365 + }
67366 + else if( pFrame->FC.Type == BTYPE_DATA )
67367 + {
67368 + }
67369 + else if(pFrame->FC.Type == BTYPE_CNTL)
67370 + {
67371 + switch(pFrame->FC.SubType)
67372 + {
67373 + case SUBTYPE_BLOCK_ACK_REQ:
67374 + {
67375 + PFRAME_BA_REQ pBAReq = (PFRAME_BA_REQ)pFrame;
67376 + *(USHORT *)(&pBAReq->BARControl) = SWAP16(*(USHORT *)(&pBAReq->BARControl));
67377 + pBAReq->BAStartingSeq.word = SWAP16(pBAReq->BAStartingSeq.word);
67378 + }
67379 + break;
67380 + case SUBTYPE_BLOCK_ACK:
67381 + // For Block Ack packet, the HT_CONTROL field is in the same offset with Addr3
67382 + *(UINT32 *)(&pFrame->Addr3[0]) = SWAP32(*(UINT32 *)(&pFrame->Addr3[0]));
67383 + break;
67384 +
67385 + case SUBTYPE_ACK:
67386 + //For ACK packet, the HT_CONTROL field is in the same offset with Addr2
67387 + *(UINT32 *)(&pFrame->Addr2[0])= SWAP32(*(UINT32 *)(&pFrame->Addr2[0]));
67388 + break;
67389 + }
67390 + }
67391 + else
67392 + {
67393 + DBGPRINT(RT_DEBUG_ERROR,("Invalid Frame Type!!!\n"));
67394 + }
67395 +
67396 + // swab 16 bit fields - Frame Control
67397 + if(Dir == DIR_WRITE)
67398 + {
67399 + *(USHORT *)pData = SWAP16(*(USHORT *)pData);
67400 + }
67401 +}
67402 +#endif // RT_BIG_ENDIAN //
67403 +
67404 +
67405 +static inline VOID ConvertMulticastIP2MAC(
67406 + IN PUCHAR pIpAddr,
67407 + IN PUCHAR *ppMacAddr,
67408 + IN UINT16 ProtoType)
67409 +{
67410 + if (pIpAddr == NULL)
67411 + return;
67412 +
67413 + if (ppMacAddr == NULL || *ppMacAddr == NULL)
67414 + return;
67415 +
67416 + switch (ProtoType)
67417 + {
67418 + case ETH_P_IPV6:
67419 +// memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
67420 + *(*ppMacAddr) = 0x33;
67421 + *(*ppMacAddr + 1) = 0x33;
67422 + *(*ppMacAddr + 2) = pIpAddr[12];
67423 + *(*ppMacAddr + 3) = pIpAddr[13];
67424 + *(*ppMacAddr + 4) = pIpAddr[14];
67425 + *(*ppMacAddr + 5) = pIpAddr[15];
67426 + break;
67427 +
67428 + case ETH_P_IP:
67429 + default:
67430 +// memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
67431 + *(*ppMacAddr) = 0x01;
67432 + *(*ppMacAddr + 1) = 0x00;
67433 + *(*ppMacAddr + 2) = 0x5e;
67434 + *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
67435 + *(*ppMacAddr + 4) = pIpAddr[2];
67436 + *(*ppMacAddr + 5) = pIpAddr[3];
67437 + break;
67438 + }
67439 +
67440 + return;
67441 +}
67442 +
67443 +BOOLEAN RTMPCheckForHang(
67444 + IN NDIS_HANDLE MiniportAdapterContext
67445 + );
67446 +
67447 +VOID RTMPHalt(
67448 + IN NDIS_HANDLE MiniportAdapterContext
67449 + );
67450 +
67451 +//
67452 +// Private routines in rtmp_init.c
67453 +//
67454 +NDIS_STATUS RTMPAllocAdapterBlock(
67455 + IN PVOID handle,
67456 + OUT PRTMP_ADAPTER *ppAdapter
67457 + );
67458 +
67459 +NDIS_STATUS RTMPAllocTxRxRingMemory(
67460 + IN PRTMP_ADAPTER pAd
67461 + );
67462 +
67463 +NDIS_STATUS RTMPFindAdapter(
67464 + IN PRTMP_ADAPTER pAd,
67465 + IN NDIS_HANDLE WrapperConfigurationContext
67466 + );
67467 +
67468 +NDIS_STATUS RTMPReadParametersHook(
67469 + IN PRTMP_ADAPTER pAd
67470 + );
67471 +
67472 +VOID RTMPFreeAdapter(
67473 + IN PRTMP_ADAPTER pAd
67474 + );
67475 +
67476 +NDIS_STATUS NICReadRegParameters(
67477 + IN PRTMP_ADAPTER pAd,
67478 + IN NDIS_HANDLE WrapperConfigurationContext
67479 + );
67480 +
67481 +#ifdef RT30xx
67482 +VOID NICInitRT30xxRFRegisters(
67483 + IN PRTMP_ADAPTER pAd);
67484 +#endif // RT30xx //
67485 +
67486 +VOID NICReadEEPROMParameters(
67487 + IN PRTMP_ADAPTER pAd,
67488 + IN PUCHAR mac_addr);
67489 +
67490 +VOID NICInitAsicFromEEPROM(
67491 + IN PRTMP_ADAPTER pAd);
67492 +
67493 +VOID NICInitTxRxRingAndBacklogQueue(
67494 + IN PRTMP_ADAPTER pAd);
67495 +
67496 +NDIS_STATUS NICInitializeAdapter(
67497 + IN PRTMP_ADAPTER pAd,
67498 + IN BOOLEAN bHardReset);
67499 +
67500 +NDIS_STATUS NICInitializeAsic(
67501 + IN PRTMP_ADAPTER pAd,
67502 + IN BOOLEAN bHardReset);
67503 +
67504 +VOID NICIssueReset(
67505 + IN PRTMP_ADAPTER pAd);
67506 +
67507 +VOID RTMPRingCleanUp(
67508 + IN PRTMP_ADAPTER pAd,
67509 + IN UCHAR RingType);
67510 +
67511 +VOID RxTest(
67512 + IN PRTMP_ADAPTER pAd);
67513 +
67514 +NDIS_STATUS DbgSendPacket(
67515 + IN PRTMP_ADAPTER pAd,
67516 + IN PNDIS_PACKET pPacket);
67517 +
67518 +VOID UserCfgInit(
67519 + IN PRTMP_ADAPTER pAd);
67520 +
67521 +VOID NICResetFromError(
67522 + IN PRTMP_ADAPTER pAd);
67523 +
67524 +VOID NICEraseFirmware(
67525 + IN PRTMP_ADAPTER pAd);
67526 +
67527 +NDIS_STATUS NICLoadFirmware(
67528 + IN PRTMP_ADAPTER pAd);
67529 +
67530 +NDIS_STATUS NICLoadRateSwitchingParams(
67531 + IN PRTMP_ADAPTER pAd);
67532 +
67533 +BOOLEAN NICCheckForHang(
67534 + IN PRTMP_ADAPTER pAd);
67535 +
67536 +VOID NICUpdateFifoStaCounters(
67537 + IN PRTMP_ADAPTER pAd);
67538 +
67539 +VOID NICUpdateRawCounters(
67540 + IN PRTMP_ADAPTER pAd);
67541 +
67542 +ULONG RTMPNotAllZero(
67543 + IN PVOID pSrc1,
67544 + IN ULONG Length);
67545 +
67546 +VOID RTMPZeroMemory(
67547 + IN PVOID pSrc,
67548 + IN ULONG Length);
67549 +
67550 +ULONG RTMPCompareMemory(
67551 + IN PVOID pSrc1,
67552 + IN PVOID pSrc2,
67553 + IN ULONG Length);
67554 +
67555 +VOID RTMPMoveMemory(
67556 + OUT PVOID pDest,
67557 + IN PVOID pSrc,
67558 + IN ULONG Length);
67559 +
67560 +VOID AtoH(
67561 + char *src,
67562 + UCHAR *dest,
67563 + int destlen);
67564 +
67565 +UCHAR BtoH(
67566 + char ch);
67567 +
67568 +VOID RTMPPatchMacBbpBug(
67569 + IN PRTMP_ADAPTER pAd);
67570 +
67571 +VOID RTMPPatchCardBus(
67572 + IN PRTMP_ADAPTER pAdapter);
67573 +
67574 +VOID RTMPPatchRalinkCardBus(
67575 + IN PRTMP_ADAPTER pAdapter,
67576 + IN ULONG Bus);
67577 +
67578 +ULONG RTMPReadCBConfig(
67579 + IN ULONG Bus,
67580 + IN ULONG Slot,
67581 + IN ULONG Func,
67582 + IN ULONG Offset);
67583 +
67584 +VOID RTMPWriteCBConfig(
67585 + IN ULONG Bus,
67586 + IN ULONG Slot,
67587 + IN ULONG Func,
67588 + IN ULONG Offset,
67589 + IN ULONG Value);
67590 +
67591 +VOID RTMPInitTimer(
67592 + IN PRTMP_ADAPTER pAd,
67593 + IN PRALINK_TIMER_STRUCT pTimer,
67594 + IN PVOID pTimerFunc,
67595 + IN PVOID pData,
67596 + IN BOOLEAN Repeat);
67597 +
67598 +VOID RTMPSetTimer(
67599 + IN PRALINK_TIMER_STRUCT pTimer,
67600 + IN ULONG Value);
67601 +
67602 +
67603 +VOID RTMPModTimer(
67604 + IN PRALINK_TIMER_STRUCT pTimer,
67605 + IN ULONG Value);
67606 +
67607 +VOID RTMPCancelTimer(
67608 + IN PRALINK_TIMER_STRUCT pTimer,
67609 + OUT BOOLEAN *pCancelled);
67610 +
67611 +VOID RTMPSetLED(
67612 + IN PRTMP_ADAPTER pAd,
67613 + IN UCHAR Status);
67614 +
67615 +VOID RTMPSetSignalLED(
67616 + IN PRTMP_ADAPTER pAd,
67617 + IN NDIS_802_11_RSSI Dbm);
67618 +
67619 +VOID RTMPEnableRxTx(
67620 + IN PRTMP_ADAPTER pAd);
67621 +
67622 +//
67623 +// prototype in action.c
67624 +//
67625 +VOID ActionStateMachineInit(
67626 + IN PRTMP_ADAPTER pAd,
67627 + IN STATE_MACHINE *S,
67628 + OUT STATE_MACHINE_FUNC Trans[]);
67629 +
67630 +VOID MlmeADDBAAction(
67631 + IN PRTMP_ADAPTER pAd,
67632 + IN MLME_QUEUE_ELEM *Elem);
67633 +
67634 +VOID MlmeDELBAAction(
67635 + IN PRTMP_ADAPTER pAd,
67636 + IN MLME_QUEUE_ELEM *Elem);
67637 +
67638 +VOID MlmeDLSAction(
67639 + IN PRTMP_ADAPTER pAd,
67640 + IN MLME_QUEUE_ELEM *Elem);
67641 +
67642 +VOID MlmeInvalidAction(
67643 + IN PRTMP_ADAPTER pAd,
67644 + IN MLME_QUEUE_ELEM *Elem);
67645 +
67646 +VOID MlmeQOSAction(
67647 + IN PRTMP_ADAPTER pAd,
67648 + IN MLME_QUEUE_ELEM *Elem);
67649 +
67650 +#ifdef DOT11_N_SUPPORT
67651 +VOID PeerAddBAReqAction(
67652 + IN PRTMP_ADAPTER pAd,
67653 + IN MLME_QUEUE_ELEM *Elem);
67654 +
67655 +VOID PeerAddBARspAction(
67656 + IN PRTMP_ADAPTER pAd,
67657 + IN MLME_QUEUE_ELEM *Elem);
67658 +
67659 +VOID PeerDelBAAction(
67660 + IN PRTMP_ADAPTER pAd,
67661 + IN MLME_QUEUE_ELEM *Elem);
67662 +
67663 +VOID PeerBAAction(
67664 + IN PRTMP_ADAPTER pAd,
67665 + IN MLME_QUEUE_ELEM *Elem);
67666 +#endif // DOT11_N_SUPPORT //
67667 +
67668 +VOID SendPSMPAction(
67669 + IN PRTMP_ADAPTER pAd,
67670 + IN UCHAR Wcid,
67671 + IN UCHAR Psmp);
67672 +
67673 +
67674 +#ifdef DOT11N_DRAFT3
67675 +VOID SendBSS2040CoexistMgmtAction(
67676 + IN PRTMP_ADAPTER pAd,
67677 + IN UCHAR Wcid,
67678 + IN UCHAR apidx,
67679 + IN UCHAR InfoReq);
67680 +
67681 +VOID SendNotifyBWActionFrame(
67682 + IN PRTMP_ADAPTER pAd,
67683 + IN UCHAR Wcid,
67684 + IN UCHAR apidx);
67685 +
67686 +BOOLEAN ChannelSwitchSanityCheck(
67687 + IN PRTMP_ADAPTER pAd,
67688 + IN UCHAR Wcid,
67689 + IN UCHAR NewChannel,
67690 + IN UCHAR Secondary);
67691 +
67692 +VOID ChannelSwitchAction(
67693 + IN PRTMP_ADAPTER pAd,
67694 + IN UCHAR Wcid,
67695 + IN UCHAR Channel,
67696 + IN UCHAR Secondary);
67697 +
67698 +ULONG BuildIntolerantChannelRep(
67699 + IN PRTMP_ADAPTER pAd,
67700 + IN PUCHAR pDest);
67701 +
67702 +VOID Update2040CoexistFrameAndNotify(
67703 + IN PRTMP_ADAPTER pAd,
67704 + IN UCHAR Wcid,
67705 + IN BOOLEAN bAddIntolerantCha);
67706 +
67707 +VOID Send2040CoexistAction(
67708 + IN PRTMP_ADAPTER pAd,
67709 + IN UCHAR Wcid,
67710 + IN BOOLEAN bAddIntolerantCha);
67711 +#endif // DOT11N_DRAFT3 //
67712 +
67713 +VOID PeerRMAction(
67714 + IN PRTMP_ADAPTER pAd,
67715 + IN MLME_QUEUE_ELEM *Elem);
67716 +
67717 +VOID PeerPublicAction(
67718 + IN PRTMP_ADAPTER pAd,
67719 + IN MLME_QUEUE_ELEM *Elem);
67720 +
67721 +#ifdef CONFIG_STA_SUPPORT
67722 +VOID StaPublicAction(
67723 + IN PRTMP_ADAPTER pAd,
67724 + IN UCHAR Bss2040Coexist);
67725 +#endif // CONFIG_STA_SUPPORT //
67726 +
67727 +
67728 +VOID PeerBSSTranAction(
67729 + IN PRTMP_ADAPTER pAd,
67730 + IN MLME_QUEUE_ELEM *Elem);
67731 +
67732 +#ifdef DOT11_N_SUPPORT
67733 +VOID PeerHTAction(
67734 + IN PRTMP_ADAPTER pAd,
67735 + IN MLME_QUEUE_ELEM *Elem);
67736 +#endif // DOT11_N_SUPPORT //
67737 +
67738 +VOID PeerQOSAction(
67739 + IN PRTMP_ADAPTER pAd,
67740 + IN MLME_QUEUE_ELEM *Elem);
67741 +
67742 +#ifdef QOS_DLS_SUPPORT
67743 +VOID PeerDLSAction(
67744 + IN PRTMP_ADAPTER pAd,
67745 + IN MLME_QUEUE_ELEM *Elem);
67746 +#endif // QOS_DLS_SUPPORT //
67747 +
67748 +#ifdef CONFIG_STA_SUPPORT
67749 +#ifdef QOS_DLS_SUPPORT
67750 +VOID DlsParmFill(
67751 + IN PRTMP_ADAPTER pAd,
67752 + IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
67753 + IN PRT_802_11_DLS pDls,
67754 + IN USHORT reason);
67755 +#endif // QOS_DLS_SUPPORT //
67756 +#endif // CONFIG_STA_SUPPORT //
67757 +
67758 +#ifdef DOT11_N_SUPPORT
67759 +VOID RECBATimerTimeout(
67760 + IN PVOID SystemSpecific1,
67761 + IN PVOID FunctionContext,
67762 + IN PVOID SystemSpecific2,
67763 + IN PVOID SystemSpecific3);
67764 +
67765 +VOID ORIBATimerTimeout(
67766 + IN PRTMP_ADAPTER pAd);
67767 +
67768 +VOID SendRefreshBAR(
67769 + IN PRTMP_ADAPTER pAd,
67770 + IN MAC_TABLE_ENTRY *pEntry);
67771 +#endif // DOT11_N_SUPPORT //
67772 +
67773 +VOID ActHeaderInit(
67774 + IN PRTMP_ADAPTER pAd,
67775 + IN OUT PHEADER_802_11 pHdr80211,
67776 + IN PUCHAR Addr1,
67777 + IN PUCHAR Addr2,
67778 + IN PUCHAR Addr3);
67779 +
67780 +VOID BarHeaderInit(
67781 + IN PRTMP_ADAPTER pAd,
67782 + IN OUT PFRAME_BAR pCntlBar,
67783 + IN PUCHAR pDA,
67784 + IN PUCHAR pSA);
67785 +
67786 +VOID InsertActField(
67787 + IN PRTMP_ADAPTER pAd,
67788 + OUT PUCHAR pFrameBuf,
67789 + OUT PULONG pFrameLen,
67790 + IN UINT8 Category,
67791 + IN UINT8 ActCode);
67792 +
67793 +BOOLEAN QosBADataParse(
67794 + IN PRTMP_ADAPTER pAd,
67795 + IN BOOLEAN bAMSDU,
67796 + IN PUCHAR p8023Header,
67797 + IN UCHAR WCID,
67798 + IN UCHAR TID,
67799 + IN USHORT Sequence,
67800 + IN UCHAR DataOffset,
67801 + IN USHORT Datasize,
67802 + IN UINT CurRxIndex);
67803 +
67804 +#ifdef DOT11_N_SUPPORT
67805 +BOOLEAN CntlEnqueueForRecv(
67806 + IN PRTMP_ADAPTER pAd,
67807 + IN ULONG Wcid,
67808 + IN ULONG MsgLen,
67809 + IN PFRAME_BA_REQ pMsg);
67810 +
67811 +VOID BaAutoManSwitch(
67812 + IN PRTMP_ADAPTER pAd);
67813 +#endif // DOT11_N_SUPPORT //
67814 +
67815 +VOID HTIOTCheck(
67816 + IN PRTMP_ADAPTER pAd,
67817 + IN UCHAR BatRecIdx);
67818 +
67819 +//
67820 +// Private routines in rtmp_data.c
67821 +//
67822 +BOOLEAN RTMPHandleRxDoneInterrupt(
67823 + IN PRTMP_ADAPTER pAd);
67824 +
67825 +VOID RTMPHandleTxDoneInterrupt(
67826 + IN PRTMP_ADAPTER pAd);
67827 +
67828 +BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(
67829 + IN PRTMP_ADAPTER pAd,
67830 + IN INT_SOURCE_CSR_STRUC TxRingBitmap);
67831 +
67832 +VOID RTMPHandleMgmtRingDmaDoneInterrupt(
67833 + IN PRTMP_ADAPTER pAd);
67834 +
67835 +VOID RTMPHandleTBTTInterrupt(
67836 + IN PRTMP_ADAPTER pAd);
67837 +
67838 +VOID RTMPHandlePreTBTTInterrupt(
67839 + IN PRTMP_ADAPTER pAd);
67840 +
67841 +void RTMPHandleTwakeupInterrupt(
67842 + IN PRTMP_ADAPTER pAd);
67843 +
67844 +VOID RTMPHandleRxCoherentInterrupt(
67845 + IN PRTMP_ADAPTER pAd);
67846 +
67847 +BOOLEAN TxFrameIsAggregatible(
67848 + IN PRTMP_ADAPTER pAd,
67849 + IN PUCHAR pPrevAddr1,
67850 + IN PUCHAR p8023hdr);
67851 +
67852 +BOOLEAN PeerIsAggreOn(
67853 + IN PRTMP_ADAPTER pAd,
67854 + IN ULONG TxRate,
67855 + IN PMAC_TABLE_ENTRY pMacEntry);
67856 +
67857 +NDIS_STATUS Sniff2BytesFromNdisBuffer(
67858 + IN PNDIS_BUFFER pFirstBuffer,
67859 + IN UCHAR DesiredOffset,
67860 + OUT PUCHAR pByte0,
67861 + OUT PUCHAR pByte1);
67862 +
67863 +NDIS_STATUS STASendPacket(
67864 + IN PRTMP_ADAPTER pAd,
67865 + IN PNDIS_PACKET pPacket);
67866 +
67867 +VOID STASendPackets(
67868 + IN NDIS_HANDLE MiniportAdapterContext,
67869 + IN PPNDIS_PACKET ppPacketArray,
67870 + IN UINT NumberOfPackets);
67871 +
67872 +VOID RTMPDeQueuePacket(
67873 + IN PRTMP_ADAPTER pAd,
67874 + IN BOOLEAN bIntContext,
67875 + IN UCHAR QueIdx,
67876 + IN UCHAR Max_Tx_Packets);
67877 +
67878 +NDIS_STATUS RTMPHardTransmit(
67879 + IN PRTMP_ADAPTER pAd,
67880 + IN PNDIS_PACKET pPacket,
67881 + IN UCHAR QueIdx,
67882 + OUT PULONG pFreeTXDLeft);
67883 +
67884 +NDIS_STATUS STAHardTransmit(
67885 + IN PRTMP_ADAPTER pAd,
67886 + IN TX_BLK *pTxBlk,
67887 + IN UCHAR QueIdx);
67888 +
67889 +VOID STARxEAPOLFrameIndicate(
67890 + IN PRTMP_ADAPTER pAd,
67891 + IN MAC_TABLE_ENTRY *pEntry,
67892 + IN RX_BLK *pRxBlk,
67893 + IN UCHAR FromWhichBSSID);
67894 +
67895 +NDIS_STATUS RTMPFreeTXDRequest(
67896 + IN PRTMP_ADAPTER pAd,
67897 + IN UCHAR RingType,
67898 + IN UCHAR NumberRequired,
67899 + IN PUCHAR FreeNumberIs);
67900 +
67901 +NDIS_STATUS MlmeHardTransmit(
67902 + IN PRTMP_ADAPTER pAd,
67903 + IN UCHAR QueIdx,
67904 + IN PNDIS_PACKET pPacket);
67905 +
67906 +NDIS_STATUS MlmeHardTransmitMgmtRing(
67907 + IN PRTMP_ADAPTER pAd,
67908 + IN UCHAR QueIdx,
67909 + IN PNDIS_PACKET pPacket);
67910 +
67911 +NDIS_STATUS MlmeHardTransmitTxRing(
67912 + IN PRTMP_ADAPTER pAd,
67913 + IN UCHAR QueIdx,
67914 + IN PNDIS_PACKET pPacket);
67915 +
67916 +USHORT RTMPCalcDuration(
67917 + IN PRTMP_ADAPTER pAd,
67918 + IN UCHAR Rate,
67919 + IN ULONG Size);
67920 +
67921 +VOID RTMPWriteTxWI(
67922 + IN PRTMP_ADAPTER pAd,
67923 + IN PTXWI_STRUC pTxWI,
67924 + IN BOOLEAN FRAG,
67925 + IN BOOLEAN CFACK,
67926 + IN BOOLEAN InsTimestamp,
67927 + IN BOOLEAN AMPDU,
67928 + IN BOOLEAN Ack,
67929 + IN BOOLEAN NSeq, // HW new a sequence.
67930 + IN UCHAR BASize,
67931 + IN UCHAR WCID,
67932 + IN ULONG Length,
67933 + IN UCHAR PID,
67934 + IN UCHAR TID,
67935 + IN UCHAR TxRate,
67936 + IN UCHAR Txopmode,
67937 + IN BOOLEAN CfAck,
67938 + IN HTTRANSMIT_SETTING *pTransmit);
67939 +
67940 +
67941 +VOID RTMPWriteTxWI_Data(
67942 + IN PRTMP_ADAPTER pAd,
67943 + IN OUT PTXWI_STRUC pTxWI,
67944 + IN TX_BLK *pTxBlk);
67945 +
67946 +
67947 +VOID RTMPWriteTxWI_Cache(
67948 + IN PRTMP_ADAPTER pAd,
67949 + IN OUT PTXWI_STRUC pTxWI,
67950 + IN TX_BLK *pTxBlk);
67951 +
67952 +VOID RTMPWriteTxDescriptor(
67953 + IN PRTMP_ADAPTER pAd,
67954 + IN PTXD_STRUC pTxD,
67955 + IN BOOLEAN bWIV,
67956 + IN UCHAR QSEL);
67957 +
67958 +VOID RTMPSuspendMsduTransmission(
67959 + IN PRTMP_ADAPTER pAd);
67960 +
67961 +VOID RTMPResumeMsduTransmission(
67962 + IN PRTMP_ADAPTER pAd);
67963 +
67964 +NDIS_STATUS MiniportMMRequest(
67965 + IN PRTMP_ADAPTER pAd,
67966 + IN UCHAR QueIdx,
67967 + IN PUCHAR pData,
67968 + IN UINT Length);
67969 +
67970 +NDIS_STATUS MiniportDataMMRequest(
67971 + IN PRTMP_ADAPTER pAd,
67972 + IN UCHAR QueIdx,
67973 + IN PUCHAR pData,
67974 + IN UINT Length);
67975 +
67976 +VOID RTMPSendNullFrame(
67977 + IN PRTMP_ADAPTER pAd,
67978 + IN UCHAR TxRate,
67979 + IN BOOLEAN bQosNull);
67980 +
67981 +VOID RTMPSendDisassociationFrame(
67982 + IN PRTMP_ADAPTER pAd);
67983 +
67984 +VOID RTMPSendRTSFrame(
67985 + IN PRTMP_ADAPTER pAd,
67986 + IN PUCHAR pDA,
67987 + IN unsigned int NextMpduSize,
67988 + IN UCHAR TxRate,
67989 + IN UCHAR RTSRate,
67990 + IN USHORT AckDuration,
67991 + IN UCHAR QueIdx,
67992 + IN UCHAR FrameGap);
67993 +
67994 +
67995 +NDIS_STATUS RTMPApplyPacketFilter(
67996 + IN PRTMP_ADAPTER pAd,
67997 + IN PRT28XX_RXD_STRUC pRxD,
67998 + IN PHEADER_802_11 pHeader);
67999 +
68000 +PQUEUE_HEADER RTMPCheckTxSwQueue(
68001 + IN PRTMP_ADAPTER pAd,
68002 + OUT UCHAR *QueIdx);
68003 +
68004 +#ifdef CONFIG_STA_SUPPORT
68005 +VOID RTMPReportMicError(
68006 + IN PRTMP_ADAPTER pAd,
68007 + IN PCIPHER_KEY pWpaKey);
68008 +
68009 +VOID WpaMicFailureReportFrame(
68010 + IN PRTMP_ADAPTER pAd,
68011 + IN MLME_QUEUE_ELEM *Elem);
68012 +
68013 +VOID WpaDisassocApAndBlockAssoc(
68014 + IN PVOID SystemSpecific1,
68015 + IN PVOID FunctionContext,
68016 + IN PVOID SystemSpecific2,
68017 + IN PVOID SystemSpecific3);
68018 +#endif // CONFIG_STA_SUPPORT //
68019 +
68020 +NDIS_STATUS RTMPCloneNdisPacket(
68021 + IN PRTMP_ADAPTER pAd,
68022 + IN BOOLEAN pInsAMSDUHdr,
68023 + IN PNDIS_PACKET pInPacket,
68024 + OUT PNDIS_PACKET *ppOutPacket);
68025 +
68026 +NDIS_STATUS RTMPAllocateNdisPacket(
68027 + IN PRTMP_ADAPTER pAd,
68028 + IN PNDIS_PACKET *pPacket,
68029 + IN PUCHAR pHeader,
68030 + IN UINT HeaderLen,
68031 + IN PUCHAR pData,
68032 + IN UINT DataLen);
68033 +
68034 +VOID RTMPFreeNdisPacket(
68035 + IN PRTMP_ADAPTER pAd,
68036 + IN PNDIS_PACKET pPacket);
68037 +
68038 +BOOLEAN RTMPFreeTXDUponTxDmaDone(
68039 + IN PRTMP_ADAPTER pAd,
68040 + IN UCHAR QueIdx);
68041 +
68042 +BOOLEAN RTMPCheckDHCPFrame(
68043 + IN PRTMP_ADAPTER pAd,
68044 + IN PNDIS_PACKET pPacket);
68045 +
68046 +
68047 +BOOLEAN RTMPCheckEtherType(
68048 + IN PRTMP_ADAPTER pAd,
68049 + IN PNDIS_PACKET pPacket);
68050 +
68051 +
68052 +VOID RTMPCckBbpTuning(
68053 + IN PRTMP_ADAPTER pAd,
68054 + IN UINT TxRate);
68055 +
68056 +//
68057 +// Private routines in rtmp_wep.c
68058 +//
68059 +VOID RTMPInitWepEngine(
68060 + IN PRTMP_ADAPTER pAd,
68061 + IN PUCHAR pKey,
68062 + IN UCHAR KeyId,
68063 + IN UCHAR KeyLen,
68064 + IN PUCHAR pDest);
68065 +
68066 +VOID RTMPEncryptData(
68067 + IN PRTMP_ADAPTER pAd,
68068 + IN PUCHAR pSrc,
68069 + IN PUCHAR pDest,
68070 + IN UINT Len);
68071 +
68072 +BOOLEAN RTMPDecryptData(
68073 + IN PRTMP_ADAPTER pAdapter,
68074 + IN PUCHAR pSrc,
68075 + IN UINT Len,
68076 + IN UINT idx);
68077 +
68078 +BOOLEAN RTMPSoftDecryptWEP(
68079 + IN PRTMP_ADAPTER pAd,
68080 + IN PUCHAR pData,
68081 + IN ULONG DataByteCnt,
68082 + IN PCIPHER_KEY pGroupKey);
68083 +
68084 +VOID RTMPSetICV(
68085 + IN PRTMP_ADAPTER pAd,
68086 + IN PUCHAR pDest);
68087 +
68088 +VOID ARCFOUR_INIT(
68089 + IN PARCFOURCONTEXT Ctx,
68090 + IN PUCHAR pKey,
68091 + IN UINT KeyLen);
68092 +
68093 +UCHAR ARCFOUR_BYTE(
68094 + IN PARCFOURCONTEXT Ctx);
68095 +
68096 +VOID ARCFOUR_DECRYPT(
68097 + IN PARCFOURCONTEXT Ctx,
68098 + IN PUCHAR pDest,
68099 + IN PUCHAR pSrc,
68100 + IN UINT Len);
68101 +
68102 +VOID ARCFOUR_ENCRYPT(
68103 + IN PARCFOURCONTEXT Ctx,
68104 + IN PUCHAR pDest,
68105 + IN PUCHAR pSrc,
68106 + IN UINT Len);
68107 +
68108 +VOID WPAARCFOUR_ENCRYPT(
68109 + IN PARCFOURCONTEXT Ctx,
68110 + IN PUCHAR pDest,
68111 + IN PUCHAR pSrc,
68112 + IN UINT Len);
68113 +
68114 +UINT RTMP_CALC_FCS32(
68115 + IN UINT Fcs,
68116 + IN PUCHAR Cp,
68117 + IN INT Len);
68118 +
68119 +//
68120 +// MLME routines
68121 +//
68122 +
68123 +// Asic/RF/BBP related functions
68124 +
68125 +VOID AsicAdjustTxPower(
68126 + IN PRTMP_ADAPTER pAd);
68127 +
68128 +VOID AsicUpdateProtect(
68129 + IN PRTMP_ADAPTER pAd,
68130 + IN USHORT OperaionMode,
68131 + IN UCHAR SetMask,
68132 + IN BOOLEAN bDisableBGProtect,
68133 + IN BOOLEAN bNonGFExist);
68134 +
68135 +VOID AsicSwitchChannel(
68136 + IN PRTMP_ADAPTER pAd,
68137 + IN UCHAR Channel,
68138 + IN BOOLEAN bScan);
68139 +
68140 +VOID AsicLockChannel(
68141 + IN PRTMP_ADAPTER pAd,
68142 + IN UCHAR Channel) ;
68143 +
68144 +VOID AsicAntennaSelect(
68145 + IN PRTMP_ADAPTER pAd,
68146 + IN UCHAR Channel);
68147 +
68148 +VOID AsicAntennaSetting(
68149 + IN PRTMP_ADAPTER pAd,
68150 + IN ABGBAND_STATE BandState);
68151 +
68152 +VOID AsicRfTuningExec(
68153 + IN PVOID SystemSpecific1,
68154 + IN PVOID FunctionContext,
68155 + IN PVOID SystemSpecific2,
68156 + IN PVOID SystemSpecific3);
68157 +
68158 +#ifdef CONFIG_STA_SUPPORT
68159 +VOID AsicSleepThenAutoWakeup(
68160 + IN PRTMP_ADAPTER pAd,
68161 + IN USHORT TbttNumToNextWakeUp);
68162 +
68163 +VOID AsicForceSleep(
68164 + IN PRTMP_ADAPTER pAd);
68165 +
68166 +VOID AsicForceWakeup(
68167 + IN PRTMP_ADAPTER pAd,
68168 + IN BOOLEAN bFromTx);
68169 +#endif // CONFIG_STA_SUPPORT //
68170 +
68171 +VOID AsicSetBssid(
68172 + IN PRTMP_ADAPTER pAd,
68173 + IN PUCHAR pBssid);
68174 +
68175 +VOID AsicSetMcastWC(
68176 + IN PRTMP_ADAPTER pAd);
68177 +
68178 +VOID AsicDelWcidTab(
68179 + IN PRTMP_ADAPTER pAd,
68180 + IN UCHAR Wcid);
68181 +
68182 +VOID AsicEnableRDG(
68183 + IN PRTMP_ADAPTER pAd);
68184 +
68185 +VOID AsicDisableRDG(
68186 + IN PRTMP_ADAPTER pAd);
68187 +
68188 +VOID AsicDisableSync(
68189 + IN PRTMP_ADAPTER pAd);
68190 +
68191 +VOID AsicEnableBssSync(
68192 + IN PRTMP_ADAPTER pAd);
68193 +
68194 +VOID AsicEnableIbssSync(
68195 + IN PRTMP_ADAPTER pAd);
68196 +
68197 +VOID AsicSetEdcaParm(
68198 + IN PRTMP_ADAPTER pAd,
68199 + IN PEDCA_PARM pEdcaParm);
68200 +
68201 +VOID AsicSetSlotTime(
68202 + IN PRTMP_ADAPTER pAd,
68203 + IN BOOLEAN bUseShortSlotTime);
68204 +
68205 +VOID AsicAddSharedKeyEntry(
68206 + IN PRTMP_ADAPTER pAd,
68207 + IN UCHAR BssIndex,
68208 + IN UCHAR KeyIdx,
68209 + IN UCHAR CipherAlg,
68210 + IN PUCHAR pKey,
68211 + IN PUCHAR pTxMic,
68212 + IN PUCHAR pRxMic);
68213 +
68214 +VOID AsicRemoveSharedKeyEntry(
68215 + IN PRTMP_ADAPTER pAd,
68216 + IN UCHAR BssIndex,
68217 + IN UCHAR KeyIdx);
68218 +
68219 +VOID AsicUpdateWCIDAttribute(
68220 + IN PRTMP_ADAPTER pAd,
68221 + IN USHORT WCID,
68222 + IN UCHAR BssIndex,
68223 + IN UCHAR CipherAlg,
68224 + IN BOOLEAN bUsePairewiseKeyTable);
68225 +
68226 +VOID AsicUpdateWCIDIVEIV(
68227 + IN PRTMP_ADAPTER pAd,
68228 + IN USHORT WCID,
68229 + IN ULONG uIV,
68230 + IN ULONG uEIV);
68231 +
68232 +VOID AsicUpdateRxWCIDTable(
68233 + IN PRTMP_ADAPTER pAd,
68234 + IN USHORT WCID,
68235 + IN PUCHAR pAddr);
68236 +
68237 +VOID AsicAddKeyEntry(
68238 + IN PRTMP_ADAPTER pAd,
68239 + IN USHORT WCID,
68240 + IN UCHAR BssIndex,
68241 + IN UCHAR KeyIdx,
68242 + IN PCIPHER_KEY pCipherKey,
68243 + IN BOOLEAN bUsePairewiseKeyTable,
68244 + IN BOOLEAN bTxKey);
68245 +
68246 +VOID AsicAddPairwiseKeyEntry(
68247 + IN PRTMP_ADAPTER pAd,
68248 + IN PUCHAR pAddr,
68249 + IN UCHAR WCID,
68250 + IN CIPHER_KEY *pCipherKey);
68251 +
68252 +VOID AsicRemovePairwiseKeyEntry(
68253 + IN PRTMP_ADAPTER pAd,
68254 + IN UCHAR BssIdx,
68255 + IN UCHAR Wcid);
68256 +
68257 +BOOLEAN AsicSendCommandToMcu(
68258 + IN PRTMP_ADAPTER pAd,
68259 + IN UCHAR Command,
68260 + IN UCHAR Token,
68261 + IN UCHAR Arg0,
68262 + IN UCHAR Arg1);
68263 +
68264 +
68265 +VOID MacAddrRandomBssid(
68266 + IN PRTMP_ADAPTER pAd,
68267 + OUT PUCHAR pAddr);
68268 +
68269 +VOID MgtMacHeaderInit(
68270 + IN PRTMP_ADAPTER pAd,
68271 + IN OUT PHEADER_802_11 pHdr80211,
68272 + IN UCHAR SubType,
68273 + IN UCHAR ToDs,
68274 + IN PUCHAR pDA,
68275 + IN PUCHAR pBssid);
68276 +
68277 +VOID MlmeRadioOff(
68278 + IN PRTMP_ADAPTER pAd);
68279 +
68280 +VOID MlmeRadioOn(
68281 + IN PRTMP_ADAPTER pAd);
68282 +
68283 +
68284 +VOID BssTableInit(
68285 + IN BSS_TABLE *Tab);
68286 +
68287 +#ifdef DOT11_N_SUPPORT
68288 +VOID BATableInit(
68289 + IN PRTMP_ADAPTER pAd,
68290 + IN BA_TABLE *Tab);
68291 +#endif // DOT11_N_SUPPORT //
68292 +
68293 +ULONG BssTableSearch(
68294 + IN BSS_TABLE *Tab,
68295 + IN PUCHAR pBssid,
68296 + IN UCHAR Channel);
68297 +
68298 +ULONG BssSsidTableSearch(
68299 + IN BSS_TABLE *Tab,
68300 + IN PUCHAR pBssid,
68301 + IN PUCHAR pSsid,
68302 + IN UCHAR SsidLen,
68303 + IN UCHAR Channel);
68304 +
68305 +ULONG BssTableSearchWithSSID(
68306 + IN BSS_TABLE *Tab,
68307 + IN PUCHAR Bssid,
68308 + IN PUCHAR pSsid,
68309 + IN UCHAR SsidLen,
68310 + IN UCHAR Channel);
68311 +
68312 +VOID BssTableDeleteEntry(
68313 + IN OUT PBSS_TABLE pTab,
68314 + IN PUCHAR pBssid,
68315 + IN UCHAR Channel);
68316 +
68317 +#ifdef DOT11_N_SUPPORT
68318 +VOID BATableDeleteORIEntry(
68319 + IN OUT PRTMP_ADAPTER pAd,
68320 + IN BA_ORI_ENTRY *pBAORIEntry);
68321 +
68322 +VOID BATableDeleteRECEntry(
68323 + IN OUT PRTMP_ADAPTER pAd,
68324 + IN BA_REC_ENTRY *pBARECEntry);
68325 +
68326 +VOID BATableTearORIEntry(
68327 + IN OUT PRTMP_ADAPTER pAd,
68328 + IN UCHAR TID,
68329 + IN UCHAR Wcid,
68330 + IN BOOLEAN bForceDelete,
68331 + IN BOOLEAN ALL);
68332 +
68333 +VOID BATableTearRECEntry(
68334 + IN OUT PRTMP_ADAPTER pAd,
68335 + IN UCHAR TID,
68336 + IN UCHAR WCID,
68337 + IN BOOLEAN ALL);
68338 +#endif // DOT11_N_SUPPORT //
68339 +
68340 +VOID BssEntrySet(
68341 + IN PRTMP_ADAPTER pAd,
68342 + OUT PBSS_ENTRY pBss,
68343 + IN PUCHAR pBssid,
68344 + IN CHAR Ssid[],
68345 + IN UCHAR SsidLen,
68346 + IN UCHAR BssType,
68347 + IN USHORT BeaconPeriod,
68348 + IN PCF_PARM CfParm,
68349 + IN USHORT AtimWin,
68350 + IN USHORT CapabilityInfo,
68351 + IN UCHAR SupRate[],
68352 + IN UCHAR SupRateLen,
68353 + IN UCHAR ExtRate[],
68354 + IN UCHAR ExtRateLen,
68355 + IN HT_CAPABILITY_IE *pHtCapability,
68356 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
68357 + IN UCHAR HtCapabilityLen,
68358 + IN UCHAR AddHtInfoLen,
68359 + IN UCHAR NewExtChanOffset,
68360 + IN UCHAR Channel,
68361 + IN CHAR Rssi,
68362 + IN LARGE_INTEGER TimeStamp,
68363 + IN UCHAR CkipFlag,
68364 + IN PEDCA_PARM pEdcaParm,
68365 + IN PQOS_CAPABILITY_PARM pQosCapability,
68366 + IN PQBSS_LOAD_PARM pQbssLoad,
68367 + IN USHORT LengthVIE,
68368 + IN PNDIS_802_11_VARIABLE_IEs pVIE);
68369 +
68370 +ULONG BssTableSetEntry(
68371 + IN PRTMP_ADAPTER pAd,
68372 + OUT PBSS_TABLE pTab,
68373 + IN PUCHAR pBssid,
68374 + IN CHAR Ssid[],
68375 + IN UCHAR SsidLen,
68376 + IN UCHAR BssType,
68377 + IN USHORT BeaconPeriod,
68378 + IN CF_PARM *CfParm,
68379 + IN USHORT AtimWin,
68380 + IN USHORT CapabilityInfo,
68381 + IN UCHAR SupRate[],
68382 + IN UCHAR SupRateLen,
68383 + IN UCHAR ExtRate[],
68384 + IN UCHAR ExtRateLen,
68385 + IN HT_CAPABILITY_IE *pHtCapability,
68386 + IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
68387 + IN UCHAR HtCapabilityLen,
68388 + IN UCHAR AddHtInfoLen,
68389 + IN UCHAR NewExtChanOffset,
68390 + IN UCHAR Channel,
68391 + IN CHAR Rssi,
68392 + IN LARGE_INTEGER TimeStamp,
68393 + IN UCHAR CkipFlag,
68394 + IN PEDCA_PARM pEdcaParm,
68395 + IN PQOS_CAPABILITY_PARM pQosCapability,
68396 + IN PQBSS_LOAD_PARM pQbssLoad,
68397 + IN USHORT LengthVIE,
68398 + IN PNDIS_802_11_VARIABLE_IEs pVIE);
68399 +
68400 +#ifdef DOT11_N_SUPPORT
68401 +VOID BATableInsertEntry(
68402 + IN PRTMP_ADAPTER pAd,
68403 + IN USHORT Aid,
68404 + IN USHORT TimeOutValue,
68405 + IN USHORT StartingSeq,
68406 + IN UCHAR TID,
68407 + IN UCHAR BAWinSize,
68408 + IN UCHAR OriginatorStatus,
68409 + IN BOOLEAN IsRecipient);
68410 +
68411 +#ifdef DOT11N_DRAFT3
68412 +VOID Bss2040CoexistTimeOut(
68413 + IN PVOID SystemSpecific1,
68414 + IN PVOID FunctionContext,
68415 + IN PVOID SystemSpecific2,
68416 + IN PVOID SystemSpecific3);
68417 +
68418 +
68419 +VOID TriEventInit(
68420 + IN PRTMP_ADAPTER pAd);
68421 +
68422 +ULONG TriEventTableSetEntry(
68423 + IN PRTMP_ADAPTER pAd,
68424 + OUT TRIGGER_EVENT_TAB *Tab,
68425 + IN PUCHAR pBssid,
68426 + IN HT_CAPABILITY_IE *pHtCapability,
68427 + IN UCHAR HtCapabilityLen,
68428 + IN UCHAR RegClass,
68429 + IN UCHAR ChannelNo);
68430 +
68431 +VOID TriEventCounterMaintenance(
68432 + IN PRTMP_ADAPTER pAd);
68433 +#endif // DOT11N_DRAFT3 //
68434 +#endif // DOT11_N_SUPPORT //
68435 +
68436 +VOID BssTableSsidSort(
68437 + IN PRTMP_ADAPTER pAd,
68438 + OUT BSS_TABLE *OutTab,
68439 + IN CHAR Ssid[],
68440 + IN UCHAR SsidLen);
68441 +
68442 +VOID BssTableSortByRssi(
68443 + IN OUT BSS_TABLE *OutTab);
68444 +
68445 +VOID BssCipherParse(
68446 + IN OUT PBSS_ENTRY pBss);
68447 +
68448 +NDIS_STATUS MlmeQueueInit(
68449 + IN MLME_QUEUE *Queue);
68450 +
68451 +VOID MlmeQueueDestroy(
68452 + IN MLME_QUEUE *Queue);
68453 +
68454 +BOOLEAN MlmeEnqueue(
68455 + IN PRTMP_ADAPTER pAd,
68456 + IN ULONG Machine,
68457 + IN ULONG MsgType,
68458 + IN ULONG MsgLen,
68459 + IN VOID *Msg);
68460 +
68461 +BOOLEAN MlmeEnqueueForRecv(
68462 + IN PRTMP_ADAPTER pAd,
68463 + IN ULONG Wcid,
68464 + IN ULONG TimeStampHigh,
68465 + IN ULONG TimeStampLow,
68466 + IN UCHAR Rssi0,
68467 + IN UCHAR Rssi1,
68468 + IN UCHAR Rssi2,
68469 + IN ULONG MsgLen,
68470 + IN PVOID Msg,
68471 + IN UCHAR Signal);
68472 +
68473 +
68474 +BOOLEAN MlmeDequeue(
68475 + IN MLME_QUEUE *Queue,
68476 + OUT MLME_QUEUE_ELEM **Elem);
68477 +
68478 +VOID MlmeRestartStateMachine(
68479 + IN PRTMP_ADAPTER pAd);
68480 +
68481 +BOOLEAN MlmeQueueEmpty(
68482 + IN MLME_QUEUE *Queue);
68483 +
68484 +BOOLEAN MlmeQueueFull(
68485 + IN MLME_QUEUE *Queue);
68486 +
68487 +BOOLEAN MsgTypeSubst(
68488 + IN PRTMP_ADAPTER pAd,
68489 + IN PFRAME_802_11 pFrame,
68490 + OUT INT *Machine,
68491 + OUT INT *MsgType);
68492 +
68493 +VOID StateMachineInit(
68494 + IN STATE_MACHINE *Sm,
68495 + IN STATE_MACHINE_FUNC Trans[],
68496 + IN ULONG StNr,
68497 + IN ULONG MsgNr,
68498 + IN STATE_MACHINE_FUNC DefFunc,
68499 + IN ULONG InitState,
68500 + IN ULONG Base);
68501 +
68502 +VOID StateMachineSetAction(
68503 + IN STATE_MACHINE *S,
68504 + IN ULONG St,
68505 + ULONG Msg,
68506 + IN STATE_MACHINE_FUNC F);
68507 +
68508 +VOID StateMachinePerformAction(
68509 + IN PRTMP_ADAPTER pAd,
68510 + IN STATE_MACHINE *S,
68511 + IN MLME_QUEUE_ELEM *Elem);
68512 +
68513 +VOID Drop(
68514 + IN PRTMP_ADAPTER pAd,
68515 + IN MLME_QUEUE_ELEM *Elem);
68516 +
68517 +VOID AssocStateMachineInit(
68518 + IN PRTMP_ADAPTER pAd,
68519 + IN STATE_MACHINE *Sm,
68520 + OUT STATE_MACHINE_FUNC Trans[]);
68521 +
68522 +VOID ReassocTimeout(
68523 + IN PVOID SystemSpecific1,
68524 + IN PVOID FunctionContext,
68525 + IN PVOID SystemSpecific2,
68526 + IN PVOID SystemSpecific3);
68527 +
68528 +VOID AssocTimeout(
68529 + IN PVOID SystemSpecific1,
68530 + IN PVOID FunctionContext,
68531 + IN PVOID SystemSpecific2,
68532 + IN PVOID SystemSpecific3);
68533 +
68534 +VOID DisassocTimeout(
68535 + IN PVOID SystemSpecific1,
68536 + IN PVOID FunctionContext,
68537 + IN PVOID SystemSpecific2,
68538 + IN PVOID SystemSpecific3);
68539 +
68540 +//----------------------------------------------
68541 +VOID MlmeDisassocReqAction(
68542 + IN PRTMP_ADAPTER pAd,
68543 + IN MLME_QUEUE_ELEM *Elem);
68544 +
68545 +VOID MlmeAssocReqAction(
68546 + IN PRTMP_ADAPTER pAd,
68547 + IN MLME_QUEUE_ELEM *Elem);
68548 +
68549 +VOID MlmeReassocReqAction(
68550 + IN PRTMP_ADAPTER pAd,
68551 + IN MLME_QUEUE_ELEM *Elem);
68552 +
68553 +VOID MlmeDisassocReqAction(
68554 + IN PRTMP_ADAPTER pAd,
68555 + IN MLME_QUEUE_ELEM *Elem);
68556 +
68557 +VOID PeerAssocRspAction(
68558 + IN PRTMP_ADAPTER pAd,
68559 + IN MLME_QUEUE_ELEM *Elem);
68560 +
68561 +VOID PeerReassocRspAction(
68562 + IN PRTMP_ADAPTER pAd,
68563 + IN MLME_QUEUE_ELEM *Elem);
68564 +
68565 +VOID PeerDisassocAction(
68566 + IN PRTMP_ADAPTER pAd,
68567 + IN MLME_QUEUE_ELEM *Elem);
68568 +
68569 +VOID DisassocTimeoutAction(
68570 + IN PRTMP_ADAPTER pAd,
68571 + IN MLME_QUEUE_ELEM *Elem);
68572 +
68573 +VOID AssocTimeoutAction(
68574 + IN PRTMP_ADAPTER pAd,
68575 + IN MLME_QUEUE_ELEM *Elem);
68576 +
68577 +VOID ReassocTimeoutAction(
68578 + IN PRTMP_ADAPTER pAd,
68579 + IN MLME_QUEUE_ELEM *Elem);
68580 +
68581 +VOID Cls3errAction(
68582 + IN PRTMP_ADAPTER pAd,
68583 + IN PUCHAR pAddr);
68584 +
68585 +VOID SwitchBetweenWepAndCkip(
68586 + IN PRTMP_ADAPTER pAd);
68587 +
68588 +VOID InvalidStateWhenAssoc(
68589 + IN PRTMP_ADAPTER pAd,
68590 + IN MLME_QUEUE_ELEM *Elem);
68591 +
68592 +VOID InvalidStateWhenReassoc(
68593 + IN PRTMP_ADAPTER pAd,
68594 + IN MLME_QUEUE_ELEM *Elem);
68595 +
68596 +VOID InvalidStateWhenDisassociate(
68597 + IN PRTMP_ADAPTER pAd,
68598 + IN MLME_QUEUE_ELEM *Elem);
68599 +
68600 +#ifdef RT2870
68601 +VOID MlmeCntlConfirm(
68602 + IN PRTMP_ADAPTER pAd,
68603 + IN ULONG MsgType,
68604 + IN USHORT Msg);
68605 +#endif // RT2870 //
68606 +
68607 +VOID ComposePsPoll(
68608 + IN PRTMP_ADAPTER pAd);
68609 +
68610 +VOID ComposeNullFrame(
68611 + IN PRTMP_ADAPTER pAd);
68612 +
68613 +VOID AssocPostProc(
68614 + IN PRTMP_ADAPTER pAd,
68615 + IN PUCHAR pAddr2,
68616 + IN USHORT CapabilityInfo,
68617 + IN USHORT Aid,
68618 + IN UCHAR SupRate[],
68619 + IN UCHAR SupRateLen,
68620 + IN UCHAR ExtRate[],
68621 + IN UCHAR ExtRateLen,
68622 + IN PEDCA_PARM pEdcaParm,
68623 + IN HT_CAPABILITY_IE *pHtCapability,
68624 + IN UCHAR HtCapabilityLen,
68625 + IN ADD_HT_INFO_IE *pAddHtInfo);
68626 +
68627 +VOID AuthStateMachineInit(
68628 + IN PRTMP_ADAPTER pAd,
68629 + IN PSTATE_MACHINE sm,
68630 + OUT STATE_MACHINE_FUNC Trans[]);
68631 +
68632 +VOID AuthTimeout(
68633 + IN PVOID SystemSpecific1,
68634 + IN PVOID FunctionContext,
68635 + IN PVOID SystemSpecific2,
68636 + IN PVOID SystemSpecific3);
68637 +
68638 +VOID MlmeAuthReqAction(
68639 + IN PRTMP_ADAPTER pAd,
68640 + IN MLME_QUEUE_ELEM *Elem);
68641 +
68642 +VOID PeerAuthRspAtSeq2Action(
68643 + IN PRTMP_ADAPTER pAd,
68644 + IN MLME_QUEUE_ELEM *Elem);
68645 +
68646 +VOID PeerAuthRspAtSeq4Action(
68647 + IN PRTMP_ADAPTER pAd,
68648 + IN MLME_QUEUE_ELEM *Elem);
68649 +
68650 +VOID AuthTimeoutAction(
68651 + IN PRTMP_ADAPTER pAd,
68652 + IN MLME_QUEUE_ELEM *Elem);
68653 +
68654 +VOID Cls2errAction(
68655 + IN PRTMP_ADAPTER pAd,
68656 + IN PUCHAR pAddr);
68657 +
68658 +VOID MlmeDeauthReqAction(
68659 + IN PRTMP_ADAPTER pAd,
68660 + IN MLME_QUEUE_ELEM *Elem);
68661 +
68662 +VOID InvalidStateWhenAuth(
68663 + IN PRTMP_ADAPTER pAd,
68664 + IN MLME_QUEUE_ELEM *Elem);
68665 +
68666 +//=============================================
68667 +
68668 +VOID AuthRspStateMachineInit(
68669 + IN PRTMP_ADAPTER pAd,
68670 + IN PSTATE_MACHINE Sm,
68671 + IN STATE_MACHINE_FUNC Trans[]);
68672 +
68673 +VOID PeerDeauthAction(
68674 + IN PRTMP_ADAPTER pAd,
68675 + IN MLME_QUEUE_ELEM *Elem);
68676 +
68677 +VOID PeerAuthSimpleRspGenAndSend(
68678 + IN PRTMP_ADAPTER pAd,
68679 + IN PHEADER_802_11 pHdr80211,
68680 + IN USHORT Alg,
68681 + IN USHORT Seq,
68682 + IN USHORT Reason,
68683 + IN USHORT Status);
68684 +
68685 +//
68686 +// Private routines in dls.c
68687 +//
68688 +
68689 +#ifdef CONFIG_STA_SUPPORT
68690 +#ifdef QOS_DLS_SUPPORT
68691 +void DlsStateMachineInit(
68692 + IN PRTMP_ADAPTER pAd,
68693 + IN STATE_MACHINE *Sm,
68694 + OUT STATE_MACHINE_FUNC Trans[]);
68695 +
68696 +VOID MlmeDlsReqAction(
68697 + IN PRTMP_ADAPTER pAd,
68698 + IN MLME_QUEUE_ELEM *Elem);
68699 +
68700 +VOID PeerDlsReqAction(
68701 + IN PRTMP_ADAPTER pAd,
68702 + IN MLME_QUEUE_ELEM *Elem);
68703 +
68704 +VOID PeerDlsRspAction(
68705 + IN PRTMP_ADAPTER pAd,
68706 + IN MLME_QUEUE_ELEM *Elem);
68707 +
68708 +VOID MlmeDlsTearDownAction(
68709 + IN PRTMP_ADAPTER pAd,
68710 + IN MLME_QUEUE_ELEM *Elem);
68711 +
68712 +VOID PeerDlsTearDownAction(
68713 + IN PRTMP_ADAPTER pAd,
68714 + IN MLME_QUEUE_ELEM *Elem);
68715 +
68716 +VOID RTMPCheckDLSTimeOut(
68717 + IN PRTMP_ADAPTER pAd);
68718 +
68719 +BOOLEAN RTMPRcvFrameDLSCheck(
68720 + IN PRTMP_ADAPTER pAd,
68721 + IN PHEADER_802_11 pHeader,
68722 + IN ULONG Len,
68723 + IN PRT28XX_RXD_STRUC pRxD);
68724 +
68725 +INT RTMPCheckDLSFrame(
68726 + IN PRTMP_ADAPTER pAd,
68727 + IN PUCHAR pDA);
68728 +
68729 +VOID RTMPSendDLSTearDownFrame(
68730 + IN PRTMP_ADAPTER pAd,
68731 + IN PUCHAR pDA);
68732 +
68733 +NDIS_STATUS RTMPSendSTAKeyRequest(
68734 + IN PRTMP_ADAPTER pAd,
68735 + IN PUCHAR pDA);
68736 +
68737 +NDIS_STATUS RTMPSendSTAKeyHandShake(
68738 + IN PRTMP_ADAPTER pAd,
68739 + IN PUCHAR pDA);
68740 +
68741 +VOID DlsTimeoutAction(
68742 + IN PVOID SystemSpecific1,
68743 + IN PVOID FunctionContext,
68744 + IN PVOID SystemSpecific2,
68745 + IN PVOID SystemSpecific3);
68746 +
68747 +BOOLEAN MlmeDlsReqSanity(
68748 + IN PRTMP_ADAPTER pAd,
68749 + IN VOID *Msg,
68750 + IN ULONG MsgLen,
68751 + OUT PRT_802_11_DLS *pDLS,
68752 + OUT PUSHORT pReason);
68753 +
68754 +INT Set_DlsEntryInfo_Display_Proc(
68755 + IN PRTMP_ADAPTER pAd,
68756 + IN PUCHAR arg);
68757 +
68758 +MAC_TABLE_ENTRY *MacTableInsertDlsEntry(
68759 + IN PRTMP_ADAPTER pAd,
68760 + IN PUCHAR pAddr,
68761 + IN UINT DlsEntryIdx);
68762 +
68763 +BOOLEAN MacTableDeleteDlsEntry(
68764 + IN PRTMP_ADAPTER pAd,
68765 + IN USHORT wcid,
68766 + IN PUCHAR pAddr);
68767 +
68768 +MAC_TABLE_ENTRY *DlsEntryTableLookup(
68769 + IN PRTMP_ADAPTER pAd,
68770 + IN PUCHAR pAddr,
68771 + IN BOOLEAN bResetIdelCount);
68772 +
68773 +MAC_TABLE_ENTRY *DlsEntryTableLookupByWcid(
68774 + IN PRTMP_ADAPTER pAd,
68775 + IN UCHAR wcid,
68776 + IN PUCHAR pAddr,
68777 + IN BOOLEAN bResetIdelCount);
68778 +
68779 +INT Set_DlsAddEntry_Proc(
68780 + IN PRTMP_ADAPTER pAd,
68781 + IN PUCHAR arg);
68782 +
68783 +INT Set_DlsTearDownEntry_Proc(
68784 + IN PRTMP_ADAPTER pAd,
68785 + IN PUCHAR arg);
68786 +#endif // QOS_DLS_SUPPORT //
68787 +#endif // CONFIG_STA_SUPPORT //
68788 +
68789 +#ifdef QOS_DLS_SUPPORT
68790 +BOOLEAN PeerDlsReqSanity(
68791 + IN PRTMP_ADAPTER pAd,
68792 + IN VOID *Msg,
68793 + IN ULONG MsgLen,
68794 + OUT PUCHAR pDA,
68795 + OUT PUCHAR pSA,
68796 + OUT USHORT *pCapabilityInfo,
68797 + OUT USHORT *pDlsTimeout,
68798 + OUT UCHAR *pRatesLen,
68799 + OUT UCHAR Rates[],
68800 + OUT UCHAR *pHtCapabilityLen,
68801 + OUT HT_CAPABILITY_IE *pHtCapability);
68802 +
68803 +BOOLEAN PeerDlsRspSanity(
68804 + IN PRTMP_ADAPTER pAd,
68805 + IN VOID *Msg,
68806 + IN ULONG MsgLen,
68807 + OUT PUCHAR pDA,
68808 + OUT PUCHAR pSA,
68809 + OUT USHORT *pCapabilityInfo,
68810 + OUT USHORT *pStatus,
68811 + OUT UCHAR *pRatesLen,
68812 + OUT UCHAR Rates[],
68813 + OUT UCHAR *pHtCapabilityLen,
68814 + OUT HT_CAPABILITY_IE *pHtCapability);
68815 +
68816 +BOOLEAN PeerDlsTearDownSanity(
68817 + IN PRTMP_ADAPTER pAd,
68818 + IN VOID *Msg,
68819 + IN ULONG MsgLen,
68820 + OUT PUCHAR pDA,
68821 + OUT PUCHAR pSA,
68822 + OUT USHORT *pReason);
68823 +#endif // QOS_DLS_SUPPORT //
68824 +
68825 +//========================================
68826 +
68827 +VOID SyncStateMachineInit(
68828 + IN PRTMP_ADAPTER pAd,
68829 + IN STATE_MACHINE *Sm,
68830 + OUT STATE_MACHINE_FUNC Trans[]);
68831 +
68832 +VOID BeaconTimeout(
68833 + IN PVOID SystemSpecific1,
68834 + IN PVOID FunctionContext,
68835 + IN PVOID SystemSpecific2,
68836 + IN PVOID SystemSpecific3);
68837 +
68838 +VOID ScanTimeout(
68839 + IN PVOID SystemSpecific1,
68840 + IN PVOID FunctionContext,
68841 + IN PVOID SystemSpecific2,
68842 + IN PVOID SystemSpecific3);
68843 +
68844 +VOID MlmeScanReqAction(
68845 + IN PRTMP_ADAPTER pAd,
68846 + IN MLME_QUEUE_ELEM *Elem);
68847 +
68848 +VOID InvalidStateWhenScan(
68849 + IN PRTMP_ADAPTER pAd,
68850 + IN MLME_QUEUE_ELEM *Elem);
68851 +
68852 +VOID InvalidStateWhenJoin(
68853 + IN PRTMP_ADAPTER pAd,
68854 + IN MLME_QUEUE_ELEM *Elem);
68855 +
68856 +VOID InvalidStateWhenStart(
68857 + IN PRTMP_ADAPTER pAd,
68858 + IN MLME_QUEUE_ELEM *Elem);
68859 +
68860 +VOID PeerBeacon(
68861 + IN PRTMP_ADAPTER pAd,
68862 + IN MLME_QUEUE_ELEM *Elem);
68863 +
68864 +VOID EnqueueProbeRequest(
68865 + IN PRTMP_ADAPTER pAd);
68866 +
68867 +BOOLEAN ScanRunning(
68868 + IN PRTMP_ADAPTER pAd);
68869 +//=========================================
68870 +
68871 +VOID MlmeCntlInit(
68872 + IN PRTMP_ADAPTER pAd,
68873 + IN STATE_MACHINE *S,
68874 + OUT STATE_MACHINE_FUNC Trans[]);
68875 +
68876 +VOID MlmeCntlMachinePerformAction(
68877 + IN PRTMP_ADAPTER pAd,
68878 + IN STATE_MACHINE *S,
68879 + IN MLME_QUEUE_ELEM *Elem);
68880 +
68881 +VOID CntlIdleProc(
68882 + IN PRTMP_ADAPTER pAd,
68883 + IN MLME_QUEUE_ELEM *Elem);
68884 +
68885 +VOID CntlOidScanProc(
68886 + IN PRTMP_ADAPTER pAd,
68887 + IN MLME_QUEUE_ELEM *Elem);
68888 +
68889 +VOID CntlOidSsidProc(
68890 + IN PRTMP_ADAPTER pAd,
68891 + IN MLME_QUEUE_ELEM * Elem);
68892 +
68893 +VOID CntlOidRTBssidProc(
68894 + IN PRTMP_ADAPTER pAd,
68895 + IN MLME_QUEUE_ELEM * Elem);
68896 +
68897 +VOID CntlMlmeRoamingProc(
68898 + IN PRTMP_ADAPTER pAd,
68899 + IN MLME_QUEUE_ELEM * Elem);
68900 +
68901 +VOID CntlWaitDisassocProc(
68902 + IN PRTMP_ADAPTER pAd,
68903 + IN MLME_QUEUE_ELEM *Elem);
68904 +
68905 +VOID CntlWaitJoinProc(
68906 + IN PRTMP_ADAPTER pAd,
68907 + IN MLME_QUEUE_ELEM *Elem);
68908 +
68909 +VOID CntlWaitReassocProc(
68910 + IN PRTMP_ADAPTER pAd,
68911 + IN MLME_QUEUE_ELEM *Elem);
68912 +
68913 +VOID CntlWaitStartProc(
68914 + IN PRTMP_ADAPTER pAd,
68915 + IN MLME_QUEUE_ELEM *Elem);
68916 +
68917 +VOID CntlWaitAuthProc(
68918 + IN PRTMP_ADAPTER pAd,
68919 + IN MLME_QUEUE_ELEM *Elem);
68920 +
68921 +VOID CntlWaitAuthProc2(
68922 + IN PRTMP_ADAPTER pAd,
68923 + IN MLME_QUEUE_ELEM *Elem);
68924 +
68925 +VOID CntlWaitAssocProc(
68926 + IN PRTMP_ADAPTER pAd,
68927 + IN MLME_QUEUE_ELEM *Elem);
68928 +
68929 +#ifdef QOS_DLS_SUPPORT
68930 +VOID CntlOidDLSSetupProc(
68931 + IN PRTMP_ADAPTER pAd,
68932 + IN MLME_QUEUE_ELEM *Elem);
68933 +#endif // QOS_DLS_SUPPORT //
68934 +
68935 +VOID LinkUp(
68936 + IN PRTMP_ADAPTER pAd,
68937 + IN UCHAR BssType);
68938 +
68939 +VOID LinkDown(
68940 + IN PRTMP_ADAPTER pAd,
68941 + IN BOOLEAN IsReqFromAP);
68942 +
68943 +VOID IterateOnBssTab(
68944 + IN PRTMP_ADAPTER pAd);
68945 +
68946 +VOID IterateOnBssTab2(
68947 + IN PRTMP_ADAPTER pAd);;
68948 +
68949 +VOID JoinParmFill(
68950 + IN PRTMP_ADAPTER pAd,
68951 + IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
68952 + IN ULONG BssIdx);
68953 +
68954 +VOID AssocParmFill(
68955 + IN PRTMP_ADAPTER pAd,
68956 + IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
68957 + IN PUCHAR pAddr,
68958 + IN USHORT CapabilityInfo,
68959 + IN ULONG Timeout,
68960 + IN USHORT ListenIntv);
68961 +
68962 +VOID ScanParmFill(
68963 + IN PRTMP_ADAPTER pAd,
68964 + IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
68965 + IN CHAR Ssid[],
68966 + IN UCHAR SsidLen,
68967 + IN UCHAR BssType,
68968 + IN UCHAR ScanType);
68969 +
68970 +VOID DisassocParmFill(
68971 + IN PRTMP_ADAPTER pAd,
68972 + IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
68973 + IN PUCHAR pAddr,
68974 + IN USHORT Reason);
68975 +
68976 +VOID StartParmFill(
68977 + IN PRTMP_ADAPTER pAd,
68978 + IN OUT MLME_START_REQ_STRUCT *StartReq,
68979 + IN CHAR Ssid[],
68980 + IN UCHAR SsidLen);
68981 +
68982 +VOID AuthParmFill(
68983 + IN PRTMP_ADAPTER pAd,
68984 + IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
68985 + IN PUCHAR pAddr,
68986 + IN USHORT Alg);
68987 +
68988 +VOID EnqueuePsPoll(
68989 + IN PRTMP_ADAPTER pAd);
68990 +
68991 +VOID EnqueueBeaconFrame(
68992 + IN PRTMP_ADAPTER pAd);
68993 +
68994 +VOID MlmeJoinReqAction(
68995 + IN PRTMP_ADAPTER pAd,
68996 + IN MLME_QUEUE_ELEM *Elem);
68997 +
68998 +VOID MlmeScanReqAction(
68999 + IN PRTMP_ADAPTER pAd,
69000 + IN MLME_QUEUE_ELEM *Elem);
69001 +
69002 +VOID MlmeStartReqAction(
69003 + IN PRTMP_ADAPTER pAd,
69004 + IN MLME_QUEUE_ELEM *Elem);
69005 +
69006 +VOID ScanTimeoutAction(
69007 + IN PRTMP_ADAPTER pAd,
69008 + IN MLME_QUEUE_ELEM *Elem);
69009 +
69010 +VOID BeaconTimeoutAtJoinAction(
69011 + IN PRTMP_ADAPTER pAd,
69012 + IN MLME_QUEUE_ELEM *Elem);
69013 +
69014 +VOID PeerBeaconAtScanAction(
69015 + IN PRTMP_ADAPTER pAd,
69016 + IN MLME_QUEUE_ELEM *Elem);
69017 +
69018 +VOID PeerBeaconAtJoinAction(
69019 + IN PRTMP_ADAPTER pAd,
69020 + IN MLME_QUEUE_ELEM *Elem);
69021 +
69022 +VOID PeerBeacon(
69023 + IN PRTMP_ADAPTER pAd,
69024 + IN MLME_QUEUE_ELEM *Elem);
69025 +
69026 +VOID PeerProbeReqAction(
69027 + IN PRTMP_ADAPTER pAd,
69028 + IN MLME_QUEUE_ELEM *Elem);
69029 +
69030 +VOID ScanNextChannel(
69031 + IN PRTMP_ADAPTER pAd);
69032 +
69033 +ULONG MakeIbssBeacon(
69034 + IN PRTMP_ADAPTER pAd);
69035 +
69036 +VOID CCXAdjacentAPReport(
69037 + IN PRTMP_ADAPTER pAd);
69038 +
69039 +BOOLEAN MlmeScanReqSanity(
69040 + IN PRTMP_ADAPTER pAd,
69041 + IN VOID *Msg,
69042 + IN ULONG MsgLen,
69043 + OUT UCHAR *BssType,
69044 + OUT CHAR ssid[],
69045 + OUT UCHAR *SsidLen,
69046 + OUT UCHAR *ScanType);
69047 +
69048 +BOOLEAN PeerBeaconAndProbeRspSanity(
69049 + IN PRTMP_ADAPTER pAd,
69050 + IN VOID *Msg,
69051 + IN ULONG MsgLen,
69052 + IN UCHAR MsgChannel,
69053 + OUT PUCHAR pAddr2,
69054 + OUT PUCHAR pBssid,
69055 + OUT CHAR Ssid[],
69056 + OUT UCHAR *pSsidLen,
69057 + OUT UCHAR *pBssType,
69058 + OUT USHORT *pBeaconPeriod,
69059 + OUT UCHAR *pChannel,
69060 + OUT UCHAR *pNewChannel,
69061 + OUT LARGE_INTEGER *pTimestamp,
69062 + OUT CF_PARM *pCfParm,
69063 + OUT USHORT *pAtimWin,
69064 + OUT USHORT *pCapabilityInfo,
69065 + OUT UCHAR *pErp,
69066 + OUT UCHAR *pDtimCount,
69067 + OUT UCHAR *pDtimPeriod,
69068 + OUT UCHAR *pBcastFlag,
69069 + OUT UCHAR *pMessageToMe,
69070 + OUT UCHAR SupRate[],
69071 + OUT UCHAR *pSupRateLen,
69072 + OUT UCHAR ExtRate[],
69073 + OUT UCHAR *pExtRateLen,
69074 + OUT UCHAR *pCkipFlag,
69075 + OUT UCHAR *pAironetCellPowerLimit,
69076 + OUT PEDCA_PARM pEdcaParm,
69077 + OUT PQBSS_LOAD_PARM pQbssLoad,
69078 + OUT PQOS_CAPABILITY_PARM pQosCapability,
69079 + OUT ULONG *pRalinkIe,
69080 + OUT UCHAR *pHtCapabilityLen,
69081 +#ifdef CONFIG_STA_SUPPORT
69082 + OUT UCHAR *pPreNHtCapabilityLen,
69083 +#endif // CONFIG_STA_SUPPORT //
69084 + OUT HT_CAPABILITY_IE *pHtCapability,
69085 + OUT UCHAR *AddHtInfoLen,
69086 + OUT ADD_HT_INFO_IE *AddHtInfo,
69087 + OUT UCHAR *NewExtChannel,
69088 + OUT USHORT *LengthVIE,
69089 + OUT PNDIS_802_11_VARIABLE_IEs pVIE);
69090 +
69091 +BOOLEAN PeerAddBAReqActionSanity(
69092 + IN PRTMP_ADAPTER pAd,
69093 + IN VOID *pMsg,
69094 + IN ULONG MsgLen,
69095 + OUT PUCHAR pAddr2);
69096 +
69097 +BOOLEAN PeerAddBARspActionSanity(
69098 + IN PRTMP_ADAPTER pAd,
69099 + IN VOID *pMsg,
69100 + IN ULONG MsgLen);
69101 +
69102 +BOOLEAN PeerDelBAActionSanity(
69103 + IN PRTMP_ADAPTER pAd,
69104 + IN UCHAR Wcid,
69105 + IN VOID *pMsg,
69106 + IN ULONG MsgLen);
69107 +
69108 +BOOLEAN MlmeAssocReqSanity(
69109 + IN PRTMP_ADAPTER pAd,
69110 + IN VOID *Msg,
69111 + IN ULONG MsgLen,
69112 + OUT PUCHAR pApAddr,
69113 + OUT USHORT *CapabilityInfo,
69114 + OUT ULONG *Timeout,
69115 + OUT USHORT *ListenIntv);
69116 +
69117 +BOOLEAN MlmeAuthReqSanity(
69118 + IN PRTMP_ADAPTER pAd,
69119 + IN VOID *Msg,
69120 + IN ULONG MsgLen,
69121 + OUT PUCHAR pAddr,
69122 + OUT ULONG *Timeout,
69123 + OUT USHORT *Alg);
69124 +
69125 +BOOLEAN MlmeStartReqSanity(
69126 + IN PRTMP_ADAPTER pAd,
69127 + IN VOID *Msg,
69128 + IN ULONG MsgLen,
69129 + OUT CHAR Ssid[],
69130 + OUT UCHAR *Ssidlen);
69131 +
69132 +BOOLEAN PeerAuthSanity(
69133 + IN PRTMP_ADAPTER pAd,
69134 + IN VOID *Msg,
69135 + IN ULONG MsgLen,
69136 + OUT PUCHAR pAddr,
69137 + OUT USHORT *Alg,
69138 + OUT USHORT *Seq,
69139 + OUT USHORT *Status,
69140 + OUT CHAR ChlgText[]);
69141 +
69142 +BOOLEAN PeerAssocRspSanity(
69143 + IN PRTMP_ADAPTER pAd,
69144 + IN VOID *pMsg,
69145 + IN ULONG MsgLen,
69146 + OUT PUCHAR pAddr2,
69147 + OUT USHORT *pCapabilityInfo,
69148 + OUT USHORT *pStatus,
69149 + OUT USHORT *pAid,
69150 + OUT UCHAR SupRate[],
69151 + OUT UCHAR *pSupRateLen,
69152 + OUT UCHAR ExtRate[],
69153 + OUT UCHAR *pExtRateLen,
69154 + OUT HT_CAPABILITY_IE *pHtCapability,
69155 + OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
69156 + OUT UCHAR *pHtCapabilityLen,
69157 + OUT UCHAR *pAddHtInfoLen,
69158 + OUT UCHAR *pNewExtChannelOffset,
69159 + OUT PEDCA_PARM pEdcaParm,
69160 + OUT UCHAR *pCkipFlag);
69161 +
69162 +BOOLEAN PeerDisassocSanity(
69163 + IN PRTMP_ADAPTER pAd,
69164 + IN VOID *Msg,
69165 + IN ULONG MsgLen,
69166 + OUT PUCHAR pAddr2,
69167 + OUT USHORT *Reason);
69168 +
69169 +BOOLEAN PeerWpaMessageSanity(
69170 + IN PRTMP_ADAPTER pAd,
69171 + IN PEAPOL_PACKET pMsg,
69172 + IN ULONG MsgLen,
69173 + IN UCHAR MsgType,
69174 + IN MAC_TABLE_ENTRY *pEntry);
69175 +
69176 +BOOLEAN PeerDeauthSanity(
69177 + IN PRTMP_ADAPTER pAd,
69178 + IN VOID *Msg,
69179 + IN ULONG MsgLen,
69180 + OUT PUCHAR pAddr2,
69181 + OUT USHORT *Reason);
69182 +
69183 +BOOLEAN PeerProbeReqSanity(
69184 + IN PRTMP_ADAPTER pAd,
69185 + IN VOID *Msg,
69186 + IN ULONG MsgLen,
69187 + OUT PUCHAR pAddr2,
69188 + OUT CHAR Ssid[],
69189 + OUT UCHAR *pSsidLen);
69190 +
69191 +BOOLEAN GetTimBit(
69192 + IN CHAR *Ptr,
69193 + IN USHORT Aid,
69194 + OUT UCHAR *TimLen,
69195 + OUT UCHAR *BcastFlag,
69196 + OUT UCHAR *DtimCount,
69197 + OUT UCHAR *DtimPeriod,
69198 + OUT UCHAR *MessageToMe);
69199 +
69200 +UCHAR ChannelSanity(
69201 + IN PRTMP_ADAPTER pAd,
69202 + IN UCHAR channel);
69203 +
69204 +NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(
69205 + IN PBSS_ENTRY pBss);
69206 +
69207 +BOOLEAN MlmeDelBAReqSanity(
69208 + IN PRTMP_ADAPTER pAd,
69209 + IN VOID *Msg,
69210 + IN ULONG MsgLen);
69211 +
69212 +BOOLEAN MlmeAddBAReqSanity(
69213 + IN PRTMP_ADAPTER pAd,
69214 + IN VOID *Msg,
69215 + IN ULONG MsgLen,
69216 + OUT PUCHAR pAddr2);
69217 +
69218 +ULONG MakeOutgoingFrame(
69219 + OUT CHAR *Buffer,
69220 + OUT ULONG *Length, ...);
69221 +
69222 +VOID LfsrInit(
69223 + IN PRTMP_ADAPTER pAd,
69224 + IN ULONG Seed);
69225 +
69226 +UCHAR RandomByte(
69227 + IN PRTMP_ADAPTER pAd);
69228 +
69229 +VOID AsicUpdateAutoFallBackTable(
69230 + IN PRTMP_ADAPTER pAd,
69231 + IN PUCHAR pTxRate);
69232 +
69233 +VOID MlmePeriodicExec(
69234 + IN PVOID SystemSpecific1,
69235 + IN PVOID FunctionContext,
69236 + IN PVOID SystemSpecific2,
69237 + IN PVOID SystemSpecific3);
69238 +
69239 +VOID LinkDownExec(
69240 + IN PVOID SystemSpecific1,
69241 + IN PVOID FunctionContext,
69242 + IN PVOID SystemSpecific2,
69243 + IN PVOID SystemSpecific3);
69244 +
69245 +VOID LinkUpExec(
69246 + IN PVOID SystemSpecific1,
69247 + IN PVOID FunctionContext,
69248 + IN PVOID SystemSpecific2,
69249 + IN PVOID SystemSpecific3);
69250 +
69251 +VOID STAMlmePeriodicExec(
69252 + PRTMP_ADAPTER pAd);
69253 +
69254 +VOID MlmeAutoScan(
69255 + IN PRTMP_ADAPTER pAd);
69256 +
69257 +VOID MlmeAutoReconnectLastSSID(
69258 + IN PRTMP_ADAPTER pAd);
69259 +
69260 +BOOLEAN MlmeValidateSSID(
69261 + IN PUCHAR pSsid,
69262 + IN UCHAR SsidLen);
69263 +
69264 +VOID MlmeCheckForRoaming(
69265 + IN PRTMP_ADAPTER pAd,
69266 + IN ULONG Now32);
69267 +
69268 +VOID MlmeCheckForFastRoaming(
69269 + IN PRTMP_ADAPTER pAd,
69270 + IN ULONG Now);
69271 +
69272 +VOID MlmeDynamicTxRateSwitching(
69273 + IN PRTMP_ADAPTER pAd);
69274 +
69275 +VOID MlmeSetTxRate(
69276 + IN PRTMP_ADAPTER pAd,
69277 + IN PMAC_TABLE_ENTRY pEntry,
69278 + IN PRTMP_TX_RATE_SWITCH pTxRate);
69279 +
69280 +VOID MlmeSelectTxRateTable(
69281 + IN PRTMP_ADAPTER pAd,
69282 + IN PMAC_TABLE_ENTRY pEntry,
69283 + IN PUCHAR *ppTable,
69284 + IN PUCHAR pTableSize,
69285 + IN PUCHAR pInitTxRateIdx);
69286 +
69287 +VOID MlmeCalculateChannelQuality(
69288 + IN PRTMP_ADAPTER pAd,
69289 + IN ULONG Now);
69290 +
69291 +VOID MlmeCheckPsmChange(
69292 + IN PRTMP_ADAPTER pAd,
69293 + IN ULONG Now32);
69294 +
69295 +VOID MlmeSetPsmBit(
69296 + IN PRTMP_ADAPTER pAd,
69297 + IN USHORT psm);
69298 +
69299 +VOID MlmeSetTxPreamble(
69300 + IN PRTMP_ADAPTER pAd,
69301 + IN USHORT TxPreamble);
69302 +
69303 +VOID UpdateBasicRateBitmap(
69304 + IN PRTMP_ADAPTER pAd);
69305 +
69306 +VOID MlmeUpdateTxRates(
69307 + IN PRTMP_ADAPTER pAd,
69308 + IN BOOLEAN bLinkUp,
69309 + IN UCHAR apidx);
69310 +
69311 +#ifdef DOT11_N_SUPPORT
69312 +VOID MlmeUpdateHtTxRates(
69313 + IN PRTMP_ADAPTER pAd,
69314 + IN UCHAR apidx);
69315 +#endif // DOT11_N_SUPPORT //
69316 +
69317 +VOID RTMPCheckRates(
69318 + IN PRTMP_ADAPTER pAd,
69319 + IN OUT UCHAR SupRate[],
69320 + IN OUT UCHAR *SupRateLen);
69321 +
69322 +#ifdef CONFIG_STA_SUPPORT
69323 +BOOLEAN RTMPCheckChannel(
69324 + IN PRTMP_ADAPTER pAd,
69325 + IN UCHAR CentralChannel,
69326 + IN UCHAR Channel);
69327 +#endif // CONFIG_STA_SUPPORT //
69328 +
69329 +BOOLEAN RTMPCheckHt(
69330 + IN PRTMP_ADAPTER pAd,
69331 + IN UCHAR Wcid,
69332 + IN OUT HT_CAPABILITY_IE *pHtCapability,
69333 + IN OUT ADD_HT_INFO_IE *pAddHtInfo);
69334 +
69335 +VOID StaQuickResponeForRateUpExec(
69336 + IN PVOID SystemSpecific1,
69337 + IN PVOID FunctionContext,
69338 + IN PVOID SystemSpecific2,
69339 + IN PVOID SystemSpecific3);
69340 +
69341 +VOID AsicBbpTuning1(
69342 + IN PRTMP_ADAPTER pAd);
69343 +
69344 +VOID AsicBbpTuning2(
69345 + IN PRTMP_ADAPTER pAd);
69346 +
69347 +VOID RTMPUpdateMlmeRate(
69348 + IN PRTMP_ADAPTER pAd);
69349 +
69350 +CHAR RTMPMaxRssi(
69351 + IN PRTMP_ADAPTER pAd,
69352 + IN CHAR Rssi0,
69353 + IN CHAR Rssi1,
69354 + IN CHAR Rssi2);
69355 +
69356 +VOID AsicSetRxAnt(
69357 + IN PRTMP_ADAPTER pAd,
69358 + IN UCHAR Ant);
69359 +
69360 +VOID AsicEvaluateRxAnt(
69361 + IN PRTMP_ADAPTER pAd);
69362 +
69363 +VOID AsicRxAntEvalTimeout(
69364 + IN PVOID SystemSpecific1,
69365 + IN PVOID FunctionContext,
69366 + IN PVOID SystemSpecific2,
69367 + IN PVOID SystemSpecific3);
69368 +
69369 +VOID APSDPeriodicExec(
69370 + IN PVOID SystemSpecific1,
69371 + IN PVOID FunctionContext,
69372 + IN PVOID SystemSpecific2,
69373 + IN PVOID SystemSpecific3);
69374 +
69375 +BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(
69376 + IN PRTMP_ADAPTER pAd,
69377 + IN PMAC_TABLE_ENTRY pEntry);
69378 +
69379 +UCHAR RTMPStaFixedTxMode(
69380 + IN PRTMP_ADAPTER pAd,
69381 + IN PMAC_TABLE_ENTRY pEntry);
69382 +
69383 +VOID RTMPUpdateLegacyTxSetting(
69384 + UCHAR fixed_tx_mode,
69385 + PMAC_TABLE_ENTRY pEntry);
69386 +
69387 +BOOLEAN RTMPAutoRateSwitchCheck(
69388 + IN PRTMP_ADAPTER pAd);
69389 +
69390 +NDIS_STATUS MlmeInit(
69391 + IN PRTMP_ADAPTER pAd);
69392 +
69393 +VOID MlmeHandler(
69394 + IN PRTMP_ADAPTER pAd);
69395 +
69396 +VOID MlmeHalt(
69397 + IN PRTMP_ADAPTER pAd);
69398 +
69399 +VOID MlmeResetRalinkCounters(
69400 + IN PRTMP_ADAPTER pAd);
69401 +
69402 +VOID BuildChannelList(
69403 + IN PRTMP_ADAPTER pAd);
69404 +
69405 +UCHAR FirstChannel(
69406 + IN PRTMP_ADAPTER pAd);
69407 +
69408 +UCHAR NextChannel(
69409 + IN PRTMP_ADAPTER pAd,
69410 + IN UCHAR channel);
69411 +
69412 +VOID ChangeToCellPowerLimit(
69413 + IN PRTMP_ADAPTER pAd,
69414 + IN UCHAR AironetCellPowerLimit);
69415 +
69416 +VOID RaiseClock(
69417 + IN PRTMP_ADAPTER pAd,
69418 + IN UINT32 *x);
69419 +
69420 +VOID LowerClock(
69421 + IN PRTMP_ADAPTER pAd,
69422 + IN UINT32 *x);
69423 +
69424 +USHORT ShiftInBits(
69425 + IN PRTMP_ADAPTER pAd);
69426 +
69427 +VOID ShiftOutBits(
69428 + IN PRTMP_ADAPTER pAd,
69429 + IN USHORT data,
69430 + IN USHORT count);
69431 +
69432 +VOID EEpromCleanup(
69433 + IN PRTMP_ADAPTER pAd);
69434 +
69435 +VOID EWDS(
69436 + IN PRTMP_ADAPTER pAd);
69437 +
69438 +VOID EWEN(
69439 + IN PRTMP_ADAPTER pAd);
69440 +
69441 +USHORT RTMP_EEPROM_READ16(
69442 + IN PRTMP_ADAPTER pAd,
69443 + IN USHORT Offset);
69444 +
69445 +VOID RTMP_EEPROM_WRITE16(
69446 + IN PRTMP_ADAPTER pAd,
69447 + IN USHORT Offset,
69448 + IN USHORT Data);
69449 +
69450 +//
69451 +// Prototypes of function definition in rtmp_tkip.c
69452 +//
69453 +VOID RTMPInitTkipEngine(
69454 + IN PRTMP_ADAPTER pAd,
69455 + IN PUCHAR pTKey,
69456 + IN UCHAR KeyId,
69457 + IN PUCHAR pTA,
69458 + IN PUCHAR pMICKey,
69459 + IN PUCHAR pTSC,
69460 + OUT PULONG pIV16,
69461 + OUT PULONG pIV32);
69462 +
69463 +VOID RTMPInitMICEngine(
69464 + IN PRTMP_ADAPTER pAd,
69465 + IN PUCHAR pKey,
69466 + IN PUCHAR pDA,
69467 + IN PUCHAR pSA,
69468 + IN UCHAR UserPriority,
69469 + IN PUCHAR pMICKey);
69470 +
69471 +BOOLEAN RTMPTkipCompareMICValue(
69472 + IN PRTMP_ADAPTER pAd,
69473 + IN PUCHAR pSrc,
69474 + IN PUCHAR pDA,
69475 + IN PUCHAR pSA,
69476 + IN PUCHAR pMICKey,
69477 + IN UCHAR UserPriority,
69478 + IN UINT Len);
69479 +
69480 +VOID RTMPCalculateMICValue(
69481 + IN PRTMP_ADAPTER pAd,
69482 + IN PNDIS_PACKET pPacket,
69483 + IN PUCHAR pEncap,
69484 + IN PCIPHER_KEY pKey,
69485 + IN UCHAR apidx);
69486 +
69487 +BOOLEAN RTMPTkipCompareMICValueWithLLC(
69488 + IN PRTMP_ADAPTER pAd,
69489 + IN PUCHAR pLLC,
69490 + IN PUCHAR pSrc,
69491 + IN PUCHAR pDA,
69492 + IN PUCHAR pSA,
69493 + IN PUCHAR pMICKey,
69494 + IN UINT Len);
69495 +
69496 +VOID RTMPTkipAppendByte(
69497 + IN PTKIP_KEY_INFO pTkip,
69498 + IN UCHAR uChar);
69499 +
69500 +VOID RTMPTkipAppend(
69501 + IN PTKIP_KEY_INFO pTkip,
69502 + IN PUCHAR pSrc,
69503 + IN UINT nBytes);
69504 +
69505 +VOID RTMPTkipGetMIC(
69506 + IN PTKIP_KEY_INFO pTkip);
69507 +
69508 +BOOLEAN RTMPSoftDecryptTKIP(
69509 + IN PRTMP_ADAPTER pAd,
69510 + IN PUCHAR pData,
69511 + IN ULONG DataByteCnt,
69512 + IN UCHAR UserPriority,
69513 + IN PCIPHER_KEY pWpaKey);
69514 +
69515 +BOOLEAN RTMPSoftDecryptAES(
69516 + IN PRTMP_ADAPTER pAd,
69517 + IN PUCHAR pData,
69518 + IN ULONG DataByteCnt,
69519 + IN PCIPHER_KEY pWpaKey);
69520 +
69521 +//
69522 +// Prototypes of function definition in cmm_info.c
69523 +//
69524 +NDIS_STATUS RTMPWPARemoveKeyProc(
69525 + IN PRTMP_ADAPTER pAd,
69526 + IN PVOID pBuf);
69527 +
69528 +VOID RTMPWPARemoveAllKeys(
69529 + IN PRTMP_ADAPTER pAd);
69530 +
69531 +BOOLEAN RTMPCheckStrPrintAble(
69532 + IN CHAR *pInPutStr,
69533 + IN UCHAR strLen);
69534 +
69535 +VOID RTMPSetPhyMode(
69536 + IN PRTMP_ADAPTER pAd,
69537 + IN ULONG phymode);
69538 +
69539 +VOID RTMPUpdateHTIE(
69540 + IN RT_HT_CAPABILITY *pRtHt,
69541 + IN UCHAR *pMcsSet,
69542 + OUT HT_CAPABILITY_IE *pHtCapability,
69543 + OUT ADD_HT_INFO_IE *pAddHtInfo);
69544 +
69545 +VOID RTMPAddWcidAttributeEntry(
69546 + IN PRTMP_ADAPTER pAd,
69547 + IN UCHAR BssIdx,
69548 + IN UCHAR KeyIdx,
69549 + IN UCHAR CipherAlg,
69550 + IN MAC_TABLE_ENTRY *pEntry);
69551 +
69552 +CHAR *GetEncryptType(
69553 + CHAR enc);
69554 +
69555 +CHAR *GetAuthMode(
69556 + CHAR auth);
69557 +
69558 +VOID RTMPIoctlGetSiteSurvey(
69559 + IN PRTMP_ADAPTER pAdapter,
69560 + IN struct iwreq *wrq);
69561 +
69562 +VOID RTMPIoctlGetMacTable(
69563 + IN PRTMP_ADAPTER pAd,
69564 + IN struct iwreq *wrq);
69565 +
69566 +VOID RTMPIndicateWPA2Status(
69567 + IN PRTMP_ADAPTER pAdapter);
69568 +
69569 +VOID RTMPOPModeSwitching(
69570 + IN PRTMP_ADAPTER pAd);
69571 +
69572 +#ifdef CONFIG_STA_SUPPORT
69573 +VOID RTMPAddBSSIDCipher(
69574 + IN PRTMP_ADAPTER pAd,
69575 + IN UCHAR Aid,
69576 + IN PNDIS_802_11_KEY pKey,
69577 + IN UCHAR CipherAlg);
69578 +#endif // CONFIG_STA_SUPPORT //
69579 +
69580 +#ifdef DOT11_N_SUPPORT
69581 +VOID RTMPSetHT(
69582 + IN PRTMP_ADAPTER pAd,
69583 + IN OID_SET_HT_PHYMODE *pHTPhyMode);
69584 +
69585 +VOID RTMPSetIndividualHT(
69586 + IN PRTMP_ADAPTER pAd,
69587 + IN UCHAR apidx);
69588 +#endif // DOT11_N_SUPPORT //
69589 +
69590 +VOID RTMPSendWirelessEvent(
69591 + IN PRTMP_ADAPTER pAd,
69592 + IN USHORT Event_flag,
69593 + IN PUCHAR pAddr,
69594 + IN UCHAR BssIdx,
69595 + IN CHAR Rssi);
69596 +
69597 +VOID NICUpdateCntlCounters(
69598 + IN PRTMP_ADAPTER pAd,
69599 + IN PHEADER_802_11 pHeader,
69600 + IN UCHAR SubType,
69601 + IN PRXWI_STRUC pRxWI);
69602 +//
69603 +// prototype in wpa.c
69604 +//
69605 +BOOLEAN WpaMsgTypeSubst(
69606 + IN UCHAR EAPType,
69607 + OUT INT *MsgType);
69608 +
69609 +VOID WpaPskStateMachineInit(
69610 + IN PRTMP_ADAPTER pAd,
69611 + IN STATE_MACHINE *S,
69612 + OUT STATE_MACHINE_FUNC Trans[]);
69613 +
69614 +VOID WpaEAPOLKeyAction(
69615 + IN PRTMP_ADAPTER pAd,
69616 + IN MLME_QUEUE_ELEM *Elem);
69617 +
69618 +VOID WpaPairMsg1Action(
69619 + IN PRTMP_ADAPTER pAd,
69620 + IN MLME_QUEUE_ELEM *Elem);
69621 +
69622 +VOID WpaPairMsg3Action(
69623 + IN PRTMP_ADAPTER pAd,
69624 + IN MLME_QUEUE_ELEM *Elem);
69625 +
69626 +VOID WpaGroupMsg1Action(
69627 + IN PRTMP_ADAPTER pAd,
69628 + IN MLME_QUEUE_ELEM *Elem);
69629 +
69630 +VOID WpaMacHeaderInit(
69631 + IN PRTMP_ADAPTER pAd,
69632 + IN OUT PHEADER_802_11 pHdr80211,
69633 + IN UCHAR wep,
69634 + IN PUCHAR pAddr1);
69635 +
69636 +VOID Wpa2PairMsg1Action(
69637 + IN PRTMP_ADAPTER pAd,
69638 + IN MLME_QUEUE_ELEM *Elem);
69639 +
69640 +VOID Wpa2PairMsg3Action(
69641 + IN PRTMP_ADAPTER pAd,
69642 + IN MLME_QUEUE_ELEM *Elem);
69643 +
69644 +BOOLEAN ParseKeyData(
69645 + IN PRTMP_ADAPTER pAd,
69646 + IN PUCHAR pKeyData,
69647 + IN UCHAR KeyDataLen,
69648 + IN UCHAR bPairewise);
69649 +
69650 +VOID RTMPToWirelessSta(
69651 + IN PRTMP_ADAPTER pAd,
69652 + IN PUCHAR pHeader802_3,
69653 + IN UINT HdrLen,
69654 + IN PUCHAR pData,
69655 + IN UINT DataLen,
69656 + IN BOOLEAN is4wayFrame);
69657 +
69658 +VOID HMAC_SHA1(
69659 + IN UCHAR *text,
69660 + IN UINT text_len,
69661 + IN UCHAR *key,
69662 + IN UINT key_len,
69663 + IN UCHAR *digest);
69664 +
69665 +VOID PRF(
69666 + IN UCHAR *key,
69667 + IN INT key_len,
69668 + IN UCHAR *prefix,
69669 + IN INT prefix_len,
69670 + IN UCHAR *data,
69671 + IN INT data_len,
69672 + OUT UCHAR *output,
69673 + IN INT len);
69674 +
69675 +VOID CCKMPRF(
69676 + IN UCHAR *key,
69677 + IN INT key_len,
69678 + IN UCHAR *data,
69679 + IN INT data_len,
69680 + OUT UCHAR *output,
69681 + IN INT len);
69682 +
69683 +VOID WpaCountPTK(
69684 + IN PRTMP_ADAPTER pAd,
69685 + IN UCHAR *PMK,
69686 + IN UCHAR *ANonce,
69687 + IN UCHAR *AA,
69688 + IN UCHAR *SNonce,
69689 + IN UCHAR *SA,
69690 + OUT UCHAR *output,
69691 + IN UINT len);
69692 +
69693 +VOID GenRandom(
69694 + IN PRTMP_ADAPTER pAd,
69695 + IN UCHAR *macAddr,
69696 + OUT UCHAR *random);
69697 +
69698 +//
69699 +// prototype in aironet.c
69700 +//
69701 +VOID AironetStateMachineInit(
69702 + IN PRTMP_ADAPTER pAd,
69703 + IN STATE_MACHINE *S,
69704 + OUT STATE_MACHINE_FUNC Trans[]);
69705 +
69706 +VOID AironetMsgAction(
69707 + IN PRTMP_ADAPTER pAd,
69708 + IN MLME_QUEUE_ELEM *Elem);
69709 +
69710 +VOID AironetRequestAction(
69711 + IN PRTMP_ADAPTER pAd,
69712 + IN MLME_QUEUE_ELEM *Elem);
69713 +
69714 +VOID ChannelLoadRequestAction(
69715 + IN PRTMP_ADAPTER pAd,
69716 + IN UCHAR Index);
69717 +
69718 +VOID NoiseHistRequestAction(
69719 + IN PRTMP_ADAPTER pAd,
69720 + IN UCHAR Index);
69721 +
69722 +VOID BeaconRequestAction(
69723 + IN PRTMP_ADAPTER pAd,
69724 + IN UCHAR Index);
69725 +
69726 +VOID AironetReportAction(
69727 + IN PRTMP_ADAPTER pAd,
69728 + IN MLME_QUEUE_ELEM *Elem);
69729 +
69730 +VOID ChannelLoadReportAction(
69731 + IN PRTMP_ADAPTER pAd,
69732 + IN UCHAR Index);
69733 +
69734 +VOID NoiseHistReportAction(
69735 + IN PRTMP_ADAPTER pAd,
69736 + IN UCHAR Index);
69737 +
69738 +VOID AironetFinalReportAction(
69739 + IN PRTMP_ADAPTER pAd);
69740 +
69741 +VOID BeaconReportAction(
69742 + IN PRTMP_ADAPTER pAd,
69743 + IN UCHAR Index);
69744 +
69745 +VOID AironetAddBeaconReport(
69746 + IN PRTMP_ADAPTER pAd,
69747 + IN ULONG Index,
69748 + IN PMLME_QUEUE_ELEM pElem);
69749 +
69750 +VOID AironetCreateBeaconReportFromBssTable(
69751 + IN PRTMP_ADAPTER pAd);
69752 +
69753 +VOID DBGPRINT_TX_RING(
69754 + IN PRTMP_ADAPTER pAd,
69755 + IN UCHAR QueIdx);
69756 +
69757 +VOID DBGPRINT_RX_RING(
69758 + IN PRTMP_ADAPTER pAd);
69759 +
69760 +CHAR ConvertToRssi(
69761 + IN PRTMP_ADAPTER pAd,
69762 + IN CHAR Rssi,
69763 + IN UCHAR RssiNumber);
69764 +
69765 +
69766 +#ifdef DOT11N_DRAFT3
69767 +VOID BuildEffectedChannelList(
69768 + IN PRTMP_ADAPTER pAd);
69769 +#endif // DOT11N_DRAFT3 //
69770 +
69771 +
69772 +VOID APAsicEvaluateRxAnt(
69773 + IN PRTMP_ADAPTER pAd);
69774 +
69775 +
69776 +VOID APAsicRxAntEvalTimeout(
69777 + IN PRTMP_ADAPTER pAd);
69778 +
69779 +//
69780 +// function prototype in cmm_wpa.c
69781 +//
69782 +BOOLEAN RTMPCheckWPAframe(
69783 + IN PRTMP_ADAPTER pAd,
69784 + IN PMAC_TABLE_ENTRY pEntry,
69785 + IN PUCHAR pData,
69786 + IN ULONG DataByteCount,
69787 + IN UCHAR FromWhichBSSID);
69788 +
69789 +VOID AES_GTK_KEY_UNWRAP(
69790 + IN UCHAR *key,
69791 + OUT UCHAR *plaintext,
69792 + IN UCHAR c_len,
69793 + IN UCHAR *ciphertext);
69794 +
69795 +BOOLEAN RTMPCheckRSNIE(
69796 + IN PRTMP_ADAPTER pAd,
69797 + IN PUCHAR pData,
69798 + IN UCHAR DataLen,
69799 + IN MAC_TABLE_ENTRY *pEntry,
69800 + OUT UCHAR *Offset);
69801 +
69802 +BOOLEAN RTMPParseEapolKeyData(
69803 + IN PRTMP_ADAPTER pAd,
69804 + IN PUCHAR pKeyData,
69805 + IN UCHAR KeyDataLen,
69806 + IN UCHAR GroupKeyIndex,
69807 + IN UCHAR MsgType,
69808 + IN BOOLEAN bWPA2,
69809 + IN MAC_TABLE_ENTRY *pEntry);
69810 +
69811 +VOID ConstructEapolMsg(
69812 + IN PRTMP_ADAPTER pAd,
69813 + IN UCHAR PeerAuthMode,
69814 + IN UCHAR PeerWepStatus,
69815 + IN UCHAR MyGroupKeyWepStatus,
69816 + IN UCHAR MsgType,
69817 + IN UCHAR DefaultKeyIdx,
69818 + IN UCHAR *ReplayCounter,
69819 + IN UCHAR *KeyNonce,
69820 + IN UCHAR *TxRSC,
69821 + IN UCHAR *PTK,
69822 + IN UCHAR *GTK,
69823 + IN UCHAR *RSNIE,
69824 + IN UCHAR RSNIE_Len,
69825 + OUT PEAPOL_PACKET pMsg);
69826 +
69827 +VOID CalculateMIC(
69828 + IN PRTMP_ADAPTER pAd,
69829 + IN UCHAR PeerWepStatus,
69830 + IN UCHAR *PTK,
69831 + OUT PEAPOL_PACKET pMsg);
69832 +
69833 +NDIS_STATUS RTMPSoftDecryptBroadCastData(
69834 + IN PRTMP_ADAPTER pAd,
69835 + IN RX_BLK *pRxBlk,
69836 + IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
69837 + IN PCIPHER_KEY pShard_key);
69838 +
69839 +VOID ConstructEapolKeyData(
69840 + IN PRTMP_ADAPTER pAd,
69841 + IN UCHAR PeerAuthMode,
69842 + IN UCHAR PeerWepStatus,
69843 + IN UCHAR GroupKeyWepStatus,
69844 + IN UCHAR MsgType,
69845 + IN UCHAR DefaultKeyIdx,
69846 + IN BOOLEAN bWPA2Capable,
69847 + IN UCHAR *PTK,
69848 + IN UCHAR *GTK,
69849 + IN UCHAR *RSNIE,
69850 + IN UCHAR RSNIE_LEN,
69851 + OUT PEAPOL_PACKET pMsg);
69852 +
69853 +VOID RTMPMakeRSNIE(
69854 + IN PRTMP_ADAPTER pAd,
69855 + IN UINT AuthMode,
69856 + IN UINT WepStatus,
69857 + IN UCHAR apidx);
69858 +
69859 +//
69860 +// function prototype in ap_wpa.c
69861 +//
69862 +
69863 +BOOLEAN APWpaMsgTypeSubst(
69864 + IN UCHAR EAPType,
69865 + OUT INT *MsgType) ;
69866 +
69867 +MAC_TABLE_ENTRY *PACInquiry(
69868 + IN PRTMP_ADAPTER pAd,
69869 + IN ULONG Wcid);
69870 +
69871 +BOOLEAN RTMPCheckMcast(
69872 + IN PRTMP_ADAPTER pAd,
69873 + IN PEID_STRUCT eid_ptr,
69874 + IN MAC_TABLE_ENTRY *pEntry);
69875 +
69876 +BOOLEAN RTMPCheckUcast(
69877 + IN PRTMP_ADAPTER pAd,
69878 + IN PEID_STRUCT eid_ptr,
69879 + IN MAC_TABLE_ENTRY *pEntry);
69880 +
69881 +BOOLEAN RTMPCheckAUTH(
69882 + IN PRTMP_ADAPTER pAd,
69883 + IN PEID_STRUCT eid_ptr,
69884 + IN MAC_TABLE_ENTRY *pEntry);
69885 +
69886 +VOID WPAStart4WayHS(
69887 + IN PRTMP_ADAPTER pAd,
69888 + IN MAC_TABLE_ENTRY *pEntry,
69889 + IN ULONG TimeInterval);
69890 +
69891 +VOID WPAStart2WayGroupHS(
69892 + IN PRTMP_ADAPTER pAd,
69893 + IN MAC_TABLE_ENTRY *pEntry);
69894 +
69895 +VOID APWpaEAPPacketAction(
69896 + IN PRTMP_ADAPTER pAd,
69897 + IN MLME_QUEUE_ELEM *Elem);
69898 +
69899 +VOID APWpaEAPOLStartAction(
69900 + IN PRTMP_ADAPTER pAd,
69901 + IN MLME_QUEUE_ELEM *Elem);
69902 +
69903 +VOID APWpaEAPOLLogoffAction(
69904 + IN PRTMP_ADAPTER pAd,
69905 + IN MLME_QUEUE_ELEM *Elem);
69906 +
69907 +VOID APWpaEAPOLKeyAction(
69908 + IN PRTMP_ADAPTER pAd,
69909 + IN MLME_QUEUE_ELEM *Elem);
69910 +
69911 +VOID APWpaEAPOLASFAlertAction(
69912 + IN PRTMP_ADAPTER pAd,
69913 + IN MLME_QUEUE_ELEM *Elem);
69914 +
69915 +VOID HandleCounterMeasure(
69916 + IN PRTMP_ADAPTER pAd,
69917 + IN MAC_TABLE_ENTRY *pEntry);
69918 +
69919 +VOID PeerPairMsg2Action(
69920 + IN PRTMP_ADAPTER pAd,
69921 + IN MAC_TABLE_ENTRY *pEntry,
69922 + IN MLME_QUEUE_ELEM *Elem);
69923 +
69924 +VOID PeerPairMsg4Action(
69925 + IN PRTMP_ADAPTER pAd,
69926 + IN MAC_TABLE_ENTRY *pEntry,
69927 + IN MLME_QUEUE_ELEM *Elem);
69928 +
69929 +VOID CMTimerExec(
69930 + IN PVOID SystemSpecific1,
69931 + IN PVOID FunctionContext,
69932 + IN PVOID SystemSpecific2,
69933 + IN PVOID SystemSpecific3);
69934 +
69935 +VOID WPARetryExec(
69936 + IN PVOID SystemSpecific1,
69937 + IN PVOID FunctionContext,
69938 + IN PVOID SystemSpecific2,
69939 + IN PVOID SystemSpecific3);
69940 +
69941 +VOID EnqueueStartForPSKExec(
69942 + IN PVOID SystemSpecific1,
69943 + IN PVOID FunctionContext,
69944 + IN PVOID SystemSpecific2,
69945 + IN PVOID SystemSpecific3);
69946 +
69947 +VOID RTMPHandleSTAKey(
69948 + IN PRTMP_ADAPTER pAdapter,
69949 + IN MAC_TABLE_ENTRY *pEntry,
69950 + IN MLME_QUEUE_ELEM *Elem);
69951 +
69952 +VOID PeerGroupMsg2Action(
69953 + IN PRTMP_ADAPTER pAd,
69954 + IN PMAC_TABLE_ENTRY pEntry,
69955 + IN VOID *Msg,
69956 + IN UINT MsgLen);
69957 +
69958 +VOID PairDisAssocAction(
69959 + IN PRTMP_ADAPTER pAd,
69960 + IN PMAC_TABLE_ENTRY pEntry,
69961 + IN USHORT Reason);
69962 +
69963 +VOID MlmeDeAuthAction(
69964 + IN PRTMP_ADAPTER pAd,
69965 + IN PMAC_TABLE_ENTRY pEntry,
69966 + IN USHORT Reason);
69967 +
69968 +VOID GREKEYPeriodicExec(
69969 + IN PVOID SystemSpecific1,
69970 + IN PVOID FunctionContext,
69971 + IN PVOID SystemSpecific2,
69972 + IN PVOID SystemSpecific3);
69973 +
69974 +VOID CountGTK(
69975 + IN UCHAR *PMK,
69976 + IN UCHAR *GNonce,
69977 + IN UCHAR *AA,
69978 + OUT UCHAR *output,
69979 + IN UINT len);
69980 +
69981 +VOID GetSmall(
69982 + IN PVOID pSrc1,
69983 + IN PVOID pSrc2,
69984 + OUT PUCHAR out,
69985 + IN ULONG Length);
69986 +
69987 +VOID GetLarge(
69988 + IN PVOID pSrc1,
69989 + IN PVOID pSrc2,
69990 + OUT PUCHAR out,
69991 + IN ULONG Length);
69992 +
69993 +VOID APGenRandom(
69994 + IN PRTMP_ADAPTER pAd,
69995 + OUT UCHAR *random);
69996 +
69997 +VOID AES_GTK_KEY_WRAP(
69998 + IN UCHAR *key,
69999 + IN UCHAR *plaintext,
70000 + IN UCHAR p_len,
70001 + OUT UCHAR *ciphertext);
70002 +
70003 +VOID WpaSend(
70004 + IN PRTMP_ADAPTER pAdapter,
70005 + IN PUCHAR pPacket,
70006 + IN ULONG Len);
70007 +
70008 +VOID APToWirelessSta(
70009 + IN PRTMP_ADAPTER pAd,
70010 + IN MAC_TABLE_ENTRY *pEntry,
70011 + IN PUCHAR pHeader802_3,
70012 + IN UINT HdrLen,
70013 + IN PUCHAR pData,
70014 + IN UINT DataLen,
70015 + IN BOOLEAN bClearFrame);
70016 +
70017 +VOID RTMPAddPMKIDCache(
70018 + IN PRTMP_ADAPTER pAd,
70019 + IN INT apidx,
70020 + IN PUCHAR pAddr,
70021 + IN UCHAR *PMKID,
70022 + IN UCHAR *PMK);
70023 +
70024 +INT RTMPSearchPMKIDCache(
70025 + IN PRTMP_ADAPTER pAd,
70026 + IN INT apidx,
70027 + IN PUCHAR pAddr);
70028 +
70029 +VOID RTMPDeletePMKIDCache(
70030 + IN PRTMP_ADAPTER pAd,
70031 + IN INT apidx,
70032 + IN INT idx);
70033 +
70034 +VOID RTMPMaintainPMKIDCache(
70035 + IN PRTMP_ADAPTER pAd);
70036 +
70037 +VOID RTMPSendTriggerFrame(
70038 + IN PRTMP_ADAPTER pAd,
70039 + IN PVOID pBuffer,
70040 + IN ULONG Length,
70041 + IN UCHAR TxRate,
70042 + IN BOOLEAN bQosNull);
70043 +
70044 +#ifdef RT30xx
70045 +VOID RTMPFilterCalibration(
70046 + IN PRTMP_ADAPTER pAd);
70047 +#endif // RT30xx //
70048 +
70049 +
70050 +//typedef void (*TIMER_FUNCTION)(unsigned long);
70051 +
70052 +
70053 +/* timeout -- ms */
70054 +VOID RTMP_SetPeriodicTimer(
70055 + IN NDIS_MINIPORT_TIMER *pTimer,
70056 + IN unsigned long timeout);
70057 +
70058 +VOID RTMP_OS_Init_Timer(
70059 + IN PRTMP_ADAPTER pAd,
70060 + IN NDIS_MINIPORT_TIMER *pTimer,
70061 + IN TIMER_FUNCTION function,
70062 + IN PVOID data);
70063 +
70064 +VOID RTMP_OS_Add_Timer(
70065 + IN NDIS_MINIPORT_TIMER *pTimer,
70066 + IN unsigned long timeout);
70067 +
70068 +VOID RTMP_OS_Mod_Timer(
70069 + IN NDIS_MINIPORT_TIMER *pTimer,
70070 + IN unsigned long timeout);
70071 +
70072 +
70073 +VOID RTMP_OS_Del_Timer(
70074 + IN NDIS_MINIPORT_TIMER *pTimer,
70075 + OUT BOOLEAN *pCancelled);
70076 +
70077 +
70078 +VOID RTMP_OS_Release_Packet(
70079 + IN PRTMP_ADAPTER pAd,
70080 + IN PQUEUE_ENTRY pEntry);
70081 +
70082 +VOID RTMPusecDelay(
70083 + IN ULONG usec);
70084 +
70085 +NDIS_STATUS os_alloc_mem(
70086 + IN PRTMP_ADAPTER pAd,
70087 + OUT PUCHAR *mem,
70088 + IN ULONG size);
70089 +
70090 +NDIS_STATUS os_free_mem(
70091 + IN PRTMP_ADAPTER pAd,
70092 + IN PUCHAR mem);
70093 +
70094 +
70095 +void RTMP_AllocateSharedMemory(
70096 + IN PRTMP_ADAPTER pAd,
70097 + IN ULONG Length,
70098 + IN BOOLEAN Cached,
70099 + OUT PVOID *VirtualAddress,
70100 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70101 +
70102 +VOID RTMPFreeTxRxRingMemory(
70103 + IN PRTMP_ADAPTER pAd);
70104 +
70105 +NDIS_STATUS AdapterBlockAllocateMemory(
70106 + IN PVOID handle,
70107 + OUT PVOID *ppAd);
70108 +
70109 +void RTMP_AllocateTxDescMemory(
70110 + IN PRTMP_ADAPTER pAd,
70111 + IN UINT Index,
70112 + IN ULONG Length,
70113 + IN BOOLEAN Cached,
70114 + OUT PVOID *VirtualAddress,
70115 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70116 +
70117 +void RTMP_AllocateFirstTxBuffer(
70118 + IN PRTMP_ADAPTER pAd,
70119 + IN UINT Index,
70120 + IN ULONG Length,
70121 + IN BOOLEAN Cached,
70122 + OUT PVOID *VirtualAddress,
70123 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70124 +
70125 +void RTMP_AllocateMgmtDescMemory(
70126 + IN PRTMP_ADAPTER pAd,
70127 + IN ULONG Length,
70128 + IN BOOLEAN Cached,
70129 + OUT PVOID *VirtualAddress,
70130 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70131 +
70132 +void RTMP_AllocateRxDescMemory(
70133 + IN PRTMP_ADAPTER pAd,
70134 + IN ULONG Length,
70135 + IN BOOLEAN Cached,
70136 + OUT PVOID *VirtualAddress,
70137 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70138 +
70139 +PNDIS_PACKET RTMP_AllocateRxPacketBuffer(
70140 + IN PRTMP_ADAPTER pAd,
70141 + IN ULONG Length,
70142 + IN BOOLEAN Cached,
70143 + OUT PVOID *VirtualAddress,
70144 + OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
70145 +
70146 +PNDIS_PACKET RTMP_AllocateTxPacketBuffer(
70147 + IN PRTMP_ADAPTER pAd,
70148 + IN ULONG Length,
70149 + IN BOOLEAN Cached,
70150 + OUT PVOID *VirtualAddress);
70151 +
70152 +PNDIS_PACKET RTMP_AllocateFragPacketBuffer(
70153 + IN PRTMP_ADAPTER pAd,
70154 + IN ULONG Length);
70155 +
70156 +void RTMP_QueryPacketInfo(
70157 + IN PNDIS_PACKET pPacket,
70158 + OUT PACKET_INFO *pPacketInfo,
70159 + OUT PUCHAR *pSrcBufVA,
70160 + OUT UINT *pSrcBufLen);
70161 +
70162 +void RTMP_QueryNextPacketInfo(
70163 + IN PNDIS_PACKET *ppPacket,
70164 + OUT PACKET_INFO *pPacketInfo,
70165 + OUT PUCHAR *pSrcBufVA,
70166 + OUT UINT *pSrcBufLen);
70167 +
70168 +
70169 +BOOLEAN RTMP_FillTxBlkInfo(
70170 + IN RTMP_ADAPTER *pAd,
70171 + IN TX_BLK *pTxBlk);
70172 +
70173 +
70174 +PRTMP_SCATTER_GATHER_LIST
70175 +rt_get_sg_list_from_packet(PNDIS_PACKET pPacket, RTMP_SCATTER_GATHER_LIST *sg);
70176 +
70177 +
70178 + void announce_802_3_packet(
70179 + IN PRTMP_ADAPTER pAd,
70180 + IN PNDIS_PACKET pPacket);
70181 +
70182 +
70183 +UINT BA_Reorder_AMSDU_Annnounce(
70184 + IN PRTMP_ADAPTER pAd,
70185 + IN PNDIS_PACKET pPacket);
70186 +
70187 +
70188 +UINT Handle_AMSDU_Packet(
70189 + IN PRTMP_ADAPTER pAd,
70190 + IN PUCHAR pData,
70191 + IN ULONG DataSize,
70192 + IN UCHAR FromWhichBSSID);
70193 +
70194 +
70195 +void convert_802_11_to_802_3_packet(
70196 + IN PRTMP_ADAPTER pAd,
70197 + IN PNDIS_PACKET pPacket,
70198 + IN PUCHAR p8023hdr,
70199 + IN PUCHAR pData,
70200 + IN ULONG DataSize,
70201 + IN UCHAR FromWhichBSSID);
70202 +
70203 +
70204 +PNET_DEV get_netdev_from_bssid(
70205 + IN PRTMP_ADAPTER pAd,
70206 + IN UCHAR FromWhichBSSID);
70207 +
70208 +
70209 +PNDIS_PACKET duplicate_pkt(
70210 + IN PRTMP_ADAPTER pAd,
70211 + IN PUCHAR pHeader802_3,
70212 + IN UINT HdrLen,
70213 + IN PUCHAR pData,
70214 + IN ULONG DataSize,
70215 + IN UCHAR FromWhichBSSID);
70216 +
70217 +
70218 +PNDIS_PACKET duplicate_pkt_with_TKIP_MIC(
70219 + IN PRTMP_ADAPTER pAd,
70220 + IN PNDIS_PACKET pOldPkt);
70221 +
70222 +PNDIS_PACKET duplicate_pkt_with_VLAN(
70223 + IN PRTMP_ADAPTER pAd,
70224 + IN PUCHAR pHeader802_3,
70225 + IN UINT HdrLen,
70226 + IN PUCHAR pData,
70227 + IN ULONG DataSize,
70228 + IN UCHAR FromWhichBSSID);
70229 +
70230 +PNDIS_PACKET duplicate_pkt_with_WPI(
70231 + IN PRTMP_ADAPTER pAd,
70232 + IN PNDIS_PACKET pPacket,
70233 + IN UINT32 ext_head_len,
70234 + IN UINT32 ext_tail_len);
70235 +
70236 +UCHAR VLAN_8023_Header_Copy(
70237 + IN PRTMP_ADAPTER pAd,
70238 + IN PUCHAR pHeader802_3,
70239 + IN UINT HdrLen,
70240 + OUT PUCHAR pData,
70241 + IN UCHAR FromWhichBSSID);
70242 +
70243 +#ifdef DOT11_N_SUPPORT
70244 +void ba_flush_reordering_timeout_mpdus(
70245 + IN PRTMP_ADAPTER pAd,
70246 + IN PBA_REC_ENTRY pBAEntry,
70247 + IN ULONG Now32);
70248 +
70249 +
70250 +VOID BAOriSessionSetUp(
70251 + IN PRTMP_ADAPTER pAd,
70252 + IN MAC_TABLE_ENTRY *pEntry,
70253 + IN UCHAR TID,
70254 + IN USHORT TimeOut,
70255 + IN ULONG DelayTime,
70256 + IN BOOLEAN isForced);
70257 +
70258 +VOID BASessionTearDownALL(
70259 + IN OUT PRTMP_ADAPTER pAd,
70260 + IN UCHAR Wcid);
70261 +#endif // DOT11_N_SUPPORT //
70262 +
70263 +BOOLEAN OS_Need_Clone_Packet(void);
70264 +
70265 +
70266 +VOID build_tx_packet(
70267 + IN PRTMP_ADAPTER pAd,
70268 + IN PNDIS_PACKET pPacket,
70269 + IN PUCHAR pFrame,
70270 + IN ULONG FrameLen);
70271 +
70272 +
70273 +VOID BAOriSessionTearDown(
70274 + IN OUT PRTMP_ADAPTER pAd,
70275 + IN UCHAR Wcid,
70276 + IN UCHAR TID,
70277 + IN BOOLEAN bPassive,
70278 + IN BOOLEAN bForceSend);
70279 +
70280 +VOID BARecSessionTearDown(
70281 + IN OUT PRTMP_ADAPTER pAd,
70282 + IN UCHAR Wcid,
70283 + IN UCHAR TID,
70284 + IN BOOLEAN bPassive);
70285 +
70286 +BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
70287 +void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
70288 +
70289 +ULONG AutoChBssInsertEntry(
70290 + IN PRTMP_ADAPTER pAd,
70291 + IN PUCHAR pBssid,
70292 + IN CHAR Ssid[],
70293 + IN UCHAR SsidLen,
70294 + IN UCHAR ChannelNo,
70295 + IN CHAR Rssi);
70296 +
70297 +void AutoChBssTableInit(
70298 + IN PRTMP_ADAPTER pAd);
70299 +
70300 +void ChannelInfoInit(
70301 + IN PRTMP_ADAPTER pAd);
70302 +
70303 +void AutoChBssTableDestroy(
70304 + IN PRTMP_ADAPTER pAd);
70305 +
70306 +void ChannelInfoDestroy(
70307 + IN PRTMP_ADAPTER pAd);
70308 +
70309 +UCHAR New_ApAutoSelectChannel(
70310 + IN PRTMP_ADAPTER pAd);
70311 +
70312 +
70313 +#ifdef NINTENDO_AP
70314 +VOID InitNINTENDO_TABLE(
70315 + IN PRTMP_ADAPTER pAd);
70316 +
70317 +UCHAR CheckNINTENDO_TABLE(
70318 + IN PRTMP_ADAPTER pAd,
70319 + PCHAR pDS_Ssid,
70320 + UCHAR DS_SsidLen,
70321 + PUCHAR pDS_Addr);
70322 +
70323 +UCHAR DelNINTENDO_ENTRY(
70324 + IN PRTMP_ADAPTER pAd,
70325 + UCHAR * pDS_Addr);
70326 +
70327 +VOID RTMPIoctlNintendoCapable(
70328 + IN PRTMP_ADAPTER pAd,
70329 + IN struct iwreq *wrq);
70330 +
70331 +VOID RTMPIoctlNintendoGetTable(
70332 + IN PRTMP_ADAPTER pAd,
70333 + IN struct iwreq *wrq);
70334 +
70335 +VOID RTMPIoctlNintendoSetTable(
70336 + IN PRTMP_ADAPTER pAd,
70337 + IN struct iwreq *wrq);
70338 +
70339 +#endif // NINTENDO_AP //
70340 +
70341 +BOOLEAN rtstrmactohex(
70342 + IN char *s1,
70343 + IN char *s2);
70344 +
70345 +BOOLEAN rtstrcasecmp(
70346 + IN char *s1,
70347 + IN char *s2);
70348 +
70349 +char *rtstrstruncasecmp(
70350 + IN char *s1,
70351 + IN char *s2);
70352 +
70353 +char *rtstrstr(
70354 + IN const char * s1,
70355 + IN const char * s2);
70356 +
70357 +char *rstrtok(
70358 + IN char * s,
70359 + IN const char * ct);
70360 +
70361 +int rtinet_aton(
70362 + const char *cp,
70363 + unsigned int *addr);
70364 +
70365 +////////// common ioctl functions //////////
70366 +INT Set_DriverVersion_Proc(
70367 + IN PRTMP_ADAPTER pAd,
70368 + IN PUCHAR arg);
70369 +
70370 +INT Set_CountryRegion_Proc(
70371 + IN PRTMP_ADAPTER pAd,
70372 + IN PUCHAR arg);
70373 +
70374 +INT Set_CountryRegionABand_Proc(
70375 + IN PRTMP_ADAPTER pAd,
70376 + IN PUCHAR arg);
70377 +
70378 +INT Set_WirelessMode_Proc(
70379 + IN PRTMP_ADAPTER pAd,
70380 + IN PUCHAR arg);
70381 +
70382 +INT Set_Channel_Proc(
70383 + IN PRTMP_ADAPTER pAd,
70384 + IN PUCHAR arg);
70385 +
70386 +INT Set_ShortSlot_Proc(
70387 + IN PRTMP_ADAPTER pAd,
70388 + IN PUCHAR arg);
70389 +
70390 +INT Set_TxPower_Proc(
70391 + IN PRTMP_ADAPTER pAd,
70392 + IN PUCHAR arg);
70393 +
70394 +INT Set_BGProtection_Proc(
70395 + IN PRTMP_ADAPTER pAd,
70396 + IN PUCHAR arg);
70397 +
70398 +INT Set_TxPreamble_Proc(
70399 + IN PRTMP_ADAPTER pAd,
70400 + IN PUCHAR arg);
70401 +
70402 +INT Set_RTSThreshold_Proc(
70403 + IN PRTMP_ADAPTER pAd,
70404 + IN PUCHAR arg);
70405 +
70406 +INT Set_FragThreshold_Proc(
70407 + IN PRTMP_ADAPTER pAd,
70408 + IN PUCHAR arg);
70409 +
70410 +INT Set_TxBurst_Proc(
70411 + IN PRTMP_ADAPTER pAd,
70412 + IN PUCHAR arg);
70413 +
70414 +#ifdef AGGREGATION_SUPPORT
70415 +INT Set_PktAggregate_Proc(
70416 + IN PRTMP_ADAPTER pAd,
70417 + IN PUCHAR arg);
70418 +#endif
70419 +
70420 +INT Set_IEEE80211H_Proc(
70421 + IN PRTMP_ADAPTER pAd,
70422 + IN PUCHAR arg);
70423 +
70424 +#ifdef DBG
70425 +INT Set_Debug_Proc(
70426 + IN PRTMP_ADAPTER pAd,
70427 + IN PUCHAR arg);
70428 +#endif
70429 +
70430 +INT Show_DescInfo_Proc(
70431 + IN PRTMP_ADAPTER pAd,
70432 + IN PUCHAR arg);
70433 +
70434 +INT Set_ResetStatCounter_Proc(
70435 + IN PRTMP_ADAPTER pAd,
70436 + IN PUCHAR arg);
70437 +
70438 +#ifdef DOT11_N_SUPPORT
70439 +INT Set_BASetup_Proc(
70440 + IN PRTMP_ADAPTER pAd,
70441 + IN PUCHAR arg);
70442 +
70443 +INT Set_BADecline_Proc(
70444 + IN PRTMP_ADAPTER pAd,
70445 + IN PUCHAR arg);
70446 +
70447 +INT Set_BAOriTearDown_Proc(
70448 + IN PRTMP_ADAPTER pAd,
70449 + IN PUCHAR arg);
70450 +
70451 +INT Set_BARecTearDown_Proc(
70452 + IN PRTMP_ADAPTER pAd,
70453 + IN PUCHAR arg);
70454 +
70455 +INT Set_HtBw_Proc(
70456 + IN PRTMP_ADAPTER pAd,
70457 + IN PUCHAR arg);
70458 +
70459 +INT Set_HtMcs_Proc(
70460 + IN PRTMP_ADAPTER pAd,
70461 + IN PUCHAR arg);
70462 +
70463 +INT Set_HtGi_Proc(
70464 + IN PRTMP_ADAPTER pAd,
70465 + IN PUCHAR arg);
70466 +
70467 +INT Set_HtOpMode_Proc(
70468 + IN PRTMP_ADAPTER pAd,
70469 + IN PUCHAR arg);
70470 +
70471 +INT Set_HtStbc_Proc(
70472 + IN PRTMP_ADAPTER pAd,
70473 + IN PUCHAR arg);
70474 +
70475 +INT Set_HtHtc_Proc(
70476 + IN PRTMP_ADAPTER pAd,
70477 + IN PUCHAR arg);
70478 +
70479 +INT Set_HtExtcha_Proc(
70480 + IN PRTMP_ADAPTER pAd,
70481 + IN PUCHAR arg);
70482 +
70483 +INT Set_HtMpduDensity_Proc(
70484 + IN PRTMP_ADAPTER pAd,
70485 + IN PUCHAR arg);
70486 +
70487 +INT Set_HtBaWinSize_Proc(
70488 + IN PRTMP_ADAPTER pAd,
70489 + IN PUCHAR arg);
70490 +
70491 +INT Set_HtRdg_Proc(
70492 + IN PRTMP_ADAPTER pAd,
70493 + IN PUCHAR arg);
70494 +
70495 +INT Set_HtLinkAdapt_Proc(
70496 + IN PRTMP_ADAPTER pAd,
70497 + IN PUCHAR arg);
70498 +
70499 +INT Set_HtAmsdu_Proc(
70500 + IN PRTMP_ADAPTER pAd,
70501 + IN PUCHAR arg);
70502 +
70503 +INT Set_HtAutoBa_Proc(
70504 + IN PRTMP_ADAPTER pAd,
70505 + IN PUCHAR arg);
70506 +
70507 +INT Set_HtProtect_Proc(
70508 + IN PRTMP_ADAPTER pAd,
70509 + IN PUCHAR arg);
70510 +
70511 +INT Set_HtMimoPs_Proc(
70512 + IN PRTMP_ADAPTER pAd,
70513 + IN PUCHAR arg);
70514 +
70515 +
70516 +INT Set_ForceShortGI_Proc(
70517 + IN PRTMP_ADAPTER pAd,
70518 + IN PUCHAR arg);
70519 +
70520 +INT Set_ForceGF_Proc(
70521 + IN PRTMP_ADAPTER pAd,
70522 + IN PUCHAR arg);
70523 +
70524 +INT SetCommonHT(
70525 + IN PRTMP_ADAPTER pAd);
70526 +
70527 +INT Set_SendPSMPAction_Proc(
70528 + IN PRTMP_ADAPTER pAd,
70529 + IN PUCHAR arg);
70530 +
70531 +INT Set_HtMIMOPSmode_Proc(
70532 + IN PRTMP_ADAPTER pAd,
70533 + IN PUCHAR arg);
70534 +
70535 +
70536 +INT Set_HtTxBASize_Proc(
70537 + IN PRTMP_ADAPTER pAd,
70538 + IN PUCHAR arg);
70539 +#endif // DOT11_N_SUPPORT //
70540 +
70541 +
70542 +
70543 +#ifdef CONFIG_STA_SUPPORT
70544 +//Dls , kathy
70545 +VOID RTMPSendDLSTearDownFrame(
70546 + IN PRTMP_ADAPTER pAd,
70547 + IN PUCHAR pDA);
70548 +
70549 +#ifdef DOT11_N_SUPPORT
70550 +//Block ACK
70551 +VOID QueryBATABLE(
70552 + IN PRTMP_ADAPTER pAd,
70553 + OUT PQUERYBA_TABLE pBAT);
70554 +#endif // DOT11_N_SUPPORT //
70555 +
70556 +#ifdef WPA_SUPPLICANT_SUPPORT
70557 +INT WpaCheckEapCode(
70558 + IN PRTMP_ADAPTER pAd,
70559 + IN PUCHAR pFrame,
70560 + IN USHORT FrameLen,
70561 + IN USHORT OffSet);
70562 +
70563 +VOID WpaSendMicFailureToWpaSupplicant(
70564 + IN PRTMP_ADAPTER pAd,
70565 + IN BOOLEAN bUnicast);
70566 +
70567 +VOID SendAssocIEsToWpaSupplicant(
70568 + IN PRTMP_ADAPTER pAd);
70569 +#endif // WPA_SUPPLICANT_SUPPORT //
70570 +
70571 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
70572 +int wext_notify_event_assoc(
70573 + IN RTMP_ADAPTER *pAd);
70574 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
70575 +
70576 +#endif // CONFIG_STA_SUPPORT //
70577 +
70578 +
70579 +
70580 +#ifdef DOT11_N_SUPPORT
70581 +VOID Handle_BSS_Width_Trigger_Events(
70582 + IN PRTMP_ADAPTER pAd);
70583 +
70584 +void build_ext_channel_switch_ie(
70585 + IN PRTMP_ADAPTER pAd,
70586 + IN HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE *pIE);
70587 +#endif // DOT11_N_SUPPORT //
70588 +
70589 +
70590 +BOOLEAN APRxDoneInterruptHandle(
70591 + IN PRTMP_ADAPTER pAd);
70592 +
70593 +BOOLEAN STARxDoneInterruptHandle(
70594 + IN PRTMP_ADAPTER pAd,
70595 + IN BOOLEAN argc);
70596 +
70597 +#ifdef DOT11_N_SUPPORT
70598 +// AMPDU packet indication
70599 +VOID Indicate_AMPDU_Packet(
70600 + IN PRTMP_ADAPTER pAd,
70601 + IN RX_BLK *pRxBlk,
70602 + IN UCHAR FromWhichBSSID);
70603 +
70604 +// AMSDU packet indication
70605 +VOID Indicate_AMSDU_Packet(
70606 + IN PRTMP_ADAPTER pAd,
70607 + IN RX_BLK *pRxBlk,
70608 + IN UCHAR FromWhichBSSID);
70609 +#endif // DOT11_N_SUPPORT //
70610 +
70611 +// Normal legacy Rx packet indication
70612 +VOID Indicate_Legacy_Packet(
70613 + IN PRTMP_ADAPTER pAd,
70614 + IN RX_BLK *pRxBlk,
70615 + IN UCHAR FromWhichBSSID);
70616 +
70617 +VOID Indicate_EAPOL_Packet(
70618 + IN PRTMP_ADAPTER pAd,
70619 + IN RX_BLK *pRxBlk,
70620 + IN UCHAR FromWhichBSSID);
70621 +
70622 +void update_os_packet_info(
70623 + IN PRTMP_ADAPTER pAd,
70624 + IN RX_BLK *pRxBlk,
70625 + IN UCHAR FromWhichBSSID);
70626 +
70627 +void wlan_802_11_to_802_3_packet(
70628 + IN PRTMP_ADAPTER pAd,
70629 + IN RX_BLK *pRxBlk,
70630 + IN PUCHAR pHeader802_3,
70631 + IN UCHAR FromWhichBSSID);
70632 +
70633 +UINT deaggregate_AMSDU_announce(
70634 + IN PRTMP_ADAPTER pAd,
70635 + PNDIS_PACKET pPacket,
70636 + IN PUCHAR pData,
70637 + IN ULONG DataSize);
70638 +
70639 +
70640 +#ifdef CONFIG_STA_SUPPORT
70641 +// remove LLC and get 802_3 Header
70642 +#define RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3) \
70643 +{ \
70644 + PUCHAR _pRemovedLLCSNAP = NULL, _pDA, _pSA; \
70645 + \
70646 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH)) \
70647 + { \
70648 + _pDA = _pRxBlk->pHeader->Addr3; \
70649 + _pSA = (PUCHAR)_pRxBlk->pHeader + sizeof(HEADER_802_11); \
70650 + } \
70651 + else \
70652 + { \
70653 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA)) \
70654 + { \
70655 + _pDA = _pRxBlk->pHeader->Addr1; \
70656 + if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS)) \
70657 + _pSA = _pRxBlk->pHeader->Addr2; \
70658 + else \
70659 + _pSA = _pRxBlk->pHeader->Addr3; \
70660 + } \
70661 + else \
70662 + { \
70663 + _pDA = _pRxBlk->pHeader->Addr1; \
70664 + _pSA = _pRxBlk->pHeader->Addr2; \
70665 + } \
70666 + } \
70667 + \
70668 + CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData, \
70669 + _pRxBlk->DataSize, _pRemovedLLCSNAP); \
70670 +}
70671 +#endif // CONFIG_STA_SUPPORT //
70672 +
70673 +
70674 +BOOLEAN APFowardWirelessStaToWirelessSta(
70675 + IN PRTMP_ADAPTER pAd,
70676 + IN PNDIS_PACKET pPacket,
70677 + IN ULONG FromWhichBSSID);
70678 +
70679 +VOID Announce_or_Forward_802_3_Packet(
70680 + IN PRTMP_ADAPTER pAd,
70681 + IN PNDIS_PACKET pPacket,
70682 + IN UCHAR FromWhichBSSID);
70683 +
70684 +VOID Sta_Announce_or_Forward_802_3_Packet(
70685 + IN PRTMP_ADAPTER pAd,
70686 + IN PNDIS_PACKET pPacket,
70687 + IN UCHAR FromWhichBSSID);
70688 +
70689 +
70690 +#ifdef CONFIG_STA_SUPPORT
70691 +#define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
70692 + Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
70693 + //announce_802_3_packet(_pAd, _pPacket);
70694 +#endif // CONFIG_STA_SUPPORT //
70695 +
70696 +
70697 +PNDIS_PACKET DuplicatePacket(
70698 + IN PRTMP_ADAPTER pAd,
70699 + IN PNDIS_PACKET pPacket,
70700 + IN UCHAR FromWhichBSSID);
70701 +
70702 +
70703 +PNDIS_PACKET ClonePacket(
70704 + IN PRTMP_ADAPTER pAd,
70705 + IN PNDIS_PACKET pPacket,
70706 + IN PUCHAR pData,
70707 + IN ULONG DataSize);
70708 +
70709 +
70710 +// Normal, AMPDU or AMSDU
70711 +VOID CmmRxnonRalinkFrameIndicate(
70712 + IN PRTMP_ADAPTER pAd,
70713 + IN RX_BLK *pRxBlk,
70714 + IN UCHAR FromWhichBSSID);
70715 +
70716 +VOID CmmRxRalinkFrameIndicate(
70717 + IN PRTMP_ADAPTER pAd,
70718 + IN MAC_TABLE_ENTRY *pEntry,
70719 + IN RX_BLK *pRxBlk,
70720 + IN UCHAR FromWhichBSSID);
70721 +
70722 +VOID Update_Rssi_Sample(
70723 + IN PRTMP_ADAPTER pAd,
70724 + IN RSSI_SAMPLE *pRssi,
70725 + IN PRXWI_STRUC pRxWI);
70726 +
70727 +PNDIS_PACKET GetPacketFromRxRing(
70728 + IN PRTMP_ADAPTER pAd,
70729 + OUT PRT28XX_RXD_STRUC pSaveRxD,
70730 + OUT BOOLEAN *pbReschedule,
70731 + IN OUT UINT32 *pRxPending);
70732 +
70733 +PNDIS_PACKET RTMPDeFragmentDataFrame(
70734 + IN PRTMP_ADAPTER pAd,
70735 + IN RX_BLK *pRxBlk);
70736 +
70737 +////////////////////////////////////////
70738 +
70739 +
70740 +
70741 +
70742 +
70743 +#ifdef SNMP_SUPPORT
70744 +//for snmp , kathy
70745 +typedef struct _DefaultKeyIdxValue
70746 +{
70747 + UCHAR KeyIdx;
70748 + UCHAR Value[16];
70749 +} DefaultKeyIdxValue, *PDefaultKeyIdxValue;
70750 +#endif
70751 +
70752 +
70753 +#ifdef CONFIG_STA_SUPPORT
70754 +enum {
70755 + DIDmsg_lnxind_wlansniffrm = 0x00000044,
70756 + DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
70757 + DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
70758 + DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
70759 + DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
70760 + DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
70761 + DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
70762 + DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
70763 + DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
70764 + DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
70765 + DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
70766 +};
70767 +enum {
70768 + P80211ENUM_msgitem_status_no_value = 0x00
70769 +};
70770 +enum {
70771 + P80211ENUM_truth_false = 0x00,
70772 + P80211ENUM_truth_true = 0x01
70773 +};
70774 +
70775 +/* Definition from madwifi */
70776 +typedef struct {
70777 + UINT32 did;
70778 + UINT16 status;
70779 + UINT16 len;
70780 + UINT32 data;
70781 +} p80211item_uint32_t;
70782 +
70783 +typedef struct {
70784 + UINT32 msgcode;
70785 + UINT32 msglen;
70786 +#define WLAN_DEVNAMELEN_MAX 16
70787 + UINT8 devname[WLAN_DEVNAMELEN_MAX];
70788 + p80211item_uint32_t hosttime;
70789 + p80211item_uint32_t mactime;
70790 + p80211item_uint32_t channel;
70791 + p80211item_uint32_t rssi;
70792 + p80211item_uint32_t sq;
70793 + p80211item_uint32_t signal;
70794 + p80211item_uint32_t noise;
70795 + p80211item_uint32_t rate;
70796 + p80211item_uint32_t istx;
70797 + p80211item_uint32_t frmlen;
70798 +} wlan_ng_prism2_header;
70799 +
70800 +/* The radio capture header precedes the 802.11 header. */
70801 +typedef struct PACKED _ieee80211_radiotap_header {
70802 + UINT8 it_version; /* Version 0. Only increases
70803 + * for drastic changes,
70804 + * introduction of compatible
70805 + * new fields does not count.
70806 + */
70807 + UINT8 it_pad;
70808 + UINT16 it_len; /* length of the whole
70809 + * header in bytes, including
70810 + * it_version, it_pad,
70811 + * it_len, and data fields.
70812 + */
70813 + UINT32 it_present; /* A bitmap telling which
70814 + * fields are present. Set bit 31
70815 + * (0x80000000) to extend the
70816 + * bitmap by another 32 bits.
70817 + * Additional extensions are made
70818 + * by setting bit 31.
70819 + */
70820 +}ieee80211_radiotap_header ;
70821 +
70822 +enum ieee80211_radiotap_type {
70823 + IEEE80211_RADIOTAP_TSFT = 0,
70824 + IEEE80211_RADIOTAP_FLAGS = 1,
70825 + IEEE80211_RADIOTAP_RATE = 2,
70826 + IEEE80211_RADIOTAP_CHANNEL = 3,
70827 + IEEE80211_RADIOTAP_FHSS = 4,
70828 + IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
70829 + IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
70830 + IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
70831 + IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
70832 + IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
70833 + IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
70834 + IEEE80211_RADIOTAP_ANTENNA = 11,
70835 + IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
70836 + IEEE80211_RADIOTAP_DB_ANTNOISE = 13
70837 +};
70838 +
70839 +#define WLAN_RADIOTAP_PRESENT ( \
70840 + (1 << IEEE80211_RADIOTAP_TSFT) | \
70841 + (1 << IEEE80211_RADIOTAP_FLAGS) | \
70842 + (1 << IEEE80211_RADIOTAP_RATE) | \
70843 + 0)
70844 +
70845 +typedef struct _wlan_radiotap_header {
70846 + ieee80211_radiotap_header wt_ihdr;
70847 + INT64 wt_tsft;
70848 + UINT8 wt_flags;
70849 + UINT8 wt_rate;
70850 +} wlan_radiotap_header;
70851 +/* Definition from madwifi */
70852 +
70853 +void send_monitor_packets(
70854 + IN PRTMP_ADAPTER pAd,
70855 + IN RX_BLK *pRxBlk);
70856 +
70857 +#if WIRELESS_EXT >= 12
70858 +// This function will be called when query /proc
70859 +struct iw_statistics *rt28xx_get_wireless_stats(
70860 + IN struct net_device *net_dev);
70861 +#endif
70862 +
70863 +VOID RTMPSetDesiredRates(
70864 + IN PRTMP_ADAPTER pAdapter,
70865 + IN LONG Rates);
70866 +#endif // CONFIG_STA_SUPPORT //
70867 +
70868 +INT Set_FixedTxMode_Proc(
70869 + IN PRTMP_ADAPTER pAd,
70870 + IN PUCHAR arg);
70871 +
70872 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
70873 +INT Set_OpMode_Proc(
70874 + IN PRTMP_ADAPTER pAd,
70875 + IN PUCHAR arg);
70876 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
70877 +
70878 +static inline char* GetPhyMode(
70879 + int Mode)
70880 +{
70881 + switch(Mode)
70882 + {
70883 + case MODE_CCK:
70884 + return "CCK";
70885 +
70886 + case MODE_OFDM:
70887 + return "OFDM";
70888 +#ifdef DOT11_N_SUPPORT
70889 + case MODE_HTMIX:
70890 + return "HTMIX";
70891 +
70892 + case MODE_HTGREENFIELD:
70893 + return "GREEN";
70894 +#endif // DOT11_N_SUPPORT //
70895 + default:
70896 + return "N/A";
70897 + }
70898 +}
70899 +
70900 +
70901 +static inline char* GetBW(
70902 + int BW)
70903 +{
70904 + switch(BW)
70905 + {
70906 + case BW_10:
70907 + return "10M";
70908 +
70909 + case BW_20:
70910 + return "20M";
70911 +#ifdef DOT11_N_SUPPORT
70912 + case BW_40:
70913 + return "40M";
70914 +#endif // DOT11_N_SUPPORT //
70915 + default:
70916 + return "N/A";
70917 + }
70918 +}
70919 +
70920 +
70921 +VOID RT28xxThreadTerminate(
70922 + IN RTMP_ADAPTER *pAd);
70923 +
70924 +BOOLEAN RT28XXChipsetCheck(
70925 + IN void *_dev_p);
70926 +
70927 +BOOLEAN RT28XXNetDevInit(
70928 + IN void *_dev_p,
70929 + IN struct net_device *net_dev,
70930 + IN RTMP_ADAPTER *pAd);
70931 +
70932 +BOOLEAN RT28XXProbePostConfig(
70933 + IN void *_dev_p,
70934 + IN RTMP_ADAPTER *pAd,
70935 + IN INT32 argc);
70936 +
70937 +VOID RT28XXDMADisable(
70938 + IN RTMP_ADAPTER *pAd);
70939 +
70940 +VOID RT28XXDMAEnable(
70941 + IN RTMP_ADAPTER *pAd);
70942 +
70943 +VOID RT28xx_UpdateBeaconToAsic(
70944 + IN RTMP_ADAPTER * pAd,
70945 + IN INT apidx,
70946 + IN ULONG BeaconLen,
70947 + IN ULONG UpdatePos);
70948 +
70949 +INT rt28xx_ioctl(
70950 + IN struct net_device *net_dev,
70951 + IN OUT struct ifreq *rq,
70952 + IN INT cmd);
70953 +
70954 +
70955 +#ifdef CONFIG_STA_SUPPORT
70956 +INT rt28xx_sta_ioctl(
70957 + IN struct net_device *net_dev,
70958 + IN OUT struct ifreq *rq,
70959 + IN INT cmd);
70960 +#endif // CONFIG_STA_SUPPORT //
70961 +
70962 +BOOLEAN RT28XXSecurityKeyAdd(
70963 + IN PRTMP_ADAPTER pAd,
70964 + IN ULONG apidx,
70965 + IN ULONG KeyIdx,
70966 + IN MAC_TABLE_ENTRY *pEntry);
70967 +
70968 +////////////////////////////////////////
70969 +PNDIS_PACKET GetPacketFromRxRing(
70970 + IN PRTMP_ADAPTER pAd,
70971 + OUT PRT28XX_RXD_STRUC pSaveRxD,
70972 + OUT BOOLEAN *pbReschedule,
70973 + IN OUT UINT32 *pRxPending);
70974 +
70975 +
70976 +void kill_thread_task(PRTMP_ADAPTER pAd);
70977 +
70978 +void tbtt_tasklet(unsigned long data);
70979 +
70980 +
70981 +VOID AsicTurnOffRFClk(
70982 + IN PRTMP_ADAPTER pAd,
70983 + IN UCHAR Channel);
70984 +
70985 +VOID AsicTurnOnRFClk(
70986 + IN PRTMP_ADAPTER pAd,
70987 + IN UCHAR Channel);
70988 +
70989 +#ifdef RT30xx
70990 +NTSTATUS RT30xxWriteRFRegister(
70991 + IN PRTMP_ADAPTER pAd,
70992 + IN UCHAR RegID,
70993 + IN UCHAR Value);
70994 +
70995 +NTSTATUS RT30xxReadRFRegister(
70996 + IN PRTMP_ADAPTER pAd,
70997 + IN UCHAR RegID,
70998 + IN PUCHAR pValue);
70999 +
71000 +//2008/09/11:KH add to support efuse<--
71001 +UCHAR eFuseReadRegisters(
71002 + IN PRTMP_ADAPTER pAd,
71003 + IN USHORT Offset,
71004 + IN USHORT Length,
71005 + OUT USHORT* pData);
71006 +
71007 +VOID eFuseReadPhysical(
71008 + IN PRTMP_ADAPTER pAd,
71009 + IN PUSHORT lpInBuffer,
71010 + IN ULONG nInBufferSize,
71011 + OUT PUSHORT lpOutBuffer,
71012 + IN ULONG nOutBufferSize
71013 +);
71014 +
71015 +NTSTATUS eFuseRead(
71016 + IN PRTMP_ADAPTER pAd,
71017 + IN USHORT Offset,
71018 + OUT PUCHAR pData,
71019 + IN USHORT Length);
71020 +
71021 +VOID eFusePhysicalWriteRegisters(
71022 + IN PRTMP_ADAPTER pAd,
71023 + IN USHORT Offset,
71024 + IN USHORT Length,
71025 + OUT USHORT* pData);
71026 +
71027 +NTSTATUS eFuseWriteRegisters(
71028 + IN PRTMP_ADAPTER pAd,
71029 + IN USHORT Offset,
71030 + IN USHORT Length,
71031 + IN USHORT* pData);
71032 +
71033 +VOID eFuseWritePhysical(
71034 + IN PRTMP_ADAPTER pAd,
71035 + PUSHORT lpInBuffer,
71036 + ULONG nInBufferSize,
71037 + PUCHAR lpOutBuffer,
71038 + ULONG nOutBufferSize
71039 +);
71040 +
71041 +NTSTATUS eFuseWrite(
71042 + IN PRTMP_ADAPTER pAd,
71043 + IN USHORT Offset,
71044 + IN PUCHAR pData,
71045 + IN USHORT length);
71046 +
71047 +INT set_eFuseGetFreeBlockCount_Proc(
71048 + IN PRTMP_ADAPTER pAd,
71049 + IN PUCHAR arg);
71050 +
71051 +INT set_eFusedump_Proc(
71052 + IN PRTMP_ADAPTER pAd,
71053 + IN PUCHAR arg);
71054 +
71055 +INT set_eFuseLoadFromBin_Proc(
71056 + IN PRTMP_ADAPTER pAd,
71057 + IN PUCHAR arg);
71058 +
71059 +NTSTATUS eFuseWriteRegistersFromBin(
71060 + IN PRTMP_ADAPTER pAd,
71061 + IN USHORT Offset,
71062 + IN USHORT Length,
71063 + IN USHORT* pData);
71064 +
71065 +VOID eFusePhysicalReadRegisters(
71066 + IN PRTMP_ADAPTER pAd,
71067 + IN USHORT Offset,
71068 + IN USHORT Length,
71069 + OUT USHORT* pData);
71070 +
71071 +NDIS_STATUS NICLoadEEPROM(
71072 + IN PRTMP_ADAPTER pAd);
71073 +
71074 +BOOLEAN bNeedLoadEEPROM(
71075 + IN PRTMP_ADAPTER pAd);
71076 +//2008/09/11:KH add to support efuse-->
71077 +#endif // RT30xx //
71078 +
71079 +#ifdef RT30xx
71080 +// add by johnli, RF power sequence setup
71081 +VOID RT30xxLoadRFNormalModeSetup(
71082 + IN PRTMP_ADAPTER pAd);
71083 +
71084 +VOID RT30xxLoadRFSleepModeSetup(
71085 + IN PRTMP_ADAPTER pAd);
71086 +
71087 +VOID RT30xxReverseRFSleepModeSetup(
71088 + IN PRTMP_ADAPTER pAd);
71089 +// end johnli
71090 +#endif // RT30xx //
71091 +
71092 +#ifdef RT2870
71093 +//
71094 +// Function Prototype in rtusb_bulk.c
71095 +//
71096 +VOID RTUSBInitTxDesc(
71097 + IN PRTMP_ADAPTER pAd,
71098 + IN PTX_CONTEXT pTxContext,
71099 + IN UCHAR BulkOutPipeId,
71100 + IN usb_complete_t Func);
71101 +
71102 +VOID RTUSBInitHTTxDesc(
71103 + IN PRTMP_ADAPTER pAd,
71104 + IN PHT_TX_CONTEXT pTxContext,
71105 + IN UCHAR BulkOutPipeId,
71106 + IN ULONG BulkOutSize,
71107 + IN usb_complete_t Func);
71108 +
71109 +VOID RTUSBInitRxDesc(
71110 + IN PRTMP_ADAPTER pAd,
71111 + IN PRX_CONTEXT pRxContext);
71112 +
71113 +VOID RTUSBCleanUpDataBulkOutQueue(
71114 + IN PRTMP_ADAPTER pAd);
71115 +
71116 +VOID RTUSBCancelPendingBulkOutIRP(
71117 + IN PRTMP_ADAPTER pAd);
71118 +
71119 +VOID RTUSBBulkOutDataPacket(
71120 + IN PRTMP_ADAPTER pAd,
71121 + IN UCHAR BulkOutPipeId,
71122 + IN UCHAR Index);
71123 +
71124 +VOID RTUSBBulkOutNullFrame(
71125 + IN PRTMP_ADAPTER pAd);
71126 +
71127 +VOID RTUSBBulkOutRTSFrame(
71128 + IN PRTMP_ADAPTER pAd);
71129 +
71130 +VOID RTUSBCancelPendingBulkInIRP(
71131 + IN PRTMP_ADAPTER pAd);
71132 +
71133 +VOID RTUSBCancelPendingIRPs(
71134 + IN PRTMP_ADAPTER pAd);
71135 +
71136 +VOID RTUSBBulkOutMLMEPacket(
71137 + IN PRTMP_ADAPTER pAd,
71138 + IN UCHAR Index);
71139 +
71140 +VOID RTUSBBulkOutPsPoll(
71141 + IN PRTMP_ADAPTER pAd);
71142 +
71143 +VOID RTUSBCleanUpMLMEBulkOutQueue(
71144 + IN PRTMP_ADAPTER pAd);
71145 +
71146 +VOID RTUSBKickBulkOut(
71147 + IN PRTMP_ADAPTER pAd);
71148 +
71149 +VOID RTUSBBulkReceive(
71150 + IN PRTMP_ADAPTER pAd);
71151 +
71152 +VOID DoBulkIn(
71153 + IN RTMP_ADAPTER *pAd);
71154 +
71155 +VOID RTUSBInitRxDesc(
71156 + IN PRTMP_ADAPTER pAd,
71157 + IN PRX_CONTEXT pRxContext);
71158 +
71159 +VOID RTUSBBulkRxHandle(
71160 + IN unsigned long data);
71161 +
71162 +//
71163 +// Function Prototype in rtusb_io.c
71164 +//
71165 +NTSTATUS RTUSBMultiRead(
71166 + IN PRTMP_ADAPTER pAd,
71167 + IN USHORT Offset,
71168 + OUT PUCHAR pData,
71169 + IN USHORT length);
71170 +
71171 +NTSTATUS RTUSBMultiWrite(
71172 + IN PRTMP_ADAPTER pAd,
71173 + IN USHORT Offset,
71174 + IN PUCHAR pData,
71175 + IN USHORT length);
71176 +
71177 +NTSTATUS RTUSBMultiWrite_OneByte(
71178 + IN PRTMP_ADAPTER pAd,
71179 + IN USHORT Offset,
71180 + IN PUCHAR pData);
71181 +
71182 +NTSTATUS RTUSBReadBBPRegister(
71183 + IN PRTMP_ADAPTER pAd,
71184 + IN UCHAR Id,
71185 + IN PUCHAR pValue);
71186 +
71187 +NTSTATUS RTUSBWriteBBPRegister(
71188 + IN PRTMP_ADAPTER pAd,
71189 + IN UCHAR Id,
71190 + IN UCHAR Value);
71191 +
71192 +NTSTATUS RTUSBWriteRFRegister(
71193 + IN PRTMP_ADAPTER pAd,
71194 + IN UINT32 Value);
71195 +
71196 +NTSTATUS RTUSB_VendorRequest(
71197 + IN PRTMP_ADAPTER pAd,
71198 + IN UINT32 TransferFlags,
71199 + IN UCHAR ReservedBits,
71200 + IN UCHAR Request,
71201 + IN USHORT Value,
71202 + IN USHORT Index,
71203 + IN PVOID TransferBuffer,
71204 + IN UINT32 TransferBufferLength);
71205 +
71206 +NTSTATUS RTUSBReadEEPROM(
71207 + IN PRTMP_ADAPTER pAd,
71208 + IN USHORT Offset,
71209 + OUT PUCHAR pData,
71210 + IN USHORT length);
71211 +
71212 +NTSTATUS RTUSBWriteEEPROM(
71213 + IN PRTMP_ADAPTER pAd,
71214 + IN USHORT Offset,
71215 + IN PUCHAR pData,
71216 + IN USHORT length);
71217 +
71218 +VOID RTUSBPutToSleep(
71219 + IN PRTMP_ADAPTER pAd);
71220 +
71221 +NTSTATUS RTUSBWakeUp(
71222 + IN PRTMP_ADAPTER pAd);
71223 +
71224 +VOID RTUSBInitializeCmdQ(
71225 + IN PCmdQ cmdq);
71226 +
71227 +NDIS_STATUS RTUSBEnqueueCmdFromNdis(
71228 + IN PRTMP_ADAPTER pAd,
71229 + IN NDIS_OID Oid,
71230 + IN BOOLEAN SetInformation,
71231 + IN PVOID pInformationBuffer,
71232 + IN UINT32 InformationBufferLength);
71233 +
71234 +NDIS_STATUS RTUSBEnqueueInternalCmd(
71235 + IN PRTMP_ADAPTER pAd,
71236 + IN NDIS_OID Oid,
71237 + IN PVOID pInformationBuffer,
71238 + IN UINT32 InformationBufferLength);
71239 +
71240 +VOID RTUSBDequeueCmd(
71241 + IN PCmdQ cmdq,
71242 + OUT PCmdQElmt *pcmdqelmt);
71243 +
71244 +INT RTUSBCmdThread(
71245 + IN OUT PVOID Context);
71246 +
71247 +INT TimerQThread(
71248 + IN OUT PVOID Context);
71249 +
71250 +RT2870_TIMER_ENTRY *RT2870_TimerQ_Insert(
71251 + IN RTMP_ADAPTER *pAd,
71252 + IN RALINK_TIMER_STRUCT *pTimer);
71253 +
71254 +BOOLEAN RT2870_TimerQ_Remove(
71255 + IN RTMP_ADAPTER *pAd,
71256 + IN RALINK_TIMER_STRUCT *pTimer);
71257 +
71258 +void RT2870_TimerQ_Exit(
71259 + IN RTMP_ADAPTER *pAd);
71260 +
71261 +void RT2870_TimerQ_Init(
71262 + IN RTMP_ADAPTER *pAd);
71263 +
71264 +VOID RT2870_BssBeaconExit(
71265 + IN RTMP_ADAPTER *pAd);
71266 +
71267 +VOID RT2870_BssBeaconStop(
71268 + IN RTMP_ADAPTER *pAd);
71269 +
71270 +VOID RT2870_BssBeaconStart(
71271 + IN RTMP_ADAPTER * pAd);
71272 +
71273 +VOID RT2870_BssBeaconInit(
71274 + IN RTMP_ADAPTER *pAd);
71275 +
71276 +VOID RT2870_WatchDog(
71277 + IN RTMP_ADAPTER *pAd);
71278 +
71279 +NTSTATUS RTUSBWriteMACRegister(
71280 + IN PRTMP_ADAPTER pAd,
71281 + IN USHORT Offset,
71282 + IN UINT32 Value);
71283 +
71284 +NTSTATUS RTUSBReadMACRegister(
71285 + IN PRTMP_ADAPTER pAd,
71286 + IN USHORT Offset,
71287 + OUT PUINT32 pValue);
71288 +
71289 +NTSTATUS RTUSBSingleWrite(
71290 + IN RTMP_ADAPTER *pAd,
71291 + IN USHORT Offset,
71292 + IN USHORT Value);
71293 +
71294 +NTSTATUS RTUSBFirmwareRun(
71295 + IN PRTMP_ADAPTER pAd);
71296 +
71297 +NTSTATUS RTUSBFirmwareWrite(
71298 + IN PRTMP_ADAPTER pAd,
71299 + IN PUCHAR pFwImage,
71300 + IN ULONG FwLen);
71301 +
71302 +NTSTATUS RTUSBFirmwareOpmode(
71303 + IN PRTMP_ADAPTER pAd,
71304 + OUT PUINT32 pValue);
71305 +
71306 +NTSTATUS RTUSBVenderReset(
71307 + IN PRTMP_ADAPTER pAd);
71308 +
71309 +NDIS_STATUS RTUSBSetHardWareRegister(
71310 + IN PRTMP_ADAPTER pAdapter,
71311 + IN PVOID pBuf);
71312 +
71313 +NDIS_STATUS RTUSBQueryHardWareRegister(
71314 + IN PRTMP_ADAPTER pAdapter,
71315 + IN PVOID pBuf);
71316 +
71317 +VOID CMDHandler(
71318 + IN PRTMP_ADAPTER pAd);
71319 +
71320 +
71321 +NDIS_STATUS CreateThreads(
71322 + IN struct net_device *net_dev );
71323 +
71324 +
71325 +VOID MacTableInitialize(
71326 + IN PRTMP_ADAPTER pAd);
71327 +
71328 +VOID MlmeSetPsm(
71329 + IN PRTMP_ADAPTER pAd,
71330 + IN USHORT psm);
71331 +
71332 +NDIS_STATUS RTMPWPAAddKeyProc(
71333 + IN PRTMP_ADAPTER pAd,
71334 + IN PVOID pBuf);
71335 +
71336 +VOID AsicRxAntEvalAction(
71337 + IN PRTMP_ADAPTER pAd);
71338 +
71339 +void append_pkt(
71340 + IN PRTMP_ADAPTER pAd,
71341 + IN PUCHAR pHeader802_3,
71342 + IN UINT HdrLen,
71343 + IN PUCHAR pData,
71344 + IN ULONG DataSize,
71345 + OUT PNDIS_PACKET *ppPacket);
71346 +
71347 +UINT deaggregate_AMSDU_announce(
71348 + IN PRTMP_ADAPTER pAd,
71349 + PNDIS_PACKET pPacket,
71350 + IN PUCHAR pData,
71351 + IN ULONG DataSize);
71352 +
71353 +NDIS_STATUS RTMPCheckRxError(
71354 + IN PRTMP_ADAPTER pAd,
71355 + IN PHEADER_802_11 pHeader,
71356 + IN PRXWI_STRUC pRxWI,
71357 + IN PRT28XX_RXD_STRUC pRxINFO);
71358 +
71359 +
71360 +VOID RTUSBMlmeHardTransmit(
71361 + IN PRTMP_ADAPTER pAd,
71362 + IN PMGMT_STRUC pMgmt);
71363 +
71364 +INT MlmeThread(
71365 + IN PVOID Context);
71366 +
71367 +//
71368 +// Function Prototype in rtusb_data.c
71369 +//
71370 +NDIS_STATUS RTUSBFreeDescriptorRequest(
71371 + IN PRTMP_ADAPTER pAd,
71372 + IN UCHAR BulkOutPipeId,
71373 + IN UINT32 NumberRequired);
71374 +
71375 +
71376 +BOOLEAN RTUSBNeedQueueBackForAgg(
71377 + IN RTMP_ADAPTER *pAd,
71378 + IN UCHAR BulkOutPipeId);
71379 +
71380 +
71381 +VOID RTMPWriteTxInfo(
71382 + IN PRTMP_ADAPTER pAd,
71383 + IN PTXINFO_STRUC pTxInfo,
71384 + IN USHORT USBDMApktLen,
71385 + IN BOOLEAN bWiv,
71386 + IN UCHAR QueueSel,
71387 + IN UCHAR NextValid,
71388 + IN UCHAR TxBurst);
71389 +
71390 +//
71391 +// Function Prototype in cmm_data_2870.c
71392 +//
71393 +USHORT RtmpUSB_WriteSubTxResource(
71394 + IN PRTMP_ADAPTER pAd,
71395 + IN TX_BLK *pTxBlk,
71396 + IN BOOLEAN bIsLast,
71397 + OUT USHORT *FreeNumber);
71398 +
71399 +USHORT RtmpUSB_WriteSingleTxResource(
71400 + IN PRTMP_ADAPTER pAd,
71401 + IN TX_BLK *pTxBlk,
71402 + IN BOOLEAN bIsLast,
71403 + OUT USHORT *FreeNumber);
71404 +
71405 +USHORT RtmpUSB_WriteFragTxResource(
71406 + IN PRTMP_ADAPTER pAd,
71407 + IN TX_BLK *pTxBlk,
71408 + IN UCHAR fragNum,
71409 + OUT USHORT *FreeNumber);
71410 +
71411 +USHORT RtmpUSB_WriteMultiTxResource(
71412 + IN PRTMP_ADAPTER pAd,
71413 + IN TX_BLK *pTxBlk,
71414 + IN UCHAR frameNum,
71415 + OUT USHORT *FreeNumber);
71416 +
71417 +VOID RtmpUSB_FinalWriteTxResource(
71418 + IN PRTMP_ADAPTER pAd,
71419 + IN TX_BLK *pTxBlk,
71420 + IN USHORT totalMPDUSize,
71421 + IN USHORT TxIdx);
71422 +
71423 +VOID RtmpUSBDataLastTxIdx(
71424 + IN PRTMP_ADAPTER pAd,
71425 + IN UCHAR QueIdx,
71426 + IN USHORT TxIdx);
71427 +
71428 +VOID RtmpUSBDataKickOut(
71429 + IN PRTMP_ADAPTER pAd,
71430 + IN TX_BLK *pTxBlk,
71431 + IN UCHAR QueIdx);
71432 +
71433 +
71434 +int RtmpUSBMgmtKickOut(
71435 + IN RTMP_ADAPTER *pAd,
71436 + IN UCHAR QueIdx,
71437 + IN PNDIS_PACKET pPacket,
71438 + IN PUCHAR pSrcBufVA,
71439 + IN UINT SrcBufLen);
71440 +
71441 +VOID RtmpUSBNullFrameKickOut(
71442 + IN RTMP_ADAPTER *pAd,
71443 + IN UCHAR QueIdx,
71444 + IN UCHAR *pNullFrame,
71445 + IN UINT32 frameLen);
71446 +
71447 +VOID RT28xxUsbStaAsicForceWakeup(
71448 + IN PRTMP_ADAPTER pAd,
71449 + IN BOOLEAN bFromTx);
71450 +
71451 +VOID RT28xxUsbStaAsicSleepThenAutoWakeup(
71452 + IN PRTMP_ADAPTER pAd,
71453 + IN USHORT TbttNumToNextWakeUp);
71454 +
71455 +VOID RT28xxUsbMlmeRadioOn(
71456 + IN PRTMP_ADAPTER pAd);
71457 +
71458 +VOID RT28xxUsbMlmeRadioOFF(
71459 + IN PRTMP_ADAPTER pAd);
71460 +#endif // RT2870 //
71461 +
71462 +////////////////////////////////////////
71463 +
71464 +VOID QBSS_LoadInit(
71465 + IN RTMP_ADAPTER *pAd);
71466 +
71467 +UINT32 QBSS_LoadElementAppend(
71468 + IN RTMP_ADAPTER *pAd,
71469 + OUT UINT8 *buf_p);
71470 +
71471 +VOID QBSS_LoadUpdate(
71472 + IN RTMP_ADAPTER *pAd);
71473 +
71474 +///////////////////////////////////////
71475 +INT RTMPShowCfgValue(
71476 + IN PRTMP_ADAPTER pAd,
71477 + IN PUCHAR pName,
71478 + IN PUCHAR pBuf);
71479 +
71480 +PCHAR RTMPGetRalinkAuthModeStr(
71481 + IN NDIS_802_11_AUTHENTICATION_MODE authMode);
71482 +
71483 +PCHAR RTMPGetRalinkEncryModeStr(
71484 + IN USHORT encryMode);
71485 +//////////////////////////////////////
71486 +
71487 +#ifdef CONFIG_STA_SUPPORT
71488 +VOID AsicStaBbpTuning(
71489 + IN PRTMP_ADAPTER pAd);
71490 +
71491 +BOOLEAN StaAddMacTableEntry(
71492 + IN PRTMP_ADAPTER pAd,
71493 + IN PMAC_TABLE_ENTRY pEntry,
71494 + IN UCHAR MaxSupportedRateIn500Kbps,
71495 + IN HT_CAPABILITY_IE *pHtCapability,
71496 + IN UCHAR HtCapabilityLen,
71497 + IN USHORT CapabilityInfo);
71498 +#endif // CONFIG_STA_SUPPORT //
71499 +
71500 +void RTMP_IndicateMediaState(
71501 + IN PRTMP_ADAPTER pAd);
71502 +
71503 +VOID ReSyncBeaconTime(
71504 + IN PRTMP_ADAPTER pAd);
71505 +
71506 +VOID RTMPSetAGCInitValue(
71507 + IN PRTMP_ADAPTER pAd,
71508 + IN UCHAR BandWidth);
71509 +
71510 +int rt28xx_close(IN PNET_DEV dev);
71511 +int rt28xx_open(IN PNET_DEV dev);
71512 +
71513 +__inline INT VIRTUAL_IF_UP(PRTMP_ADAPTER pAd)
71514 +{
71515 +extern VOID MeshMakeBeacon(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
71516 +extern VOID MeshUpdateBeaconFrame(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
71517 +
71518 + if (VIRTUAL_IF_NUM(pAd) == 0)
71519 + {
71520 + if (rt28xx_open(pAd->net_dev) != 0)
71521 + return -1;
71522 + }
71523 + else
71524 + {
71525 + }
71526 + VIRTUAL_IF_INC(pAd);
71527 + return 0;
71528 +}
71529 +
71530 +__inline VOID VIRTUAL_IF_DOWN(PRTMP_ADAPTER pAd)
71531 +{
71532 + VIRTUAL_IF_DEC(pAd);
71533 + if (VIRTUAL_IF_NUM(pAd) == 0)
71534 + rt28xx_close(pAd->net_dev);
71535 + return;
71536 +}
71537 +
71538 +
71539 +#endif // __RTMP_H__
71540 +
71541 --- /dev/null
71542 +++ b/drivers/staging/rt3070/rtmp_type.h
71543 @@ -0,0 +1,95 @@
71544 +/*
71545 + *************************************************************************
71546 + * Ralink Tech Inc.
71547 + * 5F., No.36, Taiyuan St., Jhubei City,
71548 + * Hsinchu County 302,
71549 + * Taiwan, R.O.C.
71550 + *
71551 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
71552 + *
71553 + * This program is free software; you can redistribute it and/or modify *
71554 + * it under the terms of the GNU General Public License as published by *
71555 + * the Free Software Foundation; either version 2 of the License, or *
71556 + * (at your option) any later version. *
71557 + * *
71558 + * This program is distributed in the hope that it will be useful, *
71559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
71560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
71561 + * GNU General Public License for more details. *
71562 + * *
71563 + * You should have received a copy of the GNU General Public License *
71564 + * along with this program; if not, write to the *
71565 + * Free Software Foundation, Inc., *
71566 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
71567 + * *
71568 + *************************************************************************
71569 +
71570 + Module Name:
71571 + rtmp_type.h
71572 +
71573 + Abstract:
71574 +
71575 + Revision History:
71576 + Who When What
71577 + -------- ---------- ----------------------------------------------
71578 + Name Date Modification logs
71579 + Paul Lin 1-2-2004
71580 +*/
71581 +#ifndef __RTMP_TYPE_H__
71582 +#define __RTMP_TYPE_H__
71583 +
71584 +
71585 +#define PACKED __attribute__ ((packed))
71586 +
71587 +// Put platform dependent declaration here
71588 +// For example, linux type definition
71589 +typedef unsigned char UINT8;
71590 +typedef unsigned short UINT16;
71591 +typedef unsigned int UINT32;
71592 +typedef unsigned long long UINT64;
71593 +typedef int INT32;
71594 +typedef long long INT64;
71595 +
71596 +typedef unsigned char * PUINT8;
71597 +typedef unsigned short * PUINT16;
71598 +typedef unsigned int * PUINT32;
71599 +typedef unsigned long long * PUINT64;
71600 +typedef int * PINT32;
71601 +typedef long long * PINT64;
71602 +
71603 +typedef signed char CHAR;
71604 +typedef signed short SHORT;
71605 +typedef signed int INT;
71606 +typedef signed long LONG;
71607 +typedef signed long long LONGLONG;
71608 +
71609 +
71610 +typedef unsigned char UCHAR;
71611 +typedef unsigned short USHORT;
71612 +typedef unsigned int UINT;
71613 +typedef unsigned long ULONG;
71614 +typedef unsigned long long ULONGLONG;
71615 +
71616 +typedef unsigned char BOOLEAN;
71617 +typedef void VOID;
71618 +
71619 +typedef VOID * PVOID;
71620 +typedef CHAR * PCHAR;
71621 +typedef UCHAR * PUCHAR;
71622 +typedef USHORT * PUSHORT;
71623 +typedef LONG * PLONG;
71624 +typedef ULONG * PULONG;
71625 +typedef UINT * PUINT;
71626 +
71627 +typedef unsigned int NDIS_MEDIA_STATE;
71628 +
71629 +typedef union _LARGE_INTEGER {
71630 + struct {
71631 + UINT LowPart;
71632 + INT32 HighPart;
71633 + } u;
71634 + INT64 QuadPart;
71635 +} LARGE_INTEGER;
71636 +
71637 +#endif // __RTMP_TYPE_H__
71638 +
71639 --- /dev/null
71640 +++ b/drivers/staging/rt3070/rt_profile.c
71641 @@ -0,0 +1,2041 @@
71642 +/*
71643 + *************************************************************************
71644 + * Ralink Tech Inc.
71645 + * 5F., No.36, Taiyuan St., Jhubei City,
71646 + * Hsinchu County 302,
71647 + * Taiwan, R.O.C.
71648 + *
71649 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
71650 + *
71651 + * This program is free software; you can redistribute it and/or modify *
71652 + * it under the terms of the GNU General Public License as published by *
71653 + * the Free Software Foundation; either version 2 of the License, or *
71654 + * (at your option) any later version. *
71655 + * *
71656 + * This program is distributed in the hope that it will be useful, *
71657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
71658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
71659 + * GNU General Public License for more details. *
71660 + * *
71661 + * You should have received a copy of the GNU General Public License *
71662 + * along with this program; if not, write to the *
71663 + * Free Software Foundation, Inc., *
71664 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
71665 + * *
71666 + *************************************************************************
71667 + */
71668 +
71669 +#include "rt_config.h"
71670 +
71671 +#ifdef DOT11_N_SUPPORT
71672 +static void HTParametersHook(
71673 + IN PRTMP_ADAPTER pAd,
71674 + IN CHAR *pValueStr,
71675 + IN CHAR *pInput);
71676 +#endif // DOT11_N_SUPPORT //
71677 +
71678 +#define ETH_MAC_ADDR_STR_LEN 17 // in format of xx:xx:xx:xx:xx:xx
71679 +
71680 +// We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
71681 +BOOLEAN rtstrmactohex(char *s1, char *s2)
71682 +{
71683 + int i = 0;
71684 + char *ptokS = s1, *ptokE = s1;
71685 +
71686 + if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
71687 + return FALSE;
71688 +
71689 + while((*ptokS) != '\0')
71690 + {
71691 + if((ptokE = strchr(ptokS, ':')) != NULL)
71692 + *ptokE++ = '\0';
71693 + if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
71694 + break; // fail
71695 + AtoH(ptokS, &s2[i++], 1);
71696 + ptokS = ptokE;
71697 + if (i == 6)
71698 + break; // parsing finished
71699 + }
71700 +
71701 + return ( i == 6 ? TRUE : FALSE);
71702 +
71703 +}
71704 +
71705 +
71706 +// we assume the s1 and s2 both are strings.
71707 +BOOLEAN rtstrcasecmp(char *s1, char *s2)
71708 +{
71709 + char *p1 = s1, *p2 = s2;
71710 +
71711 + if (strlen(s1) != strlen(s2))
71712 + return FALSE;
71713 +
71714 + while(*p1 != '\0')
71715 + {
71716 + if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
71717 + return FALSE;
71718 + p1++;
71719 + p2++;
71720 + }
71721 +
71722 + return TRUE;
71723 +}
71724 +
71725 +// we assume the s1 (buffer) and s2 (key) both are strings.
71726 +char * rtstrstruncasecmp(char * s1, char * s2)
71727 +{
71728 + INT l1, l2, i;
71729 + char temp1, temp2;
71730 +
71731 + l2 = strlen(s2);
71732 + if (!l2)
71733 + return (char *) s1;
71734 +
71735 + l1 = strlen(s1);
71736 +
71737 + while (l1 >= l2)
71738 + {
71739 + l1--;
71740 +
71741 + for(i=0; i<l2; i++)
71742 + {
71743 + temp1 = *(s1+i);
71744 + temp2 = *(s2+i);
71745 +
71746 + if (('a' <= temp1) && (temp1 <= 'z'))
71747 + temp1 = 'A'+(temp1-'a');
71748 + if (('a' <= temp2) && (temp2 <= 'z'))
71749 + temp2 = 'A'+(temp2-'a');
71750 +
71751 + if (temp1 != temp2)
71752 + break;
71753 + }
71754 +
71755 + if (i == l2)
71756 + return (char *) s1;
71757 +
71758 + s1++;
71759 + }
71760 +
71761 + return NULL; // not found
71762 +}
71763 +
71764 +//add by kathy
71765 +
71766 + /**
71767 + * strstr - Find the first substring in a %NUL terminated string
71768 + * @s1: The string to be searched
71769 + * @s2: The string to search for
71770 + */
71771 +char * rtstrstr(const char * s1,const char * s2)
71772 +{
71773 + INT l1, l2;
71774 +
71775 + l2 = strlen(s2);
71776 + if (!l2)
71777 + return (char *) s1;
71778 +
71779 + l1 = strlen(s1);
71780 +
71781 + while (l1 >= l2)
71782 + {
71783 + l1--;
71784 + if (!memcmp(s1,s2,l2))
71785 + return (char *) s1;
71786 + s1++;
71787 + }
71788 +
71789 + return NULL;
71790 +}
71791 +
71792 +/**
71793 + * rstrtok - Split a string into tokens
71794 + * @s: The string to be searched
71795 + * @ct: The characters to search for
71796 + * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
71797 + */
71798 +char * __rstrtok;
71799 +char * rstrtok(char * s,const char * ct)
71800 +{
71801 + char *sbegin, *send;
71802 +
71803 + sbegin = s ? s : __rstrtok;
71804 + if (!sbegin)
71805 + {
71806 + return NULL;
71807 + }
71808 +
71809 + sbegin += strspn(sbegin,ct);
71810 + if (*sbegin == '\0')
71811 + {
71812 + __rstrtok = NULL;
71813 + return( NULL );
71814 + }
71815 +
71816 + send = strpbrk( sbegin, ct);
71817 + if (send && *send != '\0')
71818 + *send++ = '\0';
71819 +
71820 + __rstrtok = send;
71821 +
71822 + return (sbegin);
71823 +}
71824 +
71825 +/**
71826 + * delimitcnt - return the count of a given delimiter in a given string.
71827 + * @s: The string to be searched.
71828 + * @ct: The delimiter to search for.
71829 + * Notice : We suppose the delimiter is a single-char string(for example : ";").
71830 + */
71831 +INT delimitcnt(char * s,const char * ct)
71832 +{
71833 + INT count = 0;
71834 + /* point to the beginning of the line */
71835 + const char *token = s;
71836 +
71837 + for ( ;; )
71838 + {
71839 + token = strpbrk(token, ct); /* search for delimiters */
71840 +
71841 + if ( token == NULL )
71842 + {
71843 + /* advanced to the terminating null character */
71844 + break;
71845 + }
71846 + /* skip the delimiter */
71847 + ++token;
71848 +
71849 + /*
71850 + * Print the found text: use len with %.*s to specify field width.
71851 + */
71852 +
71853 + /* accumulate delimiter count */
71854 + ++count;
71855 + }
71856 + return count;
71857 +}
71858 +
71859 +/*
71860 + * converts the Internet host address from the standard numbers-and-dots notation
71861 + * into binary data.
71862 + * returns nonzero if the address is valid, zero if not.
71863 + */
71864 +int rtinet_aton(const char *cp, unsigned int *addr)
71865 +{
71866 + unsigned int val;
71867 + int base, n;
71868 + char c;
71869 + unsigned int parts[4];
71870 + unsigned int *pp = parts;
71871 +
71872 + for (;;)
71873 + {
71874 + /*
71875 + * Collect number up to ``.''.
71876 + * Values are specified as for C:
71877 + * 0x=hex, 0=octal, other=decimal.
71878 + */
71879 + val = 0;
71880 + base = 10;
71881 + if (*cp == '0')
71882 + {
71883 + if (*++cp == 'x' || *cp == 'X')
71884 + base = 16, cp++;
71885 + else
71886 + base = 8;
71887 + }
71888 + while ((c = *cp) != '\0')
71889 + {
71890 + if (isdigit((unsigned char) c))
71891 + {
71892 + val = (val * base) + (c - '0');
71893 + cp++;
71894 + continue;
71895 + }
71896 + if (base == 16 && isxdigit((unsigned char) c))
71897 + {
71898 + val = (val << 4) +
71899 + (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
71900 + cp++;
71901 + continue;
71902 + }
71903 + break;
71904 + }
71905 + if (*cp == '.')
71906 + {
71907 + /*
71908 + * Internet format: a.b.c.d a.b.c (with c treated as 16-bits)
71909 + * a.b (with b treated as 24 bits)
71910 + */
71911 + if (pp >= parts + 3 || val > 0xff)
71912 + return 0;
71913 + *pp++ = val, cp++;
71914 + }
71915 + else
71916 + break;
71917 + }
71918 +
71919 + /*
71920 + * Check for trailing junk.
71921 + */
71922 + while (*cp)
71923 + if (!isspace((unsigned char) *cp++))
71924 + return 0;
71925 +
71926 + /*
71927 + * Concoct the address according to the number of parts specified.
71928 + */
71929 + n = pp - parts + 1;
71930 + switch (n)
71931 + {
71932 +
71933 + case 1: /* a -- 32 bits */
71934 + break;
71935 +
71936 + case 2: /* a.b -- 8.24 bits */
71937 + if (val > 0xffffff)
71938 + return 0;
71939 + val |= parts[0] << 24;
71940 + break;
71941 +
71942 + case 3: /* a.b.c -- 8.8.16 bits */
71943 + if (val > 0xffff)
71944 + return 0;
71945 + val |= (parts[0] << 24) | (parts[1] << 16);
71946 + break;
71947 +
71948 + case 4: /* a.b.c.d -- 8.8.8.8 bits */
71949 + if (val > 0xff)
71950 + return 0;
71951 + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
71952 + break;
71953 + }
71954 +
71955 + *addr = htonl(val);
71956 + return 1;
71957 +
71958 +}
71959 +
71960 +/*
71961 + ========================================================================
71962 +
71963 + Routine Description:
71964 + Find key section for Get key parameter.
71965 +
71966 + Arguments:
71967 + buffer Pointer to the buffer to start find the key section
71968 + section the key of the secion to be find
71969 +
71970 + Return Value:
71971 + NULL Fail
71972 + Others Success
71973 + ========================================================================
71974 +*/
71975 +PUCHAR RTMPFindSection(
71976 + IN PCHAR buffer)
71977 +{
71978 + CHAR temp_buf[32];
71979 + PUCHAR ptr;
71980 +
71981 + strcpy(temp_buf, "Default");
71982 +
71983 + if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
71984 + return (ptr+strlen("\n"));
71985 + else
71986 + return NULL;
71987 +}
71988 +
71989 +/*
71990 + ========================================================================
71991 +
71992 + Routine Description:
71993 + Get key parameter.
71994 +
71995 + Arguments:
71996 + key Pointer to key string
71997 + dest Pointer to destination
71998 + destsize The datasize of the destination
71999 + buffer Pointer to the buffer to start find the key
72000 +
72001 + Return Value:
72002 + TRUE Success
72003 + FALSE Fail
72004 +
72005 + Note:
72006 + This routine get the value with the matched key (case case-sensitive)
72007 + ========================================================================
72008 +*/
72009 +INT RTMPGetKeyParameter(
72010 + IN PCHAR key,
72011 + OUT PCHAR dest,
72012 + IN INT destsize,
72013 + IN PCHAR buffer)
72014 +{
72015 + UCHAR *temp_buf1 = NULL;
72016 + UCHAR *temp_buf2 = NULL;
72017 + CHAR *start_ptr;
72018 + CHAR *end_ptr;
72019 + CHAR *ptr;
72020 + CHAR *offset = 0;
72021 + INT len;
72022 +
72023 + //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
72024 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
72025 +
72026 + if(temp_buf1 == NULL)
72027 + return (FALSE);
72028 +
72029 + //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
72030 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
72031 + if(temp_buf2 == NULL)
72032 + {
72033 + os_free_mem(NULL, temp_buf1);
72034 + return (FALSE);
72035 + }
72036 +
72037 + //find section
72038 + if((offset = RTMPFindSection(buffer)) == NULL)
72039 + {
72040 + os_free_mem(NULL, temp_buf1);
72041 + os_free_mem(NULL, temp_buf2);
72042 + return (FALSE);
72043 + }
72044 +
72045 + strcpy(temp_buf1, "\n");
72046 + strcat(temp_buf1, key);
72047 + strcat(temp_buf1, "=");
72048 +
72049 + //search key
72050 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
72051 + {
72052 + os_free_mem(NULL, temp_buf1);
72053 + os_free_mem(NULL, temp_buf2);
72054 + return (FALSE);
72055 + }
72056 +
72057 + start_ptr+=strlen("\n");
72058 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
72059 + end_ptr=start_ptr+strlen(start_ptr);
72060 +
72061 + if (end_ptr<start_ptr)
72062 + {
72063 + os_free_mem(NULL, temp_buf1);
72064 + os_free_mem(NULL, temp_buf2);
72065 + return (FALSE);
72066 + }
72067 +
72068 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
72069 + temp_buf2[end_ptr-start_ptr]='\0';
72070 + len = strlen(temp_buf2);
72071 + strcpy(temp_buf1, temp_buf2);
72072 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
72073 + {
72074 + os_free_mem(NULL, temp_buf1);
72075 + os_free_mem(NULL, temp_buf2);
72076 + return (FALSE);
72077 + }
72078 +
72079 + strcpy(temp_buf2, start_ptr+1);
72080 + ptr = temp_buf2;
72081 + //trim space or tab
72082 + while(*ptr != 0x00)
72083 + {
72084 + if( (*ptr == ' ') || (*ptr == '\t') )
72085 + ptr++;
72086 + else
72087 + break;
72088 + }
72089 +
72090 + len = strlen(ptr);
72091 + memset(dest, 0x00, destsize);
72092 + strncpy(dest, ptr, len >= destsize ? destsize: len);
72093 +
72094 + os_free_mem(NULL, temp_buf1);
72095 + os_free_mem(NULL, temp_buf2);
72096 + return TRUE;
72097 +}
72098 +
72099 +/*
72100 + ========================================================================
72101 +
72102 + Routine Description:
72103 + Get key parameter.
72104 +
72105 + Arguments:
72106 + key Pointer to key string
72107 + dest Pointer to destination
72108 + destsize The datasize of the destination
72109 + buffer Pointer to the buffer to start find the key
72110 +
72111 + Return Value:
72112 + TRUE Success
72113 + FALSE Fail
72114 +
72115 + Note:
72116 + This routine get the value with the matched key (case case-sensitive).
72117 + It is called for parsing SSID and any key string.
72118 + ========================================================================
72119 +*/
72120 +INT RTMPGetCriticalParameter(
72121 + IN PCHAR key,
72122 + OUT PCHAR dest,
72123 + IN INT destsize,
72124 + IN PCHAR buffer)
72125 +{
72126 + UCHAR *temp_buf1 = NULL;
72127 + UCHAR *temp_buf2 = NULL;
72128 + CHAR *start_ptr;
72129 + CHAR *end_ptr;
72130 + CHAR *ptr;
72131 + CHAR *offset = 0;
72132 + INT len;
72133 +
72134 + //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
72135 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
72136 +
72137 + if(temp_buf1 == NULL)
72138 + return (FALSE);
72139 +
72140 + //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
72141 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
72142 + if(temp_buf2 == NULL)
72143 + {
72144 + os_free_mem(NULL, temp_buf1);
72145 + return (FALSE);
72146 + }
72147 +
72148 + //find section
72149 + if((offset = RTMPFindSection(buffer)) == NULL)
72150 + {
72151 + os_free_mem(NULL, temp_buf1);
72152 + os_free_mem(NULL, temp_buf2);
72153 + return (FALSE);
72154 + }
72155 +
72156 + strcpy(temp_buf1, "\n");
72157 + strcat(temp_buf1, key);
72158 + strcat(temp_buf1, "=");
72159 +
72160 + //search key
72161 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
72162 + {
72163 + os_free_mem(NULL, temp_buf1);
72164 + os_free_mem(NULL, temp_buf2);
72165 + return (FALSE);
72166 + }
72167 +
72168 + start_ptr+=strlen("\n");
72169 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
72170 + end_ptr=start_ptr+strlen(start_ptr);
72171 +
72172 + if (end_ptr<start_ptr)
72173 + {
72174 + os_free_mem(NULL, temp_buf1);
72175 + os_free_mem(NULL, temp_buf2);
72176 + return (FALSE);
72177 + }
72178 +
72179 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
72180 + temp_buf2[end_ptr-start_ptr]='\0';
72181 + len = strlen(temp_buf2);
72182 + strcpy(temp_buf1, temp_buf2);
72183 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
72184 + {
72185 + os_free_mem(NULL, temp_buf1);
72186 + os_free_mem(NULL, temp_buf2);
72187 + return (FALSE);
72188 + }
72189 +
72190 + strcpy(temp_buf2, start_ptr+1);
72191 + ptr = temp_buf2;
72192 +
72193 + //trim tab
72194 + /* We cannot trim space(' ') for SSID and key string. */
72195 + while(*ptr != 0x00)
72196 + {
72197 + //if( (*ptr == ' ') || (*ptr == '\t') )
72198 + if( (*ptr == '\t') )
72199 + ptr++;
72200 + else
72201 + break;
72202 + }
72203 +
72204 + len = strlen(ptr);
72205 + memset(dest, 0x00, destsize);
72206 + strncpy(dest, ptr, len >= destsize ? destsize: len);
72207 +
72208 + os_free_mem(NULL, temp_buf1);
72209 + os_free_mem(NULL, temp_buf2);
72210 + return TRUE;
72211 +}
72212 +
72213 +/*
72214 + ========================================================================
72215 +
72216 + Routine Description:
72217 + Get multiple key parameter.
72218 +
72219 + Arguments:
72220 + key Pointer to key string
72221 + dest Pointer to destination
72222 + destsize The datasize of the destination
72223 + buffer Pointer to the buffer to start find the key
72224 +
72225 + Return Value:
72226 + TRUE Success
72227 + FALSE Fail
72228 +
72229 + Note:
72230 + This routine get the value with the matched key (case case-sensitive)
72231 + ========================================================================
72232 +*/
72233 +INT RTMPGetKeyParameterWithOffset(
72234 + IN PCHAR key,
72235 + OUT PCHAR dest,
72236 + OUT USHORT *end_offset,
72237 + IN INT destsize,
72238 + IN PCHAR buffer,
72239 + IN BOOLEAN bTrimSpace)
72240 +{
72241 + UCHAR *temp_buf1 = NULL;
72242 + UCHAR *temp_buf2 = NULL;
72243 + CHAR *start_ptr;
72244 + CHAR *end_ptr;
72245 + CHAR *ptr;
72246 + CHAR *offset = 0;
72247 + INT len;
72248 +
72249 + if (*end_offset >= MAX_INI_BUFFER_SIZE)
72250 + return (FALSE);
72251 +
72252 + os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
72253 +
72254 + if(temp_buf1 == NULL)
72255 + return (FALSE);
72256 +
72257 + os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
72258 + if(temp_buf2 == NULL)
72259 + {
72260 + os_free_mem(NULL, temp_buf1);
72261 + return (FALSE);
72262 + }
72263 +
72264 + //find section
72265 + if(*end_offset == 0)
72266 + {
72267 + if ((offset = RTMPFindSection(buffer)) == NULL)
72268 + {
72269 + os_free_mem(NULL, temp_buf1);
72270 + os_free_mem(NULL, temp_buf2);
72271 + return (FALSE);
72272 + }
72273 + }
72274 + else
72275 + offset = buffer + (*end_offset);
72276 +
72277 + strcpy(temp_buf1, "\n");
72278 + strcat(temp_buf1, key);
72279 + strcat(temp_buf1, "=");
72280 +
72281 + //search key
72282 + if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
72283 + {
72284 + os_free_mem(NULL, temp_buf1);
72285 + os_free_mem(NULL, temp_buf2);
72286 + return (FALSE);
72287 + }
72288 +
72289 + start_ptr+=strlen("\n");
72290 + if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
72291 + end_ptr=start_ptr+strlen(start_ptr);
72292 +
72293 + if (end_ptr<start_ptr)
72294 + {
72295 + os_free_mem(NULL, temp_buf1);
72296 + os_free_mem(NULL, temp_buf2);
72297 + return (FALSE);
72298 + }
72299 +
72300 + *end_offset = end_ptr - buffer;
72301 +
72302 + NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
72303 + temp_buf2[end_ptr-start_ptr]='\0';
72304 + len = strlen(temp_buf2);
72305 + strcpy(temp_buf1, temp_buf2);
72306 + if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
72307 + {
72308 + os_free_mem(NULL, temp_buf1);
72309 + os_free_mem(NULL, temp_buf2);
72310 + return (FALSE);
72311 + }
72312 +
72313 + strcpy(temp_buf2, start_ptr+1);
72314 + ptr = temp_buf2;
72315 + //trim space or tab
72316 + while(*ptr != 0x00)
72317 + {
72318 + if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
72319 + ptr++;
72320 + else
72321 + break;
72322 + }
72323 +
72324 + len = strlen(ptr);
72325 + memset(dest, 0x00, destsize);
72326 + strncpy(dest, ptr, len >= destsize ? destsize: len);
72327 +
72328 + os_free_mem(NULL, temp_buf1);
72329 + os_free_mem(NULL, temp_buf2);
72330 + return TRUE;
72331 +}
72332 +
72333 +
72334 +static int rtmp_parse_key_buffer_from_file(IN PRTMP_ADAPTER pAd,IN char *buffer,IN ULONG KeyType,IN INT BSSIdx,IN INT KeyIdx)
72335 +{
72336 + PUCHAR keybuff;
72337 + INT i = BSSIdx, idx = KeyIdx;
72338 + ULONG KeyLen;
72339 + UCHAR CipherAlg = CIPHER_WEP64;
72340 +
72341 + keybuff = buffer;
72342 + KeyLen = strlen(keybuff);
72343 +
72344 + if (KeyType == 1)
72345 + {//Ascii
72346 + if( (KeyLen == 5) || (KeyLen == 13))
72347 + {
72348 + pAd->SharedKey[i][idx].KeyLen = KeyLen;
72349 + NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen);
72350 + if (KeyLen == 5)
72351 + CipherAlg = CIPHER_WEP64;
72352 + else
72353 + CipherAlg = CIPHER_WEP128;
72354 + pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
72355 +
72356 + DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
72357 + return 1;
72358 + }
72359 + else
72360 + {//Invalid key length
72361 + DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen));
72362 + return 0;
72363 + }
72364 + }
72365 + else
72366 + {//Hex type
72367 + if( (KeyLen == 10) || (KeyLen == 26))
72368 + {
72369 + pAd->SharedKey[i][idx].KeyLen = KeyLen / 2;
72370 + AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2);
72371 + if (KeyLen == 10)
72372 + CipherAlg = CIPHER_WEP64;
72373 + else
72374 + CipherAlg = CIPHER_WEP128;
72375 + pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
72376 +
72377 + DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
72378 + return 1;
72379 + }
72380 + else
72381 + {//Invalid key length
72382 + DBGPRINT(RT_DEBUG_ERROR, ("I/F(ra%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen));
72383 + return 0;
72384 + }
72385 + }
72386 +}
72387 +static void rtmp_read_key_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
72388 +{
72389 + char tok_str[16];
72390 + PUCHAR macptr;
72391 + INT i = 0, idx;
72392 + ULONG KeyType[MAX_MBSSID_NUM];
72393 + ULONG KeyIdx;
72394 +
72395 + NdisZeroMemory(KeyType, MAX_MBSSID_NUM);
72396 +
72397 + //DefaultKeyID
72398 + if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer))
72399 + {
72400 +
72401 +#ifdef CONFIG_STA_SUPPORT
72402 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72403 + {
72404 + KeyIdx = simple_strtol(tmpbuf, 0, 10);
72405 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
72406 + pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
72407 + else
72408 + pAd->StaCfg.DefaultKeyId = 0;
72409 +
72410 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
72411 + }
72412 +#endif // CONFIG_STA_SUPPORT //
72413 + }
72414 +
72415 +
72416 + for (idx = 0; idx < 4; idx++)
72417 + {
72418 + sprintf(tok_str, "Key%dType", idx + 1);
72419 + //Key1Type
72420 + if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer))
72421 + {
72422 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
72423 + {
72424 + KeyType[i] = simple_strtol(macptr, 0, 10);
72425 + }
72426 +
72427 +#ifdef CONFIG_STA_SUPPORT
72428 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72429 + {
72430 + sprintf(tok_str, "Key%dStr", idx + 1);
72431 + if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))
72432 + {
72433 + rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
72434 + }
72435 + }
72436 +#endif // CONFIG_STA_SUPPORT //
72437 + }
72438 + }
72439 +}
72440 +
72441 +
72442 +#ifdef CONFIG_STA_SUPPORT
72443 +static void rtmp_read_sta_wmm_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
72444 +{
72445 + PUCHAR macptr;
72446 + INT i=0;
72447 + BOOLEAN bWmmEnable = FALSE;
72448 +
72449 + //WmmCapable
72450 + if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer))
72451 + {
72452 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72453 + {
72454 + pAd->CommonCfg.bWmmCapable = TRUE;
72455 + bWmmEnable = TRUE;
72456 + }
72457 + else //Disable
72458 + {
72459 + pAd->CommonCfg.bWmmCapable = FALSE;
72460 + }
72461 +
72462 + DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
72463 + }
72464 +
72465 +#ifdef QOS_DLS_SUPPORT
72466 + //DLSCapable
72467 + if(RTMPGetKeyParameter("DLSCapable", tmpbuf, 32, buffer))
72468 + {
72469 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72470 + {
72471 + pAd->CommonCfg.bDLSCapable = TRUE;
72472 + }
72473 + else //Disable
72474 + {
72475 + pAd->CommonCfg.bDLSCapable = FALSE;
72476 + }
72477 +
72478 + DBGPRINT(RT_DEBUG_TRACE, ("bDLSCapable=%d\n", pAd->CommonCfg.bDLSCapable));
72479 + }
72480 +#endif // QOS_DLS_SUPPORT //
72481 +
72482 + //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
72483 + if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer))
72484 + {
72485 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
72486 + {
72487 + pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
72488 +
72489 + DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
72490 + }
72491 + }
72492 +
72493 + if (bWmmEnable)
72494 + {
72495 + //APSDCapable
72496 + if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))
72497 + {
72498 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72499 + pAd->CommonCfg.bAPSDCapable = TRUE;
72500 + else
72501 + pAd->CommonCfg.bAPSDCapable = FALSE;
72502 +
72503 + DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
72504 + }
72505 +
72506 + //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
72507 + if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))
72508 + {
72509 + BOOLEAN apsd_ac[4];
72510 +
72511 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
72512 + {
72513 + apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
72514 +
72515 + DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d %d\n", i, apsd_ac[i]));
72516 + }
72517 +
72518 + pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
72519 + pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
72520 + pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
72521 + pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
72522 + }
72523 + }
72524 +
72525 +}
72526 +#endif // CONFIG_STA_SUPPORT //
72527 +
72528 +
72529 +NDIS_STATUS RTMPReadParametersHook(
72530 + IN PRTMP_ADAPTER pAd)
72531 +{
72532 + PUCHAR src = NULL;
72533 + struct file *srcf;
72534 + INT retval, orgfsuid, orgfsgid;
72535 + mm_segment_t orgfs;
72536 + CHAR *buffer;
72537 + CHAR *tmpbuf;
72538 + ULONG RtsThresh;
72539 + ULONG FragThresh;
72540 +#ifdef CONFIG_STA_SUPPORT
72541 + UCHAR keyMaterial[40];
72542 +#endif // CONFIG_STA_SUPPORT //
72543 +
72544 +
72545 + PUCHAR macptr;
72546 + INT i = 0;
72547 +
72548 + buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
72549 + if(buffer == NULL)
72550 + return NDIS_STATUS_FAILURE;
72551 +
72552 + tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
72553 + if(tmpbuf == NULL)
72554 + {
72555 + kfree(buffer);
72556 + return NDIS_STATUS_FAILURE;
72557 + }
72558 +
72559 +#ifdef CONFIG_STA_SUPPORT
72560 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72561 + src = STA_PROFILE_PATH;
72562 +#endif // CONFIG_STA_SUPPORT //
72563 +#ifdef MULTIPLE_CARD_SUPPORT
72564 + src = pAd->MC_FileName;
72565 +#endif // MULTIPLE_CARD_SUPPORT //
72566 +
72567 + // Save uid and gid used for filesystem access.
72568 + // Set user and group to 0 (root)
72569 +#if 0
72570 + orgfsuid = current->fsuid;
72571 + orgfsgid = current->fsgid;
72572 + current->fsuid=current->fsgid = 0;
72573 +#endif
72574 + orgfs = get_fs();
72575 + set_fs(KERNEL_DS);
72576 +
72577 + if (src && *src)
72578 + {
72579 + srcf = filp_open(src, O_RDONLY, 0);
72580 + if (IS_ERR(srcf))
72581 + {
72582 + DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
72583 + }
72584 + else
72585 + {
72586 + // The object must have a read method
72587 + if (srcf->f_op && srcf->f_op->read)
72588 + {
72589 + memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
72590 + retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
72591 + if (retval < 0)
72592 + {
72593 + DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));
72594 + }
72595 + else
72596 + {
72597 + // set file parameter to portcfg
72598 + //CountryRegion
72599 + if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))
72600 + {
72601 + pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);
72602 + DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
72603 + }
72604 + //CountryRegionABand
72605 + if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))
72606 + {
72607 + pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);
72608 + DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
72609 + }
72610 + //CountryCode
72611 + if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))
72612 + {
72613 + NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
72614 +#ifdef CONFIG_STA_SUPPORT
72615 +#ifdef EXT_BUILD_CHANNEL_LIST
72616 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72617 + NdisMoveMemory(pAd->StaCfg.StaOriCountryCode, tmpbuf , 2);
72618 +#endif // EXT_BUILD_CHANNEL_LIST //
72619 +#endif // CONFIG_STA_SUPPORT //
72620 + if (strlen(pAd->CommonCfg.CountryCode) != 0)
72621 + {
72622 + pAd->CommonCfg.bCountryFlag = TRUE;
72623 + }
72624 + DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
72625 + }
72626 + //ChannelGeography
72627 + if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))
72628 + {
72629 + UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
72630 + if (Geography <= BOTH)
72631 + {
72632 + pAd->CommonCfg.Geography = Geography;
72633 + pAd->CommonCfg.CountryCode[2] =
72634 + (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
72635 +#ifdef CONFIG_STA_SUPPORT
72636 +#ifdef EXT_BUILD_CHANNEL_LIST
72637 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72638 + pAd->StaCfg.StaOriGeography = pAd->CommonCfg.Geography;
72639 +#endif // EXT_BUILD_CHANNEL_LIST //
72640 +#endif // CONFIG_STA_SUPPORT //
72641 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
72642 + }
72643 + }
72644 + else
72645 + {
72646 + pAd->CommonCfg.Geography = BOTH;
72647 + pAd->CommonCfg.CountryCode[2] = ' ';
72648 + }
72649 +
72650 +
72651 +#ifdef CONFIG_STA_SUPPORT
72652 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72653 + {
72654 + //SSID
72655 + if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))
72656 + {
72657 + if (strlen(tmpbuf) <= 32)
72658 + {
72659 + pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
72660 + NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
72661 + NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
72662 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
72663 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
72664 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
72665 + pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
72666 + NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
72667 + NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
72668 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __FUNCTION__, tmpbuf));
72669 + }
72670 + }
72671 + }
72672 +#endif // CONFIG_STA_SUPPORT //
72673 +
72674 +#ifdef CONFIG_STA_SUPPORT
72675 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72676 + {
72677 + //NetworkType
72678 + if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, buffer))
72679 + {
72680 + pAd->bConfigChanged = TRUE;
72681 + if (strcmp(tmpbuf, "Adhoc") == 0)
72682 + pAd->StaCfg.BssType = BSS_ADHOC;
72683 + else //Default Infrastructure mode
72684 + pAd->StaCfg.BssType = BSS_INFRA;
72685 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
72686 + pAd->StaCfg.WpaState = SS_NOTUSE;
72687 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __FUNCTION__, pAd->StaCfg.BssType));
72688 + }
72689 + }
72690 +#endif // CONFIG_STA_SUPPORT //
72691 + //Channel
72692 + if(RTMPGetKeyParameter("Channel", tmpbuf, 10, buffer))
72693 + {
72694 + pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
72695 + DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
72696 + }
72697 + //WirelessMode
72698 + if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, buffer))
72699 + {
72700 + int value = 0, maxPhyMode = PHY_11G;
72701 +
72702 +#ifdef DOT11_N_SUPPORT
72703 + maxPhyMode = PHY_11N_5G;
72704 +#endif // DOT11_N_SUPPORT //
72705 +
72706 + value = simple_strtol(tmpbuf, 0, 10);
72707 +
72708 + if (value <= maxPhyMode)
72709 + {
72710 + pAd->CommonCfg.PhyMode = value;
72711 + }
72712 + DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
72713 + }
72714 + //BasicRate
72715 + if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, buffer))
72716 + {
72717 + pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
72718 + DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
72719 + }
72720 + //BeaconPeriod
72721 + if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, buffer))
72722 + {
72723 + pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
72724 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
72725 + }
72726 + //TxPower
72727 + if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, buffer))
72728 + {
72729 + pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
72730 +#ifdef CONFIG_STA_SUPPORT
72731 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72732 + pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
72733 +#endif // CONFIG_STA_SUPPORT //
72734 + DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
72735 + }
72736 + //BGProtection
72737 + if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, buffer))
72738 + {
72739 + switch (simple_strtol(tmpbuf, 0, 10))
72740 + {
72741 + case 1: //Always On
72742 + pAd->CommonCfg.UseBGProtection = 1;
72743 + break;
72744 + case 2: //Always OFF
72745 + pAd->CommonCfg.UseBGProtection = 2;
72746 + break;
72747 + case 0: //AUTO
72748 + default:
72749 + pAd->CommonCfg.UseBGProtection = 0;
72750 + break;
72751 + }
72752 + DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
72753 + }
72754 + //OLBCDetection
72755 + if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, buffer))
72756 + {
72757 + switch (simple_strtol(tmpbuf, 0, 10))
72758 + {
72759 + case 1: //disable OLBC Detection
72760 + pAd->CommonCfg.DisableOLBCDetect = 1;
72761 + break;
72762 + case 0: //enable OLBC Detection
72763 + pAd->CommonCfg.DisableOLBCDetect = 0;
72764 + break;
72765 + default:
72766 + pAd->CommonCfg.DisableOLBCDetect= 0;
72767 + break;
72768 + }
72769 + DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
72770 + }
72771 + //TxPreamble
72772 + if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, buffer))
72773 + {
72774 + switch (simple_strtol(tmpbuf, 0, 10))
72775 + {
72776 + case Rt802_11PreambleShort:
72777 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
72778 + break;
72779 + case Rt802_11PreambleLong:
72780 + default:
72781 + pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
72782 + break;
72783 + }
72784 + DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
72785 + }
72786 + //RTSThreshold
72787 + if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, buffer))
72788 + {
72789 + RtsThresh = simple_strtol(tmpbuf, 0, 10);
72790 + if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
72791 + pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
72792 + else
72793 + pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
72794 +
72795 + DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
72796 + }
72797 + //FragThreshold
72798 + if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, buffer))
72799 + {
72800 + FragThresh = simple_strtol(tmpbuf, 0, 10);
72801 + pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
72802 +
72803 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
72804 + { //illegal FragThresh so we set it to default
72805 + pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
72806 + pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
72807 + }
72808 + else if (FragThresh % 2 == 1)
72809 + {
72810 + // The length of each fragment shall always be an even number of octets, except for the last fragment
72811 + // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
72812 + pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
72813 + }
72814 + else
72815 + {
72816 + pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
72817 + }
72818 + //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
72819 + DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
72820 + }
72821 + //TxBurst
72822 + if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, buffer))
72823 + {
72824 +//#ifdef WIFI_TEST
72825 +// pAd->CommonCfg.bEnableTxBurst = FALSE;
72826 +//#else
72827 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72828 + pAd->CommonCfg.bEnableTxBurst = TRUE;
72829 + else //Disable
72830 + pAd->CommonCfg.bEnableTxBurst = FALSE;
72831 +//#endif
72832 + DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
72833 + }
72834 +
72835 +#ifdef AGGREGATION_SUPPORT
72836 + //PktAggregate
72837 + if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, buffer))
72838 + {
72839 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72840 + pAd->CommonCfg.bAggregationCapable = TRUE;
72841 + else //Disable
72842 + pAd->CommonCfg.bAggregationCapable = FALSE;
72843 +#ifdef PIGGYBACK_SUPPORT
72844 + pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
72845 +#endif // PIGGYBACK_SUPPORT //
72846 + DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
72847 + }
72848 +#else
72849 + pAd->CommonCfg.bAggregationCapable = FALSE;
72850 + pAd->CommonCfg.bPiggyBackCapable = FALSE;
72851 +#endif // AGGREGATION_SUPPORT //
72852 +
72853 + // WmmCapable
72854 +
72855 +#ifdef CONFIG_STA_SUPPORT
72856 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72857 + rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, buffer);
72858 +#endif // CONFIG_STA_SUPPORT //
72859 +
72860 + //ShortSlot
72861 + if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, buffer))
72862 + {
72863 + if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
72864 + pAd->CommonCfg.bUseShortSlotTime = TRUE;
72865 + else //Disable
72866 + pAd->CommonCfg.bUseShortSlotTime = FALSE;
72867 +
72868 + DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
72869 + }
72870 + //IEEE80211H
72871 + if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, buffer))
72872 + {
72873 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
72874 + {
72875 + if(simple_strtol(macptr, 0, 10) != 0) //Enable
72876 + pAd->CommonCfg.bIEEE80211H = TRUE;
72877 + else //Disable
72878 + pAd->CommonCfg.bIEEE80211H = FALSE;
72879 +
72880 + DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
72881 + }
72882 + }
72883 + //CSPeriod
72884 + if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, buffer))
72885 + {
72886 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72887 + pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
72888 + else
72889 + pAd->CommonCfg.RadarDetect.CSPeriod = 0;
72890 +
72891 + DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
72892 + }
72893 +
72894 + //RDRegion
72895 + if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, buffer))
72896 + {
72897 + if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
72898 + {
72899 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W53;
72900 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 15;
72901 + }
72902 + else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
72903 + {
72904 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W56;
72905 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72906 + }
72907 + else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
72908 + {
72909 + pAd->CommonCfg.RadarDetect.RDDurRegion = JAP;
72910 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
72911 + }
72912 + else if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
72913 + {
72914 + pAd->CommonCfg.RadarDetect.RDDurRegion = FCC;
72915 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
72916 + }
72917 + else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
72918 + {
72919 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72920 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72921 + }
72922 + else
72923 + {
72924 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72925 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72926 + }
72927 +
72928 + DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pAd->CommonCfg.RadarDetect.RDDurRegion));
72929 + }
72930 + else
72931 + {
72932 + pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
72933 + pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
72934 + }
72935 +
72936 + //WirelessEvent
72937 + if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, buffer))
72938 + {
72939 +#if WIRELESS_EXT >= 15
72940 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72941 + pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
72942 + else
72943 + pAd->CommonCfg.bWirelessEvent = 0; // disable
72944 +#else
72945 + pAd->CommonCfg.bWirelessEvent = 0; // disable
72946 +#endif
72947 + DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
72948 + }
72949 + if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, buffer))
72950 + {
72951 + if(simple_strtol(tmpbuf, 0, 10) != 0)
72952 + pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
72953 + else
72954 + pAd->CommonCfg.bWiFiTest = 0; // disable
72955 +
72956 + DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
72957 + }
72958 + //AuthMode
72959 + if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, buffer))
72960 + {
72961 +#ifdef CONFIG_STA_SUPPORT
72962 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72963 + {
72964 + if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
72965 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
72966 + else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
72967 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
72968 + else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
72969 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
72970 + else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
72971 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
72972 + else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
72973 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
72974 +#ifdef WPA_SUPPLICANT_SUPPORT
72975 + else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
72976 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
72977 + else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
72978 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
72979 +#endif // WPA_SUPPLICANT_SUPPORT //
72980 + else
72981 + pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
72982 +
72983 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
72984 +
72985 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __FUNCTION__, pAd->StaCfg.WepStatus));
72986 + }
72987 +#endif // CONFIG_STA_SUPPORT //
72988 + }
72989 + //EncrypType
72990 + if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, buffer))
72991 + {
72992 +
72993 +#ifdef CONFIG_STA_SUPPORT
72994 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
72995 + {
72996 + if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
72997 + pAd->StaCfg.WepStatus = Ndis802_11WEPEnabled;
72998 + else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
72999 + pAd->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
73000 + else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
73001 + pAd->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
73002 + else
73003 + pAd->StaCfg.WepStatus = Ndis802_11WEPDisabled;
73004 +
73005 + // Update all wepstatus related
73006 + pAd->StaCfg.PairCipher = pAd->StaCfg.WepStatus;
73007 + pAd->StaCfg.GroupCipher = pAd->StaCfg.WepStatus;
73008 + pAd->StaCfg.OrigWepStatus = pAd->StaCfg.WepStatus;
73009 + pAd->StaCfg.bMixCipher = FALSE;
73010 +
73011 + //RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
73012 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __FUNCTION__, pAd->StaCfg.WepStatus));
73013 + }
73014 +#endif // CONFIG_STA_SUPPORT //
73015 + }
73016 +
73017 +
73018 +
73019 +#ifdef CONFIG_STA_SUPPORT
73020 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
73021 + {
73022 + if(RTMPGetCriticalParameter("WPAPSK", tmpbuf, 512, buffer))
73023 + {
73024 + int err=0;
73025 +
73026 + tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
73027 +
73028 + if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
73029 + (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
73030 + (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
73031 + )
73032 + {
73033 + err = 1;
73034 + }
73035 + else if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) < 64))
73036 + {
73037 + PasswordHash((char *)tmpbuf, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, keyMaterial);
73038 + NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
73039 +
73040 + }
73041 + else if (strlen(tmpbuf) == 64)
73042 + {
73043 + AtoH(tmpbuf, keyMaterial, 32);
73044 + NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
73045 + }
73046 + else
73047 + {
73048 + err = 1;
73049 + DBGPRINT(RT_DEBUG_ERROR, ("%s::(WPAPSK key-string required 8 ~ 64 characters!)\n", __FUNCTION__));
73050 + }
73051 +
73052 + if (err == 0)
73053 + {
73054 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
73055 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
73056 + {
73057 + // Start STA supplicant state machine
73058 + pAd->StaCfg.WpaState = SS_START;
73059 + }
73060 + else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
73061 + {
73062 + /*
73063 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
73064 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
73065 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
73066 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
73067 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
73068 +
73069 + // Decide its ChiperAlg
73070 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
73071 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
73072 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
73073 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
73074 + else
73075 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
73076 + */
73077 + pAd->StaCfg.WpaState = SS_NOTUSE;
73078 + }
73079 +
73080 + DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __FUNCTION__, tmpbuf));
73081 + }
73082 + }
73083 + }
73084 +#endif // CONFIG_STA_SUPPORT //
73085 +
73086 + //DefaultKeyID, KeyType, KeyStr
73087 + rtmp_read_key_parms_from_file(pAd, tmpbuf, buffer);
73088 +
73089 +
73090 + //HSCounter
73091 + /*if(RTMPGetKeyParameter("HSCounter", tmpbuf, 10, buffer))
73092 + {
73093 + switch (simple_strtol(tmpbuf, 0, 10))
73094 + {
73095 + case 1: //Enable
73096 + pAd->CommonCfg.bEnableHSCounter = TRUE;
73097 + break;
73098 + case 0: //Disable
73099 + default:
73100 + pAd->CommonCfg.bEnableHSCounter = FALSE;
73101 + break;
73102 + }
73103 + DBGPRINT(RT_DEBUG_TRACE, "HSCounter=%d\n", pAd->CommonCfg.bEnableHSCounter);
73104 + }*/
73105 +
73106 +#ifdef DOT11_N_SUPPORT
73107 + HTParametersHook(pAd, tmpbuf, buffer);
73108 +#endif // DOT11_N_SUPPORT //
73109 +
73110 +
73111 +#ifdef CARRIER_DETECTION_SUPPORT
73112 + //CarrierDetect
73113 + if(RTMPGetKeyParameter("CarrierDetect", tmpbuf, 128, buffer))
73114 + {
73115 + if ((strncmp(tmpbuf, "0", 1) == 0))
73116 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
73117 + else if ((strncmp(tmpbuf, "1", 1) == 0))
73118 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
73119 + else
73120 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
73121 +
73122 + DBGPRINT(RT_DEBUG_TRACE, ("CarrierDetect.Enable=%d\n", pAd->CommonCfg.CarrierDetect.Enable));
73123 + }
73124 + else
73125 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
73126 +#endif // CARRIER_DETECTION_SUPPORT //
73127 +
73128 +#ifdef CONFIG_STA_SUPPORT
73129 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
73130 + {
73131 + //PSMode
73132 + if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, buffer))
73133 + {
73134 + if (pAd->StaCfg.BssType == BSS_INFRA)
73135 + {
73136 + if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
73137 + {
73138 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
73139 + // to exclude certain situations.
73140 + // MlmeSetPsm(pAd, PWR_SAVE);
73141 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
73142 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
73143 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
73144 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
73145 + pAd->StaCfg.DefaultListenCount = 5;
73146 + }
73147 + else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
73148 + || (strcmp(tmpbuf, "FAST_PSP") == 0))
73149 + {
73150 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
73151 + // to exclude certain situations.
73152 + // MlmeSetPsmBit(pAd, PWR_SAVE);
73153 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
73154 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
73155 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
73156 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
73157 + pAd->StaCfg.DefaultListenCount = 3;
73158 + }
73159 + else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
73160 + || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
73161 + {
73162 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
73163 + // to exclude certain situations.
73164 + // MlmeSetPsmBit(pAd, PWR_SAVE);
73165 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
73166 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
73167 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
73168 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
73169 + pAd->StaCfg.DefaultListenCount = 3;
73170 + }
73171 + else
73172 + { //Default Ndis802_11PowerModeCAM
73173 + // clear PSM bit immediately
73174 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
73175 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
73176 + if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
73177 + pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
73178 + pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
73179 + }
73180 + DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
73181 + }
73182 + }
73183 + // FastRoaming
73184 + if (RTMPGetKeyParameter("FastRoaming", tmpbuf, 32, buffer))
73185 + {
73186 + if (simple_strtol(tmpbuf, 0, 10) == 0)
73187 + pAd->StaCfg.bFastRoaming = FALSE;
73188 + else
73189 + pAd->StaCfg.bFastRoaming = TRUE;
73190 +
73191 + DBGPRINT(RT_DEBUG_TRACE, ("FastRoaming=%d\n", pAd->StaCfg.bFastRoaming));
73192 + }
73193 + // RoamThreshold
73194 + if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, buffer))
73195 + {
73196 + long lInfo = simple_strtol(tmpbuf, 0, 10);
73197 +
73198 + if (lInfo > 90 || lInfo < 60)
73199 + pAd->StaCfg.dBmToRoam = -70;
73200 + else
73201 + pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
73202 +
73203 + DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d dBm\n", pAd->StaCfg.dBmToRoam));
73204 + }
73205 +
73206 + if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, buffer))
73207 + {
73208 + if(simple_strtol(tmpbuf, 0, 10) == 0)
73209 + pAd->StaCfg.bTGnWifiTest = FALSE;
73210 + else
73211 + pAd->StaCfg.bTGnWifiTest = TRUE;
73212 + DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
73213 + }
73214 + }
73215 +#endif // CONFIG_STA_SUPPORT //
73216 +
73217 +
73218 +#ifdef RT30xx
73219 +#ifdef CONFIG_STA_SUPPORT
73220 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
73221 + {
73222 + if(RTMPGetKeyParameter("AntDiversity", tmpbuf, 10, buffer))
73223 + {
73224 + for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
73225 + {
73226 + if(simple_strtol(macptr, 0, 10) != 0) //Enable
73227 + pAd->CommonCfg.bRxAntDiversity = TRUE;
73228 + else //Disable
73229 + pAd->CommonCfg.bRxAntDiversity = FALSE;
73230 +
73231 + DBGPRINT(RT_DEBUG_ERROR, ("AntDiversity=%d\n", pAd->CommonCfg.bRxAntDiversity));
73232 + }
73233 + }
73234 + }
73235 +#endif // CONFIG_STA_SUPPORT //
73236 +#endif // RT30xx //
73237 + }
73238 + }
73239 + else
73240 + {
73241 + DBGPRINT(RT_DEBUG_TRACE, ("--> %s does not have a write method\n", src));
73242 + }
73243 +
73244 + retval=filp_close(srcf,NULL);
73245 +
73246 + if (retval)
73247 + {
73248 + DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
73249 + }
73250 + }
73251 + }
73252 +
73253 + set_fs(orgfs);
73254 +#if 0
73255 + current->fsuid = orgfsuid;
73256 + current->fsgid = orgfsgid;
73257 +#endif
73258 +
73259 + kfree(buffer);
73260 + kfree(tmpbuf);
73261 +
73262 + return (NDIS_STATUS_SUCCESS);
73263 +}
73264 +
73265 +#ifdef DOT11_N_SUPPORT
73266 +static void HTParametersHook(
73267 + IN PRTMP_ADAPTER pAd,
73268 + IN CHAR *pValueStr,
73269 + IN CHAR *pInput)
73270 +{
73271 +
73272 + INT Value;
73273 +
73274 + if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput))
73275 + {
73276 + Value = simple_strtol(pValueStr, 0, 10);
73277 + if (Value == 0)
73278 + {
73279 + pAd->CommonCfg.bHTProtect = FALSE;
73280 + }
73281 + else
73282 + {
73283 + pAd->CommonCfg.bHTProtect = TRUE;
73284 + }
73285 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection = %s\n", (Value==0) ? "Disable" : "Enable"));
73286 + }
73287 +
73288 + if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput))
73289 + {
73290 + Value = simple_strtol(pValueStr, 0, 10);
73291 + if (Value == 0)
73292 + {
73293 + pAd->CommonCfg.bMIMOPSEnable = FALSE;
73294 + }
73295 + else
73296 + {
73297 + pAd->CommonCfg.bMIMOPSEnable = TRUE;
73298 + }
73299 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable = %s\n", (Value==0) ? "Disable" : "Enable"));
73300 + }
73301 +
73302 +
73303 + if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput))
73304 + {
73305 + Value = simple_strtol(pValueStr, 0, 10);
73306 + if (Value > MMPS_ENABLE)
73307 + {
73308 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
73309 + }
73310 + else
73311 + {
73312 + //TODO: add mimo power saving mechanism
73313 + pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
73314 + //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
73315 + }
73316 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode = %d\n", Value));
73317 + }
73318 +
73319 + if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput))
73320 + {
73321 + Value = simple_strtol(pValueStr, 0, 10);
73322 + if (Value == 0)
73323 + {
73324 + pAd->CommonCfg.bBADecline = FALSE;
73325 + }
73326 + else
73327 + {
73328 + pAd->CommonCfg.bBADecline = TRUE;
73329 + }
73330 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline = %s\n", (Value==0) ? "Disable" : "Enable"));
73331 + }
73332 +
73333 +
73334 + if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput))
73335 + {
73336 + Value = simple_strtol(pValueStr, 0, 10);
73337 + if (Value == 0)
73338 + {
73339 + pAd->CommonCfg.bDisableReordering = FALSE;
73340 + }
73341 + else
73342 + {
73343 + pAd->CommonCfg.bDisableReordering = TRUE;
73344 + }
73345 + DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering = %s\n", (Value==0) ? "Disable" : "Enable"));
73346 + }
73347 +
73348 + if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput))
73349 + {
73350 + Value = simple_strtol(pValueStr, 0, 10);
73351 + if (Value == 0)
73352 + {
73353 + pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
73354 + pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
73355 + }
73356 + else
73357 + {
73358 + pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
73359 + pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
73360 + }
73361 + pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
73362 + pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy;
73363 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA = %s\n", (Value==0) ? "Disable" : "Enable"));
73364 + }
73365 +
73366 + // Tx_+HTC frame
73367 + if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput))
73368 + {
73369 + Value = simple_strtol(pValueStr, 0, 10);
73370 + if (Value == 0)
73371 + {
73372 + pAd->HTCEnable = FALSE;
73373 + }
73374 + else
73375 + {
73376 + pAd->HTCEnable = TRUE;
73377 + }
73378 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
73379 + }
73380 +
73381 + // Enable HT Link Adaptation Control
73382 + if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput))
73383 + {
73384 + Value = simple_strtol(pValueStr, 0, 10);
73385 + if (Value == 0)
73386 + {
73387 + pAd->bLinkAdapt = FALSE;
73388 + }
73389 + else
73390 + {
73391 + pAd->HTCEnable = TRUE;
73392 + pAd->bLinkAdapt = TRUE;
73393 + }
73394 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
73395 + }
73396 +
73397 + // Reverse Direction Mechanism
73398 + if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput))
73399 + {
73400 + Value = simple_strtol(pValueStr, 0, 10);
73401 + if (Value == 0)
73402 + {
73403 + pAd->CommonCfg.bRdg = FALSE;
73404 + }
73405 + else
73406 + {
73407 + pAd->HTCEnable = TRUE;
73408 + pAd->CommonCfg.bRdg = TRUE;
73409 + }
73410 + DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
73411 + }
73412 +
73413 +
73414 +
73415 +
73416 + // Tx A-MSUD ?
73417 + if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput))
73418 + {
73419 + Value = simple_strtol(pValueStr, 0, 10);
73420 + if (Value == 0)
73421 + {
73422 + pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
73423 + }
73424 + else
73425 + {
73426 + pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
73427 + }
73428 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
73429 + }
73430 +
73431 + // MPDU Density
73432 + if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput))
73433 + {
73434 + Value = simple_strtol(pValueStr, 0, 10);
73435 + if (Value <=7 && Value >= 0)
73436 + {
73437 + pAd->CommonCfg.BACapability.field.MpduDensity = Value;
73438 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", Value));
73439 + }
73440 + else
73441 + {
73442 + pAd->CommonCfg.BACapability.field.MpduDensity = 4;
73443 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
73444 + }
73445 + }
73446 +
73447 + // Max Rx BA Window Size
73448 + if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput))
73449 + {
73450 + Value = simple_strtol(pValueStr, 0, 10);
73451 +
73452 + if (Value >=1 && Value <= 64)
73453 + {
73454 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
73455 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
73456 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", Value));
73457 + }
73458 + else
73459 + {
73460 + pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
73461 + pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
73462 + DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
73463 + }
73464 +
73465 + }
73466 +
73467 + // Guard Interval
73468 + if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput))
73469 + {
73470 + Value = simple_strtol(pValueStr, 0, 10);
73471 +
73472 + if (Value == GI_400)
73473 + {
73474 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
73475 + }
73476 + else
73477 + {
73478 + pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
73479 + }
73480 +
73481 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
73482 + }
73483 +
73484 + // HT Operation Mode : Mixed Mode , Green Field
73485 + if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput))
73486 + {
73487 + Value = simple_strtol(pValueStr, 0, 10);
73488 +
73489 + if (Value == HTMODE_GF)
73490 + {
73491 +
73492 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
73493 + }
73494 + else
73495 + {
73496 + pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
73497 + }
73498 +
73499 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
73500 + }
73501 +
73502 + // Fixed Tx mode : CCK, OFDM
73503 + if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput))
73504 + {
73505 + UCHAR fix_tx_mode;
73506 +
73507 +#ifdef CONFIG_STA_SUPPORT
73508 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
73509 + {
73510 + fix_tx_mode = FIXED_TXMODE_HT;
73511 +
73512 + if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
73513 + {
73514 + fix_tx_mode = FIXED_TXMODE_OFDM;
73515 + }
73516 + else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
73517 + {
73518 + fix_tx_mode = FIXED_TXMODE_CCK;
73519 + }
73520 + else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
73521 + {
73522 + fix_tx_mode = FIXED_TXMODE_HT;
73523 + }
73524 + else
73525 + {
73526 + Value = simple_strtol(pValueStr, 0, 10);
73527 + // 1 : CCK
73528 + // 2 : OFDM
73529 + // otherwise : HT
73530 + if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
73531 + fix_tx_mode = Value;
73532 + else
73533 + fix_tx_mode = FIXED_TXMODE_HT;
73534 + }
73535 +
73536 + pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
73537 + DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
73538 +
73539 + }
73540 +#endif // CONFIG_STA_SUPPORT //
73541 + }
73542 +
73543 +
73544 + // Channel Width
73545 + if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput))
73546 + {
73547 + Value = simple_strtol(pValueStr, 0, 10);
73548 +
73549 + if (Value == BW_40)
73550 + {
73551 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
73552 + }
73553 + else
73554 + {
73555 + pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
73556 + }
73557 +
73558 +#ifdef MCAST_RATE_SPECIFIC
73559 + pAd->CommonCfg.MCastPhyMode.field.BW = pAd->CommonCfg.RegTransmitSetting.field.BW;
73560 +#endif // MCAST_RATE_SPECIFIC //
73561 +
73562 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
73563 + }
73564 +
73565 + if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput))
73566 + {
73567 + Value = simple_strtol(pValueStr, 0, 10);
73568 +
73569 + if (Value == 0)
73570 + {
73571 +
73572 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
73573 + }
73574 + else
73575 + {
73576 + pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
73577 + }
73578 +
73579 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
73580 + }
73581 +
73582 + // MSC
73583 + if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput))
73584 + {
73585 +
73586 +#ifdef CONFIG_STA_SUPPORT
73587 + IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
73588 + {
73589 + Value = simple_strtol(pValueStr, 0, 10);
73590 +
73591 +// if ((Value >= 0 && Value <= 15) || (Value == 32))
73592 + if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
73593 + {
73594 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = Value;
73595 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
73596 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
73597 + }
73598 + else
73599 + {
73600 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
73601 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
73602 + DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
73603 + }
73604 + }
73605 +#endif // CONFIG_STA_SUPPORT //
73606 + }
73607 +
73608 + // STBC
73609 + if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput))
73610 + {
73611 + Value = simple_strtol(pValueStr, 0, 10);
73612 + if (Value == STBC_USE)
73613 + {
73614 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
73615 + }
73616 + else
73617 + {
73618 + pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
73619 + }
73620 + DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
73621 + }
73622 +
73623 + // 40_Mhz_Intolerant
73624 + if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput))
73625 + {
73626 + Value = simple_strtol(pValueStr, 0, 10);
73627 + if (Value == 0)
73628 + {
73629 + pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
73630 + }
73631 + else
73632 + {
73633 + pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
73634 + }
73635 + DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
73636 + }
73637 + //HT_TxStream
73638 + if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput))
73639 + {
73640 + switch (simple_strtol(pValueStr, 0, 10))
73641 + {
73642 + case 1:
73643 + pAd->CommonCfg.TxStream = 1;
73644 + break;
73645 + case 2:
73646 + pAd->CommonCfg.TxStream = 2;
73647 + break;
73648 + case 3: // 3*3
73649 + default:
73650 + pAd->CommonCfg.TxStream = 3;
73651 +
73652 + if (pAd->MACVersion < RALINK_2883_VERSION)
73653 + pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
73654 + break;
73655 + }
73656 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
73657 + }
73658 + //HT_RxStream
73659 + if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput))
73660 + {
73661 + switch (simple_strtol(pValueStr, 0, 10))
73662 + {
73663 + case 1:
73664 + pAd->CommonCfg.RxStream = 1;
73665 + break;
73666 + case 2:
73667 + pAd->CommonCfg.RxStream = 2;
73668 + break;
73669 + case 3:
73670 + default:
73671 + pAd->CommonCfg.RxStream = 3;
73672 +
73673 + if (pAd->MACVersion < RALINK_2883_VERSION)
73674 + pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
73675 + break;
73676 + }
73677 + DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));
73678 + }
73679 +
73680 +}
73681 +#endif // DOT11_N_SUPPORT //
73682 +
73683 --- /dev/null
73684 +++ b/drivers/staging/rt3070/spectrum_def.h
73685 @@ -0,0 +1,95 @@
73686 +/*
73687 + *************************************************************************
73688 + * Ralink Tech Inc.
73689 + * 5F., No.36, Taiyuan St., Jhubei City,
73690 + * Hsinchu County 302,
73691 + * Taiwan, R.O.C.
73692 + *
73693 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
73694 + *
73695 + * This program is free software; you can redistribute it and/or modify *
73696 + * it under the terms of the GNU General Public License as published by *
73697 + * the Free Software Foundation; either version 2 of the License, or *
73698 + * (at your option) any later version. *
73699 + * *
73700 + * This program is distributed in the hope that it will be useful, *
73701 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
73702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
73703 + * GNU General Public License for more details. *
73704 + * *
73705 + * You should have received a copy of the GNU General Public License *
73706 + * along with this program; if not, write to the *
73707 + * Free Software Foundation, Inc., *
73708 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
73709 + * *
73710 + *************************************************************************
73711 +
73712 + Module Name:
73713 + spectrum_def.h
73714 +
73715 + Abstract:
73716 + Handle association related requests either from WSTA or from local MLME
73717 +
73718 + Revision History:
73719 + Who When What
73720 + --------- ---------- ----------------------------------------------
73721 + Fonchi Wu 2008 created for 802.11h
73722 + */
73723 +
73724 +#ifndef __SPECTRUM_DEF_H__
73725 +#define __SPECTRUM_DEF_H__
73726 +
73727 +#define MAX_MEASURE_REQ_TAB_SIZE 3
73728 +#define MAX_HASH_MEASURE_REQ_TAB_SIZE MAX_MEASURE_REQ_TAB_SIZE
73729 +
73730 +#define MAX_TPC_REQ_TAB_SIZE 3
73731 +#define MAX_HASH_TPC_REQ_TAB_SIZE MAX_TPC_REQ_TAB_SIZE
73732 +
73733 +#define MIN_RCV_PWR 100 /* Negative value ((dBm) */
73734 +
73735 +#define RM_TPC_REQ 0
73736 +#define RM_MEASURE_REQ 1
73737 +
73738 +#define RM_BASIC 0
73739 +#define RM_CCA 1
73740 +#define RM_RPI_HISTOGRAM 2
73741 +
73742 +#define TPC_REQ_AGE_OUT 500 /* ms */
73743 +#define MQ_REQ_AGE_OUT 500 /* ms */
73744 +
73745 +#define TPC_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_HASH_TPC_REQ_TAB_SIZE)
73746 +#define MQ_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_MEASURE_REQ_TAB_SIZE)
73747 +
73748 +typedef struct _MEASURE_REQ_ENTRY
73749 +{
73750 + struct _MEASURE_REQ_ENTRY *pNext;
73751 + ULONG lastTime;
73752 + BOOLEAN Valid;
73753 + UINT8 DialogToken;
73754 + UINT8 MeasureDialogToken[3]; // 0:basic measure, 1: CCA measure, 2: RPI_Histogram measure.
73755 +} MEASURE_REQ_ENTRY, *PMEASURE_REQ_ENTRY;
73756 +
73757 +typedef struct _MEASURE_REQ_TAB
73758 +{
73759 + UCHAR Size;
73760 + PMEASURE_REQ_ENTRY Hash[MAX_HASH_MEASURE_REQ_TAB_SIZE];
73761 + MEASURE_REQ_ENTRY Content[MAX_MEASURE_REQ_TAB_SIZE];
73762 +} MEASURE_REQ_TAB, *PMEASURE_REQ_TAB;
73763 +
73764 +typedef struct _TPC_REQ_ENTRY
73765 +{
73766 + struct _TPC_REQ_ENTRY *pNext;
73767 + ULONG lastTime;
73768 + BOOLEAN Valid;
73769 + UINT8 DialogToken;
73770 +} TPC_REQ_ENTRY, *PTPC_REQ_ENTRY;
73771 +
73772 +typedef struct _TPC_REQ_TAB
73773 +{
73774 + UCHAR Size;
73775 + PTPC_REQ_ENTRY Hash[MAX_HASH_TPC_REQ_TAB_SIZE];
73776 + TPC_REQ_ENTRY Content[MAX_TPC_REQ_TAB_SIZE];
73777 +} TPC_REQ_TAB, *PTPC_REQ_TAB;
73778 +
73779 +#endif // __SPECTRUM_DEF_H__ //
73780 +
73781 --- /dev/null
73782 +++ b/drivers/staging/rt3070/spectrum.h
73783 @@ -0,0 +1,322 @@
73784 +/*
73785 + *************************************************************************
73786 + * Ralink Tech Inc.
73787 + * 5F., No.36, Taiyuan St., Jhubei City,
73788 + * Hsinchu County 302,
73789 + * Taiwan, R.O.C.
73790 + *
73791 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
73792 + *
73793 + * This program is free software; you can redistribute it and/or modify *
73794 + * it under the terms of the GNU General Public License as published by *
73795 + * the Free Software Foundation; either version 2 of the License, or *
73796 + * (at your option) any later version. *
73797 + * *
73798 + * This program is distributed in the hope that it will be useful, *
73799 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
73800 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
73801 + * GNU General Public License for more details. *
73802 + * *
73803 + * You should have received a copy of the GNU General Public License *
73804 + * along with this program; if not, write to the *
73805 + * Free Software Foundation, Inc., *
73806 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
73807 + * *
73808 + *************************************************************************
73809 + */
73810 +
73811 +#ifndef __SPECTRUM_H__
73812 +#define __SPECTRUM_H__
73813 +
73814 +#include "rtmp_type.h"
73815 +#include "spectrum_def.h"
73816 +
73817 +typedef struct PACKED _TPC_REPORT_INFO
73818 +{
73819 + UINT8 TxPwr;
73820 + UINT8 LinkMargin;
73821 +} TPC_REPORT_INFO, *PTPC_REPORT_INFO;
73822 +
73823 +typedef struct PACKED _CH_SW_ANN_INFO
73824 +{
73825 + UINT8 ChSwMode;
73826 + UINT8 Channel;
73827 + UINT8 ChSwCnt;
73828 +} CH_SW_ANN_INFO, *PCH_SW_ANN_INFO;
73829 +
73830 +typedef union PACKED _MEASURE_REQ_MODE
73831 +{
73832 +#ifdef RT_BIG_ENDIAN
73833 + struct PACKED
73834 + {
73835 + UINT8 Rev1:4;
73836 + UINT8 Report:1;
73837 + UINT8 Request:1;
73838 + UINT8 Enable:1;
73839 + UINT8 Rev0:1;
73840 + } field;
73841 +#else
73842 + struct PACKED
73843 + {
73844 + UINT8 Rev0:1;
73845 + UINT8 Enable:1;
73846 + UINT8 Request:1;
73847 + UINT8 Report:1;
73848 + UINT8 Rev1:4;
73849 + } field;
73850 +#endif // RT_BIG_ENDIAN //
73851 + UINT8 word;
73852 +} MEASURE_REQ_MODE, *PMEASURE_REQ_MODE;
73853 +
73854 +typedef struct PACKED _MEASURE_REQ
73855 +{
73856 + UINT8 ChNum;
73857 + UINT64 MeasureStartTime;
73858 + UINT16 MeasureDuration;
73859 +} MEASURE_REQ, *PMEASURE_REQ;
73860 +
73861 +typedef struct PACKED _MEASURE_REQ_INFO
73862 +{
73863 + UINT8 Token;
73864 + MEASURE_REQ_MODE ReqMode;
73865 + UINT8 ReqType;
73866 + MEASURE_REQ MeasureReq;
73867 +} MEASURE_REQ_INFO, *PMEASURE_REQ_INFO;
73868 +
73869 +typedef union PACKED _MEASURE_BASIC_REPORT_MAP
73870 +{
73871 +#ifdef RT_BIG_ENDIAN
73872 + struct PACKED
73873 + {
73874 + UINT8 Rev:3;
73875 + UINT8 Unmeasure:1;
73876 + UINT8 Radar:1;
73877 + UINT8 UnidentifiedSignal:1;
73878 + UINT8 OfdmPreamble:1;
73879 + UINT8 BSS:1;
73880 + } field;
73881 +#else
73882 + struct PACKED
73883 + {
73884 + UINT8 BSS:1;
73885 + UINT8 OfdmPreamble:1;
73886 + UINT8 UnidentifiedSignal:1;
73887 + UINT8 Radar:1;
73888 + UINT8 Unmeasure:1;
73889 + UINT8 Rev:3;
73890 + } field;
73891 +#endif // RT_BIG_ENDIAN //
73892 + UINT8 word;
73893 +} MEASURE_BASIC_REPORT_MAP, *PMEASURE_BASIC_REPORT_MAP;
73894 +
73895 +typedef struct PACKED _MEASURE_BASIC_REPORT
73896 +{
73897 + UINT8 ChNum;
73898 + UINT64 MeasureStartTime;
73899 + UINT16 MeasureDuration;
73900 + MEASURE_BASIC_REPORT_MAP Map;
73901 +} MEASURE_BASIC_REPORT, *PMEASURE_BASIC_REPORT;
73902 +
73903 +typedef struct PACKED _MEASURE_CCA_REPORT
73904 +{
73905 + UINT8 ChNum;
73906 + UINT64 MeasureStartTime;
73907 + UINT16 MeasureDuration;
73908 + UINT8 CCA_Busy_Fraction;
73909 +} MEASURE_CCA_REPORT, *PMEASURE_CCA_REPORT;
73910 +
73911 +typedef struct PACKED _MEASURE_RPI_REPORT
73912 +{
73913 + UINT8 ChNum;
73914 + UINT64 MeasureStartTime;
73915 + UINT16 MeasureDuration;
73916 + UINT8 RPI_Density[8];
73917 +} MEASURE_RPI_REPORT, *PMEASURE_RPI_REPORT;
73918 +
73919 +typedef union PACKED _MEASURE_REPORT_MODE
73920 +{
73921 + struct PACKED
73922 + {
73923 +#ifdef RT_BIG_ENDIAN
73924 + UINT8 Rev:5;
73925 + UINT8 Refused:1;
73926 + UINT8 Incapable:1;
73927 + UINT8 Late:1;
73928 +#else
73929 + UINT8 Late:1;
73930 + UINT8 Incapable:1;
73931 + UINT8 Refused:1;
73932 + UINT8 Rev:5;
73933 +#endif // RT_BIG_ENDIAN //
73934 + } field;
73935 + UINT8 word;
73936 +} MEASURE_REPORT_MODE, *PMEASURE_REPORT_MODE;
73937 +
73938 +typedef struct PACKED _MEASURE_REPORT_INFO
73939 +{
73940 + UINT8 Token;
73941 + MEASURE_REPORT_MODE ReportMode;
73942 + UINT8 ReportType;
73943 + UINT8 Octect[0];
73944 +} MEASURE_REPORT_INFO, *PMEASURE_REPORT_INFO;
73945 +
73946 +typedef struct PACKED _QUIET_INFO
73947 +{
73948 + UINT8 QuietCnt;
73949 + UINT8 QuietPeriod;
73950 + UINT8 QuietDuration;
73951 + UINT8 QuietOffset;
73952 +} QUIET_INFO, *PQUIET_INFO;
73953 +
73954 +/*
73955 + ==========================================================================
73956 + Description:
73957 + Prepare Measurement request action frame and enqueue it into
73958 + management queue waiting for transmition.
73959 +
73960 + Parametrs:
73961 + 1. the destination mac address of the frame.
73962 +
73963 + Return : None.
73964 + ==========================================================================
73965 + */
73966 +VOID EnqueueMeasurementReq(
73967 + IN PRTMP_ADAPTER pAd,
73968 + IN PUCHAR pDA,
73969 + IN UINT8 MeasureToken,
73970 + IN UINT8 MeasureReqMode,
73971 + IN UINT8 MeasureReqType,
73972 + IN UINT8 MeasureCh,
73973 + IN UINT16 MeasureDuration);
73974 +
73975 +/*
73976 + ==========================================================================
73977 + Description:
73978 + Prepare Measurement report action frame and enqueue it into
73979 + management queue waiting for transmition.
73980 +
73981 + Parametrs:
73982 + 1. the destination mac address of the frame.
73983 +
73984 + Return : None.
73985 + ==========================================================================
73986 + */
73987 +VOID EnqueueMeasurementRep(
73988 + IN PRTMP_ADAPTER pAd,
73989 + IN PUCHAR pDA,
73990 + IN UINT8 DialogToken,
73991 + IN UINT8 MeasureToken,
73992 + IN UINT8 MeasureReqMode,
73993 + IN UINT8 MeasureReqType,
73994 + IN UINT8 ReportInfoLen,
73995 + IN PUINT8 pReportInfo);
73996 +
73997 +/*
73998 + ==========================================================================
73999 + Description:
74000 + Prepare TPC Request action frame and enqueue it into
74001 + management queue waiting for transmition.
74002 +
74003 + Parametrs:
74004 + 1. the destination mac address of the frame.
74005 +
74006 + Return : None.
74007 + ==========================================================================
74008 + */
74009 +VOID EnqueueTPCReq(
74010 + IN PRTMP_ADAPTER pAd,
74011 + IN PUCHAR pDA,
74012 + IN UCHAR DialogToken);
74013 +
74014 +/*
74015 + ==========================================================================
74016 + Description:
74017 + Prepare TPC Report action frame and enqueue it into
74018 + management queue waiting for transmition.
74019 +
74020 + Parametrs:
74021 + 1. the destination mac address of the frame.
74022 +
74023 + Return : None.
74024 + ==========================================================================
74025 + */
74026 +VOID EnqueueTPCRep(
74027 + IN PRTMP_ADAPTER pAd,
74028 + IN PUCHAR pDA,
74029 + IN UINT8 DialogToken,
74030 + IN UINT8 TxPwr,
74031 + IN UINT8 LinkMargin);
74032 +
74033 +/*
74034 + ==========================================================================
74035 + Description:
74036 + Prepare Channel Switch Announcement action frame and enqueue it into
74037 + management queue waiting for transmition.
74038 +
74039 + Parametrs:
74040 + 1. the destination mac address of the frame.
74041 + 2. Channel switch announcement mode.
74042 + 2. a New selected channel.
74043 +
74044 + Return : None.
74045 + ==========================================================================
74046 + */
74047 +VOID EnqueueChSwAnn(
74048 + IN PRTMP_ADAPTER pAd,
74049 + IN PUCHAR pDA,
74050 + IN UINT8 ChSwMode,
74051 + IN UINT8 NewCh);
74052 +
74053 +/*
74054 + ==========================================================================
74055 + Description:
74056 + Spectrun action frames Handler such as channel switch annoucement,
74057 + measurement report, measurement request actions frames.
74058 +
74059 + Parametrs:
74060 + Elme - MLME message containing the received frame
74061 +
74062 + Return : None.
74063 + ==========================================================================
74064 + */
74065 +VOID PeerSpectrumAction(
74066 + IN PRTMP_ADAPTER pAd,
74067 + IN MLME_QUEUE_ELEM *Elem);
74068 +
74069 +/*
74070 + ==========================================================================
74071 + Description:
74072 +
74073 + Parametrs:
74074 +
74075 + Return : None.
74076 + ==========================================================================
74077 + */
74078 +INT Set_MeasureReq_Proc(
74079 + IN PRTMP_ADAPTER pAd,
74080 + IN PUCHAR arg);
74081 +
74082 +INT Set_TpcReq_Proc(
74083 + IN PRTMP_ADAPTER pAd,
74084 + IN PUCHAR arg);
74085 +
74086 +VOID MeasureReqTabInit(
74087 + IN PRTMP_ADAPTER pAd);
74088 +
74089 +VOID MeasureReqTabExit(
74090 + IN PRTMP_ADAPTER pAd);
74091 +
74092 +VOID TpcReqTabInit(
74093 + IN PRTMP_ADAPTER pAd);
74094 +
74095 +VOID TpcReqTabExit(
74096 + IN PRTMP_ADAPTER pAd);
74097 +
74098 +VOID NotifyChSwAnnToPeerAPs(
74099 + IN PRTMP_ADAPTER pAd,
74100 + IN PUCHAR pRA,
74101 + IN PUCHAR pTA,
74102 + IN UINT8 ChSwMode,
74103 + IN UINT8 Channel);
74104 +#endif // __SPECTRUM_H__ //
74105 +
74106 --- /dev/null
74107 +++ b/drivers/staging/rt3070/sta/aironet.c
74108 @@ -0,0 +1,1312 @@
74109 +/*
74110 + *************************************************************************
74111 + * Ralink Tech Inc.
74112 + * 5F., No.36, Taiyuan St., Jhubei City,
74113 + * Hsinchu County 302,
74114 + * Taiwan, R.O.C.
74115 + *
74116 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
74117 + *
74118 + * This program is free software; you can redistribute it and/or modify *
74119 + * it under the terms of the GNU General Public License as published by *
74120 + * the Free Software Foundation; either version 2 of the License, or *
74121 + * (at your option) any later version. *
74122 + * *
74123 + * This program is distributed in the hope that it will be useful, *
74124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
74125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
74126 + * GNU General Public License for more details. *
74127 + * *
74128 + * You should have received a copy of the GNU General Public License *
74129 + * along with this program; if not, write to the *
74130 + * Free Software Foundation, Inc., *
74131 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
74132 + * *
74133 + *************************************************************************
74134 +
74135 + Module Name:
74136 + aironet.c
74137 +
74138 + Abstract:
74139 +
74140 + Revision History:
74141 + Who When What
74142 + -------- ---------- ----------------------------------------------
74143 + Paul Lin 04-06-15 Initial
74144 +*/
74145 +#include "../rt_config.h"
74146 +
74147 +/*
74148 + ==========================================================================
74149 + Description:
74150 + association state machine init, including state transition and timer init
74151 + Parameters:
74152 + S - pointer to the association state machine
74153 + ==========================================================================
74154 + */
74155 +VOID AironetStateMachineInit(
74156 + IN PRTMP_ADAPTER pAd,
74157 + IN STATE_MACHINE *S,
74158 + OUT STATE_MACHINE_FUNC Trans[])
74159 +{
74160 + StateMachineInit(S, Trans, MAX_AIRONET_STATE, MAX_AIRONET_MSG, (STATE_MACHINE_FUNC)Drop, AIRONET_IDLE, AIRONET_MACHINE_BASE);
74161 + StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_MSG, (STATE_MACHINE_FUNC)AironetMsgAction);
74162 + StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_SCAN_REQ, (STATE_MACHINE_FUNC)AironetRequestAction);
74163 + StateMachineSetAction(S, AIRONET_SCANNING, MT2_AIRONET_SCAN_DONE, (STATE_MACHINE_FUNC)AironetReportAction);
74164 +}
74165 +
74166 +/*
74167 + ==========================================================================
74168 + Description:
74169 + This is state machine function.
74170 + When receiving EAPOL packets which is for 802.1x key management.
74171 + Use both in WPA, and WPAPSK case.
74172 + In this function, further dispatch to different functions according to the received packet. 3 categories are :
74173 + 1. normal 4-way pairwisekey and 2-way groupkey handshake
74174 + 2. MIC error (Countermeasures attack) report packet from STA.
74175 + 3. Request for pairwise/group key update from STA
74176 + Return:
74177 + ==========================================================================
74178 +*/
74179 +VOID AironetMsgAction(
74180 + IN PRTMP_ADAPTER pAd,
74181 + IN MLME_QUEUE_ELEM *Elem)
74182 +{
74183 + USHORT Length;
74184 + UCHAR Index, i;
74185 + PUCHAR pData;
74186 + PAIRONET_RM_REQUEST_FRAME pRMReq;
74187 + PRM_REQUEST_ACTION pReqElem;
74188 +
74189 + DBGPRINT(RT_DEBUG_TRACE, ("-----> AironetMsgAction\n"));
74190 +
74191 + // 0. Get Aironet IAPP header first
74192 + pRMReq = (PAIRONET_RM_REQUEST_FRAME) &Elem->Msg[LENGTH_802_11];
74193 + pData = (PUCHAR) &Elem->Msg[LENGTH_802_11];
74194 +
74195 + // 1. Change endian format form network to little endian
74196 + Length = be2cpu16(pRMReq->IAPP.Length);
74197 +
74198 + // 2.0 Sanity check, this should only happen when CCX 2.0 support is enabled
74199 + if (pAd->StaCfg.CCXEnable != TRUE)
74200 + return;
74201 +
74202 + // 2.1 Radio measurement must be on
74203 + if (pAd->StaCfg.CCXControl.field.RMEnable != 1)
74204 + return;
74205 +
74206 + // 2.2. Debug print all bit information
74207 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP ID & Length %d\n", Length));
74208 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Type %x\n", pRMReq->IAPP.Type));
74209 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP SubType %x\n", pRMReq->IAPP.SubType));
74210 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Dialog Token %x\n", pRMReq->IAPP.Token));
74211 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Activation Delay %x\n", pRMReq->Delay));
74212 + DBGPRINT(RT_DEBUG_TRACE, ("IAPP Measurement Offset %x\n", pRMReq->Offset));
74213 +
74214 + // 3. Check IAPP frame type, it must be 0x32 for Cisco Aironet extension
74215 + if (pRMReq->IAPP.Type != AIRONET_IAPP_TYPE)
74216 + {
74217 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP type for Cisco Aironet extension\n"));
74218 + return;
74219 + }
74220 +
74221 + // 4. Check IAPP frame subtype, it must be 0x01 for Cisco Aironet extension request.
74222 + // Since we are acting as client only, we will disregards reply subtype.
74223 + if (pRMReq->IAPP.SubType != AIRONET_IAPP_SUBTYPE_REQUEST)
74224 + {
74225 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP subtype for Cisco Aironet extension\n"));
74226 + return;
74227 + }
74228 +
74229 + // 5. Verify Destination MAC and Source MAC, both should be all zeros.
74230 + if (! MAC_ADDR_EQUAL(pRMReq->IAPP.DA, ZERO_MAC_ADDR))
74231 + {
74232 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP DA for Cisco Aironet extension, it's not Zero\n"));
74233 + return;
74234 + }
74235 +
74236 + if (! MAC_ADDR_EQUAL(pRMReq->IAPP.SA, ZERO_MAC_ADDR))
74237 + {
74238 + DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP SA for Cisco Aironet extension, it's not Zero\n"));
74239 + return;
74240 + }
74241 +
74242 + // 6. Reinit all report related fields
74243 + NdisZeroMemory(pAd->StaCfg.FrameReportBuf, 2048);
74244 + NdisZeroMemory(pAd->StaCfg.BssReportOffset, sizeof(USHORT) * MAX_LEN_OF_BSS_TABLE);
74245 + NdisZeroMemory(pAd->StaCfg.MeasurementRequest, sizeof(RM_REQUEST_ACTION) * 4);
74246 +
74247 + // 7. Point to the start of first element report element
74248 + pAd->StaCfg.FrameReportLen = LENGTH_802_11 + sizeof(AIRONET_IAPP_HEADER);
74249 + DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));
74250 + pAd->StaCfg.LastBssIndex = 0xff;
74251 + pAd->StaCfg.RMReqCnt = 0;
74252 + pAd->StaCfg.ParallelReq = FALSE;
74253 + pAd->StaCfg.ParallelDuration = 0;
74254 + pAd->StaCfg.ParallelChannel = 0;
74255 + pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;
74256 + pAd->StaCfg.CurrentRMReqIdx = 0;
74257 + pAd->StaCfg.CLBusyBytes = 0;
74258 + // Reset the statistics
74259 + for (i = 0; i < 8; i++)
74260 + pAd->StaCfg.RPIDensity[i] = 0;
74261 +
74262 + Index = 0;
74263 +
74264 + // 8. Save dialog token for report
74265 + pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;
74266 +
74267 + // Save Activation delay & measurement offset, Not really needed
74268 +
74269 + // 9. Point to the first request element
74270 + pData += sizeof(AIRONET_RM_REQUEST_FRAME);
74271 + // Length should exclude the CISCO Aironet SNAP header
74272 + Length -= (sizeof(AIRONET_RM_REQUEST_FRAME) - LENGTH_802_1_H);
74273 +
74274 + // 10. Start Parsing the Measurement elements.
74275 + // Be careful about multiple MR elements within one frames.
74276 + while (Length > 0)
74277 + {
74278 + pReqElem = (PRM_REQUEST_ACTION) pData;
74279 + switch (pReqElem->ReqElem.Eid)
74280 + {
74281 + case IE_MEASUREMENT_REQUEST:
74282 + // From the example, it seems we only need to support one request in one frame
74283 + // There is no multiple request in one frame.
74284 + // Besides, looks like we need to take care the measurement request only.
74285 + // The measurement request is always 4 bytes.
74286 +
74287 + // Start parsing this type of request.
74288 + // 0. Eid is IE_MEASUREMENT_REQUEST
74289 + // 1. Length didn't include Eid and Length field, it always be 8.
74290 + // 2. Measurement Token, we nned to save it for the corresponding report.
74291 + // 3. Measurement Mode, Although there are definitions, but we din't see value other than
74292 + // 0 from test specs examples.
74293 + // 4. Measurement Type, this is what we need to do.
74294 + switch (pReqElem->ReqElem.Type)
74295 + {
74296 + case MSRN_TYPE_CHANNEL_LOAD_REQ:
74297 + case MSRN_TYPE_NOISE_HIST_REQ:
74298 + case MSRN_TYPE_BEACON_REQ:
74299 + // Check the Enable non-serving channel measurement control
74300 + if (pAd->StaCfg.CCXControl.field.DCRMEnable == 0)
74301 + {
74302 + // Check channel before enqueue the action
74303 + if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)
74304 + break;
74305 + }
74306 + else
74307 + {
74308 + // If off channel measurement, check the TU duration limit
74309 + if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)
74310 + if (pReqElem->Measurement.Duration > pAd->StaCfg.CCXControl.field.TuLimit)
74311 + break;
74312 + }
74313 +
74314 + // Save requests and execute actions later
74315 + NdisMoveMemory(&pAd->StaCfg.MeasurementRequest[Index], pReqElem, sizeof(RM_REQUEST_ACTION));
74316 + Index += 1;
74317 + break;
74318 +
74319 + case MSRN_TYPE_FRAME_REQ:
74320 + // Since it's option, we will support later
74321 + // FrameRequestAction(pAd, pData);
74322 + break;
74323 +
74324 + default:
74325 + break;
74326 + }
74327 +
74328 + // Point to next Measurement request
74329 + pData += sizeof(RM_REQUEST_ACTION);
74330 + Length -= sizeof(RM_REQUEST_ACTION);
74331 + break;
74332 +
74333 + // We accept request only, all others are dropped
74334 + case IE_MEASUREMENT_REPORT:
74335 + case IE_AP_TX_POWER:
74336 + case IE_MEASUREMENT_CAPABILITY:
74337 + default:
74338 + return;
74339 + }
74340 + }
74341 +
74342 + // 11. Update some flags and index
74343 + pAd->StaCfg.RMReqCnt = Index;
74344 +
74345 + if (Index)
74346 + {
74347 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);
74348 + RT28XX_MLME_HANDLER(pAd);
74349 + }
74350 +
74351 + DBGPRINT(RT_DEBUG_TRACE, ("<----- AironetMsgAction\n"));
74352 +}
74353 +
74354 +/*
74355 + ========================================================================
74356 +
74357 + Routine Description:
74358 +
74359 + Arguments:
74360 +
74361 + Return Value:
74362 + None
74363 +
74364 + Note:
74365 +
74366 + ========================================================================
74367 +*/
74368 +VOID AironetRequestAction(
74369 + IN PRTMP_ADAPTER pAd,
74370 + IN MLME_QUEUE_ELEM *Elem)
74371 +{
74372 + PRM_REQUEST_ACTION pReq;
74373 +
74374 + // 1. Point to next request element
74375 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
74376 +
74377 + // 2. Parse measurement type and call appropriate functions
74378 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
74379 + // Channel Load measurement request
74380 + ChannelLoadRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74381 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
74382 + // Noise Histogram measurement request
74383 + NoiseHistRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74384 + else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)
74385 + // Beacon measurement request
74386 + BeaconRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74387 + else
74388 + // Unknown. Do nothing and return, this should never happen
74389 + return;
74390 +
74391 + // 3. Peek into the next request, if it's parallel, we will update the scan time to the largest one
74392 + if ((pAd->StaCfg.CurrentRMReqIdx + 1) < pAd->StaCfg.RMReqCnt)
74393 + {
74394 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx + 1];
74395 + // Check for parallel bit
74396 + if ((pReq->ReqElem.Mode & 0x01) && (pReq->Measurement.Channel == pAd->StaCfg.CCXScanChannel))
74397 + {
74398 + // Update parallel mode request information
74399 + pAd->StaCfg.ParallelReq = TRUE;
74400 + pAd->StaCfg.CCXScanTime = ((pReq->Measurement.Duration > pAd->StaCfg.CCXScanTime) ?
74401 + (pReq->Measurement.Duration) : (pAd->StaCfg.CCXScanTime));
74402 + }
74403 + }
74404 +
74405 + // 4. Call RT28XX_MLME_HANDLER to execute the request mlme commands, Scan request is the only one used
74406 + RT28XX_MLME_HANDLER(pAd);
74407 +
74408 +}
74409 +
74410 +
74411 +/*
74412 + ========================================================================
74413 +
74414 + Routine Description:
74415 + Prepare channel load report action, special scan operation added
74416 + to support
74417 +
74418 + Arguments:
74419 + pAd Pointer to our adapter
74420 + pData Start from element ID
74421 +
74422 + Return Value:
74423 + None
74424 +
74425 + Note:
74426 +
74427 + ========================================================================
74428 +*/
74429 +VOID ChannelLoadRequestAction(
74430 + IN PRTMP_ADAPTER pAd,
74431 + IN UCHAR Index)
74432 +{
74433 + PRM_REQUEST_ACTION pReq;
74434 + MLME_SCAN_REQ_STRUCT ScanReq;
74435 + UCHAR ZeroSsid[32];
74436 + NDIS_STATUS NStatus;
74437 + PUCHAR pOutBuffer = NULL;
74438 + PHEADER_802_11 pNullFrame;
74439 +
74440 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction ----->\n"));
74441 +
74442 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
74443 + NdisZeroMemory(ZeroSsid, 32);
74444 +
74445 + // Prepare for special scan request
74446 + // The scan definition is different with our Active, Passive scan definition.
74447 + // For CCX2, Active means send out probe request with broadcast BSSID.
74448 + // Passive means no probe request sent, only listen to the beacons.
74449 + // The channel scanned is fixed as specified, no need to scan all channels.
74450 + // The scan wait time is specified in the request too.
74451 + // Passive scan Mode
74452 +
74453 + // Control state machine is not idle, reject the request
74454 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
74455 + return;
74456 +
74457 + // Fill out stuff for scan request
74458 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_CHANNEL_LOAD);
74459 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
74460 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
74461 +
74462 + // Reset some internal control flags to make sure this scan works.
74463 + BssTableInit(&pAd->StaCfg.CCXBssTab);
74464 + pAd->StaCfg.ScanCnt = 0;
74465 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
74466 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
74467 +
74468 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));
74469 +
74470 + // If it's non serving channel scan, send out a null frame with PSM bit on.
74471 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
74472 + {
74473 + // Use MLME enqueue method
74474 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
74475 + if (NStatus != NDIS_STATUS_SUCCESS)
74476 + return;
74477 +
74478 + pNullFrame = (PHEADER_802_11) pOutBuffer;;
74479 + // Make the power save Null frame with PSM bit on
74480 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
74481 + pNullFrame->Duration = 0;
74482 + pNullFrame->FC.Type = BTYPE_DATA;
74483 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
74484 +
74485 + // Send using priority queue
74486 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
74487 + MlmeFreeMemory(pAd, pOutBuffer);
74488 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
74489 + RTMPusecDelay(5000);
74490 + }
74491 +
74492 + pAd->StaCfg.CCXReqType = MSRN_TYPE_CHANNEL_LOAD_REQ;
74493 + pAd->StaCfg.CLBusyBytes = 0;
74494 + // Enable Rx with promiscuous reception
74495 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);
74496 +
74497 + // Set channel load measurement flag
74498 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
74499 +
74500 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
74501 +
74502 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction <-----\n"));
74503 +}
74504 +
74505 +/*
74506 + ========================================================================
74507 +
74508 + Routine Description:
74509 + Prepare noise histogram report action, special scan operation added
74510 + to support
74511 +
74512 + Arguments:
74513 + pAd Pointer to our adapter
74514 + pData Start from element ID
74515 +
74516 + Return Value:
74517 + None
74518 +
74519 + Note:
74520 +
74521 + ========================================================================
74522 +*/
74523 +VOID NoiseHistRequestAction(
74524 + IN PRTMP_ADAPTER pAd,
74525 + IN UCHAR Index)
74526 +{
74527 + PRM_REQUEST_ACTION pReq;
74528 + MLME_SCAN_REQ_STRUCT ScanReq;
74529 + UCHAR ZeroSsid[32], i;
74530 + NDIS_STATUS NStatus;
74531 + PUCHAR pOutBuffer = NULL;
74532 + PHEADER_802_11 pNullFrame;
74533 +
74534 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction ----->\n"));
74535 +
74536 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
74537 + NdisZeroMemory(ZeroSsid, 32);
74538 +
74539 + // Prepare for special scan request
74540 + // The scan definition is different with our Active, Passive scan definition.
74541 + // For CCX2, Active means send out probe request with broadcast BSSID.
74542 + // Passive means no probe request sent, only listen to the beacons.
74543 + // The channel scanned is fixed as specified, no need to scan all channels.
74544 + // The scan wait time is specified in the request too.
74545 + // Passive scan Mode
74546 +
74547 + // Control state machine is not idle, reject the request
74548 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
74549 + return;
74550 +
74551 + // Fill out stuff for scan request
74552 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_NOISE);
74553 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
74554 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
74555 +
74556 + // Reset some internal control flags to make sure this scan works.
74557 + BssTableInit(&pAd->StaCfg.CCXBssTab);
74558 + pAd->StaCfg.ScanCnt = 0;
74559 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
74560 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
74561 + pAd->StaCfg.CCXReqType = MSRN_TYPE_NOISE_HIST_REQ;
74562 +
74563 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));
74564 +
74565 + // If it's non serving channel scan, send out a null frame with PSM bit on.
74566 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
74567 + {
74568 + // Use MLME enqueue method
74569 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
74570 + if (NStatus != NDIS_STATUS_SUCCESS)
74571 + return;
74572 +
74573 + pNullFrame = (PHEADER_802_11) pOutBuffer;
74574 + // Make the power save Null frame with PSM bit on
74575 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
74576 + pNullFrame->Duration = 0;
74577 + pNullFrame->FC.Type = BTYPE_DATA;
74578 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
74579 +
74580 + // Send using priority queue
74581 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
74582 + MlmeFreeMemory(pAd, pOutBuffer);
74583 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
74584 + RTMPusecDelay(5000);
74585 + }
74586 +
74587 + // Reset the statistics
74588 + for (i = 0; i < 8; i++)
74589 + pAd->StaCfg.RPIDensity[i] = 0;
74590 +
74591 + // Enable Rx with promiscuous reception
74592 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);
74593 +
74594 + // Set channel load measurement flag
74595 + RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
74596 +
74597 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
74598 +
74599 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction <-----\n"));
74600 +}
74601 +
74602 +/*
74603 + ========================================================================
74604 +
74605 + Routine Description:
74606 + Prepare Beacon report action, special scan operation added
74607 + to support
74608 +
74609 + Arguments:
74610 + pAd Pointer to our adapter
74611 + pData Start from element ID
74612 +
74613 + Return Value:
74614 + None
74615 +
74616 + Note:
74617 +
74618 + ========================================================================
74619 +*/
74620 +VOID BeaconRequestAction(
74621 + IN PRTMP_ADAPTER pAd,
74622 + IN UCHAR Index)
74623 +{
74624 + PRM_REQUEST_ACTION pReq;
74625 + NDIS_STATUS NStatus;
74626 + PUCHAR pOutBuffer = NULL;
74627 + PHEADER_802_11 pNullFrame;
74628 + MLME_SCAN_REQ_STRUCT ScanReq;
74629 + UCHAR ZeroSsid[32];
74630 +
74631 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction ----->\n"));
74632 +
74633 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];
74634 + NdisZeroMemory(ZeroSsid, 32);
74635 +
74636 + // Prepare for special scan request
74637 + // The scan definition is different with our Active, Passive scan definition.
74638 + // For CCX2, Active means send out probe request with broadcast BSSID.
74639 + // Passive means no probe request sent, only listen to the beacons.
74640 + // The channel scanned is fixed as specified, no need to scan all channels.
74641 + // The scan wait time is specified in the request too.
74642 + if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_PASSIVE)
74643 + {
74644 + // Passive scan Mode
74645 + DBGPRINT(RT_DEBUG_TRACE, ("Passive Scan Mode!\n"));
74646 +
74647 + // Control state machine is not idle, reject the request
74648 + if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))
74649 + return;
74650 +
74651 + // Fill out stuff for scan request
74652 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_PASSIVE);
74653 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
74654 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
74655 +
74656 + // Reset some internal control flags to make sure this scan works.
74657 + BssTableInit(&pAd->StaCfg.CCXBssTab);
74658 + pAd->StaCfg.ScanCnt = 0;
74659 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
74660 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
74661 + pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;
74662 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));
74663 +
74664 + // If it's non serving channel scan, send out a null frame with PSM bit on.
74665 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
74666 + {
74667 + // Use MLME enqueue method
74668 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
74669 + if (NStatus != NDIS_STATUS_SUCCESS)
74670 + return;
74671 +
74672 + pNullFrame = (PHEADER_802_11) pOutBuffer;
74673 + // Make the power save Null frame with PSM bit on
74674 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
74675 + pNullFrame->Duration = 0;
74676 + pNullFrame->FC.Type = BTYPE_DATA;
74677 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
74678 +
74679 + // Send using priority queue
74680 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
74681 + MlmeFreeMemory(pAd, pOutBuffer);
74682 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
74683 + RTMPusecDelay(5000);
74684 + }
74685 +
74686 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
74687 + }
74688 + else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_ACTIVE)
74689 + {
74690 + // Active scan Mode
74691 + DBGPRINT(RT_DEBUG_TRACE, ("Active Scan Mode!\n"));
74692 +
74693 + // Control state machine is not idle, reject the request
74694 + if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
74695 + return;
74696 +
74697 + // Fill out stuff for scan request
74698 + ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_ACTIVE);
74699 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
74700 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
74701 +
74702 + // Reset some internal control flags to make sure this scan works.
74703 + BssTableInit(&pAd->StaCfg.CCXBssTab);
74704 + pAd->StaCfg.ScanCnt = 0;
74705 + pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;
74706 + pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;
74707 + pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;
74708 + DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));
74709 +
74710 + // If it's non serving channel scan, send out a null frame with PSM bit on.
74711 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
74712 + {
74713 + // Use MLME enqueue method
74714 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
74715 + if (NStatus != NDIS_STATUS_SUCCESS)
74716 + return;
74717 +
74718 + pNullFrame = (PHEADER_802_11) pOutBuffer;
74719 + // Make the power save Null frame with PSM bit on
74720 + MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
74721 + pNullFrame->Duration = 0;
74722 + pNullFrame->FC.Type = BTYPE_DATA;
74723 + pNullFrame->FC.PwrMgmt = PWR_SAVE;
74724 +
74725 + // Send using priority queue
74726 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
74727 + MlmeFreeMemory(pAd, pOutBuffer);
74728 + DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));
74729 + RTMPusecDelay(5000);
74730 + }
74731 +
74732 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
74733 + }
74734 + else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_BEACON_TABLE)
74735 + {
74736 + // Beacon report Mode, report all the APS in current bss table
74737 + DBGPRINT(RT_DEBUG_TRACE, ("Beacon Report Mode!\n"));
74738 +
74739 + // Copy current BSS table to CCX table, we can omit this step later on.
74740 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab, &pAd->ScanTab, sizeof(BSS_TABLE));
74741 +
74742 + // Create beacon report from Bss table
74743 + AironetCreateBeaconReportFromBssTable(pAd);
74744 +
74745 + // Set state to scanning
74746 + pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;
74747 +
74748 + // Enqueue report request
74749 + // Cisco scan request is finished, prepare beacon report
74750 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
74751 + }
74752 + else
74753 + {
74754 + // Wrong scan Mode
74755 + DBGPRINT(RT_DEBUG_TRACE, ("Wrong Scan Mode!\n"));
74756 + }
74757 +
74758 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction <-----\n"));
74759 +}
74760 +
74761 +/*
74762 + ========================================================================
74763 +
74764 + Routine Description:
74765 +
74766 + Arguments:
74767 +
74768 + Return Value:
74769 + None
74770 +
74771 + Note:
74772 +
74773 + ========================================================================
74774 +*/
74775 +VOID AironetReportAction(
74776 + IN PRTMP_ADAPTER pAd,
74777 + IN MLME_QUEUE_ELEM *Elem)
74778 +{
74779 + PRM_REQUEST_ACTION pReq;
74780 + ULONG Now32;
74781 +
74782 + NdisGetSystemUpTime(&Now32);
74783 + pAd->StaCfg.LastBeaconRxTime = Now32;
74784 +
74785 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
74786 +
74787 + DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction ----->\n"));
74788 +
74789 + // 1. Parse measurement type and call appropriate functions
74790 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
74791 + // Channel Load measurement request
74792 + ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74793 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
74794 + // Noise Histogram measurement request
74795 + NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74796 + else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)
74797 + // Beacon measurement request
74798 + BeaconReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74799 + else
74800 + // Unknown. Do nothing and return
74801 + ;
74802 +
74803 + // 2. Point to the correct index of action element, start from 0
74804 + pAd->StaCfg.CurrentRMReqIdx++;
74805 +
74806 + // 3. Check for parallel actions
74807 + if (pAd->StaCfg.ParallelReq == TRUE)
74808 + {
74809 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
74810 +
74811 + // Process next action right away
74812 + if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)
74813 + // Channel Load measurement request
74814 + ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74815 + else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)
74816 + // Noise Histogram measurement request
74817 + NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);
74818 +
74819 + pAd->StaCfg.ParallelReq = FALSE;
74820 + pAd->StaCfg.CurrentRMReqIdx++;
74821 + }
74822 +
74823 + if (pAd->StaCfg.CurrentRMReqIdx >= pAd->StaCfg.RMReqCnt)
74824 + {
74825 + // 4. There is no more unprocessed measurement request, go for transmit this report
74826 + AironetFinalReportAction(pAd);
74827 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
74828 + }
74829 + else
74830 + {
74831 + pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];
74832 +
74833 + if (pReq->Measurement.Channel != pAd->CommonCfg.Channel)
74834 + {
74835 + RTMPusecDelay(100000);
74836 + }
74837 +
74838 + // 5. There are more requests to be measure
74839 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);
74840 + RT28XX_MLME_HANDLER(pAd);
74841 + }
74842 +
74843 + DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction <-----\n"));
74844 +}
74845 +
74846 +/*
74847 + ========================================================================
74848 +
74849 + Routine Description:
74850 +
74851 + Arguments:
74852 +
74853 + Return Value:
74854 + None
74855 +
74856 + Note:
74857 +
74858 + ========================================================================
74859 +*/
74860 +VOID AironetFinalReportAction(
74861 + IN PRTMP_ADAPTER pAd)
74862 +{
74863 + PUCHAR pDest;
74864 + PAIRONET_IAPP_HEADER pIAPP;
74865 + PHEADER_802_11 pHeader;
74866 + UCHAR AckRate = RATE_2;
74867 + USHORT AckDuration = 0;
74868 + NDIS_STATUS NStatus;
74869 + PUCHAR pOutBuffer = NULL;
74870 + ULONG FrameLen = 0;
74871 +
74872 + DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction ----->\n"));
74873 +
74874 + // 0. Set up the frame pointer, Frame was inited at the end of message action
74875 + pDest = &pAd->StaCfg.FrameReportBuf[LENGTH_802_11];
74876 +
74877 + // 1. Update report IAPP fields
74878 + pIAPP = (PAIRONET_IAPP_HEADER) pDest;
74879 +
74880 + // 2. Copy Cisco SNAP header
74881 + NdisMoveMemory(pIAPP->CiscoSnapHeader, SNAP_AIRONET, LENGTH_802_1_H);
74882 +
74883 + // 3. network order for this 16bit length
74884 + pIAPP->Length = cpu2be16(pAd->StaCfg.FrameReportLen - LENGTH_802_11 - LENGTH_802_1_H);
74885 +
74886 + // 3.1 sanity check the report length, ignore it if there is nothing to report
74887 + if (be2cpu16(pIAPP->Length) <= 18)
74888 + return;
74889 +
74890 + // 4. Type must be 0x32
74891 + pIAPP->Type = AIRONET_IAPP_TYPE;
74892 +
74893 + // 5. SubType for report must be 0x81
74894 + pIAPP->SubType = AIRONET_IAPP_SUBTYPE_REPORT;
74895 +
74896 + // 6. DA is not used and must be zero, although the whole frame was cleared at the start of function
74897 + // We will do it again here. We can use BSSID instead
74898 + COPY_MAC_ADDR(pIAPP->DA, pAd->CommonCfg.Bssid);
74899 +
74900 + // 7. SA is the client reporting which must be our MAC
74901 + COPY_MAC_ADDR(pIAPP->SA, pAd->CurrentAddress);
74902 +
74903 + // 8. Copy the saved dialog token
74904 + pIAPP->Token = pAd->StaCfg.IAPPToken;
74905 +
74906 + // 9. Make the Report frame 802.11 header
74907 + // Reuse function in wpa.c
74908 + pHeader = (PHEADER_802_11) pAd->StaCfg.FrameReportBuf;
74909 + pAd->Sequence ++;
74910 + WpaMacHeaderInit(pAd, pHeader, 0, pAd->CommonCfg.Bssid);
74911 +
74912 + // ACK size is 14 include CRC, and its rate is based on real time information
74913 + AckRate = pAd->CommonCfg.ExpectedACKRate[pAd->CommonCfg.MlmeRate];
74914 + AckDuration = RTMPCalcDuration(pAd, AckRate, 14);
74915 + pHeader->Duration = pAd->CommonCfg.Dsifs + AckDuration;
74916 +
74917 + // Use MLME enqueue method
74918 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
74919 + if (NStatus != NDIS_STATUS_SUCCESS)
74920 + return;
74921 +
74922 + // 10. Prepare report frame with dynamic outbuffer. Just simply copy everything.
74923 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
74924 + pAd->StaCfg.FrameReportLen, pAd->StaCfg.FrameReportBuf,
74925 + END_OF_ARGS);
74926 +
74927 + // 11. Send using priority queue
74928 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
74929 + MlmeFreeMemory(pAd, pOutBuffer);
74930 +
74931 + pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED;
74932 +
74933 + DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction <-----\n"));
74934 +}
74935 +
74936 +/*
74937 + ========================================================================
74938 +
74939 + Routine Description:
74940 +
74941 + Arguments:
74942 +
74943 + Return Value:
74944 + None
74945 +
74946 + Note:
74947 +
74948 + ========================================================================
74949 +*/
74950 +VOID ChannelLoadReportAction(
74951 + IN PRTMP_ADAPTER pAd,
74952 + IN UCHAR Index)
74953 +{
74954 + PMEASUREMENT_REPORT_ELEMENT pReport;
74955 + PCHANNEL_LOAD_REPORT pLoad;
74956 + PUCHAR pDest;
74957 + UCHAR CCABusyFraction;
74958 +
74959 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction ----->\n"));
74960 +
74961 + // Disable Rx with promiscuous reception, make it back to normal
74962 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
74963 +
74964 + // 0. Setup pointer for processing beacon & probe response
74965 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
74966 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
74967 +
74968 + // 1. Fill Measurement report element field.
74969 + pReport->Eid = IE_MEASUREMENT_REPORT;
74970 + // Fixed Length at 9, not include Eid and length fields
74971 + pReport->Length = 9;
74972 + pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;
74973 + pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;
74974 + pReport->Type = MSRN_TYPE_CHANNEL_LOAD_REQ;
74975 +
74976 + // 2. Fill channel report measurement data
74977 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
74978 + pLoad = (PCHANNEL_LOAD_REPORT) pDest;
74979 + pLoad->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;
74980 + pLoad->Spare = 0;
74981 + pLoad->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;
74982 +
74983 + // 3. Calculate the CCA Busy Fraction
74984 + // (Bytes + ACK size) * 8 / Tx speed * 255 / 1000 / measurement duration, use 24 us Tx speed
74985 + // = (Bytes + ACK) / 12 / duration
74986 + // 9 is the good value for pAd->StaCfg.CLFactor
74987 + // CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 9 / pLoad->Duration);
74988 + CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / pAd->StaCfg.CLFactor / pLoad->Duration);
74989 + if (CCABusyFraction < 10)
74990 + CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 3 / pLoad->Duration) + 1;
74991 +
74992 + pLoad->CCABusy = CCABusyFraction;
74993 + DBGPRINT(RT_DEBUG_TRACE, ("CLBusyByte %ld, Duration %d, Result, %d\n", pAd->StaCfg.CLBusyBytes, pLoad->Duration, CCABusyFraction));
74994 +
74995 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));
74996 + pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(CHANNEL_LOAD_REPORT));
74997 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));
74998 +
74999 + // 4. Clear channel load measurement flag
75000 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
75001 +
75002 + // 5. reset to idle state
75003 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
75004 +
75005 + DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction <-----\n"));
75006 +}
75007 +
75008 +/*
75009 + ========================================================================
75010 +
75011 + Routine Description:
75012 +
75013 + Arguments:
75014 +
75015 + Return Value:
75016 + None
75017 +
75018 + Note:
75019 +
75020 + ========================================================================
75021 +*/
75022 +VOID NoiseHistReportAction(
75023 + IN PRTMP_ADAPTER pAd,
75024 + IN UCHAR Index)
75025 +{
75026 + PMEASUREMENT_REPORT_ELEMENT pReport;
75027 + PNOISE_HIST_REPORT pNoise;
75028 + PUCHAR pDest;
75029 + UCHAR i,NoiseCnt;
75030 + USHORT TotalRPICnt, TotalRPISum;
75031 +
75032 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction ----->\n"));
75033 +
75034 + // 0. Disable Rx with promiscuous reception, make it back to normal
75035 + RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.
75036 + // 1. Setup pointer for processing beacon & probe response
75037 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
75038 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
75039 +
75040 + // 2. Fill Measurement report element field.
75041 + pReport->Eid = IE_MEASUREMENT_REPORT;
75042 + // Fixed Length at 16, not include Eid and length fields
75043 + pReport->Length = 16;
75044 + pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;
75045 + pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;
75046 + pReport->Type = MSRN_TYPE_NOISE_HIST_REQ;
75047 +
75048 + // 3. Fill noise histogram report measurement data
75049 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
75050 + pNoise = (PNOISE_HIST_REPORT) pDest;
75051 + pNoise->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;
75052 + pNoise->Spare = 0;
75053 + pNoise->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;
75054 + // 4. Fill Noise histogram, the total RPI counts should be 0.4 * TU
75055 + // We estimate 4000 normal packets received durning 10 seconds test.
75056 + // Adjust it if required.
75057 + // 3 is a good value for pAd->StaCfg.NHFactor
75058 + // TotalRPICnt = pNoise->Duration * 3 / 10;
75059 + TotalRPICnt = pNoise->Duration * pAd->StaCfg.NHFactor / 10;
75060 + TotalRPISum = 0;
75061 +
75062 + for (i = 0; i < 8; i++)
75063 + {
75064 + TotalRPISum += pAd->StaCfg.RPIDensity[i];
75065 + DBGPRINT(RT_DEBUG_TRACE, ("RPI %d Conuts %d\n", i, pAd->StaCfg.RPIDensity[i]));
75066 + }
75067 +
75068 + // Double check if the counter is larger than our expectation.
75069 + // We will replace it with the total number plus a fraction.
75070 + if (TotalRPISum > TotalRPICnt)
75071 + TotalRPICnt = TotalRPISum + pNoise->Duration / 20;
75072 +
75073 + DBGPRINT(RT_DEBUG_TRACE, ("Total RPI Conuts %d\n", TotalRPICnt));
75074 +
75075 + // 5. Initialize noise count for the total summation of 0xff
75076 + NoiseCnt = 0;
75077 + for (i = 1; i < 8; i++)
75078 + {
75079 + pNoise->Density[i] = (UCHAR) (pAd->StaCfg.RPIDensity[i] * 255 / TotalRPICnt);
75080 + if ((pNoise->Density[i] == 0) && (pAd->StaCfg.RPIDensity[i] != 0))
75081 + pNoise->Density[i]++;
75082 + NoiseCnt += pNoise->Density[i];
75083 + DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[%d] = 0x%02x\n", i, pNoise->Density[i]));
75084 + }
75085 +
75086 + // 6. RPI[0] represents the rest of counts
75087 + pNoise->Density[0] = 0xff - NoiseCnt;
75088 + DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[0] = 0x%02x\n", pNoise->Density[0]));
75089 +
75090 + pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(NOISE_HIST_REPORT));
75091 +
75092 + // 7. Clear channel load measurement flag
75093 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);
75094 +
75095 + // 8. reset to idle state
75096 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
75097 +
75098 + DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction <-----\n"));
75099 +}
75100 +
75101 +/*
75102 + ========================================================================
75103 +
75104 + Routine Description:
75105 + Prepare Beacon report action,
75106 +
75107 + Arguments:
75108 + pAd Pointer to our adapter
75109 +
75110 + Return Value:
75111 + None
75112 +
75113 + Note:
75114 +
75115 + ========================================================================
75116 +*/
75117 +VOID BeaconReportAction(
75118 + IN PRTMP_ADAPTER pAd,
75119 + IN UCHAR Index)
75120 +{
75121 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction ----->\n"));
75122 +
75123 + // Looks like we don't have anything thing need to do here.
75124 + // All measurement report already finished in AddBeaconReport
75125 + // The length is in the FrameReportLen
75126 +
75127 + // reset Beacon index for next beacon request
75128 + pAd->StaCfg.LastBssIndex = 0xff;
75129 +
75130 + // reset to idle state
75131 + pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;
75132 +
75133 + DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction <-----\n"));
75134 +}
75135 +
75136 +/*
75137 + ========================================================================
75138 +
75139 + Routine Description:
75140 +
75141 + Arguments:
75142 + Index Current BSSID in CCXBsstab entry index
75143 +
75144 + Return Value:
75145 +
75146 + Note:
75147 +
75148 + ========================================================================
75149 +*/
75150 +VOID AironetAddBeaconReport(
75151 + IN PRTMP_ADAPTER pAd,
75152 + IN ULONG Index,
75153 + IN PMLME_QUEUE_ELEM pElem)
75154 +{
75155 + PVOID pMsg;
75156 + PUCHAR pSrc, pDest;
75157 + UCHAR ReqIdx;
75158 + ULONG MsgLen;
75159 + USHORT Length;
75160 + PFRAME_802_11 pFrame;
75161 + PMEASUREMENT_REPORT_ELEMENT pReport;
75162 + PEID_STRUCT pEid;
75163 + PBEACON_REPORT pBeaconReport;
75164 + PBSS_ENTRY pBss;
75165 +
75166 + // 0. Setup pointer for processing beacon & probe response
75167 + pMsg = pElem->Msg;
75168 + MsgLen = pElem->MsgLen;
75169 + pFrame = (PFRAME_802_11) pMsg;
75170 + pSrc = pFrame->Octet; // Start from AP TSF
75171 + pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];
75172 + ReqIdx = pAd->StaCfg.CurrentRMReqIdx;
75173 +
75174 + // 1 Check the Index, if we already create this entry, only update the average RSSI
75175 + if ((Index <= pAd->StaCfg.LastBssIndex) && (pAd->StaCfg.LastBssIndex != 0xff))
75176 + {
75177 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.BssReportOffset[Index]];
75178 + // Point to bss report information
75179 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
75180 + pBeaconReport = (PBEACON_REPORT) pDest;
75181 +
75182 + // Update Rx power, in dBm
75183 + // Get the original RSSI readback from BBP
75184 + pBeaconReport->RxPower += pAd->BbpRssiToDbmDelta;
75185 + // Average the Rssi reading
75186 + pBeaconReport->RxPower = (pBeaconReport->RxPower + pBss->Rssi) / 2;
75187 + // Get to dBm format
75188 + pBeaconReport->RxPower -= pAd->BbpRssiToDbmDelta;
75189 +
75190 + DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",
75191 + pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],
75192 + pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
75193 + DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld] Rssi %d, Avg Rssi %d\n", Index, (pBss->Rssi - pAd->BbpRssiToDbmDelta), pBeaconReport->RxPower - 256));
75194 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.BssReportOffset[Index]));
75195 +
75196 + // Update other information here
75197 +
75198 + // Done
75199 + return;
75200 + }
75201 +
75202 + // 2. Update reported Index
75203 + pAd->StaCfg.LastBssIndex = Index;
75204 +
75205 + // 3. Setup the buffer address for copying this BSSID into reporting frame
75206 + // The offset should start after 802.11 header and report frame header.
75207 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
75208 +
75209 + // 4. Save the start offset of each Bss in report frame
75210 + pAd->StaCfg.BssReportOffset[Index] = pAd->StaCfg.FrameReportLen;
75211 +
75212 + // 5. Fill Measurement report fields
75213 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
75214 + pReport->Eid = IE_MEASUREMENT_REPORT;
75215 + pReport->Length = 0;
75216 + pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;
75217 + pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;
75218 + pReport->Type = MSRN_TYPE_BEACON_REQ;
75219 + Length = sizeof(MEASUREMENT_REPORT_ELEMENT);
75220 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
75221 +
75222 + // 6. Start thebeacon report format
75223 + pBeaconReport = (PBEACON_REPORT) pDest;
75224 + pDest += sizeof(BEACON_REPORT);
75225 + Length += sizeof(BEACON_REPORT);
75226 +
75227 + // 7. Copy Channel number
75228 + pBeaconReport->Channel = pBss->Channel;
75229 + pBeaconReport->Spare = 0;
75230 + pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;
75231 + pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);
75232 + // 8. Rx power, in dBm
75233 + pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;
75234 +
75235 + DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",
75236 + pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],
75237 + pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
75238 + DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld], Rssi %d\n", Index, pBeaconReport->RxPower - 256));
75239 + DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.FrameReportLen));
75240 +
75241 + pBeaconReport->BeaconInterval = pBss->BeaconPeriod;
75242 + COPY_MAC_ADDR(pBeaconReport->BSSID, pFrame->Hdr.Addr3);
75243 + NdisMoveMemory(pBeaconReport->ParentTSF, pSrc, 4);
75244 + NdisMoveMemory(pBeaconReport->TargetTSF, &pElem->TimeStamp.u.LowPart, 4);
75245 + NdisMoveMemory(&pBeaconReport->TargetTSF[4], &pElem->TimeStamp.u.HighPart, 4);
75246 +
75247 + // 9. Skip the beacon frame and offset to start of capabilityinfo since we already processed capabilityinfo
75248 + pSrc += (TIMESTAMP_LEN + 2);
75249 + pBeaconReport->CapabilityInfo = *(USHORT *)pSrc;
75250 +
75251 + // 10. Point to start of element ID
75252 + pSrc += 2;
75253 + pEid = (PEID_STRUCT) pSrc;
75254 +
75255 + // 11. Start process all variable Eid oayload and add the appropriate to the frame report
75256 + while (((PUCHAR) pEid + pEid->Len + 1) < ((PUCHAR) pFrame + MsgLen))
75257 + {
75258 + // Only limited EID are required to report for CCX 2. It includes SSID, Supported rate,
75259 + // FH paramenter set, DS parameter set, CF parameter set, IBSS parameter set,
75260 + // TIM (report first 4 bytes only, radio measurement capability
75261 + switch (pEid->Eid)
75262 + {
75263 + case IE_SSID:
75264 + case IE_SUPP_RATES:
75265 + case IE_FH_PARM:
75266 + case IE_DS_PARM:
75267 + case IE_CF_PARM:
75268 + case IE_IBSS_PARM:
75269 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
75270 + pDest += (pEid->Len + 2);
75271 + Length += (pEid->Len + 2);
75272 + break;
75273 +
75274 + case IE_MEASUREMENT_CAPABILITY:
75275 + // Since this IE is duplicated with WPA security IE, we has to do sanity check before
75276 + // recognize it.
75277 + // 1. It also has fixed 6 bytes IE length.
75278 + if (pEid->Len != 6)
75279 + break;
75280 + // 2. Check the Cisco Aironet OUI
75281 + if (NdisEqualMemory(CISCO_OUI, (pSrc + 2), 3))
75282 + {
75283 + // Matched, this is what we want
75284 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
75285 + pDest += (pEid->Len + 2);
75286 + Length += (pEid->Len + 2);
75287 + }
75288 + break;
75289 +
75290 + case IE_TIM:
75291 + if (pEid->Len > 4)
75292 + {
75293 + // May truncate and report the first 4 bytes only, with the eid & len, total should be 6
75294 + NdisMoveMemory(pDest, pEid, 6);
75295 + pDest += 6;
75296 + Length += 6;
75297 + }
75298 + else
75299 + {
75300 + NdisMoveMemory(pDest, pEid, pEid->Len + 2);
75301 + pDest += (pEid->Len + 2);
75302 + Length += (pEid->Len + 2);
75303 + }
75304 + break;
75305 +
75306 + default:
75307 + break;
75308 + }
75309 + // 12. Move to next element ID
75310 + pSrc += (2 + pEid->Len);
75311 + pEid = (PEID_STRUCT) pSrc;
75312 + }
75313 +
75314 + // 13. Update the length in the header, not include EID and length
75315 + pReport->Length = Length - 4;
75316 +
75317 + // 14. Update the frame report buffer data length
75318 + pAd->StaCfg.FrameReportLen += Length;
75319 + DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));
75320 +}
75321 +
75322 +/*
75323 + ========================================================================
75324 +
75325 + Routine Description:
75326 +
75327 + Arguments:
75328 + Index Current BSSID in CCXBsstab entry index
75329 +
75330 + Return Value:
75331 +
75332 + Note:
75333 +
75334 + ========================================================================
75335 +*/
75336 +VOID AironetCreateBeaconReportFromBssTable(
75337 + IN PRTMP_ADAPTER pAd)
75338 +{
75339 + PMEASUREMENT_REPORT_ELEMENT pReport;
75340 + PBEACON_REPORT pBeaconReport;
75341 + UCHAR Index, ReqIdx;
75342 + USHORT Length;
75343 + PUCHAR pDest;
75344 + PBSS_ENTRY pBss;
75345 +
75346 + // 0. setup base pointer
75347 + ReqIdx = pAd->StaCfg.CurrentRMReqIdx;
75348 +
75349 + for (Index = 0; Index < pAd->StaCfg.CCXBssTab.BssNr; Index++)
75350 + {
75351 + // 1. Setup the buffer address for copying this BSSID into reporting frame
75352 + // The offset should start after 802.11 header and report frame header.
75353 + pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];
75354 + pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];
75355 + Length = 0;
75356 +
75357 + // 2. Fill Measurement report fields
75358 + pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;
75359 + pReport->Eid = IE_MEASUREMENT_REPORT;
75360 + pReport->Length = 0;
75361 + pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;
75362 + pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;
75363 + pReport->Type = MSRN_TYPE_BEACON_REQ;
75364 + Length = sizeof(MEASUREMENT_REPORT_ELEMENT);
75365 + pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);
75366 +
75367 + // 3. Start the beacon report format
75368 + pBeaconReport = (PBEACON_REPORT) pDest;
75369 + pDest += sizeof(BEACON_REPORT);
75370 + Length += sizeof(BEACON_REPORT);
75371 +
75372 + // 4. Copy Channel number
75373 + pBeaconReport->Channel = pBss->Channel;
75374 + pBeaconReport->Spare = 0;
75375 + pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;
75376 + pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);
75377 + pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;
75378 + pBeaconReport->BeaconInterval = pBss->BeaconPeriod;
75379 + pBeaconReport->CapabilityInfo = pBss->CapabilityInfo;
75380 + COPY_MAC_ADDR(pBeaconReport->BSSID, pBss->Bssid);
75381 + NdisMoveMemory(pBeaconReport->ParentTSF, pBss->PTSF, 4);
75382 + NdisMoveMemory(pBeaconReport->TargetTSF, pBss->TTSF, 8);
75383 +
75384 + // 5. Create SSID
75385 + *pDest++ = 0x00;
75386 + *pDest++ = pBss->SsidLen;
75387 + NdisMoveMemory(pDest, pBss->Ssid, pBss->SsidLen);
75388 + pDest += pBss->SsidLen;
75389 + Length += (2 + pBss->SsidLen);
75390 +
75391 + // 6. Create SupportRates
75392 + *pDest++ = 0x01;
75393 + *pDest++ = pBss->SupRateLen;
75394 + NdisMoveMemory(pDest, pBss->SupRate, pBss->SupRateLen);
75395 + pDest += pBss->SupRateLen;
75396 + Length += (2 + pBss->SupRateLen);
75397 +
75398 + // 7. DS Parameter
75399 + *pDest++ = 0x03;
75400 + *pDest++ = 1;
75401 + *pDest++ = pBss->Channel;
75402 + Length += 3;
75403 +
75404 + // 8. IBSS parameter if presents
75405 + if (pBss->BssType == BSS_ADHOC)
75406 + {
75407 + *pDest++ = 0x06;
75408 + *pDest++ = 2;
75409 + *(PUSHORT) pDest = pBss->AtimWin;
75410 + pDest += 2;
75411 + Length += 4;
75412 + }
75413 +
75414 + // 9. Update length field, not include EID and length
75415 + pReport->Length = Length - 4;
75416 +
75417 + // 10. Update total frame size
75418 + pAd->StaCfg.FrameReportLen += Length;
75419 + }
75420 +}
75421 --- /dev/null
75422 +++ b/drivers/staging/rt3070/sta/assoc.c
75423 @@ -0,0 +1,2060 @@
75424 +/*
75425 + *************************************************************************
75426 + * Ralink Tech Inc.
75427 + * 5F., No.36, Taiyuan St., Jhubei City,
75428 + * Hsinchu County 302,
75429 + * Taiwan, R.O.C.
75430 + *
75431 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
75432 + *
75433 + * This program is free software; you can redistribute it and/or modify *
75434 + * it under the terms of the GNU General Public License as published by *
75435 + * the Free Software Foundation; either version 2 of the License, or *
75436 + * (at your option) any later version. *
75437 + * *
75438 + * This program is distributed in the hope that it will be useful, *
75439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
75440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
75441 + * GNU General Public License for more details. *
75442 + * *
75443 + * You should have received a copy of the GNU General Public License *
75444 + * along with this program; if not, write to the *
75445 + * Free Software Foundation, Inc., *
75446 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
75447 + * *
75448 + *************************************************************************
75449 +
75450 + Module Name:
75451 + assoc.c
75452 +
75453 + Abstract:
75454 +
75455 + Revision History:
75456 + Who When What
75457 + -------- ---------- ----------------------------------------------
75458 + John 2004-9-3 porting from RT2500
75459 +*/
75460 +#include "../rt_config.h"
75461 +
75462 +UCHAR CipherWpaTemplate[] = {
75463 + 0xdd, // WPA IE
75464 + 0x16, // Length
75465 + 0x00, 0x50, 0xf2, 0x01, // oui
75466 + 0x01, 0x00, // Version
75467 + 0x00, 0x50, 0xf2, 0x02, // Multicast
75468 + 0x01, 0x00, // Number of unicast
75469 + 0x00, 0x50, 0xf2, 0x02, // unicast
75470 + 0x01, 0x00, // number of authentication method
75471 + 0x00, 0x50, 0xf2, 0x01 // authentication
75472 + };
75473 +
75474 +UCHAR CipherWpa2Template[] = {
75475 + 0x30, // RSN IE
75476 + 0x14, // Length
75477 + 0x01, 0x00, // Version
75478 + 0x00, 0x0f, 0xac, 0x02, // group cipher, TKIP
75479 + 0x01, 0x00, // number of pairwise
75480 + 0x00, 0x0f, 0xac, 0x02, // unicast
75481 + 0x01, 0x00, // number of authentication method
75482 + 0x00, 0x0f, 0xac, 0x02, // authentication
75483 + 0x00, 0x00, // RSN capability
75484 + };
75485 +
75486 +UCHAR Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02};
75487 +
75488 +/*
75489 + ==========================================================================
75490 + Description:
75491 + association state machine init, including state transition and timer init
75492 + Parameters:
75493 + S - pointer to the association state machine
75494 +
75495 + IRQL = PASSIVE_LEVEL
75496 +
75497 + ==========================================================================
75498 + */
75499 +VOID AssocStateMachineInit(
75500 + IN PRTMP_ADAPTER pAd,
75501 + IN STATE_MACHINE *S,
75502 + OUT STATE_MACHINE_FUNC Trans[])
75503 +{
75504 + StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, (STATE_MACHINE_FUNC)Drop, ASSOC_IDLE, ASSOC_MACHINE_BASE);
75505 +
75506 + // first column
75507 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)MlmeAssocReqAction);
75508 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)MlmeReassocReqAction);
75509 + StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)MlmeDisassocReqAction);
75510 + StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
75511 +
75512 + // second column
75513 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
75514 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
75515 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
75516 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
75517 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);
75518 + //
75519 + // Patch 3Com AP MOde:3CRWE454G72
75520 + // We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp.
75521 + //
75522 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);
75523 + StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, (STATE_MACHINE_FUNC)AssocTimeoutAction);
75524 +
75525 + // third column
75526 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
75527 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
75528 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
75529 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
75530 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);
75531 + //
75532 + // Patch, AP doesn't send Reassociate Rsp frame to Station.
75533 + //
75534 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);
75535 + StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, (STATE_MACHINE_FUNC)ReassocTimeoutAction);
75536 +
75537 + // fourth column
75538 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);
75539 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);
75540 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);
75541 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);
75542 + StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, (STATE_MACHINE_FUNC)DisassocTimeoutAction);
75543 +
75544 + // initialize the timer
75545 + RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer, GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);
75546 + RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer, GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);
75547 + RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer, GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);
75548 +}
75549 +
75550 +/*
75551 + ==========================================================================
75552 + Description:
75553 + Association timeout procedure. After association timeout, this function
75554 + will be called and it will put a message into the MLME queue
75555 + Parameters:
75556 + Standard timer parameters
75557 +
75558 + IRQL = DISPATCH_LEVEL
75559 +
75560 + ==========================================================================
75561 + */
75562 +VOID AssocTimeout(IN PVOID SystemSpecific1,
75563 + IN PVOID FunctionContext,
75564 + IN PVOID SystemSpecific2,
75565 + IN PVOID SystemSpecific3)
75566 +{
75567 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
75568 +
75569 + // Do nothing if the driver is starting halt state.
75570 + // This might happen when timer already been fired before cancel timer with mlmehalt
75571 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
75572 + return;
75573 +
75574 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);
75575 + RT28XX_MLME_HANDLER(pAd);
75576 +}
75577 +
75578 +/*
75579 + ==========================================================================
75580 + Description:
75581 + Reassociation timeout procedure. After reassociation timeout, this
75582 + function will be called and put a message into the MLME queue
75583 + Parameters:
75584 + Standard timer parameters
75585 +
75586 + IRQL = DISPATCH_LEVEL
75587 +
75588 + ==========================================================================
75589 + */
75590 +VOID ReassocTimeout(IN PVOID SystemSpecific1,
75591 + IN PVOID FunctionContext,
75592 + IN PVOID SystemSpecific2,
75593 + IN PVOID SystemSpecific3)
75594 +{
75595 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
75596 +
75597 + // Do nothing if the driver is starting halt state.
75598 + // This might happen when timer already been fired before cancel timer with mlmehalt
75599 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
75600 + return;
75601 +
75602 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);
75603 + RT28XX_MLME_HANDLER(pAd);
75604 +}
75605 +
75606 +/*
75607 + ==========================================================================
75608 + Description:
75609 + Disassociation timeout procedure. After disassociation timeout, this
75610 + function will be called and put a message into the MLME queue
75611 + Parameters:
75612 + Standard timer parameters
75613 +
75614 + IRQL = DISPATCH_LEVEL
75615 +
75616 + ==========================================================================
75617 + */
75618 +VOID DisassocTimeout(IN PVOID SystemSpecific1,
75619 + IN PVOID FunctionContext,
75620 + IN PVOID SystemSpecific2,
75621 + IN PVOID SystemSpecific3)
75622 +{
75623 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
75624 +
75625 + // Do nothing if the driver is starting halt state.
75626 + // This might happen when timer already been fired before cancel timer with mlmehalt
75627 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
75628 + return;
75629 +
75630 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);
75631 + RT28XX_MLME_HANDLER(pAd);
75632 +}
75633 +
75634 +/*
75635 + ==========================================================================
75636 + Description:
75637 + mlme assoc req handling procedure
75638 + Parameters:
75639 + Adapter - Adapter pointer
75640 + Elem - MLME Queue Element
75641 + Pre:
75642 + the station has been authenticated and the following information is stored in the config
75643 + -# SSID
75644 + -# supported rates and their length
75645 + -# listen interval (Adapter->StaCfg.default_listen_count)
75646 + -# Transmit power (Adapter->StaCfg.tx_power)
75647 + Post :
75648 + -# An association request frame is generated and sent to the air
75649 + -# Association timer starts
75650 + -# Association state -> ASSOC_WAIT_RSP
75651 +
75652 + IRQL = DISPATCH_LEVEL
75653 +
75654 + ==========================================================================
75655 + */
75656 +VOID MlmeAssocReqAction(
75657 + IN PRTMP_ADAPTER pAd,
75658 + IN MLME_QUEUE_ELEM *Elem)
75659 +{
75660 + UCHAR ApAddr[6];
75661 + HEADER_802_11 AssocHdr;
75662 + UCHAR Ccx2Len = 5;
75663 + UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
75664 + USHORT ListenIntv;
75665 + ULONG Timeout;
75666 + USHORT CapabilityInfo;
75667 + BOOLEAN TimerCancelled;
75668 + PUCHAR pOutBuffer = NULL;
75669 + NDIS_STATUS NStatus;
75670 + ULONG FrameLen = 0;
75671 + ULONG tmp;
75672 + USHORT VarIesOffset;
75673 + UCHAR CkipFlag;
75674 + UCHAR CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH];
75675 + UCHAR AironetCkipIe = IE_AIRONET_CKIP;
75676 + UCHAR AironetCkipLen = CKIP_NEGOTIATION_LENGTH;
75677 + UCHAR AironetIPAddressIE = IE_AIRONET_IPADDRESS;
75678 + UCHAR AironetIPAddressLen = AIRONET_IPADDRESS_LENGTH;
75679 + UCHAR AironetIPAddressBuffer[AIRONET_IPADDRESS_LENGTH] = {0x00, 0x40, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
75680 + USHORT Status;
75681 +
75682 + // Block all authentication request durning WPA block period
75683 + if (pAd->StaCfg.bBlockAssoc == TRUE)
75684 + {
75685 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block Assoc request durning WPA block period!\n"));
75686 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75687 + Status = MLME_STATE_MACHINE_REJECT;
75688 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
75689 + }
75690 + // check sanity first
75691 + else if (MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
75692 + {
75693 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
75694 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
75695 +
75696 + // Get an unused nonpaged memory
75697 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
75698 + if (NStatus != NDIS_STATUS_SUCCESS)
75699 + {
75700 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));
75701 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
75702 + Status = MLME_FAIL_NO_RESOURCE;
75703 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
75704 + return;
75705 + }
75706 +
75707 + // Add by James 03/06/27
75708 + pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
75709 + // Association don't need to report MAC address
75710 + pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =
75711 + NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_LISTENINTERVAL;
75712 + pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities = CapabilityInfo;
75713 + pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval = ListenIntv;
75714 + // Only reassociate need this
75715 + //COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr);
75716 + pAd->StaCfg.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
75717 +
75718 + NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);
75719 + // First add SSID
75720 + VarIesOffset = 0;
75721 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe, 1);
75722 + VarIesOffset += 1;
75723 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SsidLen, 1);
75724 + VarIesOffset += 1;
75725 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
75726 + VarIesOffset += pAd->MlmeAux.SsidLen;
75727 +
75728 + // Second add Supported rates
75729 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe, 1);
75730 + VarIesOffset += 1;
75731 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SupRateLen, 1);
75732 + VarIesOffset += 1;
75733 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);
75734 + VarIesOffset += pAd->MlmeAux.SupRateLen;
75735 + // End Add by James
75736 +
75737 + if ((pAd->CommonCfg.Channel > 14) &&
75738 + (pAd->CommonCfg.bIEEE80211H == TRUE))
75739 + CapabilityInfo |= 0x0100;
75740 +
75741 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));
75742 + MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, ApAddr);
75743 +
75744 + // Build basic frame first
75745 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
75746 + sizeof(HEADER_802_11), &AssocHdr,
75747 + 2, &CapabilityInfo,
75748 + 2, &ListenIntv,
75749 + 1, &SsidIe,
75750 + 1, &pAd->MlmeAux.SsidLen,
75751 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
75752 + 1, &SupRateIe,
75753 + 1, &pAd->MlmeAux.SupRateLen,
75754 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
75755 + END_OF_ARGS);
75756 +
75757 + if (pAd->MlmeAux.ExtRateLen != 0)
75758 + {
75759 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75760 + 1, &ExtRateIe,
75761 + 1, &pAd->MlmeAux.ExtRateLen,
75762 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
75763 + END_OF_ARGS);
75764 + FrameLen += tmp;
75765 + }
75766 +
75767 +#ifdef DOT11_N_SUPPORT
75768 + // HT
75769 + if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
75770 + {
75771 + ULONG TmpLen;
75772 + UCHAR HtLen;
75773 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
75774 + if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)
75775 + {
75776 + HtLen = SIZE_HT_CAP_IE + 4;
75777 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
75778 + 1, &WpaIe,
75779 + 1, &HtLen,
75780 + 4, &BROADCOM[0],
75781 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
75782 + END_OF_ARGS);
75783 + }
75784 + else
75785 + {
75786 +#ifdef RT_BIG_ENDIAN
75787 + HT_CAPABILITY_IE HtCapabilityTmp;
75788 +#endif
75789 +
75790 +#ifndef RT_BIG_ENDIAN
75791 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
75792 + 1, &HtCapIe,
75793 + 1, &pAd->MlmeAux.HtCapabilityLen,
75794 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
75795 + END_OF_ARGS);
75796 +#else
75797 + NdisZeroMemory(&HtCapabilityTmp, sizeof(HT_CAPABILITY_IE));
75798 + NdisMoveMemory(&HtCapabilityTmp, &pAd->MlmeAux.HtCapability, pAd->MlmeAux.HtCapabilityLen);
75799 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
75800 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
75801 +
75802 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
75803 + 1, &HtCapIe,
75804 + 1, &pAd->MlmeAux.HtCapabilityLen,
75805 + pAd->MlmeAux.HtCapabilityLen,&HtCapabilityTmp,
75806 + END_OF_ARGS);
75807 +#endif
75808 + }
75809 + FrameLen += TmpLen;
75810 + }
75811 +#endif // DOT11_N_SUPPORT //
75812 +
75813 + // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION
75814 + // Case I: (Aggregation + Piggy-Back)
75815 + // 1. user enable aggregation, AND
75816 + // 2. Mac support piggy-back
75817 + // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON
75818 + // Case II: (Aggregation)
75819 + // 1. user enable aggregation, AND
75820 + // 2. AP annouces it's AGGREGATION-capable in BEACON
75821 + if (pAd->CommonCfg.bAggregationCapable)
75822 + {
75823 + if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))
75824 + {
75825 + ULONG TmpLen;
75826 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};
75827 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75828 + 9, RalinkIe,
75829 + END_OF_ARGS);
75830 + FrameLen += TmpLen;
75831 + }
75832 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
75833 + {
75834 + ULONG TmpLen;
75835 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
75836 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75837 + 9, RalinkIe,
75838 + END_OF_ARGS);
75839 + FrameLen += TmpLen;
75840 + }
75841 + }
75842 + else
75843 + {
75844 + ULONG TmpLen;
75845 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06, 0x00, 0x00, 0x00};
75846 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
75847 + 9, RalinkIe,
75848 + END_OF_ARGS);
75849 + FrameLen += TmpLen;
75850 + }
75851 +
75852 + if (pAd->MlmeAux.APEdcaParm.bValid)
75853 + {
75854 + if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)
75855 + {
75856 + QBSS_STA_INFO_PARM QosInfo;
75857 +
75858 + NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));
75859 + QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
75860 + QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
75861 + QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
75862 + QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
75863 + QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;
75864 + WmeIe[8] |= *(PUCHAR)&QosInfo;
75865 + }
75866 + else
75867 + {
75868 + // The Parameter Set Count is set to ¡§0¡¨ in the association request frames
75869 + // WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f);
75870 + }
75871 +
75872 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75873 + 9, &WmeIe[0],
75874 + END_OF_ARGS);
75875 + FrameLen += tmp;
75876 + }
75877 +
75878 + //
75879 + // Let WPA(#221) Element ID on the end of this association frame.
75880 + // Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp.
75881 + // For example: Put Vendor Specific IE on the front of WPA IE.
75882 + // This happens on AP (Model No:Linksys WRK54G)
75883 + //
75884 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
75885 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
75886 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
75887 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
75888 + )
75889 + )
75890 + {
75891 + UCHAR RSNIe = IE_WPA;
75892 +
75893 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
75894 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
75895 + {
75896 + RSNIe = IE_WPA2;
75897 + }
75898 +
75899 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
75900 +#ifdef SIOCSIWGENIE
75901 + if (pAd->StaCfg.WpaSupplicantUP != 1)
75902 +#endif // SIOCSIWGENIE //
75903 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75904 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
75905 +
75906 + // Check for WPA PMK cache list
75907 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
75908 + {
75909 + INT idx;
75910 + BOOLEAN FoundPMK = FALSE;
75911 + // Search chched PMKID, append it if existed
75912 + for (idx = 0; idx < PMKID_NO; idx++)
75913 + {
75914 + if (NdisEqualMemory(ApAddr, &pAd->StaCfg.SavedPMK[idx].BSSID, 6))
75915 + {
75916 + FoundPMK = TRUE;
75917 + break;
75918 + }
75919 + }
75920 +
75921 + if (FoundPMK)
75922 + {
75923 + // Set PMK number
75924 + *(PUSHORT) &pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len] = 1;
75925 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len + 2], &pAd->StaCfg.SavedPMK[idx].PMKID, 16);
75926 + pAd->StaCfg.RSNIE_Len += 18;
75927 + }
75928 + }
75929 +
75930 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
75931 +#ifdef SIOCSIWGENIE
75932 + if (pAd->StaCfg.WpaSupplicantUP == 1)
75933 + {
75934 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75935 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
75936 + END_OF_ARGS);
75937 + }
75938 + else
75939 +#endif
75940 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75941 + {
75942 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75943 + 1, &RSNIe,
75944 + 1, &pAd->StaCfg.RSNIE_Len,
75945 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
75946 + END_OF_ARGS);
75947 + }
75948 +
75949 + FrameLen += tmp;
75950 +
75951 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
75952 +#ifdef SIOCSIWGENIE
75953 + if (pAd->StaCfg.WpaSupplicantUP != 1)
75954 +#endif
75955 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
75956 + {
75957 + // Append Variable IE
75958 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &RSNIe, 1);
75959 + VarIesOffset += 1;
75960 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->StaCfg.RSNIE_Len, 1);
75961 + VarIesOffset += 1;
75962 + }
75963 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
75964 + VarIesOffset += pAd->StaCfg.RSNIE_Len;
75965 +
75966 + // Set Variable IEs Length
75967 + pAd->StaCfg.ReqVarIELen = VarIesOffset;
75968 + }
75969 +
75970 + // We have update that at PeerBeaconAtJoinRequest()
75971 + CkipFlag = pAd->StaCfg.CkipFlag;
75972 + if (CkipFlag != 0)
75973 + {
75974 + NdisZeroMemory(CkipNegotiationBuffer, CKIP_NEGOTIATION_LENGTH);
75975 + CkipNegotiationBuffer[2] = 0x66;
75976 + // Make it try KP & MIC, since we have to follow the result from AssocRsp
75977 + CkipNegotiationBuffer[8] = 0x18;
75978 + CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH - 1] = 0x22;
75979 + CkipFlag = 0x18;
75980 +
75981 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75982 + 1, &AironetCkipIe,
75983 + 1, &AironetCkipLen,
75984 + AironetCkipLen, CkipNegotiationBuffer,
75985 + END_OF_ARGS);
75986 + FrameLen += tmp;
75987 + }
75988 +
75989 + // Add CCX v2 request if CCX2 admin state is on
75990 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
75991 + {
75992 +
75993 + //
75994 + // Add AironetIPAddressIE for Cisco CCX 2.X
75995 + // Add CCX Version
75996 + //
75997 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
75998 + 1, &AironetIPAddressIE,
75999 + 1, &AironetIPAddressLen,
76000 + AironetIPAddressLen, AironetIPAddressBuffer,
76001 + 1, &Ccx2Ie,
76002 + 1, &Ccx2Len,
76003 + Ccx2Len, Ccx2IeInfo,
76004 + END_OF_ARGS);
76005 + FrameLen += tmp;
76006 +
76007 + //
76008 + // Add CipherSuite CCKM or LeapTkip if setting.
76009 + //
76010 +#ifdef LEAP_SUPPORT
76011 + if (LEAP_CCKM_ON(pAd))
76012 + {
76013 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76014 + CipherSuiteCiscoCCKMLen, CipherSuiteCiscoCCKM,
76015 + END_OF_ARGS);
76016 + FrameLen += tmp;
76017 +
76018 + // Third add RSN
76019 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, CipherSuiteCiscoCCKM, CipherSuiteCiscoCCKMLen); //Save CipherSuite
76020 + VarIesOffset += CipherSuiteCiscoCCKMLen;
76021 + }
76022 + else if ((pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP) && (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled))
76023 + {
76024 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76025 + CipherSuiteCCXTkipLen, CipherSuiteCCXTkip,
76026 + END_OF_ARGS);
76027 + FrameLen += tmp;
76028 +
76029 + // Third add RSN
76030 + NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, CipherSuiteCCXTkip, CipherSuiteCCXTkipLen);
76031 + VarIesOffset += CipherSuiteCCXTkipLen;
76032 + }
76033 +#endif // LEAP_SUPPORT //
76034 +
76035 + // Add by James 03/06/27
76036 + // Set Variable IEs Length
76037 + pAd->StaCfg.ReqVarIELen = VarIesOffset;
76038 + pAd->StaCfg.AssocInfo.RequestIELength = VarIesOffset;
76039 +
76040 + // OffsetResponseIEs follow ReqVarIE
76041 + pAd->StaCfg.AssocInfo.OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAd->StaCfg.ReqVarIELen;
76042 + // End Add by James
76043 + }
76044 +
76045 +
76046 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76047 + MlmeFreeMemory(pAd, pOutBuffer);
76048 +
76049 + RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout);
76050 + pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;
76051 + }
76052 + else
76053 + {
76054 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!!!!!! \n"));
76055 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76056 + Status = MLME_INVALID_FORMAT;
76057 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76058 + }
76059 +
76060 +}
76061 +
76062 +/*
76063 + ==========================================================================
76064 + Description:
76065 + mlme reassoc req handling procedure
76066 + Parameters:
76067 + Elem -
76068 + Pre:
76069 + -# SSID (Adapter->StaCfg.ssid[])
76070 + -# BSSID (AP address, Adapter->StaCfg.bssid)
76071 + -# Supported rates (Adapter->StaCfg.supported_rates[])
76072 + -# Supported rates length (Adapter->StaCfg.supported_rates_len)
76073 + -# Tx power (Adapter->StaCfg.tx_power)
76074 +
76075 + IRQL = DISPATCH_LEVEL
76076 +
76077 + ==========================================================================
76078 + */
76079 +VOID MlmeReassocReqAction(
76080 + IN PRTMP_ADAPTER pAd,
76081 + IN MLME_QUEUE_ELEM *Elem)
76082 +{
76083 + UCHAR ApAddr[6];
76084 + HEADER_802_11 ReassocHdr;
76085 + UCHAR Ccx2Len = 5;
76086 + UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
76087 + USHORT CapabilityInfo, ListenIntv;
76088 + ULONG Timeout;
76089 + ULONG FrameLen = 0;
76090 + BOOLEAN TimerCancelled;
76091 + NDIS_STATUS NStatus;
76092 + ULONG tmp;
76093 + PUCHAR pOutBuffer = NULL;
76094 +//CCX 2.X
76095 +#ifdef LEAP_SUPPORT
76096 + UCHAR CkipFlag;
76097 + UCHAR CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH];
76098 + UCHAR AironetCkipIe = IE_AIRONET_CKIP;
76099 + UCHAR AironetCkipLen = CKIP_NEGOTIATION_LENGTH;
76100 + UCHAR AironetIPAddressIE = IE_AIRONET_IPADDRESS;
76101 + UCHAR AironetIPAddressLen = AIRONET_IPADDRESS_LENGTH;
76102 + UCHAR AironetIPAddressBuffer[AIRONET_IPADDRESS_LENGTH] = {0x00, 0x40, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};
76103 + UCHAR AironetCCKMReassocIE = IE_AIRONET_CCKMREASSOC;
76104 + UCHAR AironetCCKMReassocLen = AIRONET_CCKMREASSOC_LENGTH;
76105 + UCHAR AironetCCKMReassocBuffer[AIRONET_CCKMREASSOC_LENGTH];
76106 + UCHAR AironetOUI[] = {0x00, 0x40, 0x96, 0x00};
76107 + UCHAR MICMN[16];
76108 + UCHAR CalcMicBuffer[80];
76109 + ULONG CalcMicBufferLen = 0;
76110 +#endif // LEAP_SUPPORT //
76111 + USHORT Status;
76112 +
76113 + // Block all authentication request durning WPA block period
76114 + if (pAd->StaCfg.bBlockAssoc == TRUE)
76115 + {
76116 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block ReAssoc request durning WPA block period!\n"));
76117 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76118 + Status = MLME_STATE_MACHINE_REJECT;
76119 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76120 + }
76121 + // the parameters are the same as the association
76122 + else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
76123 + {
76124 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
76125 +
76126 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
76127 + if(NStatus != NDIS_STATUS_SUCCESS)
76128 + {
76129 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() allocate memory failed \n"));
76130 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76131 + Status = MLME_FAIL_NO_RESOURCE;
76132 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76133 + return;
76134 + }
76135 +
76136 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
76137 +
76138 + // make frame, use bssid as the AP address??
76139 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send RE-ASSOC request...\n"));
76140 + MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0, ApAddr, ApAddr);
76141 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76142 + sizeof(HEADER_802_11), &ReassocHdr,
76143 + 2, &CapabilityInfo,
76144 + 2, &ListenIntv,
76145 + MAC_ADDR_LEN, ApAddr,
76146 + 1, &SsidIe,
76147 + 1, &pAd->MlmeAux.SsidLen,
76148 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
76149 + 1, &SupRateIe,
76150 + 1, &pAd->MlmeAux.SupRateLen,
76151 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
76152 + END_OF_ARGS);
76153 +
76154 + if (pAd->MlmeAux.ExtRateLen != 0)
76155 + {
76156 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76157 + 1, &ExtRateIe,
76158 + 1, &pAd->MlmeAux.ExtRateLen,
76159 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
76160 + END_OF_ARGS);
76161 + FrameLen += tmp;
76162 + }
76163 +
76164 + if (pAd->MlmeAux.APEdcaParm.bValid)
76165 + {
76166 + if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)
76167 + {
76168 + QBSS_STA_INFO_PARM QosInfo;
76169 +
76170 + NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));
76171 + QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
76172 + QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
76173 + QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
76174 + QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
76175 + QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;
76176 + WmeIe[8] |= *(PUCHAR)&QosInfo;
76177 + }
76178 +
76179 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76180 + 9, &WmeIe[0],
76181 + END_OF_ARGS);
76182 + FrameLen += tmp;
76183 + }
76184 +
76185 +#ifdef DOT11_N_SUPPORT
76186 + // HT
76187 + if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
76188 + {
76189 + ULONG TmpLen;
76190 + UCHAR HtLen;
76191 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
76192 + if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)
76193 + {
76194 + HtLen = SIZE_HT_CAP_IE + 4;
76195 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
76196 + 1, &WpaIe,
76197 + 1, &HtLen,
76198 + 4, &BROADCOM[0],
76199 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
76200 + END_OF_ARGS);
76201 + }
76202 + else
76203 + {
76204 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
76205 + 1, &HtCapIe,
76206 + 1, &pAd->MlmeAux.HtCapabilityLen,
76207 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
76208 + END_OF_ARGS);
76209 + }
76210 + FrameLen += TmpLen;
76211 + }
76212 +#endif // DOT11_N_SUPPORT //
76213 +
76214 + // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION
76215 + // Case I: (Aggregation + Piggy-Back)
76216 + // 1. user enable aggregation, AND
76217 + // 2. Mac support piggy-back
76218 + // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON
76219 + // Case II: (Aggregation)
76220 + // 1. user enable aggregation, AND
76221 + // 2. AP annouces it's AGGREGATION-capable in BEACON
76222 + if (pAd->CommonCfg.bAggregationCapable)
76223 + {
76224 + if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))
76225 + {
76226 + ULONG TmpLen;
76227 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};
76228 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
76229 + 9, RalinkIe,
76230 + END_OF_ARGS);
76231 + FrameLen += TmpLen;
76232 + }
76233 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
76234 + {
76235 + ULONG TmpLen;
76236 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
76237 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
76238 + 9, RalinkIe,
76239 + END_OF_ARGS);
76240 + FrameLen += TmpLen;
76241 + }
76242 + }
76243 + else
76244 + {
76245 + ULONG TmpLen;
76246 + UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04, 0x00, 0x00, 0x00};
76247 + MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
76248 + 9, RalinkIe,
76249 + END_OF_ARGS);
76250 + FrameLen += TmpLen;
76251 + }
76252 +#ifdef LEAP_SUPPORT
76253 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
76254 + {
76255 + CkipFlag = pAd->StaCfg.CkipFlag; // We have update that at PeerBeaconAtJoinRequest()
76256 + if (CkipFlag != 0)
76257 + {
76258 + NdisZeroMemory(CkipNegotiationBuffer, CKIP_NEGOTIATION_LENGTH);
76259 + CkipNegotiationBuffer[2] = 0x66;
76260 + // Make it try KP & MIC, since we have to follow the result from AssocRsp
76261 + CkipNegotiationBuffer[8] = 0x18;
76262 + CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH - 1] = 0x22;
76263 +
76264 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76265 + 1, &AironetCkipIe,
76266 + 1, &AironetCkipLen,
76267 + AironetCkipLen, CkipNegotiationBuffer,
76268 + END_OF_ARGS);
76269 + FrameLen += tmp;
76270 + }
76271 +
76272 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76273 + 1, &AironetIPAddressIE,
76274 + 1, &AironetIPAddressLen,
76275 + AironetIPAddressLen, AironetIPAddressBuffer,
76276 + END_OF_ARGS);
76277 + FrameLen += tmp;
76278 +
76279 + //
76280 + // The RN is incremented before each reassociation request.
76281 + //
76282 + pAd->StaCfg.CCKMRN++;
76283 + //
76284 + // Calculate MIC = hmac-md5(krk, STA-ID|BSSID|RSNIE|TSF|RN);
76285 + //
76286 + COPY_MAC_ADDR(CalcMicBuffer, pAd->CurrentAddress);
76287 + CalcMicBufferLen = MAC_ADDR_LEN;
76288 + COPY_MAC_ADDR(CalcMicBuffer + CalcMicBufferLen, pAd->MlmeAux.Bssid);
76289 + CalcMicBufferLen += MAC_ADDR_LEN;
76290 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, CipherSuiteCiscoCCKM, CipherSuiteCiscoCCKMLen);
76291 + CalcMicBufferLen += CipherSuiteCiscoCCKMLen;
76292 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, (PUCHAR) &pAd->StaCfg.CCKMBeaconAtJoinTimeStamp, sizeof(pAd->StaCfg.CCKMBeaconAtJoinTimeStamp));
76293 + CalcMicBufferLen += sizeof(pAd->StaCfg.CCKMBeaconAtJoinTimeStamp);
76294 + NdisMoveMemory(CalcMicBuffer + CalcMicBufferLen, (PUCHAR)&pAd->StaCfg.CCKMRN, sizeof(pAd->StaCfg.CCKMRN));
76295 + CalcMicBufferLen += sizeof(pAd->StaCfg.CCKMRN);
76296 + hmac_md5(pAd->StaCfg.KRK, LEN_EAP_MICK, CalcMicBuffer, CalcMicBufferLen, MICMN);
76297 +
76298 + //
76299 + // fill up CCKM reassociation request element
76300 + //
76301 + NdisMoveMemory(AironetCCKMReassocBuffer, AironetOUI, 4);
76302 + NdisMoveMemory(AironetCCKMReassocBuffer + 4, (PUCHAR)&pAd->StaCfg.CCKMBeaconAtJoinTimeStamp, 8);
76303 + NdisMoveMemory(AironetCCKMReassocBuffer + 12, (PUCHAR) &pAd->StaCfg.CCKMRN, 4);
76304 + NdisMoveMemory(AironetCCKMReassocBuffer +16, MICMN, 8);
76305 +
76306 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76307 + 1, &AironetCCKMReassocIE,
76308 + 1, &AironetCCKMReassocLen,
76309 + AironetCCKMReassocLen, AironetCCKMReassocBuffer,
76310 + END_OF_ARGS);
76311 + FrameLen += tmp;
76312 +
76313 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76314 + CipherSuiteCiscoCCKMLen,CipherSuiteCiscoCCKM,
76315 + END_OF_ARGS);
76316 + FrameLen += tmp;
76317 + }
76318 +#endif // LEAP_SUPPORT //
76319 +
76320 + // Add CCX v2 request if CCX2 admin state is on
76321 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
76322 + {
76323 + //
76324 + // Add CCX Version
76325 + //
76326 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
76327 + 1, &Ccx2Ie,
76328 + 1, &Ccx2Len,
76329 + Ccx2Len, Ccx2IeInfo,
76330 + END_OF_ARGS);
76331 + FrameLen += tmp;
76332 + }
76333 +
76334 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76335 + MlmeFreeMemory(pAd, pOutBuffer);
76336 +
76337 + RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */
76338 + pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;
76339 + }
76340 + else
76341 + {
76342 + DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!!!! \n"));
76343 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76344 + Status = MLME_INVALID_FORMAT;
76345 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76346 + }
76347 +}
76348 +
76349 +/*
76350 + ==========================================================================
76351 + Description:
76352 + Upper layer issues disassoc request
76353 + Parameters:
76354 + Elem -
76355 +
76356 + IRQL = PASSIVE_LEVEL
76357 +
76358 + ==========================================================================
76359 + */
76360 +VOID MlmeDisassocReqAction(
76361 + IN PRTMP_ADAPTER pAd,
76362 + IN MLME_QUEUE_ELEM *Elem)
76363 +{
76364 + PMLME_DISASSOC_REQ_STRUCT pDisassocReq;
76365 + HEADER_802_11 DisassocHdr;
76366 + PHEADER_802_11 pDisassocHdr;
76367 + PUCHAR pOutBuffer = NULL;
76368 + ULONG FrameLen = 0;
76369 + NDIS_STATUS NStatus;
76370 + BOOLEAN TimerCancelled;
76371 + ULONG Timeout = 0;
76372 + USHORT Status;
76373 +
76374 +#ifdef QOS_DLS_SUPPORT
76375 + // send DLS-TEAR_DOWN message,
76376 + if (pAd->CommonCfg.bDLSCapable)
76377 + {
76378 + UCHAR i;
76379 +
76380 + // tear down local dls table entry
76381 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
76382 + {
76383 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
76384 + {
76385 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
76386 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
76387 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
76388 + }
76389 + }
76390 +
76391 + // tear down peer dls table entry
76392 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
76393 + {
76394 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
76395 + {
76396 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
76397 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
76398 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
76399 + }
76400 + }
76401 + }
76402 +#endif // QOS_DLS_SUPPORT //
76403 +
76404 + // skip sanity check
76405 + pDisassocReq = (PMLME_DISASSOC_REQ_STRUCT)(Elem->Msg);
76406 +
76407 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
76408 + if (NStatus != NDIS_STATUS_SUCCESS)
76409 + {
76410 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n"));
76411 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76412 + Status = MLME_FAIL_NO_RESOURCE;
76413 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
76414 + return;
76415 + }
76416 +
76417 +
76418 +
76419 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled);
76420 +
76421 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send DISASSOC request[BSSID::%02x:%02x:%02x:%02x:%02x:%02x (Reason=%d)\n",
76422 + pDisassocReq->Addr[0], pDisassocReq->Addr[1], pDisassocReq->Addr[2],
76423 + pDisassocReq->Addr[3], pDisassocReq->Addr[4], pDisassocReq->Addr[5], pDisassocReq->Reason));
76424 + MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); // patch peap ttls switching issue
76425 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
76426 + sizeof(HEADER_802_11),&DisassocHdr,
76427 + 2, &pDisassocReq->Reason,
76428 + END_OF_ARGS);
76429 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76430 +
76431 + // To patch Instance and Buffalo(N) AP
76432 + // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine
76433 + // Therefore, we send both of them.
76434 + pDisassocHdr = (PHEADER_802_11)pOutBuffer;
76435 + pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
76436 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
76437 +
76438 + MlmeFreeMemory(pAd, pOutBuffer);
76439 +
76440 + pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;
76441 + COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr);
76442 +
76443 + RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */
76444 + pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;
76445 +
76446 +#ifdef WPA_SUPPLICANT_SUPPORT
76447 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
76448 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
76449 + {
76450 + union iwreq_data wrqu;
76451 + //send disassociate event to wpa_supplicant
76452 + memset(&wrqu, 0, sizeof(wrqu));
76453 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
76454 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
76455 + }
76456 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76457 +#endif // WPA_SUPPLICANT_SUPPORT //
76458 +
76459 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76460 + {
76461 + union iwreq_data wrqu;
76462 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
76463 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
76464 + }
76465 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76466 +
76467 +}
76468 +
76469 +/*
76470 + ==========================================================================
76471 + Description:
76472 + peer sends assoc rsp back
76473 + Parameters:
76474 + Elme - MLME message containing the received frame
76475 +
76476 + IRQL = DISPATCH_LEVEL
76477 +
76478 + ==========================================================================
76479 + */
76480 +VOID PeerAssocRspAction(
76481 + IN PRTMP_ADAPTER pAd,
76482 + IN MLME_QUEUE_ELEM *Elem)
76483 +{
76484 + USHORT CapabilityInfo, Status, Aid;
76485 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
76486 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
76487 + UCHAR Addr2[MAC_ADDR_LEN];
76488 + BOOLEAN TimerCancelled;
76489 + UCHAR CkipFlag;
76490 + EDCA_PARM EdcaParm;
76491 + HT_CAPABILITY_IE HtCapability;
76492 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
76493 + UCHAR HtCapabilityLen;
76494 + UCHAR AddHtInfoLen;
76495 + UCHAR NewExtChannelOffset = 0xff;
76496 +
76497 + if (PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,
76498 + &HtCapability,&AddHtInfo, &HtCapabilityLen,&AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))
76499 + {
76500 + // The frame is for me ?
76501 + if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid))
76502 + {
76503 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n", Status));
76504 +#ifdef DOT11_N_SUPPORT
76505 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspAction():MacTable [%d].AMsduSize = %d. ClientStatusFlags = 0x%lx \n",Elem->Wcid, pAd->MacTab.Content[BSSID_WCID].AMsduSize, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
76506 +#endif // DOT11_N_SUPPORT //
76507 + RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
76508 + if(Status == MLME_SUCCESS)
76509 + {
76510 + UCHAR MaxSupportedRateIn500Kbps = 0;
76511 + UCHAR idx;
76512 +
76513 + // supported rates array may not be sorted. sort it and find the maximum rate
76514 + for (idx=0; idx<SupRateLen; idx++)
76515 + {
76516 + if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))
76517 + MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;
76518 + }
76519 +
76520 + for (idx=0; idx<ExtRateLen; idx++)
76521 + {
76522 + if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))
76523 + MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;
76524 + }
76525 + // go to procedure listed on page 376
76526 + AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,
76527 + &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);
76528 +
76529 + StaAddMacTableEntry(pAd, &pAd->MacTab.Content[BSSID_WCID], MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo);
76530 +
76531 + pAd->StaCfg.CkipFlag = CkipFlag;
76532 + if (CkipFlag & 0x18)
76533 + {
76534 + NdisZeroMemory(pAd->StaCfg.TxSEQ, 4);
76535 + NdisZeroMemory(pAd->StaCfg.RxSEQ, 4);
76536 + NdisZeroMemory(pAd->StaCfg.CKIPMIC, 4);
76537 + pAd->StaCfg.GIV[0] = RandomByte(pAd);
76538 + pAd->StaCfg.GIV[1] = RandomByte(pAd);
76539 + pAd->StaCfg.GIV[2] = RandomByte(pAd);
76540 + pAd->StaCfg.bCkipOn = TRUE;
76541 + DBGPRINT(RT_DEBUG_TRACE, ("<CCX> pAd->StaCfg.CkipFlag = 0x%02x\n", pAd->StaCfg.CkipFlag));
76542 + }
76543 + }
76544 + else
76545 + {
76546 + // Faile on Association, we need to check the status code
76547 + // Is that a Rogue AP?
76548 +#ifdef LEAP_SUPPORT
76549 + if ((pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP) && (Status == MLME_ALG_NOT_SUPPORT))
76550 + { //Possibly Rogue AP
76551 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, pAd->MlmeAux.Bssid, LEAP_REASON_INVALID_AUTH);
76552 + }
76553 +#endif // LEAP_SUPPORT //
76554 + }
76555 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76556 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76557 + }
76558 + }
76559 + else
76560 + {
76561 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerAssocRspAction() sanity check fail\n"));
76562 + }
76563 +}
76564 +
76565 +/*
76566 + ==========================================================================
76567 + Description:
76568 + peer sends reassoc rsp
76569 + Parametrs:
76570 + Elem - MLME message cntaining the received frame
76571 +
76572 + IRQL = DISPATCH_LEVEL
76573 +
76574 + ==========================================================================
76575 + */
76576 +VOID PeerReassocRspAction(
76577 + IN PRTMP_ADAPTER pAd,
76578 + IN MLME_QUEUE_ELEM *Elem)
76579 +{
76580 + USHORT CapabilityInfo;
76581 + USHORT Status;
76582 + USHORT Aid;
76583 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
76584 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
76585 + UCHAR Addr2[MAC_ADDR_LEN];
76586 + UCHAR CkipFlag;
76587 + BOOLEAN TimerCancelled;
76588 + EDCA_PARM EdcaParm;
76589 + HT_CAPABILITY_IE HtCapability;
76590 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
76591 + UCHAR HtCapabilityLen;
76592 + UCHAR AddHtInfoLen;
76593 + UCHAR NewExtChannelOffset = 0xff;
76594 +
76595 + if(PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,
76596 + &HtCapability, &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))
76597 + {
76598 + if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) // The frame is for me ?
76599 + {
76600 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - receive REASSOC_RSP to me (status=%d)\n", Status));
76601 + RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
76602 +
76603 + if(Status == MLME_SUCCESS)
76604 + {
76605 + // go to procedure listed on page 376
76606 + AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,
76607 + &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);
76608 +
76609 +#ifdef WPA_SUPPLICANT_SUPPORT
76610 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
76611 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
76612 + {
76613 + union iwreq_data wrqu;
76614 +
76615 + SendAssocIEsToWpaSupplicant(pAd);
76616 + memset(&wrqu, 0, sizeof(wrqu));
76617 + wrqu.data.flags = RT_ASSOC_EVENT_FLAG;
76618 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
76619 + }
76620 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76621 +#endif // WPA_SUPPLICANT_SUPPORT //
76622 +
76623 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76624 + {
76625 + union iwreq_data wrqu;
76626 + wext_notify_event_assoc(pAd);
76627 +
76628 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
76629 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
76630 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
76631 +
76632 + }
76633 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76634 +
76635 + }
76636 +
76637 + //
76638 + // Cisco Leap CCKM supported Re-association.
76639 + //
76640 +#ifdef LEAP_SUPPORT
76641 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
76642 + {
76643 + if (CCKMAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen) == TRUE)
76644 + {
76645 + pAd->StaCfg.CkipFlag = CkipFlag;
76646 + if (CkipFlag & 0x18)
76647 + {
76648 + NdisZeroMemory(pAd->StaCfg.TxSEQ, 4);
76649 + NdisZeroMemory(pAd->StaCfg.RxSEQ, 4);
76650 + NdisZeroMemory(pAd->StaCfg.CKIPMIC, 4);
76651 + pAd->StaCfg.GIV[0] = RandomByte(pAd);
76652 + pAd->StaCfg.GIV[1] = RandomByte(pAd);
76653 + pAd->StaCfg.GIV[2] = RandomByte(pAd);
76654 + pAd->StaCfg.bCkipOn = TRUE;
76655 + DBGPRINT(RT_DEBUG_TRACE, ("<CCX> pAd->StaCfg.CkipFlag = 0x%02x\n", pAd->StaCfg.CkipFlag));
76656 + }
76657 +
76658 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76659 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76660 + }
76661 + else
76662 + {
76663 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - CCKMAssocRspSanity() sanity check fail\n"));
76664 + }
76665 + }
76666 + else
76667 +#endif // LEAP_SUPPORT //
76668 + {
76669 + // CkipFlag is no use for reassociate
76670 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76671 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76672 + }
76673 + }
76674 + }
76675 + else
76676 + {
76677 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerReassocRspAction() sanity check fail\n"));
76678 + }
76679 +
76680 +}
76681 +
76682 +/*
76683 + ==========================================================================
76684 + Description:
76685 + procedures on IEEE 802.11/1999 p.376
76686 + Parametrs:
76687 +
76688 + IRQL = DISPATCH_LEVEL
76689 +
76690 + ==========================================================================
76691 + */
76692 +VOID AssocPostProc(
76693 + IN PRTMP_ADAPTER pAd,
76694 + IN PUCHAR pAddr2,
76695 + IN USHORT CapabilityInfo,
76696 + IN USHORT Aid,
76697 + IN UCHAR SupRate[],
76698 + IN UCHAR SupRateLen,
76699 + IN UCHAR ExtRate[],
76700 + IN UCHAR ExtRateLen,
76701 + IN PEDCA_PARM pEdcaParm,
76702 + IN HT_CAPABILITY_IE *pHtCapability,
76703 + IN UCHAR HtCapabilityLen,
76704 + IN ADD_HT_INFO_IE *pAddHtInfo) // AP might use this additional ht info IE
76705 +{
76706 + ULONG Idx;
76707 +
76708 + pAd->MlmeAux.BssType = BSS_INFRA;
76709 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2);
76710 + pAd->MlmeAux.Aid = Aid;
76711 + pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
76712 +#ifdef DOT11_N_SUPPORT
76713 + // Some HT AP might lost WMM IE. We add WMM ourselves. beacuase HT requires QoS on.
76714 + if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE))
76715 + {
76716 + pEdcaParm->bValid = TRUE;
76717 + pEdcaParm->Aifsn[0] = 3;
76718 + pEdcaParm->Aifsn[1] = 7;
76719 + pEdcaParm->Aifsn[2] = 2;
76720 + pEdcaParm->Aifsn[3] = 2;
76721 +
76722 + pEdcaParm->Cwmin[0] = 4;
76723 + pEdcaParm->Cwmin[1] = 4;
76724 + pEdcaParm->Cwmin[2] = 3;
76725 + pEdcaParm->Cwmin[3] = 2;
76726 +
76727 + pEdcaParm->Cwmax[0] = 10;
76728 + pEdcaParm->Cwmax[1] = 10;
76729 + pEdcaParm->Cwmax[2] = 4;
76730 + pEdcaParm->Cwmax[3] = 3;
76731 +
76732 + pEdcaParm->Txop[0] = 0;
76733 + pEdcaParm->Txop[1] = 0;
76734 + pEdcaParm->Txop[2] = 96;
76735 + pEdcaParm->Txop[3] = 48;
76736 +
76737 + }
76738 +#endif // DOT11_N_SUPPORT //
76739 +
76740 + NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM));
76741 +
76742 + // filter out un-supported rates
76743 + pAd->MlmeAux.SupRateLen = SupRateLen;
76744 + NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
76745 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
76746 +
76747 + // filter out un-supported rates
76748 + pAd->MlmeAux.ExtRateLen = ExtRateLen;
76749 + NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
76750 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
76751 +
76752 +#ifdef DOT11_N_SUPPORT
76753 + if (HtCapabilityLen > 0)
76754 + {
76755 + RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo);
76756 + }
76757 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n", pAd->MacTab.Content[BSSID_WCID].AMsduSize, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
76758 +
76759 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n",
76760 + pAd->MacTab.Content[BSSID_WCID].MmpsMode, pAd->MacTab.Content[BSSID_WCID].AMsduSize));
76761 +#endif // DOT11_N_SUPPORT //
76762 +
76763 + // Set New WPA information
76764 + Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);
76765 + if (Idx == BSS_NOT_FOUND)
76766 + {
76767 + DBGPRINT_ERR(("ASSOC - Can't find BSS after receiving Assoc response\n"));
76768 + }
76769 + else
76770 + {
76771 + // Init variable
76772 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;
76773 + NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, MAX_LEN_OF_RSNIE);
76774 +
76775 + // Store appropriate RSN_IE for WPA SM negotiation later
76776 + if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0))
76777 + {
76778 + PUCHAR pVIE;
76779 + USHORT len;
76780 + PEID_STRUCT pEid;
76781 +
76782 + pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs;
76783 + len = pAd->ScanTab.BssEntry[Idx].VarIELen;
76784 +
76785 + while (len > 0)
76786 + {
76787 + pEid = (PEID_STRUCT) pVIE;
76788 + // For WPA/WPAPSK
76789 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
76790 + && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
76791 + {
76792 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));
76793 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);
76794 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n"));
76795 + }
76796 + // For WPA2/WPA2PSK
76797 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))
76798 + && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
76799 + {
76800 + NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));
76801 + pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);
76802 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n"));
76803 + }
76804 +
76805 + pVIE += (pEid->Len + 2);
76806 + len -= (pEid->Len + 2);
76807 + }
76808 + }
76809 +
76810 + if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0)
76811 + {
76812 + DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> no RSN_IE \n"));
76813 + }
76814 + else
76815 + {
76816 + hex_dump("RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
76817 + }
76818 + }
76819 +}
76820 +
76821 +/*
76822 + ==========================================================================
76823 + Description:
76824 + left part of IEEE 802.11/1999 p.374
76825 + Parameters:
76826 + Elem - MLME message containing the received frame
76827 +
76828 + IRQL = DISPATCH_LEVEL
76829 +
76830 + ==========================================================================
76831 + */
76832 +VOID PeerDisassocAction(
76833 + IN PRTMP_ADAPTER pAd,
76834 + IN MLME_QUEUE_ELEM *Elem)
76835 +{
76836 + UCHAR Addr2[MAC_ADDR_LEN];
76837 + USHORT Reason;
76838 +
76839 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n"));
76840 + if(PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))
76841 + {
76842 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() Reason = %d\n", Reason));
76843 + if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2))
76844 + {
76845 +
76846 + if (pAd->CommonCfg.bWirelessEvent)
76847 + {
76848 + RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
76849 + }
76850 +
76851 +
76852 +#ifdef LEAP_SUPPORT
76853 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
76854 + {
76855 + // Cisco_LEAP has start a timer
76856 + // We should cancel it if using LEAP
76857 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &TimerCancelled);
76858 + //Check is it mach the LEAP Authentication failed as possible a Rogue AP
76859 + //on it's PortSecured not equal to WPA_802_1X_PORT_SECURED while process the Association.
76860 + if ((pAd->Mlme.LeapMachine.CurrState != LEAP_IDLE) && (pAd->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
76861 + {
76862 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_AUTH_TIMEOUT);
76863 + }
76864 + }
76865 +#endif // LEAP_SUPPORT //
76866 + //
76867 + // Get Current System time and Turn on AdjacentAPReport
76868 + //
76869 + NdisGetSystemUpTime(&pAd->StaCfg.CCXAdjacentAPLinkDownTime);
76870 + pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE;
76871 + LinkDown(pAd, TRUE);
76872 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76873 +
76874 +#ifdef WPA_SUPPLICANT_SUPPORT
76875 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
76876 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
76877 + {
76878 + union iwreq_data wrqu;
76879 + //send disassociate event to wpa_supplicant
76880 + memset(&wrqu, 0, sizeof(wrqu));
76881 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
76882 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
76883 + }
76884 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76885 +#endif // WPA_SUPPLICANT_SUPPORT //
76886 +
76887 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
76888 + {
76889 + union iwreq_data wrqu;
76890 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
76891 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
76892 + }
76893 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
76894 + }
76895 + }
76896 + else
76897 + {
76898 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() sanity check fail\n"));
76899 + }
76900 +
76901 +}
76902 +
76903 +/*
76904 + ==========================================================================
76905 + Description:
76906 + what the state machine will do after assoc timeout
76907 + Parameters:
76908 + Elme -
76909 +
76910 + IRQL = DISPATCH_LEVEL
76911 +
76912 + ==========================================================================
76913 + */
76914 +VOID AssocTimeoutAction(
76915 + IN PRTMP_ADAPTER pAd,
76916 + IN MLME_QUEUE_ELEM *Elem)
76917 +{
76918 + USHORT Status;
76919 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n"));
76920 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76921 + Status = MLME_REJ_TIMEOUT;
76922 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76923 +}
76924 +
76925 +/*
76926 + ==========================================================================
76927 + Description:
76928 + what the state machine will do after reassoc timeout
76929 +
76930 + IRQL = DISPATCH_LEVEL
76931 +
76932 + ==========================================================================
76933 + */
76934 +VOID ReassocTimeoutAction(
76935 + IN PRTMP_ADAPTER pAd,
76936 + IN MLME_QUEUE_ELEM *Elem)
76937 +{
76938 + USHORT Status;
76939 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n"));
76940 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76941 + Status = MLME_REJ_TIMEOUT;
76942 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76943 +}
76944 +
76945 +/*
76946 + ==========================================================================
76947 + Description:
76948 + what the state machine will do after disassoc timeout
76949 +
76950 + IRQL = DISPATCH_LEVEL
76951 +
76952 + ==========================================================================
76953 + */
76954 +VOID DisassocTimeoutAction(
76955 + IN PRTMP_ADAPTER pAd,
76956 + IN MLME_QUEUE_ELEM *Elem)
76957 +{
76958 + USHORT Status;
76959 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n"));
76960 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76961 + Status = MLME_SUCCESS;
76962 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
76963 +}
76964 +
76965 +VOID InvalidStateWhenAssoc(
76966 + IN PRTMP_ADAPTER pAd,
76967 + IN MLME_QUEUE_ELEM *Elem)
76968 +{
76969 + USHORT Status;
76970 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n",
76971 + pAd->Mlme.AssocMachine.CurrState));
76972 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76973 + Status = MLME_STATE_MACHINE_REJECT;
76974 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
76975 +}
76976 +
76977 +VOID InvalidStateWhenReassoc(
76978 + IN PRTMP_ADAPTER pAd,
76979 + IN MLME_QUEUE_ELEM *Elem)
76980 +{
76981 + USHORT Status;
76982 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n",
76983 + pAd->Mlme.AssocMachine.CurrState));
76984 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76985 + Status = MLME_STATE_MACHINE_REJECT;
76986 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
76987 +}
76988 +
76989 +VOID InvalidStateWhenDisassociate(
76990 + IN PRTMP_ADAPTER pAd,
76991 + IN MLME_QUEUE_ELEM *Elem)
76992 +{
76993 + USHORT Status;
76994 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n",
76995 + pAd->Mlme.AssocMachine.CurrState));
76996 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
76997 + Status = MLME_STATE_MACHINE_REJECT;
76998 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);
76999 +}
77000 +
77001 +/*
77002 + ==========================================================================
77003 + Description:
77004 + right part of IEEE 802.11/1999 page 374
77005 + Note:
77006 + This event should never cause ASSOC state machine perform state
77007 + transition, and has no relationship with CNTL machine. So we separate
77008 + this routine as a service outside of ASSOC state transition table.
77009 +
77010 + IRQL = DISPATCH_LEVEL
77011 +
77012 + ==========================================================================
77013 + */
77014 +VOID Cls3errAction(
77015 + IN PRTMP_ADAPTER pAd,
77016 + IN PUCHAR pAddr)
77017 +{
77018 + HEADER_802_11 DisassocHdr;
77019 + PHEADER_802_11 pDisassocHdr;
77020 + PUCHAR pOutBuffer = NULL;
77021 + ULONG FrameLen = 0;
77022 + NDIS_STATUS NStatus;
77023 + USHORT Reason = REASON_CLS3ERR;
77024 +
77025 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
77026 + if (NStatus != NDIS_STATUS_SUCCESS)
77027 + return;
77028 +
77029 + DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Class 3 Error, Send DISASSOC frame\n"));
77030 + MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); // patch peap ttls switching issue
77031 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77032 + sizeof(HEADER_802_11),&DisassocHdr,
77033 + 2, &Reason,
77034 + END_OF_ARGS);
77035 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77036 +
77037 + // To patch Instance and Buffalo(N) AP
77038 + // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine
77039 + // Therefore, we send both of them.
77040 + pDisassocHdr = (PHEADER_802_11)pOutBuffer;
77041 + pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
77042 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77043 +
77044 + MlmeFreeMemory(pAd, pOutBuffer);
77045 +
77046 + pAd->StaCfg.DisassocReason = REASON_CLS3ERR;
77047 + COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr);
77048 +}
77049 +
77050 + /*
77051 + ==========================================================================
77052 + Description:
77053 + Switch between WEP and CKIP upon new association up.
77054 + Parameters:
77055 +
77056 + IRQL = DISPATCH_LEVEL
77057 +
77058 + ==========================================================================
77059 + */
77060 +VOID SwitchBetweenWepAndCkip(
77061 + IN PRTMP_ADAPTER pAd)
77062 +{
77063 + int i;
77064 + SHAREDKEY_MODE_STRUC csr1;
77065 +
77066 + // if KP is required. change the CipherAlg in hardware shard key table from WEP
77067 + // to CKIP. else remain as WEP
77068 + if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10))
77069 + {
77070 + // modify hardware key table so that MAC use correct algorithm to decrypt RX
77071 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);
77072 + if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP64)
77073 + csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP64;
77074 + else if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP128)
77075 + csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP128;
77076 +
77077 + if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP64)
77078 + csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP64;
77079 + else if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP128)
77080 + csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP128;
77081 +
77082 + if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP64)
77083 + csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP64;
77084 + else if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP128)
77085 + csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP128;
77086 +
77087 + if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP64)
77088 + csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP64;
77089 + else if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP128)
77090 + csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP128;
77091 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);
77092 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));
77093 +
77094 + // modify software key table so that driver can specify correct algorithm in TXD upon TX
77095 + for (i=0; i<SHARE_KEY_NUM; i++)
77096 + {
77097 + if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP64)
77098 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP64;
77099 + else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP128)
77100 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP128;
77101 + }
77102 + }
77103 +
77104 + // else if KP NOT inused. change the CipherAlg in hardware shard key table from CKIP
77105 + // to WEP.
77106 + else
77107 + {
77108 + // modify hardware key table so that MAC use correct algorithm to decrypt RX
77109 + RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);
77110 + if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP64)
77111 + csr1.field.Bss0Key0CipherAlg = CIPHER_WEP64;
77112 + else if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP128)
77113 + csr1.field.Bss0Key0CipherAlg = CIPHER_WEP128;
77114 +
77115 + if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP64)
77116 + csr1.field.Bss0Key1CipherAlg = CIPHER_WEP64;
77117 + else if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP128)
77118 + csr1.field.Bss0Key1CipherAlg = CIPHER_WEP128;
77119 +
77120 + if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP64)
77121 + csr1.field.Bss0Key2CipherAlg = CIPHER_WEP64;
77122 + else if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP128)
77123 + csr1.field.Bss0Key2CipherAlg = CIPHER_WEP128;
77124 +
77125 + if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP64)
77126 + csr1.field.Bss0Key3CipherAlg = CIPHER_WEP64;
77127 + else if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP128)
77128 + csr1.field.Bss0Key3CipherAlg = CIPHER_WEP128;
77129 +
77130 + // modify software key table so that driver can specify correct algorithm in TXD upon TX
77131 + for (i=0; i<SHARE_KEY_NUM; i++)
77132 + {
77133 + if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP64)
77134 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP64;
77135 + else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP128)
77136 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP128;
77137 + }
77138 +
77139 + //
77140 + // On WPA-NONE, must update CipherAlg.
77141 + // Because the OID_802_11_WEP_STATUS was been set after OID_802_11_ADD_KEY
77142 + // and CipherAlg will be CIPHER_NONE by Windows ZeroConfig.
77143 + // So we need to update CipherAlg after connect.
77144 + //
77145 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
77146 + {
77147 + for (i = 0; i < SHARE_KEY_NUM; i++)
77148 + {
77149 + if (pAd->SharedKey[BSS0][i].KeyLen != 0)
77150 + {
77151 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
77152 + {
77153 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_TKIP;
77154 + }
77155 + else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
77156 + {
77157 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_AES;
77158 + }
77159 + }
77160 + else
77161 + {
77162 + pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
77163 + }
77164 + }
77165 +
77166 + csr1.field.Bss0Key0CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
77167 + csr1.field.Bss0Key1CipherAlg = pAd->SharedKey[BSS0][1].CipherAlg;
77168 + csr1.field.Bss0Key2CipherAlg = pAd->SharedKey[BSS0][2].CipherAlg;
77169 + csr1.field.Bss0Key3CipherAlg = pAd->SharedKey[BSS0][3].CipherAlg;
77170 + }
77171 + RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);
77172 + DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));
77173 + }
77174 +}
77175 +
77176 +#ifdef WPA_SUPPLICANT_SUPPORT
77177 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
77178 +VOID SendAssocIEsToWpaSupplicant(
77179 + IN PRTMP_ADAPTER pAd)
77180 +{
77181 + union iwreq_data wrqu;
77182 + unsigned char custom[IW_CUSTOM_MAX] = {0};
77183 +
77184 + if ((pAd->StaCfg.ReqVarIELen + 17) <= IW_CUSTOM_MAX)
77185 + {
77186 + sprintf(custom, "ASSOCINFO_ReqIEs=");
77187 + NdisMoveMemory(custom+17, pAd->StaCfg.ReqVarIEs, pAd->StaCfg.ReqVarIELen);
77188 + memset(&wrqu, 0, sizeof(wrqu));
77189 + wrqu.data.length = pAd->StaCfg.ReqVarIELen + 17;
77190 + wrqu.data.flags = RT_REQIE_EVENT_FLAG;
77191 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
77192 +
77193 + memset(&wrqu, 0, sizeof(wrqu));
77194 + wrqu.data.flags = RT_ASSOCINFO_EVENT_FLAG;
77195 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
77196 + }
77197 + else
77198 + DBGPRINT(RT_DEBUG_TRACE, ("pAd->StaCfg.ReqVarIELen + 17 > MAX_CUSTOM_LEN\n"));
77199 +
77200 + return;
77201 +}
77202 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77203 +#endif // WPA_SUPPLICANT_SUPPORT //
77204 +
77205 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
77206 +int wext_notify_event_assoc(
77207 + IN RTMP_ADAPTER *pAd)
77208 +{
77209 + union iwreq_data wrqu;
77210 + char custom[IW_CUSTOM_MAX] = {0};
77211 +
77212 +#if WIRELESS_EXT > 17
77213 + if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX)
77214 + {
77215 + wrqu.data.length = pAd->StaCfg.ReqVarIELen;
77216 + memcpy(custom, pAd->StaCfg.ReqVarIEs, pAd->StaCfg.ReqVarIELen);
77217 + wireless_send_event(pAd->net_dev, IWEVASSOCREQIE, &wrqu, custom);
77218 + }
77219 + else
77220 + DBGPRINT(RT_DEBUG_TRACE, ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n"));
77221 +#else
77222 + if (((pAd->StaCfg.ReqVarIELen*2) + 17) <= IW_CUSTOM_MAX)
77223 + {
77224 + UCHAR idx;
77225 + wrqu.data.length = (pAd->StaCfg.ReqVarIELen*2) + 17;
77226 + sprintf(custom, "ASSOCINFO(ReqIEs=");
77227 + for (idx=0; idx<pAd->StaCfg.ReqVarIELen; idx++)
77228 + sprintf(custom, "%s%02x", custom, pAd->StaCfg.ReqVarIEs[idx]);
77229 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
77230 + }
77231 + else
77232 + DBGPRINT(RT_DEBUG_TRACE, ("(pAd->StaCfg.ReqVarIELen*2) + 17 > MAX_CUSTOM_LEN\n"));
77233 +#endif
77234 +
77235 + return 0;
77236 +
77237 +}
77238 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77239 +
77240 +
77241 +BOOLEAN StaAddMacTableEntry(
77242 + IN PRTMP_ADAPTER pAd,
77243 + IN PMAC_TABLE_ENTRY pEntry,
77244 + IN UCHAR MaxSupportedRateIn500Kbps,
77245 + IN HT_CAPABILITY_IE *pHtCapability,
77246 + IN UCHAR HtCapabilityLen,
77247 + IN USHORT CapabilityInfo)
77248 +{
77249 + UCHAR MaxSupportedRate = RATE_11;
77250 +
77251 + if (ADHOC_ON(pAd))
77252 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
77253 +
77254 + switch (MaxSupportedRateIn500Kbps)
77255 + {
77256 + case 108: MaxSupportedRate = RATE_54; break;
77257 + case 96: MaxSupportedRate = RATE_48; break;
77258 + case 72: MaxSupportedRate = RATE_36; break;
77259 + case 48: MaxSupportedRate = RATE_24; break;
77260 + case 36: MaxSupportedRate = RATE_18; break;
77261 + case 24: MaxSupportedRate = RATE_12; break;
77262 + case 18: MaxSupportedRate = RATE_9; break;
77263 + case 12: MaxSupportedRate = RATE_6; break;
77264 + case 22: MaxSupportedRate = RATE_11; break;
77265 + case 11: MaxSupportedRate = RATE_5_5; break;
77266 + case 4: MaxSupportedRate = RATE_2; break;
77267 + case 2: MaxSupportedRate = RATE_1; break;
77268 + default: MaxSupportedRate = RATE_11; break;
77269 + }
77270 +
77271 + if ((pAd->CommonCfg.PhyMode == PHY_11G) && (MaxSupportedRate < RATE_FIRST_OFDM_RATE))
77272 + return FALSE;
77273 +
77274 +#ifdef DOT11_N_SUPPORT
77275 + // 11n only
77276 + if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))&& (HtCapabilityLen == 0))
77277 + return FALSE;
77278 +#endif // DOT11_N_SUPPORT //
77279 +
77280 + if (!pEntry)
77281 + return FALSE;
77282 +
77283 + NdisAcquireSpinLock(&pAd->MacTabLock);
77284 + if (pEntry)
77285 + {
77286 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
77287 + if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) ||
77288 + (pAd->CommonCfg.PhyMode == PHY_11B))
77289 + {
77290 + pEntry->RateLen = 4;
77291 + if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE)
77292 + MaxSupportedRate = RATE_11;
77293 + }
77294 + else
77295 + pEntry->RateLen = 12;
77296 +
77297 + pEntry->MaxHTPhyMode.word = 0;
77298 + pEntry->MinHTPhyMode.word = 0;
77299 + pEntry->HTPhyMode.word = 0;
77300 + pEntry->MaxSupportedRate = MaxSupportedRate;
77301 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
77302 + {
77303 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
77304 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
77305 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
77306 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
77307 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
77308 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
77309 + }
77310 + else
77311 + {
77312 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
77313 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
77314 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
77315 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
77316 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
77317 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
77318 + }
77319 + pEntry->CapabilityInfo = CapabilityInfo;
77320 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE);
77321 + CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE);
77322 + }
77323 +
77324 +#ifdef DOT11_N_SUPPORT
77325 + // If this Entry supports 802.11n, upgrade to HT rate.
77326 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
77327 + {
77328 + UCHAR j, bitmask; //k,bitmask;
77329 + CHAR i;
77330 +
77331 + if (ADHOC_ON(pAd))
77332 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
77333 + if ((pHtCapability->HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
77334 + {
77335 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
77336 + }
77337 + else
77338 + {
77339 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
77340 + pAd->MacTab.fAnyStationNonGF = TRUE;
77341 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
77342 + }
77343 +
77344 + if ((pHtCapability->HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
77345 + {
77346 + pEntry->MaxHTPhyMode.field.BW= BW_40;
77347 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(pHtCapability->HtCapInfo.ShortGIfor40));
77348 + }
77349 + else
77350 + {
77351 + pEntry->MaxHTPhyMode.field.BW = BW_20;
77352 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(pHtCapability->HtCapInfo.ShortGIfor20));
77353 + pAd->MacTab.fAnyStation20Only = TRUE;
77354 + }
77355 +
77356 + // 3*3
77357 + if (pAd->MACVersion >= RALINK_2883_VERSION && pAd->MACVersion < RALINK_3070_VERSION)
77358 + pEntry->MaxHTPhyMode.field.TxBF = pAd->CommonCfg.RegTransmitSetting.field.TxBF;
77359 +
77360 + // find max fixed rate
77361 + for (i=23; i>=0; i--) // 3*3
77362 + {
77363 + j = i/8;
77364 + bitmask = (1<<(i-(j*8)));
77365 + if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask) && (pHtCapability->MCSSet[j] & bitmask))
77366 + {
77367 + pEntry->MaxHTPhyMode.field.MCS = i;
77368 + break;
77369 + }
77370 + if (i==0)
77371 + break;
77372 + }
77373 +
77374 +
77375 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
77376 + {
77377 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
77378 + {
77379 + // Fix MCS as HT Duplicated Mode
77380 + pEntry->MaxHTPhyMode.field.BW = 1;
77381 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
77382 + pEntry->MaxHTPhyMode.field.STBC = 0;
77383 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
77384 + pEntry->MaxHTPhyMode.field.MCS = 32;
77385 + }
77386 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
77387 + {
77388 + // STA supports fixed MCS
77389 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
77390 + }
77391 + }
77392 +
77393 + pEntry->MaxHTPhyMode.field.STBC = (pHtCapability->HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
77394 + pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity;
77395 + pEntry->MaxRAmpduFactor = pHtCapability->HtCapParm.MaxRAmpduFactor;
77396 + pEntry->MmpsMode = (UCHAR)pHtCapability->HtCapInfo.MimoPs;
77397 + pEntry->AMsduSize = (UCHAR)pHtCapability->HtCapInfo.AMsduSize;
77398 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
77399 +
77400 + if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE))
77401 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED);
77402 + if (pHtCapability->HtCapInfo.ShortGIfor20)
77403 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
77404 + if (pHtCapability->HtCapInfo.ShortGIfor40)
77405 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
77406 + if (pHtCapability->HtCapInfo.TxSTBC)
77407 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
77408 + if (pHtCapability->HtCapInfo.RxSTBC)
77409 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
77410 + if (pHtCapability->ExtHtCapInfo.PlusHTC)
77411 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
77412 + if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport)
77413 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
77414 + if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03)
77415 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
77416 + }
77417 + else
77418 + {
77419 + pAd->MacTab.fAnyStationIsLegacy = TRUE;
77420 + }
77421 +
77422 + NdisMoveMemory(&pEntry->HTCapability, pHtCapability, sizeof(HT_CAPABILITY_IE));
77423 +#endif // DOT11_N_SUPPORT //
77424 +
77425 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
77426 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
77427 +
77428 + // Set asic auto fall back
77429 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
77430 + {
77431 + PUCHAR pTable;
77432 + UCHAR TableSize = 0;
77433 +
77434 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
77435 + pEntry->bAutoTxRateSwitch = TRUE;
77436 + }
77437 + else
77438 + {
77439 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
77440 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
77441 + pEntry->bAutoTxRateSwitch = FALSE;
77442 +
77443 + // If the legacy mode is set, overwrite the transmit setting of this entry.
77444 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
77445 + }
77446 +
77447 + pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
77448 + pEntry->Sst = SST_ASSOC;
77449 + pEntry->AuthState = AS_AUTH_OPEN;
77450 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
77451 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
77452 +
77453 + NdisReleaseSpinLock(&pAd->MacTabLock);
77454 +
77455 +#ifdef WPA_SUPPLICANT_SUPPORT
77456 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
77457 + if (pAd->StaCfg.WpaSupplicantUP)
77458 + {
77459 + union iwreq_data wrqu;
77460 +
77461 + SendAssocIEsToWpaSupplicant(pAd);
77462 + memset(&wrqu, 0, sizeof(wrqu));
77463 + wrqu.data.flags = RT_ASSOC_EVENT_FLAG;
77464 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
77465 + }
77466 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77467 +#endif // WPA_SUPPLICANT_SUPPORT //
77468 +
77469 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
77470 + {
77471 + union iwreq_data wrqu;
77472 + wext_notify_event_assoc(pAd);
77473 +
77474 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
77475 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
77476 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
77477 +
77478 + }
77479 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
77480 + return TRUE;
77481 +}
77482 +
77483 +
77484 --- /dev/null
77485 +++ b/drivers/staging/rt3070/sta/auth.c
77486 @@ -0,0 +1,475 @@
77487 +/*
77488 + *************************************************************************
77489 + * Ralink Tech Inc.
77490 + * 5F., No.36, Taiyuan St., Jhubei City,
77491 + * Hsinchu County 302,
77492 + * Taiwan, R.O.C.
77493 + *
77494 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
77495 + *
77496 + * This program is free software; you can redistribute it and/or modify *
77497 + * it under the terms of the GNU General Public License as published by *
77498 + * the Free Software Foundation; either version 2 of the License, or *
77499 + * (at your option) any later version. *
77500 + * *
77501 + * This program is distributed in the hope that it will be useful, *
77502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
77503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
77504 + * GNU General Public License for more details. *
77505 + * *
77506 + * You should have received a copy of the GNU General Public License *
77507 + * along with this program; if not, write to the *
77508 + * Free Software Foundation, Inc., *
77509 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
77510 + * *
77511 + *************************************************************************
77512 +
77513 + Module Name:
77514 + auth.c
77515 +
77516 + Abstract:
77517 +
77518 + Revision History:
77519 + Who When What
77520 + -------- ---------- ----------------------------------------------
77521 + John 2004-9-3 porting from RT2500
77522 +*/
77523 +#include "../rt_config.h"
77524 +
77525 +/*
77526 + ==========================================================================
77527 + Description:
77528 + authenticate state machine init, including state transition and timer init
77529 + Parameters:
77530 + Sm - pointer to the auth state machine
77531 + Note:
77532 + The state machine looks like this
77533 +
77534 + AUTH_REQ_IDLE AUTH_WAIT_SEQ2 AUTH_WAIT_SEQ4
77535 + MT2_MLME_AUTH_REQ mlme_auth_req_action invalid_state_when_auth invalid_state_when_auth
77536 + MT2_PEER_AUTH_EVEN drop peer_auth_even_at_seq2_action peer_auth_even_at_seq4_action
77537 + MT2_AUTH_TIMEOUT Drop auth_timeout_action auth_timeout_action
77538 +
77539 + IRQL = PASSIVE_LEVEL
77540 +
77541 + ==========================================================================
77542 + */
77543 +
77544 +void AuthStateMachineInit(
77545 + IN PRTMP_ADAPTER pAd,
77546 + IN STATE_MACHINE *Sm,
77547 + OUT STATE_MACHINE_FUNC Trans[])
77548 +{
77549 + StateMachineInit(Sm, Trans, MAX_AUTH_STATE, MAX_AUTH_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_REQ_IDLE, AUTH_MACHINE_BASE);
77550 +
77551 + // the first column
77552 + StateMachineSetAction(Sm, AUTH_REQ_IDLE, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)MlmeAuthReqAction);
77553 +
77554 + // the second column
77555 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);
77556 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq2Action);
77557 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);
77558 +
77559 + // the third column
77560 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);
77561 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq4Action);
77562 + StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);
77563 +
77564 + RTMPInitTimer(pAd, &pAd->MlmeAux.AuthTimer, GET_TIMER_FUNCTION(AuthTimeout), pAd, FALSE);
77565 +}
77566 +
77567 +/*
77568 + ==========================================================================
77569 + Description:
77570 + function to be executed at timer thread when auth timer expires
77571 +
77572 + IRQL = DISPATCH_LEVEL
77573 +
77574 + ==========================================================================
77575 + */
77576 +VOID AuthTimeout(
77577 + IN PVOID SystemSpecific1,
77578 + IN PVOID FunctionContext,
77579 + IN PVOID SystemSpecific2,
77580 + IN PVOID SystemSpecific3)
77581 +{
77582 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
77583 +
77584 + DBGPRINT(RT_DEBUG_TRACE,("AUTH - AuthTimeout\n"));
77585 +
77586 + // Do nothing if the driver is starting halt state.
77587 + // This might happen when timer already been fired before cancel timer with mlmehalt
77588 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
77589 + return;
77590 +
77591 + // send a de-auth to reset AP's state machine (Patch AP-Dir635)
77592 + if (pAd->Mlme.AuthMachine.CurrState == AUTH_WAIT_SEQ2)
77593 + Cls2errAction(pAd, pAd->MlmeAux.Bssid);
77594 +
77595 +
77596 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_AUTH_TIMEOUT, 0, NULL);
77597 + RT28XX_MLME_HANDLER(pAd);
77598 +}
77599 +
77600 +
77601 +/*
77602 + ==========================================================================
77603 + Description:
77604 +
77605 + IRQL = DISPATCH_LEVEL
77606 +
77607 + ==========================================================================
77608 + */
77609 +VOID MlmeAuthReqAction(
77610 + IN PRTMP_ADAPTER pAd,
77611 + IN MLME_QUEUE_ELEM *Elem)
77612 +{
77613 + UCHAR Addr[6];
77614 + USHORT Alg, Seq, Status;
77615 + ULONG Timeout;
77616 + HEADER_802_11 AuthHdr;
77617 + BOOLEAN TimerCancelled;
77618 + NDIS_STATUS NStatus;
77619 + PUCHAR pOutBuffer = NULL;
77620 + ULONG FrameLen = 0;
77621 +
77622 + // Block all authentication request durning WPA block period
77623 + if (pAd->StaCfg.bBlockAssoc == TRUE)
77624 + {
77625 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Block Auth request durning WPA block period!\n"));
77626 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77627 + Status = MLME_STATE_MACHINE_REJECT;
77628 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77629 + }
77630 + else if(MlmeAuthReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr, &Timeout, &Alg))
77631 + {
77632 + // reset timer
77633 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
77634 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, Addr);
77635 + pAd->MlmeAux.Alg = Alg;
77636 + Seq = 1;
77637 + Status = MLME_SUCCESS;
77638 +
77639 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
77640 + if(NStatus != NDIS_STATUS_SUCCESS)
77641 + {
77642 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeAuthReqAction(Alg:%d) allocate memory failed\n", Alg));
77643 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77644 + Status = MLME_FAIL_NO_RESOURCE;
77645 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77646 + return;
77647 + }
77648 +
77649 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#1 (Alg=%d)...\n", Alg));
77650 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr, pAd->MlmeAux.Bssid);
77651 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77652 + sizeof(HEADER_802_11),&AuthHdr,
77653 + 2, &Alg,
77654 + 2, &Seq,
77655 + 2, &Status,
77656 + END_OF_ARGS);
77657 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77658 + MlmeFreeMemory(pAd, pOutBuffer);
77659 +
77660 + RTMPSetTimer(&pAd->MlmeAux.AuthTimer, Timeout);
77661 + pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ2;
77662 + }
77663 + else
77664 + {
77665 + DBGPRINT_ERR(("AUTH - MlmeAuthReqAction() sanity check failed\n"));
77666 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77667 + Status = MLME_INVALID_FORMAT;
77668 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77669 + }
77670 +}
77671 +
77672 +/*
77673 + ==========================================================================
77674 + Description:
77675 +
77676 + IRQL = DISPATCH_LEVEL
77677 +
77678 + ==========================================================================
77679 + */
77680 +VOID PeerAuthRspAtSeq2Action(
77681 + IN PRTMP_ADAPTER pAd,
77682 + IN MLME_QUEUE_ELEM *Elem)
77683 +{
77684 + UCHAR Addr2[MAC_ADDR_LEN];
77685 + USHORT Seq, Status, RemoteStatus, Alg;
77686 + UCHAR ChlgText[CIPHER_TEXT_LEN];
77687 + UCHAR CyperChlgText[CIPHER_TEXT_LEN + 8 + 8];
77688 + UCHAR Element[2];
77689 + HEADER_802_11 AuthHdr;
77690 + BOOLEAN TimerCancelled;
77691 + PUCHAR pOutBuffer = NULL;
77692 + NDIS_STATUS NStatus;
77693 + ULONG FrameLen = 0;
77694 + USHORT Status2;
77695 +
77696 + if (PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))
77697 + {
77698 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 2)
77699 + {
77700 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#2 to me (Alg=%d, Status=%d)\n", Alg, Status));
77701 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
77702 +
77703 + if (Status == MLME_SUCCESS)
77704 + {
77705 + // Authentication Mode "LEAP" has allow for CCX 1.X
77706 + if ((pAd->MlmeAux.Alg == Ndis802_11AuthModeOpen)
77707 +#ifdef LEAP_SUPPORT
77708 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
77709 +#endif // LEAP_SUPPORT //
77710 + )
77711 + {
77712 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77713 +#ifdef LEAP_SUPPORT
77714 + pAd->Mlme.LeapMachine.CurrState = LEAP_IDLE;
77715 +#endif // LEAP_SUPPORT //
77716 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77717 + }
77718 + else
77719 + {
77720 + // 2. shared key, need to be challenged
77721 + Seq++;
77722 + RemoteStatus = MLME_SUCCESS;
77723 +
77724 + // Get an unused nonpaged memory
77725 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
77726 + if(NStatus != NDIS_STATUS_SUCCESS)
77727 + {
77728 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq2Action() allocate memory fail\n"));
77729 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77730 + Status2 = MLME_FAIL_NO_RESOURCE;
77731 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status2);
77732 + return;
77733 + }
77734 +
77735 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#3...\n"));
77736 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr2, pAd->MlmeAux.Bssid);
77737 + AuthHdr.FC.Wep = 1;
77738 + // Encrypt challenge text & auth information
77739 + RTMPInitWepEngine(
77740 + pAd,
77741 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
77742 + pAd->StaCfg.DefaultKeyId,
77743 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen,
77744 + CyperChlgText);
77745 +
77746 + Alg = cpu2le16(*(USHORT *)&Alg);
77747 + Seq = cpu2le16(*(USHORT *)&Seq);
77748 + RemoteStatus= cpu2le16(*(USHORT *)&RemoteStatus);
77749 +
77750 + RTMPEncryptData(pAd, (PUCHAR) &Alg, CyperChlgText + 4, 2);
77751 + RTMPEncryptData(pAd, (PUCHAR) &Seq, CyperChlgText + 6, 2);
77752 + RTMPEncryptData(pAd, (PUCHAR) &RemoteStatus, CyperChlgText + 8, 2);
77753 + Element[0] = 16;
77754 + Element[1] = 128;
77755 + RTMPEncryptData(pAd, Element, CyperChlgText + 10, 2);
77756 + RTMPEncryptData(pAd, ChlgText, CyperChlgText + 12, 128);
77757 + RTMPSetICV(pAd, CyperChlgText + 140);
77758 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77759 + sizeof(HEADER_802_11), &AuthHdr,
77760 + CIPHER_TEXT_LEN + 16, CyperChlgText,
77761 + END_OF_ARGS);
77762 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77763 + MlmeFreeMemory(pAd, pOutBuffer);
77764 +
77765 + RTMPSetTimer(&pAd->MlmeAux.AuthTimer, AUTH_TIMEOUT);
77766 + pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ4;
77767 + }
77768 + }
77769 + else
77770 + {
77771 +#ifdef LEAP_SUPPORT
77772 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
77773 + {
77774 + //Invalid Authentication possible rogue AP
77775 + //Add this Ap to Rogue AP.
77776 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_INVALID_AUTH);
77777 + }
77778 +#endif // LEAP_SUPPORT //
77779 + pAd->StaCfg.AuthFailReason = Status;
77780 + COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
77781 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77782 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77783 + }
77784 + }
77785 + }
77786 + else
77787 + {
77788 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthSanity() sanity check fail\n"));
77789 + }
77790 +}
77791 +
77792 +/*
77793 + ==========================================================================
77794 + Description:
77795 +
77796 + IRQL = DISPATCH_LEVEL
77797 +
77798 + ==========================================================================
77799 + */
77800 +VOID PeerAuthRspAtSeq4Action(
77801 + IN PRTMP_ADAPTER pAd,
77802 + IN MLME_QUEUE_ELEM *Elem)
77803 +{
77804 + UCHAR Addr2[MAC_ADDR_LEN];
77805 + USHORT Alg, Seq, Status;
77806 + CHAR ChlgText[CIPHER_TEXT_LEN];
77807 + BOOLEAN TimerCancelled;
77808 +
77809 + if(PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))
77810 + {
77811 + if(MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 4)
77812 + {
77813 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#4 to me\n"));
77814 + RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);
77815 +
77816 + if (Status != MLME_SUCCESS)
77817 + {
77818 + pAd->StaCfg.AuthFailReason = Status;
77819 + COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
77820 + }
77821 +
77822 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77823 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77824 + }
77825 + }
77826 + else
77827 + {
77828 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq4Action() sanity check fail\n"));
77829 + }
77830 +}
77831 +
77832 +/*
77833 + ==========================================================================
77834 + Description:
77835 +
77836 + IRQL = DISPATCH_LEVEL
77837 +
77838 + ==========================================================================
77839 + */
77840 +VOID MlmeDeauthReqAction(
77841 + IN PRTMP_ADAPTER pAd,
77842 + IN MLME_QUEUE_ELEM *Elem)
77843 +{
77844 + MLME_DEAUTH_REQ_STRUCT *pInfo;
77845 + HEADER_802_11 DeauthHdr;
77846 + PUCHAR pOutBuffer = NULL;
77847 + NDIS_STATUS NStatus;
77848 + ULONG FrameLen = 0;
77849 + USHORT Status;
77850 +
77851 + pInfo = (MLME_DEAUTH_REQ_STRUCT *)Elem->Msg;
77852 +
77853 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
77854 + if (NStatus != NDIS_STATUS_SUCCESS)
77855 + {
77856 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeDeauthReqAction() allocate memory fail\n"));
77857 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77858 + Status = MLME_FAIL_NO_RESOURCE;
77859 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);
77860 + return;
77861 + }
77862 +
77863 +
77864 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send DE-AUTH request (Reason=%d)...\n", pInfo->Reason));
77865 + MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pInfo->Addr, pAd->MlmeAux.Bssid);
77866 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77867 + sizeof(HEADER_802_11),&DeauthHdr,
77868 + 2, &pInfo->Reason,
77869 + END_OF_ARGS);
77870 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77871 + MlmeFreeMemory(pAd, pOutBuffer);
77872 +
77873 + pAd->StaCfg.DeauthReason = pInfo->Reason;
77874 + COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pInfo->Addr);
77875 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77876 + Status = MLME_SUCCESS;
77877 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);
77878 +
77879 + // send wireless event - for deauthentication
77880 + if (pAd->CommonCfg.bWirelessEvent)
77881 + RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
77882 +}
77883 +
77884 +/*
77885 + ==========================================================================
77886 + Description:
77887 +
77888 + IRQL = DISPATCH_LEVEL
77889 +
77890 + ==========================================================================
77891 + */
77892 +VOID AuthTimeoutAction(
77893 + IN PRTMP_ADAPTER pAd,
77894 + IN MLME_QUEUE_ELEM *Elem)
77895 +{
77896 + USHORT Status;
77897 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeoutAction\n"));
77898 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77899 + Status = MLME_REJ_TIMEOUT;
77900 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77901 +}
77902 +
77903 +/*
77904 + ==========================================================================
77905 + Description:
77906 +
77907 + IRQL = DISPATCH_LEVEL
77908 +
77909 + ==========================================================================
77910 + */
77911 +VOID InvalidStateWhenAuth(
77912 + IN PRTMP_ADAPTER pAd,
77913 + IN MLME_QUEUE_ELEM *Elem)
77914 +{
77915 + USHORT Status;
77916 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - InvalidStateWhenAuth (state=%ld), reset AUTH state machine\n", pAd->Mlme.AuthMachine.CurrState));
77917 + pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
77918 + Status = MLME_STATE_MACHINE_REJECT;
77919 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
77920 +}
77921 +
77922 +/*
77923 + ==========================================================================
77924 + Description:
77925 + Some STA/AP
77926 + Note:
77927 + This action should never trigger AUTH state transition, therefore we
77928 + separate it from AUTH state machine, and make it as a standalone service
77929 +
77930 + IRQL = DISPATCH_LEVEL
77931 +
77932 + ==========================================================================
77933 + */
77934 +VOID Cls2errAction(
77935 + IN PRTMP_ADAPTER pAd,
77936 + IN PUCHAR pAddr)
77937 +{
77938 + HEADER_802_11 DeauthHdr;
77939 + PUCHAR pOutBuffer = NULL;
77940 + NDIS_STATUS NStatus;
77941 + ULONG FrameLen = 0;
77942 + USHORT Reason = REASON_CLS2ERR;
77943 +
77944 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
77945 + if (NStatus != NDIS_STATUS_SUCCESS)
77946 + return;
77947 +
77948 + DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Class 2 error, Send DEAUTH frame...\n"));
77949 + MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pAddr, pAd->MlmeAux.Bssid);
77950 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
77951 + sizeof(HEADER_802_11),&DeauthHdr,
77952 + 2, &Reason,
77953 + END_OF_ARGS);
77954 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
77955 + MlmeFreeMemory(pAd, pOutBuffer);
77956 +
77957 + pAd->StaCfg.DeauthReason = Reason;
77958 + COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pAddr);
77959 +}
77960 +
77961 +
77962 --- /dev/null
77963 +++ b/drivers/staging/rt3070/sta/auth_rsp.c
77964 @@ -0,0 +1,167 @@
77965 +/*
77966 + *************************************************************************
77967 + * Ralink Tech Inc.
77968 + * 5F., No.36, Taiyuan St., Jhubei City,
77969 + * Hsinchu County 302,
77970 + * Taiwan, R.O.C.
77971 + *
77972 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
77973 + *
77974 + * This program is free software; you can redistribute it and/or modify *
77975 + * it under the terms of the GNU General Public License as published by *
77976 + * the Free Software Foundation; either version 2 of the License, or *
77977 + * (at your option) any later version. *
77978 + * *
77979 + * This program is distributed in the hope that it will be useful, *
77980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
77981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
77982 + * GNU General Public License for more details. *
77983 + * *
77984 + * You should have received a copy of the GNU General Public License *
77985 + * along with this program; if not, write to the *
77986 + * Free Software Foundation, Inc., *
77987 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
77988 + * *
77989 + *************************************************************************
77990 +
77991 + Module Name:
77992 + auth_rsp.c
77993 +
77994 + Abstract:
77995 +
77996 + Revision History:
77997 + Who When What
77998 + -------- ---------- ----------------------------------------------
77999 + John 2004-10-1 copy from RT2560
78000 +*/
78001 +#include "../rt_config.h"
78002 +
78003 +/*
78004 + ==========================================================================
78005 + Description:
78006 + authentication state machine init procedure
78007 + Parameters:
78008 + Sm - the state machine
78009 +
78010 + IRQL = PASSIVE_LEVEL
78011 +
78012 + ==========================================================================
78013 + */
78014 +VOID AuthRspStateMachineInit(
78015 + IN PRTMP_ADAPTER pAd,
78016 + IN PSTATE_MACHINE Sm,
78017 + IN STATE_MACHINE_FUNC Trans[])
78018 +{
78019 + StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_RSP_IDLE, AUTH_RSP_MACHINE_BASE);
78020 +
78021 + // column 1
78022 + StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
78023 +
78024 + // column 2
78025 + StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
78026 +
78027 +}
78028 +
78029 +/*
78030 + ==========================================================================
78031 + Description:
78032 +
78033 + IRQL = DISPATCH_LEVEL
78034 +
78035 + ==========================================================================
78036 +*/
78037 +VOID PeerAuthSimpleRspGenAndSend(
78038 + IN PRTMP_ADAPTER pAd,
78039 + IN PHEADER_802_11 pHdr80211,
78040 + IN USHORT Alg,
78041 + IN USHORT Seq,
78042 + IN USHORT Reason,
78043 + IN USHORT Status)
78044 +{
78045 + HEADER_802_11 AuthHdr;
78046 + ULONG FrameLen = 0;
78047 + PUCHAR pOutBuffer = NULL;
78048 + NDIS_STATUS NStatus;
78049 +
78050 + if (Reason != MLME_SUCCESS)
78051 + {
78052 + DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n"));
78053 + return;
78054 + }
78055 +
78056 + //Get an unused nonpaged memory
78057 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
78058 + if (NStatus != NDIS_STATUS_SUCCESS)
78059 + return;
78060 +
78061 + DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n"));
78062 + MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2, pAd->MlmeAux.Bssid);
78063 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
78064 + sizeof(HEADER_802_11), &AuthHdr,
78065 + 2, &Alg,
78066 + 2, &Seq,
78067 + 2, &Reason,
78068 + END_OF_ARGS);
78069 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
78070 + MlmeFreeMemory(pAd, pOutBuffer);
78071 +}
78072 +
78073 +/*
78074 + ==========================================================================
78075 + Description:
78076 +
78077 + IRQL = DISPATCH_LEVEL
78078 +
78079 + ==========================================================================
78080 +*/
78081 +VOID PeerDeauthAction(
78082 + IN PRTMP_ADAPTER pAd,
78083 + IN PMLME_QUEUE_ELEM Elem)
78084 +{
78085 + UCHAR Addr2[MAC_ADDR_LEN];
78086 + USHORT Reason;
78087 +
78088 + if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))
78089 + {
78090 + if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid))
78091 + {
78092 + DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n", Reason));
78093 +
78094 +
78095 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
78096 + {
78097 + union iwreq_data wrqu;
78098 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
78099 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
78100 + }
78101 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
78102 +
78103 +
78104 + // send wireless event - for deauthentication
78105 + if (pAd->CommonCfg.bWirelessEvent)
78106 + RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
78107 +
78108 + LinkDown(pAd, TRUE);
78109 +
78110 + // Authentication Mode Cisco_LEAP has start a timer
78111 + // We should cancel it if using LEAP
78112 +#ifdef LEAP_SUPPORT
78113 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
78114 + {
78115 + RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &TimerCancelled);
78116 + //Check is it mach the LEAP Authentication failed as possible a Rogue AP
78117 + //on it's PortSecured not equal to WPA_802_1X_PORT_SECURED while process the Authenticaton.
78118 + if ((pAd->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED) && (pAd->Mlme.LeapMachine.CurrState != LEAP_IDLE))
78119 + {
78120 + RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_AUTH_TIMEOUT);
78121 + }
78122 + }
78123 +#endif // LEAP_SUPPORT //
78124 + }
78125 + }
78126 + else
78127 + {
78128 + DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - PeerDeauthAction() sanity check fail\n"));
78129 + }
78130 +}
78131 +
78132 --- /dev/null
78133 +++ b/drivers/staging/rt3070/sta/connect.c
78134 @@ -0,0 +1,2857 @@
78135 +/*
78136 + *************************************************************************
78137 + * Ralink Tech Inc.
78138 + * 5F., No.36, Taiyuan St., Jhubei City,
78139 + * Hsinchu County 302,
78140 + * Taiwan, R.O.C.
78141 + *
78142 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
78143 + *
78144 + * This program is free software; you can redistribute it and/or modify *
78145 + * it under the terms of the GNU General Public License as published by *
78146 + * the Free Software Foundation; either version 2 of the License, or *
78147 + * (at your option) any later version. *
78148 + * *
78149 + * This program is distributed in the hope that it will be useful, *
78150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
78151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
78152 + * GNU General Public License for more details. *
78153 + * *
78154 + * You should have received a copy of the GNU General Public License *
78155 + * along with this program; if not, write to the *
78156 + * Free Software Foundation, Inc., *
78157 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
78158 + * *
78159 + *************************************************************************
78160 +
78161 + Module Name:
78162 + connect.c
78163 +
78164 + Abstract:
78165 +
78166 + Revision History:
78167 + Who When What
78168 + -------- ---------- ----------------------------------------------
78169 + John 2004-08-08 Major modification from RT2560
78170 +*/
78171 +#include "../rt_config.h"
78172 +
78173 +UCHAR CipherSuiteWpaNoneTkip[] = {
78174 + 0x00, 0x50, 0xf2, 0x01, // oui
78175 + 0x01, 0x00, // Version
78176 + 0x00, 0x50, 0xf2, 0x02, // Multicast
78177 + 0x01, 0x00, // Number of unicast
78178 + 0x00, 0x50, 0xf2, 0x02, // unicast
78179 + 0x01, 0x00, // number of authentication method
78180 + 0x00, 0x50, 0xf2, 0x00 // authentication
78181 + };
78182 +UCHAR CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));
78183 +
78184 +UCHAR CipherSuiteWpaNoneAes[] = {
78185 + 0x00, 0x50, 0xf2, 0x01, // oui
78186 + 0x01, 0x00, // Version
78187 + 0x00, 0x50, 0xf2, 0x04, // Multicast
78188 + 0x01, 0x00, // Number of unicast
78189 + 0x00, 0x50, 0xf2, 0x04, // unicast
78190 + 0x01, 0x00, // number of authentication method
78191 + 0x00, 0x50, 0xf2, 0x00 // authentication
78192 + };
78193 +UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));
78194 +
78195 +// The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,
78196 +// or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS
78197 +// All settings successfuly negotiated furing MLME state machines become final settings
78198 +// and are copied to pAd->StaActive
78199 +#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
78200 +{ \
78201 + (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
78202 + NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
78203 + COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
78204 + (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
78205 + (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
78206 + (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
78207 + (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
78208 + (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
78209 + (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
78210 + (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
78211 + (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
78212 + (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
78213 + NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
78214 + (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
78215 + NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
78216 + NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\
78217 + NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\
78218 + NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\
78219 + COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
78220 + (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
78221 + (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
78222 + COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
78223 + (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
78224 +}
78225 +
78226 +/*
78227 + ==========================================================================
78228 + Description:
78229 +
78230 + IRQL = PASSIVE_LEVEL
78231 +
78232 + ==========================================================================
78233 +*/
78234 +VOID MlmeCntlInit(
78235 + IN PRTMP_ADAPTER pAd,
78236 + IN STATE_MACHINE *S,
78237 + OUT STATE_MACHINE_FUNC Trans[])
78238 +{
78239 + // Control state machine differs from other state machines, the interface
78240 + // follows the standard interface
78241 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78242 +}
78243 +
78244 +/*
78245 + ==========================================================================
78246 + Description:
78247 +
78248 + IRQL = DISPATCH_LEVEL
78249 +
78250 + ==========================================================================
78251 +*/
78252 +VOID MlmeCntlMachinePerformAction(
78253 + IN PRTMP_ADAPTER pAd,
78254 + IN STATE_MACHINE *S,
78255 + IN MLME_QUEUE_ELEM *Elem)
78256 +{
78257 + switch(pAd->Mlme.CntlMachine.CurrState)
78258 + {
78259 + case CNTL_IDLE:
78260 + {
78261 + CntlIdleProc(pAd, Elem);
78262 + }
78263 + break;
78264 + case CNTL_WAIT_DISASSOC:
78265 + CntlWaitDisassocProc(pAd, Elem);
78266 + break;
78267 + case CNTL_WAIT_JOIN:
78268 + CntlWaitJoinProc(pAd, Elem);
78269 + break;
78270 +
78271 + // CNTL_WAIT_REASSOC is the only state in CNTL machine that does
78272 + // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".
78273 + // Therefore not protected by NDIS's "only one outstanding OID request"
78274 + // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.
78275 + // Current approach is to block new SET request at RTMPSetInformation()
78276 + // when CntlMachine.CurrState is not CNTL_IDLE
78277 + case CNTL_WAIT_REASSOC:
78278 + CntlWaitReassocProc(pAd, Elem);
78279 + break;
78280 +
78281 + case CNTL_WAIT_START:
78282 + CntlWaitStartProc(pAd, Elem);
78283 + break;
78284 + case CNTL_WAIT_AUTH:
78285 + CntlWaitAuthProc(pAd, Elem);
78286 + break;
78287 + case CNTL_WAIT_AUTH2:
78288 + CntlWaitAuthProc2(pAd, Elem);
78289 + break;
78290 + case CNTL_WAIT_ASSOC:
78291 + CntlWaitAssocProc(pAd, Elem);
78292 + break;
78293 +
78294 + case CNTL_WAIT_OID_LIST_SCAN:
78295 + if(Elem->MsgType == MT2_SCAN_CONF)
78296 + {
78297 + // Resume TxRing after SCANING complete. We hope the out-of-service time
78298 + // won't be too long to let upper layer time-out the waiting frames
78299 + RTMPResumeMsduTransmission(pAd);
78300 + if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
78301 + {
78302 + // Cisco scan request is finished, prepare beacon report
78303 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
78304 + }
78305 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78306 +
78307 + //
78308 + // Set LED status to previous status.
78309 + //
78310 + if (pAd->bLedOnScanning)
78311 + {
78312 + pAd->bLedOnScanning = FALSE;
78313 + RTMPSetLED(pAd, pAd->LedStatus);
78314 + }
78315 +#ifdef DOT11N_DRAFT3
78316 + // AP sent a 2040Coexistence mgmt frame, then station perform a scan, and then send back the respone.
78317 + if (pAd->CommonCfg.BSSCoexist2040.field.InfoReq == 1)
78318 + {
78319 + Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
78320 + }
78321 +#endif // DOT11N_DRAFT3 //
78322 + }
78323 + break;
78324 +
78325 + case CNTL_WAIT_OID_DISASSOC:
78326 + if (Elem->MsgType == MT2_DISASSOC_CONF)
78327 + {
78328 + LinkDown(pAd, FALSE);
78329 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78330 + }
78331 + break;
78332 +#ifdef RT2870
78333 + //
78334 + // This state is for that we want to connect to an AP but
78335 + // it didn't find on BSS List table. So we need to scan the air first,
78336 + // after that we can try to connect to the desired AP if available.
78337 + //
78338 + case CNTL_WAIT_SCAN_FOR_CONNECT:
78339 + if(Elem->MsgType == MT2_SCAN_CONF)
78340 + {
78341 + // Resume TxRing after SCANING complete. We hope the out-of-service time
78342 + // won't be too long to let upper layer time-out the waiting frames
78343 + RTMPResumeMsduTransmission(pAd);
78344 +#ifdef CCX_SUPPORT
78345 + if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
78346 + {
78347 + // Cisco scan request is finished, prepare beacon report
78348 + MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
78349 + }
78350 +#endif // CCX_SUPPORT //
78351 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78352 +
78353 + //
78354 + // Check if we can connect to.
78355 + //
78356 + BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
78357 + if (pAd->MlmeAux.SsidBssTab.BssNr > 0)
78358 + {
78359 + MlmeAutoReconnectLastSSID(pAd);
78360 + }
78361 + }
78362 + break;
78363 +#endif // RT2870 //
78364 + default:
78365 + DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));
78366 + break;
78367 + }
78368 +}
78369 +
78370 +
78371 +/*
78372 + ==========================================================================
78373 + Description:
78374 +
78375 + IRQL = DISPATCH_LEVEL
78376 +
78377 + ==========================================================================
78378 +*/
78379 +VOID CntlIdleProc(
78380 + IN PRTMP_ADAPTER pAd,
78381 + IN MLME_QUEUE_ELEM *Elem)
78382 +{
78383 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
78384 +
78385 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
78386 + return;
78387 +
78388 + switch(Elem->MsgType)
78389 + {
78390 + case OID_802_11_SSID:
78391 + CntlOidSsidProc(pAd, Elem);
78392 + break;
78393 +
78394 + case OID_802_11_BSSID:
78395 + CntlOidRTBssidProc(pAd,Elem);
78396 + break;
78397 +
78398 + case OID_802_11_BSSID_LIST_SCAN:
78399 + CntlOidScanProc(pAd,Elem);
78400 + break;
78401 +
78402 + case OID_802_11_DISASSOCIATE:
78403 +#ifdef RALINK_ATE
78404 + if(ATE_ON(pAd))
78405 + {
78406 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
78407 + break;
78408 + }
78409 +#endif // RALINK_ATE //
78410 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
78411 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
78412 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
78413 +#ifdef WPA_SUPPLICANT_SUPPORT
78414 + if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)
78415 +#endif // WPA_SUPPLICANT_SUPPORT //
78416 + {
78417 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
78418 + // Since calling this indicate user don't want to connect to that SSID anymore.
78419 + pAd->MlmeAux.AutoReconnectSsidLen= 32;
78420 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
78421 + }
78422 + break;
78423 +
78424 + case MT2_MLME_ROAMING_REQ:
78425 + CntlMlmeRoamingProc(pAd, Elem);
78426 + break;
78427 +
78428 + case OID_802_11_MIC_FAILURE_REPORT_FRAME:
78429 + WpaMicFailureReportFrame(pAd, Elem);
78430 + break;
78431 +
78432 +#ifdef QOS_DLS_SUPPORT
78433 + case RT_OID_802_11_SET_DLS_PARAM:
78434 + CntlOidDLSSetupProc(pAd, Elem);
78435 + break;
78436 +#endif // QOS_DLS_SUPPORT //
78437 +
78438 + default:
78439 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));
78440 + break;
78441 + }
78442 +}
78443 +
78444 +VOID CntlOidScanProc(
78445 + IN PRTMP_ADAPTER pAd,
78446 + IN MLME_QUEUE_ELEM *Elem)
78447 +{
78448 + MLME_SCAN_REQ_STRUCT ScanReq;
78449 + ULONG BssIdx = BSS_NOT_FOUND;
78450 + BSS_ENTRY CurrBss;
78451 +
78452 +#ifdef RALINK_ATE
78453 +/* Disable scanning when ATE is running. */
78454 + if (ATE_ON(pAd))
78455 + return;
78456 +#endif // RALINK_ATE //
78457 +
78458 +
78459 + // record current BSS if network is connected.
78460 + // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
78461 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
78462 + {
78463 + BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);
78464 + if (BssIdx != BSS_NOT_FOUND)
78465 + {
78466 + NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
78467 + }
78468 + }
78469 +
78470 + // clean up previous SCAN result, add current BSS back to table if any
78471 + BssTableInit(&pAd->ScanTab);
78472 + if (BssIdx != BSS_NOT_FOUND)
78473 + {
78474 + // DDK Note: If the NIC is associated with a particular BSSID and SSID
78475 + // that are not contained in the list of BSSIDs generated by this scan, the
78476 + // BSSID description of the currently associated BSSID and SSID should be
78477 + // appended to the list of BSSIDs in the NIC's database.
78478 + // To ensure this, we append this BSS as the first entry in SCAN result
78479 + NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));
78480 + pAd->ScanTab.BssNr = 1;
78481 + }
78482 +
78483 + ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE);
78484 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
78485 + sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
78486 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
78487 +}
78488 +
78489 +/*
78490 + ==========================================================================
78491 + Description:
78492 + Before calling this routine, user desired SSID should already been
78493 + recorded in CommonCfg.Ssid[]
78494 + IRQL = DISPATCH_LEVEL
78495 +
78496 + ==========================================================================
78497 +*/
78498 +VOID CntlOidSsidProc(
78499 + IN PRTMP_ADAPTER pAd,
78500 + IN MLME_QUEUE_ELEM * Elem)
78501 +{
78502 + PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;
78503 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
78504 + ULONG Now;
78505 +
78506 + // Step 1. record the desired user settings to MlmeAux
78507 + NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
78508 + NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
78509 + pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength;
78510 + NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
78511 + pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
78512 +
78513 +
78514 + //
78515 + // Update Reconnect Ssid, that user desired to connect.
78516 + //
78517 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
78518 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
78519 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
78520 +
78521 + // step 2. find all matching BSS in the lastest SCAN result (inBssTab)
78522 + // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order
78523 + BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
78524 +
78525 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
78526 + pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));
78527 + NdisGetSystemUpTime(&Now);
78528 +
78529 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
78530 + (pAd->CommonCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) &&
78531 + NdisEqualMemory(pAd->CommonCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->CommonCfg.SsidLen) &&
78532 + MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid))
78533 + {
78534 + // Case 1. already connected with an AP who has the desired SSID
78535 + // with highest RSSI
78536 +
78537 + // Add checking Mode "LEAP" for CCX 1.0
78538 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
78539 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
78540 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
78541 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
78542 +#ifdef LEAP_SUPPORT
78543 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
78544 +#endif // LEAP_SUPPORT //
78545 + ) &&
78546 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
78547 + {
78548 + // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo
78549 + // connection process
78550 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
78551 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
78552 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
78553 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
78554 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
78555 + }
78556 + else if (pAd->bConfigChanged == TRUE)
78557 + {
78558 + // case 1.2 Important Config has changed, we have to reconnect to the same AP
78559 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
78560 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
78561 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
78562 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
78563 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
78564 + }
78565 + else
78566 + {
78567 + // case 1.3. already connected to the SSID with highest RSSI.
78568 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
78569 + //
78570 + // (HCT 12.1) 1c_wlan_mediaevents required
78571 + // media connect events are indicated when associating with the same AP
78572 + //
78573 + if (INFRA_ON(pAd))
78574 + {
78575 + //
78576 + // Since MediaState already is NdisMediaStateConnected
78577 + // We just indicate the connect event again to meet the WHQL required.
78578 + //
78579 + pAd->IndicateMediaState = NdisMediaStateConnected;
78580 + RTMP_IndicateMediaState(pAd);
78581 + pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
78582 + }
78583 +
78584 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78585 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
78586 + {
78587 + union iwreq_data wrqu;
78588 +
78589 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
78590 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
78591 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
78592 +
78593 + }
78594 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
78595 + }
78596 + }
78597 + else if (INFRA_ON(pAd))
78598 + {
78599 + //
78600 + // For RT61
78601 + // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
78602 + // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect
78603 + // But media status is connected, so the SSID not report correctly.
78604 + //
78605 + if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen))
78606 + {
78607 + //
78608 + // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.
78609 + //
78610 + pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
78611 + }
78612 + // case 2. active INFRA association existent
78613 + // roaming is done within miniport driver, nothing to do with configuration
78614 + // utility. so upon a new SET(OID_802_11_SSID) is received, we just
78615 + // disassociate with the current associated AP,
78616 + // then perform a new association with this new SSID, no matter the
78617 + // new/old SSID are the same or not.
78618 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
78619 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
78620 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
78621 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
78622 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
78623 + }
78624 + else
78625 + {
78626 + if (ADHOC_ON(pAd))
78627 + {
78628 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
78629 + LinkDown(pAd, FALSE);
78630 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
78631 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
78632 + RTMP_IndicateMediaState(pAd);
78633 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
78634 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
78635 + }
78636 +
78637 + if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
78638 + (pAd->StaCfg.bAutoReconnect == TRUE) &&
78639 + (pAd->MlmeAux.BssType == BSS_INFRA) &&
78640 + (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)
78641 + )
78642 + {
78643 + MLME_SCAN_REQ_STRUCT ScanReq;
78644 +
78645 + DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
78646 + ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
78647 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
78648 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
78649 + // Reset Missed scan number
78650 + pAd->StaCfg.LastScanTime = Now;
78651 + }
78652 + else
78653 + {
78654 + pAd->MlmeAux.BssIdx = 0;
78655 + IterateOnBssTab(pAd);
78656 + }
78657 + }
78658 +}
78659 +
78660 +
78661 +/*
78662 + ==========================================================================
78663 + Description:
78664 +
78665 + IRQL = DISPATCH_LEVEL
78666 +
78667 + ==========================================================================
78668 +*/
78669 +VOID CntlOidRTBssidProc(
78670 + IN PRTMP_ADAPTER pAd,
78671 + IN MLME_QUEUE_ELEM * Elem)
78672 +{
78673 + ULONG BssIdx;
78674 + PUCHAR pOidBssid = (PUCHAR)Elem->Msg;
78675 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
78676 + MLME_JOIN_REQ_STRUCT JoinReq;
78677 +
78678 +#ifdef RALINK_ATE
78679 +/* No need to perform this routine when ATE is running. */
78680 + if (ATE_ON(pAd))
78681 + return;
78682 +#endif // RALINK_ATE //
78683 +
78684 + // record user desired settings
78685 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
78686 + pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
78687 +
78688 + //
78689 + // Update Reconnect Ssid, that user desired to connect.
78690 + //
78691 + NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
78692 + pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
78693 + NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
78694 +
78695 + // find the desired BSS in the latest SCAN result table
78696 + BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
78697 + if (BssIdx == BSS_NOT_FOUND)
78698 + {
78699 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
78700 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78701 + return;
78702 + }
78703 +
78704 + // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?
78705 + // Because we need this entry to become the JOIN target in later on SYNC state machine
78706 + pAd->MlmeAux.BssIdx = 0;
78707 + pAd->MlmeAux.SsidBssTab.BssNr = 1;
78708 + NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
78709 +
78710 + //pAd->MlmeAux.AutoReconnectSsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
78711 + //NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->ScanTab.BssEntry[BssIdx].SsidLen);
78712 +
78713 + // Add SSID into MlmeAux for site surey joining hidden SSID
78714 + //pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
78715 + //NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->MlmeAux.SsidLen);
78716 +
78717 + // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP
78718 + // we just follow normal procedure. The reason of user doing this may because he/she changed
78719 + // AP to another channel, but we still received BEACON from it thus don't claim Link Down.
78720 + // Since user knows he's changed AP channel, he'll re-connect again. By skipping the following
78721 + // checking, we'll disassociate then re-do normal association with this AP at the new channel.
78722 + // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do
78723 + // connection when setting the same BSSID.
78724 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
78725 + MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid))
78726 + {
78727 + // already connected to the same BSSID, go back to idle state directly
78728 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));
78729 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
78730 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
78731 + {
78732 + union iwreq_data wrqu;
78733 +
78734 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
78735 + memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
78736 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
78737 +
78738 + }
78739 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
78740 + }
78741 + else
78742 + {
78743 + if (INFRA_ON(pAd))
78744 + {
78745 + // disassoc from current AP first
78746 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n"));
78747 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
78748 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
78749 + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
78750 +
78751 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
78752 + }
78753 + else
78754 + {
78755 + if (ADHOC_ON(pAd))
78756 + {
78757 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - drop current ADHOC\n"));
78758 + LinkDown(pAd, FALSE);
78759 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
78760 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
78761 + RTMP_IndicateMediaState(pAd);
78762 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
78763 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
78764 + }
78765 +
78766 + // Change the wepstatus to original wepstatus
78767 + pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
78768 + pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
78769 + pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
78770 +
78771 + // Check cipher suite, AP must have more secured cipher than station setting
78772 + // Set the Pairwise and Group cipher to match the intended AP setting
78773 + // We can only connect to AP with less secured cipher setting
78774 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
78775 + {
78776 + pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;
78777 +
78778 + if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)
78779 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;
78780 + else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
78781 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;
78782 + else // There is no PairCipher Aux, downgrade our capability to TKIP
78783 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
78784 + }
78785 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
78786 + {
78787 + pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;
78788 +
78789 + if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)
78790 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;
78791 + else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
78792 + pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;
78793 + else // There is no PairCipher Aux, downgrade our capability to TKIP
78794 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
78795 +
78796 + // RSN capability
78797 + pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;
78798 + }
78799 +
78800 + // Set Mix cipher flag
78801 + pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
78802 + if (pAd->StaCfg.bMixCipher == TRUE)
78803 + {
78804 + // If mix cipher, re-build RSNIE
78805 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
78806 + }
78807 + // No active association, join the BSS immediately
78808 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
78809 + pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]));
78810 +
78811 + JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
78812 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);
78813 +
78814 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
78815 + }
78816 + }
78817 +}
78818 +
78819 +// Roaming is the only external request triggering CNTL state machine
78820 +// despite of other "SET OID" operation. All "SET OID" related oerations
78821 +// happen in sequence, because no other SET OID will be sent to this device
78822 +// until the the previous SET operation is complete (successful o failed).
78823 +// So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?
78824 +// or been corrupted by other "SET OID"?
78825 +//
78826 +// IRQL = DISPATCH_LEVEL
78827 +VOID CntlMlmeRoamingProc(
78828 + IN PRTMP_ADAPTER pAd,
78829 + IN MLME_QUEUE_ELEM *Elem)
78830 +{
78831 + // TODO:
78832 + // AP in different channel may show lower RSSI than actual value??
78833 + // should we add a weighting factor to compensate it?
78834 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - Roaming in MlmeAux.RoamTab...\n"));
78835 +
78836 + NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));
78837 + pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
78838 +
78839 + BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
78840 + pAd->MlmeAux.BssIdx = 0;
78841 + IterateOnBssTab(pAd);
78842 +}
78843 +
78844 +#ifdef QOS_DLS_SUPPORT
78845 +/*
78846 + ==========================================================================
78847 + Description:
78848 +
78849 + IRQL = DISPATCH_LEVEL
78850 +
78851 + ==========================================================================
78852 +*/
78853 +VOID CntlOidDLSSetupProc(
78854 + IN PRTMP_ADAPTER pAd,
78855 + IN MLME_QUEUE_ELEM *Elem)
78856 +{
78857 + PRT_802_11_DLS pDLS = (PRT_802_11_DLS)Elem->Msg;
78858 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
78859 + INT i;
78860 + USHORT reason = REASON_UNSPECIFY;
78861 +
78862 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - (OID set %02x:%02x:%02x:%02x:%02x:%02x with Valid=%d, Status=%d, TimeOut=%d, CountDownTimer=%d)\n",
78863 + pDLS->MacAddr[0], pDLS->MacAddr[1], pDLS->MacAddr[2], pDLS->MacAddr[3], pDLS->MacAddr[4], pDLS->MacAddr[5],
78864 + pDLS->Valid, pDLS->Status, pDLS->TimeOut, pDLS->CountDownTimer));
78865 +
78866 + if (!pAd->CommonCfg.bDLSCapable)
78867 + return;
78868 +
78869 + // DLS will not be supported when Adhoc mode
78870 + if (INFRA_ON(pAd))
78871 + {
78872 + for (i = 0; i < MAX_NUM_OF_DLS_ENTRY; i++)
78873 + {
78874 + if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
78875 + (pDLS->TimeOut == pAd->StaCfg.DLSEntry[i].TimeOut) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78876 + {
78877 + // 1. Same setting, just drop it
78878 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - setting unchanged\n"));
78879 + break;
78880 + }
78881 + else if (!pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
78882 + MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78883 + {
78884 + // 2. Disable DLS link case, just tear down DLS link
78885 + reason = REASON_QOS_UNWANTED_MECHANISM;
78886 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
78887 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
78888 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78889 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78890 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - start tear down procedure\n"));
78891 + break;
78892 + }
78893 + else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && !pAd->StaCfg.DLSEntry[i].Valid)
78894 + {
78895 + // 3. Enable case, start DLS setup procedure
78896 + NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
78897 +
78898 + //Update countdown timer
78899 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
78900 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78901 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78902 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS setup case\n"));
78903 + break;
78904 + }
78905 + else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78906 + (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && !MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78907 + {
78908 + // 4. update mac case, tear down old DLS and setup new DLS
78909 + reason = REASON_QOS_UNWANTED_MECHANISM;
78910 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
78911 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
78912 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78913 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78914 + NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
78915 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78916 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78917 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS tear down and restart case\n"));
78918 + break;
78919 + }
78920 + else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78921 + MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr) && (pAd->StaCfg.DLSEntry[i].TimeOut != pDLS->TimeOut))
78922 + {
78923 + // 5. update timeout case, start DLS setup procedure (no tear down)
78924 + pAd->StaCfg.DLSEntry[i].TimeOut = pDLS->TimeOut;
78925 + //Update countdown timer
78926 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
78927 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78928 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78929 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS update timeout case\n"));
78930 + break;
78931 + }
78932 + else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
78933 + (pAd->StaCfg.DLSEntry[i].Status != DLS_FINISH) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
78934 + {
78935 + // 6. re-setup case, start DLS setup procedure (no tear down)
78936 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
78937 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
78938 + DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS retry setup procedure\n"));
78939 + break;
78940 + }
78941 + else
78942 + {
78943 + DBGPRINT(RT_DEBUG_WARN,("CNTL - DLS not changed in entry - %d - Valid=%d, Status=%d, TimeOut=%d\n",
78944 + i, pAd->StaCfg.DLSEntry[i].Valid, pAd->StaCfg.DLSEntry[i].Status, pAd->StaCfg.DLSEntry[i].TimeOut));
78945 + }
78946 + }
78947 + }
78948 +}
78949 +#endif // QOS_DLS_SUPPORT //
78950 +
78951 +/*
78952 + ==========================================================================
78953 + Description:
78954 +
78955 + IRQL = DISPATCH_LEVEL
78956 +
78957 + ==========================================================================
78958 +*/
78959 +VOID CntlWaitDisassocProc(
78960 + IN PRTMP_ADAPTER pAd,
78961 + IN MLME_QUEUE_ELEM *Elem)
78962 +{
78963 + MLME_START_REQ_STRUCT StartReq;
78964 +
78965 + if (Elem->MsgType == MT2_DISASSOC_CONF)
78966 + {
78967 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
78968 +
78969 + if (pAd->CommonCfg.bWirelessEvent)
78970 + {
78971 + RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
78972 + }
78973 +
78974 + LinkDown(pAd, FALSE);
78975 +
78976 + // case 1. no matching BSS, and user wants ADHOC, so we just start a new one
78977 + if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC))
78978 + {
78979 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
78980 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
78981 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
78982 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
78983 + }
78984 + // case 2. try each matched BSS
78985 + else
78986 + {
78987 + pAd->MlmeAux.BssIdx = 0;
78988 +
78989 + IterateOnBssTab(pAd);
78990 + }
78991 + }
78992 +}
78993 +
78994 +/*
78995 + ==========================================================================
78996 + Description:
78997 +
78998 + IRQL = DISPATCH_LEVEL
78999 +
79000 + ==========================================================================
79001 +*/
79002 +VOID CntlWaitJoinProc(
79003 + IN PRTMP_ADAPTER pAd,
79004 + IN MLME_QUEUE_ELEM *Elem)
79005 +{
79006 + USHORT Reason;
79007 + MLME_AUTH_REQ_STRUCT AuthReq;
79008 +
79009 + if (Elem->MsgType == MT2_JOIN_CONF)
79010 + {
79011 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
79012 + if (Reason == MLME_SUCCESS)
79013 + {
79014 + // 1. joined an IBSS, we are pretty much done here
79015 + if (pAd->MlmeAux.BssType == BSS_ADHOC)
79016 + {
79017 + //
79018 + // 5G bands rules of Japan:
79019 + // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
79020 + //
79021 + if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
79022 + RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
79023 + )
79024 + {
79025 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79026 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
79027 + return;
79028 + }
79029 +
79030 + LinkUp(pAd, BSS_ADHOC);
79031 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79032 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
79033 + pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
79034 + pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
79035 +
79036 + pAd->IndicateMediaState = NdisMediaStateConnected;
79037 + pAd->ExtraInfo = GENERAL_LINK_UP;
79038 + }
79039 + // 2. joined a new INFRA network, start from authentication
79040 + else
79041 + {
79042 +#ifdef LEAP_SUPPORT
79043 + // Add AuthMode "LEAP" for CCX 1.X
79044 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
79045 + {
79046 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
79047 + }
79048 + else
79049 +#endif // LEAP_SUPPORT //
79050 + {
79051 + // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
79052 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
79053 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
79054 + {
79055 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
79056 + }
79057 + else
79058 + {
79059 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
79060 + }
79061 + }
79062 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
79063 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
79064 +
79065 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;
79066 + }
79067 + }
79068 + else
79069 + {
79070 + // 3. failed, try next BSS
79071 + pAd->MlmeAux.BssIdx++;
79072 + IterateOnBssTab(pAd);
79073 + }
79074 + }
79075 +}
79076 +
79077 +
79078 +/*
79079 + ==========================================================================
79080 + Description:
79081 +
79082 + IRQL = DISPATCH_LEVEL
79083 +
79084 + ==========================================================================
79085 +*/
79086 +VOID CntlWaitStartProc(
79087 + IN PRTMP_ADAPTER pAd,
79088 + IN MLME_QUEUE_ELEM *Elem)
79089 +{
79090 + USHORT Result;
79091 +
79092 + if (Elem->MsgType == MT2_START_CONF)
79093 + {
79094 + NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
79095 + if (Result == MLME_SUCCESS)
79096 + {
79097 + //
79098 + // 5G bands rules of Japan:
79099 + // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
79100 + //
79101 + if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
79102 + RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
79103 + )
79104 + {
79105 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79106 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
79107 + return;
79108 + }
79109 +#ifdef DOT11_N_SUPPORT
79110 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
79111 + {
79112 + N_ChannelCheck(pAd);
79113 + SetCommonHT(pAd);
79114 + NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, &pAd->CommonCfg.AddHTInfo, sizeof(ADD_HT_INFO_IE));
79115 + RTMPCheckHt(pAd, BSSID_WCID, &pAd->CommonCfg.HtCapability, &pAd->CommonCfg.AddHTInfo);
79116 + pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
79117 + NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], 16);
79118 + NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], &pAd->CommonCfg.HtCapability.MCSSet[0], 16);
79119 + COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
79120 +
79121 + if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
79122 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
79123 + {
79124 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel + 2;
79125 + }
79126 + else if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
79127 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
79128 + {
79129 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel - 2;
79130 + }
79131 + }
79132 + else
79133 +#endif // DOT11_N_SUPPORT //
79134 + {
79135 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
79136 + }
79137 + LinkUp(pAd, BSS_ADHOC);
79138 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79139 + // Before send beacon, driver need do radar detection
79140 + if ((pAd->CommonCfg.Channel > 14 )
79141 + && (pAd->CommonCfg.bIEEE80211H == 1)
79142 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
79143 + {
79144 + pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;
79145 + pAd->CommonCfg.RadarDetect.RDCount = 0;
79146 +#ifdef DFS_SUPPORT
79147 + BbpRadarDetectionStart(pAd);
79148 +#endif // DFS_SUPPORT //
79149 + }
79150 +
79151 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
79152 + pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
79153 + pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
79154 + }
79155 + else
79156 + {
79157 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Start IBSS fail. BUG!!!!!\n"));
79158 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79159 + }
79160 + }
79161 +}
79162 +
79163 +/*
79164 + ==========================================================================
79165 + Description:
79166 +
79167 + IRQL = DISPATCH_LEVEL
79168 +
79169 + ==========================================================================
79170 +*/
79171 +VOID CntlWaitAuthProc(
79172 + IN PRTMP_ADAPTER pAd,
79173 + IN MLME_QUEUE_ELEM *Elem)
79174 +{
79175 + USHORT Reason;
79176 + MLME_ASSOC_REQ_STRUCT AssocReq;
79177 + MLME_AUTH_REQ_STRUCT AuthReq;
79178 +
79179 + if (Elem->MsgType == MT2_AUTH_CONF)
79180 + {
79181 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
79182 + if (Reason == MLME_SUCCESS)
79183 + {
79184 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
79185 + AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
79186 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
79187 +
79188 +#ifdef LEAP_SUPPORT
79189 + //
79190 + // Cisco Leap CCKM supported Re-association.
79191 + //
79192 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
79193 + {
79194 + //if CCKM is turn on , that's mean Fast Reauthentication
79195 + //Use CCKM Reassociation instead of normal association for Fast Roaming.
79196 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
79197 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
79198 +
79199 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
79200 + }
79201 + else
79202 +#endif // LEAP_SUPPORT //
79203 + {
79204 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
79205 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
79206 +
79207 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
79208 + }
79209 + }
79210 + else
79211 + {
79212 + // This fail may because of the AP already keep us in its MAC table without
79213 + // ageing-out. The previous authentication attempt must have let it remove us.
79214 + // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
79215 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));
79216 +#ifdef LEAP_SUPPORT
79217 + //Add AuthMode "LEAP" for CCX 1.X
79218 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
79219 + {
79220 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
79221 + }
79222 + else
79223 +#endif // LEAP_SUPPORT //
79224 + {
79225 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
79226 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
79227 + {
79228 + // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
79229 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
79230 + }
79231 + else
79232 + {
79233 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
79234 + }
79235 + }
79236 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
79237 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
79238 +
79239 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
79240 + }
79241 + }
79242 +}
79243 +
79244 +/*
79245 + ==========================================================================
79246 + Description:
79247 +
79248 + IRQL = DISPATCH_LEVEL
79249 +
79250 + ==========================================================================
79251 +*/
79252 +VOID CntlWaitAuthProc2(
79253 + IN PRTMP_ADAPTER pAd,
79254 + IN MLME_QUEUE_ELEM *Elem)
79255 +{
79256 + USHORT Reason;
79257 + MLME_ASSOC_REQ_STRUCT AssocReq;
79258 + MLME_AUTH_REQ_STRUCT AuthReq;
79259 +
79260 + if (Elem->MsgType == MT2_AUTH_CONF)
79261 + {
79262 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
79263 + if (Reason == MLME_SUCCESS)
79264 + {
79265 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
79266 + AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
79267 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
79268 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
79269 + sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
79270 +
79271 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
79272 + }
79273 + else
79274 + {
79275 +#ifdef LEAP_SUPPORT
79276 + // Process LEAP first, since it use different control variable
79277 + // We don't want to affect other poven operation
79278 + if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
79279 + {
79280 + // LEAP Auth not success, try next BSS
79281 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - *LEAP* AUTH FAIL, give up; try next BSS\n"));
79282 + DBGPRINT(RT_DEBUG_TRACE, ("Total match BSSID [=%d]\n", pAd->MlmeAux.SsidBssTab.BssNr));
79283 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79284 + pAd->MlmeAux.BssIdx++;
79285 + IterateOnBssTab(pAd);
79286 + }
79287 + else
79288 +#endif // LEAP_SUPPORT //
79289 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&
79290 + (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))
79291 + {
79292 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try OPEN system...\n"));
79293 + AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
79294 + MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
79295 + sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
79296 +
79297 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
79298 + }
79299 + else
79300 + {
79301 + // not success, try next BSS
79302 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, give up; try next BSS\n"));
79303 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????
79304 + pAd->MlmeAux.BssIdx++;
79305 + IterateOnBssTab(pAd);
79306 + }
79307 + }
79308 + }
79309 +}
79310 +
79311 +/*
79312 + ==========================================================================
79313 + Description:
79314 +
79315 + IRQL = DISPATCH_LEVEL
79316 +
79317 + ==========================================================================
79318 +*/
79319 +VOID CntlWaitAssocProc(
79320 + IN PRTMP_ADAPTER pAd,
79321 + IN MLME_QUEUE_ELEM *Elem)
79322 +{
79323 + USHORT Reason;
79324 +
79325 + if (Elem->MsgType == MT2_ASSOC_CONF)
79326 + {
79327 + NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
79328 + if (Reason == MLME_SUCCESS)
79329 + {
79330 + LinkUp(pAd, BSS_INFRA);
79331 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79332 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association successful on BSS #%ld\n",pAd->MlmeAux.BssIdx));
79333 +
79334 + if (pAd->CommonCfg.bWirelessEvent)
79335 + {
79336 + RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
79337 + }
79338 + }
79339 + else
79340 + {
79341 + // not success, try next BSS
79342 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association fails on BSS #%ld\n",pAd->MlmeAux.BssIdx));
79343 + pAd->MlmeAux.BssIdx++;
79344 + IterateOnBssTab(pAd);
79345 + }
79346 + }
79347 +}
79348 +
79349 +/*
79350 + ==========================================================================
79351 + Description:
79352 +
79353 + IRQL = DISPATCH_LEVEL
79354 +
79355 + ==========================================================================
79356 +*/
79357 +VOID CntlWaitReassocProc(
79358 + IN PRTMP_ADAPTER pAd,
79359 + IN MLME_QUEUE_ELEM *Elem)
79360 +{
79361 + USHORT Result;
79362 +
79363 + if (Elem->MsgType == MT2_REASSOC_CONF)
79364 + {
79365 + NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
79366 + if (Result == MLME_SUCCESS)
79367 + {
79368 + //
79369 + // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC
79370 + //
79371 + LinkUp(pAd, BSS_INFRA);
79372 +
79373 + // send wireless event - for association
79374 + if (pAd->CommonCfg.bWirelessEvent)
79375 + RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
79376 +
79377 +
79378 +#ifdef LEAP_SUPPORT
79379 + if (LEAP_CCKM_ON(pAd))
79380 + {
79381 + STA_PORT_SECURED(pAd);
79382 + pAd->StaCfg.WpaState = SS_FINISH;
79383 + }
79384 +#endif // LEAP_SUPPORT //
79385 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
79386 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
79387 + }
79388 + else
79389 + {
79390 + // reassoc failed, try to pick next BSS in the BSS Table
79391 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
79392 + pAd->MlmeAux.RoamIdx++;
79393 + IterateOnBssTab2(pAd);
79394 + }
79395 + }
79396 +}
79397 +
79398 +
79399 +VOID AdhocTurnOnQos(
79400 + IN PRTMP_ADAPTER pAd)
79401 +{
79402 +#define AC0_DEF_TXOP 0
79403 +#define AC1_DEF_TXOP 0
79404 +#define AC2_DEF_TXOP 94
79405 +#define AC3_DEF_TXOP 47
79406 +
79407 + // Turn on QOs if use HT rate.
79408 + if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
79409 + {
79410 + pAd->CommonCfg.APEdcaParm.bValid = TRUE;
79411 + pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
79412 + pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
79413 + pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
79414 + pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
79415 +
79416 + pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
79417 + pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
79418 + pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
79419 + pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
79420 +
79421 + pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
79422 + pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
79423 + pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
79424 + pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
79425 +
79426 + pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
79427 + pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
79428 + pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
79429 + pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
79430 + }
79431 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
79432 +}
79433 +
79434 +/*
79435 + ==========================================================================
79436 + Description:
79437 +
79438 + IRQL = DISPATCH_LEVEL
79439 +
79440 + ==========================================================================
79441 +*/
79442 +VOID LinkUp(
79443 + IN PRTMP_ADAPTER pAd,
79444 + IN UCHAR BssType)
79445 +{
79446 + ULONG Now;
79447 + UINT32 Data;
79448 + BOOLEAN Cancelled;
79449 + UCHAR Value = 0, idx;
79450 + MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
79451 +
79452 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
79453 +
79454 + //
79455 + // ASSOC - DisassocTimeoutAction
79456 + // CNTL - Dis-associate successful
79457 + // !!! LINK DOWN !!!
79458 + // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
79459 + //
79460 + // To prevent DisassocTimeoutAction to call Link down after we link up,
79461 + // cancel the DisassocTimer no matter what it start or not.
79462 + //
79463 + RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
79464 +
79465 + COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
79466 +
79467 +#ifdef DOT11_N_SUPPORT
79468 + COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
79469 +#endif // DOT11_N_SUPPORT //
79470 + // It's quite difficult to tell if a newly added KEY is WEP or CKIP until a new BSS
79471 + // is formed (either ASSOC/RE-ASSOC done or IBSS started. LinkUP should be a safe place
79472 + // to examine if cipher algorithm switching is required.
79473 + //rt2860b. Don't know why need this
79474 + SwitchBetweenWepAndCkip(pAd);
79475 +
79476 +
79477 + if (BssType == BSS_ADHOC)
79478 + {
79479 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
79480 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
79481 +
79482 +#ifdef DOT11_N_SUPPORT
79483 + if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
79484 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
79485 + {
79486 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
79487 + }
79488 + else if ((pAd->CommonCfg.Channel > 2) &&
79489 + (pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
79490 + (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
79491 + {
79492 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
79493 + }
79494 +#endif // DOT11_N_SUPPORT //
79495 +
79496 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
79497 + // No carrier detection when adhoc
79498 + // CarrierDetectionStop(pAd);
79499 + pAd->CommonCfg.CarrierDetect.CD_State = CD_NORMAL;
79500 +#endif // CARRIER_DETECTION_SUPPORT //
79501 +
79502 +#ifdef DOT11_N_SUPPORT
79503 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
79504 + AdhocTurnOnQos(pAd);
79505 +#endif // DOT11_N_SUPPORT //
79506 +
79507 + DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));
79508 + }
79509 + else
79510 + {
79511 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
79512 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
79513 +
79514 + DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n" ));
79515 + }
79516 +
79517 + // 3*3
79518 + // reset Tx beamforming bit
79519 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
79520 + Value &= (~0x01);
79521 + Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
79522 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
79523 +
79524 +#ifdef DOT11_N_SUPPORT
79525 + // Change to AP channel
79526 + if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
79527 + {
79528 + // Must using 40MHz.
79529 + pAd->CommonCfg.BBPCurrentBW = BW_40;
79530 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
79531 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
79532 +
79533 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
79534 + Value &= (~0x18);
79535 + Value |= 0x10;
79536 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
79537 +
79538 + // RX : control channel at lower
79539 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
79540 + Value &= (~0x20);
79541 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
79542 +
79543 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
79544 + Data &= 0xfffffffe;
79545 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
79546 +
79547 + if (pAd->MACVersion == 0x28600100)
79548 + {
79549 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
79550 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
79551 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
79552 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
79553 + }
79554 +
79555 + DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
79556 + }
79557 + else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
79558 + {
79559 + // Must using 40MHz.
79560 + pAd->CommonCfg.BBPCurrentBW = BW_40;
79561 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
79562 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
79563 +
79564 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
79565 + Value &= (~0x18);
79566 + Value |= 0x10;
79567 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
79568 +
79569 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
79570 + Data |= 0x1;
79571 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
79572 +
79573 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
79574 + Value |= (0x20);
79575 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
79576 +
79577 + if (pAd->MACVersion == 0x28600100)
79578 + {
79579 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
79580 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
79581 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
79582 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
79583 + }
79584 +
79585 + DBGPRINT(RT_DEBUG_TRACE, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
79586 + }
79587 + else
79588 +#endif // DOT11_N_SUPPORT //
79589 + {
79590 + pAd->CommonCfg.BBPCurrentBW = BW_20;
79591 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
79592 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
79593 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
79594 +
79595 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
79596 + Value &= (~0x18);
79597 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
79598 +
79599 + RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
79600 + Data &= 0xfffffffe;
79601 + RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
79602 +
79603 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
79604 + Value &= (~0x20);
79605 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
79606 +
79607 + if (pAd->MACVersion == 0x28600100)
79608 + {
79609 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
79610 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
79611 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
79612 + DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
79613 + }
79614 +
79615 + DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n" ));
79616 + }
79617 +
79618 + RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
79619 + //
79620 + // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission
79621 + //
79622 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
79623 +
79624 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
79625 + BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
79626 +
79627 +#ifdef DOT11_N_SUPPORT
79628 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (Density =%d, )\n", pAd->MacTab.Content[BSSID_WCID].MpduDensity));
79629 +#endif // DOT11_N_SUPPORT //
79630 +
79631 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
79632 +
79633 + AsicSetSlotTime(pAd, TRUE);
79634 + AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
79635 +
79636 + // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit
79637 + AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, FALSE);
79638 +
79639 +#ifdef DOT11_N_SUPPORT
79640 + if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))
79641 + {
79642 + // Update HT protectionfor based on AP's operating mode.
79643 + if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
79644 + {
79645 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
79646 + }
79647 + else
79648 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
79649 + }
79650 +#endif // DOT11_N_SUPPORT //
79651 +
79652 + NdisZeroMemory(&pAd->DrsCounters, sizeof(COUNTER_DRS));
79653 +
79654 + NdisGetSystemUpTime(&Now);
79655 + pAd->StaCfg.LastBeaconRxTime = Now; // last RX timestamp
79656 +
79657 + if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
79658 + CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo))
79659 + {
79660 + MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
79661 + }
79662 +
79663 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79664 +
79665 + if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)
79666 + {
79667 +#ifdef DFS_SUPPORT
79668 + RadarDetectionStop(pAd);
79669 +#endif // DFS_SUPPORT //
79670 + }
79671 + pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
79672 +
79673 + if (BssType == BSS_ADHOC)
79674 + {
79675 + MakeIbssBeacon(pAd);
79676 + if ((pAd->CommonCfg.Channel > 14)
79677 + && (pAd->CommonCfg.bIEEE80211H == 1)
79678 + && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
79679 + {
79680 + ; //Do nothing
79681 + }
79682 + else
79683 + {
79684 + AsicEnableIbssSync(pAd);
79685 + }
79686 +
79687 + // In ad hoc mode, use MAC table from index 1.
79688 + // p.s ASIC use all 0xff as termination of WCID table search.To prevent it's 0xff-ff-ff-ff-ff-ff, Write 0 here.
79689 + RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
79690 + RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
79691 +
79692 + // If WEP is enabled, add key material and cipherAlg into Asic
79693 + // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
79694 +
79695 + if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
79696 + {
79697 + PUCHAR Key;
79698 + UCHAR CipherAlg;
79699 +
79700 + for (idx=0; idx < SHARE_KEY_NUM; idx++)
79701 + {
79702 + CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
79703 + Key = pAd->SharedKey[BSS0][idx].Key;
79704 +
79705 + if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
79706 + {
79707 + // Set key material and cipherAlg to Asic
79708 + AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
79709 +
79710 + if (idx == pAd->StaCfg.DefaultKeyId)
79711 + {
79712 + // Update WCID attribute table and IVEIV table for this group key table
79713 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
79714 + }
79715 + }
79716 +
79717 +
79718 + }
79719 + }
79720 + // If WPANone is enabled, add key material and cipherAlg into Asic
79721 + // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
79722 + else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
79723 + {
79724 + pAd->StaCfg.DefaultKeyId = 0; // always be zero
79725 +
79726 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
79727 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
79728 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
79729 +
79730 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
79731 + {
79732 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
79733 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
79734 + }
79735 +
79736 + // Decide its ChiperAlg
79737 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
79738 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
79739 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
79740 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
79741 + else
79742 + {
79743 + DBGPRINT(RT_DEBUG_TRACE, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd->StaCfg.PairCipher));
79744 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
79745 + }
79746 +
79747 + // Set key material and cipherAlg to Asic
79748 + AsicAddSharedKeyEntry(pAd,
79749 + BSS0,
79750 + 0,
79751 + pAd->SharedKey[BSS0][0].CipherAlg,
79752 + pAd->SharedKey[BSS0][0].Key,
79753 + pAd->SharedKey[BSS0][0].TxMic,
79754 + pAd->SharedKey[BSS0][0].RxMic);
79755 +
79756 + // Update WCID attribute table and IVEIV table for this group key table
79757 + RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pAd->SharedKey[BSS0][0].CipherAlg, NULL);
79758 +
79759 + }
79760 +
79761 + }
79762 + else // BSS_INFRA
79763 + {
79764 + // Check the new SSID with last SSID
79765 + while (Cancelled == TRUE)
79766 + {
79767 + if (pAd->CommonCfg.LastSsidLen == pAd->CommonCfg.SsidLen)
79768 + {
79769 + if (RTMPCompareMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen) == 0)
79770 + {
79771 + // Link to the old one no linkdown is required.
79772 + break;
79773 + }
79774 + }
79775 + // Send link down event before set to link up
79776 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
79777 + RTMP_IndicateMediaState(pAd);
79778 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
79779 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
79780 + break;
79781 + }
79782 +
79783 + //
79784 + // On WPA mode, Remove All Keys if not connect to the last BSSID
79785 + // Key will be set after 4-way handshake.
79786 + //
79787 + if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
79788 + {
79789 + ULONG IV;
79790 +
79791 + // Remove all WPA keys
79792 + RTMPWPARemoveAllKeys(pAd);
79793 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
79794 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
79795 +
79796 + // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP
79797 + // If IV related values are too large in GroupMsg2, AP would ignore this message.
79798 + IV = 0;
79799 + IV |= (pAd->StaCfg.DefaultKeyId << 30);
79800 + AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
79801 + }
79802 + // NOTE:
79803 + // the decision of using "short slot time" or not may change dynamically due to
79804 + // new STA association to the AP. so we have to decide that upon parsing BEACON, not here
79805 +
79806 + // NOTE:
79807 + // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically
79808 + // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here
79809 +
79810 + ComposePsPoll(pAd);
79811 + ComposeNullFrame(pAd);
79812 +
79813 + AsicEnableBssSync(pAd);
79814 +
79815 + // Add BSSID to WCID search table
79816 + AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
79817 +
79818 + NdisAcquireSpinLock(&pAd->MacTabLock);
79819 + // add this BSSID entry into HASH table
79820 + {
79821 + UCHAR HashIdx;
79822 +
79823 + //pEntry = &pAd->MacTab.Content[BSSID_WCID];
79824 + HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
79825 + if (pAd->MacTab.Hash[HashIdx] == NULL)
79826 + {
79827 + pAd->MacTab.Hash[HashIdx] = pEntry;
79828 + }
79829 + else
79830 + {
79831 + pCurrEntry = pAd->MacTab.Hash[HashIdx];
79832 + while (pCurrEntry->pNext != NULL)
79833 + pCurrEntry = pCurrEntry->pNext;
79834 + pCurrEntry->pNext = pEntry;
79835 + }
79836 + }
79837 + NdisReleaseSpinLock(&pAd->MacTabLock);
79838 +
79839 +
79840 + // If WEP is enabled, add paiewise and shared key
79841 +#ifdef WPA_SUPPLICANT_SUPPORT
79842 + if (((pAd->StaCfg.WpaSupplicantUP)&&
79843 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&
79844 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
79845 + ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&
79846 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))
79847 +#else
79848 + if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
79849 +#endif // WPA_SUPPLICANT_SUPPORT //
79850 + {
79851 + PUCHAR Key;
79852 + UCHAR CipherAlg;
79853 +
79854 + for (idx=0; idx < SHARE_KEY_NUM; idx++)
79855 + {
79856 + CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
79857 + Key = pAd->SharedKey[BSS0][idx].Key;
79858 +
79859 + if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
79860 + {
79861 + // Set key material and cipherAlg to Asic
79862 + AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
79863 +
79864 + if (idx == pAd->StaCfg.DefaultKeyId)
79865 + {
79866 + // Assign group key info
79867 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
79868 +
79869 + // Assign pairwise key info
79870 + RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);
79871 + }
79872 + }
79873 + }
79874 + }
79875 +
79876 + // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode
79877 + // should wait until at least 2 active nodes in this BSSID.
79878 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
79879 +
79880 + // For GUI ++
79881 + if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
79882 + {
79883 + pAd->IndicateMediaState = NdisMediaStateConnected;
79884 + pAd->ExtraInfo = GENERAL_LINK_UP;
79885 + RTMP_IndicateMediaState(pAd);
79886 + }
79887 + // --
79888 +
79889 + // Add BSSID in my MAC Table.
79890 + NdisAcquireSpinLock(&pAd->MacTabLock);
79891 + RTMPMoveMemory(pAd->MacTab.Content[BSSID_WCID].Addr, pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
79892 + pAd->MacTab.Content[BSSID_WCID].Aid = BSSID_WCID;
79893 + pAd->MacTab.Content[BSSID_WCID].pAd = pAd;
79894 + pAd->MacTab.Content[BSSID_WCID].ValidAsCLI = TRUE; //Although this is bssid..still set ValidAsCl
79895 + pAd->MacTab.Size = 1; // infra mode always set MACtab size =1.
79896 + pAd->MacTab.Content[BSSID_WCID].Sst = SST_ASSOC;
79897 + pAd->MacTab.Content[BSSID_WCID].AuthState = SST_ASSOC;
79898 + pAd->MacTab.Content[BSSID_WCID].AuthMode = pAd->StaCfg.AuthMode;
79899 + pAd->MacTab.Content[BSSID_WCID].WepStatus = pAd->StaCfg.WepStatus;
79900 + NdisReleaseSpinLock(&pAd->MacTabLock);
79901 +
79902 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
79903 + pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
79904 +
79905 + MlmeUpdateTxRates(pAd, TRUE, BSS0);
79906 +#ifdef DOT11_N_SUPPORT
79907 + MlmeUpdateHtTxRates(pAd, BSS0);
79908 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));
79909 +#endif // DOT11_N_SUPPORT //
79910 +
79911 + //
79912 + // Report Adjacent AP report.
79913 + //
79914 +#ifdef LEAP_SUPPORT
79915 + CCXAdjacentAPReport(pAd);
79916 +#endif // LEAP_SUPPORT //
79917 +
79918 + if (pAd->CommonCfg.bAggregationCapable)
79919 + {
79920 + if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)
79921 + {
79922 +
79923 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
79924 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79925 + RTMPSetPiggyBack(pAd, TRUE);
79926 + DBGPRINT(RT_DEBUG_TRACE, ("Turn on Piggy-Back\n"));
79927 + }
79928 + else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
79929 + {
79930 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
79931 + }
79932 + }
79933 +
79934 + if (pAd->MlmeAux.APRalinkIe != 0x0)
79935 + {
79936 +#ifdef DOT11_N_SUPPORT
79937 + if (CLIENT_STATUS_TEST_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RDG_CAPABLE))
79938 + {
79939 + AsicEnableRDG(pAd);
79940 + }
79941 +#endif // DOT11_N_SUPPORT //
79942 + OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
79943 + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
79944 + }
79945 + else
79946 + {
79947 + OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
79948 + CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
79949 + }
79950 + }
79951 +
79952 +#ifdef DOT11_N_SUPPORT
79953 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n", pAd->CommonCfg.BACapability.word, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
79954 +#endif // DOT11_N_SUPPORT //
79955 +
79956 + // Set LED
79957 + RTMPSetLED(pAd, LED_LINK_UP);
79958 +
79959 + pAd->Mlme.PeriodicRound = 0;
79960 + pAd->Mlme.OneSecPeriodicRound = 0;
79961 + pAd->bConfigChanged = FALSE; // Reset config flag
79962 + pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
79963 +
79964 + // Set asic auto fall back
79965 + {
79966 + PUCHAR pTable;
79967 + UCHAR TableSize = 0;
79968 +
79969 + MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], &pTable, &TableSize, &pAd->CommonCfg.TxRateIndex);
79970 + AsicUpdateAutoFallBackTable(pAd, pTable);
79971 + }
79972 +
79973 + NdisAcquireSpinLock(&pAd->MacTabLock);
79974 + pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
79975 + pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
79976 + if (pAd->StaCfg.bAutoTxRateSwitch == FALSE)
79977 + {
79978 + pEntry->bAutoTxRateSwitch = FALSE;
79979 +#ifdef DOT11_N_SUPPORT
79980 + if (pEntry->HTPhyMode.field.MCS == 32)
79981 + pEntry->HTPhyMode.field.ShortGI = GI_800;
79982 +
79983 + if ((pEntry->HTPhyMode.field.MCS > MCS_7) || (pEntry->HTPhyMode.field.MCS == 32))
79984 + pEntry->HTPhyMode.field.STBC = STBC_NONE;
79985 +#endif // DOT11_N_SUPPORT //
79986 + // If the legacy mode is set, overwrite the transmit setting of this entry.
79987 + if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
79988 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
79989 + }
79990 + else
79991 + pEntry->bAutoTxRateSwitch = TRUE;
79992 + NdisReleaseSpinLock(&pAd->MacTabLock);
79993 +
79994 + // Let Link Status Page display first initial rate.
79995 + pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
79996 + // Select DAC according to HT or Legacy
79997 + if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00)
79998 + {
79999 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
80000 + Value &= (~0x18);
80001 + if (pAd->Antenna.field.TxPath == 2)
80002 + {
80003 + Value |= 0x10;
80004 + }
80005 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
80006 + }
80007 + else
80008 + {
80009 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
80010 + Value &= (~0x18);
80011 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
80012 + }
80013 +
80014 +#ifdef DOT11_N_SUPPORT
80015 + if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
80016 + {
80017 + }
80018 + else if (pEntry->MaxRAmpduFactor == 0)
80019 + {
80020 + // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.
80021 + // Because our Init value is 1 at MACRegTable.
80022 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
80023 + }
80024 +#endif // DOT11_N_SUPPORT //
80025 +
80026 + // Patch for Marvel AP to gain high throughput
80027 + // Need to set as following,
80028 + // 1. Set txop in register-EDCA_AC0_CFG as 0x60
80029 + // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero
80030 + // 3. PBF_MAX_PCNT as 0x1F3FBF9F
80031 + // 4. kick per two packets when dequeue
80032 + //
80033 + // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable
80034 + //
80035 + // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.
80036 +#ifdef DOT11_N_SUPPORT
80037 +// if ((!IS_RT30xx(pAd)) &&
80038 + if (!((pAd->CommonCfg.RxStream == 1)&&(pAd->CommonCfg.TxStream == 1)) &&
80039 + (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
80040 + || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE))))
80041 + {
80042 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
80043 + Data &= 0xFFFFFF00;
80044 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
80045 +
80046 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
80047 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
80048 + }
80049 + else
80050 +#endif // DOT11_N_SUPPORT //
80051 + if (pAd->CommonCfg.bEnableTxBurst)
80052 + {
80053 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
80054 + Data &= 0xFFFFFF00;
80055 + Data |= 0x60;
80056 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
80057 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
80058 +
80059 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
80060 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
80061 + }
80062 + else
80063 + {
80064 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
80065 + Data &= 0xFFFFFF00;
80066 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
80067 +
80068 + RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
80069 + DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
80070 + }
80071 +
80072 +#ifdef DOT11_N_SUPPORT
80073 + // Re-check to turn on TX burst or not.
80074 + if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) && ((STA_WEP_ON(pAd))||(STA_TKIP_ON(pAd))))
80075 + {
80076 + pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
80077 + if (pAd->CommonCfg.bEnableTxBurst)
80078 + {
80079 + UINT32 MACValue = 0;
80080 + // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.
80081 + // I didn't change PBF_MAX_PCNT setting.
80082 + RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
80083 + MACValue &= 0xFFFFFF00;
80084 + RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
80085 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
80086 + }
80087 + }
80088 + else
80089 + {
80090 + pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
80091 + }
80092 +#endif // DOT11_N_SUPPORT //
80093 +
80094 + pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
80095 + COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
80096 + DBGPRINT(RT_DEBUG_TRACE, ("!!!pAd->bNextDisableRxBA= %d \n", pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
80097 + // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap
80098 + // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.
80099 + // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.
80100 +
80101 + if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled)
80102 + {
80103 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
80104 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
80105 + }
80106 +
80107 + NdisAcquireSpinLock(&pAd->MacTabLock);
80108 + pEntry->PortSecured = pAd->StaCfg.PortSecured;
80109 + NdisReleaseSpinLock(&pAd->MacTabLock);
80110 +
80111 + //
80112 + // Patch Atheros AP TX will breakdown issue.
80113 + // AP Model: DLink DWL-8200AP
80114 + //
80115 + if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && STA_TKIP_ON(pAd))
80116 + {
80117 + RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
80118 + }
80119 + else
80120 + {
80121 + RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
80122 + }
80123 +
80124 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
80125 +
80126 +#ifdef DOT11_N_SUPPORT
80127 +#ifdef DOT11N_DRAFT3
80128 + if ((pAd->CommonCfg.BACapability.field.b2040CoexistScanSup) && (pAd->CommonCfg.Channel <= 11))
80129 + {
80130 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SCAN_2040);
80131 + BuildEffectedChannelList(pAd);
80132 + }
80133 +#endif // DOT11N_DRAFT3 //
80134 +#endif // DOT11_N_SUPPORT //
80135 +}
80136 +
80137 +/*
80138 + ==========================================================================
80139 +
80140 + Routine Description:
80141 + Disconnect current BSSID
80142 +
80143 + Arguments:
80144 + pAd - Pointer to our adapter
80145 + IsReqFromAP - Request from AP
80146 +
80147 + Return Value:
80148 + None
80149 +
80150 + IRQL = DISPATCH_LEVEL
80151 +
80152 + Note:
80153 + We need more information to know it's this requst from AP.
80154 + If yes! we need to do extra handling, for example, remove the WPA key.
80155 + Otherwise on 4-way handshaking will faied, since the WPA key didn't be
80156 + remove while auto reconnect.
80157 + Disconnect request from AP, it means we will start afresh 4-way handshaking
80158 + on WPA mode.
80159 +
80160 + ==========================================================================
80161 +*/
80162 +VOID LinkDown(
80163 + IN PRTMP_ADAPTER pAd,
80164 + IN BOOLEAN IsReqFromAP)
80165 +{
80166 + UCHAR i, ByteValue = 0;
80167 +
80168 + // Do nothing if monitor mode is on
80169 + if (MONITOR_ON(pAd))
80170 + return;
80171 +
80172 +#ifdef RALINK_ATE
80173 + // Nothing to do in ATE mode.
80174 + if (ATE_ON(pAd))
80175 + return;
80176 +#endif // RALINK_ATE //
80177 +
80178 + if (pAd->CommonCfg.bWirelessEvent)
80179 + {
80180 + RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
80181 + }
80182 +
80183 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
80184 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
80185 +
80186 + if (ADHOC_ON(pAd)) // Adhoc mode link down
80187 + {
80188 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
80189 +
80190 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
80191 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
80192 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
80193 + RTMP_IndicateMediaState(pAd);
80194 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
80195 + BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
80196 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));
80197 + }
80198 + else // Infra structure mode
80199 + {
80200 + DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
80201 +
80202 +#ifdef QOS_DLS_SUPPORT
80203 + // DLS tear down frame must be sent before link down
80204 + // send DLS-TEAR_DOWN message
80205 + if (pAd->CommonCfg.bDLSCapable)
80206 + {
80207 + // tear down local dls table entry
80208 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
80209 + {
80210 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
80211 + {
80212 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
80213 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
80214 + }
80215 + }
80216 +
80217 + // tear down peer dls table entry
80218 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
80219 + {
80220 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
80221 + {
80222 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
80223 + RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
80224 + }
80225 + }
80226 + }
80227 +#endif // QOS_DLS_SUPPORT //
80228 +
80229 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
80230 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
80231 +
80232 + // Saved last SSID for linkup comparison
80233 + pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
80234 + NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen);
80235 + COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
80236 + if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)
80237 + {
80238 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
80239 + RTMP_IndicateMediaState(pAd);
80240 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
80241 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
80242 + pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
80243 + }
80244 + else
80245 + {
80246 + //
80247 + // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.
80248 + // Otherwise lost beacon or receive De-Authentication from AP,
80249 + // then we should delete BSSID from BssTable.
80250 + // If we don't delete from entry, roaming will fail.
80251 + //
80252 + BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
80253 + }
80254 +
80255 + // restore back to -
80256 + // 1. long slot (20 us) or short slot (9 us) time
80257 + // 2. turn on/off RTS/CTS and/or CTS-to-self protection
80258 + // 3. short preamble
80259 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
80260 +
80261 + if (pAd->StaCfg.CCXAdjacentAPReportFlag == TRUE)
80262 + {
80263 + //
80264 + // Record current AP's information.
80265 + // for later used reporting Adjacent AP report.
80266 + //
80267 + pAd->StaCfg.CCXAdjacentAPChannel = pAd->CommonCfg.Channel;
80268 + pAd->StaCfg.CCXAdjacentAPSsidLen = pAd->CommonCfg.SsidLen;
80269 + NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);
80270 + COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);
80271 + }
80272 +
80273 +#ifdef EXT_BUILD_CHANNEL_LIST
80274 + // Country IE of the AP will be evaluated and will be used.
80275 + if (pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None)
80276 + {
80277 + NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pAd->StaCfg.StaOriCountryCode[0], 2);
80278 + pAd->CommonCfg.Geography = pAd->StaCfg.StaOriGeography;
80279 + BuildChannelListEx(pAd);
80280 + }
80281 +#endif // EXT_BUILD_CHANNEL_LIST //
80282 +
80283 + }
80284 +
80285 + for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
80286 + {
80287 + if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
80288 + MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, pAd->MacTab.Content[i].Addr);
80289 + }
80290 +
80291 + pAd->StaCfg.CCXQosECWMin = 4;
80292 + pAd->StaCfg.CCXQosECWMax = 10;
80293 +
80294 + AsicSetSlotTime(pAd, TRUE); //FALSE);
80295 + AsicSetEdcaParm(pAd, NULL);
80296 +
80297 + // Set LED
80298 + RTMPSetLED(pAd, LED_LINK_DOWN);
80299 + pAd->LedIndicatorStregth = 0xF0;
80300 + RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
80301 +
80302 + AsicDisableSync(pAd);
80303 +
80304 + pAd->Mlme.PeriodicRound = 0;
80305 + pAd->Mlme.OneSecPeriodicRound = 0;
80306 +
80307 + if (pAd->StaCfg.BssType == BSS_INFRA)
80308 + {
80309 + // Remove StaCfg Information after link down
80310 + NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
80311 + NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
80312 + pAd->CommonCfg.SsidLen = 0;
80313 + }
80314 +#ifdef DOT11_N_SUPPORT
80315 + NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(HT_CAPABILITY_IE));
80316 + NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(ADD_HT_INFO_IE));
80317 + pAd->MlmeAux.HtCapabilityLen = 0;
80318 + pAd->MlmeAux.NewExtChannelOffset = 0xff;
80319 +#endif // DOT11_N_SUPPORT //
80320 +
80321 + // Reset WPA-PSK state. Only reset when supplicant enabled
80322 + if (pAd->StaCfg.WpaState != SS_NOTUSE)
80323 + {
80324 + pAd->StaCfg.WpaState = SS_START;
80325 + // Clear Replay counter
80326 + NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
80327 +
80328 +#ifdef QOS_DLS_SUPPORT
80329 + if (pAd->CommonCfg.bDLSCapable)
80330 + NdisZeroMemory(pAd->StaCfg.DlsReplayCounter, 8);
80331 +#endif // QOS_DLS_SUPPORT //
80332 + }
80333 +
80334 +
80335 + //
80336 + // if link down come from AP, we need to remove all WPA keys on WPA mode.
80337 + // otherwise will cause 4-way handshaking failed, since the WPA key not empty.
80338 + //
80339 + if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
80340 + {
80341 + // Remove all WPA keys
80342 + RTMPWPARemoveAllKeys(pAd);
80343 + }
80344 +
80345 + // 802.1x port control
80346 +#ifdef WPA_SUPPLICANT_SUPPORT
80347 + // Prevent clear PortSecured here with static WEP
80348 + // NetworkManger set security policy first then set SSID to connect AP.
80349 + if (pAd->StaCfg.WpaSupplicantUP &&
80350 + (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
80351 + (pAd->StaCfg.IEEE8021X == FALSE))
80352 + {
80353 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
80354 + }
80355 + else
80356 +#endif // WPA_SUPPLICANT_SUPPORT //
80357 + {
80358 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
80359 + pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
80360 + }
80361 +
80362 + NdisAcquireSpinLock(&pAd->MacTabLock);
80363 + pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
80364 + NdisReleaseSpinLock(&pAd->MacTabLock);
80365 +
80366 + pAd->StaCfg.MicErrCnt = 0;
80367 +
80368 + // Turn off Ckip control flag
80369 + pAd->StaCfg.bCkipOn = FALSE;
80370 + pAd->StaCfg.CCXEnable = FALSE;
80371 +
80372 + pAd->IndicateMediaState = NdisMediaStateDisconnected;
80373 + // Update extra information to link is up
80374 + pAd->ExtraInfo = GENERAL_LINK_DOWN;
80375 +
80376 + //pAd->StaCfg.AdhocBOnlyJoined = FALSE;
80377 + //pAd->StaCfg.AdhocBGJoined = FALSE;
80378 + //pAd->StaCfg.Adhoc20NJoined = FALSE;
80379 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
80380 +
80381 + // Reset the Current AP's IP address
80382 + NdisZeroMemory(pAd->StaCfg.AironetIPAddress, 4);
80383 +#ifdef RT2870
80384 + pAd->bUsbTxBulkAggre = FALSE;
80385 +#endif // RT2870 //
80386 +
80387 + // Clean association information
80388 + NdisZeroMemory(&pAd->StaCfg.AssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
80389 + pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
80390 + pAd->StaCfg.ReqVarIELen = 0;
80391 + pAd->StaCfg.ResVarIELen = 0;
80392 +
80393 + //
80394 + // Reset RSSI value after link down
80395 + //
80396 + pAd->StaCfg.RssiSample.AvgRssi0 = 0;
80397 + pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
80398 + pAd->StaCfg.RssiSample.AvgRssi1 = 0;
80399 + pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
80400 + pAd->StaCfg.RssiSample.AvgRssi2 = 0;
80401 + pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
80402 +
80403 + // Restore MlmeRate
80404 + pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
80405 + pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
80406 +
80407 +#ifdef DOT11_N_SUPPORT
80408 + //
80409 + // After Link down, reset piggy-back setting in ASIC. Disable RDG.
80410 + //
80411 + if (pAd->CommonCfg.BBPCurrentBW == BW_40)
80412 + {
80413 + pAd->CommonCfg.BBPCurrentBW = BW_20;
80414 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
80415 + ByteValue &= (~0x18);
80416 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
80417 + }
80418 +#endif // DOT11_N_SUPPORT //
80419 + // Reset DAC
80420 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
80421 + ByteValue &= (~0x18);
80422 + if (pAd->Antenna.field.TxPath == 2)
80423 + {
80424 + ByteValue |= 0x10;
80425 + }
80426 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
80427 +
80428 + RTMPSetPiggyBack(pAd,FALSE);
80429 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
80430 +
80431 +#ifdef DOT11_N_SUPPORT
80432 + pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
80433 +#endif // DOT11_N_SUPPORT //
80434 +
80435 + // Restore all settings in the following.
80436 + AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);
80437 + AsicDisableRDG(pAd);
80438 + pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
80439 + pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
80440 +
80441 +#ifdef DOT11_N_SUPPORT
80442 +#ifdef DOT11N_DRAFT3
80443 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SCAN_2040);
80444 + pAd->CommonCfg.BSSCoexist2040.word = 0;
80445 + TriEventInit(pAd);
80446 + for (i = 0; i < (pAd->ChannelListNum - 1); i++)
80447 + {
80448 + pAd->ChannelList[i].bEffectedChannel = FALSE;
80449 + }
80450 +#endif // DOT11N_DRAFT3 //
80451 +#endif // DOT11_N_SUPPORT //
80452 +
80453 + RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
80454 + RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
80455 +
80456 +#ifdef WPA_SUPPLICANT_SUPPORT
80457 +#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
80458 + if (pAd->StaCfg.WpaSupplicantUP) {
80459 + union iwreq_data wrqu;
80460 + //send disassociate event to wpa_supplicant
80461 + memset(&wrqu, 0, sizeof(wrqu));
80462 + wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
80463 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
80464 + }
80465 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
80466 +#endif // WPA_SUPPLICANT_SUPPORT //
80467 +
80468 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
80469 + {
80470 + union iwreq_data wrqu;
80471 + memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
80472 + wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
80473 + }
80474 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
80475 +
80476 +#ifdef RT30xx
80477 + if (IS_RT3090(pAd))
80478 + {
80479 + UINT32 macdata;
80480 + // disable MMPS BBP control register
80481 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &ByteValue);
80482 + ByteValue &= ~(0x04); //bit 2
80483 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, ByteValue);
80484 +
80485 + // disable MMPS MAC control register
80486 + RTMP_IO_READ32(pAd, 0x1210, &macdata);
80487 + macdata &= ~(0x09); //bit 0, 3
80488 + RTMP_IO_WRITE32(pAd, 0x1210, macdata);
80489 + }
80490 +#endif // RT30xx //
80491 +
80492 +}
80493 +
80494 +/*
80495 + ==========================================================================
80496 + Description:
80497 +
80498 + IRQL = DISPATCH_LEVEL
80499 +
80500 + ==========================================================================
80501 +*/
80502 +VOID IterateOnBssTab(
80503 + IN PRTMP_ADAPTER pAd)
80504 +{
80505 + MLME_START_REQ_STRUCT StartReq;
80506 + MLME_JOIN_REQ_STRUCT JoinReq;
80507 + ULONG BssIdx;
80508 +
80509 + // Change the wepstatus to original wepstatus
80510 + pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
80511 + pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
80512 + pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
80513 +
80514 + BssIdx = pAd->MlmeAux.BssIdx;
80515 + if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)
80516 + {
80517 + // Check cipher suite, AP must have more secured cipher than station setting
80518 + // Set the Pairwise and Group cipher to match the intended AP setting
80519 + // We can only connect to AP with less secured cipher setting
80520 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
80521 + {
80522 + pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;
80523 +
80524 + if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)
80525 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;
80526 + else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
80527 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;
80528 + else // There is no PairCipher Aux, downgrade our capability to TKIP
80529 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
80530 + }
80531 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
80532 + {
80533 + pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;
80534 +
80535 + if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)
80536 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;
80537 + else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
80538 + pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;
80539 + else // There is no PairCipher Aux, downgrade our capability to TKIP
80540 + pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
80541 +
80542 + // RSN capability
80543 + pAd->StaCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;
80544 + }
80545 +
80546 + // Set Mix cipher flag
80547 + pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
80548 + if (pAd->StaCfg.bMixCipher == TRUE)
80549 + {
80550 + // If mix cipher, re-build RSNIE
80551 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
80552 + }
80553 +
80554 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr));
80555 + JoinParmFill(pAd, &JoinReq, BssIdx);
80556 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT),
80557 + &JoinReq);
80558 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
80559 + }
80560 + else if (pAd->StaCfg.BssType == BSS_ADHOC)
80561 + {
80562 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
80563 + StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
80564 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
80565 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
80566 + }
80567 + else // no more BSS
80568 + {
80569 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All roaming failed, stay @ ch #%d\n", pAd->CommonCfg.Channel));
80570 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
80571 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
80572 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
80573 + }
80574 +}
80575 +
80576 +// for re-association only
80577 +// IRQL = DISPATCH_LEVEL
80578 +VOID IterateOnBssTab2(
80579 + IN PRTMP_ADAPTER pAd)
80580 +{
80581 + MLME_REASSOC_REQ_STRUCT ReassocReq;
80582 + ULONG BssIdx;
80583 + BSS_ENTRY *pBss;
80584 +
80585 + BssIdx = pAd->MlmeAux.RoamIdx;
80586 + pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
80587 +
80588 + if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)
80589 + {
80590 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr));
80591 +
80592 + AsicSwitchChannel(pAd, pBss->Channel, FALSE);
80593 + AsicLockChannel(pAd, pBss->Channel);
80594 +
80595 + // reassociate message has the same structure as associate message
80596 + AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,
80597 + ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
80598 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
80599 + sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);
80600 +
80601 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
80602 + }
80603 + else // no more BSS
80604 + {
80605 + DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All fast roaming failed, back to ch #%d\n",pAd->CommonCfg.Channel));
80606 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
80607 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
80608 + pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
80609 + }
80610 +}
80611 +
80612 +/*
80613 + ==========================================================================
80614 + Description:
80615 +
80616 + IRQL = DISPATCH_LEVEL
80617 +
80618 + ==========================================================================
80619 +*/
80620 +VOID JoinParmFill(
80621 + IN PRTMP_ADAPTER pAd,
80622 + IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
80623 + IN ULONG BssIdx)
80624 +{
80625 + JoinReq->BssIdx = BssIdx;
80626 +}
80627 +
80628 +/*
80629 + ==========================================================================
80630 + Description:
80631 +
80632 + IRQL = DISPATCH_LEVEL
80633 +
80634 + ==========================================================================
80635 +*/
80636 +VOID ScanParmFill(
80637 + IN PRTMP_ADAPTER pAd,
80638 + IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
80639 + IN CHAR Ssid[],
80640 + IN UCHAR SsidLen,
80641 + IN UCHAR BssType,
80642 + IN UCHAR ScanType)
80643 +{
80644 + NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
80645 + ScanReq->SsidLen = SsidLen;
80646 + NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
80647 + ScanReq->BssType = BssType;
80648 + ScanReq->ScanType = ScanType;
80649 +}
80650 +
80651 +#ifdef QOS_DLS_SUPPORT
80652 +/*
80653 + ==========================================================================
80654 + Description:
80655 +
80656 + IRQL = DISPATCH_LEVEL
80657 +
80658 + ==========================================================================
80659 +*/
80660 +VOID DlsParmFill(
80661 + IN PRTMP_ADAPTER pAd,
80662 + IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
80663 + IN PRT_802_11_DLS pDls,
80664 + IN USHORT reason)
80665 +{
80666 + pDlsReq->pDLS = pDls;
80667 + pDlsReq->Reason = reason;
80668 +}
80669 +#endif // QOS_DLS_SUPPORT //
80670 +
80671 +/*
80672 + ==========================================================================
80673 + Description:
80674 +
80675 + IRQL = DISPATCH_LEVEL
80676 +
80677 + ==========================================================================
80678 +*/
80679 +VOID StartParmFill(
80680 + IN PRTMP_ADAPTER pAd,
80681 + IN OUT MLME_START_REQ_STRUCT *StartReq,
80682 + IN CHAR Ssid[],
80683 + IN UCHAR SsidLen)
80684 +{
80685 + ASSERT(SsidLen <= MAX_LEN_OF_SSID);
80686 + NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
80687 + StartReq->SsidLen = SsidLen;
80688 +}
80689 +
80690 +/*
80691 + ==========================================================================
80692 + Description:
80693 +
80694 + IRQL = DISPATCH_LEVEL
80695 +
80696 + ==========================================================================
80697 +*/
80698 +VOID AuthParmFill(
80699 + IN PRTMP_ADAPTER pAd,
80700 + IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
80701 + IN PUCHAR pAddr,
80702 + IN USHORT Alg)
80703 +{
80704 + COPY_MAC_ADDR(AuthReq->Addr, pAddr);
80705 + AuthReq->Alg = Alg;
80706 + AuthReq->Timeout = AUTH_TIMEOUT;
80707 +}
80708 +
80709 +/*
80710 + ==========================================================================
80711 + Description:
80712 +
80713 + IRQL = DISPATCH_LEVEL
80714 +
80715 + ==========================================================================
80716 + */
80717 +
80718 +
80719 +#ifdef RT2870
80720 +
80721 +VOID MlmeCntlConfirm(
80722 + IN PRTMP_ADAPTER pAd,
80723 + IN ULONG MsgType,
80724 + IN USHORT Msg)
80725 +{
80726 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(USHORT), &Msg);
80727 +}
80728 +
80729 +VOID ComposePsPoll(
80730 + IN PRTMP_ADAPTER pAd)
80731 +{
80732 + PTXINFO_STRUC pTxInfo;
80733 + PTXWI_STRUC pTxWI;
80734 +
80735 + DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
80736 + NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
80737 +
80738 + pAd->PsPollFrame.FC.PwrMgmt = 0;
80739 + pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
80740 + pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
80741 + pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
80742 + COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
80743 + COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
80744 +
80745 + RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0], 100);
80746 + pTxInfo = (PTXINFO_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0];
80747 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(PSPOLL_FRAME)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
80748 + pTxWI = (PTXWI_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
80749 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(PSPOLL_FRAME)),
80750 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
80751 + RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
80752 + // Append 4 extra zero bytes.
80753 + pAd->PsPollContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(PSPOLL_FRAME) + 4;
80754 +}
80755 +
80756 +// IRQL = DISPATCH_LEVEL
80757 +VOID ComposeNullFrame(
80758 + IN PRTMP_ADAPTER pAd)
80759 +{
80760 + PTXINFO_STRUC pTxInfo;
80761 + PTXWI_STRUC pTxWI;
80762 +
80763 + NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));
80764 + pAd->NullFrame.FC.Type = BTYPE_DATA;
80765 + pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
80766 + pAd->NullFrame.FC.ToDs = 1;
80767 + COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
80768 + COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
80769 + COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
80770 + RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], 100);
80771 + pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
80772 + RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
80773 + pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
80774 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
80775 + 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
80776 + RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
80777 + pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
80778 +}
80779 +#endif // RT2870 //
80780 +
80781 +
80782 +/*
80783 + ==========================================================================
80784 + Description:
80785 + Pre-build a BEACON frame in the shared memory
80786 +
80787 + IRQL = PASSIVE_LEVEL
80788 + IRQL = DISPATCH_LEVEL
80789 +
80790 + ==========================================================================
80791 +*/
80792 +ULONG MakeIbssBeacon(
80793 + IN PRTMP_ADAPTER pAd)
80794 +{
80795 + UCHAR DsLen = 1, IbssLen = 2;
80796 + UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};
80797 + HEADER_802_11 BcnHdr;
80798 + USHORT CapabilityInfo;
80799 + LARGE_INTEGER FakeTimestamp;
80800 + ULONG FrameLen = 0;
80801 + PTXWI_STRUC pTxWI = &pAd->BeaconTxWI;
80802 + CHAR *pBeaconFrame = pAd->BeaconBuf;
80803 + BOOLEAN Privacy;
80804 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
80805 + UCHAR SupRateLen = 0;
80806 + UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
80807 + UCHAR ExtRateLen = 0;
80808 + UCHAR RSNIe = IE_WPA;
80809 +
80810 + if ((pAd->CommonCfg.PhyMode == PHY_11B) && (pAd->CommonCfg.Channel <= 14))
80811 + {
80812 + SupRate[0] = 0x82; // 1 mbps
80813 + SupRate[1] = 0x84; // 2 mbps
80814 + SupRate[2] = 0x8b; // 5.5 mbps
80815 + SupRate[3] = 0x96; // 11 mbps
80816 + SupRateLen = 4;
80817 + ExtRateLen = 0;
80818 + }
80819 + else if (pAd->CommonCfg.Channel > 14)
80820 + {
80821 + SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
80822 + SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
80823 + SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
80824 + SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
80825 + SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
80826 + SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
80827 + SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
80828 + SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
80829 + SupRateLen = 8;
80830 + ExtRateLen = 0;
80831 +
80832 + //
80833 + // Also Update MlmeRate & RtsRate for G only & A only
80834 + //
80835 + pAd->CommonCfg.MlmeRate = RATE_6;
80836 + pAd->CommonCfg.RtsRate = RATE_6;
80837 + pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
80838 + pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
80839 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
80840 + pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
80841 + }
80842 + else
80843 + {
80844 + SupRate[0] = 0x82; // 1 mbps
80845 + SupRate[1] = 0x84; // 2 mbps
80846 + SupRate[2] = 0x8b; // 5.5 mbps
80847 + SupRate[3] = 0x96; // 11 mbps
80848 + SupRateLen = 4;
80849 +
80850 + ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,
80851 + ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
80852 + ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,
80853 + ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
80854 + ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,
80855 + ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
80856 + ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
80857 + ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
80858 + ExtRateLen = 8;
80859 + }
80860 +
80861 + pAd->StaActive.SupRateLen = SupRateLen;
80862 + NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
80863 + pAd->StaActive.ExtRateLen = ExtRateLen;
80864 + NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
80865 +
80866 + // compose IBSS beacon frame
80867 + MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->CommonCfg.Bssid);
80868 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
80869 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
80870 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
80871 + CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
80872 +
80873 + MakeOutgoingFrame(pBeaconFrame, &FrameLen,
80874 + sizeof(HEADER_802_11), &BcnHdr,
80875 + TIMESTAMP_LEN, &FakeTimestamp,
80876 + 2, &pAd->CommonCfg.BeaconPeriod,
80877 + 2, &CapabilityInfo,
80878 + 1, &SsidIe,
80879 + 1, &pAd->CommonCfg.SsidLen,
80880 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
80881 + 1, &SupRateIe,
80882 + 1, &SupRateLen,
80883 + SupRateLen, SupRate,
80884 + 1, &DsIe,
80885 + 1, &DsLen,
80886 + 1, &pAd->CommonCfg.Channel,
80887 + 1, &IbssIe,
80888 + 1, &IbssLen,
80889 + 2, &pAd->StaActive.AtimWin,
80890 + END_OF_ARGS);
80891 +
80892 + // add ERP_IE and EXT_RAE IE of in 802.11g
80893 + if (ExtRateLen)
80894 + {
80895 + ULONG tmp;
80896 +
80897 + MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
80898 + 3, LocalErpIe,
80899 + 1, &ExtRateIe,
80900 + 1, &ExtRateLen,
80901 + ExtRateLen, ExtRate,
80902 + END_OF_ARGS);
80903 + FrameLen += tmp;
80904 + }
80905 +
80906 + // If adhoc secruity is set for WPA-None, append the cipher suite IE
80907 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
80908 + {
80909 + ULONG tmp;
80910 + RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
80911 +
80912 + MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
80913 + 1, &RSNIe,
80914 + 1, &pAd->StaCfg.RSNIE_Len,
80915 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
80916 + END_OF_ARGS);
80917 + FrameLen += tmp;
80918 + }
80919 +
80920 +#ifdef DOT11_N_SUPPORT
80921 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
80922 + {
80923 + ULONG TmpLen;
80924 + UCHAR HtLen, HtLen1;
80925 +
80926 +#ifdef RT_BIG_ENDIAN
80927 + HT_CAPABILITY_IE HtCapabilityTmp;
80928 + ADD_HT_INFO_IE addHTInfoTmp;
80929 + USHORT b2lTmp, b2lTmp2;
80930 +#endif
80931 +
80932 + // add HT Capability IE
80933 + HtLen = sizeof(pAd->CommonCfg.HtCapability);
80934 + HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
80935 +#ifndef RT_BIG_ENDIAN
80936 + MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
80937 + 1, &HtCapIe,
80938 + 1, &HtLen,
80939 + HtLen, &pAd->CommonCfg.HtCapability,
80940 + 1, &AddHtInfoIe,
80941 + 1, &HtLen1,
80942 + HtLen1, &pAd->CommonCfg.AddHTInfo,
80943 + END_OF_ARGS);
80944 +#else
80945 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
80946 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
80947 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
80948 +
80949 + NdisMoveMemory(&addHTInfoTmp, &pAd->CommonCfg.AddHTInfo, HtLen1);
80950 + *(USHORT *)(&addHTInfoTmp.AddHtInfo2) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo2));
80951 + *(USHORT *)(&addHTInfoTmp.AddHtInfo3) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo3));
80952 +
80953 + MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
80954 + 1, &HtCapIe,
80955 + 1, &HtLen,
80956 + HtLen, &HtCapabilityTmp,
80957 + 1, &AddHtInfoIe,
80958 + 1, &HtLen1,
80959 + HtLen1, &addHTInfoTmp,
80960 + END_OF_ARGS);
80961 +#endif
80962 + FrameLen += TmpLen;
80963 + }
80964 +#endif // DOT11_N_SUPPORT //
80965 +
80966 + //beacon use reserved WCID 0xff
80967 + if (pAd->CommonCfg.Channel > 14)
80968 + {
80969 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
80970 + PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
80971 + }
80972 + else
80973 + {
80974 + // Set to use 1Mbps for Adhoc beacon.
80975 + HTTRANSMIT_SETTING Transmit;
80976 + Transmit.word = 0;
80977 + RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
80978 + PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);
80979 + }
80980 +
80981 +#ifdef RT_BIG_ENDIAN
80982 + RTMPFrameEndianChange(pAd, pBeaconFrame, DIR_WRITE, FALSE);
80983 + RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
80984 +#endif
80985 +
80986 + DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
80987 + FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));
80988 + return FrameLen;
80989 +}
80990 +
80991 +
80992 --- /dev/null
80993 +++ b/drivers/staging/rt3070/sta/dls.c
80994 @@ -0,0 +1,2170 @@
80995 +/*
80996 + *************************************************************************
80997 + * Ralink Tech Inc.
80998 + * 5F., No.36, Taiyuan St., Jhubei City,
80999 + * Hsinchu County 302,
81000 + * Taiwan, R.O.C.
81001 + *
81002 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
81003 + *
81004 + * This program is free software; you can redistribute it and/or modify *
81005 + * it under the terms of the GNU General Public License as published by *
81006 + * the Free Software Foundation; either version 2 of the License, or *
81007 + * (at your option) any later version. *
81008 + * *
81009 + * This program is distributed in the hope that it will be useful, *
81010 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
81011 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
81012 + * GNU General Public License for more details. *
81013 + * *
81014 + * You should have received a copy of the GNU General Public License *
81015 + * along with this program; if not, write to the *
81016 + * Free Software Foundation, Inc., *
81017 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
81018 + * *
81019 + *************************************************************************
81020 +
81021 + Module Name:
81022 + dls.c
81023 +
81024 + Abstract:
81025 + Handle WMM-DLS state machine
81026 +
81027 + Revision History:
81028 + Who When What
81029 + -------- ---------- ----------------------------------------------
81030 + Rory Chen 02-14-2006
81031 + Arvin Tai 06-03-2008 Modified for RT28xx
81032 + */
81033 +
81034 +#include "../rt_config.h"
81035 +
81036 +/*
81037 + ==========================================================================
81038 + Description:
81039 + dls state machine init, including state transition and timer init
81040 + Parameters:
81041 + Sm - pointer to the dls state machine
81042 + Note:
81043 + The state machine looks like this
81044 +
81045 + DLS_IDLE
81046 + MT2_MLME_DLS_REQUEST MlmeDlsReqAction
81047 + MT2_PEER_DLS_REQUEST PeerDlsReqAction
81048 + MT2_PEER_DLS_RESPONSE PeerDlsRspAction
81049 + MT2_MLME_DLS_TEARDOWN MlmeTearDownAction
81050 + MT2_PEER_DLS_TEARDOWN PeerTearDownAction
81051 +
81052 + IRQL = PASSIVE_LEVEL
81053 +
81054 + ==========================================================================
81055 + */
81056 +void DlsStateMachineInit(
81057 + IN PRTMP_ADAPTER pAd,
81058 + IN STATE_MACHINE *Sm,
81059 + OUT STATE_MACHINE_FUNC Trans[])
81060 +{
81061 + UCHAR i;
81062 +
81063 + StateMachineInit(Sm, (STATE_MACHINE_FUNC*)Trans, MAX_DLS_STATE, MAX_DLS_MSG, (STATE_MACHINE_FUNC)Drop, DLS_IDLE, DLS_MACHINE_BASE);
81064 +
81065 + // the first column
81066 + StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_REQ, (STATE_MACHINE_FUNC)MlmeDlsReqAction);
81067 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_REQ, (STATE_MACHINE_FUNC)PeerDlsReqAction);
81068 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_RSP, (STATE_MACHINE_FUNC)PeerDlsRspAction);
81069 + StateMachineSetAction(Sm, DLS_IDLE, MT2_MLME_DLS_TEAR_DOWN, (STATE_MACHINE_FUNC)MlmeDlsTearDownAction);
81070 + StateMachineSetAction(Sm, DLS_IDLE, MT2_PEER_DLS_TEAR_DOWN, (STATE_MACHINE_FUNC)PeerDlsTearDownAction);
81071 +
81072 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
81073 + {
81074 + pAd->StaCfg.DLSEntry[i].pAd = pAd;
81075 + RTMPInitTimer(pAd, &pAd->StaCfg.DLSEntry[i].Timer, GET_TIMER_FUNCTION(DlsTimeoutAction), pAd, FALSE);
81076 + }
81077 +}
81078 +
81079 +/*
81080 + ==========================================================================
81081 + Description:
81082 +
81083 + IRQL = DISPATCH_LEVEL
81084 +
81085 + ==========================================================================
81086 + */
81087 +VOID MlmeDlsReqAction(
81088 + IN PRTMP_ADAPTER pAd,
81089 + IN MLME_QUEUE_ELEM *Elem)
81090 +{
81091 + PUCHAR pOutBuffer = NULL;
81092 + NDIS_STATUS NStatus;
81093 + ULONG FrameLen = 0;
81094 + HEADER_802_11 DlsReqHdr;
81095 + PRT_802_11_DLS pDLS = NULL;
81096 + UCHAR Category = CATEGORY_DLS;
81097 + UCHAR Action = ACTION_DLS_REQUEST;
81098 + ULONG tmp;
81099 + USHORT reason;
81100 + ULONG Timeout;
81101 + BOOLEAN TimerCancelled;
81102 +
81103 + if(!MlmeDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, &pDLS, &reason))
81104 + return;
81105 +
81106 + DBGPRINT(RT_DEBUG_TRACE,("DLS - MlmeDlsReqAction() \n"));
81107 +
81108 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
81109 + if (NStatus != NDIS_STATUS_SUCCESS)
81110 + {
81111 + DBGPRINT(RT_DEBUG_ERROR,("DLS - MlmeDlsReqAction() allocate memory failed \n"));
81112 + return;
81113 + }
81114 +
81115 + ActHeaderInit(pAd, &DlsReqHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
81116 +
81117 + // Build basic frame first
81118 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81119 + sizeof(HEADER_802_11), &DlsReqHdr,
81120 + 1, &Category,
81121 + 1, &Action,
81122 + 6, &pDLS->MacAddr,
81123 + 6, pAd->CurrentAddress,
81124 + 2, &pAd->StaActive.CapabilityInfo,
81125 + 2, &pDLS->TimeOut,
81126 + 1, &SupRateIe,
81127 + 1, &pAd->MlmeAux.SupRateLen,
81128 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
81129 + END_OF_ARGS);
81130 +
81131 + if (pAd->MlmeAux.ExtRateLen != 0)
81132 + {
81133 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81134 + 1, &ExtRateIe,
81135 + 1, &pAd->MlmeAux.ExtRateLen,
81136 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
81137 + END_OF_ARGS);
81138 + FrameLen += tmp;
81139 + }
81140 +
81141 +#ifdef DOT11_N_SUPPORT
81142 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
81143 + {
81144 + UCHAR HtLen;
81145 +
81146 +#ifdef RT_BIG_ENDIAN
81147 + HT_CAPABILITY_IE HtCapabilityTmp;
81148 +#endif
81149 +
81150 + // add HT Capability IE
81151 + HtLen = sizeof(HT_CAPABILITY_IE);
81152 +#ifndef RT_BIG_ENDIAN
81153 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81154 + 1, &HtCapIe,
81155 + 1, &HtLen,
81156 + HtLen, &pAd->CommonCfg.HtCapability,
81157 + END_OF_ARGS);
81158 +#else
81159 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
81160 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
81161 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
81162 +
81163 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81164 + 1, &HtCapIe,
81165 + 1, &HtLen,
81166 + HtLen, &HtCapabilityTmp,
81167 + END_OF_ARGS);
81168 +#endif
81169 + FrameLen = FrameLen + tmp;
81170 + }
81171 +#endif // DOT11_N_SUPPORT //
81172 +
81173 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
81174 + Timeout = DLS_TIMEOUT;
81175 + RTMPSetTimer(&pDLS->Timer, Timeout);
81176 +
81177 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
81178 + MlmeFreeMemory(pAd, pOutBuffer);
81179 +}
81180 +
81181 +/*
81182 + ==========================================================================
81183 + Description:
81184 +
81185 + IRQL = DISPATCH_LEVEL
81186 +
81187 + ==========================================================================
81188 + */
81189 +VOID PeerDlsReqAction(
81190 + IN PRTMP_ADAPTER pAd,
81191 + IN MLME_QUEUE_ELEM *Elem)
81192 +{
81193 + PUCHAR pOutBuffer = NULL;
81194 + NDIS_STATUS NStatus;
81195 + ULONG FrameLen = 0;
81196 + USHORT StatusCode = MLME_SUCCESS;
81197 + HEADER_802_11 DlsRspHdr;
81198 + UCHAR Category = CATEGORY_DLS;
81199 + UCHAR Action = ACTION_DLS_RESPONSE;
81200 + ULONG tmp;
81201 + USHORT CapabilityInfo;
81202 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
81203 + USHORT DLSTimeOut;
81204 + SHORT i;
81205 + ULONG Timeout;
81206 + BOOLEAN TimerCancelled;
81207 + PRT_802_11_DLS pDLS = NULL;
81208 + UCHAR MaxSupportedRateIn500Kbps = 0;
81209 + UCHAR SupportedRatesLen;
81210 + UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
81211 + UCHAR HtCapabilityLen;
81212 + HT_CAPABILITY_IE HtCapability;
81213 +
81214 + if (!PeerDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &DLSTimeOut,
81215 + &SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen, &HtCapability))
81216 + return;
81217 +
81218 + // supported rates array may not be sorted. sort it and find the maximum rate
81219 + for (i = 0; i < SupportedRatesLen; i++)
81220 + {
81221 + if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
81222 + MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
81223 + }
81224 +
81225 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsReqAction() from %02x:%02x:%02x:%02x:%02x:%02x\n", SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
81226 +
81227 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
81228 + if (NStatus != NDIS_STATUS_SUCCESS)
81229 + {
81230 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsReqAction() allocate memory failed \n"));
81231 + return;
81232 + }
81233 +
81234 + if (!INFRA_ON(pAd))
81235 + {
81236 + StatusCode = MLME_REQUEST_DECLINED;
81237 + }
81238 + else if (!pAd->CommonCfg.bWmmCapable)
81239 + {
81240 + StatusCode = MLME_DEST_STA_IS_NOT_A_QSTA;
81241 + }
81242 + else if (!pAd->CommonCfg.bDLSCapable)
81243 + {
81244 + StatusCode = MLME_REQUEST_DECLINED;
81245 + }
81246 + else
81247 + {
81248 + // find table to update parameters
81249 + for (i = (MAX_NUM_OF_DLS_ENTRY-1); i >= 0; i--)
81250 + {
81251 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
81252 + {
81253 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
81254 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
81255 + else
81256 + {
81257 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81258 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81259 + }
81260 +
81261 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
81262 + pAd->StaCfg.DLSEntry[i].TimeOut = DLSTimeOut;
81263 + pAd->StaCfg.DLSEntry[i].CountDownTimer = DLSTimeOut;
81264 + if (HtCapabilityLen != 0)
81265 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
81266 + else
81267 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
81268 + pDLS = &pAd->StaCfg.DLSEntry[i];
81269 + break;
81270 + }
81271 + }
81272 +
81273 + // can not find in table, create a new one
81274 + if (i < 0)
81275 + {
81276 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsReqAction() can not find same entry \n"));
81277 + for (i=(MAX_NUM_OF_DLS_ENTRY - 1); i >= MAX_NUM_OF_INIT_DLS_ENTRY; i--)
81278 + {
81279 + if (!pAd->StaCfg.DLSEntry[i].Valid)
81280 + {
81281 + MAC_TABLE_ENTRY *pEntry;
81282 + UCHAR MaxSupportedRate = RATE_11;
81283 +
81284 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
81285 + {
81286 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
81287 + }
81288 + else
81289 + {
81290 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81291 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81292 + }
81293 +
81294 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
81295 + pAd->StaCfg.DLSEntry[i].Valid = TRUE;
81296 + pAd->StaCfg.DLSEntry[i].TimeOut = DLSTimeOut;
81297 + pAd->StaCfg.DLSEntry[i].CountDownTimer = DLSTimeOut;
81298 + NdisMoveMemory(pAd->StaCfg.DLSEntry[i].MacAddr, SA, MAC_ADDR_LEN);
81299 + if (HtCapabilityLen != 0)
81300 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
81301 + else
81302 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
81303 + pDLS = &pAd->StaCfg.DLSEntry[i];
81304 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
81305 +
81306 + switch (MaxSupportedRateIn500Kbps)
81307 + {
81308 + case 108: MaxSupportedRate = RATE_54; break;
81309 + case 96: MaxSupportedRate = RATE_48; break;
81310 + case 72: MaxSupportedRate = RATE_36; break;
81311 + case 48: MaxSupportedRate = RATE_24; break;
81312 + case 36: MaxSupportedRate = RATE_18; break;
81313 + case 24: MaxSupportedRate = RATE_12; break;
81314 + case 18: MaxSupportedRate = RATE_9; break;
81315 + case 12: MaxSupportedRate = RATE_6; break;
81316 + case 22: MaxSupportedRate = RATE_11; break;
81317 + case 11: MaxSupportedRate = RATE_5_5; break;
81318 + case 4: MaxSupportedRate = RATE_2; break;
81319 + case 2: MaxSupportedRate = RATE_1; break;
81320 + default: MaxSupportedRate = RATE_11; break;
81321 + }
81322 +
81323 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
81324 +
81325 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
81326 + {
81327 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
81328 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81329 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
81330 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81331 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
81332 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81333 + }
81334 + else
81335 + {
81336 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
81337 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81338 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
81339 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81340 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
81341 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81342 + }
81343 +
81344 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81345 + pEntry->MinHTPhyMode.field.BW = BW_20;
81346 +
81347 +#ifdef DOT11_N_SUPPORT
81348 + pEntry->HTCapability.MCSSet[0] = 0;
81349 + pEntry->HTCapability.MCSSet[1] = 0;
81350 +
81351 + // If this Entry supports 802.11n, upgrade to HT rate.
81352 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
81353 + {
81354 + UCHAR j, bitmask; //k,bitmask;
81355 + CHAR ii;
81356 +
81357 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
81358 + {
81359 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
81360 + }
81361 + else
81362 + {
81363 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81364 + pAd->MacTab.fAnyStationNonGF = TRUE;
81365 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
81366 + }
81367 +
81368 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
81369 + {
81370 + pEntry->MaxHTPhyMode.field.BW= BW_40;
81371 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
81372 + }
81373 + else
81374 + {
81375 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81376 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
81377 + pAd->MacTab.fAnyStation20Only = TRUE;
81378 + }
81379 +
81380 + // find max fixed rate
81381 + for (ii=15; ii>=0; ii--)
81382 + {
81383 + j = ii/8;
81384 + bitmask = (1<<(ii-(j*8)));
81385 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
81386 + {
81387 + pEntry->MaxHTPhyMode.field.MCS = ii;
81388 + break;
81389 + }
81390 + if (ii==0)
81391 + break;
81392 + }
81393 +
81394 +
81395 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
81396 + {
81397 +
81398 + printk("@@@ pAd->CommonCfg.RegTransmitSetting.field.MCS = %d\n",
81399 + pAd->StaCfg.DesiredTransmitSetting.field.MCS);
81400 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
81401 + {
81402 + // Fix MCS as HT Duplicated Mode
81403 + pEntry->MaxHTPhyMode.field.BW = 1;
81404 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81405 + pEntry->MaxHTPhyMode.field.STBC = 0;
81406 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
81407 + pEntry->MaxHTPhyMode.field.MCS = 32;
81408 + }
81409 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
81410 + {
81411 + // STA supports fixed MCS
81412 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81413 + }
81414 + }
81415 +
81416 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
81417 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
81418 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
81419 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
81420 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
81421 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81422 +
81423 + if (HtCapability.HtCapInfo.ShortGIfor20)
81424 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
81425 + if (HtCapability.HtCapInfo.ShortGIfor40)
81426 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
81427 + if (HtCapability.HtCapInfo.TxSTBC)
81428 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
81429 + if (HtCapability.HtCapInfo.RxSTBC)
81430 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
81431 + if (HtCapability.ExtHtCapInfo.PlusHTC)
81432 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
81433 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
81434 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
81435 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
81436 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
81437 +
81438 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
81439 + }
81440 +#endif // DOT11_N_SUPPORT //
81441 +
81442 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81443 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
81444 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
81445 +
81446 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
81447 + {
81448 + PUCHAR pTable;
81449 + UCHAR TableSize = 0;
81450 +
81451 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
81452 + pEntry->bAutoTxRateSwitch = TRUE;
81453 + }
81454 + else
81455 + {
81456 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
81457 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81458 + pEntry->bAutoTxRateSwitch = FALSE;
81459 +
81460 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
81461 + }
81462 + pEntry->RateLen = SupportedRatesLen;
81463 +
81464 + break;
81465 + }
81466 + }
81467 + }
81468 + StatusCode = MLME_SUCCESS;
81469 +
81470 + // can not find in table, create a new one
81471 + if (i < 0)
81472 + {
81473 + StatusCode = MLME_QOS_UNSPECIFY;
81474 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsReqAction() DLSEntry table full(only can support %d DLS session) \n", MAX_NUM_OF_DLS_ENTRY - MAX_NUM_OF_INIT_DLS_ENTRY));
81475 + }
81476 + else
81477 + {
81478 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsReqAction() use entry(%d) %02x:%02x:%02x:%02x:%02x:%02x\n",
81479 + i, SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
81480 + }
81481 + }
81482 +
81483 + ActHeaderInit(pAd, &DlsRspHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
81484 +
81485 + // Build basic frame first
81486 + if (StatusCode == MLME_SUCCESS)
81487 + {
81488 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81489 + sizeof(HEADER_802_11), &DlsRspHdr,
81490 + 1, &Category,
81491 + 1, &Action,
81492 + 2, &StatusCode,
81493 + 6, SA,
81494 + 6, pAd->CurrentAddress,
81495 + 2, &pAd->StaActive.CapabilityInfo,
81496 + 1, &SupRateIe,
81497 + 1, &pAd->MlmeAux.SupRateLen,
81498 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
81499 + END_OF_ARGS);
81500 +
81501 + if (pAd->MlmeAux.ExtRateLen != 0)
81502 + {
81503 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81504 + 1, &ExtRateIe,
81505 + 1, &pAd->MlmeAux.ExtRateLen,
81506 + pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
81507 + END_OF_ARGS);
81508 + FrameLen += tmp;
81509 + }
81510 +
81511 +#ifdef DOT11_N_SUPPORT
81512 + if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
81513 + {
81514 + UCHAR HtLen;
81515 +
81516 +#ifdef RT_BIG_ENDIAN
81517 + HT_CAPABILITY_IE HtCapabilityTmp;
81518 +#endif
81519 +
81520 + // add HT Capability IE
81521 + HtLen = sizeof(HT_CAPABILITY_IE);
81522 +#ifndef RT_BIG_ENDIAN
81523 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81524 + 1, &HtCapIe,
81525 + 1, &HtLen,
81526 + HtLen, &pAd->CommonCfg.HtCapability,
81527 + END_OF_ARGS);
81528 +#else
81529 + NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
81530 + *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
81531 + *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
81532 +
81533 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
81534 + 1, &HtCapIe,
81535 + 1, &HtLen,
81536 + HtLen, &HtCapabilityTmp,
81537 + END_OF_ARGS);
81538 +#endif
81539 + FrameLen = FrameLen + tmp;
81540 + }
81541 +#endif // DOT11_N_SUPPORT //
81542 +
81543 + if (pDLS && (pDLS->Status != DLS_FINISH))
81544 + {
81545 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
81546 + Timeout = DLS_TIMEOUT;
81547 + RTMPSetTimer(&pDLS->Timer, Timeout);
81548 + }
81549 + }
81550 + else
81551 + {
81552 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
81553 + sizeof(HEADER_802_11), &DlsRspHdr,
81554 + 1, &Category,
81555 + 1, &Action,
81556 + 2, &StatusCode,
81557 + 6, SA,
81558 + 6, pAd->CurrentAddress,
81559 + END_OF_ARGS);
81560 + }
81561 +
81562 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
81563 + MlmeFreeMemory(pAd, pOutBuffer);
81564 +}
81565 +
81566 +/*
81567 + ==========================================================================
81568 + Description:
81569 +
81570 + IRQL = DISPATCH_LEVEL
81571 +
81572 + ==========================================================================
81573 + */
81574 +VOID PeerDlsRspAction(
81575 + IN PRTMP_ADAPTER pAd,
81576 + IN MLME_QUEUE_ELEM *Elem)
81577 +{
81578 + USHORT CapabilityInfo;
81579 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
81580 + USHORT StatusCode;
81581 + SHORT i;
81582 + BOOLEAN TimerCancelled;
81583 + UCHAR MaxSupportedRateIn500Kbps = 0;
81584 + UCHAR SupportedRatesLen;
81585 + UCHAR SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
81586 + UCHAR HtCapabilityLen;
81587 + HT_CAPABILITY_IE HtCapability;
81588 +
81589 + if (!pAd->CommonCfg.bDLSCapable)
81590 + return;
81591 +
81592 + if (!INFRA_ON(pAd))
81593 + return;
81594 +
81595 + if (!PeerDlsRspSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &CapabilityInfo, &StatusCode,
81596 + &SupportedRatesLen, &SupportedRates[0], &HtCapabilityLen, &HtCapability))
81597 + return;
81598 +
81599 + // supported rates array may not be sorted. sort it and find the maximum rate
81600 + for (i=0; i<SupportedRatesLen; i++)
81601 + {
81602 + if (MaxSupportedRateIn500Kbps < (SupportedRates[i] & 0x7f))
81603 + MaxSupportedRateIn500Kbps = SupportedRates[i] & 0x7f;
81604 + }
81605 +
81606 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x with StatusCode=%d, CapabilityInfo=0x%x\n",
81607 + SA[0], SA[1], SA[2], SA[3], SA[4], SA[5], StatusCode, CapabilityInfo));
81608 +
81609 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
81610 + {
81611 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
81612 + {
81613 + if (StatusCode == MLME_SUCCESS)
81614 + {
81615 + MAC_TABLE_ENTRY *pEntry;
81616 + UCHAR MaxSupportedRate = RATE_11;
81617 +
81618 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
81619 +
81620 + switch (MaxSupportedRateIn500Kbps)
81621 + {
81622 + case 108: MaxSupportedRate = RATE_54; break;
81623 + case 96: MaxSupportedRate = RATE_48; break;
81624 + case 72: MaxSupportedRate = RATE_36; break;
81625 + case 48: MaxSupportedRate = RATE_24; break;
81626 + case 36: MaxSupportedRate = RATE_18; break;
81627 + case 24: MaxSupportedRate = RATE_12; break;
81628 + case 18: MaxSupportedRate = RATE_9; break;
81629 + case 12: MaxSupportedRate = RATE_6; break;
81630 + case 22: MaxSupportedRate = RATE_11; break;
81631 + case 11: MaxSupportedRate = RATE_5_5; break;
81632 + case 4: MaxSupportedRate = RATE_2; break;
81633 + case 2: MaxSupportedRate = RATE_1; break;
81634 + default: MaxSupportedRate = RATE_11; break;
81635 + }
81636 +
81637 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
81638 +
81639 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
81640 + {
81641 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
81642 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81643 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
81644 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81645 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
81646 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81647 + }
81648 + else
81649 + {
81650 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
81651 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81652 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
81653 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81654 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
81655 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81656 + }
81657 +
81658 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81659 + pEntry->MinHTPhyMode.field.BW = BW_20;
81660 +
81661 +#ifdef DOT11_N_SUPPORT
81662 + pEntry->HTCapability.MCSSet[0] = 0;
81663 + pEntry->HTCapability.MCSSet[1] = 0;
81664 +
81665 + // If this Entry supports 802.11n, upgrade to HT rate.
81666 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
81667 + {
81668 + UCHAR j, bitmask; //k,bitmask;
81669 + CHAR ii;
81670 +
81671 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
81672 + {
81673 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
81674 + }
81675 + else
81676 + {
81677 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81678 + pAd->MacTab.fAnyStationNonGF = TRUE;
81679 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
81680 + }
81681 +
81682 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
81683 + {
81684 + pEntry->MaxHTPhyMode.field.BW= BW_40;
81685 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
81686 + }
81687 + else
81688 + {
81689 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81690 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
81691 + pAd->MacTab.fAnyStation20Only = TRUE;
81692 + }
81693 +
81694 + // find max fixed rate
81695 + for (ii=15; ii>=0; ii--)
81696 + {
81697 + j = ii/8;
81698 + bitmask = (1<<(ii-(j*8)));
81699 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
81700 + {
81701 + pEntry->MaxHTPhyMode.field.MCS = ii;
81702 + break;
81703 + }
81704 + if (ii==0)
81705 + break;
81706 + }
81707 +
81708 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
81709 + {
81710 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
81711 + {
81712 + // Fix MCS as HT Duplicated Mode
81713 + pEntry->MaxHTPhyMode.field.BW = 1;
81714 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81715 + pEntry->MaxHTPhyMode.field.STBC = 0;
81716 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
81717 + pEntry->MaxHTPhyMode.field.MCS = 32;
81718 + }
81719 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
81720 + {
81721 + // STA supports fixed MCS
81722 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81723 + }
81724 + }
81725 +
81726 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
81727 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
81728 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
81729 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
81730 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
81731 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81732 +
81733 + if (HtCapability.HtCapInfo.ShortGIfor20)
81734 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
81735 + if (HtCapability.HtCapInfo.ShortGIfor40)
81736 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
81737 + if (HtCapability.HtCapInfo.TxSTBC)
81738 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
81739 + if (HtCapability.HtCapInfo.RxSTBC)
81740 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
81741 + if (HtCapability.ExtHtCapInfo.PlusHTC)
81742 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
81743 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
81744 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
81745 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
81746 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
81747 +
81748 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
81749 + }
81750 +#endif // DOT11_N_SUPPORT //
81751 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81752 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
81753 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
81754 +
81755 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
81756 + {
81757 + PUCHAR pTable;
81758 + UCHAR TableSize = 0;
81759 +
81760 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
81761 + pEntry->bAutoTxRateSwitch = TRUE;
81762 + }
81763 + else
81764 + {
81765 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
81766 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81767 + pEntry->bAutoTxRateSwitch = FALSE;
81768 +
81769 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
81770 + }
81771 + pEntry->RateLen = SupportedRatesLen;
81772 +
81773 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
81774 + {
81775 + // If support WPA or WPA2, start STAKey hand shake,
81776 + // If failed hand shake, just tear down peer DLS
81777 + if (RTMPSendSTAKeyRequest(pAd, pAd->StaCfg.DLSEntry[i].MacAddr) != NDIS_STATUS_SUCCESS)
81778 + {
81779 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81780 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
81781 +
81782 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81783 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
81784 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81785 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81786 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed when call RTMPSendSTAKeyRequest \n"));
81787 + }
81788 + else
81789 + {
81790 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
81791 + DBGPRINT(RT_DEBUG_TRACE,("DLS - waiting for STAKey handshake procedure\n"));
81792 + }
81793 + }
81794 + else
81795 + {
81796 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81797 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
81798 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x Succeed with WEP or no security\n", SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
81799 + }
81800 +
81801 + //initialize seq no for DLS frames.
81802 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
81803 + if (HtCapabilityLen != 0)
81804 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
81805 + else
81806 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
81807 + }
81808 + else
81809 + {
81810 + // DLS setup procedure failed.
81811 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
81812 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
81813 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
81814 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed with StatusCode=%d \n", StatusCode));
81815 + }
81816 + }
81817 + }
81818 +
81819 + if (i >= MAX_NUM_OF_INIT_DLS_ENTRY)
81820 + {
81821 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() update timeout value \n"));
81822 + for (i=(MAX_NUM_OF_DLS_ENTRY-1); i>=MAX_NUM_OF_INIT_DLS_ENTRY; i--)
81823 + {
81824 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
81825 + {
81826 + if (StatusCode == MLME_SUCCESS)
81827 + {
81828 + MAC_TABLE_ENTRY *pEntry;
81829 + UCHAR MaxSupportedRate = RATE_11;
81830 +
81831 + pEntry = MacTableInsertDlsEntry(pAd, SA, i);
81832 +
81833 + switch (MaxSupportedRateIn500Kbps)
81834 + {
81835 + case 108: MaxSupportedRate = RATE_54; break;
81836 + case 96: MaxSupportedRate = RATE_48; break;
81837 + case 72: MaxSupportedRate = RATE_36; break;
81838 + case 48: MaxSupportedRate = RATE_24; break;
81839 + case 36: MaxSupportedRate = RATE_18; break;
81840 + case 24: MaxSupportedRate = RATE_12; break;
81841 + case 18: MaxSupportedRate = RATE_9; break;
81842 + case 12: MaxSupportedRate = RATE_6; break;
81843 + case 22: MaxSupportedRate = RATE_11; break;
81844 + case 11: MaxSupportedRate = RATE_5_5; break;
81845 + case 4: MaxSupportedRate = RATE_2; break;
81846 + case 2: MaxSupportedRate = RATE_1; break;
81847 + default: MaxSupportedRate = RATE_11; break;
81848 + }
81849 +
81850 + pEntry->MaxSupportedRate = min(pAd->CommonCfg.MaxTxRate, MaxSupportedRate);
81851 +
81852 + if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)
81853 + {
81854 + pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
81855 + pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81856 + pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
81857 + pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81858 + pEntry->HTPhyMode.field.MODE = MODE_CCK;
81859 + pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
81860 + }
81861 + else
81862 + {
81863 + pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
81864 + pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81865 + pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
81866 + pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81867 + pEntry->HTPhyMode.field.MODE = MODE_OFDM;
81868 + pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
81869 + }
81870 +
81871 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81872 + pEntry->MinHTPhyMode.field.BW = BW_20;
81873 +
81874 +#ifdef DOT11_N_SUPPORT
81875 + pEntry->HTCapability.MCSSet[0] = 0;
81876 + pEntry->HTCapability.MCSSet[1] = 0;
81877 +
81878 + // If this Entry supports 802.11n, upgrade to HT rate.
81879 + if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
81880 + {
81881 + UCHAR j, bitmask; //k,bitmask;
81882 + CHAR ii;
81883 +
81884 + if ((HtCapability.HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
81885 + {
81886 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
81887 + }
81888 + else
81889 + {
81890 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81891 + pAd->MacTab.fAnyStationNonGF = TRUE;
81892 + pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
81893 + }
81894 +
81895 + if ((HtCapability.HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))
81896 + {
81897 + pEntry->MaxHTPhyMode.field.BW= BW_40;
81898 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(HtCapability.HtCapInfo.ShortGIfor40));
81899 + }
81900 + else
81901 + {
81902 + pEntry->MaxHTPhyMode.field.BW = BW_20;
81903 + pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(HtCapability.HtCapInfo.ShortGIfor20));
81904 + pAd->MacTab.fAnyStation20Only = TRUE;
81905 + }
81906 +
81907 + // find max fixed rate
81908 + for (ii=15; ii>=0; ii--)
81909 + {
81910 + j = ii/8;
81911 + bitmask = (1<<(ii-(j*8)));
81912 + if ( (pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j]&bitmask) && (HtCapability.MCSSet[j]&bitmask))
81913 + {
81914 + pEntry->MaxHTPhyMode.field.MCS = ii;
81915 + break;
81916 + }
81917 + if (ii==0)
81918 + break;
81919 + }
81920 +
81921 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)
81922 + {
81923 + printk("@@@ pAd->CommonCfg.RegTransmitSetting.field.MCS = %d\n",
81924 + pAd->StaCfg.DesiredTransmitSetting.field.MCS);
81925 + if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)
81926 + {
81927 + // Fix MCS as HT Duplicated Mode
81928 + pEntry->MaxHTPhyMode.field.BW = 1;
81929 + pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
81930 + pEntry->MaxHTPhyMode.field.STBC = 0;
81931 + pEntry->MaxHTPhyMode.field.ShortGI = 0;
81932 + pEntry->MaxHTPhyMode.field.MCS = 32;
81933 + }
81934 + else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)
81935 + {
81936 + // STA supports fixed MCS
81937 + pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81938 + }
81939 + }
81940 +
81941 + pEntry->MaxHTPhyMode.field.STBC = (HtCapability.HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
81942 + pEntry->MpduDensity = HtCapability.HtCapParm.MpduDensity;
81943 + pEntry->MaxRAmpduFactor = HtCapability.HtCapParm.MaxRAmpduFactor;
81944 + pEntry->MmpsMode = (UCHAR)HtCapability.HtCapInfo.MimoPs;
81945 + pEntry->AMsduSize = (UCHAR)HtCapability.HtCapInfo.AMsduSize;
81946 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81947 +
81948 + if (HtCapability.HtCapInfo.ShortGIfor20)
81949 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);
81950 + if (HtCapability.HtCapInfo.ShortGIfor40)
81951 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);
81952 + if (HtCapability.HtCapInfo.TxSTBC)
81953 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);
81954 + if (HtCapability.HtCapInfo.RxSTBC)
81955 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);
81956 + if (HtCapability.ExtHtCapInfo.PlusHTC)
81957 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);
81958 + if (pAd->CommonCfg.bRdg && HtCapability.ExtHtCapInfo.RDGSupport)
81959 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);
81960 + if (HtCapability.ExtHtCapInfo.MCSFeedback == 0x03)
81961 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
81962 +
81963 + NdisMoveMemory(&pEntry->HTCapability, &HtCapability, sizeof(HT_CAPABILITY_IE));
81964 + }
81965 +#endif // DOT11_N_SUPPORT //
81966 +
81967 + pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
81968 + pEntry->CurrTxRate = pEntry->MaxSupportedRate;
81969 + CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
81970 +
81971 + if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)
81972 + {
81973 + PUCHAR pTable;
81974 + UCHAR TableSize = 0;
81975 +
81976 + MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);
81977 + pEntry->bAutoTxRateSwitch = TRUE;
81978 + }
81979 + else
81980 + {
81981 + pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
81982 + pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
81983 + pEntry->bAutoTxRateSwitch = FALSE;
81984 +
81985 + RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
81986 + }
81987 + pEntry->RateLen = SupportedRatesLen;
81988 +
81989 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
81990 + {
81991 + // If support WPA or WPA2, start STAKey hand shake,
81992 + // If failed hand shake, just tear down peer DLS
81993 + if (RTMPSendSTAKeyRequest(pAd, pAd->StaCfg.DLSEntry[i].MacAddr) != NDIS_STATUS_SUCCESS)
81994 + {
81995 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
81996 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
81997 +
81998 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
81999 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
82000 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82001 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82002 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed when call RTMPSendSTAKeyRequest \n"));
82003 + }
82004 + else
82005 + {
82006 + pAd->StaCfg.DLSEntry[i].Status = DLS_WAIT_KEY;
82007 + DBGPRINT(RT_DEBUG_TRACE,("DLS - waiting for STAKey handshake procedure\n"));
82008 + }
82009 + }
82010 + else
82011 + {
82012 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82013 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
82014 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsRspAction() from %02x:%02x:%02x:%02x:%02x:%02x Succeed with WEP or no security\n", SA[0], SA[1], SA[2], SA[3], SA[4], SA[5]));
82015 + }
82016 + pAd->StaCfg.DLSEntry[i].Sequence = 0;
82017 + if (HtCapabilityLen != 0)
82018 + pAd->StaCfg.DLSEntry[i].bHTCap = TRUE;
82019 + else
82020 + pAd->StaCfg.DLSEntry[i].bHTCap = FALSE;
82021 + }
82022 + else
82023 + {
82024 + // DLS setup procedure failed.
82025 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82026 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82027 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82028 + DBGPRINT(RT_DEBUG_ERROR,("DLS - PeerDlsRspAction failed with StatusCode=%d \n", StatusCode));
82029 + }
82030 + }
82031 + }
82032 + }
82033 +}
82034 +
82035 +/*
82036 + ==========================================================================
82037 + Description:
82038 +
82039 + IRQL = DISPATCH_LEVEL
82040 +
82041 + ==========================================================================
82042 + */
82043 +VOID MlmeDlsTearDownAction(
82044 + IN PRTMP_ADAPTER pAd,
82045 + IN MLME_QUEUE_ELEM *Elem)
82046 +{
82047 + PUCHAR pOutBuffer = NULL;
82048 + NDIS_STATUS NStatus;
82049 + ULONG FrameLen = 0;
82050 + UCHAR Category = CATEGORY_DLS;
82051 + UCHAR Action = ACTION_DLS_TEARDOWN;
82052 + USHORT ReasonCode = REASON_QOS_UNSPECIFY;
82053 + HEADER_802_11 DlsTearDownHdr;
82054 + PRT_802_11_DLS pDLS;
82055 + BOOLEAN TimerCancelled;
82056 + UCHAR i;
82057 +
82058 + if(!MlmeDlsReqSanity(pAd, Elem->Msg, Elem->MsgLen, &pDLS, &ReasonCode))
82059 + return;
82060 +
82061 + DBGPRINT(RT_DEBUG_TRACE,("DLS - MlmeDlsTearDownAction() with ReasonCode=%d \n", ReasonCode));
82062 +
82063 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
82064 + if (NStatus != NDIS_STATUS_SUCCESS)
82065 + {
82066 + DBGPRINT(RT_DEBUG_ERROR,("DLS - MlmeDlsTearDownAction() allocate memory failed \n"));
82067 + return;
82068 + }
82069 +
82070 + ActHeaderInit(pAd, &DlsTearDownHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
82071 +
82072 + // Build basic frame first
82073 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82074 + sizeof(HEADER_802_11), &DlsTearDownHdr,
82075 + 1, &Category,
82076 + 1, &Action,
82077 + 6, &pDLS->MacAddr,
82078 + 6, pAd->CurrentAddress,
82079 + 2, &ReasonCode,
82080 + END_OF_ARGS);
82081 +
82082 + MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
82083 + MlmeFreeMemory(pAd, pOutBuffer);
82084 + RTMPCancelTimer(&pDLS->Timer, &TimerCancelled);
82085 +
82086 + // Remove key in local dls table entry
82087 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82088 + {
82089 + if (MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
82090 + {
82091 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82092 + }
82093 + }
82094 +
82095 + // clear peer dls table entry
82096 + for (i = MAX_NUM_OF_INIT_DLS_ENTRY; i < MAX_NUM_OF_DLS_ENTRY; i++)
82097 + {
82098 + if (MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
82099 + {
82100 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82101 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82102 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82103 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82104 + }
82105 + }
82106 +}
82107 +
82108 +/*
82109 + ==========================================================================
82110 + Description:
82111 +
82112 + IRQL = DISPATCH_LEVEL
82113 +
82114 + ==========================================================================
82115 + */
82116 +VOID PeerDlsTearDownAction(
82117 + IN PRTMP_ADAPTER pAd,
82118 + IN MLME_QUEUE_ELEM *Elem)
82119 +{
82120 + UCHAR DA[MAC_ADDR_LEN], SA[MAC_ADDR_LEN];
82121 + USHORT ReasonCode;
82122 + UINT i;
82123 + BOOLEAN TimerCancelled;
82124 +
82125 + if (!pAd->CommonCfg.bDLSCapable)
82126 + return;
82127 +
82128 + if (!INFRA_ON(pAd))
82129 + return;
82130 +
82131 + if (!PeerDlsTearDownSanity(pAd, Elem->Msg, Elem->MsgLen, DA, SA, &ReasonCode))
82132 + return;
82133 +
82134 + DBGPRINT(RT_DEBUG_TRACE,("DLS - PeerDlsTearDownAction() from %02x:%02x:%02x:%02x:%02x:%02x with ReasonCode=%d\n", SA[0], SA[1], SA[2], SA[3], SA[4], SA[5], ReasonCode));
82135 +
82136 + // clear local dls table entry
82137 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82138 + {
82139 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
82140 + {
82141 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82142 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82143 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82144 + //AsicDelWcidTab(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
82145 + //AsicRemovePairwiseKeyEntry(pAd, BSS0, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
82146 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82147 + }
82148 + }
82149 +
82150 + // clear peer dls table entry
82151 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
82152 + {
82153 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(SA, pAd->StaCfg.DLSEntry[i].MacAddr))
82154 + {
82155 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82156 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82157 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82158 + //AsicDelWcidTab(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
82159 + //AsicRemovePairwiseKeyEntry(pAd, BSS0, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID);
82160 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82161 + }
82162 + }
82163 +}
82164 +
82165 +/*
82166 + ==========================================================================
82167 + Description:
82168 +
82169 + IRQL = DISPATCH_LEVEL
82170 +
82171 + ==========================================================================
82172 + */
82173 +VOID RTMPCheckDLSTimeOut(
82174 + IN PRTMP_ADAPTER pAd)
82175 +{
82176 + ULONG i;
82177 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
82178 + USHORT reason = REASON_QOS_UNSPECIFY;
82179 +
82180 + if (! pAd->CommonCfg.bDLSCapable)
82181 + return;
82182 +
82183 + if (! INFRA_ON(pAd))
82184 + return;
82185 +
82186 + // If timeout value is equaled to zero, it means always not be timeout.
82187 +
82188 + // update local dls table entry
82189 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82190 + {
82191 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82192 + && (pAd->StaCfg.DLSEntry[i].TimeOut != 0))
82193 + {
82194 + pAd->StaCfg.DLSEntry[i].CountDownTimer --;
82195 +
82196 + if (pAd->StaCfg.DLSEntry[i].CountDownTimer == 0)
82197 + {
82198 + reason = REASON_QOS_REQUEST_TIMEOUT;
82199 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82200 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82201 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
82202 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
82203 + }
82204 + }
82205 + }
82206 +
82207 + // update peer dls table entry
82208 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
82209 + {
82210 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82211 + && (pAd->StaCfg.DLSEntry[i].TimeOut != 0))
82212 + {
82213 + pAd->StaCfg.DLSEntry[i].CountDownTimer --;
82214 +
82215 + if (pAd->StaCfg.DLSEntry[i].CountDownTimer == 0)
82216 + {
82217 + reason = REASON_QOS_REQUEST_TIMEOUT;
82218 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82219 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82220 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
82221 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
82222 + }
82223 + }
82224 + }
82225 +}
82226 +
82227 +/*
82228 + ==========================================================================
82229 + Description:
82230 +
82231 + IRQL = DISPATCH_LEVEL
82232 +
82233 + ==========================================================================
82234 + */
82235 +BOOLEAN RTMPRcvFrameDLSCheck(
82236 + IN PRTMP_ADAPTER pAd,
82237 + IN PHEADER_802_11 pHeader,
82238 + IN ULONG Len,
82239 + IN PRT28XX_RXD_STRUC pRxD)
82240 +{
82241 + ULONG i;
82242 + BOOLEAN bFindEntry = FALSE;
82243 + BOOLEAN bSTAKeyFrame = FALSE;
82244 + PEAPOL_PACKET pEap;
82245 + PUCHAR pProto, pAddr = NULL;
82246 + PUCHAR pSTAKey = NULL;
82247 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
82248 + UCHAR Mic[16], OldMic[16];
82249 + UCHAR digest[80];
82250 + UCHAR DlsPTK[80];
82251 + UCHAR temp[64];
82252 + BOOLEAN TimerCancelled;
82253 + CIPHER_KEY PairwiseKey;
82254 +
82255 +
82256 + if (! pAd->CommonCfg.bDLSCapable)
82257 + return bSTAKeyFrame;
82258 +
82259 + if (! INFRA_ON(pAd))
82260 + return bSTAKeyFrame;
82261 +
82262 + if (! (pHeader->FC.SubType & 0x08))
82263 + return bSTAKeyFrame;
82264 +
82265 + if (Len < LENGTH_802_11 + 6 + 2 + 2)
82266 + return bSTAKeyFrame;
82267 +
82268 + pProto = (PUCHAR)pHeader + LENGTH_802_11 + 2 + 6; // QOS Control field , 0xAA 0xAA 0xAA 0x00 0x00 0x00
82269 + pAddr = pHeader->Addr2;
82270 +
82271 + // L2PAD bit on will pad 2 bytes at LLC
82272 + if (pRxD->L2PAD)
82273 + {
82274 + pProto += 2;
82275 + }
82276 +
82277 + if (RTMPEqualMemory(EAPOL, pProto, 2) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
82278 + {
82279 + pEap = (PEAPOL_PACKET) (pProto + 2);
82280 +
82281 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Sniff Len=%ld, DataLen=%d, KeyMic=%d, Install=%d, KeyAck=%d, Secure=%d, EKD_DL=%d, Error=%d, Request=%d\n", Len,
82282 + (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE + 16),
82283 + pEap->KeyDesc.KeyInfo.KeyMic,
82284 + pEap->KeyDesc.KeyInfo.Install,
82285 + pEap->KeyDesc.KeyInfo.KeyAck,
82286 + pEap->KeyDesc.KeyInfo.Secure,
82287 + pEap->KeyDesc.KeyInfo.EKD_DL,
82288 + pEap->KeyDesc.KeyInfo.Error,
82289 + pEap->KeyDesc.KeyInfo.Request));
82290 +
82291 + if ((Len >= (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE + 16)) && pEap->KeyDesc.KeyInfo.KeyMic
82292 + && pEap->KeyDesc.KeyInfo.Install && pEap->KeyDesc.KeyInfo.KeyAck && pEap->KeyDesc.KeyInfo.Secure
82293 + && pEap->KeyDesc.KeyInfo.EKD_DL && !pEap->KeyDesc.KeyInfo.Error && !pEap->KeyDesc.KeyInfo.Request)
82294 + {
82295 + // First validate replay counter, only accept message with larger replay counter
82296 + // Let equal pass, some AP start with all zero replay counter
82297 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
82298 + if ((RTMPCompareMemory(pEap->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1) &&
82299 + (RTMPCompareMemory(pEap->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
82300 + return bSTAKeyFrame;
82301 +
82302 + //RTMPMoveMemory(pAd->StaCfg.ReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
82303 + RTMPMoveMemory(pAd->StaCfg.DlsReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
82304 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Sniff replay counter (%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x) Len=%ld, KeyDataLen=%d\n",
82305 + pAd->StaCfg.ReplayCounter[0], pAd->StaCfg.ReplayCounter[1], pAd->StaCfg.ReplayCounter[2],
82306 + pAd->StaCfg.ReplayCounter[3], pAd->StaCfg.ReplayCounter[4], pAd->StaCfg.ReplayCounter[5],
82307 + pAd->StaCfg.ReplayCounter[6], pAd->StaCfg.ReplayCounter[7], Len, pEap->KeyDesc.KeyData[1]));
82308 +
82309 + // put these code segment to get the replay counter
82310 + if (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
82311 + return bSTAKeyFrame;
82312 +
82313 + // Check MIC value
82314 + // Save the MIC and replace with zero
82315 + // use proprietary PTK
82316 + NdisZeroMemory(temp, 64);
82317 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
82318 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
82319 +
82320 + NdisMoveMemory(OldMic, pEap->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
82321 + NdisZeroMemory(pEap->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
82322 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
82323 + {
82324 + // AES
82325 + HMAC_SHA1((PUCHAR) pEap, pEap->Body_Len[1] + 4, DlsPTK, LEN_EAP_MICK, digest);
82326 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
82327 + }
82328 + else
82329 + {
82330 + hmac_md5(DlsPTK, LEN_EAP_MICK, (PUCHAR) pEap, pEap->Body_Len[1] + 4, Mic);
82331 + }
82332 +
82333 + if (!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
82334 + {
82335 + DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in Msg1 of STAKey handshake! \n"));
82336 + return bSTAKeyFrame;
82337 + }
82338 + else
82339 + DBGPRINT(RT_DEBUG_TRACE, ("MIC VALID in Msg1 of STAKey handshake! \n"));
82340 +#if 1
82341 + if ((pEap->KeyDesc.KeyData[0] == 0xDD) && (pEap->KeyDesc.KeyData[2] == 0x00) && (pEap->KeyDesc.KeyData[3] == 0x0C)
82342 + && (pEap->KeyDesc.KeyData[4] == 0x43) && (pEap->KeyDesc.KeyData[5] == 0x02))
82343 + {
82344 + pAddr = pEap->KeyDesc.KeyData + 8; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2)
82345 + pSTAKey = pEap->KeyDesc.KeyData + 14; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2), STAKey_Mac_Addr(6)
82346 +
82347 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 from %02x:%02x:%02x:%02x:%02x:%02x Len=%ld, KeyDataLen=%d\n",
82348 + pAddr[0], pAddr[1], pAddr[2], pAddr[3], pAddr[4], pAddr[5], Len, pEap->KeyDesc.KeyData[1]));
82349 +
82350 + bSTAKeyFrame = TRUE;
82351 + }
82352 +#else
82353 + if ((pEap->KeyDesc.KeyData[0] == 0xDD) && (pEap->KeyDesc.KeyData[2] == 0x00) && (pEap->KeyDesc.KeyData[3] == 0x0F)
82354 + && (pEap->KeyDesc.KeyData[4] == 0xAC) && (pEap->KeyDesc.KeyData[5] == 0x02))
82355 + {
82356 + pAddr = pEap->KeyDesc.KeyData + 8; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2)
82357 + pSTAKey = pEap->KeyDesc.KeyData + 14; // Tpe(1), Len(1), OUI(3), DataType(1), Reserved(2), STAKey_Mac_Addr(6)
82358 +
82359 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 from %02x:%02x:%02x:%02x:%02x:%02x Len=%d, KeyDataLen=%d\n",
82360 + pAddr[0], pAddr[1], pAddr[2], pAddr[3], pAddr[4], pAddr[5], Len, pEap->KeyDesc.KeyData[1]));
82361 +
82362 + bSTAKeyFrame = TRUE;
82363 + }
82364 +#endif
82365 +
82366 + }
82367 + else if (Len >= (LENGTH_802_11 + 6 + 2 + 2 + sizeof(EAPOL_PACKET) - MAX_LEN_OF_RSNIE))
82368 + {
82369 + RTMPMoveMemory(pAd->StaCfg.DlsReplayCounter, pEap->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
82370 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Sniff replay counter 2(%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x) Len=%ld, KeyDataLen=%d\n",
82371 + pAd->StaCfg.ReplayCounter[0], pAd->StaCfg.ReplayCounter[1], pAd->StaCfg.ReplayCounter[2],
82372 + pAd->StaCfg.ReplayCounter[3], pAd->StaCfg.ReplayCounter[4], pAd->StaCfg.ReplayCounter[5],
82373 + pAd->StaCfg.ReplayCounter[6], pAd->StaCfg.ReplayCounter[7], Len, pEap->KeyDesc.KeyData[1]));
82374 +
82375 + }
82376 + }
82377 +
82378 + // If timeout value is equaled to zero, it means always not be timeout.
82379 + // update local dls table entry
82380 + for (i= 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82381 + {
82382 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(pAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
82383 + {
82384 + if (bSTAKeyFrame)
82385 + {
82386 + PMAC_TABLE_ENTRY pEntry;
82387 +
82388 + // STAKey frame, add pairwise key table
82389 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
82390 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82391 +
82392 + PairwiseKey.KeyLen = LEN_TKIP_EK;
82393 + NdisMoveMemory(PairwiseKey.Key, &pSTAKey[0], LEN_TKIP_EK);
82394 + NdisMoveMemory(PairwiseKey.TxMic, &pSTAKey[16], LEN_TKIP_RXMICK);
82395 + NdisMoveMemory(PairwiseKey.RxMic, &pSTAKey[24], LEN_TKIP_TXMICK);
82396 +
82397 + PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg;
82398 +
82399 + pEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
82400 + //AsicAddKeyEntry(pAd, (USHORT)(i + 2), BSS0, 0, &PairwiseKey, TRUE, TRUE); // reserve 0 for multicast, 1 for unicast
82401 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
82402 + // Add Pair-wise key to Asic
82403 +#ifdef RT2870
82404 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 -->
82405 + {
82406 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
82407 + COPY_MAC_ADDR(KeyInfo.MacAddr,pAd->StaCfg.DLSEntry[i].MacAddr);
82408 + KeyInfo.MacTabMatchWCID=pAd->StaCfg.DLSEntry[i].MacTabMatchWCID;
82409 + NdisMoveMemory(&KeyInfo.CipherKey, &PairwiseKey,sizeof(CIPHER_KEY));
82410 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_KEY_TABLE, &KeyInfo, sizeof(RT_ADD_PAIRWISE_KEY_ENTRY));
82411 + }
82412 + {
82413 + PMAC_TABLE_ENTRY pDLSEntry;
82414 + pDLSEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
82415 + pDLSEntry->PairwiseKey.CipherAlg=PairwiseKey.CipherAlg;
82416 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_RX_WCID_TABLE, pDLSEntry, sizeof(MAC_TABLE_ENTRY));
82417 + }
82418 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 <--
82419 +#endif // RT2870 //
82420 + NdisMoveMemory(&pEntry->PairwiseKey, &PairwiseKey, sizeof(CIPHER_KEY));
82421 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 (Peer STA MAC Address STAKey) \n"));
82422 +
82423 + RTMPSendSTAKeyHandShake(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
82424 +
82425 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Finish STAKey handshake procedure (Initiator side)\n"));
82426 + }
82427 + else
82428 + {
82429 + // Data frame, update timeout value
82430 + if (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82431 + {
82432 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
82433 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
82434 + }
82435 + }
82436 +
82437 + bFindEntry = TRUE;
82438 + }
82439 + }
82440 +
82441 + // update peer dls table entry
82442 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
82443 + {
82444 + if (pAd->StaCfg.DLSEntry[i].Valid && MAC_ADDR_EQUAL(pAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
82445 + {
82446 + if (bSTAKeyFrame)
82447 + {
82448 + PMAC_TABLE_ENTRY pEntry = NULL;
82449 +
82450 + // STAKey frame, add pairwise key table, and send STAkey Msg-2
82451 + pAd->StaCfg.DLSEntry[i].Status = DLS_FINISH;
82452 + RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &TimerCancelled);
82453 +
82454 + PairwiseKey.KeyLen = LEN_TKIP_EK;
82455 + NdisMoveMemory(PairwiseKey.Key, &pSTAKey[0], LEN_TKIP_EK);
82456 + NdisMoveMemory(PairwiseKey.TxMic, &pSTAKey[16], LEN_TKIP_RXMICK);
82457 + NdisMoveMemory(PairwiseKey.RxMic, &pSTAKey[24], LEN_TKIP_TXMICK);
82458 +
82459 + PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg;
82460 +
82461 + pEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
82462 + //AsicAddKeyEntry(pAd, (USHORT)(i + 2), BSS0, 0, &PairwiseKey, TRUE, TRUE); // reserve 0 for multicast, 1 for unicast
82463 + //AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr);
82464 + // Add Pair-wise key to Asic
82465 +#ifdef RT2870
82466 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 -->
82467 + {
82468 + RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo;
82469 + COPY_MAC_ADDR(KeyInfo.MacAddr,pAd->StaCfg.DLSEntry[i].MacAddr);
82470 + KeyInfo.MacTabMatchWCID=pAd->StaCfg.DLSEntry[i].MacTabMatchWCID;
82471 + NdisMoveMemory(&KeyInfo.CipherKey, &PairwiseKey,sizeof(CIPHER_KEY));
82472 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_KEY_TABLE, &KeyInfo, sizeof(RT_ADD_PAIRWISE_KEY_ENTRY));
82473 + }
82474 + {
82475 + PMAC_TABLE_ENTRY pDLSEntry;
82476 + pDLSEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE);
82477 + pDLSEntry->PairwiseKey.CipherAlg=PairwiseKey.CipherAlg;
82478 + RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_RX_WCID_TABLE, pDLSEntry, sizeof(MAC_TABLE_ENTRY));
82479 + }
82480 +//Benson modified for USB interface, avoid in interrupt when write key, 20080724 <--
82481 +#endif // RT2870 //
82482 + NdisMoveMemory(&pEntry->PairwiseKey, &PairwiseKey, sizeof(CIPHER_KEY));
82483 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 (Initiator STA MAC Address STAKey)\n"));
82484 +
82485 + // If support WPA or WPA2, start STAKey hand shake,
82486 + // If failed hand shake, just tear down peer DLS
82487 + if (RTMPSendSTAKeyHandShake(pAd, pAddr) != NDIS_STATUS_SUCCESS)
82488 + {
82489 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
82490 + USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT;
82491 +
82492 + pAd->StaCfg.DLSEntry[i].Valid = FALSE;
82493 + pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
82494 + DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
82495 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
82496 + }
82497 + else
82498 + {
82499 + DBGPRINT(RT_DEBUG_TRACE,("DLS - Finish STAKey handshake procedure (Peer side)\n"));
82500 + }
82501 + }
82502 + else
82503 + {
82504 + // Data frame, update timeout value
82505 + if (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82506 + {
82507 + pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
82508 + }
82509 + }
82510 +
82511 + bFindEntry = TRUE;
82512 + }
82513 + }
82514 +
82515 +
82516 + return bSTAKeyFrame;
82517 +}
82518 +
82519 +/*
82520 + ========================================================================
82521 +
82522 + Routine Description:
82523 + Check if the frame can be sent through DLS direct link interface
82524 +
82525 + Arguments:
82526 + pAd Pointer to adapter
82527 +
82528 + Return Value:
82529 + DLS entry index
82530 +
82531 + Note:
82532 +
82533 + ========================================================================
82534 +*/
82535 +INT RTMPCheckDLSFrame(
82536 + IN PRTMP_ADAPTER pAd,
82537 + IN PUCHAR pDA)
82538 +{
82539 + INT rval = -1;
82540 + INT i;
82541 +
82542 + if (!pAd->CommonCfg.bDLSCapable)
82543 + return rval;
82544 +
82545 + if (!INFRA_ON(pAd))
82546 + return rval;
82547 +
82548 + do{
82549 + // check local dls table entry
82550 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82551 + {
82552 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
82553 + MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
82554 + {
82555 + rval = i;
82556 + break;
82557 + }
82558 + }
82559 +
82560 + // check peer dls table entry
82561 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
82562 + {
82563 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
82564 + MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
82565 + {
82566 + rval = i;
82567 + break;
82568 + }
82569 + }
82570 + } while (FALSE);
82571 +
82572 + return rval;
82573 +}
82574 +
82575 +/*
82576 + ==========================================================================
82577 + Description:
82578 +
82579 + IRQL = DISPATCH_LEVEL
82580 +
82581 + ==========================================================================
82582 + */
82583 +VOID RTMPSendDLSTearDownFrame(
82584 + IN PRTMP_ADAPTER pAd,
82585 + IN PUCHAR pDA)
82586 +{
82587 + PUCHAR pOutBuffer = NULL;
82588 + NDIS_STATUS NStatus;
82589 + HEADER_802_11 DlsTearDownHdr;
82590 + ULONG FrameLen = 0;
82591 + USHORT Reason = REASON_QOS_QSTA_LEAVING_QBSS;
82592 + UCHAR Category = CATEGORY_DLS;
82593 + UCHAR Action = ACTION_DLS_TEARDOWN;
82594 + UCHAR i = 0;
82595 +
82596 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
82597 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
82598 + return;
82599 +
82600 + DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame \n"));
82601 +
82602 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
82603 + if (NStatus != NDIS_STATUS_SUCCESS)
82604 + {
82605 + DBGPRINT(RT_DEBUG_ERROR,("ASSOC - RTMPSendDLSTearDownFrame() allocate memory failed \n"));
82606 + return;
82607 + }
82608 +
82609 + ActHeaderInit(pAd, &DlsTearDownHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid);
82610 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82611 + sizeof(HEADER_802_11), &DlsTearDownHdr,
82612 + 1, &Category,
82613 + 1, &Action,
82614 + 6, pDA,
82615 + 6, pAd->CurrentAddress,
82616 + 2, &Reason,
82617 + END_OF_ARGS);
82618 +
82619 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
82620 + MlmeFreeMemory(pAd, pOutBuffer);
82621 +
82622 + // Remove key in local dls table entry
82623 + for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++)
82624 + {
82625 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82626 + && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
82627 + {
82628 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82629 + }
82630 + }
82631 +
82632 + // Remove key in peer dls table entry
82633 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
82634 + {
82635 + if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH)
82636 + && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr))
82637 + {
82638 + MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr);
82639 + }
82640 + }
82641 +
82642 + DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame and remove key in (i=%d) \n", i));
82643 +}
82644 +
82645 +/*
82646 + ==========================================================================
82647 + Description:
82648 +
82649 + IRQL = DISPATCH_LEVEL
82650 +
82651 + ==========================================================================
82652 + */
82653 +NDIS_STATUS RTMPSendSTAKeyRequest(
82654 + IN PRTMP_ADAPTER pAd,
82655 + IN PUCHAR pDA)
82656 +{
82657 + UCHAR Header802_3[14];
82658 + NDIS_STATUS NStatus;
82659 + ULONG FrameLen = 0;
82660 + EAPOL_PACKET Packet;
82661 + UCHAR Mic[16];
82662 + UCHAR digest[80];
82663 + PUCHAR pOutBuffer = NULL;
82664 + PNDIS_PACKET pNdisPacket;
82665 + UCHAR temp[64];
82666 + UCHAR DlsPTK[80];
82667 +
82668 + DBGPRINT(RT_DEBUG_TRACE,("DLS - RTMPSendSTAKeyRequest() to %02x:%02x:%02x:%02x:%02x:%02x\n", pDA[0], pDA[1], pDA[2], pDA[3], pDA[4], pDA[5]));
82669 +
82670 + pAd->Sequence ++;
82671 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
82672 +
82673 + // Zero message body
82674 + NdisZeroMemory(&Packet, sizeof(Packet));
82675 + Packet.ProVer = EAPOL_VER;
82676 + Packet.ProType = EAPOLKey;
82677 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE andPeer MAC address
82678 +
82679 + // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE)
82680 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
82681 + {
82682 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
82683 + }
82684 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
82685 + {
82686 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
82687 + }
82688 +
82689 + // Key descriptor version
82690 + Packet.KeyDesc.KeyInfo.KeyDescVer =
82691 + (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
82692 +
82693 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
82694 + Packet.KeyDesc.KeyInfo.Secure = 1;
82695 + Packet.KeyDesc.KeyInfo.Request = 1;
82696 +
82697 + Packet.KeyDesc.KeyDataLen[1] = 12;
82698 +
82699 + // use our own OUI to distinguish proprietary with standard.
82700 + Packet.KeyDesc.KeyData[0] = 0xDD;
82701 + Packet.KeyDesc.KeyData[1] = 0x0A;
82702 + Packet.KeyDesc.KeyData[2] = 0x00;
82703 + Packet.KeyDesc.KeyData[3] = 0x0C;
82704 + Packet.KeyDesc.KeyData[4] = 0x43;
82705 + Packet.KeyDesc.KeyData[5] = 0x03;
82706 + NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN);
82707 +
82708 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY);
82709 +
82710 + // Allocate buffer for transmitting message
82711 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
82712 + if (NStatus != NDIS_STATUS_SUCCESS)
82713 + return NStatus;
82714 +
82715 + // Prepare EAPOL frame for MIC calculation
82716 + // Be careful, only EAPOL frame is counted for MIC calculation
82717 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82718 + Packet.Body_Len[1] + 4, &Packet,
82719 + END_OF_ARGS);
82720 +
82721 + // use proprietary PTK
82722 + NdisZeroMemory(temp, 64);
82723 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
82724 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
82725 +
82726 + // calculate MIC
82727 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
82728 + {
82729 + // AES
82730 + NdisZeroMemory(digest, sizeof(digest));
82731 + HMAC_SHA1(pOutBuffer, FrameLen, DlsPTK, LEN_EAP_MICK, digest);
82732 + NdisMoveMemory(Packet.KeyDesc.KeyMic, digest, LEN_KEY_DESC_MIC);
82733 + }
82734 + else
82735 + {
82736 + NdisZeroMemory(Mic, sizeof(Mic));
82737 + hmac_md5(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
82738 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
82739 + }
82740 +
82741 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82742 + sizeof(Header802_3), Header802_3,
82743 + Packet.Body_Len[1] + 4, &Packet,
82744 + END_OF_ARGS);
82745 +
82746 + NStatus = RTMPAllocateNdisPacket(pAd, &pNdisPacket, NULL, 0, pOutBuffer, FrameLen);
82747 + if (NStatus == NDIS_STATUS_SUCCESS)
82748 + {
82749 + RTMP_SET_PACKET_WCID(pNdisPacket, BSSID_WCID);
82750 + STASendPacket(pAd, pNdisPacket);
82751 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
82752 + }
82753 +
82754 + MlmeFreeMemory(pAd, pOutBuffer);
82755 +
82756 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSendSTAKeyRequest- Send STAKey request (NStatus=%x, FrameLen=%ld)\n", NStatus, FrameLen));
82757 +
82758 + return NStatus;
82759 +}
82760 +
82761 +/*
82762 + ==========================================================================
82763 + Description:
82764 +
82765 + IRQL = DISPATCH_LEVEL
82766 +
82767 + ==========================================================================
82768 + */
82769 +NDIS_STATUS RTMPSendSTAKeyHandShake(
82770 + IN PRTMP_ADAPTER pAd,
82771 + IN PUCHAR pDA)
82772 +{
82773 + UCHAR Header802_3[14];
82774 + NDIS_STATUS NStatus;
82775 + ULONG FrameLen = 0;
82776 + EAPOL_PACKET Packet;
82777 + UCHAR Mic[16];
82778 + UCHAR digest[80];
82779 + PUCHAR pOutBuffer = NULL;
82780 + PNDIS_PACKET pNdisPacket;
82781 + UCHAR temp[64];
82782 + UCHAR DlsPTK[80]; // Due to dirver can not get PTK, use proprietary PTK
82783 +
82784 + DBGPRINT(RT_DEBUG_TRACE,("DLS - RTMPSendSTAKeyHandShake() to %02x:%02x:%02x:%02x:%02x:%02x\n", pDA[0], pDA[1], pDA[2], pDA[3], pDA[4], pDA[5]));
82785 +
82786 + pAd->Sequence ++;
82787 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
82788 +
82789 + // Zero message body
82790 + NdisZeroMemory(&Packet, sizeof(Packet));
82791 + Packet.ProVer = EAPOL_VER;
82792 + Packet.ProType = EAPOLKey;
82793 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE and Peer MAC address
82794 +
82795 + // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE)
82796 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
82797 + {
82798 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
82799 + }
82800 + else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
82801 + {
82802 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
82803 + }
82804 +
82805 + // Key descriptor version
82806 + Packet.KeyDesc.KeyInfo.KeyDescVer =
82807 + (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
82808 +
82809 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
82810 + Packet.KeyDesc.KeyInfo.Secure = 1;
82811 +
82812 + Packet.KeyDesc.KeyDataLen[1] = 12;
82813 +
82814 + // use our own OUI to distinguish proprietary with standard.
82815 + Packet.KeyDesc.KeyData[0] = 0xDD;
82816 + Packet.KeyDesc.KeyData[1] = 0x0A;
82817 + Packet.KeyDesc.KeyData[2] = 0x00;
82818 + Packet.KeyDesc.KeyData[3] = 0x0C;
82819 + Packet.KeyDesc.KeyData[4] = 0x43;
82820 + Packet.KeyDesc.KeyData[5] = 0x03;
82821 + NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN);
82822 +
82823 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY);
82824 +
82825 + // Allocate buffer for transmitting message
82826 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
82827 + if (NStatus != NDIS_STATUS_SUCCESS)
82828 + return NStatus;
82829 +
82830 + // Prepare EAPOL frame for MIC calculation
82831 + // Be careful, only EAPOL frame is counted for MIC calculation
82832 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82833 + Packet.Body_Len[1] + 4, &Packet,
82834 + END_OF_ARGS);
82835 +
82836 + // use proprietary PTK
82837 + NdisZeroMemory(temp, 64);
82838 + NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32);
82839 + WpaCountPTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK);
82840 +
82841 + // calculate MIC
82842 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
82843 + {
82844 + // AES
82845 + NdisZeroMemory(digest, sizeof(digest));
82846 + HMAC_SHA1(pOutBuffer, FrameLen, DlsPTK, LEN_EAP_MICK, digest);
82847 + NdisMoveMemory(Packet.KeyDesc.KeyMic, digest, LEN_KEY_DESC_MIC);
82848 + }
82849 + else
82850 + {
82851 + NdisZeroMemory(Mic, sizeof(Mic));
82852 + hmac_md5(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
82853 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
82854 + }
82855 +
82856 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
82857 + sizeof(Header802_3), Header802_3,
82858 + Packet.Body_Len[1] + 4, &Packet,
82859 + END_OF_ARGS);
82860 +
82861 + NStatus = RTMPAllocateNdisPacket(pAd, &pNdisPacket, NULL, 0, pOutBuffer, FrameLen);
82862 + if (NStatus == NDIS_STATUS_SUCCESS)
82863 + {
82864 + RTMP_SET_PACKET_WCID(pNdisPacket, BSSID_WCID);
82865 + STASendPacket(pAd, pNdisPacket);
82866 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
82867 + }
82868 +
82869 + MlmeFreeMemory(pAd, pOutBuffer);
82870 +
82871 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPSendSTAKeyHandShake- Send STAKey Message-2 (NStatus=%x, FrameLen=%ld)\n", NStatus, FrameLen));
82872 +
82873 + return NStatus;
82874 +}
82875 +
82876 +VOID DlsTimeoutAction(
82877 + IN PVOID SystemSpecific1,
82878 + IN PVOID FunctionContext,
82879 + IN PVOID SystemSpecific2,
82880 + IN PVOID SystemSpecific3)
82881 +{
82882 + MLME_DLS_REQ_STRUCT MlmeDlsReq;
82883 + USHORT reason;
82884 + PRT_802_11_DLS pDLS = (PRT_802_11_DLS)FunctionContext;
82885 + PRTMP_ADAPTER pAd = pDLS->pAd;
82886 +
82887 + DBGPRINT(RT_DEBUG_TRACE, ("DlsTimeout - Tear down DLS links (%02x:%02x:%02x:%02x:%02x:%02x)\n",
82888 + pDLS->MacAddr[0], pDLS->MacAddr[1], pDLS->MacAddr[2], pDLS->MacAddr[3], pDLS->MacAddr[4], pDLS->MacAddr[5]));
82889 +
82890 + if ((pDLS) && (pDLS->Valid))
82891 + {
82892 + reason = REASON_QOS_REQUEST_TIMEOUT;
82893 + pDLS->Valid = FALSE;
82894 + pDLS->Status = DLS_NONE;
82895 + DlsParmFill(pAd, &MlmeDlsReq, pDLS, reason);
82896 + MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
82897 + RT28XX_MLME_HANDLER(pAd);
82898 + }
82899 +}
82900 +
82901 +/*
82902 +================================================================
82903 +Description : because DLS and CLI share the same WCID table in ASIC.
82904 +Mesh entry also insert to pAd->MacTab.content[]. Such is marked as ValidAsDls = TRUE.
82905 +Also fills the pairwise key.
82906 +Because front MAX_AID_BA entries have direct mapping to BAEntry, which is only used as CLI. So we insert Dls
82907 +from index MAX_AID_BA.
82908 +================================================================
82909 +*/
82910 +MAC_TABLE_ENTRY *MacTableInsertDlsEntry(
82911 + IN PRTMP_ADAPTER pAd,
82912 + IN PUCHAR pAddr,
82913 + IN UINT DlsEntryIdx)
82914 +{
82915 + PMAC_TABLE_ENTRY pEntry = NULL;
82916 +
82917 + DBGPRINT(RT_DEBUG_TRACE, ("====> MacTableInsertDlsEntry\n"));
82918 + // if FULL, return
82919 + if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE)
82920 + return NULL;
82921 +
82922 + do
82923 + {
82924 + if((pEntry = DlsEntryTableLookup(pAd, pAddr, TRUE)) != NULL)
82925 + break;
82926 +
82927 + // allocate one MAC entry
82928 + pEntry = MacTableInsertEntry(pAd, pAddr, DlsEntryIdx + MIN_NET_DEVICE_FOR_DLS, TRUE);
82929 + if (pEntry)
82930 + {
82931 + pAd->StaCfg.DLSEntry[DlsEntryIdx].MacTabMatchWCID = pEntry->Aid;
82932 + pEntry->MatchDlsEntryIdx = DlsEntryIdx;
82933 + pEntry->AuthMode = pAd->StaCfg.AuthMode;
82934 + pEntry->WepStatus = pAd->StaCfg.WepStatus;
82935 +
82936 + DBGPRINT(RT_DEBUG_TRACE, ("MacTableInsertDlsEntry - allocate entry #%d, Total= %d\n",pEntry->Aid, pAd->MacTab.Size));
82937 +
82938 + // If legacy WEP is used, set pair-wise cipherAlg into WCID attribute table for this entry
82939 + if ((pEntry->ValidAsDls) && (pEntry->WepStatus == Ndis802_11WEPEnabled))
82940 + {
82941 + UCHAR KeyIdx = 0;
82942 + UCHAR CipherAlg = 0;
82943 +
82944 + KeyIdx = pAd->StaCfg.DefaultKeyId;
82945 +
82946 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
82947 +
82948 + RTMPAddWcidAttributeEntry(pAd,
82949 + BSS0,
82950 + pAd->StaCfg.DefaultKeyId,
82951 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
82952 + pEntry);
82953 + }
82954 +
82955 + break;
82956 + }
82957 + } while(FALSE);
82958 +
82959 + DBGPRINT(RT_DEBUG_TRACE, ("<==== MacTableInsertDlsEntry\n"));
82960 +
82961 + return pEntry;
82962 +}
82963 +
82964 +
82965 +/*
82966 + ==========================================================================
82967 + Description:
82968 + Delete all Mesh Entry in pAd->MacTab
82969 + ==========================================================================
82970 + */
82971 +BOOLEAN MacTableDeleteDlsEntry(
82972 + IN PRTMP_ADAPTER pAd,
82973 + IN USHORT wcid,
82974 + IN PUCHAR pAddr)
82975 +{
82976 + DBGPRINT(RT_DEBUG_TRACE, ("====> MacTableDeleteDlsEntry\n"));
82977 +
82978 + if (!VALID_WCID(wcid))
82979 + return FALSE;
82980 +
82981 + MacTableDeleteEntry(pAd, wcid, pAddr);
82982 +
82983 + DBGPRINT(RT_DEBUG_TRACE, ("<==== MacTableDeleteDlsEntry\n"));
82984 +
82985 + return TRUE;
82986 +}
82987 +
82988 +MAC_TABLE_ENTRY *DlsEntryTableLookup(
82989 + IN PRTMP_ADAPTER pAd,
82990 + IN PUCHAR pAddr,
82991 + IN BOOLEAN bResetIdelCount)
82992 +{
82993 + ULONG HashIdx;
82994 + MAC_TABLE_ENTRY *pEntry = NULL;
82995 +
82996 + RTMP_SEM_LOCK(&pAd->MacTabLock);
82997 + HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
82998 + pEntry = pAd->MacTab.Hash[HashIdx];
82999 +
83000 + while (pEntry)
83001 + {
83002 + if ((pEntry->ValidAsDls == TRUE)
83003 + && MAC_ADDR_EQUAL(pEntry->Addr, pAddr))
83004 + {
83005 + if(bResetIdelCount)
83006 + pEntry->NoDataIdleCount = 0;
83007 + break;
83008 + }
83009 + else
83010 + pEntry = pEntry->pNext;
83011 + }
83012 +
83013 + RTMP_SEM_UNLOCK(&pAd->MacTabLock);
83014 + return pEntry;
83015 +}
83016 +
83017 +MAC_TABLE_ENTRY *DlsEntryTableLookupByWcid(
83018 + IN PRTMP_ADAPTER pAd,
83019 + IN UCHAR wcid,
83020 + IN PUCHAR pAddr,
83021 + IN BOOLEAN bResetIdelCount)
83022 +{
83023 + ULONG DLsIndex;
83024 + PMAC_TABLE_ENTRY pCurEntry = NULL;
83025 + PMAC_TABLE_ENTRY pEntry = NULL;
83026 +
83027 + if (!VALID_WCID(wcid))
83028 + return NULL;
83029 +
83030 + RTMP_SEM_LOCK(&pAd->MacTabLock);
83031 +
83032 + do
83033 + {
83034 + pCurEntry = &pAd->MacTab.Content[wcid];
83035 +
83036 + DLsIndex = 0xff;
83037 + if ((pCurEntry) && (pCurEntry->ValidAsDls== TRUE))
83038 + {
83039 + DLsIndex = pCurEntry->MatchDlsEntryIdx;
83040 + }
83041 +
83042 + if (DLsIndex == 0xff)
83043 + break;
83044 +
83045 + if (MAC_ADDR_EQUAL(pCurEntry->Addr, pAddr))
83046 + {
83047 + if(bResetIdelCount)
83048 + pCurEntry->NoDataIdleCount = 0;
83049 + pEntry = pCurEntry;
83050 + break;
83051 + }
83052 + } while(FALSE);
83053 +
83054 + RTMP_SEM_UNLOCK(&pAd->MacTabLock);
83055 +
83056 + return pEntry;
83057 +}
83058 +
83059 +INT Set_DlsEntryInfo_Display_Proc(
83060 + IN PRTMP_ADAPTER pAd,
83061 + IN PUCHAR arg)
83062 +{
83063 + INT i;
83064 +
83065 + printk("\n%-19s%-8s\n", "MAC", "TIMEOUT\n");
83066 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
83067 + {
83068 + if ((pAd->StaCfg.DLSEntry[i].Valid) && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
83069 + {
83070 + printk("%02x:%02x:%02x:%02x:%02x:%02x ",
83071 + pAd->StaCfg.DLSEntry[i].MacAddr[0], pAd->StaCfg.DLSEntry[i].MacAddr[1], pAd->StaCfg.DLSEntry[i].MacAddr[2],
83072 + pAd->StaCfg.DLSEntry[i].MacAddr[3], pAd->StaCfg.DLSEntry[i].MacAddr[4], pAd->StaCfg.DLSEntry[i].MacAddr[5]);
83073 + printk("%-8d\n", pAd->StaCfg.DLSEntry[i].TimeOut);
83074 + }
83075 + }
83076 +
83077 + return TRUE;
83078 +}
83079 +
83080 +INT Set_DlsAddEntry_Proc(
83081 + IN PRTMP_ADAPTER pAd,
83082 + IN PUCHAR arg)
83083 +{
83084 + UCHAR mac[MAC_ADDR_LEN];
83085 + USHORT Timeout;
83086 + char *token, sepValue[] = ":", DASH = '-';
83087 + INT i;
83088 + RT_802_11_DLS Dls;
83089 +
83090 + if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and timeout value in decimal format.
83091 + return FALSE;
83092 +
83093 + token = strchr(arg, DASH);
83094 + if ((token != NULL) && (strlen(token)>1))
83095 + {
83096 + Timeout = simple_strtol((token+1), 0, 10);
83097 +
83098 + *token = '\0';
83099 + for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
83100 + {
83101 + if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
83102 + return FALSE;
83103 + AtoH(token, (PUCHAR)(&mac[i]), 1);
83104 + }
83105 + if(i != 6)
83106 + return FALSE;
83107 +
83108 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%d", mac[0], mac[1],
83109 + mac[2], mac[3], mac[4], mac[5], (int)Timeout);
83110 +
83111 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
83112 + Dls.TimeOut = Timeout;
83113 + COPY_MAC_ADDR(Dls.MacAddr, mac);
83114 + Dls.Valid = 1;
83115 +
83116 + MlmeEnqueue(pAd,
83117 + MLME_CNTL_STATE_MACHINE,
83118 + RT_OID_802_11_SET_DLS_PARAM,
83119 + sizeof(RT_802_11_DLS),
83120 + &Dls);
83121 +
83122 + return TRUE;
83123 + }
83124 +
83125 + return FALSE;
83126 +
83127 +}
83128 +
83129 +INT Set_DlsTearDownEntry_Proc(
83130 + IN PRTMP_ADAPTER pAd,
83131 + IN PUCHAR arg)
83132 +{
83133 + UCHAR macAddr[MAC_ADDR_LEN];
83134 + CHAR *value;
83135 + INT i;
83136 + RT_802_11_DLS Dls;
83137 +
83138 + if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
83139 + return FALSE;
83140 +
83141 + for (i=0, value = rstrtok(arg,":"); value; value = rstrtok(NULL,":"))
83142 + {
83143 + if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
83144 + return FALSE; //Invalid
83145 +
83146 + AtoH(value, &macAddr[i++], 2);
83147 + }
83148 +
83149 + printk("\n%02x:%02x:%02x:%02x:%02x:%02x", macAddr[0], macAddr[1],
83150 + macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
83151 +
83152 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
83153 + COPY_MAC_ADDR(Dls.MacAddr, macAddr);
83154 + Dls.Valid = 0;
83155 +
83156 + MlmeEnqueue(pAd,
83157 + MLME_CNTL_STATE_MACHINE,
83158 + RT_OID_802_11_SET_DLS_PARAM,
83159 + sizeof(RT_802_11_DLS),
83160 + &Dls);
83161 +
83162 + return TRUE;
83163 +}
83164 +
83165 --- /dev/null
83166 +++ b/drivers/staging/rt3070/sta_ioctl.c
83167 @@ -0,0 +1,7203 @@
83168 +/*
83169 + *************************************************************************
83170 + * Ralink Tech Inc.
83171 + * 5F., No.36, Taiyuan St., Jhubei City,
83172 + * Hsinchu County 302,
83173 + * Taiwan, R.O.C.
83174 + *
83175 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
83176 + *
83177 + * This program is free software; you can redistribute it and/or modify *
83178 + * it under the terms of the GNU General Public License as published by *
83179 + * the Free Software Foundation; either version 2 of the License, or *
83180 + * (at your option) any later version. *
83181 + * *
83182 + * This program is distributed in the hope that it will be useful, *
83183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
83184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
83185 + * GNU General Public License for more details. *
83186 + * *
83187 + * You should have received a copy of the GNU General Public License *
83188 + * along with this program; if not, write to the *
83189 + * Free Software Foundation, Inc., *
83190 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
83191 + * *
83192 + *************************************************************************
83193 +
83194 + Module Name:
83195 + sta_ioctl.c
83196 +
83197 + Abstract:
83198 + IOCTL related subroutines
83199 +
83200 + Revision History:
83201 + Who When What
83202 + -------- ---------- ----------------------------------------------
83203 + Rory Chen 01-03-2003 created
83204 + Rory Chen 02-14-2005 modify to support RT61
83205 +*/
83206 +
83207 +#include "rt_config.h"
83208 +
83209 +#ifdef DBG
83210 +extern ULONG RTDebugLevel;
83211 +#endif
83212 +
83213 +#define NR_WEP_KEYS 4
83214 +#define WEP_SMALL_KEY_LEN (40/8)
83215 +#define WEP_LARGE_KEY_LEN (104/8)
83216 +
83217 +#define GROUP_KEY_NO 4
83218 +
83219 +extern UCHAR CipherWpa2Template[];
83220 +extern UCHAR CipherWpaPskTkip[];
83221 +extern UCHAR CipherWpaPskTkipLen;
83222 +
83223 +typedef struct PACKED _RT_VERSION_INFO{
83224 + UCHAR DriverVersionW;
83225 + UCHAR DriverVersionX;
83226 + UCHAR DriverVersionY;
83227 + UCHAR DriverVersionZ;
83228 + UINT DriverBuildYear;
83229 + UINT DriverBuildMonth;
83230 + UINT DriverBuildDay;
83231 +} RT_VERSION_INFO, *PRT_VERSION_INFO;
83232 +
83233 +struct iw_priv_args privtab[] = {
83234 +{ RTPRIV_IOCTL_SET,
83235 + IW_PRIV_TYPE_CHAR | 1024, 0,
83236 + "set"},
83237 +
83238 +{ RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
83239 + ""},
83240 +{ RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
83241 + ""},
83242 +/* --- sub-ioctls definitions --- */
83243 + { SHOW_CONN_STATUS,
83244 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
83245 + { SHOW_DRVIER_VERION,
83246 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
83247 + { SHOW_BA_INFO,
83248 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
83249 + { SHOW_DESC_INFO,
83250 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
83251 + { RAIO_OFF,
83252 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
83253 + { RAIO_ON,
83254 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
83255 +#ifdef QOS_DLS_SUPPORT
83256 + { SHOW_DLS_ENTRY_INFO,
83257 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
83258 +#endif // QOS_DLS_SUPPORT //
83259 + { SHOW_CFG_VALUE,
83260 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
83261 +/* --- sub-ioctls relations --- */
83262 +
83263 +#ifdef DBG
83264 +{ RTPRIV_IOCTL_BBP,
83265 + IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
83266 + "bbp"},
83267 +{ RTPRIV_IOCTL_MAC,
83268 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
83269 + "mac"},
83270 +#ifdef RT30xx
83271 +{ RTPRIV_IOCTL_RF,
83272 + IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
83273 + "rf"},
83274 +#endif // RT30xx //
83275 +{ RTPRIV_IOCTL_E2P,
83276 + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
83277 + "e2p"},
83278 +#endif /* DBG */
83279 +
83280 +{ RTPRIV_IOCTL_STATISTICS,
83281 + 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
83282 + "stat"},
83283 +{ RTPRIV_IOCTL_GSITESURVEY,
83284 + 0, IW_PRIV_TYPE_CHAR | 1024,
83285 + "get_site_survey"},
83286 +
83287 +
83288 +};
83289 +
83290 +INT Set_SSID_Proc(
83291 + IN PRTMP_ADAPTER pAdapter,
83292 + IN PUCHAR arg);
83293 +
83294 +#ifdef WMM_SUPPORT
83295 +INT Set_WmmCapable_Proc(
83296 + IN PRTMP_ADAPTER pAd,
83297 + IN PUCHAR arg);
83298 +#endif
83299 +
83300 +INT Set_NetworkType_Proc(
83301 + IN PRTMP_ADAPTER pAdapter,
83302 + IN PUCHAR arg);
83303 +
83304 +INT Set_AuthMode_Proc(
83305 + IN PRTMP_ADAPTER pAdapter,
83306 + IN PUCHAR arg);
83307 +
83308 +INT Set_EncrypType_Proc(
83309 + IN PRTMP_ADAPTER pAdapter,
83310 + IN PUCHAR arg);
83311 +
83312 +INT Set_DefaultKeyID_Proc(
83313 + IN PRTMP_ADAPTER pAdapter,
83314 + IN PUCHAR arg);
83315 +
83316 +INT Set_Key1_Proc(
83317 + IN PRTMP_ADAPTER pAdapter,
83318 + IN PUCHAR arg);
83319 +
83320 +INT Set_Key2_Proc(
83321 + IN PRTMP_ADAPTER pAdapter,
83322 + IN PUCHAR arg);
83323 +
83324 +INT Set_Key3_Proc(
83325 + IN PRTMP_ADAPTER pAdapter,
83326 + IN PUCHAR arg);
83327 +
83328 +INT Set_Key4_Proc(
83329 + IN PRTMP_ADAPTER pAdapter,
83330 + IN PUCHAR arg);
83331 +
83332 +INT Set_WPAPSK_Proc(
83333 + IN PRTMP_ADAPTER pAdapter,
83334 + IN PUCHAR arg);
83335 +
83336 +
83337 +INT Set_PSMode_Proc(
83338 + IN PRTMP_ADAPTER pAdapter,
83339 + IN PUCHAR arg);
83340 +
83341 +#ifdef WPA_SUPPLICANT_SUPPORT
83342 +INT Set_Wpa_Support(
83343 + IN PRTMP_ADAPTER pAd,
83344 + IN PUCHAR arg);
83345 +#endif // WPA_SUPPLICANT_SUPPORT //
83346 +
83347 +#ifdef DBG
83348 +
83349 +VOID RTMPIoctlMAC(
83350 + IN PRTMP_ADAPTER pAdapter,
83351 + IN struct iwreq *wrq);
83352 +
83353 +VOID RTMPIoctlE2PROM(
83354 + IN PRTMP_ADAPTER pAdapter,
83355 + IN struct iwreq *wrq);
83356 +
83357 +#ifdef RT30xx
83358 +VOID RTMPIoctlRF(
83359 + IN PRTMP_ADAPTER pAdapter,
83360 + IN struct iwreq *wrq);
83361 +#endif // RT30xx //
83362 +#endif // DBG //
83363 +
83364 +
83365 +NDIS_STATUS RTMPWPANoneAddKeyProc(
83366 + IN PRTMP_ADAPTER pAd,
83367 + IN PVOID pBuf);
83368 +
83369 +INT Set_FragTest_Proc(
83370 + IN PRTMP_ADAPTER pAdapter,
83371 + IN PUCHAR arg);
83372 +
83373 +#ifdef DOT11_N_SUPPORT
83374 +INT Set_TGnWifiTest_Proc(
83375 + IN PRTMP_ADAPTER pAd,
83376 + IN PUCHAR arg);
83377 +#endif // DOT11_N_SUPPORT //
83378 +
83379 +INT Set_LongRetryLimit_Proc(
83380 + IN PRTMP_ADAPTER pAdapter,
83381 + IN PUCHAR arg);
83382 +
83383 +INT Set_ShortRetryLimit_Proc(
83384 + IN PRTMP_ADAPTER pAdapter,
83385 + IN PUCHAR arg);
83386 +
83387 +#ifdef EXT_BUILD_CHANNEL_LIST
83388 +INT Set_Ieee80211dClientMode_Proc(
83389 + IN PRTMP_ADAPTER pAdapter,
83390 + IN PUCHAR arg);
83391 +#endif // EXT_BUILD_CHANNEL_LIST //
83392 +
83393 +#ifdef CARRIER_DETECTION_SUPPORT
83394 +INT Set_CarrierDetect_Proc(
83395 + IN PRTMP_ADAPTER pAd,
83396 + IN PUCHAR arg);
83397 +#endif // CARRIER_DETECTION_SUPPORT //
83398 +
83399 +static struct {
83400 + CHAR *name;
83401 + INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
83402 +} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
83403 + {"DriverVersion", Set_DriverVersion_Proc},
83404 + {"CountryRegion", Set_CountryRegion_Proc},
83405 + {"CountryRegionABand", Set_CountryRegionABand_Proc},
83406 + {"SSID", Set_SSID_Proc},
83407 + {"WirelessMode", Set_WirelessMode_Proc},
83408 + {"TxBurst", Set_TxBurst_Proc},
83409 + {"TxPreamble", Set_TxPreamble_Proc},
83410 + {"TxPower", Set_TxPower_Proc},
83411 + {"Channel", Set_Channel_Proc},
83412 + {"BGProtection", Set_BGProtection_Proc},
83413 + {"RTSThreshold", Set_RTSThreshold_Proc},
83414 + {"FragThreshold", Set_FragThreshold_Proc},
83415 +#ifdef DOT11_N_SUPPORT
83416 + {"HtBw", Set_HtBw_Proc},
83417 + {"HtMcs", Set_HtMcs_Proc},
83418 + {"HtGi", Set_HtGi_Proc},
83419 + {"HtOpMode", Set_HtOpMode_Proc},
83420 + {"HtExtcha", Set_HtExtcha_Proc},
83421 + {"HtMpduDensity", Set_HtMpduDensity_Proc},
83422 + {"HtBaWinSize", Set_HtBaWinSize_Proc},
83423 + {"HtRdg", Set_HtRdg_Proc},
83424 + {"HtAmsdu", Set_HtAmsdu_Proc},
83425 + {"HtAutoBa", Set_HtAutoBa_Proc},
83426 + {"HtBaDecline", Set_BADecline_Proc},
83427 + {"HtProtect", Set_HtProtect_Proc},
83428 + {"HtMimoPs", Set_HtMimoPs_Proc},
83429 +#endif // DOT11_N_SUPPORT //
83430 +
83431 +#ifdef AGGREGATION_SUPPORT
83432 + {"PktAggregate", Set_PktAggregate_Proc},
83433 +#endif
83434 +
83435 +#ifdef WMM_SUPPORT
83436 + {"WmmCapable", Set_WmmCapable_Proc},
83437 +#endif
83438 + {"IEEE80211H", Set_IEEE80211H_Proc},
83439 + {"NetworkType", Set_NetworkType_Proc},
83440 + {"AuthMode", Set_AuthMode_Proc},
83441 + {"EncrypType", Set_EncrypType_Proc},
83442 + {"DefaultKeyID", Set_DefaultKeyID_Proc},
83443 + {"Key1", Set_Key1_Proc},
83444 + {"Key2", Set_Key2_Proc},
83445 + {"Key3", Set_Key3_Proc},
83446 + {"Key4", Set_Key4_Proc},
83447 + {"WPAPSK", Set_WPAPSK_Proc},
83448 + {"ResetCounter", Set_ResetStatCounter_Proc},
83449 + {"PSMode", Set_PSMode_Proc},
83450 +#ifdef DBG
83451 + {"Debug", Set_Debug_Proc},
83452 +#endif
83453 +
83454 +#ifdef RALINK_ATE
83455 + {"ATE", Set_ATE_Proc},
83456 + {"ATEDA", Set_ATE_DA_Proc},
83457 + {"ATESA", Set_ATE_SA_Proc},
83458 + {"ATEBSSID", Set_ATE_BSSID_Proc},
83459 + {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
83460 + {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
83461 + {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
83462 + {"ATETXANT", Set_ATE_TX_Antenna_Proc},
83463 + {"ATERXANT", Set_ATE_RX_Antenna_Proc},
83464 + {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
83465 + {"ATETXBW", Set_ATE_TX_BW_Proc},
83466 + {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
83467 + {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
83468 + {"ATETXMCS", Set_ATE_TX_MCS_Proc},
83469 + {"ATETXMODE", Set_ATE_TX_MODE_Proc},
83470 + {"ATETXGI", Set_ATE_TX_GI_Proc},
83471 + {"ATERXFER", Set_ATE_RX_FER_Proc},
83472 + {"ATERRF", Set_ATE_Read_RF_Proc},
83473 + {"ATEWRF1", Set_ATE_Write_RF1_Proc},
83474 + {"ATEWRF2", Set_ATE_Write_RF2_Proc},
83475 + {"ATEWRF3", Set_ATE_Write_RF3_Proc},
83476 + {"ATEWRF4", Set_ATE_Write_RF4_Proc},
83477 + {"ATELDE2P", Set_ATE_Load_E2P_Proc},
83478 + {"ATERE2P", Set_ATE_Read_E2P_Proc},
83479 + {"ATESHOW", Set_ATE_Show_Proc},
83480 + {"ATEHELP", Set_ATE_Help_Proc},
83481 +
83482 +#ifdef RALINK_28xx_QA
83483 + {"TxStop", Set_TxStop_Proc},
83484 + {"RxStop", Set_RxStop_Proc},
83485 +#endif // RALINK_28xx_QA //
83486 +#endif // RALINK_ATE //
83487 +
83488 +#ifdef WPA_SUPPLICANT_SUPPORT
83489 + {"WpaSupport", Set_Wpa_Support},
83490 +#endif // WPA_SUPPLICANT_SUPPORT //
83491 +
83492 +
83493 +
83494 + {"FixedTxMode", Set_FixedTxMode_Proc},
83495 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
83496 + {"OpMode", Set_OpMode_Proc},
83497 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
83498 +#ifdef DOT11_N_SUPPORT
83499 + {"TGnWifiTest", Set_TGnWifiTest_Proc},
83500 + {"ForceGF", Set_ForceGF_Proc},
83501 +#endif // DOT11_N_SUPPORT //
83502 +#ifdef QOS_DLS_SUPPORT
83503 + {"DlsAddEntry", Set_DlsAddEntry_Proc},
83504 + {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
83505 +#endif // QOS_DLS_SUPPORT //
83506 + {"LongRetry", Set_LongRetryLimit_Proc},
83507 + {"ShortRetry", Set_ShortRetryLimit_Proc},
83508 +#ifdef EXT_BUILD_CHANNEL_LIST
83509 + {"11dClientMode", Set_Ieee80211dClientMode_Proc},
83510 +#endif // EXT_BUILD_CHANNEL_LIST //
83511 +#ifdef CARRIER_DETECTION_SUPPORT
83512 + {"CarrierDetect", Set_CarrierDetect_Proc},
83513 +#endif // CARRIER_DETECTION_SUPPORT //
83514 +//2008/09/11:KH add to support efuse<--
83515 +#ifdef RT30xx
83516 + {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
83517 + {"efuseDump", set_eFusedump_Proc},
83518 + {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
83519 +#endif // RT30xx //
83520 +//2008/09/11:KH add to support efuse-->
83521 + {NULL,}
83522 +};
83523 +
83524 +
83525 +VOID RTMPAddKey(
83526 + IN PRTMP_ADAPTER pAd,
83527 + IN PNDIS_802_11_KEY pKey)
83528 +{
83529 + ULONG KeyIdx;
83530 + MAC_TABLE_ENTRY *pEntry;
83531 +
83532 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
83533 +
83534 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
83535 + {
83536 + if (pKey->KeyIndex & 0x80000000)
83537 + {
83538 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
83539 + {
83540 + NdisZeroMemory(pAd->StaCfg.PMK, 32);
83541 + NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
83542 + goto end;
83543 + }
83544 + // Update PTK
83545 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
83546 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
83547 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
83548 +#ifdef WPA_SUPPLICANT_SUPPORT
83549 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
83550 + {
83551 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
83552 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
83553 + }
83554 + else
83555 +#endif // WPA_SUPPLICANT_SUPPORT //
83556 + {
83557 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
83558 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
83559 + }
83560 +
83561 + // Decide its ChiperAlg
83562 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
83563 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
83564 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
83565 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
83566 + else
83567 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
83568 +
83569 + // Update these related information to MAC_TABLE_ENTRY
83570 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
83571 + NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
83572 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
83573 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
83574 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
83575 +
83576 + // Update pairwise key information to ASIC Shared Key Table
83577 + AsicAddSharedKeyEntry(pAd,
83578 + BSS0,
83579 + 0,
83580 + pAd->SharedKey[BSS0][0].CipherAlg,
83581 + pAd->SharedKey[BSS0][0].Key,
83582 + pAd->SharedKey[BSS0][0].TxMic,
83583 + pAd->SharedKey[BSS0][0].RxMic);
83584 +
83585 + // Update ASIC WCID attribute table and IVEIV table
83586 + RTMPAddWcidAttributeEntry(pAd,
83587 + BSS0,
83588 + 0,
83589 + pAd->SharedKey[BSS0][0].CipherAlg,
83590 + pEntry);
83591 +
83592 + if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
83593 + {
83594 + // set 802.1x port control
83595 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
83596 + STA_PORT_SECURED(pAd);
83597 +
83598 + // Indicate Connected for GUI
83599 + pAd->IndicateMediaState = NdisMediaStateConnected;
83600 + }
83601 + }
83602 + else
83603 + {
83604 + // Update GTK
83605 + pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
83606 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
83607 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
83608 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
83609 +#ifdef WPA_SUPPLICANT_SUPPORT
83610 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
83611 + {
83612 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
83613 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
83614 + }
83615 + else
83616 +#endif // WPA_SUPPLICANT_SUPPORT //
83617 + {
83618 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
83619 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
83620 + }
83621 +
83622 + // Update Shared Key CipherAlg
83623 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
83624 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
83625 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
83626 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
83627 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
83628 +
83629 + // Update group key information to ASIC Shared Key Table
83630 + AsicAddSharedKeyEntry(pAd,
83631 + BSS0,
83632 + pAd->StaCfg.DefaultKeyId,
83633 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
83634 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
83635 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
83636 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
83637 +
83638 + // Update ASIC WCID attribute table and IVEIV table
83639 + RTMPAddWcidAttributeEntry(pAd,
83640 + BSS0,
83641 + pAd->StaCfg.DefaultKeyId,
83642 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
83643 + NULL);
83644 +
83645 + // set 802.1x port control
83646 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
83647 + STA_PORT_SECURED(pAd);
83648 +
83649 + // Indicate Connected for GUI
83650 + pAd->IndicateMediaState = NdisMediaStateConnected;
83651 + }
83652 + }
83653 + else // dynamic WEP from wpa_supplicant
83654 + {
83655 + UCHAR CipherAlg;
83656 + PUCHAR Key;
83657 +
83658 + if(pKey->KeyLength == 32)
83659 + goto end;
83660 +
83661 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
83662 +
83663 + if (KeyIdx < 4)
83664 + {
83665 + // it is a default shared key, for Pairwise key setting
83666 + if (pKey->KeyIndex & 0x80000000)
83667 + {
83668 + pEntry = MacTableLookup(pAd, pKey->BSSID);
83669 +
83670 + if (pEntry)
83671 + {
83672 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
83673 +
83674 + // set key material and key length
83675 + pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
83676 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
83677 +
83678 + // set Cipher type
83679 + if (pKey->KeyLength == 5)
83680 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
83681 + else
83682 + pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
83683 +
83684 + // Add Pair-wise key to Asic
83685 + AsicAddPairwiseKeyEntry(
83686 + pAd,
83687 + pEntry->Addr,
83688 + (UCHAR)pEntry->Aid,
83689 + &pEntry->PairwiseKey);
83690 +
83691 + // update WCID attribute table and IVEIV table for this entry
83692 + RTMPAddWcidAttributeEntry(
83693 + pAd,
83694 + BSS0,
83695 + KeyIdx, // The value may be not zero
83696 + pEntry->PairwiseKey.CipherAlg,
83697 + pEntry);
83698 +
83699 + }
83700 + }
83701 + else
83702 + {
83703 + // Default key for tx (shared key)
83704 + pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
83705 +
83706 + // set key material and key length
83707 + pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
83708 + NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
83709 +
83710 + // Set Ciper type
83711 + if (pKey->KeyLength == 5)
83712 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
83713 + else
83714 + pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
83715 +
83716 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
83717 + Key = pAd->SharedKey[BSS0][KeyIdx].Key;
83718 +
83719 + // Set Group key material to Asic
83720 + AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
83721 +
83722 + // Update WCID attribute table and IVEIV table for this group key table
83723 + RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
83724 +
83725 + }
83726 + }
83727 + }
83728 +end:
83729 + return;
83730 +}
83731 +
83732 +char * rtstrchr(const char * s, int c)
83733 +{
83734 + for(; *s != (char) c; ++s)
83735 + if (*s == '\0')
83736 + return NULL;
83737 + return (char *) s;
83738 +}
83739 +
83740 +/*
83741 +This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
83742 +*/
83743 +
83744 +int
83745 +rt_ioctl_giwname(struct net_device *dev,
83746 + struct iw_request_info *info,
83747 + char *name, char *extra)
83748 +{
83749 +// PRTMP_ADAPTER pAdapter = dev->ml_priv;
83750 +
83751 +#ifdef RT2870
83752 + strncpy(name, "RT2870 Wireless", IFNAMSIZ);
83753 +#endif // RT2870 //
83754 + return 0;
83755 +}
83756 +
83757 +int rt_ioctl_siwfreq(struct net_device *dev,
83758 + struct iw_request_info *info,
83759 + struct iw_freq *freq, char *extra)
83760 +{
83761 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83762 + int chan = -1;
83763 +
83764 + //check if the interface is down
83765 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83766 + {
83767 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83768 + return -ENETDOWN;
83769 + }
83770 +
83771 +
83772 + if (freq->e > 1)
83773 + return -EINVAL;
83774 +
83775 + if((freq->e == 0) && (freq->m <= 1000))
83776 + chan = freq->m; // Setting by channel number
83777 + else
83778 + MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
83779 +
83780 + if (ChannelSanity(pAdapter, chan) == TRUE)
83781 + {
83782 + pAdapter->CommonCfg.Channel = chan;
83783 + DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
83784 + }
83785 + else
83786 + return -EINVAL;
83787 +
83788 + return 0;
83789 +}
83790 +int rt_ioctl_giwfreq(struct net_device *dev,
83791 + struct iw_request_info *info,
83792 + struct iw_freq *freq, char *extra)
83793 +{
83794 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
83795 + PRTMP_ADAPTER pAdapter;
83796 + UCHAR ch;
83797 + ULONG m;
83798 +
83799 + if (dev->priv_flags == INT_MAIN)
83800 + {
83801 + pAdapter = dev->ml_priv;
83802 + }
83803 + else
83804 + {
83805 + pVirtualAd = dev->ml_priv;
83806 + pAdapter = pVirtualAd->RtmpDev->ml_priv;
83807 + }
83808 +
83809 + if (pAdapter == NULL)
83810 + {
83811 + /* if 1st open fail, pAd will be free;
83812 + So the net_dev->ml_priv will be NULL in 2rd open */
83813 + return -ENETDOWN;
83814 + }
83815 +
83816 + ch = pAdapter->CommonCfg.Channel;
83817 +
83818 + DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
83819 +
83820 + MAP_CHANNEL_ID_TO_KHZ(ch, m);
83821 + freq->m = m * 100;
83822 + freq->e = 1;
83823 + return 0;
83824 +}
83825 +
83826 +int rt_ioctl_siwmode(struct net_device *dev,
83827 + struct iw_request_info *info,
83828 + __u32 *mode, char *extra)
83829 +{
83830 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83831 +
83832 + //check if the interface is down
83833 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83834 + {
83835 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83836 + return -ENETDOWN;
83837 + }
83838 +
83839 + switch (*mode)
83840 + {
83841 + case IW_MODE_ADHOC:
83842 + Set_NetworkType_Proc(pAdapter, "Adhoc");
83843 + break;
83844 + case IW_MODE_INFRA:
83845 + Set_NetworkType_Proc(pAdapter, "Infra");
83846 + break;
83847 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
83848 + case IW_MODE_MONITOR:
83849 + Set_NetworkType_Proc(pAdapter, "Monitor");
83850 + break;
83851 +#endif
83852 + default:
83853 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
83854 + return -EINVAL;
83855 + }
83856 +
83857 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
83858 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
83859 +
83860 + return 0;
83861 +}
83862 +
83863 +int rt_ioctl_giwmode(struct net_device *dev,
83864 + struct iw_request_info *info,
83865 + __u32 *mode, char *extra)
83866 +{
83867 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83868 +
83869 + if (ADHOC_ON(pAdapter))
83870 + *mode = IW_MODE_ADHOC;
83871 + else if (INFRA_ON(pAdapter))
83872 + *mode = IW_MODE_INFRA;
83873 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
83874 + else if (MONITOR_ON(pAdapter))
83875 + {
83876 + *mode = IW_MODE_MONITOR;
83877 + }
83878 +#endif
83879 + else
83880 + *mode = IW_MODE_AUTO;
83881 +
83882 + DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
83883 + return 0;
83884 +}
83885 +
83886 +int rt_ioctl_siwsens(struct net_device *dev,
83887 + struct iw_request_info *info,
83888 + char *name, char *extra)
83889 +{
83890 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83891 +
83892 + //check if the interface is down
83893 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
83894 + {
83895 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
83896 + return -ENETDOWN;
83897 + }
83898 +
83899 + return 0;
83900 +}
83901 +
83902 +int rt_ioctl_giwsens(struct net_device *dev,
83903 + struct iw_request_info *info,
83904 + char *name, char *extra)
83905 +{
83906 + return 0;
83907 +}
83908 +
83909 +int rt_ioctl_giwrange(struct net_device *dev,
83910 + struct iw_request_info *info,
83911 + struct iw_point *data, char *extra)
83912 +{
83913 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83914 +
83915 + struct iw_range *range = (struct iw_range *) extra;
83916 + u16 val;
83917 + int i;
83918 +
83919 + DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
83920 + data->length = sizeof(struct iw_range);
83921 + memset(range, 0, sizeof(struct iw_range));
83922 +
83923 + range->txpower_capa = IW_TXPOW_DBM;
83924 +
83925 + if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
83926 + {
83927 + range->min_pmp = 1 * 1024;
83928 + range->max_pmp = 65535 * 1024;
83929 + range->min_pmt = 1 * 1024;
83930 + range->max_pmt = 1000 * 1024;
83931 + range->pmp_flags = IW_POWER_PERIOD;
83932 + range->pmt_flags = IW_POWER_TIMEOUT;
83933 + range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
83934 + IW_POWER_UNICAST_R | IW_POWER_ALL_R;
83935 + }
83936 +
83937 + range->we_version_compiled = WIRELESS_EXT;
83938 + range->we_version_source = 14;
83939 +
83940 + range->retry_capa = IW_RETRY_LIMIT;
83941 + range->retry_flags = IW_RETRY_LIMIT;
83942 + range->min_retry = 0;
83943 + range->max_retry = 255;
83944 +
83945 + range->num_channels = pAdapter->ChannelListNum;
83946 +
83947 + val = 0;
83948 + for (i = 1; i <= range->num_channels; i++)
83949 + {
83950 + u32 m;
83951 + range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
83952 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
83953 + range->freq[val].m = m * 100; /* HZ */
83954 +
83955 + range->freq[val].e = 1;
83956 + val++;
83957 + if (val == IW_MAX_FREQUENCIES)
83958 + break;
83959 + }
83960 + range->num_frequency = val;
83961 +
83962 + range->max_qual.qual = 100; /* what is correct max? This was not
83963 + * documented exactly. At least
83964 + * 69 has been observed. */
83965 + range->max_qual.level = 0; /* dB */
83966 + range->max_qual.noise = 0; /* dB */
83967 +
83968 + /* What would be suitable values for "average/typical" qual? */
83969 + range->avg_qual.qual = 20;
83970 + range->avg_qual.level = -60;
83971 + range->avg_qual.noise = -95;
83972 + range->sensitivity = 3;
83973 +
83974 + range->max_encoding_tokens = NR_WEP_KEYS;
83975 + range->num_encoding_sizes = 2;
83976 + range->encoding_size[0] = 5;
83977 + range->encoding_size[1] = 13;
83978 +
83979 + range->min_rts = 0;
83980 + range->max_rts = 2347;
83981 + range->min_frag = 256;
83982 + range->max_frag = 2346;
83983 +
83984 +#if WIRELESS_EXT > 17
83985 + /* IW_ENC_CAPA_* bit field */
83986 + range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
83987 + IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
83988 +#endif
83989 +
83990 + return 0;
83991 +}
83992 +
83993 +int rt_ioctl_siwap(struct net_device *dev,
83994 + struct iw_request_info *info,
83995 + struct sockaddr *ap_addr, char *extra)
83996 +{
83997 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
83998 + NDIS_802_11_MAC_ADDRESS Bssid;
83999 +
84000 + //check if the interface is down
84001 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84002 + {
84003 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84004 + return -ENETDOWN;
84005 + }
84006 +
84007 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
84008 + {
84009 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
84010 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
84011 + }
84012 +
84013 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
84014 + // this request, because this request is initiated by NDIS.
84015 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
84016 + // Prevent to connect AP again in STAMlmePeriodicExec
84017 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
84018 +
84019 + memset(Bssid, 0, MAC_ADDR_LEN);
84020 + memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
84021 + MlmeEnqueue(pAdapter,
84022 + MLME_CNTL_STATE_MACHINE,
84023 + OID_802_11_BSSID,
84024 + sizeof(NDIS_802_11_MAC_ADDRESS),
84025 + (VOID *)&Bssid);
84026 +
84027 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
84028 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
84029 +
84030 + return 0;
84031 +}
84032 +
84033 +int rt_ioctl_giwap(struct net_device *dev,
84034 + struct iw_request_info *info,
84035 + struct sockaddr *ap_addr, char *extra)
84036 +{
84037 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84038 +
84039 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
84040 + {
84041 + ap_addr->sa_family = ARPHRD_ETHER;
84042 + memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
84043 + }
84044 +#ifdef WPA_SUPPLICANT_SUPPORT
84045 + // Add for RT2870
84046 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
84047 + {
84048 + ap_addr->sa_family = ARPHRD_ETHER;
84049 + memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
84050 + }
84051 +#endif // WPA_SUPPLICANT_SUPPORT //
84052 + else
84053 + {
84054 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
84055 + return -ENOTCONN;
84056 + }
84057 +
84058 + return 0;
84059 +}
84060 +
84061 +/*
84062 + * Units are in db above the noise floor. That means the
84063 + * rssi values reported in the tx/rx descriptors in the
84064 + * driver are the SNR expressed in db.
84065 + *
84066 + * If you assume that the noise floor is -95, which is an
84067 + * excellent assumption 99.5 % of the time, then you can
84068 + * derive the absolute signal level (i.e. -95 + rssi).
84069 + * There are some other slight factors to take into account
84070 + * depending on whether the rssi measurement is from 11b,
84071 + * 11g, or 11a. These differences are at most 2db and
84072 + * can be documented.
84073 + *
84074 + * NB: various calculations are based on the orinoco/wavelan
84075 + * drivers for compatibility
84076 + */
84077 +static void set_quality(PRTMP_ADAPTER pAdapter,
84078 + struct iw_quality *iq,
84079 + signed char rssi)
84080 +{
84081 + __u8 ChannelQuality;
84082 +
84083 + // Normalize Rssi
84084 + if (rssi >= -50)
84085 + ChannelQuality = 100;
84086 + else if (rssi >= -80) // between -50 ~ -80dbm
84087 + ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
84088 + else if (rssi >= -90) // between -80 ~ -90dbm
84089 + ChannelQuality = (__u8)((rssi + 90) * 26)/10;
84090 + else
84091 + ChannelQuality = 0;
84092 +
84093 + iq->qual = (__u8)ChannelQuality;
84094 +
84095 + iq->level = (__u8)(rssi);
84096 + iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
84097 + iq->noise += 256 - 143;
84098 + iq->updated = pAdapter->iw_stats.qual.updated;
84099 +}
84100 +
84101 +int rt_ioctl_iwaplist(struct net_device *dev,
84102 + struct iw_request_info *info,
84103 + struct iw_point *data, char *extra)
84104 +{
84105 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84106 +
84107 + struct sockaddr addr[IW_MAX_AP];
84108 + struct iw_quality qual[IW_MAX_AP];
84109 + int i;
84110 +
84111 + //check if the interface is down
84112 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84113 + {
84114 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84115 + data->length = 0;
84116 + return 0;
84117 + //return -ENETDOWN;
84118 + }
84119 +
84120 + for (i = 0; i <IW_MAX_AP ; i++)
84121 + {
84122 + if (i >= pAdapter->ScanTab.BssNr)
84123 + break;
84124 + addr[i].sa_family = ARPHRD_ETHER;
84125 + memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
84126 + set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
84127 + }
84128 + data->length = i;
84129 + memcpy(extra, &addr, i*sizeof(addr[0]));
84130 + data->flags = 1; /* signal quality present (sort of) */
84131 + memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
84132 +
84133 + return 0;
84134 +}
84135 +
84136 +#ifdef SIOCGIWSCAN
84137 +int rt_ioctl_siwscan(struct net_device *dev,
84138 + struct iw_request_info *info,
84139 + struct iw_point *data, char *extra)
84140 +{
84141 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84142 +
84143 + ULONG Now;
84144 + int Status = NDIS_STATUS_SUCCESS;
84145 +
84146 + //check if the interface is down
84147 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84148 + {
84149 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84150 + return -ENETDOWN;
84151 + }
84152 +
84153 + if (MONITOR_ON(pAdapter))
84154 + {
84155 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
84156 + return -EINVAL;
84157 + }
84158 +
84159 +
84160 +#ifdef WPA_SUPPLICANT_SUPPORT
84161 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
84162 + {
84163 + pAdapter->StaCfg.WpaSupplicantScanCount++;
84164 + }
84165 +#endif // WPA_SUPPLICANT_SUPPORT //
84166 +
84167 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
84168 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
84169 + return 0;
84170 + do{
84171 + Now = jiffies;
84172 +
84173 +#ifdef WPA_SUPPLICANT_SUPPORT
84174 + if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
84175 + (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
84176 + {
84177 + DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
84178 + Status = NDIS_STATUS_SUCCESS;
84179 + break;
84180 + }
84181 +#endif // WPA_SUPPLICANT_SUPPORT //
84182 +
84183 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
84184 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
84185 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
84186 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
84187 + {
84188 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
84189 + Status = NDIS_STATUS_SUCCESS;
84190 + break;
84191 + }
84192 +
84193 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
84194 + {
84195 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
84196 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
84197 + }
84198 +
84199 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
84200 + // this request, because this request is initiated by NDIS.
84201 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
84202 + // Reset allowed scan retries
84203 + pAdapter->StaCfg.ScanCnt = 0;
84204 + pAdapter->StaCfg.LastScanTime = Now;
84205 +
84206 + MlmeEnqueue(pAdapter,
84207 + MLME_CNTL_STATE_MACHINE,
84208 + OID_802_11_BSSID_LIST_SCAN,
84209 + 0,
84210 + NULL);
84211 +
84212 + Status = NDIS_STATUS_SUCCESS;
84213 + RT28XX_MLME_HANDLER(pAdapter);
84214 + }while(0);
84215 + return 0;
84216 +}
84217 +
84218 +int rt_ioctl_giwscan(struct net_device *dev,
84219 + struct iw_request_info *info,
84220 + struct iw_point *data, char *extra)
84221 +{
84222 +
84223 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84224 + int i=0;
84225 + char *current_ev = extra, *previous_ev = extra;
84226 + char *end_buf;
84227 + char *current_val, custom[MAX_CUSTOM_LEN] = {0};
84228 +#ifndef IWEVGENIE
84229 + char idx;
84230 +#endif // IWEVGENIE //
84231 + struct iw_event iwe;
84232 +
84233 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
84234 + {
84235 + /*
84236 + * Still scanning, indicate the caller should try again.
84237 + */
84238 + return -EAGAIN;
84239 + }
84240 +
84241 +
84242 +#ifdef WPA_SUPPLICANT_SUPPORT
84243 + if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
84244 + {
84245 + pAdapter->StaCfg.WpaSupplicantScanCount = 0;
84246 + }
84247 +#endif // WPA_SUPPLICANT_SUPPORT //
84248 +
84249 + if (pAdapter->ScanTab.BssNr == 0)
84250 + {
84251 + data->length = 0;
84252 + return 0;
84253 + }
84254 +
84255 +#if WIRELESS_EXT >= 17
84256 + if (data->length > 0)
84257 + end_buf = extra + data->length;
84258 + else
84259 + end_buf = extra + IW_SCAN_MAX_DATA;
84260 +#else
84261 + end_buf = extra + IW_SCAN_MAX_DATA;
84262 +#endif
84263 +
84264 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
84265 + {
84266 + if (current_ev >= end_buf)
84267 + {
84268 +#if WIRELESS_EXT >= 17
84269 + return -E2BIG;
84270 +#else
84271 + break;
84272 +#endif
84273 + }
84274 +
84275 + //MAC address
84276 + //================================
84277 + memset(&iwe, 0, sizeof(iwe));
84278 + iwe.cmd = SIOCGIWAP;
84279 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
84280 + memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
84281 +
84282 + previous_ev = current_ev;
84283 + current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
84284 + if (current_ev == previous_ev)
84285 +#if WIRELESS_EXT >= 17
84286 + return -E2BIG;
84287 +#else
84288 + break;
84289 +#endif
84290 +
84291 + /*
84292 + Protocol:
84293 + it will show scanned AP's WirelessMode .
84294 + it might be
84295 + 802.11a
84296 + 802.11a/n
84297 + 802.11g/n
84298 + 802.11b/g/n
84299 + 802.11g
84300 + 802.11b/g
84301 + */
84302 + memset(&iwe, 0, sizeof(iwe));
84303 + iwe.cmd = SIOCGIWNAME;
84304 +
84305 +
84306 + {
84307 + PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
84308 + BOOLEAN isGonly=FALSE;
84309 + int rateCnt=0;
84310 +
84311 + if (pBssEntry->Channel>14)
84312 + {
84313 + if (pBssEntry->HtCapabilityLen!=0)
84314 + strcpy(iwe.u.name,"802.11a/n");
84315 + else
84316 + strcpy(iwe.u.name,"802.11a");
84317 + }
84318 + else
84319 + {
84320 + /*
84321 + if one of non B mode rate is set supported rate . it mean G only.
84322 + */
84323 + for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
84324 + {
84325 + /*
84326 + 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
84327 + */
84328 + if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
84329 + isGonly=TRUE;
84330 + }
84331 +
84332 + for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
84333 + {
84334 + if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
84335 + isGonly=TRUE;
84336 + }
84337 +
84338 +
84339 + if (pBssEntry->HtCapabilityLen!=0)
84340 + {
84341 + if (isGonly==TRUE)
84342 + strcpy(iwe.u.name,"802.11g/n");
84343 + else
84344 + strcpy(iwe.u.name,"802.11b/g/n");
84345 + }
84346 + else
84347 + {
84348 + if (isGonly==TRUE)
84349 + strcpy(iwe.u.name,"802.11g");
84350 + else
84351 + {
84352 + if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
84353 + strcpy(iwe.u.name,"802.11b");
84354 + else
84355 + strcpy(iwe.u.name,"802.11b/g");
84356 + }
84357 + }
84358 + }
84359 + }
84360 +
84361 + previous_ev = current_ev;
84362 + current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
84363 + if (current_ev == previous_ev)
84364 +#if WIRELESS_EXT >= 17
84365 + return -E2BIG;
84366 +#else
84367 + break;
84368 +#endif
84369 +
84370 + //ESSID
84371 + //================================
84372 + memset(&iwe, 0, sizeof(iwe));
84373 + iwe.cmd = SIOCGIWESSID;
84374 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
84375 + iwe.u.data.flags = 1;
84376 +
84377 + previous_ev = current_ev;
84378 + current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
84379 + if (current_ev == previous_ev)
84380 +#if WIRELESS_EXT >= 17
84381 + return -E2BIG;
84382 +#else
84383 + break;
84384 +#endif
84385 +
84386 + //Network Type
84387 + //================================
84388 + memset(&iwe, 0, sizeof(iwe));
84389 + iwe.cmd = SIOCGIWMODE;
84390 + if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
84391 + {
84392 + iwe.u.mode = IW_MODE_ADHOC;
84393 + }
84394 + else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
84395 + {
84396 + iwe.u.mode = IW_MODE_INFRA;
84397 + }
84398 + else
84399 + {
84400 + iwe.u.mode = IW_MODE_AUTO;
84401 + }
84402 + iwe.len = IW_EV_UINT_LEN;
84403 +
84404 + previous_ev = current_ev;
84405 + current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
84406 + if (current_ev == previous_ev)
84407 +#if WIRELESS_EXT >= 17
84408 + return -E2BIG;
84409 +#else
84410 + break;
84411 +#endif
84412 +
84413 + //Channel and Frequency
84414 + //================================
84415 + memset(&iwe, 0, sizeof(iwe));
84416 + iwe.cmd = SIOCGIWFREQ;
84417 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
84418 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
84419 + else
84420 + iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
84421 + iwe.u.freq.e = 0;
84422 + iwe.u.freq.i = 0;
84423 +
84424 + previous_ev = current_ev;
84425 + current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
84426 + if (current_ev == previous_ev)
84427 +#if WIRELESS_EXT >= 17
84428 + return -E2BIG;
84429 +#else
84430 + break;
84431 +#endif
84432 +
84433 + //Add quality statistics
84434 + //================================
84435 + memset(&iwe, 0, sizeof(iwe));
84436 + iwe.cmd = IWEVQUAL;
84437 + iwe.u.qual.level = 0;
84438 + iwe.u.qual.noise = 0;
84439 + set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
84440 + current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
84441 + if (current_ev == previous_ev)
84442 +#if WIRELESS_EXT >= 17
84443 + return -E2BIG;
84444 +#else
84445 + break;
84446 +#endif
84447 +
84448 + //Encyption key
84449 + //================================
84450 + memset(&iwe, 0, sizeof(iwe));
84451 + iwe.cmd = SIOCGIWENCODE;
84452 + if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
84453 + iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
84454 + else
84455 + iwe.u.data.flags = IW_ENCODE_DISABLED;
84456 +
84457 + previous_ev = current_ev;
84458 + current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, (char *)pAdapter->SharedKey[BSS0][(iwe.u.data.flags & IW_ENCODE_INDEX)-1].Key);
84459 + if (current_ev == previous_ev)
84460 +#if WIRELESS_EXT >= 17
84461 + return -E2BIG;
84462 +#else
84463 + break;
84464 +#endif
84465 +
84466 + //Bit Rate
84467 + //================================
84468 + if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
84469 + {
84470 + UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
84471 + memset(&iwe, 0, sizeof(iwe));
84472 + iwe.cmd = SIOCGIWRATE;
84473 + current_val = current_ev + IW_EV_LCP_LEN;
84474 + if (tmpRate == 0x82)
84475 + iwe.u.bitrate.value = 1 * 1000000;
84476 + else if (tmpRate == 0x84)
84477 + iwe.u.bitrate.value = 2 * 1000000;
84478 + else if (tmpRate == 0x8B)
84479 + iwe.u.bitrate.value = 5.5 * 1000000;
84480 + else if (tmpRate == 0x96)
84481 + iwe.u.bitrate.value = 11 * 1000000;
84482 + else
84483 + iwe.u.bitrate.value = (tmpRate/2) * 1000000;
84484 +
84485 + iwe.u.bitrate.disabled = 0;
84486 + current_val = iwe_stream_add_value(info, current_ev,
84487 + current_val, end_buf, &iwe,
84488 + IW_EV_PARAM_LEN);
84489 +
84490 + if((current_val-current_ev)>IW_EV_LCP_LEN)
84491 + current_ev = current_val;
84492 + else
84493 +#if WIRELESS_EXT >= 17
84494 + return -E2BIG;
84495 +#else
84496 + break;
84497 +#endif
84498 + }
84499 +
84500 +#ifdef IWEVGENIE
84501 + //WPA IE
84502 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
84503 + {
84504 + memset(&iwe, 0, sizeof(iwe));
84505 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
84506 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
84507 + pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
84508 + iwe.cmd = IWEVGENIE;
84509 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
84510 + current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
84511 + if (current_ev == previous_ev)
84512 +#if WIRELESS_EXT >= 17
84513 + return -E2BIG;
84514 +#else
84515 + break;
84516 +#endif
84517 + }
84518 +
84519 + //WPA2 IE
84520 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
84521 + {
84522 + memset(&iwe, 0, sizeof(iwe));
84523 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
84524 + memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
84525 + pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
84526 + iwe.cmd = IWEVGENIE;
84527 + iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
84528 + current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
84529 + if (current_ev == previous_ev)
84530 +#if WIRELESS_EXT >= 17
84531 + return -E2BIG;
84532 +#else
84533 + break;
84534 +#endif
84535 + }
84536 +#else
84537 + //WPA IE
84538 + //================================
84539 + if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
84540 + {
84541 + NdisZeroMemory(&iwe, sizeof(iwe));
84542 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
84543 + iwe.cmd = IWEVCUSTOM;
84544 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
84545 + NdisMoveMemory(custom, "wpa_ie=", 7);
84546 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
84547 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
84548 + previous_ev = current_ev;
84549 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
84550 + if (current_ev == previous_ev)
84551 +#if WIRELESS_EXT >= 17
84552 + return -E2BIG;
84553 +#else
84554 + break;
84555 +#endif
84556 + }
84557 +
84558 + //WPA2 IE
84559 + if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
84560 + {
84561 + NdisZeroMemory(&iwe, sizeof(iwe));
84562 + memset(&custom[0], 0, MAX_CUSTOM_LEN);
84563 + iwe.cmd = IWEVCUSTOM;
84564 + iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
84565 + NdisMoveMemory(custom, "rsn_ie=", 7);
84566 + for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
84567 + sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
84568 + previous_ev = current_ev;
84569 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
84570 + if (current_ev == previous_ev)
84571 +#if WIRELESS_EXT >= 17
84572 + return -E2BIG;
84573 +#else
84574 + break;
84575 +#endif
84576 + }
84577 +#endif // IWEVGENIE //
84578 + }
84579 +
84580 + data->length = current_ev - extra;
84581 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
84582 + DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
84583 + return 0;
84584 +}
84585 +#endif
84586 +
84587 +int rt_ioctl_siwessid(struct net_device *dev,
84588 + struct iw_request_info *info,
84589 + struct iw_point *data, char *essid)
84590 +{
84591 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84592 +
84593 + //check if the interface is down
84594 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84595 + {
84596 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84597 + return -ENETDOWN;
84598 + }
84599 +
84600 + if (data->flags)
84601 + {
84602 + PCHAR pSsidString = NULL;
84603 +
84604 + // Includes null character.
84605 + if (data->length > (IW_ESSID_MAX_SIZE + 1))
84606 + return -E2BIG;
84607 +
84608 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
84609 + if (pSsidString)
84610 + {
84611 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
84612 + NdisMoveMemory(pSsidString, essid, data->length);
84613 + if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
84614 + return -EINVAL;
84615 + }
84616 + else
84617 + return -ENOMEM;
84618 + }
84619 + else
84620 + {
84621 + // ANY ssid
84622 + if (Set_SSID_Proc(pAdapter, "") == FALSE)
84623 + return -EINVAL;
84624 + }
84625 + return 0;
84626 +}
84627 +
84628 +int rt_ioctl_giwessid(struct net_device *dev,
84629 + struct iw_request_info *info,
84630 + struct iw_point *data, char *essid)
84631 +{
84632 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84633 +
84634 + data->flags = 1;
84635 + if (MONITOR_ON(pAdapter))
84636 + {
84637 + data->length = 0;
84638 + return 0;
84639 + }
84640 +
84641 + if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
84642 + {
84643 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
84644 + data->length = pAdapter->CommonCfg.SsidLen;
84645 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
84646 + }
84647 +#ifdef RT2870
84648 +#ifdef WPA_SUPPLICANT_SUPPORT
84649 + // Add for RT2870
84650 + else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
84651 + {
84652 + data->length = pAdapter->CommonCfg.SsidLen;
84653 + memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
84654 + }
84655 +#endif // WPA_SUPPLICANT_SUPPORT //
84656 +#endif // RT2870 //
84657 + else
84658 + {//the ANY ssid was specified
84659 + data->length = 0;
84660 + DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
84661 + }
84662 +
84663 + return 0;
84664 +
84665 +}
84666 +
84667 +int rt_ioctl_siwnickn(struct net_device *dev,
84668 + struct iw_request_info *info,
84669 + struct iw_point *data, char *nickname)
84670 +{
84671 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84672 +
84673 + //check if the interface is down
84674 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84675 + {
84676 + DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
84677 + return -ENETDOWN;
84678 + }
84679 +
84680 + if (data->length > IW_ESSID_MAX_SIZE)
84681 + return -EINVAL;
84682 +
84683 + memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
84684 + memcpy(pAdapter->nickname, nickname, data->length);
84685 +
84686 +
84687 + return 0;
84688 +}
84689 +
84690 +int rt_ioctl_giwnickn(struct net_device *dev,
84691 + struct iw_request_info *info,
84692 + struct iw_point *data, char *nickname)
84693 +{
84694 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84695 +
84696 + if (data->length > strlen(pAdapter->nickname) + 1)
84697 + data->length = strlen(pAdapter->nickname) + 1;
84698 + if (data->length > 0) {
84699 + memcpy(nickname, pAdapter->nickname, data->length-1);
84700 + nickname[data->length-1] = '\0';
84701 + }
84702 + return 0;
84703 +}
84704 +
84705 +int rt_ioctl_siwrts(struct net_device *dev,
84706 + struct iw_request_info *info,
84707 + struct iw_param *rts, char *extra)
84708 +{
84709 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84710 + u16 val;
84711 +
84712 + //check if the interface is down
84713 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84714 + {
84715 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84716 + return -ENETDOWN;
84717 + }
84718 +
84719 + if (rts->disabled)
84720 + val = MAX_RTS_THRESHOLD;
84721 + else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
84722 + return -EINVAL;
84723 + else if (rts->value == 0)
84724 + val = MAX_RTS_THRESHOLD;
84725 + else
84726 + val = rts->value;
84727 +
84728 + if (val != pAdapter->CommonCfg.RtsThreshold)
84729 + pAdapter->CommonCfg.RtsThreshold = val;
84730 +
84731 + return 0;
84732 +}
84733 +
84734 +int rt_ioctl_giwrts(struct net_device *dev,
84735 + struct iw_request_info *info,
84736 + struct iw_param *rts, char *extra)
84737 +{
84738 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84739 +
84740 + //check if the interface is down
84741 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84742 + {
84743 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84744 + return -ENETDOWN;
84745 + }
84746 +
84747 + rts->value = pAdapter->CommonCfg.RtsThreshold;
84748 + rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
84749 + rts->fixed = 1;
84750 +
84751 + return 0;
84752 +}
84753 +
84754 +int rt_ioctl_siwfrag(struct net_device *dev,
84755 + struct iw_request_info *info,
84756 + struct iw_param *frag, char *extra)
84757 +{
84758 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84759 + u16 val;
84760 +
84761 + //check if the interface is down
84762 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84763 + {
84764 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84765 + return -ENETDOWN;
84766 + }
84767 +
84768 + if (frag->disabled)
84769 + val = MAX_FRAG_THRESHOLD;
84770 + else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
84771 + val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
84772 + else if (frag->value == 0)
84773 + val = MAX_FRAG_THRESHOLD;
84774 + else
84775 + return -EINVAL;
84776 +
84777 + pAdapter->CommonCfg.FragmentThreshold = val;
84778 + return 0;
84779 +}
84780 +
84781 +int rt_ioctl_giwfrag(struct net_device *dev,
84782 + struct iw_request_info *info,
84783 + struct iw_param *frag, char *extra)
84784 +{
84785 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84786 +
84787 + //check if the interface is down
84788 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84789 + {
84790 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84791 + return -ENETDOWN;
84792 + }
84793 +
84794 + frag->value = pAdapter->CommonCfg.FragmentThreshold;
84795 + frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
84796 + frag->fixed = 1;
84797 +
84798 + return 0;
84799 +}
84800 +
84801 +#define MAX_WEP_KEY_SIZE 13
84802 +#define MIN_WEP_KEY_SIZE 5
84803 +int rt_ioctl_siwencode(struct net_device *dev,
84804 + struct iw_request_info *info,
84805 + struct iw_point *erq, char *extra)
84806 +{
84807 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84808 +
84809 + //check if the interface is down
84810 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84811 + {
84812 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84813 + return -ENETDOWN;
84814 + }
84815 +
84816 + if ((erq->length == 0) &&
84817 + (erq->flags & IW_ENCODE_DISABLED))
84818 + {
84819 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
84820 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
84821 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
84822 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84823 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
84824 + goto done;
84825 + }
84826 + else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
84827 + {
84828 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
84829 + STA_PORT_SECURED(pAdapter);
84830 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
84831 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
84832 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
84833 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
84834 + if (erq->flags & IW_ENCODE_RESTRICTED)
84835 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
84836 + else
84837 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
84838 + }
84839 +
84840 + if (erq->length > 0)
84841 + {
84842 + int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
84843 + /* Check the size of the key */
84844 + if (erq->length > MAX_WEP_KEY_SIZE)
84845 + {
84846 + return -EINVAL;
84847 + }
84848 + /* Check key index */
84849 + if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
84850 + {
84851 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
84852 + keyIdx, pAdapter->StaCfg.DefaultKeyId));
84853 +
84854 + //Using default key
84855 + keyIdx = pAdapter->StaCfg.DefaultKeyId;
84856 + }
84857 + else
84858 + {
84859 + pAdapter->StaCfg.DefaultKeyId=keyIdx;
84860 + }
84861 +
84862 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
84863 +
84864 + if (erq->length == MAX_WEP_KEY_SIZE)
84865 + {
84866 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
84867 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
84868 + }
84869 + else if (erq->length == MIN_WEP_KEY_SIZE)
84870 + {
84871 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
84872 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
84873 + }
84874 + else
84875 + /* Disable the key */
84876 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
84877 +
84878 + /* Check if the key is not marked as invalid */
84879 + if(!(erq->flags & IW_ENCODE_NOKEY))
84880 + {
84881 + /* Copy the key in the driver */
84882 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
84883 + }
84884 + }
84885 + else
84886 + {
84887 + /* Do we want to just set the transmit key index ? */
84888 + int index = (erq->flags & IW_ENCODE_INDEX) - 1;
84889 + if ((index >= 0) && (index < 4))
84890 + {
84891 + pAdapter->StaCfg.DefaultKeyId = index;
84892 + }
84893 + else
84894 + /* Don't complain if only change the mode */
84895 + if(!erq->flags & IW_ENCODE_MODE)
84896 + {
84897 + return -EINVAL;
84898 + }
84899 + }
84900 +
84901 +done:
84902 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
84903 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
84904 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
84905 + DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
84906 + return 0;
84907 +}
84908 +
84909 +int
84910 +rt_ioctl_giwencode(struct net_device *dev,
84911 + struct iw_request_info *info,
84912 + struct iw_point *erq, char *key)
84913 +{
84914 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
84915 + int kid;
84916 +
84917 + //check if the interface is down
84918 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
84919 + {
84920 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
84921 + return -ENETDOWN;
84922 + }
84923 +
84924 + kid = erq->flags & IW_ENCODE_INDEX;
84925 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
84926 +
84927 + if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
84928 + {
84929 + erq->length = 0;
84930 + erq->flags = IW_ENCODE_DISABLED;
84931 + }
84932 + else if ((kid > 0) && (kid <=4))
84933 + {
84934 + // copy wep key
84935 + erq->flags = kid ; /* NB: base 1 */
84936 + if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
84937 + erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
84938 + memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
84939 + //if ((kid == pAdapter->PortCfg.DefaultKeyId))
84940 + //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
84941 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84942 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84943 + else
84944 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84945 +
84946 + }
84947 + else if (kid == 0)
84948 + {
84949 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84950 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84951 + else
84952 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84953 + erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
84954 + memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
84955 + // copy default key ID
84956 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
84957 + erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
84958 + else
84959 + erq->flags |= IW_ENCODE_OPEN; /* XXX */
84960 + erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
84961 + erq->flags |= IW_ENCODE_ENABLED; /* XXX */
84962 + }
84963 +
84964 + return 0;
84965 +
84966 +}
84967 +
84968 +static int
84969 +rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
84970 + void *w, char *extra)
84971 +{
84972 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
84973 + PRTMP_ADAPTER pAdapter;
84974 + POS_COOKIE pObj;
84975 + char *this_char = extra;
84976 + char *value;
84977 + int Status=0;
84978 +
84979 + if (dev->priv_flags == INT_MAIN)
84980 + {
84981 + pAdapter = dev->ml_priv;
84982 + }
84983 + else
84984 + {
84985 + pVirtualAd = dev->ml_priv;
84986 + pAdapter = pVirtualAd->RtmpDev->ml_priv;
84987 + }
84988 + pObj = (POS_COOKIE) pAdapter->OS_Cookie;
84989 +
84990 + if (pAdapter == NULL)
84991 + {
84992 + /* if 1st open fail, pAd will be free;
84993 + So the net_dev->ml_priv will be NULL in 2rd open */
84994 + return -ENETDOWN;
84995 + }
84996 +
84997 + {
84998 + pObj->ioctl_if_type = INT_MAIN;
84999 + pObj->ioctl_if = MAIN_MBSSID;
85000 + }
85001 +
85002 + //check if the interface is down
85003 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85004 + {
85005 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
85006 + return -ENETDOWN;
85007 + }
85008 +
85009 + if (!*this_char)
85010 + return -EINVAL;
85011 +
85012 + if ((value = rtstrchr(this_char, '=')) != NULL)
85013 + *value++ = 0;
85014 +
85015 + if (!value)
85016 + return -EINVAL;
85017 +
85018 + // reject setting nothing besides ANY ssid(ssidLen=0)
85019 + if (!*value && (strcmp(this_char, "SSID") != 0))
85020 + return -EINVAL;
85021 +
85022 + for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
85023 + {
85024 + if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
85025 + {
85026 + if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
85027 + { //FALSE:Set private failed then return Invalid argument
85028 + Status = -EINVAL;
85029 + }
85030 + break; //Exit for loop.
85031 + }
85032 + }
85033 +
85034 + if(PRTMP_PRIVATE_SET_PROC->name == NULL)
85035 + { //Not found argument
85036 + Status = -EINVAL;
85037 + DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
85038 + }
85039 +
85040 + return Status;
85041 +}
85042 +
85043 +
85044 +static int
85045 +rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
85046 + struct iw_point *wrq, char *extra)
85047 +{
85048 + INT Status = 0;
85049 + PRTMP_ADAPTER pAd = dev->ml_priv;
85050 +
85051 + if (extra == NULL)
85052 + {
85053 + wrq->length = 0;
85054 + return -EIO;
85055 + }
85056 +
85057 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
85058 + sprintf(extra, "\n\n");
85059 +
85060 +#ifdef RALINK_ATE
85061 + if (ATE_ON(pAd))
85062 + {
85063 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
85064 + //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
85065 + }
85066 + else
85067 +#endif // RALINK_ATE //
85068 + {
85069 + sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
85070 + sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
85071 + }
85072 + sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
85073 + sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
85074 + sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
85075 + sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
85076 +
85077 + sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
85078 + sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
85079 + sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
85080 + sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
85081 +
85082 + sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
85083 +#ifdef RALINK_ATE
85084 + if (ATE_ON(pAd))
85085 + {
85086 + if (pAd->ate.RxAntennaSel == 0)
85087 + {
85088 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
85089 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
85090 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
85091 + }
85092 + else
85093 + {
85094 + sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
85095 + }
85096 + }
85097 + else
85098 +#endif // RALINK_ATE //
85099 + {
85100 + sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
85101 + sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
85102 + sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
85103 + }
85104 +#ifdef WPA_SUPPLICANT_SUPPORT
85105 + sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
85106 +#endif // WPA_SUPPLICANT_SUPPORT //
85107 +
85108 +
85109 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85110 + DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
85111 +
85112 + return Status;
85113 +}
85114 +
85115 +#ifdef DOT11_N_SUPPORT
85116 +void getBaInfo(
85117 + IN PRTMP_ADAPTER pAd,
85118 + IN PUCHAR pOutBuf)
85119 +{
85120 + INT i, j;
85121 + BA_ORI_ENTRY *pOriBAEntry;
85122 + BA_REC_ENTRY *pRecBAEntry;
85123 +
85124 + for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
85125 + {
85126 + PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
85127 + if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
85128 + || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
85129 + {
85130 + sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
85131 + pOutBuf,
85132 + pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
85133 + pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
85134 +
85135 + sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
85136 + for (j=0; j < NUM_OF_TID; j++)
85137 + {
85138 + if (pEntry->BARecWcidArray[j] != 0)
85139 + {
85140 + pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
85141 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
85142 + }
85143 + }
85144 + sprintf(pOutBuf, "%s\n", pOutBuf);
85145 +
85146 + sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
85147 + for (j=0; j < NUM_OF_TID; j++)
85148 + {
85149 + if (pEntry->BAOriWcidArray[j] != 0)
85150 + {
85151 + pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
85152 + sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
85153 + }
85154 + }
85155 + sprintf(pOutBuf, "%s\n\n", pOutBuf);
85156 + }
85157 + if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
85158 + break;
85159 + }
85160 +
85161 + return;
85162 +}
85163 +#endif // DOT11_N_SUPPORT //
85164 +
85165 +static int
85166 +rt_private_show(struct net_device *dev, struct iw_request_info *info,
85167 + struct iw_point *wrq, char *extra)
85168 +{
85169 + INT Status = 0;
85170 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
85171 + PRTMP_ADAPTER pAd;
85172 + POS_COOKIE pObj;
85173 + u32 subcmd = wrq->flags;
85174 +
85175 + if (dev->priv_flags == INT_MAIN)
85176 + pAd = dev->ml_priv;
85177 + else
85178 + {
85179 + pVirtualAd = dev->ml_priv;
85180 + pAd = pVirtualAd->RtmpDev->ml_priv;
85181 + }
85182 + pObj = (POS_COOKIE) pAd->OS_Cookie;
85183 +
85184 + if (pAd == NULL)
85185 + {
85186 + /* if 1st open fail, pAd will be free;
85187 + So the net_dev->ml_priv will be NULL in 2rd open */
85188 + return -ENETDOWN;
85189 + }
85190 +
85191 + if (extra == NULL)
85192 + {
85193 + wrq->length = 0;
85194 + return -EIO;
85195 + }
85196 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
85197 +
85198 + {
85199 + pObj->ioctl_if_type = INT_MAIN;
85200 + pObj->ioctl_if = MAIN_MBSSID;
85201 + }
85202 +
85203 + switch(subcmd)
85204 + {
85205 +
85206 + case SHOW_CONN_STATUS:
85207 + if (MONITOR_ON(pAd))
85208 + {
85209 +#ifdef DOT11_N_SUPPORT
85210 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
85211 + pAd->CommonCfg.RegTransmitSetting.field.BW)
85212 + sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
85213 + else
85214 +#endif // DOT11_N_SUPPORT //
85215 + sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
85216 + }
85217 + else
85218 + {
85219 + if (pAd->IndicateMediaState == NdisMediaStateConnected)
85220 + {
85221 + if (INFRA_ON(pAd))
85222 + {
85223 + sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
85224 + pAd->CommonCfg.Ssid,
85225 + pAd->CommonCfg.Bssid[0],
85226 + pAd->CommonCfg.Bssid[1],
85227 + pAd->CommonCfg.Bssid[2],
85228 + pAd->CommonCfg.Bssid[3],
85229 + pAd->CommonCfg.Bssid[4],
85230 + pAd->CommonCfg.Bssid[5]);
85231 + DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
85232 + }
85233 + else if (ADHOC_ON(pAd))
85234 + sprintf(extra, "Connected\n");
85235 + }
85236 + else
85237 + {
85238 + sprintf(extra, "Disconnected\n");
85239 + DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
85240 + }
85241 + }
85242 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85243 + break;
85244 + case SHOW_DRVIER_VERION:
85245 + sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
85246 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85247 + break;
85248 +#ifdef DOT11_N_SUPPORT
85249 + case SHOW_BA_INFO:
85250 + getBaInfo(pAd, extra);
85251 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85252 + break;
85253 +#endif // DOT11_N_SUPPORT //
85254 + case SHOW_DESC_INFO:
85255 + {
85256 + Show_DescInfo_Proc(pAd, NULL);
85257 + wrq->length = 0; // 1: size of '\0'
85258 + }
85259 + break;
85260 + case RAIO_OFF:
85261 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
85262 + {
85263 + sprintf(extra, "Scanning\n");
85264 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85265 + break;
85266 + }
85267 + pAd->StaCfg.bSwRadio = FALSE;
85268 + if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
85269 + {
85270 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
85271 + if (pAd->StaCfg.bRadio == FALSE)
85272 + {
85273 + MlmeRadioOff(pAd);
85274 + // Update extra information
85275 + pAd->ExtraInfo = SW_RADIO_OFF;
85276 + }
85277 + }
85278 + sprintf(extra, "Radio Off\n");
85279 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85280 + break;
85281 + case RAIO_ON:
85282 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
85283 + {
85284 + sprintf(extra, "Scanning\n");
85285 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85286 + break;
85287 + }
85288 + pAd->StaCfg.bSwRadio = TRUE;
85289 + //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
85290 + {
85291 + pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
85292 + if (pAd->StaCfg.bRadio == TRUE)
85293 + {
85294 + MlmeRadioOn(pAd);
85295 + // Update extra information
85296 + pAd->ExtraInfo = EXTRA_INFO_CLEAR;
85297 + }
85298 + }
85299 + sprintf(extra, "Radio On\n");
85300 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85301 + break;
85302 +
85303 +
85304 +#ifdef QOS_DLS_SUPPORT
85305 + case SHOW_DLS_ENTRY_INFO:
85306 + {
85307 + Set_DlsEntryInfo_Display_Proc(pAd, NULL);
85308 + wrq->length = 0; // 1: size of '\0'
85309 + }
85310 + break;
85311 +#endif // QOS_DLS_SUPPORT //
85312 +
85313 + case SHOW_CFG_VALUE:
85314 + {
85315 + Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
85316 + if (Status == 0)
85317 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
85318 + }
85319 + break;
85320 + default:
85321 + DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __FUNCTION__, subcmd));
85322 + break;
85323 + }
85324 +
85325 + return Status;
85326 +}
85327 +
85328 +#ifdef SIOCSIWMLME
85329 +int rt_ioctl_siwmlme(struct net_device *dev,
85330 + struct iw_request_info *info,
85331 + union iwreq_data *wrqu,
85332 + char *extra)
85333 +{
85334 + PRTMP_ADAPTER pAd = dev->ml_priv;
85335 + struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
85336 + MLME_QUEUE_ELEM MsgElem;
85337 + MLME_DISASSOC_REQ_STRUCT DisAssocReq;
85338 + MLME_DEAUTH_REQ_STRUCT DeAuthReq;
85339 +
85340 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __FUNCTION__));
85341 +
85342 + if (pMlme == NULL)
85343 + return -EINVAL;
85344 +
85345 + switch(pMlme->cmd)
85346 + {
85347 +#ifdef IW_MLME_DEAUTH
85348 + case IW_MLME_DEAUTH:
85349 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __FUNCTION__));
85350 + COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
85351 + DeAuthReq.Reason = pMlme->reason_code;
85352 + MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
85353 + NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
85354 + MlmeDeauthReqAction(pAd, &MsgElem);
85355 + if (INFRA_ON(pAd))
85356 + {
85357 + LinkDown(pAd, FALSE);
85358 + pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
85359 + }
85360 + break;
85361 +#endif // IW_MLME_DEAUTH //
85362 +#ifdef IW_MLME_DISASSOC
85363 + case IW_MLME_DISASSOC:
85364 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __FUNCTION__));
85365 + COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
85366 + DisAssocReq.Reason = pMlme->reason_code;
85367 +
85368 + MsgElem.Machine = ASSOC_STATE_MACHINE;
85369 + MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
85370 + MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
85371 + NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
85372 +
85373 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
85374 + MlmeDisassocReqAction(pAd, &MsgElem);
85375 + break;
85376 +#endif // IW_MLME_DISASSOC //
85377 + default:
85378 + DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __FUNCTION__));
85379 + break;
85380 + }
85381 +
85382 + return 0;
85383 +}
85384 +#endif // SIOCSIWMLME //
85385 +
85386 +#if WIRELESS_EXT > 17
85387 +int rt_ioctl_siwauth(struct net_device *dev,
85388 + struct iw_request_info *info,
85389 + union iwreq_data *wrqu, char *extra)
85390 +{
85391 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
85392 + struct iw_param *param = &wrqu->param;
85393 +
85394 + //check if the interface is down
85395 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85396 + {
85397 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
85398 + return -ENETDOWN;
85399 + }
85400 + switch (param->flags & IW_AUTH_INDEX) {
85401 + case IW_AUTH_WPA_VERSION:
85402 + if (param->value == IW_AUTH_WPA_VERSION_WPA)
85403 + {
85404 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
85405 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
85406 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
85407 + }
85408 + else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
85409 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
85410 +
85411 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
85412 + break;
85413 + case IW_AUTH_CIPHER_PAIRWISE:
85414 + if (param->value == IW_AUTH_CIPHER_NONE)
85415 + {
85416 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
85417 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
85418 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
85419 + }
85420 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
85421 + param->value == IW_AUTH_CIPHER_WEP104)
85422 + {
85423 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
85424 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
85425 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
85426 +#ifdef WPA_SUPPLICANT_SUPPORT
85427 + pAdapter->StaCfg.IEEE8021X = FALSE;
85428 +#endif // WPA_SUPPLICANT_SUPPORT //
85429 + }
85430 + else if (param->value == IW_AUTH_CIPHER_TKIP)
85431 + {
85432 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
85433 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
85434 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
85435 + }
85436 + else if (param->value == IW_AUTH_CIPHER_CCMP)
85437 + {
85438 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
85439 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
85440 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
85441 + }
85442 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __FUNCTION__, param->value));
85443 + break;
85444 + case IW_AUTH_CIPHER_GROUP:
85445 + if (param->value == IW_AUTH_CIPHER_NONE)
85446 + {
85447 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
85448 + }
85449 + else if (param->value == IW_AUTH_CIPHER_WEP40 ||
85450 + param->value == IW_AUTH_CIPHER_WEP104)
85451 + {
85452 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
85453 + }
85454 + else if (param->value == IW_AUTH_CIPHER_TKIP)
85455 + {
85456 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
85457 + }
85458 + else if (param->value == IW_AUTH_CIPHER_CCMP)
85459 + {
85460 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
85461 + }
85462 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __FUNCTION__, param->value));
85463 + break;
85464 + case IW_AUTH_KEY_MGMT:
85465 + if (param->value == IW_AUTH_KEY_MGMT_802_1X)
85466 + {
85467 + if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
85468 + {
85469 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
85470 +#ifdef WPA_SUPPLICANT_SUPPORT
85471 + pAdapter->StaCfg.IEEE8021X = FALSE;
85472 +#endif // WPA_SUPPLICANT_SUPPORT //
85473 + }
85474 + else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
85475 + {
85476 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
85477 +#ifdef WPA_SUPPLICANT_SUPPORT
85478 + pAdapter->StaCfg.IEEE8021X = FALSE;
85479 +#endif // WPA_SUPPLICANT_SUPPORT //
85480 + }
85481 +#ifdef WPA_SUPPLICANT_SUPPORT
85482 + else
85483 + // WEP 1x
85484 + pAdapter->StaCfg.IEEE8021X = TRUE;
85485 +#endif // WPA_SUPPLICANT_SUPPORT //
85486 + }
85487 + else if (param->value == 0)
85488 + {
85489 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85490 + STA_PORT_SECURED(pAdapter);
85491 + }
85492 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __FUNCTION__, param->value));
85493 + break;
85494 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
85495 + break;
85496 + case IW_AUTH_PRIVACY_INVOKED:
85497 + /*if (param->value == 0)
85498 + {
85499 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
85500 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
85501 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
85502 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
85503 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
85504 + }*/
85505 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __FUNCTION__, param->value));
85506 + break;
85507 + case IW_AUTH_DROP_UNENCRYPTED:
85508 + if (param->value != 0)
85509 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
85510 + else
85511 + {
85512 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85513 + STA_PORT_SECURED(pAdapter);
85514 + }
85515 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __FUNCTION__, param->value));
85516 + break;
85517 + case IW_AUTH_80211_AUTH_ALG:
85518 + if (param->value & IW_AUTH_ALG_SHARED_KEY)
85519 + {
85520 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
85521 + }
85522 + else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
85523 + {
85524 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
85525 + }
85526 + else
85527 + return -EINVAL;
85528 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __FUNCTION__, param->value));
85529 + break;
85530 + case IW_AUTH_WPA_ENABLED:
85531 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __FUNCTION__, param->value));
85532 + break;
85533 + default:
85534 + return -EOPNOTSUPP;
85535 +}
85536 +
85537 + return 0;
85538 +}
85539 +
85540 +int rt_ioctl_giwauth(struct net_device *dev,
85541 + struct iw_request_info *info,
85542 + union iwreq_data *wrqu, char *extra)
85543 +{
85544 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
85545 + struct iw_param *param = &wrqu->param;
85546 +
85547 + //check if the interface is down
85548 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85549 + {
85550 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
85551 + return -ENETDOWN;
85552 + }
85553 +
85554 + switch (param->flags & IW_AUTH_INDEX) {
85555 + case IW_AUTH_DROP_UNENCRYPTED:
85556 + param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
85557 + break;
85558 +
85559 + case IW_AUTH_80211_AUTH_ALG:
85560 + param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
85561 + break;
85562 +
85563 + case IW_AUTH_WPA_ENABLED:
85564 + param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
85565 + break;
85566 +
85567 + default:
85568 + return -EOPNOTSUPP;
85569 + }
85570 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
85571 + return 0;
85572 +}
85573 +
85574 +void fnSetCipherKey(
85575 + IN PRTMP_ADAPTER pAdapter,
85576 + IN INT keyIdx,
85577 + IN UCHAR CipherAlg,
85578 + IN BOOLEAN bGTK,
85579 + IN struct iw_encode_ext *ext)
85580 +{
85581 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
85582 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
85583 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
85584 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
85585 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
85586 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
85587 +
85588 + // Update group key information to ASIC Shared Key Table
85589 + AsicAddSharedKeyEntry(pAdapter,
85590 + BSS0,
85591 + keyIdx,
85592 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
85593 + pAdapter->SharedKey[BSS0][keyIdx].Key,
85594 + pAdapter->SharedKey[BSS0][keyIdx].TxMic,
85595 + pAdapter->SharedKey[BSS0][keyIdx].RxMic);
85596 +
85597 + if (bGTK)
85598 + // Update ASIC WCID attribute table and IVEIV table
85599 + RTMPAddWcidAttributeEntry(pAdapter,
85600 + BSS0,
85601 + keyIdx,
85602 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
85603 + NULL);
85604 + else
85605 + // Update ASIC WCID attribute table and IVEIV table
85606 + RTMPAddWcidAttributeEntry(pAdapter,
85607 + BSS0,
85608 + keyIdx,
85609 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
85610 + &pAdapter->MacTab.Content[BSSID_WCID]);
85611 +}
85612 +
85613 +int rt_ioctl_siwencodeext(struct net_device *dev,
85614 + struct iw_request_info *info,
85615 + union iwreq_data *wrqu,
85616 + char *extra)
85617 + {
85618 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
85619 + struct iw_point *encoding = &wrqu->encoding;
85620 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
85621 + int keyIdx, alg = ext->alg;
85622 +
85623 + //check if the interface is down
85624 + if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
85625 + {
85626 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
85627 + return -ENETDOWN;
85628 + }
85629 +
85630 + if (encoding->flags & IW_ENCODE_DISABLED)
85631 + {
85632 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
85633 + // set BSSID wcid entry of the Pair-wise Key table as no-security mode
85634 + AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
85635 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
85636 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
85637 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
85638 + NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
85639 + DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __FUNCTION__, encoding->flags));
85640 + }
85641 + else
85642 + {
85643 + // Get Key Index and convet to our own defined key index
85644 + keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
85645 + if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
85646 + return -EINVAL;
85647 +
85648 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
85649 + {
85650 + pAdapter->StaCfg.DefaultKeyId = keyIdx;
85651 + DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __FUNCTION__, pAdapter->StaCfg.DefaultKeyId));
85652 + }
85653 +
85654 + switch (alg) {
85655 + case IW_ENCODE_ALG_NONE:
85656 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __FUNCTION__));
85657 + break;
85658 + case IW_ENCODE_ALG_WEP:
85659 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __FUNCTION__, ext->key_len, keyIdx));
85660 + if (ext->key_len == MAX_WEP_KEY_SIZE)
85661 + {
85662 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
85663 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
85664 + }
85665 + else if (ext->key_len == MIN_WEP_KEY_SIZE)
85666 + {
85667 + pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
85668 + pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
85669 + }
85670 + else
85671 + return -EINVAL;
85672 +
85673 + NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
85674 + NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
85675 + break;
85676 + case IW_ENCODE_ALG_TKIP:
85677 + DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __FUNCTION__, keyIdx, ext->key_len));
85678 + if (ext->key_len == 32)
85679 + {
85680 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
85681 + {
85682 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
85683 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
85684 + {
85685 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85686 + STA_PORT_SECURED(pAdapter);
85687 + }
85688 + }
85689 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
85690 + {
85691 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
85692 +
85693 + // set 802.1x port control
85694 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85695 + STA_PORT_SECURED(pAdapter);
85696 + }
85697 + }
85698 + else
85699 + return -EINVAL;
85700 + break;
85701 + case IW_ENCODE_ALG_CCMP:
85702 + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
85703 + {
85704 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
85705 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
85706 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85707 + STA_PORT_SECURED(pAdapter);
85708 + }
85709 + else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
85710 + {
85711 + fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
85712 +
85713 + // set 802.1x port control
85714 + //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
85715 + STA_PORT_SECURED(pAdapter);
85716 + }
85717 + break;
85718 + default:
85719 + return -EINVAL;
85720 + }
85721 + }
85722 +
85723 + return 0;
85724 +}
85725 +
85726 +int
85727 +rt_ioctl_giwencodeext(struct net_device *dev,
85728 + struct iw_request_info *info,
85729 + union iwreq_data *wrqu, char *extra)
85730 +{
85731 + PRTMP_ADAPTER pAd = dev->ml_priv;
85732 + PCHAR pKey = NULL;
85733 + struct iw_point *encoding = &wrqu->encoding;
85734 + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
85735 + int idx, max_key_len;
85736 +
85737 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
85738 +
85739 + max_key_len = encoding->length - sizeof(*ext);
85740 + if (max_key_len < 0)
85741 + return -EINVAL;
85742 +
85743 + idx = encoding->flags & IW_ENCODE_INDEX;
85744 + if (idx)
85745 + {
85746 + if (idx < 1 || idx > 4)
85747 + return -EINVAL;
85748 + idx--;
85749 +
85750 + if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
85751 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
85752 + {
85753 + if (idx != pAd->StaCfg.DefaultKeyId)
85754 + {
85755 + ext->key_len = 0;
85756 + return 0;
85757 + }
85758 + }
85759 + }
85760 + else
85761 + idx = pAd->StaCfg.DefaultKeyId;
85762 +
85763 + encoding->flags = idx + 1;
85764 + memset(ext, 0, sizeof(*ext));
85765 +
85766 + ext->key_len = 0;
85767 + switch(pAd->StaCfg.WepStatus) {
85768 + case Ndis802_11WEPDisabled:
85769 + ext->alg = IW_ENCODE_ALG_NONE;
85770 + encoding->flags |= IW_ENCODE_DISABLED;
85771 + break;
85772 + case Ndis802_11WEPEnabled:
85773 + ext->alg = IW_ENCODE_ALG_WEP;
85774 + if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
85775 + return -E2BIG;
85776 + else
85777 + {
85778 + ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
85779 + pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
85780 + }
85781 + break;
85782 + case Ndis802_11Encryption2Enabled:
85783 + case Ndis802_11Encryption3Enabled:
85784 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
85785 + ext->alg = IW_ENCODE_ALG_TKIP;
85786 + else
85787 + ext->alg = IW_ENCODE_ALG_CCMP;
85788 +
85789 + if (max_key_len < 32)
85790 + return -E2BIG;
85791 + else
85792 + {
85793 + ext->key_len = 32;
85794 + pKey = &pAd->StaCfg.PMK[0];
85795 + }
85796 + break;
85797 + default:
85798 + return -EINVAL;
85799 + }
85800 +
85801 + if (ext->key_len && pKey)
85802 + {
85803 + encoding->flags |= IW_ENCODE_ENABLED;
85804 + memcpy(ext->key, pKey, ext->key_len);
85805 + }
85806 +
85807 + return 0;
85808 +}
85809 +
85810 +#ifdef SIOCSIWGENIE
85811 +int rt_ioctl_siwgenie(struct net_device *dev,
85812 + struct iw_request_info *info,
85813 + union iwreq_data *wrqu, char *extra)
85814 +{
85815 + PRTMP_ADAPTER pAd = dev->ml_priv;
85816 +
85817 + if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
85818 + (wrqu->data.length && extra == NULL))
85819 + return -EINVAL;
85820 +
85821 + if (wrqu->data.length)
85822 + {
85823 + pAd->StaCfg.RSNIE_Len = wrqu->data.length;
85824 + NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
85825 + }
85826 + else
85827 + {
85828 + pAd->StaCfg.RSNIE_Len = 0;
85829 + NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
85830 + }
85831 +
85832 + return 0;
85833 +}
85834 +#endif // SIOCSIWGENIE //
85835 +
85836 +int rt_ioctl_giwgenie(struct net_device *dev,
85837 + struct iw_request_info *info,
85838 + union iwreq_data *wrqu, char *extra)
85839 +{
85840 + PRTMP_ADAPTER pAd = dev->ml_priv;
85841 +
85842 + if ((pAd->StaCfg.RSNIE_Len == 0) ||
85843 + (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
85844 + {
85845 + wrqu->data.length = 0;
85846 + return 0;
85847 + }
85848 +
85849 +#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
85850 +#ifdef SIOCSIWGENIE
85851 + if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
85852 + {
85853 + if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
85854 + return -E2BIG;
85855 +
85856 + wrqu->data.length = pAd->StaCfg.RSNIE_Len;
85857 + memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
85858 + }
85859 + else
85860 +#endif // SIOCSIWGENIE //
85861 +#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
85862 + {
85863 + UCHAR RSNIe = IE_WPA;
85864 +
85865 + if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
85866 + return -E2BIG;
85867 + wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
85868 +
85869 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
85870 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
85871 + RSNIe = IE_RSN;
85872 +
85873 + extra[0] = (char)RSNIe;
85874 + extra[1] = pAd->StaCfg.RSNIE_Len;
85875 + memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
85876 + }
85877 +
85878 + return 0;
85879 +}
85880 +
85881 +int rt_ioctl_siwpmksa(struct net_device *dev,
85882 + struct iw_request_info *info,
85883 + union iwreq_data *wrqu,
85884 + char *extra)
85885 +{
85886 + PRTMP_ADAPTER pAd = dev->ml_priv;
85887 + struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
85888 + INT CachedIdx = 0, idx = 0;
85889 +
85890 + if (pPmksa == NULL)
85891 + return -EINVAL;
85892 +
85893 + DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
85894 + switch(pPmksa->cmd)
85895 + {
85896 + case IW_PMKSA_FLUSH:
85897 + NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
85898 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
85899 + break;
85900 + case IW_PMKSA_REMOVE:
85901 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
85902 + {
85903 + // compare the BSSID
85904 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
85905 + {
85906 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
85907 + NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
85908 + for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
85909 + {
85910 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
85911 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
85912 + }
85913 + pAd->StaCfg.SavedPMKNum--;
85914 + break;
85915 + }
85916 + }
85917 +
85918 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
85919 + break;
85920 + case IW_PMKSA_ADD:
85921 + for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
85922 + {
85923 + // compare the BSSID
85924 + if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
85925 + break;
85926 + }
85927 +
85928 + // Found, replace it
85929 + if (CachedIdx < PMKID_NO)
85930 + {
85931 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
85932 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
85933 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
85934 + pAd->StaCfg.SavedPMKNum++;
85935 + }
85936 + // Not found, replace the last one
85937 + else
85938 + {
85939 + // Randomly replace one
85940 + CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
85941 + DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
85942 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
85943 + NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
85944 + }
85945 +
85946 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
85947 + break;
85948 + default:
85949 + DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
85950 + break;
85951 + }
85952 +
85953 + return 0;
85954 +}
85955 +#endif // #if WIRELESS_EXT > 17
85956 +
85957 +#ifdef DBG
85958 +static int
85959 +rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
85960 + struct iw_point *wrq, char *extra)
85961 + {
85962 + CHAR *this_char;
85963 + CHAR *value = NULL;
85964 + UCHAR regBBP = 0;
85965 +// CHAR arg[255]={0};
85966 + UINT32 bbpId;
85967 + UINT32 bbpValue;
85968 + BOOLEAN bIsPrintAllBBP = FALSE;
85969 + INT Status = 0;
85970 + PRTMP_ADAPTER pAdapter = dev->ml_priv;
85971 +
85972 +
85973 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
85974 +
85975 + if (wrq->length > 1) //No parameters.
85976 + {
85977 + sprintf(extra, "\n");
85978 +
85979 + //Parsing Read or Write
85980 + this_char = wrq->pointer;
85981 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
85982 + if (!*this_char)
85983 + goto next;
85984 +
85985 + if ((value = rtstrchr(this_char, '=')) != NULL)
85986 + *value++ = 0;
85987 +
85988 + if (!value || !*value)
85989 + { //Read
85990 + DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
85991 + if (sscanf(this_char, "%d", &(bbpId)) == 1)
85992 + {
85993 +#ifndef RT30xx
85994 + if (bbpId <= 136)
85995 +#endif // RT30xx //
85996 +#ifdef RT30xx
85997 + if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
85998 +#endif // RT30xx //
85999 + {
86000 +#ifdef RALINK_ATE
86001 + if (ATE_ON(pAdapter))
86002 + {
86003 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86004 + }
86005 + else
86006 +#endif // RALINK_ATE //
86007 + {
86008 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86009 + }
86010 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
86011 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
86012 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
86013 + }
86014 + else
86015 + {//Invalid parametes, so default printk all bbp
86016 + bIsPrintAllBBP = TRUE;
86017 + goto next;
86018 + }
86019 + }
86020 + else
86021 + { //Invalid parametes, so default printk all bbp
86022 + bIsPrintAllBBP = TRUE;
86023 + goto next;
86024 + }
86025 + }
86026 + else
86027 + { //Write
86028 + if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
86029 + {
86030 +#ifndef RT30xx
86031 + if (bbpId <= 136)
86032 +#endif // RT30xx //
86033 +#ifdef RT30xx
86034 + if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
86035 +#endif // RT30xx //
86036 + {
86037 +#ifdef RALINK_ATE
86038 + if (ATE_ON(pAdapter))
86039 + {
86040 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
86041 + //Read it back for showing
86042 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86043 + }
86044 + else
86045 +#endif // RALINK_ATE //
86046 + {
86047 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
86048 + //Read it back for showing
86049 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86050 + }
86051 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
86052 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
86053 + DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
86054 + }
86055 + else
86056 + {//Invalid parametes, so default printk all bbp
86057 + bIsPrintAllBBP = TRUE;
86058 + goto next;
86059 + }
86060 + }
86061 + else
86062 + { //Invalid parametes, so default printk all bbp
86063 + bIsPrintAllBBP = TRUE;
86064 + goto next;
86065 + }
86066 + }
86067 + }
86068 + else
86069 + bIsPrintAllBBP = TRUE;
86070 +
86071 +next:
86072 + if (bIsPrintAllBBP)
86073 + {
86074 + memset(extra, 0x00, IW_PRIV_SIZE_MASK);
86075 + sprintf(extra, "\n");
86076 +#ifndef RT30xx
86077 + for (bbpId = 0; bbpId <= 136; bbpId++)
86078 +#endif // RT30xx //
86079 +#ifdef RT30xx
86080 + for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
86081 +#endif // RT30xx //
86082 + {
86083 + if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
86084 + break;
86085 +#ifdef RALINK_ATE
86086 + if (ATE_ON(pAdapter))
86087 + {
86088 + ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86089 + }
86090 + else
86091 +#endif // RALINK_ATE //
86092 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
86093 +/*
86094 + sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
86095 + if (bbpId%5 == 4)
86096 + sprintf(extra+strlen(extra), "\n");
86097 +*/
86098 + sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
86099 + }
86100 +
86101 + wrq->length = strlen(extra) + 1; // 1: size of '\0'
86102 + DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
86103 + }
86104 +
86105 + DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
86106 +
86107 + return Status;
86108 +}
86109 +#endif // DBG //
86110 +
86111 +int rt_ioctl_siwrate(struct net_device *dev,
86112 + struct iw_request_info *info,
86113 + union iwreq_data *wrqu, char *extra)
86114 +{
86115 + PRTMP_ADAPTER pAd = dev->ml_priv;
86116 + UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
86117 +
86118 + //check if the interface is down
86119 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
86120 + {
86121 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
86122 + return -ENETDOWN;
86123 + }
86124 +
86125 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
86126 + /* rate = -1 => auto rate
86127 + rate = X, fixed = 1 => (fixed rate X)
86128 + */
86129 + if (rate == -1)
86130 + {
86131 + //Auto Rate
86132 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
86133 + pAd->StaCfg.bAutoTxRateSwitch = TRUE;
86134 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
86135 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
86136 + RTMPSetDesiredRates(pAd, -1);
86137 +
86138 +#ifdef DOT11_N_SUPPORT
86139 + SetCommonHT(pAd);
86140 +#endif // DOT11_N_SUPPORT //
86141 + }
86142 + else
86143 + {
86144 + if (fixed)
86145 + {
86146 + pAd->StaCfg.bAutoTxRateSwitch = FALSE;
86147 + if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
86148 + (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
86149 + RTMPSetDesiredRates(pAd, rate);
86150 + else
86151 + {
86152 + pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
86153 +#ifdef DOT11_N_SUPPORT
86154 + SetCommonHT(pAd);
86155 +#endif // DOT11_N_SUPPORT //
86156 + }
86157 + DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
86158 + }
86159 + else
86160 + {
86161 + // TODO: rate = X, fixed = 0 => (rates <= X)
86162 + return -EOPNOTSUPP;
86163 + }
86164 + }
86165 +
86166 + return 0;
86167 +}
86168 +
86169 +int rt_ioctl_giwrate(struct net_device *dev,
86170 + struct iw_request_info *info,
86171 + union iwreq_data *wrqu, char *extra)
86172 +{
86173 + PRTMP_ADAPTER pAd = dev->ml_priv;
86174 + int rate_index = 0, rate_count = 0;
86175 + HTTRANSMIT_SETTING ht_setting;
86176 + __s32 ralinkrate[] =
86177 + {2, 4, 11, 22, // CCK
86178 + 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
86179 + 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
86180 + 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
86181 + 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
86182 + 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
86183 + 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
86184 + 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
86185 + 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
86186 + 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
86187 +
86188 + rate_count = sizeof(ralinkrate)/sizeof(__s32);
86189 + //check if the interface is down
86190 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
86191 + {
86192 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
86193 + return -ENETDOWN;
86194 + }
86195 +
86196 + if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
86197 + (INFRA_ON(pAd)) &&
86198 + ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
86199 + ht_setting.word = pAd->StaCfg.HTPhyMode.word;
86200 + else
86201 + ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
86202 +
86203 +#ifdef DOT11_N_SUPPORT
86204 + if (ht_setting.field.MODE >= MODE_HTMIX)
86205 + {
86206 +// rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
86207 + rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
86208 + }
86209 + else
86210 +#endif // DOT11_N_SUPPORT //
86211 + if (ht_setting.field.MODE == MODE_OFDM)
86212 + rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
86213 + else if (ht_setting.field.MODE == MODE_CCK)
86214 + rate_index = (UCHAR)(ht_setting.field.MCS);
86215 +
86216 + if (rate_index < 0)
86217 + rate_index = 0;
86218 +
86219 + if (rate_index > rate_count)
86220 + rate_index = rate_count;
86221 +
86222 + wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
86223 + wrqu->bitrate.disabled = 0;
86224 +
86225 + return 0;
86226 +}
86227 +
86228 +static const iw_handler rt_handler[] =
86229 +{
86230 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
86231 + (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
86232 + (iw_handler) NULL, /* SIOCSIWNWID */
86233 + (iw_handler) NULL, /* SIOCGIWNWID */
86234 + (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
86235 + (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
86236 + (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
86237 + (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
86238 + (iw_handler) NULL, /* SIOCSIWSENS */
86239 + (iw_handler) NULL, /* SIOCGIWSENS */
86240 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
86241 + (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
86242 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
86243 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
86244 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
86245 + (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
86246 + (iw_handler) NULL, /* SIOCSIWSPY */
86247 + (iw_handler) NULL, /* SIOCGIWSPY */
86248 + (iw_handler) NULL, /* SIOCSIWTHRSPY */
86249 + (iw_handler) NULL, /* SIOCGIWTHRSPY */
86250 + (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
86251 + (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
86252 +#ifdef SIOCSIWMLME
86253 + (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
86254 +#else
86255 + (iw_handler) NULL, /* SIOCSIWMLME */
86256 +#endif // SIOCSIWMLME //
86257 + (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
86258 +#ifdef SIOCGIWSCAN
86259 + (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
86260 + (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
86261 +#else
86262 + (iw_handler) NULL, /* SIOCSIWSCAN */
86263 + (iw_handler) NULL, /* SIOCGIWSCAN */
86264 +#endif /* SIOCGIWSCAN */
86265 + (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
86266 + (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
86267 + (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
86268 + (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
86269 + (iw_handler) NULL, /* -- hole -- */
86270 + (iw_handler) NULL, /* -- hole -- */
86271 + (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
86272 + (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
86273 + (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
86274 + (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
86275 + (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
86276 + (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
86277 + (iw_handler) NULL, /* SIOCSIWTXPOW */
86278 + (iw_handler) NULL, /* SIOCGIWTXPOW */
86279 + (iw_handler) NULL, /* SIOCSIWRETRY */
86280 + (iw_handler) NULL, /* SIOCGIWRETRY */
86281 + (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
86282 + (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
86283 + (iw_handler) NULL, /* SIOCSIWPOWER */
86284 + (iw_handler) NULL, /* SIOCGIWPOWER */
86285 + (iw_handler) NULL, /* -- hole -- */
86286 + (iw_handler) NULL, /* -- hole -- */
86287 +#if WIRELESS_EXT > 17
86288 + (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
86289 + (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
86290 + (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
86291 + (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
86292 + (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
86293 + (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
86294 + (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
86295 +#endif
86296 +};
86297 +
86298 +static const iw_handler rt_priv_handlers[] = {
86299 + (iw_handler) NULL, /* + 0x00 */
86300 + (iw_handler) NULL, /* + 0x01 */
86301 +#ifndef CONFIG_AP_SUPPORT
86302 + (iw_handler) rt_ioctl_setparam, /* + 0x02 */
86303 +#else
86304 + (iw_handler) NULL, /* + 0x02 */
86305 +#endif // CONFIG_AP_SUPPORT //
86306 +#ifdef DBG
86307 + (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
86308 +#else
86309 + (iw_handler) NULL, /* + 0x03 */
86310 +#endif
86311 + (iw_handler) NULL, /* + 0x04 */
86312 + (iw_handler) NULL, /* + 0x05 */
86313 + (iw_handler) NULL, /* + 0x06 */
86314 + (iw_handler) NULL, /* + 0x07 */
86315 + (iw_handler) NULL, /* + 0x08 */
86316 + (iw_handler) rt_private_get_statistics, /* + 0x09 */
86317 + (iw_handler) NULL, /* + 0x0A */
86318 + (iw_handler) NULL, /* + 0x0B */
86319 + (iw_handler) NULL, /* + 0x0C */
86320 + (iw_handler) NULL, /* + 0x0D */
86321 + (iw_handler) NULL, /* + 0x0E */
86322 + (iw_handler) NULL, /* + 0x0F */
86323 + (iw_handler) NULL, /* + 0x10 */
86324 + (iw_handler) rt_private_show, /* + 0x11 */
86325 + (iw_handler) NULL, /* + 0x12 */
86326 + (iw_handler) NULL, /* + 0x13 */
86327 + (iw_handler) NULL, /* + 0x15 */
86328 + (iw_handler) NULL, /* + 0x17 */
86329 + (iw_handler) NULL, /* + 0x18 */
86330 +};
86331 +
86332 +const struct iw_handler_def rt28xx_iw_handler_def =
86333 +{
86334 +#define N(a) (sizeof (a) / sizeof (a[0]))
86335 + .standard = (iw_handler *) rt_handler,
86336 + .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
86337 + .private = (iw_handler *) rt_priv_handlers,
86338 + .num_private = N(rt_priv_handlers),
86339 + .private_args = (struct iw_priv_args *) privtab,
86340 + .num_private_args = N(privtab),
86341 +#if IW_HANDLER_VERSION >= 7
86342 + .get_wireless_stats = rt28xx_get_wireless_stats,
86343 +#endif
86344 +};
86345 +
86346 +INT RTMPSetInformation(
86347 + IN PRTMP_ADAPTER pAdapter,
86348 + IN OUT struct ifreq *rq,
86349 + IN INT cmd)
86350 +{
86351 + struct iwreq *wrq = (struct iwreq *) rq;
86352 + NDIS_802_11_SSID Ssid;
86353 + NDIS_802_11_MAC_ADDRESS Bssid;
86354 + RT_802_11_PHY_MODE PhyMode;
86355 + RT_802_11_STA_CONFIG StaConfig;
86356 + NDIS_802_11_RATES aryRates;
86357 + RT_802_11_PREAMBLE Preamble;
86358 + NDIS_802_11_WEP_STATUS WepStatus;
86359 + NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
86360 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
86361 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
86362 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
86363 + NDIS_802_11_POWER_MODE PowerMode;
86364 + PNDIS_802_11_KEY pKey = NULL;
86365 + PNDIS_802_11_WEP pWepKey =NULL;
86366 + PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
86367 + NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
86368 + NDIS_802_11_NETWORK_TYPE NetType;
86369 + ULONG Now;
86370 + UINT KeyIdx = 0;
86371 + INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
86372 + ULONG PowerTemp;
86373 + BOOLEAN RadioState;
86374 + BOOLEAN StateMachineTouched = FALSE;
86375 +#ifdef DOT11_N_SUPPORT
86376 + OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
86377 +#endif // DOT11_N_SUPPORT //
86378 +#ifdef WPA_SUPPLICANT_SUPPORT
86379 + PNDIS_802_11_PMKID pPmkId = NULL;
86380 + BOOLEAN IEEE8021xState = FALSE;
86381 + BOOLEAN IEEE8021x_required_keys = FALSE;
86382 + UCHAR wpa_supplicant_enable = 0;
86383 +#endif // WPA_SUPPLICANT_SUPPORT //
86384 +
86385 +#ifdef SNMP_SUPPORT
86386 + TX_RTY_CFG_STRUC tx_rty_cfg;
86387 + ULONG ShortRetryLimit, LongRetryLimit;
86388 + UCHAR ctmp;
86389 +#endif // SNMP_SUPPORT //
86390 +
86391 +
86392 +#ifdef DOT11_N_SUPPORT
86393 + MaxPhyMode = PHY_11N_5G;
86394 +#endif // DOT11_N_SUPPORT //
86395 +
86396 +
86397 + DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
86398 + switch(cmd & 0x7FFF) {
86399 + case RT_OID_802_11_COUNTRY_REGION:
86400 + if (wrq->u.data.length < sizeof(UCHAR))
86401 + Status = -EINVAL;
86402 + // Only avaliable when EEPROM not programming
86403 + else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
86404 + {
86405 + ULONG Country;
86406 + UCHAR TmpPhy;
86407 +
86408 + Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
86409 + pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
86410 + pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
86411 + TmpPhy = pAdapter->CommonCfg.PhyMode;
86412 + pAdapter->CommonCfg.PhyMode = 0xff;
86413 + // Build all corresponding channel information
86414 + RTMPSetPhyMode(pAdapter, TmpPhy);
86415 +#ifdef DOT11_N_SUPPORT
86416 + SetCommonHT(pAdapter);
86417 +#endif // DOT11_N_SUPPORT //
86418 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
86419 + pAdapter->CommonCfg.CountryRegion));
86420 + }
86421 + break;
86422 + case OID_802_11_BSSID_LIST_SCAN:
86423 + #ifdef RALINK_ATE
86424 + if (ATE_ON(pAdapter))
86425 + {
86426 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
86427 + break;
86428 + }
86429 +#endif // RALINK_ATE //
86430 + Now = jiffies;
86431 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
86432 +
86433 + if (MONITOR_ON(pAdapter))
86434 + {
86435 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
86436 + break;
86437 + }
86438 +
86439 + //Benson add 20080527, when radio off, sta don't need to scan
86440 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
86441 + break;
86442 +
86443 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
86444 + {
86445 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
86446 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
86447 + Status = NDIS_STATUS_SUCCESS;
86448 + break;
86449 + }
86450 +
86451 + if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
86452 + {
86453 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
86454 + Status = NDIS_STATUS_SUCCESS;
86455 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
86456 + break;
86457 + }
86458 +
86459 + if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
86460 + ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
86461 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
86462 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
86463 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
86464 + (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
86465 + {
86466 + DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
86467 + Status = NDIS_STATUS_SUCCESS;
86468 + pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
86469 + break;
86470 + }
86471 +
86472 +
86473 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
86474 + {
86475 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
86476 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
86477 + }
86478 +
86479 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
86480 + // this request, because this request is initiated by NDIS.
86481 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
86482 + // Reset allowed scan retries
86483 + pAdapter->StaCfg.ScanCnt = 0;
86484 + pAdapter->StaCfg.LastScanTime = Now;
86485 +
86486 + pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
86487 + RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
86488 + MlmeEnqueue(pAdapter,
86489 + MLME_CNTL_STATE_MACHINE,
86490 + OID_802_11_BSSID_LIST_SCAN,
86491 + 0,
86492 + NULL);
86493 +
86494 + Status = NDIS_STATUS_SUCCESS;
86495 + StateMachineTouched = TRUE;
86496 + break;
86497 + case OID_802_11_SSID:
86498 + if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
86499 + Status = -EINVAL;
86500 + else
86501 + {
86502 + PCHAR pSsidString = NULL;
86503 + Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
86504 +
86505 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
86506 + if (Ssid.SsidLength > MAX_LEN_OF_SSID)
86507 + Status = -EINVAL;
86508 + else
86509 + {
86510 + if (Ssid.SsidLength == 0)
86511 + {
86512 + Set_SSID_Proc(pAdapter, "");
86513 + }
86514 + else
86515 + {
86516 + pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
86517 + if (pSsidString)
86518 + {
86519 + NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
86520 + NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
86521 + Set_SSID_Proc(pAdapter, pSsidString);
86522 + kfree(pSsidString);
86523 + }
86524 + else
86525 + Status = -ENOMEM;
86526 + }
86527 + }
86528 + }
86529 + break;
86530 + case OID_802_11_BSSID:
86531 +#ifdef RALINK_ATE
86532 + if (ATE_ON(pAdapter))
86533 + {
86534 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
86535 + break;
86536 + }
86537 +#endif // RALINK_ATE //
86538 + if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
86539 + Status = -EINVAL;
86540 + else
86541 + {
86542 + Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
86543 +
86544 + // tell CNTL state machine to call NdisMSetInformationComplete() after completing
86545 + // this request, because this request is initiated by NDIS.
86546 + pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
86547 +
86548 + // Prevent to connect AP again in STAMlmePeriodicExec
86549 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
86550 +
86551 + // Reset allowed scan retries
86552 + pAdapter->StaCfg.ScanCnt = 0;
86553 +
86554 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
86555 + {
86556 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
86557 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
86558 + }
86559 + MlmeEnqueue(pAdapter,
86560 + MLME_CNTL_STATE_MACHINE,
86561 + OID_802_11_BSSID,
86562 + sizeof(NDIS_802_11_MAC_ADDRESS),
86563 + (VOID *)&Bssid);
86564 + Status = NDIS_STATUS_SUCCESS;
86565 + StateMachineTouched = TRUE;
86566 +
86567 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
86568 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
86569 + }
86570 + break;
86571 + case RT_OID_802_11_RADIO:
86572 + if (wrq->u.data.length != sizeof(BOOLEAN))
86573 + Status = -EINVAL;
86574 + else
86575 + {
86576 + Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
86577 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
86578 + if (pAdapter->StaCfg.bSwRadio != RadioState)
86579 + {
86580 + pAdapter->StaCfg.bSwRadio = RadioState;
86581 + if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
86582 + {
86583 + pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
86584 + if (pAdapter->StaCfg.bRadio == TRUE)
86585 + {
86586 + MlmeRadioOn(pAdapter);
86587 + // Update extra information
86588 + pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
86589 + }
86590 + else
86591 + {
86592 + MlmeRadioOff(pAdapter);
86593 + // Update extra information
86594 + pAdapter->ExtraInfo = SW_RADIO_OFF;
86595 + }
86596 + }
86597 + }
86598 + }
86599 + break;
86600 + case RT_OID_802_11_PHY_MODE:
86601 + if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
86602 + Status = -EINVAL;
86603 + else
86604 + {
86605 + Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
86606 + if (PhyMode <= MaxPhyMode)
86607 + {
86608 + RTMPSetPhyMode(pAdapter, PhyMode);
86609 +#ifdef DOT11_N_SUPPORT
86610 + SetCommonHT(pAdapter);
86611 +#endif // DOT11_N_SUPPORT //
86612 + }
86613 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
86614 + }
86615 + break;
86616 + case RT_OID_802_11_STA_CONFIG:
86617 + if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
86618 + Status = -EINVAL;
86619 + else
86620 + {
86621 + Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
86622 + pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
86623 + pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
86624 + pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
86625 + if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
86626 + (StaConfig.AdhocMode <= MaxPhyMode))
86627 + {
86628 + // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
86629 + // if setting changed, need to reset current TX rate as well as BEACON frame format
86630 + pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
86631 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
86632 + {
86633 + RTMPSetPhyMode(pAdapter, PhyMode);
86634 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
86635 + MakeIbssBeacon(pAdapter); // re-build BEACON frame
86636 + AsicEnableIbssSync(pAdapter); // copy to on-chip memory
86637 + }
86638 + }
86639 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
86640 + pAdapter->CommonCfg.bEnableTxBurst,
86641 + pAdapter->CommonCfg.UseBGProtection,
86642 + pAdapter->CommonCfg.bUseShortSlotTime));
86643 + }
86644 + break;
86645 + case OID_802_11_DESIRED_RATES:
86646 + if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
86647 + Status = -EINVAL;
86648 + else
86649 + {
86650 + Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
86651 + NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
86652 + NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
86653 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
86654 + pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
86655 + pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
86656 + pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
86657 + pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
86658 + // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
86659 + MlmeUpdateTxRates(pAdapter, FALSE, 0);
86660 + }
86661 + break;
86662 + case RT_OID_802_11_PREAMBLE:
86663 + if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
86664 + Status = -EINVAL;
86665 + else
86666 + {
86667 + Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
86668 + if (Preamble == Rt802_11PreambleShort)
86669 + {
86670 + pAdapter->CommonCfg.TxPreamble = Preamble;
86671 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
86672 + }
86673 + else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
86674 + {
86675 + // if user wants AUTO, initialize to LONG here, then change according to AP's
86676 + // capability upon association.
86677 + pAdapter->CommonCfg.TxPreamble = Preamble;
86678 + MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
86679 + }
86680 + else
86681 + {
86682 + Status = -EINVAL;
86683 + break;
86684 + }
86685 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
86686 + }
86687 + break;
86688 + case OID_802_11_WEP_STATUS:
86689 + if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
86690 + Status = -EINVAL;
86691 + else
86692 + {
86693 + Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
86694 + // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
86695 + if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
86696 + {
86697 + if (pAdapter->StaCfg.WepStatus != WepStatus)
86698 + {
86699 + // Config has changed
86700 + pAdapter->bConfigChanged = TRUE;
86701 + }
86702 + pAdapter->StaCfg.WepStatus = WepStatus;
86703 + pAdapter->StaCfg.OrigWepStatus = WepStatus;
86704 + pAdapter->StaCfg.PairCipher = WepStatus;
86705 + pAdapter->StaCfg.GroupCipher = WepStatus;
86706 + }
86707 + else
86708 + {
86709 + Status = -EINVAL;
86710 + break;
86711 + }
86712 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
86713 + }
86714 + break;
86715 + case OID_802_11_AUTHENTICATION_MODE:
86716 + if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
86717 + Status = -EINVAL;
86718 + else
86719 + {
86720 + Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
86721 + if (AuthMode > Ndis802_11AuthModeMax)
86722 + {
86723 + Status = -EINVAL;
86724 + break;
86725 + }
86726 + else
86727 + {
86728 + if (pAdapter->StaCfg.AuthMode != AuthMode)
86729 + {
86730 + // Config has changed
86731 + pAdapter->bConfigChanged = TRUE;
86732 + }
86733 + pAdapter->StaCfg.AuthMode = AuthMode;
86734 + }
86735 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
86736 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
86737 + }
86738 + break;
86739 + case OID_802_11_INFRASTRUCTURE_MODE:
86740 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
86741 + Status = -EINVAL;
86742 + else
86743 + {
86744 + Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
86745 +
86746 + if (BssType == Ndis802_11IBSS)
86747 + Set_NetworkType_Proc(pAdapter, "Adhoc");
86748 + else if (BssType == Ndis802_11Infrastructure)
86749 + Set_NetworkType_Proc(pAdapter, "Infra");
86750 + else if (BssType == Ndis802_11Monitor)
86751 + Set_NetworkType_Proc(pAdapter, "Monitor");
86752 + else
86753 + {
86754 + Status = -EINVAL;
86755 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
86756 + }
86757 + }
86758 + break;
86759 + case OID_802_11_REMOVE_WEP:
86760 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
86761 + if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
86762 + {
86763 + Status = -EINVAL;
86764 + }
86765 + else
86766 + {
86767 + KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
86768 +
86769 + if (KeyIdx & 0x80000000)
86770 + {
86771 + // Should never set default bit when remove key
86772 + Status = -EINVAL;
86773 + }
86774 + else
86775 + {
86776 + KeyIdx = KeyIdx & 0x0fffffff;
86777 + if (KeyIdx >= 4){
86778 + Status = -EINVAL;
86779 + }
86780 + else
86781 + {
86782 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
86783 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
86784 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
86785 + }
86786 + }
86787 + }
86788 + break;
86789 + case RT_OID_802_11_RESET_COUNTERS:
86790 + NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
86791 + NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
86792 + NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
86793 + pAdapter->Counters8023.RxNoBuffer = 0;
86794 + pAdapter->Counters8023.GoodReceives = 0;
86795 + pAdapter->Counters8023.RxNoBuffer = 0;
86796 +#ifdef RT2870
86797 + pAdapter->BulkOutComplete = 0;
86798 + pAdapter->BulkOutCompleteOther= 0;
86799 + pAdapter->BulkOutCompleteCancel = 0;
86800 + pAdapter->BulkOutReq = 0;
86801 + pAdapter->BulkInReq= 0;
86802 + pAdapter->BulkInComplete = 0;
86803 + pAdapter->BulkInCompleteFail = 0;
86804 +#endif // RT2870 //
86805 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
86806 + break;
86807 + case OID_802_11_RTS_THRESHOLD:
86808 + if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
86809 + Status = -EINVAL;
86810 + else
86811 + {
86812 + Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
86813 + if (RtsThresh > MAX_RTS_THRESHOLD)
86814 + Status = -EINVAL;
86815 + else
86816 + pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
86817 + }
86818 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
86819 + break;
86820 + case OID_802_11_FRAGMENTATION_THRESHOLD:
86821 + if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
86822 + Status = -EINVAL;
86823 + else
86824 + {
86825 + Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
86826 + pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
86827 + if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
86828 + {
86829 + if (FragThresh == 0)
86830 + {
86831 + pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
86832 + pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
86833 + }
86834 + else
86835 + Status = -EINVAL;
86836 + }
86837 + else
86838 + pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
86839 + }
86840 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
86841 + break;
86842 + case OID_802_11_POWER_MODE:
86843 + if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
86844 + Status = -EINVAL;
86845 + else
86846 + {
86847 + Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
86848 + if (PowerMode == Ndis802_11PowerModeCAM)
86849 + Set_PSMode_Proc(pAdapter, "CAM");
86850 + else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
86851 + Set_PSMode_Proc(pAdapter, "Max_PSP");
86852 + else if (PowerMode == Ndis802_11PowerModeFast_PSP)
86853 + Set_PSMode_Proc(pAdapter, "Fast_PSP");
86854 + else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
86855 + Set_PSMode_Proc(pAdapter, "Legacy_PSP");
86856 + else
86857 + Status = -EINVAL;
86858 + }
86859 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
86860 + break;
86861 + case RT_OID_802_11_TX_POWER_LEVEL_1:
86862 + if (wrq->u.data.length < sizeof(ULONG))
86863 + Status = -EINVAL;
86864 + else
86865 + {
86866 + Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
86867 + if (PowerTemp > 100)
86868 + PowerTemp = 0xffffffff; // AUTO
86869 + pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
86870 + pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
86871 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
86872 + }
86873 + break;
86874 + case OID_802_11_NETWORK_TYPE_IN_USE:
86875 + if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
86876 + Status = -EINVAL;
86877 + else
86878 + {
86879 + Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
86880 +
86881 + if (NetType == Ndis802_11DS)
86882 + RTMPSetPhyMode(pAdapter, PHY_11B);
86883 + else if (NetType == Ndis802_11OFDM24)
86884 + RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
86885 + else if (NetType == Ndis802_11OFDM5)
86886 + RTMPSetPhyMode(pAdapter, PHY_11A);
86887 + else
86888 + Status = -EINVAL;
86889 +#ifdef DOT11_N_SUPPORT
86890 + if (Status == NDIS_STATUS_SUCCESS)
86891 + SetCommonHT(pAdapter);
86892 +#endif // DOT11_N_SUPPORT //
86893 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
86894 + }
86895 + break;
86896 + // For WPA PSK PMK key
86897 + case RT_OID_802_11_ADD_WPA:
86898 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86899 + if(pKey == NULL)
86900 + {
86901 + Status = -ENOMEM;
86902 + break;
86903 + }
86904 +
86905 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
86906 + if (pKey->Length != wrq->u.data.length)
86907 + {
86908 + Status = -EINVAL;
86909 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
86910 + }
86911 + else
86912 + {
86913 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
86914 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
86915 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
86916 + {
86917 + Status = -EOPNOTSUPP;
86918 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
86919 + }
86920 + else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
86921 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
86922 + (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
86923 + {
86924 + NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
86925 + // Use RaConfig as PSK agent.
86926 + // Start STA supplicant state machine
86927 + if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
86928 + pAdapter->StaCfg.WpaState = SS_START;
86929 +
86930 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
86931 + }
86932 + else
86933 + {
86934 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
86935 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
86936 + }
86937 + }
86938 + kfree(pKey);
86939 + break;
86940 + case OID_802_11_REMOVE_KEY:
86941 + pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86942 + if(pRemoveKey == NULL)
86943 + {
86944 + Status = -ENOMEM;
86945 + break;
86946 + }
86947 +
86948 + Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
86949 + if (pRemoveKey->Length != wrq->u.data.length)
86950 + {
86951 + Status = -EINVAL;
86952 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
86953 + }
86954 + else
86955 + {
86956 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
86957 + {
86958 + RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
86959 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
86960 + }
86961 + else
86962 + {
86963 + KeyIdx = pRemoveKey->KeyIndex;
86964 +
86965 + if (KeyIdx & 0x80000000)
86966 + {
86967 + // Should never set default bit when remove key
86968 + Status = -EINVAL;
86969 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
86970 + }
86971 + else
86972 + {
86973 + KeyIdx = KeyIdx & 0x0fffffff;
86974 + if (KeyIdx > 3)
86975 + {
86976 + Status = -EINVAL;
86977 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
86978 + }
86979 + else
86980 + {
86981 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
86982 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
86983 + AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
86984 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
86985 + }
86986 + }
86987 + }
86988 + }
86989 + kfree(pRemoveKey);
86990 + break;
86991 + // New for WPA
86992 + case OID_802_11_ADD_KEY:
86993 + pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
86994 + if(pKey == NULL)
86995 + {
86996 + Status = -ENOMEM;
86997 + break;
86998 + }
86999 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
87000 + if (pKey->Length != wrq->u.data.length)
87001 + {
87002 + Status = -EINVAL;
87003 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
87004 + }
87005 + else
87006 + {
87007 + RTMPAddKey(pAdapter, pKey);
87008 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
87009 + }
87010 + kfree(pKey);
87011 + break;
87012 + case OID_802_11_CONFIGURATION:
87013 + if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
87014 + Status = -EINVAL;
87015 + else
87016 + {
87017 + Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
87018 + pConfig = &Config;
87019 +
87020 + if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
87021 + pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
87022 +
87023 + pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
87024 + MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
87025 + //
87026 + // Save the channel on MlmeAux for CntlOidRTBssidProc used.
87027 + //
87028 + pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
87029 +
87030 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
87031 + pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
87032 + // Config has changed
87033 + pAdapter->bConfigChanged = TRUE;
87034 + }
87035 + break;
87036 +#ifdef DOT11_N_SUPPORT
87037 + case RT_OID_802_11_SET_HT_PHYMODE:
87038 + if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
87039 + Status = -EINVAL;
87040 + else
87041 + {
87042 + POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
87043 +
87044 + Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
87045 + DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
87046 + pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
87047 + pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
87048 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
87049 + RTMPSetHT(pAdapter, pHTPhyMode);
87050 + }
87051 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
87052 + pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
87053 + pAdapter->StaCfg.HTPhyMode.field.STBC));
87054 + break;
87055 +#endif // DOT11_N_SUPPORT //
87056 + case RT_OID_802_11_SET_APSD_SETTING:
87057 + if (wrq->u.data.length != sizeof(ULONG))
87058 + Status = -EINVAL;
87059 + else
87060 + {
87061 + ULONG apsd ;
87062 + Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
87063 +
87064 + /*-------------------------------------------------------------------
87065 + |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
87066 + ---------------------------------------------------------------------
87067 + | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
87068 + ---------------------------------------------------------------------*/
87069 + pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
87070 + pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
87071 + pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
87072 + pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
87073 + pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
87074 + pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
87075 +
87076 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_SETTING (apsd=0x%lx, APSDCap=%d, [BE,BK,VI,VO]=[%d/%d/%d/%d], MaxSPLen=%d)\n", apsd, pAdapter->CommonCfg.bAPSDCapable,
87077 + pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
87078 + }
87079 + break;
87080 +
87081 + case RT_OID_802_11_SET_APSD_PSM:
87082 + if (wrq->u.data.length != sizeof(ULONG))
87083 + Status = -EINVAL;
87084 + else
87085 + {
87086 + // Driver needs to notify AP when PSM changes
87087 + Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
87088 + if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
87089 + {
87090 + MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
87091 + RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
87092 + }
87093 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
87094 + }
87095 + break;
87096 +#ifdef QOS_DLS_SUPPORT
87097 + case RT_OID_802_11_SET_DLS:
87098 + if (wrq->u.data.length != sizeof(ULONG))
87099 + Status = -EINVAL;
87100 + else
87101 + {
87102 + BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
87103 + Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
87104 + if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
87105 + {
87106 + int i;
87107 + // tear down local dls table entry
87108 + for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
87109 + {
87110 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
87111 + {
87112 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
87113 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
87114 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
87115 + }
87116 + }
87117 +
87118 + // tear down peer dls table entry
87119 + for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
87120 + {
87121 + if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
87122 + {
87123 + pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
87124 + pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
87125 + RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
87126 + }
87127 + }
87128 + }
87129 +
87130 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
87131 + }
87132 + break;
87133 +
87134 + case RT_OID_802_11_SET_DLS_PARAM:
87135 + if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
87136 + Status = -EINVAL;
87137 + else
87138 + {
87139 + RT_802_11_DLS Dls;
87140 +
87141 + NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
87142 + RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
87143 + MlmeEnqueue(pAdapter,
87144 + MLME_CNTL_STATE_MACHINE,
87145 + RT_OID_802_11_SET_DLS_PARAM,
87146 + sizeof(RT_802_11_DLS),
87147 + &Dls);
87148 + DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
87149 + }
87150 + break;
87151 +#endif // QOS_DLS_SUPPORT //
87152 + case RT_OID_802_11_SET_WMM:
87153 + if (wrq->u.data.length != sizeof(BOOLEAN))
87154 + Status = -EINVAL;
87155 + else
87156 + {
87157 + Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
87158 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
87159 + }
87160 + break;
87161 +
87162 + case OID_802_11_DISASSOCIATE:
87163 +#ifdef RALINK_ATE
87164 + if (ATE_ON(pAdapter))
87165 + {
87166 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
87167 + break;
87168 + }
87169 +#endif // RALINK_ATE //
87170 + //
87171 + // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
87172 + // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
87173 + // when query OID_802_11_BSSID_LIST.
87174 + //
87175 + // TRUE: NumberOfItems will set to 0.
87176 + // FALSE: NumberOfItems no change.
87177 + //
87178 + pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
87179 + // Set to immediately send the media disconnect event
87180 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
87181 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
87182 +
87183 + if (INFRA_ON(pAdapter))
87184 + {
87185 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
87186 + {
87187 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
87188 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
87189 + }
87190 +
87191 + MlmeEnqueue(pAdapter,
87192 + MLME_CNTL_STATE_MACHINE,
87193 + OID_802_11_DISASSOCIATE,
87194 + 0,
87195 + NULL);
87196 +
87197 + StateMachineTouched = TRUE;
87198 + }
87199 + break;
87200 +
87201 +#ifdef DOT11_N_SUPPORT
87202 + case RT_OID_802_11_SET_IMME_BA_CAP:
87203 + if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
87204 + Status = -EINVAL;
87205 + else
87206 + {
87207 + OID_BACAP_STRUC Orde ;
87208 + Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
87209 + if (Orde.Policy > BA_NOTUSE)
87210 + {
87211 + Status = NDIS_STATUS_INVALID_DATA;
87212 + }
87213 + else if (Orde.Policy == BA_NOTUSE)
87214 + {
87215 + pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
87216 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
87217 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
87218 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
87219 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
87220 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
87221 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
87222 + // UPdata to HT IE
87223 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
87224 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
87225 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
87226 + }
87227 + else
87228 + {
87229 + pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
87230 + pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
87231 + pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
87232 + pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
87233 + pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
87234 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
87235 + pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
87236 + pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
87237 +
87238 + // UPdata to HT IE
87239 + pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
87240 + pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
87241 + pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
87242 +
87243 + if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
87244 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
87245 +
87246 + }
87247 +
87248 + pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
87249 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
87250 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
87251 + DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
87252 + pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
87253 + }
87254 +
87255 + break;
87256 + case RT_OID_802_11_ADD_IMME_BA:
87257 + DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
87258 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
87259 + Status = -EINVAL;
87260 + else
87261 + {
87262 + UCHAR index;
87263 + OID_ADD_BA_ENTRY BA;
87264 + MAC_TABLE_ENTRY *pEntry;
87265 +
87266 + Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
87267 + if (BA.TID > 15)
87268 + {
87269 + Status = NDIS_STATUS_INVALID_DATA;
87270 + break;
87271 + }
87272 + else
87273 + {
87274 + //BATableInsertEntry
87275 + //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
87276 + index = BA.TID;
87277 + // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
87278 + pEntry = MacTableLookup(pAdapter, BA.MACAddr);
87279 + if (!pEntry)
87280 + {
87281 + DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
87282 + break;
87283 + }
87284 + if (BA.IsRecipient == FALSE)
87285 + {
87286 + if (pEntry->bIAmBadAtheros == TRUE)
87287 + pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
87288 +
87289 + BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
87290 + }
87291 + else
87292 + {
87293 + //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
87294 + }
87295 +
87296 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
87297 + BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
87298 + , BA.MACAddr[4], BA.MACAddr[5]));
87299 + }
87300 + }
87301 + break;
87302 +
87303 + case RT_OID_802_11_TEAR_IMME_BA:
87304 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
87305 + if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
87306 + Status = -EINVAL;
87307 + else
87308 + {
87309 + POID_ADD_BA_ENTRY pBA;
87310 + MAC_TABLE_ENTRY *pEntry;
87311 +
87312 + pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
87313 +
87314 + if (pBA == NULL)
87315 + {
87316 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
87317 + Status = NDIS_STATUS_FAILURE;
87318 + }
87319 + else
87320 + {
87321 + Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
87322 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
87323 +
87324 + if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
87325 + {
87326 + Status = NDIS_STATUS_INVALID_DATA;
87327 + break;
87328 + }
87329 +
87330 + if (pBA->IsRecipient == FALSE)
87331 + {
87332 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
87333 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
87334 + if (pEntry)
87335 + {
87336 + DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
87337 + BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
87338 + }
87339 + else
87340 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
87341 + }
87342 + else
87343 + {
87344 + pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
87345 + if (pEntry)
87346 + {
87347 + BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
87348 + }
87349 + else
87350 + DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
87351 + }
87352 + kfree(pBA);
87353 + }
87354 + }
87355 + break;
87356 +#endif // DOT11_N_SUPPORT //
87357 +
87358 + // For WPA_SUPPLICANT to set static wep key
87359 + case OID_802_11_ADD_WEP:
87360 + pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
87361 +
87362 + if(pWepKey == NULL)
87363 + {
87364 + Status = -ENOMEM;
87365 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
87366 + break;
87367 + }
87368 + Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
87369 + if (Status)
87370 + {
87371 + Status = -EINVAL;
87372 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
87373 + }
87374 + else
87375 + {
87376 + KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
87377 + // KeyIdx must be 0 ~ 3
87378 + if (KeyIdx > 4)
87379 + {
87380 + Status = -EINVAL;
87381 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
87382 + }
87383 + else
87384 + {
87385 + UCHAR CipherAlg = 0;
87386 + PUCHAR Key;
87387 +
87388 + // set key material and key length
87389 + NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
87390 + pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
87391 + NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
87392 +
87393 + switch(pWepKey->KeyLength)
87394 + {
87395 + case 5:
87396 + CipherAlg = CIPHER_WEP64;
87397 + break;
87398 + case 13:
87399 + CipherAlg = CIPHER_WEP128;
87400 + break;
87401 + default:
87402 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
87403 + Status = -EINVAL;
87404 + break;
87405 + }
87406 + pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
87407 +
87408 + // Default key for tx (shared key)
87409 + if (pWepKey->KeyIndex & 0x80000000)
87410 + {
87411 +#ifdef WPA_SUPPLICANT_SUPPORT
87412 + // set key material and key length
87413 + NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
87414 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
87415 + NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
87416 + pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
87417 + pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
87418 +#endif // WPA_SUPPLICANT_SUPPORT //
87419 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
87420 + }
87421 +
87422 +#ifdef WPA_SUPPLICANT_SUPPORT
87423 + if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
87424 +#endif // WPA_SUPPLICANT_SUPPORT
87425 + {
87426 + Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
87427 +
87428 + // Set key material and cipherAlg to Asic
87429 + AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
87430 +
87431 + if (pWepKey->KeyIndex & 0x80000000)
87432 + {
87433 + PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
87434 + // Assign group key info
87435 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
87436 + // Assign pairwise key info
87437 + RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
87438 + }
87439 + }
87440 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP (id=0x%x, Len=%d-byte), %s\n", pWepKey->KeyIndex, pWepKey->KeyLength, (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED) ? "Port Secured":"Port NOT Secured"));
87441 + }
87442 + }
87443 + kfree(pWepKey);
87444 + break;
87445 +#ifdef WPA_SUPPLICANT_SUPPORT
87446 + case OID_SET_COUNTERMEASURES:
87447 + if (wrq->u.data.length != sizeof(int))
87448 + Status = -EINVAL;
87449 + else
87450 + {
87451 + int enabled = 0;
87452 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
87453 + if (enabled == 1)
87454 + pAdapter->StaCfg.bBlockAssoc = TRUE;
87455 + else
87456 + // WPA MIC error should block association attempt for 60 seconds
87457 + pAdapter->StaCfg.bBlockAssoc = FALSE;
87458 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
87459 + }
87460 + break;
87461 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
87462 + if (wrq->u.data.length != sizeof(UCHAR))
87463 + Status = -EINVAL;
87464 + else
87465 + {
87466 + Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
87467 + pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
87468 + DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
87469 + }
87470 + break;
87471 + case OID_802_11_DEAUTHENTICATION:
87472 + if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
87473 + Status = -EINVAL;
87474 + else
87475 + {
87476 + MLME_DEAUTH_REQ_STRUCT *pInfo;
87477 + MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
87478 +
87479 + pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
87480 + Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
87481 + MlmeDeauthReqAction(pAdapter, MsgElem);
87482 + kfree(MsgElem);
87483 +
87484 + if (INFRA_ON(pAdapter))
87485 + {
87486 + LinkDown(pAdapter, FALSE);
87487 + pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
87488 + }
87489 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
87490 + }
87491 + break;
87492 + case OID_802_11_DROP_UNENCRYPTED:
87493 + if (wrq->u.data.length != sizeof(int))
87494 + Status = -EINVAL;
87495 + else
87496 + {
87497 + int enabled = 0;
87498 + Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
87499 + if (enabled == 1)
87500 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
87501 + else
87502 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
87503 + NdisAcquireSpinLock(&pAdapter->MacTabLock);
87504 + pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
87505 + NdisReleaseSpinLock(&pAdapter->MacTabLock);
87506 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
87507 + }
87508 + break;
87509 + case OID_802_11_SET_IEEE8021X:
87510 + if (wrq->u.data.length != sizeof(BOOLEAN))
87511 + Status = -EINVAL;
87512 + else
87513 + {
87514 + Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
87515 + pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
87516 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
87517 + }
87518 + break;
87519 + case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
87520 + if (wrq->u.data.length != sizeof(BOOLEAN))
87521 + Status = -EINVAL;
87522 + else
87523 + {
87524 + Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
87525 + pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
87526 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
87527 + }
87528 + break;
87529 + case OID_802_11_PMKID:
87530 + pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
87531 +
87532 + if(pPmkId == NULL) {
87533 + Status = -ENOMEM;
87534 + break;
87535 + }
87536 + Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
87537 +
87538 + // check the PMKID information
87539 + if (pPmkId->BSSIDInfoCount == 0)
87540 + NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
87541 + else
87542 + {
87543 + PBSSID_INFO pBssIdInfo;
87544 + UINT BssIdx;
87545 + UINT CachedIdx;
87546 +
87547 + for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
87548 + {
87549 + // point to the indexed BSSID_INFO structure
87550 + pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
87551 + // Find the entry in the saved data base.
87552 + for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
87553 + {
87554 + // compare the BSSID
87555 + if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
87556 + break;
87557 + }
87558 +
87559 + // Found, replace it
87560 + if (CachedIdx < PMKID_NO)
87561 + {
87562 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
87563 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
87564 + pAdapter->StaCfg.SavedPMKNum++;
87565 + }
87566 + // Not found, replace the last one
87567 + else
87568 + {
87569 + // Randomly replace one
87570 + CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
87571 + DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
87572 + NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
87573 + }
87574 + }
87575 + }
87576 + if(pPmkId)
87577 + kfree(pPmkId);
87578 + break;
87579 +#endif // WPA_SUPPLICANT_SUPPORT //
87580 +
87581 +
87582 +
87583 +#ifdef SNMP_SUPPORT
87584 + case OID_802_11_SHORTRETRYLIMIT:
87585 + if (wrq->u.data.length != sizeof(ULONG))
87586 + Status = -EINVAL;
87587 + else
87588 + {
87589 + Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
87590 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
87591 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
87592 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
87593 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
87594 + }
87595 + break;
87596 +
87597 + case OID_802_11_LONGRETRYLIMIT:
87598 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
87599 + if (wrq->u.data.length != sizeof(ULONG))
87600 + Status = -EINVAL;
87601 + else
87602 + {
87603 + Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
87604 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
87605 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
87606 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
87607 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
87608 + }
87609 + break;
87610 +
87611 + case OID_802_11_WEPDEFAULTKEYVALUE:
87612 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
87613 + pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
87614 + Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
87615 + //pKey = &WepKey;
87616 +
87617 + if ( pKey->Length != wrq->u.data.length)
87618 + {
87619 + Status = -EINVAL;
87620 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
87621 + }
87622 + KeyIdx = pKey->KeyIndex & 0x0fffffff;
87623 + DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
87624 +
87625 + // it is a shared key
87626 + if (KeyIdx > 4)
87627 + Status = -EINVAL;
87628 + else
87629 + {
87630 + pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
87631 + NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
87632 + if (pKey->KeyIndex & 0x80000000)
87633 + {
87634 + // Default key for tx (shared key)
87635 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
87636 + }
87637 + //RestartAPIsRequired = TRUE;
87638 + }
87639 + break;
87640 +
87641 +
87642 + case OID_802_11_WEPDEFAULTKEYID:
87643 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
87644 +
87645 + if (wrq->u.data.length != sizeof(UCHAR))
87646 + Status = -EINVAL;
87647 + else
87648 + Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
87649 +
87650 + break;
87651 +
87652 +
87653 + case OID_802_11_CURRENTCHANNEL:
87654 + DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
87655 + if (wrq->u.data.length != sizeof(UCHAR))
87656 + Status = -EINVAL;
87657 + else
87658 + {
87659 + Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
87660 + sprintf(&ctmp,"%d", ctmp);
87661 + Set_Channel_Proc(pAdapter, &ctmp);
87662 + }
87663 + break;
87664 +#endif
87665 +
87666 +
87667 +
87668 + default:
87669 + DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
87670 + Status = -EOPNOTSUPP;
87671 + break;
87672 + }
87673 +
87674 +
87675 + return Status;
87676 +}
87677 +
87678 +INT RTMPQueryInformation(
87679 + IN PRTMP_ADAPTER pAdapter,
87680 + IN OUT struct ifreq *rq,
87681 + IN INT cmd)
87682 +{
87683 + struct iwreq *wrq = (struct iwreq *) rq;
87684 + NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
87685 + PNDIS_WLAN_BSSID_EX pBss;
87686 + NDIS_802_11_SSID Ssid;
87687 + NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
87688 + RT_802_11_LINK_STATUS *pLinkStatus = NULL;
87689 + RT_802_11_STA_CONFIG *pStaConfig = NULL;
87690 + NDIS_802_11_STATISTICS *pStatistics = NULL;
87691 + NDIS_802_11_RTS_THRESHOLD RtsThresh;
87692 + NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
87693 + NDIS_802_11_POWER_MODE PowerMode;
87694 + NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
87695 + RT_802_11_PREAMBLE PreamType;
87696 + NDIS_802_11_AUTHENTICATION_MODE AuthMode;
87697 + NDIS_802_11_WEP_STATUS WepStatus;
87698 + NDIS_MEDIA_STATE MediaState;
87699 + ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
87700 + USHORT BssLen = 0;
87701 + PUCHAR pBuf = NULL, pPtr;
87702 + INT Status = NDIS_STATUS_SUCCESS;
87703 + UINT we_version_compiled;
87704 + UCHAR i, Padding = 0;
87705 + BOOLEAN RadioState;
87706 + UCHAR driverVersion[8];
87707 + OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
87708 +
87709 +
87710 +#ifdef SNMP_SUPPORT
87711 + //for snmp, kathy
87712 + DefaultKeyIdxValue *pKeyIdxValue;
87713 + INT valueLen;
87714 + TX_RTY_CFG_STRUC tx_rty_cfg;
87715 + ULONG ShortRetryLimit, LongRetryLimit;
87716 + UCHAR tmp[64];
87717 +#endif //SNMP
87718 +
87719 + switch(cmd)
87720 + {
87721 + case RT_OID_DEVICE_NAME:
87722 + wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
87723 + Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
87724 + break;
87725 + case RT_OID_VERSION_INFO:
87726 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
87727 + wrq->u.data.length = 8*sizeof(UCHAR);
87728 + sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
87729 + driverVersion[7] = '\0';
87730 + if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
87731 + {
87732 + Status = -EFAULT;
87733 + }
87734 + break;
87735 +#ifdef RALINK_ATE
87736 + case RT_QUERY_ATE_TXDONE_COUNT:
87737 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
87738 + wrq->u.data.length = sizeof(UINT32);
87739 + if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
87740 + {
87741 + Status = -EFAULT;
87742 + }
87743 + break;
87744 +#endif // RALINK_ATE //
87745 + case OID_802_11_BSSID_LIST:
87746 + if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
87747 + {
87748 + /*
87749 + * Still scanning, indicate the caller should try again.
87750 + */
87751 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
87752 + return -EAGAIN;
87753 + }
87754 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
87755 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
87756 + // Claculate total buffer size required
87757 + BssBufSize = sizeof(ULONG);
87758 +
87759 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
87760 + {
87761 + // Align pointer to 4 bytes boundary.
87762 + //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
87763 + //if (Padding == 4)
87764 + // Padding = 0;
87765 + BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
87766 + }
87767 +
87768 + // For safety issue, we add 256 bytes just in case
87769 + BssBufSize += 256;
87770 + // Allocate the same size as passed from higher layer
87771 + pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
87772 + if(pBuf == NULL)
87773 + {
87774 + Status = -ENOMEM;
87775 + break;
87776 + }
87777 + // Init 802_11_BSSID_LIST_EX structure
87778 + NdisZeroMemory(pBuf, BssBufSize);
87779 + pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
87780 + pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
87781 +
87782 + // Calculate total buffer length
87783 + BssLen = 4; // Consist of NumberOfItems
87784 + // Point to start of NDIS_WLAN_BSSID_EX
87785 + // pPtr = pBuf + sizeof(ULONG);
87786 + pPtr = (PUCHAR) &pBssidList->Bssid[0];
87787 + for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
87788 + {
87789 + pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
87790 + NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
87791 + if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
87792 + {
87793 + //
87794 + // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
87795 + // and then failed to send EAPOl farame.
87796 + //
87797 + if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
87798 + {
87799 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
87800 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
87801 + }
87802 + else
87803 + pBss->Ssid.SsidLength = 0;
87804 + }
87805 + else
87806 + {
87807 + pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
87808 + NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
87809 + }
87810 + pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
87811 + pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
87812 + pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
87813 + pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
87814 + pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
87815 + pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
87816 +
87817 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
87818 +
87819 + if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
87820 + pBss->InfrastructureMode = Ndis802_11Infrastructure;
87821 + else
87822 + pBss->InfrastructureMode = Ndis802_11IBSS;
87823 +
87824 + NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
87825 + NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
87826 + pAdapter->ScanTab.BssEntry[i].ExtRate,
87827 + pAdapter->ScanTab.BssEntry[i].ExtRateLen);
87828 +
87829 + if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
87830 + {
87831 + pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
87832 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
87833 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
87834 + }
87835 + else
87836 + {
87837 + pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
87838 + pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
87839 + NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
87840 + NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
87841 + pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
87842 + }
87843 + pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
87844 +
87845 +#if WIRELESS_EXT < 17
87846 + if ((BssLen + pBss->Length) < wrq->u.data.length)
87847 + BssLen += pBss->Length;
87848 + else
87849 + {
87850 + pBssidList->NumberOfItems = i;
87851 + break;
87852 + }
87853 +#else
87854 + BssLen += pBss->Length;
87855 +#endif
87856 + }
87857 +
87858 +#if WIRELESS_EXT < 17
87859 + wrq->u.data.length = BssLen;
87860 +#else
87861 + if (BssLen > wrq->u.data.length)
87862 + {
87863 + kfree(pBssidList);
87864 + return -E2BIG;
87865 + }
87866 + else
87867 + wrq->u.data.length = BssLen;
87868 +#endif
87869 + Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
87870 + kfree(pBssidList);
87871 + break;
87872 + case OID_802_3_CURRENT_ADDRESS:
87873 + wrq->u.data.length = MAC_ADDR_LEN;
87874 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
87875 + break;
87876 + case OID_GEN_MEDIA_CONNECT_STATUS:
87877 + if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
87878 + MediaState = NdisMediaStateConnected;
87879 + else
87880 + MediaState = NdisMediaStateDisconnected;
87881 +
87882 + wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
87883 + Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
87884 + break;
87885 + case OID_802_11_BSSID:
87886 +#ifdef RALINK_ATE
87887 + if (ATE_ON(pAdapter))
87888 + {
87889 + DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
87890 + Status = NDIS_STATUS_RESOURCES;
87891 + break;
87892 + }
87893 +#endif // RALINK_ATE //
87894 + if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
87895 + {
87896 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
87897 +
87898 + }
87899 + else
87900 + {
87901 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
87902 + Status = -ENOTCONN;
87903 + }
87904 + break;
87905 + case OID_802_11_SSID:
87906 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
87907 + NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
87908 + Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
87909 + memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
87910 + wrq->u.data.length = sizeof(NDIS_802_11_SSID);
87911 + Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
87912 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
87913 + break;
87914 + case RT_OID_802_11_QUERY_LINK_STATUS:
87915 + pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
87916 + if (pLinkStatus)
87917 + {
87918 + pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
87919 + pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
87920 + pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
87921 + pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
87922 + pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
87923 + wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
87924 + Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
87925 + kfree(pLinkStatus);
87926 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
87927 + }
87928 + else
87929 + {
87930 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
87931 + Status = -EFAULT;
87932 + }
87933 + break;
87934 + case OID_802_11_CONFIGURATION:
87935 + pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
87936 + if (pConfiguration)
87937 + {
87938 + pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
87939 + pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
87940 + pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
87941 + MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
87942 + wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
87943 + Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
87944 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
87945 + pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
87946 + kfree(pConfiguration);
87947 + }
87948 + else
87949 + {
87950 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
87951 + Status = -EFAULT;
87952 + }
87953 + break;
87954 + case RT_OID_802_11_SNR_0:
87955 + if ((pAdapter->StaCfg.LastSNR0 > 0))
87956 + {
87957 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
87958 + wrq->u.data.length = sizeof(ulInfo);
87959 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87960 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
87961 + }
87962 + else
87963 + Status = -EFAULT;
87964 + break;
87965 + case RT_OID_802_11_SNR_1:
87966 + if ((pAdapter->Antenna.field.RxPath > 1) &&
87967 + (pAdapter->StaCfg.LastSNR1 > 0))
87968 + {
87969 + ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
87970 + wrq->u.data.length = sizeof(ulInfo);
87971 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87972 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
87973 + }
87974 + else
87975 + Status = -EFAULT;
87976 + DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
87977 + break;
87978 + case OID_802_11_RSSI_TRIGGER:
87979 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
87980 + wrq->u.data.length = sizeof(ulInfo);
87981 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87982 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
87983 + break;
87984 + case OID_802_11_RSSI:
87985 + case RT_OID_802_11_RSSI:
87986 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
87987 + wrq->u.data.length = sizeof(ulInfo);
87988 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87989 + break;
87990 + case RT_OID_802_11_RSSI_1:
87991 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
87992 + wrq->u.data.length = sizeof(ulInfo);
87993 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87994 + break;
87995 + case RT_OID_802_11_RSSI_2:
87996 + ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
87997 + wrq->u.data.length = sizeof(ulInfo);
87998 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
87999 + break;
88000 + case OID_802_11_STATISTICS:
88001 + pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
88002 + if (pStatistics)
88003 + {
88004 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
88005 + // add the most up-to-date h/w raw counters into software counters
88006 + NICUpdateRawCounters(pAdapter);
88007 +
88008 + // Sanity check for calculation of sucessful count
88009 + if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
88010 + pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
88011 +
88012 + pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
88013 + pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
88014 + pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
88015 + pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
88016 + pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
88017 + pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
88018 + pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
88019 + pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
88020 + pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
88021 + pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
88022 + pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
88023 +#ifdef DBG
88024 + pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
88025 +#else
88026 + pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
88027 + pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
88028 +#endif
88029 + wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
88030 + Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
88031 + kfree(pStatistics);
88032 + }
88033 + else
88034 + {
88035 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
88036 + Status = -EFAULT;
88037 + }
88038 + break;
88039 + case OID_GEN_RCV_OK:
88040 + ulInfo = pAdapter->Counters8023.GoodReceives;
88041 + wrq->u.data.length = sizeof(ulInfo);
88042 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88043 + break;
88044 + case OID_GEN_RCV_NO_BUFFER:
88045 + ulInfo = pAdapter->Counters8023.RxNoBuffer;
88046 + wrq->u.data.length = sizeof(ulInfo);
88047 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88048 + break;
88049 + case RT_OID_802_11_PHY_MODE:
88050 + ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
88051 + wrq->u.data.length = sizeof(ulInfo);
88052 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88053 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
88054 + break;
88055 + case RT_OID_802_11_STA_CONFIG:
88056 + pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
88057 + if (pStaConfig)
88058 + {
88059 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
88060 + pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
88061 + pStaConfig->EnableTurboRate = 0;
88062 + pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
88063 + pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
88064 + //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
88065 + pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
88066 + pStaConfig->Rsv1 = 0;
88067 + pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
88068 + wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
88069 + Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
88070 + kfree(pStaConfig);
88071 + }
88072 + else
88073 + {
88074 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
88075 + Status = -EFAULT;
88076 + }
88077 + break;
88078 + case OID_802_11_RTS_THRESHOLD:
88079 + RtsThresh = pAdapter->CommonCfg.RtsThreshold;
88080 + wrq->u.data.length = sizeof(RtsThresh);
88081 + Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
88082 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
88083 + break;
88084 + case OID_802_11_FRAGMENTATION_THRESHOLD:
88085 + FragThresh = pAdapter->CommonCfg.FragmentThreshold;
88086 + if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
88087 + FragThresh = 0;
88088 + wrq->u.data.length = sizeof(FragThresh);
88089 + Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
88090 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
88091 + break;
88092 + case OID_802_11_POWER_MODE:
88093 + PowerMode = pAdapter->StaCfg.WindowsPowerMode;
88094 + wrq->u.data.length = sizeof(PowerMode);
88095 + Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
88096 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
88097 + break;
88098 + case RT_OID_802_11_RADIO:
88099 + RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
88100 + wrq->u.data.length = sizeof(RadioState);
88101 + Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
88102 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
88103 + break;
88104 + case OID_802_11_INFRASTRUCTURE_MODE:
88105 + if (pAdapter->StaCfg.BssType == BSS_ADHOC)
88106 + BssType = Ndis802_11IBSS;
88107 + else if (pAdapter->StaCfg.BssType == BSS_INFRA)
88108 + BssType = Ndis802_11Infrastructure;
88109 + else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
88110 + BssType = Ndis802_11Monitor;
88111 + else
88112 + BssType = Ndis802_11AutoUnknown;
88113 +
88114 + wrq->u.data.length = sizeof(BssType);
88115 + Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
88116 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
88117 + break;
88118 + case RT_OID_802_11_PREAMBLE:
88119 + PreamType = pAdapter->CommonCfg.TxPreamble;
88120 + wrq->u.data.length = sizeof(PreamType);
88121 + Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
88122 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
88123 + break;
88124 + case OID_802_11_AUTHENTICATION_MODE:
88125 + AuthMode = pAdapter->StaCfg.AuthMode;
88126 + wrq->u.data.length = sizeof(AuthMode);
88127 + Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
88128 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
88129 + break;
88130 + case OID_802_11_WEP_STATUS:
88131 + WepStatus = pAdapter->StaCfg.WepStatus;
88132 + wrq->u.data.length = sizeof(WepStatus);
88133 + Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
88134 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
88135 + break;
88136 + case OID_802_11_TX_POWER_LEVEL:
88137 + wrq->u.data.length = sizeof(ULONG);
88138 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
88139 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
88140 + break;
88141 + case RT_OID_802_11_TX_POWER_LEVEL_1:
88142 + wrq->u.data.length = sizeof(ULONG);
88143 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
88144 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
88145 + break;
88146 + case OID_802_11_NETWORK_TYPES_SUPPORTED:
88147 + if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
88148 + {
88149 + NetworkTypeList[0] = 3; // NumberOfItems = 3
88150 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
88151 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
88152 + NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
88153 + wrq->u.data.length = 16;
88154 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
88155 + }
88156 + else
88157 + {
88158 + NetworkTypeList[0] = 2; // NumberOfItems = 2
88159 + NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
88160 + NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
88161 + wrq->u.data.length = 12;
88162 + Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
88163 + }
88164 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
88165 + break;
88166 + case OID_802_11_NETWORK_TYPE_IN_USE:
88167 + wrq->u.data.length = sizeof(ULONG);
88168 + if (pAdapter->CommonCfg.PhyMode == PHY_11A)
88169 + ulInfo = Ndis802_11OFDM5;
88170 + else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
88171 + ulInfo = Ndis802_11OFDM24;
88172 + else
88173 + ulInfo = Ndis802_11DS;
88174 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88175 + break;
88176 + case RT_OID_802_11_QUERY_LAST_RX_RATE:
88177 + ulInfo = (ULONG)pAdapter->LastRxRate;
88178 + wrq->u.data.length = sizeof(ulInfo);
88179 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88180 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
88181 + break;
88182 + case RT_OID_802_11_QUERY_LAST_TX_RATE:
88183 + //ulInfo = (ULONG)pAdapter->LastTxRate;
88184 + ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
88185 + wrq->u.data.length = sizeof(ulInfo);
88186 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88187 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
88188 + break;
88189 + case RT_OID_802_11_QUERY_EEPROM_VERSION:
88190 + wrq->u.data.length = sizeof(ULONG);
88191 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
88192 + break;
88193 + case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
88194 + wrq->u.data.length = sizeof(ULONG);
88195 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
88196 + break;
88197 + case RT_OID_802_11_QUERY_NOISE_LEVEL:
88198 + wrq->u.data.length = sizeof(UCHAR);
88199 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
88200 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
88201 + break;
88202 + case RT_OID_802_11_EXTRA_INFO:
88203 + wrq->u.data.length = sizeof(ULONG);
88204 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
88205 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
88206 + break;
88207 + case RT_OID_WE_VERSION_COMPILED:
88208 + wrq->u.data.length = sizeof(UINT);
88209 + we_version_compiled = WIRELESS_EXT;
88210 + Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
88211 + break;
88212 + case RT_OID_802_11_QUERY_APSD_SETTING:
88213 + apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
88214 + | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
88215 +
88216 + wrq->u.data.length = sizeof(ULONG);
88217 + Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
88218 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_SETTING (=0x%lx,APSDCap=%d,AC_BE=%d,AC_BK=%d,AC_VI=%d,AC_VO=%d,MAXSPLen=%d)\n",
88219 + apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
88220 + break;
88221 + case RT_OID_802_11_QUERY_APSD_PSM:
88222 + wrq->u.data.length = sizeof(ULONG);
88223 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
88224 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
88225 + break;
88226 + case RT_OID_802_11_QUERY_WMM:
88227 + wrq->u.data.length = sizeof(BOOLEAN);
88228 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
88229 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
88230 + break;
88231 +#ifdef WPA_SUPPLICANT_SUPPORT
88232 + case RT_OID_NEW_DRIVER:
88233 + {
88234 + UCHAR enabled = 1;
88235 + wrq->u.data.length = sizeof(UCHAR);
88236 + Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
88237 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
88238 + }
88239 + break;
88240 + case RT_OID_WPA_SUPPLICANT_SUPPORT:
88241 + wrq->u.data.length = sizeof(UCHAR);
88242 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
88243 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
88244 + break;
88245 +#endif // WPA_SUPPLICANT_SUPPORT //
88246 +
88247 + case RT_OID_DRIVER_DEVICE_NAME:
88248 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
88249 + wrq->u.data.length = 16;
88250 + if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
88251 + {
88252 + Status = -EFAULT;
88253 + }
88254 + break;
88255 + case RT_OID_802_11_QUERY_HT_PHYMODE:
88256 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
88257 + if (pHTPhyMode)
88258 + {
88259 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
88260 + pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
88261 + pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
88262 + pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
88263 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
88264 + pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
88265 +
88266 + pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
88267 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
88268 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
88269 + {
88270 + Status = -EFAULT;
88271 + }
88272 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
88273 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
88274 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
88275 + }
88276 + else
88277 + {
88278 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
88279 + Status = -EFAULT;
88280 + }
88281 + break;
88282 + case RT_OID_802_11_COUNTRY_REGION:
88283 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
88284 + wrq->u.data.length = sizeof(ulInfo);
88285 + ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
88286 + ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
88287 + if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
88288 + {
88289 + Status = -EFAULT;
88290 + }
88291 + break;
88292 + case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
88293 + pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
88294 + if (pHTPhyMode)
88295 + {
88296 + pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
88297 + pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
88298 + pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
88299 + pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
88300 + pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
88301 + pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
88302 +
88303 + wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
88304 + if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
88305 + {
88306 + Status = -EFAULT;
88307 + }
88308 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
88309 + pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
88310 + DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
88311 + }
88312 + else
88313 + {
88314 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
88315 + Status = -EFAULT;
88316 + }
88317 + break;
88318 + case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
88319 + wrq->u.data.length = sizeof(UCHAR);
88320 + i = 0;
88321 +#ifdef MULTIPLE_CARD_SUPPORT
88322 + i = 1;
88323 +#endif // MULTIPLE_CARD_SUPPORT //
88324 + if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
88325 + {
88326 + Status = -EFAULT;
88327 + }
88328 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
88329 + break;
88330 +#ifdef SNMP_SUPPORT
88331 + case RT_OID_802_11_MAC_ADDRESS:
88332 + wrq->u.data.length = MAC_ADDR_LEN;
88333 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
88334 + break;
88335 +
88336 + case RT_OID_802_11_MANUFACTUREROUI:
88337 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
88338 + wrq->u.data.length = ManufacturerOUI_LEN;
88339 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
88340 + break;
88341 +
88342 + case RT_OID_802_11_MANUFACTURERNAME:
88343 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
88344 + wrq->u.data.length = strlen(ManufacturerNAME);
88345 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
88346 + break;
88347 +
88348 + case RT_OID_802_11_RESOURCETYPEIDNAME:
88349 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
88350 + wrq->u.data.length = strlen(ResourceTypeIdName);
88351 + Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
88352 + break;
88353 +
88354 + case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
88355 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
88356 + ulInfo = 1; // 1 is support wep else 2 is not support.
88357 + wrq->u.data.length = sizeof(ulInfo);
88358 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88359 + break;
88360 +
88361 + case RT_OID_802_11_POWERMANAGEMENTMODE:
88362 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
88363 + if (pAdapter->StaCfg.Psm == PSMP_ACTION)
88364 + ulInfo = 1; // 1 is power active else 2 is power save.
88365 + else
88366 + ulInfo = 2;
88367 +
88368 + wrq->u.data.length = sizeof(ulInfo);
88369 + Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
88370 + break;
88371 +
88372 + case OID_802_11_WEPDEFAULTKEYVALUE:
88373 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
88374 + //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
88375 + pKeyIdxValue = wrq->u.data.pointer;
88376 + DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
88377 + valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
88378 + NdisMoveMemory(pKeyIdxValue->Value,
88379 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
88380 + valueLen);
88381 + pKeyIdxValue->Value[valueLen]='\0';
88382 +
88383 + wrq->u.data.length = sizeof(DefaultKeyIdxValue);
88384 +
88385 + Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
88386 + DBGPRINT(RT_DEBUG_TRACE,("DefaultKeyId = %d, total len = %d, str len=%d, KeyValue= %02x %02x %02x %02x \n", pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
88387 + pAdapter->SharedKey[BSS0][0].Key[0],
88388 + pAdapter->SharedKey[BSS0][1].Key[0],
88389 + pAdapter->SharedKey[BSS0][2].Key[0],
88390 + pAdapter->SharedKey[BSS0][3].Key[0]));
88391 + break;
88392 +
88393 + case OID_802_11_WEPDEFAULTKEYID:
88394 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
88395 + wrq->u.data.length = sizeof(UCHAR);
88396 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
88397 + DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
88398 + break;
88399 +
88400 + case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
88401 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
88402 + wrq->u.data.length = sizeof(UCHAR);
88403 + Status = copy_to_user(wrq->u.data.pointer,
88404 + &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
88405 + wrq->u.data.length);
88406 + break;
88407 +
88408 + case OID_802_11_SHORTRETRYLIMIT:
88409 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
88410 + wrq->u.data.length = sizeof(ULONG);
88411 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
88412 + ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
88413 + DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
88414 + Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
88415 + break;
88416 +
88417 + case OID_802_11_LONGRETRYLIMIT:
88418 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
88419 + wrq->u.data.length = sizeof(ULONG);
88420 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
88421 + LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
88422 + DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
88423 + Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
88424 + break;
88425 +
88426 + case RT_OID_802_11_PRODUCTID:
88427 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
88428 +
88429 +#ifdef RT2870
88430 + sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
88431 +
88432 +#endif // RT2870 //
88433 + wrq->u.data.length = strlen(tmp);
88434 + Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
88435 + break;
88436 +
88437 + case RT_OID_802_11_MANUFACTUREID:
88438 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
88439 + wrq->u.data.length = strlen(ManufacturerNAME);
88440 + Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
88441 + break;
88442 +
88443 + case OID_802_11_CURRENTCHANNEL:
88444 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
88445 + wrq->u.data.length = sizeof(UCHAR);
88446 + DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
88447 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
88448 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
88449 + break;
88450 +#endif //SNMP_SUPPORT
88451 +
88452 + case OID_802_11_BUILD_CHANNEL_EX:
88453 + {
88454 + UCHAR value;
88455 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
88456 + wrq->u.data.length = sizeof(UCHAR);
88457 +#ifdef EXT_BUILD_CHANNEL_LIST
88458 + DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
88459 + value = 1;
88460 +#else
88461 + DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
88462 + value = 0;
88463 +#endif // EXT_BUILD_CHANNEL_LIST //
88464 + Status = copy_to_user(wrq->u.data.pointer, &value, 1);
88465 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
88466 + }
88467 + break;
88468 +
88469 + case OID_802_11_GET_CH_LIST:
88470 + {
88471 + PRT_CHANNEL_LIST_INFO pChListBuf;
88472 +
88473 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
88474 + if (pAdapter->ChannelListNum == 0)
88475 + {
88476 + wrq->u.data.length = 0;
88477 + break;
88478 + }
88479 +
88480 + pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
88481 + if (pChListBuf == NULL)
88482 + {
88483 + wrq->u.data.length = 0;
88484 + break;
88485 + }
88486 +
88487 + pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
88488 + for (i = 0; i < pChListBuf->ChannelListNum; i++)
88489 + pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
88490 +
88491 + wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
88492 + Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
88493 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
88494 +
88495 + if (pChListBuf)
88496 + kfree(pChListBuf);
88497 + }
88498 + break;
88499 +
88500 + case OID_802_11_GET_COUNTRY_CODE:
88501 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
88502 + wrq->u.data.length = 2;
88503 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
88504 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
88505 + break;
88506 +
88507 + case OID_802_11_GET_CHANNEL_GEOGRAPHY:
88508 + DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
88509 + wrq->u.data.length = 1;
88510 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
88511 + DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
88512 + break;
88513 +
88514 +
88515 +#ifdef QOS_DLS_SUPPORT
88516 + case RT_OID_802_11_QUERY_DLS:
88517 + wrq->u.data.length = sizeof(BOOLEAN);
88518 + Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
88519 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
88520 + break;
88521 +
88522 + case RT_OID_802_11_QUERY_DLS_PARAM:
88523 + {
88524 + PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
88525 + if (pDlsInfo == NULL)
88526 + break;
88527 +
88528 + for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
88529 + {
88530 + RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
88531 + }
88532 +
88533 + pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
88534 + wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
88535 + Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
88536 + DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
88537 +
88538 + if (pDlsInfo)
88539 + kfree(pDlsInfo);
88540 + }
88541 + break;
88542 +#endif // QOS_DLS_SUPPORT //
88543 + default:
88544 + DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
88545 + Status = -EOPNOTSUPP;
88546 + break;
88547 + }
88548 + return Status;
88549 +}
88550 +
88551 +INT rt28xx_sta_ioctl(
88552 + IN struct net_device *net_dev,
88553 + IN OUT struct ifreq *rq,
88554 + IN INT cmd)
88555 +{
88556 + POS_COOKIE pObj;
88557 + VIRTUAL_ADAPTER *pVirtualAd = NULL;
88558 + RTMP_ADAPTER *pAd = NULL;
88559 + struct iwreq *wrq = (struct iwreq *) rq;
88560 + BOOLEAN StateMachineTouched = FALSE;
88561 + INT Status = NDIS_STATUS_SUCCESS;
88562 + USHORT subcmd;
88563 +
88564 + if (net_dev->priv_flags == INT_MAIN)
88565 + {
88566 + pAd = net_dev->ml_priv;
88567 + }
88568 + else
88569 + {
88570 + pVirtualAd = net_dev->ml_priv;
88571 + pAd = pVirtualAd->RtmpDev->ml_priv;
88572 + }
88573 + pObj = (POS_COOKIE) pAd->OS_Cookie;
88574 +
88575 + if (pAd == NULL)
88576 + {
88577 + /* if 1st open fail, pAd will be free;
88578 + So the net_dev->ml_priv will be NULL in 2rd open */
88579 + return -ENETDOWN;
88580 + }
88581 +
88582 + //check if the interface is down
88583 + if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
88584 + {
88585 +#ifdef CONFIG_APSTA_MIXED_SUPPORT
88586 + if (wrq->u.data.pointer == NULL)
88587 + {
88588 + return Status;
88589 + }
88590 +
88591 + if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
88592 +#endif // CONFIG_APSTA_MIXED_SUPPORT //
88593 + {
88594 + DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
88595 + return -ENETDOWN;
88596 + }
88597 + }
88598 +
88599 + { // determine this ioctl command is comming from which interface.
88600 + pObj->ioctl_if_type = INT_MAIN;
88601 + pObj->ioctl_if = MAIN_MBSSID;
88602 + }
88603 +
88604 + switch(cmd)
88605 + {
88606 +#ifdef RALINK_ATE
88607 +#ifdef RALINK_28xx_QA
88608 + case RTPRIV_IOCTL_ATE:
88609 + {
88610 + RtmpDoAte(pAd, wrq);
88611 + }
88612 + break;
88613 +#endif // RALINK_28xx_QA //
88614 +#endif // RALINK_ATE //
88615 + case SIOCGIFHWADDR:
88616 + DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
88617 + memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
88618 + break;
88619 + case SIOCGIWNAME:
88620 + {
88621 + char *name=&wrq->u.name[0];
88622 + rt_ioctl_giwname(net_dev, NULL, name, NULL);
88623 + break;
88624 + }
88625 + case SIOCGIWESSID: //Get ESSID
88626 + {
88627 + struct iw_point *essid=&wrq->u.essid;
88628 + rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
88629 + break;
88630 + }
88631 + case SIOCSIWESSID: //Set ESSID
88632 + {
88633 + struct iw_point *essid=&wrq->u.essid;
88634 + rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
88635 + break;
88636 + }
88637 + case SIOCSIWNWID: // set network id (the cell)
88638 + case SIOCGIWNWID: // get network id
88639 + Status = -EOPNOTSUPP;
88640 + break;
88641 + case SIOCSIWFREQ: //set channel/frequency (Hz)
88642 + {
88643 + struct iw_freq *freq=&wrq->u.freq;
88644 + rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
88645 + break;
88646 + }
88647 + case SIOCGIWFREQ: // get channel/frequency (Hz)
88648 + {
88649 + struct iw_freq *freq=&wrq->u.freq;
88650 + rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
88651 + break;
88652 + }
88653 + case SIOCSIWNICKN: //set node name/nickname
88654 + {
88655 + struct iw_point *data=&wrq->u.data;
88656 + rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
88657 + break;
88658 + }
88659 + case SIOCGIWNICKN: //get node name/nickname
88660 + {
88661 + struct iw_point *data=&wrq->u.data;
88662 + rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
88663 + break;
88664 + }
88665 + case SIOCGIWRATE: //get default bit rate (bps)
88666 + rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
88667 + break;
88668 + case SIOCSIWRATE: //set default bit rate (bps)
88669 + rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
88670 + break;
88671 + case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
88672 + {
88673 + struct iw_param *rts=&wrq->u.rts;
88674 + rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
88675 + break;
88676 + }
88677 + case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
88678 + {
88679 + struct iw_param *rts=&wrq->u.rts;
88680 + rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
88681 + break;
88682 + }
88683 + case SIOCGIWFRAG: //get fragmentation thr (bytes)
88684 + {
88685 + struct iw_param *frag=&wrq->u.frag;
88686 + rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
88687 + break;
88688 + }
88689 + case SIOCSIWFRAG: //set fragmentation thr (bytes)
88690 + {
88691 + struct iw_param *frag=&wrq->u.frag;
88692 + rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
88693 + break;
88694 + }
88695 + case SIOCGIWENCODE: //get encoding token & mode
88696 + {
88697 + struct iw_point *erq=&wrq->u.encoding;
88698 + if(erq->pointer)
88699 + rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
88700 + break;
88701 + }
88702 + case SIOCSIWENCODE: //set encoding token & mode
88703 + {
88704 + struct iw_point *erq=&wrq->u.encoding;
88705 + if(erq->pointer)
88706 + rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
88707 + break;
88708 + }
88709 + case SIOCGIWAP: //get access point MAC addresses
88710 + {
88711 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
88712 + rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
88713 + break;
88714 + }
88715 + case SIOCSIWAP: //set access point MAC addresses
88716 + {
88717 + struct sockaddr *ap_addr=&wrq->u.ap_addr;
88718 + rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
88719 + break;
88720 + }
88721 + case SIOCGIWMODE: //get operation mode
88722 + {
88723 + __u32 *mode=&wrq->u.mode;
88724 + rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
88725 + break;
88726 + }
88727 + case SIOCSIWMODE: //set operation mode
88728 + {
88729 + __u32 *mode=&wrq->u.mode;
88730 + rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
88731 + break;
88732 + }
88733 + case SIOCGIWSENS: //get sensitivity (dBm)
88734 + case SIOCSIWSENS: //set sensitivity (dBm)
88735 + case SIOCGIWPOWER: //get Power Management settings
88736 + case SIOCSIWPOWER: //set Power Management settings
88737 + case SIOCGIWTXPOW: //get transmit power (dBm)
88738 + case SIOCSIWTXPOW: //set transmit power (dBm)
88739 + case SIOCGIWRANGE: //Get range of parameters
88740 + case SIOCGIWRETRY: //get retry limits and lifetime
88741 + case SIOCSIWRETRY: //set retry limits and lifetime
88742 + Status = -EOPNOTSUPP;
88743 + break;
88744 + case RT_PRIV_IOCTL:
88745 + case RT_PRIV_IOCTL_EXT:
88746 + subcmd = wrq->u.data.flags;
88747 + if( subcmd & OID_GET_SET_TOGGLE)
88748 + Status = RTMPSetInformation(pAd, rq, subcmd);
88749 + else
88750 + Status = RTMPQueryInformation(pAd, rq, subcmd);
88751 + break;
88752 + case SIOCGIWPRIV:
88753 + if (wrq->u.data.pointer)
88754 + {
88755 + if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
88756 + break;
88757 + wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
88758 + if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
88759 + Status = -EFAULT;
88760 + }
88761 + break;
88762 + case RTPRIV_IOCTL_SET:
88763 + if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
88764 + break;
88765 + rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
88766 + break;
88767 + case RTPRIV_IOCTL_GSITESURVEY:
88768 + RTMPIoctlGetSiteSurvey(pAd, wrq);
88769 + break;
88770 +#ifdef DBG
88771 + case RTPRIV_IOCTL_MAC:
88772 + RTMPIoctlMAC(pAd, wrq);
88773 + break;
88774 + case RTPRIV_IOCTL_E2P:
88775 + RTMPIoctlE2PROM(pAd, wrq);
88776 + break;
88777 +#ifdef RT30xx
88778 + case RTPRIV_IOCTL_RF:
88779 + RTMPIoctlRF(pAd, wrq);
88780 + break;
88781 +#endif // RT30xx //
88782 +#endif // DBG //
88783 + case SIOCETHTOOL:
88784 + break;
88785 + default:
88786 + DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
88787 + Status = -EOPNOTSUPP;
88788 + break;
88789 + }
88790 +
88791 + if(StateMachineTouched) // Upper layer sent a MLME-related operations
88792 + RT28XX_MLME_HANDLER(pAd);
88793 +
88794 + return Status;
88795 +}
88796 +
88797 +/*
88798 + ==========================================================================
88799 + Description:
88800 + Set SSID
88801 + Return:
88802 + TRUE if all parameters are OK, FALSE otherwise
88803 + ==========================================================================
88804 +*/
88805 +INT Set_SSID_Proc(
88806 + IN PRTMP_ADAPTER pAdapter,
88807 + IN PUCHAR arg)
88808 +{
88809 + NDIS_802_11_SSID Ssid, *pSsid=NULL;
88810 + BOOLEAN StateMachineTouched = FALSE;
88811 + int success = TRUE;
88812 +
88813 + if( strlen(arg) <= MAX_LEN_OF_SSID)
88814 + {
88815 + NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
88816 + if (strlen(arg) != 0)
88817 + {
88818 + NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
88819 + Ssid.SsidLength = strlen(arg);
88820 + }
88821 + else //ANY ssid
88822 + {
88823 + Ssid.SsidLength = 0;
88824 + memcpy(Ssid.Ssid, "", 0);
88825 + pAdapter->StaCfg.BssType = BSS_INFRA;
88826 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
88827 + pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
88828 + }
88829 + pSsid = &Ssid;
88830 +
88831 + if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
88832 + {
88833 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
88834 + DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
88835 + }
88836 +
88837 + pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
88838 + pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
88839 + pAdapter->bConfigChanged = TRUE;
88840 +
88841 + MlmeEnqueue(pAdapter,
88842 + MLME_CNTL_STATE_MACHINE,
88843 + OID_802_11_SSID,
88844 + sizeof(NDIS_802_11_SSID),
88845 + (VOID *)pSsid);
88846 +
88847 + StateMachineTouched = TRUE;
88848 + DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
88849 + }
88850 + else
88851 + success = FALSE;
88852 +
88853 + if (StateMachineTouched) // Upper layer sent a MLME-related operations
88854 + RT28XX_MLME_HANDLER(pAdapter);
88855 +
88856 + return success;
88857 +}
88858 +
88859 +#ifdef WMM_SUPPORT
88860 +/*
88861 + ==========================================================================
88862 + Description:
88863 + Set WmmCapable Enable or Disable
88864 + Return:
88865 + TRUE if all parameters are OK, FALSE otherwise
88866 + ==========================================================================
88867 +*/
88868 +INT Set_WmmCapable_Proc(
88869 + IN PRTMP_ADAPTER pAd,
88870 + IN PUCHAR arg)
88871 +{
88872 + BOOLEAN bWmmCapable;
88873 +
88874 + bWmmCapable = simple_strtol(arg, 0, 10);
88875 +
88876 + if ((bWmmCapable == 1)
88877 +#ifdef RT2870
88878 + && (pAd->NumberOfPipes >= 5)
88879 +#endif // RT2870 //
88880 + )
88881 + pAd->CommonCfg.bWmmCapable = TRUE;
88882 + else if (bWmmCapable == 0)
88883 + pAd->CommonCfg.bWmmCapable = FALSE;
88884 + else
88885 + return FALSE; //Invalid argument
88886 +
88887 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
88888 + pAd->CommonCfg.bWmmCapable));
88889 +
88890 + return TRUE;
88891 +}
88892 +#endif // WMM_SUPPORT //
88893 +
88894 +/*
88895 + ==========================================================================
88896 + Description:
88897 + Set Network Type(Infrastructure/Adhoc mode)
88898 + Return:
88899 + TRUE if all parameters are OK, FALSE otherwise
88900 + ==========================================================================
88901 +*/
88902 +INT Set_NetworkType_Proc(
88903 + IN PRTMP_ADAPTER pAdapter,
88904 + IN PUCHAR arg)
88905 +{
88906 + UINT32 Value = 0;
88907 +
88908 + if (strcmp(arg, "Adhoc") == 0)
88909 + {
88910 + if (pAdapter->StaCfg.BssType != BSS_ADHOC)
88911 + {
88912 + // Config has changed
88913 + pAdapter->bConfigChanged = TRUE;
88914 + if (MONITOR_ON(pAdapter))
88915 + {
88916 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
88917 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
88918 + Value &= (~0x80);
88919 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
88920 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88921 + pAdapter->StaCfg.bAutoReconnect = TRUE;
88922 + LinkDown(pAdapter, FALSE);
88923 + }
88924 + if (INFRA_ON(pAdapter))
88925 + {
88926 + //BOOLEAN Cancelled;
88927 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
88928 + // Since calling this indicate user don't want to connect to that SSID anymore.
88929 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
88930 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
88931 +
88932 + LinkDown(pAdapter, FALSE);
88933 +
88934 + DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
88935 + }
88936 + }
88937 + pAdapter->StaCfg.BssType = BSS_ADHOC;
88938 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
88939 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
88940 + }
88941 + else if (strcmp(arg, "Infra") == 0)
88942 + {
88943 + if (pAdapter->StaCfg.BssType != BSS_INFRA)
88944 + {
88945 + // Config has changed
88946 + pAdapter->bConfigChanged = TRUE;
88947 + if (MONITOR_ON(pAdapter))
88948 + {
88949 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
88950 + RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
88951 + Value &= (~0x80);
88952 + RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
88953 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88954 + pAdapter->StaCfg.bAutoReconnect = TRUE;
88955 + LinkDown(pAdapter, FALSE);
88956 + }
88957 + if (ADHOC_ON(pAdapter))
88958 + {
88959 + // Set the AutoReconnectSsid to prevent it reconnect to old SSID
88960 + // Since calling this indicate user don't want to connect to that SSID anymore.
88961 + pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
88962 + NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
88963 +
88964 + LinkDown(pAdapter, FALSE);
88965 + }
88966 + }
88967 + pAdapter->StaCfg.BssType = BSS_INFRA;
88968 + pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
88969 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
88970 +
88971 + pAdapter->StaCfg.BssType = BSS_INFRA;
88972 + }
88973 + else if (strcmp(arg, "Monitor") == 0)
88974 + {
88975 + UCHAR bbpValue = 0;
88976 + BCN_TIME_CFG_STRUC csr;
88977 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
88978 + OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
88979 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
88980 + // disable all periodic state machine
88981 + pAdapter->StaCfg.bAutoReconnect = FALSE;
88982 + // reset all mlme state machine
88983 + RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
88984 + DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
88985 + if (pAdapter->CommonCfg.CentralChannel == 0)
88986 + {
88987 +#ifdef DOT11_N_SUPPORT
88988 + if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
88989 + pAdapter->CommonCfg.CentralChannel = 36;
88990 + else
88991 +#endif // DOT11_N_SUPPORT //
88992 + pAdapter->CommonCfg.CentralChannel = 6;
88993 + }
88994 +#ifdef DOT11_N_SUPPORT
88995 + else
88996 + N_ChannelCheck(pAdapter);
88997 +#endif // DOT11_N_SUPPORT //
88998 +
88999 +#ifdef DOT11_N_SUPPORT
89000 + if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
89001 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
89002 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
89003 + {
89004 + // 40MHz ,control channel at lower
89005 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
89006 + bbpValue &= (~0x18);
89007 + bbpValue |= 0x10;
89008 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
89009 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
89010 + // RX : control channel at lower
89011 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
89012 + bbpValue &= (~0x20);
89013 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
89014 +
89015 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
89016 + Value &= 0xfffffffe;
89017 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
89018 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
89019 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
89020 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
89021 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
89022 + pAdapter->CommonCfg.Channel,
89023 + pAdapter->CommonCfg.CentralChannel));
89024 + }
89025 + else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
89026 + pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
89027 + pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
89028 + {
89029 + // 40MHz ,control channel at upper
89030 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
89031 + bbpValue &= (~0x18);
89032 + bbpValue |= 0x10;
89033 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
89034 + pAdapter->CommonCfg.BBPCurrentBW = BW_40;
89035 + RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
89036 + Value |= 0x1;
89037 + RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
89038 +
89039 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
89040 + bbpValue |= (0x20);
89041 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
89042 + pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
89043 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
89044 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
89045 + DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
89046 + pAdapter->CommonCfg.Channel,
89047 + pAdapter->CommonCfg.CentralChannel));
89048 + }
89049 + else
89050 +#endif // DOT11_N_SUPPORT //
89051 + {
89052 + // 20MHz
89053 + RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
89054 + bbpValue &= (~0x18);
89055 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
89056 + pAdapter->CommonCfg.BBPCurrentBW = BW_20;
89057 + AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
89058 + AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
89059 + DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
89060 + }
89061 + // Enable Rx with promiscuous reception
89062 + RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
89063 + // ASIC supporsts sniffer function with replacing RSSI with timestamp.
89064 + //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
89065 + //Value |= (0x80);
89066 + //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
89067 + // disable sync
89068 + RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
89069 + csr.field.bBeaconGen = 0;
89070 + csr.field.bTBTTEnable = 0;
89071 + csr.field.TsfSyncMode = 0;
89072 + RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
89073 +
89074 + pAdapter->StaCfg.BssType = BSS_MONITOR;
89075 + pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
89076 + DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
89077 + }
89078 +
89079 + // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
89080 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
89081 +
89082 + DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
89083 +
89084 + return TRUE;
89085 +}
89086 +
89087 +/*
89088 + ==========================================================================
89089 + Description:
89090 + Set Authentication mode
89091 + Return:
89092 + TRUE if all parameters are OK, FALSE otherwise
89093 + ==========================================================================
89094 +*/
89095 +INT Set_AuthMode_Proc(
89096 + IN PRTMP_ADAPTER pAdapter,
89097 + IN PUCHAR arg)
89098 +{
89099 + if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
89100 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
89101 + else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
89102 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
89103 + else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
89104 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
89105 + else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
89106 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
89107 + else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
89108 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
89109 + else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
89110 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
89111 +#ifdef WPA_SUPPLICANT_SUPPORT
89112 + else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
89113 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
89114 + else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
89115 + pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
89116 +#endif // WPA_SUPPLICANT_SUPPORT //
89117 + else
89118 + return FALSE;
89119 +
89120 + pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
89121 +
89122 + DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
89123 +
89124 + return TRUE;
89125 +}
89126 +
89127 +/*
89128 + ==========================================================================
89129 + Description:
89130 + Set Encryption Type
89131 + Return:
89132 + TRUE if all parameters are OK, FALSE otherwise
89133 + ==========================================================================
89134 +*/
89135 +INT Set_EncrypType_Proc(
89136 + IN PRTMP_ADAPTER pAdapter,
89137 + IN PUCHAR arg)
89138 +{
89139 + if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
89140 + {
89141 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89142 + return TRUE; // do nothing
89143 +
89144 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
89145 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
89146 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
89147 + }
89148 + else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
89149 + {
89150 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89151 + return TRUE; // do nothing
89152 +
89153 + pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
89154 + pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
89155 + pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
89156 + }
89157 + else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
89158 + {
89159 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
89160 + return TRUE; // do nothing
89161 +
89162 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
89163 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
89164 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
89165 + }
89166 + else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
89167 + {
89168 + if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
89169 + return TRUE; // do nothing
89170 +
89171 + pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
89172 + pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
89173 + pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
89174 + }
89175 + else
89176 + return FALSE;
89177 +
89178 + pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
89179 +
89180 + DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
89181 +
89182 + return TRUE;
89183 +}
89184 +
89185 +/*
89186 + ==========================================================================
89187 + Description:
89188 + Set Default Key ID
89189 + Return:
89190 + TRUE if all parameters are OK, FALSE otherwise
89191 + ==========================================================================
89192 +*/
89193 +INT Set_DefaultKeyID_Proc(
89194 + IN PRTMP_ADAPTER pAdapter,
89195 + IN PUCHAR arg)
89196 +{
89197 + ULONG KeyIdx;
89198 +
89199 + KeyIdx = simple_strtol(arg, 0, 10);
89200 + if((KeyIdx >= 1 ) && (KeyIdx <= 4))
89201 + pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
89202 + else
89203 + return FALSE; //Invalid argument
89204 +
89205 + DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
89206 +
89207 + return TRUE;
89208 +}
89209 +
89210 +/*
89211 + ==========================================================================
89212 + Description:
89213 + Set WEP KEY1
89214 + Return:
89215 + TRUE if all parameters are OK, FALSE otherwise
89216 + ==========================================================================
89217 +*/
89218 +INT Set_Key1_Proc(
89219 + IN PRTMP_ADAPTER pAdapter,
89220 + IN PUCHAR arg)
89221 +{
89222 + int KeyLen;
89223 + int i;
89224 + UCHAR CipherAlg=CIPHER_WEP64;
89225 +
89226 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89227 + return TRUE; // do nothing
89228 +
89229 + KeyLen = strlen(arg);
89230 +
89231 + switch (KeyLen)
89232 + {
89233 + case 5: //wep 40 Ascii type
89234 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
89235 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
89236 + CipherAlg = CIPHER_WEP64;
89237 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
89238 + break;
89239 + case 10: //wep 40 Hex type
89240 + for(i=0; i < KeyLen; i++)
89241 + {
89242 + if( !isxdigit(*(arg+i)) )
89243 + return FALSE; //Not Hex value;
89244 + }
89245 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
89246 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
89247 + CipherAlg = CIPHER_WEP64;
89248 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
89249 + break;
89250 + case 13: //wep 104 Ascii type
89251 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
89252 + memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
89253 + CipherAlg = CIPHER_WEP128;
89254 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
89255 + break;
89256 + case 26: //wep 104 Hex type
89257 + for(i=0; i < KeyLen; i++)
89258 + {
89259 + if( !isxdigit(*(arg+i)) )
89260 + return FALSE; //Not Hex value;
89261 + }
89262 + pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
89263 + AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
89264 + CipherAlg = CIPHER_WEP128;
89265 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
89266 + break;
89267 + default: //Invalid argument
89268 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
89269 + return FALSE;
89270 + }
89271 +
89272 + pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
89273 +
89274 + // Set keys (into ASIC)
89275 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89276 + ; // not support
89277 + else // Old WEP stuff
89278 + {
89279 + AsicAddSharedKeyEntry(pAdapter,
89280 + 0,
89281 + 0,
89282 + pAdapter->SharedKey[BSS0][0].CipherAlg,
89283 + pAdapter->SharedKey[BSS0][0].Key,
89284 + NULL,
89285 + NULL);
89286 + }
89287 +
89288 + return TRUE;
89289 +}
89290 +/*
89291 + ==========================================================================
89292 +
89293 + Description:
89294 + Set WEP KEY2
89295 + Return:
89296 + TRUE if all parameters are OK, FALSE otherwise
89297 + ==========================================================================
89298 +*/
89299 +INT Set_Key2_Proc(
89300 + IN PRTMP_ADAPTER pAdapter,
89301 + IN PUCHAR arg)
89302 +{
89303 + int KeyLen;
89304 + int i;
89305 + UCHAR CipherAlg=CIPHER_WEP64;
89306 +
89307 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89308 + return TRUE; // do nothing
89309 +
89310 + KeyLen = strlen(arg);
89311 +
89312 + switch (KeyLen)
89313 + {
89314 + case 5: //wep 40 Ascii type
89315 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
89316 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
89317 + CipherAlg = CIPHER_WEP64;
89318 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
89319 + break;
89320 + case 10: //wep 40 Hex type
89321 + for(i=0; i < KeyLen; i++)
89322 + {
89323 + if( !isxdigit(*(arg+i)) )
89324 + return FALSE; //Not Hex value;
89325 + }
89326 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
89327 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
89328 + CipherAlg = CIPHER_WEP64;
89329 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
89330 + break;
89331 + case 13: //wep 104 Ascii type
89332 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
89333 + memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
89334 + CipherAlg = CIPHER_WEP128;
89335 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
89336 + break;
89337 + case 26: //wep 104 Hex type
89338 + for(i=0; i < KeyLen; i++)
89339 + {
89340 + if( !isxdigit(*(arg+i)) )
89341 + return FALSE; //Not Hex value;
89342 + }
89343 + pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
89344 + AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
89345 + CipherAlg = CIPHER_WEP128;
89346 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
89347 + break;
89348 + default: //Invalid argument
89349 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
89350 + return FALSE;
89351 + }
89352 + pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
89353 +
89354 + // Set keys (into ASIC)
89355 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89356 + ; // not support
89357 + else // Old WEP stuff
89358 + {
89359 + AsicAddSharedKeyEntry(pAdapter,
89360 + 0,
89361 + 1,
89362 + pAdapter->SharedKey[BSS0][1].CipherAlg,
89363 + pAdapter->SharedKey[BSS0][1].Key,
89364 + NULL,
89365 + NULL);
89366 + }
89367 +
89368 + return TRUE;
89369 +}
89370 +/*
89371 + ==========================================================================
89372 + Description:
89373 + Set WEP KEY3
89374 + Return:
89375 + TRUE if all parameters are OK, FALSE otherwise
89376 + ==========================================================================
89377 +*/
89378 +INT Set_Key3_Proc(
89379 + IN PRTMP_ADAPTER pAdapter,
89380 + IN PUCHAR arg)
89381 +{
89382 + int KeyLen;
89383 + int i;
89384 + UCHAR CipherAlg=CIPHER_WEP64;
89385 +
89386 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89387 + return TRUE; // do nothing
89388 +
89389 + KeyLen = strlen(arg);
89390 +
89391 + switch (KeyLen)
89392 + {
89393 + case 5: //wep 40 Ascii type
89394 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
89395 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
89396 + CipherAlg = CIPHER_WEP64;
89397 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
89398 + break;
89399 + case 10: //wep 40 Hex type
89400 + for(i=0; i < KeyLen; i++)
89401 + {
89402 + if( !isxdigit(*(arg+i)) )
89403 + return FALSE; //Not Hex value;
89404 + }
89405 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
89406 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
89407 + CipherAlg = CIPHER_WEP64;
89408 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
89409 + break;
89410 + case 13: //wep 104 Ascii type
89411 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
89412 + memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
89413 + CipherAlg = CIPHER_WEP128;
89414 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
89415 + break;
89416 + case 26: //wep 104 Hex type
89417 + for(i=0; i < KeyLen; i++)
89418 + {
89419 + if( !isxdigit(*(arg+i)) )
89420 + return FALSE; //Not Hex value;
89421 + }
89422 + pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
89423 + AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
89424 + CipherAlg = CIPHER_WEP128;
89425 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
89426 + break;
89427 + default: //Invalid argument
89428 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
89429 + return FALSE;
89430 + }
89431 + pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
89432 +
89433 + // Set keys (into ASIC)
89434 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89435 + ; // not support
89436 + else // Old WEP stuff
89437 + {
89438 + AsicAddSharedKeyEntry(pAdapter,
89439 + 0,
89440 + 2,
89441 + pAdapter->SharedKey[BSS0][2].CipherAlg,
89442 + pAdapter->SharedKey[BSS0][2].Key,
89443 + NULL,
89444 + NULL);
89445 + }
89446 +
89447 + return TRUE;
89448 +}
89449 +/*
89450 + ==========================================================================
89451 + Description:
89452 + Set WEP KEY4
89453 + Return:
89454 + TRUE if all parameters are OK, FALSE otherwise
89455 + ==========================================================================
89456 +*/
89457 +INT Set_Key4_Proc(
89458 + IN PRTMP_ADAPTER pAdapter,
89459 + IN PUCHAR arg)
89460 +{
89461 + int KeyLen;
89462 + int i;
89463 + UCHAR CipherAlg=CIPHER_WEP64;
89464 +
89465 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89466 + return TRUE; // do nothing
89467 +
89468 + KeyLen = strlen(arg);
89469 +
89470 + switch (KeyLen)
89471 + {
89472 + case 5: //wep 40 Ascii type
89473 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
89474 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
89475 + CipherAlg = CIPHER_WEP64;
89476 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
89477 + break;
89478 + case 10: //wep 40 Hex type
89479 + for(i=0; i < KeyLen; i++)
89480 + {
89481 + if( !isxdigit(*(arg+i)) )
89482 + return FALSE; //Not Hex value;
89483 + }
89484 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
89485 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
89486 + CipherAlg = CIPHER_WEP64;
89487 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
89488 + break;
89489 + case 13: //wep 104 Ascii type
89490 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
89491 + memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
89492 + CipherAlg = CIPHER_WEP128;
89493 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
89494 + break;
89495 + case 26: //wep 104 Hex type
89496 + for(i=0; i < KeyLen; i++)
89497 + {
89498 + if( !isxdigit(*(arg+i)) )
89499 + return FALSE; //Not Hex value;
89500 + }
89501 + pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
89502 + AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
89503 + CipherAlg = CIPHER_WEP128;
89504 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
89505 + break;
89506 + default: //Invalid argument
89507 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
89508 + return FALSE;
89509 + }
89510 + pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
89511 +
89512 + // Set keys (into ASIC)
89513 + if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
89514 + ; // not support
89515 + else // Old WEP stuff
89516 + {
89517 + AsicAddSharedKeyEntry(pAdapter,
89518 + 0,
89519 + 3,
89520 + pAdapter->SharedKey[BSS0][3].CipherAlg,
89521 + pAdapter->SharedKey[BSS0][3].Key,
89522 + NULL,
89523 + NULL);
89524 + }
89525 +
89526 + return TRUE;
89527 +}
89528 +
89529 +/*
89530 + ==========================================================================
89531 + Description:
89532 + Set WPA PSK key
89533 + Return:
89534 + TRUE if all parameters are OK, FALSE otherwise
89535 + ==========================================================================
89536 +*/
89537 +INT Set_WPAPSK_Proc(
89538 + IN PRTMP_ADAPTER pAdapter,
89539 + IN PUCHAR arg)
89540 +{
89541 + UCHAR keyMaterial[40];
89542 +
89543 + if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
89544 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
89545 + (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
89546 + )
89547 + return TRUE; // do nothing
89548 +
89549 + DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
89550 +
89551 + NdisZeroMemory(keyMaterial, 40);
89552 +
89553 + if ((strlen(arg) < 8) || (strlen(arg) > 64))
89554 + {
89555 + DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
89556 + return FALSE;
89557 + }
89558 +
89559 + if (strlen(arg) == 64)
89560 + {
89561 + AtoH(arg, keyMaterial, 32);
89562 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
89563 +
89564 + }
89565 + else
89566 + {
89567 + PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
89568 + NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
89569 + }
89570 +
89571 +
89572 +
89573 + if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
89574 + pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
89575 + {
89576 + pAdapter->StaCfg.WpaState = SS_NOTUSE;
89577 + }
89578 + else
89579 + {
89580 + // Start STA supplicant state machine
89581 + pAdapter->StaCfg.WpaState = SS_START;
89582 + }
89583 +
89584 + return TRUE;
89585 +}
89586 +
89587 +/*
89588 + ==========================================================================
89589 + Description:
89590 + Set Power Saving mode
89591 + Return:
89592 + TRUE if all parameters are OK, FALSE otherwise
89593 + ==========================================================================
89594 +*/
89595 +INT Set_PSMode_Proc(
89596 + IN PRTMP_ADAPTER pAdapter,
89597 + IN PUCHAR arg)
89598 +{
89599 + if (pAdapter->StaCfg.BssType == BSS_INFRA)
89600 + {
89601 + if ((strcmp(arg, "Max_PSP") == 0) ||
89602 + (strcmp(arg, "max_psp") == 0) ||
89603 + (strcmp(arg, "MAX_PSP") == 0))
89604 + {
89605 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
89606 + // to exclude certain situations.
89607 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
89608 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
89609 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
89610 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
89611 + pAdapter->StaCfg.DefaultListenCount = 5;
89612 +
89613 + }
89614 + else if ((strcmp(arg, "Fast_PSP") == 0) ||
89615 + (strcmp(arg, "fast_psp") == 0) ||
89616 + (strcmp(arg, "FAST_PSP") == 0))
89617 + {
89618 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
89619 + // to exclude certain situations.
89620 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
89621 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
89622 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
89623 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
89624 + pAdapter->StaCfg.DefaultListenCount = 3;
89625 + }
89626 + else if ((strcmp(arg, "Legacy_PSP") == 0) ||
89627 + (strcmp(arg, "legacy_psp") == 0) ||
89628 + (strcmp(arg, "LEGACY_PSP") == 0))
89629 + {
89630 + // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
89631 + // to exclude certain situations.
89632 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
89633 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
89634 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
89635 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
89636 + pAdapter->StaCfg.DefaultListenCount = 3;
89637 + }
89638 + else
89639 + {
89640 + //Default Ndis802_11PowerModeCAM
89641 + // clear PSM bit immediately
89642 + MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
89643 + OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
89644 + if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
89645 + pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
89646 + pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
89647 + }
89648 +
89649 + DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
89650 + }
89651 + else
89652 + return FALSE;
89653 +
89654 +
89655 + return TRUE;
89656 +}
89657 +
89658 +#ifdef WPA_SUPPLICANT_SUPPORT
89659 +/*
89660 + ==========================================================================
89661 + Description:
89662 + Set WpaSupport flag.
89663 + Value:
89664 + 0: Driver ignore wpa_supplicant.
89665 + 1: wpa_supplicant initiates scanning and AP selection.
89666 + 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
89667 + Return:
89668 + TRUE if all parameters are OK, FALSE otherwise
89669 + ==========================================================================
89670 +*/
89671 +INT Set_Wpa_Support(
89672 + IN PRTMP_ADAPTER pAd,
89673 + IN PUCHAR arg)
89674 +{
89675 +
89676 + if ( simple_strtol(arg, 0, 10) == 0)
89677 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
89678 + else if ( simple_strtol(arg, 0, 10) == 1)
89679 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
89680 + else if ( simple_strtol(arg, 0, 10) == 2)
89681 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
89682 + else
89683 + pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
89684 +
89685 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
89686 +
89687 + return TRUE;
89688 +}
89689 +#endif // WPA_SUPPLICANT_SUPPORT //
89690 +
89691 +#ifdef DBG
89692 +/*
89693 + ==========================================================================
89694 + Description:
89695 + Read / Write MAC
89696 + Arguments:
89697 + pAdapter Pointer to our adapter
89698 + wrq Pointer to the ioctl argument
89699 +
89700 + Return Value:
89701 + None
89702 +
89703 + Note:
89704 + Usage:
89705 + 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
89706 + 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
89707 + ==========================================================================
89708 +*/
89709 +VOID RTMPIoctlMAC(
89710 + IN PRTMP_ADAPTER pAdapter,
89711 + IN struct iwreq *wrq)
89712 +{
89713 + CHAR *this_char;
89714 + CHAR *value;
89715 + INT j = 0, k = 0;
89716 + CHAR msg[1024];
89717 + CHAR arg[255];
89718 + ULONG macAddr = 0;
89719 + UCHAR temp[16], temp2[16];
89720 + UINT32 macValue = 0;
89721 + INT Status;
89722 + BOOLEAN bIsPrintAllMAC = FALSE;
89723 +
89724 +
89725 + memset(msg, 0x00, 1024);
89726 + if (wrq->u.data.length > 1) //No parameters.
89727 + {
89728 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
89729 + sprintf(msg, "\n");
89730 +
89731 + //Parsing Read or Write
89732 + this_char = arg;
89733 + if (!*this_char)
89734 + goto next;
89735 +
89736 + if ((value = rtstrchr(this_char, '=')) != NULL)
89737 + *value++ = 0;
89738 +
89739 + if (!value || !*value)
89740 + { //Read
89741 + // Sanity check
89742 + if(strlen(this_char) > 4)
89743 + goto next;
89744 +
89745 + j = strlen(this_char);
89746 + while(j-- > 0)
89747 + {
89748 + if(this_char[j] > 'f' || this_char[j] < '0')
89749 + return;
89750 + }
89751 +
89752 + // Mac Addr
89753 + k = j = strlen(this_char);
89754 + while(j-- > 0)
89755 + {
89756 + this_char[4-k+j] = this_char[j];
89757 + }
89758 +
89759 + while(k < 4)
89760 + this_char[3-k++]='0';
89761 + this_char[4]='\0';
89762 +
89763 + if(strlen(this_char) == 4)
89764 + {
89765 + AtoH(this_char, temp, 2);
89766 + macAddr = *temp*256 + temp[1];
89767 + if (macAddr < 0xFFFF)
89768 + {
89769 + RTMP_IO_READ32(pAdapter, macAddr, &macValue);
89770 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
89771 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
89772 + }
89773 + else
89774 + {//Invalid parametes, so default printk all mac
89775 + bIsPrintAllMAC = TRUE;
89776 + goto next;
89777 + }
89778 + }
89779 + }
89780 + else
89781 + { //Write
89782 + memcpy(&temp2, value, strlen(value));
89783 + temp2[strlen(value)] = '\0';
89784 +
89785 + // Sanity check
89786 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
89787 + goto next;
89788 +
89789 + j = strlen(this_char);
89790 + while(j-- > 0)
89791 + {
89792 + if(this_char[j] > 'f' || this_char[j] < '0')
89793 + return;
89794 + }
89795 +
89796 + j = strlen(temp2);
89797 + while(j-- > 0)
89798 + {
89799 + if(temp2[j] > 'f' || temp2[j] < '0')
89800 + return;
89801 + }
89802 +
89803 + //MAC Addr
89804 + k = j = strlen(this_char);
89805 + while(j-- > 0)
89806 + {
89807 + this_char[4-k+j] = this_char[j];
89808 + }
89809 +
89810 + while(k < 4)
89811 + this_char[3-k++]='0';
89812 + this_char[4]='\0';
89813 +
89814 + //MAC value
89815 + k = j = strlen(temp2);
89816 + while(j-- > 0)
89817 + {
89818 + temp2[8-k+j] = temp2[j];
89819 + }
89820 +
89821 + while(k < 8)
89822 + temp2[7-k++]='0';
89823 + temp2[8]='\0';
89824 +
89825 + {
89826 + AtoH(this_char, temp, 2);
89827 + macAddr = *temp*256 + temp[1];
89828 +
89829 + AtoH(temp2, temp, 4);
89830 + macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
89831 +
89832 + // debug mode
89833 + if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
89834 + {
89835 + // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
89836 + if (macValue & 0x000000ff)
89837 + {
89838 + pAdapter->BbpTuning.bEnable = TRUE;
89839 + DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
89840 + }
89841 + else
89842 + {
89843 + UCHAR R66;
89844 + pAdapter->BbpTuning.bEnable = FALSE;
89845 + R66 = 0x26 + GET_LNA_GAIN(pAdapter);
89846 +#ifdef RALINK_ATE
89847 + if (ATE_ON(pAdapter))
89848 + {
89849 + ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
89850 + }
89851 + else
89852 +#endif // RALINK_ATE //
89853 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
89854 + DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
89855 + }
89856 + return;
89857 + }
89858 +
89859 + DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
89860 +
89861 + RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
89862 + sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
89863 + }
89864 + }
89865 + }
89866 + else
89867 + bIsPrintAllMAC = TRUE;
89868 +next:
89869 + if (bIsPrintAllMAC)
89870 + {
89871 + struct file *file_w;
89872 + PCHAR fileName = "MacDump.txt";
89873 + mm_segment_t orig_fs;
89874 +
89875 + orig_fs = get_fs();
89876 + set_fs(KERNEL_DS);
89877 +
89878 + // open file
89879 + file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
89880 + if (IS_ERR(file_w))
89881 + {
89882 + DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __FUNCTION__, -PTR_ERR(file_w), fileName));
89883 + }
89884 + else
89885 + {
89886 + if (file_w->f_op && file_w->f_op->write)
89887 + {
89888 + file_w->f_pos = 0;
89889 + macAddr = 0x1000;
89890 +
89891 + while (macAddr <= 0x1800)
89892 + {
89893 + RTMP_IO_READ32(pAdapter, macAddr, &macValue);
89894 + sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
89895 +
89896 + // write data to file
89897 + file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
89898 +
89899 + printk("%s", msg);
89900 + macAddr += 4;
89901 + }
89902 + sprintf(msg, "\nDump all MAC values to %s\n", fileName);
89903 + }
89904 + filp_close(file_w, NULL);
89905 + }
89906 + set_fs(orig_fs);
89907 + }
89908 + if(strlen(msg) == 1)
89909 + sprintf(msg+strlen(msg), "===>Error command format!");
89910 +
89911 + // Copy the information into the user buffer
89912 + wrq->u.data.length = strlen(msg);
89913 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
89914 +
89915 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
89916 +}
89917 +
89918 +/*
89919 + ==========================================================================
89920 + Description:
89921 + Read / Write E2PROM
89922 + Arguments:
89923 + pAdapter Pointer to our adapter
89924 + wrq Pointer to the ioctl argument
89925 +
89926 + Return Value:
89927 + None
89928 +
89929 + Note:
89930 + Usage:
89931 + 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
89932 + 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
89933 + ==========================================================================
89934 +*/
89935 +VOID RTMPIoctlE2PROM(
89936 + IN PRTMP_ADAPTER pAdapter,
89937 + IN struct iwreq *wrq)
89938 +{
89939 + CHAR *this_char;
89940 + CHAR *value;
89941 + INT j = 0, k = 0;
89942 + CHAR msg[1024];
89943 + CHAR arg[255];
89944 + USHORT eepAddr = 0;
89945 + UCHAR temp[16], temp2[16];
89946 + USHORT eepValue;
89947 + int Status;
89948 + BOOLEAN bIsPrintAllE2P = FALSE;
89949 +
89950 +
89951 + memset(msg, 0x00, 1024);
89952 + if (wrq->u.data.length > 1) //No parameters.
89953 + {
89954 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
89955 + sprintf(msg, "\n");
89956 +
89957 + //Parsing Read or Write
89958 + this_char = arg;
89959 +
89960 +
89961 + if (!*this_char)
89962 + goto next;
89963 +
89964 + if ((value = rtstrchr(this_char, '=')) != NULL)
89965 + *value++ = 0;
89966 +
89967 + if (!value || !*value)
89968 + { //Read
89969 +
89970 + // Sanity check
89971 + if(strlen(this_char) > 4)
89972 + goto next;
89973 +
89974 + j = strlen(this_char);
89975 + while(j-- > 0)
89976 + {
89977 + if(this_char[j] > 'f' || this_char[j] < '0')
89978 + return;
89979 + }
89980 +
89981 + // E2PROM addr
89982 + k = j = strlen(this_char);
89983 + while(j-- > 0)
89984 + {
89985 + this_char[4-k+j] = this_char[j];
89986 + }
89987 +
89988 + while(k < 4)
89989 + this_char[3-k++]='0';
89990 + this_char[4]='\0';
89991 +
89992 + if(strlen(this_char) == 4)
89993 + {
89994 + AtoH(this_char, temp, 2);
89995 + eepAddr = *temp*256 + temp[1];
89996 + if (eepAddr < 0xFFFF)
89997 + {
89998 + RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
89999 + sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
90000 + }
90001 + else
90002 + {//Invalid parametes, so default printk all bbp
90003 + bIsPrintAllE2P = TRUE;
90004 + goto next;
90005 + }
90006 + }
90007 + }
90008 + else
90009 + { //Write
90010 + memcpy(&temp2, value, strlen(value));
90011 + temp2[strlen(value)] = '\0';
90012 +
90013 + // Sanity check
90014 + if((strlen(this_char) > 4) || strlen(temp2) > 8)
90015 + goto next;
90016 +
90017 + j = strlen(this_char);
90018 + while(j-- > 0)
90019 + {
90020 + if(this_char[j] > 'f' || this_char[j] < '0')
90021 + return;
90022 + }
90023 + j = strlen(temp2);
90024 + while(j-- > 0)
90025 + {
90026 + if(temp2[j] > 'f' || temp2[j] < '0')
90027 + return;
90028 + }
90029 +
90030 + //MAC Addr
90031 + k = j = strlen(this_char);
90032 + while(j-- > 0)
90033 + {
90034 + this_char[4-k+j] = this_char[j];
90035 + }
90036 +
90037 + while(k < 4)
90038 + this_char[3-k++]='0';
90039 + this_char[4]='\0';
90040 +
90041 + //MAC value
90042 + k = j = strlen(temp2);
90043 + while(j-- > 0)
90044 + {
90045 + temp2[4-k+j] = temp2[j];
90046 + }
90047 +
90048 + while(k < 4)
90049 + temp2[3-k++]='0';
90050 + temp2[4]='\0';
90051 +
90052 + AtoH(this_char, temp, 2);
90053 + eepAddr = *temp*256 + temp[1];
90054 +
90055 + AtoH(temp2, temp, 2);
90056 + eepValue = *temp*256 + temp[1];
90057 +
90058 + RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
90059 + sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
90060 + }
90061 + }
90062 + else
90063 + bIsPrintAllE2P = TRUE;
90064 +next:
90065 + if (bIsPrintAllE2P)
90066 + {
90067 + struct file *file_w;
90068 + PCHAR fileName = "EEPROMDump.txt";
90069 + mm_segment_t orig_fs;
90070 +
90071 + orig_fs = get_fs();
90072 + set_fs(KERNEL_DS);
90073 +
90074 + // open file
90075 + file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
90076 + if (IS_ERR(file_w))
90077 + {
90078 + DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __FUNCTION__, -PTR_ERR(file_w), fileName));
90079 + }
90080 + else
90081 + {
90082 + if (file_w->f_op && file_w->f_op->write)
90083 + {
90084 + file_w->f_pos = 0;
90085 + eepAddr = 0x00;
90086 +
90087 + while (eepAddr <= 0xFE)
90088 + {
90089 + RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
90090 + sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
90091 +
90092 + // write data to file
90093 + file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
90094 +
90095 + printk("%s", msg);
90096 + eepAddr += 2;
90097 + }
90098 + sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
90099 + }
90100 + filp_close(file_w, NULL);
90101 + }
90102 + set_fs(orig_fs);
90103 + }
90104 + if(strlen(msg) == 1)
90105 + sprintf(msg+strlen(msg), "===>Error command format!");
90106 +
90107 +
90108 + // Copy the information into the user buffer
90109 + wrq->u.data.length = strlen(msg);
90110 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
90111 +
90112 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
90113 +}
90114 +#ifdef RT30xx
90115 +/*
90116 + ==========================================================================
90117 + Description:
90118 + Read / Write RF register
90119 +Arguments:
90120 + pAdapter Pointer to our adapter
90121 + wrq Pointer to the ioctl argument
90122 +
90123 + Return Value:
90124 + None
90125 +
90126 + Note:
90127 + Usage:
90128 + 1.) iwpriv ra0 rf ==> read all RF registers
90129 + 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
90130 + 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
90131 + ==========================================================================
90132 +*/
90133 +VOID RTMPIoctlRF(
90134 + IN PRTMP_ADAPTER pAdapter,
90135 + IN struct iwreq *wrq)
90136 +{
90137 + CHAR *this_char;
90138 + CHAR *value;
90139 + UCHAR regRF = 0;
90140 + CHAR msg[2048];
90141 + CHAR arg[255];
90142 + INT rfId;
90143 + LONG rfValue;
90144 + int Status;
90145 + BOOLEAN bIsPrintAllRF = FALSE;
90146 +
90147 +
90148 + memset(msg, 0x00, 2048);
90149 + if (wrq->u.data.length > 1) //No parameters.
90150 + {
90151 + Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
90152 + sprintf(msg, "\n");
90153 +
90154 + //Parsing Read or Write
90155 + this_char = arg;
90156 + if (!*this_char)
90157 + goto next;
90158 +
90159 + if ((value = strchr(this_char, '=')) != NULL)
90160 + *value++ = 0;
90161 +
90162 + if (!value || !*value)
90163 + { //Read
90164 + if (sscanf(this_char, "%d", &(rfId)) == 1)
90165 + {
90166 + if (rfId <= 31)
90167 + {
90168 + // In RT2860 ATE mode, we do not load 8051 firmware.
90169 + //We must access RF directly.
90170 + // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
90171 +#ifdef RALINK_ATE
90172 + if (ATE_ON(pAdapter))
90173 + {
90174 + ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, &regRF);
90175 + }
90176 + else
90177 +#endif // RALINK_ATE //
90178 + // according to Andy, Gary, David require.
90179 + // the command rf shall read rf register directly for dubug.
90180 + // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
90181 + RT30xxReadRFRegister(pAdapter, rfId, &regRF);
90182 +
90183 + sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
90184 + }
90185 + else
90186 + {//Invalid parametes, so default printk all RF
90187 + bIsPrintAllRF = TRUE;
90188 + goto next;
90189 + }
90190 + }
90191 + else
90192 + { //Invalid parametes, so default printk all RF
90193 + bIsPrintAllRF = TRUE;
90194 + goto next;
90195 + }
90196 + }
90197 + else
90198 + { //Write
90199 + if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
90200 + {
90201 + if (rfId <= 31)
90202 + {
90203 + // In RT2860 ATE mode, we do not load 8051 firmware.
90204 + // We should access RF registers directly.
90205 + // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
90206 +#ifdef RALINK_ATE
90207 + if (ATE_ON(pAdapter))
90208 + {
90209 + ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, &regRF);
90210 + ATE_RF_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
90211 + //Read it back for showing
90212 + ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, &regRF);
90213 + sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
90214 + }
90215 + else
90216 +#endif // RALINK_ATE //
90217 + {
90218 + // according to Andy, Gary, David require.
90219 + // the command RF shall read/write RF register directly for dubug.
90220 + //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
90221 + //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
90222 + RT30xxReadRFRegister(pAdapter, rfId, &regRF);
90223 + RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
90224 + //Read it back for showing
90225 + //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
90226 + RT30xxReadRFRegister(pAdapter, rfId, &regRF);
90227 + sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
90228 + }
90229 + }
90230 + else
90231 + {//Invalid parametes, so default printk all RF
90232 + bIsPrintAllRF = TRUE;
90233 + }
90234 + }
90235 + else
90236 + { //Invalid parametes, so default printk all RF
90237 + bIsPrintAllRF = TRUE;
90238 + }
90239 + }
90240 + }
90241 + else
90242 + bIsPrintAllRF = TRUE;
90243 +next:
90244 + if (bIsPrintAllRF)
90245 + {
90246 + memset(msg, 0x00, 2048);
90247 + sprintf(msg, "\n");
90248 + for (rfId = 0; rfId <= 31; rfId++)
90249 + {
90250 + // In RT2860 ATE mode, we do not load 8051 firmware.
90251 + // We should access RF registers directly.
90252 + // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
90253 +#ifdef RALINK_ATE
90254 + if (ATE_ON(pAdapter))
90255 + {
90256 + ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, &regRF);
90257 + }
90258 + else
90259 +#endif // RALINK_ATE //
90260 +
90261 + // according to Andy, Gary, David require.
90262 + // the command RF shall read/write RF register directly for dubug.
90263 + RT30xxReadRFRegister(pAdapter, rfId, &regRF);
90264 + sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
90265 + }
90266 + // Copy the information into the user buffer
90267 + DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
90268 + wrq->u.data.length = strlen(msg);
90269 + if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
90270 + {
90271 + DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __FUNCTION__));
90272 + }
90273 + }
90274 + else
90275 + {
90276 + if(strlen(msg) == 1)
90277 + sprintf(msg+strlen(msg), "===>Error command format!");
90278 +
90279 + DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
90280 + // Copy the information into the user buffer
90281 + DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
90282 +
90283 + // Copy the information into the user buffer
90284 + wrq->u.data.length = strlen(msg);
90285 + Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
90286 + }
90287 +
90288 + DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
90289 +}
90290 +#endif // RT30xx //
90291 +#endif // DBG //
90292 +
90293 +
90294 +
90295 +
90296 +INT Set_TGnWifiTest_Proc(
90297 + IN PRTMP_ADAPTER pAd,
90298 + IN PUCHAR arg)
90299 +{
90300 + if (simple_strtol(arg, 0, 10) == 0)
90301 + pAd->StaCfg.bTGnWifiTest = FALSE;
90302 + else
90303 + pAd->StaCfg.bTGnWifiTest = TRUE;
90304 +
90305 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
90306 + return TRUE;
90307 +}
90308 +
90309 +INT Set_LongRetryLimit_Proc(
90310 + IN PRTMP_ADAPTER pAdapter,
90311 + IN PUCHAR arg)
90312 +{
90313 + TX_RTY_CFG_STRUC tx_rty_cfg;
90314 + UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
90315 +
90316 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
90317 + tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
90318 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
90319 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
90320 + return TRUE;
90321 +}
90322 +
90323 +INT Set_ShortRetryLimit_Proc(
90324 + IN PRTMP_ADAPTER pAdapter,
90325 + IN PUCHAR arg)
90326 +{
90327 + TX_RTY_CFG_STRUC tx_rty_cfg;
90328 + UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
90329 +
90330 + RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
90331 + tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
90332 + RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
90333 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
90334 + return TRUE;
90335 +}
90336 +
90337 +#ifdef EXT_BUILD_CHANNEL_LIST
90338 +INT Set_Ieee80211dClientMode_Proc(
90339 + IN PRTMP_ADAPTER pAdapter,
90340 + IN PUCHAR arg)
90341 +{
90342 + if (simple_strtol(arg, 0, 10) == 0)
90343 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
90344 + else if (simple_strtol(arg, 0, 10) == 1)
90345 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
90346 + else if (simple_strtol(arg, 0, 10) == 2)
90347 + pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
90348 + else
90349 + return FALSE;
90350 +
90351 + DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
90352 + return TRUE;
90353 +}
90354 +#endif // EXT_BUILD_CHANNEL_LIST //
90355 +
90356 +#ifdef CARRIER_DETECTION_SUPPORT
90357 +INT Set_CarrierDetect_Proc(
90358 + IN PRTMP_ADAPTER pAd,
90359 + IN PUCHAR arg)
90360 +{
90361 + if (simple_strtol(arg, 0, 10) == 0)
90362 + pAd->CommonCfg.CarrierDetect.Enable = FALSE;
90363 + else
90364 + pAd->CommonCfg.CarrierDetect.Enable = TRUE;
90365 +
90366 + DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
90367 + return TRUE;
90368 +}
90369 +#endif // CARRIER_DETECTION_SUPPORT //
90370 +
90371 --- /dev/null
90372 +++ b/drivers/staging/rt3070/sta/rtmp_data.c
90373 @@ -0,0 +1,2637 @@
90374 +/*
90375 + *************************************************************************
90376 + * Ralink Tech Inc.
90377 + * 5F., No.36, Taiyuan St., Jhubei City,
90378 + * Hsinchu County 302,
90379 + * Taiwan, R.O.C.
90380 + *
90381 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
90382 + *
90383 + * This program is free software; you can redistribute it and/or modify *
90384 + * it under the terms of the GNU General Public License as published by *
90385 + * the Free Software Foundation; either version 2 of the License, or *
90386 + * (at your option) any later version. *
90387 + * *
90388 + * This program is distributed in the hope that it will be useful, *
90389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
90390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
90391 + * GNU General Public License for more details. *
90392 + * *
90393 + * You should have received a copy of the GNU General Public License *
90394 + * along with this program; if not, write to the *
90395 + * Free Software Foundation, Inc., *
90396 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
90397 + * *
90398 + *************************************************************************
90399 +
90400 + Module Name:
90401 + rtmp_data.c
90402 +
90403 + Abstract:
90404 + Data path subroutines
90405 +
90406 + Revision History:
90407 + Who When What
90408 + -------- ---------- ----------------------------------------------
90409 + John Aug/17/04 major modification for RT2561/2661
90410 + Jan Lee Mar/17/06 major modification for RT2860 New Ring Design
90411 +*/
90412 +#include "../rt_config.h"
90413 +
90414 +
90415 +
90416 +VOID STARxEAPOLFrameIndicate(
90417 + IN PRTMP_ADAPTER pAd,
90418 + IN MAC_TABLE_ENTRY *pEntry,
90419 + IN RX_BLK *pRxBlk,
90420 + IN UCHAR FromWhichBSSID)
90421 +{
90422 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
90423 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
90424 + UCHAR *pTmpBuf;
90425 +
90426 +
90427 +#ifdef WPA_SUPPLICANT_SUPPORT
90428 + if (pAd->StaCfg.WpaSupplicantUP)
90429 + {
90430 + // All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon)
90431 + // TBD : process fragmented EAPol frames
90432 + {
90433 + // In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable
90434 + if ( pAd->StaCfg.IEEE8021X == TRUE &&
90435 + (EAP_CODE_SUCCESS == WpaCheckEapCode(pAd, pRxBlk->pData, pRxBlk->DataSize, LENGTH_802_1_H)))
90436 + {
90437 + PUCHAR Key;
90438 + UCHAR CipherAlg;
90439 + int idx = 0;
90440 +
90441 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("Receive EAP-SUCCESS Packet\n"));
90442 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
90443 + STA_PORT_SECURED(pAd);
90444 +
90445 + if (pAd->StaCfg.IEEE8021x_required_keys == FALSE)
90446 + {
90447 + idx = pAd->StaCfg.DesireSharedKeyId;
90448 + CipherAlg = pAd->StaCfg.DesireSharedKey[idx].CipherAlg;
90449 + Key = pAd->StaCfg.DesireSharedKey[idx].Key;
90450 +
90451 + if (pAd->StaCfg.DesireSharedKey[idx].KeyLen > 0)
90452 + {
90453 +#ifdef RT2870
90454 + union
90455 + {
90456 + char buf[sizeof(NDIS_802_11_WEP)+MAX_LEN_OF_KEY- 1];
90457 + NDIS_802_11_WEP keyinfo;
90458 + } WepKey;
90459 + int len;
90460 +
90461 +
90462 + NdisZeroMemory(&WepKey, sizeof(WepKey));
90463 + len =pAd->StaCfg.DesireSharedKey[idx].KeyLen;
90464 +
90465 + NdisMoveMemory(WepKey.keyinfo.KeyMaterial,
90466 + pAd->StaCfg.DesireSharedKey[idx].Key,
90467 + pAd->StaCfg.DesireSharedKey[idx].KeyLen);
90468 +
90469 + WepKey.keyinfo.KeyIndex = 0x80000000 + idx;
90470 + WepKey.keyinfo.KeyLength = len;
90471 + pAd->SharedKey[BSS0][idx].KeyLen =(UCHAR) (len <= 5 ? 5 : 13);
90472 +
90473 + pAd->IndicateMediaState = NdisMediaStateConnected;
90474 + pAd->ExtraInfo = GENERAL_LINK_UP;
90475 + // need to enqueue cmd to thread
90476 + RTUSBEnqueueCmdFromNdis(pAd, OID_802_11_ADD_WEP, TRUE, &WepKey, sizeof(WepKey.keyinfo) + len - 1);
90477 +#endif // RT2870 //
90478 + // For Preventing ShardKey Table is cleared by remove key procedure.
90479 + pAd->SharedKey[BSS0][idx].CipherAlg = CipherAlg;
90480 + pAd->SharedKey[BSS0][idx].KeyLen = pAd->StaCfg.DesireSharedKey[idx].KeyLen;
90481 + NdisMoveMemory(pAd->SharedKey[BSS0][idx].Key,
90482 + pAd->StaCfg.DesireSharedKey[idx].Key,
90483 + pAd->StaCfg.DesireSharedKey[idx].KeyLen);
90484 + }
90485 + }
90486 + }
90487 +
90488 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
90489 + return;
90490 + }
90491 + }
90492 + else
90493 +#endif // WPA_SUPPLICANT_SUPPORT //
90494 + {
90495 + // Special DATA frame that has to pass to MLME
90496 + // 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process
90497 + // 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process
90498 + {
90499 + pTmpBuf = pRxBlk->pData - LENGTH_802_11;
90500 + NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11);
90501 + REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pTmpBuf, pRxBlk->DataSize + LENGTH_802_11, pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
90502 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! report EAPOL/AIRONET DATA to MLME (len=%d) !!!\n", pRxBlk->DataSize));
90503 + }
90504 + }
90505 +
90506 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
90507 + return;
90508 +
90509 +}
90510 +
90511 +VOID STARxDataFrameAnnounce(
90512 + IN PRTMP_ADAPTER pAd,
90513 + IN MAC_TABLE_ENTRY *pEntry,
90514 + IN RX_BLK *pRxBlk,
90515 + IN UCHAR FromWhichBSSID)
90516 +{
90517 +
90518 + // non-EAP frame
90519 + if (!RTMPCheckWPAframe(pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID))
90520 + {
90521 +
90522 + {
90523 + // drop all non-EAP DATA frame before
90524 + // this client's Port-Access-Control is secured
90525 + if (pRxBlk->pHeader->FC.Wep)
90526 + {
90527 + // unsupported cipher suite
90528 + if (pAd->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
90529 + {
90530 + // release packet
90531 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
90532 + return;
90533 + }
90534 + }
90535 + else
90536 + {
90537 + // encryption in-use but receive a non-EAPOL clear text frame, drop it
90538 + if ((pAd->StaCfg.WepStatus != Ndis802_11EncryptionDisabled) &&
90539 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
90540 + {
90541 + // release packet
90542 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
90543 + return;
90544 + }
90545 + }
90546 + }
90547 + RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP);
90548 + if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK))
90549 + {
90550 + // Normal legacy, AMPDU or AMSDU
90551 + CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, FromWhichBSSID);
90552 +
90553 + }
90554 + else
90555 + {
90556 + // ARALINK
90557 + CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
90558 + }
90559 +#ifdef QOS_DLS_SUPPORT
90560 + RX_BLK_CLEAR_FLAG(pRxBlk, fRX_DLS);
90561 +#endif // QOS_DLS_SUPPORT //
90562 + }
90563 + else
90564 + {
90565 + RX_BLK_SET_FLAG(pRxBlk, fRX_EAP);
90566 +#ifdef DOT11_N_SUPPORT
90567 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))
90568 + {
90569 + Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
90570 + }
90571 + else
90572 +#endif // DOT11_N_SUPPORT //
90573 + {
90574 + // Determin the destination of the EAP frame
90575 + // to WPA state machine or upper layer
90576 + STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
90577 + }
90578 + }
90579 +}
90580 +
90581 +
90582 +// For TKIP frame, calculate the MIC value
90583 +BOOLEAN STACheckTkipMICValue(
90584 + IN PRTMP_ADAPTER pAd,
90585 + IN MAC_TABLE_ENTRY *pEntry,
90586 + IN RX_BLK *pRxBlk)
90587 +{
90588 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
90589 + UCHAR *pData = pRxBlk->pData;
90590 + USHORT DataSize = pRxBlk->DataSize;
90591 + UCHAR UserPriority = pRxBlk->UserPriority;
90592 + PCIPHER_KEY pWpaKey;
90593 + UCHAR *pDA, *pSA;
90594 +
90595 + pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex];
90596 +
90597 + pDA = pHeader->Addr1;
90598 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA))
90599 + {
90600 + pSA = pHeader->Addr3;
90601 + }
90602 + else
90603 + {
90604 + pSA = pHeader->Addr2;
90605 + }
90606 +
90607 + if (RTMPTkipCompareMICValue(pAd,
90608 + pData,
90609 + pDA,
90610 + pSA,
90611 + pWpaKey->RxMic,
90612 + UserPriority,
90613 + DataSize) == FALSE)
90614 + {
90615 + DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error 2\n"));
90616 +
90617 +#ifdef WPA_SUPPLICANT_SUPPORT
90618 + if (pAd->StaCfg.WpaSupplicantUP)
90619 + {
90620 + WpaSendMicFailureToWpaSupplicant(pAd, (pWpaKey->Type == PAIRWISEKEY) ? TRUE : FALSE);
90621 + }
90622 + else
90623 +#endif // WPA_SUPPLICANT_SUPPORT //
90624 + {
90625 + RTMPReportMicError(pAd, pWpaKey);
90626 + }
90627 +
90628 + // release packet
90629 + RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
90630 + return FALSE;
90631 + }
90632 +
90633 + return TRUE;
90634 +}
90635 +
90636 +
90637 +//
90638 +// All Rx routines use RX_BLK structure to hande rx events
90639 +// It is very important to build pRxBlk attributes
90640 +// 1. pHeader pointer to 802.11 Header
90641 +// 2. pData pointer to payload including LLC (just skip Header)
90642 +// 3. set payload size including LLC to DataSize
90643 +// 4. set some flags with RX_BLK_SET_FLAG()
90644 +//
90645 +VOID STAHandleRxDataFrame(
90646 + IN PRTMP_ADAPTER pAd,
90647 + IN RX_BLK *pRxBlk)
90648 +{
90649 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
90650 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
90651 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
90652 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
90653 + BOOLEAN bFragment = FALSE;
90654 + MAC_TABLE_ENTRY *pEntry = NULL;
90655 + UCHAR FromWhichBSSID = BSS0;
90656 + UCHAR UserPriority = 0;
90657 +
90658 + {
90659 + // before LINK UP, all DATA frames are rejected
90660 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
90661 + {
90662 + // release packet
90663 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90664 + return;
90665 + }
90666 +
90667 +#ifdef QOS_DLS_SUPPORT
90668 + //if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
90669 + if (RTMPRcvFrameDLSCheck(pAd, pHeader, pRxWI->MPDUtotalByteCount, pRxD))
90670 + {
90671 + return;
90672 + }
90673 +#endif // QOS_DLS_SUPPORT //
90674 +
90675 + // Drop not my BSS frames
90676 + if (pRxD->MyBss == 0)
90677 + {
90678 + {
90679 + // release packet
90680 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90681 + return;
90682 + }
90683 + }
90684 +
90685 + pAd->RalinkCounters.RxCountSinceLastNULL++;
90686 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable && (pHeader->FC.SubType & 0x08))
90687 + {
90688 + UCHAR *pData;
90689 + DBGPRINT(RT_DEBUG_TRACE,("bAPSDCapable\n"));
90690 +
90691 + // Qos bit 4
90692 + pData = (PUCHAR)pHeader + LENGTH_802_11;
90693 + if ((*pData >> 4) & 0x01)
90694 + {
90695 + DBGPRINT(RT_DEBUG_TRACE,("RxDone- Rcv EOSP frame, driver may fall into sleep\n"));
90696 + pAd->CommonCfg.bInServicePeriod = FALSE;
90697 +
90698 + // Force driver to fall into sleep mode when rcv EOSP frame
90699 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
90700 + {
90701 + USHORT TbttNumToNextWakeUp;
90702 + USHORT NextDtim = pAd->StaCfg.DtimPeriod;
90703 + ULONG Now;
90704 +
90705 + NdisGetSystemUpTime(&Now);
90706 + NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod;
90707 +
90708 + TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
90709 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
90710 + TbttNumToNextWakeUp = NextDtim;
90711 +
90712 + MlmeSetPsmBit(pAd, PWR_SAVE);
90713 + // if WMM-APSD is failed, try to disable following line
90714 + AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
90715 + }
90716 + }
90717 +
90718 + if ((pHeader->FC.MoreData) && (pAd->CommonCfg.bInServicePeriod))
90719 + {
90720 + DBGPRINT(RT_DEBUG_TRACE,("Sending another trigger frame when More Data bit is set to 1\n"));
90721 + }
90722 + }
90723 +
90724 + // Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame
90725 + if ((pHeader->FC.SubType & 0x04)) // bit 2 : no DATA
90726 + {
90727 + // release packet
90728 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90729 + return;
90730 + }
90731 +
90732 + // Drop not my BSS frame (we can not only check the MyBss bit in RxD)
90733 +#ifdef QOS_DLS_SUPPORT
90734 + if (!pAd->CommonCfg.bDLSCapable)
90735 + {
90736 +#endif // QOS_DLS_SUPPORT //
90737 + if (INFRA_ON(pAd))
90738 + {
90739 + // Infrastructure mode, check address 2 for BSSID
90740 + if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6))
90741 + {
90742 + // Receive frame not my BSSID
90743 + // release packet
90744 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90745 + return;
90746 + }
90747 + }
90748 + else // Ad-Hoc mode or Not associated
90749 + {
90750 + // Ad-Hoc mode, check address 3 for BSSID
90751 + if (!RTMPEqualMemory(&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6))
90752 + {
90753 + // Receive frame not my BSSID
90754 + // release packet
90755 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90756 + return;
90757 + }
90758 + }
90759 +#ifdef QOS_DLS_SUPPORT
90760 + }
90761 +#endif // QOS_DLS_SUPPORT //
90762 +
90763 + //
90764 + // find pEntry
90765 + //
90766 + if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)
90767 + {
90768 + pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
90769 + }
90770 + else
90771 + {
90772 + // 1. release packet if infra mode
90773 + // 2. new a pEntry if ad-hoc mode
90774 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90775 + return;
90776 + }
90777 +
90778 + // infra or ad-hoc
90779 + if (INFRA_ON(pAd))
90780 + {
90781 + RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);
90782 +#ifdef QOS_DLS_SUPPORT
90783 + if ((pHeader->FC.FrDs == 0) && (pHeader->FC.ToDs == 0))
90784 + RX_BLK_SET_FLAG(pRxBlk, fRX_DLS);
90785 + else
90786 +#endif // QOS_DLS_SUPPORT //
90787 + ASSERT(pRxWI->WirelessCliID == BSSID_WCID);
90788 + }
90789 +
90790 + // check Atheros Client
90791 + if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) && (pHeader->FC.Retry ))
90792 + {
90793 + pEntry->bIAmBadAtheros = TRUE;
90794 + pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE;
90795 + pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE;
90796 + if (!STA_AES_ON(pAd))
90797 + {
90798 + AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, FALSE);
90799 + }
90800 + }
90801 + }
90802 +
90803 + pRxBlk->pData = (UCHAR *)pHeader;
90804 +
90805 + //
90806 + // update RxBlk->pData, DataSize
90807 + // 802.11 Header, QOS, HTC, Hw Padding
90808 + //
90809 +
90810 + // 1. skip 802.11 HEADER
90811 + {
90812 + pRxBlk->pData += LENGTH_802_11;
90813 + pRxBlk->DataSize -= LENGTH_802_11;
90814 + }
90815 +
90816 + // 2. QOS
90817 + if (pHeader->FC.SubType & 0x08)
90818 + {
90819 + RX_BLK_SET_FLAG(pRxBlk, fRX_QOS);
90820 + UserPriority = *(pRxBlk->pData) & 0x0f;
90821 + // bit 7 in QoS Control field signals the HT A-MSDU format
90822 + if ((*pRxBlk->pData) & 0x80)
90823 + {
90824 + RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU);
90825 + }
90826 +
90827 + // skip QOS contorl field
90828 + pRxBlk->pData += 2;
90829 + pRxBlk->DataSize -=2;
90830 + }
90831 + pRxBlk->UserPriority = UserPriority;
90832 +
90833 + // 3. Order bit: A-Ralink or HTC+
90834 + if (pHeader->FC.Order)
90835 + {
90836 +#ifdef AGGREGATION_SUPPORT
90837 + if ((pRxWI->PHYMODE <= MODE_OFDM) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)))
90838 + {
90839 + RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK);
90840 + }
90841 + else
90842 +#endif
90843 + {
90844 +#ifdef DOT11_N_SUPPORT
90845 + RX_BLK_SET_FLAG(pRxBlk, fRX_HTC);
90846 + // skip HTC contorl field
90847 + pRxBlk->pData += 4;
90848 + pRxBlk->DataSize -= 4;
90849 +#endif // DOT11_N_SUPPORT //
90850 + }
90851 + }
90852 +
90853 + // 4. skip HW padding
90854 + if (pRxD->L2PAD)
90855 + {
90856 + // just move pData pointer
90857 + // because DataSize excluding HW padding
90858 + RX_BLK_SET_FLAG(pRxBlk, fRX_PAD);
90859 + pRxBlk->pData += 2;
90860 + }
90861 +
90862 +#ifdef DOT11_N_SUPPORT
90863 + if (pRxD->BA)
90864 + {
90865 + RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU);
90866 + }
90867 +#endif // DOT11_N_SUPPORT //
90868 +
90869 +
90870 + //
90871 + // Case I Process Broadcast & Multicast data frame
90872 + //
90873 + if (pRxD->Bcast || pRxD->Mcast)
90874 + {
90875 + INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);
90876 +
90877 + // Drop Mcast/Bcast frame with fragment bit on
90878 + if (pHeader->FC.MoreFrag)
90879 + {
90880 + // release packet
90881 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90882 + return;
90883 + }
90884 +
90885 + // Filter out Bcast frame which AP relayed for us
90886 + if (pHeader->FC.FrDs && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress))
90887 + {
90888 + // release packet
90889 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90890 + return;
90891 + }
90892 +
90893 + Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
90894 + return;
90895 + }
90896 + else if (pRxD->U2M)
90897 + {
90898 + pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
90899 +
90900 +
90901 +#ifdef QOS_DLS_SUPPORT
90902 + if (RX_BLK_TEST_FLAG(pRxBlk, fRX_DLS))
90903 + {
90904 + MAC_TABLE_ENTRY *pDlsEntry = NULL;
90905 +
90906 + pDlsEntry = DlsEntryTableLookupByWcid(pAd, pRxWI->WirelessCliID, pHeader->Addr2, TRUE);
90907 + if(pDlsEntry)
90908 + Update_Rssi_Sample(pAd, &pDlsEntry->RssiSample, pRxWI);
90909 + }
90910 + else
90911 +#endif // QOS_DLS_SUPPORT //
90912 + if (ADHOC_ON(pAd))
90913 + {
90914 + pEntry = MacTableLookup(pAd, pHeader->Addr2);
90915 + if (pEntry)
90916 + Update_Rssi_Sample(pAd, &pEntry->RssiSample, pRxWI);
90917 + }
90918 +
90919 +
90920 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
90921 +
90922 + pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
90923 + pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
90924 +
90925 + pAd->RalinkCounters.OneSecRxOkDataCnt++;
90926 +
90927 +
90928 + if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0)))
90929 + {
90930 + // re-assemble the fragmented packets
90931 + // return complete frame (pRxPacket) or NULL
90932 + bFragment = TRUE;
90933 + pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk);
90934 + }
90935 +
90936 + if (pRxPacket)
90937 + {
90938 + pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
90939 +
90940 + // process complete frame
90941 + if (bFragment && (pRxD->Decrypted) && (pEntry->WepStatus == Ndis802_11Encryption2Enabled))
90942 + {
90943 + // Minus MIC length
90944 + pRxBlk->DataSize -= 8;
90945 +
90946 + // For TKIP frame, calculate the MIC value
90947 + if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == FALSE)
90948 + {
90949 + return;
90950 + }
90951 + }
90952 +
90953 + STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, FromWhichBSSID);
90954 + return;
90955 + }
90956 + else
90957 + {
90958 + // just return
90959 + // because RTMPDeFragmentDataFrame() will release rx packet,
90960 + // if packet is fragmented
90961 + return;
90962 + }
90963 + }
90964 +
90965 + ASSERT(0);
90966 + // release packet
90967 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
90968 +}
90969 +
90970 +VOID STAHandleRxMgmtFrame(
90971 + IN PRTMP_ADAPTER pAd,
90972 + IN RX_BLK *pRxBlk)
90973 +{
90974 + PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
90975 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
90976 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
90977 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
90978 +
90979 + do
90980 + {
90981 +
90982 + // We should collect RSSI not only U2M data but also my beacon
90983 + if ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2))
90984 + && (pAd->RxAnt.EvaluatePeriod == 0))
90985 + {
90986 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
90987 +
90988 + pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);
90989 + pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);
90990 + }
90991 +
90992 +#ifdef RT30xx
90993 + // collect rssi information for antenna diversity
90994 + if (pAd->NicConfig2.field.AntDiversity)
90995 + {
90996 + if ((pRxD->U2M) || ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2))))
90997 + {
90998 + COLLECT_RX_ANTENNA_AVERAGE_RSSI(pAd, ConvertToRssi(pAd, (UCHAR)pRxWI->RSSI0, RSSI_0), 0); //Note: RSSI2 not used on RT73
90999 + pAd->StaCfg.NumOfAvgRssiSample ++;
91000 + }
91001 + }
91002 +#endif // RT30xx //
91003 +
91004 + // First check the size, it MUST not exceed the mlme queue size
91005 + if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE)
91006 + {
91007 + DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount));
91008 + break;
91009 + }
91010 +
91011 + REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, pRxWI->MPDUtotalByteCount,
91012 + pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);
91013 + } while (FALSE);
91014 +
91015 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
91016 +}
91017 +
91018 +VOID STAHandleRxControlFrame(
91019 + IN PRTMP_ADAPTER pAd,
91020 + IN RX_BLK *pRxBlk)
91021 +{
91022 +#ifdef DOT11_N_SUPPORT
91023 + PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
91024 +#endif // DOT11_N_SUPPORT //
91025 + PHEADER_802_11 pHeader = pRxBlk->pHeader;
91026 + PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;
91027 +
91028 + switch (pHeader->FC.SubType)
91029 + {
91030 + case SUBTYPE_BLOCK_ACK_REQ:
91031 +#ifdef DOT11_N_SUPPORT
91032 + {
91033 + CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, (pRxWI->MPDUtotalByteCount), (PFRAME_BA_REQ)pHeader);
91034 + }
91035 + break;
91036 +#endif // DOT11_N_SUPPORT //
91037 + case SUBTYPE_BLOCK_ACK:
91038 + case SUBTYPE_ACK:
91039 + default:
91040 + break;
91041 + }
91042 +
91043 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
91044 +}
91045 +
91046 +
91047 +/*
91048 + ========================================================================
91049 +
91050 + Routine Description:
91051 + Process RxDone interrupt, running in DPC level
91052 +
91053 + Arguments:
91054 + pAd Pointer to our adapter
91055 +
91056 + Return Value:
91057 + None
91058 +
91059 + IRQL = DISPATCH_LEVEL
91060 +
91061 + Note:
91062 + This routine has to maintain Rx ring read pointer.
91063 + Need to consider QOS DATA format when converting to 802.3
91064 + ========================================================================
91065 +*/
91066 +BOOLEAN STARxDoneInterruptHandle(
91067 + IN PRTMP_ADAPTER pAd,
91068 + IN BOOLEAN argc)
91069 +{
91070 + NDIS_STATUS Status;
91071 + UINT32 RxProcessed, RxPending;
91072 + BOOLEAN bReschedule = FALSE;
91073 + RT28XX_RXD_STRUC *pRxD;
91074 + UCHAR *pData;
91075 + PRXWI_STRUC pRxWI;
91076 + PNDIS_PACKET pRxPacket;
91077 + PHEADER_802_11 pHeader;
91078 + RX_BLK RxCell;
91079 +
91080 + RxProcessed = RxPending = 0;
91081 +
91082 + // process whole rx ring
91083 + while (1)
91084 + {
91085 +
91086 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF |
91087 + fRTMP_ADAPTER_RESET_IN_PROGRESS |
91088 + fRTMP_ADAPTER_HALT_IN_PROGRESS |
91089 + fRTMP_ADAPTER_NIC_NOT_EXIST) ||
91090 + !RTMP_TEST_FLAG(pAd,fRTMP_ADAPTER_START_UP))
91091 + {
91092 + break;
91093 + }
91094 +
91095 +
91096 + RxProcessed ++; // test
91097 +
91098 + // 1. allocate a new data packet into rx ring to replace received packet
91099 + // then processing the received packet
91100 + // 2. the callee must take charge of release of packet
91101 + // 3. As far as driver is concerned ,
91102 + // the rx packet must
91103 + // a. be indicated to upper layer or
91104 + // b. be released if it is discarded
91105 + pRxPacket = GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, &RxPending);
91106 + if (pRxPacket == NULL)
91107 + {
91108 + // no more packet to process
91109 + break;
91110 + }
91111 +
91112 + // get rx ring descriptor
91113 + pRxD = &(RxCell.RxD);
91114 + // get rx data buffer
91115 + pData = GET_OS_PKT_DATAPTR(pRxPacket);
91116 + pRxWI = (PRXWI_STRUC) pData;
91117 + pHeader = (PHEADER_802_11) (pData+RXWI_SIZE) ;
91118 +
91119 +#ifdef RT_BIG_ENDIAN
91120 + RTMPFrameEndianChange(pAd, (PUCHAR)pHeader, DIR_READ, TRUE);
91121 + RTMPWIEndianChange((PUCHAR)pRxWI, TYPE_RXWI);
91122 +#endif
91123 +
91124 + // build RxCell
91125 + RxCell.pRxWI = pRxWI;
91126 + RxCell.pHeader = pHeader;
91127 + RxCell.pRxPacket = pRxPacket;
91128 + RxCell.pData = (UCHAR *) pHeader;
91129 + RxCell.DataSize = pRxWI->MPDUtotalByteCount;
91130 + RxCell.Flags = 0;
91131 +
91132 + // Increase Total receive byte counter after real data received no mater any error or not
91133 + pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount;
91134 + pAd->RalinkCounters.RxCount ++;
91135 +
91136 + INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);
91137 +
91138 + if (pRxWI->MPDUtotalByteCount < 14)
91139 + Status = NDIS_STATUS_FAILURE;
91140 +
91141 + if (MONITOR_ON(pAd))
91142 + {
91143 + send_monitor_packets(pAd, &RxCell);
91144 + break;
91145 + }
91146 + /* RT2870 invokes STARxDoneInterruptHandle() in rtusb_bulk.c */
91147 +#ifdef RALINK_ATE
91148 + if (ATE_ON(pAd))
91149 + {
91150 + pAd->ate.RxCntPerSec++;
91151 + ATESampleRssi(pAd, pRxWI);
91152 +#ifdef RALINK_28xx_QA
91153 + if (pAd->ate.bQARxStart == TRUE)
91154 + {
91155 + /* (*pRxD) has been swapped in GetPacketFromRxRing() */
91156 + ATE_QA_Statistics(pAd, pRxWI, pRxD, pHeader);
91157 + }
91158 +#endif // RALINK_28xx_QA //
91159 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
91160 + continue;
91161 + }
91162 +#endif // RALINK_ATE //
91163 +
91164 + // Check for all RxD errors
91165 + Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);
91166 +
91167 + // Handle the received frame
91168 + if (Status == NDIS_STATUS_SUCCESS)
91169 + {
91170 + switch (pHeader->FC.Type)
91171 + {
91172 + // CASE I, receive a DATA frame
91173 + case BTYPE_DATA:
91174 + {
91175 + // process DATA frame
91176 + STAHandleRxDataFrame(pAd, &RxCell);
91177 + }
91178 + break;
91179 + // CASE II, receive a MGMT frame
91180 + case BTYPE_MGMT:
91181 + {
91182 + STAHandleRxMgmtFrame(pAd, &RxCell);
91183 + }
91184 + break;
91185 + // CASE III. receive a CNTL frame
91186 + case BTYPE_CNTL:
91187 + {
91188 + STAHandleRxControlFrame(pAd, &RxCell);
91189 + }
91190 + break;
91191 + // discard other type
91192 + default:
91193 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
91194 + break;
91195 + }
91196 + }
91197 + else
91198 + {
91199 + pAd->Counters8023.RxErrors++;
91200 + // discard this frame
91201 + RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
91202 + }
91203 + }
91204 +
91205 + return bReschedule;
91206 +}
91207 +
91208 +/*
91209 + ========================================================================
91210 +
91211 + Routine Description:
91212 + Arguments:
91213 + pAd Pointer to our adapter
91214 +
91215 + IRQL = DISPATCH_LEVEL
91216 +
91217 + ========================================================================
91218 +*/
91219 +VOID RTMPHandleTwakeupInterrupt(
91220 + IN PRTMP_ADAPTER pAd)
91221 +{
91222 + AsicForceWakeup(pAd, FALSE);
91223 +}
91224 +
91225 +/*
91226 +========================================================================
91227 +Routine Description:
91228 + Early checking and OS-depened parsing for Tx packet send to our STA driver.
91229 +
91230 +Arguments:
91231 + NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd.
91232 + PPNDIS_PACKET ppPacketArray The packet array need to do transmission.
91233 + UINT NumberOfPackets Number of packet in packet array.
91234 +
91235 +Return Value:
91236 + NONE
91237 +
91238 +Note:
91239 + This function do early checking and classification for send-out packet.
91240 + You only can put OS-depened & STA related code in here.
91241 +========================================================================
91242 +*/
91243 +VOID STASendPackets(
91244 + IN NDIS_HANDLE MiniportAdapterContext,
91245 + IN PPNDIS_PACKET ppPacketArray,
91246 + IN UINT NumberOfPackets)
91247 +{
91248 + UINT Index;
91249 + PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) MiniportAdapterContext;
91250 + PNDIS_PACKET pPacket;
91251 + BOOLEAN allowToSend = FALSE;
91252 +
91253 +
91254 + for (Index = 0; Index < NumberOfPackets; Index++)
91255 + {
91256 + pPacket = ppPacketArray[Index];
91257 +
91258 + do
91259 + {
91260 +
91261 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
91262 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
91263 + RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
91264 + {
91265 + // Drop send request since hardware is in reset state
91266 + break;
91267 + }
91268 + else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd))
91269 + {
91270 + // Drop send request since there are no physical connection yet
91271 + break;
91272 + }
91273 + else
91274 + {
91275 + // Record that orignal packet source is from NDIS layer,so that
91276 + // later on driver knows how to release this NDIS PACKET
91277 +#ifdef QOS_DLS_SUPPORT
91278 + MAC_TABLE_ENTRY *pEntry;
91279 + PUCHAR pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
91280 +
91281 + pEntry = MacTableLookup(pAd, pSrcBufVA);
91282 + if (pEntry && (pEntry->ValidAsDls == TRUE))
91283 + {
91284 + RTMP_SET_PACKET_WCID(pPacket, pEntry->Aid);
91285 + }
91286 + else
91287 +#endif // QOS_DLS_SUPPORT //
91288 + RTMP_SET_PACKET_WCID(pPacket, 0); // this field is useless when in STA mode
91289 + RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
91290 + NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING);
91291 + pAd->RalinkCounters.PendingNdisPacketCount++;
91292 +
91293 + allowToSend = TRUE;
91294 + }
91295 + } while(FALSE);
91296 +
91297 + if (allowToSend == TRUE)
91298 + STASendPacket(pAd, pPacket);
91299 + else
91300 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91301 + }
91302 +
91303 + // Dequeue outgoing frames from TxSwQueue[] and process it
91304 + RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
91305 +
91306 +}
91307 +
91308 +
91309 +/*
91310 +========================================================================
91311 +Routine Description:
91312 + This routine is used to do packet parsing and classification for Tx packet
91313 + to STA device, and it will en-queue packets to our TxSwQueue depends on AC
91314 + class.
91315 +
91316 +Arguments:
91317 + pAd Pointer to our adapter
91318 + pPacket Pointer to send packet
91319 +
91320 +Return Value:
91321 + NDIS_STATUS_SUCCESS If succes to queue the packet into TxSwQueue.
91322 + NDIS_STATUS_FAILURE If failed to do en-queue.
91323 +
91324 +Note:
91325 + You only can put OS-indepened & STA related code in here.
91326 +========================================================================
91327 +*/
91328 +NDIS_STATUS STASendPacket(
91329 + IN PRTMP_ADAPTER pAd,
91330 + IN PNDIS_PACKET pPacket)
91331 +{
91332 + PACKET_INFO PacketInfo;
91333 + PUCHAR pSrcBufVA;
91334 + UINT SrcBufLen;
91335 + UINT AllowFragSize;
91336 + UCHAR NumberOfFrag;
91337 +// UCHAR RTSRequired;
91338 + UCHAR QueIdx, UserPriority;
91339 + MAC_TABLE_ENTRY *pEntry = NULL;
91340 + unsigned int IrqFlags;
91341 + UCHAR FlgIsIP = 0;
91342 + UCHAR Rate;
91343 +
91344 + // Prepare packet information structure for buffer descriptor
91345 + // chained within a single NDIS packet.
91346 + RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
91347 +
91348 + if (pSrcBufVA == NULL)
91349 + {
91350 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> pSrcBufVA == NULL !!!SrcBufLen=%x\n",SrcBufLen));
91351 + // Resourece is low, system did not allocate virtual address
91352 + // return NDIS_STATUS_FAILURE directly to upper layer
91353 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91354 + return NDIS_STATUS_FAILURE;
91355 + }
91356 +
91357 +
91358 + if (SrcBufLen < 14)
91359 + {
91360 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> Ndis Packet buffer error !!!\n"));
91361 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91362 + return (NDIS_STATUS_FAILURE);
91363 + }
91364 +
91365 + // In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry.
91366 + // Note multicast packets in adhoc also use BSSID_WCID index.
91367 + {
91368 + if(INFRA_ON(pAd))
91369 + {
91370 +#ifdef QOS_DLS_SUPPORT
91371 + USHORT tmpWcid;
91372 +
91373 + tmpWcid = RTMP_GET_PACKET_WCID(pPacket);
91374 + if (VALID_WCID(tmpWcid) &&
91375 + (pAd->MacTab.Content[tmpWcid].ValidAsDls== TRUE))
91376 + {
91377 + pEntry = &pAd->MacTab.Content[tmpWcid];
91378 + Rate = pAd->MacTab.Content[tmpWcid].CurrTxRate;
91379 + }
91380 + else
91381 +#endif // QOS_DLS_SUPPORT //
91382 + {
91383 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
91384 + RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID);
91385 + Rate = pAd->CommonCfg.TxRate;
91386 + }
91387 + }
91388 + else if (ADHOC_ON(pAd))
91389 + {
91390 + if (*pSrcBufVA & 0x01)
91391 + {
91392 + RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID);
91393 + pEntry = &pAd->MacTab.Content[MCAST_WCID];
91394 + }
91395 + else
91396 + {
91397 + pEntry = MacTableLookup(pAd, pSrcBufVA);
91398 + }
91399 + Rate = pAd->CommonCfg.TxRate;
91400 + }
91401 + }
91402 +
91403 + if (!pEntry)
91404 + {
91405 + DBGPRINT(RT_DEBUG_ERROR,("STASendPacket->Cannot find pEntry(%2x:%2x:%2x:%2x:%2x:%2x) in MacTab!\n", PRINT_MAC(pSrcBufVA)));
91406 + // Resourece is low, system did not allocate virtual address
91407 + // return NDIS_STATUS_FAILURE directly to upper layer
91408 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91409 + return NDIS_STATUS_FAILURE;
91410 + }
91411 +
91412 + if (ADHOC_ON(pAd)
91413 + )
91414 + {
91415 + RTMP_SET_PACKET_WCID(pPacket, (UCHAR)pEntry->Aid);
91416 + }
91417 +
91418 + //
91419 + // Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags.
91420 + // Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL).
91421 + RTMPCheckEtherType(pAd, pPacket);
91422 +
91423 +
91424 +
91425 + //
91426 + // WPA 802.1x secured port control - drop all non-802.1x frame before port secured
91427 + //
91428 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
91429 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
91430 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
91431 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
91432 +#ifdef WPA_SUPPLICANT_SUPPORT
91433 + || (pAd->StaCfg.IEEE8021X == TRUE)
91434 +#endif // WPA_SUPPLICANT_SUPPORT //
91435 +#ifdef LEAP_SUPPORT
91436 + || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
91437 +#endif // LEAP_SUPPORT //
91438 + )
91439 + && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) || (pAd->StaCfg.MicErrCnt >= 2))
91440 + && (RTMP_GET_PACKET_EAPOL(pPacket)== FALSE)
91441 + )
91442 + {
91443 + DBGPRINT(RT_DEBUG_TRACE,("STASendPacket --> Drop packet before port secured !!!\n"));
91444 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91445 +
91446 + return (NDIS_STATUS_FAILURE);
91447 + }
91448 +
91449 +
91450 + // STEP 1. Decide number of fragments required to deliver this MSDU.
91451 + // The estimation here is not very accurate because difficult to
91452 + // take encryption overhead into consideration here. The result
91453 + // "NumberOfFrag" is then just used to pre-check if enough free
91454 + // TXD are available to hold this MSDU.
91455 +
91456 +
91457 + if (*pSrcBufVA & 0x01) // fragmentation not allowed on multicast & broadcast
91458 + NumberOfFrag = 1;
91459 + else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))
91460 + NumberOfFrag = 1; // Aggregation overwhelms fragmentation
91461 + else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED))
91462 + NumberOfFrag = 1; // Aggregation overwhelms fragmentation
91463 +#ifdef DOT11_N_SUPPORT
91464 + else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD))
91465 + NumberOfFrag = 1; // MIMO RATE overwhelms fragmentation
91466 +#endif // DOT11_N_SUPPORT //
91467 + else
91468 + {
91469 + // The calculated "NumberOfFrag" is a rough estimation because of various
91470 + // encryption/encapsulation overhead not taken into consideration. This number is just
91471 + // used to make sure enough free TXD are available before fragmentation takes place.
91472 + // In case the actual required number of fragments of an NDIS packet
91473 + // excceeds "NumberOfFrag"caculated here and not enough free TXD available, the
91474 + // last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of
91475 + // resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should
91476 + // rarely happen and the penalty is just like a TX RETRY fail. Affordable.
91477 +
91478 + AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
91479 + NumberOfFrag = ((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) / AllowFragSize) + 1;
91480 + // To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size
91481 + if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) % AllowFragSize) == 0)
91482 + {
91483 + NumberOfFrag--;
91484 + }
91485 + }
91486 +
91487 + // Save fragment number to Ndis packet reserved field
91488 + RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag);
91489 +
91490 +
91491 + // STEP 2. Check the requirement of RTS:
91492 + // If multiple fragment required, RTS is required only for the first fragment
91493 + // if the fragment size large than RTS threshold
91494 + // For RT28xx, Let ASIC send RTS/CTS
91495 + RTMP_SET_PACKET_RTS(pPacket, 0);
91496 + RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate);
91497 +
91498 + //
91499 + // STEP 3. Traffic classification. outcome = <UserPriority, QueIdx>
91500 + //
91501 + UserPriority = 0;
91502 + QueIdx = QID_AC_BE;
91503 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
91504 + CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE))
91505 + {
91506 + USHORT Protocol;
91507 + UCHAR LlcSnapLen = 0, Byte0, Byte1;
91508 + do
91509 + {
91510 + // get Ethernet protocol field
91511 + Protocol = (USHORT)((pSrcBufVA[12] << 8) + pSrcBufVA[13]);
91512 + if (Protocol <= 1500)
91513 + {
91514 + // get Ethernet protocol field from LLC/SNAP
91515 + if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
91516 + break;
91517 +
91518 + Protocol = (USHORT)((Byte0 << 8) + Byte1);
91519 + LlcSnapLen = 8;
91520 + }
91521 +
91522 + // always AC_BE for non-IP packet
91523 + if (Protocol != 0x0800)
91524 + break;
91525 +
91526 + // get IP header
91527 + if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
91528 + break;
91529 +
91530 + // return AC_BE if packet is not IPv4
91531 + if ((Byte0 & 0xf0) != 0x40)
91532 + break;
91533 +
91534 + FlgIsIP = 1;
91535 + UserPriority = (Byte1 & 0xe0) >> 5;
91536 + QueIdx = MapUserPriorityToAccessCategory[UserPriority];
91537 +
91538 + // TODO: have to check ACM bit. apply TSPEC if ACM is ON
91539 + // TODO: downgrade UP & QueIdx before passing ACM
91540 + if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx])
91541 + {
91542 + UserPriority = 0;
91543 + QueIdx = QID_AC_BE;
91544 + }
91545 + } while (FALSE);
91546 + }
91547 +
91548 + RTMP_SET_PACKET_UP(pPacket, UserPriority);
91549 +
91550 +
91551 +
91552 + // Make sure SendTxWait queue resource won't be used by other threads
91553 + RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
91554 + if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE)
91555 + {
91556 + RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
91557 +#ifdef BLOCK_NET_IF
91558 + StopNetIfQueue(pAd, QueIdx, pPacket);
91559 +#endif // BLOCK_NET_IF //
91560 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
91561 +
91562 + return NDIS_STATUS_FAILURE;
91563 + }
91564 + else
91565 + {
91566 + InsertTailQueue(&pAd->TxSwQueue[QueIdx], PACKET_TO_QUEUE_ENTRY(pPacket));
91567 + }
91568 + RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
91569 +
91570 +#ifdef DOT11_N_SUPPORT
91571 + if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE)&&
91572 + IS_HT_STA(pEntry))
91573 + {
91574 + //PMAC_TABLE_ENTRY pMacEntry = &pAd->MacTab.Content[BSSID_WCID];
91575 + if (((pEntry->TXBAbitmap & (1<<UserPriority)) == 0) &&
91576 + ((pEntry->BADeclineBitmap & (1<<UserPriority)) == 0) &&
91577 + (pEntry->PortSecured == WPA_802_1X_PORT_SECURED)
91578 + // For IOT compatibility, if
91579 + // 1. It is Ralink chip or
91580 + // 2. It is OPEN or AES mode,
91581 + // then BA session can be bulit.
91582 + && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) ||
91583 + (pEntry->WepStatus == Ndis802_11WEPDisabled || pEntry->WepStatus == Ndis802_11Encryption3Enabled))
91584 + )
91585 + {
91586 + BAOriSessionSetUp(pAd, pEntry, 0, 0, 10, FALSE);
91587 + }
91588 + }
91589 +#endif // DOT11_N_SUPPORT //
91590 +
91591 + pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; // TODO: for debug only. to be removed
91592 + return NDIS_STATUS_SUCCESS;
91593 +}
91594 +
91595 +
91596 +/*
91597 + ========================================================================
91598 +
91599 + Routine Description:
91600 + This subroutine will scan through releative ring descriptor to find
91601 + out avaliable free ring descriptor and compare with request size.
91602 +
91603 + Arguments:
91604 + pAd Pointer to our adapter
91605 + QueIdx Selected TX Ring
91606 +
91607 + Return Value:
91608 + NDIS_STATUS_FAILURE Not enough free descriptor
91609 + NDIS_STATUS_SUCCESS Enough free descriptor
91610 +
91611 + IRQL = PASSIVE_LEVEL
91612 + IRQL = DISPATCH_LEVEL
91613 +
91614 + Note:
91615 +
91616 + ========================================================================
91617 +*/
91618 +
91619 +#ifdef RT2870
91620 +/*
91621 + Actually, this function used to check if the TxHardware Queue still has frame need to send.
91622 + If no frame need to send, go to sleep, else, still wake up.
91623 +*/
91624 +NDIS_STATUS RTMPFreeTXDRequest(
91625 + IN PRTMP_ADAPTER pAd,
91626 + IN UCHAR QueIdx,
91627 + IN UCHAR NumberRequired,
91628 + IN PUCHAR FreeNumberIs)
91629 +{
91630 + //ULONG FreeNumber = 0;
91631 + NDIS_STATUS Status = NDIS_STATUS_FAILURE;
91632 + unsigned long IrqFlags;
91633 + HT_TX_CONTEXT *pHTTXContext;
91634 +
91635 + switch (QueIdx)
91636 + {
91637 + case QID_AC_BK:
91638 + case QID_AC_BE:
91639 + case QID_AC_VI:
91640 + case QID_AC_VO:
91641 + case QID_HCCA:
91642 + {
91643 + pHTTXContext = &pAd->TxContext[QueIdx];
91644 + RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
91645 + if ((pHTTXContext->CurWritePosition != pHTTXContext->ENextBulkOutPosition) ||
91646 + (pHTTXContext->IRPPending == TRUE))
91647 + {
91648 + Status = NDIS_STATUS_FAILURE;
91649 + }
91650 + else
91651 + {
91652 + Status = NDIS_STATUS_SUCCESS;
91653 + }
91654 + RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
91655 + }
91656 + break;
91657 +
91658 + case QID_MGMT:
91659 + if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE)
91660 + Status = NDIS_STATUS_FAILURE;
91661 + else
91662 + Status = NDIS_STATUS_SUCCESS;
91663 + break;
91664 +
91665 + default:
91666 + DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));
91667 + break;
91668 + }
91669 +
91670 + return (Status);
91671 +
91672 +}
91673 +#endif // RT2870 //
91674 +
91675 +
91676 +VOID RTMPSendDisassociationFrame(
91677 + IN PRTMP_ADAPTER pAd)
91678 +{
91679 +}
91680 +
91681 +VOID RTMPSendNullFrame(
91682 + IN PRTMP_ADAPTER pAd,
91683 + IN UCHAR TxRate,
91684 + IN BOOLEAN bQosNull)
91685 +{
91686 + UCHAR NullFrame[48];
91687 + ULONG Length;
91688 + PHEADER_802_11 pHeader_802_11;
91689 +
91690 +
91691 +#ifdef RALINK_ATE
91692 + if(ATE_ON(pAd))
91693 + {
91694 + return;
91695 + }
91696 +#endif // RALINK_ATE //
91697 +
91698 + // WPA 802.1x secured port control
91699 + if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
91700 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
91701 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
91702 + (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
91703 +#ifdef WPA_SUPPLICANT_SUPPORT
91704 + || (pAd->StaCfg.IEEE8021X == TRUE)
91705 +#endif
91706 + ) &&
91707 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
91708 + {
91709 + return;
91710 + }
91711 +
91712 + NdisZeroMemory(NullFrame, 48);
91713 + Length = sizeof(HEADER_802_11);
91714 +
91715 + pHeader_802_11 = (PHEADER_802_11) NullFrame;
91716 +
91717 + pHeader_802_11->FC.Type = BTYPE_DATA;
91718 + pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC;
91719 + pHeader_802_11->FC.ToDs = 1;
91720 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
91721 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
91722 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
91723 +
91724 + if (pAd->CommonCfg.bAPSDForcePowerSave)
91725 + {
91726 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
91727 + }
91728 + else
91729 + {
91730 + pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE) ? 1: 0;
91731 + }
91732 + pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14);
91733 +
91734 + pAd->Sequence++;
91735 + pHeader_802_11->Sequence = pAd->Sequence;
91736 +
91737 + // Prepare QosNull function frame
91738 + if (bQosNull)
91739 + {
91740 + pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL;
91741 +
91742 + // copy QOS control bytes
91743 + NullFrame[Length] = 0;
91744 + NullFrame[Length+1] = 0;
91745 + Length += 2;// if pad with 2 bytes for alignment, APSD will fail
91746 + }
91747 +
91748 + HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length);
91749 +
91750 +}
91751 +
91752 +// IRQL = DISPATCH_LEVEL
91753 +VOID RTMPSendRTSFrame(
91754 + IN PRTMP_ADAPTER pAd,
91755 + IN PUCHAR pDA,
91756 + IN unsigned int NextMpduSize,
91757 + IN UCHAR TxRate,
91758 + IN UCHAR RTSRate,
91759 + IN USHORT AckDuration,
91760 + IN UCHAR QueIdx,
91761 + IN UCHAR FrameGap)
91762 +{
91763 +}
91764 +
91765 +
91766 +
91767 +// --------------------------------------------------------
91768 +// FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM
91769 +// Find the WPA key, either Group or Pairwise Key
91770 +// LEAP + TKIP also use WPA key.
91771 +// --------------------------------------------------------
91772 +// Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst
91773 +// In Cisco CCX 2.0 Leap Authentication
91774 +// WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey
91775 +// Instead of the SharedKey, SharedKey Length may be Zero.
91776 +VOID STAFindCipherAlgorithm(
91777 + IN PRTMP_ADAPTER pAd,
91778 + IN TX_BLK *pTxBlk)
91779 +{
91780 + NDIS_802_11_ENCRYPTION_STATUS Cipher; // To indicate cipher used for this packet
91781 + UCHAR CipherAlg = CIPHER_NONE; // cipher alogrithm
91782 + UCHAR KeyIdx = 0xff;
91783 + PUCHAR pSrcBufVA;
91784 + PCIPHER_KEY pKey = NULL;
91785 +
91786 + pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket);
91787 +
91788 + {
91789 + // Select Cipher
91790 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
91791 + Cipher = pAd->StaCfg.GroupCipher; // Cipher for Multicast or Broadcast
91792 + else
91793 + Cipher = pAd->StaCfg.PairCipher; // Cipher for Unicast
91794 +
91795 + if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
91796 + {
91797 + ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= CIPHER_CKIP128);
91798 +
91799 + // 4-way handshaking frame must be clear
91800 + if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) && (pAd->SharedKey[BSS0][0].CipherAlg) &&
91801 + (pAd->SharedKey[BSS0][0].KeyLen))
91802 + {
91803 + CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
91804 + KeyIdx = 0;
91805 + }
91806 + }
91807 + else if (Cipher == Ndis802_11Encryption1Enabled)
91808 + {
91809 +#ifdef LEAP_SUPPORT
91810 + if (pAd->StaCfg.CkipFlag & 0x10) // Cisco CKIP KP is on
91811 + {
91812 + if (LEAP_CCKM_ON(pAd))
91813 + {
91814 + if (((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))))
91815 + KeyIdx = 1;
91816 + else
91817 + KeyIdx = 0;
91818 + }
91819 + else
91820 + KeyIdx = pAd->StaCfg.DefaultKeyId;
91821 + }
91822 + else if (pAd->StaCfg.CkipFlag & 0x08) // only CKIP CMIC
91823 + KeyIdx = pAd->StaCfg.DefaultKeyId;
91824 + else if (LEAP_CCKM_ON(pAd))
91825 + {
91826 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
91827 + KeyIdx = 1;
91828 + else
91829 + KeyIdx = 0;
91830 + }
91831 + else // standard WEP64 or WEP128
91832 +#endif // LEAP_SUPPORT //
91833 + KeyIdx = pAd->StaCfg.DefaultKeyId;
91834 + }
91835 + else if ((Cipher == Ndis802_11Encryption2Enabled) ||
91836 + (Cipher == Ndis802_11Encryption3Enabled))
91837 + {
91838 + if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) // multicast
91839 + KeyIdx = pAd->StaCfg.DefaultKeyId;
91840 + else if (pAd->SharedKey[BSS0][0].KeyLen)
91841 + KeyIdx = 0;
91842 + else
91843 + KeyIdx = pAd->StaCfg.DefaultKeyId;
91844 + }
91845 +
91846 + if (KeyIdx == 0xff)
91847 + CipherAlg = CIPHER_NONE;
91848 + else if ((Cipher == Ndis802_11EncryptionDisabled) || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0))
91849 + CipherAlg = CIPHER_NONE;
91850 +#ifdef WPA_SUPPLICANT_SUPPORT
91851 + else if ( pAd->StaCfg.WpaSupplicantUP &&
91852 + (Cipher == Ndis802_11Encryption1Enabled) &&
91853 + (pAd->StaCfg.IEEE8021X == TRUE) &&
91854 + (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
91855 + CipherAlg = CIPHER_NONE;
91856 +#endif // WPA_SUPPLICANT_SUPPORT //
91857 + else
91858 + {
91859 + //Header_802_11.FC.Wep = 1;
91860 + CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
91861 + pKey = &pAd->SharedKey[BSS0][KeyIdx];
91862 + }
91863 + }
91864 +
91865 + pTxBlk->CipherAlg = CipherAlg;
91866 + pTxBlk->pKey = pKey;
91867 +}
91868 +
91869 +
91870 +VOID STABuildCommon802_11Header(
91871 + IN PRTMP_ADAPTER pAd,
91872 + IN TX_BLK *pTxBlk)
91873 +{
91874 +
91875 + HEADER_802_11 *pHeader_802_11;
91876 +#ifdef QOS_DLS_SUPPORT
91877 + BOOLEAN bDLSFrame = FALSE;
91878 + INT DlsEntryIndex = 0;
91879 +#endif // QOS_DLS_SUPPORT //
91880 +
91881 + //
91882 + // MAKE A COMMON 802.11 HEADER
91883 + //
91884 +
91885 + // normal wlan header size : 24 octets
91886 + pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
91887 +
91888 + pHeader_802_11 = (HEADER_802_11 *) &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
91889 +
91890 + NdisZeroMemory(pHeader_802_11, sizeof(HEADER_802_11));
91891 +
91892 + pHeader_802_11->FC.FrDs = 0;
91893 + pHeader_802_11->FC.Type = BTYPE_DATA;
91894 + pHeader_802_11->FC.SubType = ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : SUBTYPE_DATA);
91895 +
91896 +#ifdef QOS_DLS_SUPPORT
91897 + if (INFRA_ON(pAd))
91898 + {
91899 + // Check if the frame can be sent through DLS direct link interface
91900 + // If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
91901 + DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
91902 + if (DlsEntryIndex >= 0)
91903 + bDLSFrame = TRUE;
91904 + else
91905 + bDLSFrame = FALSE;
91906 + }
91907 +#endif // QOS_DLS_SUPPORT //
91908 +
91909 + if (pTxBlk->pMacEntry)
91910 + {
91911 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS))
91912 + {
91913 + pHeader_802_11->Sequence = pTxBlk->pMacEntry->NonQosDataSeq;
91914 + pTxBlk->pMacEntry->NonQosDataSeq = (pTxBlk->pMacEntry->NonQosDataSeq+1) & MAXSEQ;
91915 + }
91916 + else
91917 + {
91918 +#ifdef QOS_DLS_SUPPORT
91919 + if (bDLSFrame)
91920 + {
91921 + pHeader_802_11->Sequence = pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence;
91922 + pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence = (pAd->StaCfg.DLSEntry[DlsEntryIndex].Sequence+1) & MAXSEQ;
91923 + }
91924 + else
91925 +#endif // QOS_DLS_SUPPORT //
91926 + {
91927 + pHeader_802_11->Sequence = pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority];
91928 + pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = (pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
91929 + }
91930 + }
91931 + }
91932 + else
91933 + {
91934 + pHeader_802_11->Sequence = pAd->Sequence;
91935 + pAd->Sequence = (pAd->Sequence+1) & MAXSEQ; // next sequence
91936 + }
91937 +
91938 + pHeader_802_11->Frag = 0;
91939 +
91940 + pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
91941 +
91942 + {
91943 + if (INFRA_ON(pAd))
91944 + {
91945 +#ifdef QOS_DLS_SUPPORT
91946 + if (bDLSFrame)
91947 + {
91948 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
91949 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
91950 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
91951 + pHeader_802_11->FC.ToDs = 0;
91952 + }
91953 + else
91954 +#endif // QOS_DLS_SUPPORT //
91955 + {
91956 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
91957 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
91958 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pTxBlk->pSrcBufHeader);
91959 + pHeader_802_11->FC.ToDs = 1;
91960 + }
91961 + }
91962 + else if (ADHOC_ON(pAd))
91963 + {
91964 + COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);
91965 + COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
91966 + COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
91967 + pHeader_802_11->FC.ToDs = 0;
91968 + }
91969 + }
91970 +
91971 + if (pTxBlk->CipherAlg != CIPHER_NONE)
91972 + pHeader_802_11->FC.Wep = 1;
91973 +
91974 + // -----------------------------------------------------------------
91975 + // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
91976 + // -----------------------------------------------------------------
91977 + if (pAd->CommonCfg.bAPSDForcePowerSave)
91978 + pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
91979 + else
91980 + pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
91981 +}
91982 +
91983 +#ifdef DOT11_N_SUPPORT
91984 +VOID STABuildCache802_11Header(
91985 + IN RTMP_ADAPTER *pAd,
91986 + IN TX_BLK *pTxBlk,
91987 + IN UCHAR *pHeader)
91988 +{
91989 + MAC_TABLE_ENTRY *pMacEntry;
91990 + PHEADER_802_11 pHeader80211;
91991 +
91992 + pHeader80211 = (PHEADER_802_11)pHeader;
91993 + pMacEntry = pTxBlk->pMacEntry;
91994 +
91995 + //
91996 + // Update the cached 802.11 HEADER
91997 + //
91998 +
91999 + // normal wlan header size : 24 octets
92000 + pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);
92001 +
92002 + // More Bit
92003 + pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
92004 +
92005 + // Sequence
92006 + pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority];
92007 + pMacEntry->TxSeq[pTxBlk->UserPriority] = (pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;
92008 +
92009 + {
92010 + // Check if the frame can be sent through DLS direct link interface
92011 + // If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability)
92012 +#ifdef QOS_DLS_SUPPORT
92013 + BOOLEAN bDLSFrame = FALSE;
92014 + INT DlsEntryIndex = 0;
92015 +
92016 + DlsEntryIndex = RTMPCheckDLSFrame(pAd, pTxBlk->pSrcBufHeader);
92017 + if (DlsEntryIndex >= 0)
92018 + bDLSFrame = TRUE;
92019 + else
92020 + bDLSFrame = FALSE;
92021 +#endif // QOS_DLS_SUPPORT //
92022 +
92023 + // The addr3 of normal packet send from DS is Dest Mac address.
92024 +#ifdef QOS_DLS_SUPPORT
92025 + if (bDLSFrame)
92026 + {
92027 + COPY_MAC_ADDR(pHeader80211->Addr1, pTxBlk->pSrcBufHeader);
92028 + COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
92029 + pHeader80211->FC.ToDs = 0;
92030 + }
92031 + else
92032 +#endif // QOS_DLS_SUPPORT //
92033 + if (ADHOC_ON(pAd))
92034 + COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);
92035 + else
92036 + COPY_MAC_ADDR(pHeader80211->Addr3, pTxBlk->pSrcBufHeader);
92037 + }
92038 +
92039 + // -----------------------------------------------------------------
92040 + // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.
92041 + // -----------------------------------------------------------------
92042 + if (pAd->CommonCfg.bAPSDForcePowerSave)
92043 + pHeader80211->FC.PwrMgmt = PWR_SAVE;
92044 + else
92045 + pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
92046 +}
92047 +#endif // DOT11_N_SUPPORT //
92048 +
92049 +static inline PUCHAR STA_Build_ARalink_Frame_Header(
92050 + IN RTMP_ADAPTER *pAd,
92051 + IN TX_BLK *pTxBlk)
92052 +{
92053 + PUCHAR pHeaderBufPtr;
92054 + HEADER_802_11 *pHeader_802_11;
92055 + PNDIS_PACKET pNextPacket;
92056 + UINT32 nextBufLen;
92057 + PQUEUE_ENTRY pQEntry;
92058 +
92059 + STAFindCipherAlgorithm(pAd, pTxBlk);
92060 + STABuildCommon802_11Header(pAd, pTxBlk);
92061 +
92062 +
92063 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
92064 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
92065 +
92066 + // steal "order" bit to mark "aggregation"
92067 + pHeader_802_11->FC.Order = 1;
92068 +
92069 + // skip common header
92070 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
92071 +
92072 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
92073 + {
92074 + //
92075 + // build QOS Control bytes
92076 + //
92077 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
92078 +
92079 + *(pHeaderBufPtr+1) = 0;
92080 + pHeaderBufPtr +=2;
92081 + pTxBlk->MpduHeaderLen += 2;
92082 + }
92083 +
92084 + // padding at front of LLC header. LLC header should at 4-bytes aligment.
92085 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
92086 + pHeaderBufPtr = (PCHAR)ROUND_UP(pHeaderBufPtr, 4);
92087 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
92088 +
92089 + // For RA Aggregation,
92090 + // put the 2nd MSDU length(extra 2-byte field) after QOS_CONTROL in little endian format
92091 + pQEntry = pTxBlk->TxPacketList.Head;
92092 + pNextPacket = QUEUE_ENTRY_TO_PKT(pQEntry);
92093 + nextBufLen = GET_OS_PKT_LEN(pNextPacket);
92094 + if (RTMP_GET_PACKET_VLAN(pNextPacket))
92095 + nextBufLen -= LENGTH_802_1Q;
92096 +
92097 + *pHeaderBufPtr = (UCHAR)nextBufLen & 0xff;
92098 + *(pHeaderBufPtr+1) = (UCHAR)(nextBufLen >> 8);
92099 +
92100 + pHeaderBufPtr += 2;
92101 + pTxBlk->MpduHeaderLen += 2;
92102 +
92103 + return pHeaderBufPtr;
92104 +
92105 +}
92106 +
92107 +#ifdef DOT11_N_SUPPORT
92108 +static inline PUCHAR STA_Build_AMSDU_Frame_Header(
92109 + IN RTMP_ADAPTER *pAd,
92110 + IN TX_BLK *pTxBlk)
92111 +{
92112 + PUCHAR pHeaderBufPtr;//, pSaveBufPtr;
92113 + HEADER_802_11 *pHeader_802_11;
92114 +
92115 +
92116 + STAFindCipherAlgorithm(pAd, pTxBlk);
92117 + STABuildCommon802_11Header(pAd, pTxBlk);
92118 +
92119 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
92120 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
92121 +
92122 + // skip common header
92123 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
92124 +
92125 + //
92126 + // build QOS Control bytes
92127 + //
92128 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
92129 +
92130 + //
92131 + // A-MSDU packet
92132 + //
92133 + *pHeaderBufPtr |= 0x80;
92134 +
92135 + *(pHeaderBufPtr+1) = 0;
92136 + pHeaderBufPtr +=2;
92137 + pTxBlk->MpduHeaderLen += 2;
92138 +
92139 + //pSaveBufPtr = pHeaderBufPtr;
92140 +
92141 + //
92142 + // padding at front of LLC header
92143 + // LLC header should locate at 4-octets aligment
92144 + //
92145 + // @@@ MpduHeaderLen excluding padding @@@
92146 + //
92147 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
92148 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
92149 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
92150 +
92151 + return pHeaderBufPtr;
92152 +
92153 +}
92154 +
92155 +
92156 +VOID STA_AMPDU_Frame_Tx(
92157 + IN PRTMP_ADAPTER pAd,
92158 + IN TX_BLK *pTxBlk)
92159 +{
92160 + HEADER_802_11 *pHeader_802_11;
92161 + PUCHAR pHeaderBufPtr;
92162 + USHORT FreeNumber;
92163 + MAC_TABLE_ENTRY *pMacEntry;
92164 + BOOLEAN bVLANPkt;
92165 + PQUEUE_ENTRY pQEntry;
92166 +
92167 + ASSERT(pTxBlk);
92168 +
92169 + while(pTxBlk->TxPacketList.Head)
92170 + {
92171 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92172 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92173 + if ( RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
92174 + {
92175 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
92176 + continue;
92177 + }
92178 +
92179 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
92180 +
92181 + pMacEntry = pTxBlk->pMacEntry;
92182 + if (pMacEntry->isCached)
92183 + {
92184 + // NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]!!!!
92185 + NdisMoveMemory((PUCHAR)&pTxBlk->HeaderBuf[TXINFO_SIZE], (PUCHAR)&pMacEntry->CachedBuf[0], TXWI_SIZE + sizeof(HEADER_802_11));
92186 + pHeaderBufPtr = (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]);
92187 + STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr);
92188 + }
92189 + else
92190 + {
92191 + STAFindCipherAlgorithm(pAd, pTxBlk);
92192 + STABuildCommon802_11Header(pAd, pTxBlk);
92193 +
92194 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
92195 + }
92196 +
92197 +
92198 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
92199 +
92200 + // skip common header
92201 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
92202 +
92203 + //
92204 + // build QOS Control bytes
92205 + //
92206 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
92207 + *(pHeaderBufPtr+1) = 0;
92208 + pHeaderBufPtr +=2;
92209 + pTxBlk->MpduHeaderLen += 2;
92210 +
92211 + //
92212 + // build HTC+
92213 + // HTC control filed following QoS field
92214 + //
92215 + if ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, fCLIENT_STATUS_RDG_CAPABLE))
92216 + {
92217 + if (pMacEntry->isCached == FALSE)
92218 + {
92219 + // mark HTC bit
92220 + pHeader_802_11->FC.Order = 1;
92221 +
92222 + NdisZeroMemory(pHeaderBufPtr, 4);
92223 + *(pHeaderBufPtr+3) |= 0x80;
92224 + }
92225 + pHeaderBufPtr += 4;
92226 + pTxBlk->MpduHeaderLen += 4;
92227 + }
92228 +
92229 + //pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE;
92230 + ASSERT(pTxBlk->MpduHeaderLen >= 24);
92231 +
92232 + // skip 802.3 header
92233 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
92234 + pTxBlk->SrcBufLen -= LENGTH_802_3;
92235 +
92236 + // skip vlan tag
92237 + if (bVLANPkt)
92238 + {
92239 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
92240 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
92241 + }
92242 +
92243 + //
92244 + // padding at front of LLC header
92245 + // LLC header should locate at 4-octets aligment
92246 + //
92247 + // @@@ MpduHeaderLen excluding padding @@@
92248 + //
92249 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
92250 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
92251 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
92252 +
92253 + {
92254 +
92255 + //
92256 + // Insert LLC-SNAP encapsulation - 8 octets
92257 + //
92258 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
92259 + if (pTxBlk->pExtraLlcSnapEncap)
92260 + {
92261 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
92262 + pHeaderBufPtr += 6;
92263 + // get 2 octets (TypeofLen)
92264 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
92265 + pHeaderBufPtr += 2;
92266 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
92267 + }
92268 +
92269 + }
92270 +
92271 + if (pMacEntry->isCached)
92272 + {
92273 + RTMPWriteTxWI_Cache(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92274 + }
92275 + else
92276 + {
92277 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92278 +
92279 + NdisZeroMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), sizeof(pMacEntry->CachedBuf));
92280 + NdisMoveMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), (pHeaderBufPtr - (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE])));
92281 + pMacEntry->isCached = TRUE;
92282 + }
92283 +
92284 + // calculate Transmitted AMPDU count and ByteCount
92285 + {
92286 + pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.LowPart ++;
92287 + pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.QuadPart += pTxBlk->SrcBufLen;
92288 + }
92289 +
92290 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
92291 +
92292 + HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
92293 +
92294 + //
92295 + // Kick out Tx
92296 + //
92297 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
92298 +
92299 + pAd->RalinkCounters.KickTxCount++;
92300 + pAd->RalinkCounters.OneSecTxDoneCount++;
92301 + }
92302 +
92303 +}
92304 +
92305 +
92306 +VOID STA_AMSDU_Frame_Tx(
92307 + IN PRTMP_ADAPTER pAd,
92308 + IN TX_BLK *pTxBlk)
92309 +{
92310 + PUCHAR pHeaderBufPtr;
92311 + USHORT FreeNumber;
92312 + USHORT subFramePayloadLen = 0; // AMSDU Subframe length without AMSDU-Header / Padding.
92313 + USHORT totalMPDUSize=0;
92314 + UCHAR *subFrameHeader;
92315 + UCHAR padding = 0;
92316 + USHORT FirstTx = 0, LastTxIdx = 0;
92317 + BOOLEAN bVLANPkt;
92318 + int frameNum = 0;
92319 + PQUEUE_ENTRY pQEntry;
92320 +
92321 +
92322 + ASSERT(pTxBlk);
92323 +
92324 + ASSERT((pTxBlk->TxPacketList.Number > 1));
92325 +
92326 + while(pTxBlk->TxPacketList.Head)
92327 + {
92328 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92329 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92330 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
92331 + {
92332 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
92333 + continue;
92334 + }
92335 +
92336 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
92337 +
92338 + // skip 802.3 header
92339 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
92340 + pTxBlk->SrcBufLen -= LENGTH_802_3;
92341 +
92342 + // skip vlan tag
92343 + if (bVLANPkt)
92344 + {
92345 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
92346 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
92347 + }
92348 +
92349 + if (frameNum == 0)
92350 + {
92351 + pHeaderBufPtr = STA_Build_AMSDU_Frame_Header(pAd, pTxBlk);
92352 +
92353 + // NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled.
92354 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92355 + }
92356 + else
92357 + {
92358 + pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
92359 + padding = ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen, 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen);
92360 + NdisZeroMemory(pHeaderBufPtr, padding + LENGTH_AMSDU_SUBFRAMEHEAD);
92361 + pHeaderBufPtr += padding;
92362 + pTxBlk->MpduHeaderLen = padding;
92363 + }
92364 +
92365 + //
92366 + // A-MSDU subframe
92367 + // DA(6)+SA(6)+Length(2) + LLC/SNAP Encap
92368 + //
92369 + subFrameHeader = pHeaderBufPtr;
92370 + subFramePayloadLen = pTxBlk->SrcBufLen;
92371 +
92372 + NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12);
92373 +
92374 +
92375 + pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD;
92376 + pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD;
92377 +
92378 +
92379 + //
92380 + // Insert LLC-SNAP encapsulation - 8 octets
92381 + //
92382 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
92383 +
92384 + subFramePayloadLen = pTxBlk->SrcBufLen;
92385 +
92386 + if (pTxBlk->pExtraLlcSnapEncap)
92387 + {
92388 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
92389 + pHeaderBufPtr += 6;
92390 + // get 2 octets (TypeofLen)
92391 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
92392 + pHeaderBufPtr += 2;
92393 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
92394 + subFramePayloadLen += LENGTH_802_1_H;
92395 + }
92396 +
92397 + // update subFrame Length field
92398 + subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8;
92399 + subFrameHeader[13] = subFramePayloadLen & 0xFF;
92400 +
92401 + totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
92402 +
92403 + if (frameNum ==0)
92404 + FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
92405 + else
92406 + LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
92407 +
92408 + frameNum++;
92409 +
92410 + pAd->RalinkCounters.KickTxCount++;
92411 + pAd->RalinkCounters.OneSecTxDoneCount++;
92412 +
92413 + // calculate Transmitted AMSDU Count and ByteCount
92414 + {
92415 + pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart ++;
92416 + pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += totalMPDUSize;
92417 + }
92418 +
92419 + }
92420 +
92421 + HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
92422 + HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
92423 +
92424 + //
92425 + // Kick out Tx
92426 + //
92427 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
92428 +}
92429 +#endif // DOT11_N_SUPPORT //
92430 +
92431 +VOID STA_Legacy_Frame_Tx(
92432 + IN PRTMP_ADAPTER pAd,
92433 + IN TX_BLK *pTxBlk)
92434 +{
92435 + HEADER_802_11 *pHeader_802_11;
92436 + PUCHAR pHeaderBufPtr;
92437 + USHORT FreeNumber;
92438 + BOOLEAN bVLANPkt;
92439 + PQUEUE_ENTRY pQEntry;
92440 +
92441 + ASSERT(pTxBlk);
92442 +
92443 +
92444 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92445 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92446 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
92447 + {
92448 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
92449 + return;
92450 + }
92451 +
92452 + if (pTxBlk->TxFrameType == TX_MCAST_FRAME)
92453 + {
92454 + INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount);
92455 + }
92456 +
92457 + if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket))
92458 + TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired);
92459 + else
92460 + TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired);
92461 +
92462 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
92463 +
92464 + if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate)
92465 + pTxBlk->TxRate = pAd->CommonCfg.MinTxRate;
92466 +
92467 + STAFindCipherAlgorithm(pAd, pTxBlk);
92468 + STABuildCommon802_11Header(pAd, pTxBlk);
92469 +
92470 +
92471 + // skip 802.3 header
92472 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
92473 + pTxBlk->SrcBufLen -= LENGTH_802_3;
92474 +
92475 + // skip vlan tag
92476 + if (bVLANPkt)
92477 + {
92478 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
92479 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
92480 + }
92481 +
92482 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
92483 + pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;
92484 +
92485 + // skip common header
92486 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
92487 +
92488 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
92489 + {
92490 + //
92491 + // build QOS Control bytes
92492 + //
92493 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
92494 + *(pHeaderBufPtr+1) = 0;
92495 + pHeaderBufPtr +=2;
92496 + pTxBlk->MpduHeaderLen += 2;
92497 + }
92498 +
92499 + // The remaining content of MPDU header should locate at 4-octets aligment
92500 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
92501 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
92502 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
92503 +
92504 + {
92505 +
92506 + //
92507 + // Insert LLC-SNAP encapsulation - 8 octets
92508 + //
92509 + //
92510 + // if original Ethernet frame contains no LLC/SNAP,
92511 + // then an extra LLC/SNAP encap is required
92512 + //
92513 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
92514 + if (pTxBlk->pExtraLlcSnapEncap)
92515 + {
92516 + UCHAR vlan_size;
92517 +
92518 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
92519 + pHeaderBufPtr += 6;
92520 + // skip vlan tag
92521 + vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
92522 + // get 2 octets (TypeofLen)
92523 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
92524 + pHeaderBufPtr += 2;
92525 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
92526 + }
92527 +
92528 + }
92529 +
92530 + //
92531 + // prepare for TXWI
92532 + // use Wcid as Key Index
92533 + //
92534 +
92535 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92536 +
92537 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
92538 +
92539 + HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
92540 +
92541 + pAd->RalinkCounters.KickTxCount++;
92542 + pAd->RalinkCounters.OneSecTxDoneCount++;
92543 +
92544 + //
92545 + // Kick out Tx
92546 + //
92547 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
92548 +}
92549 +
92550 +
92551 +VOID STA_ARalink_Frame_Tx(
92552 + IN PRTMP_ADAPTER pAd,
92553 + IN TX_BLK *pTxBlk)
92554 +{
92555 + PUCHAR pHeaderBufPtr;
92556 + USHORT FreeNumber;
92557 + USHORT totalMPDUSize=0;
92558 + USHORT FirstTx, LastTxIdx;
92559 + int frameNum = 0;
92560 + BOOLEAN bVLANPkt;
92561 + PQUEUE_ENTRY pQEntry;
92562 +
92563 +
92564 + ASSERT(pTxBlk);
92565 +
92566 + ASSERT((pTxBlk->TxPacketList.Number== 2));
92567 +
92568 +
92569 + FirstTx = LastTxIdx = 0; // Is it ok init they as 0?
92570 + while(pTxBlk->TxPacketList.Head)
92571 + {
92572 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92573 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92574 +
92575 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
92576 + {
92577 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
92578 + continue;
92579 + }
92580 +
92581 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
92582 +
92583 + // skip 802.3 header
92584 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
92585 + pTxBlk->SrcBufLen -= LENGTH_802_3;
92586 +
92587 + // skip vlan tag
92588 + if (bVLANPkt)
92589 + {
92590 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
92591 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
92592 + }
92593 +
92594 + if (frameNum == 0)
92595 + { // For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header
92596 +
92597 + pHeaderBufPtr = STA_Build_ARalink_Frame_Header(pAd, pTxBlk);
92598 +
92599 + // It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount
92600 + // will be updated after final frame was handled.
92601 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92602 +
92603 +
92604 + //
92605 + // Insert LLC-SNAP encapsulation - 8 octets
92606 + //
92607 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);
92608 +
92609 + if (pTxBlk->pExtraLlcSnapEncap)
92610 + {
92611 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
92612 + pHeaderBufPtr += 6;
92613 + // get 2 octets (TypeofLen)
92614 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
92615 + pHeaderBufPtr += 2;
92616 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
92617 + }
92618 + }
92619 + else
92620 + { // For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0.
92621 +
92622 + pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
92623 + pTxBlk->MpduHeaderLen = 0;
92624 +
92625 + // A-Ralink sub-sequent frame header is the same as 802.3 header.
92626 + // DA(6)+SA(6)+FrameType(2)
92627 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, 12);
92628 + pHeaderBufPtr += 12;
92629 + // get 2 octets (TypeofLen)
92630 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);
92631 + pHeaderBufPtr += 2;
92632 + pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD;
92633 + }
92634 +
92635 + totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
92636 +
92637 + //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);
92638 + if (frameNum ==0)
92639 + FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
92640 + else
92641 + LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);
92642 +
92643 + frameNum++;
92644 +
92645 + pAd->RalinkCounters.OneSecTxAggregationCount++;
92646 + pAd->RalinkCounters.KickTxCount++;
92647 + pAd->RalinkCounters.OneSecTxDoneCount++;
92648 +
92649 + }
92650 +
92651 + HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
92652 + HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
92653 +
92654 + //
92655 + // Kick out Tx
92656 + //
92657 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
92658 +
92659 +}
92660 +
92661 +
92662 +VOID STA_Fragment_Frame_Tx(
92663 + IN RTMP_ADAPTER *pAd,
92664 + IN TX_BLK *pTxBlk)
92665 +{
92666 + HEADER_802_11 *pHeader_802_11;
92667 + PUCHAR pHeaderBufPtr;
92668 + USHORT FreeNumber;
92669 + UCHAR fragNum = 0;
92670 + PACKET_INFO PacketInfo;
92671 + USHORT EncryptionOverhead = 0;
92672 + UINT32 FreeMpduSize, SrcRemainingBytes;
92673 + USHORT AckDuration;
92674 + UINT NextMpduSize;
92675 + BOOLEAN bVLANPkt;
92676 + PQUEUE_ENTRY pQEntry;
92677 +
92678 +
92679 + ASSERT(pTxBlk);
92680 +
92681 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92682 + pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92683 + if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)
92684 + {
92685 + RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
92686 + return;
92687 + }
92688 +
92689 + ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag));
92690 + bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
92691 +
92692 + STAFindCipherAlgorithm(pAd, pTxBlk);
92693 + STABuildCommon802_11Header(pAd, pTxBlk);
92694 +
92695 + if (pTxBlk->CipherAlg == CIPHER_TKIP)
92696 + {
92697 + pTxBlk->pPacket = duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket);
92698 + if (pTxBlk->pPacket == NULL)
92699 + return;
92700 + RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);
92701 + }
92702 +
92703 + // skip 802.3 header
92704 + pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
92705 + pTxBlk->SrcBufLen -= LENGTH_802_3;
92706 +
92707 +
92708 + // skip vlan tag
92709 + if (bVLANPkt)
92710 + {
92711 + pTxBlk->pSrcBufData += LENGTH_802_1Q;
92712 + pTxBlk->SrcBufLen -= LENGTH_802_1Q;
92713 + }
92714 +
92715 + pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
92716 + pHeader_802_11 = (HEADER_802_11 *)pHeaderBufPtr;
92717 +
92718 +
92719 + // skip common header
92720 + pHeaderBufPtr += pTxBlk->MpduHeaderLen;
92721 +
92722 + if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))
92723 + {
92724 + //
92725 + // build QOS Control bytes
92726 + //
92727 + *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
92728 +
92729 + *(pHeaderBufPtr+1) = 0;
92730 + pHeaderBufPtr +=2;
92731 + pTxBlk->MpduHeaderLen += 2;
92732 + }
92733 +
92734 + //
92735 + // padding at front of LLC header
92736 + // LLC header should locate at 4-octets aligment
92737 + //
92738 + pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;
92739 + pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);
92740 + pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);
92741 +
92742 +
92743 +
92744 + //
92745 + // Insert LLC-SNAP encapsulation - 8 octets
92746 + //
92747 + //
92748 + // if original Ethernet frame contains no LLC/SNAP,
92749 + // then an extra LLC/SNAP encap is required
92750 + //
92751 + EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);
92752 + if (pTxBlk->pExtraLlcSnapEncap)
92753 + {
92754 + UCHAR vlan_size;
92755 +
92756 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
92757 + pHeaderBufPtr += 6;
92758 + // skip vlan tag
92759 + vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
92760 + // get 2 octets (TypeofLen)
92761 + NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);
92762 + pHeaderBufPtr += 2;
92763 + pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
92764 + }
92765 +
92766 +
92767 + // If TKIP is used and fragmentation is required. Driver has to
92768 + // append TKIP MIC at tail of the scatter buffer
92769 + // MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC
92770 + if (pTxBlk->CipherAlg == CIPHER_TKIP)
92771 + {
92772 +
92773 + // NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust
92774 + // to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress.
92775 + NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, &pAd->PrivateInfo.Tx.MIC[0], 8);
92776 + //skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8);
92777 + pTxBlk->SrcBufLen += 8;
92778 + pTxBlk->TotalFrameLen += 8;
92779 + pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;
92780 + }
92781 +
92782 + //
92783 + // calcuate the overhead bytes that encryption algorithm may add. This
92784 + // affects the calculate of "duration" field
92785 + //
92786 + if ((pTxBlk->CipherAlg == CIPHER_WEP64) || (pTxBlk->CipherAlg == CIPHER_WEP128))
92787 + EncryptionOverhead = 8; //WEP: IV[4] + ICV[4];
92788 + else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC)
92789 + EncryptionOverhead = 12;//TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength
92790 + else if (pTxBlk->CipherAlg == CIPHER_TKIP)
92791 + EncryptionOverhead = 20;//TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8]
92792 + else if (pTxBlk->CipherAlg == CIPHER_AES)
92793 + EncryptionOverhead = 16; // AES: IV[4] + EIV[4] + MIC[8]
92794 + else
92795 + EncryptionOverhead = 0;
92796 +
92797 + // decide how much time an ACK/CTS frame will consume in the air
92798 + AckDuration = RTMPCalcDuration(pAd, pAd->CommonCfg.ExpectedACKRate[pTxBlk->TxRate], 14);
92799 +
92800 + // Init the total payload length of this frame.
92801 + SrcRemainingBytes = pTxBlk->SrcBufLen;
92802 +
92803 + pTxBlk->TotalFragNum = 0xff;
92804 +
92805 + do {
92806 +
92807 + FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC;
92808 +
92809 + FreeMpduSize -= pTxBlk->MpduHeaderLen;
92810 +
92811 + if (SrcRemainingBytes <= FreeMpduSize)
92812 + { // this is the last or only fragment
92813 +
92814 + pTxBlk->SrcBufLen = SrcRemainingBytes;
92815 +
92816 + pHeader_802_11->FC.MoreFrag = 0;
92817 + pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + AckDuration;
92818 +
92819 + // Indicate the lower layer that this's the last fragment.
92820 + pTxBlk->TotalFragNum = fragNum;
92821 + }
92822 + else
92823 + { // more fragment is required
92824 +
92825 + pTxBlk->SrcBufLen = FreeMpduSize;
92826 +
92827 + NextMpduSize = min(((UINT)SrcRemainingBytes - pTxBlk->SrcBufLen), ((UINT)pAd->CommonCfg.FragmentThreshold));
92828 + pHeader_802_11->FC.MoreFrag = 1;
92829 + pHeader_802_11->Duration = (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + RTMPCalcDuration(pAd, pTxBlk->TxRate, NextMpduSize + EncryptionOverhead);
92830 + }
92831 +
92832 + if (fragNum == 0)
92833 + pTxBlk->FrameGap = IFS_HTTXOP;
92834 + else
92835 + pTxBlk->FrameGap = IFS_SIFS;
92836 +
92837 + RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);
92838 +
92839 + HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber);
92840 +
92841 + pAd->RalinkCounters.KickTxCount++;
92842 + pAd->RalinkCounters.OneSecTxDoneCount++;
92843 +
92844 + // Update the frame number, remaining size of the NDIS packet payload.
92845 +
92846 + // space for 802.11 header.
92847 + if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap)
92848 + pTxBlk->MpduHeaderLen -= LENGTH_802_1_H;
92849 +
92850 + fragNum++;
92851 + SrcRemainingBytes -= pTxBlk->SrcBufLen;
92852 + pTxBlk->pSrcBufData += pTxBlk->SrcBufLen;
92853 +
92854 + pHeader_802_11->Frag++; // increase Frag #
92855 +
92856 + }while(SrcRemainingBytes > 0);
92857 +
92858 + //
92859 + // Kick out Tx
92860 + //
92861 + HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
92862 +}
92863 +
92864 +
92865 +#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \
92866 + while(_pTxBlk->TxPacketList.Head) \
92867 + { \
92868 + _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \
92869 + RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \
92870 + }
92871 +
92872 +
92873 +/*
92874 + ========================================================================
92875 +
92876 + Routine Description:
92877 + Copy frame from waiting queue into relative ring buffer and set
92878 + appropriate ASIC register to kick hardware encryption before really
92879 + sent out to air.
92880 +
92881 + Arguments:
92882 + pAd Pointer to our adapter
92883 + PNDIS_PACKET Pointer to outgoing Ndis frame
92884 + NumberOfFrag Number of fragment required
92885 +
92886 + Return Value:
92887 + None
92888 +
92889 + IRQL = DISPATCH_LEVEL
92890 +
92891 + Note:
92892 +
92893 + ========================================================================
92894 +*/
92895 +NDIS_STATUS STAHardTransmit(
92896 + IN PRTMP_ADAPTER pAd,
92897 + IN TX_BLK *pTxBlk,
92898 + IN UCHAR QueIdx)
92899 +{
92900 + NDIS_PACKET *pPacket;
92901 + PQUEUE_ENTRY pQEntry;
92902 +
92903 + // ---------------------------------------------
92904 + // STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION.
92905 + // ---------------------------------------------
92906 + //
92907 + ASSERT(pTxBlk->TxPacketList.Number);
92908 + if (pTxBlk->TxPacketList.Head == NULL)
92909 + {
92910 + DBGPRINT(RT_DEBUG_ERROR, ("pTxBlk->TotalFrameNum == %ld!\n", pTxBlk->TxPacketList.Number));
92911 + return NDIS_STATUS_FAILURE;
92912 + }
92913 +
92914 + pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head);
92915 +
92916 + // ------------------------------------------------------------------
92917 + // STEP 1. WAKE UP PHY
92918 + // outgoing frame always wakeup PHY to prevent frame lost and
92919 + // turn off PSM bit to improve performance
92920 + // ------------------------------------------------------------------
92921 + // not to change PSM bit, just send this frame out?
92922 + if ((pAd->StaCfg.Psm == PWR_SAVE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
92923 + {
92924 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicForceWakeup At HardTx\n"));
92925 + AsicForceWakeup(pAd, TRUE);
92926 + }
92927 +
92928 + // It should not change PSM bit, when APSD turn on.
92929 + if ((!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE))
92930 + || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
92931 + || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket)))
92932 + {
92933 + if ((pAd->StaCfg.Psm == PWR_SAVE) &&
92934 + (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP))
92935 + MlmeSetPsmBit(pAd, PWR_ACTIVE);
92936 + }
92937 +
92938 + switch (pTxBlk->TxFrameType)
92939 + {
92940 +#ifdef DOT11_N_SUPPORT
92941 + case TX_AMPDU_FRAME:
92942 + STA_AMPDU_Frame_Tx(pAd, pTxBlk);
92943 + break;
92944 + case TX_AMSDU_FRAME:
92945 + STA_AMSDU_Frame_Tx(pAd, pTxBlk);
92946 + break;
92947 +#endif // DOT11_N_SUPPORT //
92948 + case TX_LEGACY_FRAME:
92949 + STA_Legacy_Frame_Tx(pAd, pTxBlk);
92950 + break;
92951 + case TX_MCAST_FRAME:
92952 + STA_Legacy_Frame_Tx(pAd, pTxBlk);
92953 + break;
92954 + case TX_RALINK_FRAME:
92955 + STA_ARalink_Frame_Tx(pAd, pTxBlk);
92956 + break;
92957 + case TX_FRAG_FRAME:
92958 + STA_Fragment_Frame_Tx(pAd, pTxBlk);
92959 + break;
92960 + default:
92961 + {
92962 + // It should not happened!
92963 + DBGPRINT(RT_DEBUG_ERROR, ("Send a pacekt was not classified!! It should not happen!\n"));
92964 + while(pTxBlk->TxPacketList.Number)
92965 + {
92966 + pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
92967 + pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
92968 + if (pPacket)
92969 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
92970 + }
92971 + }
92972 + break;
92973 + }
92974 +
92975 + return (NDIS_STATUS_SUCCESS);
92976 +
92977 +}
92978 +
92979 +ULONG HashBytesPolynomial(UCHAR *value, unsigned int len)
92980 +{
92981 + unsigned char *word = value;
92982 + unsigned int ret = 0;
92983 + unsigned int i;
92984 +
92985 + for(i=0; i < len; i++)
92986 + {
92987 + int mod = i % 32;
92988 + ret ^=(unsigned int) (word[i]) << mod;
92989 + ret ^=(unsigned int) (word[i]) >> (32 - mod);
92990 + }
92991 + return ret;
92992 +}
92993 +
92994 +VOID Sta_Announce_or_Forward_802_3_Packet(
92995 + IN PRTMP_ADAPTER pAd,
92996 + IN PNDIS_PACKET pPacket,
92997 + IN UCHAR FromWhichBSSID)
92998 +{
92999 + if (TRUE
93000 + )
93001 + {
93002 + announce_802_3_packet(pAd, pPacket);
93003 + }
93004 + else
93005 + {
93006 + // release packet
93007 + RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
93008 + }
93009 +}
93010 +
93011 --- /dev/null
93012 +++ b/drivers/staging/rt3070/sta/sanity.c
93013 @@ -0,0 +1,420 @@
93014 +/*
93015 + *************************************************************************
93016 + * Ralink Tech Inc.
93017 + * 5F., No.36, Taiyuan St., Jhubei City,
93018 + * Hsinchu County 302,
93019 + * Taiwan, R.O.C.
93020 + *
93021 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
93022 + *
93023 + * This program is free software; you can redistribute it and/or modify *
93024 + * it under the terms of the GNU General Public License as published by *
93025 + * the Free Software Foundation; either version 2 of the License, or *
93026 + * (at your option) any later version. *
93027 + * *
93028 + * This program is distributed in the hope that it will be useful, *
93029 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
93030 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
93031 + * GNU General Public License for more details. *
93032 + * *
93033 + * You should have received a copy of the GNU General Public License *
93034 + * along with this program; if not, write to the *
93035 + * Free Software Foundation, Inc., *
93036 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
93037 + * *
93038 + *************************************************************************
93039 +
93040 + Module Name:
93041 + sanity.c
93042 +
93043 + Abstract:
93044 +
93045 + Revision History:
93046 + Who When What
93047 + -------- ---------- ----------------------------------------------
93048 + John Chang 2004-09-01 add WMM support
93049 +*/
93050 +#include "../rt_config.h"
93051 +
93052 +extern UCHAR CISCO_OUI[];
93053 +
93054 +extern UCHAR WPA_OUI[];
93055 +extern UCHAR RSN_OUI[];
93056 +extern UCHAR WME_INFO_ELEM[];
93057 +extern UCHAR WME_PARM_ELEM[];
93058 +extern UCHAR Ccx2QosInfo[];
93059 +extern UCHAR RALINK_OUI[];
93060 +extern UCHAR BROADCOM_OUI[];
93061 +
93062 +/*
93063 + ==========================================================================
93064 + Description:
93065 + MLME message sanity check
93066 + Return:
93067 + TRUE if all parameters are OK, FALSE otherwise
93068 + ==========================================================================
93069 + */
93070 +BOOLEAN MlmeStartReqSanity(
93071 + IN PRTMP_ADAPTER pAd,
93072 + IN VOID *Msg,
93073 + IN ULONG MsgLen,
93074 + OUT CHAR Ssid[],
93075 + OUT UCHAR *pSsidLen)
93076 +{
93077 + MLME_START_REQ_STRUCT *Info;
93078 +
93079 + Info = (MLME_START_REQ_STRUCT *)(Msg);
93080 +
93081 + if (Info->SsidLen > MAX_LEN_OF_SSID)
93082 + {
93083 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqSanity fail - wrong SSID length\n"));
93084 + return FALSE;
93085 + }
93086 +
93087 + *pSsidLen = Info->SsidLen;
93088 + NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
93089 +
93090 + return TRUE;
93091 +}
93092 +
93093 +/*
93094 + ==========================================================================
93095 + Description:
93096 + MLME message sanity check
93097 + Return:
93098 + TRUE if all parameters are OK, FALSE otherwise
93099 +
93100 + IRQL = DISPATCH_LEVEL
93101 +
93102 + ==========================================================================
93103 + */
93104 +BOOLEAN PeerAssocRspSanity(
93105 + IN PRTMP_ADAPTER pAd,
93106 + IN VOID *pMsg,
93107 + IN ULONG MsgLen,
93108 + OUT PUCHAR pAddr2,
93109 + OUT USHORT *pCapabilityInfo,
93110 + OUT USHORT *pStatus,
93111 + OUT USHORT *pAid,
93112 + OUT UCHAR SupRate[],
93113 + OUT UCHAR *pSupRateLen,
93114 + OUT UCHAR ExtRate[],
93115 + OUT UCHAR *pExtRateLen,
93116 + OUT HT_CAPABILITY_IE *pHtCapability,
93117 + OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
93118 + OUT UCHAR *pHtCapabilityLen,
93119 + OUT UCHAR *pAddHtInfoLen,
93120 + OUT UCHAR *pNewExtChannelOffset,
93121 + OUT PEDCA_PARM pEdcaParm,
93122 + OUT UCHAR *pCkipFlag)
93123 +{
93124 + CHAR IeType, *Ptr;
93125 + PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
93126 + PEID_STRUCT pEid;
93127 + ULONG Length = 0;
93128 +
93129 + *pNewExtChannelOffset = 0xff;
93130 + *pHtCapabilityLen = 0;
93131 + *pAddHtInfoLen = 0;
93132 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
93133 + Ptr = pFrame->Octet;
93134 + Length += LENGTH_802_11;
93135 +
93136 + NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);
93137 + Length += 2;
93138 + NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);
93139 + Length += 2;
93140 + *pCkipFlag = 0;
93141 + *pExtRateLen = 0;
93142 + pEdcaParm->bValid = FALSE;
93143 +
93144 + if (*pStatus != MLME_SUCCESS)
93145 + return TRUE;
93146 +
93147 + NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
93148 + Length += 2;
93149 +
93150 + // Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform
93151 + *pAid = (*pAid) & 0x3fff; // AID is low 14-bit
93152 +
93153 + // -- get supported rates from payload and advance the pointer
93154 + IeType = pFrame->Octet[6];
93155 + *pSupRateLen = pFrame->Octet[7];
93156 + if ((IeType != IE_SUPP_RATES) || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES))
93157 + {
93158 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));
93159 + return FALSE;
93160 + }
93161 + else
93162 + NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);
93163 +
93164 + Length = Length + 2 + *pSupRateLen;
93165 +
93166 + // many AP implement proprietary IEs in non-standard order, we'd better
93167 + // tolerate mis-ordered IEs to get best compatibility
93168 + pEid = (PEID_STRUCT) &pFrame->Octet[8 + (*pSupRateLen)];
93169 +
93170 + // get variable fields from payload and advance the pointer
93171 + while ((Length + 2 + pEid->Len) <= MsgLen)
93172 + {
93173 + switch (pEid->Eid)
93174 + {
93175 + case IE_EXT_SUPP_RATES:
93176 + if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
93177 + {
93178 + NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
93179 + *pExtRateLen = pEid->Len;
93180 + }
93181 + break;
93182 +
93183 + case IE_HT_CAP:
93184 + case IE_HT_CAP2:
93185 + if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!
93186 + {
93187 + NdisMoveMemory(pHtCapability, pEid->Octet, SIZE_HT_CAP_IE);
93188 +
93189 + *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
93190 + *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
93191 +
93192 + *pHtCapabilityLen = SIZE_HT_CAP_IE;
93193 + }
93194 + else
93195 + {
93196 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));
93197 + }
93198 +
93199 + break;
93200 +#ifdef DOT11_N_SUPPORT
93201 + case IE_ADD_HT:
93202 + case IE_ADD_HT2:
93203 + if (pEid->Len >= sizeof(ADD_HT_INFO_IE))
93204 + {
93205 + // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only
93206 + // copy first sizeof(ADD_HT_INFO_IE)
93207 + NdisMoveMemory(pAddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));
93208 +
93209 + *(USHORT *)(&pAddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo2));
93210 + *(USHORT *)(&pAddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo3));
93211 +
93212 + *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;
93213 + }
93214 + else
93215 + {
93216 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));
93217 + }
93218 +
93219 + break;
93220 + case IE_SECONDARY_CH_OFFSET:
93221 + if (pEid->Len == 1)
93222 + {
93223 + *pNewExtChannelOffset = pEid->Octet[0];
93224 + }
93225 + else
93226 + {
93227 + DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
93228 + }
93229 +#endif // DOT11_N_SUPPORT //
93230 + break;
93231 + case IE_AIRONET_CKIP:
93232 + // 0. Check Aironet IE length, it must be larger or equal to 28
93233 + // Cisco's AP VxWork version(will not be supported) used this IE length as 28
93234 + // Cisco's AP IOS version used this IE length as 30
93235 + if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
93236 + break;
93237 +
93238 + // 1. Copy CKIP flag byte to buffer for process
93239 + *pCkipFlag = *(pEid->Octet + 8);
93240 + break;
93241 +
93242 + case IE_AIRONET_IPADDRESS:
93243 + if (pEid->Len != 0x0A)
93244 + break;
93245 +
93246 + // Get Cisco Aironet IP information
93247 + if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
93248 + NdisMoveMemory(pAd->StaCfg.AironetIPAddress, pEid->Octet + 4, 4);
93249 + break;
93250 +
93251 + // CCX2, WMM use the same IE value
93252 + // case IE_CCX_V2:
93253 + case IE_VENDOR_SPECIFIC:
93254 + // handle WME PARAMTER ELEMENT
93255 + if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))
93256 + {
93257 + PUCHAR ptr;
93258 + int i;
93259 +
93260 + // parsing EDCA parameters
93261 + pEdcaParm->bValid = TRUE;
93262 + pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
93263 + pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
93264 + pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
93265 + //pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80;
93266 + pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
93267 + pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
93268 + ptr = &pEid->Octet[8];
93269 + for (i=0; i<4; i++)
93270 + {
93271 + UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX
93272 + pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM
93273 + pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN
93274 + pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin
93275 + pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax
93276 + pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us
93277 + ptr += 4; // point to next AC
93278 + }
93279 + }
93280 +
93281 + // handle CCX IE
93282 + else
93283 + {
93284 + // 0. Check the size and CCX admin control
93285 + if (pAd->StaCfg.CCXControl.field.Enable == 0)
93286 + break;
93287 + if (pEid->Len != 5)
93288 + break;
93289 +
93290 + // Turn CCX2 if matched
93291 + if (NdisEqualMemory(pEid->Octet, Ccx2IeInfo, 5) == 1)
93292 + pAd->StaCfg.CCXEnable = TRUE;
93293 + break;
93294 + }
93295 + break;
93296 +
93297 + default:
93298 + DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity - ignore unrecognized EID = %d\n", pEid->Eid));
93299 + break;
93300 + }
93301 +
93302 + Length = Length + 2 + pEid->Len;
93303 + pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
93304 + }
93305 +
93306 + // Force CCX2 enable to TRUE for those AP didn't replay CCX v2 IE, we still force it to be on
93307 + if (pAd->StaCfg.CCXControl.field.Enable == 1)
93308 + pAd->StaCfg.CCXEnable = TRUE;
93309 +
93310 + return TRUE;
93311 +}
93312 +
93313 +/*
93314 + ==========================================================================
93315 + Description:
93316 + MLME message sanity check
93317 + Return:
93318 + TRUE if all parameters are OK, FALSE otherwise
93319 +
93320 + IRQL = DISPATCH_LEVEL
93321 +
93322 + ==========================================================================
93323 + */
93324 +BOOLEAN PeerProbeReqSanity(
93325 + IN PRTMP_ADAPTER pAd,
93326 + IN VOID *Msg,
93327 + IN ULONG MsgLen,
93328 + OUT PUCHAR pAddr2,
93329 + OUT CHAR Ssid[],
93330 + OUT UCHAR *pSsidLen)
93331 +{
93332 + UCHAR Idx;
93333 + UCHAR RateLen;
93334 + CHAR IeType;
93335 + PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
93336 +
93337 + COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
93338 +
93339 + if ((pFrame->Octet[0] != IE_SSID) || (pFrame->Octet[1] > MAX_LEN_OF_SSID))
93340 + {
93341 + DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",pFrame->Octet[0],pFrame->Octet[1]));
93342 + return FALSE;
93343 + }
93344 +
93345 + *pSsidLen = pFrame->Octet[1];
93346 + NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);
93347 +
93348 + Idx = *pSsidLen + 2;
93349 +
93350 + // -- get supported rates from payload and advance the pointer
93351 + IeType = pFrame->Octet[Idx];
93352 + RateLen = pFrame->Octet[Idx + 1];
93353 + if (IeType != IE_SUPP_RATES)
93354 + {
93355 + DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",pFrame->Octet[Idx],pFrame->Octet[Idx+1]));
93356 + return FALSE;
93357 + }
93358 + else
93359 + {
93360 + if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))
93361 + return (FALSE);
93362 + }
93363 +
93364 + return TRUE;
93365 +}
93366 +
93367 +/*
93368 + ==========================================================================
93369 + Description:
93370 +
93371 + IRQL = DISPATCH_LEVEL
93372 +
93373 + ==========================================================================
93374 + */
93375 +BOOLEAN GetTimBit(
93376 + IN CHAR *Ptr,
93377 + IN USHORT Aid,
93378 + OUT UCHAR *TimLen,
93379 + OUT UCHAR *BcastFlag,
93380 + OUT UCHAR *DtimCount,
93381 + OUT UCHAR *DtimPeriod,
93382 + OUT UCHAR *MessageToMe)
93383 +{
93384 + UCHAR BitCntl, N1, N2, MyByte, MyBit;
93385 + CHAR *IdxPtr;
93386 +
93387 + IdxPtr = Ptr;
93388 +
93389 + IdxPtr ++;
93390 + *TimLen = *IdxPtr;
93391 +
93392 + // get DTIM Count from TIM element
93393 + IdxPtr ++;
93394 + *DtimCount = *IdxPtr;
93395 +
93396 + // get DTIM Period from TIM element
93397 + IdxPtr++;
93398 + *DtimPeriod = *IdxPtr;
93399 +
93400 + // get Bitmap Control from TIM element
93401 + IdxPtr++;
93402 + BitCntl = *IdxPtr;
93403 +
93404 + if ((*DtimCount == 0) && (BitCntl & 0x01))
93405 + *BcastFlag = TRUE;
93406 + else
93407 + *BcastFlag = FALSE;
93408 +
93409 + // Parse Partial Virtual Bitmap from TIM element
93410 + N1 = BitCntl & 0xfe; // N1 is the first bitmap byte#
93411 + N2 = *TimLen - 4 + N1; // N2 is the last bitmap byte#
93412 +
93413 + if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))
93414 + *MessageToMe = FALSE;
93415 + else
93416 + {
93417 + MyByte = (Aid >> 3) - N1; // my byte position in the bitmap byte-stream
93418 + MyBit = Aid % 16 - ((MyByte & 0x01)? 8:0);
93419 +
93420 + IdxPtr += (MyByte + 1);
93421 +
93422 + //if (*IdxPtr)
93423 + // DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr));
93424 +
93425 + if (*IdxPtr & (0x01 << MyBit))
93426 + *MessageToMe = TRUE;
93427 + else
93428 + *MessageToMe = FALSE;
93429 + }
93430 +
93431 + return TRUE;
93432 +}
93433 +
93434 --- /dev/null
93435 +++ b/drivers/staging/rt3070/sta/sync.c
93436 @@ -0,0 +1,1755 @@
93437 +/*
93438 + *************************************************************************
93439 + * Ralink Tech Inc.
93440 + * 5F., No.36, Taiyuan St., Jhubei City,
93441 + * Hsinchu County 302,
93442 + * Taiwan, R.O.C.
93443 + *
93444 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
93445 + *
93446 + * This program is free software; you can redistribute it and/or modify *
93447 + * it under the terms of the GNU General Public License as published by *
93448 + * the Free Software Foundation; either version 2 of the License, or *
93449 + * (at your option) any later version. *
93450 + * *
93451 + * This program is distributed in the hope that it will be useful, *
93452 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
93453 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
93454 + * GNU General Public License for more details. *
93455 + * *
93456 + * You should have received a copy of the GNU General Public License *
93457 + * along with this program; if not, write to the *
93458 + * Free Software Foundation, Inc., *
93459 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
93460 + * *
93461 + *************************************************************************
93462 +
93463 + Module Name:
93464 + sync.c
93465 +
93466 + Abstract:
93467 +
93468 + Revision History:
93469 + Who When What
93470 + -------- ---------- ----------------------------------------------
93471 + John Chang 2004-09-01 modified for rt2561/2661
93472 + Jan Lee 2006-08-01 modified for rt2860 for 802.11n
93473 +*/
93474 +#include "../rt_config.h"
93475 +
93476 +#define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) // 2 sec
93477 +
93478 +/*
93479 + ==========================================================================
93480 + Description:
93481 + The sync state machine,
93482 + Parameters:
93483 + Sm - pointer to the state machine
93484 + Note:
93485 + the state machine looks like the following
93486 +
93487 + ==========================================================================
93488 + */
93489 +VOID SyncStateMachineInit(
93490 + IN PRTMP_ADAPTER pAd,
93491 + IN STATE_MACHINE *Sm,
93492 + OUT STATE_MACHINE_FUNC Trans[])
93493 +{
93494 + StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG, (STATE_MACHINE_FUNC)Drop, SYNC_IDLE, SYNC_MACHINE_BASE);
93495 +
93496 + // column 1
93497 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)MlmeScanReqAction);
93498 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)MlmeJoinReqAction);
93499 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)MlmeStartReqAction);
93500 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeacon);
93501 + StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ, (STATE_MACHINE_FUNC)PeerProbeReqAction);
93502 +
93503 + //column 2
93504 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
93505 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
93506 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
93507 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtJoinAction);
93508 + StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT, (STATE_MACHINE_FUNC)BeaconTimeoutAtJoinAction);
93509 +
93510 + // column 3
93511 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
93512 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
93513 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
93514 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
93515 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
93516 + StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT, (STATE_MACHINE_FUNC)ScanTimeoutAction);
93517 +
93518 + // timer init
93519 + RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer, GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE);
93520 + RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer, GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE);
93521 +}
93522 +
93523 +/*
93524 + ==========================================================================
93525 + Description:
93526 + Beacon timeout handler, executed in timer thread
93527 +
93528 + IRQL = DISPATCH_LEVEL
93529 +
93530 + ==========================================================================
93531 + */
93532 +VOID BeaconTimeout(
93533 + IN PVOID SystemSpecific1,
93534 + IN PVOID FunctionContext,
93535 + IN PVOID SystemSpecific2,
93536 + IN PVOID SystemSpecific3)
93537 +{
93538 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
93539 +
93540 + DBGPRINT(RT_DEBUG_TRACE,("SYNC - BeaconTimeout\n"));
93541 +
93542 + // Do nothing if the driver is starting halt state.
93543 + // This might happen when timer already been fired before cancel timer with mlmehalt
93544 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
93545 + return;
93546 +
93547 +#ifdef DOT11_N_SUPPORT
93548 + if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
93549 + )
93550 + {
93551 + UCHAR BBPValue = 0;
93552 + AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
93553 + AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
93554 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
93555 + BBPValue &= (~0x18);
93556 + BBPValue |= 0x10;
93557 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
93558 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
93559 + }
93560 +#endif // DOT11_N_SUPPORT //
93561 +
93562 + MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL);
93563 + RT28XX_MLME_HANDLER(pAd);
93564 +}
93565 +
93566 +/*
93567 + ==========================================================================
93568 + Description:
93569 + Scan timeout handler, executed in timer thread
93570 +
93571 + IRQL = DISPATCH_LEVEL
93572 +
93573 + ==========================================================================
93574 + */
93575 +VOID ScanTimeout(
93576 + IN PVOID SystemSpecific1,
93577 + IN PVOID FunctionContext,
93578 + IN PVOID SystemSpecific2,
93579 + IN PVOID SystemSpecific3)
93580 +{
93581 + RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
93582 +
93583 +
93584 + // Do nothing if the driver is starting halt state.
93585 + // This might happen when timer already been fired before cancel timer with mlmehalt
93586 + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
93587 + return;
93588 +
93589 + if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL))
93590 + {
93591 + RT28XX_MLME_HANDLER(pAd);
93592 + }
93593 + else
93594 + {
93595 + // To prevent SyncMachine.CurrState is SCAN_LISTEN forever.
93596 + pAd->MlmeAux.Channel = 0;
93597 + ScanNextChannel(pAd);
93598 + if (pAd->CommonCfg.bWirelessEvent)
93599 + {
93600 + RTMPSendWirelessEvent(pAd, IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
93601 + }
93602 + }
93603 +}
93604 +
93605 +/*
93606 + ==========================================================================
93607 + Description:
93608 + MLME SCAN req state machine procedure
93609 + ==========================================================================
93610 + */
93611 +VOID MlmeScanReqAction(
93612 + IN PRTMP_ADAPTER pAd,
93613 + IN MLME_QUEUE_ELEM *Elem)
93614 +{
93615 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0;
93616 + BOOLEAN TimerCancelled;
93617 + ULONG Now;
93618 + USHORT Status;
93619 + PHEADER_802_11 pHdr80211;
93620 + PUCHAR pOutBuffer = NULL;
93621 + NDIS_STATUS NStatus;
93622 +
93623 + // Check the total scan tries for one single OID command
93624 + // If this is the CCX 2.0 Case, skip that!
93625 + if ( !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
93626 + {
93627 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeScanReqAction before Startup\n"));
93628 + return;
93629 + }
93630 +
93631 + // Increase the scan retry counters.
93632 + pAd->StaCfg.ScanCnt++;
93633 +
93634 +
93635 + // first check the parameter sanity
93636 + if (MlmeScanReqSanity(pAd,
93637 + Elem->Msg,
93638 + Elem->MsgLen,
93639 + &BssType,
93640 + Ssid,
93641 + &SsidLen,
93642 + &ScanType))
93643 + {
93644 +
93645 + // Check for channel load and noise hist request
93646 + // Suspend MSDU only at scan request, not the last two mentioned
93647 + if ((ScanType == SCAN_CISCO_NOISE) || (ScanType == SCAN_CISCO_CHANNEL_LOAD))
93648 + {
93649 + if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
93650 + RTMPSuspendMsduTransmission(pAd); // Suspend MSDU transmission here
93651 + }
93652 + else
93653 + {
93654 + // Suspend MSDU transmission here
93655 + RTMPSuspendMsduTransmission(pAd);
93656 + }
93657 +
93658 + //
93659 + // To prevent data lost.
93660 + // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.
93661 + // And should send an NULL data with turned PSM bit off to AP, when scan progress done
93662 + //
93663 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))
93664 + {
93665 + NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);
93666 + if (NStatus == NDIS_STATUS_SUCCESS)
93667 + {
93668 + pHdr80211 = (PHEADER_802_11) pOutBuffer;
93669 + MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
93670 + pHdr80211->Duration = 0;
93671 + pHdr80211->FC.Type = BTYPE_DATA;
93672 + pHdr80211->FC.PwrMgmt = PWR_SAVE;
93673 +
93674 + // Send using priority queue
93675 + MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
93676 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n"));
93677 + MlmeFreeMemory(pAd, pOutBuffer);
93678 + RTMPusecDelay(5000);
93679 + }
93680 + }
93681 +
93682 + NdisGetSystemUpTime(&Now);
93683 + pAd->StaCfg.LastScanTime = Now;
93684 + // reset all the timers
93685 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
93686 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
93687 +
93688 + // record desired BSS parameters
93689 + pAd->MlmeAux.BssType = BssType;
93690 + pAd->MlmeAux.ScanType = ScanType;
93691 + pAd->MlmeAux.SsidLen = SsidLen;
93692 + NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
93693 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
93694 +
93695 + // start from the first channel
93696 + pAd->MlmeAux.Channel = FirstChannel(pAd);
93697 +
93698 + // Change the scan channel when dealing with CCX beacon report
93699 + if ((ScanType == SCAN_CISCO_PASSIVE) || (ScanType == SCAN_CISCO_ACTIVE) ||
93700 + (ScanType == SCAN_CISCO_CHANNEL_LOAD) || (ScanType == SCAN_CISCO_NOISE))
93701 + pAd->MlmeAux.Channel = pAd->StaCfg.CCXScanChannel;
93702 +
93703 + // Let BBP register at 20MHz to do scan
93704 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
93705 + BBPValue &= (~0x18);
93706 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
93707 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
93708 + ScanNextChannel(pAd);
93709 + }
93710 + else
93711 + {
93712 + DBGPRINT_ERR(("SYNC - MlmeScanReqAction() sanity check fail\n"));
93713 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93714 + Status = MLME_INVALID_FORMAT;
93715 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
93716 + }
93717 +}
93718 +
93719 +/*
93720 + ==========================================================================
93721 + Description:
93722 + MLME JOIN req state machine procedure
93723 + ==========================================================================
93724 + */
93725 +VOID MlmeJoinReqAction(
93726 + IN PRTMP_ADAPTER pAd,
93727 + IN MLME_QUEUE_ELEM *Elem)
93728 +{
93729 + UCHAR BBPValue = 0;
93730 + BSS_ENTRY *pBss;
93731 + BOOLEAN TimerCancelled;
93732 + HEADER_802_11 Hdr80211;
93733 + NDIS_STATUS NStatus;
93734 + ULONG FrameLen = 0;
93735 + PUCHAR pOutBuffer = NULL;
93736 + PUCHAR pSupRate = NULL;
93737 + UCHAR SupRateLen;
93738 + PUCHAR pExtRate = NULL;
93739 + UCHAR ExtRateLen;
93740 + UCHAR ASupRate[] = {0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C};
93741 + UCHAR ASupRateLen = sizeof(ASupRate)/sizeof(UCHAR);
93742 + MLME_JOIN_REQ_STRUCT *pInfo = (MLME_JOIN_REQ_STRUCT *)(Elem->Msg);
93743 +
93744 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx));
93745 +
93746 +
93747 + // reset all the timers
93748 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
93749 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
93750 +
93751 + pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx];
93752 +
93753 + // record the desired SSID & BSSID we're waiting for
93754 + COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid);
93755 +
93756 + // If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again.
93757 + if (pBss->Hidden == 0)
93758 + {
93759 + NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen);
93760 + pAd->MlmeAux.SsidLen = pBss->SsidLen;
93761 + }
93762 +
93763 + pAd->MlmeAux.BssType = pBss->BssType;
93764 + pAd->MlmeAux.Channel = pBss->Channel;
93765 + pAd->MlmeAux.CentralChannel = pBss->CentralChannel;
93766 +
93767 +#ifdef EXT_BUILD_CHANNEL_LIST
93768 + // Country IE of the AP will be evaluated and will be used.
93769 + if ((pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None) &&
93770 + (pBss->bHasCountryIE == TRUE))
93771 + {
93772 + NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pBss->CountryString[0], 2);
93773 + if (pBss->CountryString[2] == 'I')
93774 + pAd->CommonCfg.Geography = IDOR;
93775 + else if (pBss->CountryString[2] == 'O')
93776 + pAd->CommonCfg.Geography = ODOR;
93777 + else
93778 + pAd->CommonCfg.Geography = BOTH;
93779 + BuildChannelListEx(pAd);
93780 + }
93781 +#endif // EXT_BUILD_CHANNEL_LIST //
93782 +
93783 + // Let BBP register at 20MHz to do scan
93784 + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
93785 + BBPValue &= (~0x18);
93786 + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
93787 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
93788 +
93789 + // switch channel and waiting for beacon timer
93790 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
93791 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
93792 + RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT);
93793 +
93794 + do
93795 + {
93796 + if (((pAd->CommonCfg.bIEEE80211H == 1) &&
93797 + (pAd->MlmeAux.Channel > 14) &&
93798 + RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
93799 +#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
93800 + || (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
93801 +#endif // CARRIER_DETECTION_SUPPORT //
93802 + )
93803 + {
93804 + //
93805 + // We can't send any Probe request frame to meet 802.11h.
93806 + //
93807 + if (pBss->Hidden == 0)
93808 + break;
93809 + }
93810 +
93811 + //
93812 + // send probe request
93813 + //
93814 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
93815 + if (NStatus == NDIS_STATUS_SUCCESS)
93816 + {
93817 + if (pAd->MlmeAux.Channel <= 14)
93818 + {
93819 + pSupRate = pAd->CommonCfg.SupRate;
93820 + SupRateLen = pAd->CommonCfg.SupRateLen;
93821 + pExtRate = pAd->CommonCfg.ExtRate;
93822 + ExtRateLen = pAd->CommonCfg.ExtRateLen;
93823 + }
93824 + else
93825 + {
93826 + //
93827 + // Overwrite Support Rate, CCK rate are not allowed
93828 + //
93829 + pSupRate = ASupRate;
93830 + SupRateLen = ASupRateLen;
93831 + ExtRateLen = 0;
93832 + }
93833 +
93834 + if (pAd->MlmeAux.BssType == BSS_INFRA)
93835 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, pAd->MlmeAux.Bssid, pAd->MlmeAux.Bssid);
93836 + else
93837 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
93838 +
93839 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
93840 + sizeof(HEADER_802_11), &Hdr80211,
93841 + 1, &SsidIe,
93842 + 1, &pAd->MlmeAux.SsidLen,
93843 + pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
93844 + 1, &SupRateIe,
93845 + 1, &SupRateLen,
93846 + SupRateLen, pSupRate,
93847 + END_OF_ARGS);
93848 +
93849 + if (ExtRateLen)
93850 + {
93851 + ULONG Tmp;
93852 + MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
93853 + 1, &ExtRateIe,
93854 + 1, &ExtRateLen,
93855 + ExtRateLen, pExtRate,
93856 + END_OF_ARGS);
93857 + FrameLen += Tmp;
93858 + }
93859 +
93860 +
93861 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
93862 + MlmeFreeMemory(pAd, pOutBuffer);
93863 + }
93864 + } while (FALSE);
93865 +
93866 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Switch to ch %d, Wait BEACON from %02x:%02x:%02x:%02x:%02x:%02x\n",
93867 + pBss->Channel, pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2], pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
93868 +
93869 + pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON;
93870 +}
93871 +
93872 +/*
93873 + ==========================================================================
93874 + Description:
93875 + MLME START Request state machine procedure, starting an IBSS
93876 + ==========================================================================
93877 + */
93878 +VOID MlmeStartReqAction(
93879 + IN PRTMP_ADAPTER pAd,
93880 + IN MLME_QUEUE_ELEM *Elem)
93881 +{
93882 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen;
93883 + BOOLEAN TimerCancelled;
93884 +
93885 + // New for WPA security suites
93886 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
93887 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
93888 + LARGE_INTEGER TimeStamp;
93889 + BOOLEAN Privacy;
93890 + USHORT Status;
93891 +
93892 + // Init Variable IE structure
93893 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
93894 + pVIE->Length = 0;
93895 + TimeStamp.u.LowPart = 0;
93896 + TimeStamp.u.HighPart = 0;
93897 +
93898 + if (MlmeStartReqSanity(pAd, Elem->Msg, Elem->MsgLen, Ssid, &SsidLen))
93899 + {
93900 + // reset all the timers
93901 + RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
93902 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
93903 +
93904 + //
93905 + // Start a new IBSS. All IBSS parameters are decided now....
93906 + //
93907 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n"));
93908 + pAd->MlmeAux.BssType = BSS_ADHOC;
93909 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
93910 + pAd->MlmeAux.SsidLen = SsidLen;
93911 +
93912 + // generate a radom number as BSSID
93913 + MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid);
93914 + DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - generate a radom number as BSSID \n"));
93915 +
93916 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
93917 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
93918 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
93919 + pAd->MlmeAux.CapabilityInfo = CAP_GENERATE(0,1,Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 1, 0);
93920 + pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod;
93921 + pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin;
93922 + pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;
93923 +
93924 + pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
93925 + pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel;
93926 +
93927 + pAd->MlmeAux.SupRateLen= pAd->CommonCfg.SupRateLen;
93928 + NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
93929 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
93930 + pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen;
93931 + NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
93932 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
93933 +#ifdef DOT11_N_SUPPORT
93934 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
93935 + {
93936 + RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy, &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0], &pAd->MlmeAux.HtCapability, &pAd->MlmeAux.AddHtInfo);
93937 + pAd->MlmeAux.HtCapabilityLen = sizeof(HT_CAPABILITY_IE);
93938 + // Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here.
93939 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n"));
93940 + }
93941 + else
93942 +#endif // DOT11_N_SUPPORT //
93943 + {
93944 + pAd->MlmeAux.HtCapabilityLen = 0;
93945 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
93946 + }
93947 + // temporarily not support QOS in IBSS
93948 + NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
93949 + NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
93950 + NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
93951 +
93952 + AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
93953 + AsicLockChannel(pAd, pAd->MlmeAux.Channel);
93954 +
93955 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n",
93956 + pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
93957 +
93958 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93959 + Status = MLME_SUCCESS;
93960 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
93961 + }
93962 + else
93963 + {
93964 + DBGPRINT_ERR(("SYNC - MlmeStartReqAction() sanity check fail.\n"));
93965 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
93966 + Status = MLME_INVALID_FORMAT;
93967 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
93968 + }
93969 +}
93970 +
93971 +/*
93972 + ==========================================================================
93973 + Description:
93974 + peer sends beacon back when scanning
93975 + ==========================================================================
93976 + */
93977 +VOID PeerBeaconAtScanAction(
93978 + IN PRTMP_ADAPTER pAd,
93979 + IN MLME_QUEUE_ELEM *Elem)
93980 +{
93981 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
93982 + UCHAR Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel,
93983 + SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe;
93984 + CF_PARM CfParm;
93985 + USHORT BeaconPeriod, AtimWin, CapabilityInfo;
93986 + PFRAME_802_11 pFrame;
93987 + LARGE_INTEGER TimeStamp;
93988 + UCHAR Erp;
93989 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
93990 + UCHAR SupRateLen, ExtRateLen;
93991 + USHORT LenVIE;
93992 + UCHAR CkipFlag;
93993 + UCHAR AironetCellPowerLimit;
93994 + EDCA_PARM EdcaParm;
93995 + QBSS_LOAD_PARM QbssLoad;
93996 + QOS_CAPABILITY_PARM QosCapability;
93997 + ULONG RalinkIe;
93998 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
93999 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
94000 + HT_CAPABILITY_IE HtCapability;
94001 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
94002 + UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
94003 + UCHAR AddHtInfoLen;
94004 + UCHAR NewExtChannelOffset = 0xff;
94005 +
94006 +
94007 + // NdisFillMemory(Ssid, MAX_LEN_OF_SSID, 0x00);
94008 + pFrame = (PFRAME_802_11) Elem->Msg;
94009 + // Init Variable IE structure
94010 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
94011 + pVIE->Length = 0;
94012 +#ifdef DOT11_N_SUPPORT
94013 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
94014 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
94015 +#endif // DOT11_N_SUPPORT //
94016 +
94017 + if (PeerBeaconAndProbeRspSanity(pAd,
94018 + Elem->Msg,
94019 + Elem->MsgLen,
94020 + Elem->Channel,
94021 + Addr2,
94022 + Bssid,
94023 + Ssid,
94024 + &SsidLen,
94025 + &BssType,
94026 + &BeaconPeriod,
94027 + &Channel,
94028 + &NewChannel,
94029 + &TimeStamp,
94030 + &CfParm,
94031 + &AtimWin,
94032 + &CapabilityInfo,
94033 + &Erp,
94034 + &DtimCount,
94035 + &DtimPeriod,
94036 + &BcastFlag,
94037 + &MessageToMe,
94038 + SupRate,
94039 + &SupRateLen,
94040 + ExtRate,
94041 + &ExtRateLen,
94042 + &CkipFlag,
94043 + &AironetCellPowerLimit,
94044 + &EdcaParm,
94045 + &QbssLoad,
94046 + &QosCapability,
94047 + &RalinkIe,
94048 + &HtCapabilityLen,
94049 + &PreNHtCapabilityLen,
94050 + &HtCapability,
94051 + &AddHtInfoLen,
94052 + &AddHtInfo,
94053 + &NewExtChannelOffset,
94054 + &LenVIE,
94055 + pVIE))
94056 + {
94057 + ULONG Idx;
94058 + CHAR Rssi = 0;
94059 +
94060 + Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
94061 + if (Idx != BSS_NOT_FOUND)
94062 + Rssi = pAd->ScanTab.BssEntry[Idx].Rssi;
94063 +
94064 + Rssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
94065 +
94066 +
94067 +#ifdef DOT11_N_SUPPORT
94068 + if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
94069 + HtCapabilityLen = SIZE_HT_CAP_IE;
94070 +#endif // DOT11_N_SUPPORT //
94071 + if ((pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) && (Channel == pAd->StaCfg.CCXScanChannel))
94072 + {
94073 + Idx = BssTableSetEntry(pAd, &pAd->StaCfg.CCXBssTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
94074 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen,ExtRate, ExtRateLen, &HtCapability,
94075 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
94076 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
94077 + if (Idx != BSS_NOT_FOUND)
94078 + {
94079 + NdisMoveMemory(pAd->StaCfg.CCXBssTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
94080 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
94081 + NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
94082 + if (pAd->StaCfg.CCXReqType == MSRN_TYPE_BEACON_REQ)
94083 + AironetAddBeaconReport(pAd, Idx, Elem);
94084 + }
94085 + }
94086 + else
94087 + {
94088 + Idx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
94089 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
94090 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
94091 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
94092 +#ifdef DOT11_N_SUPPORT
94093 +#ifdef DOT11N_DRAFT3
94094 + if (pAd->ChannelList[pAd->CommonCfg.ChannelListIdx].bEffectedChannel == TRUE)
94095 + {
94096 + UCHAR RegClass;
94097 + PeerBeaconAndProbeRspSanity2(pAd, Elem->Msg, Elem->MsgLen, &RegClass);
94098 + TriEventTableSetEntry(pAd, &pAd->CommonCfg.TriggerEventTab, Bssid, &HtCapability, HtCapabilityLen, RegClass, Channel);
94099 + }
94100 +#endif // DOT11N_DRAFT3 //
94101 +#endif // DOT11_N_SUPPORT //
94102 + if (Idx != BSS_NOT_FOUND)
94103 + {
94104 + NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
94105 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
94106 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
94107 + }
94108 + }
94109 + }
94110 + // sanity check fail, ignored
94111 +}
94112 +
94113 +/*
94114 + ==========================================================================
94115 + Description:
94116 + When waiting joining the (I)BSS, beacon received from external
94117 + ==========================================================================
94118 + */
94119 +VOID PeerBeaconAtJoinAction(
94120 + IN PRTMP_ADAPTER pAd,
94121 + IN MLME_QUEUE_ELEM *Elem)
94122 +{
94123 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
94124 + UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe,
94125 + DtimCount, DtimPeriod, BcastFlag, NewChannel;
94126 + LARGE_INTEGER TimeStamp;
94127 + USHORT BeaconPeriod, AtimWin, CapabilityInfo;
94128 + CF_PARM Cf;
94129 + BOOLEAN TimerCancelled;
94130 + UCHAR Erp;
94131 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
94132 + UCHAR SupRateLen, ExtRateLen;
94133 + UCHAR CkipFlag;
94134 + USHORT LenVIE;
94135 + UCHAR AironetCellPowerLimit;
94136 + EDCA_PARM EdcaParm;
94137 + QBSS_LOAD_PARM QbssLoad;
94138 + QOS_CAPABILITY_PARM QosCapability;
94139 + USHORT Status;
94140 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
94141 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
94142 + ULONG RalinkIe;
94143 + ULONG Idx;
94144 + HT_CAPABILITY_IE HtCapability;
94145 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
94146 + UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
94147 + UCHAR AddHtInfoLen;
94148 + UCHAR NewExtChannelOffset = 0xff;
94149 +#ifdef DOT11_N_SUPPORT
94150 + UCHAR CentralChannel;
94151 +#endif // DOT11_N_SUPPORT //
94152 +
94153 + // Init Variable IE structure
94154 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
94155 + pVIE->Length = 0;
94156 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
94157 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
94158 +
94159 +
94160 + if (PeerBeaconAndProbeRspSanity(pAd,
94161 + Elem->Msg,
94162 + Elem->MsgLen,
94163 + Elem->Channel,
94164 + Addr2,
94165 + Bssid,
94166 + Ssid,
94167 + &SsidLen,
94168 + &BssType,
94169 + &BeaconPeriod,
94170 + &Channel,
94171 + &NewChannel,
94172 + &TimeStamp,
94173 + &Cf,
94174 + &AtimWin,
94175 + &CapabilityInfo,
94176 + &Erp,
94177 + &DtimCount,
94178 + &DtimPeriod,
94179 + &BcastFlag,
94180 + &MessageToMe,
94181 + SupRate,
94182 + &SupRateLen,
94183 + ExtRate,
94184 + &ExtRateLen,
94185 + &CkipFlag,
94186 + &AironetCellPowerLimit,
94187 + &EdcaParm,
94188 + &QbssLoad,
94189 + &QosCapability,
94190 + &RalinkIe,
94191 + &HtCapabilityLen,
94192 + &PreNHtCapabilityLen,
94193 + &HtCapability,
94194 + &AddHtInfoLen,
94195 + &AddHtInfo,
94196 + &NewExtChannelOffset,
94197 + &LenVIE,
94198 + pVIE))
94199 + {
94200 + // Disqualify 11b only adhoc when we are in 11g only adhoc mode
94201 + if ((BssType == BSS_ADHOC) && (pAd->CommonCfg.PhyMode == PHY_11G) && ((SupRateLen+ExtRateLen)< 12))
94202 + return;
94203 +
94204 + // BEACON from desired BSS/IBSS found. We should be able to decide most
94205 + // BSS parameters here.
94206 + // Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATEION?
94207 + // Do we need to receover back all parameters belonging to previous BSS?
94208 + // A. Should be not. There's no back-door recover to previous AP. It still need
94209 + // a new JOIN-AUTH-ASSOC sequence.
94210 + if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid))
94211 + {
94212 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n", Channel));
94213 + RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
94214 +
94215 + // Update RSSI to prevent No signal display when cards first initialized
94216 + pAd->StaCfg.RssiSample.LastRssi0 = ConvertToRssi(pAd, Elem->Rssi0, RSSI_0);
94217 + pAd->StaCfg.RssiSample.LastRssi1 = ConvertToRssi(pAd, Elem->Rssi1, RSSI_1);
94218 + pAd->StaCfg.RssiSample.LastRssi2 = ConvertToRssi(pAd, Elem->Rssi2, RSSI_2);
94219 + pAd->StaCfg.RssiSample.AvgRssi0 = pAd->StaCfg.RssiSample.LastRssi0;
94220 + pAd->StaCfg.RssiSample.AvgRssi0X8 = pAd->StaCfg.RssiSample.AvgRssi0 << 3;
94221 + pAd->StaCfg.RssiSample.AvgRssi1 = pAd->StaCfg.RssiSample.LastRssi1;
94222 + pAd->StaCfg.RssiSample.AvgRssi1X8 = pAd->StaCfg.RssiSample.AvgRssi1 << 3;
94223 + pAd->StaCfg.RssiSample.AvgRssi2 = pAd->StaCfg.RssiSample.LastRssi2;
94224 + pAd->StaCfg.RssiSample.AvgRssi2X8 = pAd->StaCfg.RssiSample.AvgRssi2 << 3;
94225 +
94226 + //
94227 + // We need to check if SSID only set to any, then we can record the current SSID.
94228 + // Otherwise will cause hidden SSID association failed.
94229 + //
94230 + if (pAd->MlmeAux.SsidLen == 0)
94231 + {
94232 + NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
94233 + pAd->MlmeAux.SsidLen = SsidLen;
94234 + }
94235 + else
94236 + {
94237 + Idx = BssSsidTableSearch(&pAd->ScanTab, Bssid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Channel);
94238 +
94239 + if (Idx != BSS_NOT_FOUND)
94240 + {
94241 + //
94242 + // Multiple SSID case, used correct CapabilityInfo
94243 + //
94244 + CapabilityInfo = pAd->ScanTab.BssEntry[Idx].CapabilityInfo;
94245 + }
94246 + }
94247 + NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN);
94248 + pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
94249 + pAd->MlmeAux.BssType = BssType;
94250 + pAd->MlmeAux.BeaconPeriod = BeaconPeriod;
94251 + pAd->MlmeAux.Channel = Channel;
94252 + pAd->MlmeAux.AtimWin = AtimWin;
94253 + pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod;
94254 + pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;
94255 + pAd->MlmeAux.APRalinkIe = RalinkIe;
94256 +
94257 + // Copy AP's supported rate to MlmeAux for creating assoication request
94258 + // Also filter out not supported rate
94259 + pAd->MlmeAux.SupRateLen = SupRateLen;
94260 + NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
94261 + RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
94262 + pAd->MlmeAux.ExtRateLen = ExtRateLen;
94263 + NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
94264 + RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
94265 +
94266 + NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, 16);
94267 +#ifdef DOT11_N_SUPPORT
94268 + pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
94269 + pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen;
94270 +
94271 + // filter out un-supported ht rates
94272 + if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
94273 + {
94274 + RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
94275 + RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo, &AddHtInfo, SIZE_ADD_HT_INFO_IE);
94276 +
94277 + // StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability
94278 + NdisMoveMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, HtCapability.MCSSet, 16);
94279 + pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
94280 + pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE;
94281 + pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
94282 + if (PreNHtCapabilityLen > 0)
94283 + pAd->StaActive.SupportedPhyInfo.bPreNHt = TRUE;
94284 + RTMPCheckHt(pAd, BSSID_WCID, &HtCapability, &AddHtInfo);
94285 + // Copy AP Parameter to StaActive. This is also in LinkUp.
94286 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n",
94287 + pAd->StaActive.SupportedHtPhy.MpduDensity, pAd->StaActive.SupportedHtPhy.MaxRAmpduFactor, HtCapability.HtCapInfo.ChannelWidth));
94288 +
94289 + if (AddHtInfoLen > 0)
94290 + {
94291 + CentralChannel = AddHtInfo.ControlChan;
94292 + // Check again the Bandwidth capability of this AP.
94293 + if ((AddHtInfo.ControlChan > 2)&& (AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
94294 + {
94295 + CentralChannel = AddHtInfo.ControlChan - 2;
94296 + }
94297 + else if ((AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
94298 + {
94299 + CentralChannel = AddHtInfo.ControlChan + 2;
94300 + }
94301 +
94302 + // Check Error .
94303 + if (pAd->MlmeAux.CentralChannel != CentralChannel)
94304 + DBGPRINT(RT_DEBUG_ERROR, ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n", CentralChannel, AddHtInfo.ControlChan, pAd->MlmeAux.CentralChannel));
94305 +
94306 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n", CentralChannel, AddHtInfo.ControlChan));
94307 +
94308 + }
94309 +
94310 + }
94311 + else
94312 +#endif // DOT11_N_SUPPORT //
94313 + {
94314 + // To prevent error, let legacy AP must have same CentralChannel and Channel.
94315 + if ((HtCapabilityLen == 0) && (PreNHtCapabilityLen == 0))
94316 + pAd->MlmeAux.CentralChannel = pAd->MlmeAux.Channel;
94317 +
94318 + pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
94319 + RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
94320 + RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo, SIZE_ADD_HT_INFO_IE);
94321 + }
94322 +
94323 + RTMPUpdateMlmeRate(pAd);
94324 +
94325 + // copy QOS related information
94326 + if ((pAd->CommonCfg.bWmmCapable)
94327 +#ifdef DOT11_N_SUPPORT
94328 + || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
94329 +#endif // DOT11_N_SUPPORT //
94330 + )
94331 + {
94332 + NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, &EdcaParm, sizeof(EDCA_PARM));
94333 + NdisMoveMemory(&pAd->MlmeAux.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
94334 + NdisMoveMemory(&pAd->MlmeAux.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
94335 + }
94336 + else
94337 + {
94338 + NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
94339 + NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
94340 + NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
94341 + }
94342 +
94343 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n",
94344 + pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
94345 +
94346 +#ifdef LEAP_SUPPORT
94347 + // Update CkipFlag
94348 + pAd->StaCfg.CkipFlag = CkipFlag;
94349 +
94350 + // Keep TimeStamp for Re-Association used.
94351 + if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
94352 + pAd->StaCfg.CCKMBeaconAtJoinTimeStamp = TimeStamp;
94353 +#endif // LEAP_SUPPORT //
94354 +
94355 + if (AironetCellPowerLimit != 0xFF)
94356 + {
94357 + //We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power
94358 + ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
94359 + }
94360 + else //Used the default TX Power Percentage.
94361 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
94362 +
94363 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
94364 + Status = MLME_SUCCESS;
94365 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
94366 + }
94367 + // not to me BEACON, ignored
94368 + }
94369 + // sanity check fail, ignore this frame
94370 +}
94371 +
94372 +/*
94373 + ==========================================================================
94374 + Description:
94375 + receive BEACON from peer
94376 +
94377 + IRQL = DISPATCH_LEVEL
94378 +
94379 + ==========================================================================
94380 + */
94381 +VOID PeerBeacon(
94382 + IN PRTMP_ADAPTER pAd,
94383 + IN MLME_QUEUE_ELEM *Elem)
94384 +{
94385 + UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
94386 + CHAR Ssid[MAX_LEN_OF_SSID];
94387 + CF_PARM CfParm;
94388 + UCHAR SsidLen, MessageToMe=0, BssType, Channel, NewChannel, index=0;
94389 + UCHAR DtimCount=0, DtimPeriod=0, BcastFlag=0;
94390 + USHORT CapabilityInfo, AtimWin, BeaconPeriod;
94391 + LARGE_INTEGER TimeStamp;
94392 + USHORT TbttNumToNextWakeUp;
94393 + UCHAR Erp;
94394 + UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
94395 + UCHAR SupRateLen, ExtRateLen;
94396 + UCHAR CkipFlag;
94397 + USHORT LenVIE;
94398 + UCHAR AironetCellPowerLimit;
94399 + EDCA_PARM EdcaParm;
94400 + QBSS_LOAD_PARM QbssLoad;
94401 + QOS_CAPABILITY_PARM QosCapability;
94402 + ULONG RalinkIe;
94403 + // New for WPA security suites
94404 + UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
94405 + NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
94406 + HT_CAPABILITY_IE HtCapability;
94407 + ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
94408 + UCHAR HtCapabilityLen, PreNHtCapabilityLen;
94409 + UCHAR AddHtInfoLen;
94410 + UCHAR NewExtChannelOffset = 0xff;
94411 +
94412 +
94413 +#ifdef RALINK_ATE
94414 + if (ATE_ON(pAd))
94415 + {
94416 + return;
94417 + }
94418 +#endif // RALINK_ATE //
94419 +
94420 + if (!(INFRA_ON(pAd) || ADHOC_ON(pAd)
94421 + ))
94422 + return;
94423 +
94424 + // Init Variable IE structure
94425 + pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
94426 + pVIE->Length = 0;
94427 + RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
94428 + RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
94429 +
94430 + if (PeerBeaconAndProbeRspSanity(pAd,
94431 + Elem->Msg,
94432 + Elem->MsgLen,
94433 + Elem->Channel,
94434 + Addr2,
94435 + Bssid,
94436 + Ssid,
94437 + &SsidLen,
94438 + &BssType,
94439 + &BeaconPeriod,
94440 + &Channel,
94441 + &NewChannel,
94442 + &TimeStamp,
94443 + &CfParm,
94444 + &AtimWin,
94445 + &CapabilityInfo,
94446 + &Erp,
94447 + &DtimCount,
94448 + &DtimPeriod,
94449 + &BcastFlag,
94450 + &MessageToMe,
94451 + SupRate,
94452 + &SupRateLen,
94453 + ExtRate,
94454 + &ExtRateLen,
94455 + &CkipFlag,
94456 + &AironetCellPowerLimit,
94457 + &EdcaParm,
94458 + &QbssLoad,
94459 + &QosCapability,
94460 + &RalinkIe,
94461 + &HtCapabilityLen,
94462 + &PreNHtCapabilityLen,
94463 + &HtCapability,
94464 + &AddHtInfoLen,
94465 + &AddHtInfo,
94466 + &NewExtChannelOffset,
94467 + &LenVIE,
94468 + pVIE))
94469 + {
94470 + BOOLEAN is_my_bssid, is_my_ssid;
94471 + ULONG Bssidx, Now;
94472 + BSS_ENTRY *pBss;
94473 + CHAR RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
94474 +
94475 + is_my_bssid = MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid)? TRUE : FALSE;
94476 + is_my_ssid = SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen)? TRUE:FALSE;
94477 +
94478 +
94479 + // ignore BEACON not for my SSID
94480 + if ((! is_my_ssid) && (! is_my_bssid))
94481 + return;
94482 +
94483 + // It means STA waits disassoc completely from this AP, ignores this beacon.
94484 + if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC)
94485 + return;
94486 +
94487 +#ifdef DOT11_N_SUPPORT
94488 + // Copy Control channel for this BSSID.
94489 + if (AddHtInfoLen != 0)
94490 + Channel = AddHtInfo.ControlChan;
94491 +
94492 + if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
94493 + HtCapabilityLen = SIZE_HT_CAP_IE;
94494 +#endif // DOT11_N_SUPPORT //
94495 +
94496 + //
94497 + // Housekeeping "SsidBssTab" table for later-on ROAMing usage.
94498 + //
94499 + Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
94500 + if (Bssidx == BSS_NOT_FOUND)
94501 + {
94502 + // discover new AP of this network, create BSS entry
94503 + Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
94504 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,
94505 + &HtCapability, &AddHtInfo,HtCapabilityLen,AddHtInfoLen,NewExtChannelOffset, Channel,
94506 + RealRssi, TimeStamp, CkipFlag, &EdcaParm, &QosCapability,
94507 + &QbssLoad, LenVIE, pVIE);
94508 + if (Bssidx == BSS_NOT_FOUND) // return if BSS table full
94509 + return;
94510 +
94511 + NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF, &Elem->Msg[24], 4);
94512 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
94513 + NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
94514 +
94515 +
94516 +
94517 + }
94518 +
94519 + if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
94520 + {
94521 + // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
94522 + // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
94523 + AsicSwitchChannel(pAd, 1, FALSE);
94524 + AsicLockChannel(pAd, 1);
94525 + LinkDown(pAd, FALSE);
94526 + MlmeQueueInit(&pAd->Mlme.Queue);
94527 + BssTableInit(&pAd->ScanTab);
94528 + RTMPusecDelay(1000000); // use delay to prevent STA do reassoc
94529 +
94530 + // channel sanity check
94531 + for (index = 0 ; index < pAd->ChannelListNum; index++)
94532 + {
94533 + if (pAd->ChannelList[index].Channel == NewChannel)
94534 + {
94535 + pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
94536 + pAd->CommonCfg.Channel = NewChannel;
94537 + AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
94538 + AsicLockChannel(pAd, pAd->CommonCfg.Channel);
94539 + DBGPRINT(RT_DEBUG_TRACE, ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
94540 + break;
94541 + }
94542 + }
94543 +
94544 + if (index >= pAd->ChannelListNum)
94545 + {
94546 + DBGPRINT_ERR(("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
94547 + }
94548 + }
94549 +
94550 + // if the ssid matched & bssid unmatched, we should select the bssid with large value.
94551 + // This might happened when two STA start at the same time
94552 + if ((! is_my_bssid) && ADHOC_ON(pAd))
94553 + {
94554 + INT i;
94555 +
94556 + // Add the safeguard against the mismatch of adhoc wep status
94557 + if (pAd->StaCfg.WepStatus != pAd->ScanTab.BssEntry[Bssidx].WepStatus)
94558 + {
94559 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Not matched wep status %d %d\n", pAd->StaCfg.WepStatus, pAd->ScanTab.BssEntry[Bssidx].WepStatus));
94560 + DBGPRINT(RT_DEBUG_TRACE, ("bssid=%s\n", pAd->ScanTab.BssEntry[Bssidx].Bssid));
94561 + return;
94562 + }
94563 +
94564 + // collapse into the ADHOC network which has bigger BSSID value.
94565 + for (i = 0; i < 6; i++)
94566 + {
94567 + if (Bssid[i] > pAd->CommonCfg.Bssid[i])
94568 + {
94569 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - merge to the IBSS with bigger BSSID=%02x:%02x:%02x:%02x:%02x:%02x\n",
94570 + Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
94571 + AsicDisableSync(pAd);
94572 + COPY_MAC_ADDR(pAd->CommonCfg.Bssid, Bssid);
94573 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
94574 + MakeIbssBeacon(pAd); // re-build BEACON frame
94575 + AsicEnableIbssSync(pAd); // copy BEACON frame to on-chip memory
94576 + is_my_bssid = TRUE;
94577 + break;
94578 + }
94579 + else if (Bssid[i] < pAd->CommonCfg.Bssid[i])
94580 + break;
94581 + }
94582 + }
94583 +
94584 +
94585 + NdisGetSystemUpTime(&Now);
94586 + pBss = &pAd->ScanTab.BssEntry[Bssidx];
94587 + pBss->Rssi = RealRssi; // lastest RSSI
94588 + pBss->LastBeaconRxTime = Now; // last RX timestamp
94589 +
94590 + //
94591 + // BEACON from my BSSID - either IBSS or INFRA network
94592 + //
94593 + if (is_my_bssid)
94594 + {
94595 + RXWI_STRUC RxWI;
94596 +
94597 + pAd->StaCfg.DtimCount = DtimCount;
94598 + pAd->StaCfg.DtimPeriod = DtimPeriod;
94599 + pAd->StaCfg.LastBeaconRxTime = Now;
94600 +
94601 +
94602 + RxWI.RSSI0 = Elem->Rssi0;
94603 + RxWI.RSSI1 = Elem->Rssi1;
94604 + RxWI.RSSI2 = Elem->Rssi2;
94605 +
94606 + Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI);
94607 + if (AironetCellPowerLimit != 0xFF)
94608 + {
94609 + //
94610 + // We get the Cisco (ccx) "TxPower Limit" required
94611 + // Changed to appropriate TxPower Limit for Ciso Compatible Extensions
94612 + //
94613 + ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
94614 + }
94615 + else
94616 + {
94617 + //
94618 + // AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist.
94619 + // Used the default TX Power Percentage, that set from UI.
94620 + //
94621 + pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
94622 + }
94623 +
94624 + if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo)))
94625 + {
94626 + UCHAR MaxSupportedRateIn500Kbps = 0;
94627 + UCHAR idx;
94628 + MAC_TABLE_ENTRY *pEntry;
94629 +
94630 + // supported rates array may not be sorted. sort it and find the maximum rate
94631 + for (idx=0; idx<SupRateLen; idx++)
94632 + {
94633 + if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))
94634 + MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;
94635 + }
94636 +
94637 + for (idx=0; idx<ExtRateLen; idx++)
94638 + {
94639 + if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))
94640 + MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;
94641 + }
94642 +
94643 + // look up the existing table
94644 + pEntry = MacTableLookup(pAd, Addr2);
94645 +
94646 + // Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon.
94647 + // To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station.
94648 + if ((ADHOC_ON(pAd) && (Elem->Wcid == RESERVED_WCID)) ||
94649 + (pEntry && ((pEntry->LastBeaconRxTime + ADHOC_ENTRY_BEACON_LOST_TIME) < Now)))
94650 + {
94651 + if (pEntry == NULL)
94652 + // Another adhoc joining, add to our MAC table.
94653 + pEntry = MacTableInsertEntry(pAd, Addr2, BSS0, FALSE);
94654 +
94655 + if (StaAddMacTableEntry(pAd, pEntry, MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo) == FALSE)
94656 + {
94657 + DBGPRINT(RT_DEBUG_TRACE, ("ADHOC - Add Entry failed.\n"));
94658 + return;
94659 + }
94660 +
94661 + if (pEntry &&
94662 + (Elem->Wcid == RESERVED_WCID))
94663 + {
94664 + idx = pAd->StaCfg.DefaultKeyId;
94665 + RT28XX_STA_SECURITY_INFO_ADD(pAd, BSS0, idx, pEntry);
94666 + }
94667 + }
94668 +
94669 + if (pEntry && pEntry->ValidAsCLI)
94670 + pEntry->LastBeaconRxTime = Now;
94671 +
94672 + // At least another peer in this IBSS, declare MediaState as CONNECTED
94673 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
94674 + {
94675 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
94676 +
94677 + pAd->IndicateMediaState = NdisMediaStateConnected;
94678 + RTMP_IndicateMediaState(pAd);
94679 + pAd->ExtraInfo = GENERAL_LINK_UP;
94680 + AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
94681 +
94682 + // 2003/03/12 - john
94683 + // Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that
94684 + // "site survey" result should always include the current connected network.
94685 + //
94686 + Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
94687 + if (Bssidx == BSS_NOT_FOUND)
94688 + {
94689 + Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
94690 + &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
94691 + &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, RealRssi, TimeStamp, 0,
94692 + &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
94693 + }
94694 + DBGPRINT(RT_DEBUG_TRACE, ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n"));
94695 + }
94696 + }
94697 +
94698 + if (INFRA_ON(pAd))
94699 + {
94700 + BOOLEAN bUseShortSlot, bUseBGProtection;
94701 +
94702 + // decide to use/change to -
94703 + // 1. long slot (20 us) or short slot (9 us) time
94704 + // 2. turn on/off RTS/CTS and/or CTS-to-self protection
94705 + // 3. short preamble
94706 +
94707 + //bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo);
94708 + bUseShortSlot = CAP_IS_SHORT_SLOT(CapabilityInfo);
94709 + if (bUseShortSlot != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))
94710 + AsicSetSlotTime(pAd, bUseShortSlot);
94711 +
94712 + bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || // always use
94713 + ((pAd->CommonCfg.UseBGProtection == 0) && ERP_IS_USE_PROTECTION(Erp));
94714 +
94715 + if (pAd->CommonCfg.Channel > 14) // always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP
94716 + bUseBGProtection = FALSE;
94717 +
94718 + if (bUseBGProtection != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
94719 + {
94720 + if (bUseBGProtection)
94721 + {
94722 + OPSTATUS_SET_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
94723 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),FALSE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
94724 + }
94725 + else
94726 + {
94727 + OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
94728 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),TRUE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
94729 + }
94730 +
94731 + DBGPRINT(RT_DEBUG_WARN, ("SYNC - AP changed B/G protection to %d\n", bUseBGProtection));
94732 + }
94733 +
94734 +#ifdef DOT11_N_SUPPORT
94735 + // check Ht protection mode. and adhere to the Non-GF device indication by AP.
94736 + if ((AddHtInfoLen != 0) &&
94737 + ((AddHtInfo.AddHtInfo2.OperaionMode != pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode) ||
94738 + (AddHtInfo.AddHtInfo2.NonGfPresent != pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent)))
94739 + {
94740 + pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent = AddHtInfo.AddHtInfo2.NonGfPresent;
94741 + pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode = AddHtInfo.AddHtInfo2.OperaionMode;
94742 + if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
94743 + {
94744 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
94745 + }
94746 + else
94747 + AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
94748 +
94749 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP changed N OperaionMode to %d\n", pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode));
94750 + }
94751 +#endif // DOT11_N_SUPPORT //
94752 +
94753 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED) &&
94754 + ERP_IS_USE_BARKER_PREAMBLE(Erp))
94755 + {
94756 + MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
94757 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP forced to use LONG preamble\n"));
94758 + }
94759 +
94760 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
94761 + (EdcaParm.bValid == TRUE) &&
94762 + (EdcaParm.EdcaUpdateCount != pAd->CommonCfg.APEdcaParm.EdcaUpdateCount))
94763 + {
94764 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP change EDCA parameters(from %d to %d)\n",
94765 + pAd->CommonCfg.APEdcaParm.EdcaUpdateCount,
94766 + EdcaParm.EdcaUpdateCount));
94767 + AsicSetEdcaParm(pAd, &EdcaParm);
94768 + }
94769 +
94770 + // copy QOS related information
94771 + NdisMoveMemory(&pAd->CommonCfg.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
94772 + NdisMoveMemory(&pAd->CommonCfg.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
94773 + }
94774 +
94775 + // only INFRASTRUCTURE mode support power-saving feature
94776 + if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE)) || (pAd->CommonCfg.bAPSDForcePowerSave))
94777 + {
94778 + UCHAR FreeNumber;
94779 + // 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL
94780 + // 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE
94781 + // 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE
94782 + // 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE
94783 + // 5. otherwise, put PHY back to sleep to save battery.
94784 + if (MessageToMe)
94785 + {
94786 + if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable &&
94787 + pAd->CommonCfg.bAPSDAC_BE && pAd->CommonCfg.bAPSDAC_BK && pAd->CommonCfg.bAPSDAC_VI && pAd->CommonCfg.bAPSDAC_VO)
94788 + {
94789 + pAd->CommonCfg.bNeedSendTriggerFrame = TRUE;
94790 + }
94791 + else
94792 + RT28XX_PS_POLL_ENQUEUE(pAd);
94793 + }
94794 + else if (BcastFlag && (DtimCount == 0) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM))
94795 + {
94796 + }
94797 + else if ((pAd->TxSwQueue[QID_AC_BK].Number != 0) ||
94798 + (pAd->TxSwQueue[QID_AC_BE].Number != 0) ||
94799 + (pAd->TxSwQueue[QID_AC_VI].Number != 0) ||
94800 + (pAd->TxSwQueue[QID_AC_VO].Number != 0) ||
94801 + (RTMPFreeTXDRequest(pAd, QID_AC_BK, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
94802 + (RTMPFreeTXDRequest(pAd, QID_AC_BE, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
94803 + (RTMPFreeTXDRequest(pAd, QID_AC_VI, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
94804 + (RTMPFreeTXDRequest(pAd, QID_AC_VO, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
94805 + (RTMPFreeTXDRequest(pAd, QID_MGMT, MGMT_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS))
94806 + {
94807 + // TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme
94808 + // can we cheat here (i.e. just check MGMT & AC_BE) for better performance?
94809 + }
94810 + else
94811 + {
94812 + USHORT NextDtim = DtimCount;
94813 +
94814 + if (NextDtim == 0)
94815 + NextDtim = DtimPeriod;
94816 +
94817 + TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
94818 + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
94819 + TbttNumToNextWakeUp = NextDtim;
94820 +
94821 + if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
94822 + {
94823 + AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
94824 + }
94825 + }
94826 + }
94827 + }
94828 + // not my BSSID, ignore it
94829 + }
94830 + // sanity check fail, ignore this frame
94831 +}
94832 +
94833 +/*
94834 + ==========================================================================
94835 + Description:
94836 + Receive PROBE REQ from remote peer when operating in IBSS mode
94837 + ==========================================================================
94838 + */
94839 +VOID PeerProbeReqAction(
94840 + IN PRTMP_ADAPTER pAd,
94841 + IN MLME_QUEUE_ELEM *Elem)
94842 +{
94843 + UCHAR Addr2[MAC_ADDR_LEN];
94844 + CHAR Ssid[MAX_LEN_OF_SSID];
94845 + UCHAR SsidLen;
94846 +#ifdef DOT11_N_SUPPORT
94847 + UCHAR HtLen, AddHtLen, NewExtLen;
94848 +#endif // DOT11_N_SUPPORT //
94849 + HEADER_802_11 ProbeRspHdr;
94850 + NDIS_STATUS NStatus;
94851 + PUCHAR pOutBuffer = NULL;
94852 + ULONG FrameLen = 0;
94853 + LARGE_INTEGER FakeTimestamp;
94854 + UCHAR DsLen = 1, IbssLen = 2;
94855 + UCHAR LocalErpIe[3] = {IE_ERP, 1, 0};
94856 + BOOLEAN Privacy;
94857 + USHORT CapabilityInfo;
94858 + UCHAR RSNIe = IE_WPA;
94859 +
94860 + if (! ADHOC_ON(pAd))
94861 + return;
94862 +
94863 + if (PeerProbeReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen))
94864 + {
94865 + if ((SsidLen == 0) || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))
94866 + {
94867 + // allocate and send out ProbeRsp frame
94868 + NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
94869 + if (NStatus != NDIS_STATUS_SUCCESS)
94870 + return;
94871 +
94872 + //pAd->StaCfg.AtimWin = 0; // ??????
94873 +
94874 + Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
94875 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
94876 + (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
94877 + CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
94878 +
94879 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
94880 + sizeof(HEADER_802_11), &ProbeRspHdr,
94881 + TIMESTAMP_LEN, &FakeTimestamp,
94882 + 2, &pAd->CommonCfg.BeaconPeriod,
94883 + 2, &CapabilityInfo,
94884 + 1, &SsidIe,
94885 + 1, &pAd->CommonCfg.SsidLen,
94886 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
94887 + 1, &SupRateIe,
94888 + 1, &pAd->StaActive.SupRateLen,
94889 + pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
94890 + 1, &DsIe,
94891 + 1, &DsLen,
94892 + 1, &pAd->CommonCfg.Channel,
94893 + 1, &IbssIe,
94894 + 1, &IbssLen,
94895 + 2, &pAd->StaActive.AtimWin,
94896 + END_OF_ARGS);
94897 +
94898 + if (pAd->StaActive.ExtRateLen)
94899 + {
94900 + ULONG tmp;
94901 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
94902 + 3, LocalErpIe,
94903 + 1, &ExtRateIe,
94904 + 1, &pAd->StaActive.ExtRateLen,
94905 + pAd->StaActive.ExtRateLen, &pAd->StaActive.ExtRate,
94906 + END_OF_ARGS);
94907 + FrameLen += tmp;
94908 + }
94909 +
94910 + // If adhoc secruity is set for WPA-None, append the cipher suite IE
94911 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
94912 + {
94913 + ULONG tmp;
94914 + MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
94915 + 1, &RSNIe,
94916 + 1, &pAd->StaCfg.RSNIE_Len,
94917 + pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
94918 + END_OF_ARGS);
94919 + FrameLen += tmp;
94920 + }
94921 +#ifdef DOT11_N_SUPPORT
94922 + if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
94923 + {
94924 + ULONG TmpLen;
94925 + UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
94926 + HtLen = sizeof(pAd->CommonCfg.HtCapability);
94927 + AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo);
94928 + NewExtLen = 1;
94929 + //New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame
94930 + if (pAd->bBroadComHT == TRUE)
94931 + {
94932 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
94933 + 1, &WpaIe,
94934 + 4, &BROADCOM[0],
94935 + pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
94936 + END_OF_ARGS);
94937 + }
94938 + else
94939 + {
94940 + MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
94941 + 1, &HtCapIe,
94942 + 1, &HtLen,
94943 + sizeof(HT_CAPABILITY_IE), &pAd->CommonCfg.HtCapability,
94944 + 1, &AddHtInfoIe,
94945 + 1, &AddHtLen,
94946 + sizeof(ADD_HT_INFO_IE), &pAd->CommonCfg.AddHTInfo,
94947 + 1, &NewExtChanIe,
94948 + 1, &NewExtLen,
94949 + sizeof(NEW_EXT_CHAN_IE), &pAd->CommonCfg.NewExtChanOffset,
94950 + END_OF_ARGS);
94951 + }
94952 + FrameLen += TmpLen;
94953 + }
94954 +#endif // DOT11_N_SUPPORT //
94955 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
94956 + MlmeFreeMemory(pAd, pOutBuffer);
94957 + }
94958 + }
94959 +}
94960 +
94961 +VOID BeaconTimeoutAtJoinAction(
94962 + IN PRTMP_ADAPTER pAd,
94963 + IN MLME_QUEUE_ELEM *Elem)
94964 +{
94965 + USHORT Status;
94966 + DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n"));
94967 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
94968 + Status = MLME_REJ_TIMEOUT;
94969 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
94970 +}
94971 +
94972 +/*
94973 + ==========================================================================
94974 + Description:
94975 + Scan timeout procedure. basically add channel index by 1 and rescan
94976 + ==========================================================================
94977 + */
94978 +VOID ScanTimeoutAction(
94979 + IN PRTMP_ADAPTER pAd,
94980 + IN MLME_QUEUE_ELEM *Elem)
94981 +{
94982 + pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel);
94983 +
94984 + // Only one channel scanned for CISCO beacon request
94985 + if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) ||
94986 + (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) ||
94987 + (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) ||
94988 + (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD))
94989 + pAd->MlmeAux.Channel = 0;
94990 +
94991 + // this routine will stop if pAd->MlmeAux.Channel == 0
94992 + ScanNextChannel(pAd);
94993 +}
94994 +
94995 +/*
94996 + ==========================================================================
94997 + Description:
94998 + ==========================================================================
94999 + */
95000 +VOID InvalidStateWhenScan(
95001 + IN PRTMP_ADAPTER pAd,
95002 + IN MLME_QUEUE_ELEM *Elem)
95003 +{
95004 + USHORT Status;
95005 + DBGPRINT(RT_DEBUG_TRACE, ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
95006 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
95007 + Status = MLME_STATE_MACHINE_REJECT;
95008 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
95009 +}
95010 +
95011 +/*
95012 + ==========================================================================
95013 + Description:
95014 + ==========================================================================
95015 + */
95016 +VOID InvalidStateWhenJoin(
95017 + IN PRTMP_ADAPTER pAd,
95018 + IN MLME_QUEUE_ELEM *Elem)
95019 +{
95020 + USHORT Status;
95021 + DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
95022 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
95023 + Status = MLME_STATE_MACHINE_REJECT;
95024 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
95025 +}
95026 +
95027 +/*
95028 + ==========================================================================
95029 + Description:
95030 + ==========================================================================
95031 + */
95032 +VOID InvalidStateWhenStart(
95033 + IN PRTMP_ADAPTER pAd,
95034 + IN MLME_QUEUE_ELEM *Elem)
95035 +{
95036 + USHORT Status;
95037 + DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
95038 + pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
95039 + Status = MLME_STATE_MACHINE_REJECT;
95040 + MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
95041 +}
95042 +
95043 +/*
95044 + ==========================================================================
95045 + Description:
95046 +
95047 + IRQL = DISPATCH_LEVEL
95048 +
95049 + ==========================================================================
95050 + */
95051 +VOID EnqueuePsPoll(
95052 + IN PRTMP_ADAPTER pAd)
95053 +{
95054 +#ifdef RALINK_ATE
95055 + if (ATE_ON(pAd))
95056 + {
95057 + return;
95058 + }
95059 +#endif // RALINK_ATE //
95060 +
95061 +
95062 + if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP)
95063 + pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE;
95064 + MiniportMMRequest(pAd, 0, (PUCHAR)&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
95065 +}
95066 +
95067 +
95068 +/*
95069 + ==========================================================================
95070 + Description:
95071 + ==========================================================================
95072 + */
95073 +VOID EnqueueProbeRequest(
95074 + IN PRTMP_ADAPTER pAd)
95075 +{
95076 + NDIS_STATUS NState;
95077 + PUCHAR pOutBuffer;
95078 + ULONG FrameLen = 0;
95079 + HEADER_802_11 Hdr80211;
95080 +
95081 + DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n"));
95082 +
95083 + NState = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
95084 + if (NState == NDIS_STATUS_SUCCESS)
95085 + {
95086 + MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
95087 +
95088 + // this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse
95089 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95090 + sizeof(HEADER_802_11), &Hdr80211,
95091 + 1, &SsidIe,
95092 + 1, &pAd->CommonCfg.SsidLen,
95093 + pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
95094 + 1, &SupRateIe,
95095 + 1, &pAd->StaActive.SupRateLen,
95096 + pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
95097 + END_OF_ARGS);
95098 + MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
95099 + MlmeFreeMemory(pAd, pOutBuffer);
95100 + }
95101 +
95102 +}
95103 +
95104 +#ifdef DOT11_N_SUPPORT
95105 +#ifdef DOT11N_DRAFT3
95106 +VOID BuildEffectedChannelList(
95107 + IN PRTMP_ADAPTER pAd)
95108 +{
95109 + UCHAR EChannel[11];
95110 + UCHAR i, j, k;
95111 + UCHAR UpperChannel = 0, LowerChannel = 0;
95112 +
95113 + RTMPZeroMemory(EChannel, 11);
95114 + i = 0;
95115 + // Find upper channel and lower channel.
95116 + if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
95117 + {
95118 + UpperChannel = pAd->CommonCfg.Channel;
95119 + LowerChannel = pAd->CommonCfg.CentralChannel;
95120 + }
95121 + else if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
95122 + {
95123 + UpperChannel = pAd->CommonCfg.CentralChannel;
95124 + LowerChannel = pAd->CommonCfg.Channel;
95125 + }
95126 + else
95127 + {
95128 + return;
95129 + }
95130 +
95131 + // Record channels that is below lower channel..
95132 + if (LowerChannel > 1)
95133 + {
95134 + EChannel[0] = LowerChannel - 1;
95135 + i = 1;
95136 + if (LowerChannel > 2)
95137 + {
95138 + EChannel[1] = LowerChannel - 2;
95139 + i = 2;
95140 + if (LowerChannel > 3)
95141 + {
95142 + EChannel[2] = LowerChannel - 3;
95143 + i = 3;
95144 + }
95145 + }
95146 + }
95147 + // Record channels that is between lower channel and upper channel.
95148 + for (k = LowerChannel;k < UpperChannel;k++)
95149 + {
95150 + EChannel[i] = k;
95151 + i++;
95152 + }
95153 + // Record channels that is above upper channel..
95154 + if (LowerChannel < 11)
95155 + {
95156 + EChannel[i] = UpperChannel + 1;
95157 + i++;
95158 + if (LowerChannel < 10)
95159 + {
95160 + EChannel[i] = LowerChannel + 2;
95161 + i++;
95162 + if (LowerChannel < 9)
95163 + {
95164 + EChannel[i] = LowerChannel + 3;
95165 + i++;
95166 + }
95167 + }
95168 + }
95169 + //
95170 + for (j = 0;j < i;j++)
95171 + {
95172 + for (k = 0;k < pAd->ChannelListNum;k++)
95173 + {
95174 + if (pAd->ChannelList[k].Channel == EChannel[j])
95175 + {
95176 + pAd->ChannelList[k].bEffectedChannel = TRUE;
95177 + DBGPRINT(RT_DEBUG_TRACE,(" EffectedChannel( =%d)\n", EChannel[j]));
95178 + break;
95179 + }
95180 + }
95181 + }
95182 +}
95183 +#endif // DOT11N_DRAFT3 //
95184 +#endif // DOT11_N_SUPPORT //
95185 +
95186 +BOOLEAN ScanRunning(
95187 + IN PRTMP_ADAPTER pAd)
95188 +{
95189 + return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE;
95190 +}
95191 +
95192 --- /dev/null
95193 +++ b/drivers/staging/rt3070/sta/wpa.c
95194 @@ -0,0 +1,2099 @@
95195 +/*
95196 + *************************************************************************
95197 + * Ralink Tech Inc.
95198 + * 5F., No.36, Taiyuan St., Jhubei City,
95199 + * Hsinchu County 302,
95200 + * Taiwan, R.O.C.
95201 + *
95202 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
95203 + *
95204 + * This program is free software; you can redistribute it and/or modify *
95205 + * it under the terms of the GNU General Public License as published by *
95206 + * the Free Software Foundation; either version 2 of the License, or *
95207 + * (at your option) any later version. *
95208 + * *
95209 + * This program is distributed in the hope that it will be useful, *
95210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
95211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
95212 + * GNU General Public License for more details. *
95213 + * *
95214 + * You should have received a copy of the GNU General Public License *
95215 + * along with this program; if not, write to the *
95216 + * Free Software Foundation, Inc., *
95217 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
95218 + * *
95219 + *************************************************************************
95220 +
95221 + Module Name:
95222 + wpa.c
95223 +
95224 + Abstract:
95225 +
95226 + Revision History:
95227 + Who When What
95228 + -------- ---------- ----------------------------------------------
95229 + Jan Lee 03-07-22 Initial
95230 + Paul Lin 03-11-28 Modify for supplicant
95231 +*/
95232 +#include "../rt_config.h"
95233 +
95234 +#define WPARSNIE 0xdd
95235 +#define WPA2RSNIE 0x30
95236 +
95237 +//extern UCHAR BIT8[];
95238 +UCHAR CipherWpaPskTkip[] = {
95239 + 0xDD, 0x16, // RSN IE
95240 + 0x00, 0x50, 0xf2, 0x01, // oui
95241 + 0x01, 0x00, // Version
95242 + 0x00, 0x50, 0xf2, 0x02, // Multicast
95243 + 0x01, 0x00, // Number of unicast
95244 + 0x00, 0x50, 0xf2, 0x02, // unicast
95245 + 0x01, 0x00, // number of authentication method
95246 + 0x00, 0x50, 0xf2, 0x02 // authentication
95247 + };
95248 +UCHAR CipherWpaPskTkipLen = (sizeof(CipherWpaPskTkip) / sizeof(UCHAR));
95249 +
95250 +UCHAR CipherWpaPskAes[] = {
95251 + 0xDD, 0x16, // RSN IE
95252 + 0x00, 0x50, 0xf2, 0x01, // oui
95253 + 0x01, 0x00, // Version
95254 + 0x00, 0x50, 0xf2, 0x04, // Multicast
95255 + 0x01, 0x00, // Number of unicast
95256 + 0x00, 0x50, 0xf2, 0x04, // unicast
95257 + 0x01, 0x00, // number of authentication method
95258 + 0x00, 0x50, 0xf2, 0x02 // authentication
95259 + };
95260 +UCHAR CipherWpaPskAesLen = (sizeof(CipherWpaPskAes) / sizeof(UCHAR));
95261 +
95262 +UCHAR CipherSuiteCiscoCCKM[] = {
95263 + 0xDD, 0x16, // RSN IE
95264 + 0x00, 0x50, 0xf2, 0x01, // oui
95265 + 0x01, 0x00, // Version
95266 + 0x00, 0x40, 0x96, 0x01, // Multicast
95267 + 0x01, 0x00, // Number of uicast
95268 + 0x00, 0x40, 0x96, 0x01, // unicast
95269 + 0x01, 0x00, // number of authentication method
95270 + 0x00, 0x40, 0x96, 0x00 // Authentication
95271 + };
95272 +UCHAR CipherSuiteCiscoCCKMLen = (sizeof(CipherSuiteCiscoCCKM) / sizeof(UCHAR));
95273 +
95274 +UCHAR CipherSuiteCiscoCCKM24[] = {
95275 + 0xDD, 0x18, // RSN IE
95276 + 0x00, 0x50, 0xf2, 0x01, // oui
95277 + 0x01, 0x00, // Version
95278 + 0x00, 0x40, 0x96, 0x01, // Multicast
95279 + 0x01, 0x00, // Number of uicast
95280 + 0x00, 0x40, 0x96, 0x01, // unicast
95281 + 0x01, 0x00, // number of authentication method
95282 + 0x00, 0x40, 0x96, 0x00,
95283 + 0x28, 0x00// Authentication
95284 + };
95285 +
95286 +UCHAR CipherSuiteCiscoCCKM24Len = (sizeof(CipherSuiteCiscoCCKM24) / sizeof(UCHAR));
95287 +
95288 +UCHAR CipherSuiteCCXTkip[] = {
95289 + 0xDD, 0x16, // RSN IE
95290 + 0x00, 0x50, 0xf2, 0x01, // oui
95291 + 0x01, 0x00, // Version
95292 + 0x00, 0x50, 0xf2, 0x02, // Multicast
95293 + 0x01, 0x00, // Number of unicast
95294 + 0x00, 0x50, 0xf2, 0x02, // unicast
95295 + 0x01, 0x00, // number of authentication method
95296 + 0x00, 0x50, 0xf2, 0x01 // authentication
95297 + };
95298 +UCHAR CipherSuiteCCXTkipLen = (sizeof(CipherSuiteCCXTkip) / sizeof(UCHAR));
95299 +
95300 +UCHAR CCX_LLC_HDR[] = {0xAA, 0xAA, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02};
95301 +UCHAR LLC_NORMAL[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
95302 +
95303 +UCHAR EAPOL_FRAME[] = {0x88, 0x8E};
95304 +
95305 +BOOLEAN CheckRSNIE(
95306 + IN PRTMP_ADAPTER pAd,
95307 + IN PUCHAR pData,
95308 + IN UCHAR DataLen,
95309 + OUT UCHAR *Offset);
95310 +
95311 +void inc_byte_array(UCHAR *counter, int len);
95312 +
95313 +/*
95314 + ========================================================================
95315 +
95316 + Routine Description:
95317 + Classify WPA EAP message type
95318 +
95319 + Arguments:
95320 + EAPType Value of EAP message type
95321 + MsgType Internal Message definition for MLME state machine
95322 +
95323 + Return Value:
95324 + TRUE Found appropriate message type
95325 + FALSE No appropriate message type
95326 +
95327 + IRQL = DISPATCH_LEVEL
95328 +
95329 + Note:
95330 + All these constants are defined in wpa.h
95331 + For supplicant, there is only EAPOL Key message avaliable
95332 +
95333 + ========================================================================
95334 +*/
95335 +BOOLEAN WpaMsgTypeSubst(
95336 + IN UCHAR EAPType,
95337 + OUT INT *MsgType)
95338 +{
95339 + switch (EAPType)
95340 + {
95341 + case EAPPacket:
95342 + *MsgType = MT2_EAPPacket;
95343 + break;
95344 + case EAPOLStart:
95345 + *MsgType = MT2_EAPOLStart;
95346 + break;
95347 + case EAPOLLogoff:
95348 + *MsgType = MT2_EAPOLLogoff;
95349 + break;
95350 + case EAPOLKey:
95351 + *MsgType = MT2_EAPOLKey;
95352 + break;
95353 + case EAPOLASFAlert:
95354 + *MsgType = MT2_EAPOLASFAlert;
95355 + break;
95356 + default:
95357 + return FALSE;
95358 + }
95359 + return TRUE;
95360 +}
95361 +
95362 +/*
95363 + ==========================================================================
95364 + Description:
95365 + association state machine init, including state transition and timer init
95366 + Parameters:
95367 + S - pointer to the association state machine
95368 + ==========================================================================
95369 + */
95370 +VOID WpaPskStateMachineInit(
95371 + IN PRTMP_ADAPTER pAd,
95372 + IN STATE_MACHINE *S,
95373 + OUT STATE_MACHINE_FUNC Trans[])
95374 +{
95375 + StateMachineInit(S, Trans, MAX_WPA_PSK_STATE, MAX_WPA_PSK_MSG, (STATE_MACHINE_FUNC)Drop, WPA_PSK_IDLE, WPA_MACHINE_BASE);
95376 + StateMachineSetAction(S, WPA_PSK_IDLE, MT2_EAPOLKey, (STATE_MACHINE_FUNC)WpaEAPOLKeyAction);
95377 +}
95378 +
95379 +/*
95380 + ==========================================================================
95381 + Description:
95382 + This is state machine function.
95383 + When receiving EAPOL packets which is for 802.1x key management.
95384 + Use both in WPA, and WPAPSK case.
95385 + In this function, further dispatch to different functions according to the received packet. 3 categories are :
95386 + 1. normal 4-way pairwisekey and 2-way groupkey handshake
95387 + 2. MIC error (Countermeasures attack) report packet from STA.
95388 + 3. Request for pairwise/group key update from STA
95389 + Return:
95390 + ==========================================================================
95391 +*/
95392 +VOID WpaEAPOLKeyAction(
95393 + IN PRTMP_ADAPTER pAd,
95394 + IN MLME_QUEUE_ELEM *Elem)
95395 +
95396 +{
95397 + INT MsgType = EAPOL_MSG_INVALID;
95398 + PKEY_DESCRIPTER pKeyDesc;
95399 + PHEADER_802_11 pHeader; //red
95400 + UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];
95401 + UCHAR EapolVr;
95402 + KEY_INFO peerKeyInfo;
95403 +
95404 + DBGPRINT(RT_DEBUG_TRACE, ("-----> WpaEAPOLKeyAction\n"));
95405 +
95406 + // Get 802.11 header first
95407 + pHeader = (PHEADER_802_11) Elem->Msg;
95408 +
95409 + // Get EAPoL-Key Descriptor
95410 + pKeyDesc = (PKEY_DESCRIPTER) &Elem->Msg[(LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H)];
95411 +
95412 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
95413 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pKeyDesc->KeyInfo, sizeof(KEY_INFO));
95414 +
95415 + *((USHORT *)&peerKeyInfo) = cpu2le16(*((USHORT *)&peerKeyInfo));
95416 +
95417 +
95418 + // 1. Check EAPOL frame version and type
95419 + EapolVr = (UCHAR) Elem->Msg[LENGTH_802_11+LENGTH_802_1_H];
95420 +
95421 + if (((EapolVr != EAPOL_VER) && (EapolVr != EAPOL_VER2)) || ((pKeyDesc->Type != WPA1_KEY_DESC) && (pKeyDesc->Type != WPA2_KEY_DESC)))
95422 + {
95423 + DBGPRINT(RT_DEBUG_ERROR, ("Key descripter does not match with WPA rule\n"));
95424 + return;
95425 + }
95426 +
95427 + // First validate replay counter, only accept message with larger replay counter
95428 + // Let equal pass, some AP start with all zero replay counter
95429 + NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
95430 +
95431 + if((RTMPCompareMemory(pKeyDesc->ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1) &&
95432 + (RTMPCompareMemory(pKeyDesc->ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))
95433 + {
95434 + DBGPRINT(RT_DEBUG_ERROR, (" ReplayCounter not match \n"));
95435 + return;
95436 + }
95437 +
95438 + // Process WPA2PSK frame
95439 + if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
95440 + {
95441 + if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
95442 + (peerKeyInfo.EKD_DL == 0) &&
95443 + (peerKeyInfo.KeyAck == 1) &&
95444 + (peerKeyInfo.KeyMic == 0) &&
95445 + (peerKeyInfo.Secure == 0) &&
95446 + (peerKeyInfo.Error == 0) &&
95447 + (peerKeyInfo.Request == 0))
95448 + {
95449 + MsgType = EAPOL_PAIR_MSG_1;
95450 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));
95451 + } else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
95452 + (peerKeyInfo.EKD_DL == 1) &&
95453 + (peerKeyInfo.KeyAck == 1) &&
95454 + (peerKeyInfo.KeyMic == 1) &&
95455 + (peerKeyInfo.Secure == 1) &&
95456 + (peerKeyInfo.Error == 0) &&
95457 + (peerKeyInfo.Request == 0))
95458 + {
95459 + MsgType = EAPOL_PAIR_MSG_3;
95460 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));
95461 + } else if((peerKeyInfo.KeyType == GROUPKEY) &&
95462 + (peerKeyInfo.EKD_DL == 1) &&
95463 + (peerKeyInfo.KeyAck == 1) &&
95464 + (peerKeyInfo.KeyMic == 1) &&
95465 + (peerKeyInfo.Secure == 1) &&
95466 + (peerKeyInfo.Error == 0) &&
95467 + (peerKeyInfo.Request == 0))
95468 + {
95469 + MsgType = EAPOL_GROUP_MSG_1;
95470 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));
95471 + }
95472 +
95473 + // We will assume link is up (assoc suceess and port not secured).
95474 + // All state has to be able to process message from previous state
95475 + switch(pAd->StaCfg.WpaState)
95476 + {
95477 + case SS_START:
95478 + if(MsgType == EAPOL_PAIR_MSG_1)
95479 + {
95480 + Wpa2PairMsg1Action(pAd, Elem);
95481 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95482 + }
95483 + break;
95484 +
95485 + case SS_WAIT_MSG_3:
95486 + if(MsgType == EAPOL_PAIR_MSG_1)
95487 + {
95488 + Wpa2PairMsg1Action(pAd, Elem);
95489 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95490 + }
95491 + else if(MsgType == EAPOL_PAIR_MSG_3)
95492 + {
95493 + Wpa2PairMsg3Action(pAd, Elem);
95494 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
95495 + }
95496 + break;
95497 +
95498 + case SS_WAIT_GROUP: // When doing group key exchange
95499 + case SS_FINISH: // This happened when update group key
95500 + if(MsgType == EAPOL_PAIR_MSG_1)
95501 + {
95502 + // Reset port secured variable
95503 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
95504 + Wpa2PairMsg1Action(pAd, Elem);
95505 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95506 + }
95507 + else if(MsgType == EAPOL_PAIR_MSG_3)
95508 + {
95509 + // Reset port secured variable
95510 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
95511 + Wpa2PairMsg3Action(pAd, Elem);
95512 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
95513 + }
95514 + else if(MsgType == EAPOL_GROUP_MSG_1)
95515 + {
95516 + WpaGroupMsg1Action(pAd, Elem);
95517 + pAd->StaCfg.WpaState = SS_FINISH;
95518 + }
95519 + break;
95520 +
95521 + default:
95522 + break;
95523 + }
95524 + }
95525 + // Process WPAPSK Frame
95526 + // Classify message Type, either pairwise message 1, 3, or group message 1 for supplicant
95527 + else if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
95528 + {
95529 + if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
95530 + (peerKeyInfo.KeyIndex == 0) &&
95531 + (peerKeyInfo.KeyAck == 1) &&
95532 + (peerKeyInfo.KeyMic == 0) &&
95533 + (peerKeyInfo.Secure == 0) &&
95534 + (peerKeyInfo.Error == 0) &&
95535 + (peerKeyInfo.Request == 0))
95536 + {
95537 + MsgType = EAPOL_PAIR_MSG_1;
95538 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));
95539 + }
95540 + else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&
95541 + (peerKeyInfo.KeyIndex == 0) &&
95542 + (peerKeyInfo.KeyAck == 1) &&
95543 + (peerKeyInfo.KeyMic == 1) &&
95544 + (peerKeyInfo.Secure == 0) &&
95545 + (peerKeyInfo.Error == 0) &&
95546 + (peerKeyInfo.Request == 0))
95547 + {
95548 + MsgType = EAPOL_PAIR_MSG_3;
95549 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));
95550 + }
95551 + else if((peerKeyInfo.KeyType == GROUPKEY) &&
95552 + (peerKeyInfo.KeyIndex != 0) &&
95553 + (peerKeyInfo.KeyAck == 1) &&
95554 + (peerKeyInfo.KeyMic == 1) &&
95555 + (peerKeyInfo.Secure == 1) &&
95556 + (peerKeyInfo.Error == 0) &&
95557 + (peerKeyInfo.Request == 0))
95558 + {
95559 + MsgType = EAPOL_GROUP_MSG_1;
95560 + DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));
95561 + }
95562 +
95563 + // We will assume link is up (assoc suceess and port not secured).
95564 + // All state has to be able to process message from previous state
95565 + switch(pAd->StaCfg.WpaState)
95566 + {
95567 + case SS_START:
95568 + if(MsgType == EAPOL_PAIR_MSG_1)
95569 + {
95570 + WpaPairMsg1Action(pAd, Elem);
95571 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95572 + }
95573 + break;
95574 +
95575 + case SS_WAIT_MSG_3:
95576 + if(MsgType == EAPOL_PAIR_MSG_1)
95577 + {
95578 + WpaPairMsg1Action(pAd, Elem);
95579 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95580 + }
95581 + else if(MsgType == EAPOL_PAIR_MSG_3)
95582 + {
95583 + WpaPairMsg3Action(pAd, Elem);
95584 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
95585 + }
95586 + break;
95587 +
95588 + case SS_WAIT_GROUP: // When doing group key exchange
95589 + case SS_FINISH: // This happened when update group key
95590 + if(MsgType == EAPOL_PAIR_MSG_1)
95591 + {
95592 + WpaPairMsg1Action(pAd, Elem);
95593 + pAd->StaCfg.WpaState = SS_WAIT_MSG_3;
95594 + // Reset port secured variable
95595 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
95596 + }
95597 + else if(MsgType == EAPOL_PAIR_MSG_3)
95598 + {
95599 + WpaPairMsg3Action(pAd, Elem);
95600 + pAd->StaCfg.WpaState = SS_WAIT_GROUP;
95601 + // Reset port secured variable
95602 + pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
95603 + }
95604 + else if(MsgType == EAPOL_GROUP_MSG_1)
95605 + {
95606 + WpaGroupMsg1Action(pAd, Elem);
95607 + pAd->StaCfg.WpaState = SS_FINISH;
95608 + }
95609 + break;
95610 +
95611 + default:
95612 + break;
95613 + }
95614 + }
95615 +
95616 + DBGPRINT(RT_DEBUG_TRACE, ("<----- WpaEAPOLKeyAction\n"));
95617 +}
95618 +
95619 +/*
95620 + ========================================================================
95621 +
95622 + Routine Description:
95623 + Process Pairwise key 4-way handshaking
95624 +
95625 + Arguments:
95626 + pAd Pointer to our adapter
95627 + Elem Message body
95628 +
95629 + Return Value:
95630 + None
95631 +
95632 + Note:
95633 +
95634 + ========================================================================
95635 +*/
95636 +VOID WpaPairMsg1Action(
95637 + IN PRTMP_ADAPTER pAd,
95638 + IN MLME_QUEUE_ELEM *Elem)
95639 +{
95640 + PHEADER_802_11 pHeader;
95641 + UCHAR *mpool, *PTK, *digest;
95642 + PUCHAR pOutBuffer = NULL;
95643 + UCHAR Header802_3[14];
95644 + ULONG FrameLen = 0;
95645 + PEAPOL_PACKET pMsg1;
95646 + EAPOL_PACKET Packet;
95647 + UCHAR Mic[16];
95648 +
95649 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action ----->\n"));
95650 +
95651 + // allocate memory pool
95652 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);
95653 +
95654 + if (mpool == NULL)
95655 + return;
95656 +
95657 + // PTK Len = 80.
95658 + PTK = (UCHAR *) ROUND_UP(mpool, 4);
95659 + // digest Len = 80.
95660 + digest = (UCHAR *) ROUND_UP(PTK + 80, 4);
95661 +
95662 + pHeader = (PHEADER_802_11) Elem->Msg;
95663 +
95664 + // Process message 1 from authenticator
95665 + pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
95666 +
95667 + // 1. Save Replay counter, it will use to verify message 3 and construct message 2
95668 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95669 +
95670 + // 2. Save ANonce
95671 + NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);
95672 +
95673 + // Generate random SNonce
95674 + GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);
95675 +
95676 + // Calc PTK(ANonce, SNonce)
95677 + WpaCountPTK(pAd,
95678 + pAd->StaCfg.PMK,
95679 + pAd->StaCfg.ANonce,
95680 + pAd->CommonCfg.Bssid,
95681 + pAd->StaCfg.SNonce,
95682 + pAd->CurrentAddress,
95683 + PTK,
95684 + LEN_PTK);
95685 +
95686 + // Save key to PTK entry
95687 + NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);
95688 +
95689 + // init 802.3 header and Fill Packet
95690 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
95691 +
95692 + // Zero Message 2 body
95693 + NdisZeroMemory(&Packet, sizeof(Packet));
95694 + Packet.ProVer = EAPOL_VER;
95695 + Packet.ProType = EAPOLKey;
95696 + //
95697 + // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
95698 + //
95699 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
95700 + // 1. Key descriptor version and appropriate RSN IE
95701 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95702 + {
95703 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
95704 + }
95705 + else // TKIP
95706 + {
95707 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
95708 + }
95709 +
95710 + // fill in Data Material and its length
95711 + Packet.KeyDesc.KeyData[0] = IE_WPA;
95712 + Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;
95713 + Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;
95714 + NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
95715 +
95716 + // Update packet length after decide Key data payload
95717 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];
95718 +
95719 + // Update Key length
95720 + Packet.KeyDesc.KeyLength[0] = pMsg1->KeyDesc.KeyLength[0];
95721 + Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];
95722 + // 2. Key Type PeerKey
95723 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
95724 +
95725 + // 3. KeyMic field presented
95726 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
95727 +
95728 + //Convert to little-endian format.
95729 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
95730 +
95731 +
95732 + // 4. Fill SNonce
95733 + NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);
95734 +
95735 + // 5. Key Replay Count
95736 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
95737 +
95738 + // Send EAPOL(0, 1, 0, 0, 0, P, 0, SNonce, MIC, RSN_IE)
95739 + // Out buffer for transmitting message 2
95740 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
95741 + if(pOutBuffer == NULL)
95742 + {
95743 + os_free_mem(pAd, mpool);
95744 + return;
95745 + }
95746 + // Prepare EAPOL frame for MIC calculation
95747 + // Be careful, only EAPOL frame is counted for MIC calculation
95748 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95749 + Packet.Body_Len[1] + 4, &Packet,
95750 + END_OF_ARGS);
95751 +
95752 + // 6. Prepare and Fill MIC value
95753 + NdisZeroMemory(Mic, sizeof(Mic));
95754 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95755 + { // AES
95756 +
95757 + HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
95758 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95759 + }
95760 + else
95761 + { // TKIP
95762 + hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
95763 + }
95764 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
95765 +
95766 + //hex_dump("MIC", Mic, LEN_KEY_DESC_MIC);
95767 +
95768 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95769 + LENGTH_802_3, &Header802_3,
95770 + Packet.Body_Len[1] + 4, &Packet,
95771 + END_OF_ARGS);
95772 +
95773 +
95774 + // 5. Copy frame to Tx ring and send Msg 2 to authenticator
95775 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
95776 +
95777 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
95778 + os_free_mem(pAd, (PUCHAR)mpool);
95779 +
95780 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action <-----\n"));
95781 +}
95782 +
95783 +VOID Wpa2PairMsg1Action(
95784 + IN PRTMP_ADAPTER pAd,
95785 + IN MLME_QUEUE_ELEM *Elem)
95786 +{
95787 + PHEADER_802_11 pHeader;
95788 + UCHAR *mpool, *PTK, *digest;
95789 + PUCHAR pOutBuffer = NULL;
95790 + UCHAR Header802_3[14];
95791 + ULONG FrameLen = 0;
95792 + PEAPOL_PACKET pMsg1;
95793 + EAPOL_PACKET Packet;
95794 + UCHAR Mic[16];
95795 +
95796 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action ----->\n"));
95797 +
95798 + // allocate memory pool
95799 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);
95800 +
95801 + if (mpool == NULL)
95802 + return;
95803 +
95804 + // PTK Len = 80.
95805 + PTK = (UCHAR *) ROUND_UP(mpool, 4);
95806 + // digest Len = 80.
95807 + digest = (UCHAR *) ROUND_UP(PTK + 80, 4);
95808 +
95809 + pHeader = (PHEADER_802_11) Elem->Msg;
95810 +
95811 + // Process message 1 from authenticator
95812 + pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
95813 +
95814 + // 1. Save Replay counter, it will use to verify message 3 and construct message 2
95815 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
95816 +
95817 + // 2. Save ANonce
95818 + NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);
95819 +
95820 + // Generate random SNonce
95821 + GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);
95822 +
95823 + if(pMsg1->KeyDesc.KeyDataLen[1] > 0 )
95824 + {
95825 + // cached PMKID
95826 + }
95827 +
95828 + // Calc PTK(ANonce, SNonce)
95829 + WpaCountPTK(pAd,
95830 + pAd->StaCfg.PMK,
95831 + pAd->StaCfg.ANonce,
95832 + pAd->CommonCfg.Bssid,
95833 + pAd->StaCfg.SNonce,
95834 + pAd->CurrentAddress,
95835 + PTK,
95836 + LEN_PTK);
95837 +
95838 + // Save key to PTK entry
95839 + NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);
95840 +
95841 + // init 802.3 header and Fill Packet
95842 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
95843 +
95844 + // Zero message 2 body
95845 + NdisZeroMemory(&Packet, sizeof(Packet));
95846 + Packet.ProVer = EAPOL_VER;
95847 + Packet.ProType = EAPOLKey;
95848 + //
95849 + // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
95850 + //
95851 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
95852 +
95853 + // 1. Key descriptor version and appropriate RSN IE
95854 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95855 + {
95856 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
95857 + }
95858 + else // TKIP
95859 + {
95860 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
95861 + }
95862 +
95863 + // fill in Data Material and its length
95864 + Packet.KeyDesc.KeyData[0] = IE_WPA2;
95865 + Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;
95866 + Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;
95867 + NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);
95868 +
95869 + // Update packet length after decide Key data payload
95870 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];
95871 +
95872 + // 2. Key Type PeerKey
95873 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
95874 +
95875 + // 3. KeyMic field presented
95876 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
95877 +
95878 + // Update Key Length
95879 + Packet.KeyDesc.KeyLength[0] = 0;
95880 + Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];
95881 +
95882 + // 4. Fill SNonce
95883 + NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);
95884 +
95885 + // 5. Key Replay Count
95886 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
95887 +
95888 + // Convert to little-endian format.
95889 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
95890 +
95891 + // Send EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)
95892 + // Out buffer for transmitting message 2
95893 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
95894 + if(pOutBuffer == NULL)
95895 + {
95896 + os_free_mem(pAd, mpool);
95897 + return;
95898 + }
95899 +
95900 + // Prepare EAPOL frame for MIC calculation
95901 + // Be careful, only EAPOL frame is counted for MIC calculation
95902 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95903 + Packet.Body_Len[1] + 4, &Packet,
95904 + END_OF_ARGS);
95905 +
95906 + // 6. Prepare and Fill MIC value
95907 + NdisZeroMemory(Mic, sizeof(Mic));
95908 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
95909 + {
95910 + // AES
95911 + HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
95912 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
95913 + }
95914 + else
95915 + {
95916 + hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
95917 + }
95918 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
95919 +
95920 +
95921 + // Make Transmitting frame
95922 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
95923 + LENGTH_802_3, &Header802_3,
95924 + Packet.Body_Len[1] + 4, &Packet,
95925 + END_OF_ARGS);
95926 +
95927 +
95928 + // 5. Copy frame to Tx ring
95929 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
95930 +
95931 + MlmeFreeMemory(pAd, pOutBuffer);
95932 + os_free_mem(pAd, mpool);
95933 +
95934 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action <-----\n"));
95935 +
95936 +}
95937 +
95938 +/*
95939 + ========================================================================
95940 +
95941 + Routine Description:
95942 + Process Pairwise key 4-way handshaking
95943 +
95944 + Arguments:
95945 + pAd Pointer to our adapter
95946 + Elem Message body
95947 +
95948 + Return Value:
95949 + None
95950 +
95951 + Note:
95952 +
95953 + ========================================================================
95954 +*/
95955 +VOID WpaPairMsg3Action(
95956 + IN PRTMP_ADAPTER pAd,
95957 + IN MLME_QUEUE_ELEM *Elem)
95958 +
95959 +{
95960 + PHEADER_802_11 pHeader;
95961 + PUCHAR pOutBuffer = NULL;
95962 + UCHAR Header802_3[14];
95963 + ULONG FrameLen = 0;
95964 + EAPOL_PACKET Packet;
95965 + PEAPOL_PACKET pMsg3;
95966 + UCHAR Mic[16], OldMic[16];
95967 + MAC_TABLE_ENTRY *pEntry = NULL;
95968 + UCHAR skip_offset;
95969 + KEY_INFO peerKeyInfo;
95970 +
95971 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action ----->\n"));
95972 +
95973 + // Record 802.11 header & the received EAPOL packet Msg3
95974 + pHeader = (PHEADER_802_11) Elem->Msg;
95975 + pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
95976 +
95977 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
95978 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));
95979 +
95980 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
95981 +
95982 +
95983 + // 1. Verify cipher type match
95984 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))
95985 + {
95986 + return;
95987 + }
95988 + else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
95989 + {
95990 + return;
95991 + }
95992 +
95993 + // Verify RSN IE
95994 + //if (!RTMPEqualMemory(pMsg3->KeyDesc.KeyData, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len))
95995 + if (!CheckRSNIE(pAd, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1], &skip_offset))
95996 + {
95997 + DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in Msg 3 of WPA1 4-way handshake!! \n"));
95998 + hex_dump("The original RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
95999 + hex_dump("The received RSN_IE", pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);
96000 + return;
96001 + }
96002 + else
96003 + DBGPRINT(RT_DEBUG_TRACE, ("RSN_IE VALID in Msg 3 of WPA1 4-way handshake!! \n"));
96004 +
96005 +
96006 + // 2. Check MIC value
96007 + // Save the MIC and replace with zero
96008 + NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96009 + NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96010 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96011 + {
96012 + // AES
96013 + UCHAR digest[80];
96014 +
96015 + HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96016 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96017 + }
96018 + else // TKIP
96019 + {
96020 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);
96021 + }
96022 +
96023 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
96024 + {
96025 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));
96026 + return;
96027 + }
96028 + else
96029 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));
96030 +
96031 + // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger
96032 + if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
96033 + return;
96034 +
96035 + // Update new replay counter
96036 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96037 +
96038 + // 4. Double check ANonce
96039 + if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))
96040 + return;
96041 +
96042 + // init 802.3 header and Fill Packet
96043 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
96044 +
96045 + // Zero Message 4 body
96046 + NdisZeroMemory(&Packet, sizeof(Packet));
96047 + Packet.ProVer = EAPOL_VER;
96048 + Packet.ProType = EAPOLKey;
96049 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
96050 +
96051 + //
96052 + // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)
96053 + //
96054 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
96055 +
96056 + // Key descriptor version and appropriate RSN IE
96057 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
96058 +
96059 + // Update Key Length
96060 + Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];
96061 + Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];
96062 +
96063 + // Key Type PeerKey
96064 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
96065 +
96066 + // KeyMic field presented
96067 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
96068 +
96069 + // In Msg3, KeyInfo.secure =0 if Group Key HS to come. 1 if no group key HS
96070 + // Station sends Msg4 KeyInfo.secure should be the same as that in Msg.3
96071 + Packet.KeyDesc.KeyInfo.Secure= peerKeyInfo.Secure;
96072 +
96073 + // Convert to little-endian format.
96074 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
96075 +
96076 + // Key Replay count
96077 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96078 +
96079 + // Out buffer for transmitting message 4
96080 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
96081 + if(pOutBuffer == NULL)
96082 + return;
96083 +
96084 + // Prepare EAPOL frame for MIC calculation
96085 + // Be careful, only EAPOL frame is counted for MIC calculation
96086 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96087 + Packet.Body_Len[1] + 4, &Packet,
96088 + END_OF_ARGS);
96089 +
96090 + // Prepare and Fill MIC value
96091 + NdisZeroMemory(Mic, sizeof(Mic));
96092 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96093 + {
96094 + // AES
96095 + UCHAR digest[80];
96096 +
96097 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96098 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96099 + }
96100 + else
96101 + {
96102 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
96103 + }
96104 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
96105 +
96106 + // Update PTK
96107 + // Prepare pair-wise key information into shared key table
96108 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
96109 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
96110 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
96111 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
96112 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
96113 +
96114 + // Decide its ChiperAlg
96115 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
96116 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
96117 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
96118 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
96119 + else
96120 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
96121 +
96122 + // Update these related information to MAC_TABLE_ENTRY
96123 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
96124 + NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
96125 + NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
96126 + NdisMoveMemory(pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
96127 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
96128 +
96129 + // Update pairwise key information to ASIC Shared Key Table
96130 + AsicAddSharedKeyEntry(pAd,
96131 + BSS0,
96132 + 0,
96133 + pAd->SharedKey[BSS0][0].CipherAlg,
96134 + pAd->SharedKey[BSS0][0].Key,
96135 + pAd->SharedKey[BSS0][0].TxMic,
96136 + pAd->SharedKey[BSS0][0].RxMic);
96137 +
96138 + // Update ASIC WCID attribute table and IVEIV table
96139 + RTMPAddWcidAttributeEntry(pAd,
96140 + BSS0,
96141 + 0,
96142 + pAd->SharedKey[BSS0][0].CipherAlg,
96143 + pEntry);
96144 +
96145 + // Make transmitting frame
96146 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96147 + LENGTH_802_3, &Header802_3,
96148 + Packet.Body_Len[1] + 4, &Packet,
96149 + END_OF_ARGS);
96150 +
96151 +
96152 + // Copy frame to Tx ring and Send Message 4 to authenticator
96153 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
96154 +
96155 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
96156 +
96157 + DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action <-----\n"));
96158 +}
96159 +
96160 +VOID Wpa2PairMsg3Action(
96161 + IN PRTMP_ADAPTER pAd,
96162 + IN MLME_QUEUE_ELEM *Elem)
96163 +
96164 +{
96165 + PHEADER_802_11 pHeader;
96166 + PUCHAR pOutBuffer = NULL;
96167 + UCHAR Header802_3[14];
96168 + ULONG FrameLen = 0;
96169 + EAPOL_PACKET Packet;
96170 + PEAPOL_PACKET pMsg3;
96171 + UCHAR Mic[16], OldMic[16];
96172 + UCHAR *mpool, *KEYDATA, *digest;
96173 + UCHAR Key[32];
96174 + MAC_TABLE_ENTRY *pEntry = NULL;
96175 + KEY_INFO peerKeyInfo;
96176 +
96177 + // allocate memory
96178 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);
96179 +
96180 + if(mpool == NULL)
96181 + return;
96182 +
96183 + // KEYDATA Len = 512.
96184 + KEYDATA = (UCHAR *) ROUND_UP(mpool, 4);
96185 + // digest Len = 80.
96186 + digest = (UCHAR *) ROUND_UP(KEYDATA + 512, 4);
96187 +
96188 + DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg3Action ----->\n"));
96189 +
96190 + pHeader = (PHEADER_802_11) Elem->Msg;
96191 +
96192 + // Process message 3 frame.
96193 + pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
96194 +
96195 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
96196 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));
96197 +
96198 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
96199 +
96200 + // 1. Verify cipher type match
96201 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer!= 2))
96202 + {
96203 + os_free_mem(pAd, (PUCHAR)mpool);
96204 + return;
96205 + }
96206 + else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
96207 + {
96208 + os_free_mem(pAd, (PUCHAR)mpool);
96209 + return;
96210 + }
96211 +
96212 + // 2. Check MIC value
96213 + // Save the MIC and replace with zero
96214 + NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96215 + NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96216 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96217 + {
96218 + // AES
96219 + HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96220 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96221 + }
96222 + else
96223 + {
96224 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);
96225 + }
96226 +
96227 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
96228 + {
96229 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));
96230 + os_free_mem(pAd, (PUCHAR)mpool);
96231 + return;
96232 + }
96233 + else
96234 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));
96235 +
96236 + // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger
96237 + if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
96238 + {
96239 + os_free_mem(pAd, (PUCHAR)mpool);
96240 + return;
96241 + }
96242 +
96243 + // Update new replay counter
96244 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96245 +
96246 + // 4. Double check ANonce
96247 + if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))
96248 + {
96249 + os_free_mem(pAd, (PUCHAR)mpool);
96250 + return;
96251 + }
96252 +
96253 + // Obtain GTK
96254 + // 5. Decrypt GTK from Key Data
96255 + DBGPRINT_RAW(RT_DEBUG_TRACE, ("EKD = %d\n", peerKeyInfo.EKD_DL));
96256 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96257 + {
96258 + // Decrypt AES GTK
96259 + AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pMsg3->KeyDesc.KeyDataLen[1],pMsg3->KeyDesc.KeyData);
96260 + }
96261 + else // TKIP
96262 + {
96263 + INT i;
96264 + // Decrypt TKIP GTK
96265 + // Construct 32 bytes RC4 Key
96266 + NdisMoveMemory(Key, pMsg3->KeyDesc.KeyIv, 16);
96267 + NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);
96268 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
96269 + //discard first 256 bytes
96270 + for(i = 0; i < 256; i++)
96271 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
96272 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
96273 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);
96274 + }
96275 +
96276 + if (!ParseKeyData(pAd, KEYDATA, pMsg3->KeyDesc.KeyDataLen[1], 1))
96277 + {
96278 + os_free_mem(pAd, (PUCHAR)mpool);
96279 + return;
96280 + }
96281 +
96282 + // Update GTK to ASIC
96283 + // Update group key information to ASIC Shared Key Table
96284 + AsicAddSharedKeyEntry(pAd,
96285 + BSS0,
96286 + pAd->StaCfg.DefaultKeyId,
96287 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96288 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
96289 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
96290 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
96291 +
96292 + // Update ASIC WCID attribute table and IVEIV table
96293 + RTMPAddWcidAttributeEntry(pAd,
96294 + BSS0,
96295 + pAd->StaCfg.DefaultKeyId,
96296 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96297 + NULL);
96298 +
96299 + // init 802.3 header and Fill Packet
96300 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
96301 +
96302 + // Zero message 4 body
96303 + NdisZeroMemory(&Packet, sizeof(Packet));
96304 + Packet.ProVer = EAPOL_VER;
96305 + Packet.ProType = EAPOLKey;
96306 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
96307 +
96308 + //
96309 + // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)
96310 + //
96311 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
96312 +
96313 + // Key descriptor version and appropriate RSN IE
96314 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
96315 +
96316 + // Update Key Length
96317 + Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];
96318 + Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];
96319 +
96320 + // Key Type PeerKey
96321 + Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
96322 +
96323 + // KeyMic field presented
96324 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
96325 + Packet.KeyDesc.KeyInfo.Secure = 1;
96326 +
96327 + // Convert to little-endian format.
96328 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
96329 +
96330 + // Key Replay count
96331 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96332 +
96333 + // Out buffer for transmitting message 4
96334 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
96335 + if(pOutBuffer == NULL)
96336 + {
96337 + os_free_mem(pAd, (PUCHAR)mpool);
96338 + return;
96339 + }
96340 +
96341 + // Prepare EAPOL frame for MIC calculation
96342 + // Be careful, only EAPOL frame is counted for MIC calculation
96343 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96344 + Packet.Body_Len[1] + 4, &Packet,
96345 + END_OF_ARGS);
96346 +
96347 + // Prepare and Fill MIC value
96348 + NdisZeroMemory(Mic, sizeof(Mic));
96349 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96350 + {
96351 + // AES
96352 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96353 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96354 + }
96355 + else
96356 + {
96357 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
96358 + }
96359 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
96360 +
96361 + // Update PTK
96362 + // Prepare pair-wise key information into shared key table
96363 + NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
96364 + pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
96365 + NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
96366 + NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
96367 + NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
96368 +
96369 + // Decide its ChiperAlg
96370 + if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
96371 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
96372 + else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
96373 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
96374 + else
96375 + pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
96376 +
96377 + // Update these related information to MAC_TABLE_ENTRY
96378 + pEntry = &pAd->MacTab.Content[BSSID_WCID];
96379 + NdisMoveMemory(&pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
96380 + NdisMoveMemory(&pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);
96381 + NdisMoveMemory(&pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
96382 + pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
96383 +
96384 + // Update pairwise key information to ASIC Shared Key Table
96385 + AsicAddSharedKeyEntry(pAd,
96386 + BSS0,
96387 + 0,
96388 + pAd->SharedKey[BSS0][0].CipherAlg,
96389 + pAd->SharedKey[BSS0][0].Key,
96390 + pAd->SharedKey[BSS0][0].TxMic,
96391 + pAd->SharedKey[BSS0][0].RxMic);
96392 +
96393 + // Update ASIC WCID attribute table and IVEIV table
96394 + RTMPAddWcidAttributeEntry(pAd,
96395 + BSS0,
96396 + 0,
96397 + pAd->SharedKey[BSS0][0].CipherAlg,
96398 + pEntry);
96399 +
96400 + // Make Transmitting frame
96401 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96402 + LENGTH_802_3, &Header802_3,
96403 + Packet.Body_Len[1] + 4, &Packet,
96404 + END_OF_ARGS);
96405 +
96406 +
96407 + // Copy frame to Tx ring and Send Message 4 to authenticator
96408 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);
96409 +
96410 + // set 802.1x port control
96411 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
96412 + STA_PORT_SECURED(pAd);
96413 +
96414 + // Indicate Connected for GUI
96415 + pAd->IndicateMediaState = NdisMediaStateConnected;
96416 +
96417 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
96418 + os_free_mem(pAd, (PUCHAR)mpool);
96419 +
96420 +
96421 + // send wireless event - for set key done WPA2
96422 + if (pAd->CommonCfg.bWirelessEvent)
96423 + RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pEntry->Addr, BSS0, 0);
96424 +
96425 + DBGPRINT(RT_DEBUG_ERROR, ("Wpa2PairMsg3Action <-----\n"));
96426 +
96427 +}
96428 +
96429 +/*
96430 + ========================================================================
96431 +
96432 + Routine Description:
96433 + Process Group key 2-way handshaking
96434 +
96435 + Arguments:
96436 + pAd Pointer to our adapter
96437 + Elem Message body
96438 +
96439 + Return Value:
96440 + None
96441 +
96442 + Note:
96443 +
96444 + ========================================================================
96445 +*/
96446 +VOID WpaGroupMsg1Action(
96447 + IN PRTMP_ADAPTER pAd,
96448 + IN MLME_QUEUE_ELEM *Elem)
96449 +
96450 +{
96451 + PUCHAR pOutBuffer = NULL;
96452 + UCHAR Header802_3[14];
96453 + ULONG FrameLen = 0;
96454 + EAPOL_PACKET Packet;
96455 + PEAPOL_PACKET pGroup;
96456 + UCHAR *mpool, *digest, *KEYDATA;
96457 + UCHAR Mic[16], OldMic[16];
96458 + UCHAR GTK[32], Key[32];
96459 + KEY_INFO peerKeyInfo;
96460 +
96461 + // allocate memory
96462 + os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);
96463 +
96464 + if(mpool == NULL)
96465 + return;
96466 +
96467 + // digest Len = 80.
96468 + digest = (UCHAR *) ROUND_UP(mpool, 4);
96469 + // KEYDATA Len = 512.
96470 + KEYDATA = (UCHAR *) ROUND_UP(digest + 80, 4);
96471 +
96472 + DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action ----->\n"));
96473 +
96474 + // Process Group Message 1 frame. skip 802.11 header(24) & LLC_SNAP header(8)
96475 + pGroup = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
96476 +
96477 + NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));
96478 + NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pGroup->KeyDesc.KeyInfo, sizeof(KEY_INFO));
96479 +
96480 + *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));
96481 +
96482 + // 0. Check cipher type match
96483 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))
96484 + {
96485 + os_free_mem(pAd, (PUCHAR)mpool);
96486 + return;
96487 + }
96488 + else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))
96489 + {
96490 + os_free_mem(pAd, (PUCHAR)mpool);
96491 + return;
96492 + }
96493 +
96494 + // 1. Verify Replay counter
96495 + // Check Replay Counter, it has to be larger than last one. No need to be exact one larger
96496 + if(RTMPCompareMemory(pGroup->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)
96497 + {
96498 + os_free_mem(pAd, (PUCHAR)mpool);
96499 + return;
96500 + }
96501 +
96502 + // Update new replay counter
96503 + NdisMoveMemory(pAd->StaCfg.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96504 +
96505 + // 2. Verify MIC is valid
96506 + // Save the MIC and replace with zero
96507 + NdisMoveMemory(OldMic, pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96508 + NdisZeroMemory(pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
96509 +
96510 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96511 + { // AES
96512 + HMAC_SHA1((PUCHAR) pGroup, pGroup->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96513 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96514 + }
96515 + else
96516 + { // TKIP
96517 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pGroup, pGroup->Body_Len[1] + 4, Mic);
96518 + }
96519 +
96520 + if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))
96521 + {
96522 + DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in group msg 1 of 2-way handshake!!!!!!!!!! \n"));
96523 + MlmeFreeMemory(pAd, (PUCHAR)mpool);
96524 + return;
96525 + }
96526 + else
96527 + DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in group msg 1 of 2-way handshake!!!!!!!!!! \n"));
96528 +
96529 +
96530 + // 3. Decrypt GTK from Key Data
96531 + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96532 + {
96533 + // Decrypt AES GTK
96534 + AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pGroup->KeyDesc.KeyDataLen[1], pGroup->KeyDesc.KeyData);
96535 + }
96536 + else // TKIP
96537 + {
96538 + INT i;
96539 +
96540 + // Decrypt TKIP GTK
96541 + // Construct 32 bytes RC4 Key
96542 + NdisMoveMemory(Key, pGroup->KeyDesc.KeyIv, 16);
96543 + NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);
96544 + ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);
96545 + //discard first 256 bytes
96546 + for(i = 0; i < 256; i++)
96547 + ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);
96548 + // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not
96549 + ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pGroup->KeyDesc.KeyData, pGroup->KeyDesc.KeyDataLen[1]);
96550 + }
96551 +
96552 + // Process decrypted key data material
96553 + // Parse keyData to handle KDE format for WPA2PSK
96554 + if (peerKeyInfo.EKD_DL)
96555 + {
96556 + if (!ParseKeyData(pAd, KEYDATA, pGroup->KeyDesc.KeyDataLen[1], 0))
96557 + {
96558 + os_free_mem(pAd, (PUCHAR)mpool);
96559 + return;
96560 + }
96561 + }
96562 + else // WPAPSK
96563 + {
96564 + // set key material, TxMic and RxMic for WPAPSK
96565 + NdisMoveMemory(GTK, KEYDATA, 32);
96566 + NdisMoveMemory(pAd->StaCfg.GTK, GTK, 32);
96567 + pAd->StaCfg.DefaultKeyId = peerKeyInfo.KeyIndex;
96568 +
96569 + // Prepare pair-wise key information into shared key table
96570 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
96571 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
96572 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, GTK, LEN_TKIP_EK);
96573 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, &GTK[16], LEN_TKIP_RXMICK);
96574 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, &GTK[24], LEN_TKIP_TXMICK);
96575 +
96576 + // Update Shared Key CipherAlg
96577 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
96578 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
96579 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
96580 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
96581 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
96582 +
96583 + //hex_dump("Group Key :", pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, LEN_TKIP_EK);
96584 + }
96585 +
96586 + // Update group key information to ASIC Shared Key Table
96587 + AsicAddSharedKeyEntry(pAd,
96588 + BSS0,
96589 + pAd->StaCfg.DefaultKeyId,
96590 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96591 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
96592 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
96593 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
96594 +
96595 + // Update ASIC WCID attribute table and IVEIV table
96596 + RTMPAddWcidAttributeEntry(pAd,
96597 + BSS0,
96598 + pAd->StaCfg.DefaultKeyId,
96599 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
96600 + NULL);
96601 +
96602 + // set 802.1x port control
96603 + //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
96604 + STA_PORT_SECURED(pAd);
96605 +
96606 + // Indicate Connected for GUI
96607 + pAd->IndicateMediaState = NdisMediaStateConnected;
96608 +
96609 + // init header and Fill Packet
96610 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
96611 +
96612 + // Zero Group message 1 body
96613 + NdisZeroMemory(&Packet, sizeof(Packet));
96614 + Packet.ProVer = EAPOL_VER;
96615 + Packet.ProType = EAPOLKey;
96616 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field
96617 +
96618 + //
96619 + // Group Message 2 as EAPOL-Key(1,0,0,0,G,0,0,MIC,0)
96620 + //
96621 + if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
96622 + {
96623 + Packet.KeyDesc.Type = WPA2_KEY_DESC;
96624 + }
96625 + else
96626 + {
96627 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
96628 + }
96629 +
96630 + // Key descriptor version and appropriate RSN IE
96631 + Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;
96632 +
96633 + // Update Key Length
96634 + Packet.KeyDesc.KeyLength[0] = pGroup->KeyDesc.KeyLength[0];
96635 + Packet.KeyDesc.KeyLength[1] = pGroup->KeyDesc.KeyLength[1];
96636 +
96637 + // Key Index as G-Msg 1
96638 + if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
96639 + Packet.KeyDesc.KeyInfo.KeyIndex = peerKeyInfo.KeyIndex;
96640 +
96641 + // Key Type Group key
96642 + Packet.KeyDesc.KeyInfo.KeyType = GROUPKEY;
96643 +
96644 + // KeyMic field presented
96645 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
96646 +
96647 + // Secure bit
96648 + Packet.KeyDesc.KeyInfo.Secure = 1;
96649 +
96650 + // Convert to little-endian format.
96651 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
96652 +
96653 + // Key Replay count
96654 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);
96655 +
96656 + // Out buffer for transmitting group message 2
96657 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
96658 + if(pOutBuffer == NULL)
96659 + {
96660 + MlmeFreeMemory(pAd, (PUCHAR)mpool);
96661 + return;
96662 + }
96663 +
96664 + // Prepare EAPOL frame for MIC calculation
96665 + // Be careful, only EAPOL frame is counted for MIC calculation
96666 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96667 + Packet.Body_Len[1] + 4, &Packet,
96668 + END_OF_ARGS);
96669 +
96670 + // Prepare and Fill MIC value
96671 + NdisZeroMemory(Mic, sizeof(Mic));
96672 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
96673 + {
96674 + // AES
96675 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
96676 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
96677 + }
96678 + else
96679 + {
96680 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
96681 + }
96682 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
96683 +
96684 +
96685 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
96686 + LENGTH_802_3, &Header802_3,
96687 + Packet.Body_Len[1] + 4, &Packet,
96688 + END_OF_ARGS);
96689 +
96690 +
96691 + // 5. Copy frame to Tx ring and prepare for encryption
96692 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);
96693 +
96694 + // 6 Free allocated memory
96695 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
96696 + os_free_mem(pAd, (PUCHAR)mpool);
96697 +
96698 + // send wireless event - for set key done WPA2
96699 + if (pAd->CommonCfg.bWirelessEvent)
96700 + RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
96701 +
96702 + DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action <-----\n"));
96703 +}
96704 +
96705 +/*
96706 + ========================================================================
96707 +
96708 + Routine Description:
96709 + Init WPA MAC header
96710 +
96711 + Arguments:
96712 + pAd Pointer to our adapter
96713 +
96714 + Return Value:
96715 + None
96716 +
96717 + Note:
96718 +
96719 + ========================================================================
96720 +*/
96721 +VOID WpaMacHeaderInit(
96722 + IN PRTMP_ADAPTER pAd,
96723 + IN OUT PHEADER_802_11 pHdr80211,
96724 + IN UCHAR wep,
96725 + IN PUCHAR pAddr1)
96726 +{
96727 + NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));
96728 + pHdr80211->FC.Type = BTYPE_DATA;
96729 + pHdr80211->FC.ToDs = 1;
96730 + if (wep == 1)
96731 + pHdr80211->FC.Wep = 1;
96732 +
96733 + // Addr1: BSSID, Addr2: SA, Addr3: DA
96734 + COPY_MAC_ADDR(pHdr80211->Addr1, pAddr1);
96735 + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
96736 + COPY_MAC_ADDR(pHdr80211->Addr3, pAd->CommonCfg.Bssid);
96737 + pHdr80211->Sequence = pAd->Sequence;
96738 +}
96739 +
96740 +/*
96741 + ========================================================================
96742 +
96743 + Routine Description:
96744 + Copy frame from waiting queue into relative ring buffer and set
96745 + appropriate ASIC register to kick hardware encryption before really
96746 + sent out to air.
96747 +
96748 + Arguments:
96749 + pAd Pointer to our adapter
96750 + PNDIS_PACKET Pointer to outgoing Ndis frame
96751 + NumberOfFrag Number of fragment required
96752 +
96753 + Return Value:
96754 + None
96755 +
96756 + Note:
96757 +
96758 + ========================================================================
96759 +*/
96760 +VOID RTMPToWirelessSta(
96761 + IN PRTMP_ADAPTER pAd,
96762 + IN PUCHAR pHeader802_3,
96763 + IN UINT HdrLen,
96764 + IN PUCHAR pData,
96765 + IN UINT DataLen,
96766 + IN BOOLEAN is4wayFrame)
96767 +
96768 +{
96769 + NDIS_STATUS Status;
96770 + PNDIS_PACKET pPacket;
96771 + UCHAR Index;
96772 +
96773 + do
96774 + {
96775 + // 1. build a NDIS packet and call RTMPSendPacket();
96776 + // be careful about how/when to release this internal allocated NDIS PACKET buffer
96777 + Status = RTMPAllocateNdisPacket(pAd, &pPacket, pHeader802_3, HdrLen, pData, DataLen);
96778 + if (Status != NDIS_STATUS_SUCCESS)
96779 + break;
96780 +
96781 + if (is4wayFrame)
96782 + RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 1);
96783 + else
96784 + RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 0);
96785 +
96786 + // 2. send out the packet
96787 + Status = STASendPacket(pAd, pPacket);
96788 + if(Status == NDIS_STATUS_SUCCESS)
96789 + {
96790 + // Dequeue one frame from TxSwQueue0..3 queue and process it
96791 + // There are three place calling dequeue for TX ring.
96792 + // 1. Here, right after queueing the frame.
96793 + // 2. At the end of TxRingTxDone service routine.
96794 + // 3. Upon NDIS call RTMPSendPackets
96795 + if((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
96796 + (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)))
96797 + {
96798 + for(Index = 0; Index < 5; Index ++)
96799 + if(pAd->TxSwQueue[Index].Number > 0)
96800 + RTMPDeQueuePacket(pAd, FALSE, Index, MAX_TX_PROCESS);
96801 + }
96802 + }
96803 + } while(FALSE);
96804 +
96805 +}
96806 +
96807 +/*
96808 + ========================================================================
96809 +
96810 + Routine Description:
96811 + Check Sanity RSN IE form AP
96812 +
96813 + Arguments:
96814 +
96815 + Return Value:
96816 +
96817 +
96818 + ========================================================================
96819 +*/
96820 +BOOLEAN CheckRSNIE(
96821 + IN PRTMP_ADAPTER pAd,
96822 + IN PUCHAR pData,
96823 + IN UCHAR DataLen,
96824 + OUT UCHAR *Offset)
96825 +{
96826 + PUCHAR pVIE;
96827 + UCHAR len;
96828 + PEID_STRUCT pEid;
96829 + BOOLEAN result = FALSE;
96830 +
96831 + pVIE = pData;
96832 + len = DataLen;
96833 + *Offset = 0;
96834 +
96835 + while (len > sizeof(RSNIE2))
96836 + {
96837 + pEid = (PEID_STRUCT) pVIE;
96838 + // WPA RSN IE
96839 + if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
96840 + {
96841 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) &&
96842 + (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&
96843 + (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))
96844 + {
96845 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA/WPAPSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));
96846 + result = TRUE;
96847 + }
96848 +
96849 + *Offset += (pEid->Len + 2);
96850 + }
96851 + // WPA2 RSN IE
96852 + else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
96853 + {
96854 + if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) &&
96855 + (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&
96856 + (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))
96857 + {
96858 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));
96859 + result = TRUE;
96860 + }
96861 +
96862 + *Offset += (pEid->Len + 2);
96863 + }
96864 + else
96865 + {
96866 + break;
96867 + }
96868 +
96869 + pVIE += (pEid->Len + 2);
96870 + len -= (pEid->Len + 2);
96871 + }
96872 +
96873 + DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> skip_offset(%d) \n", *Offset));
96874 +
96875 + return result;
96876 +
96877 +}
96878 +
96879 +
96880 +/*
96881 + ========================================================================
96882 +
96883 + Routine Description:
96884 + Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
96885 + GTK is encaptulated in KDE format at p.83 802.11i D10
96886 +
96887 + Arguments:
96888 +
96889 + Return Value:
96890 +
96891 + Note:
96892 + 802.11i D10
96893 +
96894 + ========================================================================
96895 +*/
96896 +BOOLEAN ParseKeyData(
96897 + IN PRTMP_ADAPTER pAd,
96898 + IN PUCHAR pKeyData,
96899 + IN UCHAR KeyDataLen,
96900 + IN UCHAR bPairewise)
96901 +{
96902 + PKDE_ENCAP pKDE = NULL;
96903 + PUCHAR pMyKeyData = pKeyData;
96904 + UCHAR KeyDataLength = KeyDataLen;
96905 + UCHAR GTKLEN;
96906 + UCHAR skip_offset;
96907 +
96908 + // Verify The RSN IE contained in Pairewise-Msg 3 and skip it
96909 + if (bPairewise)
96910 + {
96911 + // Check RSN IE whether it is WPA2/WPA2PSK
96912 + if (!CheckRSNIE(pAd, pKeyData, KeyDataLen, &skip_offset))
96913 + {
96914 + DBGPRINT(RT_DEBUG_ERROR, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE mismatched \n"));
96915 + hex_dump("Get KEYDATA :", pKeyData, KeyDataLen);
96916 + return FALSE;
96917 + }
96918 + else
96919 + {
96920 + // skip RSN IE
96921 + pMyKeyData += skip_offset;
96922 + KeyDataLength -= skip_offset;
96923 +
96924 + //DBGPRINT(RT_DEBUG_TRACE, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
96925 + }
96926 + }
96927 +
96928 + DBGPRINT(RT_DEBUG_TRACE,("ParseKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
96929 +
96930 + // Parse EKD format
96931 + if (KeyDataLength >= 8)
96932 + {
96933 + pKDE = (PKDE_ENCAP) pMyKeyData;
96934 + }
96935 + else
96936 + {
96937 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KeyDataLength is too short \n"));
96938 + return FALSE;
96939 + }
96940 +
96941 +
96942 + // Sanity check - shared key index should not be 0
96943 + if (pKDE->GTKEncap.Kid == 0)
96944 + {
96945 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index zero \n"));
96946 + return FALSE;
96947 + }
96948 +
96949 + // Sanity check - KED length
96950 + if (KeyDataLength < (pKDE->Len + 2))
96951 + {
96952 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
96953 + return FALSE;
96954 + }
96955 +
96956 + // Get GTK length - refer to IEEE 802.11i-2004 p.82
96957 + GTKLEN = pKDE->Len -6;
96958 +
96959 + if (GTKLEN < LEN_AES_KEY)
96960 + {
96961 + DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
96962 + return FALSE;
96963 + }
96964 + else
96965 + DBGPRINT(RT_DEBUG_TRACE, ("GTK Key with KDE formet got index=%d, len=%d \n", pKDE->GTKEncap.Kid, GTKLEN));
96966 +
96967 + // Update GTK
96968 + // set key material, TxMic and RxMic for WPAPSK
96969 + NdisMoveMemory(pAd->StaCfg.GTK, pKDE->GTKEncap.GTK, 32);
96970 + pAd->StaCfg.DefaultKeyId = pKDE->GTKEncap.Kid;
96971 +
96972 + // Update shared key table
96973 + NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
96974 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
96975 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKDE->GTKEncap.GTK, LEN_TKIP_EK);
96976 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, &pKDE->GTKEncap.GTK[16], LEN_TKIP_RXMICK);
96977 + NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, &pKDE->GTKEncap.GTK[24], LEN_TKIP_TXMICK);
96978 +
96979 + // Update Shared Key CipherAlg
96980 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
96981 + if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
96982 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
96983 + else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
96984 + pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
96985 +
96986 + return TRUE;
96987 +
96988 +}
96989 +
96990 +/*
96991 + ========================================================================
96992 +
96993 + Routine Description:
96994 + Cisco CCKM PRF function
96995 +
96996 + Arguments:
96997 + key Cisco Base Transient Key (BTK)
96998 + key_len The key length of the BTK
96999 + data Ruquest Number(RN) + BSSID
97000 + data_len The length of the data
97001 + output Store for PTK(Pairwise transient keys)
97002 + len The length of the output
97003 + Return Value:
97004 + None
97005 +
97006 + Note:
97007 + 802.1i Annex F.9
97008 +
97009 + ========================================================================
97010 +*/
97011 +VOID CCKMPRF(
97012 + IN UCHAR *key,
97013 + IN INT key_len,
97014 + IN UCHAR *data,
97015 + IN INT data_len,
97016 + OUT UCHAR *output,
97017 + IN INT len)
97018 +{
97019 + INT i;
97020 + UCHAR input[1024];
97021 + INT currentindex = 0;
97022 + INT total_len;
97023 +
97024 + NdisMoveMemory(input, data, data_len);
97025 + total_len = data_len;
97026 + input[total_len] = 0;
97027 + total_len++;
97028 + for (i = 0; i < (len + 19) / 20; i++)
97029 + {
97030 + HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
97031 + currentindex += 20;
97032 + input[total_len - 1]++;
97033 + }
97034 +}
97035 +
97036 +/*
97037 + ========================================================================
97038 +
97039 + Routine Description:
97040 + Process MIC error indication and record MIC error timer.
97041 +
97042 + Arguments:
97043 + pAd Pointer to our adapter
97044 + pWpaKey Pointer to the WPA key structure
97045 +
97046 + Return Value:
97047 + None
97048 +
97049 + IRQL = DISPATCH_LEVEL
97050 +
97051 + Note:
97052 +
97053 + ========================================================================
97054 +*/
97055 +VOID RTMPReportMicError(
97056 + IN PRTMP_ADAPTER pAd,
97057 + IN PCIPHER_KEY pWpaKey)
97058 +{
97059 + ULONG Now;
97060 + UCHAR unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1:0);
97061 +
97062 + // Record Last MIC error time and count
97063 + Now = jiffies;
97064 + if (pAd->StaCfg.MicErrCnt == 0)
97065 + {
97066 + pAd->StaCfg.MicErrCnt++;
97067 + pAd->StaCfg.LastMicErrorTime = Now;
97068 + NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
97069 + }
97070 + else if (pAd->StaCfg.MicErrCnt == 1)
97071 + {
97072 + if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now)
97073 + {
97074 + // Update Last MIC error time, this did not violate two MIC errors within 60 seconds
97075 + pAd->StaCfg.LastMicErrorTime = Now;
97076 + }
97077 + else
97078 + {
97079 +
97080 + if (pAd->CommonCfg.bWirelessEvent)
97081 + RTMPSendWirelessEvent(pAd, IW_COUNTER_MEASURES_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
97082 +
97083 + pAd->StaCfg.LastMicErrorTime = Now;
97084 + // Violate MIC error counts, MIC countermeasures kicks in
97085 + pAd->StaCfg.MicErrCnt++;
97086 + // We shall block all reception
97087 + // We shall clean all Tx ring and disassoicate from AP after next EAPOL frame
97088 + //
97089 + // No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets
97090 + // if pAd->StaCfg.MicErrCnt greater than 2.
97091 + //
97092 + // RTMPRingCleanUp(pAd, QID_AC_BK);
97093 + // RTMPRingCleanUp(pAd, QID_AC_BE);
97094 + // RTMPRingCleanUp(pAd, QID_AC_VI);
97095 + // RTMPRingCleanUp(pAd, QID_AC_VO);
97096 + // RTMPRingCleanUp(pAd, QID_HCCA);
97097 + }
97098 + }
97099 + else
97100 + {
97101 + // MIC error count >= 2
97102 + // This should not happen
97103 + ;
97104 + }
97105 + MlmeEnqueue(pAd,
97106 + MLME_CNTL_STATE_MACHINE,
97107 + OID_802_11_MIC_FAILURE_REPORT_FRAME,
97108 + 1,
97109 + &unicastKey);
97110 +
97111 + if (pAd->StaCfg.MicErrCnt == 2)
97112 + {
97113 + RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100);
97114 + }
97115 +}
97116 +
97117 +
97118 +#ifdef WPA_SUPPLICANT_SUPPORT
97119 +#define LENGTH_EAP_H 4
97120 +// If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)).
97121 +INT WpaCheckEapCode(
97122 + IN PRTMP_ADAPTER pAd,
97123 + IN PUCHAR pFrame,
97124 + IN USHORT FrameLen,
97125 + IN USHORT OffSet)
97126 +{
97127 +
97128 + PUCHAR pData;
97129 + INT result = 0;
97130 +
97131 + if( FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H )
97132 + return result;
97133 +
97134 + pData = pFrame + OffSet; // skip offset bytes
97135 +
97136 + if(*(pData+1) == EAPPacket) // 802.1x header - Packet Type
97137 + {
97138 + result = *(pData+4); // EAP header - Code
97139 + }
97140 +
97141 + return result;
97142 +}
97143 +
97144 +VOID WpaSendMicFailureToWpaSupplicant(
97145 + IN PRTMP_ADAPTER pAd,
97146 + IN BOOLEAN bUnicast)
97147 +{
97148 + union iwreq_data wrqu;
97149 + char custom[IW_CUSTOM_MAX] = {0};
97150 +
97151 + sprintf(custom, "MLME-MICHAELMICFAILURE.indication");
97152 + if (bUnicast)
97153 + sprintf(custom, "%s unicast", custom);
97154 + wrqu.data.length = strlen(custom);
97155 + wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);
97156 +
97157 + return;
97158 +}
97159 +#endif // WPA_SUPPLICANT_SUPPORT //
97160 +
97161 +VOID WpaMicFailureReportFrame(
97162 + IN PRTMP_ADAPTER pAd,
97163 + IN MLME_QUEUE_ELEM *Elem)
97164 +{
97165 + PUCHAR pOutBuffer = NULL;
97166 + UCHAR Header802_3[14];
97167 + ULONG FrameLen = 0;
97168 + EAPOL_PACKET Packet;
97169 + UCHAR Mic[16];
97170 + BOOLEAN bUnicast;
97171 +
97172 + DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n"));
97173 +
97174 + bUnicast = (Elem->Msg[0] == 1 ? TRUE:FALSE);
97175 + pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER);
97176 +
97177 + // init 802.3 header and Fill Packet
97178 + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);
97179 +
97180 + NdisZeroMemory(&Packet, sizeof(Packet));
97181 + Packet.ProVer = EAPOL_VER;
97182 + Packet.ProType = EAPOLKey;
97183 +
97184 + Packet.KeyDesc.Type = WPA1_KEY_DESC;
97185 +
97186 + // Request field presented
97187 + Packet.KeyDesc.KeyInfo.Request = 1;
97188 +
97189 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
97190 + {
97191 + Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
97192 + }
97193 + else // TKIP
97194 + {
97195 + Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
97196 + }
97197 +
97198 + Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY);
97199 +
97200 + // KeyMic field presented
97201 + Packet.KeyDesc.KeyInfo.KeyMic = 1;
97202 +
97203 + // Error field presented
97204 + Packet.KeyDesc.KeyInfo.Error = 1;
97205 +
97206 + // Update packet length after decide Key data payload
97207 + Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE;
97208 +
97209 + // Key Replay Count
97210 + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
97211 + inc_byte_array(pAd->StaCfg.ReplayCounter, 8);
97212 +
97213 + // Convert to little-endian format.
97214 + *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));
97215 +
97216 +
97217 + MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory
97218 + if(pOutBuffer == NULL)
97219 + {
97220 + return;
97221 + }
97222 +
97223 + // Prepare EAPOL frame for MIC calculation
97224 + // Be careful, only EAPOL frame is counted for MIC calculation
97225 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
97226 + Packet.Body_Len[1] + 4, &Packet,
97227 + END_OF_ARGS);
97228 +
97229 + // Prepare and Fill MIC value
97230 + NdisZeroMemory(Mic, sizeof(Mic));
97231 + if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
97232 + { // AES
97233 + UCHAR digest[20] = {0};
97234 + HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);
97235 + NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
97236 + }
97237 + else
97238 + { // TKIP
97239 + hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);
97240 + }
97241 + NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
97242 +
97243 + MakeOutgoingFrame(pOutBuffer, &FrameLen,
97244 + LENGTH_802_3, &Header802_3,
97245 + Packet.Body_Len[1] + 4, &Packet,
97246 + END_OF_ARGS);
97247 +
97248 + // opy frame to Tx ring and send MIC failure report frame to authenticator
97249 + RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);
97250 +
97251 + MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);
97252 +
97253 + DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n"));
97254 +}
97255 +
97256 +/** from wpa_supplicant
97257 + * inc_byte_array - Increment arbitrary length byte array by one
97258 + * @counter: Pointer to byte array
97259 + * @len: Length of the counter in bytes
97260 + *
97261 + * This function increments the last byte of the counter by one and continues
97262 + * rolling over to more significant bytes if the byte was incremented from
97263 + * 0xff to 0x00.
97264 + */
97265 +void inc_byte_array(UCHAR *counter, int len)
97266 +{
97267 + int pos = len - 1;
97268 + while (pos >= 0) {
97269 + counter[pos]++;
97270 + if (counter[pos] != 0)
97271 + break;
97272 + pos--;
97273 + }
97274 +}
97275 +
97276 +VOID WpaDisassocApAndBlockAssoc(
97277 + IN PVOID SystemSpecific1,
97278 + IN PVOID FunctionContext,
97279 + IN PVOID SystemSpecific2,
97280 + IN PVOID SystemSpecific3)
97281 +{
97282 + RTMP_ADAPTER *pAd = (PRTMP_ADAPTER)FunctionContext;
97283 + MLME_DISASSOC_REQ_STRUCT DisassocReq;
97284 +
97285 + // disassoc from current AP first
97286 + DBGPRINT(RT_DEBUG_TRACE, ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n"));
97287 + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_MIC_FAILURE);
97288 + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
97289 +
97290 + pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
97291 + pAd->StaCfg.bBlockAssoc = TRUE;
97292 +}
97293 +
97294 --- /dev/null
97295 +++ b/drivers/staging/rt3070/wpa.h
97296 @@ -0,0 +1,356 @@
97297 +/*
97298 + *************************************************************************
97299 + * Ralink Tech Inc.
97300 + * 5F., No.36, Taiyuan St., Jhubei City,
97301 + * Hsinchu County 302,
97302 + * Taiwan, R.O.C.
97303 + *
97304 + * (c) Copyright 2002-2007, Ralink Technology, Inc.
97305 + *
97306 + * This program is free software; you can redistribute it and/or modify *
97307 + * it under the terms of the GNU General Public License as published by *
97308 + * the Free Software Foundation; either version 2 of the License, or *
97309 + * (at your option) any later version. *
97310 + * *
97311 + * This program is distributed in the hope that it will be useful, *
97312 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
97313 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
97314 + * GNU General Public License for more details. *
97315 + * *
97316 + * You should have received a copy of the GNU General Public License *
97317 + * along with this program; if not, write to the *
97318 + * Free Software Foundation, Inc., *
97319 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
97320 + * *
97321 + *************************************************************************
97322 +
97323 + Module Name:
97324 + wpa.h
97325 +
97326 + Abstract:
97327 +
97328 + Revision History:
97329 + Who When What
97330 + -------- ---------- ----------------------------------------------
97331 + Name Date Modification logs
97332 +*/
97333 +
97334 +#ifndef __WPA_H__
97335 +#define __WPA_H__
97336 +
97337 +// EAPOL Key descripter frame format related length
97338 +#define LEN_KEY_DESC_NONCE 32
97339 +#define LEN_KEY_DESC_IV 16
97340 +#define LEN_KEY_DESC_RSC 8
97341 +#define LEN_KEY_DESC_ID 8
97342 +#define LEN_KEY_DESC_REPLAY 8
97343 +#define LEN_KEY_DESC_MIC 16
97344 +
97345 +// The length is the EAPoL-Key frame except key data field.
97346 +// Please refer to 802.11i-2004 ,Figure 43u in p.78
97347 +#define LEN_EAPOL_KEY_MSG (sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE)
97348 +
97349 +// EAP Code Type.
97350 +#define EAP_CODE_REQUEST 1
97351 +#define EAP_CODE_RESPONSE 2
97352 +#define EAP_CODE_SUCCESS 3
97353 +#define EAP_CODE_FAILURE 4
97354 +
97355 +// EAPOL frame Protocol Version
97356 +#define EAPOL_VER 1
97357 +#define EAPOL_VER2 2
97358 +
97359 +// EAPOL-KEY Descriptor Type
97360 +#define WPA1_KEY_DESC 0xfe
97361 +#define WPA2_KEY_DESC 0x02
97362 +
97363 +// Key Descriptor Version of Key Information
97364 +#define DESC_TYPE_TKIP 1
97365 +#define DESC_TYPE_AES 2
97366 +#define DESC_TYPE_MESH 3
97367 +
97368 +#define LEN_MSG1_2WAY 0x7f
97369 +#define MAX_LEN_OF_EAP_HS 256
97370 +
97371 +#define LEN_MASTER_KEY 32
97372 +
97373 +// EAPOL EK, MK
97374 +#define LEN_EAP_EK 16
97375 +#define LEN_EAP_MICK 16
97376 +#define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK))
97377 +// TKIP key related
97378 +#define LEN_PMKID 16
97379 +#define LEN_TKIP_EK 16
97380 +#define LEN_TKIP_RXMICK 8
97381 +#define LEN_TKIP_TXMICK 8
97382 +#define LEN_AES_EK 16
97383 +#define LEN_AES_KEY LEN_AES_EK
97384 +#define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
97385 +#define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK))
97386 +#define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK)
97387 +#define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
97388 +#define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY))
97389 +
97390 +// RSN IE Length definition
97391 +#define MAX_LEN_OF_RSNIE 90
97392 +#define MIN_LEN_OF_RSNIE 8
97393 +
97394 +//EAP Packet Type
97395 +#define EAPPacket 0
97396 +#define EAPOLStart 1
97397 +#define EAPOLLogoff 2
97398 +#define EAPOLKey 3
97399 +#define EAPOLASFAlert 4
97400 +#define EAPTtypeMax 5
97401 +
97402 +#define EAPOL_MSG_INVALID 0
97403 +#define EAPOL_PAIR_MSG_1 1
97404 +#define EAPOL_PAIR_MSG_2 2
97405 +#define EAPOL_PAIR_MSG_3 3
97406 +#define EAPOL_PAIR_MSG_4 4
97407 +#define EAPOL_GROUP_MSG_1 5
97408 +#define EAPOL_GROUP_MSG_2 6
97409 +
97410 +#define PAIRWISEKEY 1
97411 +#define GROUPKEY 0
97412 +
97413 +// Retry timer counter initial value
97414 +#define PEER_MSG1_RETRY_TIMER_CTR 0
97415 +#define PEER_MSG3_RETRY_TIMER_CTR 10
97416 +#define GROUP_MSG1_RETRY_TIMER_CTR 20
97417 +
97418 +
97419 +#define EAPOL_START_DISABLE 0
97420 +#define EAPOL_START_PSK 1
97421 +#define EAPOL_START_1X 2
97422 +
97423 +#define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
97424 +#define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
97425 +#define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
97426 +#define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
97427 +
97428 +#define ROUND_UP(__x, __y) \
97429 + (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
97430 +
97431 +#define ADD_ONE_To_64BIT_VAR(_V) \
97432 +{ \
97433 + UCHAR cnt = LEN_KEY_DESC_REPLAY; \
97434 + do \
97435 + { \
97436 + cnt--; \
97437 + _V[cnt]++; \
97438 + if (cnt == 0) \
97439 + break; \
97440 + }while (_V[cnt] == 0); \
97441 +}
97442 +
97443 +#define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
97444 +
97445 +// EAPOL Key Information definition within Key descriptor format
97446 +typedef struct PACKED _KEY_INFO
97447 +{
97448 +#ifdef RT_BIG_ENDIAN
97449 + UCHAR KeyAck:1;
97450 + UCHAR Install:1;
97451 + UCHAR KeyIndex:2;
97452 + UCHAR KeyType:1;
97453 + UCHAR KeyDescVer:3;
97454 + UCHAR Rsvd:3;
97455 + UCHAR EKD_DL:1; // EKD for AP; DL for STA
97456 + UCHAR Request:1;
97457 + UCHAR Error:1;
97458 + UCHAR Secure:1;
97459 + UCHAR KeyMic:1;
97460 +#else
97461 + UCHAR KeyMic:1;
97462 + UCHAR Secure:1;
97463 + UCHAR Error:1;
97464 + UCHAR Request:1;
97465 + UCHAR EKD_DL:1; // EKD for AP; DL for STA
97466 + UCHAR Rsvd:3;
97467 + UCHAR KeyDescVer:3;
97468 + UCHAR KeyType:1;
97469 + UCHAR KeyIndex:2;
97470 + UCHAR Install:1;
97471 + UCHAR KeyAck:1;
97472 +#endif
97473 +} KEY_INFO, *PKEY_INFO;
97474 +
97475 +// EAPOL Key descriptor format
97476 +typedef struct PACKED _KEY_DESCRIPTER
97477 +{
97478 + UCHAR Type;
97479 + KEY_INFO KeyInfo;
97480 + UCHAR KeyLength[2];
97481 + UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY];
97482 + UCHAR KeyNonce[LEN_KEY_DESC_NONCE];
97483 + UCHAR KeyIv[LEN_KEY_DESC_IV];
97484 + UCHAR KeyRsc[LEN_KEY_DESC_RSC];
97485 + UCHAR KeyId[LEN_KEY_DESC_ID];
97486 + UCHAR KeyMic[LEN_KEY_DESC_MIC];
97487 + UCHAR KeyDataLen[2];
97488 + UCHAR KeyData[MAX_LEN_OF_RSNIE];
97489 +} KEY_DESCRIPTER, *PKEY_DESCRIPTER;
97490 +
97491 +typedef struct PACKED _EAPOL_PACKET
97492 +{
97493 + UCHAR ProVer;
97494 + UCHAR ProType;
97495 + UCHAR Body_Len[2];
97496 + KEY_DESCRIPTER KeyDesc;
97497 +} EAPOL_PACKET, *PEAPOL_PACKET;
97498 +
97499 +//802.11i D10 page 83
97500 +typedef struct PACKED _GTK_ENCAP
97501 +{
97502 +#ifndef RT_BIG_ENDIAN
97503 + UCHAR Kid:2;
97504 + UCHAR tx:1;
97505 + UCHAR rsv:5;
97506 + UCHAR rsv1;
97507 +#else
97508 + UCHAR rsv:5;
97509 + UCHAR tx:1;
97510 + UCHAR Kid:2;
97511 + UCHAR rsv1;
97512 +#endif
97513 + UCHAR GTK[TKIP_GTK_LENGTH];
97514 +} GTK_ENCAP, *PGTK_ENCAP;
97515 +
97516 +typedef struct PACKED _KDE_ENCAP
97517 +{
97518 + UCHAR Type;
97519 + UCHAR Len;
97520 + UCHAR OUI[3];
97521 + UCHAR DataType;
97522 + GTK_ENCAP GTKEncap;
97523 +} KDE_ENCAP, *PKDE_ENCAP;
97524 +
97525 +// For WPA1
97526 +typedef struct PACKED _RSNIE {
97527 + UCHAR oui[4];
97528 + USHORT version;
97529 + UCHAR mcast[4];
97530 + USHORT ucount;
97531 + struct PACKED {
97532 + UCHAR oui[4];
97533 + }ucast[1];
97534 +} RSNIE, *PRSNIE;
97535 +
97536 +// For WPA2
97537 +typedef struct PACKED _RSNIE2 {
97538 + USHORT version;
97539 + UCHAR mcast[4];
97540 + USHORT ucount;
97541 + struct PACKED {
97542 + UCHAR oui[4];
97543 + }ucast[1];
97544 +} RSNIE2, *PRSNIE2;
97545 +
97546 +// AKM Suite
97547 +typedef struct PACKED _RSNIE_AUTH {
97548 + USHORT acount;
97549 + struct PACKED {
97550 + UCHAR oui[4];
97551 + }auth[1];
97552 +} RSNIE_AUTH,*PRSNIE_AUTH;
97553 +
97554 +typedef union PACKED _RSN_CAPABILITIES {
97555 + struct PACKED {
97556 +#ifdef RT_BIG_ENDIAN
97557 + USHORT Rsvd:10;
97558 + USHORT GTKSA_R_Counter:2;
97559 + USHORT PTKSA_R_Counter:2;
97560 + USHORT No_Pairwise:1;
97561 + USHORT PreAuth:1;
97562 +#else
97563 + USHORT PreAuth:1;
97564 + USHORT No_Pairwise:1;
97565 + USHORT PTKSA_R_Counter:2;
97566 + USHORT GTKSA_R_Counter:2;
97567 + USHORT Rsvd:10;
97568 +#endif
97569 + } field;
97570 + USHORT word;
97571 +} RSN_CAPABILITIES, *PRSN_CAPABILITIES;
97572 +
97573 +typedef struct PACKED _EAP_HDR {
97574 + UCHAR ProVer;
97575 + UCHAR ProType;
97576 + UCHAR Body_Len[2];
97577 + UCHAR code;
97578 + UCHAR identifier;
97579 + UCHAR length[2]; // including code and identifier, followed by length-2 octets of data
97580 +} EAP_HDR, *PEAP_HDR;
97581 +
97582 +// For supplicant state machine states. 802.11i Draft 4.1, p. 97
97583 +// We simplified it
97584 +typedef enum _WpaState
97585 +{
97586 + SS_NOTUSE, // 0
97587 + SS_START, // 1
97588 + SS_WAIT_MSG_3, // 2
97589 + SS_WAIT_GROUP, // 3
97590 + SS_FINISH, // 4
97591 + SS_KEYUPDATE, // 5
97592 +} WPA_STATE;
97593 +
97594 +//
97595 +// The definition of the cipher combination
97596 +//
97597 +// bit3 bit2 bit1 bit0
97598 +// +------------+------------+
97599 +// | WPA | WPA2 |
97600 +// +------+-----+------+-----+
97601 +// | TKIP | AES | TKIP | AES |
97602 +// | 0 | 1 | 1 | 0 | -> 0x06
97603 +// | 0 | 1 | 1 | 1 | -> 0x07
97604 +// | 1 | 0 | 0 | 1 | -> 0x09
97605 +// | 1 | 0 | 1 | 1 | -> 0x0B
97606 +// | 1 | 1 | 0 | 1 | -> 0x0D
97607 +// | 1 | 1 | 1 | 0 | -> 0x0E
97608 +// | 1 | 1 | 1 | 1 | -> 0x0F
97609 +// +------+-----+------+-----+
97610 +//
97611 +typedef enum _WpaMixPairCipher
97612 +{
97613 + MIX_CIPHER_NOTUSE = 0x00,
97614 + WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES
97615 + WPA_AES_WPA2_TKIP = 0x06,
97616 + WPA_AES_WPA2_TKIPAES = 0x07,
97617 + WPA_TKIP_WPA2_AES = 0x09,
97618 + WPA_TKIP_WPA2_TKIPAES = 0x0B,
97619 + WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES
97620 + WPA_TKIPAES_WPA2_AES = 0x0D,
97621 + WPA_TKIPAES_WPA2_TKIP = 0x0E,
97622 + WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
97623 +} WPA_MIX_PAIR_CIPHER;
97624 +
97625 +typedef struct PACKED _RSN_IE_HEADER_STRUCT {
97626 + UCHAR Eid;
97627 + UCHAR Length;
97628 + USHORT Version; // Little endian format
97629 +} RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
97630 +
97631 +// Cipher suite selector types
97632 +typedef struct PACKED _CIPHER_SUITE_STRUCT {
97633 + UCHAR Oui[3];
97634 + UCHAR Type;
97635 +} CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
97636 +
97637 +// Authentication and Key Management suite selector
97638 +typedef struct PACKED _AKM_SUITE_STRUCT {
97639 + UCHAR Oui[3];
97640 + UCHAR Type;
97641 +} AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
97642 +
97643 +// RSN capability
97644 +typedef struct PACKED _RSN_CAPABILITY {
97645 + USHORT Rsv:10;
97646 + USHORT GTKSAReplayCnt:2;
97647 + USHORT PTKSAReplayCnt:2;
97648 + USHORT NoPairwise:1;
97649 + USHORT PreAuth:1;
97650 +} RSN_CAPABILITY, *PRSN_CAPABILITY;
97651 +
97652 +#endif